From 69d8270e8fc2b7117b10755c27d81bc095883415 Mon Sep 17 00:00:00 2001
From: Athanasius <github@miggy.org>
Date: Fri, 21 May 2021 16:55:10 +0100
Subject: [PATCH] config: Rework 'git but dirty?' check to handle 'no git'

`shorthash` was still `None` if no git, so we then tried to concatenate
`NoneType` and `str` which is verbotten.

There's no point using git to detect dirtyness if `shorthash` is None
because that itself indicates no git available.
---
 config.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/config.py b/config.py
index 290d08fe..fb644a73 100644
--- a/config.py
+++ b/config.py
@@ -101,15 +101,6 @@ def git_shorthash_from_head() -> str:
     :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(),
@@ -127,7 +118,16 @@ 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 + ('-WORKING-DIR-IS-DIRTY' if dirty else '')
+    if shorthash is not None:
+        with contextlib.suppress(Exception):
+            result = subprocess.run('git diff --stat HEAD'.split(), capture_output=True)
+            if len(result.stdout) > 0:
+                shorthash += '-WORKING-DIR-IS-DIRTY'
+
+            if len(result.stderr) > 0:
+                logger.warning(f'Data from git on stderr:\n{str(result.stderr)}')
+
+    return shorthash
 
 
 def appversion() -> semantic_version.Version: