From e6f64dde41d8186f3d9c93ea4b8357de571ffb66 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Fri, 20 Jun 2008 12:04:48 -0500 Subject: [PATCH] First test for emails. --- server/post-receive-email | 12 ++++--- tests/t2200-1.txt | 44 ++++++++++++++++++++++++ tests/t2200-server-post-receive-email.sh | 37 ++++++++++++++++++++ tests/test-lib.sh | 18 ++++++++++ 4 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 tests/t2200-1.txt create mode 100644 tests/t2200-server-post-receive-email.sh diff --git a/server/post-receive-email b/server/post-receive-email index 9fa133b..39c32ac 100644 --- a/server/post-receive-email +++ b/server/post-receive-email @@ -202,12 +202,11 @@ generate_email_header() generate_email_footer() { - SPACE=" " cat <<-EOF hooks/post-receive - --${SPACE} + -- $projectdesc EOF } @@ -597,7 +596,7 @@ generate_delete_general_email() send_mail() { - if [ -n "$envelopesender" ]; then + if [ -n "$envelopesender" ] ; then /usr/sbin/sendmail -t -f "$envelopesender" else # /usr/sbin/sendmail -t @@ -632,6 +631,7 @@ recipients=$(git config hooks.mailinglist) 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 @@ -644,6 +644,10 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then 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 diff --git a/tests/t2200-1.txt b/tests/t2200-1.txt new file mode 100644 index 0000000..1917a8e --- /dev/null +++ b/tests/t2200-1.txt @@ -0,0 +1,44 @@ +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 +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 diff --git a/tests/t2200-server-post-receive-email.sh b/tests/t2200-server-post-receive-email.sh new file mode 100644 index 0000000..42f8b82 --- /dev/null +++ b/tests/t2200-server-post-receive-email.sh @@ -0,0 +1,37 @@ +#!/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 + diff --git a/tests/test-lib.sh b/tests/test-lib.sh index feb64c6..2c5413d 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -337,6 +337,24 @@ test_cmp() { $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 test_create_repo () { -- 2.39.5