Created
July 17, 2015 16:29
-
-
Save pronskiy/cbb0fde6d621a3db5a0c to your computer and use it in GitHub Desktop.
Git update hook - commit message format
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 | |
ref_to_check="refs/heads/dev" | |
commit_format="^\[(NG|KWAPI|KWUI|KEC|KWSRV)-[1-9]+\]\s" | |
refname="$1" | |
oldrev="$2" | |
newrev="$3" | |
echo "Enforcing Policies..." | |
echo $oldrev $newrev $refname | |
if [ "$refname" == "$ref_to_check" ]; then | |
git rev-list $oldrev..$newrev | while read rev; do | |
commit_message=`git cat-file commit $rev | sed '1,/^$/d'` | |
if ! [[ $commit_message =~ $commit_format ]]; then | |
echo "[POLICY]" | |
echo "Your message is not formatted correctly. Please follow the pattern: " $commit_format | |
echo "For more information see the page https://confluence.accellion.net/display/EN/Git+Convention" | |
exit 1 | |
fi; | |
done | |
[ $? == 1 ] && exit 1; | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment