]>
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 | |
b7f30e0a DK |
98 | cat >expected-show-all-headers <<\EOF |
99 | 0001-Second.patch | |
100 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
5012699d JS |
101 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
102 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
b7f30e0a DK |
103 | Dry-OK. Log says: |
104 | Server: relay.example.com | |
105 | MAIL FROM:<from@example.com> | |
5012699d | 106 | RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<bcc@example.com> |
b7f30e0a DK |
107 | From: Example <from@example.com> |
108 | To: to@example.com | |
5012699d | 109 | Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com |
b7f30e0a DK |
110 | Subject: [PATCH 1/1] Second. |
111 | Date: DATE-STRING | |
112 | Message-Id: MESSAGE-ID-STRING | |
113 | X-Mailer: X-MAILER-STRING | |
114 | In-Reply-To: <unique-message-id@example.com> | |
115 | References: <unique-message-id@example.com> | |
116 | ||
117 | Result: OK | |
118 | EOF | |
119 | ||
120 | test_expect_success 'Show all headers' ' | |
121 | git send-email \ | |
122 | --dry-run \ | |
3531e270 | 123 | --suppress-cc=sob \ |
b7f30e0a DK |
124 | --from="Example <from@example.com>" \ |
125 | --to=to@example.com \ | |
126 | --cc=cc@example.com \ | |
127 | --bcc=bcc@example.com \ | |
128 | --in-reply-to="<unique-message-id@example.com>" \ | |
129 | --smtp-server relay.example.com \ | |
130 | $patches | | |
131 | sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ | |
132 | -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ | |
133 | -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ | |
134 | >actual-show-all-headers && | |
82ebb0b6 | 135 | test_cmp expected-show-all-headers actual-show-all-headers |
b7f30e0a DK |
136 | ' |
137 | ||
0da43a68 JS |
138 | test_expect_success 'Prompting works' ' |
139 | clean_fake_sendmail && | |
140 | (echo "Example <from@example.com>" | |
141 | echo "to@example.com" | |
142 | echo "" | |
143 | ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
144 | --smtp-server="$(pwd)/fake.sendmail" \ | |
145 | $patches \ | |
146 | 2>errors && | |
147 | grep "^From: Example <from@example.com>$" msgtxt1 && | |
148 | grep "^To: to@example.com$" msgtxt1 | |
149 | ' | |
150 | ||
cb8a9bd5 PB |
151 | test_expect_success 'cccmd works' ' |
152 | clean_fake_sendmail && | |
153 | cp $patches cccmd.patch && | |
154 | echo cccmd--cccmd@example.com >>cccmd.patch && | |
977e289e BC |
155 | { |
156 | echo "#!$SHELL_PATH" | |
157 | echo sed -n -e s/^cccmd--//p \"\$1\" | |
158 | } > cccmd-sed && | |
cb8a9bd5 PB |
159 | chmod +x cccmd-sed && |
160 | git send-email \ | |
161 | --from="Example <nobody@example.com>" \ | |
162 | --to=nobody@example.com \ | |
163 | --cc-cmd=./cccmd-sed \ | |
164 | --smtp-server="$(pwd)/fake.sendmail" \ | |
165 | cccmd.patch \ | |
166 | && | |
167 | grep ^Cc:.*cccmd@example.com msgtxt1 | |
168 | ' | |
169 | ||
747bbff9 JK |
170 | z8=zzzzzzzz |
171 | z64=$z8$z8$z8$z8$z8$z8$z8$z8 | |
172 | z512=$z64$z64$z64$z64$z64$z64$z64$z64 | |
173 | test_expect_success 'reject long lines' ' | |
6d34a2ba | 174 | clean_fake_sendmail && |
747bbff9 JK |
175 | cp $patches longline.patch && |
176 | echo $z512$z512 >>longline.patch && | |
d492b31c | 177 | test_must_fail git send-email \ |
747bbff9 JK |
178 | --from="Example <nobody@example.com>" \ |
179 | --to=nobody@example.com \ | |
180 | --smtp-server="$(pwd)/fake.sendmail" \ | |
181 | $patches longline.patch \ | |
182 | 2>errors && | |
183 | grep longline.patch errors | |
184 | ' | |
185 | ||
186 | test_expect_success 'no patch was sent' ' | |
6d34a2ba | 187 | ! test -e commandline1 |
747bbff9 JK |
188 | ' |
189 | ||
5012699d JS |
190 | test_expect_success 'Author From: in message body' ' |
191 | clean_fake_sendmail && | |
192 | git send-email \ | |
193 | --from="Example <nobody@example.com>" \ | |
194 | --to=nobody@example.com \ | |
195 | --smtp-server="$(pwd)/fake.sendmail" \ | |
196 | $patches && | |
197 | sed "1,/^$/d" < msgtxt1 > msgbody1 | |
198 | grep "From: A <author@example.com>" msgbody1 | |
199 | ' | |
200 | ||
201 | test_expect_success 'Author From: not in message body' ' | |
202 | clean_fake_sendmail && | |
203 | git send-email \ | |
204 | --from="A <author@example.com>" \ | |
205 | --to=nobody@example.com \ | |
206 | --smtp-server="$(pwd)/fake.sendmail" \ | |
207 | $patches && | |
208 | sed "1,/^$/d" < msgtxt1 > msgbody1 | |
209 | ! grep "From: A <author@example.com>" msgbody1 | |
210 | ' | |
211 | ||
c764a0c2 JK |
212 | test_expect_success 'allow long lines with --no-validate' ' |
213 | git send-email \ | |
214 | --from="Example <nobody@example.com>" \ | |
215 | --to=nobody@example.com \ | |
216 | --smtp-server="$(pwd)/fake.sendmail" \ | |
3fee1fe8 | 217 | --novalidate \ |
c764a0c2 JK |
218 | $patches longline.patch \ |
219 | 2>errors | |
220 | ' | |
221 | ||
0fb7fc75 | 222 | test_expect_success 'Invalid In-Reply-To' ' |
6d34a2ba | 223 | clean_fake_sendmail && |
0fb7fc75 JS |
224 | git send-email \ |
225 | --from="Example <nobody@example.com>" \ | |
226 | --to=nobody@example.com \ | |
227 | --in-reply-to=" " \ | |
228 | --smtp-server="$(pwd)/fake.sendmail" \ | |
229 | $patches | |
230 | 2>errors | |
6d34a2ba | 231 | ! grep "^In-Reply-To: < *>" msgtxt1 |
0fb7fc75 JS |
232 | ' |
233 | ||
234 | test_expect_success 'Valid In-Reply-To when prompting' ' | |
6d34a2ba | 235 | clean_fake_sendmail && |
0fb7fc75 JS |
236 | (echo "From Example <from@example.com>" |
237 | echo "To Example <to@example.com>" | |
238 | echo "" | |
239 | ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \ | |
240 | --smtp-server="$(pwd)/fake.sendmail" \ | |
241 | $patches 2>errors && | |
6d34a2ba | 242 | ! grep "^In-Reply-To: < *>" msgtxt1 |
0fb7fc75 JS |
243 | ' |
244 | ||
8a8bf469 | 245 | test_expect_success 'setup fake editor' ' |
bb3e4f03 | 246 | (echo "#!$SHELL_PATH" && |
065096c2 | 247 | echo "echo fake edit >>\"\$1\"" |
8a8bf469 JK |
248 | ) >fake-editor && |
249 | chmod +x fake-editor | |
250 | ' | |
251 | ||
7f0475c3 | 252 | test_set_editor "$(pwd)/fake-editor" |
065096c2 | 253 | |
8a8bf469 JK |
254 | test_expect_success '--compose works' ' |
255 | clean_fake_sendmail && | |
c1f2aa45 JS |
256 | git send-email \ |
257 | --compose --subject foo \ | |
258 | --from="Example <nobody@example.com>" \ | |
259 | --to=nobody@example.com \ | |
260 | --smtp-server="$(pwd)/fake.sendmail" \ | |
261 | $patches \ | |
262 | 2>errors | |
8a8bf469 JK |
263 | ' |
264 | ||
265 | test_expect_success 'first message is compose text' ' | |
266 | grep "^fake edit" msgtxt1 | |
267 | ' | |
268 | ||
269 | test_expect_success 'second message is patch' ' | |
270 | grep "Subject:.*Second" msgtxt2 | |
271 | ' | |
272 | ||
3531e270 | 273 | cat >expected-suppress-sob <<\EOF |
33c592dd MV |
274 | 0001-Second.patch |
275 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
5012699d JS |
276 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
277 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
33c592dd MV |
278 | Dry-OK. Log says: |
279 | Server: relay.example.com | |
280 | MAIL FROM:<from@example.com> | |
5012699d | 281 | RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com> |
33c592dd MV |
282 | From: Example <from@example.com> |
283 | To: to@example.com | |
5012699d | 284 | Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com |
33c592dd MV |
285 | Subject: [PATCH 1/1] Second. |
286 | Date: DATE-STRING | |
287 | Message-Id: MESSAGE-ID-STRING | |
288 | X-Mailer: X-MAILER-STRING | |
289 | ||
290 | Result: OK | |
291 | EOF | |
292 | ||
3531e270 | 293 | test_suppression () { |
33c592dd MV |
294 | git send-email \ |
295 | --dry-run \ | |
cb8a9bd5 | 296 | --suppress-cc=$1 ${2+"--suppress-cc=$2"} \ |
33c592dd MV |
297 | --from="Example <from@example.com>" \ |
298 | --to=to@example.com \ | |
299 | --smtp-server relay.example.com \ | |
300 | $patches | | |
301 | sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ | |
302 | -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ | |
303 | -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ | |
cb8a9bd5 PB |
304 | >actual-suppress-$1${2+"-$2"} && |
305 | test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"} | |
3531e270 JS |
306 | } |
307 | ||
308 | test_expect_success 'sendemail.cc set' ' | |
309 | git config sendemail.cc cc@example.com && | |
310 | test_suppression sob | |
33c592dd MV |
311 | ' |
312 | ||
3531e270 | 313 | cat >expected-suppress-sob <<\EOF |
33c592dd MV |
314 | 0001-Second.patch |
315 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
5012699d JS |
316 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' |
317 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
33c592dd MV |
318 | Dry-OK. Log says: |
319 | Server: relay.example.com | |
320 | MAIL FROM:<from@example.com> | |
5012699d | 321 | RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com> |
33c592dd MV |
322 | From: Example <from@example.com> |
323 | To: to@example.com | |
5012699d | 324 | Cc: A <author@example.com>, One <one@example.com>, two@example.com |
33c592dd MV |
325 | Subject: [PATCH 1/1] Second. |
326 | Date: DATE-STRING | |
327 | Message-Id: MESSAGE-ID-STRING | |
328 | X-Mailer: X-MAILER-STRING | |
329 | ||
330 | Result: OK | |
331 | EOF | |
332 | ||
333 | test_expect_success 'sendemail.cc unset' ' | |
334 | git config --unset sendemail.cc && | |
3531e270 JS |
335 | test_suppression sob |
336 | ' | |
337 | ||
cb8a9bd5 PB |
338 | cat >expected-suppress-cccmd <<\EOF |
339 | 0001-Second.patch | |
340 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
341 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
342 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
343 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
344 | Dry-OK. Log says: | |
345 | Server: relay.example.com | |
346 | MAIL FROM:<from@example.com> | |
347 | RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com> | |
348 | From: Example <from@example.com> | |
349 | To: to@example.com | |
350 | Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com> | |
351 | Subject: [PATCH 1/1] Second. | |
352 | Date: DATE-STRING | |
353 | Message-Id: MESSAGE-ID-STRING | |
354 | X-Mailer: X-MAILER-STRING | |
355 | ||
356 | Result: OK | |
357 | EOF | |
358 | ||
359 | test_expect_success 'sendemail.cccmd' ' | |
360 | echo echo cc-cmd@example.com > cccmd && | |
361 | chmod +x cccmd && | |
362 | git config sendemail.cccmd ./cccmd && | |
363 | test_suppression cccmd | |
364 | ' | |
365 | ||
3531e270 JS |
366 | cat >expected-suppress-all <<\EOF |
367 | 0001-Second.patch | |
368 | Dry-OK. Log says: | |
369 | Server: relay.example.com | |
370 | MAIL FROM:<from@example.com> | |
371 | RCPT TO:<to@example.com> | |
372 | From: Example <from@example.com> | |
373 | To: to@example.com | |
374 | Subject: [PATCH 1/1] Second. | |
375 | Date: DATE-STRING | |
376 | Message-Id: MESSAGE-ID-STRING | |
377 | X-Mailer: X-MAILER-STRING | |
378 | ||
379 | Result: OK | |
380 | EOF | |
381 | ||
382 | test_expect_success '--suppress-cc=all' ' | |
383 | test_suppression all | |
384 | ' | |
385 | ||
386 | cat >expected-suppress-body <<\EOF | |
387 | 0001-Second.patch | |
388 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
389 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
390 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
cb8a9bd5 | 391 | (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd' |
3531e270 JS |
392 | Dry-OK. Log says: |
393 | Server: relay.example.com | |
394 | MAIL FROM:<from@example.com> | |
cb8a9bd5 | 395 | RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<cc-cmd@example.com> |
3531e270 JS |
396 | From: Example <from@example.com> |
397 | To: to@example.com | |
cb8a9bd5 | 398 | Cc: A <author@example.com>, One <one@example.com>, two@example.com, cc-cmd@example.com |
3531e270 JS |
399 | Subject: [PATCH 1/1] Second. |
400 | Date: DATE-STRING | |
401 | Message-Id: MESSAGE-ID-STRING | |
402 | X-Mailer: X-MAILER-STRING | |
403 | ||
404 | Result: OK | |
405 | EOF | |
406 | ||
407 | test_expect_success '--suppress-cc=body' ' | |
408 | test_suppression body | |
409 | ' | |
410 | ||
cb8a9bd5 PB |
411 | cat >expected-suppress-body-cccmd <<\EOF |
412 | 0001-Second.patch | |
413 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
414 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
415 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
416 | Dry-OK. Log says: | |
417 | Server: relay.example.com | |
418 | MAIL FROM:<from@example.com> | |
419 | RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com> | |
420 | From: Example <from@example.com> | |
421 | To: to@example.com | |
422 | Cc: A <author@example.com>, One <one@example.com>, two@example.com | |
423 | Subject: [PATCH 1/1] Second. | |
424 | Date: DATE-STRING | |
425 | Message-Id: MESSAGE-ID-STRING | |
426 | X-Mailer: X-MAILER-STRING | |
427 | ||
428 | Result: OK | |
429 | EOF | |
430 | ||
431 | test_expect_success '--suppress-cc=body --suppress-cc=cccmd' ' | |
432 | test_suppression body cccmd | |
433 | ' | |
434 | ||
3531e270 JS |
435 | cat >expected-suppress-sob <<\EOF |
436 | 0001-Second.patch | |
437 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
438 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
439 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
440 | Dry-OK. Log says: | |
441 | Server: relay.example.com | |
442 | MAIL FROM:<from@example.com> | |
443 | RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com> | |
444 | From: Example <from@example.com> | |
445 | To: to@example.com | |
446 | Cc: A <author@example.com>, One <one@example.com>, two@example.com | |
447 | Subject: [PATCH 1/1] Second. | |
448 | Date: DATE-STRING | |
449 | Message-Id: MESSAGE-ID-STRING | |
450 | X-Mailer: X-MAILER-STRING | |
451 | ||
452 | Result: OK | |
453 | EOF | |
454 | ||
455 | test_expect_success '--suppress-cc=sob' ' | |
cb8a9bd5 | 456 | git config --unset sendemail.cccmd |
3531e270 JS |
457 | test_suppression sob |
458 | ' | |
459 | ||
460 | cat >expected-suppress-bodycc <<\EOF | |
461 | 0001-Second.patch | |
462 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
463 | (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' | |
464 | (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' | |
465 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
466 | Dry-OK. Log says: | |
467 | Server: relay.example.com | |
468 | MAIL FROM:<from@example.com> | |
469 | RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com> | |
470 | From: Example <from@example.com> | |
471 | To: to@example.com | |
472 | Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com> | |
473 | Subject: [PATCH 1/1] Second. | |
474 | Date: DATE-STRING | |
475 | Message-Id: MESSAGE-ID-STRING | |
476 | X-Mailer: X-MAILER-STRING | |
477 | ||
478 | Result: OK | |
479 | EOF | |
480 | ||
481 | test_expect_success '--suppress-cc=bodycc' ' | |
482 | test_suppression bodycc | |
483 | ' | |
484 | ||
485 | cat >expected-suppress-cc <<\EOF | |
486 | 0001-Second.patch | |
487 | (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' | |
488 | (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' | |
489 | Dry-OK. Log says: | |
490 | Server: relay.example.com | |
491 | MAIL FROM:<from@example.com> | |
492 | RCPT TO:<to@example.com>,<author@example.com>,<committer@example.com> | |
493 | From: Example <from@example.com> | |
494 | To: to@example.com | |
495 | Cc: A <author@example.com>, C O Mitter <committer@example.com> | |
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=cc' ' | |
505 | test_suppression cc | |
33c592dd MV |
506 | ' |
507 | ||
c1f2aa45 JS |
508 | test_confirm () { |
509 | echo y | \ | |
510 | GIT_SEND_EMAIL_NOTTY=1 \ | |
511 | git send-email \ | |
512 | --from="Example <nobody@example.com>" \ | |
513 | --to=nobody@example.com \ | |
514 | --smtp-server="$(pwd)/fake.sendmail" \ | |
c18f75a1 JS |
515 | $@ $patches > stdout && |
516 | grep "Send this email" stdout | |
c1f2aa45 JS |
517 | } |
518 | ||
519 | test_expect_success '--confirm=always' ' | |
520 | test_confirm --confirm=always --suppress-cc=all | |
521 | ' | |
522 | ||
523 | test_expect_success '--confirm=auto' ' | |
524 | test_confirm --confirm=auto | |
525 | ' | |
526 | ||
527 | test_expect_success '--confirm=cc' ' | |
528 | test_confirm --confirm=cc | |
529 | ' | |
530 | ||
531 | test_expect_success '--confirm=compose' ' | |
532 | test_confirm --confirm=compose --compose | |
533 | ' | |
534 | ||
535 | test_expect_success 'confirm by default (due to cc)' ' | |
536 | CONFIRM=$(git config --get sendemail.confirm) && | |
537 | git config --unset sendemail.confirm && | |
c18f75a1 JS |
538 | test_confirm |
539 | ret="$?" | |
540 | git config sendemail.confirm ${CONFIRM:-never} | |
541 | test $ret = "0" | |
c1f2aa45 JS |
542 | ' |
543 | ||
544 | test_expect_success 'confirm by default (due to --compose)' ' | |
545 | CONFIRM=$(git config --get sendemail.confirm) && | |
546 | git config --unset sendemail.confirm && | |
547 | test_confirm --suppress-cc=all --compose | |
548 | ret="$?" | |
549 | git config sendemail.confirm ${CONFIRM:-never} | |
550 | test $ret = "0" | |
551 | ' | |
552 | ||
c18f75a1 JS |
553 | test_expect_success 'confirm detects EOF (inform assumes y)' ' |
554 | CONFIRM=$(git config --get sendemail.confirm) && | |
555 | git config --unset sendemail.confirm && | |
dc1460aa JS |
556 | rm -fr outdir && |
557 | git format-patch -2 -o outdir && | |
c18f75a1 JS |
558 | GIT_SEND_EMAIL_NOTTY=1 \ |
559 | git send-email \ | |
560 | --from="Example <nobody@example.com>" \ | |
561 | --to=nobody@example.com \ | |
562 | --smtp-server="$(pwd)/fake.sendmail" \ | |
dc1460aa | 563 | outdir/*.patch < /dev/null |
c18f75a1 JS |
564 | ret="$?" |
565 | git config sendemail.confirm ${CONFIRM:-never} | |
566 | test $ret = "0" | |
567 | ' | |
568 | ||
569 | test_expect_success 'confirm detects EOF (auto causes failure)' ' | |
570 | CONFIRM=$(git config --get sendemail.confirm) && | |
571 | git config sendemail.confirm auto && | |
3b3637c3 JS |
572 | GIT_SEND_EMAIL_NOTTY=1 && |
573 | export GIT_SEND_EMAIL_NOTTY && | |
c18f75a1 JS |
574 | test_must_fail git send-email \ |
575 | --from="Example <nobody@example.com>" \ | |
576 | --to=nobody@example.com \ | |
577 | --smtp-server="$(pwd)/fake.sendmail" \ | |
578 | $patches < /dev/null | |
579 | ret="$?" | |
580 | git config sendemail.confirm ${CONFIRM:-never} | |
581 | test $ret = "0" | |
582 | ' | |
583 | ||
584 | test_expect_success 'confirm doesnt loop forever' ' | |
585 | CONFIRM=$(git config --get sendemail.confirm) && | |
586 | git config sendemail.confirm auto && | |
3b3637c3 JS |
587 | GIT_SEND_EMAIL_NOTTY=1 && |
588 | export GIT_SEND_EMAIL_NOTTY && | |
589 | yes "bogus" | test_must_fail git send-email \ | |
c18f75a1 JS |
590 | --from="Example <nobody@example.com>" \ |
591 | --to=nobody@example.com \ | |
592 | --smtp-server="$(pwd)/fake.sendmail" \ | |
593 | $patches | |
594 | ret="$?" | |
595 | git config sendemail.confirm ${CONFIRM:-never} | |
596 | test $ret = "0" | |
597 | ' | |
598 | ||
a61c0ffa JS |
599 | test_expect_success 'utf8 Cc is rfc2047 encoded' ' |
600 | clean_fake_sendmail && | |
601 | rm -fr outdir && | |
602 | git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" && | |
603 | git send-email \ | |
604 | --from="Example <nobody@example.com>" \ | |
605 | --to=nobody@example.com \ | |
606 | --smtp-server="$(pwd)/fake.sendmail" \ | |
607 | outdir/*.patch && | |
608 | grep "^Cc:" msgtxt1 | | |
d1fff6fc | 609 | grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>" |
a61c0ffa JS |
610 | ' |
611 | ||
0706bd19 JK |
612 | test_expect_success '--compose adds MIME for utf8 body' ' |
613 | clean_fake_sendmail && | |
bb3e4f03 | 614 | (echo "#!$SHELL_PATH" && |
c01cdde1 | 615 | echo "echo utf8 body: àéìöú >>\"\$1\"" |
0706bd19 JK |
616 | ) >fake-editor-utf8 && |
617 | chmod +x fake-editor-utf8 && | |
c01cdde1 | 618 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \ |
0706bd19 JK |
619 | git send-email \ |
620 | --compose --subject foo \ | |
621 | --from="Example <nobody@example.com>" \ | |
622 | --to=nobody@example.com \ | |
623 | --smtp-server="$(pwd)/fake.sendmail" \ | |
624 | $patches && | |
625 | grep "^utf8 body" msgtxt1 && | |
d1fff6fc | 626 | grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 |
0706bd19 JK |
627 | ' |
628 | ||
629 | test_expect_success '--compose respects user mime type' ' | |
630 | clean_fake_sendmail && | |
bb3e4f03 | 631 | (echo "#!$SHELL_PATH" && |
0706bd19 JK |
632 | echo "(echo MIME-Version: 1.0" |
633 | echo " echo Content-Type: text/plain\\; charset=iso-8859-1" | |
634 | echo " echo Content-Transfer-Encoding: 8bit" | |
635 | echo " echo Subject: foo" | |
636 | echo " echo " | |
c01cdde1 | 637 | echo " echo utf8 body: àéìöú) >\"\$1\"" |
0706bd19 JK |
638 | ) >fake-editor-utf8-mime && |
639 | chmod +x fake-editor-utf8-mime && | |
c01cdde1 | 640 | GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \ |
0706bd19 JK |
641 | git send-email \ |
642 | --compose --subject foo \ | |
643 | --from="Example <nobody@example.com>" \ | |
644 | --to=nobody@example.com \ | |
645 | --smtp-server="$(pwd)/fake.sendmail" \ | |
646 | $patches && | |
647 | grep "^utf8 body" msgtxt1 && | |
648 | grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 && | |
d1fff6fc | 649 | ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 |
0706bd19 JK |
650 | ' |
651 | ||
d54eaaa2 JK |
652 | test_expect_success '--compose adds MIME for utf8 subject' ' |
653 | clean_fake_sendmail && | |
c01cdde1 | 654 | GIT_EDITOR="\"$(pwd)/fake-editor\"" \ |
d54eaaa2 JK |
655 | git send-email \ |
656 | --compose --subject utf8-sübjëct \ | |
657 | --from="Example <nobody@example.com>" \ | |
658 | --to=nobody@example.com \ | |
659 | --smtp-server="$(pwd)/fake.sendmail" \ | |
660 | $patches && | |
661 | grep "^fake edit" msgtxt1 && | |
d1fff6fc | 662 | grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 |
d54eaaa2 JK |
663 | ' |
664 | ||
5df9fcf6 PH |
665 | test_expect_success 'detects ambiguous reference/file conflict' ' |
666 | echo master > master && | |
667 | git add master && | |
668 | git commit -m"add master" && | |
669 | test_must_fail git send-email --dry-run master 2>errors && | |
670 | grep disambiguate errors | |
671 | ' | |
672 | ||
69f4ce55 JH |
673 | test_expect_success 'feed two files' ' |
674 | rm -fr outdir && | |
675 | git format-patch -2 -o outdir && | |
c1f2aa45 | 676 | git send-email \ |
69f4ce55 JH |
677 | --dry-run \ |
678 | --from="Example <nobody@example.com>" \ | |
679 | --to=nobody@example.com \ | |
680 | outdir/000?-*.patch 2>errors >out && | |
681 | grep "^Subject: " out >subjects && | |
682 | test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." && | |
683 | test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master" | |
684 | ' | |
685 | ||
aaab4b9f TR |
686 | test_expect_success 'in-reply-to but no threading' ' |
687 | git send-email \ | |
688 | --dry-run \ | |
689 | --from="Example <nobody@example.com>" \ | |
690 | --to=nobody@example.com \ | |
691 | --in-reply-to="<in-reply-id@example.com>" \ | |
84eeb687 | 692 | --nothread \ |
aaab4b9f TR |
693 | $patches | |
694 | grep "In-Reply-To: <in-reply-id@example.com>" | |
695 | ' | |
696 | ||
5e9758e2 | 697 | test_expect_success 'no in-reply-to and no threading' ' |
32ae8319 MH |
698 | git send-email \ |
699 | --dry-run \ | |
700 | --from="Example <nobody@example.com>" \ | |
701 | --to=nobody@example.com \ | |
702 | --nothread \ | |
703 | $patches $patches >stdout && | |
704 | ! grep "In-Reply-To: " stdout | |
705 | ' | |
706 | ||
f74fe34b | 707 | test_expect_success 'threading but no chain-reply-to' ' |
d67114a5 MH |
708 | git send-email \ |
709 | --dry-run \ | |
710 | --from="Example <nobody@example.com>" \ | |
711 | --to=nobody@example.com \ | |
712 | --thread \ | |
713 | --nochain-reply-to \ | |
714 | $patches $patches >stdout && | |
715 | grep "In-Reply-To: " stdout | |
716 | ' | |
717 | ||
ce903018 | 718 | test_done |