Skip to content

cdd-worktree-resume: prune stale remote branches from discovery#45

Merged
drabaioli merged 1 commit into
mainfrom
worktree_done_cd_and_resume_filter
Jul 3, 2026
Merged

cdd-worktree-resume: prune stale remote branches from discovery#45
drabaioli merged 1 commit into
mainfrom
worktree_done_cd_and_resume_filter

Conversation

@drabaioli

@drabaioli drabaioli commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

cdd-worktree-resume now runs git fetch --prune origin (was git fetch origin) before discovering resumable branches. GitHub deletes a PR's head branch when it merges, but the stale origin/<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:

  • Discovery (for-each-ref refs/remotes/origin) no longer lists the pruned branch.
  • Explicit resume (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.shgit 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

`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>
@drabaioli drabaioli changed the title cdd-worktree-resume: prune stale remote branches from discovery Worktree helper: fix cdd-worktree-done stranding + prune landed branches from resume Jul 3, 2026
@drabaioli drabaioli force-pushed the worktree_done_cd_and_resume_filter branch from e0b0e73 to f117121 Compare July 3, 2026 22:07
@drabaioli drabaioli changed the title Worktree helper: fix cdd-worktree-done stranding + prune landed branches from resume cdd-worktree-resume: prune stale remote branches from discovery Jul 3, 2026
@drabaioli drabaioli merged commit f4662ab into main Jul 3, 2026
2 checks passed
@drabaioli drabaioli deleted the worktree_done_cd_and_resume_filter branch July 3, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant