Skip to content

fix(git): a worktree that lost its .git no longer fails the gather (#368) - #372

Merged
baldurpan merged 5 commits into
mainfrom
368-remove-list-and-cleanup-fail-when-a-worktree
Nov 25, 2026
Merged

baldurpan merged 5 commits into
mainfrom
368-remove-list-and-cleanup-fail-when-a-worktree

Conversation

@baldurpan

Copy link
Copy Markdown
Contributor

Closes #368

What changed

  • parseWorktreeRecords (src/lib/git.ts) now reads git's prunable line. gitGetWorktrees reports a prunable record as pathExists: false, so none of the git probes (status -s, ahead and behind counts, churn) run in a directory with no .git. One broken entry no longer fails list, remove or cleanup.
  • gitNukeWorktreeCmd runs git worktree prune instead of git worktree remove when the directory has no .git, then deletes the branch. The directory is left on disk: without .git its contents can't be checked for uncommitted work.
  • A new label, missingPathDetail (src/lib/utils.ts), used by list and by cleanup's reasons: such an entry reads Not a git checkout (.git missing), directory kept. A directory that is really gone still reads Path does not exist.
  • Docs: list.mdx (the pathExists and uncommittedChanges rows), cleanup.mdx (the reason vocabulary) and a new section in remove.mdx.
  • Release note: .changeset/prunable-worktree-entry.md (patch).

The issue left one decision open: whether remove should also delete the directory. This change answers no, and drops only git's record and the branch.

Gates

  • Gate 1: every section of context/verify.md passed: pnpm check, typecheck, docs typecheck, build, docs:build, worker:bundle-check, docs:audit-dist, test (4,132 passed), docs:test, and the test-marker check.
  • Gate 2: the reviewer subagent. Loop 1 failed because the docs no longer matched the code; fixed. Loop 2 passed with notes. Two of its notes are fixed here: the "five reasons" count in cleanup.mdx, and a test that pins the new label.

Out of scope (from the review, not fixed here)

  • A locked worktree that loses its .git is not marked prunable by git, so it would still fail the gather.
  • gitFindBranchCheckout does not read prunable, so worktree branch <name> on such a record still treats the broken directory as a checkout.

)

git lists such a record as prunable. It is now read from the porcelain
output and treated as a missing path, so no probe runs in the directory
and list, remove and cleanup no longer fail on it. Removal prunes git's
record and deletes the branch; the directory is left on disk and is
labelled "Not a git checkout (.git missing), directory kept".

Closes #368

@baldurs-reviewer baldurs-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code-reviewer: minor issues

This change reads git's prunable annotation so a worktree whose directory has lost its .git is treated as a missing path. As a result, list, remove and cleanup no longer run git probes in it. On removal it prunes the record instead of running git worktree remove, and leaves the directory in place. The fix for the reported failure looks correct, and the parser and nuke changes are tested. The main concern is that cleanup (including --force) will now sweep such a worktree and git branch -D its branch without counting unpushed commits, even though they could be counted from the main repository. Two smaller points: the removal progress bar measures a directory it never deletes, and a few doc sentences outside the edited rows are now out of date.


Reviewed f79c1a9 for baldurpan · claude-opus-5-5 · 10 files · $0.44

Comment thread src/lib/git.ts Resolved
Comment thread src/lib/git.ts Resolved
Comment thread docs/src/content/docs/commands/list.mdx Resolved
…368)

Review of #372: treating a prunable record as a missing path let cleanup
`branch -D` it without counting its commits. Its branch and HEAD are still
in git's records, so the commits are now counted from the repository, and
the record clears isSafeToRemove only on that count. Removal progress no
longer walks a directory it keeps, and the docs that still said "gone" or
"present" are brought in line.

@baldurs-reviewer baldurs-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code-reviewer follow-up: minor issues

Since the last review, this push takes the ahead count for prunable records from the repository (branch ref, upstream, or the recorded HEAD for a detached record) and runs the merged probe the same way. isSafeToRemove no longer waves prunable entries through, removal progress skips a kept directory, and the docs are reworded to match. All three earlier comments are addressed, and the new tests pin the held-back, upstream and detached cases. One thing remains: git also marks a worktree whose directory is gone entirely as prunable, which widens the behaviour change beyond the .git-only case and leaves parts of the docs untrue.

Earlier comments


Reviewed b27ff5e (changes since f79c1a9) for baldurpan · claude-opus-5-5 · 6 files · $0.27

Comment thread src/lib/git.ts Resolved
…368)

Review of #372: git also marks a record prunable when its whole directory
is gone, so b27ff5e started counting and holding back deleted directories
too, against what the docs say. Only a prunable record whose directory is
still on disk is marked now; a gone one is uncounted and safe, as before.

@baldurs-reviewer baldurs-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code-reviewer follow-up: looks good

Since the last review, gitGetWorktrees marks a record prunable (and carries its head) only when git calls it prunable and its directory is still on disk. A worktree whose directory is gone therefore keeps its old verdict: no probe, ahead undefined, safe to remove. New tests cover both cases at the gitGetWorktrees level, and one checks at the gather level that no rev-list runs and the entry stays safe. The comments in git.ts and types.ts now match, and I found nothing new to raise.

Earlier comments


Reviewed bd1e559 (changes since b27ff5e) for baldurpan · claude-opus-5-5 · 3 files · $0.16

@baldurpan
baldurpan merged commit 64bc6a8 into main Nov 25, 2026
2 checks passed
@baldurpan
baldurpan deleted the 368-remove-list-and-cleanup-fail-when-a-worktree branch November 25, 2026 12:40
baldurpan added a commit that referenced this pull request Nov 25, 2026
#372's cleanup.mdx edit ranks /commands/cleanup/ first for reworded-cleanup-merged-prs
(was second), so retrieval.mrr moves 0.7 -> 0.719.
This was referenced Nov 25, 2026
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.

remove, list and cleanup fail when a worktree directory has lost its .git file

1 participant