Skip to content

Instantly share code, notes, and snippets.

@pronskiy
Created July 17, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pronskiy/cbb0fde6d621a3db5a0c to your computer and use it in GitHub Desktop.
Save pronskiy/cbb0fde6d621a3db5a0c to your computer and use it in GitHub Desktop.
Git update hook - commit message format
#!/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