33acbc7bb80eb8361530f84176d24517dffc19a0
[git-central.git] / server / update-ensure-ticket-reference
1 #!/bin/sh
2
3 # Command line
4 refname="$1"
5 oldrev="$2"
6 newrev="$3"
7
8 # We only care about branches moving--ignore tags/etc.
9 case "$refname" in
10         refs/heads/*)
11                 short_refname=${refname##refs/heads/}
12                 ;;
13         *)
14                 exit 0
15                 ;;
16 esac
17
18
19 excused=" $(git config hooks.update-ensure-ticket-reference.excused) "
20 if [[ $excused =~ " $short_refname " ]] ; then
21         exit 0
22 fi
23
24 if expr "$oldrev" : '0*$' >/dev/null ; then
25         git rev-parse --not --branches | git rev-list --stdin --no-merges $newrev
26 else
27         git rev-parse --not --branches | git rev-list --stdin --no-merges $oldrev..$newrev
28 fi | while read commit ; do
29         # Have log dump the "subject line, new line, body" of each commit message for grepping
30         git log -n 1 '--pretty=format:%s%n%b' "$commit" | grep -i '\(\(re\|refs\|qa\) #[0-9]\+\)\|\(no ticket\)' > /dev/null
31         if [ $? -ne 0 ] ; then
32                 echo "----------------------------------------------------" >&2
33                 echo "" >&2
34                 echo "Commit $commit does not reference a ticket" >&2
35                 echo "" >&2
36                 echo "----------------------------------------------------" >&2
37                 exit 1
38         fi
39 done
40