From cc9e5f3969346ea818ad01d67807c55496d64390 Mon Sep 17 00:00:00 2001 From: Simone Date: Sat, 9 May 2026 00:45:27 +0200 Subject: [PATCH] fix: shallow clone + unshallow fallback for specific commit checkout Previous fix removed --depth 1 entirely when $Commit was set, causing full clones on every workflow run (github.sha is always non-empty). Better approach: keep --depth 1 (fast path), detect checkout failure, then fetch --unshallow and retry. Only pays full-clone cost when the requested commit is actually older than HEAD. Co-Authored-By: Claude Sonnet 4.6 --- scripts/Invoke-CIJob.ps1 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/Invoke-CIJob.ps1 b/scripts/Invoke-CIJob.ps1 index 21e7936..73c1e45 100644 --- a/scripts/Invoke-CIJob.ps1 +++ b/scripts/Invoke-CIJob.ps1 @@ -195,11 +195,7 @@ try { # into the VM environment. Write-Host "`n[Phase 1/6] Cloning repository on host..." if (Test-Path $hostCloneDir) { Remove-Item $hostCloneDir -Recurse -Force } - # Skip --depth 1 when a specific commit is requested: shallow clones - # only contain HEAD, so checkout of an older commit will fail. - $gitArgs = @('clone') - if ([string]::IsNullOrWhiteSpace($Commit)) { $gitArgs += @('--depth', '1') } - $gitArgs += @('--branch', $Branch) + $gitArgs = @('clone', '--depth', '1', '--branch', $Branch) if ($Submodules) { $gitArgs += '--recurse-submodules' } $gitArgs += @($RepoUrl, $hostCloneDir) $ErrorActionPreference = 'Continue' @@ -213,6 +209,14 @@ try { $ErrorActionPreference = 'Continue' $gitOutput = & git -C $hostCloneDir checkout $Commit 2>&1 | ForEach-Object { "$_" } $gitExit = $LASTEXITCODE + if ($gitExit -ne 0) { + # Commit not in shallow history (e.g. manual run on older SHA). + # Fetch full history and retry. + Write-Host "[Invoke-CIJob] Shallow checkout failed — fetching full history..." + & git -C $hostCloneDir fetch --unshallow 2>&1 | Out-Null + $gitOutput = & git -C $hostCloneDir checkout $Commit 2>&1 | ForEach-Object { "$_" } + $gitExit = $LASTEXITCODE + } $ErrorActionPreference = 'Stop' if ($gitExit -ne 0) { throw "git checkout $Commit failed (exit $gitExit):`n$($gitOutput -join "`n")"