fix(fork-sync): actually push to origin after FF

The previous version only updated local clones (the CI workdir) but
never pushed the synced state back to the fork. This means the Gitea
web UI kept showing stale branches even after a green CI run.

Now `git push origin <branch>` runs after each successful fast-forward
and after each created branch. The local CI run can then verify via
the Gitea API that the fork actually moved.

Note: forks whose default_branch differs from upstream default_branch
(e.g. hermes/hermes-voice-gateway uses feat/voice-gateway-mvp while
upstream Org1/hermes-voice-gateway uses main) will still lag on the
default branch. To keep both in sync, run the workflow with a
FORK_BRANCHES env that includes the upstream default_branch name.

Assisted-By: hermes-agent:minimax-m3
This commit is contained in:
hermes
2026-09-14 17:38:22 +00:00
parent a63f8f3f9c
commit 9f6ef132f8
+20 -5
View File
@@ -93,7 +93,7 @@ def list_local_branches(local):
def ff_one(local, branch):
"""Try to fast-forward local/<branch> to upstream/<branch>. Returns (ok, behind)."""
"""Try to fast-forward local/<branch> to upstream/<branch> and push to origin."""
if not subprocess.run(
["git", "rev-parse", "--verify", "--quiet", f"refs/remotes/upstream/{branch}"],
cwd=str(local), capture_output=True,
@@ -108,6 +108,13 @@ def ff_one(local, branch):
return True, 0
try:
run(["git", "merge", "--ff-only", f"upstream/{branch}"], cwd=str(local), timeout=30)
except Exception as e:
return False, behind
try:
push_res = run(
["git", "push", "origin", branch],
cwd=str(local), capture=True, timeout=120,
)
return True, behind
except Exception as e:
return False, behind
@@ -129,10 +136,11 @@ def ff_all(local):
def create_missing_branches(local):
"""Create local tracking branches for every upstream branch we don't have."""
"""Create local tracking branches for every upstream branch we don't have, push to origin."""
upstream_branches = list_upstream_branches(local)
local_branches = set(list_local_branches(local))
created = []
pushed = []
for b in upstream_branches:
if b in SKIP_BRANCHES:
continue
@@ -140,7 +148,12 @@ def create_missing_branches(local):
continue
run(["git", "branch", b, f"upstream/{b}"], cwd=str(local), check=False)
created.append(b)
return created
try:
run(["git", "push", "origin", b], cwd=str(local), capture=True, timeout=120)
pushed.append(b)
except Exception:
pass
return created, pushed
def main():
@@ -160,16 +173,18 @@ def main():
try:
local = ensure_clone(fork, upstream)
ffed, divs = ff_all(local)
created = create_missing_branches(local)
created, pushed = create_missing_branches(local)
except Exception as e:
alerts.append(f"❌ {fork}: ERROR {e!r}")
continue
if ffed or divs or created:
if ffed or divs or created or pushed:
line = f"📦 {fork} (← {upstream}):"
if ffed:
line += f" ff={ffed}"
if created:
line += f" created={created}"
if pushed:
line += f" pushed={pushed}"
if divs:
line += f" divergent={divs}"
alerts.append(line)