3 test_description
='git send-email'
8 'prepare reference tree' \
9 'echo "1A quick brown fox jumps over the" >file &&
10 echo "lazy dog" >>file &&
12 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
16 '(echo "#!$SHELL_PATH"
19 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
22 echo " echo \"!\$a!\""
23 echo "done >commandline\$output"
24 echo "cat > msgtxt\$output"
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
*
34 test_expect_success
'Extract patches' '
35 patches=`git format-patch --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
38 test_expect_success
'Send patches' '
39 git send-email --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
49 'Verify commandline' \
50 'diff commandline1 expected'
52 cat >expected-show-all-headers
<<\EOF
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'
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
>
63 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
64 Subject
: [PATCH
1/1] Second.
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
>
74 test_expect_success
'Show all headers' '
77 --from="Example <from@example.com>" \
80 --bcc=bcc@example.com \
81 --in-reply-to="<unique-message-id@example.com>" \
82 --smtp-server relay.example.com \
84 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
85 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
86 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
87 >actual-show-all-headers &&
88 test_cmp expected-show-all-headers actual-show-all-headers
92 z64
=$z8$z8$z8$z8$z8$z8$z8$z8
93 z512
=$z64$z64$z64$z64$z64$z64$z64$z64
94 test_expect_success
'reject long lines' '
95 clean_fake_sendmail &&
96 cp $patches longline.patch &&
97 echo $z512$z512 >>longline.patch &&
98 test_must_fail git send-email \
99 --from="Example <nobody@example.com>" \
100 --to=nobody@example.com \
101 --smtp-server="$(pwd)/fake.sendmail" \
102 $patches longline.patch \
104 grep longline.patch errors
107 test_expect_success
'no patch was sent' '
108 ! test -e commandline1
111 test_expect_success
'Author From: in message body' '
112 clean_fake_sendmail &&
114 --from="Example <nobody@example.com>" \
115 --to=nobody@example.com \
116 --smtp-server="$(pwd)/fake.sendmail" \
118 sed "1,/^$/d" < msgtxt1 > msgbody1
119 grep "From: A <author@example.com>" msgbody1
122 test_expect_success
'Author From: not in message body' '
123 clean_fake_sendmail &&
125 --from="A <author@example.com>" \
126 --to=nobody@example.com \
127 --smtp-server="$(pwd)/fake.sendmail" \
129 sed "1,/^$/d" < msgtxt1 > msgbody1
130 ! grep "From: A <author@example.com>" msgbody1
133 test_expect_success
'allow long lines with --no-validate' '
135 --from="Example <nobody@example.com>" \
136 --to=nobody@example.com \
137 --smtp-server="$(pwd)/fake.sendmail" \
139 $patches longline.patch \
143 test_expect_success
'Invalid In-Reply-To' '
144 clean_fake_sendmail &&
146 --from="Example <nobody@example.com>" \
147 --to=nobody@example.com \
149 --smtp-server="$(pwd)/fake.sendmail" \
152 ! grep "^In-Reply-To: < *>" msgtxt1
155 test_expect_success
'Valid In-Reply-To when prompting' '
156 clean_fake_sendmail &&
157 (echo "From Example <from@example.com>"
158 echo "To Example <to@example.com>"
160 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
161 --smtp-server="$(pwd)/fake.sendmail" \
163 ! grep "^In-Reply-To: < *>" msgtxt1
166 test_expect_success
'setup fake editor' '
167 (echo "#!$SHELL_PATH" &&
168 echo "echo fake edit >>\"\$1\""
173 test_set_editor
"$(pwd)/fake-editor"
175 test_expect_success
'--compose works' '
176 clean_fake_sendmail &&
178 GIT_SEND_EMAIL_NOTTY=1 \
180 --compose --subject foo \
181 --from="Example <nobody@example.com>" \
182 --to=nobody@example.com \
183 --smtp-server="$(pwd)/fake.sendmail" \
188 test_expect_success
'first message is compose text' '
189 grep "^fake edit" msgtxt1
192 test_expect_success
'second message is patch' '
193 grep "Subject:.*Second" msgtxt2
196 cat >expected-show-all-headers
<<\EOF
198 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
199 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
200 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
202 Server
: relay.example.com
203 MAIL FROM
:<from@example.com
>
204 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
205 From
: Example
<from@example.com
>
207 Cc
: cc@example.com
, A
<author@example.com
>, One
<one@example.com
>, two@example.com
208 Subject
: [PATCH
1/1] Second.
210 Message-Id
: MESSAGE-ID-STRING
211 X-Mailer
: X-MAILER-STRING
216 test_expect_success
'sendemail.cc set' '
217 git config sendemail.cc cc@example.com &&
220 --from="Example <from@example.com>" \
221 --to=to@example.com \
222 --smtp-server relay.example.com \
224 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
225 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
226 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
227 >actual-show-all-headers &&
228 test_cmp expected-show-all-headers actual-show-all-headers
231 cat >expected-show-all-headers
<<\EOF
233 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
234 (mbox
) Adding cc
: One
<one@example.com
> from line
'Cc: One <one@example.com>, two@example.com'
235 (mbox
) Adding cc
: two@example.com from line
'Cc: One <one@example.com>, two@example.com'
237 Server
: relay.example.com
238 MAIL FROM
:<from@example.com
>
239 RCPT TO
:<to@example.com
>,<author@example.com
>,<one@example.com
>,<two@example.com
>
240 From
: Example
<from@example.com
>
242 Cc
: A
<author@example.com
>, One
<one@example.com
>, two@example.com
243 Subject
: [PATCH
1/1] Second.
245 Message-Id
: MESSAGE-ID-STRING
246 X-Mailer
: X-MAILER-STRING
251 test_expect_success
'sendemail.cc unset' '
252 git config --unset sendemail.cc &&
255 --from="Example <from@example.com>" \
256 --to=to@example.com \
257 --smtp-server relay.example.com \
259 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
260 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
261 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
262 >actual-show-all-headers &&
263 test_cmp expected-show-all-headers actual-show-all-headers
266 test_expect_success
'--compose adds MIME for utf8 body' '
267 clean_fake_sendmail &&
268 (echo "#!$SHELL_PATH" &&
269 echo "echo utf8 body: àéìöú >>\"\$1\""
270 ) >fake-editor-utf8 &&
271 chmod +x fake-editor-utf8 &&
273 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
274 GIT_SEND_EMAIL_NOTTY=1 \
276 --compose --subject foo \
277 --from="Example <nobody@example.com>" \
278 --to=nobody@example.com \
279 --smtp-server="$(pwd)/fake.sendmail" \
281 grep "^utf8 body" msgtxt1 &&
282 grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
285 test_expect_success
'--compose respects user mime type' '
286 clean_fake_sendmail &&
287 (echo "#!$SHELL_PATH" &&
288 echo "(echo MIME-Version: 1.0"
289 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
290 echo " echo Content-Transfer-Encoding: 8bit"
291 echo " echo Subject: foo"
293 echo " echo utf8 body: àéìöú) >\"\$1\""
294 ) >fake-editor-utf8-mime &&
295 chmod +x fake-editor-utf8-mime &&
297 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
298 GIT_SEND_EMAIL_NOTTY=1 \
300 --compose --subject foo \
301 --from="Example <nobody@example.com>" \
302 --to=nobody@example.com \
303 --smtp-server="$(pwd)/fake.sendmail" \
305 grep "^utf8 body" msgtxt1 &&
306 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
307 ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
310 test_expect_success
'--compose adds MIME for utf8 subject' '
311 clean_fake_sendmail &&
313 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
314 GIT_SEND_EMAIL_NOTTY=1 \
316 --compose --subject utf8-sübjëct \
317 --from="Example <nobody@example.com>" \
318 --to=nobody@example.com \
319 --smtp-server="$(pwd)/fake.sendmail" \
321 grep "^fake edit" msgtxt1 &&
322 grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
325 test_expect_success
'detects ambiguous reference/file conflict' '
326 echo master > master &&
328 git commit -m"add master" &&
329 test_must_fail git send-email --dry-run master 2>errors &&
330 grep disambiguate errors
333 test_expect_success
'feed two files' '
335 git format-patch -2 -o outdir &&
336 GIT_SEND_EMAIL_NOTTY=1 git send-email \
338 --from="Example <nobody@example.com>" \
339 --to=nobody@example.com \
340 outdir/000?-*.patch 2>errors >out &&
341 grep "^Subject: " out >subjects &&
342 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
343 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"