From 924221f063b6e05cb4fc506f8bb4c36307b8fc46 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 21 May 2021 08:39:13 +0200 Subject: [PATCH] Show whether or not the git wdir is dirty in version Closes #1073 --- config.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 3476095d..85dadc5e 100644 --- a/config.py +++ b/config.py @@ -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: