Created
August 28, 2015 03:43
-
-
Save pR0Ps/b32a205383d2cd59f628 to your computer and use it in GitHub Desktop.
Validate commit messages on the client side
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 | |
# Don't worry about merge commits | |
if [ -f .git/MERGE_MSG ]; then | |
exit 0 | |
fi | |
# Get first non-comment line of the commit message | |
fl=$(sed '/^#.*/d' $1 | head -1) | |
# Check the line against a regex | |
if ! [[ $fl =~ ^[A-Z]+-[0-9]{4}:\ .* ]]; then | |
echo "Improperly formatted commit message '"$fl"'" | |
echo "Example of a correctly formatted message: 'PROJECT-1234: Message'" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment