feat: resolve diverged worktrees, status --plan, snapshot size limit

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5.5 committed 2026-11-16 13:25:22 +01:00
1 parent b86342b1d0
commit 398b959ffe
13 files changed
+443 -17

No files matched your search

+7
View File
@@ -35,6 +35,13 @@ fn new_repo_pushes_and_a_fresh_machine_clones_it_into_the_bare_layout() {
let b = base.join("B/g/proj");
let made = clone_bare_layout(url, &b, &[]).unwrap();
assert_eq!(made.len(), 1);
assert_eq!(
Git::new(b.join("main"))
.run(&["rev-parse", "--abbrev-ref", "@{upstream}"])
.unwrap(),
"origin/main",
"cloned worktrees must track their remote branch"
);
assert!(b.join("main/.git").exists() && b.join(".bare").is_dir());
assert_eq!(
Git::new(b.join("main"))
+107
View File
@@ -0,0 +1,107 @@
mod common;
use common::*;
use grove_core::git::Git;
use grove_core::inspect::state;
use grove_core::registry::{clone_bare_layout, init_bare_layout, push_initial};
use grove_core::resolve::{Choice, resolve};
use grove_core::state::State;
use std::fs;
use std::path::PathBuf;
/// Two machines on the bare layout, both committed on main: diverged on B.
fn diverged() -> (PathBuf, PathBuf, PathBuf) {
let base = tmpdir("resolve");
let remote = base.join("r.git");
Git::new(&base)
.run(&[
"init",
"-q",
"--bare",
"-b",
"main",
remote.to_str().unwrap(),
])
.unwrap();
let url = remote.to_str().unwrap().to_string();
let a = base.join("A");
init_bare_layout(&a, &url).unwrap();
push_initial(&a, &[]).unwrap();
let b = base.join("B");
clone_bare_layout(&url, &b, &[]).unwrap();
for (root, who) in [(&a, "a"), (&b, "b")] {
let g = Git::new(root.join("main"));
g.run(&["config", "user.email", "t@t"]).unwrap();
g.run(&["config", "user.name", "t"]).unwrap();
let _ = who;
}
// A commits and pushes; B commits locally and fetches.
let ga = Git::new(a.join("main"));
fs::write(a.join("main/f.txt"), "from A\n").unwrap();
ga.run(&["add", "-A"]).unwrap();
ga.run(&["commit", "-qm", "a"]).unwrap();
ga.run(&["push", "-q"]).unwrap();
let gb = Git::new(b.join("main"));
fs::write(b.join("main/g.txt"), "from B\n").unwrap();
gb.run(&["add", "-A"]).unwrap();
gb.run(&["commit", "-qm", "b"]).unwrap();
gb.run(&["fetch", "-q"]).unwrap();
assert_eq!(state(&b.join("main")), State::Diverged);
(base, a, b)
}
#[test]
fn take_remote_discards_local_commits_but_keeps_a_backup_ref() {
let (_base, _a, b) = diverged();
let wt = b.join("main");
let msg = resolve(&wt, "B", "s1", &Choice::TakeRemote).unwrap();
assert!(msg.contains("backup"));
let g = Git::new(&wt);
assert_eq!(state(&wt), State::Synced);
assert!(wt.join("f.txt").exists() && !wt.join("g.txt").exists());
let backup = g
.run(&["rev-parse", "refs/sync-backup/B/s1/resolve-local/main"])
.unwrap();
assert!(g.run(&["show", &format!("{backup}:g.txt")]).is_ok());
}
#[test]
fn save_as_branch_keeps_the_local_work_in_its_own_worktree() {
let (_base, _a, b) = diverged();
let wt = b.join("main");
resolve(&wt, "B", "s1", &Choice::SaveAsBranch("b-work".into())).unwrap();
assert_eq!(state(&wt), State::Synced);
assert!(!wt.join("g.txt").exists());
assert_eq!(
fs::read_to_string(b.join("b-work/g.txt")).unwrap(),
"from B\n"
);
}
#[test]
fn keep_local_force_pushes_with_lease_and_backs_up_the_remote_tip() {
let (_base, a, b) = diverged();
let wt = b.join("main");
resolve(&wt, "B", "s1", &Choice::KeepLocal).unwrap();
assert_eq!(state(&wt), State::Synced);
let ga = Git::new(a.join("main"));
ga.run(&["fetch", "-q"]).unwrap();
let remote_tree = ga.run(&["ls-tree", "--name-only", "origin/main"]).unwrap();
assert!(remote_tree.contains("g.txt") && !remote_tree.contains("f.txt"));
let g = Git::new(&wt);
assert!(
g.run(&["rev-parse", "refs/sync-backup/B/s1/resolve-remote/main"])
.is_ok()
);
}
#[test]
fn refuses_when_not_diverged_or_when_the_worktree_is_dirty() {
let (_base, _a, b) = diverged();
let wt = b.join("main");
fs::write(wt.join("wip.txt"), "x\n").unwrap();
let e = resolve(&wt, "B", "s", &Choice::TakeRemote)
.unwrap_err()
.to_string();
assert!(e.contains("uncommitted"), "{e}");
assert!(wt.join("wip.txt").exists() && wt.join("g.txt").exists());
}
+43
View File
@@ -0,0 +1,43 @@
//! Own test binary: the limit is process-wide.
mod common;
use common::*;
use grove_core::git::Git;
use grove_core::snapshot::{Outcome, set_max_file_bytes, take};
use std::fs;
#[test]
fn oversized_changes_are_left_out_but_small_ones_and_head_content_stay() {
let base = tmpdir("size");
let g = init(&base.join("p"));
commit(&g, "tracked.bin", "old\n");
set_max_file_bytes(1000);
let p = base.join("p");
fs::write(p.join("small.txt"), "ok\n").unwrap();
fs::write(p.join("big.bin"), vec![b'x'; 5000]).unwrap(); // untracked, too big
fs::write(p.join("tracked.bin"), vec![b'y'; 5000]).unwrap(); // tracked, modified, too big
let Outcome::Created(s) = take(&p, "A", "t").unwrap() else {
panic!("expected a snapshot")
};
let mut skipped = s.skipped.clone();
skipped.sort();
assert_eq!(skipped, ["big.bin", "tracked.bin"]);
let show = |f: &str| Git::new(&p).run(&["show", &format!("{}:{f}", s.commit)]);
assert_eq!(show("small.txt").unwrap(), "ok");
assert!(
show("big.bin").is_err(),
"big untracked file must not be in the snapshot"
);
assert_eq!(
show("tracked.bin").unwrap(),
"old",
"tracked file keeps its HEAD content"
);
// The user's real index and files are untouched.
assert_eq!(fs::read(p.join("big.bin")).unwrap().len(), 5000);
assert!(
Git::new(&p)
.run(&["status", "--porcelain"])
.unwrap()
.contains("big.bin")
);
}