openafs/build-tools/git-version
Simon Wilkinson 417d2c8f95 Build: Rework git version detection
Rework the git version detection script to handle some issues that
have been pointed out.

1/ Make it work properly with objdir builds
2/ Don't try to work out if the tree is dirty if git describe failed
3/ Use the configured VERSION as a fallback if we can't obtain proper
   version information during a make

Change-Id: I39494e1c18cf4eacbb55386334da7128fbe96310
Reviewed-on: http://gerrit.openafs.org/2283
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
2010-07-02 09:48:46 -07:00

33 lines
690 B
Bash
Executable File

#!/bin/sh
srcdir=$1
fallback=$2
if [ "x$fallback" = "x" ]; then
fallback=UNKNOWN
fi
if [ -f $srcdir/.version ] ; then
git_version=`cat $srcdir/.version`
else
if which git > /dev/null; then
cd $srcdir
git_version=`git describe --abbrev=4 HEAD 2>/dev/null`
if [ $? = 0 ]; then
# Is the working tree dirty?
if git diff-index --quiet --cached HEAD --ignore-submodules && \
git diff-files --quiet --ignore-submodules ; then
:
else
git_version="$git_version-dirty"
fi
else
git_version=$fallback
fi
else
git_version=$fallback
fi
fi
echo "$git_version" | sed -e 's/openafs-[^-]*-//' -e 's/_/./g' | tr -d '\012'