From 416e20d292b395fe2eaa2af9798ee4889cafd461 Mon Sep 17 00:00:00 2001 From: xucl Date: Mon, 16 Nov 2026 14:13:12 +0800 Subject: [PATCH] fix(git): re-spell the linked worktrees a WSL repository lists `git worktree list` prints the same POSIX spelling as `rev-parse --show-toplevel` when it runs inside the distribution, so in a WSL workspace every linked checkout arrived as `/home/...`. That broke the worktree selector in two ways at once: `current` compared a POSIX entry against the now-UNC current root and never matched (so no checkout was marked as the current one), and `resolveWorktree` handed the POSIX entry back as a command target, which the Windows git then refused. Re-spell in `listedWorktrees()`, the single place both the inventory (`worktrees()`) and the selector (`resolveWorktree()`) read from. Refs #1189 --- src/git.ts | 9 ++++++++- tests/git-spawn.spec.ts | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/git.ts b/src/git.ts index 169a915c..8faab6f0 100644 --- a/src/git.ts +++ b/src/git.ts @@ -1042,7 +1042,14 @@ async function listedWorktrees(cwd: string): Promise { raw = await runGit(cwd, ['worktree', 'list', '--porcelain']) } } - return parseWorktreeList(raw).filter(entry => !entry.prunable) + return parseWorktreeList(raw) + .filter(entry => !entry.prunable) + // Every path in this listing was printed by the git that ran in `cwd`, so a + // linked checkout of a WSL workspace arrives POSIX-spelled exactly like the + // main root does. Re-spell them HERE, the one place both the inventory and + // the selector read from: a POSIX entry would neither match the current + // root nor survive as a command target (issue #1189). + .map(entry => ({ ...entry, path: wslRootSpelling(cwd, entry.path) })) } /** diff --git a/tests/git-spawn.spec.ts b/tests/git-spawn.spec.ts index 78034d92..a28e0797 100644 --- a/tests/git-spawn.spec.ts +++ b/tests/git-spawn.spec.ts @@ -438,4 +438,28 @@ describe('a repository root reported from inside a WSL distribution (issue #1189 expect(spawnMock.mock.calls.every(call => call[0] === 'git')).toBe(true) }) + + it('re-spells every linked checkout the distribution listed', async () => { + spawnMock.mockImplementation((_file: string, args: string[]) => { + const command = subcommandOf(args) + if (command[0] === 'rev-parse' && command[1] === '--is-inside-work-tree') return fakeGit('true\n') + if (command[0] === 'rev-parse' && command[1] === '--show-toplevel') return fakeGit('/home/me/linked\n') + if (command[0] === 'worktree') { + return fakeGit([ + 'worktree /home/me/linked', 'HEAD abc', 'branch refs/heads/main', '', + 'worktree /home/me/linked-feature', 'HEAD def', 'branch refs/heads/feature', '', + ].join('\n')) + } + if (command[0] === 'status') return fakeGit('') + throw new Error(`unexpected git command: ${command.join(' ')}`) + }) + + // A POSIX-spelled checkout is not usable as a command target either: the + // current one must still be recognised as current (it drives the selector) + // and every entry must be a path this host can run git in. + await expect(worktrees(unc('/home/me/linked'))).resolves.toEqual([ + { path: unc('/home/me/linked'), branch: 'main', current: true, changes: 0 }, + { path: unc('/home/me/linked-feature'), branch: 'feature', current: false, changes: 0 }, + ]) + }) })