Merge branch 'mn/maint-iconv-autoconf'
[git] / t / t9001-send-email.sh
1 #!/bin/sh
2
3 test_description='git send-email'
4 . ./test-lib.sh
5
6 if ! test_have_prereq PERL; then
7         say 'skipping git send-email tests, perl not available'
8         test_done
9 fi
10
11 PROG='git send-email'
12 test_expect_success \
13     'prepare reference tree' \
14     'echo "1A quick brown fox jumps over the" >file &&
15      echo "lazy dog" >>file &&
16      git add file &&
17      GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
18
19 test_expect_success \
20     'Setup helper tool' \
21     '(echo "#!$SHELL_PATH"
22       echo shift
23       echo output=1
24       echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
25       echo for a
26       echo do
27       echo "  echo \"!\$a!\""
28       echo "done >commandline\$output"
29       echo "cat > msgtxt\$output"
30       ) >fake.sendmail &&
31      chmod +x ./fake.sendmail &&
32      git add fake.sendmail &&
33      GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
34
35 clean_fake_sendmail() {
36         rm -f commandline* msgtxt*
37 }
38
39 test_expect_success 'Extract patches' '
40     patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
41 '
42
43 # Test no confirm early to ensure remaining tests will not hang
44 test_no_confirm () {
45         rm -f no_confirm_okay
46         echo n | \
47                 GIT_SEND_EMAIL_NOTTY=1 \
48                 git send-email \
49                 --from="Example <from@example.com>" \
50                 --to=nobody@example.com \
51                 --smtp-server="$(pwd)/fake.sendmail" \
52                 $@ \
53                 $patches > stdout &&
54                 test_must_fail grep "Send this email" stdout &&
55                 > no_confirm_okay
56 }
57
58 # Exit immediately to prevent hang if a no-confirm test fails
59 check_no_confirm () {
60         test -f no_confirm_okay || {
61                 say 'No confirm test failed; skipping remaining tests to prevent hanging'
62                 test_done
63         }
64 }
65
66 test_expect_success 'No confirm with --suppress-cc' '
67         test_no_confirm --suppress-cc=sob
68 '
69 check_no_confirm
70
71 test_expect_success 'No confirm with --confirm=never' '
72         test_no_confirm --confirm=never
73 '
74 check_no_confirm
75
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
81 '
82 check_no_confirm
83
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
86 '
87
88 cat >expected <<\EOF
89 !nobody@example.com!
90 !author@example.com!
91 !one@example.com!
92 !two@example.com!
93 EOF
94 test_expect_success \
95     'Verify commandline' \
96     'test_cmp expected commandline1'
97
98 cat >expected-show-all-headers <<\EOF
99 0001-Second.patch
100 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
101 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
102 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
103 Dry-OK. Log says:
104 Server: relay.example.com
105 MAIL FROM:<from@example.com>
106 RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<bcc@example.com>
107 From: Example <from@example.com>
108 To: to@example.com
109 Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
110 Subject: [PATCH 1/1] Second.
111 Date: DATE-STRING
112 Message-Id: MESSAGE-ID-STRING
113 X-Mailer: X-MAILER-STRING
114 In-Reply-To: <unique-message-id@example.com>
115 References: <unique-message-id@example.com>
116
117 Result: OK
118 EOF
119
120 test_expect_success 'Show all headers' '
121         git send-email \
122                 --dry-run \
123                 --suppress-cc=sob \
124                 --from="Example <from@example.com>" \
125                 --to=to@example.com \
126                 --cc=cc@example.com \
127                 --bcc=bcc@example.com \
128                 --in-reply-to="<unique-message-id@example.com>" \
129                 --smtp-server relay.example.com \
130                 $patches |
131         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
132                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
133                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
134                 >actual-show-all-headers &&
135         test_cmp expected-show-all-headers actual-show-all-headers
136 '
137
138 test_expect_success 'Prompting works' '
139         clean_fake_sendmail &&
140         (echo "Example <from@example.com>"
141          echo "to@example.com"
142          echo ""
143         ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
144                 --smtp-server="$(pwd)/fake.sendmail" \
145                 $patches \
146                 2>errors &&
147                 grep "^From: Example <from@example.com>$" msgtxt1 &&
148                 grep "^To: to@example.com$" msgtxt1
149 '
150
151 test_expect_success 'cccmd works' '
152         clean_fake_sendmail &&
153         cp $patches cccmd.patch &&
154         echo cccmd--cccmd@example.com >>cccmd.patch &&
155         echo sed -n s/^cccmd--//p \"\$1\" > cccmd-sed &&
156         chmod +x cccmd-sed &&
157         git send-email \
158                 --from="Example <nobody@example.com>" \
159                 --to=nobody@example.com \
160                 --cc-cmd=./cccmd-sed \
161                 --smtp-server="$(pwd)/fake.sendmail" \
162                 cccmd.patch \
163                 &&
164         grep ^Cc:.*cccmd@example.com msgtxt1
165 '
166
167 z8=zzzzzzzz
168 z64=$z8$z8$z8$z8$z8$z8$z8$z8
169 z512=$z64$z64$z64$z64$z64$z64$z64$z64
170 test_expect_success 'reject long lines' '
171         clean_fake_sendmail &&
172         cp $patches longline.patch &&
173         echo $z512$z512 >>longline.patch &&
174         test_must_fail git send-email \
175                 --from="Example <nobody@example.com>" \
176                 --to=nobody@example.com \
177                 --smtp-server="$(pwd)/fake.sendmail" \
178                 $patches longline.patch \
179                 2>errors &&
180         grep longline.patch errors
181 '
182
183 test_expect_success 'no patch was sent' '
184         ! test -e commandline1
185 '
186
187 test_expect_success 'Author From: in message body' '
188         clean_fake_sendmail &&
189         git send-email \
190                 --from="Example <nobody@example.com>" \
191                 --to=nobody@example.com \
192                 --smtp-server="$(pwd)/fake.sendmail" \
193                 $patches &&
194         sed "1,/^$/d" < msgtxt1 > msgbody1
195         grep "From: A <author@example.com>" msgbody1
196 '
197
198 test_expect_success 'Author From: not in message body' '
199         clean_fake_sendmail &&
200         git send-email \
201                 --from="A <author@example.com>" \
202                 --to=nobody@example.com \
203                 --smtp-server="$(pwd)/fake.sendmail" \
204                 $patches &&
205         sed "1,/^$/d" < msgtxt1 > msgbody1
206         ! grep "From: A <author@example.com>" msgbody1
207 '
208
209 test_expect_success 'allow long lines with --no-validate' '
210         git send-email \
211                 --from="Example <nobody@example.com>" \
212                 --to=nobody@example.com \
213                 --smtp-server="$(pwd)/fake.sendmail" \
214                 --novalidate \
215                 $patches longline.patch \
216                 2>errors
217 '
218
219 test_expect_success 'Invalid In-Reply-To' '
220         clean_fake_sendmail &&
221         git send-email \
222                 --from="Example <nobody@example.com>" \
223                 --to=nobody@example.com \
224                 --in-reply-to=" " \
225                 --smtp-server="$(pwd)/fake.sendmail" \
226                 $patches
227                 2>errors
228         ! grep "^In-Reply-To: < *>" msgtxt1
229 '
230
231 test_expect_success 'Valid In-Reply-To when prompting' '
232         clean_fake_sendmail &&
233         (echo "From Example <from@example.com>"
234          echo "To Example <to@example.com>"
235          echo ""
236         ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
237                 --smtp-server="$(pwd)/fake.sendmail" \
238                 $patches 2>errors &&
239         ! grep "^In-Reply-To: < *>" msgtxt1
240 '
241
242 test_expect_success 'setup fake editor' '
243         (echo "#!$SHELL_PATH" &&
244          echo "echo fake edit >>\"\$1\""
245         ) >fake-editor &&
246         chmod +x fake-editor
247 '
248
249 test_set_editor "$(pwd)/fake-editor"
250
251 test_expect_success '--compose works' '
252         clean_fake_sendmail &&
253         git send-email \
254         --compose --subject foo \
255         --from="Example <nobody@example.com>" \
256         --to=nobody@example.com \
257         --smtp-server="$(pwd)/fake.sendmail" \
258         $patches \
259         2>errors
260 '
261
262 test_expect_success 'first message is compose text' '
263         grep "^fake edit" msgtxt1
264 '
265
266 test_expect_success 'second message is patch' '
267         grep "Subject:.*Second" msgtxt2
268 '
269
270 cat >expected-suppress-sob <<\EOF
271 0001-Second.patch
272 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
273 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
274 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
275 Dry-OK. Log says:
276 Server: relay.example.com
277 MAIL FROM:<from@example.com>
278 RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
279 From: Example <from@example.com>
280 To: to@example.com
281 Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
282 Subject: [PATCH 1/1] Second.
283 Date: DATE-STRING
284 Message-Id: MESSAGE-ID-STRING
285 X-Mailer: X-MAILER-STRING
286
287 Result: OK
288 EOF
289
290 test_suppression () {
291         git send-email \
292                 --dry-run \
293                 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
294                 --from="Example <from@example.com>" \
295                 --to=to@example.com \
296                 --smtp-server relay.example.com \
297                 $patches |
298         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
299                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
300                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
301                 >actual-suppress-$1${2+"-$2"} &&
302         test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
303 }
304
305 test_expect_success 'sendemail.cc set' '
306         git config sendemail.cc cc@example.com &&
307         test_suppression sob
308 '
309
310 cat >expected-suppress-sob <<\EOF
311 0001-Second.patch
312 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
313 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
314 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
315 Dry-OK. Log says:
316 Server: relay.example.com
317 MAIL FROM:<from@example.com>
318 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
319 From: Example <from@example.com>
320 To: to@example.com
321 Cc: A <author@example.com>, One <one@example.com>, two@example.com
322 Subject: [PATCH 1/1] Second.
323 Date: DATE-STRING
324 Message-Id: MESSAGE-ID-STRING
325 X-Mailer: X-MAILER-STRING
326
327 Result: OK
328 EOF
329
330 test_expect_success 'sendemail.cc unset' '
331         git config --unset sendemail.cc &&
332         test_suppression sob
333 '
334
335 cat >expected-suppress-cccmd <<\EOF
336 0001-Second.patch
337 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
338 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
339 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
340 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
341 Dry-OK. Log says:
342 Server: relay.example.com
343 MAIL FROM:<from@example.com>
344 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com>
345 From: Example <from@example.com>
346 To: to@example.com
347 Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com>
348 Subject: [PATCH 1/1] Second.
349 Date: DATE-STRING
350 Message-Id: MESSAGE-ID-STRING
351 X-Mailer: X-MAILER-STRING
352
353 Result: OK
354 EOF
355
356 test_expect_success 'sendemail.cccmd' '
357         echo echo cc-cmd@example.com > cccmd &&
358         chmod +x cccmd &&
359         git config sendemail.cccmd ./cccmd &&
360         test_suppression cccmd
361 '
362
363 cat >expected-suppress-all <<\EOF
364 0001-Second.patch
365 Dry-OK. Log says:
366 Server: relay.example.com
367 MAIL FROM:<from@example.com>
368 RCPT TO:<to@example.com>
369 From: Example <from@example.com>
370 To: to@example.com
371 Subject: [PATCH 1/1] Second.
372 Date: DATE-STRING
373 Message-Id: MESSAGE-ID-STRING
374 X-Mailer: X-MAILER-STRING
375
376 Result: OK
377 EOF
378
379 test_expect_success '--suppress-cc=all' '
380         test_suppression all
381 '
382
383 cat >expected-suppress-body <<\EOF
384 0001-Second.patch
385 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
386 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
387 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
388 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
389 Dry-OK. Log says:
390 Server: relay.example.com
391 MAIL FROM:<from@example.com>
392 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<cc-cmd@example.com>
393 From: Example <from@example.com>
394 To: to@example.com
395 Cc: A <author@example.com>, One <one@example.com>, two@example.com, cc-cmd@example.com
396 Subject: [PATCH 1/1] Second.
397 Date: DATE-STRING
398 Message-Id: MESSAGE-ID-STRING
399 X-Mailer: X-MAILER-STRING
400
401 Result: OK
402 EOF
403
404 test_expect_success '--suppress-cc=body' '
405         test_suppression body
406 '
407
408 cat >expected-suppress-body-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 Dry-OK. Log says:
414 Server: relay.example.com
415 MAIL FROM:<from@example.com>
416 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
417 From: Example <from@example.com>
418 To: to@example.com
419 Cc: A <author@example.com>, One <one@example.com>, two@example.com
420 Subject: [PATCH 1/1] Second.
421 Date: DATE-STRING
422 Message-Id: MESSAGE-ID-STRING
423 X-Mailer: X-MAILER-STRING
424
425 Result: OK
426 EOF
427
428 test_expect_success '--suppress-cc=body --suppress-cc=cccmd' '
429         test_suppression body cccmd
430 '
431
432 cat >expected-suppress-sob <<\EOF
433 0001-Second.patch
434 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
435 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
436 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
437 Dry-OK. Log says:
438 Server: relay.example.com
439 MAIL FROM:<from@example.com>
440 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
441 From: Example <from@example.com>
442 To: to@example.com
443 Cc: A <author@example.com>, One <one@example.com>, two@example.com
444 Subject: [PATCH 1/1] Second.
445 Date: DATE-STRING
446 Message-Id: MESSAGE-ID-STRING
447 X-Mailer: X-MAILER-STRING
448
449 Result: OK
450 EOF
451
452 test_expect_success '--suppress-cc=sob' '
453         git config --unset sendemail.cccmd
454         test_suppression sob
455 '
456
457 cat >expected-suppress-bodycc <<\EOF
458 0001-Second.patch
459 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
460 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
461 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
462 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
463 Dry-OK. Log says:
464 Server: relay.example.com
465 MAIL FROM:<from@example.com>
466 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com>
467 From: Example <from@example.com>
468 To: to@example.com
469 Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com>
470 Subject: [PATCH 1/1] Second.
471 Date: DATE-STRING
472 Message-Id: MESSAGE-ID-STRING
473 X-Mailer: X-MAILER-STRING
474
475 Result: OK
476 EOF
477
478 test_expect_success '--suppress-cc=bodycc' '
479         test_suppression bodycc
480 '
481
482 cat >expected-suppress-cc <<\EOF
483 0001-Second.patch
484 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
485 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
486 Dry-OK. Log says:
487 Server: relay.example.com
488 MAIL FROM:<from@example.com>
489 RCPT TO:<to@example.com>,<author@example.com>,<committer@example.com>
490 From: Example <from@example.com>
491 To: to@example.com
492 Cc: A <author@example.com>, C O Mitter <committer@example.com>
493 Subject: [PATCH 1/1] Second.
494 Date: DATE-STRING
495 Message-Id: MESSAGE-ID-STRING
496 X-Mailer: X-MAILER-STRING
497
498 Result: OK
499 EOF
500
501 test_expect_success '--suppress-cc=cc' '
502         test_suppression cc
503 '
504
505 test_confirm () {
506         echo y | \
507                 GIT_SEND_EMAIL_NOTTY=1 \
508                 git send-email \
509                 --from="Example <nobody@example.com>" \
510                 --to=nobody@example.com \
511                 --smtp-server="$(pwd)/fake.sendmail" \
512                 $@ $patches > stdout &&
513         grep "Send this email" stdout
514 }
515
516 test_expect_success '--confirm=always' '
517         test_confirm --confirm=always --suppress-cc=all
518 '
519
520 test_expect_success '--confirm=auto' '
521         test_confirm --confirm=auto
522 '
523
524 test_expect_success '--confirm=cc' '
525         test_confirm --confirm=cc
526 '
527
528 test_expect_success '--confirm=compose' '
529         test_confirm --confirm=compose --compose
530 '
531
532 test_expect_success 'confirm by default (due to cc)' '
533         CONFIRM=$(git config --get sendemail.confirm) &&
534         git config --unset sendemail.confirm &&
535         test_confirm
536         ret="$?"
537         git config sendemail.confirm ${CONFIRM:-never}
538         test $ret = "0"
539 '
540
541 test_expect_success 'confirm by default (due to --compose)' '
542         CONFIRM=$(git config --get sendemail.confirm) &&
543         git config --unset sendemail.confirm &&
544         test_confirm --suppress-cc=all --compose
545         ret="$?"
546         git config sendemail.confirm ${CONFIRM:-never}
547         test $ret = "0"
548 '
549
550 test_expect_success 'confirm detects EOF (inform assumes y)' '
551         CONFIRM=$(git config --get sendemail.confirm) &&
552         git config --unset sendemail.confirm &&
553         rm -fr outdir &&
554         git format-patch -2 -o outdir &&
555         GIT_SEND_EMAIL_NOTTY=1 \
556                 git send-email \
557                         --from="Example <nobody@example.com>" \
558                         --to=nobody@example.com \
559                         --smtp-server="$(pwd)/fake.sendmail" \
560                         outdir/*.patch < /dev/null
561         ret="$?"
562         git config sendemail.confirm ${CONFIRM:-never}
563         test $ret = "0"
564 '
565
566 test_expect_success 'confirm detects EOF (auto causes failure)' '
567         CONFIRM=$(git config --get sendemail.confirm) &&
568         git config sendemail.confirm auto &&
569         GIT_SEND_EMAIL_NOTTY=1 &&
570         export GIT_SEND_EMAIL_NOTTY &&
571                 test_must_fail git send-email \
572                         --from="Example <nobody@example.com>" \
573                         --to=nobody@example.com \
574                         --smtp-server="$(pwd)/fake.sendmail" \
575                         $patches < /dev/null
576         ret="$?"
577         git config sendemail.confirm ${CONFIRM:-never}
578         test $ret = "0"
579 '
580
581 test_expect_success 'confirm doesnt loop forever' '
582         CONFIRM=$(git config --get sendemail.confirm) &&
583         git config sendemail.confirm auto &&
584         GIT_SEND_EMAIL_NOTTY=1 &&
585         export GIT_SEND_EMAIL_NOTTY &&
586                 yes "bogus" | test_must_fail git send-email \
587                         --from="Example <nobody@example.com>" \
588                         --to=nobody@example.com \
589                         --smtp-server="$(pwd)/fake.sendmail" \
590                         $patches
591         ret="$?"
592         git config sendemail.confirm ${CONFIRM:-never}
593         test $ret = "0"
594 '
595
596 test_expect_success 'utf8 Cc is rfc2047 encoded' '
597         clean_fake_sendmail &&
598         rm -fr outdir &&
599         git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
600         git send-email \
601         --from="Example <nobody@example.com>" \
602         --to=nobody@example.com \
603         --smtp-server="$(pwd)/fake.sendmail" \
604         outdir/*.patch &&
605         grep "^Cc:" msgtxt1 |
606         grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
607 '
608
609 test_expect_success '--compose adds MIME for utf8 body' '
610         clean_fake_sendmail &&
611         (echo "#!$SHELL_PATH" &&
612          echo "echo utf8 body: àéìöú >>\"\$1\""
613         ) >fake-editor-utf8 &&
614         chmod +x fake-editor-utf8 &&
615           GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
616           git send-email \
617           --compose --subject foo \
618           --from="Example <nobody@example.com>" \
619           --to=nobody@example.com \
620           --smtp-server="$(pwd)/fake.sendmail" \
621           $patches &&
622         grep "^utf8 body" msgtxt1 &&
623         grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
624 '
625
626 test_expect_success '--compose respects user mime type' '
627         clean_fake_sendmail &&
628         (echo "#!$SHELL_PATH" &&
629          echo "(echo MIME-Version: 1.0"
630          echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
631          echo " echo Content-Transfer-Encoding: 8bit"
632          echo " echo Subject: foo"
633          echo " echo "
634          echo " echo utf8 body: àéìöú) >\"\$1\""
635         ) >fake-editor-utf8-mime &&
636         chmod +x fake-editor-utf8-mime &&
637           GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
638           git send-email \
639           --compose --subject foo \
640           --from="Example <nobody@example.com>" \
641           --to=nobody@example.com \
642           --smtp-server="$(pwd)/fake.sendmail" \
643           $patches &&
644         grep "^utf8 body" msgtxt1 &&
645         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
646         ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
647 '
648
649 test_expect_success '--compose adds MIME for utf8 subject' '
650         clean_fake_sendmail &&
651           GIT_EDITOR="\"$(pwd)/fake-editor\"" \
652           git send-email \
653           --compose --subject utf8-sübjëct \
654           --from="Example <nobody@example.com>" \
655           --to=nobody@example.com \
656           --smtp-server="$(pwd)/fake.sendmail" \
657           $patches &&
658         grep "^fake edit" msgtxt1 &&
659         grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
660 '
661
662 test_expect_success 'detects ambiguous reference/file conflict' '
663         echo master > master &&
664         git add master &&
665         git commit -m"add master" &&
666         test_must_fail git send-email --dry-run master 2>errors &&
667         grep disambiguate errors
668 '
669
670 test_expect_success 'feed two files' '
671         rm -fr outdir &&
672         git format-patch -2 -o outdir &&
673         git send-email \
674         --dry-run \
675         --from="Example <nobody@example.com>" \
676         --to=nobody@example.com \
677         outdir/000?-*.patch 2>errors >out &&
678         grep "^Subject: " out >subjects &&
679         test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
680         test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
681 '
682
683 test_expect_success 'in-reply-to but no threading' '
684         git send-email \
685                 --dry-run \
686                 --from="Example <nobody@example.com>" \
687                 --to=nobody@example.com \
688                 --in-reply-to="<in-reply-id@example.com>" \
689                 --nothread \
690                 $patches |
691         grep "In-Reply-To: <in-reply-id@example.com>"
692 '
693
694 test_expect_success 'no in-reply-to and no threading' '
695         git send-email \
696                 --dry-run \
697                 --from="Example <nobody@example.com>" \
698                 --to=nobody@example.com \
699                 --nothread \
700                 $patches $patches >stdout &&
701         ! grep "In-Reply-To: " stdout
702 '
703
704 test_expect_success 'threading but no chain-reply-to' '
705         git send-email \
706                 --dry-run \
707                 --from="Example <nobody@example.com>" \
708                 --to=nobody@example.com \
709                 --thread \
710                 --nochain-reply-to \
711                 $patches $patches >stdout &&
712         grep "In-Reply-To: " stdout
713 '
714
715 test_done