git-gui: Handle gitgui tags in version gen.
[git/git.git] / GIT-VERSION-GEN
CommitLineData
f1cee4e6
SP
1#!/bin/sh
2
3GVF=GIT-VERSION-FILE
6a6459bc 4DEF_VER=0.5.GIT
f1cee4e6
SP
5
6LF='
7'
8
9# First try git-describe, then see if there is a version file
10# (included in release tarballs), then default
11if VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
12 case "$VN" in
13 *$LF*) (exit 1) ;;
6a6459bc 14 gitgui-[0-9]*) : happy ;;
f1cee4e6
SP
15 esac
16then
6a6459bc 17 VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
f1cee4e6
SP
18elif test -f version
19then
20 VN=$(cat version) || VN="$DEF_VER"
21else
22 VN="$DEF_VER"
23fi
24
f1cee4e6
SP
25dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty=
26case "$dirty" in
27'')
28 ;;
29*)
30 VN="$VN-dirty" ;;
31esac
32
33if test -r $GVF
34then
7e81d4ee 35 VC=$(sed -e 's/^GITGUI_VERSION = //' <$GVF)
f1cee4e6
SP
36else
37 VC=unset
38fi
39test "$VN" = "$VC" || {
7e81d4ee
SP
40 echo >&2 "GITGUI_VERSION = $VN"
41 echo "GITGUI_VERSION = $VN" >$GVF
f1cee4e6
SP
42}
43
44