From a75ddff9f3d0cd1cb32c2bbe62d0b8841f549460 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 5 Mar 2018 20:06:38 +0000 Subject: [PATCH] Ignore non-version tags --- contrib/semver/version.sh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 8dd3dd09..62acd62c 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -1,20 +1,15 @@ #!/bin/sh # Get the last tag -TAG=$(git describe --abbrev=0 --tags --match=v* 2>/dev/null) +TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null) -# Get the number of commits from the last tag, or if not, from -# the first commit -COUNT=$( \ - git rev-list v$TAG..HEAD --count 2>/dev/null || \ - git rev-list HEAD --count 2>/dev/null \ -) +# Get the number of commits from the last tag +COUNT=$(git rev-list $TAG..HEAD --count 2>/dev/null) -# Check if it matches the vX.Y.Z format -grep "v[0-9]*\.[0-9]*\.[0-9]*" <<< $TAG &>/dev/null +# If it fails then there's no last tag - go from the first commit +if [ $? != 0 ]; then + COUNT=$(git rev-list HEAD --count 2>/dev/null) -# If it doesn't, abort -if [ $? -ne 0 ]; then printf 'v0.0.0-%d' "$COUNT" exit -1 fi