Created
April 15, 2015 05:13
-
-
Save charego/423c26fcb426cc14c8a5 to your computer and use it in GitHub Desktop.
Git commit message hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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