From 31b43511f2187ba91ef8c398be7b516923079282 Mon Sep 17 00:00:00 2001 From: LaZzyMan Date: Wed, 11 Mar 2026 18:07:49 +0800 Subject: [PATCH] fix(extension): disable symlinks on Windows during git clone On Windows, non-administrator users do not have permission to create symlinks by default. Using core.symlinks=true during git clone causes checkout to fail with 'Permission denied' errors when the repository contains symlinks. This fix dynamically sets core.symlinks based on the current platform: - win32: core.symlinks=false (avoids permission errors) - other platforms: core.symlinks=true (preserves existing behavior) Fixes #2243 --- packages/core/src/extension/github.test.ts | 45 ++++++++++++++++++++++ packages/core/src/extension/github.ts | 5 ++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/packages/core/src/extension/github.test.ts b/packages/core/src/extension/github.test.ts index 8c31b1284d..c197c34fee 100644 --- a/packages/core/src/extension/github.test.ts +++ b/packages/core/src/extension/github.test.ts @@ -56,6 +56,7 @@ describe('git extension helpers', () => { }); it('should clone, fetch and checkout a repo', async () => { + mockPlatform.mockReturnValue('linux'); const installMetadata = { source: 'http://my-repo.com', ref: 'my-ref', @@ -79,6 +80,50 @@ describe('git extension helpers', () => { expect(mockGit.checkout).toHaveBeenCalledWith('FETCH_HEAD'); }); + it('should use core.symlinks=false on Windows to avoid permission errors', async () => { + mockPlatform.mockReturnValue('win32'); + const installMetadata = { + source: 'http://my-repo.com', + ref: 'my-ref', + type: 'git' as const, + }; + const destination = '/dest'; + mockGit.getRemotes.mockResolvedValue([ + { name: 'origin', refs: { fetch: 'http://my-repo.com' } }, + ]); + + await cloneFromGit(installMetadata, destination); + + expect(mockGit.clone).toHaveBeenCalledWith('http://my-repo.com', './', [ + '-c', + 'core.symlinks=false', + '--depth', + '1', + ]); + }); + + it('should use core.symlinks=true on non-Windows platforms', async () => { + mockPlatform.mockReturnValue('darwin'); + const installMetadata = { + source: 'http://my-repo.com', + ref: 'my-ref', + type: 'git' as const, + }; + const destination = '/dest'; + mockGit.getRemotes.mockResolvedValue([ + { name: 'origin', refs: { fetch: 'http://my-repo.com' } }, + ]); + + await cloneFromGit(installMetadata, destination); + + expect(mockGit.clone).toHaveBeenCalledWith('http://my-repo.com', './', [ + '-c', + 'core.symlinks=true', + '--depth', + '1', + ]); + }); + it('should use HEAD if ref is not provided', async () => { const installMetadata = { source: 'http://my-repo.com', diff --git a/packages/core/src/extension/github.ts b/packages/core/src/extension/github.ts index 4fe830e45f..e0f448b900 100644 --- a/packages/core/src/extension/github.ts +++ b/packages/core/src/extension/github.ts @@ -75,9 +75,12 @@ export async function cloneFromGit( // We let git handle the source as is. } } + // On Windows, symlinks require elevated privileges by default, so we + // disable them to avoid "Permission denied" errors during checkout. + const symlinkValue = os.platform() === 'win32' ? 'false' : 'true'; await git.clone(sourceUrl, './', [ '-c', - 'core.symlinks=true', + `core.symlinks=${symlinkValue}`, '--depth', '1', ]);