Created
July 11, 2023 13:37
-
-
Save metal3d/0934941c51a8511f0d7d0756c759b923 to your computer and use it in GitHub Desktop.
Clean git version in your Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the current clean version from your git repo | |
# - -tagname if the current commit is tagged and no changes were detected | |
# - branchname-sha if not | |
# - branchname-sha-dirty if changes were detected and not commited | |
# Use $(VERSION) to get it, wherever you want in your commands | |
VERSION=$(shell \ | |
git describe --exact-match --tags --dirty 2>/dev/null || \ | |
printf "%s-%s%s" \ | |
$(shell git branch --show-current) \ | |
$(shell git log -n1 --pretty=%h) \ | |
$(shell git diff --quiet || echo "-dirty") \ | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment