diff --git a/mkdocs_macros/context.py b/mkdocs_macros/context.py index e5596c5..eccc285 100644 --- a/mkdocs_macros/context.py +++ b/mkdocs_macros/context.py @@ -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"], diff --git a/webdoc/docs/git_info.md b/webdoc/docs/git_info.md index 3c8dfb0..b6b3002 100644 --- a/webdoc/docs/git_info.md +++ b/webdoc/docs/git_info.md @@ -52,7 +52,7 @@ 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 | @@ -60,6 +60,7 @@ Here is a list of attributes of the git object: | `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 | @@ -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: