mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
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>
33 lines
1 KiB
Python
33 lines
1 KiB
Python
import pathlib
|
|
import subprocess
|
|
|
|
__version__ = (pathlib.Path(__file__).parent / 'version.txt').read_text()
|
|
|
|
|
|
def git_revision():
|
|
try:
|
|
cmd = ('git', 'log', '-1', '--format="%H"')
|
|
revision = subprocess.check_output(cmd, stderr=subprocess.PIPE)
|
|
revision = revision.decode().strip().strip('"')
|
|
return revision
|
|
except Exception:
|
|
# Could not find git version...
|
|
return 'unknown'
|
|
|
|
|
|
def git_branch():
|
|
try:
|
|
# Not `rev-parse --abbrev-ref HEAD`: it reports "heads/release" when a stale
|
|
# `release` tag exists alongside the branch.
|
|
cmd = ('git', 'branch', '--show-current')
|
|
branch = subprocess.check_output(cmd, stderr=subprocess.PIPE)
|
|
branch = branch.decode().strip()
|
|
# A detached HEAD prints nothing.
|
|
return branch or 'HEAD'
|
|
except Exception:
|
|
return 'unknown'
|
|
|
|
|
|
def get_version_string():
|
|
"""Return a string containing the WROLPi version, git branch and git revision hash."""
|
|
return f'{__version__} (git: {git_branch()} {git_revision()})'
|