version/1.0
[ng-jackspa.git] / version.sh
blob7192d29f3b6dad09445aa73df5d493ac3933986e
1 #!/bin/sh
2 # version.sh - execute in the root of the project to get the version number
4 # Unlimited permission to copy, distribute and modify this file is granted.
5 # This file is offered as-is, without any warranty.
7 test $# -gt 0 && PACKAGE_NAME=$1
8 PACKAGE_NAME=${PACKAGE_NAME=ngjackspa}
9 DEF_VER="unknown_version"
11 NL='
14 # First try git-describe, then see if there is a VERSION file (included in
15 # release tarballs), then see if the project directory matches the project
16 # name, then use the default.
18 test -d .git || test -f .git &&
19 VN=$(git describe --abbrev=7 --match "version/*" --tags HEAD --always 2>/dev/null) &&
20 case $VN in
21 *$NL*)
22 false ;;
23 version/*)
24 git update-index -q --refresh
25 test -z "$(git diff-index --name-only HEAD --)" ||
26 VN="$VN.dirty" ;;
27 esac
28 then
29 VN=$(echo "$VN" | sed -e 's#^[vV][eE][rR][a-zA-Z]\{0,\}/##' -e 's/-/+/' -e 's/-/_/')
30 # <tag>+<num-of-commits>_g<hash>.dirty
31 elif
32 test -f VERSION && test -s VERSION
33 then
34 VN=$(cat VERSION) || VN=$DEF_VER
35 elif
36 VN=$(pwd | sed -e 's#^.\{0,\}/##') &&
37 test x"$VN" != x"${VN#"$PACKAGE_NAME-"}"
38 then
39 VN=${VN#"$PACKAGE_NAME-"}
40 else
41 VN=$DEF_VER
44 echo "$VN"