From 5285e9b17ab177d5dc4694b5c6ee75e9ca684951 Mon Sep 17 00:00:00 2001 From: Toni Bergholm Date: Mon, 19 Oct 2026 09:03:06 +0300 Subject: [PATCH 1/6] fix(repo): keep a stop's leftover .theirs sidecar out of the completing commit Resolving a binary conflict by editing the file and leaving .theirs on disk committed the sidecar as a tracked file (merge, cherry-pick and rebase completion). The completion snapshot now leaves out the sidecars the stop recorded unless a root tracks the path, and the commit removes them. Co-Authored-By: Claude Sonnet 5.5 --- CLAUDE.md | 2 +- ROADMAP.md | 11 +++---- crates/repo/src/replay.rs | 64 +++++++++++++++++++++++++++++++++++++++ crates/repo/src/repo.rs | 48 +++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 7 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 0c47796b..25f07108 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -244,7 +244,7 @@ transport-adjacent. The rest, imperatively: and abort removes listed paths the restored tree does not track as plain files. The `.theirs` sidecars it wrote are listed apart in `.sc/CONFLICT_SIDECARS`; abort, `rebase --continue` and `sc resolve` remove only those, never a `.theirs` file the stop - did not write. + did not write; the completing commit leaves them out of the tree and removes them. - **Every ref-moving or commit-creating op (including all secret/protect policy ops) is guarded against an in-progress merge/pick/rebase** — finish or abort the in-progress op first. diff --git a/ROADMAP.md b/ROADMAP.md index 318fc337..b57cadc0 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -725,12 +725,11 @@ scale-&-reach horizon): rebase abort, `rebase --continue` and `sc resolve` unlink only those (and never a path the restored tree tracks), so an untracked user `foo.txt.theirs` survives whatever the conflict kind. -- **Completion commits a leftover `.theirs` sidecar.** A binary conflict's - `.theirs` is working-tree scratch, but if the user resolves by editing - `` (not `sc resolve`) and leaves the sidecar, the completing `sc commit` - or `rebase --continue` snapshots it as a tracked file (reproduced on main with - a merge). Exclude recorded sidecars (`.sc/CONFLICT_SIDECARS`) that no input - root tracks from the completion snapshot. +- **Completion commits a leftover `.theirs` sidecar — fixed.** The completion + snapshot (`sc commit`, `rebase --continue`) leaves out the sidecars the stop + recorded in `.sc/CONFLICT_SIDECARS` unless a root tracks that path, and the + commit then removes them; resolving by hand-editing no longer commits the + scratch file. - **In-progress guard for the RECEIVING repo on push.** `LocalTransport::update_ref` moves a branch tip with only a CAS/ff gate and no in-progress check on the receiving side — a push into a repo diff --git a/crates/repo/src/replay.rs b/crates/repo/src/replay.rs index 6d236d1f..528814e6 100644 --- a/crates/repo/src/replay.rs +++ b/crates/repo/src/replay.rs @@ -3123,6 +3123,70 @@ mod tests { remove_root(&root); } + /// Two branches that conflict as binary on `bin.dat`, `main` checked out. + fn binary_conflict(name: &str) -> (std::path::PathBuf, Repo) { + let root = tmp_root(name); + let repo = Repo::init(&root).unwrap(); + std::fs::write(root.join("bin.dat"), b"\xff\xfebase\n").unwrap(); + repo.commit("me", "base").unwrap(); + repo.branch("work").unwrap(); + std::fs::write(root.join("bin.dat"), b"\xff\xfeOURS\n").unwrap(); + repo.commit("me", "main").unwrap(); + repo.switch("work").unwrap(); + std::fs::write(root.join("bin.dat"), b"\xff\xfeTHEIRS\n").unwrap(); + repo.commit("me", "work").unwrap(); + repo.switch("main").unwrap(); + (root, repo) + } + + /// Resolving by editing the file and leaving the sidecar on disk must not + /// commit the sidecar, and the next commit must not take it either. + #[test] + fn a_merge_commit_leaves_the_leftover_sidecar_out_and_removes_it() { + let (root, repo) = binary_conflict("sweep-commit-merge"); + repo.merge("work", "me").unwrap_err(); + assert!(root.join("bin.dat.theirs").exists(), "setup: sidecar"); + std::fs::write(root.join("bin.dat"), b"\xff\xferesolved\n").unwrap(); + repo.commit("me", "merge").unwrap(); + assert!(!repo.tracked_paths().unwrap().contains("bin.dat.theirs")); + assert!(!root.join("bin.dat.theirs").exists(), "scratch removed"); + std::fs::write(root.join("other.txt"), b"x\n").unwrap(); + repo.commit("me", "next").unwrap(); + assert!(!repo.tracked_paths().unwrap().contains("bin.dat.theirs")); + drop(repo); + remove_root(&root); + } + + #[test] + fn a_pick_commit_leaves_the_leftover_sidecar_out() { + let (root, repo) = binary_conflict("sweep-commit-pick"); + repo.cherry_pick("work", "me", None, None).unwrap_err(); + assert!(root.join("bin.dat.theirs").exists(), "setup: sidecar"); + std::fs::write(root.join("bin.dat"), b"\xff\xferesolved\n").unwrap(); + repo.commit("me", "pick").unwrap(); + assert!(!repo.tracked_paths().unwrap().contains("bin.dat.theirs")); + assert!(!root.join("bin.dat.theirs").exists()); + drop(repo); + remove_root(&root); + } + + #[test] + fn rebase_continue_leaves_the_leftover_sidecar_out() { + let (root, repo) = binary_conflict("sweep-commit-rebase"); + repo.switch("work").unwrap(); + assert!(matches!( + repo.rebase("main", "me", None).unwrap(), + RebaseResult::Stopped { .. } + )); + assert!(root.join("bin.dat.theirs").exists(), "setup: sidecar"); + std::fs::write(root.join("bin.dat"), b"\xff\xferesolved\n").unwrap(); + repo.rebase_continue("me", None).unwrap(); + assert!(!repo.tracked_paths().unwrap().contains("bin.dat.theirs")); + assert!(!root.join("bin.dat.theirs").exists()); + drop(repo); + remove_root(&root); + } + #[test] fn merge_abort_keeps_a_user_theirs_file_beside_a_text_conflict() { let (root, repo) = text_conflict_with_user_theirs_file("sweep-merge-abort"); diff --git a/crates/repo/src/repo.rs b/crates/repo/src/repo.rs index d76bdcd8..f07627dc 100644 --- a/crates/repo/src/repo.rs +++ b/crates/repo/src/repo.rs @@ -401,6 +401,13 @@ impl Repo { } }; + // A sidecar the stop wrote is working-tree scratch: it must reach + // neither the scanner nor the tree, whether or not the user resolved by + // hand and left it on disk. A tracked path of the same name is the + // user's own file and stays. + let files = + self.without_recorded_sidecars(files, &[tip, merge_head, pick_head], decided_root)?; + // Single pass: split protected files (capturing each rule's recipients, so // the encryption loop needn't look the prefix up again) from plaintext. let mut plain: Vec<(String, Vec, scl_core::FileMode)> = Vec::new(); @@ -900,6 +907,12 @@ impl Repo { } }; refs::write_branch_tip(&self.layout, &head, &id)?; + // The stop's `.theirs` sidecars were left out of the commit (see + // `snapshot_files`); remove them now, or the next commit would take + // them. Best effort: the ref already moved. + if let Ok(snap) = self.snapshot(&id) { + let _ = self.remove_conflict_sidecars(&[snap.root]); + } crate::merge_state::clear(&self.layout)?; crate::pick_state::clear(&self.layout)?; // The ref moved: persist the cache best-effort (no-op in the pick arm, @@ -1931,6 +1944,41 @@ impl Repo { Ok(()) } + /// Drop from `files` the sidecars the stop recorded writing + /// (`conflict_plaintext::read_sidecars`) that no snapshot in `snapshots` + /// nor `decided_root` tracks. No record, no change. + fn without_recorded_sidecars( + &self, + files: Vec<(String, Vec, scl_core::FileMode)>, + snapshots: &[Option], + decided_root: Option, + ) -> Result, scl_core::FileMode)>> { + let sidecars = crate::conflict_plaintext::read_sidecars(&self.layout)?; + if sidecars.is_empty() { + return Ok(files); + } + let mut roots: Vec = decided_root.into_iter().collect(); + for id in snapshots.iter().flatten() { + roots.push(self.snapshot(id)?.root); + } + let partial = self.promisor()?.is_some(); + let store_arc = self.vfs.store(); + let mut store = store_arc.lock().unwrap(); + let mut kept = Vec::with_capacity(files.len()); + for file in files { + let scratch = sidecars.contains(&file.0) + && !roots.iter().any(|root| { + // A failed lookup counts as tracked: keep the file. + worktree::tree_entry_at(&mut store, *root, &file.0, partial) + .map_or(true, |e| e.is_some()) + }); + if !scratch { + kept.push(file); + } + } + Ok(kept) + } + /// Remove the `.theirs` sidecars the stop recorded writing /// (`conflict_plaintext::read_sidecars`), except a file any of `roots` /// tracks: that one is the user's own and was just restored. A `.theirs` From 280ca91d1d01c624affa3114736a3c67139f642e Mon Sep 17 00:00:00 2001 From: Toni Bergholm Date: Mon, 19 Oct 2026 09:10:49 +0300 Subject: [PATCH 2/6] fix(repo): ignore a sidecar record when no operation is in progress A record left by a crash mid-stop would otherwise exclude, then delete, a file the user later made at that path on an ordinary commit. Co-Authored-By: Claude Sonnet 5.5 --- crates/repo/src/replay.rs | 17 +++++++++++++++++ crates/repo/src/repo.rs | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/repo/src/replay.rs b/crates/repo/src/replay.rs index 528814e6..85f8eea6 100644 --- a/crates/repo/src/replay.rs +++ b/crates/repo/src/replay.rs @@ -3187,6 +3187,23 @@ mod tests { remove_root(&root); } + /// A sidecar record left by a crash mid-stop (no operation in progress) + /// names nothing of ours: an ordinary commit takes a file at that path. + #[test] + fn an_orphan_sidecar_record_does_not_touch_an_ordinary_commit() { + let root = tmp_root("sweep-orphan-record"); + let repo = Repo::init(&root).unwrap(); + std::fs::write(root.join("a.txt"), b"a\n").unwrap(); + repo.commit("me", "base").unwrap(); + crate::conflict_plaintext::write_sidecars(&repo.layout, &["x.theirs".to_string()]).unwrap(); + std::fs::write(root.join("x.theirs"), b"mine\n").unwrap(); + repo.commit("me", "adds x.theirs").unwrap(); + assert!(repo.tracked_paths().unwrap().contains("x.theirs")); + assert_eq!(std::fs::read(root.join("x.theirs")).unwrap(), b"mine\n"); + drop(repo); + remove_root(&root); + } + #[test] fn merge_abort_keeps_a_user_theirs_file_beside_a_text_conflict() { let (root, repo) = text_conflict_with_user_theirs_file("sweep-merge-abort"); diff --git a/crates/repo/src/repo.rs b/crates/repo/src/repo.rs index f07627dc..761be392 100644 --- a/crates/repo/src/repo.rs +++ b/crates/repo/src/repo.rs @@ -1944,6 +1944,16 @@ impl Repo { Ok(()) } + /// The sidecars the in-progress stop recorded writing. A record with no + /// merge, pick or rebase in progress is residue of a crash mid-stop, and + /// names nothing that is ours: it reads as empty. + fn recorded_sidecars(&self) -> Result> { + if self.active_conflict_op()?.is_none() { + return Ok(std::collections::BTreeSet::new()); + } + crate::conflict_plaintext::read_sidecars(&self.layout) + } + /// Drop from `files` the sidecars the stop recorded writing /// (`conflict_plaintext::read_sidecars`) that no snapshot in `snapshots` /// nor `decided_root` tracks. No record, no change. @@ -1953,7 +1963,7 @@ impl Repo { snapshots: &[Option], decided_root: Option, ) -> Result, scl_core::FileMode)>> { - let sidecars = crate::conflict_plaintext::read_sidecars(&self.layout)?; + let sidecars = self.recorded_sidecars()?; if sidecars.is_empty() { return Ok(files); } @@ -1988,7 +1998,7 @@ impl Repo { /// a restore that fails leaves the sidecars to retry. The record is retired /// once swept. pub(crate) fn remove_conflict_sidecars(&self, roots: &[ObjectId]) -> Result<()> { - let sidecars = crate::conflict_plaintext::read_sidecars(&self.layout)?; + let sidecars = self.recorded_sidecars()?; if sidecars.is_empty() { return Ok(()); } From 704a8ab1878afcb323e21523b24bc86f87285d4d Mon Sep 17 00:00:00 2001 From: Toni Bergholm Date: Mon, 19 Oct 2026 09:12:53 +0300 Subject: [PATCH 3/6] fix(repo): scope sidecar filtering to a completion and sweep before the ref moves An ordinary commit, amend or workspace harvest never filters on the record. A sidecar that cannot be removed now fails the completing commit with nothing moved and the record intact, instead of being dropped with the state. Co-Authored-By: Claude Sonnet 5.5 --- crates/repo/src/replay.rs | 27 +++++++++++++++++++++++++++ crates/repo/src/repo.rs | 24 +++++++++++++++--------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/crates/repo/src/replay.rs b/crates/repo/src/replay.rs index 85f8eea6..309f1c94 100644 --- a/crates/repo/src/replay.rs +++ b/crates/repo/src/replay.rs @@ -3157,6 +3157,33 @@ mod tests { remove_root(&root); } + /// A sidecar that cannot be removed fails the completing commit before + /// anything moves; the record survives, and the retry finishes. + #[test] + fn a_completion_whose_sidecar_cannot_be_removed_fails_and_retries() { + let (root, repo) = binary_conflict("sweep-commit-fails"); + let ours = repo.head_tip().unwrap(); + repo.merge("work", "me").unwrap_err(); + std::fs::write(root.join("bin.dat"), b"\xff\xferesolved\n").unwrap(); + std::fs::remove_file(root.join("bin.dat.theirs")).unwrap(); + std::fs::create_dir(root.join("bin.dat.theirs")).unwrap(); + repo.commit("me", "merge").unwrap_err(); + assert_eq!(repo.head_tip().unwrap(), ours, "the ref did not move"); + assert!(repo.merge_in_progress()); + assert!( + crate::conflict_plaintext::read_sidecars(&repo.layout) + .unwrap() + .contains("bin.dat.theirs"), + "the record survives for the retry" + ); + std::fs::remove_dir(root.join("bin.dat.theirs")).unwrap(); + repo.commit("me", "merge").unwrap(); + assert!(!repo.merge_in_progress()); + assert!(!repo.tracked_paths().unwrap().contains("bin.dat.theirs")); + drop(repo); + remove_root(&root); + } + #[test] fn a_pick_commit_leaves_the_leftover_sidecar_out() { let (root, repo) = binary_conflict("sweep-commit-pick"); diff --git a/crates/repo/src/repo.rs b/crates/repo/src/repo.rs index 761be392..10865792 100644 --- a/crates/repo/src/repo.rs +++ b/crates/repo/src/repo.rs @@ -401,12 +401,16 @@ impl Repo { } }; - // A sidecar the stop wrote is working-tree scratch: it must reach - // neither the scanner nor the tree, whether or not the user resolved by + // On a completion only (an ordinary commit, amend or workspace harvest + // has none of these): a sidecar the stop wrote is working-tree scratch, + // so it must reach neither the scanner nor the tree, whether or not the user resolved by // hand and left it on disk. A tracked path of the same name is the // user's own file and stays. - let files = - self.without_recorded_sidecars(files, &[tip, merge_head, pick_head], decided_root)?; + let files = if merge_head.is_some() || pick_head.is_some() || decided_root.is_some() { + self.without_recorded_sidecars(files, &[tip, merge_head, pick_head], decided_root)? + } else { + files + }; // Single pass: split protected files (capturing each rule's recipients, so // the encryption loop needn't look the prefix up again) from plaintext. @@ -906,13 +910,15 @@ impl Repo { id } }; - refs::write_branch_tip(&self.layout, &head, &id)?; // The stop's `.theirs` sidecars were left out of the commit (see - // `snapshot_files`); remove them now, or the next commit would take - // them. Best effort: the ref already moved. - if let Ok(snap) = self.snapshot(&id) { - let _ = self.remove_conflict_sidecars(&[snap.root]); + // `snapshot_files`); remove them before the ref moves, or the next + // commit would take them. A removal failure fails this commit with + // nothing moved and the record intact, so it can be retried. + if merging || picking { + let root = self.snapshot(&id)?.root; + self.remove_conflict_sidecars(&[root])?; } + refs::write_branch_tip(&self.layout, &head, &id)?; crate::merge_state::clear(&self.layout)?; crate::pick_state::clear(&self.layout)?; // The ref moved: persist the cache best-effort (no-op in the pick arm, From 699266dc9f3bb6c48fdf39590ce423eb88b99a54 Mon Sep 17 00:00:00 2001 From: Toni Bergholm Date: Mon, 19 Oct 2026 09:23:10 +0300 Subject: [PATCH 4/6] fix(repo): judge a sidecar's ownership by the decided root, not the inputs A path the merge result deleted stays deleted even if the other side still tracked it; the stop's scratch there is no longer re-added by completion. Co-Authored-By: Claude Sonnet 5.5 --- crates/repo/src/replay.rs | 32 ++++++++++++++++++++++++++++++++ crates/repo/src/repo.rs | 6 ++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/crates/repo/src/replay.rs b/crates/repo/src/replay.rs index 309f1c94..370ab904 100644 --- a/crates/repo/src/replay.rs +++ b/crates/repo/src/replay.rs @@ -3184,6 +3184,38 @@ mod tests { remove_root(&root); } + /// Base and `work` track `bin.dat.theirs`, `main` deletes it, and + /// `bin.dat` conflicts as binary: the stop writes scratch at the path the + /// result no longer tracks. Completion must not re-add it because + /// `work` once tracked it. + #[test] + fn a_path_the_result_deleted_is_not_kept_because_theirs_tracked_it() { + let root = tmp_root("sweep-deleted-by-ours"); + let repo = Repo::init(&root).unwrap(); + std::fs::write(root.join("bin.dat"), b"\xff\xfebase\n").unwrap(); + std::fs::write(root.join("bin.dat.theirs"), b"old\n").unwrap(); + repo.commit("me", "base").unwrap(); + repo.branch("work").unwrap(); + std::fs::remove_file(root.join("bin.dat.theirs")).unwrap(); + std::fs::write(root.join("bin.dat"), b"\xff\xfeOURS\n").unwrap(); + repo.commit("me", "main").unwrap(); + repo.switch("work").unwrap(); + std::fs::write(root.join("bin.dat"), b"\xff\xfeTHEIRS\n").unwrap(); + repo.commit("me", "work").unwrap(); + repo.switch("main").unwrap(); + repo.merge("work", "me").unwrap_err(); + assert!( + root.join("bin.dat.theirs").exists(), + "setup: scratch written" + ); + std::fs::write(root.join("bin.dat"), b"\xff\xferesolved\n").unwrap(); + repo.commit("me", "merge").unwrap(); + assert!(!repo.tracked_paths().unwrap().contains("bin.dat.theirs")); + assert!(!root.join("bin.dat.theirs").exists()); + drop(repo); + remove_root(&root); + } + #[test] fn a_pick_commit_leaves_the_leftover_sidecar_out() { let (root, repo) = binary_conflict("sweep-commit-pick"); diff --git a/crates/repo/src/repo.rs b/crates/repo/src/repo.rs index 10865792..e34e6bf7 100644 --- a/crates/repo/src/repo.rs +++ b/crates/repo/src/repo.rs @@ -407,7 +407,7 @@ impl Repo { // hand and left it on disk. A tracked path of the same name is the // user's own file and stays. let files = if merge_head.is_some() || pick_head.is_some() || decided_root.is_some() { - self.without_recorded_sidecars(files, &[tip, merge_head, pick_head], decided_root)? + self.without_recorded_sidecars(files, &[tip], decided_root)? } else { files }; @@ -1962,7 +1962,9 @@ impl Repo { /// Drop from `files` the sidecars the stop recorded writing /// (`conflict_plaintext::read_sidecars`) that no snapshot in `snapshots` - /// nor `decided_root` tracks. No record, no change. + /// nor `decided_root` tracks. The other side's history does not count: a path + /// the result deleted stays deleted, however the input tracked it. No + /// record, no change. fn without_recorded_sidecars( &self, files: Vec<(String, Vec, scl_core::FileMode)>, From 76d1f5a255310a19daa975776b1c79835440722c Mon Sep 17 00:00:00 2001 From: Toni Bergholm Date: Mon, 19 Oct 2026 09:33:15 +0300 Subject: [PATCH 5/6] docs: record the sidecar-sweep crash window as a known limit Co-Authored-By: Claude Sonnet 5.5 --- ROADMAP.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ROADMAP.md b/ROADMAP.md index b57cadc0..479df47f 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -730,6 +730,10 @@ scale-&-reach horizon): recorded in `.sc/CONFLICT_SIDECARS` unless a root tracks that path, and the commit then removes them; resolving by hand-editing no longer commits the scratch file. + Known limit: the sweep retires the record before it unlinks, so a crash + between the two leaves the scratch file on disk with no record, and a retried + `sc commit` would take it. The opposite order would risk deleting a file the + user recreated at that path; closing both needs a journal. - **In-progress guard for the RECEIVING repo on push.** `LocalTransport::update_ref` moves a branch tip with only a CAS/ff gate and no in-progress check on the receiving side — a push into a repo From c9d3ba9e6dbb940b40fe241dd551ba752021a720 Mon Sep 17 00:00:00 2001 From: Toni Bergholm Date: Mon, 19 Oct 2026 09:35:29 +0300 Subject: [PATCH 6/6] fix(repo): classify a sidecar by the decided root on rebase completion The decided root now takes precedence over the parent when deciding whether a recorded sidecar is the user's, and rebase --continue sweeps against the completed commit. A rebase that deletes a path its target tracks no longer commits the stop's scratch there. Co-Authored-By: Claude Sonnet 5.5 --- crates/repo/src/replay.rs | 39 ++++++++++++++++++++++++++++++++++----- crates/repo/src/repo.rs | 9 +++++++-- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/crates/repo/src/replay.rs b/crates/repo/src/replay.rs index 370ab904..6827ce3e 100644 --- a/crates/repo/src/replay.rs +++ b/crates/repo/src/replay.rs @@ -1212,11 +1212,9 @@ impl Repo { // `merge_abort`'s cleanup): once resolved, they're pure // working-tree litter — never part of the tracked tree, so // `materialize` never touches them itself. - // Not a file any of the trees involved tracks (that one is the - // user's own): see `remove_conflict_sidecars`. - // Not a file the completion's parent tracks (that one is the - // user's own): see `remove_conflict_sidecars`. - self.remove_conflict_sidecars(&[self.snapshot(&st.acc_tip)?.root])?; + // Not a file the completed commit tracks (that one is the user's + // own): see `remove_conflict_sidecars`. + self.remove_conflict_sidecars(&[self.snapshot(&new_tip)?.root])?; // Advance state BEFORE attempting the fold, so an error from the // fold below (on a later commit) leaves a retryable, idempotent // `--continue` rather than losing resumability. `rebase_abort` @@ -3216,6 +3214,37 @@ mod tests { remove_root(&root); } + /// The target tracks `bin.dat.theirs`, the replayed commit deletes it and + /// conflicts with the target on `bin.dat`. The stop writes scratch at a + /// path the result no longer tracks; the target's old tracking of it must + /// not make completion commit the scratch. + #[test] + fn a_rebase_that_deletes_a_target_tracked_path_does_not_commit_the_scratch() { + let root = tmp_root("sweep-rebase-deleted"); + let repo = Repo::init(&root).unwrap(); + std::fs::write(root.join("bin.dat"), b"\xff\xfebase\n").unwrap(); + std::fs::write(root.join("bin.dat.theirs"), b"keep\n").unwrap(); + repo.commit("me", "base").unwrap(); + repo.branch("work").unwrap(); + std::fs::write(root.join("bin.dat"), b"\xff\xfeMAIN\n").unwrap(); + repo.commit("me", "main").unwrap(); + repo.switch("work").unwrap(); + std::fs::remove_file(root.join("bin.dat.theirs")).unwrap(); + std::fs::write(root.join("bin.dat"), b"\xff\xfeWORK\n").unwrap(); + repo.commit("me", "work").unwrap(); + assert!(matches!( + repo.rebase("main", "me", None).unwrap(), + RebaseResult::Stopped { .. } + )); + assert!(root.join("bin.dat.theirs").exists(), "setup: scratch"); + std::fs::write(root.join("bin.dat"), b"\xff\xferesolved\n").unwrap(); + repo.rebase_continue("me", None).unwrap(); + assert!(!repo.tracked_paths().unwrap().contains("bin.dat.theirs")); + assert!(!root.join("bin.dat.theirs").exists()); + drop(repo); + remove_root(&root); + } + #[test] fn a_pick_commit_leaves_the_leftover_sidecar_out() { let (root, repo) = binary_conflict("sweep-commit-pick"); diff --git a/crates/repo/src/repo.rs b/crates/repo/src/repo.rs index e34e6bf7..37b452cc 100644 --- a/crates/repo/src/repo.rs +++ b/crates/repo/src/repo.rs @@ -1975,9 +1975,14 @@ impl Repo { if sidecars.is_empty() { return Ok(files); } + // The decided root is the operation's outcome and takes precedence: a + // parent that tracks the path says nothing about a result that deleted + // it. Without one, the tip is the only owner. let mut roots: Vec = decided_root.into_iter().collect(); - for id in snapshots.iter().flatten() { - roots.push(self.snapshot(id)?.root); + if roots.is_empty() { + for id in snapshots.iter().flatten() { + roots.push(self.snapshot(id)?.root); + } } let partial = self.promisor()?.is_some(); let store_arc = self.vfs.store();