diff --git a/docs/docs/settings/error_codes.md b/docs/docs/settings/error_codes.md index bd702feb74..c613c27d62 100644 --- a/docs/docs/settings/error_codes.md +++ b/docs/docs/settings/error_codes.md @@ -25,6 +25,24 @@ You probably have a reference to invoke or a directory with invoke in your PATH ### INVE-W (InvenTree Warning) Warnings - These are non-critical errors which should be addressed when possible. +#### INVE-W1 +**Current branch could not be detected - Backend** + +During startup of the backend InvenTree tries to detect branch, commit hash and commit date to surface on various points in the UI, through tags and in the API. +This information is not needed for operation but very helpful for debugging and support. These issues might be caused by running a deployment version that delivers without git information, not having git installed or not having dulwich installed. +You can ignore this warning if you are not interested in the git information. + +#### INVE-W2 +**Dulwich module not found - Backend** + +See [INVE-W1](#inve-w1) + +#### INVE-W3 +**Could not detect git information - Backend** + +See [INVE-W1](#inve-w1) + + ### INVE-I (InvenTree Information) Information — These are not errors but information messages. They might point out potential issues or just provide information. diff --git a/src/backend/InvenTree/InvenTree/version.py b/src/backend/InvenTree/InvenTree/version.py index 64a10ffb1b..9aad2e65d8 100644 --- a/src/backend/InvenTree/InvenTree/version.py +++ b/src/backend/InvenTree/InvenTree/version.py @@ -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():