diff --git a/tools-sync/scripts/sync_repos.ps1 b/tools-sync/scripts/sync_repos.ps1 index f96b575..a5ee386 100644 --- a/tools-sync/scripts/sync_repos.ps1 +++ b/tools-sync/scripts/sync_repos.ps1 @@ -73,7 +73,9 @@ if (-not (Test-Path $CodexSkills)) { New-Item -ItemType Directory -Force $CodexS # origin/main ever arrived (init succeeded, fetch didn't). $needBootstrap = -not (Test-Path (Join-Path $CodexSkills ".git")) if (-not $needBootstrap) { - $r = Invoke-Git $CodexSkills @("rev-parse", "--verify", "--quiet", "refs/remotes/origin/$Branch") + # Upstream config is written as the very last bootstrap step, so its absence + # means a previous bootstrap died partway — redo it (all steps are idempotent). + $r = Invoke-Git $CodexSkills @("config", "--get", "branch.$Branch.merge") if ($r.Code -ne 0) { $needBootstrap = $true } } @@ -82,6 +84,7 @@ if ($needBootstrap) { if ($DryRun) { Write-Host "(dry-run) would git init + fetch + align to origin/$Branch"; exit 0 } Invoke-Git $CodexSkills @("init") | Out-Null Invoke-Git $CodexSkills @("remote", "add", "origin", $RepoUrl) | Out-Null + Invoke-Git $CodexSkills @("remote", "set-url", "origin", $RepoUrl) | Out-Null $r = Invoke-Git $CodexSkills @("fetch", "origin", $Branch) if ($r.Code -ne 0) { # Flaky server on a full first fetch is common; the primary checkout already @@ -95,7 +98,9 @@ if ($needBootstrap) { Invoke-Git $CodexSkills @("branch", "-f", $Branch, "origin/$Branch") | Out-Null Invoke-Git $CodexSkills @("checkout", $Branch) 2>$null | Out-Null $drift = Invoke-Git $CodexSkills @("status", "--porcelain") - $modified = ($drift.Out -split "`n" | Where-Object { $_ -match '^\s*(M|D)' }) + # Only M is real local drift worth rescuing; D just means the file hasn't been + # materialized in this checkout yet, so overwriting loses nothing. + $modified = ($drift.Out -split "`n" | Where-Object { $_ -match '^\s*M' }) if ($modified -and -not $Force) { Write-Host "these tracked files differ locally from the repo:" $modified | ForEach-Object { Write-Host " $_" }