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 test_have_prereq MINGW && echo "dos2unix commandline\$output"
27 echo "cat > msgtxt\$output"
29 chmod +x ./fake.sendmail &&
30 git add fake.sendmail &&
31 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
33 clean_fake_sendmail() {
34 rm -f commandline* msgtxt*
37 test_expect_success $PREREQ 'Extract patches' '
38 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
41 # Test no confirm early to ensure remaining tests will not hang
45 GIT_SEND_EMAIL_NOTTY=1 \
47 --from="Example <from@example.com>" \
48 --to=nobody@example.com \
49 --smtp-server="$(pwd)/fake.sendmail" \
52 test_must_fail grep "Send this email" stdout &&
56 # Exit immediately to prevent hang if a no-confirm test fails
58 if ! test -f no_confirm_okay
60 say 'confirm test failed; skipping remaining tests to prevent hanging'
61 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
66 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
67 test_no_confirm --suppress-cc=sob &&
72 test_expect_success $PREREQ 'No confirm with --confirm=never' '
73 test_no_confirm --confirm=never &&
77 # leave sendemail.confirm set to never after this so that none of the
78 # remaining tests prompt unintentionally.
79 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
80 git config sendemail.confirm never &&
81 test_no_confirm --compose --subject=foo &&
85 test_expect_success $PREREQ 'Send patches' '
86 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
89 test_expect_success $PREREQ 'setup expect' '
98 test_expect_success $PREREQ \
99 'Verify commandline' \
100 'test_cmp expected commandline1'
102 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
103 clean_fake_sendmail &&
104 git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
107 test_expect_success $PREREQ 'setup expect' '
118 test_expect_success $PREREQ \
119 'Verify commandline' \
120 'test_cmp expected commandline1'
122 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
123 clean_fake_sendmail &&
124 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
127 test_expect_success $PREREQ 'setup expect' '
138 test_expect_success $PREREQ \
139 'Verify commandline' \
140 'test_cmp expected commandline1'
142 test_expect_success $PREREQ 'setup expect' "
143 cat >expected-show-all-headers <<\EOF
145 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
146 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
147 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
149 Server: relay.example.com
150 MAIL FROM:<from@example.com>
151 RCPT TO:<to@example.com>
152 RCPT TO:<cc@example.com>
153 RCPT TO:<author@example.com>
154 RCPT TO:<one@example.com>
155 RCPT TO:<two@example.com>
156 RCPT TO:<bcc@example.com>
157 From: Example <from@example.com>
160 A <author@example.com>,
161 One <one@example.com>,
163 Subject: [PATCH 1/1] Second.
165 Message-Id: MESSAGE-ID-STRING
166 X-Mailer: X-MAILER-STRING
167 In-Reply-To: <unique-message-id@example.com>
168 References: <unique-message-id@example.com>
174 test_suppress_self () {
176 test_when_finished "git reset --hard HEAD^" &&
178 write_script cccmd-sed <<-EOF &&
179 sed -n -e s/^cccmd--//p "\$1"
182 git commit --amend --author="$1 <$2>" -F - &&
183 clean_fake_sendmail &&
184 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
186 git send-email --from="$1 <$2>" \
187 --to=nobody@example.com \
188 --cc-cmd=./cccmd-sed \
190 --smtp-server="$(pwd)/fake.sendmail" \
191 suppress-self-$3.patch &&
193 mv msgtxt1 msgtxt1-$3 &&
194 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
195 >"expected-no-cc-$3" &&
197 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
198 test_cmp expected-no-cc-$3 actual-no-cc-$3)
201 test_suppress_self_unquoted () {
202 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
203 test suppress-cc.self unquoted-$3 with name $1 email $2
210 Signed-off-by: $1 <$2>
214 test_expect_success $PREREQ 'self name is suppressed' "
215 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
216 'self_name_suppressed'
219 test_expect_success $PREREQ 'Show all headers' '
223 --from="Example <from@example.com>" \
224 --to=to@example.com \
225 --cc=cc@example.com \
226 --bcc=bcc@example.com \
227 --in-reply-to="<unique-message-id@example.com>" \
228 --smtp-server relay.example.com \
230 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
231 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
232 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
233 >actual-show-all-headers &&
234 test_cmp expected-show-all-headers actual-show-all-headers
237 test_expect_success $PREREQ 'Prompting works' '
238 clean_fake_sendmail &&
239 (echo "to@example.com"
241 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
242 --smtp-server="$(pwd)/fake.sendmail" \
245 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
246 grep "^To: to@example.com\$" msgtxt1
249 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
250 clean_fake_sendmail &&
251 (sane_unset GIT_AUTHOR_NAME &&
252 sane_unset GIT_AUTHOR_EMAIL &&
253 sane_unset GIT_COMMITTER_NAME &&
254 sane_unset GIT_COMMITTER_EMAIL &&
255 GIT_SEND_EMAIL_NOTTY=1 git send-email \
256 --smtp-server="$(pwd)/fake.sendmail" \
257 --to=to@example.com \
258 $patches </dev/null 2>errors
262 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
263 clean_fake_sendmail &&
264 (sane_unset GIT_AUTHOR_NAME &&
265 sane_unset GIT_AUTHOR_EMAIL &&
266 sane_unset GIT_COMMITTER_NAME &&
267 sane_unset GIT_COMMITTER_EMAIL &&
268 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
269 test_must_fail git send-email \
270 --smtp-server="$(pwd)/fake.sendmail" \
271 --to=to@example.com \
272 $patches </dev/null 2>errors &&
273 test_i18ngrep "tell me who you are" errors
277 test_expect_success $PREREQ 'tocmd works' '
278 clean_fake_sendmail &&
279 cp $patches tocmd.patch &&
280 echo tocmd--tocmd@example.com >>tocmd.patch &&
283 echo sed -n -e s/^tocmd--//p \"\$1\"
285 chmod +x tocmd-sed &&
287 --from="Example <nobody@example.com>" \
288 --to-cmd=./tocmd-sed \
289 --smtp-server="$(pwd)/fake.sendmail" \
292 grep "^To: tocmd@example.com" msgtxt1
295 test_expect_success $PREREQ 'cccmd works' '
296 clean_fake_sendmail &&
297 cp $patches cccmd.patch &&
298 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
301 echo sed -n -e s/^cccmd--//p \"\$1\"
303 chmod +x cccmd-sed &&
305 --from="Example <nobody@example.com>" \
306 --to=nobody@example.com \
307 --cc-cmd=./cccmd-sed \
308 --smtp-server="$(pwd)/fake.sendmail" \
311 grep "^ cccmd@example.com" msgtxt1
314 test_expect_success $PREREQ 'reject long lines' '
316 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
317 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
318 clean_fake_sendmail &&
319 cp $patches longline.patch &&
320 echo $z512$z512 >>longline.patch &&
321 test_must_fail git send-email \
322 --from="Example <nobody@example.com>" \
323 --to=nobody@example.com \
324 --smtp-server="$(pwd)/fake.sendmail" \
325 $patches longline.patch \
327 grep longline.patch errors
330 test_expect_success $PREREQ 'no patch was sent' '
331 ! test -e commandline1
334 test_expect_success $PREREQ 'Author From: in message body' '
335 clean_fake_sendmail &&
337 --from="Example <nobody@example.com>" \
338 --to=nobody@example.com \
339 --smtp-server="$(pwd)/fake.sendmail" \
341 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
342 grep "From: A <author@example.com>" msgbody1
345 test_expect_success $PREREQ 'Author From: not in message body' '
346 clean_fake_sendmail &&
348 --from="A <author@example.com>" \
349 --to=nobody@example.com \
350 --smtp-server="$(pwd)/fake.sendmail" \
352 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
353 ! grep "From: A <author@example.com>" msgbody1
356 test_expect_success $PREREQ 'allow long lines with --no-validate' '
358 --from="Example <nobody@example.com>" \
359 --to=nobody@example.com \
360 --smtp-server="$(pwd)/fake.sendmail" \
362 $patches longline.patch \
366 test_expect_success $PREREQ 'Invalid In-Reply-To' '
367 clean_fake_sendmail &&
369 --from="Example <nobody@example.com>" \
370 --to=nobody@example.com \
372 --smtp-server="$(pwd)/fake.sendmail" \
375 ! grep "^In-Reply-To: < *>" msgtxt1
378 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
379 clean_fake_sendmail &&
380 (echo "From Example <from@example.com>"
381 echo "To Example <to@example.com>"
383 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
384 --smtp-server="$(pwd)/fake.sendmail" \
386 ! grep "^In-Reply-To: < *>" msgtxt1
389 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
390 clean_fake_sendmail &&
391 echo "<unique-message-id@example.com>" >expect &&
393 --from="Example <nobody@example.com>" \
394 --to=nobody@example.com \
396 --in-reply-to="$(cat expect)" \
397 --smtp-server="$(pwd)/fake.sendmail" \
398 $patches $patches $patches \
400 # The first message is a reply to --in-reply-to
401 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
402 test_cmp expect actual &&
403 # Second and subsequent messages are replies to the first one
404 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
405 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
406 test_cmp expect actual &&
407 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
408 test_cmp expect actual
411 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
412 clean_fake_sendmail &&
413 echo "<unique-message-id@example.com>" >expect &&
415 --from="Example <nobody@example.com>" \
416 --to=nobody@example.com \
418 --in-reply-to="$(cat expect)" \
419 --smtp-server="$(pwd)/fake.sendmail" \
420 $patches $patches $patches \
422 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
423 test_cmp expect actual &&
424 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
425 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
426 test_cmp expect actual &&
427 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
428 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
429 test_cmp expect actual
432 test_expect_success $PREREQ 'setup fake editor' '
433 (echo "#!$SHELL_PATH" &&
434 echo "echo fake edit >>\"\$1\""
439 test_set_editor "$(pwd)/fake-editor"
441 test_expect_success $PREREQ '--compose works' '
442 clean_fake_sendmail &&
444 --compose --subject foo \
445 --from="Example <nobody@example.com>" \
446 --to=nobody@example.com \
447 --smtp-server="$(pwd)/fake.sendmail" \
452 test_expect_success $PREREQ 'first message is compose text' '
453 grep "^fake edit" msgtxt1
456 test_expect_success $PREREQ 'second message is patch' '
457 grep "Subject:.*Second" msgtxt2
460 test_expect_success $PREREQ 'setup expect' "
461 cat >expected-suppress-sob <<\EOF
463 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
464 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
465 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
467 Server: relay.example.com
468 MAIL FROM:<from@example.com>
469 RCPT TO:<to@example.com>
470 RCPT TO:<cc@example.com>
471 RCPT TO:<author@example.com>
472 RCPT TO:<one@example.com>
473 RCPT TO:<two@example.com>
474 From: Example <from@example.com>
477 A <author@example.com>,
478 One <one@example.com>,
480 Subject: [PATCH 1/1] Second.
482 Message-Id: MESSAGE-ID-STRING
483 X-Mailer: X-MAILER-STRING
489 test_suppression () {
492 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
493 --from="Example <from@example.com>" \
494 --to=to@example.com \
495 --smtp-server relay.example.com \
497 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
498 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
499 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
500 >actual-suppress-$1${2+"-$2"} &&
501 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
504 test_expect_success $PREREQ 'sendemail.cc set' '
505 git config sendemail.cc cc@example.com &&
509 test_expect_success $PREREQ 'setup expect' "
510 cat >expected-suppress-sob <<\EOF
512 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
513 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
514 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
516 Server: relay.example.com
517 MAIL FROM:<from@example.com>
518 RCPT TO:<to@example.com>
519 RCPT TO:<author@example.com>
520 RCPT TO:<one@example.com>
521 RCPT TO:<two@example.com>
522 From: Example <from@example.com>
524 Cc: A <author@example.com>,
525 One <one@example.com>,
527 Subject: [PATCH 1/1] Second.
529 Message-Id: MESSAGE-ID-STRING
530 X-Mailer: X-MAILER-STRING
536 test_expect_success $PREREQ 'sendemail.cc unset' '
537 git config --unset sendemail.cc &&
541 test_expect_success $PREREQ 'setup expect' "
542 cat >expected-suppress-cccmd <<\EOF
544 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
545 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
546 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
547 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
549 Server: relay.example.com
550 MAIL FROM:<from@example.com>
551 RCPT TO:<to@example.com>
552 RCPT TO:<author@example.com>
553 RCPT TO:<one@example.com>
554 RCPT TO:<two@example.com>
555 RCPT TO:<committer@example.com>
556 From: Example <from@example.com>
558 Cc: A <author@example.com>,
559 One <one@example.com>,
561 C O Mitter <committer@example.com>
562 Subject: [PATCH 1/1] Second.
564 Message-Id: MESSAGE-ID-STRING
565 X-Mailer: X-MAILER-STRING
571 test_expect_success $PREREQ 'sendemail.cccmd' '
572 echo echo cc-cmd@example.com > cccmd &&
574 git config sendemail.cccmd ./cccmd &&
575 test_suppression cccmd
578 test_expect_success $PREREQ 'setup expect' '
579 cat >expected-suppress-all <<\EOF
582 Server: relay.example.com
583 MAIL FROM:<from@example.com>
584 RCPT TO:<to@example.com>
585 From: Example <from@example.com>
587 Subject: [PATCH 1/1] Second.
589 Message-Id: MESSAGE-ID-STRING
590 X-Mailer: X-MAILER-STRING
596 test_expect_success $PREREQ '--suppress-cc=all' '
600 test_expect_success $PREREQ 'setup expect' "
601 cat >expected-suppress-body <<\EOF
603 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
604 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
605 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
606 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
608 Server: relay.example.com
609 MAIL FROM:<from@example.com>
610 RCPT TO:<to@example.com>
611 RCPT TO:<author@example.com>
612 RCPT TO:<one@example.com>
613 RCPT TO:<two@example.com>
614 RCPT TO:<cc-cmd@example.com>
615 From: Example <from@example.com>
617 Cc: A <author@example.com>,
618 One <one@example.com>,
621 Subject: [PATCH 1/1] Second.
623 Message-Id: MESSAGE-ID-STRING
624 X-Mailer: X-MAILER-STRING
630 test_expect_success $PREREQ '--suppress-cc=body' '
631 test_suppression body
634 test_expect_success $PREREQ 'setup expect' "
635 cat >expected-suppress-body-cccmd <<\EOF
637 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
638 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
639 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
641 Server: relay.example.com
642 MAIL FROM:<from@example.com>
643 RCPT TO:<to@example.com>
644 RCPT TO:<author@example.com>
645 RCPT TO:<one@example.com>
646 RCPT TO:<two@example.com>
647 From: Example <from@example.com>
649 Cc: A <author@example.com>,
650 One <one@example.com>,
652 Subject: [PATCH 1/1] Second.
654 Message-Id: MESSAGE-ID-STRING
655 X-Mailer: X-MAILER-STRING
661 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
662 test_suppression body cccmd
665 test_expect_success $PREREQ 'setup expect' "
666 cat >expected-suppress-sob <<\EOF
668 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
669 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
670 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
672 Server: relay.example.com
673 MAIL FROM:<from@example.com>
674 RCPT TO:<to@example.com>
675 RCPT TO:<author@example.com>
676 RCPT TO:<one@example.com>
677 RCPT TO:<two@example.com>
678 From: Example <from@example.com>
680 Cc: A <author@example.com>,
681 One <one@example.com>,
683 Subject: [PATCH 1/1] Second.
685 Message-Id: MESSAGE-ID-STRING
686 X-Mailer: X-MAILER-STRING
692 test_expect_success $PREREQ '--suppress-cc=sob' '
693 test_might_fail git config --unset sendemail.cccmd &&
697 test_expect_success $PREREQ 'setup expect' "
698 cat >expected-suppress-bodycc <<\EOF
700 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
701 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
702 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
703 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
705 Server: relay.example.com
706 MAIL FROM:<from@example.com>
707 RCPT TO:<to@example.com>
708 RCPT TO:<author@example.com>
709 RCPT TO:<one@example.com>
710 RCPT TO:<two@example.com>
711 RCPT TO:<committer@example.com>
712 From: Example <from@example.com>
714 Cc: A <author@example.com>,
715 One <one@example.com>,
717 C O Mitter <committer@example.com>
718 Subject: [PATCH 1/1] Second.
720 Message-Id: MESSAGE-ID-STRING
721 X-Mailer: X-MAILER-STRING
727 test_expect_success $PREREQ '--suppress-cc=bodycc' '
728 test_suppression bodycc
731 test_expect_success $PREREQ 'setup expect' "
732 cat >expected-suppress-cc <<\EOF
734 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
735 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
737 Server: relay.example.com
738 MAIL FROM:<from@example.com>
739 RCPT TO:<to@example.com>
740 RCPT TO:<author@example.com>
741 RCPT TO:<committer@example.com>
742 From: Example <from@example.com>
744 Cc: A <author@example.com>,
745 C O Mitter <committer@example.com>
746 Subject: [PATCH 1/1] Second.
748 Message-Id: MESSAGE-ID-STRING
749 X-Mailer: X-MAILER-STRING
755 test_expect_success $PREREQ '--suppress-cc=cc' '
761 GIT_SEND_EMAIL_NOTTY=1 \
763 --from="Example <nobody@example.com>" \
764 --to=nobody@example.com \
765 --smtp-server="$(pwd)/fake.sendmail" \
766 $@ $patches > stdout &&
767 grep "Send this email" stdout
770 test_expect_success $PREREQ '--confirm=always' '
771 test_confirm --confirm=always --suppress-cc=all
774 test_expect_success $PREREQ '--confirm=auto' '
775 test_confirm --confirm=auto
778 test_expect_success $PREREQ '--confirm=cc' '
779 test_confirm --confirm=cc
782 test_expect_success $PREREQ '--confirm=compose' '
783 test_confirm --confirm=compose --compose
786 test_expect_success $PREREQ 'confirm by default (due to cc)' '
787 CONFIRM=$(git config --get sendemail.confirm) &&
788 git config --unset sendemail.confirm &&
791 git config sendemail.confirm ${CONFIRM:-never}
795 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
796 CONFIRM=$(git config --get sendemail.confirm) &&
797 git config --unset sendemail.confirm &&
798 test_confirm --suppress-cc=all --compose
800 git config sendemail.confirm ${CONFIRM:-never}
804 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
805 CONFIRM=$(git config --get sendemail.confirm) &&
806 git config --unset sendemail.confirm &&
808 git format-patch -2 -o outdir &&
809 GIT_SEND_EMAIL_NOTTY=1 \
811 --from="Example <nobody@example.com>" \
812 --to=nobody@example.com \
813 --smtp-server="$(pwd)/fake.sendmail" \
814 outdir/*.patch < /dev/null
816 git config sendemail.confirm ${CONFIRM:-never}
820 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
821 CONFIRM=$(git config --get sendemail.confirm) &&
822 git config sendemail.confirm auto &&
823 GIT_SEND_EMAIL_NOTTY=1 &&
824 export GIT_SEND_EMAIL_NOTTY &&
825 test_must_fail git send-email \
826 --from="Example <nobody@example.com>" \
827 --to=nobody@example.com \
828 --smtp-server="$(pwd)/fake.sendmail" \
831 git config sendemail.confirm ${CONFIRM:-never}
835 test_expect_success $PREREQ 'confirm does not loop forever' '
836 CONFIRM=$(git config --get sendemail.confirm) &&
837 git config sendemail.confirm auto &&
838 GIT_SEND_EMAIL_NOTTY=1 &&
839 export GIT_SEND_EMAIL_NOTTY &&
840 yes "bogus" | test_must_fail git send-email \
841 --from="Example <nobody@example.com>" \
842 --to=nobody@example.com \
843 --smtp-server="$(pwd)/fake.sendmail" \
846 git config sendemail.confirm ${CONFIRM:-never}
850 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
851 clean_fake_sendmail &&
853 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
855 --from="Example <nobody@example.com>" \
856 --to=nobody@example.com \
857 --smtp-server="$(pwd)/fake.sendmail" \
860 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
863 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
864 clean_fake_sendmail &&
865 (echo "#!$SHELL_PATH" &&
866 echo "echo utf8 body: àéìöú >>\"\$1\""
867 ) >fake-editor-utf8 &&
868 chmod +x fake-editor-utf8 &&
869 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
871 --compose --subject foo \
872 --from="Example <nobody@example.com>" \
873 --to=nobody@example.com \
874 --smtp-server="$(pwd)/fake.sendmail" \
876 grep "^utf8 body" msgtxt1 &&
877 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
880 test_expect_success $PREREQ '--compose respects user mime type' '
881 clean_fake_sendmail &&
882 (echo "#!$SHELL_PATH" &&
883 echo "(echo MIME-Version: 1.0"
884 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
885 echo " echo Content-Transfer-Encoding: 8bit"
886 echo " echo Subject: foo"
888 echo " echo utf8 body: àéìöú) >\"\$1\""
889 ) >fake-editor-utf8-mime &&
890 chmod +x fake-editor-utf8-mime &&
891 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
893 --compose --subject foo \
894 --from="Example <nobody@example.com>" \
895 --to=nobody@example.com \
896 --smtp-server="$(pwd)/fake.sendmail" \
898 grep "^utf8 body" msgtxt1 &&
899 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
900 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
903 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
904 clean_fake_sendmail &&
905 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
907 --compose --subject utf8-sübjëct \
908 --from="Example <nobody@example.com>" \
909 --to=nobody@example.com \
910 --smtp-server="$(pwd)/fake.sendmail" \
912 grep "^fake edit" msgtxt1 &&
913 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
916 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
917 clean_fake_sendmail &&
918 test_commit weird_author &&
919 test_when_finished "git reset --hard HEAD^" &&
920 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
921 git format-patch --stdout -1 >funny_name.patch &&
922 git send-email --from="Example <nobody@example.com>" \
923 --to=nobody@example.com \
924 --smtp-server="$(pwd)/fake.sendmail" \
926 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
929 test_expect_success $PREREQ 'sendemail.composeencoding works' '
930 clean_fake_sendmail &&
931 git config sendemail.composeencoding iso-8859-1 &&
932 (echo "#!$SHELL_PATH" &&
933 echo "echo utf8 body: àéìöú >>\"\$1\""
934 ) >fake-editor-utf8 &&
935 chmod +x fake-editor-utf8 &&
936 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
938 --compose --subject foo \
939 --from="Example <nobody@example.com>" \
940 --to=nobody@example.com \
941 --smtp-server="$(pwd)/fake.sendmail" \
943 grep "^utf8 body" msgtxt1 &&
944 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
947 test_expect_success $PREREQ '--compose-encoding works' '
948 clean_fake_sendmail &&
949 (echo "#!$SHELL_PATH" &&
950 echo "echo utf8 body: àéìöú >>\"\$1\""
951 ) >fake-editor-utf8 &&
952 chmod +x fake-editor-utf8 &&
953 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
955 --compose-encoding iso-8859-1 \
956 --compose --subject foo \
957 --from="Example <nobody@example.com>" \
958 --to=nobody@example.com \
959 --smtp-server="$(pwd)/fake.sendmail" \
961 grep "^utf8 body" msgtxt1 &&
962 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
965 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
966 clean_fake_sendmail &&
967 git config sendemail.composeencoding iso-8859-1 &&
968 (echo "#!$SHELL_PATH" &&
969 echo "echo utf8 body: àéìöú >>\"\$1\""
970 ) >fake-editor-utf8 &&
971 chmod +x fake-editor-utf8 &&
972 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
974 --compose-encoding iso-8859-2 \
975 --compose --subject foo \
976 --from="Example <nobody@example.com>" \
977 --to=nobody@example.com \
978 --smtp-server="$(pwd)/fake.sendmail" \
980 grep "^utf8 body" msgtxt1 &&
981 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
984 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
985 clean_fake_sendmail &&
986 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
988 --compose-encoding iso-8859-2 \
989 --compose --subject utf8-sübjëct \
990 --from="Example <nobody@example.com>" \
991 --to=nobody@example.com \
992 --smtp-server="$(pwd)/fake.sendmail" \
994 grep "^fake edit" msgtxt1 &&
995 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
998 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
999 echo master > master &&
1001 git commit -m"add master" &&
1002 test_must_fail git send-email --dry-run master 2>errors &&
1003 grep disambiguate errors
1006 test_expect_success $PREREQ 'feed two files' '
1008 git format-patch -2 -o outdir &&
1011 --from="Example <nobody@example.com>" \
1012 --to=nobody@example.com \
1013 outdir/000?-*.patch 2>errors >out &&
1014 grep "^Subject: " out >subjects &&
1015 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1016 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1019 test_expect_success $PREREQ 'in-reply-to but no threading' '
1022 --from="Example <nobody@example.com>" \
1023 --to=nobody@example.com \
1024 --in-reply-to="<in-reply-id@example.com>" \
1027 grep "In-Reply-To: <in-reply-id@example.com>"
1030 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1033 --from="Example <nobody@example.com>" \
1034 --to=nobody@example.com \
1036 $patches $patches >stdout &&
1037 ! grep "In-Reply-To: " stdout
1040 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1043 --from="Example <nobody@example.com>" \
1044 --to=nobody@example.com \
1046 --nochain-reply-to \
1047 $patches $patches >stdout &&
1048 grep "In-Reply-To: " stdout
1051 test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
1054 --from="Example <nobody@example.com>" \
1055 --to=nobody@example.com \
1056 outdir/000?-*.patch 2>errors >out &&
1057 grep "no-chain-reply-to" errors
1060 test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
1063 --from="Example <nobody@example.com>" \
1064 --to=nobody@example.com \
1066 outdir/000?-*.patch 2>errors >out &&
1067 ! grep "no-chain-reply-to" errors
1070 test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
1073 --from="Example <nobody@example.com>" \
1074 --to=nobody@example.com \
1075 --nochain-reply-to \
1076 outdir/000?-*.patch 2>errors >out &&
1077 ! grep "no-chain-reply-to" errors
1080 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
1081 git config sendemail.chainreplyto false &&
1084 --from="Example <nobody@example.com>" \
1085 --to=nobody@example.com \
1086 outdir/000?-*.patch 2>errors >out &&
1087 ! grep "no-chain-reply-to" errors
1090 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
1091 git config sendemail.chainreplyto true &&
1094 --from="Example <nobody@example.com>" \
1095 --to=nobody@example.com \
1096 outdir/000?-*.patch 2>errors >out &&
1097 ! grep "no-chain-reply-to" errors
1100 test_expect_success $PREREQ 'sendemail.to works' '
1101 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1104 --from="Example <nobody@example.com>" \
1105 $patches $patches >stdout &&
1106 grep "To: Somebody <somebody@ex.com>" stdout
1109 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1112 --from="Example <nobody@example.com>" \
1114 --to=nobody@example.com \
1115 $patches $patches >stdout &&
1116 grep "To: nobody@example.com" stdout &&
1117 ! grep "To: Somebody <somebody@ex.com>" stdout
1120 test_expect_success $PREREQ 'sendemail.cc works' '
1121 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1124 --from="Example <nobody@example.com>" \
1125 --to=nobody@example.com \
1126 $patches $patches >stdout &&
1127 grep "Cc: Somebody <somebody@ex.com>" stdout
1130 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1133 --from="Example <nobody@example.com>" \
1135 --cc=bodies@example.com \
1136 --to=nobody@example.com \
1137 $patches $patches >stdout &&
1138 grep "Cc: bodies@example.com" stdout &&
1139 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1142 test_expect_success $PREREQ 'sendemail.bcc works' '
1143 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1146 --from="Example <nobody@example.com>" \
1147 --to=nobody@example.com \
1148 --smtp-server relay.example.com \
1149 $patches $patches >stdout &&
1150 grep "RCPT TO:<other@ex.com>" stdout
1153 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1156 --from="Example <nobody@example.com>" \
1158 --bcc=bodies@example.com \
1159 --to=nobody@example.com \
1160 --smtp-server relay.example.com \
1161 $patches $patches >stdout &&
1162 grep "RCPT TO:<bodies@example.com>" stdout &&
1163 ! grep "RCPT TO:<other@ex.com>" stdout
1166 test_expect_success $PREREQ 'patches To headers are used by default' '
1167 patch=`git format-patch -1 --to="bodies@example.com"` &&
1168 test_when_finished "rm $patch" &&
1171 --from="Example <nobody@example.com>" \
1172 --smtp-server relay.example.com \
1174 grep "RCPT TO:<bodies@example.com>" stdout
1177 test_expect_success $PREREQ 'patches To headers are appended to' '
1178 patch=`git format-patch -1 --to="bodies@example.com"` &&
1179 test_when_finished "rm $patch" &&
1182 --from="Example <nobody@example.com>" \
1183 --to=nobody@example.com \
1184 --smtp-server relay.example.com \
1186 grep "RCPT TO:<bodies@example.com>" stdout &&
1187 grep "RCPT TO:<nobody@example.com>" stdout
1190 test_expect_success $PREREQ 'To headers from files reset each patch' '
1191 patch1=`git format-patch -1 --to="bodies@example.com"` &&
1192 patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1193 test_when_finished "rm $patch1 && rm $patch2" &&
1196 --from="Example <nobody@example.com>" \
1197 --to="nobody@example.com" \
1198 --smtp-server relay.example.com \
1199 $patch1 $patch2 >stdout &&
1200 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1201 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1202 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1205 test_expect_success $PREREQ 'setup expect' '
1206 cat >email-using-8bit <<EOF
1207 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1208 Message-Id: <bogus-message-id@example.com>
1209 From: author@example.com
1210 Date: Sat, 12 Jun 2010 15:53:58 +0200
1211 Subject: subject goes here
1213 Dieser deutsche Text enthält einen Umlaut!
1217 test_expect_success $PREREQ 'setup expect' '
1219 Subject: subject goes here
1223 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1224 clean_fake_sendmail &&
1226 git send-email --from=author@example.com --to=nobody@example.com \
1227 --smtp-server="$(pwd)/fake.sendmail" \
1228 --8bit-encoding=UTF-8 \
1229 email-using-8bit >stdout &&
1230 grep "Subject" msgtxt1 >actual &&
1231 test_cmp expected actual
1234 test_expect_success $PREREQ 'setup expect' '
1235 cat >content-type-decl <<EOF
1237 Content-Type: text/plain; charset=UTF-8
1238 Content-Transfer-Encoding: 8bit
1242 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1243 clean_fake_sendmail &&
1245 git send-email --from=author@example.com --to=nobody@example.com \
1246 --smtp-server="$(pwd)/fake.sendmail" \
1247 email-using-8bit >stdout &&
1248 grep "do not declare a Content-Transfer-Encoding" stdout &&
1249 grep email-using-8bit stdout &&
1250 grep "Which 8bit encoding" stdout &&
1251 egrep "Content|MIME" msgtxt1 >actual &&
1252 test_cmp actual content-type-decl
1255 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1256 clean_fake_sendmail &&
1257 git config sendemail.assume8bitEncoding UTF-8 &&
1259 git send-email --from=author@example.com --to=nobody@example.com \
1260 --smtp-server="$(pwd)/fake.sendmail" \
1261 email-using-8bit >stdout &&
1262 egrep "Content|MIME" msgtxt1 >actual &&
1263 test_cmp actual content-type-decl
1266 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1267 clean_fake_sendmail &&
1268 git config sendemail.assume8bitEncoding "bogus too" &&
1270 git send-email --from=author@example.com --to=nobody@example.com \
1271 --smtp-server="$(pwd)/fake.sendmail" \
1272 --8bit-encoding=UTF-8 \
1273 email-using-8bit >stdout &&
1274 egrep "Content|MIME" msgtxt1 >actual &&
1275 test_cmp actual content-type-decl
1278 test_expect_success $PREREQ 'setup expect' '
1279 cat >email-using-8bit <<EOF
1280 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1281 Message-Id: <bogus-message-id@example.com>
1282 From: author@example.com
1283 Date: Sat, 12 Jun 2010 15:53:58 +0200
1284 Subject: Dieser Betreff enthält auch einen Umlaut!
1286 Nothing to see here.
1290 test_expect_success $PREREQ 'setup expect' '
1292 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1296 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1297 clean_fake_sendmail &&
1299 git send-email --from=author@example.com --to=nobody@example.com \
1300 --smtp-server="$(pwd)/fake.sendmail" \
1301 --8bit-encoding=UTF-8 \
1302 email-using-8bit >stdout &&
1303 grep "Subject" msgtxt1 >actual &&
1304 test_cmp expected actual
1307 # Note that the patches in this test are deliberately out of order; we
1308 # want to make sure it works even if the cover-letter is not in the
1310 test_expect_success $PREREQ 'refusing to send cover letter template' '
1311 clean_fake_sendmail &&
1313 git format-patch --cover-letter -2 -o outdir &&
1314 test_must_fail git send-email \
1315 --from="Example <nobody@example.com>" \
1316 --to=nobody@example.com \
1317 --smtp-server="$(pwd)/fake.sendmail" \
1318 outdir/0002-*.patch \
1319 outdir/0000-*.patch \
1320 outdir/0001-*.patch \
1322 grep "SUBJECT HERE" errors &&
1323 test -z "$(ls msgtxt*)"
1326 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1327 clean_fake_sendmail &&
1329 git format-patch --cover-letter -2 -o outdir &&
1332 --from="Example <nobody@example.com>" \
1333 --to=nobody@example.com \
1334 --smtp-server="$(pwd)/fake.sendmail" \
1335 outdir/0002-*.patch \
1336 outdir/0000-*.patch \
1337 outdir/0001-*.patch \
1339 ! grep "SUBJECT HERE" errors &&
1340 test -n "$(ls msgtxt*)"
1343 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1344 clean_fake_sendmail &&
1345 echo "alias sbd somebody@example.org" >.mailrc &&
1346 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1347 git config sendemail.aliasfiletype mailrc &&
1349 --from="Example <nobody@example.com>" \
1351 --smtp-server="$(pwd)/fake.sendmail" \
1352 outdir/0001-*.patch \
1354 grep "^!somebody@example\.org!$" commandline1
1357 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1358 clean_fake_sendmail &&
1359 echo "alias sbd someone@example.org" >~/.mailrc &&
1360 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1361 git config sendemail.aliasfiletype mailrc &&
1363 --from="Example <nobody@example.com>" \
1365 --smtp-server="$(pwd)/fake.sendmail" \
1366 outdir/0001-*.patch \
1368 grep "^!someone@example\.org!$" commandline1