fix(core): clone rolls back what it created and refuses a non-empty directory

- failure after the clone step removes the .bare and worktree dirs it made
- a directory it created is removed once the busy marker is gone
- if cleanup fails, .grove-stage makes the daemon report the repo as stalled
- git clone gets -- before url and path

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5.5 committed 2026-11-16 18:54:12 +01:00
1 parent f1509c3d65
commit fdc5a8f5a6
2 files changed
+176 -2

No files matched your search

+55
View File
@@ -74,3 +74,58 @@ fn registry_roundtrip_and_upsert() {
assert_eq!(r.repos[0].group, "a");
assert_eq!(Registry::parse(&r.to_text()).unwrap(), r);
}
fn remote_with_main(base: &std::path::Path) -> String {
let remote = base.join("r.git");
Git::new(base)
.run(&[
"init",
"-q",
"--bare",
"-b",
"main",
remote.to_str().unwrap(),
])
.unwrap();
let a = base.join("A/g/proj");
init_bare_layout(&a, remote.to_str().unwrap()).unwrap();
push_initial(&a, &[]).unwrap();
remote.to_str().unwrap().to_string()
}
#[test]
fn clone_failing_after_the_clone_step_removes_what_it_created() {
let base = tmpdir("regfail");
let url = remote_with_main(&base);
// A directory the clone creates itself: gone afterwards, no marker left.
let fresh = base.join("B/g/fresh");
assert!(clone_bare_layout_failing_after_clone(&url, &fresh, &[]).is_err());
assert!(!fresh.exists());
// A pre-existing empty directory stays, empty and without markers.
let empty = base.join("B/g/empty");
fs::create_dir_all(&empty).unwrap();
assert!(clone_bare_layout_failing_after_clone(&url, &empty, &[]).is_err());
assert_eq!(fs::read_dir(&empty).unwrap().count(), 0);
// The retry works: nothing half-built is in the way.
clone_bare_layout(&url, &fresh, &[]).unwrap();
assert!(fresh.join(".bare").is_dir() && !fresh.join(".grove-busy").exists());
fs::remove_dir_all(&base).unwrap();
}
#[test]
fn clone_refuses_a_non_empty_directory_and_touches_nothing() {
let base = tmpdir("regkeep");
let url = remote_with_main(&base);
let plain = base.join("B/g/plain");
fs::create_dir_all(plain.join(".git")).unwrap();
fs::write(plain.join("keep.txt"), "mine").unwrap();
let e = clone_bare_layout(&url, &plain, &[]).unwrap_err();
assert!(e.to_string().contains("not empty"), "{e}");
assert_eq!(fs::read_to_string(plain.join("keep.txt")).unwrap(), "mine");
assert!(plain.join(".git").is_dir() && !plain.join(".bare").exists());
assert!(!plain.join(".grove-busy").exists());
fs::remove_dir_all(&base).unwrap();
}