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