Skip to content

fix(branch): Reject unresolved explicit anchors#14812

Merged
slarse merged 2 commits into
gitbutlerapp:masterfrom
reneleonhardt:fix/fetched-merge-anchor-replay
Jul 21, 2026
Merged

fix(branch): Reject unresolved explicit anchors#14812
slarse merged 2 commits into
gitbutlerapp:masterfrom
reneleonhardt:fix/fetched-merge-anchor-replay

Conversation

@reneleonhardt

@reneleonhardt reneleonhardt commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

fix(branch): Reject unresolved explicit anchors

🧢 Changes

  • Reject an explicit but branch new --anchor <value> that cannot be resolved
    in the current workspace.
  • Keep default-base selection exclusive to calls that omit --anchor.
  • Cover a fetched merge anchor and verify rejection before creating a branch
    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_replay

Before 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

  • The fetched-merge regression fails on the old fallback and verifies that no
    reconstruction ref is created.
  • All 10 branch-creation tests and the GitHub Rust/Tauri/Windows/E2E checks
    passed.

Developed with carefully directed, manually reviewed AI assistance.

Co-Authored-By: GPT-5.6 Sol codex@openai.com

@reneleonhardt
reneleonhardt force-pushed the fix/fetched-merge-anchor-replay branch from dcfbf7f to ef4c545 Compare July 17, 2026 13:14
@Byron
Byron requested a review from slarse July 20, 2026 18:43
@Byron

Byron commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

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>
@slarse
slarse force-pushed the fix/fetched-merge-anchor-replay branch from ef4c545 to 1ebe0a4 Compare July 21, 2026 06:02

@slarse slarse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@slarse
slarse force-pushed the fix/fetched-merge-anchor-replay branch from 1ebe0a4 to 7d696a9 Compare July 21, 2026 06:13
@slarse
slarse enabled auto-merge July 21, 2026 06:28
@slarse
slarse merged commit 9ada803 into gitbutlerapp:master Jul 21, 2026
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants