fix(branch): Reject unresolved explicit anchors#14812
Conversation
dcfbf7f to
ef4c545
Compare
|
Thanks a lot for the minimal fix and the tests. As the source change is so minimal, I think @slarse would be able to take a look and see if the PR has merit, especially in the face of a possibly planned 'branch2'. |
Keep an omitted anchor as the only path that selects the default workspace base. Reject a supplied external commit before branch metadata or refs are changed, preventing later picks from producing synthetic conflict trees. Co-Authored-By: GPT-5.6 Sol <codex@openai.com>
ef4c545 to
1ebe0a4
Compare
slarse
left a comment
There was a problem hiding this comment.
Hi @reneleonhardt (and @Byron)!
This is a good change, I'm very much in favor of rejecting bad arguments rather than bending over backwards to "do something".
Like @Byron mentions, new and completely reworked branch commands are upcoming, but the ETA is not tomorrow, so this is a worthwhile change to put in for users.
I took the liberty of simplifying the test case to only reproduce the particular issue of applying a branch outside the workspace. I gather that the original test case was reproducing some particular scenario, but it didn't make a whole lot of sense to me in relation to the source code fix and was rather complicated.
1ebe0a4 to
7d696a9
Compare
fix(branch): Reject unresolved explicit anchors
🧢 Changes
but branch new --anchor <value>that cannot be resolvedin the current workspace.
--anchor.ref.
☕️ Reasoning
An explicit anchor is a requested history boundary, not a hint. Omitting one
and supplying one that cannot be resolved are distinct operations.
The invariant is independent of selector syntax: future change-ID or worktree
graph improvements may make more anchors resolvable, but an unresolved explicit
anchor must never fall back to the workspace base. Failing before mutation
keeps the repository recoverable and prevents agentic coding from replaying
history onto a boundary it did not request.
🧪 Reproduction
cargo test -p but rejects_fetched_merge_anchor_outside_workspace_before_replayBefore this fix, the explicit fetched merge anchor was treated as absent, so
branch creation succeeded at the workspace common base and a later replay could
synthesize widespread conflicts.
✅ Verification
reconstruction ref is created.
passed.
Developed with carefully directed, manually reviewed AI assistance.
Co-Authored-By: GPT-5.6 Sol codex@openai.com