From 4c830fb1679c329aabab2e878a0445aa12b26944 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 15 Apr 2025 23:21:48 +0200 Subject: [PATCH] fix(backend): reduce noice in docker image start (#9515) make dulwich detection less loud --- src/backend/InvenTree/InvenTree/version.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/version.py b/src/backend/InvenTree/InvenTree/version.py index ab9a0f31b0..5ee6f1af66 100644 --- a/src/backend/InvenTree/InvenTree/version.py +++ b/src/backend/InvenTree/InvenTree/version.py @@ -26,13 +26,21 @@ logger = logging.getLogger('inventree') # Discover git try: + from dulwich.errors import NotGitRepository 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) + main_repo = Repo(pathlib.Path(__file__).parent.parent.parent.parent.parent) + main_commit = main_repo[main_repo.head()] + except NotGitRepository: + # If we are running in a docker container, the repo may not be available + logger.warning('INVE-W3: Could not detect git information.') + main_repo = None + main_commit = None + + try: + main_branch = active_branch(main_repo) if main_repo else None except (KeyError, IndexError): logger.warning('INVE-W1: Current branch could not be detected.') main_branch = None