]> git.droids-corp.org - git-central.git/commitdiff
First test for emails.
authorStephen Haberman <stephen@exigencecorp.com>
Fri, 20 Jun 2008 17:04:48 +0000 (12:04 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Fri, 20 Jun 2008 17:04:48 +0000 (12:04 -0500)
server/post-receive-email
tests/t2200-1.txt [new file with mode: 0644]
tests/t2200-server-post-receive-email.sh [new file with mode: 0644]
tests/test-lib.sh

index 9fa133bb344688b378aa0b21dab465f7b276a548..39c32ac43f6f3fd767a82306fca4bde090777569 100644 (file)
@@ -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 (file)
index 0000000..1917a8e
--- /dev/null
@@ -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 <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
diff --git a/tests/t2200-server-post-receive-email.sh b/tests/t2200-server-post-receive-email.sh
new file mode 100644 (file)
index 0000000..42f8b82
--- /dev/null
@@ -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
+
index feb64c64d45e32710a0b2016fd687c1e4cc01b0c..2c5413dac367b2b9ab0d7b4b467259bef01a5e45 100644 (file)
@@ -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 <directory>
 test_create_repo () {