]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9001-send-email.sh
Merge branch 'mv/dashless'
[thirdparty/git.git] / t / t9001-send-email.sh
CommitLineData
ce903018
RA
1#!/bin/sh
2
3test_description='git-send-email'
4. ./test-lib.sh
5
6PROG='git send-email'
7test_expect_success \
8 'prepare reference tree' \
9 'echo "1A quick brown fox jumps over the" >file &&
10 echo "lazy dog" >>file &&
c0d45281 11 git add file &&
ce903018
RA
12 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
13
14test_expect_success \
15 'Setup helper tool' \
2186d566
JH
16 '(echo "#!/bin/sh"
17 echo shift
6d34a2ba
JK
18 echo output=1
19 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
2186d566
JH
20 echo for a
21 echo do
22 echo " echo \"!\$a!\""
6d34a2ba
JK
23 echo "done >commandline\$output"
24 echo "cat > msgtxt\$output"
c0d45281
JK
25 ) >fake.sendmail &&
26 chmod +x ./fake.sendmail &&
27 git add fake.sendmail &&
ce903018
RA
28 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
29
6d34a2ba
JK
30clean_fake_sendmail() {
31 rm -f commandline* msgtxt*
32}
33
280242d1
JH
34test_expect_success 'Extract patches' '
35 patches=`git format-patch -n HEAD^1`
36'
37
38test_expect_success 'Send patches' '
85d81a75 39 git send-email --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
280242d1 40'
ce903018 41
2186d566
JH
42cat >expected <<\EOF
43!nobody@example.com!
44!author@example.com!
45EOF
ce903018
RA
46test_expect_success \
47 'Verify commandline' \
6d34a2ba 48 'diff commandline1 expected'
ce903018 49
b7f30e0a
DK
50cat >expected-show-all-headers <<\EOF
510001-Second.patch
52(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
53Dry-OK. Log says:
54Server: relay.example.com
55MAIL FROM:<from@example.com>
56RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>,<bcc@example.com>
57From: Example <from@example.com>
58To: to@example.com
59Cc: cc@example.com, A <author@example.com>
60Subject: [PATCH 1/1] Second.
61Date: DATE-STRING
62Message-Id: MESSAGE-ID-STRING
63X-Mailer: X-MAILER-STRING
64In-Reply-To: <unique-message-id@example.com>
65References: <unique-message-id@example.com>
66
67Result: OK
68EOF
69
70test_expect_success 'Show all headers' '
71 git send-email \
72 --dry-run \
73 --from="Example <from@example.com>" \
74 --to=to@example.com \
75 --cc=cc@example.com \
76 --bcc=bcc@example.com \
77 --in-reply-to="<unique-message-id@example.com>" \
78 --smtp-server relay.example.com \
79 $patches |
80 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
81 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
82 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
83 >actual-show-all-headers &&
82ebb0b6 84 test_cmp expected-show-all-headers actual-show-all-headers
b7f30e0a
DK
85'
86
747bbff9
JK
87z8=zzzzzzzz
88z64=$z8$z8$z8$z8$z8$z8$z8$z8
89z512=$z64$z64$z64$z64$z64$z64$z64$z64
90test_expect_success 'reject long lines' '
6d34a2ba 91 clean_fake_sendmail &&
747bbff9
JK
92 cp $patches longline.patch &&
93 echo $z512$z512 >>longline.patch &&
d492b31c 94 test_must_fail git send-email \
747bbff9
JK
95 --from="Example <nobody@example.com>" \
96 --to=nobody@example.com \
97 --smtp-server="$(pwd)/fake.sendmail" \
98 $patches longline.patch \
99 2>errors &&
100 grep longline.patch errors
101'
102
103test_expect_success 'no patch was sent' '
6d34a2ba 104 ! test -e commandline1
747bbff9
JK
105'
106
c764a0c2
JK
107test_expect_success 'allow long lines with --no-validate' '
108 git send-email \
109 --from="Example <nobody@example.com>" \
110 --to=nobody@example.com \
111 --smtp-server="$(pwd)/fake.sendmail" \
112 --no-validate \
113 $patches longline.patch \
114 2>errors
115'
116
0fb7fc75 117test_expect_success 'Invalid In-Reply-To' '
6d34a2ba 118 clean_fake_sendmail &&
0fb7fc75
JS
119 git send-email \
120 --from="Example <nobody@example.com>" \
121 --to=nobody@example.com \
122 --in-reply-to=" " \
123 --smtp-server="$(pwd)/fake.sendmail" \
124 $patches
125 2>errors
6d34a2ba 126 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
127'
128
129test_expect_success 'Valid In-Reply-To when prompting' '
6d34a2ba 130 clean_fake_sendmail &&
0fb7fc75
JS
131 (echo "From Example <from@example.com>"
132 echo "To Example <to@example.com>"
133 echo ""
134 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
135 --smtp-server="$(pwd)/fake.sendmail" \
136 $patches 2>errors &&
6d34a2ba 137 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
138'
139
8a8bf469
JK
140test_expect_success 'setup fake editor' '
141 (echo "#!/bin/sh" &&
065096c2 142 echo "echo fake edit >>\"\$1\""
8a8bf469
JK
143 ) >fake-editor &&
144 chmod +x fake-editor
145'
146
7f0475c3 147test_set_editor "$(pwd)/fake-editor"
065096c2 148
8a8bf469
JK
149test_expect_success '--compose works' '
150 clean_fake_sendmail &&
151 echo y | \
8a8bf469
JK
152 GIT_SEND_EMAIL_NOTTY=1 \
153 git send-email \
154 --compose --subject foo \
155 --from="Example <nobody@example.com>" \
156 --to=nobody@example.com \
157 --smtp-server="$(pwd)/fake.sendmail" \
158 $patches \
159 2>errors
160'
161
162test_expect_success 'first message is compose text' '
163 grep "^fake edit" msgtxt1
164'
165
166test_expect_success 'second message is patch' '
167 grep "Subject:.*Second" msgtxt2
168'
169
33c592dd
MV
170cat >expected-show-all-headers <<\EOF
1710001-Second.patch
172(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
173Dry-OK. Log says:
174Server: relay.example.com
175MAIL FROM:<from@example.com>
176RCPT TO:<to@example.com>,<cc@example.com>,<author@example.com>
177From: Example <from@example.com>
178To: to@example.com
179Cc: cc@example.com, A <author@example.com>
180Subject: [PATCH 1/1] Second.
181Date: DATE-STRING
182Message-Id: MESSAGE-ID-STRING
183X-Mailer: X-MAILER-STRING
184
185Result: OK
186EOF
187
188test_expect_success 'sendemail.cc set' '
189 git config sendemail.cc cc@example.com &&
190 git send-email \
191 --dry-run \
192 --from="Example <from@example.com>" \
193 --to=to@example.com \
194 --smtp-server relay.example.com \
195 $patches |
196 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
197 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
198 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
199 >actual-show-all-headers &&
200 test_cmp expected-show-all-headers actual-show-all-headers
201'
202
203cat >expected-show-all-headers <<\EOF
2040001-Second.patch
205(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
206Dry-OK. Log says:
207Server: relay.example.com
208MAIL FROM:<from@example.com>
209RCPT TO:<to@example.com>,<author@example.com>
210From: Example <from@example.com>
211To: to@example.com
212Cc: A <author@example.com>
213Subject: [PATCH 1/1] Second.
214Date: DATE-STRING
215Message-Id: MESSAGE-ID-STRING
216X-Mailer: X-MAILER-STRING
217
218Result: OK
219EOF
220
221test_expect_success 'sendemail.cc unset' '
222 git config --unset sendemail.cc &&
223 git send-email \
224 --dry-run \
225 --from="Example <from@example.com>" \
226 --to=to@example.com \
227 --smtp-server relay.example.com \
228 $patches |
229 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
230 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
231 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
232 >actual-show-all-headers &&
233 test_cmp expected-show-all-headers actual-show-all-headers
234'
235
0706bd19
JK
236test_expect_success '--compose adds MIME for utf8 body' '
237 clean_fake_sendmail &&
238 (echo "#!/bin/sh" &&
c01cdde1 239 echo "echo utf8 body: àéìöú >>\"\$1\""
0706bd19
JK
240 ) >fake-editor-utf8 &&
241 chmod +x fake-editor-utf8 &&
242 echo y | \
c01cdde1 243 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
0706bd19
JK
244 GIT_SEND_EMAIL_NOTTY=1 \
245 git send-email \
246 --compose --subject foo \
247 --from="Example <nobody@example.com>" \
248 --to=nobody@example.com \
249 --smtp-server="$(pwd)/fake.sendmail" \
250 $patches &&
251 grep "^utf8 body" msgtxt1 &&
252 grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
253'
254
255test_expect_success '--compose respects user mime type' '
256 clean_fake_sendmail &&
257 (echo "#!/bin/sh" &&
258 echo "(echo MIME-Version: 1.0"
259 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
260 echo " echo Content-Transfer-Encoding: 8bit"
261 echo " echo Subject: foo"
262 echo " echo "
c01cdde1 263 echo " echo utf8 body: àéìöú) >\"\$1\""
0706bd19
JK
264 ) >fake-editor-utf8-mime &&
265 chmod +x fake-editor-utf8-mime &&
266 echo y | \
c01cdde1 267 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
0706bd19
JK
268 GIT_SEND_EMAIL_NOTTY=1 \
269 git send-email \
270 --compose --subject foo \
271 --from="Example <nobody@example.com>" \
272 --to=nobody@example.com \
273 --smtp-server="$(pwd)/fake.sendmail" \
274 $patches &&
275 grep "^utf8 body" msgtxt1 &&
276 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
277 ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
278'
279
d54eaaa2
JK
280test_expect_success '--compose adds MIME for utf8 subject' '
281 clean_fake_sendmail &&
282 echo y | \
c01cdde1 283 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
d54eaaa2
JK
284 GIT_SEND_EMAIL_NOTTY=1 \
285 git send-email \
286 --compose --subject utf8-sübjëct \
287 --from="Example <nobody@example.com>" \
288 --to=nobody@example.com \
289 --smtp-server="$(pwd)/fake.sendmail" \
290 $patches &&
291 grep "^fake edit" msgtxt1 &&
292 grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
293'
294
ce903018 295test_done