From d52a839cf26893f812dec6a9d8e6a40147cf5029 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 4 Jul 2023 21:57:23 +1000 Subject: [PATCH] Handle case where git head is detached (#5161) - branch information does not exist in this case - Fixes https://github.com/inventree/InvenTree/issues/5133 --- InvenTree/InvenTree/version.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index fdb8e5b907..72e2551b66 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -162,8 +162,11 @@ def inventreeBranch(): if main_commit is None: return None - branch = main_repo.refs.follow(b'HEAD')[0][1].decode() - return branch.removeprefix('refs/heads/') + try: + branch = main_repo.refs.follow(b'HEAD')[0][1].decode() + return branch.removeprefix('refs/heads/') + except IndexError: + return None # pragma: no cover def inventreeTarget():