2007-01-21 02:31:09 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
GVF=GIT-VERSION-FILE
|
2010-09-14 23:42:37 +02:00
|
|
|
DEF_VER=0.13.GITGUI
|
2007-01-21 02:31:09 +01:00
|
|
|
|
|
|
|
LF='
|
|
|
|
'
|
|
|
|
|
2007-02-12 23:05:10 +01:00
|
|
|
tree_search ()
|
|
|
|
{
|
|
|
|
head=$1
|
|
|
|
tree=$2
|
2007-02-13 16:26:16 +01:00
|
|
|
for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null)
|
2007-02-12 23:05:10 +01:00
|
|
|
do
|
|
|
|
test $tree = $(git rev-parse $p^{tree} 2>/dev/null) &&
|
|
|
|
vn=$(git describe --abbrev=4 $p 2>/dev/null) &&
|
|
|
|
case "$vn" in
|
|
|
|
gitgui-[0-9]*) echo $vn; break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2007-02-14 07:55:16 +01:00
|
|
|
# Always use the tarball version file if found, just
|
|
|
|
# in case we are somehow contained in a larger git
|
|
|
|
# repository that doesn't actually track our state.
|
|
|
|
# (At least one package manager is doing this.)
|
|
|
|
#
|
2007-02-12 23:05:10 +01:00
|
|
|
# We may be a subproject, so try looking for the merge
|
|
|
|
# commit that supplied this directory content if we are
|
|
|
|
# not at the toplevel. We probably will always be the
|
|
|
|
# second parent in the commit, but we shouldn't rely on
|
|
|
|
# that fact.
|
|
|
|
#
|
|
|
|
# If we are at the toplevel or the merge assumption fails
|
2007-02-14 07:55:16 +01:00
|
|
|
# try looking for a gitgui-* tag.
|
2007-02-12 23:05:10 +01:00
|
|
|
|
2007-02-14 07:55:16 +01:00
|
|
|
if test -f version &&
|
|
|
|
VN=$(cat version)
|
|
|
|
then
|
|
|
|
: happy
|
|
|
|
elif prefix="$(git rev-parse --show-prefix 2>/dev/null)"
|
2007-02-12 23:05:10 +01:00
|
|
|
test -n "$prefix" &&
|
|
|
|
head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
|
|
|
|
tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
|
|
|
|
VN=$(tree_search $head $tree)
|
|
|
|
case "$VN" in
|
|
|
|
gitgui-[0-9]*) : happy ;;
|
|
|
|
*) (exit 1) ;;
|
|
|
|
esac
|
|
|
|
then
|
|
|
|
VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
|
|
|
|
elif VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
|
2007-01-21 02:31:09 +01:00
|
|
|
case "$VN" in
|
2007-02-12 22:38:29 +01:00
|
|
|
gitgui-[0-9]*) : happy ;;
|
2007-02-12 23:05:10 +01:00
|
|
|
*) (exit 1) ;;
|
2007-01-21 02:31:09 +01:00
|
|
|
esac
|
|
|
|
then
|
2007-02-12 22:38:29 +01:00
|
|
|
VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
|
2007-01-21 02:31:09 +01:00
|
|
|
else
|
|
|
|
VN="$DEF_VER"
|
|
|
|
fi
|
|
|
|
|
|
|
|
dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty=
|
|
|
|
case "$dirty" in
|
|
|
|
'')
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
VN="$VN-dirty" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if test -r $GVF
|
|
|
|
then
|
2007-02-12 22:12:04 +01:00
|
|
|
VC=$(sed -e 's/^GITGUI_VERSION = //' <$GVF)
|
2007-01-21 02:31:09 +01:00
|
|
|
else
|
|
|
|
VC=unset
|
|
|
|
fi
|
|
|
|
test "$VN" = "$VC" || {
|
2007-02-12 22:12:04 +01:00
|
|
|
echo >&2 "GITGUI_VERSION = $VN"
|
|
|
|
echo "GITGUI_VERSION = $VN" >$GVF
|
2007-01-21 02:31:09 +01:00
|
|
|
}
|