upgrade: report git branch via --show-current so a stale release tag can't break upgrades

git rev-parse --abbrev-ref HEAD reports "heads/release" when a stale
tag named release exists alongside the release branch (tags outrank
heads in git ref resolution).  check_for_update then looked up the
nonexistent origin/heads/release and permanently reported no updates
available, and the Controller UI pre-filled "heads/release" as the
upgrade branch.

Use git branch --show-current everywhere instead; it never
disambiguates.  A detached HEAD (empty output) now defaults to the
release branch for upgrades; a genuine git failure still returns None.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-07-29 15:59:11 -06:00
parent 9e8050bd48
commit ab5f416b3f
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
5 changed files with 94 additions and 15 deletions

View file

@ -78,17 +78,20 @@ def get_current_branch() -> Optional[str]:
Get the current git branch of /opt/wrolpi.
Returns:
Branch name, or None if unable to determine
Branch name ('release' on a detached HEAD), or None if unable to determine
"""
try:
# Not `rev-parse --abbrev-ref HEAD`: it reports "heads/release" when a stale
# `release` tag exists alongside the branch, breaking origin/{branch} lookups.
result = subprocess.run(
["git", "-C", "/opt/wrolpi", "rev-parse", "--abbrev-ref", "HEAD"],
["git", "-C", "/opt/wrolpi", "branch", "--show-current"],
capture_output=True,
text=True,
timeout=5,
)
if result.returncode == 0:
return result.stdout.strip()
# A detached HEAD prints nothing; upgrades come from `release` by default.
return result.stdout.strip() or "release"
except (subprocess.TimeoutExpired, subprocess.SubprocessError, FileNotFoundError):
pass
return None