fix(git): enable long paths when creating Windows worktrees

This commit is contained in:
hwantage
2026-08-21 22:54:01 -07:00
committed by Neil
parent 2b1254d681
commit e1fb40f3a9
2 changed files with 42 additions and 1 deletions
@@ -99,6 +99,43 @@ describe('addWorktree', () => {
])
})
it('enables long paths for native Windows worktree creation', async () => {
const platform = vi.spyOn(process, 'platform', 'get').mockReturnValue('win32')
gitExecFileAsyncMock.mockResolvedValueOnce({ stdout: '' }) // worktree add
try {
await addWorktree('/repo', '/repo-feature', 'feature/test', 'feature/test', false, false, {
checkoutExistingBranch: true
})
expect(gitExecFileAsyncMock).toHaveBeenCalledWith(
['-c', 'core.longpaths=true', 'worktree', 'add', '/repo-feature', 'feature/test'],
{ cwd: '/repo', timeout: WORKTREE_ADD_TIMEOUT_MS }
)
} finally {
platform.mockRestore()
}
})
it('does not pass the Windows-only long-path option to WSL Git', async () => {
const platform = vi.spyOn(process, 'platform', 'get').mockReturnValue('win32')
gitExecFileAsyncMock.mockResolvedValueOnce({ stdout: '' }) // worktree add
try {
await addWorktree('/repo', '/repo-feature', 'feature/test', 'feature/test', false, false, {
checkoutExistingBranch: true,
wslDistro: 'Ubuntu'
})
expect(gitExecFileAsyncMock).toHaveBeenCalledWith(
['worktree', 'add', '/repo-feature', 'feature/test'],
{ cwd: '/repo', wslDistro: 'Ubuntu', timeout: WORKTREE_ADD_TIMEOUT_MS }
)
} finally {
platform.mockRestore()
}
})
it('bounds the worktree add call with a positive timeout (STA-1292 OneDrive stall guard)', async () => {
// Why: without a timeout, a OneDrive cloud-placeholder checkout can stall
// `git worktree add` for minutes. Assert the runner receives a non-zero
+5 -1
View File
@@ -975,7 +975,11 @@ async function performAddWorktree(
): Promise<AddWorktreeResult> {
let localBaseRefRefresh: LocalBaseRefRefreshResult | undefined
let localBaseRefUpdateSuggestion: LocalBaseRefUpdateSuggestion | undefined
const args = ['worktree', 'add']
// Why: enable long paths for this Windows checkout without changing user Git config.
const args =
process.platform === 'win32' && !options.wslDistro
? ['-c', 'core.longpaths=true', 'worktree', 'add']
: ['worktree', 'add']
let effectiveBase: string | undefined
if (noCheckout) {
args.push('--no-checkout')