2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 12:06:44 +00:00

Merge pull request #2682 from matmair/matmair/issue2672

Fix git version bug
This commit is contained in:
Oliver 2022-02-28 14:15:40 +11:00 committed by GitHub
commit 010ce48ce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 8 deletions

View File

@ -5,11 +5,13 @@ import logging
from django.apps import AppConfig from django.apps import AppConfig
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from maintenance_mode.core import set_maintenance_mode from maintenance_mode.core import set_maintenance_mode
from InvenTree.ready import isImportingData from InvenTree.ready import isImportingData
from plugin import registry from plugin import registry
from plugin.helpers import check_git_version, log_error
logger = logging.getLogger('inventree') logger = logging.getLogger('inventree')
@ -34,3 +36,8 @@ class PluginAppConfig(AppConfig):
# drop out of maintenance # drop out of maintenance
# makes sure we did not have an error in reloading and maintenance is still active # makes sure we did not have an error in reloading and maintenance is still active
set_maintenance_mode(False) 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')

View File

@ -94,21 +94,46 @@ def get_git_log(path):
""" """
Get dict with info of the last commit to file named in path Get dict with info of the last commit to file named in path
""" """
path = path.replace(os.path.dirname(settings.BASE_DIR), '')[1:] from plugin import registry
command = ['git', 'log', '-n', '1', "--pretty=format:'%H%n%aN%n%aE%n%aI%n%f%n%G?%n%GK'", '--follow', '--', path]
output = None output = None
try: if registry.git_is_modern:
output = str(subprocess.check_output(command, cwd=os.path.dirname(settings.BASE_DIR)), 'utf-8')[1:-1] path = path.replace(os.path.dirname(settings.BASE_DIR), '')[1:]
if output: command = ['git', 'log', '-n', '1', "--pretty=format:'%H%n%aN%n%aE%n%aI%n%f%n%G?%n%GK'", '--follow', '--', path]
output = output.split('\n') try:
except subprocess.CalledProcessError: # pragma: no cover output = str(subprocess.check_output(command, cwd=os.path.dirname(settings.BASE_DIR)), 'utf-8')[1:-1]
pass if output:
output = output.split('\n')
except subprocess.CalledProcessError: # pragma: no cover
pass
if not output: if not output:
output = 7 * [''] # pragma: no cover 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]} 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 GitStatus:
""" """
Class for resolving git gpg singing state Class for resolving git gpg singing state

View File

@ -52,6 +52,7 @@ class PluginsRegistry:
# flags # flags
self.is_loading = False self.is_loading = False
self.apps_loading = True # Marks if apps were reloaded yet self.apps_loading = True # Marks if apps were reloaded yet
self.git_is_modern = True # Is a modern version of git available
# integration specific # integration specific
self.installed_apps = [] # Holds all added plugin_paths self.installed_apps = [] # Holds all added plugin_paths