#!/bin/sh # Command line refname="$1" oldrev="$2" newrev="$3" # We only care about branches moving--ignore tags/etc. case "$refname" in refs/heads/*) short_refname=${refname##refs/heads/} ;; *) exit 0 ;; esac excused=" $(git config hooks.update-ensure-ticket-reference.excused) " if [[ $excused =~ " $short_refname " ]] ; then exit 0 fi if expr "$oldrev" : '0*$' >/dev/null ; then git rev-parse --not --branches | git rev-list --stdin --no-merges $newrev else git rev-parse --not --branches | git rev-list --stdin --no-merges $oldrev..$newrev fi | while read commit ; do # Have log dump the "subject line, new line, body" of each commit message for grepping git log -n 1 '--pretty=format:%s%n%b' "$commit" | grep -i '\(\(re\|refs\|qa\) #[0-9]\+\)\|\(no ticket\)' > /dev/null if [ $? -ne 0 ] ; then echo "----------------------------------------------------" >&2 echo "" >&2 echo "Commit $commit does not reference a ticket" >&2 echo "" >&2 echo "----------------------------------------------------" >&2 exit 1 fi done