Commit a8a9050
fix(stack): repoint moving PR bases to trunk before force-push (#1559)
Reordering the commits of a stack and re-pushing could make GitHub
spuriously mark a pull request as merged and auto-close it (and its
dependents). The merge is irreversible, so the stack's PR <-> commit
mapping is destroyed: `mergify stack list` then shows the reordered
commit as a phantom "merged" PR and its sibling as "no PR".
Root cause: `stack push` force-pushes every head branch in one atomic
`git push`, then updates the PR bases afterwards. When commits are
reordered, the branches hold the new order while the PRs still carry
their pre-reorder bases. During that window a PR's head branch becomes
an ancestor of its own (stale) base branch — e.g. the new-bottom PR's
head ends up contained in the branch that now holds the commit stacked
on top of it. GitHub reads "head is an ancestor of base" as "merged".
This was confirmed empirically: force-pushing only the reordered heads,
with no base change at all, is enough to trigger the auto-merge.
Fix: before the force-push, repoint any PR whose base is moving onto the
trunk. A head branch is never an ancestor of the trunk, so the push can
no longer trigger the spurious merge; the real new base is set afterwards
by `create_or_update_pr`, once every branch holds its final content and
each head is strictly ahead of its parent again. PRs already based on the
trunk or whose base is unchanged are left alone, so the common
non-reorder push issues no extra API calls.
Verified end-to-end against a sandbox repo: a 2-commit stack reordered
and re-pushed now keeps both PRs open with correctly flipped bases, and
the PR timeline shows the base repoint landing before the head
force-push, with no `merged`/`closed` event.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent e18dc2a commit a8a9050
2 files changed
Lines changed: 398 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
213 | 260 | | |
214 | 261 | | |
215 | 262 | | |
| |||
626 | 673 | | |
627 | 674 | | |
628 | 675 | | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
629 | 690 | | |
630 | 691 | | |
631 | 692 | | |
| |||
0 commit comments