Merge branch 'sg/fsck-config-in-doc'
[gitweb.git] / t / t9001-send-email.sh
index 461bb5b3077e3b3a3807ca7d3fd8607b5a6e68c2..997f90b42b3e513328b23f718ac7215eb9a960b8 100755 (executable)
@@ -253,10 +253,9 @@ test_suppress_self () {
 
        mv msgtxt1 msgtxt1-$3 &&
        sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
-       >"expected-no-cc-$3" &&
 
        (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
-        test_cmp expected-no-cc-$3 actual-no-cc-$3)
+        test_must_be_empty actual-no-cc-$3)
 }
 
 test_suppress_self_unquoted () {
@@ -332,7 +331,7 @@ test_expect_success $PREREQ 'Show all headers' '
 
 test_expect_success $PREREQ 'Prompting works' '
        clean_fake_sendmail &&
-       (echo "to@example.com"
+       (echo "to@example.com" &&
         echo ""
        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
                --smtp-server="$(pwd)/fake.sendmail" \
@@ -482,6 +481,20 @@ test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable'
        grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
 '
 
+test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
+       clean_fake_sendmail &&
+       cp $patches cr.patch &&
+       printf "this is a line\r\n" >>cr.patch &&
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               --transfer-encoding=auto \
+               --no-validate \
+               cr.patch &&
+       grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
+'
+
 for enc in auto quoted-printable base64
 do
        test_expect_success $PREREQ "--validate passes with encoding $enc" '
@@ -493,6 +506,21 @@ do
                        --validate \
                        $patches longline.patch
        '
+
+done
+
+for enc in 7bit 8bit quoted-printable base64
+do
+       test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
+               clean_fake_sendmail &&
+               git send-email \
+                       --from="Example <nobody@example.com>" \
+                       --to=nobody@example.com \
+                       --smtp-server="$(pwd)/fake.sendmail" \
+                       --transfer-encoding=$enc \
+                       $patches &&
+               grep "Content-Transfer-Encoding: $enc" msgtxt1
+       '
 done
 
 test_expect_success $PREREQ 'Invalid In-Reply-To' '
@@ -509,8 +537,8 @@ test_expect_success $PREREQ 'Invalid In-Reply-To' '
 
 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
        clean_fake_sendmail &&
-       (echo "From Example <from@example.com>"
-        echo "To Example <to@example.com>"
+       (echo "From Example <from@example.com>" &&
+        echo "To Example <to@example.com>" &&
         echo ""
        ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
                --smtp-server="$(pwd)/fake.sendmail" \
@@ -1200,6 +1228,61 @@ test_expect_success $PREREQ 'sendemail.to works' '
        grep "To: Somebody <somebody@ex.com>" stdout
 '
 
+test_expect_success $PREREQ 'setup sendemail.identity' '
+       git config --replace-all sendemail.to "default@example.com" &&
+       git config --replace-all sendemail.isp.to "isp@example.com" &&
+       git config --replace-all sendemail.cloud.to "cloud@example.com"
+'
+
+test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
+       git -c sendemail.identity=cloud send-email \
+               --dry-run \
+               --from="nobody@example.com" \
+               $patches >stdout &&
+       grep "To: cloud@example.com" stdout
+'
+
+test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
+       git -c sendemail.identity=cloud send-email \
+               --identity=isp \
+               --dry-run \
+               --from="nobody@example.com" \
+               $patches >stdout &&
+       grep "To: isp@example.com" stdout
+'
+
+test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
+       git -c sendemail.identity=cloud send-email \
+               --no-identity \
+               --dry-run \
+               --from="nobody@example.com" \
+               $patches >stdout &&
+       grep "To: default@example.com" stdout
+'
+
+test_expect_success $PREREQ 'sendemail.identity: bool identity variable existance overrides' '
+       git -c sendemail.identity=cloud \
+               -c sendemail.xmailer=true \
+               -c sendemail.cloud.xmailer=false \
+               send-email \
+               --dry-run \
+               --from="nobody@example.com" \
+               $patches >stdout &&
+       grep "To: cloud@example.com" stdout &&
+       ! grep "X-Mailer" stdout
+'
+
+test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
+       git -c sendemail.identity=cloud \
+               -c sendemail.xmailer=false \
+               send-email \
+               --dry-run \
+               --from="nobody@example.com" \
+               $patches >stdout &&
+       grep "To: cloud@example.com" stdout &&
+       ! grep "X-Mailer" stdout
+'
+
 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
        git send-email \
                --dry-run \
@@ -1409,10 +1492,10 @@ test_expect_success $PREREQ 'setup expect' '
        EOF
 '
 
-test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
+test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
        clean_fake_sendmail &&
-       git config sendemail.transferEncoding 7bit &&
-       test_must_fail git send-email \
+       test_must_fail git -c sendemail.transferEncoding=8bit \
+               send-email \
                --transfer-encoding=7bit \
                --smtp-server="$(pwd)/fake.sendmail" \
                email-using-8bit \
@@ -1421,11 +1504,10 @@ test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data'
        test -z "$(ls msgtxt*)"
 '
 
-test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
+test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
        clean_fake_sendmail &&
-       git config sendemail.transferEncoding 8bit &&
-       test_must_fail git send-email \
-               --transfer-encoding=7bit \
+       test_must_fail git -c sendemail.transferEncoding=7bit \
+               send-email \
                --smtp-server="$(pwd)/fake.sendmail" \
                email-using-8bit \
                2>errors >out &&
@@ -1433,27 +1515,15 @@ test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEnc
        test -z "$(ls msgtxt*)"
 '
 
-test_expect_success $PREREQ 'sendemail.transferencoding=8bit via config' '
+test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
        clean_fake_sendmail &&
-       git -c sendemail.transferencoding=8bit send-email \
-               --smtp-server="$(pwd)/fake.sendmail" \
-               email-using-8bit \
-               2>errors >out &&
-       sed '1,/^$/d' msgtxt1 >actual &&
-       sed '1,/^$/d' email-using-8bit >expected &&
-       test_cmp expected actual
-'
-
-test_expect_success $PREREQ 'sendemail.transferencoding=8bit via cli' '
-       clean_fake_sendmail &&
-       git send-email \
-               --transfer-encoding=8bit \
+       test_must_fail git send-email \
+               --transfer-encoding=7bit \
                --smtp-server="$(pwd)/fake.sendmail" \
                email-using-8bit \
                2>errors >out &&
-       sed '1,/^$/d' msgtxt1 >actual &&
-       sed '1,/^$/d' email-using-8bit >expected &&
-       test_cmp expected actual
+       grep "cannot send message as 7bit" errors &&
+       test -z "$(ls msgtxt*)"
 '
 
 test_expect_success $PREREQ 'setup expect' '
@@ -1770,6 +1840,15 @@ test_expect_success '--dump-aliases must be used alone' '
        test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
 '
 
+test_expect_success $PREREQ 'aliases and sendemail.identity' '
+       test_must_fail git \
+               -c sendemail.identity=cloud \
+               -c sendemail.aliasesfile=default-aliases \
+               -c sendemail.cloud.aliasesfile=cloud-aliases \
+               send-email -1 2>stderr &&
+       test_i18ngrep "cloud-aliases" stderr
+'
+
 test_sendmail_aliases () {
        msg="$1" && shift &&
        expect="$@" &&
@@ -2034,11 +2113,11 @@ test_expect_success $PREREQ 'invoke hook' '
 
                # Verify error message when a patch is rejected by the hook
                sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
-               git send-email \
+               test_must_fail git send-email \
                        --from="Example <nobody@example.com>" \
                        --to=nobody@example.com \
                        --smtp-server="$(pwd)/../fake.sendmail" \
-                       ../another.patch 2>err
+                       ../another.patch 2>err &&
                test_i18ngrep "rejected by sendemail-validate hook" err
        )
 '