version/0.1
[cdimgtools.git] / version.sh
blobb2777c8c53ddc319445db9956b0c611a8d78f7cf
1 #!/bin/sh
2 # Execute in the root of the project to get the version
4 [ $# -gt 0 ] && PACKAGE_NAME=$1
5 PACKAGE_NAME=${PACKAGE_NAME:-cdimgtools}
6 DEF_VER="unknown_version"
8 LF='
11 # First try git-describe, then see if there is a VERSION file (included in
12 # release tarballs), then see if the project directory matches the project
13 # name, then use the default.
14 if test -d .git -o -f .git &&
15 VN=$(git describe --abbrev=7 --match "version/*" --tags HEAD --always 2>/dev/null) &&
16 case "$VN" in
17 (*$LF*) false ;;
18 (version/*)
19 git update-index -q --refresh
20 test -z "$(git diff-index --name-only HEAD --)" ||
21 VN="$VN.dirty" ;;
22 esac
23 then
24 VN=$(echo "$VN" | sed -e 's#^\(ver\|VER\)[a-zA-Z]*/##' -e 's/-/+/' -e 's/-/_/')
25 # <tag>+<num-of-commits>_g<hash>.dirty
26 elif test -f VERSION && test -s VERSION
27 then
28 VN=$(cat VERSION) || VN="$DEF_VER"
29 elif VN=$(pwd -P | sed -e 's#^.*/##') &&
30 test x"$VN" != x"${VN#"$PACKAGE_NAME-"}"
31 then
32 VN=${VN#"$PACKAGE_NAME-"}
33 else
34 VN="$DEF_VER"
37 echo -n "$VN"