# The version file to be update. VERSION_FILE=package.json # The version pattern in the version file. VERSION_FILTER='"version": '
CODE_BASE=$(git rev-parse --show-toplevel) BRANCH=$(git branch | cut -d ' ' -f 2) BRANCH_TO_UPDATE_VERSION=master # If there is multiple remotes to be set in the repository, considering hard coded the next line to origin/master or similar. # Actually we need to filter the branch mapping by `git remote -v` if the branch is not mapped by name. REMOTE=$(git remote)/$BRANCH
if [ "$BRANCH" = "$BRANCH_TO_UPDATE_VERSION" ]; then CHANGES=$(git diff "$BRANCH".."$REMOTE" | wc -l)
if [ "$CHANGES" -gt "0" ]; then VERSION_CHANGED=$(git diff "$BRANCH".."$REMOTE" \ -G ${VERSION_FILTER} -- ${CODE_BASE}/${VERSION_FILE} | wc -l)
if [ "$VERSION_CHANGED" -gt "0" ]; then # In this case, the vesion was already updated. exit 0 else # if you wan to directly print error output, using this line. printf"\033[0;31mERROR: the version in file ${VERSION_FILE} was not updated.\033[0m\n" exit 1 fi fi fi