3 # Copyright (c) 2007 Andy Parkins
4 # Copyright (c) 2008 Stephen Haberman
5 # Copyright (c) 2013 Olivier Matz
7 # Based on post-receive-email
9 # This hook clone and pull the repoditory each time a commit is pushed
10 # in the tree. Each branch will be delivered in
11 # ${GIT_DELIVER_DIRECTORY}/branch. If ${GIT_DELIVER_COMMAND} is set,
12 # this command will be executed in the delivery directory.
15 # ---------------------------- Functions
17 . $(dirname $0)/functions
22 oldrev=$(git rev-parse $1)
23 newrev=$(git rev-parse $2)
30 # The revision type tells us what type the commit is, combined with
31 # the location of the ref we can decide between
36 case "$refname","$rev_type" in
41 branch=${refname##refs/heads/}
49 if expr "$newrev" : '0*$' >/dev/null; then
50 # nothing to do, branch is deleted
54 dstdir=${GIT_DELIVER_DIRECTORY}/${branch}
55 if [ ! -d ${dstdir} ]; then
56 mkdir -p ${GIT_DELIVER_DIRECTORY} || exit 2
57 cd ${GIT_DELIVER_DIRECTORY}
58 git clone --branch ${branch} ${GIT_DIR} ${branch}
65 if [ ! -z "${GIT_DELIVER_COMMAND}" ]; then
67 ${GIT_DELIVER_COMMAND}
71 # ---------------------------- main()
75 # Set GIT_DIR either from the working directory or the environment variable.
76 GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
77 if [ -z "$GIT_DIR" ]; then
78 echo >&2 "fatal: post-receive: GIT_DIR not set"
81 GIT_DIR=$(readlink -e ${GIT_DIR})
84 if [ -z "${GIT_DELIVER_DIRECTORY}" ]; then
85 echo >&2 "fatal: GIT_DELIVER_DIRECTORY not set"
89 recipients=$(git config hooks.post-receive-email.mailinglist)
92 # Allow dual mode: run from the command line just like the update hook, or
93 # if no arguments are given then run as a hook script
94 if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
95 # Output to the terminal in command line mode - if someone wanted to
96 # resend an email; they could redirect the output to sendmail
98 PAGER= generate_delivery $2 $3 $1
100 while read oldrev newrev refname
102 generate_delivery $oldrev $newrev $refname