Skip to content

Commit

Permalink
(For CI -- test that the parent PR works)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Jul 31, 2024
3 parents ce29824 + 9a6e5d4 + 450a6a5 commit 5bfb6b8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
15 changes: 11 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dunce = "1.0.4"
either = "1.13.0"
esl01-renderdag = "0.3.0"
futures = "0.3.30"
git2 = { version = "0.18.3", features = [
git2 = { version = "0.19.0", features = [
# Do *not* disable this feature even if you'd like dynamic linking. Instead,
# set the environment variable `LIBGIT2_NO_VENDOR=1` if dynamic linking must
# be used (this will override the Cargo feature), and allow static linking
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jj-lib = { workspace = true }
maplit = { workspace = true }
minus = { workspace = true }
once_cell = { workspace = true }
path-slash = "0.2.1"
pest = { workspace = true }
pest_derive = { workspace = true }
pollster = { workspace = true }
Expand Down
27 changes: 21 additions & 6 deletions cli/src/commands/git/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use jj_lib::git::{self, GitFetchError, GitFetchStats};
use jj_lib::repo::Repo;
use jj_lib::str_util::StringPattern;
use jj_lib::workspace::Workspace;
use path_slash::PathBufExt;

use crate::cli_util::{CommandHelper, WorkspaceCommandHelper};
use crate::command_error::{cli_error, user_error, user_error_with_message, CommandError};
Expand Down Expand Up @@ -47,18 +48,32 @@ pub struct GitCloneArgs {
colocate: bool,
}

fn looks_like_a_path_to_git(source: &str) -> bool {
source.chars().nth(1) == Some(':') || // Looks like a Windows C:... path
// Match Git's behavior, the URL syntax [is only recognized if there are no
// slashes before the first
// colon](https://git-scm.com/docs/git-clone#_git_urls)
!source
.split_once("/")
.map_or(source, |(first, _)| first)
.contains(":")
}

fn absolute_git_source(cwd: &Path, source: &str) -> String {
// Git appears to turn URL-like source to absolute path if local git directory
// exits, and fails because '$PWD/https' is unsupported protocol. Since it would
// be tedious to copy the exact git (or libgit2) behavior, we simply assume a
// source containing ':' is a URL, SSH remote, or absolute path with Windows
// drive letter.
if !source.contains(':') && Path::new(source).exists() {
// It's less likely that cwd isn't utf-8, so just fall back to original source.
cwd.join(source)
.into_os_string()
.into_string()
.unwrap_or_else(|_| source.to_owned())
if looks_like_a_path_to_git(source) && Path::new(source).exists() {
// TODO: This won't work for Windows UNC path or (less importantly) if the
// original source is a non-UTF Windows path. For Windows UNC paths, we
// could use dunce, though see also https://gitlab.com/kornelski/dunce/-/issues/7
cwd.join(source).to_slash().map_or_else(
// It's less likely that cwd isn't utf-8, so just fall back to original source.
|| source.to_owned(),
|s| s.to_string(),
)
} else {
source.to_owned()
}
Expand Down
6 changes: 4 additions & 2 deletions cli/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::collections::HashMap;
use std::path::{Path, PathBuf};

use itertools::Itertools as _;
use path_slash::PathBufExt;
use regex::{Captures, Regex};
use tempfile::TempDir;

Expand Down Expand Up @@ -320,8 +321,9 @@ impl TestEnvironment {
pub fn normalize_output(&self, text: &str) -> String {
let text = text.replace("jj.exe", "jj");
let regex = Regex::new(&format!(
r"{}(\S+)",
regex::escape(&self.env_root.display().to_string())
r"({}|{})(\S+)",
regex::escape(&self.env_root.display().to_string()),
regex::escape(&self.env_root.to_slash_lossy())
))
.unwrap();
regex
Expand Down
7 changes: 6 additions & 1 deletion lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,12 @@ pub fn fetch(
tracing::debug!("remote.prune");
remote.prune(None)?;
tracing::debug!("remote.update_tips");
remote.update_tips(None, false, git2::AutotagOption::Unspecified, None)?;
remote.update_tips(
None,
git2::RemoteUpdateFlags::empty(),
git2::AutotagOption::Unspecified,
None,
)?;
// TODO: We could make it optional to get the default branch since we only care
// about it on clone.
let mut default_branch = None;
Expand Down

0 comments on commit 5bfb6b8

Please sign in to comment.