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 test_expect_success
'Send patches with --envelope-sender=auto' '
116 clean_fake_sendmail &&
117 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
128 test_expect_success \
129 'Verify commandline' \
130 'test_cmp expected commandline1'
132 cat >expected-show-all-headers
<<\EOF
134 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
135 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
136 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
138 Server
: relay.example.com
139 MAIL FROM
:<from@example.com
>
140 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<bcc@example.com
>
141 From
: Example
<from@example.com
>
143 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
144 Subject
: [PATCH
1/1] Second.
146 Message-Id
: MESSAGE-ID-STRING
147 X-Mailer
: X-MAILER-STRING
148 In-Reply-To
: <unique-message-id@example.com
>
149 References
: <unique-message-id@example.com
>
154 test_expect_success
'Show all headers' '
158 --from="Example <from@example.com>" \
159 --to=to@example.com \
160 --cc=cc@example.com \
161 --bcc=bcc@example.com \
162 --in-reply-to="<unique-message-id@example.com>" \
163 --smtp-server relay.example.com \
165 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
166 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
167 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
168 >actual-show-all-headers &&
169 test_cmp expected-show-all-headers actual-show-all-headers
172 test_expect_success
'Prompting works' '
173 clean_fake_sendmail &&
174 (echo "Example <from@example.com>"
175 echo "to@example.com"
177 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
178 --smtp-server="$(pwd)/fake.sendmail" \
181 grep "^From: Example <from@example.com>$" msgtxt1 &&
182 grep "^To: to@example.com$" msgtxt1
185 test_expect_success
'cccmd works' '
186 clean_fake_sendmail &&
187 cp $patches cccmd.patch &&
188 echo cccmd--cccmd@example.com >>cccmd.patch &&
191 echo sed -n -e s/^cccmd--//p \"\$1\"
193 chmod +x cccmd-sed &&
195 --from="Example <nobody@example.com>" \
196 --to=nobody@example.com \
197 --cc-cmd=./cccmd-sed \
198 --smtp-server="$(pwd)/fake.sendmail" \
201 grep ^Cc:.*cccmd@example.com msgtxt1
205 z64
=$z8$z8$z8$z8$z8$z8$z8$z8
206 z512
=$z64$z64$z64$z64$z64$z64$z64$z64
207 test_expect_success
'reject long lines' '
208 clean_fake_sendmail &&
209 cp $patches longline.patch &&
210 echo $z512$z512 >>longline.patch &&
211 test_must_fail git send-email \
212 --from="Example <nobody@example.com>" \
213 --to=nobody@example.com \
214 --smtp-server="$(pwd)/fake.sendmail" \
215 $patches longline.patch \
217 grep longline.patch errors
220 test_expect_success
'no patch was sent' '
221 ! test -e commandline1
224 test_expect_success
'Author From: in message body' '
225 clean_fake_sendmail &&
227 --from="Example <nobody@example.com>" \
228 --to=nobody@example.com \
229 --smtp-server="$(pwd)/fake.sendmail" \
231 sed "1,/^$/d" < msgtxt1 > msgbody1
232 grep "From: A <author@example.com>" msgbody1
235 test_expect_success
'Author From: not in message body' '
236 clean_fake_sendmail &&
238 --from="A <author@example.com>" \
239 --to=nobody@example.com \
240 --smtp-server="$(pwd)/fake.sendmail" \
242 sed "1,/^$/d" < msgtxt1 > msgbody1
243 ! grep "From: A <author@example.com>" msgbody1
246 test_expect_success
'allow long lines with --no-validate' '
248 --from="Example <nobody@example.com>" \
249 --to=nobody@example.com \
250 --smtp-server="$(pwd)/fake.sendmail" \
252 $patches longline.patch \
256 test_expect_success
'Invalid In-Reply-To' '
257 clean_fake_sendmail &&
259 --from="Example <nobody@example.com>" \
260 --to=nobody@example.com \
262 --smtp-server="$(pwd)/fake.sendmail" \
265 ! grep "^In-Reply-To: < *>" msgtxt1
268 test_expect_success
'Valid In-Reply-To when prompting' '
269 clean_fake_sendmail &&
270 (echo "From Example <from@example.com>"
271 echo "To Example <to@example.com>"
273 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
274 --smtp-server="$(pwd)/fake.sendmail" \
276 ! grep "^In-Reply-To: < *>" msgtxt1
279 test_expect_success
'setup fake editor' '
280 (echo "#!$SHELL_PATH" &&
281 echo "echo fake edit >>\"\$1\""
286 test_set_editor
"$(pwd)/fake-editor"
288 test_expect_success
'--compose works' '
289 clean_fake_sendmail &&
291 --compose --subject foo \
292 --from="Example <nobody@example.com>" \
293 --to=nobody@example.com \
294 --smtp-server="$(pwd)/fake.sendmail" \
299 test_expect_success
'first message is compose text' '
300 grep "^fake edit" msgtxt1
303 test_expect_success
'second message is patch' '
304 grep "Subject:.*Second" msgtxt2
307 cat >expected-suppress-sob
<<\EOF
309 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
310 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
311 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
313 Server
: relay.example.com
314 MAIL FROM
:<from@example.com
>
315 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
316 From
: Example
<from@example.com
>
318 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
319 Subject
: [PATCH
1/1] Second.
321 Message-Id
: MESSAGE-ID-STRING
322 X-Mailer
: X-MAILER-STRING
327 test_suppression
() {
330 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
331 --from="Example <from@example.com>" \
332 --to=to@example.com \
333 --smtp-server relay.example.com \
335 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
336 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
337 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
338 >actual-suppress-
$1${2+"-$2"} &&
339 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
342 test_expect_success
'sendemail.cc set' '
343 git config sendemail.cc cc@example.com &&
347 cat >expected-suppress-sob
<<\EOF
349 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
350 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
351 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
353 Server
: relay.example.com
354 MAIL FROM
:<from@example.com
>
355 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
356 From
: Example
<from@example.com
>
358 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
359 Subject
: [PATCH
1/1] Second.
361 Message-Id
: MESSAGE-ID-STRING
362 X-Mailer
: X-MAILER-STRING
367 test_expect_success
'sendemail.cc unset' '
368 git config --unset sendemail.cc &&
372 cat >expected-suppress-cccmd
<<\EOF
374 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
375 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
376 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
377 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
379 Server
: relay.example.com
380 MAIL FROM
:<from@example.com
>
381 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
382 From
: Example
<from@example.com
>
384 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
385 Subject
: [PATCH
1/1] Second.
387 Message-Id
: MESSAGE-ID-STRING
388 X-Mailer
: X-MAILER-STRING
393 test_expect_success
'sendemail.cccmd' '
394 echo echo cc-cmd@example.com > cccmd &&
396 git config sendemail.cccmd ./cccmd &&
397 test_suppression cccmd
400 cat >expected-suppress-all
<<\EOF
403 Server
: relay.example.com
404 MAIL FROM
:<from@example.com
>
405 RCPT TO
:<to@example.com
>
406 From
: Example
<from@example.com
>
408 Subject
: [PATCH
1/1] Second.
410 Message-Id
: MESSAGE-ID-STRING
411 X-Mailer
: X-MAILER-STRING
416 test_expect_success
'--suppress-cc=all' '
420 cat >expected-suppress-body
<<\EOF
422 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
423 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
424 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
425 (cc-cmd
) Adding cc
: cc-cmd@example.com from
: './cccmd'
427 Server
: relay.example.com
428 MAIL FROM
:<from@example.com
>
429 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<cc-cmd@example.com
>
430 From
: Example
<from@example.com
>
432 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, cc-cmd@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
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
454 From
: Example
<from@example.com
>
456 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
457 Subject
: [PATCH
1/1] Second.
459 Message-Id
: MESSAGE-ID-STRING
460 X-Mailer
: X-MAILER-STRING
465 test_expect_success
'--suppress-cc=body --suppress-cc=cccmd' '
466 test_suppression body cccmd
469 cat >expected-suppress-sob
<<\EOF
471 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
472 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
473 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
475 Server
: relay.example.com
476 MAIL FROM
:<from@example.com
>
477 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
478 From
: Example
<from@example.com
>
480 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
481 Subject
: [PATCH
1/1] Second.
483 Message-Id
: MESSAGE-ID-STRING
484 X-Mailer
: X-MAILER-STRING
489 test_expect_success
'--suppress-cc=sob' '
490 git config --unset sendemail.cccmd
494 cat >expected-suppress-bodycc
<<\EOF
496 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
497 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
498 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
499 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
501 Server
: relay.example.com
502 MAIL FROM
:<from@example.com
>
503 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
504 From
: Example
<from@example.com
>
506 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
507 Subject
: [PATCH
1/1] Second.
509 Message-Id
: MESSAGE-ID-STRING
510 X-Mailer
: X-MAILER-STRING
515 test_expect_success
'--suppress-cc=bodycc' '
516 test_suppression bodycc
519 cat >expected-suppress-cc
<<\EOF
521 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
522 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
524 Server
: relay.example.com
525 MAIL FROM
:<from@example.com
>
526 RCPT TO
:<to@example.com
>,<author@example.com
>,<committer@example.com
>
527 From
: Example
<from@example.com
>
529 Cc
: A
<author@example.com
>, C O Mitter
<committer@example.com
>
530 Subject
: [PATCH
1/1] Second.
532 Message-Id
: MESSAGE-ID-STRING
533 X-Mailer
: X-MAILER-STRING
538 test_expect_success
'--suppress-cc=cc' '
544 GIT_SEND_EMAIL_NOTTY
=1 \
546 --from="Example <nobody@example.com>" \
547 --to=nobody@example.com \
548 --smtp-server="$(pwd)/fake.sendmail" \
549 $@
$patches > stdout
&&
550 grep "Send this email" stdout
553 test_expect_success
'--confirm=always' '
554 test_confirm --confirm=always --suppress-cc=all
557 test_expect_success
'--confirm=auto' '
558 test_confirm --confirm=auto
561 test_expect_success
'--confirm=cc' '
562 test_confirm --confirm=cc
565 test_expect_success
'--confirm=compose' '
566 test_confirm --confirm=compose --compose
569 test_expect_success
'confirm by default (due to cc)' '
570 CONFIRM=$(git config --get sendemail.confirm) &&
571 git config --unset sendemail.confirm &&
574 git config sendemail.confirm ${CONFIRM:-never}
578 test_expect_success
'confirm by default (due to --compose)' '
579 CONFIRM=$(git config --get sendemail.confirm) &&
580 git config --unset sendemail.confirm &&
581 test_confirm --suppress-cc=all --compose
583 git config sendemail.confirm ${CONFIRM:-never}
587 test_expect_success
'confirm detects EOF (inform assumes y)' '
588 CONFIRM=$(git config --get sendemail.confirm) &&
589 git config --unset sendemail.confirm &&
591 git format-patch -2 -o outdir &&
592 GIT_SEND_EMAIL_NOTTY=1 \
594 --from="Example <nobody@example.com>" \
595 --to=nobody@example.com \
596 --smtp-server="$(pwd)/fake.sendmail" \
597 outdir/*.patch < /dev/null
599 git config sendemail.confirm ${CONFIRM:-never}
603 test_expect_success
'confirm detects EOF (auto causes failure)' '
604 CONFIRM=$(git config --get sendemail.confirm) &&
605 git config sendemail.confirm auto &&
606 GIT_SEND_EMAIL_NOTTY=1 &&
607 export GIT_SEND_EMAIL_NOTTY &&
608 test_must_fail git send-email \
609 --from="Example <nobody@example.com>" \
610 --to=nobody@example.com \
611 --smtp-server="$(pwd)/fake.sendmail" \
614 git config sendemail.confirm ${CONFIRM:-never}
618 test_expect_success
'confirm doesnt loop forever' '
619 CONFIRM=$(git config --get sendemail.confirm) &&
620 git config sendemail.confirm auto &&
621 GIT_SEND_EMAIL_NOTTY=1 &&
622 export GIT_SEND_EMAIL_NOTTY &&
623 yes "bogus" | test_must_fail git send-email \
624 --from="Example <nobody@example.com>" \
625 --to=nobody@example.com \
626 --smtp-server="$(pwd)/fake.sendmail" \
629 git config sendemail.confirm ${CONFIRM:-never}
633 test_expect_success
'utf8 Cc is rfc2047 encoded' '
634 clean_fake_sendmail &&
636 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
638 --from="Example <nobody@example.com>" \
639 --to=nobody@example.com \
640 --smtp-server="$(pwd)/fake.sendmail" \
642 grep "^Cc:" msgtxt1 |
643 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
646 test_expect_success
'--compose adds MIME for utf8 body' '
647 clean_fake_sendmail &&
648 (echo "#!$SHELL_PATH" &&
649 echo "echo utf8 body: àéìöú >>\"\$1\""
650 ) >fake-editor-utf8 &&
651 chmod +x fake-editor-utf8 &&
652 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
654 --compose --subject foo \
655 --from="Example <nobody@example.com>" \
656 --to=nobody@example.com \
657 --smtp-server="$(pwd)/fake.sendmail" \
659 grep "^utf8 body" msgtxt1 &&
660 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
663 test_expect_success
'--compose respects user mime type' '
664 clean_fake_sendmail &&
665 (echo "#!$SHELL_PATH" &&
666 echo "(echo MIME-Version: 1.0"
667 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
668 echo " echo Content-Transfer-Encoding: 8bit"
669 echo " echo Subject: foo"
671 echo " echo utf8 body: àéìöú) >\"\$1\""
672 ) >fake-editor-utf8-mime &&
673 chmod +x fake-editor-utf8-mime &&
674 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
676 --compose --subject foo \
677 --from="Example <nobody@example.com>" \
678 --to=nobody@example.com \
679 --smtp-server="$(pwd)/fake.sendmail" \
681 grep "^utf8 body" msgtxt1 &&
682 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
683 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
686 test_expect_success
'--compose adds MIME for utf8 subject' '
687 clean_fake_sendmail &&
688 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
690 --compose --subject utf8-sübjëct \
691 --from="Example <nobody@example.com>" \
692 --to=nobody@example.com \
693 --smtp-server="$(pwd)/fake.sendmail" \
695 grep "^fake edit" msgtxt1 &&
696 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
699 test_expect_success
'detects ambiguous reference/file conflict' '
700 echo master > master &&
702 git commit -m"add master" &&
703 test_must_fail git send-email --dry-run master 2>errors &&
704 grep disambiguate errors
707 test_expect_success
'feed two files' '
709 git format-patch -2 -o outdir &&
712 --from="Example <nobody@example.com>" \
713 --to=nobody@example.com \
714 outdir/000?-*.patch 2>errors >out &&
715 grep "^Subject: " out >subjects &&
716 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
717 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
720 test_expect_success
'in-reply-to but no threading' '
723 --from="Example <nobody@example.com>" \
724 --to=nobody@example.com \
725 --in-reply-to="<in-reply-id@example.com>" \
728 grep "In-Reply-To: <in-reply-id@example.com>"
731 test_expect_success
'no in-reply-to and no threading' '
734 --from="Example <nobody@example.com>" \
735 --to=nobody@example.com \
737 $patches $patches >stdout &&
738 ! grep "In-Reply-To: " stdout
741 test_expect_success
'threading but no chain-reply-to' '
744 --from="Example <nobody@example.com>" \
745 --to=nobody@example.com \
748 $patches $patches >stdout &&
749 grep "In-Reply-To: " stdout