diff -c/--cc: do not include uninteresting deletion before leading context
[git/dscho.git] / t / t9001-send-email.sh
bloba4bcd282b609bb522d8f541a857c274996aa6842
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 "#!/bin/sh"
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*
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
42 cat >expected <<\EOF
43 !nobody@example.com!
44 !author@example.com!
45 EOF
46 test_expect_success \
47 'Verify commandline' \
48 'diff commandline1 expected'
50 cat >expected-show-all-headers <<\EOF
51 0001-Second.patch
52 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
53 Dry-OK. Log says:
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>
58 To: to@example.com
59 Cc: cc@example.com, A <author@example.com>
60 Subject: [PATCH 1/1] Second.
61 Date: DATE-STRING
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>
67 Result: OK
68 EOF
70 test_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 &&
84 test_cmp expected-show-all-headers actual-show-all-headers
87 z8=zzzzzzzz
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 ! git send-email \
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
103 test_expect_success 'no patch was sent' '
104 ! test -e commandline1
107 test_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
117 test_expect_success 'Invalid In-Reply-To' '
118 clean_fake_sendmail &&
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
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>"
133 echo ""
134 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
135 --smtp-server="$(pwd)/fake.sendmail" \
136 $patches 2>errors &&
137 ! grep "^In-Reply-To: < *>" msgtxt1
140 test_expect_success 'setup fake editor' '
141 (echo "#!/bin/sh" &&
142 echo "echo fake edit >>\$1"
143 ) >fake-editor &&
144 chmod +x fake-editor
147 test_expect_success '--compose works' '
148 clean_fake_sendmail &&
149 echo y | \
150 GIT_EDITOR=$(pwd)/fake-editor \
151 GIT_SEND_EMAIL_NOTTY=1 \
152 git send-email \
153 --compose --subject foo \
154 --from="Example <nobody@example.com>" \
155 --to=nobody@example.com \
156 --smtp-server="$(pwd)/fake.sendmail" \
157 $patches \
158 2>errors
161 test_expect_success 'first message is compose text' '
162 grep "^fake edit" msgtxt1
165 test_expect_success 'second message is patch' '
166 grep "Subject:.*Second" msgtxt2
169 test_expect_success '--compose adds MIME for utf8 body' '
170 clean_fake_sendmail &&
171 (echo "#!/bin/sh" &&
172 echo "echo utf8 body: àéìöú >>\$1"
173 ) >fake-editor-utf8 &&
174 chmod +x fake-editor-utf8 &&
175 echo y | \
176 GIT_EDITOR=$(pwd)/fake-editor-utf8 \
177 GIT_SEND_EMAIL_NOTTY=1 \
178 git send-email \
179 --compose --subject foo \
180 --from="Example <nobody@example.com>" \
181 --to=nobody@example.com \
182 --smtp-server="$(pwd)/fake.sendmail" \
183 $patches &&
184 grep "^utf8 body" msgtxt1 &&
185 grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
188 test_expect_success '--compose respects user mime type' '
189 clean_fake_sendmail &&
190 (echo "#!/bin/sh" &&
191 echo "(echo MIME-Version: 1.0"
192 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
193 echo " echo Content-Transfer-Encoding: 8bit"
194 echo " echo Subject: foo"
195 echo " echo "
196 echo " echo utf8 body: àéìöú) >\$1"
197 ) >fake-editor-utf8-mime &&
198 chmod +x fake-editor-utf8-mime &&
199 echo y | \
200 GIT_EDITOR=$(pwd)/fake-editor-utf8-mime \
201 GIT_SEND_EMAIL_NOTTY=1 \
202 git send-email \
203 --compose --subject foo \
204 --from="Example <nobody@example.com>" \
205 --to=nobody@example.com \
206 --smtp-server="$(pwd)/fake.sendmail" \
207 $patches &&
208 grep "^utf8 body" msgtxt1 &&
209 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
210 ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1
213 test_expect_success '--compose adds MIME for utf8 subject' '
214 clean_fake_sendmail &&
215 echo y | \
216 GIT_EDITOR=$(pwd)/fake-editor \
217 GIT_SEND_EMAIL_NOTTY=1 \
218 git send-email \
219 --compose --subject utf8-sübjëct \
220 --from="Example <nobody@example.com>" \
221 --to=nobody@example.com \
222 --smtp-server="$(pwd)/fake.sendmail" \
223 $patches &&
224 grep "^fake edit" msgtxt1 &&
225 grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
228 test_done