generate_email_footer()
{
- SPACE=" "
cat <<-EOF
hooks/post-receive
- --${SPACE}
+ --
$projectdesc
EOF
}
send_mail()
{
- if [ -n "$envelopesender" ]; then
+ if [ -n "$envelopesender" ] ; then
/usr/sbin/sendmail -t -f "$envelopesender"
else
# /usr/sbin/sendmail -t
announcerecipients=$(git config hooks.announcelist)
envelopesender=$(git config hooks.envelopesender)
emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')
+debug=$(git config hooks.debug)
# --- Main loop
# Allow dual mode: run from the command line just like the update hook, or
else
while read oldrev newrev refname
do
- generate_email $oldrev $newrev $refname | send_mail
+ if [ "$debug" == "true" ] ; then
+ generate_email $oldrev $newrev $refname > "${refname//\//.}.out"
+ else
+ generate_email $oldrev $newrev $refname | send_mail
+ fi
done
fi
--- /dev/null
+To: commits@list.com
+Subject: [SCM] UNNAMED PROJECT branch, master, updated. $new_commit_hash
+X-Git-Refname: refs/heads/master
+X-Git-Reftype: branch
+X-Git-Oldrev: $old_commit_hash
+X-Git-Newrev: $new_commit_hash
+
+This is an automated email from the git hooks/post-receive script. It was
+generated because a ref change was pushed to the repository containing
+the project "UNNAMED PROJECT".
+
+The branch, master has been updated
+ via $new_commit_hash (commit)
+ from $old_commit_hash (commit)
+
+Those revisions listed above that are new to this repository have
+not appeared on any other notification email; so we list those
+revisions in full, below.
+
+- Log -----------------------------------------------------------------
+commit $new_commit_hash
+Author: A U Thor <author@example.com>
+Date: $new_commit_date
+
+ simple commit
+
+-----------------------------------------------------------------------
+
+Summary of changes:
+ a | 2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
+
+diff --git a/a b/a
+index 146f275..b38f23c 100644
+--- a/a
++++ b/a
+@@ -1 +1 @@
+-setup
++simple commit
+
+
+hooks/post-receive
+--
+UNNAMED PROJECT
--- /dev/null
+#!/bin/sh
+
+test_description='server post-receive email notification'
+
+. ./test-lib.sh
+
+export POST_RECEIVE_EMAIL_DUMP=true
+
+test_expect_success 'setup' '
+ echo "setup" >a &&
+ git add a &&
+ git commit -m "setup" &&
+ git clone ./. server &&
+ rm -fr server/.git/hooks &&
+ git remote add origin ./server &&
+ git config --add branch.master.remote origin &&
+ git config --add branch.master.merge refs/heads/master &&
+ GIT_DIR=./server/.git git config --add hooks.mailinglist commits@list.com &&
+ GIT_DIR=./server/.git git config --add hooks.debug true &&
+ GIT_DIR=.
+'
+
+install_server_hook 'post-receive-email' 'post-receive'
+
+test_expect_success 'simple commit' '
+ echo $test_name >a &&
+ git commit -a -m "$test_name" &&
+ git push &&
+ old_commit_hash=$(git rev-parse HEAD^)
+ new_commit_hash=$(git rev-parse HEAD)
+ new_commit_date=$(git log -n 1 --pretty=format:%cd HEAD)
+ interpolate ../t2200-1.txt 1.txt old_commit_hash new_commit_hash new_commit_date
+ test_cmp 1.txt server/.git/refs.heads.master.out
+'
+
+test_done
+
$GIT_TEST_CMP "$@"
}
+# interpolate takes the contents of one file and interpolates the
+# given variables into it. E.g.:
+#
+# interpolate sourceFile destinationFile variableNameOne variableNameTwo
+#
+interpolate () {
+ input_file=$1
+ output_file=$2
+ shift && shift
+ data=$(cat $input_file)
+ # Interpolate the renaming arguments
+ for name in $* ; do
+ eval value="$"$name
+ data="${data//\$$name/$value}"
+ done
+ echo "$data" > $output_file
+}
+
# Most tests can use the created repository, but some may need to create more.
# Usage: test_create_repo <directory>
test_create_repo () {