forked from mirrors/jj
cli: handle init destination error gracefully
This commit is contained in:
parent
61468ed126
commit
5d42c9ebca
2 changed files with 15 additions and 5 deletions
|
@ -1037,12 +1037,14 @@ fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &InitArgs) -> Result<(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let wc_path = ui.cwd().join(&args.destination);
|
let wc_path = ui.cwd().join(&args.destination);
|
||||||
if wc_path.exists() {
|
match fs::create_dir(&wc_path) {
|
||||||
assert!(wc_path.is_dir());
|
Ok(()) => {}
|
||||||
} else {
|
Err(_) if wc_path.is_dir() => {}
|
||||||
fs::create_dir(&wc_path).unwrap();
|
Err(e) => return Err(UserError(format!("Failed to create workspace: {e}"))),
|
||||||
}
|
}
|
||||||
let wc_path = wc_path.canonicalize().unwrap();
|
let wc_path = wc_path
|
||||||
|
.canonicalize()
|
||||||
|
.map_err(|e| UserError(format!("Failed to create workspace: {e}")))?; // raced?
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -173,6 +173,14 @@ fn test_init_git_internal_but_could_be_colocated() {
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_init_git_bad_wc_path() {
|
||||||
|
let test_env = TestEnvironment::default();
|
||||||
|
std::fs::write(test_env.env_root().join("existing-file"), b"").unwrap();
|
||||||
|
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["init", "--git", "existing-file"]);
|
||||||
|
assert!(stderr.contains("Failed to create workspace"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_init_local_disallowed() {
|
fn test_init_local_disallowed() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
|
|
Loading…
Reference in a new issue