mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 23:36:11 +00:00
fix(core): adopt upstream when a dirty worktree is identical to it
A worktree with another machine's snapshot applied stayed BehindDirty forever after the author committed and pushed that work. When the worktree content is byte-identical to the upstream tree, a mixed reset moves the branch without touching any file. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
15df527064
commit
a631d0a90f
3 files changed
+73
-19
No files matched your search
@@ -2,6 +2,7 @@ mod common;
|
||||
use common::*;
|
||||
use grove_core::git::Git;
|
||||
use grove_core::receive::Applied;
|
||||
use grove_core::receive::Received;
|
||||
use grove_core::state::State;
|
||||
use grove_core::sync::{Options, sync_repo};
|
||||
use std::fs;
|
||||
@@ -70,20 +71,36 @@ fn two_machines_converge_without_manual_git() {
|
||||
assert_eq!(fs::read_to_string(db.join("a.txt")).unwrap(), "1\nwork\n");
|
||||
assert!(db.join("scratch.txt").exists());
|
||||
|
||||
// A commits and pushes by hand; B (now dirty from the applied WIP) must not be touched.
|
||||
// A commits and pushes by hand. B's applied copy is byte-identical to that commit, so B
|
||||
// adopts it (mixed reset, no file touched) and ends clean.
|
||||
ga.run(&["add", "-A"]).unwrap();
|
||||
ga.run(&["commit", "-qm", "work"]).unwrap();
|
||||
ga.run(&["push", "-q"]).unwrap();
|
||||
let rb2 = sync_repo(&db, &opts("B", "t3")).unwrap();
|
||||
assert_eq!(rb2.worktrees[0].state, State::BehindDirty);
|
||||
assert_eq!(rb2.worktrees[0].state, State::Synced);
|
||||
assert!(matches!(
|
||||
rb2.worktrees[0].received,
|
||||
Some(Received::FastForwarded { .. })
|
||||
));
|
||||
assert_eq!(fs::read_to_string(db.join("a.txt")).unwrap(), "1\nwork\n");
|
||||
assert!(
|
||||
Git::new(&db)
|
||||
.run(&["status", "--porcelain"])
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
);
|
||||
|
||||
// Discarding B's applied copy makes it clean; the next sync fast-forwards it.
|
||||
Git::new(&db).run(&["checkout", "-q", "--", "."]).unwrap();
|
||||
fs::remove_file(db.join("scratch.txt")).unwrap();
|
||||
// If B has its own extra edit when the next upstream commit arrives, it must not be touched.
|
||||
fs::write(da.join("a.txt"), "1\nwork\nmore\n").unwrap();
|
||||
ga.run(&["commit", "-qam", "more"]).unwrap();
|
||||
ga.run(&["push", "-q"]).unwrap();
|
||||
fs::write(db.join("a.txt"), "1\nwork\nlocal\n").unwrap();
|
||||
let rb3 = sync_repo(&db, &opts("B", "t4")).unwrap();
|
||||
assert_eq!(rb3.worktrees[0].state, State::Synced);
|
||||
assert!(db.join("scratch.txt").exists());
|
||||
assert_eq!(rb3.worktrees[0].state, State::BehindDirty);
|
||||
assert_eq!(
|
||||
fs::read_to_string(db.join("a.txt")).unwrap(),
|
||||
"1\nwork\nlocal\n"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user