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
This commit is contained in:
Matthias Mair 2023-05-26 00:17:32 +02:00 committed by GitHub
parent 433ea4d0de
commit 717bb07dcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,6 +93,30 @@ def inventreeDjangoVersion():
return django.get_version() 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(): def inventreeCommitHash():
"""Returns the git commit hash for the running codebase.""" """Returns the git commit hash for the running codebase."""
# First look in the environment variables, i.e. if running in docker # First look in the environment variables, i.e. if running in docker
@ -101,6 +125,9 @@ def inventreeCommitHash():
if commit_hash: if commit_hash:
return commit_hash return commit_hash
if not check_for_git():
return None
try: try:
return str(subprocess.check_output('git rev-parse --short HEAD'.split()), 'utf-8').strip() return str(subprocess.check_output('git rev-parse --short HEAD'.split()), 'utf-8').strip()
except Exception: # pragma: no cover except Exception: # pragma: no cover
@ -115,6 +142,9 @@ def inventreeCommitDate():
if commit_date: if commit_date:
return commit_date.split(' ')[0] return commit_date.split(' ')[0]
if not check_for_git():
return None
try: try:
d = str(subprocess.check_output('git show -s --format=%ci'.split()), 'utf-8').strip() d = str(subprocess.check_output('git show -s --format=%ci'.split()), 'utf-8').strip()
return d.split(' ')[0] return d.split(' ')[0]