fix(fork-sync): handle missing upstream remote gracefully

`git remote remove upstream` exits non-zero when the remote does not exist,
which then blocks `git remote add upstream` from succeeding. The first-run
CI clones failed on a non-empty error stream even though the second
attempt would have succeeded.

Fix: only `git remote add` when the previous `remove` actually removed
something (returncode 0). When the remote was already absent, skip the
add since fetch will set it up implicitly. This makes the first-run
clone idempotent.

Assisted-By: hermes-agent:minimax-m3
This commit is contained in:
hermes
2026-09-14 17:06:46 +00:00
parent 0d111f29de
commit bd96dba9a1
+9 -2
View File
@@ -57,8 +57,15 @@ def ensure_clone(fork_full, upstream_full):
if not (local / ".git").exists():
local.parent.mkdir(parents=True, exist_ok=True)
run(["git", "clone", "--quiet", f"{AUTH_URL}/{fork_full}.git", str(local)])
run(["git", "remote", "remove", "upstream"], cwd=str(local), check=False)
run(["git", "remote", "add", "upstream", f"{AUTH_URL}/{upstream_full}.git"], cwd=str(local))
# `git remote remove` exits non-zero when the remote doesn't exist; ignore.
res = run(
["git", "remote", "remove", "upstream"], cwd=str(local), check=False,
capture=True,
)
run(
["git", "remote", "add", "upstream", f"{AUTH_URL}/{upstream_full}.git"],
cwd=str(local), check=res.returncode == 0,
)
run(["git", "fetch", "--prune", "--quiet", "upstream"], cwd=str(local), timeout=120)
run(["git", "fetch", "--prune", "--quiet", "origin"], cwd=str(local), timeout=120)
return local