cdd-worktree-resume: prune stale remote branches from discovery#45
Merged
Conversation
`cdd-worktree-resume` fetched with a plain `git fetch origin`, which leaves remote-tracking refs for branches deleted on the remote. GitHub deletes a PR's head branch when it merges, so those already-landed branches lingered in the no-argument discovery list. Switch to `git fetch --prune origin` so discovery shows exactly what still exists on the remote — the default branch plus live feature branches (with or without a PR yet) — which is also what makes an explicit resume of a merged-and-deleted branch fail cleanly at the existing show-ref check. Extend worktree-resume-assert.sh: clone before deleting a branch on the bare origin (so the stale ref exists locally), then assert discovery prunes it and an explicit resume of it is refused without creating a worktree. cdd-worktree-done is left unchanged: run as the sourced function (the installed, interactive case) it already cd's to the main worktree before removing the feature one, which is correct. The not-sourced PATH-shim case can't propagate a cd out of a subshell by OS design, but that is a shell-setup concern, not something to paper over here. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
e0b0e73 to
f117121
Compare
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
cdd-worktree-resumenow runsgit fetch --prune origin(wasgit fetch origin) before discovering resumable branches. GitHub deletes a PR's head branch when it merges, but the staleorigin/<branch>remote-tracking ref lingers locally until pruned. Without--prune, discovery listed merged-and-deleted branches as resumable candidates, and an explicit resume of such a branch would succeed against a dead ref.With
--prune, both code paths exclude those branches for free:for-each-ref refs/remotes/origin) no longer lists the pruned branch.show-ref --verify origin/<branch>) fails with a clearer two-line message pointing at merge-deletion or a never-pushed branch.Changes
tools/cdd-worktree.sh—git fetch --prune origin; refreshed comments and the explicit-resume error message.doc/knowledge_base/claude-driven-development.md— §2.8 now documents that discovery lists exactly the live remote branches.scripts/worktree-resume-assert.sh— two new smoke checks: discovery prunes a remote-deleted branch, and explicit resume of one is refused without creating a worktree or launching claude.Verification
All CI gates pass locally:
bash -n, command-set drift, prompt seams, install smoke, worktree-resume smoke (incl. the two new checks), end-to-end bootstrap smoke, and demo seed-overlay smoke. No upstream drift.🤖 Generated with Claude Code