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
8 changes: 4 additions & 4 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 and P37c-ii are built and tested. One line of current fact per phase; the
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
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 | Clean 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 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 and conflicts are next | [0049](docs/adr/0049-merge-on-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) |

## Standing boundaries & gotchas

Expand All @@ -171,8 +171,8 @@ transport-adjacent. The rest, imperatively:
identity material.
- **Partial clones refuse cherry-pick/rebase, `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 that has conflicts (no ref, state or working-tree change), `sc push` to a git remote, and
`sc fetch` from any native remote but the promisor origin.** A clean `sc merge` works (P37c-ii). `sc backfill --all`
`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`
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 and 37c-ii clean merge built).** A tree-recursive three-way merge
**P37c — merge on partial clones (proposed; 37c-i engine, 37c-ii clean merge and 37c-iii conflicts 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. Clean merges are built (`sc merge` on a partial clone; a conflict is refused before any write). Conflicts are next, then cherry-pick/rebase; 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/rebase are next; sessions
are undecided. Design in
[ADR-0049](docs/adr/0049-merge-on-partial-clones.md).

Expand Down
82 changes: 68 additions & 14 deletions crates/cli/tests/partial_clone_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,15 @@ 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 merge that was refused as unsupported on a partial clone works.
/// a cherry-pick that was refused as unsupported on a partial clone works.
#[test]
fn backfill_all_lifts_partial_clone_refusals() {
let (src_root, dst_root) = make_partial_clone("backfill-all");

// A merge with conflicts is refused while partial (a clean one works, P37c-ii).
// Create a divergent, non-conflicting branch (different files) for the clean
// merge after backfill, and a clashing one (same file) for the refusal.
// 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.
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 @@ -181,19 +182,19 @@ 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 merge_before = sc(&dst_root, &["merge", "clash"]);
let pick_before = sc(&dst_root, &["cherry-pick", "clash"]);
assert!(
!merge_before.status.success(),
"a conflicting merge must still be refused before backfill --all"
!pick_before.status.success(),
"a cherry-pick must still be refused before backfill --all"
);
assert!(
stderr(&merge_before).contains("backfill --all"),
stderr(&pick_before).contains("backfill --all"),
"refusal must point at `sc backfill --all`: {}",
stderr(&merge_before)
stderr(&pick_before)
);
assert!(
!dst_root.join("src/a.txt.theirs").exists(),
"a refused merge writes nothing"
"a refused cherry-pick writes nothing"
);
assert_eq!(
std::fs::read_to_string(dst_root.join("src/a.txt")).unwrap(),
Expand All @@ -220,12 +221,12 @@ fn backfill_all_lifts_partial_clone_refusals() {
stderr(&sparse_disable)
);

// The conflicting merge is no longer refused: it reaches the ordinary
// 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, &["merge", "clash"]);
let conflict_after = sc(&dst_root, &["cherry-pick", "clash"]);
assert!(
!stderr(&conflict_after).contains("partial clone"),
"a conflicting merge must no longer be refused after backfill --all: {}",
"a cherry-pick must no longer be refused after backfill --all: {}",
stderr(&conflict_after)
);
assert!(
Expand All @@ -234,7 +235,7 @@ fn backfill_all_lifts_partial_clone_refusals() {
.contains("<<<<<<<"),
"the ordinary conflict markers are written"
);
assert!(sc(&dst_root, &["merge", "--abort"]).status.success());
assert!(sc(&dst_root, &["cherry-pick", "--abort"]).status.success());

let merge_after = sc(&dst_root, &["merge", "feature"]);
assert!(
Expand All @@ -247,6 +248,59 @@ fn backfill_all_lifts_partial_clone_refusals() {
std::fs::remove_dir_all(&dst_root).unwrap();
}

/// P37c-iii: a merge with a conflict inside the view works on a partial clone.
/// Markers land, `sc conflicts` and `sc resolve` find the path without
/// flattening a tree, and `sc commit` completes the merge. The untouched
/// `docs/` subtree is never fetched or written.
#[test]
fn conflicting_merge_on_a_partial_clone_resolves_and_commits() {
let (src_root, dst_root) = make_partial_clone("conflict-merge");
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();
assert!(sc(&dst_root, &["commit", "-m", "clash"]).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 merge = sc(&dst_root, &["merge", "clash"]);
assert!(!merge.status.success(), "a conflicting merge exits nonzero");
assert!(
!stderr(&merge).contains("partial clone"),
"not refused as unsupported: {}",
stderr(&merge)
);
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!(listed.status.success(), "{}", stderr(&listed));
assert!(stdout(&listed).contains("src/a.txt"));
let shown = sc(&dst_root, &["conflicts", "src/a.txt"]);
assert!(shown.status.success(), "{}", stderr(&shown));
assert!(stdout(&shown).contains("main-edit") && stdout(&shown).contains("clash-edit"));

let resolved = sc(&dst_root, &["resolve", "--theirs", "src/a.txt"]);
assert!(resolved.status.success(), "{}", stderr(&resolved));
let commit = sc(&dst_root, &["commit", "-m", "merge clash"]);
assert!(commit.status.success(), "{}", stderr(&commit));
assert_eq!(
std::fs::read_to_string(dst_root.join("src/a.txt")).unwrap(),
"clash-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
46 changes: 32 additions & 14 deletions crates/repo/src/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use scl_core::{Object, ObjectId, Store, PROTECTED};

use crate::error::{Error, Result};
use crate::repo::Repo;
use crate::worktree::{safe_join, tree_file_entries_with_perms};
#[cfg(test)]
use crate::worktree::tree_file_entries_with_perms;
use crate::worktree::{safe_join, tree_entry_at};

/// Which in-progress operation owns the current conflicts.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -140,20 +142,20 @@ impl Repo {
/// else non-UTF8 ours/theirs content → Binary; else Text).
pub fn conflict_kind(&self, path: &str) -> Result<ConflictKind> {
let triple = self.op_triple()?;
let partial = self.promisor()?.is_some();
let store_arc = self.vfs.store();
let mut store = store_arc.lock().unwrap();
for id in [triple.ours, triple.theirs] {
let root = store.get_snapshot(&id)?.root;
let entries = tree_file_entries_with_perms(&mut store, root)?;
if let Some((_, _, perms)) = entries.get(path) {
if let Some((_, _, perms)) = tree_entry_at(&mut store, root, path, partial)? {
if perms & PROTECTED != 0 {
return Ok(ConflictKind::Protected);
}
}
}
// Neither tip is protected: a None identity is fine to inspect content.
let ours = side_for(&mut store, triple.ours, None, path)?;
let theirs = side_for(&mut store, triple.theirs, None, path)?;
let ours = side_for(&mut store, triple.ours, None, path, partial)?;
let theirs = side_for(&mut store, triple.theirs, None, path, partial)?;
let is_binary = |s: &Side| matches!(s, Side::Present(b) if std::str::from_utf8(b).is_err());
if is_binary(&ours) || is_binary(&theirs) {
Ok(ConflictKind::Binary)
Expand All @@ -168,16 +170,29 @@ impl Repo {
&self,
path: &str,
identity: Option<&scl_crypto::SecretKey>,
) -> Result<ConflictVersions> {
self.versions_impl(path, identity, true)
}

/// [`Repo::conflict_versions`], optionally leaving the base side
/// `Absent` unread. `resolve` takes ours or theirs and never needs the
/// base, which a partial clone may not hold.
fn versions_impl(
&self,
path: &str,
identity: Option<&scl_crypto::SecretKey>,
with_base: bool,
) -> Result<ConflictVersions> {
let triple = self.op_triple()?;
let partial = self.promisor()?.is_some();
let store_arc = self.vfs.store();
let mut store = store_arc.lock().unwrap();
let base = match triple.base {
Some(id) => side_for(&mut store, id, identity, path)?,
None => Side::Absent,
Some(id) if with_base => side_for(&mut store, id, identity, path, partial)?,
_ => Side::Absent,
};
let ours = side_for(&mut store, triple.ours, identity, path)?;
let theirs = side_for(&mut store, triple.theirs, identity, path)?;
let ours = side_for(&mut store, triple.ours, identity, path, partial)?;
let theirs = side_for(&mut store, triple.theirs, identity, path, partial)?;
Ok(ConflictVersions { base, ours, theirs })
}

Expand Down Expand Up @@ -216,7 +231,7 @@ impl Repo {
)));
}

let versions = self.conflict_versions(path, identity)?;
let versions = self.versions_impl(path, identity, false)?;
let chosen = match side {
ResolveSide::Ours => versions.ours,
ResolveSide::Theirs => versions.theirs,
Expand Down Expand Up @@ -256,12 +271,12 @@ impl Repo {
ResolveSide::Ours => triple.ours,
ResolveSide::Theirs => triple.theirs,
};
let partial = self.promisor()?.is_some();
let store_arc = self.vfs.store();
let blob_id = {
let mut store = store_arc.lock().unwrap();
let snap = store.get_snapshot(&chosen_snapshot)?;
let entries = tree_file_entries_with_perms(&mut store, snap.root)?;
entries.get(path).map(|(id, _, _)| *id)
tree_entry_at(&mut store, snap.root, path, partial)?.map(|(id, _, _)| id)
};
if let Some(blob_id) = blob_id {
let mut cache = self.open_protected_cache()?;
Expand Down Expand Up @@ -326,12 +341,15 @@ fn side_for(
snapshot_id: ObjectId,
identity: Option<&scl_crypto::SecretKey>,
path: &str,
partial: bool,
) -> Result<Side> {
let snap = store.get_snapshot(&snapshot_id)?;
let entries = tree_file_entries_with_perms(store, snap.root)?;
let Some((blob_id, _mode, perms)) = entries.get(path).copied() else {
let Some((blob_id, _mode, perms)) = tree_entry_at(store, snap.root, path, partial)? else {
return Ok(Side::Absent);
};
if partial && !store.contains(&blob_id) {
return Err(crate::promisor::partial_gap_hint(path));
}
let bytes = match store.get(&blob_id)? {
Object::Blob(b) => b,
_ => return Err(Error::BadRef(format!("{path}: tree entry is not a blob"))),
Expand Down
Loading
Loading