]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9001-send-email.sh
send-email: add --no-cc, --no-to, and --no-bcc
[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
c89e3241
FC
115test_expect_success 'Send patches with --envelope-sender=auto' '
116 clean_fake_sendmail &&
117 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
118'
119
120cat >expected <<\EOF
121!nobody@example.com!
122!-i!
123!nobody@example.com!
124!author@example.com!
125!one@example.com!
126!two@example.com!
127EOF
128test_expect_success \
129 'Verify commandline' \
130 'test_cmp expected commandline1'
131
b7f30e0a
DK
132cat >expected-show-all-headers <<\EOF
1330001-Second.patch
134(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
135(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
136(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
b7f30e0a
DK
137Dry-OK. Log says:
138Server: relay.example.com
139MAIL FROM:<from@example.com>
02461e0e
JP
140RCPT TO:<to@example.com>
141RCPT TO:<cc@example.com>
142RCPT TO:<author@example.com>
143RCPT TO:<one@example.com>
144RCPT TO:<two@example.com>
145RCPT TO:<bcc@example.com>
b7f30e0a
DK
146From: Example <from@example.com>
147To: to@example.com
02461e0e
JP
148Cc: cc@example.com,
149 A <author@example.com>,
150 One <one@example.com>,
151 two@example.com
b7f30e0a
DK
152Subject: [PATCH 1/1] Second.
153Date: DATE-STRING
154Message-Id: MESSAGE-ID-STRING
155X-Mailer: X-MAILER-STRING
156In-Reply-To: <unique-message-id@example.com>
157References: <unique-message-id@example.com>
158
159Result: OK
160EOF
161
162test_expect_success 'Show all headers' '
163 git send-email \
164 --dry-run \
3531e270 165 --suppress-cc=sob \
b7f30e0a
DK
166 --from="Example <from@example.com>" \
167 --to=to@example.com \
168 --cc=cc@example.com \
169 --bcc=bcc@example.com \
170 --in-reply-to="<unique-message-id@example.com>" \
171 --smtp-server relay.example.com \
172 $patches |
173 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
174 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
175 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
176 >actual-show-all-headers &&
82ebb0b6 177 test_cmp expected-show-all-headers actual-show-all-headers
b7f30e0a
DK
178'
179
0da43a68
JS
180test_expect_success 'Prompting works' '
181 clean_fake_sendmail &&
182 (echo "Example <from@example.com>"
183 echo "to@example.com"
184 echo ""
185 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
186 --smtp-server="$(pwd)/fake.sendmail" \
187 $patches \
188 2>errors &&
9524cf29
SB
189 grep "^From: Example <from@example.com>\$" msgtxt1 &&
190 grep "^To: to@example.com\$" msgtxt1
0da43a68
JS
191'
192
cb8a9bd5
PB
193test_expect_success 'cccmd works' '
194 clean_fake_sendmail &&
195 cp $patches cccmd.patch &&
196 echo cccmd--cccmd@example.com >>cccmd.patch &&
977e289e
BC
197 {
198 echo "#!$SHELL_PATH"
199 echo sed -n -e s/^cccmd--//p \"\$1\"
200 } > cccmd-sed &&
cb8a9bd5
PB
201 chmod +x cccmd-sed &&
202 git send-email \
203 --from="Example <nobody@example.com>" \
204 --to=nobody@example.com \
205 --cc-cmd=./cccmd-sed \
206 --smtp-server="$(pwd)/fake.sendmail" \
207 cccmd.patch \
208 &&
02461e0e 209 grep "^ cccmd@example.com" msgtxt1
cb8a9bd5
PB
210'
211
747bbff9
JK
212z8=zzzzzzzz
213z64=$z8$z8$z8$z8$z8$z8$z8$z8
214z512=$z64$z64$z64$z64$z64$z64$z64$z64
215test_expect_success 'reject long lines' '
6d34a2ba 216 clean_fake_sendmail &&
747bbff9
JK
217 cp $patches longline.patch &&
218 echo $z512$z512 >>longline.patch &&
d492b31c 219 test_must_fail git send-email \
747bbff9
JK
220 --from="Example <nobody@example.com>" \
221 --to=nobody@example.com \
222 --smtp-server="$(pwd)/fake.sendmail" \
223 $patches longline.patch \
224 2>errors &&
225 grep longline.patch errors
226'
227
228test_expect_success 'no patch was sent' '
6d34a2ba 229 ! test -e commandline1
747bbff9
JK
230'
231
5012699d
JS
232test_expect_success 'Author From: in message body' '
233 clean_fake_sendmail &&
234 git send-email \
235 --from="Example <nobody@example.com>" \
236 --to=nobody@example.com \
237 --smtp-server="$(pwd)/fake.sendmail" \
238 $patches &&
9524cf29 239 sed "1,/^\$/d" < msgtxt1 > msgbody1
5012699d
JS
240 grep "From: A <author@example.com>" msgbody1
241'
242
243test_expect_success 'Author From: not in message body' '
244 clean_fake_sendmail &&
245 git send-email \
246 --from="A <author@example.com>" \
247 --to=nobody@example.com \
248 --smtp-server="$(pwd)/fake.sendmail" \
249 $patches &&
9524cf29 250 sed "1,/^\$/d" < msgtxt1 > msgbody1
5012699d
JS
251 ! grep "From: A <author@example.com>" msgbody1
252'
253
c764a0c2
JK
254test_expect_success 'allow long lines with --no-validate' '
255 git send-email \
256 --from="Example <nobody@example.com>" \
257 --to=nobody@example.com \
258 --smtp-server="$(pwd)/fake.sendmail" \
3fee1fe8 259 --novalidate \
c764a0c2
JK
260 $patches longline.patch \
261 2>errors
262'
263
0fb7fc75 264test_expect_success 'Invalid In-Reply-To' '
6d34a2ba 265 clean_fake_sendmail &&
0fb7fc75
JS
266 git send-email \
267 --from="Example <nobody@example.com>" \
268 --to=nobody@example.com \
269 --in-reply-to=" " \
270 --smtp-server="$(pwd)/fake.sendmail" \
271 $patches
272 2>errors
6d34a2ba 273 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
274'
275
276test_expect_success 'Valid In-Reply-To when prompting' '
6d34a2ba 277 clean_fake_sendmail &&
0fb7fc75
JS
278 (echo "From Example <from@example.com>"
279 echo "To Example <to@example.com>"
280 echo ""
281 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
282 --smtp-server="$(pwd)/fake.sendmail" \
283 $patches 2>errors &&
6d34a2ba 284 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
285'
286
8a8bf469 287test_expect_success 'setup fake editor' '
bb3e4f03 288 (echo "#!$SHELL_PATH" &&
065096c2 289 echo "echo fake edit >>\"\$1\""
8a8bf469
JK
290 ) >fake-editor &&
291 chmod +x fake-editor
292'
293
7f0475c3 294test_set_editor "$(pwd)/fake-editor"
065096c2 295
8a8bf469
JK
296test_expect_success '--compose works' '
297 clean_fake_sendmail &&
c1f2aa45
JS
298 git send-email \
299 --compose --subject foo \
300 --from="Example <nobody@example.com>" \
301 --to=nobody@example.com \
302 --smtp-server="$(pwd)/fake.sendmail" \
303 $patches \
304 2>errors
8a8bf469
JK
305'
306
307test_expect_success 'first message is compose text' '
308 grep "^fake edit" msgtxt1
309'
310
311test_expect_success 'second message is patch' '
312 grep "Subject:.*Second" msgtxt2
313'
314
3531e270 315cat >expected-suppress-sob <<\EOF
33c592dd
MV
3160001-Second.patch
317(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
318(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
319(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
320Dry-OK. Log says:
321Server: relay.example.com
322MAIL FROM:<from@example.com>
02461e0e
JP
323RCPT TO:<to@example.com>
324RCPT TO:<cc@example.com>
325RCPT TO:<author@example.com>
326RCPT TO:<one@example.com>
327RCPT TO:<two@example.com>
33c592dd
MV
328From: Example <from@example.com>
329To: to@example.com
02461e0e
JP
330Cc: cc@example.com,
331 A <author@example.com>,
332 One <one@example.com>,
333 two@example.com
33c592dd
MV
334Subject: [PATCH 1/1] Second.
335Date: DATE-STRING
336Message-Id: MESSAGE-ID-STRING
337X-Mailer: X-MAILER-STRING
338
339Result: OK
340EOF
341
3531e270 342test_suppression () {
33c592dd
MV
343 git send-email \
344 --dry-run \
cb8a9bd5 345 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
33c592dd
MV
346 --from="Example <from@example.com>" \
347 --to=to@example.com \
348 --smtp-server relay.example.com \
349 $patches |
350 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
351 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
352 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
cb8a9bd5
PB
353 >actual-suppress-$1${2+"-$2"} &&
354 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
3531e270
JS
355}
356
357test_expect_success 'sendemail.cc set' '
358 git config sendemail.cc cc@example.com &&
359 test_suppression sob
33c592dd
MV
360'
361
3531e270 362cat >expected-suppress-sob <<\EOF
33c592dd
MV
3630001-Second.patch
364(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
365(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
366(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
367Dry-OK. Log says:
368Server: relay.example.com
369MAIL FROM:<from@example.com>
02461e0e
JP
370RCPT TO:<to@example.com>
371RCPT TO:<author@example.com>
372RCPT TO:<one@example.com>
373RCPT TO:<two@example.com>
33c592dd
MV
374From: Example <from@example.com>
375To: to@example.com
02461e0e
JP
376Cc: A <author@example.com>,
377 One <one@example.com>,
378 two@example.com
33c592dd
MV
379Subject: [PATCH 1/1] Second.
380Date: DATE-STRING
381Message-Id: MESSAGE-ID-STRING
382X-Mailer: X-MAILER-STRING
383
384Result: OK
385EOF
386
387test_expect_success 'sendemail.cc unset' '
388 git config --unset sendemail.cc &&
3531e270
JS
389 test_suppression sob
390'
391
cb8a9bd5
PB
392cat >expected-suppress-cccmd <<\EOF
3930001-Second.patch
394(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
395(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
396(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
397(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
398Dry-OK. Log says:
399Server: relay.example.com
400MAIL FROM:<from@example.com>
02461e0e
JP
401RCPT TO:<to@example.com>
402RCPT TO:<author@example.com>
403RCPT TO:<one@example.com>
404RCPT TO:<two@example.com>
405RCPT TO:<committer@example.com>
cb8a9bd5
PB
406From: Example <from@example.com>
407To: to@example.com
02461e0e
JP
408Cc: A <author@example.com>,
409 One <one@example.com>,
410 two@example.com,
411 C O Mitter <committer@example.com>
cb8a9bd5
PB
412Subject: [PATCH 1/1] Second.
413Date: DATE-STRING
414Message-Id: MESSAGE-ID-STRING
415X-Mailer: X-MAILER-STRING
416
417Result: OK
418EOF
419
420test_expect_success 'sendemail.cccmd' '
421 echo echo cc-cmd@example.com > cccmd &&
422 chmod +x cccmd &&
423 git config sendemail.cccmd ./cccmd &&
424 test_suppression cccmd
425'
426
3531e270
JS
427cat >expected-suppress-all <<\EOF
4280001-Second.patch
429Dry-OK. Log says:
430Server: relay.example.com
431MAIL FROM:<from@example.com>
432RCPT TO:<to@example.com>
433From: Example <from@example.com>
434To: to@example.com
435Subject: [PATCH 1/1] Second.
436Date: DATE-STRING
437Message-Id: MESSAGE-ID-STRING
438X-Mailer: X-MAILER-STRING
439
440Result: OK
441EOF
442
443test_expect_success '--suppress-cc=all' '
444 test_suppression all
445'
446
447cat >expected-suppress-body <<\EOF
4480001-Second.patch
449(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
450(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
451(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
cb8a9bd5 452(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
3531e270
JS
453Dry-OK. Log says:
454Server: relay.example.com
455MAIL FROM:<from@example.com>
02461e0e
JP
456RCPT TO:<to@example.com>
457RCPT TO:<author@example.com>
458RCPT TO:<one@example.com>
459RCPT TO:<two@example.com>
460RCPT TO:<cc-cmd@example.com>
3531e270
JS
461From: Example <from@example.com>
462To: to@example.com
02461e0e
JP
463Cc: A <author@example.com>,
464 One <one@example.com>,
465 two@example.com,
466 cc-cmd@example.com
3531e270
JS
467Subject: [PATCH 1/1] Second.
468Date: DATE-STRING
469Message-Id: MESSAGE-ID-STRING
470X-Mailer: X-MAILER-STRING
471
472Result: OK
473EOF
474
475test_expect_success '--suppress-cc=body' '
476 test_suppression body
477'
478
cb8a9bd5
PB
479cat >expected-suppress-body-cccmd <<\EOF
4800001-Second.patch
481(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
482(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
483(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
484Dry-OK. Log says:
485Server: relay.example.com
486MAIL FROM:<from@example.com>
02461e0e
JP
487RCPT TO:<to@example.com>
488RCPT TO:<author@example.com>
489RCPT TO:<one@example.com>
490RCPT TO:<two@example.com>
cb8a9bd5
PB
491From: Example <from@example.com>
492To: to@example.com
02461e0e
JP
493Cc: A <author@example.com>,
494 One <one@example.com>,
495 two@example.com
cb8a9bd5
PB
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=body --suppress-cc=cccmd' '
505 test_suppression body cccmd
506'
507
3531e270
JS
508cat >expected-suppress-sob <<\EOF
5090001-Second.patch
510(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
511(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
512(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
513Dry-OK. Log says:
514Server: relay.example.com
515MAIL FROM:<from@example.com>
02461e0e
JP
516RCPT TO:<to@example.com>
517RCPT TO:<author@example.com>
518RCPT TO:<one@example.com>
519RCPT TO:<two@example.com>
3531e270
JS
520From: Example <from@example.com>
521To: to@example.com
02461e0e
JP
522Cc: A <author@example.com>,
523 One <one@example.com>,
524 two@example.com
3531e270
JS
525Subject: [PATCH 1/1] Second.
526Date: DATE-STRING
527Message-Id: MESSAGE-ID-STRING
528X-Mailer: X-MAILER-STRING
529
530Result: OK
531EOF
532
533test_expect_success '--suppress-cc=sob' '
cb8a9bd5 534 git config --unset sendemail.cccmd
3531e270
JS
535 test_suppression sob
536'
537
538cat >expected-suppress-bodycc <<\EOF
5390001-Second.patch
540(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
541(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
542(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
543(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
544Dry-OK. Log says:
545Server: relay.example.com
546MAIL FROM:<from@example.com>
02461e0e
JP
547RCPT TO:<to@example.com>
548RCPT TO:<author@example.com>
549RCPT TO:<one@example.com>
550RCPT TO:<two@example.com>
551RCPT TO:<committer@example.com>
3531e270
JS
552From: Example <from@example.com>
553To: to@example.com
02461e0e
JP
554Cc: A <author@example.com>,
555 One <one@example.com>,
556 two@example.com,
557 C O Mitter <committer@example.com>
3531e270
JS
558Subject: [PATCH 1/1] Second.
559Date: DATE-STRING
560Message-Id: MESSAGE-ID-STRING
561X-Mailer: X-MAILER-STRING
562
563Result: OK
564EOF
565
566test_expect_success '--suppress-cc=bodycc' '
567 test_suppression bodycc
568'
569
570cat >expected-suppress-cc <<\EOF
5710001-Second.patch
572(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
573(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
574Dry-OK. Log says:
575Server: relay.example.com
576MAIL FROM:<from@example.com>
02461e0e
JP
577RCPT TO:<to@example.com>
578RCPT TO:<author@example.com>
579RCPT TO:<committer@example.com>
3531e270
JS
580From: Example <from@example.com>
581To: to@example.com
02461e0e
JP
582Cc: A <author@example.com>,
583 C O Mitter <committer@example.com>
3531e270
JS
584Subject: [PATCH 1/1] Second.
585Date: DATE-STRING
586Message-Id: MESSAGE-ID-STRING
587X-Mailer: X-MAILER-STRING
588
589Result: OK
590EOF
591
592test_expect_success '--suppress-cc=cc' '
593 test_suppression cc
33c592dd
MV
594'
595
c1f2aa45
JS
596test_confirm () {
597 echo y | \
598 GIT_SEND_EMAIL_NOTTY=1 \
599 git send-email \
600 --from="Example <nobody@example.com>" \
601 --to=nobody@example.com \
602 --smtp-server="$(pwd)/fake.sendmail" \
c18f75a1
JS
603 $@ $patches > stdout &&
604 grep "Send this email" stdout
c1f2aa45
JS
605}
606
607test_expect_success '--confirm=always' '
608 test_confirm --confirm=always --suppress-cc=all
609'
610
611test_expect_success '--confirm=auto' '
612 test_confirm --confirm=auto
613'
614
615test_expect_success '--confirm=cc' '
616 test_confirm --confirm=cc
617'
618
619test_expect_success '--confirm=compose' '
620 test_confirm --confirm=compose --compose
621'
622
623test_expect_success 'confirm by default (due to cc)' '
624 CONFIRM=$(git config --get sendemail.confirm) &&
625 git config --unset sendemail.confirm &&
c18f75a1
JS
626 test_confirm
627 ret="$?"
628 git config sendemail.confirm ${CONFIRM:-never}
629 test $ret = "0"
c1f2aa45
JS
630'
631
632test_expect_success 'confirm by default (due to --compose)' '
633 CONFIRM=$(git config --get sendemail.confirm) &&
634 git config --unset sendemail.confirm &&
635 test_confirm --suppress-cc=all --compose
636 ret="$?"
637 git config sendemail.confirm ${CONFIRM:-never}
638 test $ret = "0"
639'
640
c18f75a1
JS
641test_expect_success 'confirm detects EOF (inform assumes y)' '
642 CONFIRM=$(git config --get sendemail.confirm) &&
643 git config --unset sendemail.confirm &&
dc1460aa
JS
644 rm -fr outdir &&
645 git format-patch -2 -o outdir &&
c18f75a1
JS
646 GIT_SEND_EMAIL_NOTTY=1 \
647 git send-email \
648 --from="Example <nobody@example.com>" \
649 --to=nobody@example.com \
650 --smtp-server="$(pwd)/fake.sendmail" \
dc1460aa 651 outdir/*.patch < /dev/null
c18f75a1
JS
652 ret="$?"
653 git config sendemail.confirm ${CONFIRM:-never}
654 test $ret = "0"
655'
656
657test_expect_success 'confirm detects EOF (auto causes failure)' '
658 CONFIRM=$(git config --get sendemail.confirm) &&
659 git config sendemail.confirm auto &&
3b3637c3
JS
660 GIT_SEND_EMAIL_NOTTY=1 &&
661 export GIT_SEND_EMAIL_NOTTY &&
c18f75a1
JS
662 test_must_fail git send-email \
663 --from="Example <nobody@example.com>" \
664 --to=nobody@example.com \
665 --smtp-server="$(pwd)/fake.sendmail" \
666 $patches < /dev/null
667 ret="$?"
668 git config sendemail.confirm ${CONFIRM:-never}
669 test $ret = "0"
670'
671
672test_expect_success 'confirm doesnt loop forever' '
673 CONFIRM=$(git config --get sendemail.confirm) &&
674 git config sendemail.confirm auto &&
3b3637c3
JS
675 GIT_SEND_EMAIL_NOTTY=1 &&
676 export GIT_SEND_EMAIL_NOTTY &&
677 yes "bogus" | test_must_fail git send-email \
c18f75a1
JS
678 --from="Example <nobody@example.com>" \
679 --to=nobody@example.com \
680 --smtp-server="$(pwd)/fake.sendmail" \
681 $patches
682 ret="$?"
683 git config sendemail.confirm ${CONFIRM:-never}
684 test $ret = "0"
685'
686
a61c0ffa
JS
687test_expect_success 'utf8 Cc is rfc2047 encoded' '
688 clean_fake_sendmail &&
689 rm -fr outdir &&
690 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
691 git send-email \
692 --from="Example <nobody@example.com>" \
693 --to=nobody@example.com \
694 --smtp-server="$(pwd)/fake.sendmail" \
695 outdir/*.patch &&
02461e0e 696 grep "^ " msgtxt1 |
d1fff6fc 697 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
a61c0ffa
JS
698'
699
0706bd19
JK
700test_expect_success '--compose adds MIME for utf8 body' '
701 clean_fake_sendmail &&
bb3e4f03 702 (echo "#!$SHELL_PATH" &&
c01cdde1 703 echo "echo utf8 body: àéìöú >>\"\$1\""
0706bd19
JK
704 ) >fake-editor-utf8 &&
705 chmod +x fake-editor-utf8 &&
c01cdde1 706 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
0706bd19
JK
707 git send-email \
708 --compose --subject foo \
709 --from="Example <nobody@example.com>" \
710 --to=nobody@example.com \
711 --smtp-server="$(pwd)/fake.sendmail" \
712 $patches &&
713 grep "^utf8 body" msgtxt1 &&
d1fff6fc 714 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
715'
716
717test_expect_success '--compose respects user mime type' '
718 clean_fake_sendmail &&
bb3e4f03 719 (echo "#!$SHELL_PATH" &&
0706bd19
JK
720 echo "(echo MIME-Version: 1.0"
721 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
722 echo " echo Content-Transfer-Encoding: 8bit"
723 echo " echo Subject: foo"
724 echo " echo "
c01cdde1 725 echo " echo utf8 body: àéìöú) >\"\$1\""
0706bd19
JK
726 ) >fake-editor-utf8-mime &&
727 chmod +x fake-editor-utf8-mime &&
c01cdde1 728 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
0706bd19
JK
729 git send-email \
730 --compose --subject foo \
731 --from="Example <nobody@example.com>" \
732 --to=nobody@example.com \
733 --smtp-server="$(pwd)/fake.sendmail" \
734 $patches &&
735 grep "^utf8 body" msgtxt1 &&
736 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
d1fff6fc 737 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
738'
739
d54eaaa2
JK
740test_expect_success '--compose adds MIME for utf8 subject' '
741 clean_fake_sendmail &&
c01cdde1 742 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
d54eaaa2
JK
743 git send-email \
744 --compose --subject utf8-sübjëct \
745 --from="Example <nobody@example.com>" \
746 --to=nobody@example.com \
747 --smtp-server="$(pwd)/fake.sendmail" \
748 $patches &&
749 grep "^fake edit" msgtxt1 &&
d1fff6fc 750 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
d54eaaa2
JK
751'
752
5df9fcf6
PH
753test_expect_success 'detects ambiguous reference/file conflict' '
754 echo master > master &&
755 git add master &&
756 git commit -m"add master" &&
757 test_must_fail git send-email --dry-run master 2>errors &&
758 grep disambiguate errors
759'
760
69f4ce55
JH
761test_expect_success 'feed two files' '
762 rm -fr outdir &&
763 git format-patch -2 -o outdir &&
c1f2aa45 764 git send-email \
69f4ce55
JH
765 --dry-run \
766 --from="Example <nobody@example.com>" \
767 --to=nobody@example.com \
768 outdir/000?-*.patch 2>errors >out &&
769 grep "^Subject: " out >subjects &&
770 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
771 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
772'
773
aaab4b9f
TR
774test_expect_success 'in-reply-to but no threading' '
775 git send-email \
776 --dry-run \
777 --from="Example <nobody@example.com>" \
778 --to=nobody@example.com \
779 --in-reply-to="<in-reply-id@example.com>" \
84eeb687 780 --nothread \
aaab4b9f
TR
781 $patches |
782 grep "In-Reply-To: <in-reply-id@example.com>"
783'
784
5e9758e2 785test_expect_success 'no in-reply-to and no threading' '
32ae8319
MH
786 git send-email \
787 --dry-run \
788 --from="Example <nobody@example.com>" \
789 --to=nobody@example.com \
790 --nothread \
791 $patches $patches >stdout &&
792 ! grep "In-Reply-To: " stdout
793'
794
f74fe34b 795test_expect_success 'threading but no chain-reply-to' '
d67114a5
MH
796 git send-email \
797 --dry-run \
798 --from="Example <nobody@example.com>" \
799 --to=nobody@example.com \
800 --thread \
801 --nochain-reply-to \
802 $patches $patches >stdout &&
803 grep "In-Reply-To: " stdout
804'
805
528fb087
NS
806test_expect_success 'warning with an implicit --chain-reply-to' '
807 git send-email \
808 --dry-run \
809 --from="Example <nobody@example.com>" \
810 --to=nobody@example.com \
811 outdir/000?-*.patch 2>errors >out &&
812 grep "no-chain-reply-to" errors
813'
814
815test_expect_success 'no warning with an explicit --chain-reply-to' '
816 git send-email \
817 --dry-run \
818 --from="Example <nobody@example.com>" \
819 --to=nobody@example.com \
820 --chain-reply-to \
821 outdir/000?-*.patch 2>errors >out &&
822 ! grep "no-chain-reply-to" errors
823'
824
825test_expect_success 'no warning with an explicit --no-chain-reply-to' '
826 git send-email \
827 --dry-run \
828 --from="Example <nobody@example.com>" \
829 --to=nobody@example.com \
907a0b1e 830 --nochain-reply-to \
528fb087
NS
831 outdir/000?-*.patch 2>errors >out &&
832 ! grep "no-chain-reply-to" errors
833'
834
835test_expect_success 'no warning with sendemail.chainreplyto = false' '
836 git config sendemail.chainreplyto false &&
837 git send-email \
838 --dry-run \
839 --from="Example <nobody@example.com>" \
840 --to=nobody@example.com \
841 outdir/000?-*.patch 2>errors >out &&
842 ! grep "no-chain-reply-to" errors
843'
844
845test_expect_success 'no warning with sendemail.chainreplyto = true' '
846 git config sendemail.chainreplyto true &&
847 git send-email \
848 --dry-run \
849 --from="Example <nobody@example.com>" \
850 --to=nobody@example.com \
851 outdir/000?-*.patch 2>errors >out &&
852 ! grep "no-chain-reply-to" errors
853'
854
f434c083
SB
855test_expect_success 'sendemail.to works' '
856 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
857 git send-email \
858 --dry-run \
859 --from="Example <nobody@example.com>" \
860 $patches $patches >stdout &&
861 grep "To: Somebody <somebody@ex.com>" stdout
862'
863
864test_expect_success '--no-to overrides sendemail.to' '
865 git send-email \
866 --dry-run \
867 --from="Example <nobody@example.com>" \
868 --no-to \
869 --to=nobody@example.com \
870 $patches $patches >stdout &&
871 grep "To: nobody@example.com" stdout &&
872 ! grep "To: Somebody <somebody@ex.com>" stdout
873'
874
875test_expect_success 'sendemail.cc works' '
876 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
877 git send-email \
878 --dry-run \
879 --from="Example <nobody@example.com>" \
880 --to=nobody@example.com \
881 $patches $patches >stdout &&
882 grep "Cc: Somebody <somebody@ex.com>" stdout
883'
884
885test_expect_success '--no-cc overrides sendemail.cc' '
886 git send-email \
887 --dry-run \
888 --from="Example <nobody@example.com>" \
889 --no-cc \
890 --cc=bodies@example.com \
891 --to=nobody@example.com \
892 $patches $patches >stdout &&
893 grep "Cc: bodies@example.com" stdout &&
894 ! grep "Cc: Somebody <somebody@ex.com>" stdout
895'
896
897test_expect_success 'sendemail.bcc works' '
898 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
899 git send-email \
900 --dry-run \
901 --from="Example <nobody@example.com>" \
902 --to=nobody@example.com \
903 --smtp-server relay.example.com \
904 $patches $patches >stdout &&
905 grep "RCPT TO:<other@ex.com>" stdout
906'
907
908test_expect_success '--no-bcc overrides sendemail.bcc' '
909 git send-email \
910 --dry-run \
911 --from="Example <nobody@example.com>" \
912 --no-bcc \
913 --bcc=bodies@example.com \
914 --to=nobody@example.com \
915 --smtp-server relay.example.com \
916 $patches $patches >stdout &&
917 grep "RCPT TO:<bodies@example.com>" stdout &&
918 ! grep "RCPT TO:<other@ex.com>" stdout
919'
920
ce903018 921test_done