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
10 changes: 5 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ the project tree if desired.

## Capability map (what's built, by phase)

All 36 phases, P37a, P37b-i, P37b-ii, P37c-ii and P37c-iii are built and tested. One line of current fact per phase; the
All 36 phases, P37a, P37b-i, P37b-ii and P37c are built and tested. One line of current fact per phase; the
authoritative rationale and full semantics live in the linked ADR, the design
in `ARCHITECTURE.md`. The old per-phase narrative log this table replaced is
archived verbatim at `docs/archive/claude-md-phase-log-2026-07.md` — do not
Expand Down Expand Up @@ -153,7 +153,7 @@ the code, those win.
| P36 | Bucket WAL remotes (sc+wal://, sc+s3://): immutable packs + CAS'd manifest, checkpoints + log-tail cold start, bucket-backed `sc serve --store` with disposable instances | [0046](docs/adr/0046-wal-bucket-remotes.md) |
| P37a | Want-by-id fetch: batched `GetObjects` verb (wire v5), opt-in `.sc/promisor-lazy`, `sc cat <ref>:<path>` fills only the absent trees and blob on its path; `Store::get` stays network-free; sealed objects refused by kind; sparse widen and the lifted P27 refusals are P37b | [0047](docs/adr/0047-want-by-id-fetch-and-gap-fill.md) |
| P37b-i | Presence-based partial clones: push, verify and gc walk what the store holds (`reachable_objects_partial`), not the fetch filter; push checks every gap id against the destination before sending; a view gap fails with `GapInView` before any write (preflight at the top of `materialize`, plus `undo` and `sparse set`); a partial clone fetches from its origin only. 37b-ii: on a lazy, online clone `ensure_view` fills the view closure by id before switch, fast-forward, undo and `sparse set`, `sparse set` may widen past the filter, a by-id reply is capped at `min(--max-pack-size, 512 MiB)` and a refused batch is split. | [0048](docs/adr/0048-presence-based-partial-clones.md) |
| P37c-ii, P37c-iii | Merge on a partial clone: a tree-recursive engine (`merge_trees`) carries a subtree by id when the sides agree and no protection rule applies, reads only where they differ or a rule intersects, and on a lazy, online clone fills what it asks for by id outside the store lock (a non-lazy clone gets the gap error with `sc backfill <path>`); a carried protected subtree keeps the complete input wrap union; a conflict inside the view is marked and resolved like on a full clone (`sc conflicts`/`sc resolve`/`merge --abort`/`sc commit`; the out-of-view part is grafted from the decided root), while a conflict outside the view, or a result that must be sealed outside it, is refused before any ref, merge-state or working-tree change (fetched objects stay). A subtree identical on all three sides is carried even under a protection rule. Mode-only edits now merge and a file/directory collision fails before any write, on full clones too. Cherry-pick/rebase are next | [0049](docs/adr/0049-merge-on-partial-clones.md) |
| P37c | Merge, cherry-pick and rebase on a partial clone: a tree-recursive engine (`merge_trees`) carries a subtree by id when the sides agree and no protection rule applies, reads only where they differ or a rule intersects, and on a lazy, online clone fills what it asks for by id outside the store lock (a non-lazy clone gets the gap error with `sc backfill <path>`); a carried protected subtree keeps the complete input wrap union; a conflict inside the view is marked and resolved like on a full clone (`sc conflicts`/`sc resolve`/`merge --abort`/`sc commit`; the out-of-view part is grafted from the decided root), while a conflict outside the view, or a result that must be sealed outside it, is refused before any ref, merge-state or working-tree change (fetched objects stay). A subtree identical on all three sides is carried even under a protection rule. Cherry-pick and rebase use the same engine (`replay_commit`): the fold's accumulator may hold absent subtrees, the view is filled before the final write, and a stopped pick or rebase keeps its carried subtrees in the decided root. Mode-only edits now merge and a file/directory collision fails before any write, on full clones too. Sessions are undecided | [0049](docs/adr/0049-merge-on-partial-clones.md) |

## Standing boundaries & gotchas

Expand All @@ -169,10 +169,10 @@ transport-adjacent. The rest, imperatively:
renderer has five typed repository commands, no general filesystem/shell
capability, and no DTO field capable of carrying protected ciphertext or
identity material.
- **Partial clones refuse cherry-pick/rebase, `sc ws fork`/`harvest`,
- **Partial clones refuse `sc ws fork`/`harvest`,
`sc work`, `sc export`, `sparse disable`, an empty `sparse set` (and, on a non-lazy clone, one outside the filter), `sc rewrap`,
`sc grant`/`revoke`, creating, switching to or leaving a private branch, a merge whose conflict lies outside the view or needs sealing outside it (no ref, state or working-tree change), `sc push` to a git remote, and
`sc fetch` from any native remote but the promisor origin.** `sc merge` works, including conflicts inside the view (P37c). `sc backfill --all`
`sc grant`/`revoke`, creating, switching to or leaving a private branch, a merge, cherry-pick or rebase whose conflict lies outside the view or needs sealing outside it (no ref, state or working-tree change), `sc push` to a git remote, and
`sc fetch` from any native remote but the promisor origin.** `sc merge`, `sc cherry-pick` and `sc rebase` work, including conflicts inside the view (P37c). `sc backfill --all`
converts to a genuine full clone and re-enables them. The filter records what
a clone *asked for*, not what is present: after a fetch an in-filter object
can be absent. On a lazy, online clone a switch, fast-forward, rebase, undo
Expand Down
4 changes: 2 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ clone: the view closure is filled by id before switch, fast-forward, undo and
`sparse disable` stay refused. Design and open questions in
[ADR-0048](docs/adr/0048-presence-based-partial-clones.md).

**P37c — merge on partial clones (proposed; 37c-i engine, 37c-ii clean merge and 37c-iii conflicts built).** A tree-recursive three-way merge
**P37c — merge on partial clones (proposed; 37c-i engine, 37c-ii clean merge, 37c-iii conflicts and 37c-iv replay built).** A tree-recursive three-way merge
that carries a subtree by id where the three sides agree, checks protection
rules before carrying, never drops wraps for subtrees it does not enumerate,
and fills (lazy) or refuses (otherwise) the region where the sides differ,
the region that intersects a protection rule, and the sparse view's closure. Merges are built (`sc merge` on a partial clone): a conflict inside the view is marked, resolved with `sc conflicts`/`sc resolve`, aborted or committed like on a full clone; a conflict outside the view, or one that needs sealing outside it, is refused before any write. Cherry-pick/rebase are next; sessions
the region that intersects a protection rule, and the sparse view's closure. Merges are built (`sc merge` on a partial clone): a conflict inside the view is marked, resolved with `sc conflicts`/`sc resolve`, aborted or committed like on a full clone; a conflict outside the view, or one that needs sealing outside it, is refused before any write. Cherry-pick and rebase use the same engine and conflict contract (`sc cherry-pick`, `sc rebase` and their `--continue`/`--abort` work on a partial clone); sessions
are undecided. Design in
[ADR-0049](docs/adr/0049-merge-on-partial-clones.md).

Expand Down
100 changes: 69 additions & 31 deletions crates/cli/tests/partial_clone_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,14 @@ fn status_diff_and_gc_succeed_on_fresh_partial_clone() {

/// P27 final review I2: `sc backfill --all` is the real escape hatch —
/// fetches every remaining object and removes `.sc/promisor`, after which
/// a cherry-pick that was refused as unsupported on a partial clone works.
/// a sparse disable that was refused on a partial clone works.
#[test]
fn backfill_all_lifts_partial_clone_refusals() {
let (src_root, dst_root) = make_partial_clone("backfill-all");

// Replay is still refused while partial (a merge, clean or conflicting
// inside the view, works since P37c). Create a clashing branch (same
// file) for the refusal and a non-conflicting one for the merge after
// backfill.
// `sparse disable` is still refused while partial (merge, cherry-pick
// and rebase work since P37c). Create a clashing branch and a
// non-conflicting one for the merge after backfill.
assert!(sc(&dst_root, &["branch", "clash"]).status.success());
assert!(sc(&dst_root, &["switch", "clash"]).status.success());
std::fs::write(dst_root.join("src/a.txt"), "clash-edit\n").unwrap();
Expand All @@ -182,19 +181,15 @@ fn backfill_all_lifts_partial_clone_refusals() {
std::fs::write(dst_root.join("src/a.txt"), "main-edit\n").unwrap();
assert!(sc(&dst_root, &["commit", "-m", "main"]).status.success());

let pick_before = sc(&dst_root, &["cherry-pick", "clash"]);
let disable_before = sc(&dst_root, &["sparse", "disable"]);
assert!(
!pick_before.status.success(),
"a cherry-pick must still be refused before backfill --all"
!disable_before.status.success(),
"`sparse disable` must still be refused before backfill --all"
);
assert!(
stderr(&pick_before).contains("backfill --all"),
"refusal must point at `sc backfill --all`: {}",
stderr(&pick_before)
);
assert!(
!dst_root.join("src/a.txt.theirs").exists(),
"a refused cherry-pick writes nothing"
stderr(&disable_before).contains("backfill"),
"refusal must point at `sc backfill`: {}",
stderr(&disable_before)
);
assert_eq!(
std::fs::read_to_string(dst_root.join("src/a.txt")).unwrap(),
Expand All @@ -221,22 +216,6 @@ fn backfill_all_lifts_partial_clone_refusals() {
stderr(&sparse_disable)
);

// The cherry-pick is no longer refused: it reaches the ordinary
// conflict state (markers in the file), which `--abort` undoes.
let conflict_after = sc(&dst_root, &["cherry-pick", "clash"]);
assert!(
!stderr(&conflict_after).contains("partial clone"),
"a cherry-pick must no longer be refused after backfill --all: {}",
stderr(&conflict_after)
);
assert!(
std::fs::read_to_string(dst_root.join("src/a.txt"))
.unwrap()
.contains("<<<<<<<"),
"the ordinary conflict markers are written"
);
assert!(sc(&dst_root, &["cherry-pick", "--abort"]).status.success());

let merge_after = sc(&dst_root, &["merge", "feature"]);
assert!(
merge_after.status.success(),
Expand Down Expand Up @@ -301,6 +280,65 @@ fn conflicting_merge_on_a_partial_clone_resolves_and_commits() {
std::fs::remove_dir_all(&dst_root).unwrap();
}

/// P37c-iv: cherry-pick and rebase work on a partial clone, and a conflict in
/// the view stops them with markers that `sc conflicts` and `sc resolve` find.
#[test]
fn cherry_pick_and_rebase_work_on_a_partial_clone() {
let (src_root, dst_root) = make_partial_clone("replay");
// Two branches off the first commit, each editing the same line.
assert!(sc(&dst_root, &["branch", "side"]).status.success());
assert!(sc(&dst_root, &["switch", "side"]).status.success());
std::fs::write(dst_root.join("src/a.txt"), "side-edit\n").unwrap();
assert!(sc(&dst_root, &["commit", "-m", "side"]).status.success());
assert!(sc(&dst_root, &["switch", "main"]).status.success());
std::fs::write(dst_root.join("src/a.txt"), "main-edit\n").unwrap();
assert!(sc(&dst_root, &["commit", "-m", "main"]).status.success());

let pick = sc(&dst_root, &["cherry-pick", "side"]);
assert!(!pick.status.success(), "a conflicting pick exits nonzero");
assert!(
!stderr(&pick).contains("partial clone"),
"not refused as unsupported: {}",
stderr(&pick)
);
assert!(std::fs::read_to_string(dst_root.join("src/a.txt"))
.unwrap()
.contains("<<<<<<<"));
assert!(
!dst_root.join("docs").exists(),
"docs/ stays out of the view"
);
let listed = sc(&dst_root, &["conflicts"]);
assert!(stdout(&listed).contains("src/a.txt"), "{}", stdout(&listed));
assert!(sc(&dst_root, &["cherry-pick", "--abort"]).status.success());
assert_eq!(
std::fs::read_to_string(dst_root.join("src/a.txt")).unwrap(),
"main-edit\n"
);

let rebase = sc(&dst_root, &["rebase", "side"]);
assert!(!rebase.status.success(), "a conflicting rebase stops");
assert!(
!stderr(&rebase).contains("partial clone"),
"not refused as unsupported: {}",
stderr(&rebase)
);
let resolved = sc(&dst_root, &["resolve", "--theirs", "src/a.txt"]);
assert!(resolved.status.success(), "{}", stderr(&resolved));
let cont = sc(&dst_root, &["rebase", "--continue"]);
assert!(cont.status.success(), "{}", stderr(&cont));
assert_eq!(
std::fs::read_to_string(dst_root.join("src/a.txt")).unwrap(),
"main-edit\n"
);
assert!(!dst_root.join("docs").exists());
let verify = sc(&dst_root, &["verify"]);
assert!(verify.status.success(), "{}", stderr(&verify));

std::fs::remove_dir_all(&src_root).unwrap();
std::fs::remove_dir_all(&dst_root).unwrap();
}

#[test]
fn sparse_widen_beyond_partial_filter_is_refused() {
let (src_root, dst_root) = make_partial_clone("sparse-widen");
Expand Down
2 changes: 2 additions & 0 deletions crates/repo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub mod oplog;
#[cfg(test)]
mod partial_merge;
#[cfg(test)]
mod partial_replay;
#[cfg(test)]
mod partial_walks;
pub mod pick_state;
pub mod private;
Expand Down
28 changes: 14 additions & 14 deletions crates/repo/src/partial_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ use crate::error::Error;
use crate::refs;
use crate::repo::Repo;

const SRC_A: &[u8] = b"one\ntwo\nthree\n";
pub(crate) const SRC_A: &[u8] = b"one\ntwo\nthree\n";

struct Fx {
origin_root: PathBuf,
clone_root: PathBuf,
origin: Repo,
pub(crate) struct Fx {
pub(crate) origin_root: PathBuf,
pub(crate) clone_root: PathBuf,
pub(crate) origin: Repo,
}

impl Fx {
/// An origin on `main` at one commit, with `extra` written into that first
/// commit by the caller-supplied closure.
fn origin(tag: &str, extra: impl FnOnce(&Path)) -> Fx {
pub(crate) fn origin(tag: &str, extra: impl FnOnce(&Path)) -> Fx {
let pid = std::process::id();
let base = std::env::temp_dir();
let origin_root = base.join(format!("scl-p37c-{tag}-origin-{pid}"));
Expand Down Expand Up @@ -52,7 +52,7 @@ impl Fx {

/// Cut `name` from the origin's `main`, write `files` on it, commit, and
/// return to `main`. Returns the new tip.
fn origin_branch(&self, name: &str, files: &[(&str, &[u8])]) -> ObjectId {
pub(crate) fn origin_branch(&self, name: &str, files: &[(&str, &[u8])]) -> ObjectId {
self.origin.branch(name).unwrap();
self.origin.switch(name).unwrap();
for (p, bytes) in files {
Expand All @@ -64,7 +64,7 @@ impl Fx {
}

/// A `--filter src/` clone, lazy or not, that has fetched every origin branch.
fn clone(&self, lazy: bool) -> Repo {
pub(crate) fn clone(&self, lazy: bool) -> Repo {
let clone = Repo::clone_url_filtered(
self.origin_root.to_str().unwrap(),
&self.clone_root,
Expand All @@ -76,7 +76,7 @@ impl Fx {
clone
}

fn cleanup(self) {
pub(crate) fn cleanup(self) {
drop(self.origin);
for r in [&self.origin_root, &self.clone_root] {
if r.exists() {
Expand All @@ -87,24 +87,24 @@ impl Fx {
}
}

fn has(repo: &Repo, id: &ObjectId) -> bool {
pub(crate) fn has(repo: &Repo, id: &ObjectId) -> bool {
repo.vfs().store().lock().unwrap().contains(id)
}

fn blob_id(bytes: &[u8]) -> ObjectId {
pub(crate) fn blob_id(bytes: &[u8]) -> ObjectId {
Object::blob(bytes.to_vec()).id()
}

/// The tree id of directory `name` directly under `snap`'s root.
fn dir_id(repo: &Repo, snap: &ObjectId, name: &str) -> ObjectId {
pub(crate) fn dir_id(repo: &Repo, snap: &ObjectId, name: &str) -> ObjectId {
let arc = repo.vfs().store();
let mut s = arc.lock().unwrap();
let root = s.get_snapshot(snap).unwrap().root;
s.get_tree(&root).unwrap().get(name).unwrap().id
}

/// Commit an edit to `src/a.txt` on the clone's `main`.
fn clone_edit_src(fx: &Fx, clone: &Repo, bytes: &[u8]) {
pub(crate) fn clone_edit_src(fx: &Fx, clone: &Repo, bytes: &[u8]) {
std::fs::write(fx.clone_root.join("src/a.txt"), bytes).unwrap();
clone.commit("t", "ours").unwrap();
}
Expand Down Expand Up @@ -420,7 +420,7 @@ fn a_conflict_outside_the_view_is_refused_before_any_write() {
}

/// An origin whose `vault/` is protected for `pk` (rule plus ciphertext).
fn protected_origin(tag: &str, pk: &scl_crypto::PublicKey) -> Fx {
pub(crate) fn protected_origin(tag: &str, pk: &scl_crypto::PublicKey) -> Fx {
let fx = Fx::origin(tag, |root| {
std::fs::create_dir_all(root.join("vault")).unwrap();
std::fs::write(root.join("vault/s.txt"), b"l1\nl2\nl3\n").unwrap();
Expand Down
Loading
Loading