Fix branch ancestry check logic in merge script#15
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: