Skip to content

Instantly share code, notes, and snippets.

@charego
Created April 15, 2015 05:13
Show Gist options
  • Save charego/423c26fcb426cc14c8a5 to your computer and use it in GitHub Desktop.
Save charego/423c26fcb426cc14c8a5 to your computer and use it in GitHub Desktop.
Git commit message hook
#!/bin/sh
#
# This hook rejects commit messages that do not have an issue tag.
#
COMMIT_MSG=`cat $1`
COMMIT_PREFIX="\[[A-Z]+-[0-9]+\][[:blank:]][A-Z]"
# The normal way to match regular expression doesn't work on msysGit?
# if [[ $COMMIT_MSG =~ $COMMIT_PREFIX ]]; then
if !(echo $COMMIT_MSG | grep -E $COMMIT_PREFIX > /dev/null); then
echo
echo "Commit message must contain an issue tag. To bypass, run with --no-verify."
echo
echo "Accepts:"
echo " [ABC-123] This is a commit message"
echo
echo "Rejects:"
echo " This is a commit message"
echo " [ABC-123]This is a commit message"
echo " [ABC-123] this is a commit message"
echo
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment