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 &&
157 echo sed -n -e s/^cccmd--//p \"\$1\"
159 chmod +x cccmd-sed &&
161 --from="Example <nobody@example.com>" \
162 --to=nobody@example.com \
163 --cc-cmd=./cccmd-sed \
164 --smtp-server="$(pwd)/fake.sendmail" \
167 grep ^Cc:.*cccmd@example.com msgtxt1
171 z64
=$z8$z8$z8$z8$z8$z8$z8$z8
172 z512
=$z64$z64$z64$z64$z64$z64$z64$z64
173 test_expect_success
'reject long lines' '
174 clean_fake_sendmail &&
175 cp $patches longline.patch &&
176 echo $z512$z512 >>longline.patch &&
177 test_must_fail git send-email \
178 --from="Example <nobody@example.com>" \
179 --to=nobody@example.com \
180 --smtp-server="$(pwd)/fake.sendmail" \
181 $patches longline.patch \
183 grep longline.patch errors
186 test_expect_success
'no patch was sent' '
187 ! test -e commandline1
190 test_expect_success
'Author From: in message body' '
191 clean_fake_sendmail &&
193 --from="Example <nobody@example.com>" \
194 --to=nobody@example.com \
195 --smtp-server="$(pwd)/fake.sendmail" \
197 sed "1,/^$/d" < msgtxt1 > msgbody1
198 grep "From: A <author@example.com>" msgbody1
201 test_expect_success
'Author From: not in message body' '
202 clean_fake_sendmail &&
204 --from="A <author@example.com>" \
205 --to=nobody@example.com \
206 --smtp-server="$(pwd)/fake.sendmail" \
208 sed "1,/^$/d" < msgtxt1 > msgbody1
209 ! grep "From: A <author@example.com>" msgbody1
212 test_expect_success
'allow long lines with --no-validate' '
214 --from="Example <nobody@example.com>" \
215 --to=nobody@example.com \
216 --smtp-server="$(pwd)/fake.sendmail" \
218 $patches longline.patch \
222 test_expect_success
'Invalid In-Reply-To' '
223 clean_fake_sendmail &&
225 --from="Example <nobody@example.com>" \
226 --to=nobody@example.com \
228 --smtp-server="$(pwd)/fake.sendmail" \
231 ! grep "^In-Reply-To: < *>" msgtxt1
234 test_expect_success
'Valid In-Reply-To when prompting' '
235 clean_fake_sendmail &&
236 (echo "From Example <from@example.com>"
237 echo "To Example <to@example.com>"
239 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
240 --smtp-server="$(pwd)/fake.sendmail" \
242 ! grep "^In-Reply-To: < *>" msgtxt1
245 test_expect_success
'setup fake editor' '
246 (echo "#!$SHELL_PATH" &&
247 echo "echo fake edit >>\"\$1\""
252 test_set_editor
"$(pwd)/fake-editor"
254 test_expect_success
'--compose works' '
255 clean_fake_sendmail &&
257 --compose --subject foo \
258 --from="Example <nobody@example.com>" \
259 --to=nobody@example.com \
260 --smtp-server="$(pwd)/fake.sendmail" \
265 test_expect_success
'first message is compose text' '
266 grep "^fake edit" msgtxt1
269 test_expect_success
'second message is patch' '
270 grep "Subject:.*Second" msgtxt2
273 cat >expected-suppress-sob
<<\EOF
275 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
276 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
277 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
279 Server
: relay.example.com
280 MAIL FROM
:<from@example.com
>
281 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
282 From
: Example
<from@example.com
>
284 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
285 Subject
: [PATCH
1/1] Second.
287 Message-Id
: MESSAGE-ID-STRING
288 X-Mailer
: X-MAILER-STRING
293 test_suppression
() {
296 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
297 --from="Example <from@example.com>" \
298 --to=to@example.com \
299 --smtp-server relay.example.com \
301 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
302 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
303 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
304 >actual-suppress-
$1${2+"-$2"} &&
305 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
308 test_expect_success
'sendemail.cc set' '
309 git config sendemail.cc cc@example.com &&
313 cat >expected-suppress-sob
<<\EOF
315 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
316 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
317 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
319 Server
: relay.example.com
320 MAIL FROM
:<from@example.com
>
321 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
322 From
: Example
<from@example.com
>
324 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
325 Subject
: [PATCH
1/1] Second.
327 Message-Id
: MESSAGE-ID-STRING
328 X-Mailer
: X-MAILER-STRING
333 test_expect_success
'sendemail.cc unset' '
334 git config --unset sendemail.cc &&
338 cat >expected-suppress-cccmd
<<\EOF
340 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
341 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
342 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
343 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
345 Server
: relay.example.com
346 MAIL FROM
:<from@example.com
>
347 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
348 From
: Example
<from@example.com
>
350 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
351 Subject
: [PATCH
1/1] Second.
353 Message-Id
: MESSAGE-ID-STRING
354 X-Mailer
: X-MAILER-STRING
359 test_expect_success
'sendemail.cccmd' '
360 echo echo cc-cmd@example.com > cccmd &&
362 git config sendemail.cccmd ./cccmd &&
363 test_suppression cccmd
366 cat >expected-suppress-all
<<\EOF
369 Server
: relay.example.com
370 MAIL FROM
:<from@example.com
>
371 RCPT TO
:<to@example.com
>
372 From
: Example
<from@example.com
>
374 Subject
: [PATCH
1/1] Second.
376 Message-Id
: MESSAGE-ID-STRING
377 X-Mailer
: X-MAILER-STRING
382 test_expect_success
'--suppress-cc=all' '
386 cat >expected-suppress-body
<<\EOF
388 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
389 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
390 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
391 (cc-cmd
) Adding cc
: cc-cmd@example.com from
: './cccmd'
393 Server
: relay.example.com
394 MAIL FROM
:<from@example.com
>
395 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<cc-cmd@example.com
>
396 From
: Example
<from@example.com
>
398 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, cc-cmd@example.com
399 Subject
: [PATCH
1/1] Second.
401 Message-Id
: MESSAGE-ID-STRING
402 X-Mailer
: X-MAILER-STRING
407 test_expect_success
'--suppress-cc=body' '
408 test_suppression body
411 cat >expected-suppress-body-cccmd
<<\EOF
413 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
414 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
415 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
417 Server
: relay.example.com
418 MAIL FROM
:<from@example.com
>
419 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
420 From
: Example
<from@example.com
>
422 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
423 Subject
: [PATCH
1/1] Second.
425 Message-Id
: MESSAGE-ID-STRING
426 X-Mailer
: X-MAILER-STRING
431 test_expect_success
'--suppress-cc=body --suppress-cc=cccmd' '
432 test_suppression body cccmd
435 cat >expected-suppress-sob
<<\EOF
437 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
438 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
439 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
441 Server
: relay.example.com
442 MAIL FROM
:<from@example.com
>
443 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
444 From
: Example
<from@example.com
>
446 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
447 Subject
: [PATCH
1/1] Second.
449 Message-Id
: MESSAGE-ID-STRING
450 X-Mailer
: X-MAILER-STRING
455 test_expect_success
'--suppress-cc=sob' '
456 git config --unset sendemail.cccmd
460 cat >expected-suppress-bodycc
<<\EOF
462 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
463 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
464 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
465 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
467 Server
: relay.example.com
468 MAIL FROM
:<from@example.com
>
469 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
470 From
: Example
<from@example.com
>
472 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
473 Subject
: [PATCH
1/1] Second.
475 Message-Id
: MESSAGE-ID-STRING
476 X-Mailer
: X-MAILER-STRING
481 test_expect_success
'--suppress-cc=bodycc' '
482 test_suppression bodycc
485 cat >expected-suppress-cc
<<\EOF
487 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
488 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
490 Server
: relay.example.com
491 MAIL FROM
:<from@example.com
>
492 RCPT TO
:<to@example.com
>,<author@example.com
>,<committer@example.com
>
493 From
: Example
<from@example.com
>
495 Cc
: A
<author@example.com
>, C O Mitter
<committer@example.com
>
496 Subject
: [PATCH
1/1] Second.
498 Message-Id
: MESSAGE-ID-STRING
499 X-Mailer
: X-MAILER-STRING
504 test_expect_success
'--suppress-cc=cc' '
510 GIT_SEND_EMAIL_NOTTY
=1 \
512 --from="Example <nobody@example.com>" \
513 --to=nobody@example.com \
514 --smtp-server="$(pwd)/fake.sendmail" \
515 $@
$patches > stdout
&&
516 grep "Send this email" stdout
519 test_expect_success
'--confirm=always' '
520 test_confirm --confirm=always --suppress-cc=all
523 test_expect_success
'--confirm=auto' '
524 test_confirm --confirm=auto
527 test_expect_success
'--confirm=cc' '
528 test_confirm --confirm=cc
531 test_expect_success
'--confirm=compose' '
532 test_confirm --confirm=compose --compose
535 test_expect_success
'confirm by default (due to cc)' '
536 CONFIRM=$(git config --get sendemail.confirm) &&
537 git config --unset sendemail.confirm &&
540 git config sendemail.confirm ${CONFIRM:-never}
544 test_expect_success
'confirm by default (due to --compose)' '
545 CONFIRM=$(git config --get sendemail.confirm) &&
546 git config --unset sendemail.confirm &&
547 test_confirm --suppress-cc=all --compose
549 git config sendemail.confirm ${CONFIRM:-never}
553 test_expect_success
'confirm detects EOF (inform assumes y)' '
554 CONFIRM=$(git config --get sendemail.confirm) &&
555 git config --unset sendemail.confirm &&
557 git format-patch -2 -o outdir &&
558 GIT_SEND_EMAIL_NOTTY=1 \
560 --from="Example <nobody@example.com>" \
561 --to=nobody@example.com \
562 --smtp-server="$(pwd)/fake.sendmail" \
563 outdir/*.patch < /dev/null
565 git config sendemail.confirm ${CONFIRM:-never}
569 test_expect_success
'confirm detects EOF (auto causes failure)' '
570 CONFIRM=$(git config --get sendemail.confirm) &&
571 git config sendemail.confirm auto &&
572 GIT_SEND_EMAIL_NOTTY=1 &&
573 export GIT_SEND_EMAIL_NOTTY &&
574 test_must_fail git send-email \
575 --from="Example <nobody@example.com>" \
576 --to=nobody@example.com \
577 --smtp-server="$(pwd)/fake.sendmail" \
580 git config sendemail.confirm ${CONFIRM:-never}
584 test_expect_success
'confirm doesnt loop forever' '
585 CONFIRM=$(git config --get sendemail.confirm) &&
586 git config sendemail.confirm auto &&
587 GIT_SEND_EMAIL_NOTTY=1 &&
588 export GIT_SEND_EMAIL_NOTTY &&
589 yes "bogus" | test_must_fail git send-email \
590 --from="Example <nobody@example.com>" \
591 --to=nobody@example.com \
592 --smtp-server="$(pwd)/fake.sendmail" \
595 git config sendemail.confirm ${CONFIRM:-never}
599 test_expect_success
'utf8 Cc is rfc2047 encoded' '
600 clean_fake_sendmail &&
602 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
604 --from="Example <nobody@example.com>" \
605 --to=nobody@example.com \
606 --smtp-server="$(pwd)/fake.sendmail" \
608 grep "^Cc:" msgtxt1 |
609 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
612 test_expect_success
'--compose adds MIME for utf8 body' '
613 clean_fake_sendmail &&
614 (echo "#!$SHELL_PATH" &&
615 echo "echo utf8 body: àéìöú >>\"\$1\""
616 ) >fake-editor-utf8 &&
617 chmod +x fake-editor-utf8 &&
618 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
620 --compose --subject foo \
621 --from="Example <nobody@example.com>" \
622 --to=nobody@example.com \
623 --smtp-server="$(pwd)/fake.sendmail" \
625 grep "^utf8 body" msgtxt1 &&
626 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
629 test_expect_success
'--compose respects user mime type' '
630 clean_fake_sendmail &&
631 (echo "#!$SHELL_PATH" &&
632 echo "(echo MIME-Version: 1.0"
633 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
634 echo " echo Content-Transfer-Encoding: 8bit"
635 echo " echo Subject: foo"
637 echo " echo utf8 body: àéìöú) >\"\$1\""
638 ) >fake-editor-utf8-mime &&
639 chmod +x fake-editor-utf8-mime &&
640 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
642 --compose --subject foo \
643 --from="Example <nobody@example.com>" \
644 --to=nobody@example.com \
645 --smtp-server="$(pwd)/fake.sendmail" \
647 grep "^utf8 body" msgtxt1 &&
648 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
649 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
652 test_expect_success
'--compose adds MIME for utf8 subject' '
653 clean_fake_sendmail &&
654 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
656 --compose --subject utf8-sübjëct \
657 --from="Example <nobody@example.com>" \
658 --to=nobody@example.com \
659 --smtp-server="$(pwd)/fake.sendmail" \
661 grep "^fake edit" msgtxt1 &&
662 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
665 test_expect_success
'detects ambiguous reference/file conflict' '
666 echo master > master &&
668 git commit -m"add master" &&
669 test_must_fail git send-email --dry-run master 2>errors &&
670 grep disambiguate errors
673 test_expect_success
'feed two files' '
675 git format-patch -2 -o outdir &&
678 --from="Example <nobody@example.com>" \
679 --to=nobody@example.com \
680 outdir/000?-*.patch 2>errors >out &&
681 grep "^Subject: " out >subjects &&
682 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
683 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
686 test_expect_success
'in-reply-to but no threading' '
689 --from="Example <nobody@example.com>" \
690 --to=nobody@example.com \
691 --in-reply-to="<in-reply-id@example.com>" \
694 grep "In-Reply-To: <in-reply-id@example.com>"
697 test_expect_success
'no in-reply-to and no threading' '
700 --from="Example <nobody@example.com>" \
701 --to=nobody@example.com \
703 $patches $patches >stdout &&
704 ! grep "In-Reply-To: " stdout
707 test_expect_success
'threading but no chain-reply-to' '
710 --from="Example <nobody@example.com>" \
711 --to=nobody@example.com \
714 $patches $patches >stdout &&
715 grep "In-Reply-To: " stdout