Handle case where git head is detached (#5161)

- branch information does not exist in this case
- Fixes https://github.com/inventree/InvenTree/issues/5133
This commit is contained in:
Oliver 2023-07-04 21:57:23 +10:00 committed by GitHub
parent 637a0ca7a5
commit d52a839cf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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():