3 test_description
='git send-email'
8 'prepare reference tree' \
9 'echo "1A quick brown fox jumps over the" >file &&
10 echo "lazy dog" >>file &&
12 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
16 '(echo "#!$SHELL_PATH"
19 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
22 echo " echo \"!\$a!\""
23 echo "done >commandline\$output"
24 echo "cat > msgtxt\$output"
26 chmod +x ./fake.sendmail &&
27 git add fake.sendmail &&
28 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
30 clean_fake_sendmail
() {
31 rm -f commandline
* msgtxt
*
34 test_expect_success
'Extract patches' '
35 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
38 # Test no confirm early to ensure remaining tests will not hang
42 GIT_SEND_EMAIL_NOTTY
=1 \
44 --from="Example <from@example.com>" \
45 --to=nobody@example.com \
46 --smtp-server="$(pwd)/fake.sendmail" \
49 test_must_fail
grep "Send this email" stdout
&&
53 # Exit immediately to prevent hang if a no-confirm test fails
55 test -f no_confirm_okay ||
{
56 say
'No confirm test failed; skipping remaining tests to prevent hanging'
61 test_expect_success
'No confirm with --suppress-cc' '
62 test_no_confirm --suppress-cc=sob
66 test_expect_success
'No confirm with --confirm=never' '
67 test_no_confirm --confirm=never
71 # leave sendemail.confirm set to never after this so that none of the
72 # remaining tests prompt unintentionally.
73 test_expect_success
'No confirm with sendemail.confirm=never' '
74 git config sendemail.confirm never &&
75 test_no_confirm --compose --subject=foo
79 test_expect_success
'Send patches' '
80 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
90 'Verify commandline' \
91 'test_cmp expected commandline1'
93 cat >expected-show-all-headers
<<\EOF
95 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
96 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
97 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
99 Server
: relay.example.com
100 MAIL FROM
:<from@example.com
>
101 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<bcc@example.com
>
102 From
: Example
<from@example.com
>
104 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
105 Subject
: [PATCH
1/1] Second.
107 Message-Id
: MESSAGE-ID-STRING
108 X-Mailer
: X-MAILER-STRING
109 In-Reply-To
: <unique-message-id@example.com
>
110 References
: <unique-message-id@example.com
>
115 test_expect_success
'Show all headers' '
119 --from="Example <from@example.com>" \
120 --to=to@example.com \
121 --cc=cc@example.com \
122 --bcc=bcc@example.com \
123 --in-reply-to="<unique-message-id@example.com>" \
124 --smtp-server relay.example.com \
126 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
127 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
128 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
129 >actual-show-all-headers &&
130 test_cmp expected-show-all-headers actual-show-all-headers
134 z64
=$z8$z8$z8$z8$z8$z8$z8$z8
135 z512
=$z64$z64$z64$z64$z64$z64$z64$z64
136 test_expect_success
'reject long lines' '
137 clean_fake_sendmail &&
138 cp $patches longline.patch &&
139 echo $z512$z512 >>longline.patch &&
140 test_must_fail git send-email \
141 --from="Example <nobody@example.com>" \
142 --to=nobody@example.com \
143 --smtp-server="$(pwd)/fake.sendmail" \
144 $patches longline.patch \
146 grep longline.patch errors
149 test_expect_success
'no patch was sent' '
150 ! test -e commandline1
153 test_expect_success
'Author From: in message body' '
154 clean_fake_sendmail &&
156 --from="Example <nobody@example.com>" \
157 --to=nobody@example.com \
158 --smtp-server="$(pwd)/fake.sendmail" \
160 sed "1,/^$/d" < msgtxt1 > msgbody1
161 grep "From: A <author@example.com>" msgbody1
164 test_expect_success
'Author From: not in message body' '
165 clean_fake_sendmail &&
167 --from="A <author@example.com>" \
168 --to=nobody@example.com \
169 --smtp-server="$(pwd)/fake.sendmail" \
171 sed "1,/^$/d" < msgtxt1 > msgbody1
172 ! grep "From: A <author@example.com>" msgbody1
175 test_expect_success
'allow long lines with --no-validate' '
177 --from="Example <nobody@example.com>" \
178 --to=nobody@example.com \
179 --smtp-server="$(pwd)/fake.sendmail" \
181 $patches longline.patch \
185 test_expect_success
'Invalid In-Reply-To' '
186 clean_fake_sendmail &&
188 --from="Example <nobody@example.com>" \
189 --to=nobody@example.com \
191 --smtp-server="$(pwd)/fake.sendmail" \
194 ! grep "^In-Reply-To: < *>" msgtxt1
197 test_expect_success
'Valid In-Reply-To when prompting' '
198 clean_fake_sendmail &&
199 (echo "From Example <from@example.com>"
200 echo "To Example <to@example.com>"
202 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
203 --smtp-server="$(pwd)/fake.sendmail" \
205 ! grep "^In-Reply-To: < *>" msgtxt1
208 test_expect_success
'setup fake editor' '
209 (echo "#!$SHELL_PATH" &&
210 echo "echo fake edit >>\"\$1\""
215 test_set_editor
"$(pwd)/fake-editor"
217 test_expect_success
'--compose works' '
218 clean_fake_sendmail &&
220 --compose --subject foo \
221 --from="Example <nobody@example.com>" \
222 --to=nobody@example.com \
223 --smtp-server="$(pwd)/fake.sendmail" \
228 test_expect_success
'first message is compose text' '
229 grep "^fake edit" msgtxt1
232 test_expect_success
'second message is patch' '
233 grep "Subject:.*Second" msgtxt2
236 cat >expected-suppress-sob
<<\EOF
238 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
239 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
240 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
242 Server
: relay.example.com
243 MAIL FROM
:<from@example.com
>
244 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
245 From
: Example
<from@example.com
>
247 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
248 Subject
: [PATCH
1/1] Second.
250 Message-Id
: MESSAGE-ID-STRING
251 X-Mailer
: X-MAILER-STRING
256 test_suppression
() {
260 --from="Example <from@example.com>" \
261 --to=to@example.com \
262 --smtp-server relay.example.com \
264 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
265 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
266 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
267 >actual-suppress-
$1 &&
268 test_cmp expected-suppress-
$1 actual-suppress-
$1
271 test_expect_success
'sendemail.cc set' '
272 git config sendemail.cc cc@example.com &&
276 cat >expected-suppress-sob
<<\EOF
278 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
279 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
280 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
282 Server
: relay.example.com
283 MAIL FROM
:<from@example.com
>
284 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
285 From
: Example
<from@example.com
>
287 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
288 Subject
: [PATCH
1/1] Second.
290 Message-Id
: MESSAGE-ID-STRING
291 X-Mailer
: X-MAILER-STRING
296 test_expect_success
'sendemail.cc unset' '
297 git config --unset sendemail.cc &&
301 cat >expected-suppress-all
<<\EOF
304 Server
: relay.example.com
305 MAIL FROM
:<from@example.com
>
306 RCPT TO
:<to@example.com
>
307 From
: Example
<from@example.com
>
309 Subject
: [PATCH
1/1] Second.
311 Message-Id
: MESSAGE-ID-STRING
312 X-Mailer
: X-MAILER-STRING
317 test_expect_success
'--suppress-cc=all' '
321 cat >expected-suppress-body
<<\EOF
323 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
324 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
325 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
327 Server
: relay.example.com
328 MAIL FROM
:<from@example.com
>
329 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
330 From
: Example
<from@example.com
>
332 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
333 Subject
: [PATCH
1/1] Second.
335 Message-Id
: MESSAGE-ID-STRING
336 X-Mailer
: X-MAILER-STRING
341 test_expect_success
'--suppress-cc=body' '
342 test_suppression body
345 cat >expected-suppress-sob
<<\EOF
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'
351 Server
: relay.example.com
352 MAIL FROM
:<from@example.com
>
353 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
354 From
: Example
<from@example.com
>
356 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
357 Subject
: [PATCH
1/1] Second.
359 Message-Id
: MESSAGE-ID-STRING
360 X-Mailer
: X-MAILER-STRING
365 test_expect_success
'--suppress-cc=sob' '
369 cat >expected-suppress-bodycc
<<\EOF
371 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
372 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
373 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
374 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
376 Server
: relay.example.com
377 MAIL FROM
:<from@example.com
>
378 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
379 From
: Example
<from@example.com
>
381 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
382 Subject
: [PATCH
1/1] Second.
384 Message-Id
: MESSAGE-ID-STRING
385 X-Mailer
: X-MAILER-STRING
390 test_expect_success
'--suppress-cc=bodycc' '
391 test_suppression bodycc
394 cat >expected-suppress-cc
<<\EOF
396 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
397 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
399 Server
: relay.example.com
400 MAIL FROM
:<from@example.com
>
401 RCPT TO
:<to@example.com
>,<author@example.com
>,<committer@example.com
>
402 From
: Example
<from@example.com
>
404 Cc
: A
<author@example.com
>, C O Mitter
<committer@example.com
>
405 Subject
: [PATCH
1/1] Second.
407 Message-Id
: MESSAGE-ID-STRING
408 X-Mailer
: X-MAILER-STRING
413 test_expect_success
'--suppress-cc=cc' '
419 GIT_SEND_EMAIL_NOTTY
=1 \
421 --from="Example <nobody@example.com>" \
422 --to=nobody@example.com \
423 --smtp-server="$(pwd)/fake.sendmail" \
425 $patches |
grep "Send this email"
428 test_expect_success
'--confirm=always' '
429 test_confirm --confirm=always --suppress-cc=all
432 test_expect_success
'--confirm=auto' '
433 test_confirm --confirm=auto
436 test_expect_success
'--confirm=cc' '
437 test_confirm --confirm=cc
440 test_expect_success
'--confirm=compose' '
441 test_confirm --confirm=compose --compose
444 test_expect_success
'confirm by default (due to cc)' '
445 CONFIRM=$(git config --get sendemail.confirm) &&
446 git config --unset sendemail.confirm &&
448 git config sendemail.confirm $CONFIRM
451 test_expect_success
'confirm by default (due to --compose)' '
452 CONFIRM=$(git config --get sendemail.confirm) &&
453 git config --unset sendemail.confirm &&
454 test_confirm --suppress-cc=all --compose
456 git config sendemail.confirm ${CONFIRM:-never}
460 test_expect_success
'--compose adds MIME for utf8 body' '
461 clean_fake_sendmail &&
462 (echo "#!$SHELL_PATH" &&
463 echo "echo utf8 body: àéìöú >>\"\$1\""
464 ) >fake-editor-utf8 &&
465 chmod +x fake-editor-utf8 &&
466 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
468 --compose --subject foo \
469 --from="Example <nobody@example.com>" \
470 --to=nobody@example.com \
471 --smtp-server="$(pwd)/fake.sendmail" \
473 grep "^utf8 body" msgtxt1 &&
474 grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
477 test_expect_success
'--compose respects user mime type' '
478 clean_fake_sendmail &&
479 (echo "#!$SHELL_PATH" &&
480 echo "(echo MIME-Version: 1.0"
481 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
482 echo " echo Content-Transfer-Encoding: 8bit"
483 echo " echo Subject: foo"
485 echo " echo utf8 body: àéìöú) >\"\$1\""
486 ) >fake-editor-utf8-mime &&
487 chmod +x fake-editor-utf8-mime &&
488 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
490 --compose --subject foo \
491 --from="Example <nobody@example.com>" \
492 --to=nobody@example.com \
493 --smtp-server="$(pwd)/fake.sendmail" \
495 grep "^utf8 body" msgtxt1 &&
496 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
497 ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
500 test_expect_success
'--compose adds MIME for utf8 subject' '
501 clean_fake_sendmail &&
502 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
504 --compose --subject utf8-sübjëct \
505 --from="Example <nobody@example.com>" \
506 --to=nobody@example.com \
507 --smtp-server="$(pwd)/fake.sendmail" \
509 grep "^fake edit" msgtxt1 &&
510 grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
513 test_expect_success
'detects ambiguous reference/file conflict' '
514 echo master > master &&
516 git commit -m"add master" &&
517 test_must_fail git send-email --dry-run master 2>errors &&
518 grep disambiguate errors
521 test_expect_success
'feed two files' '
523 git format-patch -2 -o outdir &&
526 --from="Example <nobody@example.com>" \
527 --to=nobody@example.com \
528 outdir/000?-*.patch 2>errors >out &&
529 grep "^Subject: " out >subjects &&
530 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
531 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"