mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-13 07:32:20 +00:00
cli: remove redundant --git-repo path canonicalization
It was moved to CLI at 42252a2f00
"cli: on `jj init --git-repo=.`, use
relative path to `.git/`." As far as I can tell, .canonicalize() is needed
to calculate relative path, which is now processed differently in
Workspace::init_external_git() and GitBackend::init_external().
This commit is contained in:
parent
4c16c05be1
commit
fd0ace4c26
3 changed files with 20 additions and 7 deletions
|
@ -392,9 +392,6 @@ pub fn git_init(
|
|||
}
|
||||
} else if let Some(path_str) = git_repo {
|
||||
let mut git_repo_path = command.cwd().join(path_str);
|
||||
git_repo_path = git_repo_path
|
||||
.canonicalize()
|
||||
.map_err(|_| user_error(format!("{} doesn't exist", git_repo_path.display())))?;
|
||||
if !git_repo_path.ends_with(".git") {
|
||||
git_repo_path.push(".git");
|
||||
// Undo if .git doesn't exist - likely a bare repo.
|
||||
|
|
|
@ -67,6 +67,12 @@ fn read_git_target(workspace_root: &Path) -> String {
|
|||
std::fs::read_to_string(path).unwrap()
|
||||
}
|
||||
|
||||
fn strip_last_line(s: &str) -> &str {
|
||||
s.trim_end_matches('\n')
|
||||
.rsplit_once('\n')
|
||||
.map_or(s, |(h, _)| &s[..h.len() + 1])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_git_init_internal() {
|
||||
let test_env = TestEnvironment::default();
|
||||
|
@ -151,8 +157,10 @@ fn test_git_init_external_non_existent_directory() {
|
|||
test_env.env_root(),
|
||||
&["git", "init", "repo", "--git-repo", "non-existent"],
|
||||
);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: $TEST_ENV/non-existent doesn't exist
|
||||
insta::assert_snapshot!(strip_last_line(&stderr), @r###"
|
||||
Error: Failed to access the repository
|
||||
Caused by:
|
||||
1: Cannot access $TEST_ENV/non-existent
|
||||
"###);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,12 @@ fn read_git_target(workspace_root: &Path) -> String {
|
|||
std::fs::read_to_string(path).unwrap()
|
||||
}
|
||||
|
||||
fn strip_last_line(s: &str) -> &str {
|
||||
s.trim_end_matches('\n')
|
||||
.rsplit_once('\n')
|
||||
.map_or(s, |(h, _)| &s[..h.len() + 1])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_init_git_internal() {
|
||||
let test_env = TestEnvironment::default();
|
||||
|
@ -153,8 +159,10 @@ fn test_init_git_external_non_existent_directory() {
|
|||
test_env.env_root(),
|
||||
&["init", "repo", "--git-repo", "non-existent"],
|
||||
);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: $TEST_ENV/non-existent doesn't exist
|
||||
insta::assert_snapshot!(strip_last_line(&stderr), @r###"
|
||||
Error: Failed to access the repository
|
||||
Caused by:
|
||||
1: Cannot access $TEST_ENV/non-existent
|
||||
"###);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue