Skip to content

Commit 298f07f

Browse files
committed
Add a short_tag attribute to git context
1 parent 428a015 commit 298f07f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mkdocs_macros/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def get_git_info():
141141
'short_commit': ['git', 'rev-parse', '--short', 'HEAD'],
142142
'commit': ['git', 'rev-parse', 'HEAD'],
143143
'tag': ['git', 'describe', '--tags'],
144+
# With --abbrev set to 0, git will find the closest tagname without any suffix
145+
'short_tag': ['git', 'describe', '--tags', '--abbrev=0'],
144146
'author': LAST_COMMIT + ["--pretty=format:%an"],
145147
'author_email': LAST_COMMIT + ["--pretty=format:%ae"],
146148
'committer': LAST_COMMIT + ["--pretty=format:%cn"],

webdoc/docs/git_info.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ Here is a list of attributes of the git object:
5252

5353

5454
| Attribute | Description |
55-
| ----------------- | ---------------------------------------------- |
55+
|-------------------|------------------------------------------------|
5656
| `short_commit` | short hash of the last commit (e.g. _2bd7950_) |
5757
| `commit` | long hash of the last commit |
5858
| `author` | author's name |
5959
| `author_email` | author's email |
6060
| `committer` | committer's name |
6161
| `committer_email` | committer's email |
6262
| `tag` | last active tag of the repo |
63+
| `short_tag` | last active tag of the repo, abbreviated |
6364
| `date` | full date of the commit (as a date object) |
6465
| `date_ISO` | full date of the commit (as an ISO string) |
6566
| `message` | full message of the last commit |
@@ -104,6 +105,13 @@ which would return e.g.
104105

105106
May 13, 2020 16:08:52
106107

108+
## `tag` and `short_tag`
109+
110+
The tag attribute shows the full description of the tag, for
111+
example `v1.0.4-14-g2414721`. Meanwhile, `short_tag` shows the
112+
tag name without any suffix, for example `v1.0.4`. The later can
113+
be usefull when showing the latest release.
114+
107115
## Tip: Is this really a git repo?
108116

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

0 commit comments

Comments
 (0)