Skip to content

Instantly share code, notes, and snippets.

@pR0Ps
Created August 28, 2015 03:43
Show Gist options
  • Save pR0Ps/b32a205383d2cd59f628 to your computer and use it in GitHub Desktop.
Save pR0Ps/b32a205383d2cd59f628 to your computer and use it in GitHub Desktop.
Validate commit messages on the client side
#!/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