Repository navigation
fix(cleanup-worktree): resolve the branch ref once — documented glob form never worked, shorthand silently skipped branch deletes - #840
Merged
admarble merged 2 commits intoJul 29, 2026
Conversation
…ented glob form match
cleanup-worktree.sh matched the worktree by literal substring and then handed
the caller's RAW argument to every downstream consumer. Two defects, same three
lines:
1. The documented invocation never worked. fullsolve/SKILL.md:676,
exec/SKILL.md:524 and docs/troubleshooting.md:46 all prescribe
`cleanup-worktree.sh feature/<issue-number>-*`. The matcher compared the
`*` literally, so that form died with "Worktree not found" — only a full
literal branch name resolved.
2. Downstream consumers got the shorthand, not the ref. `gh pr list --head`,
`git branch -D` and `git push origin --delete` all match EXACTLY:
gh pr list --head 817 -> (empty) => "PR not merged"
gh pr list --head feature/817-...-ins -> MERGED
The merge check therefore reported "not merged" for a merged PR on every
shorthand invocation. Worse, `git branch -D` and `git push origin --delete`
are `|| true`-suppressed, so they failed INVISIBLY: the script printed
"Cleanup complete!" while leaving both branches behind. Observed live during
#817's post-merge cleanup, which required a manual `git branch -D`.
The merge-check symptom matters beyond the false alarm: a warning that fires on
every invocation carries no signal and makes --yes/--force the mandatory
incantation, which re-arms the exact bypass reflex #750 removed. #750 built
that gate; this silently disarmed it.
Both are fixed by resolving path AND ref in one pass. The awk is replaced with
bash `case`, so glob matching is native (no regex-escaping dance) and both
accepted forms are one test:
*"$BRANCH_NAME"* quoted -> literal substring (`838`)
$BRANCH_NAME unquoted -> shell glob (`feature/838-*`)
`while IFS= read -r` preserves whitespace in paths (#575's hardening — covered
by a dedicated test). `mapfile` is avoided: macOS ships bash 3.2.
New __tests__/cleanup-worktree-branch-resolution.integration.test.ts drives the
real script against a real throwaway repo with a real worktree and a real bare
origin, with `gh` stubbed on PATH to emulate --head's exact-match semantics.
Every assertion is parametrized over all three input forms, so a fix that only
handles one of them fails. #750's protections are asserted in both directions:
an unmerged PR still refuses non-interactively, and still skips the remote
delete under --yes.
16 tests pass.
… usage/--help The shorthand and glob forms both resolve now, but usage said only `<branch-name>` and showed a single full-name example — so the affordances stay undiscovered and the docs keep implying the full name is required. Header comment and print_usage list all three, kept in sync as the file already requires.
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.shmatched the worktree by literal substring and then handed the caller's raw argument to every downstream consumer. Two defects, same three lines.1. The documented invocation never worked.
fullsolve/SKILL.md:676,exec/SKILL.md:524anddocs/troubleshooting.md:46all prescribecleanup-worktree.sh feature/<issue-number>-*. The matcher compared the*as a literal character, so that form exited with❌ Error: Worktree not found. Verified against the live repo:2. Downstream consumers got the shorthand, not the ref.
gh pr list --head,git branch -Dandgit push origin --deleteall match exactly:So the merge check reported "not merged" for a merged PR on every shorthand invocation. Worse, the two branch deletes are
|| true-suppressed, so they failed invisibly — the script printed✅ Cleanup complete!while leaving both local and remote branches in place.Both were observed live during #817's post-merge cleanup: the not-merged warning fired ~90s after the PR merged, and the local branch survived and needed a manual
git branch -D.Why the merge-check symptom matters beyond a false alarm
#750 built that gate precisely because agents were piping
echo y |past it. A warning that fires on every invocation carries no signal and makes--yes/--forcethe mandatory incantation — which re-arms the exact bypass reflex #750 removed. The gate was functionally back to advisory, with no code regression to point at.Change
Resolve path and ref in one pass, then use
$RESOLVED_BRANCHeverywhere downstream. The awk is replaced with bashcase, so glob matching is native and no regex-escaping dance is needed — both accepted forms collapse into one test:while IFS= read -rpreserves whitespace in paths (#575's hardening, covered by a dedicated test).mapfileis deliberately avoided — macOS ships bash 3.2.Usage/
--helpand the header comment now document all three accepted forms, since previously only the full branch name was shown and the other two were undiscoverable.Test plan
New
__tests__/cleanup-worktree-branch-resolution.integration.test.tsdrives the real script against a real throwaway git repo with a real worktree and a real bareorigin, withghstubbed onPATHto emulate--head's exact-match semantics. Every assertion is parametrized over all three input forms, so a fix handling only one of them fails.#750's protections are asserted in both directions: an unmerged PR still refuses non-interactively, and still skips the remote delete under
--yes.bash -nsyntax check--helpoutput verified__tests__/sweep: 63 files, 1148 tests, 0 failuresMutation record (per the CLAUDE.md gate-test rule)
Each mutation applied to the committed fix, then reverted and re-confirmed green:
| $BRANCH_NAMEglob arm--head "$BRANCH_NAME"git branch -D "$BRANCH_NAME"BRANCH_NAME == RESOLVED_BRANCH)Note
The new test is subprocess- and git-heavy (~30s added to the integration project). It is parametrized 3 forms × 5 behaviors because the ACs require exactly that matrix; if the integration suite's runtime becomes a problem, collapsing the three merged-path assertions into one per form is the obvious trim.
Closes #838