perf(worktrees): delete worktree directories after the removal returns (#12416)
* perf(worktrees): delete worktree directories after the removal returns `git worktree remove` deleted the whole checkout inline, so the remove IPC held the watcher/PTY gate for the entire recursive delete (prod traces: worktree.remove.git_remove p50 8-14s, p90 29s, max 34.7s). Local removals now rename the checkout into a hidden sibling trash root, clear Git's registration for the missing path, and delete the moved tree in the background. Renames that cannot run (WSL, other volume, Windows open handles) fall back to the previous in-place removal unchanged. * test(worktrees): keep no empty trash root when the rename cannot run * fix(worktrees): harden deferred trash cleanup * fix(worktrees): keep WSL trash on its owning host
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { execFile } from 'node:child_process'
|
||||
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||
import { mkdtemp, rename, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { promisify } from 'node:util'
|
||||
@@ -137,6 +137,19 @@ describeBinaryCompatibility('real Git binary compatibility', () => {
|
||||
).resolves.toBeDefined()
|
||||
})
|
||||
|
||||
it('deregisters a worktree whose directory was renamed away', async () => {
|
||||
// Orca renames the checkout into a trash directory and then clears the registration, so every
|
||||
// supported Git must accept `worktree remove --force` on the now-missing path.
|
||||
await runGit(['worktree', 'add', '-b', 'compat-deferred', 'deferred-wt'])
|
||||
await rename(join(repoPath, 'deferred-wt'), join(repoPath, 'deferred-trash'))
|
||||
|
||||
await expect(runGit(['worktree', 'remove', '--force', 'deferred-wt'])).resolves.toBeDefined()
|
||||
|
||||
const remaining = await runGit(['worktree', 'list', '--porcelain'])
|
||||
expect(remaining.stdout).not.toContain('deferred-wt')
|
||||
await rm(join(repoPath, 'deferred-trash'), { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('recognizes ref and merge-tree compatibility boundaries', async () => {
|
||||
await expectPreferredOrRecognizedFallback(
|
||||
['for-each-ref', '--format=%(refname)', '--exclude=refs/remotes/**/HEAD', '--count=10'],
|
||||
|
||||
Reference in New Issue
Block a user