Skip to content

Fix PR base branch update on merge conflicts#18

Merged
Phlogistique merged 1 commit into
mainfrom
claude/fix-merge-conflict-handling-7vgDg
Dec 26, 2025
Merged

Fix PR base branch update on merge conflicts#18
Phlogistique merged 1 commit into
mainfrom
claude/fix-merge-conflict-handling-7vgDg

Conversation

@Phlogistique
Copy link
Copy Markdown
Collaborator

When a merge conflict occurs during automatic PR stack update:

  • Don't change the PR's base branch (keeps the diff readable)
  • Don't delete the merged branch (user can reference it during resolution)

After the user resolves conflicts and pushes:

  • Update the PR's base branch to trunk
  • Delete the old base branch only if no other conflicted PRs depend on it

Changes:

  • main(): Track UPDATED_TARGETS vs CONFLICTED_TARGETS separately
  • main(): Only update base and delete branch for successfully updated PRs
  • Add has_sibling_conflicts() helper to check if other PRs share the base
  • continue_after_resolution(): Update base branch and conditionally delete
  • Update E2E tests to verify the new behavior
  • Add Scenario 3: sibling conflicts test for branch deletion timing

@Phlogistique Phlogistique force-pushed the claude/fix-merge-conflict-handling-7vgDg branch from 513bb65 to cb36bad Compare December 26, 2025 13:06
@Phlogistique
Copy link
Copy Markdown
Collaborator Author

@codex review

@Phlogistique Phlogistique force-pushed the claude/fix-merge-conflict-handling-7vgDg branch from cb36bad to 4bf6fac Compare December 26, 2025 13:08
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread update-pr-stack.sh
Comment on lines +225 to +229
if has_sibling_conflicts "$OLD_BASE" "$PR_BRANCH"; then
echo "⚠️ Keeping branch '$OLD_BASE' - still referenced by other conflicted PRs"
else
echo "Deleting old base branch '$OLD_BASE' (no other PRs depend on it)"
log_cmd git push origin ":$OLD_BASE" || echo "⚠️ Could not delete '$OLD_BASE' (may already be deleted)"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid deleting whatever base the PR currently has

In continue_after_resolution, the branch deletion uses OLD_BASE that was derived from the PR’s current base earlier in the function. If a user resolves conflicts and manually updates the PR base to main/trunk (or any other branch) before the synchronize run, OLD_BASE will be that branch and this code will attempt git push origin :<branch>. On repos without protected branches, that can delete the default branch. Consider persisting the original merged branch from the conflict event (or guarding against deleting default/base branches or when NEW_TARGET is empty) rather than deleting the current base blindly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When a merge conflict occurs during automatic PR stack update:
- Don't change the PR's base branch (keeps the diff readable)
- Don't delete the merged branch (user can reference it during resolution)

After the user resolves conflicts and pushes:
- Update the PR's base branch to trunk
- Delete the old base branch only if no other conflicted PRs depend on it

Changes:
- main(): Track UPDATED_TARGETS vs CONFLICTED_TARGETS separately
- main(): Only update base and delete branch for successfully updated PRs
- Add has_sibling_conflicts() helper to check if other PRs share the base
- continue_after_resolution(): Update base branch and conditionally delete
- Update E2E tests to verify the new behavior
- Add Scenario 3: sibling conflicts test for branch deletion timing
@Phlogistique Phlogistique force-pushed the claude/fix-merge-conflict-handling-7vgDg branch from 4bf6fac to 295018c Compare December 26, 2025 13:29
@Phlogistique Phlogistique merged commit fb022a0 into main Dec 26, 2025
4 checks passed
@github-actions github-actions Bot deleted the claude/fix-merge-conflict-handling-7vgDg branch December 26, 2025 13:34
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