diff --git a/CLAUDE.md b/CLAUDE.md index 170c4701..d55f347b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -170,7 +170,7 @@ transport-adjacent. The rest, imperatively: identity material. - **Partial clones refuse merge, 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`, leaving a private branch, `sc push` to a git remote, and + `sc grant`/`revoke`, creating, switching to or leaving a private branch, `sc push` to a git remote, and `sc fetch` from any native remote but the promisor origin.** `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 diff --git a/crates/repo/src/partial_walks.rs b/crates/repo/src/partial_walks.rs index d5e97810..01e77601 100644 --- a/crates/repo/src/partial_walks.rs +++ b/crates/repo/src/partial_walks.rs @@ -688,3 +688,50 @@ fn every_materializer_call_site_fills_or_is_exempt() { } assert!(checked >= 15, "the scan found only {checked} call sites"); } + +/// A private branch cannot be checked out on a partial clone (sealing and +/// opening flatten whole trees), so creating or switching to one is refused +/// explicitly instead of failing with a raw `NotFound` mid-switch. +#[test] +fn private_branches_are_refused_on_a_partial_clone() { + let (fx, clone) = Fx::new_in_sync("private"); + let (sk, pk) = scl_crypto::generate_keypair(); + let err = clone + .branch_private("secret-work", &sk, std::slice::from_ref(&pk), &[]) + .unwrap_err(); + assert!( + matches!(err, Error::PartialCloneUnsupported(_)), + "got {err:?}" + ); + assert!(!clone.layout().ref_path("secret-work").exists()); + + // A private ref that reached the clone some other way (a manifest tip) is + // refused at switch time, before anything is touched. + let full_root = + std::env::temp_dir().join(format!("scl-p37b-private-full-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&full_root); + let full = Repo::clone_to(&fx.origin_root, &full_root).unwrap(); + let mid = full + .branch_private("secret-work", &sk, std::slice::from_ref(&pk), &[]) + .unwrap(); + { + let src = full.vfs().store(); + let dst = clone.vfs().store(); + let m = src.lock().unwrap().get(&mid).unwrap(); + dst.lock().unwrap().put(m).unwrap(); + } + refs::write_branch_tip(clone.layout(), "secret-work", &mid).unwrap(); + let err = clone + .switch_with_identity("secret-work", Some(&sk)) + .unwrap_err(); + assert!( + matches!(err, Error::PartialCloneUnsupported(_)), + "got {err:?}" + ); + assert_eq!(refs::current_branch(clone.layout()).unwrap(), "main"); + assert!(fx.clone_root.join("src/a.txt").exists()); + drop(full); + std::fs::remove_dir_all(&full_root).unwrap(); + drop(clone); + fx.cleanup(); +} diff --git a/crates/repo/src/private.rs b/crates/repo/src/private.rs index c766e14e..215f1c4e 100644 --- a/crates/repo/src/private.rs +++ b/crates/repo/src/private.rs @@ -295,6 +295,10 @@ impl Repo { recipients: &[PublicKey], escrows: &[PublicKey], ) -> Result { + // A private branch is checked out by flattening and sealing whole + // trees, which a partial clone cannot do (ADR-0048). Refuse up front + // rather than create a branch that cannot be switched to. + self.refuse_on_partial("sc branch --private")?; crate::repo::validate_branch_name(name)?; if self.layout.ref_path(name).exists() { return Err(Error::BadRef(format!("branch already exists: {name}"))); diff --git a/crates/repo/src/repo.rs b/crates/repo/src/repo.rs index 03c3c828..7287a7d4 100644 --- a/crates/repo/src/repo.rs +++ b/crates/repo/src/repo.rs @@ -1814,6 +1814,7 @@ impl Repo { }; // Switching TO a private branch takes the private materialize path. if let Some(m) = self.manifest_at(&target_tip)? { + self.refuse_on_partial("switching to a private branch")?; return self.switch_to_private(name, target_tip, m, identity, &old_paths); } // Leaving a private branch flattens the public target's whole tree diff --git a/docs/adr/0048-presence-based-partial-clones.md b/docs/adr/0048-presence-based-partial-clones.md index b6efda76..433bd664 100644 --- a/docs/adr/0048-presence-based-partial-clones.md +++ b/docs/adr/0048-presence-based-partial-clones.md @@ -390,10 +390,11 @@ review established, as constraints on that work: Closed in 37b-ii for the files a narrowing would strand, by the `.sc/sparse-prev` marker (decision 4, as built). The in-view-reads-as-deleted half after a widen is unchanged. -10. **Private branches on a partial clone** have no `ensure_view` or - preflight (`private.rs` materializes through its own path). Untested: - whether switching to one can hit a raw `NotFound` when public base - content is absent. +10. **Private branches on a partial clone** (resolved after 37b-ii). Probing + showed that creating one succeeded and switching to it failed with a raw + `NotFound`, because opening a private branch flattens and seals whole + trees. `sc branch --private` and switching to a private branch are now + refused explicitly on a partial clone; `sc backfill --all` lifts it. ## Alternatives considered