Skip to content

Commit bc87144

Browse files
CTOUTCopilot
andcommitted
fix: recover from unrelated histories on git pull
When the remote history has diverged (e.g. force-push), fall back to git fetch + reset --hard origin/HEAD instead of failing with exit 128. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a21702b commit bc87144

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

scripts/sync-awesome-copilot.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,18 @@ if ($IsFirstRun) {
150150
# Re-apply sparse-checkout in case -Categories changed since last run
151151
& git -C $Dest sparse-checkout set @CategoriesList 2>&1 | Out-Null
152152

153-
& git -C $Dest pull 2>&1 | ForEach-Object { Write-Log $_ }
154-
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) { Write-Log "Pull failed (exit $LASTEXITCODE)" 'ERROR'; exit $LASTEXITCODE }
153+
$pullOutput = & git -C $Dest pull 2>&1
154+
$pullOutput | ForEach-Object { Write-Log $_ }
155+
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
156+
if (($pullOutput -join "`n") -match 'unrelated histories') {
157+
Write-Log "Unrelated histories detected — fetching and resetting to remote HEAD..." 'WARN'
158+
& git -C $Dest fetch origin 2>&1 | ForEach-Object { Write-Log $_ }
159+
& git -C $Dest reset --hard origin/HEAD 2>&1 | ForEach-Object { Write-Log $_ }
160+
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) { Write-Log "Reset failed (exit $LASTEXITCODE)" 'ERROR'; exit $LASTEXITCODE }
161+
} else {
162+
Write-Log "Pull failed (exit $LASTEXITCODE)" 'ERROR'; exit $LASTEXITCODE
163+
}
164+
}
155165
}
156166

157167
Check-Timeout

0 commit comments

Comments
 (0)