tools: git-gen-version fallback to VERSION file if things goes wrong
authorJean Privat <jean@pryen.org>
Mon, 6 Jul 2009 19:41:17 +0000 (15:41 -0400)
committerJean Privat <jean@pryen.org>
Mon, 6 Jul 2009 19:41:17 +0000 (15:41 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

VERSION [new file with mode: 0644]
src/git-gen-version.sh

diff --git a/VERSION b/VERSION
new file mode 100644 (file)
index 0000000..f5303c6
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+v0.2.1-git
index ada2d60..25b9a01 100755 (executable)
@@ -41,13 +41,21 @@ if [ ! -f nitc.nit ]; then
 fi
 
 VN=$(git describe --always HEAD 2>/dev/null)
+if [ "$?" != "0" ]; then
+       if [ -r ../VERSION ]; then
+               VN="$(cat ../VERSION)"
+       else
+               echo >&2 "Error: no VERSION file and not a .git repository."
+               exit 1
+       fi
+fi
 if [ -z "$VN" ]; then
        VN="undefined"
 fi
 if [ -n "$1" ]; then
        VN="${VN}_$1"
 fi
-if [ -n "$(git diff HEAD)" ]; then
+if [ -n "$(git diff HEAD 2>/dev/null)" ]; then
        VN="${VN}_dirty"
 fi