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