diff --git a/InvenTree/plugin/apps.py b/InvenTree/plugin/apps.py index dd75e3c8fb..75063c6b3c 100644 --- a/InvenTree/plugin/apps.py +++ b/InvenTree/plugin/apps.py @@ -5,11 +5,13 @@ import logging from django.apps import AppConfig from django.conf import settings +from django.utils.translation import ugettext_lazy as _ from maintenance_mode.core import set_maintenance_mode from InvenTree.ready import isImportingData from plugin import registry +from plugin.helpers import check_git_version, log_error logger = logging.getLogger('inventree') @@ -34,3 +36,8 @@ 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() + if not registry.git_is_modern: # pragma: no cover # simulating old git seems not worth it for coverage + log_error(_('Your enviroment has an outdated git version. This prevents InvenTree from loading plugin details.'), 'load') diff --git a/InvenTree/plugin/helpers.py b/InvenTree/plugin/helpers.py index 2271c01d98..1a5089aefe 100644 --- a/InvenTree/plugin/helpers.py +++ b/InvenTree/plugin/helpers.py @@ -94,21 +94,46 @@ def get_git_log(path): """ Get dict with info of the last commit to file named in path """ - path = path.replace(os.path.dirname(settings.BASE_DIR), '')[1:] - command = ['git', 'log', '-n', '1', "--pretty=format:'%H%n%aN%n%aE%n%aI%n%f%n%G?%n%GK'", '--follow', '--', path] + from plugin import registry + output = None - try: - output = str(subprocess.check_output(command, cwd=os.path.dirname(settings.BASE_DIR)), 'utf-8')[1:-1] - if output: - output = output.split('\n') - except subprocess.CalledProcessError: # pragma: no cover - pass + if registry.git_is_modern: + path = path.replace(os.path.dirname(settings.BASE_DIR), '')[1:] + command = ['git', 'log', '-n', '1', "--pretty=format:'%H%n%aN%n%aE%n%aI%n%f%n%G?%n%GK'", '--follow', '--', path] + try: + output = str(subprocess.check_output(command, cwd=os.path.dirname(settings.BASE_DIR)), 'utf-8')[1:-1] + if output: + output = output.split('\n') + except subprocess.CalledProcessError: # pragma: no cover + pass if not output: 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: # pragma: no cover + pass + + return False + + class GitStatus: """ Class for resolving git gpg singing state 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