3 test_description='git send-email'
6 # May be altered later in the test
9 test_expect_success $PREREQ \
10 'prepare reference tree' \
11 'echo "1A quick brown fox jumps over the" >file &&
12 echo "lazy dog" >>file &&
14 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
16 test_expect_success $PREREQ \
18 '(echo "#!$SHELL_PATH"
21 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
24 echo " echo \"!\$a!\""
25 echo "done >commandline\$output"
26 echo "cat > msgtxt\$output"
28 chmod +x ./fake.sendmail &&
29 git add fake.sendmail &&
30 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
32 clean_fake_sendmail() {
33 rm -f commandline* msgtxt*
36 test_expect_success $PREREQ 'Extract patches' '
37 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
40 # Test no confirm early to ensure remaining tests will not hang
44 GIT_SEND_EMAIL_NOTTY=1 \
46 --from="Example <from@example.com>" \
47 --to=nobody@example.com \
48 --smtp-server="$(pwd)/fake.sendmail" \
51 test_must_fail grep "Send this email" stdout &&
55 # Exit immediately to prevent hang if a no-confirm test fails
57 if ! test -f no_confirm_okay
59 say 'confirm test failed; skipping remaining tests to prevent hanging'
60 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
65 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
66 test_no_confirm --suppress-cc=sob &&
71 test_expect_success $PREREQ 'No confirm with --confirm=never' '
72 test_no_confirm --confirm=never &&
76 # leave sendemail.confirm set to never after this so that none of the
77 # remaining tests prompt unintentionally.
78 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
79 git config sendemail.confirm never &&
80 test_no_confirm --compose --subject=foo &&
84 test_expect_success $PREREQ 'Send patches' '
85 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
88 test_expect_success $PREREQ 'setup expect' '
97 test_expect_success $PREREQ \
98 'Verify commandline' \
99 'test_cmp expected commandline1'
101 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
102 clean_fake_sendmail &&
103 git send-email --envelope-sender="Patch Contributer <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
106 test_expect_success $PREREQ 'setup expect' '
117 test_expect_success $PREREQ \
118 'Verify commandline' \
119 'test_cmp expected commandline1'
121 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
122 clean_fake_sendmail &&
123 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
126 test_expect_success $PREREQ 'setup expect' '
137 test_expect_success $PREREQ \
138 'Verify commandline' \
139 'test_cmp expected commandline1'
141 test_expect_success $PREREQ 'setup expect' "
142 cat >expected-show-all-headers <<\EOF
144 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
145 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
146 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
148 Server: relay.example.com
149 MAIL FROM:<from@example.com>
150 RCPT TO:<to@example.com>
151 RCPT TO:<cc@example.com>
152 RCPT TO:<author@example.com>
153 RCPT TO:<one@example.com>
154 RCPT TO:<two@example.com>
155 RCPT TO:<bcc@example.com>
156 From: Example <from@example.com>
159 A <author@example.com>,
160 One <one@example.com>,
162 Subject: [PATCH 1/1] Second.
164 Message-Id: MESSAGE-ID-STRING
165 X-Mailer: X-MAILER-STRING
166 In-Reply-To: <unique-message-id@example.com>
167 References: <unique-message-id@example.com>
173 test_expect_success $PREREQ 'Show all headers' '
177 --from="Example <from@example.com>" \
178 --to=to@example.com \
179 --cc=cc@example.com \
180 --bcc=bcc@example.com \
181 --in-reply-to="<unique-message-id@example.com>" \
182 --smtp-server relay.example.com \
184 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
185 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
186 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
187 >actual-show-all-headers &&
188 test_cmp expected-show-all-headers actual-show-all-headers
191 test_expect_success $PREREQ 'Prompting works' '
192 clean_fake_sendmail &&
193 (echo "Example <from@example.com>"
194 echo "to@example.com"
196 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
197 --smtp-server="$(pwd)/fake.sendmail" \
200 grep "^From: Example <from@example.com>\$" msgtxt1 &&
201 grep "^To: to@example.com\$" msgtxt1
204 test_expect_success $PREREQ 'cccmd works' '
205 clean_fake_sendmail &&
206 cp $patches cccmd.patch &&
207 echo cccmd--cccmd@example.com >>cccmd.patch &&
210 echo sed -n -e s/^cccmd--//p \"\$1\"
212 chmod +x cccmd-sed &&
214 --from="Example <nobody@example.com>" \
215 --to=nobody@example.com \
216 --cc-cmd=./cccmd-sed \
217 --smtp-server="$(pwd)/fake.sendmail" \
220 grep "^ cccmd@example.com" msgtxt1
223 test_expect_success $PREREQ 'reject long lines' '
225 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
226 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
227 clean_fake_sendmail &&
228 cp $patches longline.patch &&
229 echo $z512$z512 >>longline.patch &&
230 test_must_fail git send-email \
231 --from="Example <nobody@example.com>" \
232 --to=nobody@example.com \
233 --smtp-server="$(pwd)/fake.sendmail" \
234 $patches longline.patch \
236 grep longline.patch errors
239 test_expect_success $PREREQ 'no patch was sent' '
240 ! test -e commandline1
243 test_expect_success $PREREQ 'Author From: in message body' '
244 clean_fake_sendmail &&
246 --from="Example <nobody@example.com>" \
247 --to=nobody@example.com \
248 --smtp-server="$(pwd)/fake.sendmail" \
250 sed "1,/^\$/d" < msgtxt1 > msgbody1
251 grep "From: A <author@example.com>" msgbody1
254 test_expect_success $PREREQ 'Author From: not in message body' '
255 clean_fake_sendmail &&
257 --from="A <author@example.com>" \
258 --to=nobody@example.com \
259 --smtp-server="$(pwd)/fake.sendmail" \
261 sed "1,/^\$/d" < msgtxt1 > msgbody1
262 ! grep "From: A <author@example.com>" msgbody1
265 test_expect_success $PREREQ 'allow long lines with --no-validate' '
267 --from="Example <nobody@example.com>" \
268 --to=nobody@example.com \
269 --smtp-server="$(pwd)/fake.sendmail" \
271 $patches longline.patch \
275 test_expect_success $PREREQ 'Invalid In-Reply-To' '
276 clean_fake_sendmail &&
278 --from="Example <nobody@example.com>" \
279 --to=nobody@example.com \
281 --smtp-server="$(pwd)/fake.sendmail" \
284 ! grep "^In-Reply-To: < *>" msgtxt1
287 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
288 clean_fake_sendmail &&
289 (echo "From Example <from@example.com>"
290 echo "To Example <to@example.com>"
292 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
293 --smtp-server="$(pwd)/fake.sendmail" \
295 ! grep "^In-Reply-To: < *>" msgtxt1
298 test_expect_success $PREREQ 'setup fake editor' '
299 (echo "#!$SHELL_PATH" &&
300 echo "echo fake edit >>\"\$1\""
305 test_set_editor "$(pwd)/fake-editor"
307 test_expect_success $PREREQ '--compose works' '
308 clean_fake_sendmail &&
310 --compose --subject foo \
311 --from="Example <nobody@example.com>" \
312 --to=nobody@example.com \
313 --smtp-server="$(pwd)/fake.sendmail" \
318 test_expect_success $PREREQ 'first message is compose text' '
319 grep "^fake edit" msgtxt1
322 test_expect_success $PREREQ 'second message is patch' '
323 grep "Subject:.*Second" msgtxt2
326 test_expect_success $PREREQ 'setup expect' "
327 cat >expected-suppress-sob <<\EOF
329 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
330 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
331 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
333 Server: relay.example.com
334 MAIL FROM:<from@example.com>
335 RCPT TO:<to@example.com>
336 RCPT TO:<cc@example.com>
337 RCPT TO:<author@example.com>
338 RCPT TO:<one@example.com>
339 RCPT TO:<two@example.com>
340 From: Example <from@example.com>
343 A <author@example.com>,
344 One <one@example.com>,
346 Subject: [PATCH 1/1] Second.
348 Message-Id: MESSAGE-ID-STRING
349 X-Mailer: X-MAILER-STRING
355 test_suppression () {
358 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
359 --from="Example <from@example.com>" \
360 --to=to@example.com \
361 --smtp-server relay.example.com \
363 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
364 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
365 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
366 >actual-suppress-$1${2+"-$2"} &&
367 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
370 test_expect_success $PREREQ 'sendemail.cc set' '
371 git config sendemail.cc cc@example.com &&
375 test_expect_success $PREREQ 'setup expect' "
376 cat >expected-suppress-sob <<\EOF
378 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
379 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
380 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
382 Server: relay.example.com
383 MAIL FROM:<from@example.com>
384 RCPT TO:<to@example.com>
385 RCPT TO:<author@example.com>
386 RCPT TO:<one@example.com>
387 RCPT TO:<two@example.com>
388 From: Example <from@example.com>
390 Cc: A <author@example.com>,
391 One <one@example.com>,
393 Subject: [PATCH 1/1] Second.
395 Message-Id: MESSAGE-ID-STRING
396 X-Mailer: X-MAILER-STRING
402 test_expect_success $PREREQ 'sendemail.cc unset' '
403 git config --unset sendemail.cc &&
407 test_expect_success $PREREQ 'setup expect' "
408 cat >expected-suppress-cccmd <<\EOF
410 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
411 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
412 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
413 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
415 Server: relay.example.com
416 MAIL FROM:<from@example.com>
417 RCPT TO:<to@example.com>
418 RCPT TO:<author@example.com>
419 RCPT TO:<one@example.com>
420 RCPT TO:<two@example.com>
421 RCPT TO:<committer@example.com>
422 From: Example <from@example.com>
424 Cc: A <author@example.com>,
425 One <one@example.com>,
427 C O Mitter <committer@example.com>
428 Subject: [PATCH 1/1] Second.
430 Message-Id: MESSAGE-ID-STRING
431 X-Mailer: X-MAILER-STRING
437 test_expect_success $PREREQ 'sendemail.cccmd' '
438 echo echo cc-cmd@example.com > cccmd &&
440 git config sendemail.cccmd ./cccmd &&
441 test_suppression cccmd
444 test_expect_success $PREREQ 'setup expect' '
445 cat >expected-suppress-all <<\EOF
448 Server: relay.example.com
449 MAIL FROM:<from@example.com>
450 RCPT TO:<to@example.com>
451 From: Example <from@example.com>
453 Subject: [PATCH 1/1] Second.
455 Message-Id: MESSAGE-ID-STRING
456 X-Mailer: X-MAILER-STRING
462 test_expect_success $PREREQ '--suppress-cc=all' '
466 test_expect_success $PREREQ 'setup expect' "
467 cat >expected-suppress-body <<\EOF
469 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
470 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
471 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
472 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
474 Server: relay.example.com
475 MAIL FROM:<from@example.com>
476 RCPT TO:<to@example.com>
477 RCPT TO:<author@example.com>
478 RCPT TO:<one@example.com>
479 RCPT TO:<two@example.com>
480 RCPT TO:<cc-cmd@example.com>
481 From: Example <from@example.com>
483 Cc: A <author@example.com>,
484 One <one@example.com>,
487 Subject: [PATCH 1/1] Second.
489 Message-Id: MESSAGE-ID-STRING
490 X-Mailer: X-MAILER-STRING
496 test_expect_success $PREREQ '--suppress-cc=body' '
497 test_suppression body
500 test_expect_success $PREREQ 'setup expect' "
501 cat >expected-suppress-body-cccmd <<\EOF
503 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
504 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
505 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
507 Server: relay.example.com
508 MAIL FROM:<from@example.com>
509 RCPT TO:<to@example.com>
510 RCPT TO:<author@example.com>
511 RCPT TO:<one@example.com>
512 RCPT TO:<two@example.com>
513 From: Example <from@example.com>
515 Cc: A <author@example.com>,
516 One <one@example.com>,
518 Subject: [PATCH 1/1] Second.
520 Message-Id: MESSAGE-ID-STRING
521 X-Mailer: X-MAILER-STRING
527 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
528 test_suppression body cccmd
531 test_expect_success $PREREQ 'setup expect' "
532 cat >expected-suppress-sob <<\EOF
534 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
535 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
536 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
538 Server: relay.example.com
539 MAIL FROM:<from@example.com>
540 RCPT TO:<to@example.com>
541 RCPT TO:<author@example.com>
542 RCPT TO:<one@example.com>
543 RCPT TO:<two@example.com>
544 From: Example <from@example.com>
546 Cc: A <author@example.com>,
547 One <one@example.com>,
549 Subject: [PATCH 1/1] Second.
551 Message-Id: MESSAGE-ID-STRING
552 X-Mailer: X-MAILER-STRING
558 test_expect_success $PREREQ '--suppress-cc=sob' '
559 git config --unset sendemail.cccmd
563 test_expect_success $PREREQ 'setup expect' "
564 cat >expected-suppress-bodycc <<\EOF
566 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
567 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
568 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
569 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
571 Server: relay.example.com
572 MAIL FROM:<from@example.com>
573 RCPT TO:<to@example.com>
574 RCPT TO:<author@example.com>
575 RCPT TO:<one@example.com>
576 RCPT TO:<two@example.com>
577 RCPT TO:<committer@example.com>
578 From: Example <from@example.com>
580 Cc: A <author@example.com>,
581 One <one@example.com>,
583 C O Mitter <committer@example.com>
584 Subject: [PATCH 1/1] Second.
586 Message-Id: MESSAGE-ID-STRING
587 X-Mailer: X-MAILER-STRING
593 test_expect_success $PREREQ '--suppress-cc=bodycc' '
594 test_suppression bodycc
597 test_expect_success $PREREQ 'setup expect' "
598 cat >expected-suppress-cc <<\EOF
600 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
601 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
603 Server: relay.example.com
604 MAIL FROM:<from@example.com>
605 RCPT TO:<to@example.com>
606 RCPT TO:<author@example.com>
607 RCPT TO:<committer@example.com>
608 From: Example <from@example.com>
610 Cc: A <author@example.com>,
611 C O Mitter <committer@example.com>
612 Subject: [PATCH 1/1] Second.
614 Message-Id: MESSAGE-ID-STRING
615 X-Mailer: X-MAILER-STRING
621 test_expect_success $PREREQ '--suppress-cc=cc' '
627 GIT_SEND_EMAIL_NOTTY=1 \
629 --from="Example <nobody@example.com>" \
630 --to=nobody@example.com \
631 --smtp-server="$(pwd)/fake.sendmail" \
632 $@ $patches > stdout &&
633 grep "Send this email" stdout
636 test_expect_success $PREREQ '--confirm=always' '
637 test_confirm --confirm=always --suppress-cc=all
640 test_expect_success $PREREQ '--confirm=auto' '
641 test_confirm --confirm=auto
644 test_expect_success $PREREQ '--confirm=cc' '
645 test_confirm --confirm=cc
648 test_expect_success $PREREQ '--confirm=compose' '
649 test_confirm --confirm=compose --compose
652 test_expect_success $PREREQ 'confirm by default (due to cc)' '
653 CONFIRM=$(git config --get sendemail.confirm) &&
654 git config --unset sendemail.confirm &&
657 git config sendemail.confirm ${CONFIRM:-never}
661 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
662 CONFIRM=$(git config --get sendemail.confirm) &&
663 git config --unset sendemail.confirm &&
664 test_confirm --suppress-cc=all --compose
666 git config sendemail.confirm ${CONFIRM:-never}
670 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
671 CONFIRM=$(git config --get sendemail.confirm) &&
672 git config --unset sendemail.confirm &&
674 git format-patch -2 -o outdir &&
675 GIT_SEND_EMAIL_NOTTY=1 \
677 --from="Example <nobody@example.com>" \
678 --to=nobody@example.com \
679 --smtp-server="$(pwd)/fake.sendmail" \
680 outdir/*.patch < /dev/null
682 git config sendemail.confirm ${CONFIRM:-never}
686 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
687 CONFIRM=$(git config --get sendemail.confirm) &&
688 git config sendemail.confirm auto &&
689 GIT_SEND_EMAIL_NOTTY=1 &&
690 export GIT_SEND_EMAIL_NOTTY &&
691 test_must_fail git send-email \
692 --from="Example <nobody@example.com>" \
693 --to=nobody@example.com \
694 --smtp-server="$(pwd)/fake.sendmail" \
697 git config sendemail.confirm ${CONFIRM:-never}
701 test_expect_success $PREREQ 'confirm doesnt loop forever' '
702 CONFIRM=$(git config --get sendemail.confirm) &&
703 git config sendemail.confirm auto &&
704 GIT_SEND_EMAIL_NOTTY=1 &&
705 export GIT_SEND_EMAIL_NOTTY &&
706 yes "bogus" | test_must_fail git send-email \
707 --from="Example <nobody@example.com>" \
708 --to=nobody@example.com \
709 --smtp-server="$(pwd)/fake.sendmail" \
712 git config sendemail.confirm ${CONFIRM:-never}
716 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
717 clean_fake_sendmail &&
719 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
721 --from="Example <nobody@example.com>" \
722 --to=nobody@example.com \
723 --smtp-server="$(pwd)/fake.sendmail" \
726 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
729 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
730 clean_fake_sendmail &&
731 (echo "#!$SHELL_PATH" &&
732 echo "echo utf8 body: àéìöú >>\"\$1\""
733 ) >fake-editor-utf8 &&
734 chmod +x fake-editor-utf8 &&
735 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
737 --compose --subject foo \
738 --from="Example <nobody@example.com>" \
739 --to=nobody@example.com \
740 --smtp-server="$(pwd)/fake.sendmail" \
742 grep "^utf8 body" msgtxt1 &&
743 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
746 test_expect_success $PREREQ '--compose respects user mime type' '
747 clean_fake_sendmail &&
748 (echo "#!$SHELL_PATH" &&
749 echo "(echo MIME-Version: 1.0"
750 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
751 echo " echo Content-Transfer-Encoding: 8bit"
752 echo " echo Subject: foo"
754 echo " echo utf8 body: àéìöú) >\"\$1\""
755 ) >fake-editor-utf8-mime &&
756 chmod +x fake-editor-utf8-mime &&
757 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
759 --compose --subject foo \
760 --from="Example <nobody@example.com>" \
761 --to=nobody@example.com \
762 --smtp-server="$(pwd)/fake.sendmail" \
764 grep "^utf8 body" msgtxt1 &&
765 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
766 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
769 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
770 clean_fake_sendmail &&
771 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
773 --compose --subject utf8-sübjëct \
774 --from="Example <nobody@example.com>" \
775 --to=nobody@example.com \
776 --smtp-server="$(pwd)/fake.sendmail" \
778 grep "^fake edit" msgtxt1 &&
779 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
782 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
783 echo master > master &&
785 git commit -m"add master" &&
786 test_must_fail git send-email --dry-run master 2>errors &&
787 grep disambiguate errors
790 test_expect_success $PREREQ 'feed two files' '
792 git format-patch -2 -o outdir &&
795 --from="Example <nobody@example.com>" \
796 --to=nobody@example.com \
797 outdir/000?-*.patch 2>errors >out &&
798 grep "^Subject: " out >subjects &&
799 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
800 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
803 test_expect_success $PREREQ 'in-reply-to but no threading' '
806 --from="Example <nobody@example.com>" \
807 --to=nobody@example.com \
808 --in-reply-to="<in-reply-id@example.com>" \
811 grep "In-Reply-To: <in-reply-id@example.com>"
814 test_expect_success $PREREQ 'no in-reply-to and no threading' '
817 --from="Example <nobody@example.com>" \
818 --to=nobody@example.com \
820 $patches $patches >stdout &&
821 ! grep "In-Reply-To: " stdout
824 test_expect_success $PREREQ 'threading but no chain-reply-to' '
827 --from="Example <nobody@example.com>" \
828 --to=nobody@example.com \
831 $patches $patches >stdout &&
832 grep "In-Reply-To: " stdout
835 test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
838 --from="Example <nobody@example.com>" \
839 --to=nobody@example.com \
840 outdir/000?-*.patch 2>errors >out &&
841 grep "no-chain-reply-to" errors
844 test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
847 --from="Example <nobody@example.com>" \
848 --to=nobody@example.com \
850 outdir/000?-*.patch 2>errors >out &&
851 ! grep "no-chain-reply-to" errors
854 test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
857 --from="Example <nobody@example.com>" \
858 --to=nobody@example.com \
860 outdir/000?-*.patch 2>errors >out &&
861 ! grep "no-chain-reply-to" errors
864 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
865 git config sendemail.chainreplyto false &&
868 --from="Example <nobody@example.com>" \
869 --to=nobody@example.com \
870 outdir/000?-*.patch 2>errors >out &&
871 ! grep "no-chain-reply-to" errors
874 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
875 git config sendemail.chainreplyto true &&
878 --from="Example <nobody@example.com>" \
879 --to=nobody@example.com \
880 outdir/000?-*.patch 2>errors >out &&
881 ! grep "no-chain-reply-to" errors
884 test_expect_success $PREREQ 'sendemail.to works' '
885 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
888 --from="Example <nobody@example.com>" \
889 $patches $patches >stdout &&
890 grep "To: Somebody <somebody@ex.com>" stdout
893 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
896 --from="Example <nobody@example.com>" \
898 --to=nobody@example.com \
899 $patches $patches >stdout &&
900 grep "To: nobody@example.com" stdout &&
901 ! grep "To: Somebody <somebody@ex.com>" stdout
904 test_expect_success $PREREQ 'sendemail.cc works' '
905 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
908 --from="Example <nobody@example.com>" \
909 --to=nobody@example.com \
910 $patches $patches >stdout &&
911 grep "Cc: Somebody <somebody@ex.com>" stdout
914 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
917 --from="Example <nobody@example.com>" \
919 --cc=bodies@example.com \
920 --to=nobody@example.com \
921 $patches $patches >stdout &&
922 grep "Cc: bodies@example.com" stdout &&
923 ! grep "Cc: Somebody <somebody@ex.com>" stdout
926 test_expect_success $PREREQ 'sendemail.bcc works' '
927 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
930 --from="Example <nobody@example.com>" \
931 --to=nobody@example.com \
932 --smtp-server relay.example.com \
933 $patches $patches >stdout &&
934 grep "RCPT TO:<other@ex.com>" stdout
937 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
940 --from="Example <nobody@example.com>" \
942 --bcc=bodies@example.com \
943 --to=nobody@example.com \
944 --smtp-server relay.example.com \
945 $patches $patches >stdout &&
946 grep "RCPT TO:<bodies@example.com>" stdout &&
947 ! grep "RCPT TO:<other@ex.com>" stdout
950 test_expect_success $PREREQ 'setup expect' '
951 cat >email-using-8bit <<EOF
952 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
953 Message-Id: <bogus-message-id@example.com>
954 From: author@example.com
955 Date: Sat, 12 Jun 2010 15:53:58 +0200
956 Subject: subject goes here
958 Dieser deutsche Text enthält einen Umlaut!
962 test_expect_success $PREREQ 'setup expect' '
963 cat >content-type-decl <<EOF
965 Content-Type: text/plain; charset=UTF-8
966 Content-Transfer-Encoding: 8bit
970 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
971 clean_fake_sendmail &&
973 git send-email --from=author@example.com --to=nobody@example.com \
974 --smtp-server="$(pwd)/fake.sendmail" \
975 email-using-8bit >stdout &&
976 grep "do not declare a Content-Transfer-Encoding" stdout &&
977 grep email-using-8bit stdout &&
978 grep "Which 8bit encoding" stdout &&
979 egrep "Content|MIME" msgtxt1 >actual &&
980 test_cmp actual content-type-decl
983 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
984 clean_fake_sendmail &&
985 git config sendemail.assume8bitEncoding UTF-8 &&
987 git send-email --from=author@example.com --to=nobody@example.com \
988 --smtp-server="$(pwd)/fake.sendmail" \
989 email-using-8bit >stdout &&
990 egrep "Content|MIME" msgtxt1 >actual &&
991 test_cmp actual content-type-decl
994 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
995 clean_fake_sendmail &&
996 git config sendemail.assume8bitEncoding "bogus too" &&
998 git send-email --from=author@example.com --to=nobody@example.com \
999 --smtp-server="$(pwd)/fake.sendmail" \
1000 --8bit-encoding=UTF-8 \
1001 email-using-8bit >stdout &&
1002 egrep "Content|MIME" msgtxt1 >actual &&
1003 test_cmp actual content-type-decl
1006 test_expect_success $PREREQ 'setup expect' '
1007 cat >email-using-8bit <<EOF
1008 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1009 Message-Id: <bogus-message-id@example.com>
1010 From: author@example.com
1011 Date: Sat, 12 Jun 2010 15:53:58 +0200
1012 Subject: Dieser Betreff enthält auch einen Umlaut!
1014 Nothing to see here.
1018 test_expect_success $PREREQ 'setup expect' '
1020 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1024 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1025 clean_fake_sendmail &&
1027 git send-email --from=author@example.com --to=nobody@example.com \
1028 --smtp-server="$(pwd)/fake.sendmail" \
1029 --8bit-encoding=UTF-8 \
1030 email-using-8bit >stdout &&
1031 grep "Subject" msgtxt1 >actual &&
1032 test_cmp expected actual
1035 # Note that the patches in this test are deliberately out of order; we
1036 # want to make sure it works even if the cover-letter is not in the
1038 test_expect_success $PREREQ 'refusing to send cover letter template' '
1039 clean_fake_sendmail &&
1041 git format-patch --cover-letter -2 -o outdir &&
1042 test_must_fail git send-email \
1043 --from="Example <nobody@example.com>" \
1044 --to=nobody@example.com \
1045 --smtp-server="$(pwd)/fake.sendmail" \
1046 outdir/0002-*.patch \
1047 outdir/0000-*.patch \
1048 outdir/0001-*.patch \
1050 grep "SUBJECT HERE" errors &&
1051 test -z "$(ls msgtxt*)"
1054 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1055 clean_fake_sendmail &&
1057 git format-patch --cover-letter -2 -o outdir &&
1060 --from="Example <nobody@example.com>" \
1061 --to=nobody@example.com \
1062 --smtp-server="$(pwd)/fake.sendmail" \
1063 outdir/0002-*.patch \
1064 outdir/0000-*.patch \
1065 outdir/0001-*.patch \
1067 ! grep "SUBJECT HERE" errors &&
1068 test -n "$(ls msgtxt*)"