Skip to content

fix(loop-worktree): don't crash gc() when a worktree dir was removed out-of-band - #518

Open
KhaiTrang1995 wants to merge 1 commit into
cobusgreyling:mainfrom
KhaiTrang1995:fix/loop-worktree-gc-orphan-realpath
Open

fix(loop-worktree): don't crash gc() when a worktree dir was removed out-of-band#518
KhaiTrang1995 wants to merge 1 commit into
cobusgreyling:mainfrom
KhaiTrang1995:fix/loop-worktree-gc-orphan-realpath

Conversation

@KhaiTrang1995

Copy link
Copy Markdown
Contributor

Problem

gc()'s gitWorktreePaths() calls realpath() on every path reported by
git worktree list --porcelain with no error handling. git keeps
listing a worktree (annotated "prunable") even after its directory is
gone -- a manual rm -rf, a crash mid-cleanup, a container wipe --
rather than removed via git worktree remove. realpath() on that
now-missing path throws ENOENT, which propagated out of gc() entirely
instead of surfacing the entry as dropped, aborting the exact
reconciliation gc() exists to perform.

Fix

Treat a missing directory as simply absent from disk instead of
letting the exception escape. The manifest entry (if any) is now
correctly reconciled as dropped.

Test plan

Added a regression test that deletes a worktree directory directly
(bypassing git worktree remove) and asserts gc() completes and
reports it as dropped. Full clean rebuild + npm test: 36/36 passing.

…out-of-band

gitWorktreePaths() called realpath() on every path from `git worktree
list --porcelain` with no error handling. git keeps listing a worktree
(annotated "prunable") even after its directory is gone -- a manual
rm -rf, a crash mid-cleanup, a container wipe -- rather than removed
via `git worktree remove`. realpath() on that missing path throws
ENOENT, which propagated out of gc() entirely instead of letting the
entry surface as `dropped`, aborting the exact reconciliation gc()
exists to perform.

Treat a missing directory as simply absent from disk instead of
crashing. Adds a regression test that deletes a worktree directory
directly (bypassing git worktree remove) and asserts gc() still
completes and reports it as dropped.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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