gitweb: skip logo in atom feed when there is none
[git/mjg.git] / t / t9001-send-email.sh
blobf1047d2ef3ee473a924f5819441dd1a7b1829768
1 #!/bin/sh
3 test_description='git send-email'
4 . ./test-lib.sh
6 # May be altered later in the test
7 PREREQ="PERL"
9 test_expect_success $PREREQ \
10 'prepare reference tree' \
11 'echo "1A quick brown fox jumps over the" >file &&
12 echo "lazy dog" >>file &&
13 git add file &&
14 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
16 test_expect_success $PREREQ \
17 'Setup helper tool' \
18 '(echo "#!$SHELL_PATH"
19 echo shift
20 echo output=1
21 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
22 echo for a
23 echo do
24 echo " echo \"!\$a!\""
25 echo "done >commandline\$output"
26 echo "cat > msgtxt\$output"
27 ) >fake.sendmail &&
28 chmod +x ./fake.sendmail &&
29 git add fake.sendmail &&
30 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
32 clean_fake_sendmail() {
33 rm -f commandline* msgtxt*
36 test_expect_success $PREREQ 'Extract patches' '
37 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
40 # Test no confirm early to ensure remaining tests will not hang
41 test_no_confirm () {
42 rm -f no_confirm_okay
43 echo n | \
44 GIT_SEND_EMAIL_NOTTY=1 \
45 git send-email \
46 --from="Example <from@example.com>" \
47 --to=nobody@example.com \
48 --smtp-server="$(pwd)/fake.sendmail" \
49 $@ \
50 $patches > stdout &&
51 test_must_fail grep "Send this email" stdout &&
52 > no_confirm_okay
55 # Exit immediately to prevent hang if a no-confirm test fails
56 check_no_confirm () {
57 if ! test -f no_confirm_okay
58 then
59 say 'confirm test failed; skipping remaining tests to prevent hanging'
60 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
62 return 0
65 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
66 test_no_confirm --suppress-cc=sob &&
67 check_no_confirm
71 test_expect_success $PREREQ 'No confirm with --confirm=never' '
72 test_no_confirm --confirm=never &&
73 check_no_confirm
76 # leave sendemail.confirm set to never after this so that none of the
77 # remaining tests prompt unintentionally.
78 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
79 git config sendemail.confirm never &&
80 test_no_confirm --compose --subject=foo &&
81 check_no_confirm
84 test_expect_success $PREREQ '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
88 test_expect_success $PREREQ 'setup expect' '
89 cat >expected <<\EOF
90 !nobody@example.com!
91 !author@example.com!
92 !one@example.com!
93 !two@example.com!
94 EOF
97 test_expect_success $PREREQ \
98 'Verify commandline' \
99 'test_cmp expected commandline1'
101 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
102 clean_fake_sendmail &&
103 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
106 test_expect_success $PREREQ 'setup expect' '
107 cat >expected <<\EOF
108 !patch@example.com!
109 !-i!
110 !nobody@example.com!
111 !author@example.com!
112 !one@example.com!
113 !two@example.com!
117 test_expect_success $PREREQ \
118 'Verify commandline' \
119 'test_cmp expected commandline1'
121 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
122 clean_fake_sendmail &&
123 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
126 test_expect_success $PREREQ 'setup expect' '
127 cat >expected <<\EOF
128 !nobody@example.com!
129 !-i!
130 !nobody@example.com!
131 !author@example.com!
132 !one@example.com!
133 !two@example.com!
137 test_expect_success $PREREQ \
138 'Verify commandline' \
139 'test_cmp expected commandline1'
141 test_expect_success $PREREQ 'setup expect' "
142 cat >expected-show-all-headers <<\EOF
143 0001-Second.patch
144 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
145 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
146 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
147 Dry-OK. Log says:
148 Server: relay.example.com
149 MAIL FROM:<from@example.com>
150 RCPT TO:<to@example.com>
151 RCPT TO:<cc@example.com>
152 RCPT TO:<author@example.com>
153 RCPT TO:<one@example.com>
154 RCPT TO:<two@example.com>
155 RCPT TO:<bcc@example.com>
156 From: Example <from@example.com>
157 To: to@example.com
158 Cc: cc@example.com,
159 A <author@example.com>,
160 One <one@example.com>,
161 two@example.com
162 Subject: [PATCH 1/1] Second.
163 Date: DATE-STRING
164 Message-Id: MESSAGE-ID-STRING
165 X-Mailer: X-MAILER-STRING
166 In-Reply-To: <unique-message-id@example.com>
167 References: <unique-message-id@example.com>
169 Result: OK
173 test_expect_success $PREREQ 'Show all headers' '
174 git send-email \
175 --dry-run \
176 --suppress-cc=sob \
177 --from="Example <from@example.com>" \
178 --to=to@example.com \
179 --cc=cc@example.com \
180 --bcc=bcc@example.com \
181 --in-reply-to="<unique-message-id@example.com>" \
182 --smtp-server relay.example.com \
183 $patches |
184 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
185 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
186 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
187 >actual-show-all-headers &&
188 test_cmp expected-show-all-headers actual-show-all-headers
191 test_expect_success $PREREQ 'Prompting works' '
192 clean_fake_sendmail &&
193 (echo "Example <from@example.com>"
194 echo "to@example.com"
195 echo ""
196 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
197 --smtp-server="$(pwd)/fake.sendmail" \
198 $patches \
199 2>errors &&
200 grep "^From: Example <from@example.com>\$" msgtxt1 &&
201 grep "^To: to@example.com\$" msgtxt1
204 test_expect_success $PREREQ 'cccmd works' '
205 clean_fake_sendmail &&
206 cp $patches cccmd.patch &&
207 echo cccmd--cccmd@example.com >>cccmd.patch &&
209 echo "#!$SHELL_PATH"
210 echo sed -n -e s/^cccmd--//p \"\$1\"
211 } > cccmd-sed &&
212 chmod +x cccmd-sed &&
213 git send-email \
214 --from="Example <nobody@example.com>" \
215 --to=nobody@example.com \
216 --cc-cmd=./cccmd-sed \
217 --smtp-server="$(pwd)/fake.sendmail" \
218 cccmd.patch \
220 grep "^ cccmd@example.com" msgtxt1
223 test_expect_success $PREREQ 'reject long lines' '
224 z8=zzzzzzzz &&
225 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
226 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
227 clean_fake_sendmail &&
228 cp $patches longline.patch &&
229 echo $z512$z512 >>longline.patch &&
230 test_must_fail git send-email \
231 --from="Example <nobody@example.com>" \
232 --to=nobody@example.com \
233 --smtp-server="$(pwd)/fake.sendmail" \
234 $patches longline.patch \
235 2>errors &&
236 grep longline.patch errors
239 test_expect_success $PREREQ 'no patch was sent' '
240 ! test -e commandline1
243 test_expect_success $PREREQ 'Author From: in message body' '
244 clean_fake_sendmail &&
245 git send-email \
246 --from="Example <nobody@example.com>" \
247 --to=nobody@example.com \
248 --smtp-server="$(pwd)/fake.sendmail" \
249 $patches &&
250 sed "1,/^\$/d" < msgtxt1 > msgbody1
251 grep "From: A <author@example.com>" msgbody1
254 test_expect_success $PREREQ 'Author From: not in message body' '
255 clean_fake_sendmail &&
256 git send-email \
257 --from="A <author@example.com>" \
258 --to=nobody@example.com \
259 --smtp-server="$(pwd)/fake.sendmail" \
260 $patches &&
261 sed "1,/^\$/d" < msgtxt1 > msgbody1
262 ! grep "From: A <author@example.com>" msgbody1
265 test_expect_success $PREREQ 'allow long lines with --no-validate' '
266 git send-email \
267 --from="Example <nobody@example.com>" \
268 --to=nobody@example.com \
269 --smtp-server="$(pwd)/fake.sendmail" \
270 --novalidate \
271 $patches longline.patch \
272 2>errors
275 test_expect_success $PREREQ 'Invalid In-Reply-To' '
276 clean_fake_sendmail &&
277 git send-email \
278 --from="Example <nobody@example.com>" \
279 --to=nobody@example.com \
280 --in-reply-to=" " \
281 --smtp-server="$(pwd)/fake.sendmail" \
282 $patches \
283 2>errors
284 ! grep "^In-Reply-To: < *>" msgtxt1
287 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
288 clean_fake_sendmail &&
289 (echo "From Example <from@example.com>"
290 echo "To Example <to@example.com>"
291 echo ""
292 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
293 --smtp-server="$(pwd)/fake.sendmail" \
294 $patches 2>errors &&
295 ! grep "^In-Reply-To: < *>" msgtxt1
298 test_expect_success $PREREQ 'setup fake editor' '
299 (echo "#!$SHELL_PATH" &&
300 echo "echo fake edit >>\"\$1\""
301 ) >fake-editor &&
302 chmod +x fake-editor
305 test_set_editor "$(pwd)/fake-editor"
307 test_expect_success $PREREQ '--compose works' '
308 clean_fake_sendmail &&
309 git send-email \
310 --compose --subject foo \
311 --from="Example <nobody@example.com>" \
312 --to=nobody@example.com \
313 --smtp-server="$(pwd)/fake.sendmail" \
314 $patches \
315 2>errors
318 test_expect_success $PREREQ 'first message is compose text' '
319 grep "^fake edit" msgtxt1
322 test_expect_success $PREREQ 'second message is patch' '
323 grep "Subject:.*Second" msgtxt2
326 test_expect_success $PREREQ 'setup expect' "
327 cat >expected-suppress-sob <<\EOF
328 0001-Second.patch
329 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
330 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
331 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
332 Dry-OK. Log says:
333 Server: relay.example.com
334 MAIL FROM:<from@example.com>
335 RCPT TO:<to@example.com>
336 RCPT TO:<cc@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>
341 To: to@example.com
342 Cc: cc@example.com,
343 A <author@example.com>,
344 One <one@example.com>,
345 two@example.com
346 Subject: [PATCH 1/1] Second.
347 Date: DATE-STRING
348 Message-Id: MESSAGE-ID-STRING
349 X-Mailer: X-MAILER-STRING
351 Result: OK
355 test_suppression () {
356 git send-email \
357 --dry-run \
358 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
359 --from="Example <from@example.com>" \
360 --to=to@example.com \
361 --smtp-server relay.example.com \
362 $patches |
363 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
364 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
365 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
366 >actual-suppress-$1${2+"-$2"} &&
367 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
370 test_expect_success $PREREQ 'sendemail.cc set' '
371 git config sendemail.cc cc@example.com &&
372 test_suppression sob
375 test_expect_success $PREREQ 'setup expect' "
376 cat >expected-suppress-sob <<\EOF
377 0001-Second.patch
378 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
379 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
380 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
381 Dry-OK. Log says:
382 Server: relay.example.com
383 MAIL FROM:<from@example.com>
384 RCPT TO:<to@example.com>
385 RCPT TO:<author@example.com>
386 RCPT TO:<one@example.com>
387 RCPT TO:<two@example.com>
388 From: Example <from@example.com>
389 To: to@example.com
390 Cc: A <author@example.com>,
391 One <one@example.com>,
392 two@example.com
393 Subject: [PATCH 1/1] Second.
394 Date: DATE-STRING
395 Message-Id: MESSAGE-ID-STRING
396 X-Mailer: X-MAILER-STRING
398 Result: OK
402 test_expect_success $PREREQ 'sendemail.cc unset' '
403 git config --unset sendemail.cc &&
404 test_suppression sob
407 test_expect_success $PREREQ 'setup expect' "
408 cat >expected-suppress-cccmd <<\EOF
409 0001-Second.patch
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'
413 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
414 Dry-OK. Log says:
415 Server: relay.example.com
416 MAIL FROM:<from@example.com>
417 RCPT TO:<to@example.com>
418 RCPT TO:<author@example.com>
419 RCPT TO:<one@example.com>
420 RCPT TO:<two@example.com>
421 RCPT TO:<committer@example.com>
422 From: Example <from@example.com>
423 To: to@example.com
424 Cc: A <author@example.com>,
425 One <one@example.com>,
426 two@example.com,
427 C O Mitter <committer@example.com>
428 Subject: [PATCH 1/1] Second.
429 Date: DATE-STRING
430 Message-Id: MESSAGE-ID-STRING
431 X-Mailer: X-MAILER-STRING
433 Result: OK
437 test_expect_success $PREREQ 'sendemail.cccmd' '
438 echo echo cc-cmd@example.com > cccmd &&
439 chmod +x cccmd &&
440 git config sendemail.cccmd ./cccmd &&
441 test_suppression cccmd
444 test_expect_success $PREREQ 'setup expect' '
445 cat >expected-suppress-all <<\EOF
446 0001-Second.patch
447 Dry-OK. Log says:
448 Server: relay.example.com
449 MAIL FROM:<from@example.com>
450 RCPT TO:<to@example.com>
451 From: Example <from@example.com>
452 To: to@example.com
453 Subject: [PATCH 1/1] Second.
454 Date: DATE-STRING
455 Message-Id: MESSAGE-ID-STRING
456 X-Mailer: X-MAILER-STRING
458 Result: OK
462 test_expect_success $PREREQ '--suppress-cc=all' '
463 test_suppression all
466 test_expect_success $PREREQ 'setup expect' "
467 cat >expected-suppress-body <<\EOF
468 0001-Second.patch
469 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
470 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
471 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
472 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
473 Dry-OK. Log says:
474 Server: relay.example.com
475 MAIL FROM:<from@example.com>
476 RCPT TO:<to@example.com>
477 RCPT TO:<author@example.com>
478 RCPT TO:<one@example.com>
479 RCPT TO:<two@example.com>
480 RCPT TO:<cc-cmd@example.com>
481 From: Example <from@example.com>
482 To: to@example.com
483 Cc: A <author@example.com>,
484 One <one@example.com>,
485 two@example.com,
486 cc-cmd@example.com
487 Subject: [PATCH 1/1] Second.
488 Date: DATE-STRING
489 Message-Id: MESSAGE-ID-STRING
490 X-Mailer: X-MAILER-STRING
492 Result: OK
496 test_expect_success $PREREQ '--suppress-cc=body' '
497 test_suppression body
500 test_expect_success $PREREQ 'setup expect' "
501 cat >expected-suppress-body-cccmd <<\EOF
502 0001-Second.patch
503 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
504 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
505 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
506 Dry-OK. Log says:
507 Server: relay.example.com
508 MAIL FROM:<from@example.com>
509 RCPT TO:<to@example.com>
510 RCPT TO:<author@example.com>
511 RCPT TO:<one@example.com>
512 RCPT TO:<two@example.com>
513 From: Example <from@example.com>
514 To: to@example.com
515 Cc: A <author@example.com>,
516 One <one@example.com>,
517 two@example.com
518 Subject: [PATCH 1/1] Second.
519 Date: DATE-STRING
520 Message-Id: MESSAGE-ID-STRING
521 X-Mailer: X-MAILER-STRING
523 Result: OK
527 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
528 test_suppression body cccmd
531 test_expect_success $PREREQ 'setup expect' "
532 cat >expected-suppress-sob <<\EOF
533 0001-Second.patch
534 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
535 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
536 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
537 Dry-OK. Log says:
538 Server: relay.example.com
539 MAIL FROM:<from@example.com>
540 RCPT TO:<to@example.com>
541 RCPT TO:<author@example.com>
542 RCPT TO:<one@example.com>
543 RCPT TO:<two@example.com>
544 From: Example <from@example.com>
545 To: to@example.com
546 Cc: A <author@example.com>,
547 One <one@example.com>,
548 two@example.com
549 Subject: [PATCH 1/1] Second.
550 Date: DATE-STRING
551 Message-Id: MESSAGE-ID-STRING
552 X-Mailer: X-MAILER-STRING
554 Result: OK
558 test_expect_success $PREREQ '--suppress-cc=sob' '
559 git config --unset sendemail.cccmd
560 test_suppression sob
563 test_expect_success $PREREQ 'setup expect' "
564 cat >expected-suppress-bodycc <<\EOF
565 0001-Second.patch
566 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
567 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
568 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
569 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
570 Dry-OK. Log says:
571 Server: relay.example.com
572 MAIL FROM:<from@example.com>
573 RCPT TO:<to@example.com>
574 RCPT TO:<author@example.com>
575 RCPT TO:<one@example.com>
576 RCPT TO:<two@example.com>
577 RCPT TO:<committer@example.com>
578 From: Example <from@example.com>
579 To: to@example.com
580 Cc: A <author@example.com>,
581 One <one@example.com>,
582 two@example.com,
583 C O Mitter <committer@example.com>
584 Subject: [PATCH 1/1] Second.
585 Date: DATE-STRING
586 Message-Id: MESSAGE-ID-STRING
587 X-Mailer: X-MAILER-STRING
589 Result: OK
593 test_expect_success $PREREQ '--suppress-cc=bodycc' '
594 test_suppression bodycc
597 test_expect_success $PREREQ 'setup expect' "
598 cat >expected-suppress-cc <<\EOF
599 0001-Second.patch
600 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
601 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
602 Dry-OK. Log says:
603 Server: relay.example.com
604 MAIL FROM:<from@example.com>
605 RCPT TO:<to@example.com>
606 RCPT TO:<author@example.com>
607 RCPT TO:<committer@example.com>
608 From: Example <from@example.com>
609 To: to@example.com
610 Cc: A <author@example.com>,
611 C O Mitter <committer@example.com>
612 Subject: [PATCH 1/1] Second.
613 Date: DATE-STRING
614 Message-Id: MESSAGE-ID-STRING
615 X-Mailer: X-MAILER-STRING
617 Result: OK
621 test_expect_success $PREREQ '--suppress-cc=cc' '
622 test_suppression cc
625 test_confirm () {
626 echo y | \
627 GIT_SEND_EMAIL_NOTTY=1 \
628 git send-email \
629 --from="Example <nobody@example.com>" \
630 --to=nobody@example.com \
631 --smtp-server="$(pwd)/fake.sendmail" \
632 $@ $patches > stdout &&
633 grep "Send this email" stdout
636 test_expect_success $PREREQ '--confirm=always' '
637 test_confirm --confirm=always --suppress-cc=all
640 test_expect_success $PREREQ '--confirm=auto' '
641 test_confirm --confirm=auto
644 test_expect_success $PREREQ '--confirm=cc' '
645 test_confirm --confirm=cc
648 test_expect_success $PREREQ '--confirm=compose' '
649 test_confirm --confirm=compose --compose
652 test_expect_success $PREREQ 'confirm by default (due to cc)' '
653 CONFIRM=$(git config --get sendemail.confirm) &&
654 git config --unset sendemail.confirm &&
655 test_confirm
656 ret="$?"
657 git config sendemail.confirm ${CONFIRM:-never}
658 test $ret = "0"
661 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
662 CONFIRM=$(git config --get sendemail.confirm) &&
663 git config --unset sendemail.confirm &&
664 test_confirm --suppress-cc=all --compose
665 ret="$?"
666 git config sendemail.confirm ${CONFIRM:-never}
667 test $ret = "0"
670 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
671 CONFIRM=$(git config --get sendemail.confirm) &&
672 git config --unset sendemail.confirm &&
673 rm -fr outdir &&
674 git format-patch -2 -o outdir &&
675 GIT_SEND_EMAIL_NOTTY=1 \
676 git send-email \
677 --from="Example <nobody@example.com>" \
678 --to=nobody@example.com \
679 --smtp-server="$(pwd)/fake.sendmail" \
680 outdir/*.patch < /dev/null
681 ret="$?"
682 git config sendemail.confirm ${CONFIRM:-never}
683 test $ret = "0"
686 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
687 CONFIRM=$(git config --get sendemail.confirm) &&
688 git config sendemail.confirm auto &&
689 GIT_SEND_EMAIL_NOTTY=1 &&
690 export GIT_SEND_EMAIL_NOTTY &&
691 test_must_fail git send-email \
692 --from="Example <nobody@example.com>" \
693 --to=nobody@example.com \
694 --smtp-server="$(pwd)/fake.sendmail" \
695 $patches < /dev/null
696 ret="$?"
697 git config sendemail.confirm ${CONFIRM:-never}
698 test $ret = "0"
701 test_expect_success $PREREQ 'confirm doesnt loop forever' '
702 CONFIRM=$(git config --get sendemail.confirm) &&
703 git config sendemail.confirm auto &&
704 GIT_SEND_EMAIL_NOTTY=1 &&
705 export GIT_SEND_EMAIL_NOTTY &&
706 yes "bogus" | test_must_fail git send-email \
707 --from="Example <nobody@example.com>" \
708 --to=nobody@example.com \
709 --smtp-server="$(pwd)/fake.sendmail" \
710 $patches
711 ret="$?"
712 git config sendemail.confirm ${CONFIRM:-never}
713 test $ret = "0"
716 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
717 clean_fake_sendmail &&
718 rm -fr outdir &&
719 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
720 git send-email \
721 --from="Example <nobody@example.com>" \
722 --to=nobody@example.com \
723 --smtp-server="$(pwd)/fake.sendmail" \
724 outdir/*.patch &&
725 grep "^ " msgtxt1 |
726 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
729 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
730 clean_fake_sendmail &&
731 (echo "#!$SHELL_PATH" &&
732 echo "echo utf8 body: àéìöú >>\"\$1\""
733 ) >fake-editor-utf8 &&
734 chmod +x fake-editor-utf8 &&
735 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
736 git send-email \
737 --compose --subject foo \
738 --from="Example <nobody@example.com>" \
739 --to=nobody@example.com \
740 --smtp-server="$(pwd)/fake.sendmail" \
741 $patches &&
742 grep "^utf8 body" msgtxt1 &&
743 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
746 test_expect_success $PREREQ '--compose respects user mime type' '
747 clean_fake_sendmail &&
748 (echo "#!$SHELL_PATH" &&
749 echo "(echo MIME-Version: 1.0"
750 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
751 echo " echo Content-Transfer-Encoding: 8bit"
752 echo " echo Subject: foo"
753 echo " echo "
754 echo " echo utf8 body: àéìöú) >\"\$1\""
755 ) >fake-editor-utf8-mime &&
756 chmod +x fake-editor-utf8-mime &&
757 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
758 git send-email \
759 --compose --subject foo \
760 --from="Example <nobody@example.com>" \
761 --to=nobody@example.com \
762 --smtp-server="$(pwd)/fake.sendmail" \
763 $patches &&
764 grep "^utf8 body" msgtxt1 &&
765 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
766 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
769 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
770 clean_fake_sendmail &&
771 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
772 git send-email \
773 --compose --subject utf8-sübjëct \
774 --from="Example <nobody@example.com>" \
775 --to=nobody@example.com \
776 --smtp-server="$(pwd)/fake.sendmail" \
777 $patches &&
778 grep "^fake edit" msgtxt1 &&
779 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
782 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
783 echo master > master &&
784 git add master &&
785 git commit -m"add master" &&
786 test_must_fail git send-email --dry-run master 2>errors &&
787 grep disambiguate errors
790 test_expect_success $PREREQ 'feed two files' '
791 rm -fr outdir &&
792 git format-patch -2 -o outdir &&
793 git send-email \
794 --dry-run \
795 --from="Example <nobody@example.com>" \
796 --to=nobody@example.com \
797 outdir/000?-*.patch 2>errors >out &&
798 grep "^Subject: " out >subjects &&
799 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
800 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
803 test_expect_success $PREREQ 'in-reply-to but no threading' '
804 git send-email \
805 --dry-run \
806 --from="Example <nobody@example.com>" \
807 --to=nobody@example.com \
808 --in-reply-to="<in-reply-id@example.com>" \
809 --nothread \
810 $patches |
811 grep "In-Reply-To: <in-reply-id@example.com>"
814 test_expect_success $PREREQ 'no in-reply-to and no threading' '
815 git send-email \
816 --dry-run \
817 --from="Example <nobody@example.com>" \
818 --to=nobody@example.com \
819 --nothread \
820 $patches $patches >stdout &&
821 ! grep "In-Reply-To: " stdout
824 test_expect_success $PREREQ 'threading but no chain-reply-to' '
825 git send-email \
826 --dry-run \
827 --from="Example <nobody@example.com>" \
828 --to=nobody@example.com \
829 --thread \
830 --nochain-reply-to \
831 $patches $patches >stdout &&
832 grep "In-Reply-To: " stdout
835 test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
836 git send-email \
837 --dry-run \
838 --from="Example <nobody@example.com>" \
839 --to=nobody@example.com \
840 outdir/000?-*.patch 2>errors >out &&
841 grep "no-chain-reply-to" errors
844 test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
845 git send-email \
846 --dry-run \
847 --from="Example <nobody@example.com>" \
848 --to=nobody@example.com \
849 --chain-reply-to \
850 outdir/000?-*.patch 2>errors >out &&
851 ! grep "no-chain-reply-to" errors
854 test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
855 git send-email \
856 --dry-run \
857 --from="Example <nobody@example.com>" \
858 --to=nobody@example.com \
859 --nochain-reply-to \
860 outdir/000?-*.patch 2>errors >out &&
861 ! grep "no-chain-reply-to" errors
864 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
865 git config sendemail.chainreplyto false &&
866 git send-email \
867 --dry-run \
868 --from="Example <nobody@example.com>" \
869 --to=nobody@example.com \
870 outdir/000?-*.patch 2>errors >out &&
871 ! grep "no-chain-reply-to" errors
874 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
875 git config sendemail.chainreplyto true &&
876 git send-email \
877 --dry-run \
878 --from="Example <nobody@example.com>" \
879 --to=nobody@example.com \
880 outdir/000?-*.patch 2>errors >out &&
881 ! grep "no-chain-reply-to" errors
884 test_expect_success $PREREQ 'sendemail.to works' '
885 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
886 git send-email \
887 --dry-run \
888 --from="Example <nobody@example.com>" \
889 $patches $patches >stdout &&
890 grep "To: Somebody <somebody@ex.com>" stdout
893 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
894 git send-email \
895 --dry-run \
896 --from="Example <nobody@example.com>" \
897 --no-to \
898 --to=nobody@example.com \
899 $patches $patches >stdout &&
900 grep "To: nobody@example.com" stdout &&
901 ! grep "To: Somebody <somebody@ex.com>" stdout
904 test_expect_success $PREREQ 'sendemail.cc works' '
905 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
906 git send-email \
907 --dry-run \
908 --from="Example <nobody@example.com>" \
909 --to=nobody@example.com \
910 $patches $patches >stdout &&
911 grep "Cc: Somebody <somebody@ex.com>" stdout
914 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
915 git send-email \
916 --dry-run \
917 --from="Example <nobody@example.com>" \
918 --no-cc \
919 --cc=bodies@example.com \
920 --to=nobody@example.com \
921 $patches $patches >stdout &&
922 grep "Cc: bodies@example.com" stdout &&
923 ! grep "Cc: Somebody <somebody@ex.com>" stdout
926 test_expect_success $PREREQ 'sendemail.bcc works' '
927 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
928 git send-email \
929 --dry-run \
930 --from="Example <nobody@example.com>" \
931 --to=nobody@example.com \
932 --smtp-server relay.example.com \
933 $patches $patches >stdout &&
934 grep "RCPT TO:<other@ex.com>" stdout
937 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
938 git send-email \
939 --dry-run \
940 --from="Example <nobody@example.com>" \
941 --no-bcc \
942 --bcc=bodies@example.com \
943 --to=nobody@example.com \
944 --smtp-server relay.example.com \
945 $patches $patches >stdout &&
946 grep "RCPT TO:<bodies@example.com>" stdout &&
947 ! grep "RCPT TO:<other@ex.com>" stdout
950 test_expect_success $PREREQ 'setup expect' '
951 cat >email-using-8bit <<EOF
952 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
953 Message-Id: <bogus-message-id@example.com>
954 From: author@example.com
955 Date: Sat, 12 Jun 2010 15:53:58 +0200
956 Subject: subject goes here
958 Dieser deutsche Text enthält einen Umlaut!
962 test_expect_success $PREREQ 'setup expect' '
963 cat >content-type-decl <<EOF
964 MIME-Version: 1.0
965 Content-Type: text/plain; charset=UTF-8
966 Content-Transfer-Encoding: 8bit
970 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
971 clean_fake_sendmail &&
972 echo |
973 git send-email --from=author@example.com --to=nobody@example.com \
974 --smtp-server="$(pwd)/fake.sendmail" \
975 email-using-8bit >stdout &&
976 grep "do not declare a Content-Transfer-Encoding" stdout &&
977 grep email-using-8bit stdout &&
978 grep "Which 8bit encoding" stdout &&
979 egrep "Content|MIME" msgtxt1 >actual &&
980 test_cmp actual content-type-decl
983 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
984 clean_fake_sendmail &&
985 git config sendemail.assume8bitEncoding UTF-8 &&
986 echo bogus |
987 git send-email --from=author@example.com --to=nobody@example.com \
988 --smtp-server="$(pwd)/fake.sendmail" \
989 email-using-8bit >stdout &&
990 egrep "Content|MIME" msgtxt1 >actual &&
991 test_cmp actual content-type-decl
994 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
995 clean_fake_sendmail &&
996 git config sendemail.assume8bitEncoding "bogus too" &&
997 echo bogus |
998 git send-email --from=author@example.com --to=nobody@example.com \
999 --smtp-server="$(pwd)/fake.sendmail" \
1000 --8bit-encoding=UTF-8 \
1001 email-using-8bit >stdout &&
1002 egrep "Content|MIME" msgtxt1 >actual &&
1003 test_cmp actual content-type-decl
1006 test_expect_success $PREREQ 'setup expect' '
1007 cat >email-using-8bit <<EOF
1008 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1009 Message-Id: <bogus-message-id@example.com>
1010 From: author@example.com
1011 Date: Sat, 12 Jun 2010 15:53:58 +0200
1012 Subject: Dieser Betreff enthält auch einen Umlaut!
1014 Nothing to see here.
1018 test_expect_success $PREREQ 'setup expect' '
1019 cat >expected <<EOF
1020 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1024 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1025 clean_fake_sendmail &&
1026 echo bogus |
1027 git send-email --from=author@example.com --to=nobody@example.com \
1028 --smtp-server="$(pwd)/fake.sendmail" \
1029 --8bit-encoding=UTF-8 \
1030 email-using-8bit >stdout &&
1031 grep "Subject" msgtxt1 >actual &&
1032 test_cmp expected actual
1035 # Note that the patches in this test are deliberately out of order; we
1036 # want to make sure it works even if the cover-letter is not in the
1037 # first mail.
1038 test_expect_success $PREREQ 'refusing to send cover letter template' '
1039 clean_fake_sendmail &&
1040 rm -fr outdir &&
1041 git format-patch --cover-letter -2 -o outdir &&
1042 test_must_fail git send-email \
1043 --from="Example <nobody@example.com>" \
1044 --to=nobody@example.com \
1045 --smtp-server="$(pwd)/fake.sendmail" \
1046 outdir/0002-*.patch \
1047 outdir/0000-*.patch \
1048 outdir/0001-*.patch \
1049 2>errors >out &&
1050 grep "SUBJECT HERE" errors &&
1051 test -z "$(ls msgtxt*)"
1054 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1055 clean_fake_sendmail &&
1056 rm -fr outdir &&
1057 git format-patch --cover-letter -2 -o outdir &&
1058 git send-email \
1059 --force \
1060 --from="Example <nobody@example.com>" \
1061 --to=nobody@example.com \
1062 --smtp-server="$(pwd)/fake.sendmail" \
1063 outdir/0002-*.patch \
1064 outdir/0000-*.patch \
1065 outdir/0001-*.patch \
1066 2>errors >out &&
1067 ! grep "SUBJECT HERE" errors &&
1068 test -n "$(ls msgtxt*)"
1071 test_done