From e1fb40f3a9689b0abe9f607797e8d3b566f24043 Mon Sep 17 00:00:00 2001 From: hwantage Date: Fri, 21 Aug 2026 22:20:46 +0900 Subject: [PATCH] fix(git): enable long paths when creating Windows worktrees --- .../git/worktree-add-creation-config.test.ts | 37 +++++++++++++++++++ src/main/git/worktree.ts | 6 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/git/worktree-add-creation-config.test.ts b/src/main/git/worktree-add-creation-config.test.ts index f6b3d0d51d6..1499d8f24ae 100644 --- a/src/main/git/worktree-add-creation-config.test.ts +++ b/src/main/git/worktree-add-creation-config.test.ts @@ -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 diff --git a/src/main/git/worktree.ts b/src/main/git/worktree.ts index 1f96523899e..8ed95972611 100644 --- a/src/main/git/worktree.ts +++ b/src/main/git/worktree.ts @@ -975,7 +975,11 @@ async function performAddWorktree( ): Promise { 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')