diff --git a/contrib/semver/name.sh b/contrib/semver/name.sh index 935cc750..1fa2ce07 100644 --- a/contrib/semver/name.sh +++ b/contrib/semver/name.sh @@ -4,8 +4,8 @@ BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) # Complain if the git history is not available -if [ $? != 0 ]; then - printf "unknown" +if [ $? != 0 ] || [ -z "$BRANCH" ]; then + printf "yggdrasil" exit 1 fi diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 964a3208..3052094a 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -1,63 +1,46 @@ #!/bin/sh -# Merge commits from this branch are counted -DEVELOPBRANCH="yggdrasil-network/develop" - # Get the last tag -TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.0" 2>/dev/null) +TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null) -# Get last merge to master -MERGE=$(git rev-list $TAG..master --grep "from $DEVELOPBRANCH" 2>/dev/null | head -n 1) - -# Get the number of merges since the last merge to master -PATCH=$(git rev-list $TAG..master --count --merges --grep="from $DEVELOPBRANCH" --first-parent master 2>/dev/null) - -# Decide whether we should prepend the version with "v" - the default is that -# we do because we use it in git tags, but we might not always need it -PREPEND="v" -if [ "$1" = "--bare" ]; then - PREPEND="" +# Did getting the tag succeed? +if [ $? != 0 ] || [ -z "$TAG" ]; then + printf -- "unknown" + exit 1 fi -# If it fails then there's no last tag - go from the first commit -if [ $? != 0 ]; then - PATCH=$(git rev-list HEAD --count 2>/dev/null) +# Get the current branch +BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null) - # Complain if the git history is not available - if [ $? != 0 ]; then - printf 'unknown' - exit 1 - fi - - printf '%s0.0.%d' "$PREPEND" "$PATCH" - exit 1 +# 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) MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2) - -# Get the current checked out branch -BRANCH=$(git rev-parse --abbrev-ref HEAD) +PATCH=$(echo $TAG | cut -c 2- | cut -d "." -f 3) # Output in the desired format -if [ $PATCH = 0 ]; then - if [ ! -z $FULL ]; then - printf '%s%d.%d.0' "$PREPEND" "$MAJOR" "$MINOR" - else - printf '%s%d.%d' "$PREPEND" "$MAJOR" "$MINOR" - fi +if [ $((PATCH)) -eq 0 ]; then + printf '%s%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))" else - printf '%s%d.%d.%d' "$PREPEND" "$MAJOR" "$MINOR" "$PATCH" + printf '%s%d.%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))" "$((PATCH))" fi -# Get the number of merges on the current branch since the last tag -TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" --first-parent master 2>/dev/null) -BUILD=$(git rev-list $TAG.. --count) - # Add the build tag on non-master branches -if [ $BRANCH != "master" ]; then - if [ $BUILD != 0 ]; then - printf -- "-%04d" "$BUILD" +if [ "$BRANCH" != "master" ]; then + BUILD=$(git rev-list --count $TAG..HEAD 2>/dev/null) + + # Did getting the count of commits since the tag succeed? + if [ $? != 0 ] || [ -z "$BUILD" ]; then + printf -- "-unknown" + exit 1 + fi + + # Is the build greater than zero? + if [ $((BUILD)) -gt 0 ]; then + printf -- "-%04d" "$((BUILD))" fi fi