Closed garlick closed 3 years ago
Use git describe --tags
plus some crafting if you need. --tags
will always give you the latest unannotated tag plus a distance from the last annotated one. I rarely use annotated.
$ git describe --long --tag --abbrev=7
2.6.1-31-gd1c2418
$ git describe --long --tags --abbrev=7 | cut -d - -f1
2.6.1
the 31
is for the last release commit if you need
the gd1c2418
is the abbreviated HEAD commit with a leading g
for git. I usually trim it.
$ git describe --long --tags --abbrev=7 | rev | cut -d g -f 1 | rev
d1c2418
Or I take the first line and put it into a variable and work on that.
# get whole commit and parse
# if tagrev > 0 then add it and commit to micro version
# Expected format is:
# v#.#.#-#-g#######
init() {
if [ -d '.git' ] ; then
describe_tag=$(git describe $tagopt --long --abbrev=7)
describe_tag=${describe_tag/v/}
describe_tag=${describe_tag/g/}
commit=$(echo $describe_tag | cut -d- -f3)
tagrev=$(echo $describe_tag | cut -d- -f2)
version=$(echo $describe_tag | cut -d- -f1)
micro=$(echo $version | cut -d. -f3)
[ $tagrev -gt 0 ] && micro=$micro-$tagrev-$commit
minor=$(echo $version | cut -d. -f2)
major=$(echo $version | cut -d. -f1)
elif [ -r VERSION ] ; then
major=$(awk '/Major: / {printf "%s",$2; exit}' VERSION)
minor=$(awk '/Minor: / {printf "%s",$2; exit}' VERSION)
micro=$(awk '/Micro: / {printf "%s",$2; exit}' VERSION)
else
echo "Cannot find .git or VERSION file. Aborting"
exit 1
fi
}
You'll appreciate the code I borrowed to check for a VERSION file in root. But this code is more or less customized for my project lrzip-next
Oh thanks, I'll go ahead and add the --tags
option given that we only have lightweight tags so far. I'll probably start using annotated tags after this since that's generally accepted as the best practice. I do want to not get too far off of the other projects my team maintains so that we can all pitch in without getting confused.
Thanks!
Problem: #29 missed a couple of things needed to fully expunge AUTHORS and META from the build system.
Fix those here.
Also, increase the signal to noise ratio in the build output by setting AM_SILENT_RULES and fixing a build warning in a test program.
Note to @pete4abw: the
git describe --always
output is 3d25926 currently. This is because none of our tags were annotated tags. I'll make sure the next tag is an annotated tag, and then we'll get the actual version when we make the dist tarball for the tag, and a version with the short commit appended for devel versions in between. Here is a demonstration that a dist tarball still works after dropping META.