Skip to content

Commit

Permalink
Merge pull request #183 from marcospereira/add-short-tag
Browse files Browse the repository at this point in the history
Add a short_tag attribute to git context
  • Loading branch information
fralau authored Oct 25, 2023
2 parents 428a015 + 298f07f commit 82c5cdd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mkdocs_macros/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def get_git_info():
'short_commit': ['git', 'rev-parse', '--short', 'HEAD'],
'commit': ['git', 'rev-parse', 'HEAD'],
'tag': ['git', 'describe', '--tags'],
# With --abbrev set to 0, git will find the closest tagname without any suffix
'short_tag': ['git', 'describe', '--tags', '--abbrev=0'],
'author': LAST_COMMIT + ["--pretty=format:%an"],
'author_email': LAST_COMMIT + ["--pretty=format:%ae"],
'committer': LAST_COMMIT + ["--pretty=format:%cn"],
Expand Down
10 changes: 9 additions & 1 deletion webdoc/docs/git_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ Here is a list of attributes of the git object:


| Attribute | Description |
| ----------------- | ---------------------------------------------- |
|-------------------|------------------------------------------------|
| `short_commit` | short hash of the last commit (e.g. _2bd7950_) |
| `commit` | long hash of the last commit |
| `author` | author's name |
| `author_email` | author's email |
| `committer` | committer's name |
| `committer_email` | committer's email |
| `tag` | last active tag of the repo |
| `short_tag` | last active tag of the repo, abbreviated |
| `date` | full date of the commit (as a date object) |
| `date_ISO` | full date of the commit (as an ISO string) |
| `message` | full message of the last commit |
Expand Down Expand Up @@ -104,6 +105,13 @@ which would return e.g.

May 13, 2020 16:08:52

## `tag` and `short_tag`

The tag attribute shows the full description of the tag, for
example `v1.0.4-14-g2414721`. Meanwhile, `short_tag` shows the
tag name without any suffix, for example `v1.0.4`. The later can
be usefull when showing the latest release.

## Tip: Is this really a git repo?

In case you are not sure that there really is a git repo, you could use:
Expand Down

0 comments on commit 82c5cdd

Please sign in to comment.