]>
Commit | Line | Data |
---|---|---|
ce903018 RA |
1 | #!/bin/sh |
2 | ||
47a528ad | 3 | test_description='git send-email' |
ce903018 RA |
4 | . ./test-lib.sh |
5 | ||
57cd35e6 ÆAB |
6 | # May be altered later in the test |
7 | PREREQ="PERL" | |
1b19ccd2 | 8 | |
57cd35e6 | 9 | test_expect_success $PREREQ \ |
ce903018 RA |
10 | 'prepare reference tree' \ |
11 | 'echo "1A quick brown fox jumps over the" >file && | |
12 | echo "lazy dog" >>file && | |
c0d45281 | 13 | git add file && |
ce903018 RA |
14 | GIT_AUTHOR_NAME="A" git commit -a -m "Initial."' |
15 | ||
57cd35e6 | 16 | test_expect_success $PREREQ \ |
ce903018 | 17 | 'Setup helper tool' \ |
bb3e4f03 | 18 | '(echo "#!$SHELL_PATH" |
2186d566 | 19 | echo shift |
6d34a2ba JK |
20 | echo output=1 |
21 | echo "while test -f commandline\$output; do output=\$((\$output+1)); done" | |
2186d566 JH |
22 | echo for a |
23 | echo do | |
24 | echo " echo \"!\$a!\"" | |
6d34a2ba | 25 | echo "done >commandline\$output" |
72b5158b | 26 | test_have_prereq MINGW && echo "dos2unix commandline\$output" |
6d34a2ba | 27 | echo "cat > msgtxt\$output" |
c0d45281 JK |
28 | ) >fake.sendmail && |
29 | chmod +x ./fake.sendmail && | |
30 | git add fake.sendmail && | |
ce903018 RA |
31 | GIT_AUTHOR_NAME="A" git commit -a -m "Second."' |
32 | ||
6d34a2ba JK |
33 | clean_fake_sendmail() { |
34 | rm -f commandline* msgtxt* | |
35 | } | |
36 | ||
57cd35e6 | 37 | test_expect_success $PREREQ 'Extract patches' ' |
3531e270 | 38 | patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1` |
280242d1 JH |
39 | ' |
40 | ||
c1f2aa45 JS |
41 | # Test no confirm early to ensure remaining tests will not hang |
42 | test_no_confirm () { | |
43 | rm -f no_confirm_okay | |
44 | echo n | \ | |
45 | GIT_SEND_EMAIL_NOTTY=1 \ | |
46 | git send-email \ | |
47 | --from="Example <from@example.com>" \ | |
48 | --to=nobody@example.com \ | |
49 | --smtp-server="$(pwd)/fake.sendmail" \ | |
50 | $@ \ | |
51 | $patches > stdout && | |
52 | test_must_fail grep "Send this email" stdout && | |
53 | > no_confirm_okay | |
54 | } | |
55 | ||
56 | # Exit immediately to prevent hang if a no-confirm test fails | |
57 | check_no_confirm () { | |
57cd35e6 ÆAB |
58 | if ! test -f no_confirm_okay |
59 | then | |
60 | say 'confirm test failed; skipping remaining tests to prevent hanging' | |
61 | PREREQ="$PREREQ,CHECK_NO_CONFIRM" | |
62 | fi | |
63 | return 0 | |
c1f2aa45 JS |
64 | } |
65 | ||
57cd35e6 ÆAB |
66 | test_expect_success $PREREQ 'No confirm with --suppress-cc' ' |
67 | test_no_confirm --suppress-cc=sob && | |
68 | check_no_confirm | |
c1f2aa45 | 69 | ' |
c1f2aa45 | 70 | |
57cd35e6 ÆAB |
71 | |
72 | test_expect_success $PREREQ 'No confirm with --confirm=never' ' | |
73 | test_no_confirm --confirm=never && | |
74 | check_no_confirm | |
c1f2aa45 | 75 | ' |
c1f2aa45 JS |
76 | |
77 | # leave sendemail.confirm set to never after this so that none of the | |
78 | # remaining tests prompt unintentionally. | |
57cd35e6 | 79 | test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' ' |
c1f2aa45 | 80 | git config sendemail.confirm never && |
57cd35e6 ÆAB |
81 | test_no_confirm --compose --subject=foo && |
82 | check_no_confirm | |
c1f2aa45 | 83 | ' |
c1f2aa45 | 84 | |
57cd35e6 | 85 | test_expect_success $PREREQ 'Send patches' ' |
3531e270 | 86 | git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors |
280242d1 | 87 | ' |
ce903018 | 88 | |
f9444147 | 89 | test_expect_success $PREREQ 'setup expect' ' |
2186d566 JH |
90 | cat >expected <<\EOF |
91 | !nobody@example.com! | |
92 | !author@example.com! | |
5012699d JS |
93 | !one@example.com! |
94 | !two@example.com! | |
2186d566 | 95 | EOF |
f9444147 ÆAB |
96 | ' |
97 | ||
57cd35e6 | 98 | test_expect_success $PREREQ \ |
ce903018 | 99 | 'Verify commandline' \ |
188c3827 | 100 | 'test_cmp expected commandline1' |
ce903018 | 101 | |
57cd35e6 | 102 | test_expect_success $PREREQ 'Send patches with --envelope-sender' ' |
4f333bc1 | 103 | clean_fake_sendmail && |
41ccfdd9 | 104 | 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 |
4f333bc1 JH |
105 | ' |
106 | ||
f9444147 | 107 | test_expect_success $PREREQ 'setup expect' ' |
4f333bc1 JH |
108 | cat >expected <<\EOF |
109 | !patch@example.com! | |
110 | !-i! | |
111 | !nobody@example.com! | |
112 | !author@example.com! | |
113 | !one@example.com! | |
114 | !two@example.com! | |
115 | EOF | |
f9444147 ÆAB |
116 | ' |
117 | ||
57cd35e6 | 118 | test_expect_success $PREREQ \ |
4f333bc1 JH |
119 | 'Verify commandline' \ |
120 | 'test_cmp expected commandline1' | |
121 | ||
57cd35e6 | 122 | test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' ' |
c89e3241 FC |
123 | clean_fake_sendmail && |
124 | 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 | |
125 | ' | |
126 | ||
f9444147 | 127 | test_expect_success $PREREQ 'setup expect' ' |
c89e3241 FC |
128 | cat >expected <<\EOF |
129 | !nobody@example.com! | |
130 | !-i! | |
131 | !nobody@example.com! | |
132 | !author@example.com! | |
133 | !one@example.com! | |
134 | !two@example.com! | |
135 | EOF | |
f9444147 ÆAB |
136 | ' |
137 | ||
57cd35e6 | 138 | test_expect_success $PREREQ \ |
c89e3241 FC |
139 | 'Verify commandline' \ |
140 | 'test_cmp expected commandline1' | |
141 | ||
f9444147 | 142 | test_expect_success $PREREQ 'setup expect' " |
b7f30e0a DK |
143 | cat >expected-show-all-headers <<\EOF |
144 | 0001-Second.patch | |
145 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
5012699d JS |
146 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
147 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
b7f30e0a DK |
148 | Dry-OK. Log says: |
149 | Server: relay.example.com | |
150 | MAIL FROM:<from@example.com> | |
02461e0e JP |
151 | RCPT TO:<to@example.com> |
152 | RCPT TO:<cc@example.com> | |
153 | RCPT TO:<author@example.com> | |
154 | RCPT TO:<one@example.com> | |
155 | RCPT TO:<two@example.com> | |
156 | RCPT TO:<bcc@example.com> | |
b7f30e0a DK |
157 | From: Example <from@example.com> |
158 | To: to@example.com | |
02461e0e JP |
159 | Cc: cc@example.com, |
160 | A <author@example.com>, | |
161 | One <one@example.com>, | |
162 | two@example.com | |
b7f30e0a DK |
163 | Subject: [PATCH 1/1] Second. |
164 | Date: DATE-STRING | |
165 | Message-Id: MESSAGE-ID-STRING | |
166 | X-Mailer: X-MAILER-STRING | |
167 | In-Reply-To: <unique-message-id@example.com> | |
168 | References: <unique-message-id@example.com> | |
169 | ||
170 | Result: OK | |
171 | EOF | |
f9444147 | 172 | " |
b7f30e0a | 173 | |
5adcf2c6 MT |
174 | test_suppress_self () { |
175 | test_commit $3 && | |
176 | test_when_finished "git reset --hard HEAD^" && | |
177 | ||
178 | write_script cccmd-sed <<-EOF && | |
179 | sed -n -e s/^cccmd--//p "\$1" | |
180 | EOF | |
181 | ||
182 | git commit --amend --author="$1 <$2>" -F - && | |
183 | clean_fake_sendmail && | |
184 | git format-patch --stdout -1 >"suppress-self-$3.patch" && | |
185 | ||
186 | git send-email --from="$1 <$2>" \ | |
187 | --to=nobody@example.com \ | |
188 | --cc-cmd=./cccmd-sed \ | |
189 | --suppress-cc=self \ | |
190 | --smtp-server="$(pwd)/fake.sendmail" \ | |
191 | suppress-self-$3.patch && | |
192 | ||
193 | mv msgtxt1 msgtxt1-$3 && | |
194 | sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" && | |
195 | >"expected-no-cc-$3" && | |
196 | ||
197 | (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3"; | |
198 | test_cmp expected-no-cc-$3 actual-no-cc-$3) | |
199 | } | |
200 | ||
201 | test_suppress_self_unquoted () { | |
202 | test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF | |
203 | test suppress-cc.self unquoted-$3 with name $1 email $2 | |
204 | ||
205 | unquoted-$3 | |
206 | ||
d6ee4456 MT |
207 | cccmd--$1 <$2> |
208 | ||
5adcf2c6 MT |
209 | Cc: $1 <$2> |
210 | Signed-off-by: $1 <$2> | |
211 | EOF | |
212 | } | |
213 | ||
dd29f0b4 MT |
214 | test_suppress_self_quoted () { |
215 | test_suppress_self "$1" "$2" "quoted-$3" <<-EOF | |
216 | test suppress-cc.self quoted-$3 with name $1 email $2 | |
217 | ||
218 | quoted-$3 | |
219 | ||
220 | cccmd--"$1" <$2> | |
221 | ||
222 | Cc: $1 <$2> | |
223 | Cc: "$1" <$2> | |
224 | Signed-off-by: $1 <$2> | |
225 | Signed-off-by: "$1" <$2> | |
226 | EOF | |
227 | } | |
228 | ||
5adcf2c6 | 229 | test_expect_success $PREREQ 'self name is suppressed' " |
d6ee4456 | 230 | test_suppress_self_unquoted 'A U Thor' 'author@example.com' \ |
5adcf2c6 MT |
231 | 'self_name_suppressed' |
232 | " | |
233 | ||
dd29f0b4 MT |
234 | test_expect_success $PREREQ 'self name with dot is suppressed' " |
235 | test_suppress_self_quoted 'A U. Thor' 'author@example.com' \ | |
236 | 'self_name_dot_suppressed' | |
237 | " | |
238 | ||
4b45bcf7 MT |
239 | test_expect_success $PREREQ 'non-ascii self name is suppressed' " |
240 | test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \ | |
241 | 'non_ascii_self_suppressed' | |
242 | " | |
243 | ||
14952666 MT |
244 | test_expect_success $PREREQ 'sanitized self name is suppressed' " |
245 | test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \ | |
246 | 'self_name_sanitized_suppressed' | |
247 | " | |
248 | ||
57cd35e6 | 249 | test_expect_success $PREREQ 'Show all headers' ' |
b7f30e0a DK |
250 | git send-email \ |
251 | --dry-run \ | |
3531e270 | 252 | --suppress-cc=sob \ |
b7f30e0a DK |
253 | --from="Example <from@example.com>" \ |
254 | --to=to@example.com \ | |
255 | --cc=cc@example.com \ | |
256 | --bcc=bcc@example.com \ | |
257 | --in-reply-to="<unique-message-id@example.com>" \ | |
258 | --smtp-server relay.example.com \ | |
259 | $patches | | |
260 | sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ | |
261 | -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ | |
262 | -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ | |
263 | >actual-show-all-headers && | |
82ebb0b6 | 264 | test_cmp expected-show-all-headers actual-show-all-headers |
b7f30e0a DK |
265 | ' |
266 | ||
57cd35e6 | 267 | test_expect_success $PREREQ 'Prompting works' ' |
0da43a68 | 268 | clean_fake_sendmail && |
8cac13dc | 269 | (echo "to@example.com" |
0da43a68 JS |
270 | echo "" |
271 | ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
272 | --smtp-server="$(pwd)/fake.sendmail" \ | |
273 | $patches \ | |
274 | 2>errors && | |
8cac13dc | 275 | grep "^From: A U Thor <author@example.com>\$" msgtxt1 && |
9524cf29 | 276 | grep "^To: to@example.com\$" msgtxt1 |
0da43a68 JS |
277 | ' |
278 | ||
59defcc3 JK |
279 | test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' ' |
280 | clean_fake_sendmail && | |
281 | (sane_unset GIT_AUTHOR_NAME && | |
282 | sane_unset GIT_AUTHOR_EMAIL && | |
283 | sane_unset GIT_COMMITTER_NAME && | |
284 | sane_unset GIT_COMMITTER_EMAIL && | |
285 | GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
286 | --smtp-server="$(pwd)/fake.sendmail" \ | |
287 | --to=to@example.com \ | |
288 | $patches </dev/null 2>errors | |
289 | ) | |
290 | ' | |
291 | ||
292 | test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' ' | |
293 | clean_fake_sendmail && | |
294 | (sane_unset GIT_AUTHOR_NAME && | |
295 | sane_unset GIT_AUTHOR_EMAIL && | |
296 | sane_unset GIT_COMMITTER_NAME && | |
297 | sane_unset GIT_COMMITTER_EMAIL && | |
298 | GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY && | |
299 | test_must_fail git send-email \ | |
300 | --smtp-server="$(pwd)/fake.sendmail" \ | |
301 | --to=to@example.com \ | |
302 | $patches </dev/null 2>errors && | |
303 | test_i18ngrep "tell me who you are" errors | |
304 | ) | |
305 | ' | |
306 | ||
6e74e075 JP |
307 | test_expect_success $PREREQ 'tocmd works' ' |
308 | clean_fake_sendmail && | |
309 | cp $patches tocmd.patch && | |
310 | echo tocmd--tocmd@example.com >>tocmd.patch && | |
311 | { | |
312 | echo "#!$SHELL_PATH" | |
313 | echo sed -n -e s/^tocmd--//p \"\$1\" | |
314 | } > tocmd-sed && | |
315 | chmod +x tocmd-sed && | |
316 | git send-email \ | |
317 | --from="Example <nobody@example.com>" \ | |
318 | --to-cmd=./tocmd-sed \ | |
319 | --smtp-server="$(pwd)/fake.sendmail" \ | |
320 | tocmd.patch \ | |
321 | && | |
322 | grep "^To: tocmd@example.com" msgtxt1 | |
323 | ' | |
324 | ||
57cd35e6 | 325 | test_expect_success $PREREQ 'cccmd works' ' |
cb8a9bd5 PB |
326 | clean_fake_sendmail && |
327 | cp $patches cccmd.patch && | |
41ae8f1d | 328 | echo "cccmd-- cccmd@example.com" >>cccmd.patch && |
977e289e BC |
329 | { |
330 | echo "#!$SHELL_PATH" | |
331 | echo sed -n -e s/^cccmd--//p \"\$1\" | |
332 | } > cccmd-sed && | |
cb8a9bd5 PB |
333 | chmod +x cccmd-sed && |
334 | git send-email \ | |
335 | --from="Example <nobody@example.com>" \ | |
336 | --to=nobody@example.com \ | |
337 | --cc-cmd=./cccmd-sed \ | |
338 | --smtp-server="$(pwd)/fake.sendmail" \ | |
339 | cccmd.patch \ | |
340 | && | |
02461e0e | 341 | grep "^ cccmd@example.com" msgtxt1 |
cb8a9bd5 PB |
342 | ' |
343 | ||
57cd35e6 | 344 | test_expect_success $PREREQ 'reject long lines' ' |
f9444147 ÆAB |
345 | z8=zzzzzzzz && |
346 | z64=$z8$z8$z8$z8$z8$z8$z8$z8 && | |
347 | z512=$z64$z64$z64$z64$z64$z64$z64$z64 && | |
6d34a2ba | 348 | clean_fake_sendmail && |
747bbff9 JK |
349 | cp $patches longline.patch && |
350 | echo $z512$z512 >>longline.patch && | |
d492b31c | 351 | test_must_fail git send-email \ |
747bbff9 JK |
352 | --from="Example <nobody@example.com>" \ |
353 | --to=nobody@example.com \ | |
354 | --smtp-server="$(pwd)/fake.sendmail" \ | |
355 | $patches longline.patch \ | |
356 | 2>errors && | |
357 | grep longline.patch errors | |
358 | ' | |
359 | ||
57cd35e6 | 360 | test_expect_success $PREREQ 'no patch was sent' ' |
6d34a2ba | 361 | ! test -e commandline1 |
747bbff9 JK |
362 | ' |
363 | ||
57cd35e6 | 364 | test_expect_success $PREREQ 'Author From: in message body' ' |
5012699d JS |
365 | clean_fake_sendmail && |
366 | git send-email \ | |
367 | --from="Example <nobody@example.com>" \ | |
368 | --to=nobody@example.com \ | |
369 | --smtp-server="$(pwd)/fake.sendmail" \ | |
370 | $patches && | |
cc7e8167 | 371 | sed "1,/^\$/d" < msgtxt1 > msgbody1 && |
5012699d JS |
372 | grep "From: A <author@example.com>" msgbody1 |
373 | ' | |
374 | ||
57cd35e6 | 375 | test_expect_success $PREREQ 'Author From: not in message body' ' |
5012699d JS |
376 | clean_fake_sendmail && |
377 | git send-email \ | |
378 | --from="A <author@example.com>" \ | |
379 | --to=nobody@example.com \ | |
380 | --smtp-server="$(pwd)/fake.sendmail" \ | |
381 | $patches && | |
cc7e8167 | 382 | sed "1,/^\$/d" < msgtxt1 > msgbody1 && |
5012699d JS |
383 | ! grep "From: A <author@example.com>" msgbody1 |
384 | ' | |
385 | ||
57cd35e6 | 386 | test_expect_success $PREREQ 'allow long lines with --no-validate' ' |
c764a0c2 JK |
387 | git send-email \ |
388 | --from="Example <nobody@example.com>" \ | |
389 | --to=nobody@example.com \ | |
390 | --smtp-server="$(pwd)/fake.sendmail" \ | |
3fee1fe8 | 391 | --novalidate \ |
c764a0c2 JK |
392 | $patches longline.patch \ |
393 | 2>errors | |
394 | ' | |
395 | ||
57cd35e6 | 396 | test_expect_success $PREREQ 'Invalid In-Reply-To' ' |
6d34a2ba | 397 | clean_fake_sendmail && |
0fb7fc75 JS |
398 | git send-email \ |
399 | --from="Example <nobody@example.com>" \ | |
400 | --to=nobody@example.com \ | |
401 | --in-reply-to=" " \ | |
402 | --smtp-server="$(pwd)/fake.sendmail" \ | |
5b57413c | 403 | $patches \ |
cc7e8167 | 404 | 2>errors && |
6d34a2ba | 405 | ! grep "^In-Reply-To: < *>" msgtxt1 |
0fb7fc75 JS |
406 | ' |
407 | ||
57cd35e6 | 408 | test_expect_success $PREREQ 'Valid In-Reply-To when prompting' ' |
6d34a2ba | 409 | clean_fake_sendmail && |
0fb7fc75 JS |
410 | (echo "From Example <from@example.com>" |
411 | echo "To Example <to@example.com>" | |
412 | echo "" | |
413 | ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
414 | --smtp-server="$(pwd)/fake.sendmail" \ | |
415 | $patches 2>errors && | |
6d34a2ba | 416 | ! grep "^In-Reply-To: < *>" msgtxt1 |
0fb7fc75 JS |
417 | ' |
418 | ||
54aae5e1 JH |
419 | test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' ' |
420 | clean_fake_sendmail && | |
421 | echo "<unique-message-id@example.com>" >expect && | |
422 | git send-email \ | |
423 | --from="Example <nobody@example.com>" \ | |
424 | --to=nobody@example.com \ | |
d2559f73 | 425 | --nochain-reply-to \ |
54aae5e1 JH |
426 | --in-reply-to="$(cat expect)" \ |
427 | --smtp-server="$(pwd)/fake.sendmail" \ | |
428 | $patches $patches $patches \ | |
429 | 2>errors && | |
db54c8e7 | 430 | # The first message is a reply to --in-reply-to |
54aae5e1 JH |
431 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && |
432 | test_cmp expect actual && | |
db54c8e7 AO |
433 | # Second and subsequent messages are replies to the first one |
434 | sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect && | |
54aae5e1 JH |
435 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && |
436 | test_cmp expect actual && | |
437 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && | |
438 | test_cmp expect actual | |
439 | ' | |
440 | ||
441 | test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' | |
442 | clean_fake_sendmail && | |
443 | echo "<unique-message-id@example.com>" >expect && | |
444 | git send-email \ | |
445 | --from="Example <nobody@example.com>" \ | |
446 | --to=nobody@example.com \ | |
447 | --chain-reply-to \ | |
448 | --in-reply-to="$(cat expect)" \ | |
449 | --smtp-server="$(pwd)/fake.sendmail" \ | |
450 | $patches $patches $patches \ | |
451 | 2>errors && | |
452 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && | |
453 | test_cmp expect actual && | |
454 | sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect && | |
455 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && | |
456 | test_cmp expect actual && | |
457 | sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect && | |
458 | sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && | |
459 | test_cmp expect actual | |
460 | ' | |
461 | ||
57cd35e6 | 462 | test_expect_success $PREREQ 'setup fake editor' ' |
bb3e4f03 | 463 | (echo "#!$SHELL_PATH" && |
065096c2 | 464 | echo "echo fake edit >>\"\$1\"" |
8a8bf469 JK |
465 | ) >fake-editor && |
466 | chmod +x fake-editor | |
467 | ' | |
468 | ||
7f0475c3 | 469 | test_set_editor "$(pwd)/fake-editor" |
065096c2 | 470 | |
57cd35e6 | 471 | test_expect_success $PREREQ '--compose works' ' |
8a8bf469 | 472 | clean_fake_sendmail && |
c1f2aa45 JS |
473 | git send-email \ |
474 | --compose --subject foo \ | |
475 | --from="Example <nobody@example.com>" \ | |
476 | --to=nobody@example.com \ | |
477 | --smtp-server="$(pwd)/fake.sendmail" \ | |
478 | $patches \ | |
479 | 2>errors | |
8a8bf469 JK |
480 | ' |
481 | ||
57cd35e6 | 482 | test_expect_success $PREREQ 'first message is compose text' ' |
8a8bf469 JK |
483 | grep "^fake edit" msgtxt1 |
484 | ' | |
485 | ||
57cd35e6 | 486 | test_expect_success $PREREQ 'second message is patch' ' |
8a8bf469 JK |
487 | grep "Subject:.*Second" msgtxt2 |
488 | ' | |
489 | ||
f9444147 | 490 | test_expect_success $PREREQ 'setup expect' " |
3531e270 | 491 | cat >expected-suppress-sob <<\EOF |
33c592dd MV |
492 | 0001-Second.patch |
493 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
5012699d JS |
494 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
495 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
33c592dd MV |
496 | Dry-OK. Log says: |
497 | Server: relay.example.com | |
498 | MAIL FROM:<from@example.com> | |
02461e0e JP |
499 | RCPT TO:<to@example.com> |
500 | RCPT TO:<cc@example.com> | |
501 | RCPT TO:<author@example.com> | |
502 | RCPT TO:<one@example.com> | |
503 | RCPT TO:<two@example.com> | |
33c592dd MV |
504 | From: Example <from@example.com> |
505 | To: to@example.com | |
02461e0e JP |
506 | Cc: cc@example.com, |
507 | A <author@example.com>, | |
508 | One <one@example.com>, | |
509 | two@example.com | |
33c592dd MV |
510 | Subject: [PATCH 1/1] Second. |
511 | Date: DATE-STRING | |
512 | Message-Id: MESSAGE-ID-STRING | |
513 | X-Mailer: X-MAILER-STRING | |
514 | ||
515 | Result: OK | |
516 | EOF | |
f9444147 | 517 | " |
33c592dd | 518 | |
3531e270 | 519 | test_suppression () { |
33c592dd MV |
520 | git send-email \ |
521 | --dry-run \ | |
cb8a9bd5 | 522 | --suppress-cc=$1 ${2+"--suppress-cc=$2"} \ |
33c592dd MV |
523 | --from="Example <from@example.com>" \ |
524 | --to=to@example.com \ | |
525 | --smtp-server relay.example.com \ | |
526 | $patches | | |
527 | sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ | |
528 | -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ | |
529 | -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ | |
cb8a9bd5 PB |
530 | >actual-suppress-$1${2+"-$2"} && |
531 | test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"} | |
3531e270 JS |
532 | } |
533 | ||
57cd35e6 | 534 | test_expect_success $PREREQ 'sendemail.cc set' ' |
3531e270 JS |
535 | git config sendemail.cc cc@example.com && |
536 | test_suppression sob | |
33c592dd MV |
537 | ' |
538 | ||
f9444147 | 539 | test_expect_success $PREREQ 'setup expect' " |
3531e270 | 540 | cat >expected-suppress-sob <<\EOF |
33c592dd MV |
541 | 0001-Second.patch |
542 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
5012699d JS |
543 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
544 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
33c592dd MV |
545 | Dry-OK. Log says: |
546 | Server: relay.example.com | |
547 | MAIL FROM:<from@example.com> | |
02461e0e JP |
548 | RCPT TO:<to@example.com> |
549 | RCPT TO:<author@example.com> | |
550 | RCPT TO:<one@example.com> | |
551 | RCPT TO:<two@example.com> | |
33c592dd MV |
552 | From: Example <from@example.com> |
553 | To: to@example.com | |
02461e0e JP |
554 | Cc: A <author@example.com>, |
555 | One <one@example.com>, | |
556 | two@example.com | |
33c592dd MV |
557 | Subject: [PATCH 1/1] Second. |
558 | Date: DATE-STRING | |
559 | Message-Id: MESSAGE-ID-STRING | |
560 | X-Mailer: X-MAILER-STRING | |
561 | ||
562 | Result: OK | |
563 | EOF | |
f9444147 | 564 | " |
33c592dd | 565 | |
57cd35e6 | 566 | test_expect_success $PREREQ 'sendemail.cc unset' ' |
33c592dd | 567 | git config --unset sendemail.cc && |
3531e270 JS |
568 | test_suppression sob |
569 | ' | |
570 | ||
f9444147 | 571 | test_expect_success $PREREQ 'setup expect' " |
cb8a9bd5 PB |
572 | cat >expected-suppress-cccmd <<\EOF |
573 | 0001-Second.patch | |
574 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
575 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
576 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
577 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
578 | Dry-OK. Log says: | |
579 | Server: relay.example.com | |
580 | MAIL FROM:<from@example.com> | |
02461e0e JP |
581 | RCPT TO:<to@example.com> |
582 | RCPT TO:<author@example.com> | |
583 | RCPT TO:<one@example.com> | |
584 | RCPT TO:<two@example.com> | |
585 | RCPT TO:<committer@example.com> | |
cb8a9bd5 PB |
586 | From: Example <from@example.com> |
587 | To: to@example.com | |
02461e0e JP |
588 | Cc: A <author@example.com>, |
589 | One <one@example.com>, | |
590 | two@example.com, | |
591 | C O Mitter <committer@example.com> | |
cb8a9bd5 PB |
592 | Subject: [PATCH 1/1] Second. |
593 | Date: DATE-STRING | |
594 | Message-Id: MESSAGE-ID-STRING | |
595 | X-Mailer: X-MAILER-STRING | |
596 | ||
597 | Result: OK | |
598 | EOF | |
f9444147 | 599 | " |
cb8a9bd5 | 600 | |
57cd35e6 | 601 | test_expect_success $PREREQ 'sendemail.cccmd' ' |
cb8a9bd5 PB |
602 | echo echo cc-cmd@example.com > cccmd && |
603 | chmod +x cccmd && | |
604 | git config sendemail.cccmd ./cccmd && | |
605 | test_suppression cccmd | |
606 | ' | |
607 | ||
f9444147 | 608 | test_expect_success $PREREQ 'setup expect' ' |
3531e270 JS |
609 | cat >expected-suppress-all <<\EOF |
610 | 0001-Second.patch | |
611 | Dry-OK. Log says: | |
612 | Server: relay.example.com | |
613 | MAIL FROM:<from@example.com> | |
614 | RCPT TO:<to@example.com> | |
615 | From: Example <from@example.com> | |
616 | To: to@example.com | |
617 | Subject: [PATCH 1/1] Second. | |
618 | Date: DATE-STRING | |
619 | Message-Id: MESSAGE-ID-STRING | |
620 | X-Mailer: X-MAILER-STRING | |
621 | ||
622 | Result: OK | |
623 | EOF | |
f9444147 | 624 | ' |
3531e270 | 625 | |
57cd35e6 | 626 | test_expect_success $PREREQ '--suppress-cc=all' ' |
3531e270 JS |
627 | test_suppression all |
628 | ' | |
629 | ||
f9444147 | 630 | test_expect_success $PREREQ 'setup expect' " |
3531e270 JS |
631 | cat >expected-suppress-body <<\EOF |
632 | 0001-Second.patch | |
633 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
634 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
635 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
cb8a9bd5 | 636 | (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd' |
3531e270 JS |
637 | Dry-OK. Log says: |
638 | Server: relay.example.com | |
639 | MAIL FROM:<from@example.com> | |
02461e0e JP |
640 | RCPT TO:<to@example.com> |
641 | RCPT TO:<author@example.com> | |
642 | RCPT TO:<one@example.com> | |
643 | RCPT TO:<two@example.com> | |
644 | RCPT TO:<cc-cmd@example.com> | |
3531e270 JS |
645 | From: Example <from@example.com> |
646 | To: to@example.com | |
02461e0e JP |
647 | Cc: A <author@example.com>, |
648 | One <one@example.com>, | |
649 | two@example.com, | |
650 | cc-cmd@example.com | |
3531e270 JS |
651 | Subject: [PATCH 1/1] Second. |
652 | Date: DATE-STRING | |
653 | Message-Id: MESSAGE-ID-STRING | |
654 | X-Mailer: X-MAILER-STRING | |
655 | ||
656 | Result: OK | |
657 | EOF | |
f9444147 | 658 | " |
3531e270 | 659 | |
57cd35e6 | 660 | test_expect_success $PREREQ '--suppress-cc=body' ' |
3531e270 JS |
661 | test_suppression body |
662 | ' | |
663 | ||
f9444147 | 664 | test_expect_success $PREREQ 'setup expect' " |
cb8a9bd5 PB |
665 | cat >expected-suppress-body-cccmd <<\EOF |
666 | 0001-Second.patch | |
667 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
668 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
669 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
670 | Dry-OK. Log says: | |
671 | Server: relay.example.com | |
672 | MAIL FROM:<from@example.com> | |
02461e0e JP |
673 | RCPT TO:<to@example.com> |
674 | RCPT TO:<author@example.com> | |
675 | RCPT TO:<one@example.com> | |
676 | RCPT TO:<two@example.com> | |
cb8a9bd5 PB |
677 | From: Example <from@example.com> |
678 | To: to@example.com | |
02461e0e JP |
679 | Cc: A <author@example.com>, |
680 | One <one@example.com>, | |
681 | two@example.com | |
cb8a9bd5 PB |
682 | Subject: [PATCH 1/1] Second. |
683 | Date: DATE-STRING | |
684 | Message-Id: MESSAGE-ID-STRING | |
685 | X-Mailer: X-MAILER-STRING | |
686 | ||
687 | Result: OK | |
688 | EOF | |
f9444147 | 689 | " |
cb8a9bd5 | 690 | |
57cd35e6 | 691 | test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' ' |
cb8a9bd5 PB |
692 | test_suppression body cccmd |
693 | ' | |
694 | ||
f9444147 | 695 | test_expect_success $PREREQ 'setup expect' " |
3531e270 JS |
696 | cat >expected-suppress-sob <<\EOF |
697 | 0001-Second.patch | |
698 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
699 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
700 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
701 | Dry-OK. Log says: | |
702 | Server: relay.example.com | |
703 | MAIL FROM:<from@example.com> | |
02461e0e JP |
704 | RCPT TO:<to@example.com> |
705 | RCPT TO:<author@example.com> | |
706 | RCPT TO:<one@example.com> | |
707 | RCPT TO:<two@example.com> | |
3531e270 JS |
708 | From: Example <from@example.com> |
709 | To: to@example.com | |
02461e0e JP |
710 | Cc: A <author@example.com>, |
711 | One <one@example.com>, | |
712 | two@example.com | |
3531e270 JS |
713 | Subject: [PATCH 1/1] Second. |
714 | Date: DATE-STRING | |
715 | Message-Id: MESSAGE-ID-STRING | |
716 | X-Mailer: X-MAILER-STRING | |
717 | ||
718 | Result: OK | |
719 | EOF | |
f9444147 | 720 | " |
3531e270 | 721 | |
57cd35e6 | 722 | test_expect_success $PREREQ '--suppress-cc=sob' ' |
cc7e8167 | 723 | test_might_fail git config --unset sendemail.cccmd && |
3531e270 JS |
724 | test_suppression sob |
725 | ' | |
726 | ||
f9444147 | 727 | test_expect_success $PREREQ 'setup expect' " |
3531e270 JS |
728 | cat >expected-suppress-bodycc <<\EOF |
729 | 0001-Second.patch | |
730 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
731 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
732 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
733 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
734 | Dry-OK. Log says: | |
735 | Server: relay.example.com | |
736 | MAIL FROM:<from@example.com> | |
02461e0e JP |
737 | RCPT TO:<to@example.com> |
738 | RCPT TO:<author@example.com> | |
739 | RCPT TO:<one@example.com> | |
740 | RCPT TO:<two@example.com> | |
741 | RCPT TO:<committer@example.com> | |
3531e270 JS |
742 | From: Example <from@example.com> |
743 | To: to@example.com | |
02461e0e JP |
744 | Cc: A <author@example.com>, |
745 | One <one@example.com>, | |
746 | two@example.com, | |
747 | C O Mitter <committer@example.com> | |
3531e270 JS |
748 | Subject: [PATCH 1/1] Second. |
749 | Date: DATE-STRING | |
750 | Message-Id: MESSAGE-ID-STRING | |
751 | X-Mailer: X-MAILER-STRING | |
752 | ||
753 | Result: OK | |
754 | EOF | |
f9444147 | 755 | " |
3531e270 | 756 | |
57cd35e6 | 757 | test_expect_success $PREREQ '--suppress-cc=bodycc' ' |
3531e270 JS |
758 | test_suppression bodycc |
759 | ' | |
760 | ||
f9444147 | 761 | test_expect_success $PREREQ 'setup expect' " |
3531e270 JS |
762 | cat >expected-suppress-cc <<\EOF |
763 | 0001-Second.patch | |
764 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
765 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
766 | Dry-OK. Log says: | |
767 | Server: relay.example.com | |
768 | MAIL FROM:<from@example.com> | |
02461e0e JP |
769 | RCPT TO:<to@example.com> |
770 | RCPT TO:<author@example.com> | |
771 | RCPT TO:<committer@example.com> | |
3531e270 JS |
772 | From: Example <from@example.com> |
773 | To: to@example.com | |
02461e0e JP |
774 | Cc: A <author@example.com>, |
775 | C O Mitter <committer@example.com> | |
3531e270 JS |
776 | Subject: [PATCH 1/1] Second. |
777 | Date: DATE-STRING | |
778 | Message-Id: MESSAGE-ID-STRING | |
779 | X-Mailer: X-MAILER-STRING | |
780 | ||
781 | Result: OK | |
782 | EOF | |
f9444147 | 783 | " |
3531e270 | 784 | |
57cd35e6 | 785 | test_expect_success $PREREQ '--suppress-cc=cc' ' |
3531e270 | 786 | test_suppression cc |
33c592dd MV |
787 | ' |
788 | ||
c1f2aa45 JS |
789 | test_confirm () { |
790 | echo y | \ | |
791 | GIT_SEND_EMAIL_NOTTY=1 \ | |
792 | git send-email \ | |
793 | --from="Example <nobody@example.com>" \ | |
794 | --to=nobody@example.com \ | |
795 | --smtp-server="$(pwd)/fake.sendmail" \ | |
c18f75a1 JS |
796 | $@ $patches > stdout && |
797 | grep "Send this email" stdout | |
c1f2aa45 JS |
798 | } |
799 | ||
57cd35e6 | 800 | test_expect_success $PREREQ '--confirm=always' ' |
c1f2aa45 JS |
801 | test_confirm --confirm=always --suppress-cc=all |
802 | ' | |
803 | ||
57cd35e6 | 804 | test_expect_success $PREREQ '--confirm=auto' ' |
c1f2aa45 JS |
805 | test_confirm --confirm=auto |
806 | ' | |
807 | ||
57cd35e6 | 808 | test_expect_success $PREREQ '--confirm=cc' ' |
c1f2aa45 JS |
809 | test_confirm --confirm=cc |
810 | ' | |
811 | ||
57cd35e6 | 812 | test_expect_success $PREREQ '--confirm=compose' ' |
c1f2aa45 JS |
813 | test_confirm --confirm=compose --compose |
814 | ' | |
815 | ||
57cd35e6 | 816 | test_expect_success $PREREQ 'confirm by default (due to cc)' ' |
c1f2aa45 JS |
817 | CONFIRM=$(git config --get sendemail.confirm) && |
818 | git config --unset sendemail.confirm && | |
c18f75a1 JS |
819 | test_confirm |
820 | ret="$?" | |
821 | git config sendemail.confirm ${CONFIRM:-never} | |
822 | test $ret = "0" | |
c1f2aa45 JS |
823 | ' |
824 | ||
57cd35e6 | 825 | test_expect_success $PREREQ 'confirm by default (due to --compose)' ' |
c1f2aa45 JS |
826 | CONFIRM=$(git config --get sendemail.confirm) && |
827 | git config --unset sendemail.confirm && | |
828 | test_confirm --suppress-cc=all --compose | |
829 | ret="$?" | |
830 | git config sendemail.confirm ${CONFIRM:-never} | |
831 | test $ret = "0" | |
832 | ' | |
833 | ||
57cd35e6 | 834 | test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' ' |
c18f75a1 JS |
835 | CONFIRM=$(git config --get sendemail.confirm) && |
836 | git config --unset sendemail.confirm && | |
dc1460aa JS |
837 | rm -fr outdir && |
838 | git format-patch -2 -o outdir && | |
c18f75a1 JS |
839 | GIT_SEND_EMAIL_NOTTY=1 \ |
840 | git send-email \ | |
841 | --from="Example <nobody@example.com>" \ | |
842 | --to=nobody@example.com \ | |
843 | --smtp-server="$(pwd)/fake.sendmail" \ | |
dc1460aa | 844 | outdir/*.patch < /dev/null |
c18f75a1 JS |
845 | ret="$?" |
846 | git config sendemail.confirm ${CONFIRM:-never} | |
847 | test $ret = "0" | |
848 | ' | |
849 | ||
57cd35e6 | 850 | test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' ' |
c18f75a1 JS |
851 | CONFIRM=$(git config --get sendemail.confirm) && |
852 | git config sendemail.confirm auto && | |
3b3637c3 JS |
853 | GIT_SEND_EMAIL_NOTTY=1 && |
854 | export GIT_SEND_EMAIL_NOTTY && | |
c18f75a1 JS |
855 | test_must_fail git send-email \ |
856 | --from="Example <nobody@example.com>" \ | |
857 | --to=nobody@example.com \ | |
858 | --smtp-server="$(pwd)/fake.sendmail" \ | |
859 | $patches < /dev/null | |
860 | ret="$?" | |
861 | git config sendemail.confirm ${CONFIRM:-never} | |
862 | test $ret = "0" | |
863 | ' | |
864 | ||
41ccfdd9 | 865 | test_expect_success $PREREQ 'confirm does not loop forever' ' |
c18f75a1 JS |
866 | CONFIRM=$(git config --get sendemail.confirm) && |
867 | git config sendemail.confirm auto && | |
3b3637c3 JS |
868 | GIT_SEND_EMAIL_NOTTY=1 && |
869 | export GIT_SEND_EMAIL_NOTTY && | |
870 | yes "bogus" | test_must_fail git send-email \ | |
c18f75a1 JS |
871 | --from="Example <nobody@example.com>" \ |
872 | --to=nobody@example.com \ | |
873 | --smtp-server="$(pwd)/fake.sendmail" \ | |
874 | $patches | |
875 | ret="$?" | |
876 | git config sendemail.confirm ${CONFIRM:-never} | |
877 | test $ret = "0" | |
878 | ' | |
879 | ||
57cd35e6 | 880 | test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' ' |
a61c0ffa JS |
881 | clean_fake_sendmail && |
882 | rm -fr outdir && | |
883 | git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" && | |
884 | git send-email \ | |
885 | --from="Example <nobody@example.com>" \ | |
886 | --to=nobody@example.com \ | |
887 | --smtp-server="$(pwd)/fake.sendmail" \ | |
888 | outdir/*.patch && | |
02461e0e | 889 | grep "^ " msgtxt1 | |
d1fff6fc | 890 | grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>" |
a61c0ffa JS |
891 | ' |
892 | ||
57cd35e6 | 893 | test_expect_success $PREREQ '--compose adds MIME for utf8 body' ' |
0706bd19 | 894 | clean_fake_sendmail && |
bb3e4f03 | 895 | (echo "#!$SHELL_PATH" && |
c01cdde1 | 896 | echo "echo utf8 body: àéìöú >>\"\$1\"" |
0706bd19 JK |
897 | ) >fake-editor-utf8 && |
898 | chmod +x fake-editor-utf8 && | |
c01cdde1 | 899 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ |
0706bd19 JK |
900 | git send-email \ |
901 | --compose --subject foo \ | |
902 | --from="Example <nobody@example.com>" \ | |
903 | --to=nobody@example.com \ | |
904 | --smtp-server="$(pwd)/fake.sendmail" \ | |
905 | $patches && | |
906 | grep "^utf8 body" msgtxt1 && | |
d1fff6fc | 907 | grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 |
0706bd19 JK |
908 | ' |
909 | ||
57cd35e6 | 910 | test_expect_success $PREREQ '--compose respects user mime type' ' |
0706bd19 | 911 | clean_fake_sendmail && |
bb3e4f03 | 912 | (echo "#!$SHELL_PATH" && |
0706bd19 JK |
913 | echo "(echo MIME-Version: 1.0" |
914 | echo " echo Content-Type: text/plain\\; charset=iso-8859-1" | |
915 | echo " echo Content-Transfer-Encoding: 8bit" | |
916 | echo " echo Subject: foo" | |
917 | echo " echo " | |
c01cdde1 | 918 | echo " echo utf8 body: àéìöú) >\"\$1\"" |
0706bd19 JK |
919 | ) >fake-editor-utf8-mime && |
920 | chmod +x fake-editor-utf8-mime && | |
c01cdde1 | 921 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \ |
0706bd19 JK |
922 | git send-email \ |
923 | --compose --subject foo \ | |
924 | --from="Example <nobody@example.com>" \ | |
925 | --to=nobody@example.com \ | |
926 | --smtp-server="$(pwd)/fake.sendmail" \ | |
927 | $patches && | |
928 | grep "^utf8 body" msgtxt1 && | |
929 | grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 && | |
d1fff6fc | 930 | ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 |
0706bd19 JK |
931 | ' |
932 | ||
57cd35e6 | 933 | test_expect_success $PREREQ '--compose adds MIME for utf8 subject' ' |
d54eaaa2 | 934 | clean_fake_sendmail && |
c01cdde1 | 935 | GIT_EDITOR="\"$(pwd)/fake-editor\"" \ |
d54eaaa2 JK |
936 | git send-email \ |
937 | --compose --subject utf8-sübjëct \ | |
938 | --from="Example <nobody@example.com>" \ | |
939 | --to=nobody@example.com \ | |
940 | --smtp-server="$(pwd)/fake.sendmail" \ | |
941 | $patches && | |
942 | grep "^fake edit" msgtxt1 && | |
d1fff6fc | 943 | grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 |
d54eaaa2 JK |
944 | ' |
945 | ||
b622d4d1 TR |
946 | test_expect_success $PREREQ 'utf8 author is correctly passed on' ' |
947 | clean_fake_sendmail && | |
948 | test_commit weird_author && | |
949 | test_when_finished "git reset --hard HEAD^" && | |
950 | git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" && | |
951 | git format-patch --stdout -1 >funny_name.patch && | |
952 | git send-email --from="Example <nobody@example.com>" \ | |
953 | --to=nobody@example.com \ | |
954 | --smtp-server="$(pwd)/fake.sendmail" \ | |
955 | funny_name.patch && | |
956 | grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1 | |
957 | ' | |
958 | ||
62e00690 KM |
959 | test_expect_success $PREREQ 'sendemail.composeencoding works' ' |
960 | clean_fake_sendmail && | |
961 | git config sendemail.composeencoding iso-8859-1 && | |
962 | (echo "#!$SHELL_PATH" && | |
963 | echo "echo utf8 body: àéìöú >>\"\$1\"" | |
964 | ) >fake-editor-utf8 && | |
965 | chmod +x fake-editor-utf8 && | |
966 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ | |
967 | git send-email \ | |
968 | --compose --subject foo \ | |
969 | --from="Example <nobody@example.com>" \ | |
970 | --to=nobody@example.com \ | |
971 | --smtp-server="$(pwd)/fake.sendmail" \ | |
972 | $patches && | |
973 | grep "^utf8 body" msgtxt1 && | |
974 | grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 | |
975 | ' | |
976 | ||
977 | test_expect_success $PREREQ '--compose-encoding works' ' | |
978 | clean_fake_sendmail && | |
979 | (echo "#!$SHELL_PATH" && | |
980 | echo "echo utf8 body: àéìöú >>\"\$1\"" | |
981 | ) >fake-editor-utf8 && | |
982 | chmod +x fake-editor-utf8 && | |
983 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ | |
984 | git send-email \ | |
985 | --compose-encoding iso-8859-1 \ | |
986 | --compose --subject foo \ | |
987 | --from="Example <nobody@example.com>" \ | |
988 | --to=nobody@example.com \ | |
989 | --smtp-server="$(pwd)/fake.sendmail" \ | |
990 | $patches && | |
991 | grep "^utf8 body" msgtxt1 && | |
992 | grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 | |
993 | ' | |
994 | ||
995 | test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' ' | |
996 | clean_fake_sendmail && | |
997 | git config sendemail.composeencoding iso-8859-1 && | |
998 | (echo "#!$SHELL_PATH" && | |
999 | echo "echo utf8 body: àéìöú >>\"\$1\"" | |
1000 | ) >fake-editor-utf8 && | |
1001 | chmod +x fake-editor-utf8 && | |
1002 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ | |
1003 | git send-email \ | |
1004 | --compose-encoding iso-8859-2 \ | |
1005 | --compose --subject foo \ | |
1006 | --from="Example <nobody@example.com>" \ | |
1007 | --to=nobody@example.com \ | |
1008 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1009 | $patches && | |
1010 | grep "^utf8 body" msgtxt1 && | |
1011 | grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1 | |
1012 | ' | |
1013 | ||
4a47a4dd KM |
1014 | test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' ' |
1015 | clean_fake_sendmail && | |
1016 | GIT_EDITOR="\"$(pwd)/fake-editor\"" \ | |
1017 | git send-email \ | |
1018 | --compose-encoding iso-8859-2 \ | |
1019 | --compose --subject utf8-sübjëct \ | |
1020 | --from="Example <nobody@example.com>" \ | |
1021 | --to=nobody@example.com \ | |
1022 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1023 | $patches && | |
1024 | grep "^fake edit" msgtxt1 && | |
1025 | grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 | |
1026 | ' | |
1027 | ||
57cd35e6 | 1028 | test_expect_success $PREREQ 'detects ambiguous reference/file conflict' ' |
5df9fcf6 PH |
1029 | echo master > master && |
1030 | git add master && | |
1031 | git commit -m"add master" && | |
1032 | test_must_fail git send-email --dry-run master 2>errors && | |
1033 | grep disambiguate errors | |
1034 | ' | |
1035 | ||
57cd35e6 | 1036 | test_expect_success $PREREQ 'feed two files' ' |
69f4ce55 JH |
1037 | rm -fr outdir && |
1038 | git format-patch -2 -o outdir && | |
c1f2aa45 | 1039 | git send-email \ |
69f4ce55 JH |
1040 | --dry-run \ |
1041 | --from="Example <nobody@example.com>" \ | |
1042 | --to=nobody@example.com \ | |
1043 | outdir/000?-*.patch 2>errors >out && | |
1044 | grep "^Subject: " out >subjects && | |
1045 | test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." && | |
1046 | test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master" | |
1047 | ' | |
1048 | ||
57cd35e6 | 1049 | test_expect_success $PREREQ 'in-reply-to but no threading' ' |
aaab4b9f TR |
1050 | git send-email \ |
1051 | --dry-run \ | |
1052 | --from="Example <nobody@example.com>" \ | |
1053 | --to=nobody@example.com \ | |
1054 | --in-reply-to="<in-reply-id@example.com>" \ | |
84eeb687 | 1055 | --nothread \ |
aaab4b9f TR |
1056 | $patches | |
1057 | grep "In-Reply-To: <in-reply-id@example.com>" | |
1058 | ' | |
1059 | ||
57cd35e6 | 1060 | test_expect_success $PREREQ 'no in-reply-to and no threading' ' |
32ae8319 MH |
1061 | git send-email \ |
1062 | --dry-run \ | |
1063 | --from="Example <nobody@example.com>" \ | |
1064 | --to=nobody@example.com \ | |
1065 | --nothread \ | |
1066 | $patches $patches >stdout && | |
1067 | ! grep "In-Reply-To: " stdout | |
1068 | ' | |
1069 | ||
57cd35e6 | 1070 | test_expect_success $PREREQ 'threading but no chain-reply-to' ' |
d67114a5 MH |
1071 | git send-email \ |
1072 | --dry-run \ | |
1073 | --from="Example <nobody@example.com>" \ | |
1074 | --to=nobody@example.com \ | |
1075 | --thread \ | |
1076 | --nochain-reply-to \ | |
1077 | $patches $patches >stdout && | |
1078 | grep "In-Reply-To: " stdout | |
1079 | ' | |
1080 | ||
57cd35e6 | 1081 | test_expect_success $PREREQ 'sendemail.to works' ' |
f434c083 SB |
1082 | git config --replace-all sendemail.to "Somebody <somebody@ex.com>" && |
1083 | git send-email \ | |
1084 | --dry-run \ | |
1085 | --from="Example <nobody@example.com>" \ | |
1086 | $patches $patches >stdout && | |
1087 | grep "To: Somebody <somebody@ex.com>" stdout | |
1088 | ' | |
1089 | ||
57cd35e6 | 1090 | test_expect_success $PREREQ '--no-to overrides sendemail.to' ' |
f434c083 SB |
1091 | git send-email \ |
1092 | --dry-run \ | |
1093 | --from="Example <nobody@example.com>" \ | |
1094 | --no-to \ | |
1095 | --to=nobody@example.com \ | |
1096 | $patches $patches >stdout && | |
1097 | grep "To: nobody@example.com" stdout && | |
1098 | ! grep "To: Somebody <somebody@ex.com>" stdout | |
1099 | ' | |
1100 | ||
57cd35e6 | 1101 | test_expect_success $PREREQ 'sendemail.cc works' ' |
f434c083 SB |
1102 | git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" && |
1103 | git send-email \ | |
1104 | --dry-run \ | |
1105 | --from="Example <nobody@example.com>" \ | |
1106 | --to=nobody@example.com \ | |
1107 | $patches $patches >stdout && | |
1108 | grep "Cc: Somebody <somebody@ex.com>" stdout | |
1109 | ' | |
1110 | ||
57cd35e6 | 1111 | test_expect_success $PREREQ '--no-cc overrides sendemail.cc' ' |
f434c083 SB |
1112 | git send-email \ |
1113 | --dry-run \ | |
1114 | --from="Example <nobody@example.com>" \ | |
1115 | --no-cc \ | |
1116 | --cc=bodies@example.com \ | |
1117 | --to=nobody@example.com \ | |
1118 | $patches $patches >stdout && | |
1119 | grep "Cc: bodies@example.com" stdout && | |
1120 | ! grep "Cc: Somebody <somebody@ex.com>" stdout | |
1121 | ' | |
1122 | ||
57cd35e6 | 1123 | test_expect_success $PREREQ 'sendemail.bcc works' ' |
f434c083 SB |
1124 | git config --replace-all sendemail.bcc "Other <other@ex.com>" && |
1125 | git send-email \ | |
1126 | --dry-run \ | |
1127 | --from="Example <nobody@example.com>" \ | |
1128 | --to=nobody@example.com \ | |
1129 | --smtp-server relay.example.com \ | |
1130 | $patches $patches >stdout && | |
1131 | grep "RCPT TO:<other@ex.com>" stdout | |
1132 | ' | |
1133 | ||
57cd35e6 | 1134 | test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' ' |
f434c083 SB |
1135 | git send-email \ |
1136 | --dry-run \ | |
1137 | --from="Example <nobody@example.com>" \ | |
1138 | --no-bcc \ | |
1139 | --bcc=bodies@example.com \ | |
1140 | --to=nobody@example.com \ | |
1141 | --smtp-server relay.example.com \ | |
1142 | $patches $patches >stdout && | |
1143 | grep "RCPT TO:<bodies@example.com>" stdout && | |
1144 | ! grep "RCPT TO:<other@ex.com>" stdout | |
1145 | ' | |
1146 | ||
21802cd3 SB |
1147 | test_expect_success $PREREQ 'patches To headers are used by default' ' |
1148 | patch=`git format-patch -1 --to="bodies@example.com"` && | |
1149 | test_when_finished "rm $patch" && | |
1150 | git send-email \ | |
1151 | --dry-run \ | |
1152 | --from="Example <nobody@example.com>" \ | |
1153 | --smtp-server relay.example.com \ | |
1154 | $patch >stdout && | |
1155 | grep "RCPT TO:<bodies@example.com>" stdout | |
1156 | ' | |
1157 | ||
1158 | test_expect_success $PREREQ 'patches To headers are appended to' ' | |
1159 | patch=`git format-patch -1 --to="bodies@example.com"` && | |
1160 | test_when_finished "rm $patch" && | |
1161 | git send-email \ | |
1162 | --dry-run \ | |
1163 | --from="Example <nobody@example.com>" \ | |
1164 | --to=nobody@example.com \ | |
1165 | --smtp-server relay.example.com \ | |
1166 | $patch >stdout && | |
1167 | grep "RCPT TO:<bodies@example.com>" stdout && | |
1168 | grep "RCPT TO:<nobody@example.com>" stdout | |
1169 | ' | |
1170 | ||
3c3bb51c SB |
1171 | test_expect_success $PREREQ 'To headers from files reset each patch' ' |
1172 | patch1=`git format-patch -1 --to="bodies@example.com"` && | |
1173 | patch2=`git format-patch -1 --to="other@example.com" HEAD~` && | |
1174 | test_when_finished "rm $patch1 && rm $patch2" && | |
1175 | git send-email \ | |
1176 | --dry-run \ | |
1177 | --from="Example <nobody@example.com>" \ | |
1178 | --to="nobody@example.com" \ | |
1179 | --smtp-server relay.example.com \ | |
1180 | $patch1 $patch2 >stdout && | |
1181 | test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 && | |
1182 | test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 && | |
1183 | test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1 | |
1184 | ' | |
1185 | ||
f9444147 | 1186 | test_expect_success $PREREQ 'setup expect' ' |
3cae7e5b TR |
1187 | cat >email-using-8bit <<EOF |
1188 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 | |
1189 | Message-Id: <bogus-message-id@example.com> | |
1190 | From: author@example.com | |
1191 | Date: Sat, 12 Jun 2010 15:53:58 +0200 | |
1192 | Subject: subject goes here | |
1193 | ||
1194 | Dieser deutsche Text enthält einen Umlaut! | |
1195 | EOF | |
f9444147 | 1196 | ' |
3cae7e5b | 1197 | |
5637d857 KM |
1198 | test_expect_success $PREREQ 'setup expect' ' |
1199 | cat >expected <<EOF | |
1200 | Subject: subject goes here | |
1201 | EOF | |
1202 | ' | |
1203 | ||
1204 | test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' ' | |
1205 | clean_fake_sendmail && | |
1206 | echo bogus | | |
1207 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1208 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1209 | --8bit-encoding=UTF-8 \ | |
1210 | email-using-8bit >stdout && | |
1211 | grep "Subject" msgtxt1 >actual && | |
1212 | test_cmp expected actual | |
1213 | ' | |
1214 | ||
f9444147 | 1215 | test_expect_success $PREREQ 'setup expect' ' |
3cae7e5b TR |
1216 | cat >content-type-decl <<EOF |
1217 | MIME-Version: 1.0 | |
1218 | Content-Type: text/plain; charset=UTF-8 | |
1219 | Content-Transfer-Encoding: 8bit | |
1220 | EOF | |
f9444147 | 1221 | ' |
3cae7e5b | 1222 | |
57cd35e6 | 1223 | test_expect_success $PREREQ 'asks about and fixes 8bit encodings' ' |
3cae7e5b TR |
1224 | clean_fake_sendmail && |
1225 | echo | | |
1226 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1227 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1228 | email-using-8bit >stdout && | |
1229 | grep "do not declare a Content-Transfer-Encoding" stdout && | |
1230 | grep email-using-8bit stdout && | |
1231 | grep "Which 8bit encoding" stdout && | |
31832862 | 1232 | egrep "Content|MIME" msgtxt1 >actual && |
3cae7e5b TR |
1233 | test_cmp actual content-type-decl |
1234 | ' | |
1235 | ||
57cd35e6 | 1236 | test_expect_success $PREREQ 'sendemail.8bitEncoding works' ' |
3cae7e5b TR |
1237 | clean_fake_sendmail && |
1238 | git config sendemail.assume8bitEncoding UTF-8 && | |
1239 | echo bogus | | |
1240 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1241 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1242 | email-using-8bit >stdout && | |
31832862 | 1243 | egrep "Content|MIME" msgtxt1 >actual && |
3cae7e5b TR |
1244 | test_cmp actual content-type-decl |
1245 | ' | |
1246 | ||
57cd35e6 | 1247 | test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' ' |
3cae7e5b TR |
1248 | clean_fake_sendmail && |
1249 | git config sendemail.assume8bitEncoding "bogus too" && | |
1250 | echo bogus | | |
1251 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1252 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1253 | --8bit-encoding=UTF-8 \ | |
1254 | email-using-8bit >stdout && | |
31832862 | 1255 | egrep "Content|MIME" msgtxt1 >actual && |
3cae7e5b TR |
1256 | test_cmp actual content-type-decl |
1257 | ' | |
1258 | ||
f9444147 | 1259 | test_expect_success $PREREQ 'setup expect' ' |
3cae7e5b TR |
1260 | cat >email-using-8bit <<EOF |
1261 | From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 | |
1262 | Message-Id: <bogus-message-id@example.com> | |
1263 | From: author@example.com | |
1264 | Date: Sat, 12 Jun 2010 15:53:58 +0200 | |
1265 | Subject: Dieser Betreff enthält auch einen Umlaut! | |
1266 | ||
1267 | Nothing to see here. | |
1268 | EOF | |
f9444147 | 1269 | ' |
3cae7e5b | 1270 | |
f9444147 | 1271 | test_expect_success $PREREQ 'setup expect' ' |
3cae7e5b TR |
1272 | cat >expected <<EOF |
1273 | Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?= | |
1274 | EOF | |
f9444147 | 1275 | ' |
3cae7e5b | 1276 | |
57cd35e6 | 1277 | test_expect_success $PREREQ '--8bit-encoding also treats subject' ' |
3cae7e5b TR |
1278 | clean_fake_sendmail && |
1279 | echo bogus | | |
1280 | git send-email --from=author@example.com --to=nobody@example.com \ | |
1281 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1282 | --8bit-encoding=UTF-8 \ | |
1283 | email-using-8bit >stdout && | |
1284 | grep "Subject" msgtxt1 >actual && | |
1285 | test_cmp expected actual | |
1286 | ' | |
1287 | ||
a03bc5b6 TR |
1288 | # Note that the patches in this test are deliberately out of order; we |
1289 | # want to make sure it works even if the cover-letter is not in the | |
1290 | # first mail. | |
57da2042 | 1291 | test_expect_success $PREREQ 'refusing to send cover letter template' ' |
a03bc5b6 TR |
1292 | clean_fake_sendmail && |
1293 | rm -fr outdir && | |
1294 | git format-patch --cover-letter -2 -o outdir && | |
1295 | test_must_fail git send-email \ | |
1296 | --from="Example <nobody@example.com>" \ | |
1297 | --to=nobody@example.com \ | |
1298 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1299 | outdir/0002-*.patch \ | |
1300 | outdir/0000-*.patch \ | |
1301 | outdir/0001-*.patch \ | |
1302 | 2>errors >out && | |
1303 | grep "SUBJECT HERE" errors && | |
1304 | test -z "$(ls msgtxt*)" | |
1305 | ' | |
1306 | ||
57da2042 | 1307 | test_expect_success $PREREQ '--force sends cover letter template anyway' ' |
a03bc5b6 TR |
1308 | clean_fake_sendmail && |
1309 | rm -fr outdir && | |
1310 | git format-patch --cover-letter -2 -o outdir && | |
1311 | git send-email \ | |
1312 | --force \ | |
1313 | --from="Example <nobody@example.com>" \ | |
1314 | --to=nobody@example.com \ | |
1315 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1316 | outdir/0002-*.patch \ | |
1317 | outdir/0000-*.patch \ | |
1318 | outdir/0001-*.patch \ | |
1319 | 2>errors >out && | |
1320 | ! grep "SUBJECT HERE" errors && | |
1321 | test -n "$(ls msgtxt*)" | |
1322 | ' | |
1323 | ||
463b0ea2 CS |
1324 | test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' ' |
1325 | clean_fake_sendmail && | |
1326 | echo "alias sbd somebody@example.org" >.mailrc && | |
1327 | git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" && | |
1328 | git config sendemail.aliasfiletype mailrc && | |
1329 | git send-email \ | |
1330 | --from="Example <nobody@example.com>" \ | |
1331 | --to=sbd \ | |
1332 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1333 | outdir/0001-*.patch \ | |
1334 | 2>errors >out && | |
1335 | grep "^!somebody@example\.org!$" commandline1 | |
1336 | ' | |
1337 | ||
1338 | test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' ' | |
1339 | clean_fake_sendmail && | |
1340 | echo "alias sbd someone@example.org" >~/.mailrc && | |
1341 | git config --replace-all sendemail.aliasesfile "~/.mailrc" && | |
1342 | git config sendemail.aliasfiletype mailrc && | |
1343 | git send-email \ | |
1344 | --from="Example <nobody@example.com>" \ | |
1345 | --to=sbd \ | |
1346 | --smtp-server="$(pwd)/fake.sendmail" \ | |
1347 | outdir/0001-*.patch \ | |
1348 | 2>errors >out && | |
1349 | grep "^!someone@example\.org!$" commandline1 | |
1350 | ' | |
1351 | ||
ce903018 | 1352 | test_done |