2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-15 19:45:46 +00:00

fix(backend): determine active branch on startup (#9056)

* fix(backend): Determine active branch on startup

* add more warnings and document them

* extend expected errors

* fix typos
This commit is contained in:
Matthias Mair
2025-02-10 23:19:49 +01:00
committed by GitHub
parent 4df6e980ba
commit 047431d67f
2 changed files with 31 additions and 9 deletions

View File

@ -26,19 +26,28 @@ logger = logging.getLogger('inventree')
# Discover git
try:
from dulwich.porcelain import active_branch
from dulwich.repo import Repo
main_repo = Repo(pathlib.Path(__file__).parent.parent.parent.parent.parent)
main_commit = main_repo[main_repo.head()]
try:
main_branch = active_branch(main_repo)
except (KeyError, IndexError):
logger.warning('INVE-W1: Current branch could not be detected.')
main_branch = None
except ImportError:
logger.warning(
'Warning: Dulwich module not found, git information will not be available.'
'INVE-W2: Dulwich module not found, git information will not be available.'
)
main_repo = None
main_commit = None
except Exception:
main_branch = None
except Exception as exc:
logger.warning('INVE-W3: Could not detect git information.', exc_info=exc)
main_repo = None
main_commit = None
main_branch = None
def checkMinPythonVersion():
@ -270,14 +279,9 @@ def inventreeBranch():
if branch:
return branch
if main_commit is None:
if main_branch is None:
return None
try:
branch = main_repo.refs.follow(b'HEAD')[0][1].decode()
return branch.removeprefix('refs/heads/')
except IndexError:
return None # pragma: no cover
return main_branch.decode('utf-8')
def inventreeTarget():