Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ transport-adjacent. The rest, imperatively:
away and retry. Merging into an unborn branch and the conflict stop of a merge into a private branch are not guarded.
- **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.
or abort the in-progress op first. A push into a repo with a stopped op is
refused for that repo's checked-out branch (other branches still accept it).
- **A `sc work`/`ws` session is the only sanctioned ephemeral+persistent mix:**
temp checkouts are removed on teardown; durable writes go only through the
normal commit path.
Expand Down
13 changes: 6 additions & 7 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,12 @@ scale-&-reach horizon):
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
with a stopped merge/pick reproduces the P19-I1 discard shape via a
remote writer (the stopped rebase has its moved-tip backstop;
merge/pick completion does not). Pre-existing since P6/P12; flagged at
the P21 final review as the one gap outside the policy-op class.
- **In-progress guard for the RECEIVING repo on push — fixed.**
`LocalTransport::update_ref` (so `sc push` to a local path and the wire
`UpdateRef`) refuses to move the receiving repo's checked-out branch while a
merge, cherry-pick or rebase is stopped there (`MergeInProgress` & co.), so
the completing commit cannot silently drop a pushed commit. Other branches
are unaffected.
- **Sparse-gate the conflict helper's non-marker writes (P24 boundary).**
`Repo::materialize_conflict_state` gates conflict *markers* against the
sparse spec but not its `to_encrypt`/sidecar write loops — so an
Expand Down
124 changes: 123 additions & 1 deletion crates/repo/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,28 @@ impl Transport for LocalTransport {
// unlocked, so the ref may have moved since (two concurrent pushes).
let current = crate::refs::read_branch_tip(&self.layout, branch)?;
if current.as_ref() == Some(id) {
return Ok(()); // already there — idempotent
return Ok(()); // already there — idempotent, nothing moves
}
// A stopped merge, cherry-pick or rebase here is completed against the
// checked-out branch's tip: moving that tip from underneath it would
// make the completing commit silently drop what was pushed (the P19-I1
// discard shape, reached by a remote writer). Refuse before any
// write; other branches are unaffected. HEAD is read only when an op
// is stopped, and a failure to read it then fails closed: the op's
// state exists, so a push must not guess which branch it belongs to.
let stopped = if crate::merge_state::in_progress(&self.layout) {
Some(Error::MergeInProgress)
} else if crate::pick_state::in_progress(&self.layout) {
Some(Error::PickInProgress)
} else if crate::rebase_state::in_progress(&self.layout) {
Some(Error::RebaseInProgress)
} else {
None
};
if let Some(err) = stopped {
if crate::refs::current_branch(&self.layout)? == branch {
return Err(err);
}
}
if current.as_ref() != expected_old {
return Err(Error::NonFastForward);
Expand Down Expand Up @@ -1096,4 +1117,105 @@ mod tests {
assert_eq!(by_id_reply_cap(64 * MIB), 64 * MIB);
assert_eq!(by_id_reply_cap(16 << 30), 512 * MIB);
}

/// A repo with a stopped merge, pick or rebase is completed against its
/// checked-out branch's tip. A push moving that tip would make the
/// completing commit drop the pushed work, so it is refused (other
/// branches are untouched), and allowed again once the op is over.
#[test]
fn update_ref_refuses_the_checked_out_branch_during_a_stopped_op() {
let root = std::env::temp_dir().join(format!("scl-xport-stopped-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&root);
std::fs::create_dir_all(&root).unwrap();
let repo = crate::repo::Repo::init(&root).unwrap();
std::fs::write(root.join("x.txt"), b"a\nb\nc\n").unwrap();
repo.commit("t", "base").unwrap();
repo.branch("other").unwrap();
std::fs::write(root.join("x.txt"), b"a\nMAIN\nc\n").unwrap();
let main_tip = repo.commit("t", "main").unwrap();
repo.switch("other").unwrap();
std::fs::write(root.join("x.txt"), b"a\nOTHER\nc\n").unwrap();
repo.commit("t", "other").unwrap();
repo.switch("main").unwrap();
assert!(repo.merge("other", "t").is_err(), "setup: a stopped merge");
assert!(repo.merge_in_progress());
// The pushed-to repo's own process has exited (a Repo handle holds the
// single-writer lock the transport needs).
let layout = repo.layout().clone();
drop(repo);

let t = LocalTransport::open(&root).unwrap();
let pushed = Object::blob(b"pushed".to_vec()).id();
// The checked-out branch: refused, and nothing moved.
assert!(matches!(
t.update_ref("main", &pushed, Some(&main_tip)),
Err(Error::MergeInProgress)
));
assert_eq!(
crate::refs::read_branch_tip(&layout, "main").unwrap(),
Some(main_tip)
);
// A retry of a push that already landed moves nothing: still accepted.
t.update_ref("main", &main_tip, None).unwrap();
// An unreadable HEAD with a stopped op fails closed, not open.
let head_path = layout.head_path();
let head_text = std::fs::read(&head_path).unwrap();
std::fs::remove_file(&head_path).unwrap();
assert!(
t.update_ref("main", &pushed, Some(&main_tip)).is_err(),
"a push must not guess the checked-out branch while an op is stopped"
);
assert_eq!(
crate::refs::read_branch_tip(&layout, "main").unwrap(),
Some(main_tip)
);
std::fs::write(&head_path, head_text).unwrap();
// A branch that is not checked out is not in the way.
t.update_ref("elsewhere", &pushed, None).unwrap();
assert_eq!(
crate::refs::read_branch_tip(&layout, "elsewhere").unwrap(),
Some(pushed)
);
// Once the merge is over the push lands.
drop(t);
let repo = crate::repo::Repo::open(&root).unwrap();
repo.merge_abort().unwrap();
drop(repo);
let t = LocalTransport::open(&root).unwrap();
t.update_ref("main", &pushed, Some(&main_tip)).unwrap();
drop(t);
std::fs::remove_dir_all(&root).unwrap();
assert!(!root.exists());
}

/// The same receiving-side refusal for a stopped cherry-pick.
#[test]
fn update_ref_refuses_the_checked_out_branch_during_a_stopped_pick() {
let root = std::env::temp_dir().join(format!("scl-xport-pick-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&root);
std::fs::create_dir_all(&root).unwrap();
let repo = crate::repo::Repo::init(&root).unwrap();
std::fs::write(root.join("x.txt"), b"a\nb\nc\n").unwrap();
repo.commit("t", "base").unwrap();
repo.branch("other").unwrap();
std::fs::write(root.join("x.txt"), b"a\nMAIN\nc\n").unwrap();
let main_tip = repo.commit("t", "main").unwrap();
repo.switch("other").unwrap();
std::fs::write(root.join("x.txt"), b"a\nOTHER\nc\n").unwrap();
repo.commit("t", "other").unwrap();
repo.switch("main").unwrap();
assert!(repo.cherry_pick("other", "t", None, None).is_err());
assert!(repo.pick_in_progress());
drop(repo);

let t = LocalTransport::open(&root).unwrap();
let pushed = Object::blob(b"pushed".to_vec()).id();
assert!(matches!(
t.update_ref("main", &pushed, Some(&main_tip)),
Err(Error::PickInProgress)
));
drop(t);
std::fs::remove_dir_all(&root).unwrap();
assert!(!root.exists());
}
}
Loading