Get git log fix (#5113)

* Simplify extraction of git repo

- Replace Repo.discover() with Repo()
- Ensure provided path is directory

* Remove profiling code
This commit is contained in:
Oliver 2023-06-30 13:43:54 +10:00 committed by GitHub
parent c8642bedcd
commit 7955d1f579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View File

@ -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

View File

@ -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