diff --git a/build/gen-git-version.sh b/build/gen-git-version.sh index bd5c8d5e..4fe07613 100755 --- a/build/gen-git-version.sh +++ b/build/gen-git-version.sh @@ -48,17 +48,17 @@ checksource () # already a hash, abbreviate hash=`echo $hash | sed -e 's/\(......\).*/\1/'` fi - # detect --g suffix added when tag is older than HEAD - if perl -e "exit !('$describe' =~ m/-[0-9]+-[0-9a-g]{8}\$/);"; then - # remove suffix to get tag (doesn't matter if we do not pick - # the most recent one) - exact= - tag=`echo $describe | sed -e 's/-[0123456789]*-g.*//'` - else + if git show-ref --tags | grep -q $hash; then # there is at least one tag matching HEAD; # pick the most recent one (based on lexical sorting) exact=1 tag=`git show-ref --tags | grep $hash | sort | tail -1 | sed -e 's;.*refs/tags/;;'` + else + # Detect --g suffix added when tag is older than HEAD. + # Remove suffix to get tag (doesn't matter if we do not pick + # the most recent one). + exact= + tag=`echo $describe | sed -e 's/-[0123456789]*-g.*//'` fi simpletag=$tag # Hyphens between numbers in the tag are dots in the version