Skip to content

Instantly share code, notes, and snippets.

@iperdomo
Last active Feb 25, 2019
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@rbianchikutta rbianchikutta commented Dec 10, 2015

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

Thanks.

@rbianchikutta

This comment has been minimized.

Copy link

@rbianchikutta rbianchikutta commented Dec 14, 2015

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