fix(worktrees): keep WSL trash on its owning host

This commit is contained in:
Brennan Benson
2026-08-04 01:44:06 -07:00
parent 99690aadb5
commit df09d69e7c
4 changed files with 32 additions and 3 deletions
+18
View File
@@ -489,6 +489,24 @@ branch refs/heads/main
expect(getGitCalls()).toContain('git worktree remove /repo-feature')
})
it('does not rename a WSL checkout configured for a native Windows repo', async () => {
const originalPlatform = process.platform
const worktreePath = '\\\\wsl.localhost\\Ubuntu\\home\\dev\\feature'
Object.defineProperty(process, 'platform', { configurable: true, value: 'win32' })
try {
mockGitCommands({})
await removeWorktree('C:\\repo', worktreePath, false, {
knownRemovedWorktree: { branch: '', head: '', locked: false }
})
expect(moveWorktreeDirectoryToTrashMock).not.toHaveBeenCalled()
expect(getGitCalls()).toEqual([`git worktree remove ${worktreePath}`])
} finally {
Object.defineProperty(process, 'platform', { configurable: true, value: originalPlatform })
}
})
it('passes one --force before the worktree path for dirty-file removal', async () => {
mockGitCommands({
'git worktree list --porcelain': {
+2 -1
View File
@@ -13,6 +13,7 @@ import {
restoreWorktreeDirectoryFromTrash,
scheduleWorktreeTrashDeletion
} from '../worktree-trash'
import { parseWslPath } from '../wsl'
import type {
GitWorktreeInfo,
LocalBaseRefRefreshResult,
@@ -1187,7 +1188,7 @@ async function tryRemoveWorktreeWithDeferredDirectoryDeletion(
options: RemoveWorktreeOptions
): Promise<boolean> {
// Why: WSL-owned checkouts are deleted inside the distro, so Node on Windows must not rename them.
if (options.wslDistro) {
if (options.wslDistro || parseWslPath(worktreePath)) {
return false
}
if (!force) {