Repository navigation
Conversation
Remote-branch deletion in cleanup-worktree.sh was unconditional: the merged-PR check only gated a non-blocking prompt while `git push origin --delete` always fired. Invoking the script (or piping `echo y |`) on a branch whose PR was still OPEN deleted the PR head branch, making GitHub close the PR unmerged and stranding the work. - Hard-gate remote delete on `PR_STATUS == MERGED` or an explicit `--delete-remote`/`--force` flag (AC-1, AC-2); otherwise skip it and leave the remote branch + open PR intact. - Local teardown (worktree + local branch) stays unconditional so the branch lock is freed for a later `gh pr merge --delete-branch` (AC-4). - Add `--yes`/`-y` and `--force` for non-interactive confirm; in a non-interactive context without a confirm flag, exit safely instead of stalling on `read -p` (AC-3). MERGED happy path is unchanged (AC-6). - Remove the stale, gitignored, divergent `.claude/scripts/` copy that carried the same unconditional-delete bug (AC-5). Entire-Checkpoint: 35d3bdee7a20
Closed
6 tasks
admarble
deleted the
feature/750-fix-cleanup-worktree-deletes-remote-branch-before-
branch
June 28, 2026 19:57
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.
Summary
cleanup-worktree.shdeleted the remote branch unconditionally — the merged-PR check only gated a non-blocking prompt, so running the script (or pipingecho y |) against a branch whose PR was still OPEN deleted the PR head branch and made GitHub close the PR unmerged, stranding the work.This PR hard-gates the destructive step and makes the script automatable:
PR_STATUS == MERGEDor an explicit--delete-remote/--forceflag. Otherwise it's skipped and the remote branch + open PR are left intact.gh pr merge --delete-branch.--yes/-y(and--force) skip the confirmation prompt; without a confirm flag in a non-interactive context the script exits safely instead of stalling onread -p..claude/scripts/cleanup-worktree.sh(carried the same bug; on no code path).Flag semantics:
--yes= non-interactive confirm only (never overrides the merge gate);--delete-remote= override the merge gate (still honors TTY confirm);--force= both.Pre-PR AC Verification
REMOTE_DELETE=NO; gate atcleanup-worktree.shremote-delete blockMERGEDor--delete-remote/--forceMERGED→delete, OPEN+--force→delete, OPEN+no flag→skip--yes/--forceruns to completion; without it, safe exit (noread -pstall)</dev/null: exit 0, safe-exit message, no hangtemplates/scripts/+.claude/scripts/reconciledtemplates/scripts/gated (scripts/symlink inherits); stale gitignored.claude/scripts/copy deletedMERGEDshort-circuits confirm gate, full local+remote teardown, no new promptTest plan
Behavior verified with a stubbed
git/ghharness (no real branches touched):--force→ remote delete fires--yes(confirm only) → no remote delete, "skipped" message--delete-remotenon-interactive (no--yes) → safe exit, no delete--yes --delete-remote→ remote delete firesbash -nsyntax clean ontemplates/+scripts/symlink;npm run build+npm run lintpassCloses #750