From 7eaee172cf22e5b54a619a2a08c233f83511224c Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 27 Dec 2018 21:22:46 +0000 Subject: [PATCH] Replace tests with ifs --- contrib/semver/version.sh | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 14dafa15..ca035ff5 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -2,11 +2,20 @@ # Get the last tag TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null) -(test $? != 0 || test -z "$TAG") && (echo "unknown"; exit 1) + +# Did getting the tag succeed? +if [ $? != 0 ] || [ -z "$TAG" ]; then + printf "unknown" + exit 1 +fi # Get the current branch BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null) -(test $? != 0 || test -z "$BRANCH") && BRANCH="master" + +# Did getting the branch succeed? +if [ $? != 0 ] || [ -z "$BRANCH" ]; then + BRANCH="master" +fi # Split out into major, minor and patch numbers MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1) @@ -22,10 +31,15 @@ fi # Add the build tag on non-master branches if [ "$BRANCH" != "master" ]; then - BUILD=$(git rev-list $TAG..HEAD --count) - if [ $? = 0 ] && [ -n "$BUILD" ]; then - if [ $((BUILD)) -gt 0 ]; then - printf -- "-%04d" "$((BUILD))" - fi + BUILD=$(git rev-list $TAG..HEAD --count 2>/dev/null) + + # Did getting the count of commits since the tag succeed? + if [ $? != 0 ] && [ -z "$BUILD" ]; then + exit 1 + fi + + # Is the build greater than zero? + if [ $((BUILD)) -gt 0 ]; then + printf -- "-%04d" "$((BUILD))" fi fi