Skip to content

Sparse + private branch: a conflicted merge-in resurrects a file the public side deleted outside the view #240

Closed

Description

@tonibergholm-codento

Found while reviewing #239 (the same class as #238, in the private-branch path). Not fixed in #239.

Symptom: a conflicted merge of a public branch into a private branch, under a sparse spec, resurrects a file the public side deleted cleanly outside the view. Without sparse the file stays deleted.

Reproduced with a scratch test in crates/repo/src/private.rs (not committed):

  1. main has src/lib.rs, docs/old.txt, docs/mod.txt. Create private branch fix; edit src/lib.rs on it and commit_private.
  2. On main: edit src/lib.rs differently, delete docs/old.txt, edit docs/mod.txt, commit.
  3. set_sparse(["src/"]) on main, switch to fix, merge_into_private("main") -> MergeConflicts(1). Resolve src/lib.rs, commit_private.
  4. Switch to main, widen the spec to src/ and docs/ (remove the leftover docs/mod.txt first), switch back to fix.

Result with sparse: docs/old.txt exists again. Without the set_sparse calls it does not.

Cause (from reading crates/repo/src/private.rs ~:738-747): merge_into_private writes merge_state with no decided root (~:1354) and completes through commit_private. There, "carry prior paths that are expected-absent" copies every prior-tip path that is out of the sparse view and absent from disk. The merge removed docs/old.txt from disk, so the prior tip's copy is carried back. This is the #238 mechanism, with the prior private tip instead of the parents.

Side finding: the conflict stop wrote docs/mod.txt (out of view) to disk, so the merge-in path does not honor the sparse spec when laying out its result. That is why the out-of-view modify landed in the repro; it is also a view wider than advertised. Worth checking against the "private branches refuse sparse *" boundary: set_sparse is refused on a private branch, but a spec set on the public branch before the switch still applies.

Direction: record a decided root for the private merge stop (the merged inner tree) and carry out-of-view paths from it in commit_private when a merge head is set, as snapshot_files now does for public branches; or decide that a sparse spec and a private branch should not combine and refuse the switch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions