3 test_description
='git send-email'
6 if ! test_have_prereq PERL
; then
7 say
'skipping git send-email tests, perl not available'
13 'prepare reference tree' \
14 'echo "1A quick brown fox jumps over the" >file &&
15 echo "lazy dog" >>file &&
17 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
21 '(echo "#!$SHELL_PATH"
24 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
27 echo " echo \"!\$a!\""
28 echo "done >commandline\$output"
29 echo "cat > msgtxt\$output"
31 chmod +x ./fake.sendmail &&
32 git add fake.sendmail &&
33 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
35 clean_fake_sendmail
() {
36 rm -f commandline
* msgtxt
*
39 test_expect_success
'Extract patches' '
40 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
43 # Test no confirm early to ensure remaining tests will not hang
47 GIT_SEND_EMAIL_NOTTY
=1 \
49 --from="Example <from@example.com>" \
50 --to=nobody@example.com \
51 --smtp-server="$(pwd)/fake.sendmail" \
54 test_must_fail
grep "Send this email" stdout
&&
58 # Exit immediately to prevent hang if a no-confirm test fails
60 test -f no_confirm_okay ||
{
61 say
'No confirm test failed; skipping remaining tests to prevent hanging'
66 test_expect_success
'No confirm with --suppress-cc' '
67 test_no_confirm --suppress-cc=sob
71 test_expect_success
'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
'No confirm with sendemail.confirm=never' '
79 git config sendemail.confirm never &&
80 test_no_confirm --compose --subject=foo
84 test_expect_success
'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
95 'Verify commandline' \
96 'test_cmp expected commandline1'
98 cat >expected-show-all-headers
<<\EOF
100 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
101 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
102 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
104 Server
: relay.example.com
105 MAIL FROM
:<from@example.com
>
106 RCPT TO
:<to@example.com
>
107 RCPT TO
:<cc@example.com
>
108 RCPT TO
:<author@example.com
>
109 RCPT TO
:<one@example.com
>
110 RCPT TO
:<two@example.com
>
111 RCPT TO
:<bcc@example.com
>
112 From
: Example
<from@example.com
>
115 A
<author@example.com
>,
116 One
<one@example.com
>,
118 Subject
: [PATCH
1/1] Second.
120 Message-Id
: MESSAGE-ID-STRING
121 X-Mailer
: X-MAILER-STRING
122 In-Reply-To
: <unique-message-id@example.com
>
123 References
: <unique-message-id@example.com
>
128 test_expect_success
'Show all headers' '
132 --from="Example <from@example.com>" \
133 --to=to@example.com \
134 --cc=cc@example.com \
135 --bcc=bcc@example.com \
136 --in-reply-to="<unique-message-id@example.com>" \
137 --smtp-server relay.example.com \
139 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
140 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
141 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
142 >actual-show-all-headers &&
143 test_cmp expected-show-all-headers actual-show-all-headers
146 test_expect_success
'Prompting works' '
147 clean_fake_sendmail &&
148 (echo "Example <from@example.com>"
149 echo "to@example.com"
151 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
152 --smtp-server="$(pwd)/fake.sendmail" \
155 grep "^From: Example <from@example.com>$" msgtxt1 &&
156 grep "^To: to@example.com$" msgtxt1
159 test_expect_success
'cccmd works' '
160 clean_fake_sendmail &&
161 cp $patches cccmd.patch &&
162 echo cccmd--cccmd@example.com >>cccmd.patch &&
165 echo sed -n -e s/^cccmd--//p \"\$1\"
167 chmod +x cccmd-sed &&
169 --from="Example <nobody@example.com>" \
170 --to=nobody@example.com \
171 --cc-cmd=./cccmd-sed \
172 --smtp-server="$(pwd)/fake.sendmail" \
175 grep "^ cccmd@example.com" msgtxt1
179 z64
=$z8$z8$z8$z8$z8$z8$z8$z8
180 z512
=$z64$z64$z64$z64$z64$z64$z64$z64
181 test_expect_success
'reject long lines' '
182 clean_fake_sendmail &&
183 cp $patches longline.patch &&
184 echo $z512$z512 >>longline.patch &&
185 test_must_fail git send-email \
186 --from="Example <nobody@example.com>" \
187 --to=nobody@example.com \
188 --smtp-server="$(pwd)/fake.sendmail" \
189 $patches longline.patch \
191 grep longline.patch errors
194 test_expect_success
'no patch was sent' '
195 ! test -e commandline1
198 test_expect_success
'Author From: in message body' '
199 clean_fake_sendmail &&
201 --from="Example <nobody@example.com>" \
202 --to=nobody@example.com \
203 --smtp-server="$(pwd)/fake.sendmail" \
205 sed "1,/^$/d" < msgtxt1 > msgbody1
206 grep "From: A <author@example.com>" msgbody1
209 test_expect_success
'Author From: not in message body' '
210 clean_fake_sendmail &&
212 --from="A <author@example.com>" \
213 --to=nobody@example.com \
214 --smtp-server="$(pwd)/fake.sendmail" \
216 sed "1,/^$/d" < msgtxt1 > msgbody1
217 ! grep "From: A <author@example.com>" msgbody1
220 test_expect_success
'allow long lines with --no-validate' '
222 --from="Example <nobody@example.com>" \
223 --to=nobody@example.com \
224 --smtp-server="$(pwd)/fake.sendmail" \
226 $patches longline.patch \
230 test_expect_success
'Invalid In-Reply-To' '
231 clean_fake_sendmail &&
233 --from="Example <nobody@example.com>" \
234 --to=nobody@example.com \
236 --smtp-server="$(pwd)/fake.sendmail" \
239 ! grep "^In-Reply-To: < *>" msgtxt1
242 test_expect_success
'Valid In-Reply-To when prompting' '
243 clean_fake_sendmail &&
244 (echo "From Example <from@example.com>"
245 echo "To Example <to@example.com>"
247 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
248 --smtp-server="$(pwd)/fake.sendmail" \
250 ! grep "^In-Reply-To: < *>" msgtxt1
253 test_expect_success
'setup fake editor' '
254 (echo "#!$SHELL_PATH" &&
255 echo "echo fake edit >>\"\$1\""
260 test_set_editor
"$(pwd)/fake-editor"
262 test_expect_success
'--compose works' '
263 clean_fake_sendmail &&
265 --compose --subject foo \
266 --from="Example <nobody@example.com>" \
267 --to=nobody@example.com \
268 --smtp-server="$(pwd)/fake.sendmail" \
273 test_expect_success
'first message is compose text' '
274 grep "^fake edit" msgtxt1
277 test_expect_success
'second message is patch' '
278 grep "Subject:.*Second" msgtxt2
281 cat >expected-suppress-sob
<<\EOF
283 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
284 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
285 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
287 Server
: relay.example.com
288 MAIL FROM
:<from@example.com
>
289 RCPT TO
:<to@example.com
>
290 RCPT TO
:<cc@example.com
>
291 RCPT TO
:<author@example.com
>
292 RCPT TO
:<one@example.com
>
293 RCPT TO
:<two@example.com
>
294 From
: Example
<from@example.com
>
297 A
<author@example.com
>,
298 One
<one@example.com
>,
300 Subject
: [PATCH
1/1] Second.
302 Message-Id
: MESSAGE-ID-STRING
303 X-Mailer
: X-MAILER-STRING
308 test_suppression
() {
311 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
312 --from="Example <from@example.com>" \
313 --to=to@example.com \
314 --smtp-server relay.example.com \
316 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
317 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
318 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
319 >actual-suppress-
$1${2+"-$2"} &&
320 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
323 test_expect_success
'sendemail.cc set' '
324 git config sendemail.cc cc@example.com &&
328 cat >expected-suppress-sob
<<\EOF
330 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
331 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
332 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
334 Server
: relay.example.com
335 MAIL FROM
:<from@example.com
>
336 RCPT TO
:<to@example.com
>
337 RCPT TO
:<author@example.com
>
338 RCPT TO
:<one@example.com
>
339 RCPT TO
:<two@example.com
>
340 From
: Example
<from@example.com
>
342 Cc
: A
<author@example.com
>,
343 One
<one@example.com
>,
345 Subject
: [PATCH
1/1] Second.
347 Message-Id
: MESSAGE-ID-STRING
348 X-Mailer
: X-MAILER-STRING
353 test_expect_success
'sendemail.cc unset' '
354 git config --unset sendemail.cc &&
358 cat >expected-suppress-cccmd
<<\EOF
360 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
361 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
362 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
363 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
365 Server
: relay.example.com
366 MAIL FROM
:<from@example.com
>
367 RCPT TO
:<to@example.com
>
368 RCPT TO
:<author@example.com
>
369 RCPT TO
:<one@example.com
>
370 RCPT TO
:<two@example.com
>
371 RCPT TO
:<committer@example.com
>
372 From
: Example
<from@example.com
>
374 Cc
: A
<author@example.com
>,
375 One
<one@example.com
>,
377 C O Mitter
<committer@example.com
>
378 Subject
: [PATCH
1/1] Second.
380 Message-Id
: MESSAGE-ID-STRING
381 X-Mailer
: X-MAILER-STRING
386 test_expect_success
'sendemail.cccmd' '
387 echo echo cc-cmd@example.com > cccmd &&
389 git config sendemail.cccmd ./cccmd &&
390 test_suppression cccmd
393 cat >expected-suppress-all
<<\EOF
396 Server
: relay.example.com
397 MAIL FROM
:<from@example.com
>
398 RCPT TO
:<to@example.com
>
399 From
: Example
<from@example.com
>
401 Subject
: [PATCH
1/1] Second.
403 Message-Id
: MESSAGE-ID-STRING
404 X-Mailer
: X-MAILER-STRING
409 test_expect_success
'--suppress-cc=all' '
413 cat >expected-suppress-body
<<\EOF
415 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
416 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
417 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
418 (cc-cmd
) Adding cc
: cc-cmd@example.com from
: './cccmd'
420 Server
: relay.example.com
421 MAIL FROM
:<from@example.com
>
422 RCPT TO
:<to@example.com
>
423 RCPT TO
:<author@example.com
>
424 RCPT TO
:<one@example.com
>
425 RCPT TO
:<two@example.com
>
426 RCPT TO
:<cc-cmd@example.com
>
427 From
: Example
<from@example.com
>
429 Cc
: A
<author@example.com
>,
430 One
<one@example.com
>,
433 Subject
: [PATCH
1/1] Second.
435 Message-Id
: MESSAGE-ID-STRING
436 X-Mailer
: X-MAILER-STRING
441 test_expect_success
'--suppress-cc=body' '
442 test_suppression body
445 cat >expected-suppress-body-cccmd
<<\EOF
447 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
448 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
449 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
451 Server
: relay.example.com
452 MAIL FROM
:<from@example.com
>
453 RCPT TO
:<to@example.com
>
454 RCPT TO
:<author@example.com
>
455 RCPT TO
:<one@example.com
>
456 RCPT TO
:<two@example.com
>
457 From
: Example
<from@example.com
>
459 Cc
: A
<author@example.com
>,
460 One
<one@example.com
>,
462 Subject
: [PATCH
1/1] Second.
464 Message-Id
: MESSAGE-ID-STRING
465 X-Mailer
: X-MAILER-STRING
470 test_expect_success
'--suppress-cc=body --suppress-cc=cccmd' '
471 test_suppression body cccmd
474 cat >expected-suppress-sob
<<\EOF
476 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
477 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
478 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
480 Server
: relay.example.com
481 MAIL FROM
:<from@example.com
>
482 RCPT TO
:<to@example.com
>
483 RCPT TO
:<author@example.com
>
484 RCPT TO
:<one@example.com
>
485 RCPT TO
:<two@example.com
>
486 From
: Example
<from@example.com
>
488 Cc
: A
<author@example.com
>,
489 One
<one@example.com
>,
491 Subject
: [PATCH
1/1] Second.
493 Message-Id
: MESSAGE-ID-STRING
494 X-Mailer
: X-MAILER-STRING
499 test_expect_success
'--suppress-cc=sob' '
500 git config --unset sendemail.cccmd
504 cat >expected-suppress-bodycc
<<\EOF
506 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
507 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
508 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
509 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
511 Server
: relay.example.com
512 MAIL FROM
:<from@example.com
>
513 RCPT TO
:<to@example.com
>
514 RCPT TO
:<author@example.com
>
515 RCPT TO
:<one@example.com
>
516 RCPT TO
:<two@example.com
>
517 RCPT TO
:<committer@example.com
>
518 From
: Example
<from@example.com
>
520 Cc
: A
<author@example.com
>,
521 One
<one@example.com
>,
523 C O Mitter
<committer@example.com
>
524 Subject
: [PATCH
1/1] Second.
526 Message-Id
: MESSAGE-ID-STRING
527 X-Mailer
: X-MAILER-STRING
532 test_expect_success
'--suppress-cc=bodycc' '
533 test_suppression bodycc
536 cat >expected-suppress-cc
<<\EOF
538 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
539 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
541 Server
: relay.example.com
542 MAIL FROM
:<from@example.com
>
543 RCPT TO
:<to@example.com
>
544 RCPT TO
:<author@example.com
>
545 RCPT TO
:<committer@example.com
>
546 From
: Example
<from@example.com
>
548 Cc
: A
<author@example.com
>,
549 C O Mitter
<committer@example.com
>
550 Subject
: [PATCH
1/1] Second.
552 Message-Id
: MESSAGE-ID-STRING
553 X-Mailer
: X-MAILER-STRING
558 test_expect_success
'--suppress-cc=cc' '
564 GIT_SEND_EMAIL_NOTTY
=1 \
566 --from="Example <nobody@example.com>" \
567 --to=nobody@example.com \
568 --smtp-server="$(pwd)/fake.sendmail" \
569 $@
$patches > stdout
&&
570 grep "Send this email" stdout
573 test_expect_success
'--confirm=always' '
574 test_confirm --confirm=always --suppress-cc=all
577 test_expect_success
'--confirm=auto' '
578 test_confirm --confirm=auto
581 test_expect_success
'--confirm=cc' '
582 test_confirm --confirm=cc
585 test_expect_success
'--confirm=compose' '
586 test_confirm --confirm=compose --compose
589 test_expect_success
'confirm by default (due to cc)' '
590 CONFIRM=$(git config --get sendemail.confirm) &&
591 git config --unset sendemail.confirm &&
594 git config sendemail.confirm ${CONFIRM:-never}
598 test_expect_success
'confirm by default (due to --compose)' '
599 CONFIRM=$(git config --get sendemail.confirm) &&
600 git config --unset sendemail.confirm &&
601 test_confirm --suppress-cc=all --compose
603 git config sendemail.confirm ${CONFIRM:-never}
607 test_expect_success
'confirm detects EOF (inform assumes y)' '
608 CONFIRM=$(git config --get sendemail.confirm) &&
609 git config --unset sendemail.confirm &&
611 git format-patch -2 -o outdir &&
612 GIT_SEND_EMAIL_NOTTY=1 \
614 --from="Example <nobody@example.com>" \
615 --to=nobody@example.com \
616 --smtp-server="$(pwd)/fake.sendmail" \
617 outdir/*.patch < /dev/null
619 git config sendemail.confirm ${CONFIRM:-never}
623 test_expect_success
'confirm detects EOF (auto causes failure)' '
624 CONFIRM=$(git config --get sendemail.confirm) &&
625 git config sendemail.confirm auto &&
626 GIT_SEND_EMAIL_NOTTY=1 &&
627 export GIT_SEND_EMAIL_NOTTY &&
628 test_must_fail git send-email \
629 --from="Example <nobody@example.com>" \
630 --to=nobody@example.com \
631 --smtp-server="$(pwd)/fake.sendmail" \
634 git config sendemail.confirm ${CONFIRM:-never}
638 test_expect_success
'confirm doesnt loop forever' '
639 CONFIRM=$(git config --get sendemail.confirm) &&
640 git config sendemail.confirm auto &&
641 GIT_SEND_EMAIL_NOTTY=1 &&
642 export GIT_SEND_EMAIL_NOTTY &&
643 yes "bogus" | test_must_fail git send-email \
644 --from="Example <nobody@example.com>" \
645 --to=nobody@example.com \
646 --smtp-server="$(pwd)/fake.sendmail" \
649 git config sendemail.confirm ${CONFIRM:-never}
653 test_expect_success
'utf8 Cc is rfc2047 encoded' '
654 clean_fake_sendmail &&
656 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
658 --from="Example <nobody@example.com>" \
659 --to=nobody@example.com \
660 --smtp-server="$(pwd)/fake.sendmail" \
663 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
666 test_expect_success
'--compose adds MIME for utf8 body' '
667 clean_fake_sendmail &&
668 (echo "#!$SHELL_PATH" &&
669 echo "echo utf8 body: àéìöú >>\"\$1\""
670 ) >fake-editor-utf8 &&
671 chmod +x fake-editor-utf8 &&
672 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
674 --compose --subject foo \
675 --from="Example <nobody@example.com>" \
676 --to=nobody@example.com \
677 --smtp-server="$(pwd)/fake.sendmail" \
679 grep "^utf8 body" msgtxt1 &&
680 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
683 test_expect_success
'--compose respects user mime type' '
684 clean_fake_sendmail &&
685 (echo "#!$SHELL_PATH" &&
686 echo "(echo MIME-Version: 1.0"
687 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
688 echo " echo Content-Transfer-Encoding: 8bit"
689 echo " echo Subject: foo"
691 echo " echo utf8 body: àéìöú) >\"\$1\""
692 ) >fake-editor-utf8-mime &&
693 chmod +x fake-editor-utf8-mime &&
694 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
696 --compose --subject foo \
697 --from="Example <nobody@example.com>" \
698 --to=nobody@example.com \
699 --smtp-server="$(pwd)/fake.sendmail" \
701 grep "^utf8 body" msgtxt1 &&
702 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
703 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
706 test_expect_success
'--compose adds MIME for utf8 subject' '
707 clean_fake_sendmail &&
708 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
710 --compose --subject utf8-sübjëct \
711 --from="Example <nobody@example.com>" \
712 --to=nobody@example.com \
713 --smtp-server="$(pwd)/fake.sendmail" \
715 grep "^fake edit" msgtxt1 &&
716 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
719 test_expect_success
'detects ambiguous reference/file conflict' '
720 echo master > master &&
722 git commit -m"add master" &&
723 test_must_fail git send-email --dry-run master 2>errors &&
724 grep disambiguate errors
727 test_expect_success
'feed two files' '
729 git format-patch -2 -o outdir &&
732 --from="Example <nobody@example.com>" \
733 --to=nobody@example.com \
734 outdir/000?-*.patch 2>errors >out &&
735 grep "^Subject: " out >subjects &&
736 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
737 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
740 test_expect_success
'in-reply-to but no threading' '
743 --from="Example <nobody@example.com>" \
744 --to=nobody@example.com \
745 --in-reply-to="<in-reply-id@example.com>" \
748 grep "In-Reply-To: <in-reply-id@example.com>"
751 test_expect_success
'no in-reply-to and no threading' '
754 --from="Example <nobody@example.com>" \
755 --to=nobody@example.com \
757 $patches $patches >stdout &&
758 ! grep "In-Reply-To: " stdout
761 test_expect_success
'threading but no chain-reply-to' '
764 --from="Example <nobody@example.com>" \
765 --to=nobody@example.com \
768 $patches $patches >stdout &&
769 grep "In-Reply-To: " stdout