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