ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: clean up .git directory if "jj git clone --colocate" failed

This commit is contained in:
Yuya Nishihara 2023-08-09 12:27:48 +09:00
parent 6625e91a4b
commit 97b6eb2684
2 changed files with 13 additions and 11 deletions

View file

@ -1,11 +1,11 @@
use std::collections::HashSet;
use std::fs;
use std::io::{Read, Write};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::Mutex;
use std::time::Instant;
use std::{fs, io};
use clap::{ArgGroup, Subcommand};
use itertools::Itertools;
@ -418,13 +418,17 @@ fn cmd_git_clone(
if clone_result.is_err() {
// Canonicalize because fs::remove_dir_all() doesn't seem to like e.g.
// `/some/path/.`
if let Err(err) = fs::remove_dir_all(canonical_wc_path.join(".jj")).and_then(|_| {
if !wc_path_existed {
fs::remove_dir(&canonical_wc_path)
} else {
Ok(())
let clean_up_dirs = || -> io::Result<()> {
fs::remove_dir_all(canonical_wc_path.join(".jj"))?;
if args.colocate {
fs::remove_dir_all(canonical_wc_path.join(".git"))?;
}
}) {
if !wc_path_existed {
fs::remove_dir(&canonical_wc_path)?;
}
Ok(())
};
if let Err(err) = clean_up_dirs() {
writeln!(
ui.warning(),
"Failed to clean up {}: {}",

View file

@ -219,11 +219,9 @@ fn test_git_clone_colocate() {
Fetching into new repo in "$TEST_ENV/failed"
"###);
insta::assert_snapshot!(stderr, @r###"
Failed to clean up $TEST_ENV/failed: Directory not empty (os error 39)
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();
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();
@ -243,7 +241,7 @@ fn test_git_clone_colocate() {
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(".git").exists());
assert!(!test_env.env_root().join("failed").join(".jj").exists());
// Failed clone (if attempted) shouldn't remove the existing workspace