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 Contributer <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_expect_success
$PREREQ 'Show all headers' '
178 --from="Example <from@example.com>" \
179 --to=to@example.com \
180 --cc=cc@example.com \
181 --bcc=bcc@example.com \
182 --in-reply-to="<unique-message-id@example.com>" \
183 --smtp-server relay.example.com \
185 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
186 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
187 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
188 >actual-show-all-headers &&
189 test_cmp expected-show-all-headers actual-show-all-headers
192 test_expect_success
$PREREQ 'Prompting works' '
193 clean_fake_sendmail &&
194 (echo "to@example.com"
196 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
197 --smtp-server="$(pwd)/fake.sendmail" \
200 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
201 grep "^To: to@example.com\$" msgtxt1
204 test_expect_success
$PREREQ,AUTOIDENT
'implicit ident is allowed' '
205 clean_fake_sendmail &&
206 (sane_unset GIT_AUTHOR_NAME &&
207 sane_unset GIT_AUTHOR_EMAIL &&
208 sane_unset GIT_COMMITTER_NAME &&
209 sane_unset GIT_COMMITTER_EMAIL &&
210 GIT_SEND_EMAIL_NOTTY=1 git send-email \
211 --smtp-server="$(pwd)/fake.sendmail" \
212 --to=to@example.com \
213 $patches </dev/null 2>errors
217 test_expect_success
$PREREQ,!AUTOIDENT
'broken implicit ident aborts send-email' '
218 clean_fake_sendmail &&
219 (sane_unset GIT_AUTHOR_NAME &&
220 sane_unset GIT_AUTHOR_EMAIL &&
221 sane_unset GIT_COMMITTER_NAME &&
222 sane_unset GIT_COMMITTER_EMAIL &&
223 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
224 test_must_fail git send-email \
225 --smtp-server="$(pwd)/fake.sendmail" \
226 --to=to@example.com \
227 $patches </dev/null 2>errors &&
228 test_i18ngrep "tell me who you are" errors
232 test_expect_success
$PREREQ 'tocmd works' '
233 clean_fake_sendmail &&
234 cp $patches tocmd.patch &&
235 echo tocmd--tocmd@example.com >>tocmd.patch &&
238 echo sed -n -e s/^tocmd--//p \"\$1\"
240 chmod +x tocmd-sed &&
242 --from="Example <nobody@example.com>" \
243 --to-cmd=./tocmd-sed \
244 --smtp-server="$(pwd)/fake.sendmail" \
247 grep "^To: tocmd@example.com" msgtxt1
250 test_expect_success
$PREREQ 'cccmd works' '
251 clean_fake_sendmail &&
252 cp $patches cccmd.patch &&
253 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
256 echo sed -n -e s/^cccmd--//p \"\$1\"
258 chmod +x cccmd-sed &&
260 --from="Example <nobody@example.com>" \
261 --to=nobody@example.com \
262 --cc-cmd=./cccmd-sed \
263 --smtp-server="$(pwd)/fake.sendmail" \
266 grep "^ cccmd@example.com" msgtxt1
269 test_expect_success
$PREREQ 'reject long lines' '
271 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
272 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
273 clean_fake_sendmail &&
274 cp $patches longline.patch &&
275 echo $z512$z512 >>longline.patch &&
276 test_must_fail git send-email \
277 --from="Example <nobody@example.com>" \
278 --to=nobody@example.com \
279 --smtp-server="$(pwd)/fake.sendmail" \
280 $patches longline.patch \
282 grep longline.patch errors
285 test_expect_success
$PREREQ 'no patch was sent' '
286 ! test -e commandline1
289 test_expect_success
$PREREQ 'Author From: in message body' '
290 clean_fake_sendmail &&
292 --from="Example <nobody@example.com>" \
293 --to=nobody@example.com \
294 --smtp-server="$(pwd)/fake.sendmail" \
296 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
297 grep "From: A <author@example.com>" msgbody1
300 test_expect_success
$PREREQ 'Author From: not in message body' '
301 clean_fake_sendmail &&
303 --from="A <author@example.com>" \
304 --to=nobody@example.com \
305 --smtp-server="$(pwd)/fake.sendmail" \
307 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
308 ! grep "From: A <author@example.com>" msgbody1
311 test_expect_success
$PREREQ 'allow long lines with --no-validate' '
313 --from="Example <nobody@example.com>" \
314 --to=nobody@example.com \
315 --smtp-server="$(pwd)/fake.sendmail" \
317 $patches longline.patch \
321 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
322 clean_fake_sendmail &&
324 --from="Example <nobody@example.com>" \
325 --to=nobody@example.com \
327 --smtp-server="$(pwd)/fake.sendmail" \
330 ! grep "^In-Reply-To: < *>" msgtxt1
333 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
334 clean_fake_sendmail &&
335 (echo "From Example <from@example.com>"
336 echo "To Example <to@example.com>"
338 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
339 --smtp-server="$(pwd)/fake.sendmail" \
341 ! grep "^In-Reply-To: < *>" msgtxt1
344 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
345 clean_fake_sendmail &&
346 echo "<unique-message-id@example.com>" >expect &&
348 --from="Example <nobody@example.com>" \
349 --to=nobody@example.com \
351 --in-reply-to="$(cat expect)" \
352 --smtp-server="$(pwd)/fake.sendmail" \
353 $patches $patches $patches \
355 # The first message is a reply to --in-reply-to
356 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
357 test_cmp expect actual &&
358 # Second and subsequent messages are replies to the first one
359 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
360 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
361 test_cmp expect actual &&
362 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
363 test_cmp expect actual
366 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
367 clean_fake_sendmail &&
368 echo "<unique-message-id@example.com>" >expect &&
370 --from="Example <nobody@example.com>" \
371 --to=nobody@example.com \
373 --in-reply-to="$(cat expect)" \
374 --smtp-server="$(pwd)/fake.sendmail" \
375 $patches $patches $patches \
377 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
378 test_cmp expect actual &&
379 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
380 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
381 test_cmp expect actual &&
382 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
383 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
384 test_cmp expect actual
387 test_expect_success
$PREREQ 'setup fake editor' '
388 (echo "#!$SHELL_PATH" &&
389 echo "echo fake edit >>\"\$1\""
394 test_set_editor
"$(pwd)/fake-editor"
396 test_expect_success
$PREREQ '--compose works' '
397 clean_fake_sendmail &&
399 --compose --subject foo \
400 --from="Example <nobody@example.com>" \
401 --to=nobody@example.com \
402 --smtp-server="$(pwd)/fake.sendmail" \
407 test_expect_success
$PREREQ 'first message is compose text' '
408 grep "^fake edit" msgtxt1
411 test_expect_success
$PREREQ 'second message is patch' '
412 grep "Subject:.*Second" msgtxt2
415 test_expect_success
$PREREQ 'setup expect' "
416 cat >expected-suppress-sob <<\EOF
418 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
419 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
420 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
422 Server: relay.example.com
423 MAIL FROM:<from@example.com>
424 RCPT TO:<to@example.com>
425 RCPT TO:<cc@example.com>
426 RCPT TO:<author@example.com>
427 RCPT TO:<one@example.com>
428 RCPT TO:<two@example.com>
429 From: Example <from@example.com>
432 A <author@example.com>,
433 One <one@example.com>,
435 Subject: [PATCH 1/1] Second.
437 Message-Id: MESSAGE-ID-STRING
438 X-Mailer: X-MAILER-STRING
444 test_suppression
() {
447 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
448 --from="Example <from@example.com>" \
449 --to=to@example.com \
450 --smtp-server relay.example.com \
452 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
453 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
454 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
455 >actual-suppress-
$1${2+"-$2"} &&
456 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
459 test_expect_success
$PREREQ 'sendemail.cc set' '
460 git config sendemail.cc cc@example.com &&
464 test_expect_success
$PREREQ 'setup expect' "
465 cat >expected-suppress-sob <<\EOF
467 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
468 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
469 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
471 Server: relay.example.com
472 MAIL FROM:<from@example.com>
473 RCPT TO:<to@example.com>
474 RCPT TO:<author@example.com>
475 RCPT TO:<one@example.com>
476 RCPT TO:<two@example.com>
477 From: Example <from@example.com>
479 Cc: A <author@example.com>,
480 One <one@example.com>,
482 Subject: [PATCH 1/1] Second.
484 Message-Id: MESSAGE-ID-STRING
485 X-Mailer: X-MAILER-STRING
491 test_expect_success
$PREREQ 'sendemail.cc unset' '
492 git config --unset sendemail.cc &&
496 test_expect_success
$PREREQ 'setup expect' "
497 cat >expected-suppress-cccmd <<\EOF
499 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
500 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
501 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
502 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
504 Server: relay.example.com
505 MAIL FROM:<from@example.com>
506 RCPT TO:<to@example.com>
507 RCPT TO:<author@example.com>
508 RCPT TO:<one@example.com>
509 RCPT TO:<two@example.com>
510 RCPT TO:<committer@example.com>
511 From: Example <from@example.com>
513 Cc: A <author@example.com>,
514 One <one@example.com>,
516 C O Mitter <committer@example.com>
517 Subject: [PATCH 1/1] Second.
519 Message-Id: MESSAGE-ID-STRING
520 X-Mailer: X-MAILER-STRING
526 test_expect_success
$PREREQ 'sendemail.cccmd' '
527 echo echo cc-cmd@example.com > cccmd &&
529 git config sendemail.cccmd ./cccmd &&
530 test_suppression cccmd
533 test_expect_success
$PREREQ 'setup expect' '
534 cat >expected-suppress-all <<\EOF
537 Server: relay.example.com
538 MAIL FROM:<from@example.com>
539 RCPT TO:<to@example.com>
540 From: Example <from@example.com>
542 Subject: [PATCH 1/1] Second.
544 Message-Id: MESSAGE-ID-STRING
545 X-Mailer: X-MAILER-STRING
551 test_expect_success
$PREREQ '--suppress-cc=all' '
555 test_expect_success
$PREREQ 'setup expect' "
556 cat >expected-suppress-body <<\EOF
558 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
559 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
560 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
561 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
563 Server: relay.example.com
564 MAIL FROM:<from@example.com>
565 RCPT TO:<to@example.com>
566 RCPT TO:<author@example.com>
567 RCPT TO:<one@example.com>
568 RCPT TO:<two@example.com>
569 RCPT TO:<cc-cmd@example.com>
570 From: Example <from@example.com>
572 Cc: A <author@example.com>,
573 One <one@example.com>,
576 Subject: [PATCH 1/1] Second.
578 Message-Id: MESSAGE-ID-STRING
579 X-Mailer: X-MAILER-STRING
585 test_expect_success
$PREREQ '--suppress-cc=body' '
586 test_suppression body
589 test_expect_success
$PREREQ 'setup expect' "
590 cat >expected-suppress-body-cccmd <<\EOF
592 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
593 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
594 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
596 Server: relay.example.com
597 MAIL FROM:<from@example.com>
598 RCPT TO:<to@example.com>
599 RCPT TO:<author@example.com>
600 RCPT TO:<one@example.com>
601 RCPT TO:<two@example.com>
602 From: Example <from@example.com>
604 Cc: A <author@example.com>,
605 One <one@example.com>,
607 Subject: [PATCH 1/1] Second.
609 Message-Id: MESSAGE-ID-STRING
610 X-Mailer: X-MAILER-STRING
616 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
617 test_suppression body cccmd
620 test_expect_success
$PREREQ 'setup expect' "
621 cat >expected-suppress-sob <<\EOF
623 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
624 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
625 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
627 Server: relay.example.com
628 MAIL FROM:<from@example.com>
629 RCPT TO:<to@example.com>
630 RCPT TO:<author@example.com>
631 RCPT TO:<one@example.com>
632 RCPT TO:<two@example.com>
633 From: Example <from@example.com>
635 Cc: A <author@example.com>,
636 One <one@example.com>,
638 Subject: [PATCH 1/1] Second.
640 Message-Id: MESSAGE-ID-STRING
641 X-Mailer: X-MAILER-STRING
647 test_expect_success
$PREREQ '--suppress-cc=sob' '
648 test_might_fail git config --unset sendemail.cccmd &&
652 test_expect_success
$PREREQ 'setup expect' "
653 cat >expected-suppress-bodycc <<\EOF
655 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
656 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
657 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
658 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
660 Server: relay.example.com
661 MAIL FROM:<from@example.com>
662 RCPT TO:<to@example.com>
663 RCPT TO:<author@example.com>
664 RCPT TO:<one@example.com>
665 RCPT TO:<two@example.com>
666 RCPT TO:<committer@example.com>
667 From: Example <from@example.com>
669 Cc: A <author@example.com>,
670 One <one@example.com>,
672 C O Mitter <committer@example.com>
673 Subject: [PATCH 1/1] Second.
675 Message-Id: MESSAGE-ID-STRING
676 X-Mailer: X-MAILER-STRING
682 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
683 test_suppression bodycc
686 test_expect_success
$PREREQ 'setup expect' "
687 cat >expected-suppress-cc <<\EOF
689 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
690 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
692 Server: relay.example.com
693 MAIL FROM:<from@example.com>
694 RCPT TO:<to@example.com>
695 RCPT TO:<author@example.com>
696 RCPT TO:<committer@example.com>
697 From: Example <from@example.com>
699 Cc: A <author@example.com>,
700 C O Mitter <committer@example.com>
701 Subject: [PATCH 1/1] Second.
703 Message-Id: MESSAGE-ID-STRING
704 X-Mailer: X-MAILER-STRING
710 test_expect_success
$PREREQ '--suppress-cc=cc' '
716 GIT_SEND_EMAIL_NOTTY
=1 \
718 --from="Example <nobody@example.com>" \
719 --to=nobody@example.com \
720 --smtp-server="$(pwd)/fake.sendmail" \
721 $@
$patches > stdout
&&
722 grep "Send this email" stdout
725 test_expect_success
$PREREQ '--confirm=always' '
726 test_confirm --confirm=always --suppress-cc=all
729 test_expect_success
$PREREQ '--confirm=auto' '
730 test_confirm --confirm=auto
733 test_expect_success
$PREREQ '--confirm=cc' '
734 test_confirm --confirm=cc
737 test_expect_success
$PREREQ '--confirm=compose' '
738 test_confirm --confirm=compose --compose
741 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
742 CONFIRM=$(git config --get sendemail.confirm) &&
743 git config --unset sendemail.confirm &&
746 git config sendemail.confirm ${CONFIRM:-never}
750 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
751 CONFIRM=$(git config --get sendemail.confirm) &&
752 git config --unset sendemail.confirm &&
753 test_confirm --suppress-cc=all --compose
755 git config sendemail.confirm ${CONFIRM:-never}
759 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
760 CONFIRM=$(git config --get sendemail.confirm) &&
761 git config --unset sendemail.confirm &&
763 git format-patch -2 -o outdir &&
764 GIT_SEND_EMAIL_NOTTY=1 \
766 --from="Example <nobody@example.com>" \
767 --to=nobody@example.com \
768 --smtp-server="$(pwd)/fake.sendmail" \
769 outdir/*.patch < /dev/null
771 git config sendemail.confirm ${CONFIRM:-never}
775 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
776 CONFIRM=$(git config --get sendemail.confirm) &&
777 git config sendemail.confirm auto &&
778 GIT_SEND_EMAIL_NOTTY=1 &&
779 export GIT_SEND_EMAIL_NOTTY &&
780 test_must_fail git send-email \
781 --from="Example <nobody@example.com>" \
782 --to=nobody@example.com \
783 --smtp-server="$(pwd)/fake.sendmail" \
786 git config sendemail.confirm ${CONFIRM:-never}
790 test_expect_success
$PREREQ 'confirm doesnt loop forever' '
791 CONFIRM=$(git config --get sendemail.confirm) &&
792 git config sendemail.confirm auto &&
793 GIT_SEND_EMAIL_NOTTY=1 &&
794 export GIT_SEND_EMAIL_NOTTY &&
795 yes "bogus" | test_must_fail git send-email \
796 --from="Example <nobody@example.com>" \
797 --to=nobody@example.com \
798 --smtp-server="$(pwd)/fake.sendmail" \
801 git config sendemail.confirm ${CONFIRM:-never}
805 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
806 clean_fake_sendmail &&
808 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
810 --from="Example <nobody@example.com>" \
811 --to=nobody@example.com \
812 --smtp-server="$(pwd)/fake.sendmail" \
815 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
818 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
819 clean_fake_sendmail &&
820 (echo "#!$SHELL_PATH" &&
821 echo "echo utf8 body: àéìöú >>\"\$1\""
822 ) >fake-editor-utf8 &&
823 chmod +x fake-editor-utf8 &&
824 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
826 --compose --subject foo \
827 --from="Example <nobody@example.com>" \
828 --to=nobody@example.com \
829 --smtp-server="$(pwd)/fake.sendmail" \
831 grep "^utf8 body" msgtxt1 &&
832 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
835 test_expect_success
$PREREQ '--compose respects user mime type' '
836 clean_fake_sendmail &&
837 (echo "#!$SHELL_PATH" &&
838 echo "(echo MIME-Version: 1.0"
839 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
840 echo " echo Content-Transfer-Encoding: 8bit"
841 echo " echo Subject: foo"
843 echo " echo utf8 body: àéìöú) >\"\$1\""
844 ) >fake-editor-utf8-mime &&
845 chmod +x fake-editor-utf8-mime &&
846 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
848 --compose --subject foo \
849 --from="Example <nobody@example.com>" \
850 --to=nobody@example.com \
851 --smtp-server="$(pwd)/fake.sendmail" \
853 grep "^utf8 body" msgtxt1 &&
854 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
855 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
858 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
859 clean_fake_sendmail &&
860 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
862 --compose --subject utf8-sübjëct \
863 --from="Example <nobody@example.com>" \
864 --to=nobody@example.com \
865 --smtp-server="$(pwd)/fake.sendmail" \
867 grep "^fake edit" msgtxt1 &&
868 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
871 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
872 clean_fake_sendmail &&
873 test_commit weird_author &&
874 test_when_finished "git reset --hard HEAD^" &&
875 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
876 git format-patch --stdout -1 >funny_name.patch &&
877 git send-email --from="Example <nobody@example.com>" \
878 --to=nobody@example.com \
879 --smtp-server="$(pwd)/fake.sendmail" \
881 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
884 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
885 clean_fake_sendmail &&
886 git config sendemail.composeencoding iso-8859-1 &&
887 (echo "#!$SHELL_PATH" &&
888 echo "echo utf8 body: àéìöú >>\"\$1\""
889 ) >fake-editor-utf8 &&
890 chmod +x fake-editor-utf8 &&
891 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
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
902 test_expect_success
$PREREQ '--compose-encoding works' '
903 clean_fake_sendmail &&
904 (echo "#!$SHELL_PATH" &&
905 echo "echo utf8 body: àéìöú >>\"\$1\""
906 ) >fake-editor-utf8 &&
907 chmod +x fake-editor-utf8 &&
908 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
910 --compose-encoding iso-8859-1 \
911 --compose --subject foo \
912 --from="Example <nobody@example.com>" \
913 --to=nobody@example.com \
914 --smtp-server="$(pwd)/fake.sendmail" \
916 grep "^utf8 body" msgtxt1 &&
917 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
920 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
921 clean_fake_sendmail &&
922 git config sendemail.composeencoding iso-8859-1 &&
923 (echo "#!$SHELL_PATH" &&
924 echo "echo utf8 body: àéìöú >>\"\$1\""
925 ) >fake-editor-utf8 &&
926 chmod +x fake-editor-utf8 &&
927 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
929 --compose-encoding iso-8859-2 \
930 --compose --subject foo \
931 --from="Example <nobody@example.com>" \
932 --to=nobody@example.com \
933 --smtp-server="$(pwd)/fake.sendmail" \
935 grep "^utf8 body" msgtxt1 &&
936 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
939 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
940 clean_fake_sendmail &&
941 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
943 --compose-encoding iso-8859-2 \
944 --compose --subject utf8-sübjëct \
945 --from="Example <nobody@example.com>" \
946 --to=nobody@example.com \
947 --smtp-server="$(pwd)/fake.sendmail" \
949 grep "^fake edit" msgtxt1 &&
950 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
953 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
954 echo master > master &&
956 git commit -m"add master" &&
957 test_must_fail git send-email --dry-run master 2>errors &&
958 grep disambiguate errors
961 test_expect_success
$PREREQ 'feed two files' '
963 git format-patch -2 -o outdir &&
966 --from="Example <nobody@example.com>" \
967 --to=nobody@example.com \
968 outdir/000?-*.patch 2>errors >out &&
969 grep "^Subject: " out >subjects &&
970 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
971 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
974 test_expect_success
$PREREQ 'in-reply-to but no threading' '
977 --from="Example <nobody@example.com>" \
978 --to=nobody@example.com \
979 --in-reply-to="<in-reply-id@example.com>" \
982 grep "In-Reply-To: <in-reply-id@example.com>"
985 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
988 --from="Example <nobody@example.com>" \
989 --to=nobody@example.com \
991 $patches $patches >stdout &&
992 ! grep "In-Reply-To: " stdout
995 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
998 --from="Example <nobody@example.com>" \
999 --to=nobody@example.com \
1001 --nochain-reply-to \
1002 $patches $patches >stdout &&
1003 grep "In-Reply-To: " stdout
1006 test_expect_success
$PREREQ 'warning with an implicit --chain-reply-to' '
1009 --from="Example <nobody@example.com>" \
1010 --to=nobody@example.com \
1011 outdir/000?-*.patch 2>errors >out &&
1012 grep "no-chain-reply-to" errors
1015 test_expect_success
$PREREQ 'no warning with an explicit --chain-reply-to' '
1018 --from="Example <nobody@example.com>" \
1019 --to=nobody@example.com \
1021 outdir/000?-*.patch 2>errors >out &&
1022 ! grep "no-chain-reply-to" errors
1025 test_expect_success
$PREREQ 'no warning with an explicit --no-chain-reply-to' '
1028 --from="Example <nobody@example.com>" \
1029 --to=nobody@example.com \
1030 --nochain-reply-to \
1031 outdir/000?-*.patch 2>errors >out &&
1032 ! grep "no-chain-reply-to" errors
1035 test_expect_success
$PREREQ 'no warning with sendemail.chainreplyto = false' '
1036 git config sendemail.chainreplyto false &&
1039 --from="Example <nobody@example.com>" \
1040 --to=nobody@example.com \
1041 outdir/000?-*.patch 2>errors >out &&
1042 ! grep "no-chain-reply-to" errors
1045 test_expect_success
$PREREQ 'no warning with sendemail.chainreplyto = true' '
1046 git config sendemail.chainreplyto true &&
1049 --from="Example <nobody@example.com>" \
1050 --to=nobody@example.com \
1051 outdir/000?-*.patch 2>errors >out &&
1052 ! grep "no-chain-reply-to" errors
1055 test_expect_success
$PREREQ 'sendemail.to works' '
1056 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1059 --from="Example <nobody@example.com>" \
1060 $patches $patches >stdout &&
1061 grep "To: Somebody <somebody@ex.com>" stdout
1064 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1067 --from="Example <nobody@example.com>" \
1069 --to=nobody@example.com \
1070 $patches $patches >stdout &&
1071 grep "To: nobody@example.com" stdout &&
1072 ! grep "To: Somebody <somebody@ex.com>" stdout
1075 test_expect_success
$PREREQ 'sendemail.cc works' '
1076 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1079 --from="Example <nobody@example.com>" \
1080 --to=nobody@example.com \
1081 $patches $patches >stdout &&
1082 grep "Cc: Somebody <somebody@ex.com>" stdout
1085 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1088 --from="Example <nobody@example.com>" \
1090 --cc=bodies@example.com \
1091 --to=nobody@example.com \
1092 $patches $patches >stdout &&
1093 grep "Cc: bodies@example.com" stdout &&
1094 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1097 test_expect_success
$PREREQ 'sendemail.bcc works' '
1098 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1101 --from="Example <nobody@example.com>" \
1102 --to=nobody@example.com \
1103 --smtp-server relay.example.com \
1104 $patches $patches >stdout &&
1105 grep "RCPT TO:<other@ex.com>" stdout
1108 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1111 --from="Example <nobody@example.com>" \
1113 --bcc=bodies@example.com \
1114 --to=nobody@example.com \
1115 --smtp-server relay.example.com \
1116 $patches $patches >stdout &&
1117 grep "RCPT TO:<bodies@example.com>" stdout &&
1118 ! grep "RCPT TO:<other@ex.com>" stdout
1121 test_expect_success
$PREREQ 'patches To headers are used by default' '
1122 patch=`git format-patch -1 --to="bodies@example.com"` &&
1123 test_when_finished "rm $patch" &&
1126 --from="Example <nobody@example.com>" \
1127 --smtp-server relay.example.com \
1129 grep "RCPT TO:<bodies@example.com>" stdout
1132 test_expect_success
$PREREQ 'patches To headers are appended to' '
1133 patch=`git format-patch -1 --to="bodies@example.com"` &&
1134 test_when_finished "rm $patch" &&
1137 --from="Example <nobody@example.com>" \
1138 --to=nobody@example.com \
1139 --smtp-server relay.example.com \
1141 grep "RCPT TO:<bodies@example.com>" stdout &&
1142 grep "RCPT TO:<nobody@example.com>" stdout
1145 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1146 patch1=`git format-patch -1 --to="bodies@example.com"` &&
1147 patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1148 test_when_finished "rm $patch1 && rm $patch2" &&
1151 --from="Example <nobody@example.com>" \
1152 --to="nobody@example.com" \
1153 --smtp-server relay.example.com \
1154 $patch1 $patch2 >stdout &&
1155 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1156 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1157 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1160 test_expect_success
$PREREQ 'setup expect' '
1161 cat >email-using-8bit <<EOF
1162 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1163 Message-Id: <bogus-message-id@example.com>
1164 From: author@example.com
1165 Date: Sat, 12 Jun 2010 15:53:58 +0200
1166 Subject: subject goes here
1168 Dieser deutsche Text enthält einen Umlaut!
1172 test_expect_success
$PREREQ 'setup expect' '
1174 Subject: subject goes here
1178 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1179 clean_fake_sendmail &&
1181 git send-email --from=author@example.com --to=nobody@example.com \
1182 --smtp-server="$(pwd)/fake.sendmail" \
1183 --8bit-encoding=UTF-8 \
1184 email-using-8bit >stdout &&
1185 grep "Subject" msgtxt1 >actual &&
1186 test_cmp expected actual
1189 test_expect_success
$PREREQ 'setup expect' '
1190 cat >content-type-decl <<EOF
1192 Content-Type: text/plain; charset=UTF-8
1193 Content-Transfer-Encoding: 8bit
1197 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1198 clean_fake_sendmail &&
1200 git send-email --from=author@example.com --to=nobody@example.com \
1201 --smtp-server="$(pwd)/fake.sendmail" \
1202 email-using-8bit >stdout &&
1203 grep "do not declare a Content-Transfer-Encoding" stdout &&
1204 grep email-using-8bit stdout &&
1205 grep "Which 8bit encoding" stdout &&
1206 egrep "Content|MIME" msgtxt1 >actual &&
1207 test_cmp actual content-type-decl
1210 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1211 clean_fake_sendmail &&
1212 git config sendemail.assume8bitEncoding UTF-8 &&
1214 git send-email --from=author@example.com --to=nobody@example.com \
1215 --smtp-server="$(pwd)/fake.sendmail" \
1216 email-using-8bit >stdout &&
1217 egrep "Content|MIME" msgtxt1 >actual &&
1218 test_cmp actual content-type-decl
1221 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1222 clean_fake_sendmail &&
1223 git config sendemail.assume8bitEncoding "bogus too" &&
1225 git send-email --from=author@example.com --to=nobody@example.com \
1226 --smtp-server="$(pwd)/fake.sendmail" \
1227 --8bit-encoding=UTF-8 \
1228 email-using-8bit >stdout &&
1229 egrep "Content|MIME" msgtxt1 >actual &&
1230 test_cmp actual content-type-decl
1233 test_expect_success
$PREREQ 'setup expect' '
1234 cat >email-using-8bit <<EOF
1235 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1236 Message-Id: <bogus-message-id@example.com>
1237 From: author@example.com
1238 Date: Sat, 12 Jun 2010 15:53:58 +0200
1239 Subject: Dieser Betreff enthält auch einen Umlaut!
1241 Nothing to see here.
1245 test_expect_success
$PREREQ 'setup expect' '
1247 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1251 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1252 clean_fake_sendmail &&
1254 git send-email --from=author@example.com --to=nobody@example.com \
1255 --smtp-server="$(pwd)/fake.sendmail" \
1256 --8bit-encoding=UTF-8 \
1257 email-using-8bit >stdout &&
1258 grep "Subject" msgtxt1 >actual &&
1259 test_cmp expected actual
1262 # Note that the patches in this test are deliberately out of order; we
1263 # want to make sure it works even if the cover-letter is not in the
1265 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1266 clean_fake_sendmail &&
1268 git format-patch --cover-letter -2 -o outdir &&
1269 test_must_fail git send-email \
1270 --from="Example <nobody@example.com>" \
1271 --to=nobody@example.com \
1272 --smtp-server="$(pwd)/fake.sendmail" \
1273 outdir/0002-*.patch \
1274 outdir/0000-*.patch \
1275 outdir/0001-*.patch \
1277 grep "SUBJECT HERE" errors &&
1278 test -z "$(ls msgtxt*)"
1281 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1282 clean_fake_sendmail &&
1284 git format-patch --cover-letter -2 -o outdir &&
1287 --from="Example <nobody@example.com>" \
1288 --to=nobody@example.com \
1289 --smtp-server="$(pwd)/fake.sendmail" \
1290 outdir/0002-*.patch \
1291 outdir/0000-*.patch \
1292 outdir/0001-*.patch \
1294 ! grep "SUBJECT HERE" errors &&
1295 test -n "$(ls msgtxt*)"
1298 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
1299 clean_fake_sendmail &&
1300 echo "alias sbd somebody@example.org" >.mailrc &&
1301 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1302 git config sendemail.aliasfiletype mailrc &&
1304 --from="Example <nobody@example.com>" \
1306 --smtp-server="$(pwd)/fake.sendmail" \
1307 outdir/0001-*.patch \
1309 grep "^!somebody@example\.org!$" commandline1
1312 test_expect_success
$PREREQ 'sendemail.aliasfile=~/.mailrc' '
1313 clean_fake_sendmail &&
1314 echo "alias sbd someone@example.org" >~/.mailrc &&
1315 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1316 git config sendemail.aliasfiletype mailrc &&
1318 --from="Example <nobody@example.com>" \
1320 --smtp-server="$(pwd)/fake.sendmail" \
1321 outdir/0001-*.patch \
1323 grep "^!someone@example\.org!$" commandline1