BUG: incorrect wmakePrintBuild -check behaviour when outside of git (issue #174)

- return 0 if not under git, since nothing particular can be said
  about the build number.

- explicitly define which git-dir is to be used.
  This ensure we don't accidentally get some values from some unrelated
  project in the parent directory.
This commit is contained in:
Mark Olesen
2016-07-12 17:37:30 +02:00
parent 5f49df4a0a
commit a6a8069d84

View File

@ -3,8 +3,8 @@
# ========= | # ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | # \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM. # This file is part of OpenFOAM.
@ -72,7 +72,6 @@ do
;; ;;
-c | -check) -c | -check)
checkOnly=true checkOnly=true
shift
;; ;;
-major) -major)
echo ${WM_PROJECT_VERSION:-unknown} echo ${WM_PROJECT_VERSION:-unknown}
@ -80,27 +79,26 @@ do
;; ;;
-u | -update) -u | -update)
update=true update=true
shift
;; ;;
-pkg | -package) -pkg | -package)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
# Mark empty as 'none', disallow '!' in string # Mark empty as 'none', disallow '!' in string
package=$(echo "${2:-none}" | sed -e 's/!//g') package=$(echo "${2:-none}" | sed -e 's/!//g')
shift 2 shift
;; ;;
-short) -short)
shortOpt=true shortOpt=true
shift
;; ;;
-v | -version) -v | -version)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument" [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
version="$2" version="$2"
shift 2 shift
;; ;;
*) *)
usage "unknown option/argument: '$*'" usage "unknown option/argument: '$1'"
;; ;;
esac esac
shift
done done
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -146,12 +144,12 @@ then
# Specified a version - no error possible # Specified a version - no error possible
rc=0 rc=0
else else
# Get the head SHA1 when building under git # Get the head SHA1 (first 12 chars) when building under git.
# if there are multiple values (eg, HEAD, origin/HEAD, ...) # If there are multiple values (eg, HEAD, origin/HEAD, ...)
# only take the first one, which is 'HEAD' # only take the first one, which is 'HEAD'
version=$( version=$(
cd $WM_PROJECT_DIR 2>/dev/null && \ git --git-dir=$WM_PROJECT_DIR/.git show-ref --head HEAD 2>/dev/null |\
git show-ref --hash=12 --head HEAD 2>/dev/null | head -1 sed -ne '1s@^\(.\{12\}\).*$@\1@p'
) )
if [ -n "$version" ] if [ -n "$version" ]
@ -205,10 +203,11 @@ then
else else
echo "version changed from previous build" 1>&2 echo "version changed from previous build" 1>&2
fi fi
exit $rc
else else
echo "no git description found" 1>&2 echo "no git description found" 1>&2
exit 0
fi fi
exit $rc
fi fi