]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t9001-send-email.sh
Merge branch 'jc/send-email-pre-process-fix'
[thirdparty/git.git] / t / t9001-send-email.sh
index 2020e0ce69e673c6559f0971750b8be25054e35a..a60b05ad3f09f03433e2b7fe96e095966ddb104a 100755 (executable)
@@ -4,7 +4,7 @@ test_description='git send-email'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
-# no longer TEST_PASSES_SANITIZE_LEAK=true - format-patch --thread leaks
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # May be altered later in the test
@@ -337,13 +337,14 @@ test_expect_success $PREREQ 'Show all headers' '
 test_expect_success $PREREQ 'Prompting works' '
        clean_fake_sendmail &&
        (echo "to@example.com" &&
-        echo ""
+        echo "my-message-id@example.com"
        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
                --smtp-server="$(pwd)/fake.sendmail" \
                $patches \
                2>errors &&
                grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
-               grep "^To: to@example.com\$" msgtxt1
+               grep "^To: to@example.com\$" msgtxt1 &&
+               grep "^In-Reply-To: <my-message-id@example.com>" msgtxt1
 '
 
 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
@@ -374,13 +375,16 @@ test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email'
        )
 '
 
-test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
+test_expect_success $PREREQ 'setup cmd scripts' '
        write_script tocmd-sed <<-\EOF &&
        sed -n -e "s/^tocmd--//p" "$1"
        EOF
-       write_script cccmd-sed <<-\EOF
+       write_script cccmd-sed <<-\EOF &&
        sed -n -e "s/^cccmd--//p" "$1"
        EOF
+       write_script headercmd-sed <<-\EOF
+       sed -n -e "s/^headercmd--//p" "$1"
+       EOF
 '
 
 test_expect_success $PREREQ 'tocmd works' '
@@ -410,6 +414,70 @@ test_expect_success $PREREQ 'cccmd works' '
        grep "^ cccmd@example.com" msgtxt1
 '
 
+test_expect_success $PREREQ 'headercmd works' '
+       clean_fake_sendmail &&
+       cp $patches headercmd.patch &&
+       echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --header-cmd=./headercmd-sed \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               headercmd.patch \
+               &&
+       grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
+'
+
+test_expect_success $PREREQ '--no-header-cmd works' '
+       clean_fake_sendmail &&
+       cp $patches headercmd.patch &&
+       echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --header-cmd=./headercmd-sed \
+               --no-header-cmd \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               headercmd.patch \
+               &&
+       ! grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
+'
+
+test_expect_success $PREREQ 'multiline fields are correctly unfolded' '
+       clean_fake_sendmail &&
+       cp $patches headercmd.patch &&
+       write_script headercmd-multiline <<-\EOF &&
+       echo "X-Debbugs-CC: someone@example.com
+FoldedField: This is a tale
+ best told using
+ multiple lines."
+       EOF
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --header-cmd=./headercmd-multiline \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               headercmd.patch &&
+       grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1
+'
+
+# Blank lines in the middle of the output of a command are invalid.
+test_expect_success $PREREQ 'malform output reported on blank lines in command output' '
+       clean_fake_sendmail &&
+       cp $patches headercmd.patch &&
+       write_script headercmd-malformed-output <<-\EOF &&
+       echo "X-Debbugs-CC: someone@example.com
+
+SomeOtherField: someone-else@example.com"
+       EOF
+       ! git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --header-cmd=./headercmd-malformed-output \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               headercmd.patch
+'
+
 test_expect_success $PREREQ 'reject long lines' '
        z8=zzzzzzzz &&
        z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
@@ -2363,6 +2431,37 @@ test_expect_success $PREREQ 'invoke hook' '
        )
 '
 
+expected_file_counter_output () {
+       total=$1
+       count=0
+       while test $count -ne $total
+       do
+               count=$((count + 1)) &&
+               echo "$count/$total" || return
+       done
+}
+
+test_expect_success $PREREQ '--validate hook allows counting of messages' '
+       test_when_finished "rm -rf my-hooks.log" &&
+       test_config core.hooksPath "my-hooks" &&
+       mkdir -p my-hooks &&
+
+       write_script my-hooks/sendemail-validate <<-\EOF &&
+               num=$GIT_SENDEMAIL_FILE_COUNTER &&
+               tot=$GIT_SENDEMAIL_FILE_TOTAL &&
+               echo "$num/$tot" >>my-hooks.log || exit 1
+       EOF
+
+       >my-hooks.log &&
+       expected_file_counter_output 4 >expect &&
+       git send-email \
+               --from="Example <from@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               --validate -3 --cover-letter --force &&
+       test_cmp expect my-hooks.log
+'
+
 test_expect_success $PREREQ 'test that send-email works outside a repo' '
        nongit git send-email \
                --from="Example <nobody@example.com>" \