Skip to content
Snippets Groups Projects
Commit f8509381 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-289: Fix lofar_logging for use on detached head, and to allow detection...

L2SS-289: Fix lofar_logging for use on detached head, and to allow detection if its own git repo if run as a direct command.
parent c157654a
No related branches found
No related tags found
1 merge request!68L2SS-289: Rewrite of logging structure
......@@ -2,7 +2,7 @@ import git # pip3 install gitpython
import os
from functools import lru_cache
def get_repo(starting_directory: str = os.path.dirname(__file__)) -> git.Repo:
def get_repo(starting_directory: str = os.path.dirname(os.path.abspath(__file__))) -> git.Repo:
""" Try finding the repository by traversing up the tree.
By default, the repository containing this module is returned.
......@@ -50,14 +50,20 @@ def get_version(repo: git.Repo = None) -> str:
if repo is None:
repo = get_repo()
branch = repo.active_branch
commit = repo.commit()
tags = {tag.commit: tag for tag in repo.tags}
if commit in tags:
# a tag = production ready
commit_str = "{}".format(tags[commit])
production_ready = True
elif repo.head.is_detached:
# no active branch
commit_str = "<detached HEAD> [{}]".format(commit)
production_ready = False
else:
# HEAD of a branch
branch = repo.active_branch
commit_str = "{} [{}]".format(branch, commit)
production_ready = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment