Skip to content

Instantly share code, notes, and snippets.

@hazzik
Forked from ericbmerritt/git-semver.sh
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hazzik/a68446c5d9430476c5fd to your computer and use it in GitHub Desktop.
Save hazzik/a68446c5d9430476c5fd to your computer and use it in GitHub Desktop.
#! /bin/bash
# Assumes that you tag versions with the version number (e.g., "1.1")
# and then the build number is that plus the number of commits since
# the tag (e.g., "1.1.17")
DESCRIBE=`git describe --tags --always`
# increment the build number (ie 115 to 116)
VERSION=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[1]}'`
BUILD=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[2]}'`
PATCH=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[3]}'`
if [[ "${DESCRIBE}" =~ ^[A-Fa-f0-9]+$ ]]; then
VERSION="0.0.0"
BUILD=`git rev-list HEAD --count`
PATCH=${DESCRIBE}
fi
if [ "${BUILD}" = "" ]; then
BUILD='0'
fi
if [ "${BUILD}" = "" ]; then
PATCH=$DESCRIBE
fi
echo ${VERSION}+build.${BUILD}.${PATCH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment