Repository navigation
fix(storage): remove Windows worktrees outside their cwd - #2424
Merged
Merged
Conversation
28 of 37 tasks
jackwener
approved these changes
Aug 7, 2026
jackwener
left a comment
Member
There was a problem hiding this comment.
Adversarial review — approve & merge
Root cause
runGit uses git -C <cwd> …, and Git chdirs into that path. On Windows, a process cannot delete its own current directory, so:
git -C <worktree> worktree remove --force <worktree>
fails when removing the worktree that is the process cwd.
Fix
Keep clean / detach / lease-branch delete on the worktree (they need the checkout), then run only the final:
git -C <gitCommonDir> worktree remove --force <path>
gitCommonDir is the resolved absolute common dir (realpath of --git-common-dir), already used for repository allocation serialization — outside the worktree being deleted.
Checked
| Concern | Result |
|---|---|
| Correct Git context | git -C <commonDir> is a valid repo entry point; verified worktree remove from common dir works |
| Path identity | Same absolute path as before; registration path from provision unchanged |
| Ordering / semantics | clean → detach → clean → branch -D → remove preserved |
| Lease branch only | Child-switched branches still preserved (existing test) |
| Orphan recovery | Uses inspected.gitCommonDir; same call path |
| Allocation lock | Still under withRepositoryAllocation(gitCommonDir) |
| Injection | execFile argv array; no shell |
| Partial failure | Pre-existing: branch may be deleted if remove fails mid-way — not introduced |
| Unix regression | Superset behavior; POSIX still fine (cwd restriction is Windows-specific) |
Validation
- CI green including windows_baseline
- Local: both named tests pass after rebuild
No blocking issues. LGTM.
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.
Summary
git worktree removefrom the stable Git common directoryCloses two failures tracked by #2142:
retires only the Host lease branch after a child switches branchesrecovery preserves live bindings and retires orphaned worktreesValidation
@maka/storagebuild6/6)git diff --checkThe complete test file separately observed a temp-root cleanup
EBUSYin an unrelated availability test. This PR does not add broad filesystem retries or claim to address that independent cleanup failure.