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
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<bcc@example.com
>
107 From
: Example
<from@example.com
>
109 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
110 Subject
: [PATCH
1/1] Second.
112 Message-Id
: MESSAGE-ID-STRING
113 X-Mailer
: X-MAILER-STRING
114 In-Reply-To
: <unique-message-id@example.com
>
115 References
: <unique-message-id@example.com
>
120 test_expect_success
'Show all headers' '
124 --from="Example <from@example.com>" \
125 --to=to@example.com \
126 --cc=cc@example.com \
127 --bcc=bcc@example.com \
128 --in-reply-to="<unique-message-id@example.com>" \
129 --smtp-server relay.example.com \
131 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
132 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
133 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
134 >actual-show-all-headers &&
135 test_cmp expected-show-all-headers actual-show-all-headers
138 test_expect_success
'Prompting works' '
139 clean_fake_sendmail &&
140 (echo "Example <from@example.com>"
141 echo "to@example.com"
143 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
144 --smtp-server="$(pwd)/fake.sendmail" \
147 grep "^From: Example <from@example.com>$" msgtxt1 &&
148 grep "^To: to@example.com$" msgtxt1
151 test_expect_success
'cccmd works' '
152 clean_fake_sendmail &&
153 cp $patches cccmd.patch &&
154 echo cccmd--cccmd@example.com >>cccmd.patch &&
155 echo sed -n s/^cccmd--//p \"\$1\" > cccmd-sed &&
156 chmod +x cccmd-sed &&
158 --from="Example <nobody@example.com>" \
159 --to=nobody@example.com \
160 --cc-cmd=./cccmd-sed \
161 --smtp-server="$(pwd)/fake.sendmail" \
164 grep ^Cc:.*cccmd@example.com msgtxt1
168 z64
=$z8$z8$z8$z8$z8$z8$z8$z8
169 z512
=$z64$z64$z64$z64$z64$z64$z64$z64
170 test_expect_success
'reject long lines' '
171 clean_fake_sendmail &&
172 cp $patches longline.patch &&
173 echo $z512$z512 >>longline.patch &&
174 test_must_fail git send-email \
175 --from="Example <nobody@example.com>" \
176 --to=nobody@example.com \
177 --smtp-server="$(pwd)/fake.sendmail" \
178 $patches longline.patch \
180 grep longline.patch errors
183 test_expect_success
'no patch was sent' '
184 ! test -e commandline1
187 test_expect_success
'Author From: in message body' '
188 clean_fake_sendmail &&
190 --from="Example <nobody@example.com>" \
191 --to=nobody@example.com \
192 --smtp-server="$(pwd)/fake.sendmail" \
194 sed "1,/^$/d" < msgtxt1 > msgbody1
195 grep "From: A <author@example.com>" msgbody1
198 test_expect_success
'Author From: not in message body' '
199 clean_fake_sendmail &&
201 --from="A <author@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
'allow long lines with --no-validate' '
211 --from="Example <nobody@example.com>" \
212 --to=nobody@example.com \
213 --smtp-server="$(pwd)/fake.sendmail" \
215 $patches longline.patch \
219 test_expect_success
'Invalid In-Reply-To' '
220 clean_fake_sendmail &&
222 --from="Example <nobody@example.com>" \
223 --to=nobody@example.com \
225 --smtp-server="$(pwd)/fake.sendmail" \
228 ! grep "^In-Reply-To: < *>" msgtxt1
231 test_expect_success
'Valid In-Reply-To when prompting' '
232 clean_fake_sendmail &&
233 (echo "From Example <from@example.com>"
234 echo "To Example <to@example.com>"
236 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
237 --smtp-server="$(pwd)/fake.sendmail" \
239 ! grep "^In-Reply-To: < *>" msgtxt1
242 test_expect_success
'setup fake editor' '
243 (echo "#!$SHELL_PATH" &&
244 echo "echo fake edit >>\"\$1\""
249 test_set_editor
"$(pwd)/fake-editor"
251 test_expect_success
'--compose works' '
252 clean_fake_sendmail &&
254 --compose --subject foo \
255 --from="Example <nobody@example.com>" \
256 --to=nobody@example.com \
257 --smtp-server="$(pwd)/fake.sendmail" \
262 test_expect_success
'first message is compose text' '
263 grep "^fake edit" msgtxt1
266 test_expect_success
'second message is patch' '
267 grep "Subject:.*Second" msgtxt2
270 cat >expected-suppress-sob
<<\EOF
272 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
273 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
274 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
276 Server
: relay.example.com
277 MAIL FROM
:<from@example.com
>
278 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
279 From
: Example
<from@example.com
>
281 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
282 Subject
: [PATCH
1/1] Second.
284 Message-Id
: MESSAGE-ID-STRING
285 X-Mailer
: X-MAILER-STRING
290 test_suppression
() {
293 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
294 --from="Example <from@example.com>" \
295 --to=to@example.com \
296 --smtp-server relay.example.com \
298 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
299 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
300 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
301 >actual-suppress-
$1${2+"-$2"} &&
302 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
305 test_expect_success
'sendemail.cc set' '
306 git config sendemail.cc cc@example.com &&
310 cat >expected-suppress-sob
<<\EOF
312 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
313 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
314 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
316 Server
: relay.example.com
317 MAIL FROM
:<from@example.com
>
318 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
319 From
: Example
<from@example.com
>
321 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
322 Subject
: [PATCH
1/1] Second.
324 Message-Id
: MESSAGE-ID-STRING
325 X-Mailer
: X-MAILER-STRING
330 test_expect_success
'sendemail.cc unset' '
331 git config --unset sendemail.cc &&
335 cat >expected-suppress-cccmd
<<\EOF
337 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
338 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
339 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
340 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
342 Server
: relay.example.com
343 MAIL FROM
:<from@example.com
>
344 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
345 From
: Example
<from@example.com
>
347 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
348 Subject
: [PATCH
1/1] Second.
350 Message-Id
: MESSAGE-ID-STRING
351 X-Mailer
: X-MAILER-STRING
356 test_expect_success
'sendemail.cccmd' '
357 echo echo cc-cmd@example.com > cccmd &&
359 git config sendemail.cccmd ./cccmd &&
360 test_suppression cccmd
363 cat >expected-suppress-all
<<\EOF
366 Server
: relay.example.com
367 MAIL FROM
:<from@example.com
>
368 RCPT TO
:<to@example.com
>
369 From
: Example
<from@example.com
>
371 Subject
: [PATCH
1/1] Second.
373 Message-Id
: MESSAGE-ID-STRING
374 X-Mailer
: X-MAILER-STRING
379 test_expect_success
'--suppress-cc=all' '
383 cat >expected-suppress-body
<<\EOF
385 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
386 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
387 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
388 (cc-cmd
) Adding cc
: cc-cmd@example.com from
: './cccmd'
390 Server
: relay.example.com
391 MAIL FROM
:<from@example.com
>
392 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<cc-cmd@example.com
>
393 From
: Example
<from@example.com
>
395 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, cc-cmd@example.com
396 Subject
: [PATCH
1/1] Second.
398 Message-Id
: MESSAGE-ID-STRING
399 X-Mailer
: X-MAILER-STRING
404 test_expect_success
'--suppress-cc=body' '
405 test_suppression body
408 cat >expected-suppress-body-cccmd
<<\EOF
410 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
411 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
412 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
414 Server
: relay.example.com
415 MAIL FROM
:<from@example.com
>
416 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
417 From
: Example
<from@example.com
>
419 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
420 Subject
: [PATCH
1/1] Second.
422 Message-Id
: MESSAGE-ID-STRING
423 X-Mailer
: X-MAILER-STRING
428 test_expect_success
'--suppress-cc=body --suppress-cc=cccmd' '
429 test_suppression body cccmd
432 cat >expected-suppress-sob
<<\EOF
434 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
435 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
436 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
438 Server
: relay.example.com
439 MAIL FROM
:<from@example.com
>
440 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
441 From
: Example
<from@example.com
>
443 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
444 Subject
: [PATCH
1/1] Second.
446 Message-Id
: MESSAGE-ID-STRING
447 X-Mailer
: X-MAILER-STRING
452 test_expect_success
'--suppress-cc=sob' '
453 git config --unset sendemail.cccmd
457 cat >expected-suppress-bodycc
<<\EOF
459 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
460 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
461 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
462 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
464 Server
: relay.example.com
465 MAIL FROM
:<from@example.com
>
466 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
467 From
: Example
<from@example.com
>
469 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
470 Subject
: [PATCH
1/1] Second.
472 Message-Id
: MESSAGE-ID-STRING
473 X-Mailer
: X-MAILER-STRING
478 test_expect_success
'--suppress-cc=bodycc' '
479 test_suppression bodycc
482 cat >expected-suppress-cc
<<\EOF
484 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
485 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
487 Server
: relay.example.com
488 MAIL FROM
:<from@example.com
>
489 RCPT TO
:<to@example.com
>,<author@example.com
>,<committer@example.com
>
490 From
: Example
<from@example.com
>
492 Cc
: A
<author@example.com
>, C O Mitter
<committer@example.com
>
493 Subject
: [PATCH
1/1] Second.
495 Message-Id
: MESSAGE-ID-STRING
496 X-Mailer
: X-MAILER-STRING
501 test_expect_success
'--suppress-cc=cc' '
507 GIT_SEND_EMAIL_NOTTY
=1 \
509 --from="Example <nobody@example.com>" \
510 --to=nobody@example.com \
511 --smtp-server="$(pwd)/fake.sendmail" \
512 $@
$patches > stdout
&&
513 grep "Send this email" stdout
516 test_expect_success
'--confirm=always' '
517 test_confirm --confirm=always --suppress-cc=all
520 test_expect_success
'--confirm=auto' '
521 test_confirm --confirm=auto
524 test_expect_success
'--confirm=cc' '
525 test_confirm --confirm=cc
528 test_expect_success
'--confirm=compose' '
529 test_confirm --confirm=compose --compose
532 test_expect_success
'confirm by default (due to cc)' '
533 CONFIRM=$(git config --get sendemail.confirm) &&
534 git config --unset sendemail.confirm &&
537 git config sendemail.confirm ${CONFIRM:-never}
541 test_expect_success
'confirm by default (due to --compose)' '
542 CONFIRM=$(git config --get sendemail.confirm) &&
543 git config --unset sendemail.confirm &&
544 test_confirm --suppress-cc=all --compose
546 git config sendemail.confirm ${CONFIRM:-never}
550 test_expect_success
'confirm detects EOF (inform assumes y)' '
551 CONFIRM=$(git config --get sendemail.confirm) &&
552 git config --unset sendemail.confirm &&
554 git format-patch -2 -o outdir &&
555 GIT_SEND_EMAIL_NOTTY=1 \
557 --from="Example <nobody@example.com>" \
558 --to=nobody@example.com \
559 --smtp-server="$(pwd)/fake.sendmail" \
560 outdir/*.patch < /dev/null
562 git config sendemail.confirm ${CONFIRM:-never}
566 test_expect_success
'confirm detects EOF (auto causes failure)' '
567 CONFIRM=$(git config --get sendemail.confirm) &&
568 git config sendemail.confirm auto &&
569 GIT_SEND_EMAIL_NOTTY=1 &&
570 export GIT_SEND_EMAIL_NOTTY &&
571 test_must_fail git send-email \
572 --from="Example <nobody@example.com>" \
573 --to=nobody@example.com \
574 --smtp-server="$(pwd)/fake.sendmail" \
577 git config sendemail.confirm ${CONFIRM:-never}
581 test_expect_success
'confirm doesnt loop forever' '
582 CONFIRM=$(git config --get sendemail.confirm) &&
583 git config sendemail.confirm auto &&
584 GIT_SEND_EMAIL_NOTTY=1 &&
585 export GIT_SEND_EMAIL_NOTTY &&
586 yes "bogus" | test_must_fail git send-email \
587 --from="Example <nobody@example.com>" \
588 --to=nobody@example.com \
589 --smtp-server="$(pwd)/fake.sendmail" \
592 git config sendemail.confirm ${CONFIRM:-never}
596 test_expect_success
'utf8 Cc is rfc2047 encoded' '
597 clean_fake_sendmail &&
599 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
601 --from="Example <nobody@example.com>" \
602 --to=nobody@example.com \
603 --smtp-server="$(pwd)/fake.sendmail" \
605 grep "^Cc:" msgtxt1 |
606 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
609 test_expect_success
'--compose adds MIME for utf8 body' '
610 clean_fake_sendmail &&
611 (echo "#!$SHELL_PATH" &&
612 echo "echo utf8 body: àéìöú >>\"\$1\""
613 ) >fake-editor-utf8 &&
614 chmod +x fake-editor-utf8 &&
615 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
617 --compose --subject foo \
618 --from="Example <nobody@example.com>" \
619 --to=nobody@example.com \
620 --smtp-server="$(pwd)/fake.sendmail" \
622 grep "^utf8 body" msgtxt1 &&
623 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
626 test_expect_success
'--compose respects user mime type' '
627 clean_fake_sendmail &&
628 (echo "#!$SHELL_PATH" &&
629 echo "(echo MIME-Version: 1.0"
630 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
631 echo " echo Content-Transfer-Encoding: 8bit"
632 echo " echo Subject: foo"
634 echo " echo utf8 body: àéìöú) >\"\$1\""
635 ) >fake-editor-utf8-mime &&
636 chmod +x fake-editor-utf8-mime &&
637 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
639 --compose --subject foo \
640 --from="Example <nobody@example.com>" \
641 --to=nobody@example.com \
642 --smtp-server="$(pwd)/fake.sendmail" \
644 grep "^utf8 body" msgtxt1 &&
645 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
646 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
649 test_expect_success
'--compose adds MIME for utf8 subject' '
650 clean_fake_sendmail &&
651 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
653 --compose --subject utf8-sübjëct \
654 --from="Example <nobody@example.com>" \
655 --to=nobody@example.com \
656 --smtp-server="$(pwd)/fake.sendmail" \
658 grep "^fake edit" msgtxt1 &&
659 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
662 test_expect_success
'detects ambiguous reference/file conflict' '
663 echo master > master &&
665 git commit -m"add master" &&
666 test_must_fail git send-email --dry-run master 2>errors &&
667 grep disambiguate errors
670 test_expect_success
'feed two files' '
672 git format-patch -2 -o outdir &&
675 --from="Example <nobody@example.com>" \
676 --to=nobody@example.com \
677 outdir/000?-*.patch 2>errors >out &&
678 grep "^Subject: " out >subjects &&
679 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
680 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
683 test_expect_success
'in-reply-to but no threading' '
686 --from="Example <nobody@example.com>" \
687 --to=nobody@example.com \
688 --in-reply-to="<in-reply-id@example.com>" \
691 grep "In-Reply-To: <in-reply-id@example.com>"
694 test_expect_success
'no in-reply-to and no threading' '
697 --from="Example <nobody@example.com>" \
698 --to=nobody@example.com \
700 $patches $patches >stdout &&
701 ! grep "In-Reply-To: " stdout
704 test_expect_success
'threading but no chain-reply-to' '
707 --from="Example <nobody@example.com>" \
708 --to=nobody@example.com \
711 $patches $patches >stdout &&
712 grep "In-Reply-To: " stdout