[Diff] Give priority to a tag if we are exactly at the tag

This commit is contained in:
Salvador E. Tropea 2022-09-06 10:37:48 -03:00
parent 947542747f
commit 43aae8b0fe
1 changed files with 24 additions and 13 deletions

View File

@ -209,21 +209,32 @@ class DiffOptions(BaseOptions):
return res
def get_git_point_desc(self, user_name):
branch = self.run_git(['rev-parse', '--abbrev-ref', 'HEAD'])
if branch == 'HEAD':
# Detached
# Try to find the name relative to a tag
try:
name = self.run_git(['describe', '--tags', '--dirty'], just_raise=True)
except CalledProcessError:
logger.debug("Can't find a tag name")
name = None
if not name:
name = user_name
else:
name = branch
# Are we at a tagged point?
try:
name = self.run_git(['describe', '--exact-match', '--tags', 'HEAD'], just_raise=True)
if user_name == 'Dirty':
name += '-dirty'
except CalledProcessError:
logger.debug("Not at a tag point")
name = None
if name is None:
# Are we at the HEAD of a branch?
branch = self.run_git(['rev-parse', '--abbrev-ref', 'HEAD'])
if branch == 'HEAD':
# Detached state
# Try to find the name relative to a tag
try:
name = self.run_git(['describe', '--tags', '--dirty'], just_raise=True)
except CalledProcessError:
logger.debug("Can't find a tag name")
name = None
if not name:
# Nothing usable, use what the user specified
name = user_name
else:
name = branch
if user_name == 'Dirty':
name += '-dirty'
return '{}({})'.format(self.run_git(['rev-parse', '--short', 'HEAD']), name)
def git_dirty(self):