blob: 2b97352dd3b113b46bbd53248315ab91f0a9356b [file] [log] [blame]
Junio C Hamano9b88fce2005-12-27 14:40:17 -08001#!/bin/sh
2
3GVF=GIT-VERSION-FILE
Junio C Hamano5f95c9f2014-02-14 11:35:04 -08004DEF_VER=v1.9.0
Junio C Hamano9b88fce2005-12-27 14:40:17 -08005
Junio C Hamanoc96c2902006-08-08 13:11:16 -07006LF='
7'
8
Junio C Hamano204d4092007-02-14 11:33:04 -08009# First see if there is a version file (included in release tarballs),
10# then try git-describe, then default.
11if test -f version
Junio C Hamano0b8b0512006-03-02 14:38:44 -080012then
Uwe Zeisberger374dfaa2006-01-26 17:39:27 +010013 VN=$(cat version) || VN="$DEF_VER"
Dennis Kaarsemaker05a95062013-06-16 01:01:11 +020014elif test -d ${GIT_DIR:-.git} -o -f .git &&
Junio C Hamanobf505152012-05-01 21:18:44 -070015 VN=$(git describe --match "v[0-9]*" --abbrev=7 HEAD 2>/dev/null) &&
Junio C Hamano204d4092007-02-14 11:33:04 -080016 case "$VN" in
17 *$LF*) (exit 1) ;;
Junio C Hamanoe5fc9a02008-02-16 22:44:31 -080018 v[0-9]*)
Junio C Hamanob13d4402008-08-08 13:31:27 -070019 git update-index -q --refresh
Lea Wiemann935e2472008-06-28 19:13:29 +020020 test -z "$(git diff-index --name-only HEAD --)" ||
Junio C Hamano31e0b2c2008-02-23 11:31:04 -080021 VN="$VN-dirty" ;;
Junio C Hamano204d4092007-02-14 11:33:04 -080022 esac
23then
24 VN=$(echo "$VN" | sed -e 's/-/./g');
Junio C Hamano0b8b0512006-03-02 14:38:44 -080025else
26 VN="$DEF_VER"
Uwe Zeisberger374dfaa2006-01-26 17:39:27 +010027fi
H. Peter Anvin181129d2006-01-09 18:07:01 -080028
29VN=$(expr "$VN" : v*'\(.*\)')
Junio C Hamanoeb858c62006-01-09 14:25:10 -080030
Junio C Hamano9b88fce2005-12-27 14:40:17 -080031if test -r $GVF
32then
33 VC=$(sed -e 's/^GIT_VERSION = //' <$GVF)
34else
35 VC=unset
36fi
37test "$VN" = "$VC" || {
38 echo >&2 "GIT_VERSION = $VN"
39 echo "GIT_VERSION = $VN" >$GVF
40}
41
42