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 test_expect_success
'Send patches with --envelope-sender' '
99 clean_fake_sendmail &&
100 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
111 test_expect_success \
112 'Verify commandline' \
113 'test_cmp expected commandline1'
115 cat >expected-show-all-headers
<<\EOF
117 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
118 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
119 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
121 Server
: relay.example.com
122 MAIL FROM
:<from@example.com
>
123 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<bcc@example.com
>
124 From
: Example
<from@example.com
>
126 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
127 Subject
: [PATCH
1/1] Second.
129 Message-Id
: MESSAGE-ID-STRING
130 X-Mailer
: X-MAILER-STRING
131 In-Reply-To
: <unique-message-id@example.com
>
132 References
: <unique-message-id@example.com
>
137 test_expect_success
'Show all headers' '
141 --from="Example <from@example.com>" \
142 --to=to@example.com \
143 --cc=cc@example.com \
144 --bcc=bcc@example.com \
145 --in-reply-to="<unique-message-id@example.com>" \
146 --smtp-server relay.example.com \
148 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
149 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
150 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
151 >actual-show-all-headers &&
152 test_cmp expected-show-all-headers actual-show-all-headers
155 test_expect_success
'Prompting works' '
156 clean_fake_sendmail &&
157 (echo "Example <from@example.com>"
158 echo "to@example.com"
160 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
161 --smtp-server="$(pwd)/fake.sendmail" \
164 grep "^From: Example <from@example.com>$" msgtxt1 &&
165 grep "^To: to@example.com$" msgtxt1
168 test_expect_success
'cccmd works' '
169 clean_fake_sendmail &&
170 cp $patches cccmd.patch &&
171 echo cccmd--cccmd@example.com >>cccmd.patch &&
174 echo sed -n -e s/^cccmd--//p \"\$1\"
176 chmod +x cccmd-sed &&
178 --from="Example <nobody@example.com>" \
179 --to=nobody@example.com \
180 --cc-cmd=./cccmd-sed \
181 --smtp-server="$(pwd)/fake.sendmail" \
184 grep ^Cc:.*cccmd@example.com msgtxt1
188 z64
=$z8$z8$z8$z8$z8$z8$z8$z8
189 z512
=$z64$z64$z64$z64$z64$z64$z64$z64
190 test_expect_success
'reject long lines' '
191 clean_fake_sendmail &&
192 cp $patches longline.patch &&
193 echo $z512$z512 >>longline.patch &&
194 test_must_fail git send-email \
195 --from="Example <nobody@example.com>" \
196 --to=nobody@example.com \
197 --smtp-server="$(pwd)/fake.sendmail" \
198 $patches longline.patch \
200 grep longline.patch errors
203 test_expect_success
'no patch was sent' '
204 ! test -e commandline1
207 test_expect_success
'Author From: in message body' '
208 clean_fake_sendmail &&
210 --from="Example <nobody@example.com>" \
211 --to=nobody@example.com \
212 --smtp-server="$(pwd)/fake.sendmail" \
214 sed "1,/^$/d" < msgtxt1 > msgbody1
215 grep "From: A <author@example.com>" msgbody1
218 test_expect_success
'Author From: not in message body' '
219 clean_fake_sendmail &&
221 --from="A <author@example.com>" \
222 --to=nobody@example.com \
223 --smtp-server="$(pwd)/fake.sendmail" \
225 sed "1,/^$/d" < msgtxt1 > msgbody1
226 ! grep "From: A <author@example.com>" msgbody1
229 test_expect_success
'allow long lines with --no-validate' '
231 --from="Example <nobody@example.com>" \
232 --to=nobody@example.com \
233 --smtp-server="$(pwd)/fake.sendmail" \
235 $patches longline.patch \
239 test_expect_success
'Invalid In-Reply-To' '
240 clean_fake_sendmail &&
242 --from="Example <nobody@example.com>" \
243 --to=nobody@example.com \
245 --smtp-server="$(pwd)/fake.sendmail" \
248 ! grep "^In-Reply-To: < *>" msgtxt1
251 test_expect_success
'Valid In-Reply-To when prompting' '
252 clean_fake_sendmail &&
253 (echo "From Example <from@example.com>"
254 echo "To Example <to@example.com>"
256 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
257 --smtp-server="$(pwd)/fake.sendmail" \
259 ! grep "^In-Reply-To: < *>" msgtxt1
262 test_expect_success
'setup fake editor' '
263 (echo "#!$SHELL_PATH" &&
264 echo "echo fake edit >>\"\$1\""
269 test_set_editor
"$(pwd)/fake-editor"
271 test_expect_success
'--compose works' '
272 clean_fake_sendmail &&
274 --compose --subject foo \
275 --from="Example <nobody@example.com>" \
276 --to=nobody@example.com \
277 --smtp-server="$(pwd)/fake.sendmail" \
282 test_expect_success
'first message is compose text' '
283 grep "^fake edit" msgtxt1
286 test_expect_success
'second message is patch' '
287 grep "Subject:.*Second" msgtxt2
290 cat >expected-suppress-sob
<<\EOF
292 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
293 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
294 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
296 Server
: relay.example.com
297 MAIL FROM
:<from@example.com
>
298 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
299 From
: Example
<from@example.com
>
301 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
302 Subject
: [PATCH
1/1] Second.
304 Message-Id
: MESSAGE-ID-STRING
305 X-Mailer
: X-MAILER-STRING
310 test_suppression
() {
313 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
314 --from="Example <from@example.com>" \
315 --to=to@example.com \
316 --smtp-server relay.example.com \
318 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
319 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
320 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
321 >actual-suppress-
$1${2+"-$2"} &&
322 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
325 test_expect_success
'sendemail.cc set' '
326 git config sendemail.cc cc@example.com &&
330 cat >expected-suppress-sob
<<\EOF
332 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
333 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
334 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
336 Server
: relay.example.com
337 MAIL FROM
:<from@example.com
>
338 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
339 From
: Example
<from@example.com
>
341 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
342 Subject
: [PATCH
1/1] Second.
344 Message-Id
: MESSAGE-ID-STRING
345 X-Mailer
: X-MAILER-STRING
350 test_expect_success
'sendemail.cc unset' '
351 git config --unset sendemail.cc &&
355 cat >expected-suppress-cccmd
<<\EOF
357 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
358 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
359 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
360 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
362 Server
: relay.example.com
363 MAIL FROM
:<from@example.com
>
364 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
365 From
: Example
<from@example.com
>
367 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
368 Subject
: [PATCH
1/1] Second.
370 Message-Id
: MESSAGE-ID-STRING
371 X-Mailer
: X-MAILER-STRING
376 test_expect_success
'sendemail.cccmd' '
377 echo echo cc-cmd@example.com > cccmd &&
379 git config sendemail.cccmd ./cccmd &&
380 test_suppression cccmd
383 cat >expected-suppress-all
<<\EOF
386 Server
: relay.example.com
387 MAIL FROM
:<from@example.com
>
388 RCPT TO
:<to@example.com
>
389 From
: Example
<from@example.com
>
391 Subject
: [PATCH
1/1] Second.
393 Message-Id
: MESSAGE-ID-STRING
394 X-Mailer
: X-MAILER-STRING
399 test_expect_success
'--suppress-cc=all' '
403 cat >expected-suppress-body
<<\EOF
405 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
406 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
407 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
408 (cc-cmd
) Adding cc
: cc-cmd@example.com from
: './cccmd'
410 Server
: relay.example.com
411 MAIL FROM
:<from@example.com
>
412 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<cc-cmd@example.com
>
413 From
: Example
<from@example.com
>
415 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, cc-cmd@example.com
416 Subject
: [PATCH
1/1] Second.
418 Message-Id
: MESSAGE-ID-STRING
419 X-Mailer
: X-MAILER-STRING
424 test_expect_success
'--suppress-cc=body' '
425 test_suppression body
428 cat >expected-suppress-body-cccmd
<<\EOF
430 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
431 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
432 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
434 Server
: relay.example.com
435 MAIL FROM
:<from@example.com
>
436 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
437 From
: Example
<from@example.com
>
439 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
440 Subject
: [PATCH
1/1] Second.
442 Message-Id
: MESSAGE-ID-STRING
443 X-Mailer
: X-MAILER-STRING
448 test_expect_success
'--suppress-cc=body --suppress-cc=cccmd' '
449 test_suppression body cccmd
452 cat >expected-suppress-sob
<<\EOF
454 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
455 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
456 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
458 Server
: relay.example.com
459 MAIL FROM
:<from@example.com
>
460 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
461 From
: Example
<from@example.com
>
463 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
464 Subject
: [PATCH
1/1] Second.
466 Message-Id
: MESSAGE-ID-STRING
467 X-Mailer
: X-MAILER-STRING
472 test_expect_success
'--suppress-cc=sob' '
473 git config --unset sendemail.cccmd
477 cat >expected-suppress-bodycc
<<\EOF
479 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
480 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
481 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
482 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
484 Server
: relay.example.com
485 MAIL FROM
:<from@example.com
>
486 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
487 From
: Example
<from@example.com
>
489 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
490 Subject
: [PATCH
1/1] Second.
492 Message-Id
: MESSAGE-ID-STRING
493 X-Mailer
: X-MAILER-STRING
498 test_expect_success
'--suppress-cc=bodycc' '
499 test_suppression bodycc
502 cat >expected-suppress-cc
<<\EOF
504 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
505 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
507 Server
: relay.example.com
508 MAIL FROM
:<from@example.com
>
509 RCPT TO
:<to@example.com
>,<author@example.com
>,<committer@example.com
>
510 From
: Example
<from@example.com
>
512 Cc
: A
<author@example.com
>, C O Mitter
<committer@example.com
>
513 Subject
: [PATCH
1/1] Second.
515 Message-Id
: MESSAGE-ID-STRING
516 X-Mailer
: X-MAILER-STRING
521 test_expect_success
'--suppress-cc=cc' '
527 GIT_SEND_EMAIL_NOTTY
=1 \
529 --from="Example <nobody@example.com>" \
530 --to=nobody@example.com \
531 --smtp-server="$(pwd)/fake.sendmail" \
532 $@
$patches > stdout
&&
533 grep "Send this email" stdout
536 test_expect_success
'--confirm=always' '
537 test_confirm --confirm=always --suppress-cc=all
540 test_expect_success
'--confirm=auto' '
541 test_confirm --confirm=auto
544 test_expect_success
'--confirm=cc' '
545 test_confirm --confirm=cc
548 test_expect_success
'--confirm=compose' '
549 test_confirm --confirm=compose --compose
552 test_expect_success
'confirm by default (due to cc)' '
553 CONFIRM=$(git config --get sendemail.confirm) &&
554 git config --unset sendemail.confirm &&
557 git config sendemail.confirm ${CONFIRM:-never}
561 test_expect_success
'confirm by default (due to --compose)' '
562 CONFIRM=$(git config --get sendemail.confirm) &&
563 git config --unset sendemail.confirm &&
564 test_confirm --suppress-cc=all --compose
566 git config sendemail.confirm ${CONFIRM:-never}
570 test_expect_success
'confirm detects EOF (inform assumes y)' '
571 CONFIRM=$(git config --get sendemail.confirm) &&
572 git config --unset sendemail.confirm &&
574 git format-patch -2 -o outdir &&
575 GIT_SEND_EMAIL_NOTTY=1 \
577 --from="Example <nobody@example.com>" \
578 --to=nobody@example.com \
579 --smtp-server="$(pwd)/fake.sendmail" \
580 outdir/*.patch < /dev/null
582 git config sendemail.confirm ${CONFIRM:-never}
586 test_expect_success
'confirm detects EOF (auto causes failure)' '
587 CONFIRM=$(git config --get sendemail.confirm) &&
588 git config sendemail.confirm auto &&
589 GIT_SEND_EMAIL_NOTTY=1 &&
590 export GIT_SEND_EMAIL_NOTTY &&
591 test_must_fail git send-email \
592 --from="Example <nobody@example.com>" \
593 --to=nobody@example.com \
594 --smtp-server="$(pwd)/fake.sendmail" \
597 git config sendemail.confirm ${CONFIRM:-never}
601 test_expect_success
'confirm doesnt loop forever' '
602 CONFIRM=$(git config --get sendemail.confirm) &&
603 git config sendemail.confirm auto &&
604 GIT_SEND_EMAIL_NOTTY=1 &&
605 export GIT_SEND_EMAIL_NOTTY &&
606 yes "bogus" | test_must_fail git send-email \
607 --from="Example <nobody@example.com>" \
608 --to=nobody@example.com \
609 --smtp-server="$(pwd)/fake.sendmail" \
612 git config sendemail.confirm ${CONFIRM:-never}
616 test_expect_success
'utf8 Cc is rfc2047 encoded' '
617 clean_fake_sendmail &&
619 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
621 --from="Example <nobody@example.com>" \
622 --to=nobody@example.com \
623 --smtp-server="$(pwd)/fake.sendmail" \
625 grep "^Cc:" msgtxt1 |
626 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
629 test_expect_success
'--compose adds MIME for utf8 body' '
630 clean_fake_sendmail &&
631 (echo "#!$SHELL_PATH" &&
632 echo "echo utf8 body: àéìöú >>\"\$1\""
633 ) >fake-editor-utf8 &&
634 chmod +x fake-editor-utf8 &&
635 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
637 --compose --subject foo \
638 --from="Example <nobody@example.com>" \
639 --to=nobody@example.com \
640 --smtp-server="$(pwd)/fake.sendmail" \
642 grep "^utf8 body" msgtxt1 &&
643 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
646 test_expect_success
'--compose respects user mime type' '
647 clean_fake_sendmail &&
648 (echo "#!$SHELL_PATH" &&
649 echo "(echo MIME-Version: 1.0"
650 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
651 echo " echo Content-Transfer-Encoding: 8bit"
652 echo " echo Subject: foo"
654 echo " echo utf8 body: àéìöú) >\"\$1\""
655 ) >fake-editor-utf8-mime &&
656 chmod +x fake-editor-utf8-mime &&
657 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
659 --compose --subject foo \
660 --from="Example <nobody@example.com>" \
661 --to=nobody@example.com \
662 --smtp-server="$(pwd)/fake.sendmail" \
664 grep "^utf8 body" msgtxt1 &&
665 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
666 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
669 test_expect_success
'--compose adds MIME for utf8 subject' '
670 clean_fake_sendmail &&
671 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
673 --compose --subject utf8-sübjëct \
674 --from="Example <nobody@example.com>" \
675 --to=nobody@example.com \
676 --smtp-server="$(pwd)/fake.sendmail" \
678 grep "^fake edit" msgtxt1 &&
679 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
682 test_expect_success
'detects ambiguous reference/file conflict' '
683 echo master > master &&
685 git commit -m"add master" &&
686 test_must_fail git send-email --dry-run master 2>errors &&
687 grep disambiguate errors
690 test_expect_success
'feed two files' '
692 git format-patch -2 -o outdir &&
695 --from="Example <nobody@example.com>" \
696 --to=nobody@example.com \
697 outdir/000?-*.patch 2>errors >out &&
698 grep "^Subject: " out >subjects &&
699 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
700 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
703 test_expect_success
'in-reply-to but no threading' '
706 --from="Example <nobody@example.com>" \
707 --to=nobody@example.com \
708 --in-reply-to="<in-reply-id@example.com>" \
711 grep "In-Reply-To: <in-reply-id@example.com>"
714 test_expect_success
'no in-reply-to and no threading' '
717 --from="Example <nobody@example.com>" \
718 --to=nobody@example.com \
720 $patches $patches >stdout &&
721 ! grep "In-Reply-To: " stdout
724 test_expect_success
'threading but no chain-reply-to' '
727 --from="Example <nobody@example.com>" \
728 --to=nobody@example.com \
731 $patches $patches >stdout &&
732 grep "In-Reply-To: " stdout