From 848184577a04bee1ccd8d424b17f5e19acb297f1 Mon Sep 17 00:00:00 2001 From: Brandon Witham Date: Thu, 23 Feb 2017 13:08:56 -0500 Subject: [PATCH] restore GitVersion --- docs/Makefile | 2 +- scripts/git/GitVersion.sh | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 scripts/git/GitVersion.sh diff --git a/docs/Makefile b/docs/Makefile index d977687186..be33fb324b 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -11,7 +11,7 @@ endif define buildAsciidoc mkdir -p tmp git log --simplify-by-decoration --no-merges "--pretty=%h|$$|%ct|$$|%s|$$|%aN" `find $(filter-out tmp/asciidoc-config,$^) || true` | node ParseRevisions.js > $(patsubst %.asciidoc,%-docinfo.xml,$<) - @REVNUMBER=`$$HOOT_HOME/scripts/GitVersion.sh` ; \ + @REVNUMBER=`$$HOOT_HOME/scripts/git/GitVersion.sh` ; \ REVDATE=`date -d @$$(git log -n 1 "--pretty=%at" ../.) "+%B %e, %Y"`; \ a2x -a docinfo --dblatex-opts "-P latex.output.revhistory=0 -P latex.unicode.use=1 -s styles/nga.sty --param doc.publisher.show=0" -a HasLatexMath -a "revdate=v$$REVNUMBER, $$REVDATE" $(A2X_QUIET) -f pdf $< a2x -a docinfo --dblatex-opts "-P latex.output.revhistory=0 -P latex.unicode.use=1 -s styles/nga.sty --param doc.publisher.show=0" -a "revdate=v$$REVNUMBER, $$REVDATE" $(A2X_QUIET) -f text $< diff --git a/scripts/git/GitVersion.sh b/scripts/git/GitVersion.sh new file mode 100755 index 0000000000..422d129d4f --- /dev/null +++ b/scripts/git/GitVersion.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Provides a slightly more pleasant version number than the typical hash value. +# +# Optionally takes a list of files. If provided, then the latest commit of +# any of the files is used for calculating the version number. +# +# If there is no version information then UNKNOWN is returned. + +set -e + +DEF_VER=UNKNOWN-VERSION + +LF=' +' + +# Is this a git repo? Do we have git? +if command -v git &> /dev/null; then + if git status &> /dev/null; then + HAS_GIT=true + fi +fi + +REVISION=`git log -n 1 --pretty=%h $*` + +# First see if there is a version file (included in release tarballs), +# then try git-describe, then default. +if test "$HAS_GIT" = "true" && + VN=$(git describe --match "v[0-9]*" --abbrev=7 --tags $REVISION 2>/dev/null) && + case "$VN" in + *$LF*) (exit 1) ;; + v[0-9]*) + git update-index -q --refresh + test -z "$(git diff-index --name-only HEAD --)" || + VN="$VN-dirty" ;; + esac +then + #VN=$(echo "$VN" | sed -e 's/-/./g'); + PASS=1 +else + VN="$DEF_VER" +fi + +# VN is the full version number. E.g. 0.1.0 if it is a tag. 0.1.0-2-deadbeef +# if it is not a tagged version +VN=$(expr "$VN" : v*'\(.*\)') + +echo $VN