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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions crates/repo/src/partial_walks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
4 changes: 4 additions & 0 deletions crates/repo/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ impl Repo {
recipients: &[PublicKey],
escrows: &[PublicKey],
) -> Result<ObjectId> {
// 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}")));
Expand Down
1 change: 1 addition & 0 deletions crates/repo/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions docs/adr/0048-presence-based-partial-clones.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading