Skip to content

Commit

Permalink
Enhance commit tag context extension
Browse files Browse the repository at this point in the history
  • Loading branch information
neoxelox committed Jul 16, 2022
1 parent 337ebf1 commit d06a7e5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions superinvoke/extensions/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ def branch(context: Context) -> str:
return context.attempt("git rev-parse --abbrev-ref HEAD")


# Gets the current commit tag if any.
def tag(context: Context) -> Optional[str]:
result = context.attempt("git name-rev --name-only --tags HEAD").replace("^0", "")
return result if result != "undefined" else None
# Gets the current or latest commit tag if any.
def tag(context: Context, current: bool = True) -> Optional[str]:
if current:
result = context.attempt("git name-rev --name-only --tags HEAD").replace("^0", "")
else:
result = context.attempt("git describe --tags --abbrev=0").replace("^0", "")

if "undefined" in result or "fatal" in result:
result = None

return result


# Gets the N last changes.
Expand Down

0 comments on commit d06a7e5

Please sign in to comment.