1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-19 10:27:38 +03:00

Show whether or not the git wdir is dirty in version

Closes #1073
This commit is contained in:
A_D 2021-05-21 08:39:13 +02:00
parent 0b9991b092
commit 924221f063
No known key found for this signature in database
GPG Key ID: 4BE9EB7DF45076C4

View File

@ -96,9 +96,21 @@ def git_shorthash_from_head() -> str:
"""
Determine short hash for current git HEAD.
Includes -DIRTY if any changes have been made from HEAD
:return: str - None if we couldn't determine the short hash.
"""
shorthash: str = None # type: ignore
dirty = False
with contextlib.suppress(Exception):
result = subprocess.run('git diff --stat HEAD'.split(), capture_output=True)
if len(result.stdout) > 0:
dirty = True
if len(result.stderr) > 0:
logger.warning(f'Data from git on stderr:\n{str(result.stderr)}')
try:
git_cmd = subprocess.Popen('git rev-parse --short HEAD'.split(),
stdout=subprocess.PIPE,
@ -115,7 +127,7 @@ def git_shorthash_from_head() -> str:
logger.error(f"'{shorthash}' doesn't look like a valid git short hash, forcing to None")
shorthash = None # type: ignore
return shorthash
return shorthash + ('-WORKING-DIR-IS-DIRTY' if dirty else '')
def appversion() -> semantic_version.Version: