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
Open
Conversation
…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>
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.
Problem
gc()'s gitWorktreePaths() calls realpath() on every path reported by
git worktree list --porcelainwith no error handling. git keepslisting 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 thatnow-missing path throws ENOENT, which propagated out of gc() entirely
instead of surfacing the entry as
dropped, aborting the exactreconciliation 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 andreports it as dropped. Full clean rebuild + npm test: 36/36 passing.