]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9001-send-email.sh
t9001: Fix test prerequisites
[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
57cd35e6
ÆAB
6# May be altered later in the test
7PREREQ="PERL"
1b19ccd2 8
57cd35e6 9test_expect_success $PREREQ \
ce903018
RA
10 'prepare reference tree' \
11 'echo "1A quick brown fox jumps over the" >file &&
12 echo "lazy dog" >>file &&
c0d45281 13 git add file &&
ce903018
RA
14 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
15
57cd35e6 16test_expect_success $PREREQ \
ce903018 17 'Setup helper tool' \
bb3e4f03 18 '(echo "#!$SHELL_PATH"
2186d566 19 echo shift
6d34a2ba
JK
20 echo output=1
21 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
2186d566
JH
22 echo for a
23 echo do
24 echo " echo \"!\$a!\""
6d34a2ba
JK
25 echo "done >commandline\$output"
26 echo "cat > msgtxt\$output"
c0d45281
JK
27 ) >fake.sendmail &&
28 chmod +x ./fake.sendmail &&
29 git add fake.sendmail &&
ce903018
RA
30 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
31
6d34a2ba
JK
32clean_fake_sendmail() {
33 rm -f commandline* msgtxt*
34}
35
57cd35e6 36test_expect_success $PREREQ 'Extract patches' '
3531e270 37 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
280242d1
JH
38'
39
c1f2aa45
JS
40# Test no confirm early to ensure remaining tests will not hang
41test_no_confirm () {
42 rm -f no_confirm_okay
43 echo n | \
44 GIT_SEND_EMAIL_NOTTY=1 \
45 git send-email \
46 --from="Example <from@example.com>" \
47 --to=nobody@example.com \
48 --smtp-server="$(pwd)/fake.sendmail" \
49 $@ \
50 $patches > stdout &&
51 test_must_fail grep "Send this email" stdout &&
52 > no_confirm_okay
53}
54
55# Exit immediately to prevent hang if a no-confirm test fails
56check_no_confirm () {
57cd35e6
ÆAB
57 if ! test -f no_confirm_okay
58 then
59 say 'confirm test failed; skipping remaining tests to prevent hanging'
60 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
61 fi
62 return 0
c1f2aa45
JS
63}
64
57cd35e6
ÆAB
65test_expect_success $PREREQ 'No confirm with --suppress-cc' '
66 test_no_confirm --suppress-cc=sob &&
67 check_no_confirm
c1f2aa45 68'
c1f2aa45 69
57cd35e6
ÆAB
70
71test_expect_success $PREREQ 'No confirm with --confirm=never' '
72 test_no_confirm --confirm=never &&
73 check_no_confirm
c1f2aa45 74'
c1f2aa45
JS
75
76# leave sendemail.confirm set to never after this so that none of the
77# remaining tests prompt unintentionally.
57cd35e6 78test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
c1f2aa45 79 git config sendemail.confirm never &&
57cd35e6
ÆAB
80 test_no_confirm --compose --subject=foo &&
81 check_no_confirm
c1f2aa45 82'
c1f2aa45 83
57cd35e6 84test_expect_success $PREREQ '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
f9444147 88test_expect_success $PREREQ 'setup expect' '
2186d566
JH
89cat >expected <<\EOF
90!nobody@example.com!
91!author@example.com!
5012699d
JS
92!one@example.com!
93!two@example.com!
2186d566 94EOF
f9444147
ÆAB
95'
96
57cd35e6 97test_expect_success $PREREQ \
ce903018 98 'Verify commandline' \
188c3827 99 'test_cmp expected commandline1'
ce903018 100
57cd35e6 101test_expect_success $PREREQ 'Send patches with --envelope-sender' '
4f333bc1
JH
102 clean_fake_sendmail &&
103 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
104'
105
f9444147 106test_expect_success $PREREQ 'setup expect' '
4f333bc1
JH
107cat >expected <<\EOF
108!patch@example.com!
109!-i!
110!nobody@example.com!
111!author@example.com!
112!one@example.com!
113!two@example.com!
114EOF
f9444147
ÆAB
115'
116
57cd35e6 117test_expect_success $PREREQ \
4f333bc1
JH
118 'Verify commandline' \
119 'test_cmp expected commandline1'
120
57cd35e6 121test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
c89e3241
FC
122 clean_fake_sendmail &&
123 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
124'
125
f9444147 126test_expect_success $PREREQ 'setup expect' '
c89e3241
FC
127cat >expected <<\EOF
128!nobody@example.com!
129!-i!
130!nobody@example.com!
131!author@example.com!
132!one@example.com!
133!two@example.com!
134EOF
f9444147
ÆAB
135'
136
57cd35e6 137test_expect_success $PREREQ \
c89e3241
FC
138 'Verify commandline' \
139 'test_cmp expected commandline1'
140
f9444147 141test_expect_success $PREREQ 'setup expect' "
b7f30e0a
DK
142cat >expected-show-all-headers <<\EOF
1430001-Second.patch
144(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
145(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
146(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
b7f30e0a
DK
147Dry-OK. Log says:
148Server: relay.example.com
149MAIL FROM:<from@example.com>
02461e0e
JP
150RCPT TO:<to@example.com>
151RCPT TO:<cc@example.com>
152RCPT TO:<author@example.com>
153RCPT TO:<one@example.com>
154RCPT TO:<two@example.com>
155RCPT TO:<bcc@example.com>
b7f30e0a
DK
156From: Example <from@example.com>
157To: to@example.com
02461e0e
JP
158Cc: cc@example.com,
159 A <author@example.com>,
160 One <one@example.com>,
161 two@example.com
b7f30e0a
DK
162Subject: [PATCH 1/1] Second.
163Date: DATE-STRING
164Message-Id: MESSAGE-ID-STRING
165X-Mailer: X-MAILER-STRING
166In-Reply-To: <unique-message-id@example.com>
167References: <unique-message-id@example.com>
168
169Result: OK
170EOF
f9444147 171"
b7f30e0a 172
57cd35e6 173test_expect_success $PREREQ 'Show all headers' '
b7f30e0a
DK
174 git send-email \
175 --dry-run \
3531e270 176 --suppress-cc=sob \
b7f30e0a
DK
177 --from="Example <from@example.com>" \
178 --to=to@example.com \
179 --cc=cc@example.com \
180 --bcc=bcc@example.com \
181 --in-reply-to="<unique-message-id@example.com>" \
182 --smtp-server relay.example.com \
183 $patches |
184 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
185 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
186 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
187 >actual-show-all-headers &&
82ebb0b6 188 test_cmp expected-show-all-headers actual-show-all-headers
b7f30e0a
DK
189'
190
57cd35e6 191test_expect_success $PREREQ 'Prompting works' '
0da43a68
JS
192 clean_fake_sendmail &&
193 (echo "Example <from@example.com>"
194 echo "to@example.com"
195 echo ""
196 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
197 --smtp-server="$(pwd)/fake.sendmail" \
198 $patches \
199 2>errors &&
9524cf29
SB
200 grep "^From: Example <from@example.com>\$" msgtxt1 &&
201 grep "^To: to@example.com\$" msgtxt1
0da43a68
JS
202'
203
57cd35e6 204test_expect_success $PREREQ 'cccmd works' '
cb8a9bd5
PB
205 clean_fake_sendmail &&
206 cp $patches cccmd.patch &&
207 echo cccmd--cccmd@example.com >>cccmd.patch &&
977e289e
BC
208 {
209 echo "#!$SHELL_PATH"
210 echo sed -n -e s/^cccmd--//p \"\$1\"
211 } > cccmd-sed &&
cb8a9bd5
PB
212 chmod +x cccmd-sed &&
213 git send-email \
214 --from="Example <nobody@example.com>" \
215 --to=nobody@example.com \
216 --cc-cmd=./cccmd-sed \
217 --smtp-server="$(pwd)/fake.sendmail" \
218 cccmd.patch \
219 &&
02461e0e 220 grep "^ cccmd@example.com" msgtxt1
cb8a9bd5
PB
221'
222
57cd35e6 223test_expect_success $PREREQ 'reject long lines' '
f9444147
ÆAB
224 z8=zzzzzzzz &&
225 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
226 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
6d34a2ba 227 clean_fake_sendmail &&
747bbff9
JK
228 cp $patches longline.patch &&
229 echo $z512$z512 >>longline.patch &&
d492b31c 230 test_must_fail git send-email \
747bbff9
JK
231 --from="Example <nobody@example.com>" \
232 --to=nobody@example.com \
233 --smtp-server="$(pwd)/fake.sendmail" \
234 $patches longline.patch \
235 2>errors &&
236 grep longline.patch errors
237'
238
57cd35e6 239test_expect_success $PREREQ 'no patch was sent' '
6d34a2ba 240 ! test -e commandline1
747bbff9
JK
241'
242
57cd35e6 243test_expect_success $PREREQ 'Author From: in message body' '
5012699d
JS
244 clean_fake_sendmail &&
245 git send-email \
246 --from="Example <nobody@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
57cd35e6 254test_expect_success $PREREQ 'Author From: not in message body' '
5012699d
JS
255 clean_fake_sendmail &&
256 git send-email \
257 --from="A <author@example.com>" \
258 --to=nobody@example.com \
259 --smtp-server="$(pwd)/fake.sendmail" \
260 $patches &&
9524cf29 261 sed "1,/^\$/d" < msgtxt1 > msgbody1
5012699d
JS
262 ! grep "From: A <author@example.com>" msgbody1
263'
264
57cd35e6 265test_expect_success $PREREQ 'allow long lines with --no-validate' '
c764a0c2
JK
266 git send-email \
267 --from="Example <nobody@example.com>" \
268 --to=nobody@example.com \
269 --smtp-server="$(pwd)/fake.sendmail" \
3fee1fe8 270 --novalidate \
c764a0c2
JK
271 $patches longline.patch \
272 2>errors
273'
274
57cd35e6 275test_expect_success $PREREQ 'Invalid In-Reply-To' '
6d34a2ba 276 clean_fake_sendmail &&
0fb7fc75
JS
277 git send-email \
278 --from="Example <nobody@example.com>" \
279 --to=nobody@example.com \
280 --in-reply-to=" " \
281 --smtp-server="$(pwd)/fake.sendmail" \
5b57413c 282 $patches \
0fb7fc75 283 2>errors
6d34a2ba 284 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
285'
286
57cd35e6 287test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
6d34a2ba 288 clean_fake_sendmail &&
0fb7fc75
JS
289 (echo "From Example <from@example.com>"
290 echo "To Example <to@example.com>"
291 echo ""
292 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
293 --smtp-server="$(pwd)/fake.sendmail" \
294 $patches 2>errors &&
6d34a2ba 295 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
296'
297
57cd35e6 298test_expect_success $PREREQ 'setup fake editor' '
bb3e4f03 299 (echo "#!$SHELL_PATH" &&
065096c2 300 echo "echo fake edit >>\"\$1\""
8a8bf469
JK
301 ) >fake-editor &&
302 chmod +x fake-editor
303'
304
7f0475c3 305test_set_editor "$(pwd)/fake-editor"
065096c2 306
57cd35e6 307test_expect_success $PREREQ '--compose works' '
8a8bf469 308 clean_fake_sendmail &&
c1f2aa45
JS
309 git send-email \
310 --compose --subject foo \
311 --from="Example <nobody@example.com>" \
312 --to=nobody@example.com \
313 --smtp-server="$(pwd)/fake.sendmail" \
314 $patches \
315 2>errors
8a8bf469
JK
316'
317
57cd35e6 318test_expect_success $PREREQ 'first message is compose text' '
8a8bf469
JK
319 grep "^fake edit" msgtxt1
320'
321
57cd35e6 322test_expect_success $PREREQ 'second message is patch' '
8a8bf469
JK
323 grep "Subject:.*Second" msgtxt2
324'
325
f9444147 326test_expect_success $PREREQ 'setup expect' "
3531e270 327cat >expected-suppress-sob <<\EOF
33c592dd
MV
3280001-Second.patch
329(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
330(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
331(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
332Dry-OK. Log says:
333Server: relay.example.com
334MAIL FROM:<from@example.com>
02461e0e
JP
335RCPT TO:<to@example.com>
336RCPT TO:<cc@example.com>
337RCPT TO:<author@example.com>
338RCPT TO:<one@example.com>
339RCPT TO:<two@example.com>
33c592dd
MV
340From: Example <from@example.com>
341To: to@example.com
02461e0e
JP
342Cc: cc@example.com,
343 A <author@example.com>,
344 One <one@example.com>,
345 two@example.com
33c592dd
MV
346Subject: [PATCH 1/1] Second.
347Date: DATE-STRING
348Message-Id: MESSAGE-ID-STRING
349X-Mailer: X-MAILER-STRING
350
351Result: OK
352EOF
f9444147 353"
33c592dd 354
3531e270 355test_suppression () {
33c592dd
MV
356 git send-email \
357 --dry-run \
cb8a9bd5 358 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
33c592dd
MV
359 --from="Example <from@example.com>" \
360 --to=to@example.com \
361 --smtp-server relay.example.com \
362 $patches |
363 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
364 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
365 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
cb8a9bd5
PB
366 >actual-suppress-$1${2+"-$2"} &&
367 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
3531e270
JS
368}
369
57cd35e6 370test_expect_success $PREREQ 'sendemail.cc set' '
3531e270
JS
371 git config sendemail.cc cc@example.com &&
372 test_suppression sob
33c592dd
MV
373'
374
f9444147 375test_expect_success $PREREQ 'setup expect' "
3531e270 376cat >expected-suppress-sob <<\EOF
33c592dd
MV
3770001-Second.patch
378(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
379(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
380(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
381Dry-OK. Log says:
382Server: relay.example.com
383MAIL FROM:<from@example.com>
02461e0e
JP
384RCPT TO:<to@example.com>
385RCPT TO:<author@example.com>
386RCPT TO:<one@example.com>
387RCPT TO:<two@example.com>
33c592dd
MV
388From: Example <from@example.com>
389To: to@example.com
02461e0e
JP
390Cc: A <author@example.com>,
391 One <one@example.com>,
392 two@example.com
33c592dd
MV
393Subject: [PATCH 1/1] Second.
394Date: DATE-STRING
395Message-Id: MESSAGE-ID-STRING
396X-Mailer: X-MAILER-STRING
397
398Result: OK
399EOF
f9444147 400"
33c592dd 401
57cd35e6 402test_expect_success $PREREQ 'sendemail.cc unset' '
33c592dd 403 git config --unset sendemail.cc &&
3531e270
JS
404 test_suppression sob
405'
406
f9444147 407test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
408cat >expected-suppress-cccmd <<\EOF
4090001-Second.patch
410(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
411(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
412(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
413(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
414Dry-OK. Log says:
415Server: relay.example.com
416MAIL FROM:<from@example.com>
02461e0e
JP
417RCPT TO:<to@example.com>
418RCPT TO:<author@example.com>
419RCPT TO:<one@example.com>
420RCPT TO:<two@example.com>
421RCPT TO:<committer@example.com>
cb8a9bd5
PB
422From: Example <from@example.com>
423To: to@example.com
02461e0e
JP
424Cc: A <author@example.com>,
425 One <one@example.com>,
426 two@example.com,
427 C O Mitter <committer@example.com>
cb8a9bd5
PB
428Subject: [PATCH 1/1] Second.
429Date: DATE-STRING
430Message-Id: MESSAGE-ID-STRING
431X-Mailer: X-MAILER-STRING
432
433Result: OK
434EOF
f9444147 435"
cb8a9bd5 436
57cd35e6 437test_expect_success $PREREQ 'sendemail.cccmd' '
cb8a9bd5
PB
438 echo echo cc-cmd@example.com > cccmd &&
439 chmod +x cccmd &&
440 git config sendemail.cccmd ./cccmd &&
441 test_suppression cccmd
442'
443
f9444147 444test_expect_success $PREREQ 'setup expect' '
3531e270
JS
445cat >expected-suppress-all <<\EOF
4460001-Second.patch
447Dry-OK. Log says:
448Server: relay.example.com
449MAIL FROM:<from@example.com>
450RCPT TO:<to@example.com>
451From: Example <from@example.com>
452To: to@example.com
453Subject: [PATCH 1/1] Second.
454Date: DATE-STRING
455Message-Id: MESSAGE-ID-STRING
456X-Mailer: X-MAILER-STRING
457
458Result: OK
459EOF
f9444147 460'
3531e270 461
57cd35e6 462test_expect_success $PREREQ '--suppress-cc=all' '
3531e270
JS
463 test_suppression all
464'
465
f9444147 466test_expect_success $PREREQ 'setup expect' "
3531e270
JS
467cat >expected-suppress-body <<\EOF
4680001-Second.patch
469(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
470(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
471(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
cb8a9bd5 472(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
3531e270
JS
473Dry-OK. Log says:
474Server: relay.example.com
475MAIL FROM:<from@example.com>
02461e0e
JP
476RCPT TO:<to@example.com>
477RCPT TO:<author@example.com>
478RCPT TO:<one@example.com>
479RCPT TO:<two@example.com>
480RCPT TO:<cc-cmd@example.com>
3531e270
JS
481From: Example <from@example.com>
482To: to@example.com
02461e0e
JP
483Cc: A <author@example.com>,
484 One <one@example.com>,
485 two@example.com,
486 cc-cmd@example.com
3531e270
JS
487Subject: [PATCH 1/1] Second.
488Date: DATE-STRING
489Message-Id: MESSAGE-ID-STRING
490X-Mailer: X-MAILER-STRING
491
492Result: OK
493EOF
f9444147 494"
3531e270 495
57cd35e6 496test_expect_success $PREREQ '--suppress-cc=body' '
3531e270
JS
497 test_suppression body
498'
499
f9444147 500test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
501cat >expected-suppress-body-cccmd <<\EOF
5020001-Second.patch
503(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
504(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
505(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
506Dry-OK. Log says:
507Server: relay.example.com
508MAIL FROM:<from@example.com>
02461e0e
JP
509RCPT TO:<to@example.com>
510RCPT TO:<author@example.com>
511RCPT TO:<one@example.com>
512RCPT TO:<two@example.com>
cb8a9bd5
PB
513From: Example <from@example.com>
514To: to@example.com
02461e0e
JP
515Cc: A <author@example.com>,
516 One <one@example.com>,
517 two@example.com
cb8a9bd5
PB
518Subject: [PATCH 1/1] Second.
519Date: DATE-STRING
520Message-Id: MESSAGE-ID-STRING
521X-Mailer: X-MAILER-STRING
522
523Result: OK
524EOF
f9444147 525"
cb8a9bd5 526
57cd35e6 527test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
cb8a9bd5
PB
528 test_suppression body cccmd
529'
530
f9444147 531test_expect_success $PREREQ 'setup expect' "
3531e270
JS
532cat >expected-suppress-sob <<\EOF
5330001-Second.patch
534(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
535(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
536(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
537Dry-OK. Log says:
538Server: relay.example.com
539MAIL FROM:<from@example.com>
02461e0e
JP
540RCPT TO:<to@example.com>
541RCPT TO:<author@example.com>
542RCPT TO:<one@example.com>
543RCPT TO:<two@example.com>
3531e270
JS
544From: Example <from@example.com>
545To: to@example.com
02461e0e
JP
546Cc: A <author@example.com>,
547 One <one@example.com>,
548 two@example.com
3531e270
JS
549Subject: [PATCH 1/1] Second.
550Date: DATE-STRING
551Message-Id: MESSAGE-ID-STRING
552X-Mailer: X-MAILER-STRING
553
554Result: OK
555EOF
f9444147 556"
3531e270 557
57cd35e6 558test_expect_success $PREREQ '--suppress-cc=sob' '
cb8a9bd5 559 git config --unset sendemail.cccmd
3531e270
JS
560 test_suppression sob
561'
562
f9444147 563test_expect_success $PREREQ 'setup expect' "
3531e270
JS
564cat >expected-suppress-bodycc <<\EOF
5650001-Second.patch
566(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
567(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
568(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
569(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
570Dry-OK. Log says:
571Server: relay.example.com
572MAIL FROM:<from@example.com>
02461e0e
JP
573RCPT TO:<to@example.com>
574RCPT TO:<author@example.com>
575RCPT TO:<one@example.com>
576RCPT TO:<two@example.com>
577RCPT TO:<committer@example.com>
3531e270
JS
578From: Example <from@example.com>
579To: to@example.com
02461e0e
JP
580Cc: A <author@example.com>,
581 One <one@example.com>,
582 two@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
f9444147 591"
3531e270 592
57cd35e6 593test_expect_success $PREREQ '--suppress-cc=bodycc' '
3531e270
JS
594 test_suppression bodycc
595'
596
f9444147 597test_expect_success $PREREQ 'setup expect' "
3531e270
JS
598cat >expected-suppress-cc <<\EOF
5990001-Second.patch
600(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
601(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
602Dry-OK. Log says:
603Server: relay.example.com
604MAIL FROM:<from@example.com>
02461e0e
JP
605RCPT TO:<to@example.com>
606RCPT TO:<author@example.com>
607RCPT TO:<committer@example.com>
3531e270
JS
608From: Example <from@example.com>
609To: to@example.com
02461e0e
JP
610Cc: A <author@example.com>,
611 C O Mitter <committer@example.com>
3531e270
JS
612Subject: [PATCH 1/1] Second.
613Date: DATE-STRING
614Message-Id: MESSAGE-ID-STRING
615X-Mailer: X-MAILER-STRING
616
617Result: OK
618EOF
f9444147 619"
3531e270 620
57cd35e6 621test_expect_success $PREREQ '--suppress-cc=cc' '
3531e270 622 test_suppression cc
33c592dd
MV
623'
624
c1f2aa45
JS
625test_confirm () {
626 echo y | \
627 GIT_SEND_EMAIL_NOTTY=1 \
628 git send-email \
629 --from="Example <nobody@example.com>" \
630 --to=nobody@example.com \
631 --smtp-server="$(pwd)/fake.sendmail" \
c18f75a1
JS
632 $@ $patches > stdout &&
633 grep "Send this email" stdout
c1f2aa45
JS
634}
635
57cd35e6 636test_expect_success $PREREQ '--confirm=always' '
c1f2aa45
JS
637 test_confirm --confirm=always --suppress-cc=all
638'
639
57cd35e6 640test_expect_success $PREREQ '--confirm=auto' '
c1f2aa45
JS
641 test_confirm --confirm=auto
642'
643
57cd35e6 644test_expect_success $PREREQ '--confirm=cc' '
c1f2aa45
JS
645 test_confirm --confirm=cc
646'
647
57cd35e6 648test_expect_success $PREREQ '--confirm=compose' '
c1f2aa45
JS
649 test_confirm --confirm=compose --compose
650'
651
57cd35e6 652test_expect_success $PREREQ 'confirm by default (due to cc)' '
c1f2aa45
JS
653 CONFIRM=$(git config --get sendemail.confirm) &&
654 git config --unset sendemail.confirm &&
c18f75a1
JS
655 test_confirm
656 ret="$?"
657 git config sendemail.confirm ${CONFIRM:-never}
658 test $ret = "0"
c1f2aa45
JS
659'
660
57cd35e6 661test_expect_success $PREREQ 'confirm by default (due to --compose)' '
c1f2aa45
JS
662 CONFIRM=$(git config --get sendemail.confirm) &&
663 git config --unset sendemail.confirm &&
664 test_confirm --suppress-cc=all --compose
665 ret="$?"
666 git config sendemail.confirm ${CONFIRM:-never}
667 test $ret = "0"
668'
669
57cd35e6 670test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
c18f75a1
JS
671 CONFIRM=$(git config --get sendemail.confirm) &&
672 git config --unset sendemail.confirm &&
dc1460aa
JS
673 rm -fr outdir &&
674 git format-patch -2 -o outdir &&
c18f75a1
JS
675 GIT_SEND_EMAIL_NOTTY=1 \
676 git send-email \
677 --from="Example <nobody@example.com>" \
678 --to=nobody@example.com \
679 --smtp-server="$(pwd)/fake.sendmail" \
dc1460aa 680 outdir/*.patch < /dev/null
c18f75a1
JS
681 ret="$?"
682 git config sendemail.confirm ${CONFIRM:-never}
683 test $ret = "0"
684'
685
57cd35e6 686test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
c18f75a1
JS
687 CONFIRM=$(git config --get sendemail.confirm) &&
688 git config sendemail.confirm auto &&
3b3637c3
JS
689 GIT_SEND_EMAIL_NOTTY=1 &&
690 export GIT_SEND_EMAIL_NOTTY &&
c18f75a1
JS
691 test_must_fail git send-email \
692 --from="Example <nobody@example.com>" \
693 --to=nobody@example.com \
694 --smtp-server="$(pwd)/fake.sendmail" \
695 $patches < /dev/null
696 ret="$?"
697 git config sendemail.confirm ${CONFIRM:-never}
698 test $ret = "0"
699'
700
57cd35e6 701test_expect_success $PREREQ 'confirm doesnt loop forever' '
c18f75a1
JS
702 CONFIRM=$(git config --get sendemail.confirm) &&
703 git config sendemail.confirm auto &&
3b3637c3
JS
704 GIT_SEND_EMAIL_NOTTY=1 &&
705 export GIT_SEND_EMAIL_NOTTY &&
706 yes "bogus" | test_must_fail git send-email \
c18f75a1
JS
707 --from="Example <nobody@example.com>" \
708 --to=nobody@example.com \
709 --smtp-server="$(pwd)/fake.sendmail" \
710 $patches
711 ret="$?"
712 git config sendemail.confirm ${CONFIRM:-never}
713 test $ret = "0"
714'
715
57cd35e6 716test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
a61c0ffa
JS
717 clean_fake_sendmail &&
718 rm -fr outdir &&
719 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
720 git send-email \
721 --from="Example <nobody@example.com>" \
722 --to=nobody@example.com \
723 --smtp-server="$(pwd)/fake.sendmail" \
724 outdir/*.patch &&
02461e0e 725 grep "^ " msgtxt1 |
d1fff6fc 726 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
a61c0ffa
JS
727'
728
57cd35e6 729test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
0706bd19 730 clean_fake_sendmail &&
bb3e4f03 731 (echo "#!$SHELL_PATH" &&
c01cdde1 732 echo "echo utf8 body: àéìöú >>\"\$1\""
0706bd19
JK
733 ) >fake-editor-utf8 &&
734 chmod +x fake-editor-utf8 &&
c01cdde1 735 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
0706bd19
JK
736 git send-email \
737 --compose --subject foo \
738 --from="Example <nobody@example.com>" \
739 --to=nobody@example.com \
740 --smtp-server="$(pwd)/fake.sendmail" \
741 $patches &&
742 grep "^utf8 body" msgtxt1 &&
d1fff6fc 743 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
744'
745
57cd35e6 746test_expect_success $PREREQ '--compose respects user mime type' '
0706bd19 747 clean_fake_sendmail &&
bb3e4f03 748 (echo "#!$SHELL_PATH" &&
0706bd19
JK
749 echo "(echo MIME-Version: 1.0"
750 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
751 echo " echo Content-Transfer-Encoding: 8bit"
752 echo " echo Subject: foo"
753 echo " echo "
c01cdde1 754 echo " echo utf8 body: àéìöú) >\"\$1\""
0706bd19
JK
755 ) >fake-editor-utf8-mime &&
756 chmod +x fake-editor-utf8-mime &&
c01cdde1 757 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
0706bd19
JK
758 git send-email \
759 --compose --subject foo \
760 --from="Example <nobody@example.com>" \
761 --to=nobody@example.com \
762 --smtp-server="$(pwd)/fake.sendmail" \
763 $patches &&
764 grep "^utf8 body" msgtxt1 &&
765 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
d1fff6fc 766 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
767'
768
57cd35e6 769test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
d54eaaa2 770 clean_fake_sendmail &&
c01cdde1 771 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
d54eaaa2
JK
772 git send-email \
773 --compose --subject utf8-sübjëct \
774 --from="Example <nobody@example.com>" \
775 --to=nobody@example.com \
776 --smtp-server="$(pwd)/fake.sendmail" \
777 $patches &&
778 grep "^fake edit" msgtxt1 &&
d1fff6fc 779 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
d54eaaa2
JK
780'
781
57cd35e6 782test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
5df9fcf6
PH
783 echo master > master &&
784 git add master &&
785 git commit -m"add master" &&
786 test_must_fail git send-email --dry-run master 2>errors &&
787 grep disambiguate errors
788'
789
57cd35e6 790test_expect_success $PREREQ 'feed two files' '
69f4ce55
JH
791 rm -fr outdir &&
792 git format-patch -2 -o outdir &&
c1f2aa45 793 git send-email \
69f4ce55
JH
794 --dry-run \
795 --from="Example <nobody@example.com>" \
796 --to=nobody@example.com \
797 outdir/000?-*.patch 2>errors >out &&
798 grep "^Subject: " out >subjects &&
799 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
800 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
801'
802
57cd35e6 803test_expect_success $PREREQ 'in-reply-to but no threading' '
aaab4b9f
TR
804 git send-email \
805 --dry-run \
806 --from="Example <nobody@example.com>" \
807 --to=nobody@example.com \
808 --in-reply-to="<in-reply-id@example.com>" \
84eeb687 809 --nothread \
aaab4b9f
TR
810 $patches |
811 grep "In-Reply-To: <in-reply-id@example.com>"
812'
813
57cd35e6 814test_expect_success $PREREQ 'no in-reply-to and no threading' '
32ae8319
MH
815 git send-email \
816 --dry-run \
817 --from="Example <nobody@example.com>" \
818 --to=nobody@example.com \
819 --nothread \
820 $patches $patches >stdout &&
821 ! grep "In-Reply-To: " stdout
822'
823
57cd35e6 824test_expect_success $PREREQ 'threading but no chain-reply-to' '
d67114a5
MH
825 git send-email \
826 --dry-run \
827 --from="Example <nobody@example.com>" \
828 --to=nobody@example.com \
829 --thread \
830 --nochain-reply-to \
831 $patches $patches >stdout &&
832 grep "In-Reply-To: " stdout
833'
834
57cd35e6 835test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
528fb087
NS
836 git send-email \
837 --dry-run \
838 --from="Example <nobody@example.com>" \
839 --to=nobody@example.com \
840 outdir/000?-*.patch 2>errors >out &&
841 grep "no-chain-reply-to" errors
842'
843
57cd35e6 844test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
528fb087
NS
845 git send-email \
846 --dry-run \
847 --from="Example <nobody@example.com>" \
848 --to=nobody@example.com \
849 --chain-reply-to \
850 outdir/000?-*.patch 2>errors >out &&
851 ! grep "no-chain-reply-to" errors
852'
853
57cd35e6 854test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
528fb087
NS
855 git send-email \
856 --dry-run \
857 --from="Example <nobody@example.com>" \
858 --to=nobody@example.com \
907a0b1e 859 --nochain-reply-to \
528fb087
NS
860 outdir/000?-*.patch 2>errors >out &&
861 ! grep "no-chain-reply-to" errors
862'
863
57cd35e6 864test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
528fb087
NS
865 git config sendemail.chainreplyto false &&
866 git send-email \
867 --dry-run \
868 --from="Example <nobody@example.com>" \
869 --to=nobody@example.com \
870 outdir/000?-*.patch 2>errors >out &&
871 ! grep "no-chain-reply-to" errors
872'
873
57cd35e6 874test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
528fb087
NS
875 git config sendemail.chainreplyto true &&
876 git send-email \
877 --dry-run \
878 --from="Example <nobody@example.com>" \
879 --to=nobody@example.com \
880 outdir/000?-*.patch 2>errors >out &&
881 ! grep "no-chain-reply-to" errors
882'
883
57cd35e6 884test_expect_success $PREREQ 'sendemail.to works' '
f434c083
SB
885 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
886 git send-email \
887 --dry-run \
888 --from="Example <nobody@example.com>" \
889 $patches $patches >stdout &&
890 grep "To: Somebody <somebody@ex.com>" stdout
891'
892
57cd35e6 893test_expect_success $PREREQ '--no-to overrides sendemail.to' '
f434c083
SB
894 git send-email \
895 --dry-run \
896 --from="Example <nobody@example.com>" \
897 --no-to \
898 --to=nobody@example.com \
899 $patches $patches >stdout &&
900 grep "To: nobody@example.com" stdout &&
901 ! grep "To: Somebody <somebody@ex.com>" stdout
902'
903
57cd35e6 904test_expect_success $PREREQ 'sendemail.cc works' '
f434c083
SB
905 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
906 git send-email \
907 --dry-run \
908 --from="Example <nobody@example.com>" \
909 --to=nobody@example.com \
910 $patches $patches >stdout &&
911 grep "Cc: Somebody <somebody@ex.com>" stdout
912'
913
57cd35e6 914test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
f434c083
SB
915 git send-email \
916 --dry-run \
917 --from="Example <nobody@example.com>" \
918 --no-cc \
919 --cc=bodies@example.com \
920 --to=nobody@example.com \
921 $patches $patches >stdout &&
922 grep "Cc: bodies@example.com" stdout &&
923 ! grep "Cc: Somebody <somebody@ex.com>" stdout
924'
925
57cd35e6 926test_expect_success $PREREQ 'sendemail.bcc works' '
f434c083
SB
927 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
928 git send-email \
929 --dry-run \
930 --from="Example <nobody@example.com>" \
931 --to=nobody@example.com \
932 --smtp-server relay.example.com \
933 $patches $patches >stdout &&
934 grep "RCPT TO:<other@ex.com>" stdout
935'
936
57cd35e6 937test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
f434c083
SB
938 git send-email \
939 --dry-run \
940 --from="Example <nobody@example.com>" \
941 --no-bcc \
942 --bcc=bodies@example.com \
943 --to=nobody@example.com \
944 --smtp-server relay.example.com \
945 $patches $patches >stdout &&
946 grep "RCPT TO:<bodies@example.com>" stdout &&
947 ! grep "RCPT TO:<other@ex.com>" stdout
948'
949
f9444147 950test_expect_success $PREREQ 'setup expect' '
3cae7e5b
TR
951cat >email-using-8bit <<EOF
952From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
953Message-Id: <bogus-message-id@example.com>
954From: author@example.com
955Date: Sat, 12 Jun 2010 15:53:58 +0200
956Subject: subject goes here
957
958Dieser deutsche Text enthält einen Umlaut!
959EOF
f9444147 960'
3cae7e5b 961
f9444147 962test_expect_success $PREREQ 'setup expect' '
3cae7e5b
TR
963cat >content-type-decl <<EOF
964MIME-Version: 1.0
965Content-Type: text/plain; charset=UTF-8
966Content-Transfer-Encoding: 8bit
967EOF
f9444147 968'
3cae7e5b 969
57cd35e6 970test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
3cae7e5b
TR
971 clean_fake_sendmail &&
972 echo |
973 git send-email --from=author@example.com --to=nobody@example.com \
974 --smtp-server="$(pwd)/fake.sendmail" \
975 email-using-8bit >stdout &&
976 grep "do not declare a Content-Transfer-Encoding" stdout &&
977 grep email-using-8bit stdout &&
978 grep "Which 8bit encoding" stdout &&
31832862 979 egrep "Content|MIME" msgtxt1 >actual &&
3cae7e5b
TR
980 test_cmp actual content-type-decl
981'
982
57cd35e6 983test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
3cae7e5b
TR
984 clean_fake_sendmail &&
985 git config sendemail.assume8bitEncoding UTF-8 &&
986 echo bogus |
987 git send-email --from=author@example.com --to=nobody@example.com \
988 --smtp-server="$(pwd)/fake.sendmail" \
989 email-using-8bit >stdout &&
31832862 990 egrep "Content|MIME" msgtxt1 >actual &&
3cae7e5b
TR
991 test_cmp actual content-type-decl
992'
993
57cd35e6 994test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
3cae7e5b
TR
995 clean_fake_sendmail &&
996 git config sendemail.assume8bitEncoding "bogus too" &&
997 echo bogus |
998 git send-email --from=author@example.com --to=nobody@example.com \
999 --smtp-server="$(pwd)/fake.sendmail" \
1000 --8bit-encoding=UTF-8 \
1001 email-using-8bit >stdout &&
31832862 1002 egrep "Content|MIME" msgtxt1 >actual &&
3cae7e5b
TR
1003 test_cmp actual content-type-decl
1004'
1005
f9444147 1006test_expect_success $PREREQ 'setup expect' '
3cae7e5b
TR
1007cat >email-using-8bit <<EOF
1008From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1009Message-Id: <bogus-message-id@example.com>
1010From: author@example.com
1011Date: Sat, 12 Jun 2010 15:53:58 +0200
1012Subject: Dieser Betreff enthält auch einen Umlaut!
1013
1014Nothing to see here.
1015EOF
f9444147 1016'
3cae7e5b 1017
f9444147 1018test_expect_success $PREREQ 'setup expect' '
3cae7e5b
TR
1019cat >expected <<EOF
1020Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1021EOF
f9444147 1022'
3cae7e5b 1023
57cd35e6 1024test_expect_success $PREREQ '--8bit-encoding also treats subject' '
3cae7e5b
TR
1025 clean_fake_sendmail &&
1026 echo bogus |
1027 git send-email --from=author@example.com --to=nobody@example.com \
1028 --smtp-server="$(pwd)/fake.sendmail" \
1029 --8bit-encoding=UTF-8 \
1030 email-using-8bit >stdout &&
1031 grep "Subject" msgtxt1 >actual &&
1032 test_cmp expected actual
1033'
1034
a03bc5b6
TR
1035# Note that the patches in this test are deliberately out of order; we
1036# want to make sure it works even if the cover-letter is not in the
1037# first mail.
57da2042 1038test_expect_success $PREREQ 'refusing to send cover letter template' '
a03bc5b6
TR
1039 clean_fake_sendmail &&
1040 rm -fr outdir &&
1041 git format-patch --cover-letter -2 -o outdir &&
1042 test_must_fail git send-email \
1043 --from="Example <nobody@example.com>" \
1044 --to=nobody@example.com \
1045 --smtp-server="$(pwd)/fake.sendmail" \
1046 outdir/0002-*.patch \
1047 outdir/0000-*.patch \
1048 outdir/0001-*.patch \
1049 2>errors >out &&
1050 grep "SUBJECT HERE" errors &&
1051 test -z "$(ls msgtxt*)"
1052'
1053
57da2042 1054test_expect_success $PREREQ '--force sends cover letter template anyway' '
a03bc5b6
TR
1055 clean_fake_sendmail &&
1056 rm -fr outdir &&
1057 git format-patch --cover-letter -2 -o outdir &&
1058 git send-email \
1059 --force \
1060 --from="Example <nobody@example.com>" \
1061 --to=nobody@example.com \
1062 --smtp-server="$(pwd)/fake.sendmail" \
1063 outdir/0002-*.patch \
1064 outdir/0000-*.patch \
1065 outdir/0001-*.patch \
1066 2>errors >out &&
1067 ! grep "SUBJECT HERE" errors &&
1068 test -n "$(ls msgtxt*)"
1069'
1070
ce903018 1071test_done