Tests redirect to err file when grepping stderr
[stgit.git] / t / t1801-import-email.sh
blob591b9bf79de1f40ff5882aafd37262042dd18373
1 #!/bin/sh
3 test_description='Test import from emails'
5 . ./test-lib.sh
7 test_expect_success \
8 'Initialize the StGit repository' \
10 cp "$TEST_DIRECTORY"/t1800/foo.txt . &&
11 stg add foo.txt &&
12 git commit -a -m "initial version" &&
13 stg init
16 test_expect_success \
17 'Apply a patch from an 8bit-encoded e-mail' \
19 stg import -m --message-id "$TEST_DIRECTORY"/t1801/email-8bit &&
20 [ $(git cat-file -p $(stg id) \
21 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
22 [ $(git cat-file -p $(stg id) \
23 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
24 [ $(git cat-file -p $(stg id) \
25 | grep -c "Message-Id: <20061111105814.23209.46952.stgit@localhost>") = 1 ] &&
26 stg delete ..
29 test_expect_success \
30 'Apply a patch from an 8bit-encoded e-mail url' \
32 stg import -u -m "file://$TEST_DIRECTORY"/t1801/email-8bit &&
33 [ $(git cat-file -p $(stg id) \
34 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
35 [ $(git cat-file -p $(stg id) \
36 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
37 [ $(git cat-file -p $(stg id) \
38 | grep -c "Message-Id: <20061111105814.23209.46952.stgit@localhost>") = 0 ] &&
39 stg delete ..
42 test_expect_success \
43 'Apply a patch from an 8bit-encoded e-mail with CRLF endings' \
45 cat "$TEST_DIRECTORY"/t1801/email-8bit | append_cr |
46 stg import -m &&
47 [ $(git cat-file -p $(stg id) \
48 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
49 [ $(git cat-file -p $(stg id) \
50 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
51 [ $(git cat-file -p $(stg id) \
52 | grep -c "Message-Id: <20061111105814.23209.46952.stgit@localhost>") = 0 ] &&
53 stg delete ..
56 test_expect_success \
57 'Apply e-mail with CRLF endings and --keep-cr' \
59 stg new -m foo-with-crlf &&
60 cat foo.txt | append_cr > foo-crlf.txt &&
61 mv foo-crlf.txt foo.txt &&
62 stg refresh &&
63 cat "$TEST_DIRECTORY"/t1801/email-8bit | append_cr |
64 stg import -m --keep-cr &&
65 [ $(git cat-file -p $(stg id) \
66 | grep -c "tree ecb72e62394189fd2a095047076dab1ae473ed4d") = 1 ] &&
67 [ $(git cat-file -p $(stg id) \
68 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
69 [ $(git cat-file -p $(stg id) \
70 | grep -c "Message-Id: <20061111105814.23209.46952.stgit@localhost>") = 0 ] &&
71 stg delete ..
74 test_expect_success \
75 'Apply a patch from latin1-encoded email specifying utf-8 charset' \
77 iconv -f UTF-8 -t LATIN1 "$TEST_DIRECTORY"/t1801/email-8bit > email-latin1 &&
78 stg import -m email-latin1 &&
79 [ $(git cat-file -p $(stg id) \
80 | grep -c "tree cf0f9884fdb30bca14d2411e1711f6ae413c9213") = 1 ] &&
81 [ $(git cat-file -p $(stg id) \
82 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
83 [ $(git cat-file -p $(stg id) \
84 | grep -c "Message-Id: <20061111105814.23209.46952.stgit@localhost>") = 0 ] &&
85 stg delete ..
88 test_expect_success \
89 'Apply a patch from email with quoted "From" header' \
91 stg import -m "$TEST_DIRECTORY"/t1801/email-quoted-from &&
92 [ $(git cat-file -p $(stg id) \
93 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
94 [ $(git cat-file -p $(stg id) \
95 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
96 [ $(git cat-file -p $(stg id) \
97 | grep -c "Message-Id: <20061111105814.23209.46952.stgit@localhost>") = 0 ] &&
98 stg delete ..
101 test_expect_success \
102 'Apply a patch from a QP-encoded e-mail' \
104 stg import -m "$TEST_DIRECTORY"/t1801/email-qp &&
105 [ $(git cat-file -p $(stg id) \
106 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
107 [ $(git cat-file -p $(stg id) \
108 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
109 [ $(git cat-file -p $(stg id) \
110 | grep -c "Message-Id: <20061111105814.23209.46952.stgit@localhost>") = 0 ] &&
111 stg delete ..
114 test_expect_success \
115 'Apply several patches from an mbox file' \
117 test_config stgit.import.message-id "no" &&
118 stg import -M --message-id "$TEST_DIRECTORY"/t1801/email-mbox &&
119 [ $(git cat-file -p $(stg id change-1) \
120 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
121 [ $(git cat-file -p $(stg id change-1) \
122 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
123 [ $(git cat-file -p $(stg id change-1) \
124 | grep -c "Message-Id: <20061111114527.31778.12942.stgit@localhost>") = 1 ] &&
125 [ $(git cat-file -p $(stg id change-2) \
126 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
127 [ $(git cat-file -p $(stg id change-2) \
128 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
129 [ $(git cat-file -p $(stg id change-2) \
130 | grep -c "Message-Id: <20061111114527.31778.92851.stgit@localhost>") = 1 ] &&
131 [ $(git cat-file -p $(stg id change-3-colon) \
132 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
133 [ $(git cat-file -p $(stg id change-3-colon) \
134 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
135 [ $(git cat-file -p $(stg id change-3-colon) \
136 | grep -c "Message-Id: <20061111114527.31778.45876.stgit@localhost>") = 1 ] &&
137 stg delete ..
140 test_expect_success \
141 'Apply several patches from an mbox url' \
143 test_config stgit.import.message-id "yes" &&
144 stg import -u -M "file://$TEST_DIRECTORY"/t1801/email-mbox &&
145 [ $(git cat-file -p $(stg id change-1) \
146 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
147 [ $(git cat-file -p $(stg id change-1) \
148 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
149 [ $(git cat-file -p $(stg id change-1) \
150 | grep -c "Message-Id: <20061111114527.31778.12942.stgit@localhost>") = 1 ] &&
151 [ $(git cat-file -p $(stg id change-2) \
152 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
153 [ $(git cat-file -p $(stg id change-2) \
154 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
155 [ $(git cat-file -p $(stg id change-2) \
156 | grep -c "Message-Id: <20061111114527.31778.92851.stgit@localhost>") = 1 ] &&
157 [ $(git cat-file -p $(stg id change-3-colon) \
158 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
159 [ $(git cat-file -p $(stg id change-3-colon) \
160 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
161 [ $(git cat-file -p $(stg id change-3-colon) \
162 | grep -c "Message-Id: <20061111114527.31778.45876.stgit@localhost>") = 1 ] &&
163 stg delete ..
166 test_expect_success \
167 'Import patches from mbox with duplicate subjects' \
169 stg import -M "$TEST_DIRECTORY"/t1801/email-mbox-same-subject &&
170 test "$(echo $(stg series --noprefix --applied))" = "my-patch my-patch-1 my-patch-2" &&
171 stg delete ..
174 test_expect_success \
175 'Apply several patches from an mbox file from stdin' \
177 test_config stgit.import.message-id "off" &&
178 cat "$TEST_DIRECTORY"/t1801/email-mbox | stg import -M &&
179 [ $(git cat-file -p $(stg id change-1) \
180 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
181 [ $(git cat-file -p $(stg id change-1) \
182 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
183 [ $(git cat-file -p $(stg id change-1) \
184 | grep -c "Message-Id: <20061111114527.31778.12942.stgit@localhost>") = 0 ] &&
185 [ $(git cat-file -p $(stg id change-2) \
186 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
187 [ $(git cat-file -p $(stg id change-2) \
188 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
189 [ $(git cat-file -p $(stg id change-2) \
190 | grep -c "Message-Id: <20061111114527.31778.92851.stgit@localhost>") = 0 ] &&
191 [ $(git cat-file -p $(stg id change-3-colon) \
192 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
193 [ $(git cat-file -p $(stg id change-3-colon) \
194 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
195 [ $(git cat-file -p $(stg id change-3-colon) \
196 | grep -c "Message-Id: <20061111114527.31778.45876.stgit@localhost>") = 0 ] &&
197 stg delete ..
200 test_expect_success \
201 'Apply several patches from an mbox file with CRLF line endings' \
203 cat "$TEST_DIRECTORY"/t1801/email-mbox | append_cr |
204 stg import -M &&
205 [ $(git cat-file -p $(stg id change-1) \
206 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
207 [ $(git cat-file -p $(stg id change-1) \
208 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
209 [ $(git cat-file -p $(stg id change-2) \
210 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
211 [ $(git cat-file -p $(stg id change-2) \
212 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
213 [ $(git cat-file -p $(stg id change-3-colon) \
214 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
215 [ $(git cat-file -p $(stg id change-3-colon) \
216 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
217 stg delete ..
220 test_expect_success \
221 'Import from git format-patch output' '
223 test_create_repo upstream &&
224 cd upstream &&
225 echo "something" > some.txt &&
226 git add some.txt &&
227 git commit -m "Add something"
228 stg init
229 ) &&
231 git clone upstream downstream
232 cd downstream &&
233 echo "else µ" >> some.txt &&
234 git commit -a --author "Éd <ed@example.com>" -m "something else" &&
235 git format-patch --stdout HEAD~1 > ../downstream.mbox
236 ) &&
238 cd upstream &&
239 stg import --mbox ../downstream.mbox &&
240 stg top | grep "something-else" &&
241 grep "else µ" some.txt
245 test_done