GIT-VERSION-GENon commit describe: match pattern for lightweight tags too (4ed19a3)
   1#!/bin/sh
   2
   3GVF=GIT-VERSION-FILE
   4DEF_VER=v1.5.5.3.GIT
   5
   6LF='
   7'
   8
   9# First see if there is a version file (included in release tarballs),
  10# then try git-describe, then default.
  11if test -f version
  12then
  13        VN=$(cat version) || VN="$DEF_VER"
  14elif test -d .git &&
  15        VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
  16        case "$VN" in
  17        *$LF*) (exit 1) ;;
  18        v[0-9]*)
  19                test -z "$(git diff-index --name-only HEAD)" ||
  20                VN="$VN-dirty" ;;
  21        esac
  22then
  23        VN=$(echo "$VN" | sed -e 's/-/./g');
  24else
  25        VN="$DEF_VER"
  26fi
  27
  28VN=$(expr "$VN" : v*'\(.*\)')
  29
  30if test -r $GVF
  31then
  32        VC=$(sed -e 's/^GIT_VERSION = //' <$GVF)
  33else
  34        VC=unset
  35fi
  36test "$VN" = "$VC" || {
  37        echo >&2 "GIT_VERSION = $VN"
  38        echo "GIT_VERSION = $VN" >$GVF
  39}
  40
  41