Skip to content

Instantly share code, notes, and snippets.

@iperdomo
Last active February 25, 2019 11:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iperdomo/8647441 to your computer and use it in GitHub Desktop.
Save iperdomo/8647441 to your computer and use it in GitHub Desktop.
Simple Git commit hook to enforce adding an issue number
#!/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
@rbianchikutta
Copy link

Are you aware of a server side hook to do the same?

Thanks.

@rbianchikutta
Copy link

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