fix(server): worktree cleanup no longer deletes files hidden by showUntrackedFiles=no #15834
main fromrefs/pull/15834/head·merged by juliusmarminge View on GitHubAutomatic worktree cleanup deleted an uncommitted file because git status was configured not to show it. With this change Git refuses the removal and the file survives:
before (main at 2a45557) after
$ git status --porcelain # looks clean $ git status --porcelain # looks clean
$ cat notes.txt $ cat notes.txt
half-written migration plan half-written migration plan
... thread deleted, cleanup runs ... ... thread deleted, cleanup runs ...
$ ls t3code-a7870ac9 WARN GitVcsDriver.removeWorktree: git worktree
No such file or directory remove exited with code 128 for ...t3code-c5e48d49
$ ls t3code-c5e48d49
.git .gitignore README.md notes.txt
Problem#
git worktree remove without --force refuses a worktree that has untracked files. That check runs git status, so it honors status.showUntrackedFiles. People set that to no to speed up status in large repos. Then status reports new files as clean, Git's own check sees nothing, and git worktree remove exits 0 and deletes them. I checked this with Git 2.55 directly.
This hits automatic cleanup, which trusts git status before removing and calls git worktree remove without --force. The web client's own worktree removal already passes force: true, so it isn't affected either way.
Change#
removeWorktree runs git -c status.showUntrackedFiles=normal worktree remove. The setting reaches Git's internal status check, so Git refuses the removal (exit 128) the same way it does for anyone else with untracked files. Doing it at removal time means a file created after cleanup's own checks is covered too. With --force Git skips the check, so forced removals behave as before.
Cleanup already handles a failed removal. It logs the refusal and keeps the worktree, and the warning names the worktree on each sweep.
Scope and approval#
A bug fix, so no prior approval is needed: automatic cleanup deletes uncommitted files that status.showUntrackedFiles=no hides from git status. It changes only the arguments removeWorktree passes to git worktree remove. It was split out of #15434 so each PR fixes one problem.
Verification#
Live run on a dev server (Windows 11, Git 2.55.0.windows.1), main at 2a45557 with and without only this change. A scratch repo with a remote, a thread in a new worktree, git config --worktree status.showUntrackedFiles no, and an uncommitted notes.txt. Settings → Storage → "Delete worktrees with deleted threads" on, then the thread deleted from the sidebar.
- Before: cleanup logged
storage cleanup removed worktreeabout 6 s later, and the worktree andnotes.txtwere gone. - After:
removeWorktreeloggedgit worktree remove exited with code 128on each sweep, and the worktree andnotes.txtstayed.
Tests in GitVcsDriverCore.test.ts:
- New: "keeps a worktree whose untracked files status is configured to hide". It hides
notes.txtfrom status, checks status reports clean, and asserts thatremoveWorktreefails and the file is intact. It fails without the-cflag and passes with it. - Two existing tests matched the exact arguments: one counted 3 arguments (now 5), one matched
args[0] === "worktree"(now matchesworktree removeanywhere in the arguments). apps/server:vp test run src/vcs/GitVcsDriverCore.test.ts -t worktree, 18 passed.tsc --noEmitinapps/server: clean.vp linton the changed files: one existing warning on a line this PR doesn't touch.
Not covered: the inactive, merged and unchanged rules currently skip any thread whose last turn completed (#15146, fixed by #15150), so the live run used the delete rule. The fix is in the removal itself, so it applies to every rule.
Split out of #15434, which keeps the change to which ignored files block cleanup.
Claude Opus 5.5 in Claude Code (via T3 Code).
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e98f1abc-537e-45c0-8e63-6f86e9d7ff4b
📥 Commits
Reviewing files that changed from the base of the PR and between f729e0ebfe7578860585a77ddde8f008e30c2351 and c20f53c23a84a34099602ffb8c580d4979671d06.
📒 Files selected for processing (2)
apps/server/src/vcs/GitVcsDriverCore.test.tsapps/server/src/vcs/GitVcsDriverCore.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough#
removeWorktreenow checks untracked files even when repository configuration setsstatus.showUntrackedFiles=no. Tests verify that removal fails and preserves an untracked file in that configuration.Changes#
Worktree Removal Check
Layer / File(s) Summary Override hidden untracked-file setting
apps/server/src/vcs/GitVcsDriverCore.ts,apps/server/src/vcs/GitVcsDriverCore.test.tsremoveWorktreerunsgit worktree removewithstatus.showUntrackedFiles=normal. Tests check the updated command arguments and verify that removal fails while an untracked file remains whenstatus.showUntrackedFiles=no.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
c20f5Worktree cleanup now preserves untracked files hidden by repository configuration, while clean removal remains covered. No actionable merge risk remains.
Architecture Summary#
Architecture risk: 🔵 Low · up to
c20f5The change affects 1 system.
Changed systems:
apps/serverArchitecture concerns No architecture-level concerns identified.
Review details
Systems and components
- observed — apps/server (service) was modified; 2 changed files map to changed impact.
Before / after behavior
- observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.test.ts: The removal failure assertion now expects five command arguments rather than three.
- observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.test.ts: Adds a test that creates a worktree, hides untracked files via
status.showUntrackedFiles=no, and verifies removal fails while the untrackednotes.txtremains. - observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.test.ts: The delayed-removal test now identifies the command by searching its joined arguments for
"worktree remove"instead of separately matchingworktreeandremoveas the first two arguments. - observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.ts:
removeWorktreeadds a comment describing howstatus.showUntrackedFiles=nocan hide untracked files from Git’s removal check, and adds-c status.showUntrackedFiles=normalto the removal command. The command now checks untracked files regardless of that setting.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2… Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Title check ✅ Passed The title clearly describes the fix: worktree cleanup no longer deletes files hidden by the Git status setting. Description check ✅ Passed The description covers the problem, change, scope and approval rationale, and verification results. It also identifies the untested cleanup rules and the agent used. ✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge merged thisd9068d3
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Approved at
c20f53cMacroscope's review found this PR approvable — This is a focused server-side bug fix that makes Git’s non-forced worktree safety check ignore hidden-untracked-file settings, preventing accidental file deletion. The accompanying integration test covers the affected scenario, and no product defaults or static-analysis suppressions are changed.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).