mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
cli: on init, don't crash when Git repo doesn't exist
This commit is contained in:
parent
650853401d
commit
0870c47559
2 changed files with 15 additions and 1 deletions
|
@ -1076,10 +1076,12 @@ fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &InitArgs) -> Result<(),
|
||||||
|
|
||||||
if let Some(git_store_str) = &args.git_repo {
|
if let Some(git_store_str) = &args.git_repo {
|
||||||
let mut git_store_path = ui.cwd().join(git_store_str);
|
let mut git_store_path = ui.cwd().join(git_store_str);
|
||||||
|
git_store_path = git_store_path
|
||||||
|
.canonicalize()
|
||||||
|
.map_err(|_| UserError(format!("{} doesn't exist", git_store_path.display())))?;
|
||||||
if !git_store_path.ends_with(".git") {
|
if !git_store_path.ends_with(".git") {
|
||||||
git_store_path = git_store_path.join(".git");
|
git_store_path = git_store_path.join(".git");
|
||||||
}
|
}
|
||||||
git_store_path = git_store_path.canonicalize().unwrap();
|
|
||||||
// If the git repo is inside the workspace, use a relative path to it so the
|
// If the git repo is inside the workspace, use a relative path to it so the
|
||||||
// whole workspace can be moved without breaking.
|
// whole workspace can be moved without breaking.
|
||||||
if let Ok(relative_path) = git_store_path.strip_prefix(&wc_path) {
|
if let Ok(relative_path) = git_store_path.strip_prefix(&wc_path) {
|
||||||
|
|
|
@ -112,6 +112,18 @@ fn test_init_git_external() {
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_init_git_external_bad_path() {
|
||||||
|
let test_env = TestEnvironment::default();
|
||||||
|
let stderr = test_env.jj_cmd_failure(
|
||||||
|
test_env.env_root(),
|
||||||
|
&["init", "repo", "--git-repo", "non-existent"],
|
||||||
|
);
|
||||||
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
|
Error: $TEST_ENV/non-existent doesn't exist
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_init_git_colocated() {
|
fn test_init_git_colocated() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
|
|
Loading…
Reference in a new issue