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=archives2git}
8 DEF_VER
="unknown_version"
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
) &&
23 git update-index
-q --refresh
24 test -z "$(git diff-index --name-only HEAD --)" ||
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
31 test -d .git ||
test -f .git
&&
32 VN
=$
(git describe
--abbrev=7 --match "version/*" --tags HEAD
--always 2>/dev
/null
) &&
37 git update-index
-q --refresh
38 test -z "$(git diff-index --name-only HEAD --)" ||
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
45 test -f VERSION
&& test -s VERSION
47 VN
=$
(cat VERSION
) || VN
=$DEF_VER
49 VN
=$
(pwd |
sed -e 's#^.\{0,\}/##') &&
50 test x
"$VN" != x
"${VN#"$PACKAGE_NAME-"}"
52 VN
=${VN#"$PACKAGE_NAME-"}