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_expect_success
'Send patches' '
39 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
49 'Verify commandline' \
50 'diff commandline1 expected'
52 cat >expected-show-all-headers
<<\EOF
54 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
55 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
56 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
58 Server
: relay.example.com
59 MAIL FROM
:<from@example.com
>
60 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<bcc@example.com
>
61 From
: Example
<from@example.com
>
63 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
64 Subject
: [PATCH
1/1] Second.
66 Message-Id
: MESSAGE-ID-STRING
67 X-Mailer
: X-MAILER-STRING
68 In-Reply-To
: <unique-message-id@example.com
>
69 References
: <unique-message-id@example.com
>
74 test_expect_success
'Show all headers' '
78 --from="Example <from@example.com>" \
81 --bcc=bcc@example.com \
82 --in-reply-to="<unique-message-id@example.com>" \
83 --smtp-server relay.example.com \
85 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
86 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
87 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
88 >actual-show-all-headers &&
89 test_cmp expected-show-all-headers actual-show-all-headers
93 z64
=$z8$z8$z8$z8$z8$z8$z8$z8
94 z512
=$z64$z64$z64$z64$z64$z64$z64$z64
95 test_expect_success
'reject long lines' '
96 clean_fake_sendmail &&
97 cp $patches longline.patch &&
98 echo $z512$z512 >>longline.patch &&
99 test_must_fail git send-email \
100 --from="Example <nobody@example.com>" \
101 --to=nobody@example.com \
102 --smtp-server="$(pwd)/fake.sendmail" \
103 $patches longline.patch \
105 grep longline.patch errors
108 test_expect_success
'no patch was sent' '
109 ! test -e commandline1
112 test_expect_success
'Author From: in message body' '
113 clean_fake_sendmail &&
115 --from="Example <nobody@example.com>" \
116 --to=nobody@example.com \
117 --smtp-server="$(pwd)/fake.sendmail" \
119 sed "1,/^$/d" < msgtxt1 > msgbody1
120 grep "From: A <author@example.com>" msgbody1
123 test_expect_success
'Author From: not in message body' '
124 clean_fake_sendmail &&
126 --from="A <author@example.com>" \
127 --to=nobody@example.com \
128 --smtp-server="$(pwd)/fake.sendmail" \
130 sed "1,/^$/d" < msgtxt1 > msgbody1
131 ! grep "From: A <author@example.com>" msgbody1
134 test_expect_success
'allow long lines with --no-validate' '
136 --from="Example <nobody@example.com>" \
137 --to=nobody@example.com \
138 --smtp-server="$(pwd)/fake.sendmail" \
140 $patches longline.patch \
144 test_expect_success
'Invalid In-Reply-To' '
145 clean_fake_sendmail &&
147 --from="Example <nobody@example.com>" \
148 --to=nobody@example.com \
150 --smtp-server="$(pwd)/fake.sendmail" \
153 ! grep "^In-Reply-To: < *>" msgtxt1
156 test_expect_success
'Valid In-Reply-To when prompting' '
157 clean_fake_sendmail &&
158 (echo "From Example <from@example.com>"
159 echo "To Example <to@example.com>"
161 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
162 --smtp-server="$(pwd)/fake.sendmail" \
164 ! grep "^In-Reply-To: < *>" msgtxt1
167 test_expect_success
'setup fake editor' '
168 (echo "#!$SHELL_PATH" &&
169 echo "echo fake edit >>\"\$1\""
174 test_set_editor
"$(pwd)/fake-editor"
176 test_expect_success
'--compose works' '
177 clean_fake_sendmail &&
179 GIT_SEND_EMAIL_NOTTY=1 \
181 --compose --subject foo \
182 --from="Example <nobody@example.com>" \
183 --to=nobody@example.com \
184 --smtp-server="$(pwd)/fake.sendmail" \
189 test_expect_success
'first message is compose text' '
190 grep "^fake edit" msgtxt1
193 test_expect_success
'second message is patch' '
194 grep "Subject:.*Second" msgtxt2
197 cat >expected-suppress-sob
<<\EOF
199 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
200 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
201 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
203 Server
: relay.example.com
204 MAIL FROM
:<from@example.com
>
205 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
206 From
: Example
<from@example.com
>
208 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
209 Subject
: [PATCH
1/1] Second.
211 Message-Id
: MESSAGE-ID-STRING
212 X-Mailer
: X-MAILER-STRING
217 test_suppression
() {
221 --from="Example <from@example.com>" \
222 --to=to@example.com \
223 --smtp-server relay.example.com \
225 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
226 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
227 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
228 >actual-suppress-
$1 &&
229 test_cmp expected-suppress-
$1 actual-suppress-
$1
232 test_expect_success
'sendemail.cc set' '
233 git config sendemail.cc cc@example.com &&
237 cat >expected-suppress-sob
<<\EOF
239 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
240 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
241 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
243 Server
: relay.example.com
244 MAIL FROM
:<from@example.com
>
245 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
246 From
: Example
<from@example.com
>
248 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
249 Subject
: [PATCH
1/1] Second.
251 Message-Id
: MESSAGE-ID-STRING
252 X-Mailer
: X-MAILER-STRING
257 test_expect_success
'sendemail.cc unset' '
258 git config --unset sendemail.cc &&
262 cat >expected-suppress-all
<<\EOF
265 Server
: relay.example.com
266 MAIL FROM
:<from@example.com
>
267 RCPT TO
:<to@example.com
>
268 From
: Example
<from@example.com
>
270 Subject
: [PATCH
1/1] Second.
272 Message-Id
: MESSAGE-ID-STRING
273 X-Mailer
: X-MAILER-STRING
278 test_expect_success
'--suppress-cc=all' '
282 cat >expected-suppress-body
<<\EOF
284 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
285 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
286 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
288 Server
: relay.example.com
289 MAIL FROM
:<from@example.com
>
290 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
291 From
: Example
<from@example.com
>
293 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
294 Subject
: [PATCH
1/1] Second.
296 Message-Id
: MESSAGE-ID-STRING
297 X-Mailer
: X-MAILER-STRING
302 test_expect_success
'--suppress-cc=body' '
303 test_suppression body
306 cat >expected-suppress-sob
<<\EOF
308 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
309 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
310 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
312 Server
: relay.example.com
313 MAIL FROM
:<from@example.com
>
314 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
315 From
: Example
<from@example.com
>
317 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
318 Subject
: [PATCH
1/1] Second.
320 Message-Id
: MESSAGE-ID-STRING
321 X-Mailer
: X-MAILER-STRING
326 test_expect_success
'--suppress-cc=sob' '
330 cat >expected-suppress-bodycc
<<\EOF
332 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
333 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
334 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
335 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
337 Server
: relay.example.com
338 MAIL FROM
:<from@example.com
>
339 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>,<committer@example.com
>
340 From
: Example
<from@example.com
>
342 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
, C O Mitter
<committer@example.com
>
343 Subject
: [PATCH
1/1] Second.
345 Message-Id
: MESSAGE-ID-STRING
346 X-Mailer
: X-MAILER-STRING
351 test_expect_success
'--suppress-cc=bodycc' '
352 test_suppression bodycc
355 cat >expected-suppress-cc
<<\EOF
357 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
358 (body
) Adding cc
: C O Mitter
<committer@example.com
> from line
'Signed-off-by: C O Mitter <committer@example.com>'
360 Server
: relay.example.com
361 MAIL FROM
:<from@example.com
>
362 RCPT TO
:<to@example.com
>,<author@example.com
>,<committer@example.com
>
363 From
: Example
<from@example.com
>
365 Cc
: A
<author@example.com
>, C O Mitter
<committer@example.com
>
366 Subject
: [PATCH
1/1] Second.
368 Message-Id
: MESSAGE-ID-STRING
369 X-Mailer
: X-MAILER-STRING
374 test_expect_success
'--suppress-cc=cc' '
378 test_expect_success
'--compose adds MIME for utf8 body' '
379 clean_fake_sendmail &&
380 (echo "#!$SHELL_PATH" &&
381 echo "echo utf8 body: àéìöú >>\"\$1\""
382 ) >fake-editor-utf8 &&
383 chmod +x fake-editor-utf8 &&
385 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
386 GIT_SEND_EMAIL_NOTTY=1 \
388 --compose --subject foo \
389 --from="Example <nobody@example.com>" \
390 --to=nobody@example.com \
391 --smtp-server="$(pwd)/fake.sendmail" \
393 grep "^utf8 body" msgtxt1 &&
394 grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
397 test_expect_success
'--compose respects user mime type' '
398 clean_fake_sendmail &&
399 (echo "#!$SHELL_PATH" &&
400 echo "(echo MIME-Version: 1.0"
401 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
402 echo " echo Content-Transfer-Encoding: 8bit"
403 echo " echo Subject: foo"
405 echo " echo utf8 body: àéìöú) >\"\$1\""
406 ) >fake-editor-utf8-mime &&
407 chmod +x fake-editor-utf8-mime &&
409 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
410 GIT_SEND_EMAIL_NOTTY=1 \
412 --compose --subject foo \
413 --from="Example <nobody@example.com>" \
414 --to=nobody@example.com \
415 --smtp-server="$(pwd)/fake.sendmail" \
417 grep "^utf8 body" msgtxt1 &&
418 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
419 ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
422 test_expect_success
'--compose adds MIME for utf8 subject' '
423 clean_fake_sendmail &&
425 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
426 GIT_SEND_EMAIL_NOTTY=1 \
428 --compose --subject utf8-sübjëct \
429 --from="Example <nobody@example.com>" \
430 --to=nobody@example.com \
431 --smtp-server="$(pwd)/fake.sendmail" \
433 grep "^fake edit" msgtxt1 &&
434 grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
437 test_expect_success
'detects ambiguous reference/file conflict' '
438 echo master > master &&
440 git commit -m"add master" &&
441 test_must_fail git send-email --dry-run master 2>errors &&
442 grep disambiguate errors
445 test_expect_success
'feed two files' '
447 git format-patch -2 -o outdir &&
448 GIT_SEND_EMAIL_NOTTY=1 git send-email \
450 --from="Example <nobody@example.com>" \
451 --to=nobody@example.com \
452 outdir/000?-*.patch 2>errors >out &&
453 grep "^Subject: " out >subjects &&
454 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
455 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
458 test_expect_success
'in-reply-to but no threading' '
461 --from="Example <nobody@example.com>" \
462 --to=nobody@example.com \
463 --in-reply-to="<in-reply-id@example.com>" \
466 grep "In-Reply-To: <in-reply-id@example.com>"