Skip to content

Commit ac7724e

Browse files
committed
fix(rebase-stack): only delete merged branch after full stack success
Prevent closing child PRs by ensuring the merged branch is only deleted after all rebases, force-pushes, and base updates succeed. On failure, the branch is kept and only a comment is left on the affected PR.
1 parent 92f4d63 commit ac7724e

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

.github/workflows/rebase-stack.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
# rebase silently altered code, it refuses to force-push.
1919
# 5. If a rebase hits conflicts, it leaves a comment with manual fix
2020
# instructions and stops processing that chain.
21-
# 6. Deletes the merged PR's head branch (replaces GitHub's auto-delete).
21+
# 6. Deletes the merged PR's head branch after all child PRs have been
22+
# retargeted and rebased. If the chain failed, the branch is kept
23+
# to avoid closing child PRs whose base was not yet updated.
2224
#
2325
# Why "rebase --onto" instead of "--fork-point":
2426
# GitHub Actions runs on a fresh clone with no reflog, so --fork-point
@@ -152,10 +154,6 @@ jobs:
152154
)
153155
gh pr comment "$pr_number" --body "$comment_body"
154156
155-
# Update the base even on failure so GitHub shows the correct
156-
# target branch, even if the diff is still wrong.
157-
gh pr edit "$pr_number" --base "$new_pr_base"
158-
159157
echo "::warning::Stopping chain at PR #${pr_number} due to conflicts."
160158
return 1
161159
fi
@@ -183,7 +181,6 @@ jobs:
183181
184182
Please rebase manually and verify the changes are correct."
185183
186-
gh pr edit "$pr_number" --base "$new_pr_base"
187184
return 1
188185
fi
189186
@@ -198,7 +195,6 @@ jobs:
198195
199196
The rebase succeeded but force-push failed for \`$pr_branch\`. This may be due to a concurrent push. Please rebase manually."
200197
201-
gh pr edit "$pr_number" --base "$new_pr_base"
202198
return 1
203199
fi
204200
@@ -235,15 +231,16 @@ jobs:
235231
"$MERGED_BASE" \
236232
|| rebase_result=$?
237233
238-
# Delete the merged PR's head branch. This replaces GitHub's
239-
# auto-delete-head-branch setting, giving us control over timing
240-
# (we delete only after the stack is rebased).
234+
# Delete the merged PR's head branch only if the rebase chain
235+
# succeeded. If it failed, some child PRs may still have this
236+
# branch as their base — deleting it would cause GitHub to close
237+
# those child PRs.
241238
echo ""
242-
echo "Deleting merged branch: $MERGED_HEAD"
243-
git push origin --delete "$MERGED_HEAD" 2>/dev/null || echo "Branch already deleted."
244-
245239
if [ "$rebase_result" -eq 0 ]; then
240+
echo "Deleting merged branch: $MERGED_HEAD"
241+
git push origin --delete "$MERGED_HEAD" 2>/dev/null || echo "Branch already deleted."
246242
echo "=== All stacked PRs rebased successfully ==="
247243
else
244+
echo "Keeping merged branch '$MERGED_HEAD' to avoid closing child PRs whose base was not updated."
248245
echo "=== Rebase chain stopped due to conflicts ==="
249246
fi

0 commit comments

Comments
 (0)