Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a short_tag attribute to git context #183

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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