]>
Commit | Line | Data |
---|---|---|
ce903018 RA |
1 | #!/bin/sh |
2 | ||
47a528ad | 3 | test_description='git send-email' |
ce903018 RA |
4 | . ./test-lib.sh |
5 | ||
1b19ccd2 JK |
6 | if ! test_have_prereq PERL; then |
7 | say 'skipping git send-email tests, perl not available' | |
8 | test_done | |
9 | fi | |
10 | ||
ce903018 RA |
11 | PROG='git send-email' |
12 | test_expect_success \ | |
13 | 'prepare reference tree' \ | |
14 | 'echo "1A quick brown fox jumps over the" >file && | |
15 | echo "lazy dog" >>file && | |
c0d45281 | 16 | git add file && |
ce903018 RA |
17 | GIT_AUTHOR_NAME="A" git commit -a -m "Initial."' |
18 | ||
19 | test_expect_success \ | |
20 | 'Setup helper tool' \ | |
bb3e4f03 | 21 | '(echo "#!$SHELL_PATH" |
2186d566 | 22 | echo shift |
6d34a2ba JK |
23 | echo output=1 |
24 | echo "while test -f commandline\$output; do output=\$((\$output+1)); done" | |
2186d566 JH |
25 | echo for a |
26 | echo do | |
27 | echo " echo \"!\$a!\"" | |
6d34a2ba JK |
28 | echo "done >commandline\$output" |
29 | echo "cat > msgtxt\$output" | |
c0d45281 JK |
30 | ) >fake.sendmail && |
31 | chmod +x ./fake.sendmail && | |
32 | git add fake.sendmail && | |
ce903018 RA |
33 | GIT_AUTHOR_NAME="A" git commit -a -m "Second."' |
34 | ||
6d34a2ba JK |
35 | clean_fake_sendmail() { |
36 | rm -f commandline* msgtxt* | |
37 | } | |
38 | ||
280242d1 | 39 | test_expect_success 'Extract patches' ' |
3531e270 | 40 | patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1` |
280242d1 JH |
41 | ' |
42 | ||
c1f2aa45 JS |
43 | # Test no confirm early to ensure remaining tests will not hang |
44 | test_no_confirm () { | |
45 | rm -f no_confirm_okay | |
46 | echo n | \ | |
47 | GIT_SEND_EMAIL_NOTTY=1 \ | |
48 | git send-email \ | |
49 | --from="Example <from@example.com>" \ | |
50 | --to=nobody@example.com \ | |
51 | --smtp-server="$(pwd)/fake.sendmail" \ | |
52 | $@ \ | |
53 | $patches > stdout && | |
54 | test_must_fail grep "Send this email" stdout && | |
55 | > no_confirm_okay | |
56 | } | |
57 | ||
58 | # Exit immediately to prevent hang if a no-confirm test fails | |
59 | check_no_confirm () { | |
60 | test -f no_confirm_okay || { | |
61 | say 'No confirm test failed; skipping remaining tests to prevent hanging' | |
62 | test_done | |
63 | } | |
64 | } | |
65 | ||
66 | test_expect_success 'No confirm with --suppress-cc' ' | |
67 | test_no_confirm --suppress-cc=sob | |
68 | ' | |
69 | check_no_confirm | |
70 | ||
71 | test_expect_success 'No confirm with --confirm=never' ' | |
72 | test_no_confirm --confirm=never | |
73 | ' | |
74 | check_no_confirm | |
75 | ||
76 | # leave sendemail.confirm set to never after this so that none of the | |
77 | # remaining tests prompt unintentionally. | |
78 | test_expect_success 'No confirm with sendemail.confirm=never' ' | |
79 | git config sendemail.confirm never && | |
80 | test_no_confirm --compose --subject=foo | |
81 | ' | |
82 | check_no_confirm | |
83 | ||
280242d1 | 84 | test_expect_success 'Send patches' ' |
3531e270 | 85 | git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors |
280242d1 | 86 | ' |
ce903018 | 87 | |
2186d566 JH |
88 | cat >expected <<\EOF |
89 | !nobody@example.com! | |
90 | !author@example.com! | |
5012699d JS |
91 | !one@example.com! |
92 | !two@example.com! | |
2186d566 | 93 | EOF |
ce903018 RA |
94 | test_expect_success \ |
95 | 'Verify commandline' \ | |
188c3827 | 96 | 'test_cmp expected commandline1' |
ce903018 | 97 | |
4f333bc1 JH |
98 | test_expect_success 'Send patches with --envelope-sender' ' |
99 | clean_fake_sendmail && | |
100 | git send-email --envelope-sender="Patch Contributer <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors | |
101 | ' | |
102 | ||
103 | cat >expected <<\EOF | |
104 | !patch@example.com! | |
105 | !-i! | |
106 | !nobody@example.com! | |
107 | !author@example.com! | |
108 | !one@example.com! | |
109 | !two@example.com! | |
110 | EOF | |
111 | test_expect_success \ | |
112 | 'Verify commandline' \ | |
113 | 'test_cmp expected commandline1' | |
114 | ||
c89e3241 FC |
115 | test_expect_success 'Send patches with --envelope-sender=auto' ' |
116 | clean_fake_sendmail && | |
117 | 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 | |
118 | ' | |
119 | ||
120 | cat >expected <<\EOF | |
121 | !nobody@example.com! | |
122 | !-i! | |
123 | !nobody@example.com! | |
124 | !author@example.com! | |
125 | !one@example.com! | |
126 | !two@example.com! | |
127 | EOF | |
128 | test_expect_success \ | |
129 | 'Verify commandline' \ | |
130 | 'test_cmp expected commandline1' | |
131 | ||
b7f30e0a DK |
132 | cat >expected-show-all-headers <<\EOF |
133 | 0001-Second.patch | |
134 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
5012699d JS |
135 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
136 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
b7f30e0a DK |
137 | Dry-OK. Log says: |
138 | Server: relay.example.com | |
139 | MAIL FROM:<from@example.com> | |
02461e0e JP |
140 | RCPT TO:<to@example.com> |
141 | RCPT TO:<cc@example.com> | |
142 | RCPT TO:<author@example.com> | |
143 | RCPT TO:<one@example.com> | |
144 | RCPT TO:<two@example.com> | |
145 | RCPT TO:<bcc@example.com> | |
b7f30e0a DK |
146 | From: Example <from@example.com> |
147 | To: to@example.com | |
02461e0e JP |
148 | Cc: cc@example.com, |
149 | A <author@example.com>, | |
150 | One <one@example.com>, | |
151 | two@example.com | |
b7f30e0a DK |
152 | Subject: [PATCH 1/1] Second. |
153 | Date: DATE-STRING | |
154 | Message-Id: MESSAGE-ID-STRING | |
155 | X-Mailer: X-MAILER-STRING | |
156 | In-Reply-To: <unique-message-id@example.com> | |
157 | References: <unique-message-id@example.com> | |
158 | ||
159 | Result: OK | |
160 | EOF | |
161 | ||
162 | test_expect_success 'Show all headers' ' | |
163 | git send-email \ | |
164 | --dry-run \ | |
3531e270 | 165 | --suppress-cc=sob \ |
b7f30e0a DK |
166 | --from="Example <from@example.com>" \ |
167 | --to=to@example.com \ | |
168 | --cc=cc@example.com \ | |
169 | --bcc=bcc@example.com \ | |
170 | --in-reply-to="<unique-message-id@example.com>" \ | |
171 | --smtp-server relay.example.com \ | |
172 | $patches | | |
173 | sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ | |
174 | -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ | |
175 | -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ | |
176 | >actual-show-all-headers && | |
82ebb0b6 | 177 | test_cmp expected-show-all-headers actual-show-all-headers |
b7f30e0a DK |
178 | ' |
179 | ||
0da43a68 JS |
180 | test_expect_success 'Prompting works' ' |
181 | clean_fake_sendmail && | |
182 | (echo "Example <from@example.com>" | |
183 | echo "to@example.com" | |
184 | echo "" | |
185 | ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
186 | --smtp-server="$(pwd)/fake.sendmail" \ | |
187 | $patches \ | |
188 | 2>errors && | |
9524cf29 SB |
189 | grep "^From: Example <from@example.com>\$" msgtxt1 && |
190 | grep "^To: to@example.com\$" msgtxt1 | |
0da43a68 JS |
191 | ' |
192 | ||
cb8a9bd5 PB |
193 | test_expect_success 'cccmd works' ' |
194 | clean_fake_sendmail && | |
195 | cp $patches cccmd.patch && | |
196 | echo cccmd--cccmd@example.com >>cccmd.patch && | |
977e289e BC |
197 | { |
198 | echo "#!$SHELL_PATH" | |
199 | echo sed -n -e s/^cccmd--//p \"\$1\" | |
200 | } > cccmd-sed && | |
cb8a9bd5 PB |
201 | chmod +x cccmd-sed && |
202 | git send-email \ | |
203 | --from="Example <nobody@example.com>" \ | |
204 | --to=nobody@example.com \ | |
205 | --cc-cmd=./cccmd-sed \ | |
206 | --smtp-server="$(pwd)/fake.sendmail" \ | |
207 | cccmd.patch \ | |
208 | && | |
02461e0e | 209 | grep "^ cccmd@example.com" msgtxt1 |
cb8a9bd5 PB |
210 | ' |
211 | ||
747bbff9 JK |
212 | z8=zzzzzzzz |
213 | z64=$z8$z8$z8$z8$z8$z8$z8$z8 | |
214 | z512=$z64$z64$z64$z64$z64$z64$z64$z64 | |
215 | test_expect_success 'reject long lines' ' | |
6d34a2ba | 216 | clean_fake_sendmail && |
747bbff9 JK |
217 | cp $patches longline.patch && |
218 | echo $z512$z512 >>longline.patch && | |
d492b31c | 219 | test_must_fail git send-email \ |
747bbff9 JK |
220 | --from="Example <nobody@example.com>" \ |
221 | --to=nobody@example.com \ | |
222 | --smtp-server="$(pwd)/fake.sendmail" \ | |
223 | $patches longline.patch \ | |
224 | 2>errors && | |
225 | grep longline.patch errors | |
226 | ' | |
227 | ||
228 | test_expect_success 'no patch was sent' ' | |
6d34a2ba | 229 | ! test -e commandline1 |
747bbff9 JK |
230 | ' |
231 | ||
5012699d JS |
232 | test_expect_success 'Author From: in message body' ' |
233 | clean_fake_sendmail && | |
234 | git send-email \ | |
235 | --from="Example <nobody@example.com>" \ | |
236 | --to=nobody@example.com \ | |
237 | --smtp-server="$(pwd)/fake.sendmail" \ | |
238 | $patches && | |
9524cf29 | 239 | sed "1,/^\$/d" < msgtxt1 > msgbody1 |
5012699d JS |
240 | grep "From: A <author@example.com>" msgbody1 |
241 | ' | |
242 | ||
243 | test_expect_success 'Author From: not in message body' ' | |
244 | clean_fake_sendmail && | |
245 | git send-email \ | |
246 | --from="A <author@example.com>" \ | |
247 | --to=nobody@example.com \ | |
248 | --smtp-server="$(pwd)/fake.sendmail" \ | |
249 | $patches && | |
9524cf29 | 250 | sed "1,/^\$/d" < msgtxt1 > msgbody1 |
5012699d JS |
251 | ! grep "From: A <author@example.com>" msgbody1 |
252 | ' | |
253 | ||
c764a0c2 JK |
254 | test_expect_success 'allow long lines with --no-validate' ' |
255 | git send-email \ | |
256 | --from="Example <nobody@example.com>" \ | |
257 | --to=nobody@example.com \ | |
258 | --smtp-server="$(pwd)/fake.sendmail" \ | |
3fee1fe8 | 259 | --novalidate \ |
c764a0c2 JK |
260 | $patches longline.patch \ |
261 | 2>errors | |
262 | ' | |
263 | ||
0fb7fc75 | 264 | test_expect_success 'Invalid In-Reply-To' ' |
6d34a2ba | 265 | clean_fake_sendmail && |
0fb7fc75 JS |
266 | git send-email \ |
267 | --from="Example <nobody@example.com>" \ | |
268 | --to=nobody@example.com \ | |
269 | --in-reply-to=" " \ | |
270 | --smtp-server="$(pwd)/fake.sendmail" \ | |
271 | $patches | |
272 | 2>errors | |
6d34a2ba | 273 | ! grep "^In-Reply-To: < *>" msgtxt1 |
0fb7fc75 JS |
274 | ' |
275 | ||
276 | test_expect_success 'Valid In-Reply-To when prompting' ' | |
6d34a2ba | 277 | clean_fake_sendmail && |
0fb7fc75 JS |
278 | (echo "From Example <from@example.com>" |
279 | echo "To Example <to@example.com>" | |
280 | echo "" | |
281 | ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
282 | --smtp-server="$(pwd)/fake.sendmail" \ | |
283 | $patches 2>errors && | |
6d34a2ba | 284 | ! grep "^In-Reply-To: < *>" msgtxt1 |
0fb7fc75 JS |
285 | ' |
286 | ||
8a8bf469 | 287 | test_expect_success 'setup fake editor' ' |
bb3e4f03 | 288 | (echo "#!$SHELL_PATH" && |
065096c2 | 289 | echo "echo fake edit >>\"\$1\"" |
8a8bf469 JK |
290 | ) >fake-editor && |
291 | chmod +x fake-editor | |
292 | ' | |
293 | ||
7f0475c3 | 294 | test_set_editor "$(pwd)/fake-editor" |
065096c2 | 295 | |
8a8bf469 JK |
296 | test_expect_success '--compose works' ' |
297 | clean_fake_sendmail && | |
c1f2aa45 JS |
298 | git send-email \ |
299 | --compose --subject foo \ | |
300 | --from="Example <nobody@example.com>" \ | |
301 | --to=nobody@example.com \ | |
302 | --smtp-server="$(pwd)/fake.sendmail" \ | |
303 | $patches \ | |
304 | 2>errors | |
8a8bf469 JK |
305 | ' |
306 | ||
307 | test_expect_success 'first message is compose text' ' | |
308 | grep "^fake edit" msgtxt1 | |
309 | ' | |
310 | ||
311 | test_expect_success 'second message is patch' ' | |
312 | grep "Subject:.*Second" msgtxt2 | |
313 | ' | |
314 | ||
3531e270 | 315 | cat >expected-suppress-sob <<\EOF |
33c592dd MV |
316 | 0001-Second.patch |
317 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
5012699d JS |
318 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
319 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
33c592dd MV |
320 | Dry-OK. Log says: |
321 | Server: relay.example.com | |
322 | MAIL FROM:<from@example.com> | |
02461e0e JP |
323 | RCPT TO:<to@example.com> |
324 | RCPT TO:<cc@example.com> | |
325 | RCPT TO:<author@example.com> | |
326 | RCPT TO:<one@example.com> | |
327 | RCPT TO:<two@example.com> | |
33c592dd MV |
328 | From: Example <from@example.com> |
329 | To: to@example.com | |
02461e0e JP |
330 | Cc: cc@example.com, |
331 | A <author@example.com>, | |
332 | One <one@example.com>, | |
333 | two@example.com | |
33c592dd MV |
334 | Subject: [PATCH 1/1] Second. |
335 | Date: DATE-STRING | |
336 | Message-Id: MESSAGE-ID-STRING | |
337 | X-Mailer: X-MAILER-STRING | |
338 | ||
339 | Result: OK | |
340 | EOF | |
341 | ||
3531e270 | 342 | test_suppression () { |
33c592dd MV |
343 | git send-email \ |
344 | --dry-run \ | |
cb8a9bd5 | 345 | --suppress-cc=$1 ${2+"--suppress-cc=$2"} \ |
33c592dd MV |
346 | --from="Example <from@example.com>" \ |
347 | --to=to@example.com \ | |
348 | --smtp-server relay.example.com \ | |
349 | $patches | | |
350 | sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ | |
351 | -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ | |
352 | -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ | |
cb8a9bd5 PB |
353 | >actual-suppress-$1${2+"-$2"} && |
354 | test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"} | |
3531e270 JS |
355 | } |
356 | ||
357 | test_expect_success 'sendemail.cc set' ' | |
358 | git config sendemail.cc cc@example.com && | |
359 | test_suppression sob | |
33c592dd MV |
360 | ' |
361 | ||
3531e270 | 362 | cat >expected-suppress-sob <<\EOF |
33c592dd MV |
363 | 0001-Second.patch |
364 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
5012699d JS |
365 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
366 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
33c592dd MV |
367 | Dry-OK. Log says: |
368 | Server: relay.example.com | |
369 | MAIL FROM:<from@example.com> | |
02461e0e JP |
370 | RCPT TO:<to@example.com> |
371 | RCPT TO:<author@example.com> | |
372 | RCPT TO:<one@example.com> | |
373 | RCPT TO:<two@example.com> | |
33c592dd MV |
374 | From: Example <from@example.com> |
375 | To: to@example.com | |
02461e0e JP |
376 | Cc: A <author@example.com>, |
377 | One <one@example.com>, | |
378 | two@example.com | |
33c592dd MV |
379 | Subject: [PATCH 1/1] Second. |
380 | Date: DATE-STRING | |
381 | Message-Id: MESSAGE-ID-STRING | |
382 | X-Mailer: X-MAILER-STRING | |
383 | ||
384 | Result: OK | |
385 | EOF | |
386 | ||
387 | test_expect_success 'sendemail.cc unset' ' | |
388 | git config --unset sendemail.cc && | |
3531e270 JS |
389 | test_suppression sob |
390 | ' | |
391 | ||
cb8a9bd5 PB |
392 | cat >expected-suppress-cccmd <<\EOF |
393 | 0001-Second.patch | |
394 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
395 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
396 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
397 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
398 | Dry-OK. Log says: | |
399 | Server: relay.example.com | |
400 | MAIL FROM:<from@example.com> | |
02461e0e JP |
401 | RCPT TO:<to@example.com> |
402 | RCPT TO:<author@example.com> | |
403 | RCPT TO:<one@example.com> | |
404 | RCPT TO:<two@example.com> | |
405 | RCPT TO:<committer@example.com> | |
cb8a9bd5 PB |
406 | From: Example <from@example.com> |
407 | To: to@example.com | |
02461e0e JP |
408 | Cc: A <author@example.com>, |
409 | One <one@example.com>, | |
410 | two@example.com, | |
411 | C O Mitter <committer@example.com> | |
cb8a9bd5 PB |
412 | Subject: [PATCH 1/1] Second. |
413 | Date: DATE-STRING | |
414 | Message-Id: MESSAGE-ID-STRING | |
415 | X-Mailer: X-MAILER-STRING | |
416 | ||
417 | Result: OK | |
418 | EOF | |
419 | ||
420 | test_expect_success 'sendemail.cccmd' ' | |
421 | echo echo cc-cmd@example.com > cccmd && | |
422 | chmod +x cccmd && | |
423 | git config sendemail.cccmd ./cccmd && | |
424 | test_suppression cccmd | |
425 | ' | |
426 | ||
3531e270 JS |
427 | cat >expected-suppress-all <<\EOF |
428 | 0001-Second.patch | |
429 | Dry-OK. Log says: | |
430 | Server: relay.example.com | |
431 | MAIL FROM:<from@example.com> | |
432 | RCPT TO:<to@example.com> | |
433 | From: Example <from@example.com> | |
434 | To: to@example.com | |
435 | Subject: [PATCH 1/1] Second. | |
436 | Date: DATE-STRING | |
437 | Message-Id: MESSAGE-ID-STRING | |
438 | X-Mailer: X-MAILER-STRING | |
439 | ||
440 | Result: OK | |
441 | EOF | |
442 | ||
443 | test_expect_success '--suppress-cc=all' ' | |
444 | test_suppression all | |
445 | ' | |
446 | ||
447 | cat >expected-suppress-body <<\EOF | |
448 | 0001-Second.patch | |
449 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
450 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
451 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
cb8a9bd5 | 452 | (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd' |
3531e270 JS |
453 | Dry-OK. Log says: |
454 | Server: relay.example.com | |
455 | MAIL FROM:<from@example.com> | |
02461e0e JP |
456 | RCPT TO:<to@example.com> |
457 | RCPT TO:<author@example.com> | |
458 | RCPT TO:<one@example.com> | |
459 | RCPT TO:<two@example.com> | |
460 | RCPT TO:<cc-cmd@example.com> | |
3531e270 JS |
461 | From: Example <from@example.com> |
462 | To: to@example.com | |
02461e0e JP |
463 | Cc: A <author@example.com>, |
464 | One <one@example.com>, | |
465 | two@example.com, | |
466 | cc-cmd@example.com | |
3531e270 JS |
467 | Subject: [PATCH 1/1] Second. |
468 | Date: DATE-STRING | |
469 | Message-Id: MESSAGE-ID-STRING | |
470 | X-Mailer: X-MAILER-STRING | |
471 | ||
472 | Result: OK | |
473 | EOF | |
474 | ||
475 | test_expect_success '--suppress-cc=body' ' | |
476 | test_suppression body | |
477 | ' | |
478 | ||
cb8a9bd5 PB |
479 | cat >expected-suppress-body-cccmd <<\EOF |
480 | 0001-Second.patch | |
481 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
482 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
483 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
484 | Dry-OK. Log says: | |
485 | Server: relay.example.com | |
486 | MAIL FROM:<from@example.com> | |
02461e0e JP |
487 | RCPT TO:<to@example.com> |
488 | RCPT TO:<author@example.com> | |
489 | RCPT TO:<one@example.com> | |
490 | RCPT TO:<two@example.com> | |
cb8a9bd5 PB |
491 | From: Example <from@example.com> |
492 | To: to@example.com | |
02461e0e JP |
493 | Cc: A <author@example.com>, |
494 | One <one@example.com>, | |
495 | two@example.com | |
cb8a9bd5 PB |
496 | Subject: [PATCH 1/1] Second. |
497 | Date: DATE-STRING | |
498 | Message-Id: MESSAGE-ID-STRING | |
499 | X-Mailer: X-MAILER-STRING | |
500 | ||
501 | Result: OK | |
502 | EOF | |
503 | ||
504 | test_expect_success '--suppress-cc=body --suppress-cc=cccmd' ' | |
505 | test_suppression body cccmd | |
506 | ' | |
507 | ||
3531e270 JS |
508 | cat >expected-suppress-sob <<\EOF |
509 | 0001-Second.patch | |
510 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
511 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
512 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
513 | Dry-OK. Log says: | |
514 | Server: relay.example.com | |
515 | MAIL FROM:<from@example.com> | |
02461e0e JP |
516 | RCPT TO:<to@example.com> |
517 | RCPT TO:<author@example.com> | |
518 | RCPT TO:<one@example.com> | |
519 | RCPT TO:<two@example.com> | |
3531e270 JS |
520 | From: Example <from@example.com> |
521 | To: to@example.com | |
02461e0e JP |
522 | Cc: A <author@example.com>, |
523 | One <one@example.com>, | |
524 | two@example.com | |
3531e270 JS |
525 | Subject: [PATCH 1/1] Second. |
526 | Date: DATE-STRING | |
527 | Message-Id: MESSAGE-ID-STRING | |
528 | X-Mailer: X-MAILER-STRING | |
529 | ||
530 | Result: OK | |
531 | EOF | |
532 | ||
533 | test_expect_success '--suppress-cc=sob' ' | |
cb8a9bd5 | 534 | git config --unset sendemail.cccmd |
3531e270 JS |
535 | test_suppression sob |
536 | ' | |
537 | ||
538 | cat >expected-suppress-bodycc <<\EOF | |
539 | 0001-Second.patch | |
540 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
541 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
542 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
543 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
544 | Dry-OK. Log says: | |
545 | Server: relay.example.com | |
546 | MAIL FROM:<from@example.com> | |
02461e0e JP |
547 | RCPT TO:<to@example.com> |
548 | RCPT TO:<author@example.com> | |
549 | RCPT TO:<one@example.com> | |
550 | RCPT TO:<two@example.com> | |
551 | RCPT TO:<committer@example.com> | |
3531e270 JS |
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, | |
557 | C O Mitter <committer@example.com> | |
3531e270 JS |
558 | Subject: [PATCH 1/1] Second. |
559 | Date: DATE-STRING | |
560 | Message-Id: MESSAGE-ID-STRING | |
561 | X-Mailer: X-MAILER-STRING | |
562 | ||
563 | Result: OK | |
564 | EOF | |
565 | ||
566 | test_expect_success '--suppress-cc=bodycc' ' | |
567 | test_suppression bodycc | |
568 | ' | |
569 | ||
570 | cat >expected-suppress-cc <<\EOF | |
571 | 0001-Second.patch | |
572 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
573 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
574 | Dry-OK. Log says: | |
575 | Server: relay.example.com | |
576 | MAIL FROM:<from@example.com> | |
02461e0e JP |
577 | RCPT TO:<to@example.com> |
578 | RCPT TO:<author@example.com> | |
579 | RCPT TO:<committer@example.com> | |
3531e270 JS |
580 | From: Example <from@example.com> |
581 | To: to@example.com | |
02461e0e JP |
582 | Cc: A <author@example.com>, |
583 | C O Mitter <committer@example.com> | |
3531e270 JS |
584 | Subject: [PATCH 1/1] Second. |
585 | Date: DATE-STRING | |
586 | Message-Id: MESSAGE-ID-STRING | |
587 | X-Mailer: X-MAILER-STRING | |
588 | ||
589 | Result: OK | |
590 | EOF | |
591 | ||
592 | test_expect_success '--suppress-cc=cc' ' | |
593 | test_suppression cc | |
33c592dd MV |
594 | ' |
595 | ||
c1f2aa45 JS |
596 | test_confirm () { |
597 | echo y | \ | |
598 | GIT_SEND_EMAIL_NOTTY=1 \ | |
599 | git send-email \ | |
600 | --from="Example <nobody@example.com>" \ | |
601 | --to=nobody@example.com \ | |
602 | --smtp-server="$(pwd)/fake.sendmail" \ | |
c18f75a1 JS |
603 | $@ $patches > stdout && |
604 | grep "Send this email" stdout | |
c1f2aa45 JS |
605 | } |
606 | ||
607 | test_expect_success '--confirm=always' ' | |
608 | test_confirm --confirm=always --suppress-cc=all | |
609 | ' | |
610 | ||
611 | test_expect_success '--confirm=auto' ' | |
612 | test_confirm --confirm=auto | |
613 | ' | |
614 | ||
615 | test_expect_success '--confirm=cc' ' | |
616 | test_confirm --confirm=cc | |
617 | ' | |
618 | ||
619 | test_expect_success '--confirm=compose' ' | |
620 | test_confirm --confirm=compose --compose | |
621 | ' | |
622 | ||
623 | test_expect_success 'confirm by default (due to cc)' ' | |
624 | CONFIRM=$(git config --get sendemail.confirm) && | |
625 | git config --unset sendemail.confirm && | |
c18f75a1 JS |
626 | test_confirm |
627 | ret="$?" | |
628 | git config sendemail.confirm ${CONFIRM:-never} | |
629 | test $ret = "0" | |
c1f2aa45 JS |
630 | ' |
631 | ||
632 | test_expect_success 'confirm by default (due to --compose)' ' | |
633 | CONFIRM=$(git config --get sendemail.confirm) && | |
634 | git config --unset sendemail.confirm && | |
635 | test_confirm --suppress-cc=all --compose | |
636 | ret="$?" | |
637 | git config sendemail.confirm ${CONFIRM:-never} | |
638 | test $ret = "0" | |
639 | ' | |
640 | ||
c18f75a1 JS |
641 | test_expect_success 'confirm detects EOF (inform assumes y)' ' |
642 | CONFIRM=$(git config --get sendemail.confirm) && | |
643 | git config --unset sendemail.confirm && | |
dc1460aa JS |
644 | rm -fr outdir && |
645 | git format-patch -2 -o outdir && | |
c18f75a1 JS |
646 | GIT_SEND_EMAIL_NOTTY=1 \ |
647 | git send-email \ | |
648 | --from="Example <nobody@example.com>" \ | |
649 | --to=nobody@example.com \ | |
650 | --smtp-server="$(pwd)/fake.sendmail" \ | |
dc1460aa | 651 | outdir/*.patch < /dev/null |
c18f75a1 JS |
652 | ret="$?" |
653 | git config sendemail.confirm ${CONFIRM:-never} | |
654 | test $ret = "0" | |
655 | ' | |
656 | ||
657 | test_expect_success 'confirm detects EOF (auto causes failure)' ' | |
658 | CONFIRM=$(git config --get sendemail.confirm) && | |
659 | git config sendemail.confirm auto && | |
3b3637c3 JS |
660 | GIT_SEND_EMAIL_NOTTY=1 && |
661 | export GIT_SEND_EMAIL_NOTTY && | |
c18f75a1 JS |
662 | test_must_fail git send-email \ |
663 | --from="Example <nobody@example.com>" \ | |
664 | --to=nobody@example.com \ | |
665 | --smtp-server="$(pwd)/fake.sendmail" \ | |
666 | $patches < /dev/null | |
667 | ret="$?" | |
668 | git config sendemail.confirm ${CONFIRM:-never} | |
669 | test $ret = "0" | |
670 | ' | |
671 | ||
672 | test_expect_success 'confirm doesnt loop forever' ' | |
673 | CONFIRM=$(git config --get sendemail.confirm) && | |
674 | git config sendemail.confirm auto && | |
3b3637c3 JS |
675 | GIT_SEND_EMAIL_NOTTY=1 && |
676 | export GIT_SEND_EMAIL_NOTTY && | |
677 | yes "bogus" | test_must_fail git send-email \ | |
c18f75a1 JS |
678 | --from="Example <nobody@example.com>" \ |
679 | --to=nobody@example.com \ | |
680 | --smtp-server="$(pwd)/fake.sendmail" \ | |
681 | $patches | |
682 | ret="$?" | |
683 | git config sendemail.confirm ${CONFIRM:-never} | |
684 | test $ret = "0" | |
685 | ' | |
686 | ||
a61c0ffa JS |
687 | test_expect_success 'utf8 Cc is rfc2047 encoded' ' |
688 | clean_fake_sendmail && | |
689 | rm -fr outdir && | |
690 | git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" && | |
691 | git send-email \ | |
692 | --from="Example <nobody@example.com>" \ | |
693 | --to=nobody@example.com \ | |
694 | --smtp-server="$(pwd)/fake.sendmail" \ | |
695 | outdir/*.patch && | |
02461e0e | 696 | grep "^ " msgtxt1 | |
d1fff6fc | 697 | grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>" |
a61c0ffa JS |
698 | ' |
699 | ||
0706bd19 JK |
700 | test_expect_success '--compose adds MIME for utf8 body' ' |
701 | clean_fake_sendmail && | |
bb3e4f03 | 702 | (echo "#!$SHELL_PATH" && |
c01cdde1 | 703 | echo "echo utf8 body: àéìöú >>\"\$1\"" |
0706bd19 JK |
704 | ) >fake-editor-utf8 && |
705 | chmod +x fake-editor-utf8 && | |
c01cdde1 | 706 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ |
0706bd19 JK |
707 | git send-email \ |
708 | --compose --subject foo \ | |
709 | --from="Example <nobody@example.com>" \ | |
710 | --to=nobody@example.com \ | |
711 | --smtp-server="$(pwd)/fake.sendmail" \ | |
712 | $patches && | |
713 | grep "^utf8 body" msgtxt1 && | |
d1fff6fc | 714 | grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 |
0706bd19 JK |
715 | ' |
716 | ||
717 | test_expect_success '--compose respects user mime type' ' | |
718 | clean_fake_sendmail && | |
bb3e4f03 | 719 | (echo "#!$SHELL_PATH" && |
0706bd19 JK |
720 | echo "(echo MIME-Version: 1.0" |
721 | echo " echo Content-Type: text/plain\\; charset=iso-8859-1" | |
722 | echo " echo Content-Transfer-Encoding: 8bit" | |
723 | echo " echo Subject: foo" | |
724 | echo " echo " | |
c01cdde1 | 725 | echo " echo utf8 body: àéìöú) >\"\$1\"" |
0706bd19 JK |
726 | ) >fake-editor-utf8-mime && |
727 | chmod +x fake-editor-utf8-mime && | |
c01cdde1 | 728 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \ |
0706bd19 JK |
729 | git send-email \ |
730 | --compose --subject foo \ | |
731 | --from="Example <nobody@example.com>" \ | |
732 | --to=nobody@example.com \ | |
733 | --smtp-server="$(pwd)/fake.sendmail" \ | |
734 | $patches && | |
735 | grep "^utf8 body" msgtxt1 && | |
736 | grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 && | |
d1fff6fc | 737 | ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 |
0706bd19 JK |
738 | ' |
739 | ||
d54eaaa2 JK |
740 | test_expect_success '--compose adds MIME for utf8 subject' ' |
741 | clean_fake_sendmail && | |
c01cdde1 | 742 | GIT_EDITOR="\"$(pwd)/fake-editor\"" \ |
d54eaaa2 JK |
743 | git send-email \ |
744 | --compose --subject utf8-sübjëct \ | |
745 | --from="Example <nobody@example.com>" \ | |
746 | --to=nobody@example.com \ | |
747 | --smtp-server="$(pwd)/fake.sendmail" \ | |
748 | $patches && | |
749 | grep "^fake edit" msgtxt1 && | |
d1fff6fc | 750 | grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 |
d54eaaa2 JK |
751 | ' |
752 | ||
5df9fcf6 PH |
753 | test_expect_success 'detects ambiguous reference/file conflict' ' |
754 | echo master > master && | |
755 | git add master && | |
756 | git commit -m"add master" && | |
757 | test_must_fail git send-email --dry-run master 2>errors && | |
758 | grep disambiguate errors | |
759 | ' | |
760 | ||
69f4ce55 JH |
761 | test_expect_success 'feed two files' ' |
762 | rm -fr outdir && | |
763 | git format-patch -2 -o outdir && | |
c1f2aa45 | 764 | git send-email \ |
69f4ce55 JH |
765 | --dry-run \ |
766 | --from="Example <nobody@example.com>" \ | |
767 | --to=nobody@example.com \ | |
768 | outdir/000?-*.patch 2>errors >out && | |
769 | grep "^Subject: " out >subjects && | |
770 | test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." && | |
771 | test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master" | |
772 | ' | |
773 | ||
aaab4b9f TR |
774 | test_expect_success 'in-reply-to but no threading' ' |
775 | git send-email \ | |
776 | --dry-run \ | |
777 | --from="Example <nobody@example.com>" \ | |
778 | --to=nobody@example.com \ | |
779 | --in-reply-to="<in-reply-id@example.com>" \ | |
84eeb687 | 780 | --nothread \ |
aaab4b9f TR |
781 | $patches | |
782 | grep "In-Reply-To: <in-reply-id@example.com>" | |
783 | ' | |
784 | ||
5e9758e2 | 785 | test_expect_success 'no in-reply-to and no threading' ' |
32ae8319 MH |
786 | git send-email \ |
787 | --dry-run \ | |
788 | --from="Example <nobody@example.com>" \ | |
789 | --to=nobody@example.com \ | |
790 | --nothread \ | |
791 | $patches $patches >stdout && | |
792 | ! grep "In-Reply-To: " stdout | |
793 | ' | |
794 | ||
f74fe34b | 795 | test_expect_success 'threading but no chain-reply-to' ' |
d67114a5 MH |
796 | git send-email \ |
797 | --dry-run \ | |
798 | --from="Example <nobody@example.com>" \ | |
799 | --to=nobody@example.com \ | |
800 | --thread \ | |
801 | --nochain-reply-to \ | |
802 | $patches $patches >stdout && | |
803 | grep "In-Reply-To: " stdout | |
804 | ' | |
805 | ||
528fb087 NS |
806 | test_expect_success 'warning with an implicit --chain-reply-to' ' |
807 | git send-email \ | |
808 | --dry-run \ | |
809 | --from="Example <nobody@example.com>" \ | |
810 | --to=nobody@example.com \ | |
811 | outdir/000?-*.patch 2>errors >out && | |
812 | grep "no-chain-reply-to" errors | |
813 | ' | |
814 | ||
815 | test_expect_success 'no warning with an explicit --chain-reply-to' ' | |
816 | git send-email \ | |
817 | --dry-run \ | |
818 | --from="Example <nobody@example.com>" \ | |
819 | --to=nobody@example.com \ | |
820 | --chain-reply-to \ | |
821 | outdir/000?-*.patch 2>errors >out && | |
822 | ! grep "no-chain-reply-to" errors | |
823 | ' | |
824 | ||
825 | test_expect_success 'no warning with an explicit --no-chain-reply-to' ' | |
826 | git send-email \ | |
827 | --dry-run \ | |
828 | --from="Example <nobody@example.com>" \ | |
829 | --to=nobody@example.com \ | |
907a0b1e | 830 | --nochain-reply-to \ |
528fb087 NS |
831 | outdir/000?-*.patch 2>errors >out && |
832 | ! grep "no-chain-reply-to" errors | |
833 | ' | |
834 | ||
835 | test_expect_success 'no warning with sendemail.chainreplyto = false' ' | |
836 | git config sendemail.chainreplyto false && | |
837 | git send-email \ | |
838 | --dry-run \ | |
839 | --from="Example <nobody@example.com>" \ | |
840 | --to=nobody@example.com \ | |
841 | outdir/000?-*.patch 2>errors >out && | |
842 | ! grep "no-chain-reply-to" errors | |
843 | ' | |
844 | ||
845 | test_expect_success 'no warning with sendemail.chainreplyto = true' ' | |
846 | git config sendemail.chainreplyto true && | |
847 | git send-email \ | |
848 | --dry-run \ | |
849 | --from="Example <nobody@example.com>" \ | |
850 | --to=nobody@example.com \ | |
851 | outdir/000?-*.patch 2>errors >out && | |
852 | ! grep "no-chain-reply-to" errors | |
853 | ' | |
854 | ||
f434c083 SB |
855 | test_expect_success 'sendemail.to works' ' |
856 | git config --replace-all sendemail.to "Somebody <somebody@ex.com>" && | |
857 | git send-email \ | |
858 | --dry-run \ | |
859 | --from="Example <nobody@example.com>" \ | |
860 | $patches $patches >stdout && | |
861 | grep "To: Somebody <somebody@ex.com>" stdout | |
862 | ' | |
863 | ||
864 | test_expect_success '--no-to overrides sendemail.to' ' | |
865 | git send-email \ | |
866 | --dry-run \ | |
867 | --from="Example <nobody@example.com>" \ | |
868 | --no-to \ | |
869 | --to=nobody@example.com \ | |
870 | $patches $patches >stdout && | |
871 | grep "To: nobody@example.com" stdout && | |
872 | ! grep "To: Somebody <somebody@ex.com>" stdout | |
873 | ' | |
874 | ||
875 | test_expect_success 'sendemail.cc works' ' | |
876 | git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" && | |
877 | git send-email \ | |
878 | --dry-run \ | |
879 | --from="Example <nobody@example.com>" \ | |
880 | --to=nobody@example.com \ | |
881 | $patches $patches >stdout && | |
882 | grep "Cc: Somebody <somebody@ex.com>" stdout | |
883 | ' | |
884 | ||
885 | test_expect_success '--no-cc overrides sendemail.cc' ' | |
886 | git send-email \ | |
887 | --dry-run \ | |
888 | --from="Example <nobody@example.com>" \ | |
889 | --no-cc \ | |
890 | --cc=bodies@example.com \ | |
891 | --to=nobody@example.com \ | |
892 | $patches $patches >stdout && | |
893 | grep "Cc: bodies@example.com" stdout && | |
894 | ! grep "Cc: Somebody <somebody@ex.com>" stdout | |
895 | ' | |
896 | ||
897 | test_expect_success 'sendemail.bcc works' ' | |
898 | git config --replace-all sendemail.bcc "Other <other@ex.com>" && | |
899 | git send-email \ | |
900 | --dry-run \ | |
901 | --from="Example <nobody@example.com>" \ | |
902 | --to=nobody@example.com \ | |
903 | --smtp-server relay.example.com \ | |
904 | $patches $patches >stdout && | |
905 | grep "RCPT TO:<other@ex.com>" stdout | |
906 | ' | |
907 | ||
908 | test_expect_success '--no-bcc overrides sendemail.bcc' ' | |
909 | git send-email \ | |
910 | --dry-run \ | |
911 | --from="Example <nobody@example.com>" \ | |
912 | --no-bcc \ | |
913 | --bcc=bodies@example.com \ | |
914 | --to=nobody@example.com \ | |
915 | --smtp-server relay.example.com \ | |
916 | $patches $patches >stdout && | |
917 | grep "RCPT TO:<bodies@example.com>" stdout && | |
918 | ! grep "RCPT TO:<other@ex.com>" stdout | |
919 | ' | |
920 | ||
ce903018 | 921 | test_done |