send-email: add test for Linux's get_maintainer.pl
[git.git] / t / t9001-send-email.sh
bloba06e5d7ba50ef116b4ef71902443a2709000b27c
1 #!/bin/sh
3 test_description='git send-email'
4 . ./test-lib.sh
6 # May be altered later in the test
7 PREREQ="PERL"
9 test_expect_success $PREREQ 'prepare reference tree' '
10 echo "1A quick brown fox jumps over the" >file &&
11 echo "lazy dog" >>file &&
12 git add file &&
13 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
16 test_expect_success $PREREQ 'Setup helper tool' '
17 write_script fake.sendmail <<-\EOF &&
18 shift
19 output=1
20 while test -f commandline$output
22 output=$(($output+1))
23 done
24 for a
26 echo "!$a!"
27 done >commandline$output
28 cat >"msgtxt$output"
29 EOF
30 git add fake.sendmail &&
31 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
34 clean_fake_sendmail () {
35 rm -f commandline* msgtxt*
38 test_expect_success $PREREQ 'Extract patches' '
39 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1)
42 # Test no confirm early to ensure remaining tests will not hang
43 test_no_confirm () {
44 rm -f no_confirm_okay
45 echo n | \
46 GIT_SEND_EMAIL_NOTTY=1 \
47 git send-email \
48 --from="Example <from@example.com>" \
49 --to=nobody@example.com \
50 --smtp-server="$(pwd)/fake.sendmail" \
51 $@ \
52 $patches >stdout &&
53 ! grep "Send this email" stdout &&
54 >no_confirm_okay
57 # Exit immediately to prevent hang if a no-confirm test fails
58 check_no_confirm () {
59 if ! test -f no_confirm_okay
60 then
61 say 'confirm test failed; skipping remaining tests to prevent hanging'
62 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
64 return 0
67 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
68 test_no_confirm --suppress-cc=sob &&
69 check_no_confirm
73 test_expect_success $PREREQ 'No confirm with --confirm=never' '
74 test_no_confirm --confirm=never &&
75 check_no_confirm
78 # leave sendemail.confirm set to never after this so that none of the
79 # remaining tests prompt unintentionally.
80 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
81 git config sendemail.confirm never &&
82 test_no_confirm --compose --subject=foo &&
83 check_no_confirm
86 test_expect_success $PREREQ 'Send patches' '
87 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
90 test_expect_success $PREREQ 'setup expect' '
91 cat >expected <<-\EOF
92 !nobody@example.com!
93 !author@example.com!
94 !one@example.com!
95 !two@example.com!
96 EOF
99 test_expect_success $PREREQ 'Verify commandline' '
100 test_cmp expected commandline1
103 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
104 clean_fake_sendmail &&
105 git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
108 test_expect_success $PREREQ 'setup expect' '
109 cat >expected <<-\EOF
110 !patch@example.com!
111 !-i!
112 !nobody@example.com!
113 !author@example.com!
114 !one@example.com!
115 !two@example.com!
119 test_expect_success $PREREQ 'Verify commandline' '
120 test_cmp expected commandline1
123 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
124 clean_fake_sendmail &&
125 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
128 test_expect_success $PREREQ 'setup expect' '
129 cat >expected <<-\EOF
130 !nobody@example.com!
131 !-i!
132 !nobody@example.com!
133 !author@example.com!
134 !one@example.com!
135 !two@example.com!
139 test_expect_success $PREREQ 'Verify commandline' '
140 test_cmp expected commandline1
143 test_expect_success $PREREQ 'setup expect for cc trailer' "
144 cat >expected-cc <<\EOF
145 !recipient@example.com!
146 !author@example.com!
147 !one@example.com!
148 !two@example.com!
149 !three@example.com!
150 !four@example.com!
151 !five@example.com!
152 !six@example.com!
156 test_expect_success $PREREQ 'cc trailer with various syntax' '
157 test_commit cc-trailer &&
158 test_when_finished "git reset --hard HEAD^" &&
159 git commit --amend -F - <<-EOF &&
160 Test Cc: trailers.
162 Cc: one@example.com
163 Cc: <two@example.com> # trailing comments are ignored
164 Cc: <three@example.com>, <not.four@example.com> one address per line
165 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
166 Cc: five@example.com # not.six@example.com
167 Cc: six@example.com, not.seven@example.com
169 clean_fake_sendmail &&
170 git send-email -1 --to=recipient@example.com \
171 --smtp-server="$(pwd)/fake.sendmail" &&
172 test_cmp expected-cc commandline1
175 test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
176 write_script expected-cc-script.sh <<-EOF
177 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
178 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
179 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
180 echo '<four@example.com> (moderated list:FOR THING)'
181 echo 'five@example.com (open list:FOR THING (FOO/bar))'
182 echo 'six@example.com (open list)'
186 test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
187 clean_fake_sendmail &&
188 git send-email -1 --to=recipient@example.com \
189 --cc-cmd=./expected-cc-script.sh \
190 --smtp-server="$(pwd)/fake.sendmail" &&
191 test_cmp expected-cc commandline1
194 test_expect_success $PREREQ 'setup expect' "
195 cat >expected-show-all-headers <<\EOF
196 0001-Second.patch
197 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
198 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
199 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
200 Dry-OK. Log says:
201 Server: relay.example.com
202 MAIL FROM:<from@example.com>
203 RCPT TO:<to@example.com>
204 RCPT TO:<cc@example.com>
205 RCPT TO:<author@example.com>
206 RCPT TO:<one@example.com>
207 RCPT TO:<two@example.com>
208 RCPT TO:<bcc@example.com>
209 From: Example <from@example.com>
210 To: to@example.com
211 Cc: cc@example.com,
212 A <author@example.com>,
213 One <one@example.com>,
214 two@example.com
215 Subject: [PATCH 1/1] Second.
216 Date: DATE-STRING
217 Message-Id: MESSAGE-ID-STRING
218 X-Mailer: X-MAILER-STRING
219 In-Reply-To: <unique-message-id@example.com>
220 References: <unique-message-id@example.com>
222 Result: OK
226 test_suppress_self () {
227 test_commit $3 &&
228 test_when_finished "git reset --hard HEAD^" &&
230 write_script cccmd-sed <<-EOF &&
231 sed -n -e s/^cccmd--//p "\$1"
234 git commit --amend --author="$1 <$2>" -F - &&
235 clean_fake_sendmail &&
236 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
238 git send-email --from="$1 <$2>" \
239 --to=nobody@example.com \
240 --cc-cmd=./cccmd-sed \
241 --suppress-cc=self \
242 --smtp-server="$(pwd)/fake.sendmail" \
243 suppress-self-$3.patch &&
245 mv msgtxt1 msgtxt1-$3 &&
246 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
247 >"expected-no-cc-$3" &&
249 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
250 test_cmp expected-no-cc-$3 actual-no-cc-$3)
253 test_suppress_self_unquoted () {
254 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
255 test suppress-cc.self unquoted-$3 with name $1 email $2
257 unquoted-$3
259 cccmd--$1 <$2>
261 Cc: $1 <$2>
262 Signed-off-by: $1 <$2>
266 test_suppress_self_quoted () {
267 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
268 test suppress-cc.self quoted-$3 with name $1 email $2
270 quoted-$3
272 cccmd--"$1" <$2>
274 Cc: $1 <$2>
275 Cc: "$1" <$2>
276 Signed-off-by: $1 <$2>
277 Signed-off-by: "$1" <$2>
281 test_expect_success $PREREQ 'self name is suppressed' "
282 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
283 'self_name_suppressed'
286 test_expect_success $PREREQ 'self name with dot is suppressed' "
287 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
288 'self_name_dot_suppressed'
291 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
292 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
293 'non_ascii_self_suppressed'
296 # This name is long enough to force format-patch to split it into multiple
297 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
298 test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
299 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
300 'long_non_ascii_self_suppressed'
303 test_expect_success $PREREQ 'sanitized self name is suppressed' "
304 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
305 'self_name_sanitized_suppressed'
308 test_expect_success $PREREQ 'Show all headers' '
309 git send-email \
310 --dry-run \
311 --suppress-cc=sob \
312 --from="Example <from@example.com>" \
313 --to=to@example.com \
314 --cc=cc@example.com \
315 --bcc=bcc@example.com \
316 --in-reply-to="<unique-message-id@example.com>" \
317 --smtp-server relay.example.com \
318 $patches |
319 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
320 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
321 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
322 >actual-show-all-headers &&
323 test_cmp expected-show-all-headers actual-show-all-headers
326 test_expect_success $PREREQ 'Prompting works' '
327 clean_fake_sendmail &&
328 (echo "to@example.com"
329 echo ""
330 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
331 --smtp-server="$(pwd)/fake.sendmail" \
332 $patches \
333 2>errors &&
334 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
335 grep "^To: to@example.com\$" msgtxt1
338 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
339 clean_fake_sendmail &&
340 (sane_unset GIT_AUTHOR_NAME &&
341 sane_unset GIT_AUTHOR_EMAIL &&
342 sane_unset GIT_COMMITTER_NAME &&
343 sane_unset GIT_COMMITTER_EMAIL &&
344 GIT_SEND_EMAIL_NOTTY=1 git send-email \
345 --smtp-server="$(pwd)/fake.sendmail" \
346 --to=to@example.com \
347 $patches </dev/null 2>errors
351 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
352 clean_fake_sendmail &&
353 (sane_unset GIT_AUTHOR_NAME &&
354 sane_unset GIT_AUTHOR_EMAIL &&
355 sane_unset GIT_COMMITTER_NAME &&
356 sane_unset GIT_COMMITTER_EMAIL &&
357 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
358 test_must_fail git send-email \
359 --smtp-server="$(pwd)/fake.sendmail" \
360 --to=to@example.com \
361 $patches </dev/null 2>errors &&
362 test_i18ngrep "tell me who you are" errors
366 test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
367 write_script tocmd-sed <<-\EOF &&
368 sed -n -e "s/^tocmd--//p" "$1"
370 write_script cccmd-sed <<-\EOF
371 sed -n -e "s/^cccmd--//p" "$1"
375 test_expect_success $PREREQ 'tocmd works' '
376 clean_fake_sendmail &&
377 cp $patches tocmd.patch &&
378 echo tocmd--tocmd@example.com >>tocmd.patch &&
379 git send-email \
380 --from="Example <nobody@example.com>" \
381 --to-cmd=./tocmd-sed \
382 --smtp-server="$(pwd)/fake.sendmail" \
383 tocmd.patch \
385 grep "^To: tocmd@example.com" msgtxt1
388 test_expect_success $PREREQ 'cccmd works' '
389 clean_fake_sendmail &&
390 cp $patches cccmd.patch &&
391 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
392 git send-email \
393 --from="Example <nobody@example.com>" \
394 --to=nobody@example.com \
395 --cc-cmd=./cccmd-sed \
396 --smtp-server="$(pwd)/fake.sendmail" \
397 cccmd.patch \
399 grep "^ cccmd@example.com" msgtxt1
402 test_expect_success $PREREQ 'reject long lines' '
403 z8=zzzzzzzz &&
404 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
405 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
406 clean_fake_sendmail &&
407 cp $patches longline.patch &&
408 echo $z512$z512 >>longline.patch &&
409 test_must_fail git send-email \
410 --from="Example <nobody@example.com>" \
411 --to=nobody@example.com \
412 --smtp-server="$(pwd)/fake.sendmail" \
413 $patches longline.patch \
414 2>errors &&
415 grep longline.patch errors
418 test_expect_success $PREREQ 'no patch was sent' '
419 ! test -e commandline1
422 test_expect_success $PREREQ 'Author From: in message body' '
423 clean_fake_sendmail &&
424 git send-email \
425 --from="Example <nobody@example.com>" \
426 --to=nobody@example.com \
427 --smtp-server="$(pwd)/fake.sendmail" \
428 $patches &&
429 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
430 grep "From: A <author@example.com>" msgbody1
433 test_expect_success $PREREQ 'Author From: not in message body' '
434 clean_fake_sendmail &&
435 git send-email \
436 --from="A <author@example.com>" \
437 --to=nobody@example.com \
438 --smtp-server="$(pwd)/fake.sendmail" \
439 $patches &&
440 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
441 ! grep "From: A <author@example.com>" msgbody1
444 test_expect_success $PREREQ 'allow long lines with --no-validate' '
445 git send-email \
446 --from="Example <nobody@example.com>" \
447 --to=nobody@example.com \
448 --smtp-server="$(pwd)/fake.sendmail" \
449 --no-validate \
450 $patches longline.patch \
451 2>errors
454 test_expect_success $PREREQ 'Invalid In-Reply-To' '
455 clean_fake_sendmail &&
456 git send-email \
457 --from="Example <nobody@example.com>" \
458 --to=nobody@example.com \
459 --in-reply-to=" " \
460 --smtp-server="$(pwd)/fake.sendmail" \
461 $patches \
462 2>errors &&
463 ! grep "^In-Reply-To: < *>" msgtxt1
466 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
467 clean_fake_sendmail &&
468 (echo "From Example <from@example.com>"
469 echo "To Example <to@example.com>"
470 echo ""
471 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
472 --smtp-server="$(pwd)/fake.sendmail" \
473 $patches 2>errors &&
474 ! grep "^In-Reply-To: < *>" msgtxt1
477 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
478 clean_fake_sendmail &&
479 echo "<unique-message-id@example.com>" >expect &&
480 git send-email \
481 --from="Example <nobody@example.com>" \
482 --to=nobody@example.com \
483 --no-chain-reply-to \
484 --in-reply-to="$(cat expect)" \
485 --smtp-server="$(pwd)/fake.sendmail" \
486 $patches $patches $patches \
487 2>errors &&
488 # The first message is a reply to --in-reply-to
489 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
490 test_cmp expect actual &&
491 # Second and subsequent messages are replies to the first one
492 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
493 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
494 test_cmp expect actual &&
495 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
496 test_cmp expect actual
499 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
500 clean_fake_sendmail &&
501 echo "<unique-message-id@example.com>" >expect &&
502 git send-email \
503 --from="Example <nobody@example.com>" \
504 --to=nobody@example.com \
505 --chain-reply-to \
506 --in-reply-to="$(cat expect)" \
507 --smtp-server="$(pwd)/fake.sendmail" \
508 $patches $patches $patches \
509 2>errors &&
510 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
511 test_cmp expect actual &&
512 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
513 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
514 test_cmp expect actual &&
515 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
516 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
517 test_cmp expect actual
520 test_expect_success $PREREQ 'setup fake editor' '
521 write_script fake-editor <<-\EOF
522 echo fake edit >>"$1"
526 test_set_editor "$(pwd)/fake-editor"
528 test_expect_success $PREREQ '--compose works' '
529 clean_fake_sendmail &&
530 git send-email \
531 --compose --subject foo \
532 --from="Example <nobody@example.com>" \
533 --to=nobody@example.com \
534 --smtp-server="$(pwd)/fake.sendmail" \
535 $patches \
536 2>errors
539 test_expect_success $PREREQ 'first message is compose text' '
540 grep "^fake edit" msgtxt1
543 test_expect_success $PREREQ 'second message is patch' '
544 grep "Subject:.*Second" msgtxt2
547 test_expect_success $PREREQ 'setup expect' "
548 cat >expected-suppress-sob <<\EOF
549 0001-Second.patch
550 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
551 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
552 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
553 Dry-OK. Log says:
554 Server: relay.example.com
555 MAIL FROM:<from@example.com>
556 RCPT TO:<to@example.com>
557 RCPT TO:<cc@example.com>
558 RCPT TO:<author@example.com>
559 RCPT TO:<one@example.com>
560 RCPT TO:<two@example.com>
561 From: Example <from@example.com>
562 To: to@example.com
563 Cc: cc@example.com,
564 A <author@example.com>,
565 One <one@example.com>,
566 two@example.com
567 Subject: [PATCH 1/1] Second.
568 Date: DATE-STRING
569 Message-Id: MESSAGE-ID-STRING
570 X-Mailer: X-MAILER-STRING
572 Result: OK
576 replace_variable_fields () {
577 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
578 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
579 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
582 test_suppression () {
583 git send-email \
584 --dry-run \
585 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
586 --from="Example <from@example.com>" \
587 --to=to@example.com \
588 --smtp-server relay.example.com \
589 $patches | replace_variable_fields \
590 >actual-suppress-$1${2+"-$2"} &&
591 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
594 test_expect_success $PREREQ 'sendemail.cc set' '
595 git config sendemail.cc cc@example.com &&
596 test_suppression sob
599 test_expect_success $PREREQ 'setup expect' "
600 cat >expected-suppress-sob <<\EOF
601 0001-Second.patch
602 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
603 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
604 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
605 Dry-OK. Log says:
606 Server: relay.example.com
607 MAIL FROM:<from@example.com>
608 RCPT TO:<to@example.com>
609 RCPT TO:<author@example.com>
610 RCPT TO:<one@example.com>
611 RCPT TO:<two@example.com>
612 From: Example <from@example.com>
613 To: to@example.com
614 Cc: A <author@example.com>,
615 One <one@example.com>,
616 two@example.com
617 Subject: [PATCH 1/1] Second.
618 Date: DATE-STRING
619 Message-Id: MESSAGE-ID-STRING
620 X-Mailer: X-MAILER-STRING
622 Result: OK
626 test_expect_success $PREREQ 'sendemail.cc unset' '
627 git config --unset sendemail.cc &&
628 test_suppression sob
631 test_expect_success $PREREQ 'setup expect' "
632 cat >expected-suppress-cccmd <<\EOF
633 0001-Second.patch
634 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
635 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
636 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
637 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
638 Dry-OK. Log says:
639 Server: relay.example.com
640 MAIL FROM:<from@example.com>
641 RCPT TO:<to@example.com>
642 RCPT TO:<author@example.com>
643 RCPT TO:<one@example.com>
644 RCPT TO:<two@example.com>
645 RCPT TO:<committer@example.com>
646 From: Example <from@example.com>
647 To: to@example.com
648 Cc: A <author@example.com>,
649 One <one@example.com>,
650 two@example.com,
651 C O Mitter <committer@example.com>
652 Subject: [PATCH 1/1] Second.
653 Date: DATE-STRING
654 Message-Id: MESSAGE-ID-STRING
655 X-Mailer: X-MAILER-STRING
657 Result: OK
661 test_expect_success $PREREQ 'sendemail.cccmd' '
662 write_script cccmd <<-\EOF &&
663 echo cc-cmd@example.com
665 git config sendemail.cccmd ./cccmd &&
666 test_suppression cccmd
669 test_expect_success $PREREQ 'setup expect' '
670 cat >expected-suppress-all <<\EOF
671 0001-Second.patch
672 Dry-OK. Log says:
673 Server: relay.example.com
674 MAIL FROM:<from@example.com>
675 RCPT TO:<to@example.com>
676 From: Example <from@example.com>
677 To: to@example.com
678 Subject: [PATCH 1/1] Second.
679 Date: DATE-STRING
680 Message-Id: MESSAGE-ID-STRING
681 X-Mailer: X-MAILER-STRING
683 Result: OK
687 test_expect_success $PREREQ '--suppress-cc=all' '
688 test_suppression all
691 test_expect_success $PREREQ 'setup expect' "
692 cat >expected-suppress-body <<\EOF
693 0001-Second.patch
694 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
695 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
696 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
697 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
698 Dry-OK. Log says:
699 Server: relay.example.com
700 MAIL FROM:<from@example.com>
701 RCPT TO:<to@example.com>
702 RCPT TO:<author@example.com>
703 RCPT TO:<one@example.com>
704 RCPT TO:<two@example.com>
705 RCPT TO:<cc-cmd@example.com>
706 From: Example <from@example.com>
707 To: to@example.com
708 Cc: A <author@example.com>,
709 One <one@example.com>,
710 two@example.com,
711 cc-cmd@example.com
712 Subject: [PATCH 1/1] Second.
713 Date: DATE-STRING
714 Message-Id: MESSAGE-ID-STRING
715 X-Mailer: X-MAILER-STRING
717 Result: OK
721 test_expect_success $PREREQ '--suppress-cc=body' '
722 test_suppression body
725 test_expect_success $PREREQ 'setup expect' "
726 cat >expected-suppress-body-cccmd <<\EOF
727 0001-Second.patch
728 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
729 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
730 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
731 Dry-OK. Log says:
732 Server: relay.example.com
733 MAIL FROM:<from@example.com>
734 RCPT TO:<to@example.com>
735 RCPT TO:<author@example.com>
736 RCPT TO:<one@example.com>
737 RCPT TO:<two@example.com>
738 From: Example <from@example.com>
739 To: to@example.com
740 Cc: A <author@example.com>,
741 One <one@example.com>,
742 two@example.com
743 Subject: [PATCH 1/1] Second.
744 Date: DATE-STRING
745 Message-Id: MESSAGE-ID-STRING
746 X-Mailer: X-MAILER-STRING
748 Result: OK
752 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
753 test_suppression body cccmd
756 test_expect_success $PREREQ 'setup expect' "
757 cat >expected-suppress-sob <<\EOF
758 0001-Second.patch
759 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
760 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
761 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
762 Dry-OK. Log says:
763 Server: relay.example.com
764 MAIL FROM:<from@example.com>
765 RCPT TO:<to@example.com>
766 RCPT TO:<author@example.com>
767 RCPT TO:<one@example.com>
768 RCPT TO:<two@example.com>
769 From: Example <from@example.com>
770 To: to@example.com
771 Cc: A <author@example.com>,
772 One <one@example.com>,
773 two@example.com
774 Subject: [PATCH 1/1] Second.
775 Date: DATE-STRING
776 Message-Id: MESSAGE-ID-STRING
777 X-Mailer: X-MAILER-STRING
779 Result: OK
783 test_expect_success $PREREQ '--suppress-cc=sob' '
784 test_might_fail git config --unset sendemail.cccmd &&
785 test_suppression sob
788 test_expect_success $PREREQ 'setup expect' "
789 cat >expected-suppress-bodycc <<\EOF
790 0001-Second.patch
791 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
792 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
793 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
794 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
795 Dry-OK. Log says:
796 Server: relay.example.com
797 MAIL FROM:<from@example.com>
798 RCPT TO:<to@example.com>
799 RCPT TO:<author@example.com>
800 RCPT TO:<one@example.com>
801 RCPT TO:<two@example.com>
802 RCPT TO:<committer@example.com>
803 From: Example <from@example.com>
804 To: to@example.com
805 Cc: A <author@example.com>,
806 One <one@example.com>,
807 two@example.com,
808 C O Mitter <committer@example.com>
809 Subject: [PATCH 1/1] Second.
810 Date: DATE-STRING
811 Message-Id: MESSAGE-ID-STRING
812 X-Mailer: X-MAILER-STRING
814 Result: OK
818 test_expect_success $PREREQ '--suppress-cc=bodycc' '
819 test_suppression bodycc
822 test_expect_success $PREREQ 'setup expect' "
823 cat >expected-suppress-cc <<\EOF
824 0001-Second.patch
825 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
826 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
827 Dry-OK. Log says:
828 Server: relay.example.com
829 MAIL FROM:<from@example.com>
830 RCPT TO:<to@example.com>
831 RCPT TO:<author@example.com>
832 RCPT TO:<committer@example.com>
833 From: Example <from@example.com>
834 To: to@example.com
835 Cc: A <author@example.com>,
836 C O Mitter <committer@example.com>
837 Subject: [PATCH 1/1] Second.
838 Date: DATE-STRING
839 Message-Id: MESSAGE-ID-STRING
840 X-Mailer: X-MAILER-STRING
842 Result: OK
846 test_expect_success $PREREQ '--suppress-cc=cc' '
847 test_suppression cc
850 test_confirm () {
851 echo y | \
852 GIT_SEND_EMAIL_NOTTY=1 \
853 git send-email \
854 --from="Example <nobody@example.com>" \
855 --to=nobody@example.com \
856 --smtp-server="$(pwd)/fake.sendmail" \
857 $@ $patches >stdout &&
858 grep "Send this email" stdout
861 test_expect_success $PREREQ '--confirm=always' '
862 test_confirm --confirm=always --suppress-cc=all
865 test_expect_success $PREREQ '--confirm=auto' '
866 test_confirm --confirm=auto
869 test_expect_success $PREREQ '--confirm=cc' '
870 test_confirm --confirm=cc
873 test_expect_success $PREREQ '--confirm=compose' '
874 test_confirm --confirm=compose --compose
877 test_expect_success $PREREQ 'confirm by default (due to cc)' '
878 test_when_finished git config sendemail.confirm never &&
879 git config --unset sendemail.confirm &&
880 test_confirm
883 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
884 test_when_finished git config sendemail.confirm never &&
885 git config --unset sendemail.confirm &&
886 test_confirm --suppress-cc=all --compose
889 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
890 test_when_finished git config sendemail.confirm never &&
891 git config --unset sendemail.confirm &&
892 rm -fr outdir &&
893 git format-patch -2 -o outdir &&
894 GIT_SEND_EMAIL_NOTTY=1 \
895 git send-email \
896 --from="Example <nobody@example.com>" \
897 --to=nobody@example.com \
898 --smtp-server="$(pwd)/fake.sendmail" \
899 outdir/*.patch </dev/null
902 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
903 test_when_finished git config sendemail.confirm never &&
904 git config sendemail.confirm auto &&
905 GIT_SEND_EMAIL_NOTTY=1 &&
906 export GIT_SEND_EMAIL_NOTTY &&
907 test_must_fail git send-email \
908 --from="Example <nobody@example.com>" \
909 --to=nobody@example.com \
910 --smtp-server="$(pwd)/fake.sendmail" \
911 $patches </dev/null
914 test_expect_success $PREREQ 'confirm does not loop forever' '
915 test_when_finished git config sendemail.confirm never &&
916 git config sendemail.confirm auto &&
917 GIT_SEND_EMAIL_NOTTY=1 &&
918 export GIT_SEND_EMAIL_NOTTY &&
919 yes "bogus" | test_must_fail git send-email \
920 --from="Example <nobody@example.com>" \
921 --to=nobody@example.com \
922 --smtp-server="$(pwd)/fake.sendmail" \
923 $patches
926 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
927 clean_fake_sendmail &&
928 rm -fr outdir &&
929 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
930 git send-email \
931 --from="Example <nobody@example.com>" \
932 --to=nobody@example.com \
933 --smtp-server="$(pwd)/fake.sendmail" \
934 outdir/*.patch &&
935 grep "^ " msgtxt1 |
936 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
939 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
940 clean_fake_sendmail &&
941 write_script fake-editor-utf8 <<-\EOF &&
942 echo "utf8 body: àéìöú" >>"$1"
944 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
945 git send-email \
946 --compose --subject foo \
947 --from="Example <nobody@example.com>" \
948 --to=nobody@example.com \
949 --smtp-server="$(pwd)/fake.sendmail" \
950 $patches &&
951 grep "^utf8 body" msgtxt1 &&
952 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
955 test_expect_success $PREREQ '--compose respects user mime type' '
956 clean_fake_sendmail &&
957 write_script fake-editor-utf8-mime <<-\EOF &&
958 cat >"$1" <<-\EOM
959 MIME-Version: 1.0
960 Content-Type: text/plain; charset=iso-8859-1
961 Content-Transfer-Encoding: 8bit
962 Subject: foo
964 utf8 body: àéìöú
967 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
968 git send-email \
969 --compose --subject foo \
970 --from="Example <nobody@example.com>" \
971 --to=nobody@example.com \
972 --smtp-server="$(pwd)/fake.sendmail" \
973 $patches &&
974 grep "^utf8 body" msgtxt1 &&
975 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
976 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
979 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
980 clean_fake_sendmail &&
981 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
982 git send-email \
983 --compose --subject utf8-sübjëct \
984 --from="Example <nobody@example.com>" \
985 --to=nobody@example.com \
986 --smtp-server="$(pwd)/fake.sendmail" \
987 $patches &&
988 grep "^fake edit" msgtxt1 &&
989 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
992 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
993 clean_fake_sendmail &&
994 test_commit weird_author &&
995 test_when_finished "git reset --hard HEAD^" &&
996 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
997 git format-patch --stdout -1 >funny_name.patch &&
998 git send-email --from="Example <nobody@example.com>" \
999 --to=nobody@example.com \
1000 --smtp-server="$(pwd)/fake.sendmail" \
1001 funny_name.patch &&
1002 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1005 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1006 clean_fake_sendmail &&
1007 test_commit weird_sender &&
1008 test_when_finished "git reset --hard HEAD^" &&
1009 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1010 git format-patch --stdout -1 >funny_name.patch &&
1011 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1012 --to=nobody@example.com \
1013 --smtp-server="$(pwd)/fake.sendmail" \
1014 funny_name.patch &&
1015 grep "^From: " msgtxt1 >msgfrom &&
1016 test_line_count = 1 msgfrom
1019 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1020 clean_fake_sendmail &&
1021 git config sendemail.composeencoding iso-8859-1 &&
1022 write_script fake-editor-utf8 <<-\EOF &&
1023 echo "utf8 body: àéìöú" >>"$1"
1025 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1026 git send-email \
1027 --compose --subject foo \
1028 --from="Example <nobody@example.com>" \
1029 --to=nobody@example.com \
1030 --smtp-server="$(pwd)/fake.sendmail" \
1031 $patches &&
1032 grep "^utf8 body" msgtxt1 &&
1033 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1036 test_expect_success $PREREQ '--compose-encoding works' '
1037 clean_fake_sendmail &&
1038 write_script fake-editor-utf8 <<-\EOF &&
1039 echo "utf8 body: àéìöú" >>"$1"
1041 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1042 git send-email \
1043 --compose-encoding iso-8859-1 \
1044 --compose --subject foo \
1045 --from="Example <nobody@example.com>" \
1046 --to=nobody@example.com \
1047 --smtp-server="$(pwd)/fake.sendmail" \
1048 $patches &&
1049 grep "^utf8 body" msgtxt1 &&
1050 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1053 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1054 clean_fake_sendmail &&
1055 git config sendemail.composeencoding iso-8859-1 &&
1056 write_script fake-editor-utf8 <<-\EOF &&
1057 echo "utf8 body: àéìöú" >>"$1"
1059 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1060 git send-email \
1061 --compose-encoding iso-8859-2 \
1062 --compose --subject foo \
1063 --from="Example <nobody@example.com>" \
1064 --to=nobody@example.com \
1065 --smtp-server="$(pwd)/fake.sendmail" \
1066 $patches &&
1067 grep "^utf8 body" msgtxt1 &&
1068 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1071 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1072 clean_fake_sendmail &&
1073 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1074 git send-email \
1075 --compose-encoding iso-8859-2 \
1076 --compose --subject utf8-sübjëct \
1077 --from="Example <nobody@example.com>" \
1078 --to=nobody@example.com \
1079 --smtp-server="$(pwd)/fake.sendmail" \
1080 $patches &&
1081 grep "^fake edit" msgtxt1 &&
1082 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1085 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1086 echo master >master &&
1087 git add master &&
1088 git commit -m"add master" &&
1089 test_must_fail git send-email --dry-run master 2>errors &&
1090 grep disambiguate errors
1093 test_expect_success $PREREQ 'feed two files' '
1094 rm -fr outdir &&
1095 git format-patch -2 -o outdir &&
1096 git send-email \
1097 --dry-run \
1098 --from="Example <nobody@example.com>" \
1099 --to=nobody@example.com \
1100 outdir/000?-*.patch 2>errors >out &&
1101 grep "^Subject: " out >subjects &&
1102 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1103 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1106 test_expect_success $PREREQ 'in-reply-to but no threading' '
1107 git send-email \
1108 --dry-run \
1109 --from="Example <nobody@example.com>" \
1110 --to=nobody@example.com \
1111 --in-reply-to="<in-reply-id@example.com>" \
1112 --no-thread \
1113 $patches |
1114 grep "In-Reply-To: <in-reply-id@example.com>"
1117 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1118 git send-email \
1119 --dry-run \
1120 --from="Example <nobody@example.com>" \
1121 --to=nobody@example.com \
1122 --no-thread \
1123 $patches $patches >stdout &&
1124 ! grep "In-Reply-To: " stdout
1127 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1128 git send-email \
1129 --dry-run \
1130 --from="Example <nobody@example.com>" \
1131 --to=nobody@example.com \
1132 --thread \
1133 --no-chain-reply-to \
1134 $patches $patches >stdout &&
1135 grep "In-Reply-To: " stdout
1138 test_expect_success $PREREQ 'sendemail.to works' '
1139 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1140 git send-email \
1141 --dry-run \
1142 --from="Example <nobody@example.com>" \
1143 $patches $patches >stdout &&
1144 grep "To: Somebody <somebody@ex.com>" stdout
1147 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1148 git send-email \
1149 --dry-run \
1150 --from="Example <nobody@example.com>" \
1151 --no-to \
1152 --to=nobody@example.com \
1153 $patches $patches >stdout &&
1154 grep "To: nobody@example.com" stdout &&
1155 ! grep "To: Somebody <somebody@ex.com>" stdout
1158 test_expect_success $PREREQ 'sendemail.cc works' '
1159 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1160 git send-email \
1161 --dry-run \
1162 --from="Example <nobody@example.com>" \
1163 --to=nobody@example.com \
1164 $patches $patches >stdout &&
1165 grep "Cc: Somebody <somebody@ex.com>" stdout
1168 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1169 git send-email \
1170 --dry-run \
1171 --from="Example <nobody@example.com>" \
1172 --no-cc \
1173 --cc=bodies@example.com \
1174 --to=nobody@example.com \
1175 $patches $patches >stdout &&
1176 grep "Cc: bodies@example.com" stdout &&
1177 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1180 test_expect_success $PREREQ 'sendemail.bcc works' '
1181 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1182 git send-email \
1183 --dry-run \
1184 --from="Example <nobody@example.com>" \
1185 --to=nobody@example.com \
1186 --smtp-server relay.example.com \
1187 $patches $patches >stdout &&
1188 grep "RCPT TO:<other@ex.com>" stdout
1191 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1192 git send-email \
1193 --dry-run \
1194 --from="Example <nobody@example.com>" \
1195 --no-bcc \
1196 --bcc=bodies@example.com \
1197 --to=nobody@example.com \
1198 --smtp-server relay.example.com \
1199 $patches $patches >stdout &&
1200 grep "RCPT TO:<bodies@example.com>" stdout &&
1201 ! grep "RCPT TO:<other@ex.com>" stdout
1204 test_expect_success $PREREQ 'patches To headers are used by default' '
1205 patch=$(git format-patch -1 --to="bodies@example.com") &&
1206 test_when_finished "rm $patch" &&
1207 git send-email \
1208 --dry-run \
1209 --from="Example <nobody@example.com>" \
1210 --smtp-server relay.example.com \
1211 $patch >stdout &&
1212 grep "RCPT TO:<bodies@example.com>" stdout
1215 test_expect_success $PREREQ 'patches To headers are appended to' '
1216 patch=$(git format-patch -1 --to="bodies@example.com") &&
1217 test_when_finished "rm $patch" &&
1218 git send-email \
1219 --dry-run \
1220 --from="Example <nobody@example.com>" \
1221 --to=nobody@example.com \
1222 --smtp-server relay.example.com \
1223 $patch >stdout &&
1224 grep "RCPT TO:<bodies@example.com>" stdout &&
1225 grep "RCPT TO:<nobody@example.com>" stdout
1228 test_expect_success $PREREQ 'To headers from files reset each patch' '
1229 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1230 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1231 test_when_finished "rm $patch1 && rm $patch2" &&
1232 git send-email \
1233 --dry-run \
1234 --from="Example <nobody@example.com>" \
1235 --to="nobody@example.com" \
1236 --smtp-server relay.example.com \
1237 $patch1 $patch2 >stdout &&
1238 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1239 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1240 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1243 test_expect_success $PREREQ 'setup expect' '
1244 cat >email-using-8bit <<\EOF
1245 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1246 Message-Id: <bogus-message-id@example.com>
1247 From: author@example.com
1248 Date: Sat, 12 Jun 2010 15:53:58 +0200
1249 Subject: subject goes here
1251 Dieser deutsche Text enthält einen Umlaut!
1255 test_expect_success $PREREQ 'setup expect' '
1256 echo "Subject: subject goes here" >expected
1259 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1260 clean_fake_sendmail &&
1261 echo bogus |
1262 git send-email --from=author@example.com --to=nobody@example.com \
1263 --smtp-server="$(pwd)/fake.sendmail" \
1264 --8bit-encoding=UTF-8 \
1265 email-using-8bit >stdout &&
1266 grep "Subject" msgtxt1 >actual &&
1267 test_cmp expected actual
1270 test_expect_success $PREREQ 'setup expect' '
1271 cat >content-type-decl <<-\EOF
1272 MIME-Version: 1.0
1273 Content-Type: text/plain; charset=UTF-8
1274 Content-Transfer-Encoding: 8bit
1278 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1279 clean_fake_sendmail &&
1280 echo |
1281 git send-email --from=author@example.com --to=nobody@example.com \
1282 --smtp-server="$(pwd)/fake.sendmail" \
1283 email-using-8bit >stdout &&
1284 grep "do not declare a Content-Transfer-Encoding" stdout &&
1285 grep email-using-8bit stdout &&
1286 grep "Which 8bit encoding" stdout &&
1287 egrep "Content|MIME" msgtxt1 >actual &&
1288 test_cmp content-type-decl actual
1291 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1292 clean_fake_sendmail &&
1293 git config sendemail.assume8bitEncoding UTF-8 &&
1294 echo bogus |
1295 git send-email --from=author@example.com --to=nobody@example.com \
1296 --smtp-server="$(pwd)/fake.sendmail" \
1297 email-using-8bit >stdout &&
1298 egrep "Content|MIME" msgtxt1 >actual &&
1299 test_cmp content-type-decl actual
1302 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1303 clean_fake_sendmail &&
1304 git config sendemail.assume8bitEncoding "bogus too" &&
1305 echo bogus |
1306 git send-email --from=author@example.com --to=nobody@example.com \
1307 --smtp-server="$(pwd)/fake.sendmail" \
1308 --8bit-encoding=UTF-8 \
1309 email-using-8bit >stdout &&
1310 egrep "Content|MIME" msgtxt1 >actual &&
1311 test_cmp content-type-decl actual
1314 test_expect_success $PREREQ 'setup expect' '
1315 cat >email-using-8bit <<-\EOF
1316 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1317 Message-Id: <bogus-message-id@example.com>
1318 From: author@example.com
1319 Date: Sat, 12 Jun 2010 15:53:58 +0200
1320 Subject: Dieser Betreff enthält auch einen Umlaut!
1322 Nothing to see here.
1326 test_expect_success $PREREQ 'setup expect' '
1327 cat >expected <<-\EOF
1328 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1332 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1333 clean_fake_sendmail &&
1334 echo bogus |
1335 git send-email --from=author@example.com --to=nobody@example.com \
1336 --smtp-server="$(pwd)/fake.sendmail" \
1337 --8bit-encoding=UTF-8 \
1338 email-using-8bit >stdout &&
1339 grep "Subject" msgtxt1 >actual &&
1340 test_cmp expected actual
1343 test_expect_success $PREREQ 'setup expect' '
1344 cat >email-using-8bit <<-\EOF
1345 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1346 Message-Id: <bogus-message-id@example.com>
1347 From: A U Thor <author@example.com>
1348 Date: Sat, 12 Jun 2010 15:53:58 +0200
1349 Content-Type: text/plain; charset=UTF-8
1350 Subject: Nothing to see here.
1352 Dieser Betreff enthält auch einen Umlaut!
1356 test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1357 clean_fake_sendmail &&
1358 git config sendemail.transferEncoding 7bit &&
1359 test_must_fail git send-email \
1360 --transfer-encoding=7bit \
1361 --smtp-server="$(pwd)/fake.sendmail" \
1362 email-using-8bit \
1363 2>errors >out &&
1364 grep "cannot send message as 7bit" errors &&
1365 test -z "$(ls msgtxt*)"
1368 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1369 clean_fake_sendmail &&
1370 git config sendemail.transferEncoding 8bit &&
1371 test_must_fail git send-email \
1372 --transfer-encoding=7bit \
1373 --smtp-server="$(pwd)/fake.sendmail" \
1374 email-using-8bit \
1375 2>errors >out &&
1376 grep "cannot send message as 7bit" errors &&
1377 test -z "$(ls msgtxt*)"
1380 test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1381 clean_fake_sendmail &&
1382 git send-email \
1383 --transfer-encoding=8bit \
1384 --smtp-server="$(pwd)/fake.sendmail" \
1385 email-using-8bit \
1386 2>errors >out &&
1387 sed '1,/^$/d' msgtxt1 >actual &&
1388 sed '1,/^$/d' email-using-8bit >expected &&
1389 test_cmp expected actual
1392 test_expect_success $PREREQ 'setup expect' '
1393 cat >expected <<-\EOF
1394 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1398 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1399 clean_fake_sendmail &&
1400 git send-email \
1401 --transfer-encoding=quoted-printable \
1402 --smtp-server="$(pwd)/fake.sendmail" \
1403 email-using-8bit \
1404 2>errors >out &&
1405 sed '1,/^$/d' msgtxt1 >actual &&
1406 test_cmp expected actual
1409 test_expect_success $PREREQ 'setup expect' '
1410 cat >expected <<-\EOF
1411 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1415 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1416 clean_fake_sendmail &&
1417 git send-email \
1418 --transfer-encoding=base64 \
1419 --smtp-server="$(pwd)/fake.sendmail" \
1420 email-using-8bit \
1421 2>errors >out &&
1422 sed '1,/^$/d' msgtxt1 >actual &&
1423 test_cmp expected actual
1426 test_expect_success $PREREQ 'setup expect' '
1427 cat >email-using-qp <<-\EOF
1428 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1429 Message-Id: <bogus-message-id@example.com>
1430 From: A U Thor <author@example.com>
1431 Date: Sat, 12 Jun 2010 15:53:58 +0200
1432 MIME-Version: 1.0
1433 Content-Transfer-Encoding: quoted-printable
1434 Content-Type: text/plain; charset=UTF-8
1435 Subject: Nothing to see here.
1437 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1441 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1442 clean_fake_sendmail &&
1443 git send-email \
1444 --transfer-encoding=base64 \
1445 --smtp-server="$(pwd)/fake.sendmail" \
1446 email-using-qp \
1447 2>errors >out &&
1448 sed '1,/^$/d' msgtxt1 >actual &&
1449 test_cmp expected actual
1452 test_expect_success $PREREQ 'setup expect' "
1453 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1454 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1455 Message-Id: <bogus-message-id@example.com>
1456 From: A U Thor <author@example.com>
1457 Date: Sat, 12 Jun 2010 15:53:58 +0200
1458 Content-Type: text/plain; charset=UTF-8
1459 Subject: Nothing to see here.
1461 Look, I have a CRLF and an = sign!%
1465 test_expect_success $PREREQ 'setup expect' '
1466 cat >expected <<-\EOF
1467 Look, I have a CRLF and an =3D sign!=0D
1471 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1472 clean_fake_sendmail &&
1473 git send-email \
1474 --transfer-encoding=quoted-printable \
1475 --smtp-server="$(pwd)/fake.sendmail" \
1476 email-using-crlf \
1477 2>errors >out &&
1478 sed '1,/^$/d' msgtxt1 >actual &&
1479 test_cmp expected actual
1482 test_expect_success $PREREQ 'setup expect' '
1483 cat >expected <<-\EOF
1484 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1488 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1489 clean_fake_sendmail &&
1490 git send-email \
1491 --transfer-encoding=base64 \
1492 --smtp-server="$(pwd)/fake.sendmail" \
1493 email-using-crlf \
1494 2>errors >out &&
1495 sed '1,/^$/d' msgtxt1 >actual &&
1496 test_cmp expected actual
1500 # Note that the patches in this test are deliberately out of order; we
1501 # want to make sure it works even if the cover-letter is not in the
1502 # first mail.
1503 test_expect_success $PREREQ 'refusing to send cover letter template' '
1504 clean_fake_sendmail &&
1505 rm -fr outdir &&
1506 git format-patch --cover-letter -2 -o outdir &&
1507 test_must_fail git send-email \
1508 --from="Example <nobody@example.com>" \
1509 --to=nobody@example.com \
1510 --smtp-server="$(pwd)/fake.sendmail" \
1511 outdir/0002-*.patch \
1512 outdir/0000-*.patch \
1513 outdir/0001-*.patch \
1514 2>errors >out &&
1515 grep "SUBJECT HERE" errors &&
1516 test -z "$(ls msgtxt*)"
1519 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1520 clean_fake_sendmail &&
1521 rm -fr outdir &&
1522 git format-patch --cover-letter -2 -o outdir &&
1523 git send-email \
1524 --force \
1525 --from="Example <nobody@example.com>" \
1526 --to=nobody@example.com \
1527 --smtp-server="$(pwd)/fake.sendmail" \
1528 outdir/0002-*.patch \
1529 outdir/0000-*.patch \
1530 outdir/0001-*.patch \
1531 2>errors >out &&
1532 ! grep "SUBJECT HERE" errors &&
1533 test -n "$(ls msgtxt*)"
1536 test_cover_addresses () {
1537 header="$1"
1538 shift
1539 clean_fake_sendmail &&
1540 rm -fr outdir &&
1541 git format-patch --cover-letter -2 -o outdir &&
1542 cover=$(echo outdir/0000-*.patch) &&
1543 mv $cover cover-to-edit.patch &&
1544 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1545 git send-email \
1546 --force \
1547 --from="Example <nobody@example.com>" \
1548 --no-to --no-cc \
1549 "$@" \
1550 --smtp-server="$(pwd)/fake.sendmail" \
1551 outdir/0000-*.patch \
1552 outdir/0001-*.patch \
1553 outdir/0002-*.patch \
1554 2>errors >out &&
1555 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1556 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1557 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1558 test_line_count = 1 to1 &&
1559 test_line_count = 1 to2 &&
1560 test_line_count = 1 to3
1563 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1564 test_cover_addresses "To" --to-cover
1567 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1568 test_cover_addresses "Cc" --cc-cover
1571 test_expect_success $PREREQ 'tocover adds To to all mail' '
1572 test_config sendemail.tocover true &&
1573 test_cover_addresses "To"
1576 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1577 test_config sendemail.cccover true &&
1578 test_cover_addresses "Cc"
1581 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1582 clean_fake_sendmail &&
1583 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1584 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1585 git config sendemail.aliasfiletype mutt &&
1586 git send-email \
1587 --from="Example <nobody@example.com>" \
1588 --to=sbd \
1589 --smtp-server="$(pwd)/fake.sendmail" \
1590 outdir/0001-*.patch \
1591 2>errors >out &&
1592 grep "^!somebody@example\.org!$" commandline1 &&
1593 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1596 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1597 clean_fake_sendmail &&
1598 echo "alias sbd somebody@example.org" >.mailrc &&
1599 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1600 git config sendemail.aliasfiletype mailrc &&
1601 git send-email \
1602 --from="Example <nobody@example.com>" \
1603 --to=sbd \
1604 --smtp-server="$(pwd)/fake.sendmail" \
1605 outdir/0001-*.patch \
1606 2>errors >out &&
1607 grep "^!somebody@example\.org!$" commandline1
1610 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1611 clean_fake_sendmail &&
1612 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1613 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1614 git config sendemail.aliasfiletype mailrc &&
1615 git send-email \
1616 --from="Example <nobody@example.com>" \
1617 --to=sbd \
1618 --smtp-server="$(pwd)/fake.sendmail" \
1619 outdir/0001-*.patch \
1620 2>errors >out &&
1621 grep "^!someone@example\.org!$" commandline1
1624 test_dump_aliases () {
1625 msg="$1" && shift &&
1626 filetype="$1" && shift &&
1627 printf '%s\n' "$@" >expect &&
1628 cat >.tmp-email-aliases &&
1630 test_expect_success $PREREQ "$msg" '
1631 clean_fake_sendmail && rm -fr outdir &&
1632 git config --replace-all sendemail.aliasesfile \
1633 "$(pwd)/.tmp-email-aliases" &&
1634 git config sendemail.aliasfiletype "$filetype" &&
1635 git send-email --dump-aliases 2>errors >actual &&
1636 test_cmp expect actual
1640 test_dump_aliases '--dump-aliases sendmail format' \
1641 'sendmail' \
1642 'abgroup' \
1643 'alice' \
1644 'bcgrp' \
1645 'bob' \
1646 'chloe' <<-\EOF
1647 alice: Alice W Land <awol@example.com>
1648 bob: Robert Bobbyton <bob@example.com>
1649 chloe: chloe@example.com
1650 abgroup: alice, bob
1651 bcgrp: bob, chloe, Other <o@example.com>
1654 test_dump_aliases '--dump-aliases mutt format' \
1655 'mutt' \
1656 'alice' \
1657 'bob' \
1658 'chloe' \
1659 'donald' <<-\EOF
1660 alias alice Alice W Land <awol@example.com>
1661 alias donald Donald C Carlton <donc@example.com>
1662 alias bob Robert Bobbyton <bob@example.com>
1663 alias chloe chloe@example.com
1666 test_dump_aliases '--dump-aliases mailrc format' \
1667 'mailrc' \
1668 'alice' \
1669 'bob' \
1670 'chloe' \
1671 'eve' <<-\EOF
1672 alias alice Alice W Land <awol@example.com>
1673 alias eve Eve <eve@example.com>
1674 alias bob Robert Bobbyton <bob@example.com>
1675 alias chloe chloe@example.com
1678 test_dump_aliases '--dump-aliases pine format' \
1679 'pine' \
1680 'alice' \
1681 'bob' \
1682 'chloe' \
1683 'eve' <<-\EOF
1684 alice Alice W Land <awol@example.com>
1685 eve Eve <eve@example.com>
1686 bob Robert Bobbyton <bob@example.com>
1687 chloe chloe@example.com
1690 test_dump_aliases '--dump-aliases gnus format' \
1691 'gnus' \
1692 'alice' \
1693 'bob' \
1694 'chloe' \
1695 'eve' <<-\EOF
1696 (define-mail-alias "alice" "awol@example.com")
1697 (define-mail-alias "eve" "eve@example.com")
1698 (define-mail-alias "bob" "bob@example.com")
1699 (define-mail-alias "chloe" "chloe@example.com")
1702 test_expect_success '--dump-aliases must be used alone' '
1703 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1706 test_sendmail_aliases () {
1707 msg="$1" && shift &&
1708 expect="$@" &&
1709 cat >.tmp-email-aliases &&
1711 test_expect_success $PREREQ "$msg" '
1712 clean_fake_sendmail && rm -fr outdir &&
1713 git format-patch -1 -o outdir &&
1714 git config --replace-all sendemail.aliasesfile \
1715 "$(pwd)/.tmp-email-aliases" &&
1716 git config sendemail.aliasfiletype sendmail &&
1717 git send-email \
1718 --from="Example <nobody@example.com>" \
1719 --to=alice --to=bcgrp \
1720 --smtp-server="$(pwd)/fake.sendmail" \
1721 outdir/0001-*.patch \
1722 2>errors >out &&
1723 for i in $expect
1725 grep "^!$i!$" commandline1 || return 1
1726 done
1730 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1731 'awol@example\.com' \
1732 'bob@example\.com' \
1733 'chloe@example\.com' \
1734 'o@example\.com' <<-\EOF
1735 alice: Alice W Land <awol@example.com>
1736 bob: Robert Bobbyton <bob@example.com>
1737 # this is a comment
1738 # this is also a comment
1739 chloe: chloe@example.com
1740 abgroup: alice, bob
1741 bcgrp: bob, chloe, Other <o@example.com>
1744 test_sendmail_aliases 'sendmail aliases line folding' \
1745 alice1 \
1746 bob1 bob2 \
1747 chuck1 chuck2 \
1748 darla1 darla2 darla3 \
1749 elton1 elton2 elton3 \
1750 fred1 fred2 \
1751 greg1 <<-\EOF
1752 alice: alice1
1753 bob: bob1,\
1754 bob2
1755 chuck: chuck1,
1756 chuck2
1757 darla: darla1,\
1758 darla2,
1759 darla3
1760 elton: elton1,
1761 elton2,\
1762 elton3
1763 fred: fred1,\
1764 fred2
1765 greg: greg1
1766 bcgrp: bob, chuck, darla, elton, fred, greg
1769 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1770 alice1 bob1 <<-\EOF
1771 alice: alice1
1772 bcgrp: bob1\
1775 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1778 test_expect_success $PREREQ 'alias support in To header' '
1779 clean_fake_sendmail &&
1780 echo "alias sbd someone@example.org" >.mailrc &&
1781 test_config sendemail.aliasesfile ".mailrc" &&
1782 test_config sendemail.aliasfiletype mailrc &&
1783 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1784 git send-email \
1785 --from="Example <nobody@example.com>" \
1786 --smtp-server="$(pwd)/fake.sendmail" \
1787 aliased.patch \
1788 2>errors >out &&
1789 grep "^!someone@example\.org!$" commandline1
1792 test_expect_success $PREREQ 'alias support in Cc header' '
1793 clean_fake_sendmail &&
1794 echo "alias sbd someone@example.org" >.mailrc &&
1795 test_config sendemail.aliasesfile ".mailrc" &&
1796 test_config sendemail.aliasfiletype mailrc &&
1797 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1798 git send-email \
1799 --from="Example <nobody@example.com>" \
1800 --smtp-server="$(pwd)/fake.sendmail" \
1801 aliased.patch \
1802 2>errors >out &&
1803 grep "^!someone@example\.org!$" commandline1
1806 test_expect_success $PREREQ 'tocmd works with aliases' '
1807 clean_fake_sendmail &&
1808 echo "alias sbd someone@example.org" >.mailrc &&
1809 test_config sendemail.aliasesfile ".mailrc" &&
1810 test_config sendemail.aliasfiletype mailrc &&
1811 git format-patch --stdout -1 >tocmd.patch &&
1812 echo tocmd--sbd >>tocmd.patch &&
1813 git send-email \
1814 --from="Example <nobody@example.com>" \
1815 --to-cmd=./tocmd-sed \
1816 --smtp-server="$(pwd)/fake.sendmail" \
1817 tocmd.patch \
1818 2>errors >out &&
1819 grep "^!someone@example\.org!$" commandline1
1822 test_expect_success $PREREQ 'cccmd works with aliases' '
1823 clean_fake_sendmail &&
1824 echo "alias sbd someone@example.org" >.mailrc &&
1825 test_config sendemail.aliasesfile ".mailrc" &&
1826 test_config sendemail.aliasfiletype mailrc &&
1827 git format-patch --stdout -1 >cccmd.patch &&
1828 echo cccmd--sbd >>cccmd.patch &&
1829 git send-email \
1830 --from="Example <nobody@example.com>" \
1831 --cc-cmd=./cccmd-sed \
1832 --smtp-server="$(pwd)/fake.sendmail" \
1833 cccmd.patch \
1834 2>errors >out &&
1835 grep "^!someone@example\.org!$" commandline1
1838 do_xmailer_test () {
1839 expected=$1 params=$2 &&
1840 git format-patch -1 &&
1841 git send-email \
1842 --from="Example <nobody@example.com>" \
1843 --to=someone@example.com \
1844 --smtp-server="$(pwd)/fake.sendmail" \
1845 $params \
1846 0001-*.patch \
1847 2>errors >out &&
1848 { grep '^X-Mailer:' out || :; } >mailer &&
1849 test_line_count = $expected mailer
1852 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1853 do_xmailer_test 1 "--xmailer" &&
1854 do_xmailer_test 0 "--no-xmailer"
1857 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1858 test_config sendemail.xmailer true &&
1859 do_xmailer_test 1 "" &&
1860 do_xmailer_test 0 "--no-xmailer" &&
1861 do_xmailer_test 1 "--xmailer"
1864 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1865 test_config sendemail.xmailer false &&
1866 do_xmailer_test 0 "" &&
1867 do_xmailer_test 0 "--no-xmailer" &&
1868 do_xmailer_test 1 "--xmailer"
1871 test_expect_success $PREREQ 'setup expected-list' '
1872 git send-email \
1873 --dry-run \
1874 --from="Example <from@example.com>" \
1875 --to="To 1 <to1@example.com>" \
1876 --to="to2@example.com" \
1877 --to="to3@example.com" \
1878 --cc="Cc 1 <cc1@example.com>" \
1879 --cc="Cc2 <cc2@example.com>" \
1880 --bcc="bcc1@example.com" \
1881 --bcc="bcc2@example.com" \
1882 0001-add-master.patch | replace_variable_fields \
1883 >expected-list
1886 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1887 git send-email \
1888 --dry-run \
1889 --from="Example <from@example.com>" \
1890 --to="To 1 <to1@example.com>, to2@example.com" \
1891 --to="to3@example.com" \
1892 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1893 --bcc="bcc1@example.com, bcc2@example.com" \
1894 0001-add-master.patch | replace_variable_fields \
1895 >actual-list &&
1896 test_cmp expected-list actual-list
1899 test_expect_success $PREREQ 'aliases work with email list' '
1900 echo "alias to2 to2@example.com" >.mutt &&
1901 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1902 test_config sendemail.aliasesfile ".mutt" &&
1903 test_config sendemail.aliasfiletype mutt &&
1904 git send-email \
1905 --dry-run \
1906 --from="Example <from@example.com>" \
1907 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1908 --cc="cc1, Cc2 <cc2@example.com>" \
1909 --bcc="bcc1@example.com, bcc2@example.com" \
1910 0001-add-master.patch | replace_variable_fields \
1911 >actual-list &&
1912 test_cmp expected-list actual-list
1915 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
1916 echo "alias to2 to2@example.com" >.mutt &&
1917 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1918 test_config sendemail.aliasesfile ".mutt" &&
1919 test_config sendemail.aliasfiletype mutt &&
1920 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
1921 TO2=$(echo "QZto2" | qz_to_tab_space) &&
1922 CC1=$(echo "cc1" | append_cr) &&
1923 BCC1=$(echo "Q bcc1@example.com Q" | q_to_nul) &&
1924 git send-email \
1925 --dry-run \
1926 --from=" Example <from@example.com>" \
1927 --to="$TO1" \
1928 --to="$TO2" \
1929 --to=" to3@example.com " \
1930 --cc="$CC1" \
1931 --cc="Cc2 <cc2@example.com>" \
1932 --bcc="$BCC1" \
1933 --bcc="bcc2@example.com" \
1934 0001-add-master.patch | replace_variable_fields \
1935 >actual-list &&
1936 test_cmp expected-list actual-list
1939 test_expect_success $PREREQ 'invoke hook' '
1940 mkdir -p .git/hooks &&
1942 write_script .git/hooks/sendemail-validate <<-\EOF &&
1943 # test that we have the correct environment variable, pwd, and
1944 # argument
1945 case "$GIT_DIR" in
1946 *.git)
1947 true
1950 false
1952 esac &&
1953 test -f 0001-add-master.patch &&
1954 grep "add master" "$1"
1957 mkdir subdir &&
1959 # Test that it works even if we are not at the root of the
1960 # working tree
1961 cd subdir &&
1962 git send-email \
1963 --from="Example <nobody@example.com>" \
1964 --to=nobody@example.com \
1965 --smtp-server="$(pwd)/../fake.sendmail" \
1966 ../0001-add-master.patch &&
1968 # Verify error message when a patch is rejected by the hook
1969 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
1970 git send-email \
1971 --from="Example <nobody@example.com>" \
1972 --to=nobody@example.com \
1973 --smtp-server="$(pwd)/../fake.sendmail" \
1974 ../another.patch 2>err
1975 test_i18ngrep "rejected by sendemail-validate hook" err
1979 test_expect_success $PREREQ 'test that send-email works outside a repo' '
1980 nongit git send-email \
1981 --from="Example <nobody@example.com>" \
1982 --to=nobody@example.com \
1983 --smtp-server="$(pwd)/fake.sendmail" \
1984 "$(pwd)/0001-add-master.patch"
1987 test_done