Last active
February 25, 2019 11:42
-
-
Save iperdomo/8647441 to your computer and use it in GitHub Desktop.
Simple Git commit hook to enforce adding an issue number
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 | |
if [[ -z "$(head -n1 "$1" | grep -o -E '#[0-9]+')" ]]; then | |
echo >&2 ERROR: Commit message must include issue number. | |
exit 1 | |
fi | |
exit 0 |
Created an update hook on the git server for each project requiring an issue number in the push message.
!/bin/sh
PATH=/usr/sbin:/usr/bin:/sbin:/bin
issue_number=$(git log --pretty=%s $2..$3 | egrep -m 1 '#[0-9]+')
if [ -z "$issue_number" ]; then
echo "Error: Commit message must include issue number."
echo " $issue_number"
exit 1
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are you aware of a server side hook to do the same?
Thanks.