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