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 -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
47 'Verify commandline' \
48 'diff commandline1 expected'
50 cat >expected-show-all-headers
<<\EOF
52 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
54 Server
: relay.example.com
55 MAIL FROM
:<from@example.com
>
56 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>,<bcc@example.com
>
57 From
: Example
<from@example.com
>
59 Cc
: cc@example.com
, A
<author@example.com
>
60 Subject
: [PATCH
1/1] Second.
62 Message-Id
: MESSAGE-ID-STRING
63 X-Mailer
: X-MAILER-STRING
64 In-Reply-To
: <unique-message-id@example.com
>
65 References
: <unique-message-id@example.com
>
70 test_expect_success
'Show all headers' '
73 --from="Example <from@example.com>" \
76 --bcc=bcc@example.com \
77 --in-reply-to="<unique-message-id@example.com>" \
78 --smtp-server relay.example.com \
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 &&
84 test_cmp expected-show-all-headers actual-show-all-headers
88 z64
=$z8$z8$z8$z8$z8$z8$z8$z8
89 z512
=$z64$z64$z64$z64$z64$z64$z64$z64
90 test_expect_success
'reject long lines' '
91 clean_fake_sendmail &&
92 cp $patches longline.patch &&
93 echo $z512$z512 >>longline.patch &&
94 test_must_fail git send-email \
95 --from="Example <nobody@example.com>" \
96 --to=nobody@example.com \
97 --smtp-server="$(pwd)/fake.sendmail" \
98 $patches longline.patch \
100 grep longline.patch errors
103 test_expect_success
'no patch was sent' '
104 ! test -e commandline1
107 test_expect_success
'allow long lines with --no-validate' '
109 --from="Example <nobody@example.com>" \
110 --to=nobody@example.com \
111 --smtp-server="$(pwd)/fake.sendmail" \
113 $patches longline.patch \
117 test_expect_success
'Invalid In-Reply-To' '
118 clean_fake_sendmail &&
120 --from="Example <nobody@example.com>" \
121 --to=nobody@example.com \
123 --smtp-server="$(pwd)/fake.sendmail" \
126 ! grep "^In-Reply-To: < *>" msgtxt1
129 test_expect_success
'Valid In-Reply-To when prompting' '
130 clean_fake_sendmail &&
131 (echo "From Example <from@example.com>"
132 echo "To Example <to@example.com>"
134 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
135 --smtp-server="$(pwd)/fake.sendmail" \
137 ! grep "^In-Reply-To: < *>" msgtxt1
140 test_expect_success
'setup fake editor' '
141 (echo "#!$SHELL_PATH" &&
142 echo "echo fake edit >>\"\$1\""
147 test_set_editor
"$(pwd)/fake-editor"
149 test_expect_success
'--compose works' '
150 clean_fake_sendmail &&
152 GIT_SEND_EMAIL_NOTTY=1 \
154 --compose --subject foo \
155 --from="Example <nobody@example.com>" \
156 --to=nobody@example.com \
157 --smtp-server="$(pwd)/fake.sendmail" \
162 test_expect_success
'first message is compose text' '
163 grep "^fake edit" msgtxt1
166 test_expect_success
'second message is patch' '
167 grep "Subject:.*Second" msgtxt2
170 cat >expected-show-all-headers
<<\EOF
172 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
174 Server
: relay.example.com
175 MAIL FROM
:<from@example.com
>
176 RCPT TO
:<to@example.com
>,<cc@example.com
>,<author@example.com
>
177 From
: Example
<from@example.com
>
179 Cc
: cc@example.com
, A
<author@example.com
>
180 Subject
: [PATCH
1/1] Second.
182 Message-Id
: MESSAGE-ID-STRING
183 X-Mailer
: X-MAILER-STRING
188 test_expect_success
'sendemail.cc set' '
189 git config sendemail.cc cc@example.com &&
192 --from="Example <from@example.com>" \
193 --to=to@example.com \
194 --smtp-server relay.example.com \
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
203 cat >expected-show-all-headers
<<\EOF
205 (mbox
) Adding cc
: A
<author@example.com
> from line
'From: A <author@example.com>'
207 Server
: relay.example.com
208 MAIL FROM
:<from@example.com
>
209 RCPT TO
:<to@example.com
>,<author@example.com
>
210 From
: Example
<from@example.com
>
212 Cc
: A
<author@example.com
>
213 Subject
: [PATCH
1/1] Second.
215 Message-Id
: MESSAGE-ID-STRING
216 X-Mailer
: X-MAILER-STRING
221 test_expect_success
'sendemail.cc unset' '
222 git config --unset sendemail.cc &&
225 --from="Example <from@example.com>" \
226 --to=to@example.com \
227 --smtp-server relay.example.com \
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
236 test_expect_success
'--compose adds MIME for utf8 body' '
237 clean_fake_sendmail &&
238 (echo "#!$SHELL_PATH" &&
239 echo "echo utf8 body: àéìöú >>\"\$1\""
240 ) >fake-editor-utf8 &&
241 chmod +x fake-editor-utf8 &&
243 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
244 GIT_SEND_EMAIL_NOTTY=1 \
246 --compose --subject foo \
247 --from="Example <nobody@example.com>" \
248 --to=nobody@example.com \
249 --smtp-server="$(pwd)/fake.sendmail" \
251 grep "^utf8 body" msgtxt1 &&
252 grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
255 test_expect_success
'--compose respects user mime type' '
256 clean_fake_sendmail &&
257 (echo "#!$SHELL_PATH" &&
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"
263 echo " echo utf8 body: àéìöú) >\"\$1\""
264 ) >fake-editor-utf8-mime &&
265 chmod +x fake-editor-utf8-mime &&
267 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
268 GIT_SEND_EMAIL_NOTTY=1 \
270 --compose --subject foo \
271 --from="Example <nobody@example.com>" \
272 --to=nobody@example.com \
273 --smtp-server="$(pwd)/fake.sendmail" \
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
280 test_expect_success
'--compose adds MIME for utf8 subject' '
281 clean_fake_sendmail &&
283 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
284 GIT_SEND_EMAIL_NOTTY=1 \
286 --compose --subject utf8-sübjëct \
287 --from="Example <nobody@example.com>" \
288 --to=nobody@example.com \
289 --smtp-server="$(pwd)/fake.sendmail" \
291 grep "^fake edit" msgtxt1 &&
292 grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
295 test_expect_success
'detects ambiguous reference/file conflict' '
296 echo master > master &&
298 git commit -m"add master" &&
299 test_must_fail git send-email --dry-run master 2>errors &&
300 grep disambiguate errors
303 test_expect_success
'feed two files' '
305 git format-patch -2 -o outdir &&
306 GIT_SEND_EMAIL_NOTTY=1 git send-email \
308 --from="Example <nobody@example.com>" \
309 --to=nobody@example.com \
310 outdir/000?-*.patch 2>errors >out &&
311 grep "^Subject: " out >subjects &&
312 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
313 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"