2007-02-12 15:04:00 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
GVF=GIT-VERSION-FILE
|
2011-12-14 08:48:24 +08:00
|
|
|
DEF_VER=0.16.GITGUI
|
2007-02-12 15:04:00 +08:00
|
|
|
|
|
|
|
LF='
|
|
|
|
'
|
|
|
|
|
2007-02-13 08:07:29 +08:00
|
|
|
tree_search ()
|
|
|
|
{
|
|
|
|
head=$1
|
|
|
|
tree=$2
|
2007-02-14 05:48:52 +08:00
|
|
|
for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null)
|
2007-02-13 08:07:29 +08: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-22 03:09:57 +08: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-13 08:07:29 +08: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-22 03:09:57 +08:00
|
|
|
# try looking for a gitgui-* tag.
|
2007-02-13 08:07:29 +08:00
|
|
|
|
2007-02-22 03:09:57 +08:00
|
|
|
if test -f version &&
|
|
|
|
VN=$(cat version)
|
|
|
|
then
|
|
|
|
: happy
|
|
|
|
elif prefix="$(git rev-parse --show-prefix 2>/dev/null)"
|
2007-02-13 08:07:29 +08: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)
|
2007-02-12 15:04:00 +08:00
|
|
|
case "$VN" in
|
2007-02-13 08:07:29 +08:00
|
|
|
gitgui-[0-9]*) : happy ;;
|
|
|
|
*) (exit 1) ;;
|
2007-02-12 15:04:00 +08:00
|
|
|
esac
|
|
|
|
then
|
2007-02-13 08:07:29 +08:00
|
|
|
VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
|
|
|
|
elif VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
|
|
|
|
case "$VN" in
|
|
|
|
gitgui-[0-9]*) : happy ;;
|
|
|
|
*) (exit 1) ;;
|
|
|
|
esac
|
|
|
|
then
|
|
|
|
VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
|
2007-02-12 15:04:00 +08: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-13 08:07:29 +08:00
|
|
|
VC=$(sed -e 's/^GITGUI_VERSION = //' <$GVF)
|
2007-02-12 15:04:00 +08:00
|
|
|
else
|
|
|
|
VC=unset
|
|
|
|
fi
|
|
|
|
test "$VN" = "$VC" || {
|
2007-02-13 08:07:29 +08:00
|
|
|
echo >&2 "GITGUI_VERSION = $VN"
|
|
|
|
echo "GITGUI_VERSION = $VN" >$GVF
|
2007-02-12 15:04:00 +08:00
|
|
|
}
|