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 'tocmd works' '
205 clean_fake_sendmail &&
206 cp $patches tocmd.patch &&
207 echo tocmd--tocmd@example.com >>tocmd.patch &&
210 echo sed -n -e s/^tocmd--//p \"\$1\"
212 chmod +x tocmd-sed &&
214 --from="Example <nobody@example.com>" \
215 --to-cmd=./tocmd-sed \
216 --smtp-server="$(pwd)/fake.sendmail" \
219 grep "^To: tocmd@example.com" msgtxt1
222 test_expect_success
$PREREQ 'cccmd works' '
223 clean_fake_sendmail &&
224 cp $patches cccmd.patch &&
225 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
228 echo sed -n -e s/^cccmd--//p \"\$1\"
230 chmod +x cccmd-sed &&
232 --from="Example <nobody@example.com>" \
233 --to=nobody@example.com \
234 --cc-cmd=./cccmd-sed \
235 --smtp-server="$(pwd)/fake.sendmail" \
238 grep "^ cccmd@example.com" msgtxt1
241 test_expect_success
$PREREQ 'reject long lines' '
243 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
244 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
245 clean_fake_sendmail &&
246 cp $patches longline.patch &&
247 echo $z512$z512 >>longline.patch &&
248 test_must_fail git send-email \
249 --from="Example <nobody@example.com>" \
250 --to=nobody@example.com \
251 --smtp-server="$(pwd)/fake.sendmail" \
252 $patches longline.patch \
254 grep longline.patch errors
257 test_expect_success
$PREREQ 'no patch was sent' '
258 ! test -e commandline1
261 test_expect_success
$PREREQ 'Author From: in message body' '
262 clean_fake_sendmail &&
264 --from="Example <nobody@example.com>" \
265 --to=nobody@example.com \
266 --smtp-server="$(pwd)/fake.sendmail" \
268 sed "1,/^\$/d" < msgtxt1 > msgbody1
269 grep "From: A <author@example.com>" msgbody1
272 test_expect_success
$PREREQ 'Author From: not in message body' '
273 clean_fake_sendmail &&
275 --from="A <author@example.com>" \
276 --to=nobody@example.com \
277 --smtp-server="$(pwd)/fake.sendmail" \
279 sed "1,/^\$/d" < msgtxt1 > msgbody1
280 ! grep "From: A <author@example.com>" msgbody1
283 test_expect_success
$PREREQ 'allow long lines with --no-validate' '
285 --from="Example <nobody@example.com>" \
286 --to=nobody@example.com \
287 --smtp-server="$(pwd)/fake.sendmail" \
289 $patches longline.patch \
293 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
294 clean_fake_sendmail &&
296 --from="Example <nobody@example.com>" \
297 --to=nobody@example.com \
299 --smtp-server="$(pwd)/fake.sendmail" \
302 ! grep "^In-Reply-To: < *>" msgtxt1
305 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
306 clean_fake_sendmail &&
307 (echo "From Example <from@example.com>"
308 echo "To Example <to@example.com>"
310 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
311 --smtp-server="$(pwd)/fake.sendmail" \
313 ! grep "^In-Reply-To: < *>" msgtxt1
316 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
317 clean_fake_sendmail &&
318 echo "<unique-message-id@example.com>" >expect &&
320 --from="Example <nobody@example.com>" \
321 --to=nobody@example.com \
322 --no-chain-reply-to \
323 --in-reply-to="$(cat expect)" \
324 --smtp-server="$(pwd)/fake.sendmail" \
325 $patches $patches $patches \
327 # All the messages are replies to --in-reply-to
328 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
329 test_cmp expect actual &&
330 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
331 test_cmp expect actual &&
332 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
333 test_cmp expect actual
336 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
337 clean_fake_sendmail &&
338 echo "<unique-message-id@example.com>" >expect &&
340 --from="Example <nobody@example.com>" \
341 --to=nobody@example.com \
343 --in-reply-to="$(cat expect)" \
344 --smtp-server="$(pwd)/fake.sendmail" \
345 $patches $patches $patches \
347 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
348 test_cmp expect actual &&
349 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
350 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
351 test_cmp expect actual &&
352 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
353 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
354 test_cmp expect actual
357 test_expect_success
$PREREQ 'setup fake editor' '
358 (echo "#!$SHELL_PATH" &&
359 echo "echo fake edit >>\"\$1\""
364 test_set_editor
"$(pwd)/fake-editor"
366 test_expect_success
$PREREQ '--compose works' '
367 clean_fake_sendmail &&
369 --compose --subject foo \
370 --from="Example <nobody@example.com>" \
371 --to=nobody@example.com \
372 --smtp-server="$(pwd)/fake.sendmail" \
377 test_expect_success
$PREREQ 'first message is compose text' '
378 grep "^fake edit" msgtxt1
381 test_expect_success
$PREREQ 'second message is patch' '
382 grep "Subject:.*Second" msgtxt2
385 test_expect_success
$PREREQ 'setup expect' "
386 cat >expected-suppress-sob <<\EOF
388 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
389 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
390 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
392 Server: relay.example.com
393 MAIL FROM:<from@example.com>
394 RCPT TO:<to@example.com>
395 RCPT TO:<cc@example.com>
396 RCPT TO:<author@example.com>
397 RCPT TO:<one@example.com>
398 RCPT TO:<two@example.com>
399 From: Example <from@example.com>
402 A <author@example.com>,
403 One <one@example.com>,
405 Subject: [PATCH 1/1] Second.
407 Message-Id: MESSAGE-ID-STRING
408 X-Mailer: X-MAILER-STRING
414 test_suppression
() {
417 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
418 --from="Example <from@example.com>" \
419 --to=to@example.com \
420 --smtp-server relay.example.com \
422 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
423 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
424 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
425 >actual-suppress-
$1${2+"-$2"} &&
426 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
429 test_expect_success
$PREREQ 'sendemail.cc set' '
430 git config sendemail.cc cc@example.com &&
434 test_expect_success
$PREREQ 'setup expect' "
435 cat >expected-suppress-sob <<\EOF
437 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
438 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
439 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
441 Server: relay.example.com
442 MAIL FROM:<from@example.com>
443 RCPT TO:<to@example.com>
444 RCPT TO:<author@example.com>
445 RCPT TO:<one@example.com>
446 RCPT TO:<two@example.com>
447 From: Example <from@example.com>
449 Cc: A <author@example.com>,
450 One <one@example.com>,
452 Subject: [PATCH 1/1] Second.
454 Message-Id: MESSAGE-ID-STRING
455 X-Mailer: X-MAILER-STRING
461 test_expect_success
$PREREQ 'sendemail.cc unset' '
462 git config --unset sendemail.cc &&
466 test_expect_success
$PREREQ 'setup expect' "
467 cat >expected-suppress-cccmd <<\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 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
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:<committer@example.com>
481 From: Example <from@example.com>
483 Cc: A <author@example.com>,
484 One <one@example.com>,
486 C O Mitter <committer@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 'sendemail.cccmd' '
497 echo echo cc-cmd@example.com > cccmd &&
499 git config sendemail.cccmd ./cccmd &&
500 test_suppression cccmd
503 test_expect_success
$PREREQ 'setup expect' '
504 cat >expected-suppress-all <<\EOF
507 Server: relay.example.com
508 MAIL FROM:<from@example.com>
509 RCPT TO:<to@example.com>
510 From: Example <from@example.com>
512 Subject: [PATCH 1/1] Second.
514 Message-Id: MESSAGE-ID-STRING
515 X-Mailer: X-MAILER-STRING
521 test_expect_success
$PREREQ '--suppress-cc=all' '
525 test_expect_success
$PREREQ 'setup expect' "
526 cat >expected-suppress-body <<\EOF
528 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
529 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
530 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
531 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
533 Server: relay.example.com
534 MAIL FROM:<from@example.com>
535 RCPT TO:<to@example.com>
536 RCPT TO:<author@example.com>
537 RCPT TO:<one@example.com>
538 RCPT TO:<two@example.com>
539 RCPT TO:<cc-cmd@example.com>
540 From: Example <from@example.com>
542 Cc: A <author@example.com>,
543 One <one@example.com>,
546 Subject: [PATCH 1/1] Second.
548 Message-Id: MESSAGE-ID-STRING
549 X-Mailer: X-MAILER-STRING
555 test_expect_success
$PREREQ '--suppress-cc=body' '
556 test_suppression body
559 test_expect_success
$PREREQ 'setup expect' "
560 cat >expected-suppress-body-cccmd <<\EOF
562 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
563 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
564 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
566 Server: relay.example.com
567 MAIL FROM:<from@example.com>
568 RCPT TO:<to@example.com>
569 RCPT TO:<author@example.com>
570 RCPT TO:<one@example.com>
571 RCPT TO:<two@example.com>
572 From: Example <from@example.com>
574 Cc: A <author@example.com>,
575 One <one@example.com>,
577 Subject: [PATCH 1/1] Second.
579 Message-Id: MESSAGE-ID-STRING
580 X-Mailer: X-MAILER-STRING
586 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
587 test_suppression body cccmd
590 test_expect_success
$PREREQ 'setup expect' "
591 cat >expected-suppress-sob <<\EOF
593 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
594 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
595 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
597 Server: relay.example.com
598 MAIL FROM:<from@example.com>
599 RCPT TO:<to@example.com>
600 RCPT TO:<author@example.com>
601 RCPT TO:<one@example.com>
602 RCPT TO:<two@example.com>
603 From: Example <from@example.com>
605 Cc: A <author@example.com>,
606 One <one@example.com>,
608 Subject: [PATCH 1/1] Second.
610 Message-Id: MESSAGE-ID-STRING
611 X-Mailer: X-MAILER-STRING
617 test_expect_success
$PREREQ '--suppress-cc=sob' '
618 git config --unset sendemail.cccmd
622 test_expect_success
$PREREQ 'setup expect' "
623 cat >expected-suppress-bodycc <<\EOF
625 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
626 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
627 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
628 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
630 Server: relay.example.com
631 MAIL FROM:<from@example.com>
632 RCPT TO:<to@example.com>
633 RCPT TO:<author@example.com>
634 RCPT TO:<one@example.com>
635 RCPT TO:<two@example.com>
636 RCPT TO:<committer@example.com>
637 From: Example <from@example.com>
639 Cc: A <author@example.com>,
640 One <one@example.com>,
642 C O Mitter <committer@example.com>
643 Subject: [PATCH 1/1] Second.
645 Message-Id: MESSAGE-ID-STRING
646 X-Mailer: X-MAILER-STRING
652 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
653 test_suppression bodycc
656 test_expect_success
$PREREQ 'setup expect' "
657 cat >expected-suppress-cc <<\EOF
659 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
660 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
662 Server: relay.example.com
663 MAIL FROM:<from@example.com>
664 RCPT TO:<to@example.com>
665 RCPT TO:<author@example.com>
666 RCPT TO:<committer@example.com>
667 From: Example <from@example.com>
669 Cc: A <author@example.com>,
670 C O Mitter <committer@example.com>
671 Subject: [PATCH 1/1] Second.
673 Message-Id: MESSAGE-ID-STRING
674 X-Mailer: X-MAILER-STRING
680 test_expect_success
$PREREQ '--suppress-cc=cc' '
686 GIT_SEND_EMAIL_NOTTY
=1 \
688 --from="Example <nobody@example.com>" \
689 --to=nobody@example.com \
690 --smtp-server="$(pwd)/fake.sendmail" \
691 $@
$patches > stdout
&&
692 grep "Send this email" stdout
695 test_expect_success
$PREREQ '--confirm=always' '
696 test_confirm --confirm=always --suppress-cc=all
699 test_expect_success
$PREREQ '--confirm=auto' '
700 test_confirm --confirm=auto
703 test_expect_success
$PREREQ '--confirm=cc' '
704 test_confirm --confirm=cc
707 test_expect_success
$PREREQ '--confirm=compose' '
708 test_confirm --confirm=compose --compose
711 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
712 CONFIRM=$(git config --get sendemail.confirm) &&
713 git config --unset sendemail.confirm &&
716 git config sendemail.confirm ${CONFIRM:-never}
720 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
721 CONFIRM=$(git config --get sendemail.confirm) &&
722 git config --unset sendemail.confirm &&
723 test_confirm --suppress-cc=all --compose
725 git config sendemail.confirm ${CONFIRM:-never}
729 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
730 CONFIRM=$(git config --get sendemail.confirm) &&
731 git config --unset sendemail.confirm &&
733 git format-patch -2 -o outdir &&
734 GIT_SEND_EMAIL_NOTTY=1 \
736 --from="Example <nobody@example.com>" \
737 --to=nobody@example.com \
738 --smtp-server="$(pwd)/fake.sendmail" \
739 outdir/*.patch < /dev/null
741 git config sendemail.confirm ${CONFIRM:-never}
745 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
746 CONFIRM=$(git config --get sendemail.confirm) &&
747 git config sendemail.confirm auto &&
748 GIT_SEND_EMAIL_NOTTY=1 &&
749 export GIT_SEND_EMAIL_NOTTY &&
750 test_must_fail git send-email \
751 --from="Example <nobody@example.com>" \
752 --to=nobody@example.com \
753 --smtp-server="$(pwd)/fake.sendmail" \
756 git config sendemail.confirm ${CONFIRM:-never}
760 test_expect_success
$PREREQ 'confirm doesnt loop forever' '
761 CONFIRM=$(git config --get sendemail.confirm) &&
762 git config sendemail.confirm auto &&
763 GIT_SEND_EMAIL_NOTTY=1 &&
764 export GIT_SEND_EMAIL_NOTTY &&
765 yes "bogus" | test_must_fail git send-email \
766 --from="Example <nobody@example.com>" \
767 --to=nobody@example.com \
768 --smtp-server="$(pwd)/fake.sendmail" \
771 git config sendemail.confirm ${CONFIRM:-never}
775 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
776 clean_fake_sendmail &&
778 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
780 --from="Example <nobody@example.com>" \
781 --to=nobody@example.com \
782 --smtp-server="$(pwd)/fake.sendmail" \
785 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
788 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
789 clean_fake_sendmail &&
790 (echo "#!$SHELL_PATH" &&
791 echo "echo utf8 body: àéìöú >>\"\$1\""
792 ) >fake-editor-utf8 &&
793 chmod +x fake-editor-utf8 &&
794 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
796 --compose --subject foo \
797 --from="Example <nobody@example.com>" \
798 --to=nobody@example.com \
799 --smtp-server="$(pwd)/fake.sendmail" \
801 grep "^utf8 body" msgtxt1 &&
802 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
805 test_expect_success
$PREREQ '--compose respects user mime type' '
806 clean_fake_sendmail &&
807 (echo "#!$SHELL_PATH" &&
808 echo "(echo MIME-Version: 1.0"
809 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
810 echo " echo Content-Transfer-Encoding: 8bit"
811 echo " echo Subject: foo"
813 echo " echo utf8 body: àéìöú) >\"\$1\""
814 ) >fake-editor-utf8-mime &&
815 chmod +x fake-editor-utf8-mime &&
816 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
818 --compose --subject foo \
819 --from="Example <nobody@example.com>" \
820 --to=nobody@example.com \
821 --smtp-server="$(pwd)/fake.sendmail" \
823 grep "^utf8 body" msgtxt1 &&
824 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
825 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
828 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
829 clean_fake_sendmail &&
830 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
832 --compose --subject utf8-sübjëct \
833 --from="Example <nobody@example.com>" \
834 --to=nobody@example.com \
835 --smtp-server="$(pwd)/fake.sendmail" \
837 grep "^fake edit" msgtxt1 &&
838 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
841 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
842 echo master > master &&
844 git commit -m"add master" &&
845 test_must_fail git send-email --dry-run master 2>errors &&
846 grep disambiguate errors
849 test_expect_success
$PREREQ 'feed two files' '
851 git format-patch -2 -o outdir &&
854 --from="Example <nobody@example.com>" \
855 --to=nobody@example.com \
856 outdir/000?-*.patch 2>errors >out &&
857 grep "^Subject: " out >subjects &&
858 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
859 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
862 test_expect_success
$PREREQ 'in-reply-to but no threading' '
865 --from="Example <nobody@example.com>" \
866 --to=nobody@example.com \
867 --in-reply-to="<in-reply-id@example.com>" \
870 grep "In-Reply-To: <in-reply-id@example.com>"
873 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
876 --from="Example <nobody@example.com>" \
877 --to=nobody@example.com \
879 $patches $patches >stdout &&
880 ! grep "In-Reply-To: " stdout
883 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
886 --from="Example <nobody@example.com>" \
887 --to=nobody@example.com \
890 $patches $patches >stdout &&
891 grep "In-Reply-To: " stdout
894 test_expect_success
$PREREQ 'warning with an implicit --chain-reply-to' '
897 --from="Example <nobody@example.com>" \
898 --to=nobody@example.com \
899 outdir/000?-*.patch 2>errors >out &&
900 grep "no-chain-reply-to" errors
903 test_expect_success
$PREREQ 'no warning with an explicit --chain-reply-to' '
906 --from="Example <nobody@example.com>" \
907 --to=nobody@example.com \
909 outdir/000?-*.patch 2>errors >out &&
910 ! grep "no-chain-reply-to" errors
913 test_expect_success
$PREREQ 'no warning with an explicit --no-chain-reply-to' '
916 --from="Example <nobody@example.com>" \
917 --to=nobody@example.com \
919 outdir/000?-*.patch 2>errors >out &&
920 ! grep "no-chain-reply-to" errors
923 test_expect_success
$PREREQ 'no warning with sendemail.chainreplyto = false' '
924 git config sendemail.chainreplyto false &&
927 --from="Example <nobody@example.com>" \
928 --to=nobody@example.com \
929 outdir/000?-*.patch 2>errors >out &&
930 ! grep "no-chain-reply-to" errors
933 test_expect_success
$PREREQ 'no warning with sendemail.chainreplyto = true' '
934 git config sendemail.chainreplyto true &&
937 --from="Example <nobody@example.com>" \
938 --to=nobody@example.com \
939 outdir/000?-*.patch 2>errors >out &&
940 ! grep "no-chain-reply-to" errors
943 test_expect_success
$PREREQ 'sendemail.to works' '
944 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
947 --from="Example <nobody@example.com>" \
948 $patches $patches >stdout &&
949 grep "To: Somebody <somebody@ex.com>" stdout
952 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
955 --from="Example <nobody@example.com>" \
957 --to=nobody@example.com \
958 $patches $patches >stdout &&
959 grep "To: nobody@example.com" stdout &&
960 ! grep "To: Somebody <somebody@ex.com>" stdout
963 test_expect_success
$PREREQ 'sendemail.cc works' '
964 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
967 --from="Example <nobody@example.com>" \
968 --to=nobody@example.com \
969 $patches $patches >stdout &&
970 grep "Cc: Somebody <somebody@ex.com>" stdout
973 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
976 --from="Example <nobody@example.com>" \
978 --cc=bodies@example.com \
979 --to=nobody@example.com \
980 $patches $patches >stdout &&
981 grep "Cc: bodies@example.com" stdout &&
982 ! grep "Cc: Somebody <somebody@ex.com>" stdout
985 test_expect_success
$PREREQ 'sendemail.bcc works' '
986 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
989 --from="Example <nobody@example.com>" \
990 --to=nobody@example.com \
991 --smtp-server relay.example.com \
992 $patches $patches >stdout &&
993 grep "RCPT TO:<other@ex.com>" stdout
996 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
999 --from="Example <nobody@example.com>" \
1001 --bcc=bodies@example.com \
1002 --to=nobody@example.com \
1003 --smtp-server relay.example.com \
1004 $patches $patches >stdout &&
1005 grep "RCPT TO:<bodies@example.com>" stdout &&
1006 ! grep "RCPT TO:<other@ex.com>" stdout
1009 test_expect_success
$PREREQ 'patches To headers are used by default' '
1010 patch=`git format-patch -1 --to="bodies@example.com"` &&
1011 test_when_finished "rm $patch" &&
1014 --from="Example <nobody@example.com>" \
1015 --smtp-server relay.example.com \
1017 grep "RCPT TO:<bodies@example.com>" stdout
1020 test_expect_success
$PREREQ 'patches To headers are appended to' '
1021 patch=`git format-patch -1 --to="bodies@example.com"` &&
1022 test_when_finished "rm $patch" &&
1025 --from="Example <nobody@example.com>" \
1026 --to=nobody@example.com \
1027 --smtp-server relay.example.com \
1029 grep "RCPT TO:<bodies@example.com>" stdout &&
1030 grep "RCPT TO:<nobody@example.com>" stdout
1033 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1034 patch1=`git format-patch -1 --to="bodies@example.com"` &&
1035 patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1036 test_when_finished "rm $patch1 && rm $patch2" &&
1039 --from="Example <nobody@example.com>" \
1040 --to="nobody@example.com" \
1041 --smtp-server relay.example.com \
1042 $patch1 $patch2 >stdout &&
1043 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1044 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1045 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1048 test_expect_success
$PREREQ 'setup expect' '
1049 cat >email-using-8bit <<EOF
1050 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1051 Message-Id: <bogus-message-id@example.com>
1052 From: author@example.com
1053 Date: Sat, 12 Jun 2010 15:53:58 +0200
1054 Subject: subject goes here
1056 Dieser deutsche Text enthält einen Umlaut!
1060 test_expect_success
$PREREQ 'setup expect' '
1061 cat >content-type-decl <<EOF
1063 Content-Type: text/plain; charset=UTF-8
1064 Content-Transfer-Encoding: 8bit
1068 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1069 clean_fake_sendmail &&
1071 git send-email --from=author@example.com --to=nobody@example.com \
1072 --smtp-server="$(pwd)/fake.sendmail" \
1073 email-using-8bit >stdout &&
1074 grep "do not declare a Content-Transfer-Encoding" stdout &&
1075 grep email-using-8bit stdout &&
1076 grep "Which 8bit encoding" stdout &&
1077 egrep "Content|MIME" msgtxt1 >actual &&
1078 test_cmp actual content-type-decl
1081 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1082 clean_fake_sendmail &&
1083 git config sendemail.assume8bitEncoding UTF-8 &&
1085 git send-email --from=author@example.com --to=nobody@example.com \
1086 --smtp-server="$(pwd)/fake.sendmail" \
1087 email-using-8bit >stdout &&
1088 egrep "Content|MIME" msgtxt1 >actual &&
1089 test_cmp actual content-type-decl
1092 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1093 clean_fake_sendmail &&
1094 git config sendemail.assume8bitEncoding "bogus too" &&
1096 git send-email --from=author@example.com --to=nobody@example.com \
1097 --smtp-server="$(pwd)/fake.sendmail" \
1098 --8bit-encoding=UTF-8 \
1099 email-using-8bit >stdout &&
1100 egrep "Content|MIME" msgtxt1 >actual &&
1101 test_cmp actual content-type-decl
1104 test_expect_success
$PREREQ 'setup expect' '
1105 cat >email-using-8bit <<EOF
1106 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1107 Message-Id: <bogus-message-id@example.com>
1108 From: author@example.com
1109 Date: Sat, 12 Jun 2010 15:53:58 +0200
1110 Subject: Dieser Betreff enthält auch einen Umlaut!
1112 Nothing to see here.
1116 test_expect_success
$PREREQ 'setup expect' '
1118 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1122 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1123 clean_fake_sendmail &&
1125 git send-email --from=author@example.com --to=nobody@example.com \
1126 --smtp-server="$(pwd)/fake.sendmail" \
1127 --8bit-encoding=UTF-8 \
1128 email-using-8bit >stdout &&
1129 grep "Subject" msgtxt1 >actual &&
1130 test_cmp expected actual
1133 # Note that the patches in this test are deliberately out of order; we
1134 # want to make sure it works even if the cover-letter is not in the
1136 test_expect_success
'refusing to send cover letter template' '
1137 clean_fake_sendmail &&
1139 git format-patch --cover-letter -2 -o outdir &&
1140 test_must_fail git send-email \
1141 --from="Example <nobody@example.com>" \
1142 --to=nobody@example.com \
1143 --smtp-server="$(pwd)/fake.sendmail" \
1144 outdir/0002-*.patch \
1145 outdir/0000-*.patch \
1146 outdir/0001-*.patch \
1148 grep "SUBJECT HERE" errors &&
1149 test -z "$(ls msgtxt*)"
1152 test_expect_success
'--force sends cover letter template anyway' '
1153 clean_fake_sendmail &&
1155 git format-patch --cover-letter -2 -o outdir &&
1158 --from="Example <nobody@example.com>" \
1159 --to=nobody@example.com \
1160 --smtp-server="$(pwd)/fake.sendmail" \
1161 outdir/0002-*.patch \
1162 outdir/0000-*.patch \
1163 outdir/0001-*.patch \
1165 ! grep "SUBJECT HERE" errors &&
1166 test -n "$(ls msgtxt*)"