Update version number script to work with git 2.1.4.
[arvados.git] / build / version-at-commit.sh
1 #!/bin/bash
2
3 set -e -o pipefail
4 commit="$1"
5 versionglob="[0-9].[0-9]*.[0-9]*"
6
7 if ! git describe --exact-match --match "$versionglob" "$commit" 2>/dev/null; then
8     if git merge-base --is-ancestor "$commit" origin/master; then
9         # x.(y+1).0.preTIMESTAMP, where x.y.z is the newest version that does not contain $commit
10         v=$(git tag | grep -vFf <(git tag --contains "$commit") | sort -Vr | head -n1 | perl -pe 's/\.(\d+)\.\d+/".".($1+1).".0"/e')
11     else
12         # x.y.(z+1).preTIMESTAMP, where x.y.z is the latest released ancestor of $commit
13         v=$(git describe --abbrev=0 --match "$versionglob" "$commit" | perl -pe 's/(\d+)$/$1+1/e')
14     fi
15     isodate=$(TZ=UTC git log -n1 --format=%cd --date=iso "$commit")
16     ts=$(TZ=UTC date --date="$isodate" "+%Y%m%d%H%M%S")
17     echo "$v.pre$ts"
18 fi