13         for p in $(git rev-list --parents --max-count=1 $head 2>/dev/null)
 
  15                 test $tree = $(git rev-parse $p^{tree} 2>/dev/null) &&
 
  16                 vn=$(git describe --abbrev=4 $p 2>/dev/null) &&
 
  18                 gitgui-[0-9]*) echo $vn; break;;
 
  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.)
 
  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
 
  34 # If we are at the toplevel or the merge assumption fails
 
  35 # try looking for a gitgui-* tag.
 
  41 elif prefix="$(git rev-parse --show-prefix 2>/dev/null)"
 
  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)
 
  47    gitgui-[0-9]*) : happy ;;
 
  51         VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
 
  52 elif VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
 
  54    gitgui-[0-9]*) : happy ;;
 
  58         VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
 
  63 dirty=$(sh -c 'git diff-index --name-only HEAD' 2>/dev/null) || dirty=
 
  73         VC=$(sed -e 's/^GITGUI_VERSION = //' <$GVF)
 
  77 test "$VN" = "$VC" || {
 
  78         echo >&2 "GITGUI_VERSION = $VN"
 
  79         echo "GITGUI_VERSION = $VN" >$GVF