From 430bcefaa6ff7c004fdd2ee7fcae2ce72010ade1 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare <48523873+rohitg00@users.noreply.github.com> Date: Fri, 10 Apr 2026 21:49:13 +0100 Subject: [PATCH] fix: narrow partial clone fallback, cap stderr, add -- before paths - Restrict try/catch to only the partial clone spawn so sparse-checkout/checkout failures bubble up as real errors instead of being misreported as "partial clone unsupported" - Cap stderr accumulator to 4KB to bound memory on verbose clones - Add -- terminator before sparsePaths in sparse-checkout set to prevent user-controlled subpath from being parsed as git options --- packages/core/src/providers/base.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/core/src/providers/base.ts b/packages/core/src/providers/base.ts index f14c492d..49197539 100644 --- a/packages/core/src/providers/base.ts +++ b/packages/core/src/providers/base.ts @@ -59,7 +59,7 @@ function spawnGit(args: string[], onProgress?: (msg: string) => void): Promise { const text = data.toString(); - stderr += text; + stderr = (stderr + text).slice(-4096); if (onProgress) { const msg = parseGitProgress(text); if (msg) onProgress(msg); @@ -94,9 +94,18 @@ export async function cloneRepo( if (tryPartialClone) { const partialArgs = [...args, '--filter=blob:none', '--no-checkout', cloneUrl, tempDir]; + let partialCloneOk = false; try { await spawnGit(partialArgs, options.onProgress ?? (() => {})); + partialCloneOk = true; + } catch { + options.onProgress?.('Partial clone unsupported, falling back to full clone'); + if (existsSync(tempDir)) { + rmSync(tempDir, { recursive: true, force: true }); + } + } + if (partialCloneOk) { execFileSync('git', ['-C', tempDir, 'sparse-checkout', 'init', '--cone'], { stdio: ['pipe', 'pipe', 'pipe'], }); @@ -110,7 +119,7 @@ export async function cloneRepo( } execFileSync( 'git', - ['-C', tempDir, 'sparse-checkout', 'set', ...sparsePaths], + ['-C', tempDir, 'sparse-checkout', 'set', '--', ...sparsePaths], { stdio: ['pipe', 'pipe', 'pipe'] }, ); @@ -118,11 +127,6 @@ export async function cloneRepo( await spawnGit(['-C', tempDir, 'checkout'], options.onProgress ?? (() => {})); return; - } catch (err) { - options.onProgress?.(`Partial clone unsupported, falling back to full clone`); - if (existsSync(tempDir)) { - rmSync(tempDir, { recursive: true, force: true }); - } } }