forked from mirrors/jj
cli: add tests for failed "jj git clone"
Perhaps, the message "(os error 39)" isn't portable, but I don't care since it will be fixed by later patch.
This commit is contained in:
parent
0570963fe3
commit
d039008db8
1 changed files with 93 additions and 0 deletions
|
@ -67,6 +67,46 @@ fn test_git_clone() {
|
|||
Nothing changed.
|
||||
"###);
|
||||
|
||||
// Failed clone should clean up the destination directory
|
||||
std::fs::create_dir(test_env.env_root().join("bad")).unwrap();
|
||||
let assert = test_env
|
||||
.jj_cmd(test_env.env_root(), &["git", "clone", "bad", "failed"])
|
||||
.assert()
|
||||
.code(1);
|
||||
let stdout = test_env.normalize_output(&common::get_stdout_string(&assert));
|
||||
let stderr = test_env.normalize_output(&common::get_stderr_string(&assert));
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Fetching into new repo in "$TEST_ENV/failed"
|
||||
"###);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: could not find repository from '$TEST_ENV/bad'; class=Repository (6)
|
||||
"###);
|
||||
assert!(!test_env.env_root().join("failed").exists());
|
||||
|
||||
// Failed clone shouldn't remove the existing destination directory
|
||||
std::fs::create_dir(test_env.env_root().join("failed")).unwrap();
|
||||
let assert = test_env
|
||||
.jj_cmd(test_env.env_root(), &["git", "clone", "bad", "failed"])
|
||||
.assert()
|
||||
.code(1);
|
||||
let stdout = test_env.normalize_output(&common::get_stdout_string(&assert));
|
||||
let stderr = test_env.normalize_output(&common::get_stderr_string(&assert));
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Fetching into new repo in "$TEST_ENV/failed"
|
||||
"###);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: could not find repository from '$TEST_ENV/bad'; class=Repository (6)
|
||||
"###);
|
||||
assert!(test_env.env_root().join("failed").exists());
|
||||
assert!(!test_env.env_root().join("failed").join(".jj").exists());
|
||||
|
||||
// Failed clone (if attempted) shouldn't remove the existing workspace
|
||||
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["git", "clone", "bad", "clone"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: Destination path exists and is not an empty directory
|
||||
"###);
|
||||
assert!(test_env.env_root().join("clone").join(".jj").exists());
|
||||
|
||||
// Try cloning into an existing workspace
|
||||
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["git", "clone", "source", "clone"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
|
@ -164,6 +204,59 @@ fn test_git_clone_colocate() {
|
|||
Nothing changed.
|
||||
"###);
|
||||
|
||||
// Failed clone should clean up the destination directory
|
||||
std::fs::create_dir(test_env.env_root().join("bad")).unwrap();
|
||||
let assert = test_env
|
||||
.jj_cmd(
|
||||
test_env.env_root(),
|
||||
&["git", "clone", "--colocate", "bad", "failed"],
|
||||
)
|
||||
.assert()
|
||||
.code(1);
|
||||
let stdout = test_env.normalize_output(&common::get_stdout_string(&assert));
|
||||
let stderr = test_env.normalize_output(&common::get_stderr_string(&assert));
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Fetching into new repo in "$TEST_ENV/failed"
|
||||
Failed to clean up $TEST_ENV/failed: Directory not empty (os error 39)
|
||||
"###);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: could not find repository from '$TEST_ENV/bad'; class=Repository (6)
|
||||
"###);
|
||||
// FIXME: assert!(!test_env.env_root().join("failed").exists());
|
||||
std::fs::remove_dir_all(test_env.env_root().join("failed")).unwrap();
|
||||
|
||||
// Failed clone shouldn't remove the existing destination directory
|
||||
std::fs::create_dir(test_env.env_root().join("failed")).unwrap();
|
||||
let assert = test_env
|
||||
.jj_cmd(
|
||||
test_env.env_root(),
|
||||
&["git", "clone", "--colocate", "bad", "failed"],
|
||||
)
|
||||
.assert()
|
||||
.code(1);
|
||||
let stdout = test_env.normalize_output(&common::get_stdout_string(&assert));
|
||||
let stderr = test_env.normalize_output(&common::get_stderr_string(&assert));
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Fetching into new repo in "$TEST_ENV/failed"
|
||||
"###);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: could not find repository from '$TEST_ENV/bad'; class=Repository (6)
|
||||
"###);
|
||||
assert!(test_env.env_root().join("failed").exists());
|
||||
// FIXME: assert!(!test_env.env_root().join("failed").join(".git").exists());
|
||||
assert!(!test_env.env_root().join("failed").join(".jj").exists());
|
||||
|
||||
// Failed clone (if attempted) shouldn't remove the existing workspace
|
||||
let stderr = test_env.jj_cmd_failure(
|
||||
test_env.env_root(),
|
||||
&["git", "clone", "--colocate", "bad", "clone"],
|
||||
);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: Destination path exists and is not an empty directory
|
||||
"###);
|
||||
assert!(test_env.env_root().join("clone").join(".git").exists());
|
||||
assert!(test_env.env_root().join("clone").join(".jj").exists());
|
||||
|
||||
// Try cloning into an existing workspace
|
||||
let stderr = test_env.jj_cmd_failure(
|
||||
test_env.env_root(),
|
||||
|
|
Loading…
Reference in a new issue