Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): worktree cleanup no longer deletes files hidden by showUntrackedFiles=no #15834

MergedSunkenInTime(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/15834/headmerged by juliusmarminge View on GitHub

Automatic 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 worktree about 6 s later, and the worktree and notes.txt were gone.
  • After: removeWorktree logged git worktree remove exited with code 128 on each sweep, and the worktree and notes.txt stayed.

Tests in GitVcsDriverCore.test.ts:

  • New: "keeps a worktree whose untracked files status is configured to hide". It hides notes.txt from status, checks status reports clean, and asserts that removeWorktree fails and the file is intact. It fails without the -c flag and passes with it.
  • Two existing tests matched the exact arguments: one counted 3 arguments (now 5), one matched args[0] === "worktree" (now matches worktree remove anywhere in the arguments).
  • apps/server: vp test run src/vcs/GitVcsDriverCore.test.ts -t worktree, 18 passed. tsc --noEmit in apps/server: clean. vp lint on 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

    2. Approvability

      Verdict: Approved at c20f53c

      Macroscope'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).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      • apps/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

      removeWorktree now checks untracked files even when repository configuration sets status.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.ts
      removeWorktree runs git worktree remove with status.showUntrackedFiles=normal. Tests check the updated command arguments and verify that removal fails while an untracked file remains when status.showUntrackedFiles=no.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to c20f5

      Worktree 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 c20f5

      The change affects 1 system.

      Changed systems: apps/server

      Architecture 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 untracked notes.txt remains.
      • 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 matching worktree and remove as the first two arguments.
      • observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.ts: removeWorktree adds a comment describing how status.showUntrackedFiles=no can hide untracked files from Git’s removal check, and adds -c status.showUntrackedFiles=normal to the removal command. The command now checks untracked files regardless of that setting.
      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Docstring Coverage✅ PassedNo 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✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly describes the fix: worktree cleanup no longer deletes files hidden by the Git status setting.
      Description check✅ PassedThe 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.
    4. juliusmarminge merged thisd9068d3

    5. juliusmarminge closed this

Sign in to join this conversation.