Skip to content

Fix branch ancestry check logic in merge script#15

Merged
Phlogistique merged 2 commits into
mainfrom
claude/fix-branch-ancestry-check-OQJO4
Dec 25, 2025
Merged

Fix branch ancestry check logic in merge script#15
Phlogistique merged 2 commits into
mainfrom
claude/fix-branch-ancestry-check-OQJO4

Conversation

@Phlogistique
Copy link
Copy Markdown
Collaborator

The is_base_ancestor function was checking remote-tracking branches (origin/$BASE and origin/$BRANCH), but merge operations performed by the script haven't been pushed yet. This caused incorrect ancestry detection for child branches.

The fix leverages control flow analysis: git checkout creates the local branch from origin if needed, so we checkout first then compare local refs. This eliminates the need for conditional branch creation and ensures idempotence even when pushes haven't occurred yet.

Changes:

  • Remove ensure_local_branch() and is_base_ancestor() helpers
  • Modify has_squash_commit() to use local refs (caller ensures they exist)
  • Move git checkout before ancestry checks in update_direct_target()
  • Inline merge-base check in update_indirect_target() after checkout
  • Add comments explaining the control flow reasoning

The is_base_ancestor function was checking remote-tracking branches
(origin/$BASE and origin/$BRANCH), but merge operations performed by
the script haven't been pushed yet. This caused incorrect ancestry
detection for child branches.

The fix leverages control flow analysis: git checkout creates the local
branch from origin if needed, so we checkout first then compare local
refs. This eliminates the need for conditional branch creation and
ensures idempotence even when pushes haven't occurred yet.

Changes:
- Remove ensure_local_branch() and is_base_ancestor() helpers
- Modify has_squash_commit() to use local refs (caller ensures they exist)
- Move git checkout before ancestry checks in update_direct_target()
- Inline merge-base check in update_indirect_target() after checkout
- Add comments explaining the control flow reasoning
The test was checking file.txt content after checking out feature4,
so it was reading feature4's content instead of feature3's.
@Phlogistique Phlogistique merged commit 4f46bd6 into main Dec 25, 2025
4 of 6 checks passed
@github-actions github-actions Bot deleted the claude/fix-branch-ancestry-check-OQJO4 branch December 25, 2025 15:03
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.

2 participants