From 7955d1f579d1195d1b3b27a2f6b92cc79a93a69a Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 30 Jun 2023 13:43:54 +1000 Subject: [PATCH] Get git log fix (#5113) * Simplify extraction of git repo - Replace Repo.discover() with Repo() - Ensure provided path is directory * Remove profiling code --- InvenTree/plugin/helpers.py | 30 ++++++++++++++++-------------- InvenTree/plugin/plugin.py | 1 + 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/InvenTree/plugin/helpers.py b/InvenTree/plugin/helpers.py index df00d1d37d..40b97aab9a 100644 --- a/InvenTree/plugin/helpers.py +++ b/InvenTree/plugin/helpers.py @@ -2,6 +2,7 @@ import inspect import logging +import os import pathlib import pkgutil import sysconfig @@ -116,25 +117,26 @@ def get_git_log(path): from InvenTree.ready import isInTestMode output = None - path = path.replace(str(settings.BASE_DIR.parent), '')[1:] + path = os.path.abspath(path) + + if os.path.exists(path) and os.path.isfile(path): + path = os.path.dirname(path) # only do this if we are not in test mode if not isInTestMode(): # pragma: no cover try: - walker = Repo.discover(path).get_walker(paths=[path.encode()], max_entries=1) - try: - commit = next(iter(walker)).commit - except StopIteration: - pass - else: - output = [ - commit.sha().hexdigest(), - commit.author.decode().split('<')[0][:-1], - commit.author.decode().split('<')[1][:-1], - datetime.datetime.fromtimestamp(commit.author_time, ).isoformat(), - commit.message.decode().split('\n')[0], - ] + repo = Repo(path) + head = repo.head() + commit = repo[head] + + output = [ + head.decode(), + commit.author.decode().split('<')[0][:-1], + commit.author.decode().split('<')[1][:-1], + datetime.datetime.fromtimestamp(commit.author_time, ).isoformat(), + commit.message.decode().split('\n')[0], + ] except NotGitRepository: pass diff --git a/InvenTree/plugin/plugin.py b/InvenTree/plugin/plugin.py index 4b2d2886cd..7288cee72c 100644 --- a/InvenTree/plugin/plugin.py +++ b/InvenTree/plugin/plugin.py @@ -348,6 +348,7 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase): # region package info def _get_package_commit(self): """Get last git commit for the plugin.""" + return get_git_log(str(self.file())) @classmethod