Added some comments
[GitHooks.git] / post-receive
blob632913d6eb5c5a65524e2399007accfbaf743e1d
1 #!/bin/bash
3 # An example hook script that is called after a successful
4 # commit is made.
6 # To enable this hook, make this file executable.
9 # CONFIG
11 # FROM - The From address for the commit messages
12 FROM="Commits"
14 # Where to send the commit messages
15 TO=""
16 BCC=""
19 export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/git/bin
21 ARGS=`cat`
23 verbose=true
25 # Default shell globbing messes things up downstream
26 GLOBIGNORE=*
28 function info {
29 $verbose && echo >&2 "-Info- $1"
32 function yes {
33 $verbose && echo >&2 "-Yes- $1"
34 echo yes
35 exit 0
38 function no {
39 $verbose && echo >&2 "-Deny- $1"
40 echo no
41 exit 1
46 REF1=`echo $ARGS | awk '{print $1}'`
47 REF2=`echo $ARGS | awk '{print $2}'`
48 REF3=`echo $ARGS | awk '{print $3}'`
49 _PWD=`pwd`
50 DEPOT=`basename ${_PWD}`
52 # Check if commit/push is made to a branch we are interested in.
53 rc=$(cat info/notify | grep -v '^#' | grep -v '^$' |
54 while read head_pattern; do
55 matchlen=$(expr "$REF3" : "$head_pattern")
56 if [ "$matchlen" == "${#REF3}" ]; then
57 info "Found matching pattern: '$head_pattern'"
58 echo "yes"
59 exit 0;
61 done
63 case "$rc" in
64 yes)
65 # Its turns out we are interested in the commit/push
66 info "Going to notify about commit/push ($REF3)"
68 # Build up the mail command
69 ABBREVHASH=`git-log --pretty=format:%h HEAD -1`
70 SUBJECT="commit to ${REF3} in ${DEPOT} - HEAD is now ${ABBREVHASH}"
72 if [ ! -z "${BCC}" ]; then
73 info "Adding bcc entries"
74 # Add the bcc's to MAILCMD
75 BCC="-b ${BCC}"
78 # Complete the MAILCMD with a final recipient
80 git-log --pretty=medium -p ${REF1}..${REF2} | mailx -s "${SUBJECT}" -a "From: ${FROM}" ${BCC} ${TO}
82 *)
84 esac