2018-03-05 22:34:23 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
2018-06-17 20:17:21 +03:00
|
|
|
# Merge commits from this branch are counted
|
|
|
|
DEVELOPBRANCH="yggdrasil-network/develop"
|
|
|
|
|
2018-12-17 22:17:29 +03:00
|
|
|
# Get the last tag
|
2018-12-03 20:44:26 +03:00
|
|
|
TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.0" 2>/dev/null)
|
2018-03-05 22:34:23 +03:00
|
|
|
|
2018-06-17 20:17:21 +03:00
|
|
|
# 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
|
2018-12-18 01:07:28 +03:00
|
|
|
PATCH=$(git rev-list $TAG..master --count --merges --grep="from $DEVELOPBRANCH" --first-parent master 2>/dev/null)
|
2018-03-05 22:34:23 +03:00
|
|
|
|
2018-12-08 13:51:31 +03:00
|
|
|
# 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"
|
2018-12-08 14:31:20 +03:00
|
|
|
if [ "$1" = "--bare" ]; then
|
2018-12-08 13:51:31 +03:00
|
|
|
PREPEND=""
|
|
|
|
fi
|
|
|
|
|
2018-03-05 23:06:38 +03:00
|
|
|
# If it fails then there's no last tag - go from the first commit
|
|
|
|
if [ $? != 0 ]; then
|
2018-06-17 20:17:21 +03:00
|
|
|
PATCH=$(git rev-list HEAD --count 2>/dev/null)
|
2018-03-05 22:34:23 +03:00
|
|
|
|
2018-12-08 01:17:09 +03:00
|
|
|
# Complain if the git history is not available
|
2018-12-08 01:03:57 +03:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
printf 'unknown'
|
2018-12-08 13:33:33 +03:00
|
|
|
exit 1
|
2018-12-08 01:03:57 +03:00
|
|
|
fi
|
|
|
|
|
2018-12-08 13:51:31 +03:00
|
|
|
printf '%s0.0.%d' "$PREPEND" "$PATCH"
|
2018-12-08 13:33:33 +03:00
|
|
|
exit 1
|
2018-03-05 22:34:23 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Split out into major, minor and patch numbers
|
2018-03-06 01:14:36 +03:00
|
|
|
MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1)
|
|
|
|
MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2)
|
2018-03-05 22:34:23 +03:00
|
|
|
|
2018-06-17 20:17:21 +03:00
|
|
|
# Get the current checked out branch
|
|
|
|
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
|
|
|
2018-03-05 22:34:23 +03:00
|
|
|
# Output in the desired format
|
2018-12-03 20:49:03 +03:00
|
|
|
if [ $PATCH = 0 ]; then
|
2018-12-03 20:44:26 +03:00
|
|
|
if [ ! -z $FULL ]; then
|
2018-12-08 13:51:31 +03:00
|
|
|
printf '%s%d.%d.0' "$PREPEND" "$MAJOR" "$MINOR"
|
2018-12-03 20:44:26 +03:00
|
|
|
else
|
2018-12-08 13:51:31 +03:00
|
|
|
printf '%s%d.%d' "$PREPEND" "$MAJOR" "$MINOR"
|
2018-12-03 20:44:26 +03:00
|
|
|
fi
|
2018-03-06 01:14:36 +03:00
|
|
|
else
|
2018-12-08 13:51:31 +03:00
|
|
|
printf '%s%d.%d.%d' "$PREPEND" "$MAJOR" "$MINOR" "$PATCH"
|
2018-03-06 01:14:36 +03:00
|
|
|
fi
|
2018-06-17 20:17:21 +03:00
|
|
|
|
2018-12-18 15:03:23 +03:00
|
|
|
# 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]*" 2>/dev/null)
|
|
|
|
BUILD=$(git rev-list $TAG..$BRANCH --count)
|
|
|
|
|
2018-06-17 20:17:21 +03:00
|
|
|
# Add the build tag on non-master branches
|
|
|
|
if [ $BRANCH != "master" ]; then
|
|
|
|
if [ $BUILD != 0 ]; then
|
|
|
|
printf -- "-%04d" "$BUILD"
|
|
|
|
fi
|
2018-12-18 14:52:22 +03:00
|
|
|
else
|
|
|
|
if [ $BUILD != 0 ]; then
|
|
|
|
printf -- "-%d" "$BUILD"
|
|
|
|
fi
|
2018-06-17 20:17:21 +03:00
|
|
|
fi
|