Skip to content

Add worktree retire for unmerged work the owner gives up - #486

Open
BunsDev wants to merge 1 commit into
mainfrom
worktree-retire
Open

BunsDev wants to merge 1 commit into
mainfrom
worktree-retire

Conversation

@BunsDev

@BunsDev BunsDev commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

prune can only remove work it proves merged, so abandoned branches (closed PRs, superseded stacks, experiments) pile up forever. At last count, 47 of 48 local worktrees were kept.

scripts/worktree.sh retire <branch> --expect-head <SHA> [--apply] [--by <who>] swaps merge proof for a verified snapshot:

  • Dirty tracked and untracked files go into a snapshot commit on top of the tip. It is built in a temporary index, so the real index is untouched.
  • Unknown ignored data (.env, .probes, logs) goes into ignored.tar (mode 0600) beside the bundle.
  • The snapshot goes through the existing archive() path: bundle, restore into an empty bare repo, fsck --full, manifest.
  • It still refuses: primary/default branch, open PR, active process, Git operation in progress or a stale marker, locks, hidden index entries, locked or unmanaged worktree, and a tip that differs from --expect-head.
  • After archiving it repeats every observation, then resets, runs a non-forced worktree remove, deletes the branch by expected SHA, and writes a retired ownership record.
  • It never touches remote branches.

Documented in docs/worktree-hygiene.md, with a pointer in AGENTS.md.

Test plan

  • node --test scripts/test/*.test.mjs: 129 pass, including 9 new retire tests (dry run, dirty, untracked and ignored snapshot round-trip through a restored repo, clean retire, and refusals for open PR, head mismatch, active process, operation marker, locked worktree, main)
  • CI unit + e2e (macOS)

🤖 Generated with Claude Code

prune keeps unmerged work forever because it has no merge proof. retire replaces
that proof with a verified snapshot: dirty tracked and untracked files become a
commit on the tip (built in a temporary index), unknown ignored data becomes a
0600 ignored.tar, and both go through the existing bundle/restore/fsck archive.
Open PRs, active processes, Git operations, locks, hidden index entries and a
moved tip still preserve the work. Removal stays non-forced and the branch is
deleted by expected SHA.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
modex Ready Ready Preview Nov 1, 2026 8:24pm UTC

Request Review

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: TypeScript

TypeScript / code-coverage-agent

main 66d0031 worktree-retire b896d44 +/-
66% 66% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

This branch was successfully deployed

1 active deployment
Preview — b896d44c Deployed Nov 1, 2026 by vercel[bot]
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