sync: BOWEI_US 2026-09-02

This commit is contained in:
Myfro9
2026-09-02 15:35:47 -05:00
parent e39e852853
commit 10f436cfde
4 changed files with 428 additions and 2 deletions
+39 -2
View File
@@ -15,7 +15,12 @@ param(
# linking; -Force deletes it and links (caller must have rescued unique content first).
[switch]$Force,
# Report what would happen without committing/pushing/linking.
[switch]$DryRun
[switch]$DryRun,
# A transport failure normally aborts the run and leaves commits stranded here. By
# default we instead log into the gitea host, repair it, and retry once. -NoDoctor
# keeps the old abort-and-report behaviour.
[switch]$NoDoctor,
[switch]$AllowDestructive
)
$ErrorActionPreference = "Stop"
@@ -34,6 +39,28 @@ function Invoke-Git {
function Fail([string]$Msg) { Write-Host "FAIL: $Msg"; exit 1 }
# git reports a server-side transport fault in the vocabulary of the pack protocol, not
# of the server. These are the shapes seen when gitea is up (auth fine, refs fine) but
# the pack plane is dead - the case gitea_doctor knows how to repair.
function Test-TransportFault([string]$GitOutput) {
return ($GitOutput -match "bad pack header|early EOF|invalid index-pack output|RPC failed|unexpected disconnect|remote end hung up|Could not read from remote repository|Connection (reset|refused|timed out)")
}
function Invoke-Doctor([string]$Why) {
if ($NoDoctor) { Write-Host "(-NoDoctor set, skipping server repair)"; return $false }
$doctor = Join-Path $PSScriptRoot "gitea_doctor.ps1"
if (-not (Test-Path $doctor)) { Write-Host "gitea_doctor.ps1 not found; cannot repair the server."; return $false }
Write-Host ""
Write-Host "=== transport fault ($Why) - running gitea_doctor -Fix ==="
$dargs = @("-RepoUrl", $RepoUrl, "-Fix")
if ($AllowDestructive) { $dargs += "-AllowDestructive" }
& $doctor @dargs
$ok = ($LASTEXITCODE -eq 0)
Write-Host "=== doctor $(if ($ok) { 'reports the transport healthy' } else { 'could NOT restore the transport' }) ==="
Write-Host ""
return $ok
}
# ---------- Phase 1: primary checkout (~\.claude\skills) ----------
Write-Host "=== [1/2] primary git sync: $ClaudeSkills ==="
if (-not (Test-Path (Join-Path $ClaudeSkills ".git"))) {
@@ -94,16 +121,26 @@ if ($DryRun) {
Assert-RemoteInSync $ClaudeSkills $Branch
} else {
$r = Invoke-Git $ClaudeSkills @("pull", "--rebase", "origin", $Branch)
if ($r.Code -ne 0 -and (Test-TransportFault $r.Out)) {
# A rebase may have been left half-started before the transport died.
Invoke-Git $ClaudeSkills @("rebase", "--abort") | Out-Null
if (Invoke-Doctor "pull --rebase") {
$r = Invoke-Git $ClaudeSkills @("pull", "--rebase", "origin", $Branch)
}
}
if ($r.Code -ne 0) {
Write-Host $r.Out
$stranded = Invoke-Git $ClaudeSkills @("rev-list", "--count", "origin/$Branch..$Branch")
if ($stranded.Code -eq 0 -and [int]$stranded.Out -gt 0) {
Write-Host "NOTE: $($stranded.Out) local commit(s) cannot reach the server until this is fixed."
}
Fail "pull --rebase failed on primary. Resolve conflicts (or 'git rebase --abort') then re-run. If the transport itself is broken (see skill Phase 1), fix the server -- do not leave commits stranded."
Fail "pull --rebase failed on primary. Conflicts are yours to resolve (or 'git rebase --abort'); a transport fault the doctor could not repair is in the skill's Phase 1.5 ladder. Either way: do not leave commits stranded."
}
Write-Host $r.Out
$r = Invoke-Git $ClaudeSkills @("push", "origin", $Branch)
if ($r.Code -ne 0 -and (Test-TransportFault $r.Out)) {
if (Invoke-Doctor "push") { $r = Invoke-Git $ClaudeSkills @("push", "origin", $Branch) }
}
if ($r.Code -ne 0) { Write-Host $r.Out; Fail "push failed (auth? see skill Phase 1)." }
Assert-RemoteInSync $ClaudeSkills $Branch
}