Skip to content

Commit 0ee6c35

Browse files
improve(installer): reduce Windows Git clone downloads (#130908)
* perf(installer): use blobless PowerShell clones * fix(installer): preserve clone compatibility on older git * fix(installer): recognize modern git filter help
1 parent 1e6e402 commit 0ee6c35

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎scripts/install.ps1‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,15 @@ function Ensure-Git {
892892
return $false
893893
}
894894

895+
function Test-GitFilterSupport {
896+
try {
897+
$help = (& git clone -h 2>&1 | Out-String)
898+
return $help -match '(?m)\s--(?:\[no-\])?filter(?:[ =]|$)'
899+
} catch {
900+
return $false
901+
}
902+
}
903+
895904
function Get-OpenClawCommandPath {
896905
$openclawCmd = Get-Command openclaw.cmd -ErrorAction SilentlyContinue
897906
if ($openclawCmd -and $openclawCmd.Source) {
@@ -1657,7 +1666,15 @@ function New-TransactionalGitCheckout {
16571666
$retainStaging = $false
16581667

16591668
try {
1660-
git clone $RepoUrl $stagingDir
1669+
# Keep ref metadata for later updates while avoiding file blobs when
1670+
# the local Git client supports partial clones. Git warns and falls
1671+
# back to a full clone when the server cannot filter.
1672+
$cloneArgs = @("clone")
1673+
if (Test-GitFilterSupport) {
1674+
$cloneArgs += "--filter=blob:none"
1675+
}
1676+
$cloneArgs += @($RepoUrl, $stagingDir)
1677+
& git @cloneArgs
16611678
if ($LASTEXITCODE -ne 0) {
16621679
throw "git clone failed with exit code $LASTEXITCODE"
16631680
}

‎test/scripts/install-ps1.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,18 @@ describe("install.ps1 failure handling", () => {
715715
'$sandbox = Join-Path ([System.IO.Path]::GetTempPath()) ("openclaw-transactional-clone-" + [guid]::NewGuid().ToString("N"))',
716716
"New-Item -ItemType Directory -Path $sandbox | Out-Null",
717717
"$script:CloneMode = 'success'",
718+
"$script:GitFilterSupport = $true",
719+
"$script:LastCloneArgs = @()",
718720
"$script:ConcurrentRepo = $null",
719721
"$script:AliasPath = $null",
720722
"$script:AliasReplacement = $null",
721723
"function git {",
724+
" if ($args[0] -eq 'clone' -and $args[1] -eq '-h') {",
725+
" if ($script:GitFilterSupport) { Write-Output ' --[no-]filter <args>' }",
726+
" $global:LASTEXITCODE = 129",
727+
" return",
728+
" }",
729+
" if ($args[0] -eq 'clone') { $script:LastCloneArgs = @($args) }",
722730
" $target = $args[-1]",
723731
" New-Item -ItemType Directory -Force -Path (Join-Path $target '.git') | Out-Null",
724732
" Set-Content -LiteralPath (Join-Path $target 'checkout.marker') -Value 'complete'",
@@ -738,11 +746,14 @@ describe("install.ps1 failure handling", () => {
738746
" $successRepo = Join-Path $sandbox 'success'",
739747
" New-TransactionalGitCheckout -RepoUrl 'https://example.invalid/openclaw.git' -RepoDir $successRepo",
740748
" if (-not (Test-Path -LiteralPath (Join-Path $successRepo 'checkout.marker'))) { throw 'complete checkout was not published' }",
749+
" if ($script:LastCloneArgs -notcontains '--filter=blob:none') { throw 'supported Git did not use a filtered clone' }",
741750
"",
742751
" $emptyRepo = Join-Path $sandbox 'empty'",
743752
" New-Item -ItemType Directory -Path $emptyRepo | Out-Null",
753+
" $script:GitFilterSupport = $false",
744754
" New-TransactionalGitCheckout -RepoUrl 'https://example.invalid/openclaw.git' -RepoDir $emptyRepo",
745755
" if (-not (Test-Path -LiteralPath (Join-Path $emptyRepo 'checkout.marker'))) { throw 'empty destination was not populated' }",
756+
" if ($script:LastCloneArgs -contains '--filter=blob:none') { throw 'unsupported Git used a filtered clone' }",
746757
"",
747758
" $aliasTarget = Join-Path $sandbox 'alias-target'",
748759
" $script:AliasReplacement = Join-Path $sandbox 'alias-replacement'",
@@ -1244,6 +1255,7 @@ describe("install.ps1 failure handling", () => {
12441255
const pnpmVersionBody = extractFunctionBody(source, "Get-RepoPnpmVersion");
12451256
const pnpmVersionMatchBody = extractFunctionBody(source, "Test-PnpmCommandMatchesVersion");
12461257
const ensurePnpmBody = extractFunctionBody(source, "Ensure-Pnpm");
1258+
const gitFilterSupportBody = extractFunctionBody(source, "Test-GitFilterSupport");
12471259
const transactionalCloneBody = extractFunctionBody(source, "New-TransactionalGitCheckout");
12481260
const gitInstallBody = extractFunctionBody(source, "Install-OpenClawFromGit");
12491261
const nodeOptionsBody = extractFunctionBody(source, "Resolve-NodeOptionsWithMinOldSpace");
@@ -1271,7 +1283,10 @@ describe("install.ps1 failure handling", () => {
12711283
expect(ensurePnpmBody).toContain(
12721284
'Invoke-NpmCommand -Arguments @("install", "-g", "--force", $pnpmSpec)',
12731285
);
1274-
expect(transactionalCloneBody).toContain("git clone $RepoUrl $stagingDir");
1286+
expect(gitFilterSupportBody).toContain("git clone -h");
1287+
expect(gitFilterSupportBody).toContain("filter");
1288+
expect(transactionalCloneBody).toContain('$cloneArgs += "--filter=blob:none"');
1289+
expect(transactionalCloneBody).toContain("& git @cloneArgs");
12751290
expect(gitInstallBody.indexOf("New-TransactionalGitCheckout")).toBeLessThan(
12761291
gitInstallBody.indexOf("Ensure-Pnpm -RepoDir $RepoDir"),
12771292
);

0 commit comments

Comments
 (0)