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