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