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_text 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_text 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_text 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_text expected-show-all-headers actual-show-all-headers
191 test_expect_success
$PREREQ 'Prompting works' '
192 clean_fake_sendmail &&
193 (echo "to@example.com"
195 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
196 --smtp-server="$(pwd)/fake.sendmail" \
199 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
200 grep "^To: to@example.com\$" msgtxt1
203 test_expect_success
$PREREQ,AUTOIDENT
'implicit ident is allowed' '
204 clean_fake_sendmail &&
205 (sane_unset GIT_AUTHOR_NAME &&
206 sane_unset GIT_AUTHOR_EMAIL &&
207 sane_unset GIT_COMMITTER_NAME &&
208 sane_unset GIT_COMMITTER_EMAIL &&
209 GIT_SEND_EMAIL_NOTTY=1 git send-email \
210 --smtp-server="$(pwd)/fake.sendmail" \
211 --to=to@example.com \
212 $patches </dev/null 2>errors
216 test_expect_success
$PREREQ,!AUTOIDENT
'broken implicit ident aborts send-email' '
217 clean_fake_sendmail &&
218 (sane_unset GIT_AUTHOR_NAME &&
219 sane_unset GIT_AUTHOR_EMAIL &&
220 sane_unset GIT_COMMITTER_NAME &&
221 sane_unset GIT_COMMITTER_EMAIL &&
222 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
223 test_must_fail git send-email \
224 --smtp-server="$(pwd)/fake.sendmail" \
225 --to=to@example.com \
226 $patches </dev/null 2>errors &&
227 test_i18ngrep "tell me who you are" errors
231 test_expect_success
$PREREQ 'tocmd works' '
232 clean_fake_sendmail &&
233 cp $patches tocmd.patch &&
234 echo tocmd--tocmd@example.com >>tocmd.patch &&
237 echo sed -n -e s/^tocmd--//p \"\$1\"
239 chmod +x tocmd-sed &&
241 --from="Example <nobody@example.com>" \
242 --to-cmd=./tocmd-sed \
243 --smtp-server="$(pwd)/fake.sendmail" \
246 grep "^To: tocmd@example.com" msgtxt1
249 test_expect_success
$PREREQ 'cccmd works' '
250 clean_fake_sendmail &&
251 cp $patches cccmd.patch &&
252 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
255 echo sed -n -e s/^cccmd--//p \"\$1\"
257 chmod +x cccmd-sed &&
259 --from="Example <nobody@example.com>" \
260 --to=nobody@example.com \
261 --cc-cmd=./cccmd-sed \
262 --smtp-server="$(pwd)/fake.sendmail" \
265 grep "^ cccmd@example.com" msgtxt1
268 test_expect_success
$PREREQ 'reject long lines' '
270 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
271 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
272 clean_fake_sendmail &&
273 cp $patches longline.patch &&
274 echo $z512$z512 >>longline.patch &&
275 test_must_fail git send-email \
276 --from="Example <nobody@example.com>" \
277 --to=nobody@example.com \
278 --smtp-server="$(pwd)/fake.sendmail" \
279 $patches longline.patch \
281 grep longline.patch errors
284 test_expect_success
$PREREQ 'no patch was sent' '
285 ! test -e commandline1
288 test_expect_success
$PREREQ 'Author From: in message body' '
289 clean_fake_sendmail &&
291 --from="Example <nobody@example.com>" \
292 --to=nobody@example.com \
293 --smtp-server="$(pwd)/fake.sendmail" \
295 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
296 grep "From: A <author@example.com>" msgbody1
299 test_expect_success
$PREREQ 'Author From: not in message body' '
300 clean_fake_sendmail &&
302 --from="A <author@example.com>" \
303 --to=nobody@example.com \
304 --smtp-server="$(pwd)/fake.sendmail" \
306 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
307 ! grep "From: A <author@example.com>" msgbody1
310 test_expect_success
$PREREQ 'allow long lines with --no-validate' '
312 --from="Example <nobody@example.com>" \
313 --to=nobody@example.com \
314 --smtp-server="$(pwd)/fake.sendmail" \
316 $patches longline.patch \
320 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
321 clean_fake_sendmail &&
323 --from="Example <nobody@example.com>" \
324 --to=nobody@example.com \
326 --smtp-server="$(pwd)/fake.sendmail" \
329 ! grep "^In-Reply-To: < *>" msgtxt1
332 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
333 clean_fake_sendmail &&
334 (echo "From Example <from@example.com>"
335 echo "To Example <to@example.com>"
337 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
338 --smtp-server="$(pwd)/fake.sendmail" \
340 ! grep "^In-Reply-To: < *>" msgtxt1
343 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
344 clean_fake_sendmail &&
345 echo "<unique-message-id@example.com>" >expect &&
347 --from="Example <nobody@example.com>" \
348 --to=nobody@example.com \
350 --in-reply-to="$(cat expect)" \
351 --smtp-server="$(pwd)/fake.sendmail" \
352 $patches $patches $patches \
354 # The first message is a reply to --in-reply-to
355 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
356 test_cmp_text expect actual &&
357 # Second and subsequent messages are replies to the first one
358 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
359 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
360 test_cmp_text expect actual &&
361 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
362 test_cmp_text expect actual
365 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
366 clean_fake_sendmail &&
367 echo "<unique-message-id@example.com>" >expect &&
369 --from="Example <nobody@example.com>" \
370 --to=nobody@example.com \
372 --in-reply-to="$(cat expect)" \
373 --smtp-server="$(pwd)/fake.sendmail" \
374 $patches $patches $patches \
376 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
377 test_cmp_text expect actual &&
378 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
379 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
380 test_cmp_text expect actual &&
381 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
382 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
383 test_cmp_text expect actual
386 test_expect_success
$PREREQ 'setup fake editor' '
387 (echo "#!$SHELL_PATH" &&
388 echo "echo fake edit >>\"\$1\""
393 test_set_editor
"$(pwd)/fake-editor"
395 test_expect_success
$PREREQ '--compose works' '
396 clean_fake_sendmail &&
398 --compose --subject foo \
399 --from="Example <nobody@example.com>" \
400 --to=nobody@example.com \
401 --smtp-server="$(pwd)/fake.sendmail" \
406 test_expect_success
$PREREQ 'first message is compose text' '
407 grep "^fake edit" msgtxt1
410 test_expect_success
$PREREQ 'second message is patch' '
411 grep "Subject:.*Second" msgtxt2
414 test_expect_success
$PREREQ 'setup expect' "
415 cat >expected-suppress-sob <<\EOF
417 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
418 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
419 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
421 Server: relay.example.com
422 MAIL FROM:<from@example.com>
423 RCPT TO:<to@example.com>
424 RCPT TO:<cc@example.com>
425 RCPT TO:<author@example.com>
426 RCPT TO:<one@example.com>
427 RCPT TO:<two@example.com>
428 From: Example <from@example.com>
431 A <author@example.com>,
432 One <one@example.com>,
434 Subject: [PATCH 1/1] Second.
436 Message-Id: MESSAGE-ID-STRING
437 X-Mailer: X-MAILER-STRING
443 test_suppression
() {
446 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
447 --from="Example <from@example.com>" \
448 --to=to@example.com \
449 --smtp-server relay.example.com \
451 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
452 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
453 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
454 >actual-suppress-
$1${2+"-$2"} &&
455 test_cmp_text expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
458 test_expect_success
$PREREQ 'sendemail.cc set' '
459 git config sendemail.cc cc@example.com &&
463 test_expect_success
$PREREQ 'setup expect' "
464 cat >expected-suppress-sob <<\EOF
466 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
467 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
468 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
470 Server: relay.example.com
471 MAIL FROM:<from@example.com>
472 RCPT TO:<to@example.com>
473 RCPT TO:<author@example.com>
474 RCPT TO:<one@example.com>
475 RCPT TO:<two@example.com>
476 From: Example <from@example.com>
478 Cc: A <author@example.com>,
479 One <one@example.com>,
481 Subject: [PATCH 1/1] Second.
483 Message-Id: MESSAGE-ID-STRING
484 X-Mailer: X-MAILER-STRING
490 test_expect_success
$PREREQ 'sendemail.cc unset' '
491 git config --unset sendemail.cc &&
495 test_expect_success
$PREREQ 'setup expect' "
496 cat >expected-suppress-cccmd <<\EOF
498 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
499 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
500 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
501 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
503 Server: relay.example.com
504 MAIL FROM:<from@example.com>
505 RCPT TO:<to@example.com>
506 RCPT TO:<author@example.com>
507 RCPT TO:<one@example.com>
508 RCPT TO:<two@example.com>
509 RCPT TO:<committer@example.com>
510 From: Example <from@example.com>
512 Cc: A <author@example.com>,
513 One <one@example.com>,
515 C O Mitter <committer@example.com>
516 Subject: [PATCH 1/1] Second.
518 Message-Id: MESSAGE-ID-STRING
519 X-Mailer: X-MAILER-STRING
525 test_expect_success
$PREREQ 'sendemail.cccmd' '
526 echo echo cc-cmd@example.com > cccmd &&
528 git config sendemail.cccmd ./cccmd &&
529 test_suppression cccmd
532 test_expect_success
$PREREQ 'setup expect' '
533 cat >expected-suppress-all <<\EOF
536 Server: relay.example.com
537 MAIL FROM:<from@example.com>
538 RCPT TO:<to@example.com>
539 From: Example <from@example.com>
541 Subject: [PATCH 1/1] Second.
543 Message-Id: MESSAGE-ID-STRING
544 X-Mailer: X-MAILER-STRING
550 test_expect_success
$PREREQ '--suppress-cc=all' '
554 test_expect_success
$PREREQ 'setup expect' "
555 cat >expected-suppress-body <<\EOF
557 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
558 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
559 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
560 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
562 Server: relay.example.com
563 MAIL FROM:<from@example.com>
564 RCPT TO:<to@example.com>
565 RCPT TO:<author@example.com>
566 RCPT TO:<one@example.com>
567 RCPT TO:<two@example.com>
568 RCPT TO:<cc-cmd@example.com>
569 From: Example <from@example.com>
571 Cc: A <author@example.com>,
572 One <one@example.com>,
575 Subject: [PATCH 1/1] Second.
577 Message-Id: MESSAGE-ID-STRING
578 X-Mailer: X-MAILER-STRING
584 test_expect_success
$PREREQ '--suppress-cc=body' '
585 test_suppression body
588 test_expect_success
$PREREQ 'setup expect' "
589 cat >expected-suppress-body-cccmd <<\EOF
591 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
592 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
593 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
595 Server: relay.example.com
596 MAIL FROM:<from@example.com>
597 RCPT TO:<to@example.com>
598 RCPT TO:<author@example.com>
599 RCPT TO:<one@example.com>
600 RCPT TO:<two@example.com>
601 From: Example <from@example.com>
603 Cc: A <author@example.com>,
604 One <one@example.com>,
606 Subject: [PATCH 1/1] Second.
608 Message-Id: MESSAGE-ID-STRING
609 X-Mailer: X-MAILER-STRING
615 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
616 test_suppression body cccmd
619 test_expect_success
$PREREQ 'setup expect' "
620 cat >expected-suppress-sob <<\EOF
622 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
623 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
624 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
626 Server: relay.example.com
627 MAIL FROM:<from@example.com>
628 RCPT TO:<to@example.com>
629 RCPT TO:<author@example.com>
630 RCPT TO:<one@example.com>
631 RCPT TO:<two@example.com>
632 From: Example <from@example.com>
634 Cc: A <author@example.com>,
635 One <one@example.com>,
637 Subject: [PATCH 1/1] Second.
639 Message-Id: MESSAGE-ID-STRING
640 X-Mailer: X-MAILER-STRING
646 test_expect_success
$PREREQ '--suppress-cc=sob' '
647 test_might_fail git config --unset sendemail.cccmd &&
651 test_expect_success
$PREREQ 'setup expect' "
652 cat >expected-suppress-bodycc <<\EOF
654 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
655 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
656 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
657 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
659 Server: relay.example.com
660 MAIL FROM:<from@example.com>
661 RCPT TO:<to@example.com>
662 RCPT TO:<author@example.com>
663 RCPT TO:<one@example.com>
664 RCPT TO:<two@example.com>
665 RCPT TO:<committer@example.com>
666 From: Example <from@example.com>
668 Cc: A <author@example.com>,
669 One <one@example.com>,
671 C O Mitter <committer@example.com>
672 Subject: [PATCH 1/1] Second.
674 Message-Id: MESSAGE-ID-STRING
675 X-Mailer: X-MAILER-STRING
681 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
682 test_suppression bodycc
685 test_expect_success
$PREREQ 'setup expect' "
686 cat >expected-suppress-cc <<\EOF
688 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
689 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
691 Server: relay.example.com
692 MAIL FROM:<from@example.com>
693 RCPT TO:<to@example.com>
694 RCPT TO:<author@example.com>
695 RCPT TO:<committer@example.com>
696 From: Example <from@example.com>
698 Cc: A <author@example.com>,
699 C O Mitter <committer@example.com>
700 Subject: [PATCH 1/1] Second.
702 Message-Id: MESSAGE-ID-STRING
703 X-Mailer: X-MAILER-STRING
709 test_expect_success
$PREREQ '--suppress-cc=cc' '
715 GIT_SEND_EMAIL_NOTTY
=1 \
717 --from="Example <nobody@example.com>" \
718 --to=nobody@example.com \
719 --smtp-server="$(pwd)/fake.sendmail" \
720 $@
$patches > stdout
&&
721 grep "Send this email" stdout
724 test_expect_success
$PREREQ '--confirm=always' '
725 test_confirm --confirm=always --suppress-cc=all
728 test_expect_success
$PREREQ '--confirm=auto' '
729 test_confirm --confirm=auto
732 test_expect_success
$PREREQ '--confirm=cc' '
733 test_confirm --confirm=cc
736 test_expect_success
$PREREQ '--confirm=compose' '
737 test_confirm --confirm=compose --compose
740 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
741 CONFIRM=$(git config --get sendemail.confirm) &&
742 git config --unset sendemail.confirm &&
745 git config sendemail.confirm ${CONFIRM:-never}
749 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
750 CONFIRM=$(git config --get sendemail.confirm) &&
751 git config --unset sendemail.confirm &&
752 test_confirm --suppress-cc=all --compose
754 git config sendemail.confirm ${CONFIRM:-never}
758 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
759 CONFIRM=$(git config --get sendemail.confirm) &&
760 git config --unset sendemail.confirm &&
762 git format-patch -2 -o outdir &&
763 GIT_SEND_EMAIL_NOTTY=1 \
765 --from="Example <nobody@example.com>" \
766 --to=nobody@example.com \
767 --smtp-server="$(pwd)/fake.sendmail" \
768 outdir/*.patch < /dev/null
770 git config sendemail.confirm ${CONFIRM:-never}
774 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
775 CONFIRM=$(git config --get sendemail.confirm) &&
776 git config sendemail.confirm auto &&
777 GIT_SEND_EMAIL_NOTTY=1 &&
778 export GIT_SEND_EMAIL_NOTTY &&
779 test_must_fail git send-email \
780 --from="Example <nobody@example.com>" \
781 --to=nobody@example.com \
782 --smtp-server="$(pwd)/fake.sendmail" \
785 git config sendemail.confirm ${CONFIRM:-never}
789 test_expect_success
$PREREQ 'confirm doesnt loop forever' '
790 CONFIRM=$(git config --get sendemail.confirm) &&
791 git config sendemail.confirm auto &&
792 GIT_SEND_EMAIL_NOTTY=1 &&
793 export GIT_SEND_EMAIL_NOTTY &&
794 yes "bogus" | test_must_fail git send-email \
795 --from="Example <nobody@example.com>" \
796 --to=nobody@example.com \
797 --smtp-server="$(pwd)/fake.sendmail" \
800 git config sendemail.confirm ${CONFIRM:-never}
804 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
805 clean_fake_sendmail &&
807 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
809 --from="Example <nobody@example.com>" \
810 --to=nobody@example.com \
811 --smtp-server="$(pwd)/fake.sendmail" \
814 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
817 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
818 clean_fake_sendmail &&
819 (echo "#!$SHELL_PATH" &&
820 echo "echo utf8 body: àéìöú >>\"\$1\""
821 ) >fake-editor-utf8 &&
822 chmod +x fake-editor-utf8 &&
823 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
825 --compose --subject foo \
826 --from="Example <nobody@example.com>" \
827 --to=nobody@example.com \
828 --smtp-server="$(pwd)/fake.sendmail" \
830 grep "^utf8 body" msgtxt1 &&
831 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
834 test_expect_success
$PREREQ '--compose respects user mime type' '
835 clean_fake_sendmail &&
836 (echo "#!$SHELL_PATH" &&
837 echo "(echo MIME-Version: 1.0"
838 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
839 echo " echo Content-Transfer-Encoding: 8bit"
840 echo " echo Subject: foo"
842 echo " echo utf8 body: àéìöú) >\"\$1\""
843 ) >fake-editor-utf8-mime &&
844 chmod +x fake-editor-utf8-mime &&
845 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
847 --compose --subject foo \
848 --from="Example <nobody@example.com>" \
849 --to=nobody@example.com \
850 --smtp-server="$(pwd)/fake.sendmail" \
852 grep "^utf8 body" msgtxt1 &&
853 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
854 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
857 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
858 clean_fake_sendmail &&
859 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
861 --compose --subject utf8-sübjëct \
862 --from="Example <nobody@example.com>" \
863 --to=nobody@example.com \
864 --smtp-server="$(pwd)/fake.sendmail" \
866 grep "^fake edit" msgtxt1 &&
867 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
870 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
871 clean_fake_sendmail &&
872 test_commit weird_author &&
873 test_when_finished "git reset --hard HEAD^" &&
874 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
875 git format-patch --stdout -1 >funny_name.patch &&
876 git send-email --from="Example <nobody@example.com>" \
877 --to=nobody@example.com \
878 --smtp-server="$(pwd)/fake.sendmail" \
880 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
883 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
884 clean_fake_sendmail &&
885 git config sendemail.composeencoding iso-8859-1 &&
886 (echo "#!$SHELL_PATH" &&
887 echo "echo utf8 body: àéìöú >>\"\$1\""
888 ) >fake-editor-utf8 &&
889 chmod +x fake-editor-utf8 &&
890 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
892 --compose --subject foo \
893 --from="Example <nobody@example.com>" \
894 --to=nobody@example.com \
895 --smtp-server="$(pwd)/fake.sendmail" \
897 grep "^utf8 body" msgtxt1 &&
898 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
901 test_expect_success
$PREREQ '--compose-encoding works' '
902 clean_fake_sendmail &&
903 (echo "#!$SHELL_PATH" &&
904 echo "echo utf8 body: àéìöú >>\"\$1\""
905 ) >fake-editor-utf8 &&
906 chmod +x fake-editor-utf8 &&
907 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
909 --compose-encoding iso-8859-1 \
910 --compose --subject foo \
911 --from="Example <nobody@example.com>" \
912 --to=nobody@example.com \
913 --smtp-server="$(pwd)/fake.sendmail" \
915 grep "^utf8 body" msgtxt1 &&
916 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
919 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
920 clean_fake_sendmail &&
921 git config sendemail.composeencoding iso-8859-1 &&
922 (echo "#!$SHELL_PATH" &&
923 echo "echo utf8 body: àéìöú >>\"\$1\""
924 ) >fake-editor-utf8 &&
925 chmod +x fake-editor-utf8 &&
926 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
928 --compose-encoding iso-8859-2 \
929 --compose --subject foo \
930 --from="Example <nobody@example.com>" \
931 --to=nobody@example.com \
932 --smtp-server="$(pwd)/fake.sendmail" \
934 grep "^utf8 body" msgtxt1 &&
935 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
938 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
939 clean_fake_sendmail &&
940 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
942 --compose-encoding iso-8859-2 \
943 --compose --subject utf8-sübjëct \
944 --from="Example <nobody@example.com>" \
945 --to=nobody@example.com \
946 --smtp-server="$(pwd)/fake.sendmail" \
948 grep "^fake edit" msgtxt1 &&
949 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
952 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
953 echo master > master &&
955 git commit -m"add master" &&
956 test_must_fail git send-email --dry-run master 2>errors &&
957 grep disambiguate errors
960 test_expect_success
$PREREQ 'feed two files' '
962 git format-patch -2 -o outdir &&
965 --from="Example <nobody@example.com>" \
966 --to=nobody@example.com \
967 outdir/000?-*.patch 2>errors >out &&
968 grep "^Subject: " out >subjects &&
969 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
970 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
973 test_expect_success
$PREREQ 'in-reply-to but no threading' '
976 --from="Example <nobody@example.com>" \
977 --to=nobody@example.com \
978 --in-reply-to="<in-reply-id@example.com>" \
981 grep "In-Reply-To: <in-reply-id@example.com>"
984 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
987 --from="Example <nobody@example.com>" \
988 --to=nobody@example.com \
990 $patches $patches >stdout &&
991 ! grep "In-Reply-To: " stdout
994 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
997 --from="Example <nobody@example.com>" \
998 --to=nobody@example.com \
1000 --nochain-reply-to \
1001 $patches $patches >stdout &&
1002 grep "In-Reply-To: " stdout
1005 test_expect_success
$PREREQ 'warning with an implicit --chain-reply-to' '
1008 --from="Example <nobody@example.com>" \
1009 --to=nobody@example.com \
1010 outdir/000?-*.patch 2>errors >out &&
1011 grep "no-chain-reply-to" errors
1014 test_expect_success
$PREREQ 'no warning with an explicit --chain-reply-to' '
1017 --from="Example <nobody@example.com>" \
1018 --to=nobody@example.com \
1020 outdir/000?-*.patch 2>errors >out &&
1021 ! grep "no-chain-reply-to" errors
1024 test_expect_success
$PREREQ 'no warning with an explicit --no-chain-reply-to' '
1027 --from="Example <nobody@example.com>" \
1028 --to=nobody@example.com \
1029 --nochain-reply-to \
1030 outdir/000?-*.patch 2>errors >out &&
1031 ! grep "no-chain-reply-to" errors
1034 test_expect_success
$PREREQ 'no warning with sendemail.chainreplyto = false' '
1035 git config sendemail.chainreplyto false &&
1038 --from="Example <nobody@example.com>" \
1039 --to=nobody@example.com \
1040 outdir/000?-*.patch 2>errors >out &&
1041 ! grep "no-chain-reply-to" errors
1044 test_expect_success
$PREREQ 'no warning with sendemail.chainreplyto = true' '
1045 git config sendemail.chainreplyto true &&
1048 --from="Example <nobody@example.com>" \
1049 --to=nobody@example.com \
1050 outdir/000?-*.patch 2>errors >out &&
1051 ! grep "no-chain-reply-to" errors
1054 test_expect_success
$PREREQ 'sendemail.to works' '
1055 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1058 --from="Example <nobody@example.com>" \
1059 $patches $patches >stdout &&
1060 grep "To: Somebody <somebody@ex.com>" stdout
1063 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1066 --from="Example <nobody@example.com>" \
1068 --to=nobody@example.com \
1069 $patches $patches >stdout &&
1070 grep "To: nobody@example.com" stdout &&
1071 ! grep "To: Somebody <somebody@ex.com>" stdout
1074 test_expect_success
$PREREQ 'sendemail.cc works' '
1075 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1078 --from="Example <nobody@example.com>" \
1079 --to=nobody@example.com \
1080 $patches $patches >stdout &&
1081 grep "Cc: Somebody <somebody@ex.com>" stdout
1084 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1087 --from="Example <nobody@example.com>" \
1089 --cc=bodies@example.com \
1090 --to=nobody@example.com \
1091 $patches $patches >stdout &&
1092 grep "Cc: bodies@example.com" stdout &&
1093 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1096 test_expect_success
$PREREQ 'sendemail.bcc works' '
1097 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1100 --from="Example <nobody@example.com>" \
1101 --to=nobody@example.com \
1102 --smtp-server relay.example.com \
1103 $patches $patches >stdout &&
1104 grep "RCPT TO:<other@ex.com>" stdout
1107 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1110 --from="Example <nobody@example.com>" \
1112 --bcc=bodies@example.com \
1113 --to=nobody@example.com \
1114 --smtp-server relay.example.com \
1115 $patches $patches >stdout &&
1116 grep "RCPT TO:<bodies@example.com>" stdout &&
1117 ! grep "RCPT TO:<other@ex.com>" stdout
1120 test_expect_success
$PREREQ 'patches To headers are used by default' '
1121 patch=`git format-patch -1 --to="bodies@example.com"` &&
1122 test_when_finished "rm $patch" &&
1125 --from="Example <nobody@example.com>" \
1126 --smtp-server relay.example.com \
1128 grep "RCPT TO:<bodies@example.com>" stdout
1131 test_expect_success
$PREREQ 'patches To headers are appended to' '
1132 patch=`git format-patch -1 --to="bodies@example.com"` &&
1133 test_when_finished "rm $patch" &&
1136 --from="Example <nobody@example.com>" \
1137 --to=nobody@example.com \
1138 --smtp-server relay.example.com \
1140 grep "RCPT TO:<bodies@example.com>" stdout &&
1141 grep "RCPT TO:<nobody@example.com>" stdout
1144 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1145 patch1=`git format-patch -1 --to="bodies@example.com"` &&
1146 patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1147 test_when_finished "rm $patch1 && rm $patch2" &&
1150 --from="Example <nobody@example.com>" \
1151 --to="nobody@example.com" \
1152 --smtp-server relay.example.com \
1153 $patch1 $patch2 >stdout &&
1154 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1155 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1156 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1159 test_expect_success
$PREREQ 'setup expect' '
1160 cat >email-using-8bit <<EOF
1161 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1162 Message-Id: <bogus-message-id@example.com>
1163 From: author@example.com
1164 Date: Sat, 12 Jun 2010 15:53:58 +0200
1165 Subject: subject goes here
1167 Dieser deutsche Text enthält einen Umlaut!
1171 test_expect_success
$PREREQ 'setup expect' '
1173 Subject: subject goes here
1177 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1178 clean_fake_sendmail &&
1180 git send-email --from=author@example.com --to=nobody@example.com \
1181 --smtp-server="$(pwd)/fake.sendmail" \
1182 --8bit-encoding=UTF-8 \
1183 email-using-8bit >stdout &&
1184 grep "Subject" msgtxt1 >actual &&
1185 test_cmp expected actual
1188 test_expect_success
$PREREQ 'setup expect' '
1189 cat >content-type-decl <<EOF
1191 Content-Type: text/plain; charset=UTF-8
1192 Content-Transfer-Encoding: 8bit
1196 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1197 clean_fake_sendmail &&
1199 git send-email --from=author@example.com --to=nobody@example.com \
1200 --smtp-server="$(pwd)/fake.sendmail" \
1201 email-using-8bit >stdout &&
1202 grep "do not declare a Content-Transfer-Encoding" stdout &&
1203 grep email-using-8bit stdout &&
1204 grep "Which 8bit encoding" stdout &&
1205 egrep "Content|MIME" msgtxt1 >actual &&
1206 test_cmp_text actual content-type-decl
1209 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1210 clean_fake_sendmail &&
1211 git config sendemail.assume8bitEncoding UTF-8 &&
1213 git send-email --from=author@example.com --to=nobody@example.com \
1214 --smtp-server="$(pwd)/fake.sendmail" \
1215 email-using-8bit >stdout &&
1216 egrep "Content|MIME" msgtxt1 >actual &&
1217 test_cmp_text actual content-type-decl
1220 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1221 clean_fake_sendmail &&
1222 git config sendemail.assume8bitEncoding "bogus too" &&
1224 git send-email --from=author@example.com --to=nobody@example.com \
1225 --smtp-server="$(pwd)/fake.sendmail" \
1226 --8bit-encoding=UTF-8 \
1227 email-using-8bit >stdout &&
1228 egrep "Content|MIME" msgtxt1 >actual &&
1229 test_cmp_text actual content-type-decl
1232 test_expect_success
$PREREQ 'setup expect' '
1233 cat >email-using-8bit <<EOF
1234 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1235 Message-Id: <bogus-message-id@example.com>
1236 From: author@example.com
1237 Date: Sat, 12 Jun 2010 15:53:58 +0200
1238 Subject: Dieser Betreff enthält auch einen Umlaut!
1240 Nothing to see here.
1244 test_expect_success
$PREREQ 'setup expect' '
1246 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1250 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1251 clean_fake_sendmail &&
1253 git send-email --from=author@example.com --to=nobody@example.com \
1254 --smtp-server="$(pwd)/fake.sendmail" \
1255 --8bit-encoding=UTF-8 \
1256 email-using-8bit >stdout &&
1257 grep "Subject" msgtxt1 >actual &&
1258 test_cmp_text expected actual
1261 # Note that the patches in this test are deliberately out of order; we
1262 # want to make sure it works even if the cover-letter is not in the
1264 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1265 clean_fake_sendmail &&
1267 git format-patch --cover-letter -2 -o outdir &&
1268 test_must_fail git send-email \
1269 --from="Example <nobody@example.com>" \
1270 --to=nobody@example.com \
1271 --smtp-server="$(pwd)/fake.sendmail" \
1272 outdir/0002-*.patch \
1273 outdir/0000-*.patch \
1274 outdir/0001-*.patch \
1276 grep "SUBJECT HERE" errors &&
1277 test -z "$(ls msgtxt*)"
1280 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1281 clean_fake_sendmail &&
1283 git format-patch --cover-letter -2 -o outdir &&
1286 --from="Example <nobody@example.com>" \
1287 --to=nobody@example.com \
1288 --smtp-server="$(pwd)/fake.sendmail" \
1289 outdir/0002-*.patch \
1290 outdir/0000-*.patch \
1291 outdir/0001-*.patch \
1293 ! grep "SUBJECT HERE" errors &&
1294 test -n "$(ls msgtxt*)"
1297 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
1298 clean_fake_sendmail &&
1299 echo "alias sbd somebody@example.org" >.mailrc &&
1300 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1301 git config sendemail.aliasfiletype mailrc &&
1303 --from="Example <nobody@example.com>" \
1305 --smtp-server="$(pwd)/fake.sendmail" \
1306 outdir/0001-*.patch \
1308 grep "^!somebody@example\.org!$" commandline1
1311 test_expect_success
$PREREQ 'sendemail.aliasfile=~/.mailrc' '
1312 clean_fake_sendmail &&
1313 echo "alias sbd someone@example.org" >~/.mailrc &&
1314 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1315 git config sendemail.aliasfiletype mailrc &&
1317 --from="Example <nobody@example.com>" \
1319 --smtp-server="$(pwd)/fake.sendmail" \
1320 outdir/0001-*.patch \
1322 grep "^!someone@example\.org!$" commandline1