From bae290d6058e8cf1b50780596d50041f226442ff Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 28 Feb 2022 00:17:21 +0100 Subject: [PATCH] check git version and safe for runtime --- InvenTree/plugin/apps.py | 4 ++++ InvenTree/plugin/helpers.py | 20 ++++++++++++++++++++ InvenTree/plugin/registry.py | 1 + 3 files changed, 25 insertions(+) diff --git a/InvenTree/plugin/apps.py b/InvenTree/plugin/apps.py index dd75e3c8fb..4de6542bf1 100644 --- a/InvenTree/plugin/apps.py +++ b/InvenTree/plugin/apps.py @@ -10,6 +10,7 @@ from maintenance_mode.core import set_maintenance_mode from InvenTree.ready import isImportingData from plugin import registry +from plugin.helpers import check_git_version logger = logging.getLogger('inventree') @@ -34,3 +35,6 @@ class PluginAppConfig(AppConfig): # drop out of maintenance # makes sure we did not have an error in reloading and maintenance is still active set_maintenance_mode(False) + + # check git version + registry.git_is_modern = check_git_version() diff --git a/InvenTree/plugin/helpers.py b/InvenTree/plugin/helpers.py index 2271c01d98..5afc8ea5fc 100644 --- a/InvenTree/plugin/helpers.py +++ b/InvenTree/plugin/helpers.py @@ -108,6 +108,26 @@ def get_git_log(path): output = 7 * [''] # pragma: no cover return {'hash': output[0], 'author': output[1], 'mail': output[2], 'date': output[3], 'message': output[4], 'verified': output[5], 'key': output[6]} +def check_git_version(): + """returns if the current git version supports modern features""" + + # get version string + try: + output = str(subprocess.check_output(['git', '--version'], cwd=os.path.dirname(settings.BASE_DIR)), 'utf-8') + except subprocess.CalledProcessError: # pragma: no cover + return False + + # process version string + try: + version = output[12:-1].split(".") + if len(version) > 1 and version[0] == '2': + if len(version) > 2 and int(version[1]) >= 22: + return True + except ValueError: + pass + + return False + class GitStatus: """ diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index aec38cc623..40a4a4e2d9 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -52,6 +52,7 @@ class PluginsRegistry: # flags self.is_loading = False self.apps_loading = True # Marks if apps were reloaded yet + self.git_is_modern = True # Is a modern version of git available # integration specific self.installed_apps = [] # Holds all added plugin_paths