Skip to content

Instantly share code, notes, and snippets.

@bymyslf
Last active October 22, 2017 13:12
Show Gist options
  • Select an option

  • Save bymyslf/caf7128327ed9fb4109887c32d61638e to your computer and use it in GitHub Desktop.

Select an option

Save bymyslf/caf7128327ed9fb4109887c32d61638e to your computer and use it in GitHub Desktop.
Git pre-receive hook to check GitVersion (http://gitversion.readthedocs.io/en/latest/) tags in merge message
#!/bin/bash
#
# check commit messages for semantic versioning tags
REGEX="\\+semver:\\s?(breaking|major|feature|minor|fix|patch|none|skip)"
DEFAULT_BRANCH=$(git symbolic-ref HEAD)
ERROR_MSG="[POLICY] The commit message doesn't contains a semantic versioning tag"
while read OLDREV NEWREV REFNAME ; do
if [[ "${REFNAME}" != "${DEFAULT_BRANCH:=refs/heads/master}" ]]; then
exit 0
else
COMMIT_MESSAGE=`git log --format=%B -n 1 $NEWREV | cat -`
if ! echo $COMMIT_MESSAGE | grep -iqE "$REGEX"; then
echo "$ERROR_MSG: $COMMIT_MESSAGE" >&2
exit 1
fi
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment