Code

4df4f965cb0f2220ea9acf769c4fabf1248ab9a1
[git.git] / t / t9001-send-email.sh
1 #!/bin/sh
3 test_description='git send-email'
4 . ./test-lib.sh
6 PROG='git send-email'
7 test_expect_success \
8     'prepare reference tree' \
9     'echo "1A quick brown fox jumps over the" >file &&
10      echo "lazy dog" >>file &&
11      git add file &&
12      GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
14 test_expect_success \
15     'Setup helper tool' \
16     '(echo "#!$SHELL_PATH"
17       echo shift
18       echo output=1
19       echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
20       echo for a
21       echo do
22       echo "  echo \"!\$a!\""
23       echo "done >commandline\$output"
24       echo "cat > msgtxt\$output"
25       ) >fake.sendmail &&
26      chmod +x ./fake.sendmail &&
27      git add fake.sendmail &&
28      GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
30 clean_fake_sendmail() {
31         rm -f commandline* msgtxt*
32 }
34 test_expect_success 'Extract patches' '
35     patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
36 '
38 test_expect_success 'Send patches' '
39      git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
40 '
42 cat >expected <<\EOF
43 !nobody@example.com!
44 !author@example.com!
45 !one@example.com!
46 !two@example.com!
47 EOF
48 test_expect_success \
49     'Verify commandline' \
50     'diff commandline1 expected'
52 cat >expected-show-all-headers <<\EOF
53 0001-Second.patch
54 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
55 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
56 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
57 Dry-OK. Log says:
58 Server: relay.example.com
59 MAIL FROM:<from@example.com>
60 RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<bcc@example.com>
61 From: Example <from@example.com>
62 To: to@example.com
63 Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
64 Subject: [PATCH 1/1] Second.
65 Date: DATE-STRING
66 Message-Id: MESSAGE-ID-STRING
67 X-Mailer: X-MAILER-STRING
68 In-Reply-To: <unique-message-id@example.com>
69 References: <unique-message-id@example.com>
71 Result: OK
72 EOF
74 test_expect_success 'Show all headers' '
75         git send-email \
76                 --dry-run \
77                 --suppress-cc=sob \
78                 --from="Example <from@example.com>" \
79                 --to=to@example.com \
80                 --cc=cc@example.com \
81                 --bcc=bcc@example.com \
82                 --in-reply-to="<unique-message-id@example.com>" \
83                 --smtp-server relay.example.com \
84                 $patches |
85         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
86                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
87                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
88                 >actual-show-all-headers &&
89         test_cmp expected-show-all-headers actual-show-all-headers
90 '
92 z8=zzzzzzzz
93 z64=$z8$z8$z8$z8$z8$z8$z8$z8
94 z512=$z64$z64$z64$z64$z64$z64$z64$z64
95 test_expect_success 'reject long lines' '
96         clean_fake_sendmail &&
97         cp $patches longline.patch &&
98         echo $z512$z512 >>longline.patch &&
99         test_must_fail git send-email \
100                 --from="Example <nobody@example.com>" \
101                 --to=nobody@example.com \
102                 --smtp-server="$(pwd)/fake.sendmail" \
103                 $patches longline.patch \
104                 2>errors &&
105         grep longline.patch errors
108 test_expect_success 'no patch was sent' '
109         ! test -e commandline1
112 test_expect_success 'Author From: in message body' '
113         clean_fake_sendmail &&
114         git send-email \
115                 --from="Example <nobody@example.com>" \
116                 --to=nobody@example.com \
117                 --smtp-server="$(pwd)/fake.sendmail" \
118                 $patches &&
119         sed "1,/^$/d" < msgtxt1 > msgbody1
120         grep "From: A <author@example.com>" msgbody1
123 test_expect_success 'Author From: not in message body' '
124         clean_fake_sendmail &&
125         git send-email \
126                 --from="A <author@example.com>" \
127                 --to=nobody@example.com \
128                 --smtp-server="$(pwd)/fake.sendmail" \
129                 $patches &&
130         sed "1,/^$/d" < msgtxt1 > msgbody1
131         ! grep "From: A <author@example.com>" msgbody1
134 test_expect_success 'allow long lines with --no-validate' '
135         git send-email \
136                 --from="Example <nobody@example.com>" \
137                 --to=nobody@example.com \
138                 --smtp-server="$(pwd)/fake.sendmail" \
139                 --novalidate \
140                 $patches longline.patch \
141                 2>errors
144 test_expect_success 'Invalid In-Reply-To' '
145         clean_fake_sendmail &&
146         git send-email \
147                 --from="Example <nobody@example.com>" \
148                 --to=nobody@example.com \
149                 --in-reply-to=" " \
150                 --smtp-server="$(pwd)/fake.sendmail" \
151                 $patches
152                 2>errors
153         ! grep "^In-Reply-To: < *>" msgtxt1
156 test_expect_success 'Valid In-Reply-To when prompting' '
157         clean_fake_sendmail &&
158         (echo "From Example <from@example.com>"
159          echo "To Example <to@example.com>"
160          echo ""
161         ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
162                 --smtp-server="$(pwd)/fake.sendmail" \
163                 $patches 2>errors &&
164         ! grep "^In-Reply-To: < *>" msgtxt1
167 test_expect_success 'setup fake editor' '
168         (echo "#!$SHELL_PATH" &&
169          echo "echo fake edit >>\"\$1\""
170         ) >fake-editor &&
171         chmod +x fake-editor
174 test_set_editor "$(pwd)/fake-editor"
176 test_expect_success '--compose works' '
177         clean_fake_sendmail &&
178         echo y | \
179                 GIT_SEND_EMAIL_NOTTY=1 \
180                 git send-email \
181                 --compose --subject foo \
182                 --from="Example <nobody@example.com>" \
183                 --to=nobody@example.com \
184                 --smtp-server="$(pwd)/fake.sendmail" \
185                 $patches \
186                 2>errors
189 test_expect_success 'first message is compose text' '
190         grep "^fake edit" msgtxt1
193 test_expect_success 'second message is patch' '
194         grep "Subject:.*Second" msgtxt2
197 cat >expected-suppress-sob <<\EOF
198 0001-Second.patch
199 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
200 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
201 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
202 Dry-OK. Log says:
203 Server: relay.example.com
204 MAIL FROM:<from@example.com>
205 RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
206 From: Example <from@example.com>
207 To: to@example.com
208 Cc: cc@example.com, A <author@example.com>, One <one@example.com>, two@example.com
209 Subject: [PATCH 1/1] Second.
210 Date: DATE-STRING
211 Message-Id: MESSAGE-ID-STRING
212 X-Mailer: X-MAILER-STRING
214 Result: OK
215 EOF
217 test_suppression () {
218         git send-email \
219                 --dry-run \
220                 --suppress-cc=$1 \
221                 --from="Example <from@example.com>" \
222                 --to=to@example.com \
223                 --smtp-server relay.example.com \
224                 $patches |
225         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
226                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
227                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
228                 >actual-suppress-$1 &&
229         test_cmp expected-suppress-$1 actual-suppress-$1
232 test_expect_success 'sendemail.cc set' '
233         git config sendemail.cc cc@example.com &&
234         test_suppression sob
237 cat >expected-suppress-sob <<\EOF
238 0001-Second.patch
239 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
240 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
241 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
242 Dry-OK. Log says:
243 Server: relay.example.com
244 MAIL FROM:<from@example.com>
245 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
246 From: Example <from@example.com>
247 To: to@example.com
248 Cc: A <author@example.com>, One <one@example.com>, two@example.com
249 Subject: [PATCH 1/1] Second.
250 Date: DATE-STRING
251 Message-Id: MESSAGE-ID-STRING
252 X-Mailer: X-MAILER-STRING
254 Result: OK
255 EOF
257 test_expect_success 'sendemail.cc unset' '
258         git config --unset sendemail.cc &&
259         test_suppression sob
262 cat >expected-suppress-all <<\EOF
263 0001-Second.patch
264 Dry-OK. Log says:
265 Server: relay.example.com
266 MAIL FROM:<from@example.com>
267 RCPT TO:<to@example.com>
268 From: Example <from@example.com>
269 To: to@example.com
270 Subject: [PATCH 1/1] Second.
271 Date: DATE-STRING
272 Message-Id: MESSAGE-ID-STRING
273 X-Mailer: X-MAILER-STRING
275 Result: OK
276 EOF
278 test_expect_success '--suppress-cc=all' '
279         test_suppression all
282 cat >expected-suppress-body <<\EOF
283 0001-Second.patch
284 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
285 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
286 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
287 Dry-OK. Log says:
288 Server: relay.example.com
289 MAIL FROM:<from@example.com>
290 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
291 From: Example <from@example.com>
292 To: to@example.com
293 Cc: A <author@example.com>, One <one@example.com>, two@example.com
294 Subject: [PATCH 1/1] Second.
295 Date: DATE-STRING
296 Message-Id: MESSAGE-ID-STRING
297 X-Mailer: X-MAILER-STRING
299 Result: OK
300 EOF
302 test_expect_success '--suppress-cc=body' '
303         test_suppression body
306 cat >expected-suppress-sob <<\EOF
307 0001-Second.patch
308 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
309 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
310 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
311 Dry-OK. Log says:
312 Server: relay.example.com
313 MAIL FROM:<from@example.com>
314 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
315 From: Example <from@example.com>
316 To: to@example.com
317 Cc: A <author@example.com>, One <one@example.com>, two@example.com
318 Subject: [PATCH 1/1] Second.
319 Date: DATE-STRING
320 Message-Id: MESSAGE-ID-STRING
321 X-Mailer: X-MAILER-STRING
323 Result: OK
324 EOF
326 test_expect_success '--suppress-cc=sob' '
327         test_suppression sob
330 cat >expected-suppress-bodycc <<\EOF
331 0001-Second.patch
332 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
333 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
334 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
335 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
336 Dry-OK. Log says:
337 Server: relay.example.com
338 MAIL FROM:<from@example.com>
339 RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com>
340 From: Example <from@example.com>
341 To: to@example.com
342 Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com>
343 Subject: [PATCH 1/1] Second.
344 Date: DATE-STRING
345 Message-Id: MESSAGE-ID-STRING
346 X-Mailer: X-MAILER-STRING
348 Result: OK
349 EOF
351 test_expect_success '--suppress-cc=bodycc' '
352         test_suppression bodycc
355 cat >expected-suppress-cc <<\EOF
356 0001-Second.patch
357 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
358 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
359 Dry-OK. Log says:
360 Server: relay.example.com
361 MAIL FROM:<from@example.com>
362 RCPT TO:<to@example.com>,<author@example.com>,<committer@example.com>
363 From: Example <from@example.com>
364 To: to@example.com
365 Cc: A <author@example.com>, C O Mitter <committer@example.com>
366 Subject: [PATCH 1/1] Second.
367 Date: DATE-STRING
368 Message-Id: MESSAGE-ID-STRING
369 X-Mailer: X-MAILER-STRING
371 Result: OK
372 EOF
374 test_expect_success '--suppress-cc=cc' '
375         test_suppression cc
378 test_expect_success '--compose adds MIME for utf8 body' '
379         clean_fake_sendmail &&
380         (echo "#!$SHELL_PATH" &&
381          echo "echo utf8 body: àéìöú >>\"\$1\""
382         ) >fake-editor-utf8 &&
383         chmod +x fake-editor-utf8 &&
384         echo y | \
385           GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
386           GIT_SEND_EMAIL_NOTTY=1 \
387           git send-email \
388           --compose --subject foo \
389           --from="Example <nobody@example.com>" \
390           --to=nobody@example.com \
391           --smtp-server="$(pwd)/fake.sendmail" \
392           $patches &&
393         grep "^utf8 body" msgtxt1 &&
394         grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
397 test_expect_success '--compose respects user mime type' '
398         clean_fake_sendmail &&
399         (echo "#!$SHELL_PATH" &&
400          echo "(echo MIME-Version: 1.0"
401          echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
402          echo " echo Content-Transfer-Encoding: 8bit"
403          echo " echo Subject: foo"
404          echo " echo "
405          echo " echo utf8 body: àéìöú) >\"\$1\""
406         ) >fake-editor-utf8-mime &&
407         chmod +x fake-editor-utf8-mime &&
408         echo y | \
409           GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
410           GIT_SEND_EMAIL_NOTTY=1 \
411           git send-email \
412           --compose --subject foo \
413           --from="Example <nobody@example.com>" \
414           --to=nobody@example.com \
415           --smtp-server="$(pwd)/fake.sendmail" \
416           $patches &&
417         grep "^utf8 body" msgtxt1 &&
418         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
419         ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
422 test_expect_success '--compose adds MIME for utf8 subject' '
423         clean_fake_sendmail &&
424         echo y | \
425           GIT_EDITOR="\"$(pwd)/fake-editor\"" \
426           GIT_SEND_EMAIL_NOTTY=1 \
427           git send-email \
428           --compose --subject utf8-sübjëct \
429           --from="Example <nobody@example.com>" \
430           --to=nobody@example.com \
431           --smtp-server="$(pwd)/fake.sendmail" \
432           $patches &&
433         grep "^fake edit" msgtxt1 &&
434         grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
437 test_expect_success 'detects ambiguous reference/file conflict' '
438         echo master > master &&
439         git add master &&
440         git commit -m"add master" &&
441         test_must_fail git send-email --dry-run master 2>errors &&
442         grep disambiguate errors
445 test_expect_success 'feed two files' '
446         rm -fr outdir &&
447         git format-patch -2 -o outdir &&
448         GIT_SEND_EMAIL_NOTTY=1 git send-email \
449         --dry-run \
450         --from="Example <nobody@example.com>" \
451         --to=nobody@example.com \
452         outdir/000?-*.patch 2>errors >out &&
453         grep "^Subject: " out >subjects &&
454         test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
455         test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
458 test_done