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
This commit is contained in:
1 parent
2c7c0cba22
commit
416e20d292
2 files changed
+32
-1
No files matched your search
+8
-1
@@ -1042,7 +1042,14 @@ async function listedWorktrees(cwd: string): Promise<GitWorktreeRecord[]> {
|
||||
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) }))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 },
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user