From 717bb07dcf603019d1134596d9e3ef8abd1cb4c2 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Fri, 26 May 2023 00:17:32 +0200 Subject: [PATCH] Possible fix for git messages (#4882) * yank git stuff out * fix tests * Add check for git to reduce warning logs Fixes #4428 * reverse git removal * and more resetting --- InvenTree/InvenTree/version.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index e87214118e..12e58d1d80 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -93,6 +93,30 @@ def inventreeDjangoVersion(): return django.get_version() +git_available: bool = None # is git available and used by the install? + + +def check_for_git(): + """Check if git is available on the install.""" + global git_available + + if git_available is not None: + return git_available + + try: + subprocess.check_output('git --version'.split(), stderr=subprocess.DEVNULL) + except Exception: + git_available = False + + if git_available is None: + try: + subprocess.check_output('git status'.split(), stderr=subprocess.DEVNULL) + git_available = True + return True + except Exception: + git_available = False + + def inventreeCommitHash(): """Returns the git commit hash for the running codebase.""" # First look in the environment variables, i.e. if running in docker @@ -101,6 +125,9 @@ def inventreeCommitHash(): if commit_hash: return commit_hash + if not check_for_git(): + return None + try: return str(subprocess.check_output('git rev-parse --short HEAD'.split()), 'utf-8').strip() except Exception: # pragma: no cover @@ -115,6 +142,9 @@ def inventreeCommitDate(): if commit_date: return commit_date.split(' ')[0] + if not check_for_git(): + return None + try: d = str(subprocess.check_output('git show -s --format=%ci'.split()), 'utf-8').strip() return d.split(' ')[0]