Last active
August 29, 2015 14:09
-
-
Save pR0Ps/ab33c11f525f93bbe85d to your computer and use it in GitHub Desktop.
Server-side commit message validation
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 | |
read oldrev newrev refname | |
NULL_SHA1="0000000000000000000000000000000000000000" | |
revs="" | |
case $oldrev,$newrev in | |
*,$NULL_SHA1) # Deleting ref | |
;; | |
$NULL_SHA1,*) # Initial push | |
revs=$(git rev-list --no-merges $newrev);; | |
*,*) # Update | |
revs=$(git rev-list --no-merges $oldrev..$newrev);; | |
esac | |
bad=0 | |
for rev in $revs; do | |
# Get first non-comment line of the commit message | |
fl=$(git cat-file commit $rev | sed '1,/^$/d' | head -1) | |
# Match the line against a regex | |
if ! [[ $fl =~ ^[A-Z]+-[0-9]{4}:\ .* ]]; then | |
echo "Improperly formatted commit message '$fl'" | |
bad=1 | |
fi | |
done | |
if [ $bad -eq 1 ]; then | |
echo "Example of a valid commit 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