diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-06-17 17:19:55 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-06-17 17:19:55 +0200 |
commit | 5dcfd36d4186337a9c6b9061defc9bfe11df99bc (patch) | |
tree | f7c0f9c7ab4c0d35eac7a7a24468933552a4257d /scripts/setupcommon.py | |
parent | 60318271035c53fa90d6c1c0de629e44f0b2b924 (diff) | |
download | qutebrowser-5dcfd36d4186337a9c6b9061defc9bfe11df99bc.tar.gz qutebrowser-5dcfd36d4186337a9c6b9061defc9bfe11df99bc.zip |
Add git branch to :version
Diffstat (limited to 'scripts/setupcommon.py')
-rw-r--r-- | scripts/setupcommon.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/scripts/setupcommon.py b/scripts/setupcommon.py index e07096546..54a162941 100644 --- a/scripts/setupcommon.py +++ b/scripts/setupcommon.py @@ -38,6 +38,14 @@ BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.pardir) +def _call_git(gitpath: str, *args: str): + """Call a git subprocess.""" + return subprocess.run( + ['git'] + list(args), + cwd=gitpath, check=True, + stdout=subprocess.PIPE).stdout.decode('UTF-8').strip() + + def _git_str(): """Try to find out git version. @@ -51,15 +59,11 @@ def _git_str(): return None try: # https://stackoverflow.com/questions/21017300/21017394#21017394 - commit_hash = subprocess.run( - ['git', 'describe', '--match=NeVeRmAtCh', '--always', '--dirty'], - cwd=BASEDIR, check=True, - stdout=subprocess.PIPE).stdout.decode('UTF-8').strip() - date = subprocess.run( - ['git', 'show', '-s', '--format=%ci', 'HEAD'], - cwd=BASEDIR, check=True, - stdout=subprocess.PIPE).stdout.decode('UTF-8').strip() - return '{} ({})'.format(commit_hash, date) + commit_hash = _call_git(BASEDIR, 'describe', '--match=NeVeRmAtCh', + '--always', '--dirty') + date = _call_git(BASEDIR, 'show', '-s', '--format=%ci', 'HEAD') + branch = _call_git(BASEDIR, 'rev-parse', '--abbrev-ref', 'HEAD') + return '{} on {} ({})'.format(commit_hash, branch, date) except (subprocess.CalledProcessError, OSError): return None |