Junio C Hamano | b4d2b04 | 2007-02-11 23:04:00 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | GVF=GIT-VERSION-FILE |
Junio C Hamano | 12644fa | 2010-09-15 12:34:37 -0700 | [diff] [blame] | 4 | DEF_VER=0.13.GITGUI |
Junio C Hamano | b4d2b04 | 2007-02-11 23:04:00 -0800 | [diff] [blame] | 5 | |
| 6 | LF=' |
| 7 | ' |
| 8 | |
Junio C Hamano | 67c7575 | 2007-02-12 16:07:29 -0800 | [diff] [blame] | 9 | tree_search () |
| 10 | { |
| 11 | head=$1 |
| 12 | tree=$2 |
Junio C Hamano | ea44949 | 2007-02-13 13:48:52 -0800 | [diff] [blame] | 13 | for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null) |
Junio C Hamano | 67c7575 | 2007-02-12 16:07:29 -0800 | [diff] [blame] | 14 | do |
| 15 | test $tree = $(git rev-parse $p^{tree} 2>/dev/null) && |
| 16 | vn=$(git describe --abbrev=4 $p 2>/dev/null) && |
| 17 | case "$vn" in |
| 18 | gitgui-[0-9]*) echo $vn; break;; |
| 19 | esac |
| 20 | done |
| 21 | } |
| 22 | |
Junio C Hamano | 5bac4a6 | 2007-02-21 11:09:57 -0800 | [diff] [blame] | 23 | # Always use the tarball version file if found, just |
| 24 | # in case we are somehow contained in a larger git |
| 25 | # repository that doesn't actually track our state. |
| 26 | # (At least one package manager is doing this.) |
| 27 | # |
Junio C Hamano | 67c7575 | 2007-02-12 16:07:29 -0800 | [diff] [blame] | 28 | # We may be a subproject, so try looking for the merge |
| 29 | # commit that supplied this directory content if we are |
| 30 | # not at the toplevel. We probably will always be the |
| 31 | # second parent in the commit, but we shouldn't rely on |
| 32 | # that fact. |
| 33 | # |
| 34 | # If we are at the toplevel or the merge assumption fails |
Junio C Hamano | 5bac4a6 | 2007-02-21 11:09:57 -0800 | [diff] [blame] | 35 | # try looking for a gitgui-* tag. |
Junio C Hamano | 67c7575 | 2007-02-12 16:07:29 -0800 | [diff] [blame] | 36 | |
Junio C Hamano | 5bac4a6 | 2007-02-21 11:09:57 -0800 | [diff] [blame] | 37 | if test -f version && |
| 38 | VN=$(cat version) |
| 39 | then |
| 40 | : happy |
| 41 | elif prefix="$(git rev-parse --show-prefix 2>/dev/null)" |
Junio C Hamano | 67c7575 | 2007-02-12 16:07:29 -0800 | [diff] [blame] | 42 | test -n "$prefix" && |
| 43 | head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) && |
| 44 | tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null) && |
| 45 | VN=$(tree_search $head $tree) |
Junio C Hamano | b4d2b04 | 2007-02-11 23:04:00 -0800 | [diff] [blame] | 46 | case "$VN" in |
Junio C Hamano | 67c7575 | 2007-02-12 16:07:29 -0800 | [diff] [blame] | 47 | gitgui-[0-9]*) : happy ;; |
| 48 | *) (exit 1) ;; |
Junio C Hamano | b4d2b04 | 2007-02-11 23:04:00 -0800 | [diff] [blame] | 49 | esac |
| 50 | then |
Junio C Hamano | 67c7575 | 2007-02-12 16:07:29 -0800 | [diff] [blame] | 51 | VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g'); |
| 52 | elif VN=$(git describe --abbrev=4 HEAD 2>/dev/null) && |
| 53 | case "$VN" in |
| 54 | gitgui-[0-9]*) : happy ;; |
| 55 | *) (exit 1) ;; |
| 56 | esac |
| 57 | then |
| 58 | VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g'); |
Junio C Hamano | b4d2b04 | 2007-02-11 23:04:00 -0800 | [diff] [blame] | 59 | else |
| 60 | VN="$DEF_VER" |
| 61 | fi |
| 62 | |
Junio C Hamano | b4d2b04 | 2007-02-11 23:04:00 -0800 | [diff] [blame] | 63 | dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty= |
| 64 | case "$dirty" in |
| 65 | '') |
| 66 | ;; |
| 67 | *) |
| 68 | VN="$VN-dirty" ;; |
| 69 | esac |
| 70 | |
| 71 | if test -r $GVF |
| 72 | then |
Junio C Hamano | 67c7575 | 2007-02-12 16:07:29 -0800 | [diff] [blame] | 73 | VC=$(sed -e 's/^GITGUI_VERSION = //' <$GVF) |
Junio C Hamano | b4d2b04 | 2007-02-11 23:04:00 -0800 | [diff] [blame] | 74 | else |
| 75 | VC=unset |
| 76 | fi |
| 77 | test "$VN" = "$VC" || { |
Junio C Hamano | 67c7575 | 2007-02-12 16:07:29 -0800 | [diff] [blame] | 78 | echo >&2 "GITGUI_VERSION = $VN" |
| 79 | echo "GITGUI_VERSION = $VN" >$GVF |
Junio C Hamano | b4d2b04 | 2007-02-11 23:04:00 -0800 | [diff] [blame] | 80 | } |