fix(cli): fall back to main when current branch has no remote counterpart

`hermes update` crashed with CalledProcessError when run on a local-only
branch (e.g. fix/stoicneko) because `git rev-list HEAD..origin/{branch}`
fails when origin/{branch} doesn't exist. Now verifies the remote branch
exists first and falls back to origin/main.
This commit is contained in:
stoicneko 2026-03-12 06:20:47 -07:00 committed by teknium1
parent a748257bf5
commit e1824ef8a6
2 changed files with 116 additions and 1 deletions

View file

@ -2056,7 +2056,15 @@ def cmd_update(args):
check=True
)
branch = result.stdout.strip()
# Fall back to main if the current branch doesn't exist on the remote
verify = subprocess.run(
git_cmd + ["rev-parse", "--verify", f"origin/{branch}"],
cwd=PROJECT_ROOT, capture_output=True, text=True,
)
if verify.returncode != 0:
branch = "main"
# Check if there are updates
result = subprocess.run(
git_cmd + ["rev-list", f"HEAD..origin/{branch}", "--count"],