t/t9001-send-email.sh: Remove needless PROG=* assignment
[git/mjg.git] / t / t9001-send-email.sh
blob6525d1dacd3f2fe7cfd7380c8f7fd0a2fc03309a
1 #!/bin/sh
3 test_description='git send-email'
4 . ./test-lib.sh
6 if ! test_have_prereq PERL; then
7 skip_all='skipping git send-email tests, perl not available'
8 test_done
9 fi
11 test_expect_success \
12 'prepare reference tree' \
13 'echo "1A quick brown fox jumps over the" >file &&
14 echo "lazy dog" >>file &&
15 git add file &&
16 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
18 test_expect_success \
19 'Setup helper tool' \
20 '(echo "#!$SHELL_PATH"
21 echo shift
22 echo output=1
23 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
24 echo for a
25 echo do
26 echo " echo \"!\$a!\""
27 echo "done >commandline\$output"
28 echo "cat > msgtxt\$output"
29 ) >fake.sendmail &&
30 chmod +x ./fake.sendmail &&
31 git add fake.sendmail &&
32 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
34 clean_fake_sendmail() {
35 rm -f commandline* msgtxt*
38 test_expect_success 'Extract patches' '
39 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
42 # Test no confirm early to ensure remaining tests will not hang
43 test_no_confirm () {
44 rm -f no_confirm_okay
45 echo n | \
46 GIT_SEND_EMAIL_NOTTY=1 \
47 git send-email \
48 --from="Example <from@example.com>" \
49 --to=nobody@example.com \
50 --smtp-server="$(pwd)/fake.sendmail" \
51 $@ \
52 $patches > stdout &&
53 test_must_fail grep "Send this email" stdout &&
54 > no_confirm_okay
57 # Exit immediately to prevent hang if a no-confirm test fails
58 check_no_confirm () {
59 test -f no_confirm_okay || {
60 skip_all='confirm test failed; skipping remaining tests to prevent hanging'
61 test_done
65 test_expect_success 'No confirm with --suppress-cc' '
66 test_no_confirm --suppress-cc=sob
68 check_no_confirm
70 test_expect_success 'No confirm with --confirm=never' '
71 test_no_confirm --confirm=never
73 check_no_confirm
75 # leave sendemail.confirm set to never after this so that none of the
76 # remaining tests prompt unintentionally.
77 test_expect_success 'No confirm with sendemail.confirm=never' '
78 git config sendemail.confirm never &&
79 test_no_confirm --compose --subject=foo
81 check_no_confirm
83 test_expect_success 'Send patches' '
84 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
87 cat >expected <<\EOF
88 !nobody@example.com!
89 !author@example.com!
90 !one@example.com!
91 !two@example.com!
92 EOF
93 test_expect_success \
94 'Verify commandline' \
95 'test_cmp expected commandline1'
97 test_expect_success 'Send patches with --envelope-sender' '
98 clean_fake_sendmail &&
99 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
102 cat >expected <<\EOF
103 !patch@example.com!
104 !-i!
105 !nobody@example.com!
106 !author@example.com!
107 !one@example.com!
108 !two@example.com!
110 test_expect_success \
111 'Verify commandline' \
112 'test_cmp expected commandline1'
114 test_expect_success 'Send patches with --envelope-sender=auto' '
115 clean_fake_sendmail &&
116 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
119 cat >expected <<\EOF
120 !nobody@example.com!
121 !-i!
122 !nobody@example.com!
123 !author@example.com!
124 !one@example.com!
125 !two@example.com!
127 test_expect_success \
128 'Verify commandline' \
129 'test_cmp expected commandline1'
131 cat >expected-show-all-headers <<\EOF
132 0001-Second.patch
133 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
134 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
135 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
136 Dry-OK. Log says:
137 Server: relay.example.com
138 MAIL FROM:<from@example.com>
139 RCPT TO:<to@example.com>
140 RCPT TO:<cc@example.com>
141 RCPT TO:<author@example.com>
142 RCPT TO:<one@example.com>
143 RCPT TO:<two@example.com>
144 RCPT TO:<bcc@example.com>
145 From: Example <from@example.com>
146 To: to@example.com
147 Cc: cc@example.com,
148 A <author@example.com>,
149 One <one@example.com>,
150 two@example.com
151 Subject: [PATCH 1/1] Second.
152 Date: DATE-STRING
153 Message-Id: MESSAGE-ID-STRING
154 X-Mailer: X-MAILER-STRING
155 In-Reply-To: <unique-message-id@example.com>
156 References: <unique-message-id@example.com>
158 Result: OK
161 test_expect_success 'Show all headers' '
162 git send-email \
163 --dry-run \
164 --suppress-cc=sob \
165 --from="Example <from@example.com>" \
166 --to=to@example.com \
167 --cc=cc@example.com \
168 --bcc=bcc@example.com \
169 --in-reply-to="<unique-message-id@example.com>" \
170 --smtp-server relay.example.com \
171 $patches |
172 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
173 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
174 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
175 >actual-show-all-headers &&
176 test_cmp expected-show-all-headers actual-show-all-headers
179 test_expect_success 'Prompting works' '
180 clean_fake_sendmail &&
181 (echo "Example <from@example.com>"
182 echo "to@example.com"
183 echo ""
184 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
185 --smtp-server="$(pwd)/fake.sendmail" \
186 $patches \
187 2>errors &&
188 grep "^From: Example <from@example.com>\$" msgtxt1 &&
189 grep "^To: to@example.com\$" msgtxt1
192 test_expect_success 'cccmd works' '
193 clean_fake_sendmail &&
194 cp $patches cccmd.patch &&
195 echo cccmd--cccmd@example.com >>cccmd.patch &&
197 echo "#!$SHELL_PATH"
198 echo sed -n -e s/^cccmd--//p \"\$1\"
199 } > cccmd-sed &&
200 chmod +x cccmd-sed &&
201 git send-email \
202 --from="Example <nobody@example.com>" \
203 --to=nobody@example.com \
204 --cc-cmd=./cccmd-sed \
205 --smtp-server="$(pwd)/fake.sendmail" \
206 cccmd.patch \
208 grep "^ cccmd@example.com" msgtxt1
211 z8=zzzzzzzz
212 z64=$z8$z8$z8$z8$z8$z8$z8$z8
213 z512=$z64$z64$z64$z64$z64$z64$z64$z64
214 test_expect_success 'reject long lines' '
215 clean_fake_sendmail &&
216 cp $patches longline.patch &&
217 echo $z512$z512 >>longline.patch &&
218 test_must_fail git send-email \
219 --from="Example <nobody@example.com>" \
220 --to=nobody@example.com \
221 --smtp-server="$(pwd)/fake.sendmail" \
222 $patches longline.patch \
223 2>errors &&
224 grep longline.patch errors
227 test_expect_success 'no patch was sent' '
228 ! test -e commandline1
231 test_expect_success 'Author From: in message body' '
232 clean_fake_sendmail &&
233 git send-email \
234 --from="Example <nobody@example.com>" \
235 --to=nobody@example.com \
236 --smtp-server="$(pwd)/fake.sendmail" \
237 $patches &&
238 sed "1,/^\$/d" < msgtxt1 > msgbody1
239 grep "From: A <author@example.com>" msgbody1
242 test_expect_success 'Author From: not in message body' '
243 clean_fake_sendmail &&
244 git send-email \
245 --from="A <author@example.com>" \
246 --to=nobody@example.com \
247 --smtp-server="$(pwd)/fake.sendmail" \
248 $patches &&
249 sed "1,/^\$/d" < msgtxt1 > msgbody1
250 ! grep "From: A <author@example.com>" msgbody1
253 test_expect_success 'allow long lines with --no-validate' '
254 git send-email \
255 --from="Example <nobody@example.com>" \
256 --to=nobody@example.com \
257 --smtp-server="$(pwd)/fake.sendmail" \
258 --novalidate \
259 $patches longline.patch \
260 2>errors
263 test_expect_success 'Invalid In-Reply-To' '
264 clean_fake_sendmail &&
265 git send-email \
266 --from="Example <nobody@example.com>" \
267 --to=nobody@example.com \
268 --in-reply-to=" " \
269 --smtp-server="$(pwd)/fake.sendmail" \
270 $patches
271 2>errors
272 ! grep "^In-Reply-To: < *>" msgtxt1
275 test_expect_success 'Valid In-Reply-To when prompting' '
276 clean_fake_sendmail &&
277 (echo "From Example <from@example.com>"
278 echo "To Example <to@example.com>"
279 echo ""
280 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
281 --smtp-server="$(pwd)/fake.sendmail" \
282 $patches 2>errors &&
283 ! grep "^In-Reply-To: < *>" msgtxt1
286 test_expect_success 'setup fake editor' '
287 (echo "#!$SHELL_PATH" &&
288 echo "echo fake edit >>\"\$1\""
289 ) >fake-editor &&
290 chmod +x fake-editor
293 test_set_editor "$(pwd)/fake-editor"
295 test_expect_success '--compose works' '
296 clean_fake_sendmail &&
297 git send-email \
298 --compose --subject foo \
299 --from="Example <nobody@example.com>" \
300 --to=nobody@example.com \
301 --smtp-server="$(pwd)/fake.sendmail" \
302 $patches \
303 2>errors
306 test_expect_success 'first message is compose text' '
307 grep "^fake edit" msgtxt1
310 test_expect_success 'second message is patch' '
311 grep "Subject:.*Second" msgtxt2
314 cat >expected-suppress-sob <<\EOF
315 0001-Second.patch
316 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
317 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
318 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
319 Dry-OK. Log says:
320 Server: relay.example.com
321 MAIL FROM:<from@example.com>
322 RCPT TO:<to@example.com>
323 RCPT TO:<cc@example.com>
324 RCPT TO:<author@example.com>
325 RCPT TO:<one@example.com>
326 RCPT TO:<two@example.com>
327 From: Example <from@example.com>
328 To: to@example.com
329 Cc: cc@example.com,
330 A <author@example.com>,
331 One <one@example.com>,
332 two@example.com
333 Subject: [PATCH 1/1] Second.
334 Date: DATE-STRING
335 Message-Id: MESSAGE-ID-STRING
336 X-Mailer: X-MAILER-STRING
338 Result: OK
341 test_suppression () {
342 git send-email \
343 --dry-run \
344 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
345 --from="Example <from@example.com>" \
346 --to=to@example.com \
347 --smtp-server relay.example.com \
348 $patches |
349 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
350 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
351 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
352 >actual-suppress-$1${2+"-$2"} &&
353 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
356 test_expect_success 'sendemail.cc set' '
357 git config sendemail.cc cc@example.com &&
358 test_suppression sob
361 cat >expected-suppress-sob <<\EOF
362 0001-Second.patch
363 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
364 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
365 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
366 Dry-OK. Log says:
367 Server: relay.example.com
368 MAIL FROM:<from@example.com>
369 RCPT TO:<to@example.com>
370 RCPT TO:<author@example.com>
371 RCPT TO:<one@example.com>
372 RCPT TO:<two@example.com>
373 From: Example <from@example.com>
374 To: to@example.com
375 Cc: A <author@example.com>,
376 One <one@example.com>,
377 two@example.com
378 Subject: [PATCH 1/1] Second.
379 Date: DATE-STRING
380 Message-Id: MESSAGE-ID-STRING
381 X-Mailer: X-MAILER-STRING
383 Result: OK
386 test_expect_success 'sendemail.cc unset' '
387 git config --unset sendemail.cc &&
388 test_suppression sob
391 cat >expected-suppress-cccmd <<\EOF
392 0001-Second.patch
393 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
394 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
395 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
396 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
397 Dry-OK. Log says:
398 Server: relay.example.com
399 MAIL FROM:<from@example.com>
400 RCPT TO:<to@example.com>
401 RCPT TO:<author@example.com>
402 RCPT TO:<one@example.com>
403 RCPT TO:<two@example.com>
404 RCPT TO:<committer@example.com>
405 From: Example <from@example.com>
406 To: to@example.com
407 Cc: A <author@example.com>,
408 One <one@example.com>,
409 two@example.com,
410 C O Mitter <committer@example.com>
411 Subject: [PATCH 1/1] Second.
412 Date: DATE-STRING
413 Message-Id: MESSAGE-ID-STRING
414 X-Mailer: X-MAILER-STRING
416 Result: OK
419 test_expect_success 'sendemail.cccmd' '
420 echo echo cc-cmd@example.com > cccmd &&
421 chmod +x cccmd &&
422 git config sendemail.cccmd ./cccmd &&
423 test_suppression cccmd
426 cat >expected-suppress-all <<\EOF
427 0001-Second.patch
428 Dry-OK. Log says:
429 Server: relay.example.com
430 MAIL FROM:<from@example.com>
431 RCPT TO:<to@example.com>
432 From: Example <from@example.com>
433 To: to@example.com
434 Subject: [PATCH 1/1] Second.
435 Date: DATE-STRING
436 Message-Id: MESSAGE-ID-STRING
437 X-Mailer: X-MAILER-STRING
439 Result: OK
442 test_expect_success '--suppress-cc=all' '
443 test_suppression all
446 cat >expected-suppress-body <<\EOF
447 0001-Second.patch
448 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
449 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
450 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
451 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
452 Dry-OK. Log says:
453 Server: relay.example.com
454 MAIL FROM:<from@example.com>
455 RCPT TO:<to@example.com>
456 RCPT TO:<author@example.com>
457 RCPT TO:<one@example.com>
458 RCPT TO:<two@example.com>
459 RCPT TO:<cc-cmd@example.com>
460 From: Example <from@example.com>
461 To: to@example.com
462 Cc: A <author@example.com>,
463 One <one@example.com>,
464 two@example.com,
465 cc-cmd@example.com
466 Subject: [PATCH 1/1] Second.
467 Date: DATE-STRING
468 Message-Id: MESSAGE-ID-STRING
469 X-Mailer: X-MAILER-STRING
471 Result: OK
474 test_expect_success '--suppress-cc=body' '
475 test_suppression body
478 cat >expected-suppress-body-cccmd <<\EOF
479 0001-Second.patch
480 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
481 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
482 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
483 Dry-OK. Log says:
484 Server: relay.example.com
485 MAIL FROM:<from@example.com>
486 RCPT TO:<to@example.com>
487 RCPT TO:<author@example.com>
488 RCPT TO:<one@example.com>
489 RCPT TO:<two@example.com>
490 From: Example <from@example.com>
491 To: to@example.com
492 Cc: A <author@example.com>,
493 One <one@example.com>,
494 two@example.com
495 Subject: [PATCH 1/1] Second.
496 Date: DATE-STRING
497 Message-Id: MESSAGE-ID-STRING
498 X-Mailer: X-MAILER-STRING
500 Result: OK
503 test_expect_success '--suppress-cc=body --suppress-cc=cccmd' '
504 test_suppression body cccmd
507 cat >expected-suppress-sob <<\EOF
508 0001-Second.patch
509 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
510 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
511 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
512 Dry-OK. Log says:
513 Server: relay.example.com
514 MAIL FROM:<from@example.com>
515 RCPT TO:<to@example.com>
516 RCPT TO:<author@example.com>
517 RCPT TO:<one@example.com>
518 RCPT TO:<two@example.com>
519 From: Example <from@example.com>
520 To: to@example.com
521 Cc: A <author@example.com>,
522 One <one@example.com>,
523 two@example.com
524 Subject: [PATCH 1/1] Second.
525 Date: DATE-STRING
526 Message-Id: MESSAGE-ID-STRING
527 X-Mailer: X-MAILER-STRING
529 Result: OK
532 test_expect_success '--suppress-cc=sob' '
533 git config --unset sendemail.cccmd
534 test_suppression sob
537 cat >expected-suppress-bodycc <<\EOF
538 0001-Second.patch
539 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
540 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
541 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
542 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
543 Dry-OK. Log says:
544 Server: relay.example.com
545 MAIL FROM:<from@example.com>
546 RCPT TO:<to@example.com>
547 RCPT TO:<author@example.com>
548 RCPT TO:<one@example.com>
549 RCPT TO:<two@example.com>
550 RCPT TO:<committer@example.com>
551 From: Example <from@example.com>
552 To: to@example.com
553 Cc: A <author@example.com>,
554 One <one@example.com>,
555 two@example.com,
556 C O Mitter <committer@example.com>
557 Subject: [PATCH 1/1] Second.
558 Date: DATE-STRING
559 Message-Id: MESSAGE-ID-STRING
560 X-Mailer: X-MAILER-STRING
562 Result: OK
565 test_expect_success '--suppress-cc=bodycc' '
566 test_suppression bodycc
569 cat >expected-suppress-cc <<\EOF
570 0001-Second.patch
571 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
572 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
573 Dry-OK. Log says:
574 Server: relay.example.com
575 MAIL FROM:<from@example.com>
576 RCPT TO:<to@example.com>
577 RCPT TO:<author@example.com>
578 RCPT TO:<committer@example.com>
579 From: Example <from@example.com>
580 To: to@example.com
581 Cc: A <author@example.com>,
582 C O Mitter <committer@example.com>
583 Subject: [PATCH 1/1] Second.
584 Date: DATE-STRING
585 Message-Id: MESSAGE-ID-STRING
586 X-Mailer: X-MAILER-STRING
588 Result: OK
591 test_expect_success '--suppress-cc=cc' '
592 test_suppression cc
595 test_confirm () {
596 echo y | \
597 GIT_SEND_EMAIL_NOTTY=1 \
598 git send-email \
599 --from="Example <nobody@example.com>" \
600 --to=nobody@example.com \
601 --smtp-server="$(pwd)/fake.sendmail" \
602 $@ $patches > stdout &&
603 grep "Send this email" stdout
606 test_expect_success '--confirm=always' '
607 test_confirm --confirm=always --suppress-cc=all
610 test_expect_success '--confirm=auto' '
611 test_confirm --confirm=auto
614 test_expect_success '--confirm=cc' '
615 test_confirm --confirm=cc
618 test_expect_success '--confirm=compose' '
619 test_confirm --confirm=compose --compose
622 test_expect_success 'confirm by default (due to cc)' '
623 CONFIRM=$(git config --get sendemail.confirm) &&
624 git config --unset sendemail.confirm &&
625 test_confirm
626 ret="$?"
627 git config sendemail.confirm ${CONFIRM:-never}
628 test $ret = "0"
631 test_expect_success 'confirm by default (due to --compose)' '
632 CONFIRM=$(git config --get sendemail.confirm) &&
633 git config --unset sendemail.confirm &&
634 test_confirm --suppress-cc=all --compose
635 ret="$?"
636 git config sendemail.confirm ${CONFIRM:-never}
637 test $ret = "0"
640 test_expect_success 'confirm detects EOF (inform assumes y)' '
641 CONFIRM=$(git config --get sendemail.confirm) &&
642 git config --unset sendemail.confirm &&
643 rm -fr outdir &&
644 git format-patch -2 -o outdir &&
645 GIT_SEND_EMAIL_NOTTY=1 \
646 git send-email \
647 --from="Example <nobody@example.com>" \
648 --to=nobody@example.com \
649 --smtp-server="$(pwd)/fake.sendmail" \
650 outdir/*.patch < /dev/null
651 ret="$?"
652 git config sendemail.confirm ${CONFIRM:-never}
653 test $ret = "0"
656 test_expect_success 'confirm detects EOF (auto causes failure)' '
657 CONFIRM=$(git config --get sendemail.confirm) &&
658 git config sendemail.confirm auto &&
659 GIT_SEND_EMAIL_NOTTY=1 &&
660 export GIT_SEND_EMAIL_NOTTY &&
661 test_must_fail git send-email \
662 --from="Example <nobody@example.com>" \
663 --to=nobody@example.com \
664 --smtp-server="$(pwd)/fake.sendmail" \
665 $patches < /dev/null
666 ret="$?"
667 git config sendemail.confirm ${CONFIRM:-never}
668 test $ret = "0"
671 test_expect_success 'confirm doesnt loop forever' '
672 CONFIRM=$(git config --get sendemail.confirm) &&
673 git config sendemail.confirm auto &&
674 GIT_SEND_EMAIL_NOTTY=1 &&
675 export GIT_SEND_EMAIL_NOTTY &&
676 yes "bogus" | test_must_fail git send-email \
677 --from="Example <nobody@example.com>" \
678 --to=nobody@example.com \
679 --smtp-server="$(pwd)/fake.sendmail" \
680 $patches
681 ret="$?"
682 git config sendemail.confirm ${CONFIRM:-never}
683 test $ret = "0"
686 test_expect_success 'utf8 Cc is rfc2047 encoded' '
687 clean_fake_sendmail &&
688 rm -fr outdir &&
689 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
690 git send-email \
691 --from="Example <nobody@example.com>" \
692 --to=nobody@example.com \
693 --smtp-server="$(pwd)/fake.sendmail" \
694 outdir/*.patch &&
695 grep "^ " msgtxt1 |
696 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
699 test_expect_success '--compose adds MIME for utf8 body' '
700 clean_fake_sendmail &&
701 (echo "#!$SHELL_PATH" &&
702 echo "echo utf8 body: àéìöú >>\"\$1\""
703 ) >fake-editor-utf8 &&
704 chmod +x fake-editor-utf8 &&
705 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
706 git send-email \
707 --compose --subject foo \
708 --from="Example <nobody@example.com>" \
709 --to=nobody@example.com \
710 --smtp-server="$(pwd)/fake.sendmail" \
711 $patches &&
712 grep "^utf8 body" msgtxt1 &&
713 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
716 test_expect_success '--compose respects user mime type' '
717 clean_fake_sendmail &&
718 (echo "#!$SHELL_PATH" &&
719 echo "(echo MIME-Version: 1.0"
720 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
721 echo " echo Content-Transfer-Encoding: 8bit"
722 echo " echo Subject: foo"
723 echo " echo "
724 echo " echo utf8 body: àéìöú) >\"\$1\""
725 ) >fake-editor-utf8-mime &&
726 chmod +x fake-editor-utf8-mime &&
727 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
728 git send-email \
729 --compose --subject foo \
730 --from="Example <nobody@example.com>" \
731 --to=nobody@example.com \
732 --smtp-server="$(pwd)/fake.sendmail" \
733 $patches &&
734 grep "^utf8 body" msgtxt1 &&
735 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
736 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
739 test_expect_success '--compose adds MIME for utf8 subject' '
740 clean_fake_sendmail &&
741 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
742 git send-email \
743 --compose --subject utf8-sübjëct \
744 --from="Example <nobody@example.com>" \
745 --to=nobody@example.com \
746 --smtp-server="$(pwd)/fake.sendmail" \
747 $patches &&
748 grep "^fake edit" msgtxt1 &&
749 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
752 test_expect_success 'detects ambiguous reference/file conflict' '
753 echo master > master &&
754 git add master &&
755 git commit -m"add master" &&
756 test_must_fail git send-email --dry-run master 2>errors &&
757 grep disambiguate errors
760 test_expect_success 'feed two files' '
761 rm -fr outdir &&
762 git format-patch -2 -o outdir &&
763 git send-email \
764 --dry-run \
765 --from="Example <nobody@example.com>" \
766 --to=nobody@example.com \
767 outdir/000?-*.patch 2>errors >out &&
768 grep "^Subject: " out >subjects &&
769 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
770 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
773 test_expect_success 'in-reply-to but no threading' '
774 git send-email \
775 --dry-run \
776 --from="Example <nobody@example.com>" \
777 --to=nobody@example.com \
778 --in-reply-to="<in-reply-id@example.com>" \
779 --nothread \
780 $patches |
781 grep "In-Reply-To: <in-reply-id@example.com>"
784 test_expect_success 'no in-reply-to and no threading' '
785 git send-email \
786 --dry-run \
787 --from="Example <nobody@example.com>" \
788 --to=nobody@example.com \
789 --nothread \
790 $patches $patches >stdout &&
791 ! grep "In-Reply-To: " stdout
794 test_expect_success 'threading but no chain-reply-to' '
795 git send-email \
796 --dry-run \
797 --from="Example <nobody@example.com>" \
798 --to=nobody@example.com \
799 --thread \
800 --nochain-reply-to \
801 $patches $patches >stdout &&
802 grep "In-Reply-To: " stdout
805 test_expect_success 'warning with an implicit --chain-reply-to' '
806 git send-email \
807 --dry-run \
808 --from="Example <nobody@example.com>" \
809 --to=nobody@example.com \
810 outdir/000?-*.patch 2>errors >out &&
811 grep "no-chain-reply-to" errors
814 test_expect_success 'no warning with an explicit --chain-reply-to' '
815 git send-email \
816 --dry-run \
817 --from="Example <nobody@example.com>" \
818 --to=nobody@example.com \
819 --chain-reply-to \
820 outdir/000?-*.patch 2>errors >out &&
821 ! grep "no-chain-reply-to" errors
824 test_expect_success 'no warning with an explicit --no-chain-reply-to' '
825 git send-email \
826 --dry-run \
827 --from="Example <nobody@example.com>" \
828 --to=nobody@example.com \
829 --nochain-reply-to \
830 outdir/000?-*.patch 2>errors >out &&
831 ! grep "no-chain-reply-to" errors
834 test_expect_success 'no warning with sendemail.chainreplyto = false' '
835 git config sendemail.chainreplyto false &&
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 'no warning with sendemail.chainreplyto = true' '
845 git config sendemail.chainreplyto true &&
846 git send-email \
847 --dry-run \
848 --from="Example <nobody@example.com>" \
849 --to=nobody@example.com \
850 outdir/000?-*.patch 2>errors >out &&
851 ! grep "no-chain-reply-to" errors
854 test_expect_success 'sendemail.to works' '
855 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
856 git send-email \
857 --dry-run \
858 --from="Example <nobody@example.com>" \
859 $patches $patches >stdout &&
860 grep "To: Somebody <somebody@ex.com>" stdout
863 test_expect_success '--no-to overrides sendemail.to' '
864 git send-email \
865 --dry-run \
866 --from="Example <nobody@example.com>" \
867 --no-to \
868 --to=nobody@example.com \
869 $patches $patches >stdout &&
870 grep "To: nobody@example.com" stdout &&
871 ! grep "To: Somebody <somebody@ex.com>" stdout
874 test_expect_success 'sendemail.cc works' '
875 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
876 git send-email \
877 --dry-run \
878 --from="Example <nobody@example.com>" \
879 --to=nobody@example.com \
880 $patches $patches >stdout &&
881 grep "Cc: Somebody <somebody@ex.com>" stdout
884 test_expect_success '--no-cc overrides sendemail.cc' '
885 git send-email \
886 --dry-run \
887 --from="Example <nobody@example.com>" \
888 --no-cc \
889 --cc=bodies@example.com \
890 --to=nobody@example.com \
891 $patches $patches >stdout &&
892 grep "Cc: bodies@example.com" stdout &&
893 ! grep "Cc: Somebody <somebody@ex.com>" stdout
896 test_expect_success 'sendemail.bcc works' '
897 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
898 git send-email \
899 --dry-run \
900 --from="Example <nobody@example.com>" \
901 --to=nobody@example.com \
902 --smtp-server relay.example.com \
903 $patches $patches >stdout &&
904 grep "RCPT TO:<other@ex.com>" stdout
907 test_expect_success '--no-bcc overrides sendemail.bcc' '
908 git send-email \
909 --dry-run \
910 --from="Example <nobody@example.com>" \
911 --no-bcc \
912 --bcc=bodies@example.com \
913 --to=nobody@example.com \
914 --smtp-server relay.example.com \
915 $patches $patches >stdout &&
916 grep "RCPT TO:<bodies@example.com>" stdout &&
917 ! grep "RCPT TO:<other@ex.com>" stdout
920 cat >email-using-8bit <<EOF
921 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
922 Message-Id: <bogus-message-id@example.com>
923 From: author@example.com
924 Date: Sat, 12 Jun 2010 15:53:58 +0200
925 Subject: subject goes here
927 Dieser deutsche Text enthält einen Umlaut!
930 cat >content-type-decl <<EOF
931 MIME-Version: 1.0
932 Content-Type: text/plain; charset=UTF-8
933 Content-Transfer-Encoding: 8bit
936 test_expect_success 'asks about and fixes 8bit encodings' '
937 clean_fake_sendmail &&
938 echo |
939 git send-email --from=author@example.com --to=nobody@example.com \
940 --smtp-server="$(pwd)/fake.sendmail" \
941 email-using-8bit >stdout &&
942 grep "do not declare a Content-Transfer-Encoding" stdout &&
943 grep email-using-8bit stdout &&
944 grep "Which 8bit encoding" stdout &&
945 egrep "Content|MIME" msgtxt1 >actual &&
946 test_cmp actual content-type-decl
949 test_expect_success 'sendemail.8bitEncoding works' '
950 clean_fake_sendmail &&
951 git config sendemail.assume8bitEncoding UTF-8 &&
952 echo bogus |
953 git send-email --from=author@example.com --to=nobody@example.com \
954 --smtp-server="$(pwd)/fake.sendmail" \
955 email-using-8bit >stdout &&
956 egrep "Content|MIME" msgtxt1 >actual &&
957 test_cmp actual content-type-decl
960 test_expect_success '--8bit-encoding overrides sendemail.8bitEncoding' '
961 clean_fake_sendmail &&
962 git config sendemail.assume8bitEncoding "bogus too" &&
963 echo bogus |
964 git send-email --from=author@example.com --to=nobody@example.com \
965 --smtp-server="$(pwd)/fake.sendmail" \
966 --8bit-encoding=UTF-8 \
967 email-using-8bit >stdout &&
968 egrep "Content|MIME" msgtxt1 >actual &&
969 test_cmp actual content-type-decl
972 cat >email-using-8bit <<EOF
973 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
974 Message-Id: <bogus-message-id@example.com>
975 From: author@example.com
976 Date: Sat, 12 Jun 2010 15:53:58 +0200
977 Subject: Dieser Betreff enthält auch einen Umlaut!
979 Nothing to see here.
982 cat >expected <<EOF
983 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
986 test_expect_success '--8bit-encoding also treats subject' '
987 clean_fake_sendmail &&
988 echo bogus |
989 git send-email --from=author@example.com --to=nobody@example.com \
990 --smtp-server="$(pwd)/fake.sendmail" \
991 --8bit-encoding=UTF-8 \
992 email-using-8bit >stdout &&
993 grep "Subject" msgtxt1 >actual &&
994 test_cmp expected actual
997 test_done