test(worktrees): keep no empty trash root when the rename cannot run

This commit is contained in:
Brennan Benson
2026-08-03 20:50:34 -07:00
parent a19d7d3843
commit 5775bbc3e6
2 changed files with 8 additions and 3 deletions
+5 -2
View File
@@ -56,8 +56,11 @@ describe('moveWorktreeDirectoryToTrash', () => {
}
})
it('reports the rename as unavailable when the checkout is missing', async () => {
expect(await moveWorktreeDirectoryToTrash(join(scratchDir, 'repo', 'gone'))).toBeUndefined()
it('reports the rename as unavailable and leaves no trash root when the checkout is missing', async () => {
const worktreePath = join(scratchDir, 'repo', 'gone')
expect(await moveWorktreeDirectoryToTrash(worktreePath)).toBeUndefined()
expect(existsSync(getWorktreeTrashRoot(worktreePath))).toBe(false)
})
async function seededWorktree(name: string): Promise<string> {
+3 -1
View File
@@ -3,7 +3,7 @@
// is a metadata operation, and the recursive delete then runs after the IPC has already returned.
import { randomBytes } from 'node:crypto'
import { mkdir, readdir, rename } from 'node:fs/promises'
import { mkdir, readdir, rename, rmdir } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import { removeHostTree } from './host-tree-removal'
import { isFolderRepo } from '../shared/repo-kind'
@@ -46,6 +46,8 @@ export async function moveWorktreeDirectoryToTrash(
`[worktrees] Deferred deletion unavailable for ${worktreePath}; deleting in place`,
error
)
// Leave no empty trash root behind when the rename never happened; rmdir keeps queued entries.
await rmdir(trashRoot).catch(() => {})
return undefined
}
}