*: determine version from git

This commit is contained in:
Eric Chiang
2016-08-09 14:38:09 -07:00
parent b8e80ffa3a
commit e6f34e1051
4 changed files with 36 additions and 21 deletions

21
scripts/git-version Executable file

@@ -0,0 +1,21 @@
#!/bin/bash -e
# parse the current git commit hash
COMMIT=`git rev-parse HEAD`
# check if the current commit has a matching tag
TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true)
# use the matching tag as the version, if available
if [ -z "$TAG" ]; then
VERSION=$COMMIT
else
VERSION=$TAG
fi
# check for changed files (not untracked files)
if [ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]; then
VERSION="${VERSION}-dirty"
fi
echo $VERSION