Merge branch 'decode-quoted-header' of https://github.com/jpgrayson/stgit
[stgit.git] / t / t1800-import.sh
blobd8a1baf5efadf3f7f7e6f159bd814fa09fd429f7
1 #!/bin/sh
2 # Copyright (c) 2006 Karl Hasselström
3 test_description='Test the import command'
4 . ./test-lib.sh
6 test_expect_success \
7 'Initialize the StGIT repository' \
9 cp $STG_ROOT/t/t1800-import/foo.txt . &&
10 stg add foo.txt &&
11 git commit -a -m "initial version" &&
12 stg init
15 test_expect_success \
16 'Apply a patch created with "git diff"' \
18 stg import $STG_ROOT/t/t1800-import/git-diff &&
19 [ $(git cat-file -p $(stg id) \
20 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
21 stg delete ..
24 test_expect_success \
25 'Apply a patch from a URL' \
27 stg import -u file://$STG_ROOT/t/t1800-import/git-diff &&
28 [ $(git cat-file -p $(stg id) \
29 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
30 stg delete ..
33 test_expect_success \
34 'Apply a patch created with "git diff" using -p1' \
36 stg import -p1 $STG_ROOT/t/t1800-import/git-diff &&
37 [ $(git cat-file -p $(stg id) \
38 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
39 stg delete ..
42 test_expect_success \
43 'Apply a patch created with "git diff" using -p0' \
45 stg import -p0 $STG_ROOT/t/t1800-import/git-diff-p0 &&
46 [ $(git cat-file -p $(stg id) \
47 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
48 stg delete ..
51 test_expect_success \
52 'Apply a patch created with "git diff" using -p2' \
54 ! stg import -p2 $STG_ROOT/t/t1800-import/git-diff &&
55 [ $(git cat-file -p $(stg id) \
56 | grep -c "tree a5850c97490398571d41d6304dd940800550f507") = 1 ] &&
57 stg delete ..
60 test_expect_success \
61 'Apply a patch created with "git diff" from a subdirectory' \
63 mkdir subdir && cd subdir &&
64 stg import $STG_ROOT/t/t1800-import/git-diff &&
65 [ $(git cat-file -p $(stg id) \
66 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
67 stg delete .. &&
68 cd ..
71 test_expect_success \
72 'Apply a patch created with GNU diff' \
74 stg import $STG_ROOT/t/t1800-import/gnu-diff &&
75 [ $(git cat-file -p $(stg id) \
76 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
77 stg delete ..
80 test_expect_success \
81 'Apply a patch created with "stg export"' \
83 stg import $STG_ROOT/t/t1800-import/stg-export &&
84 [ $(git cat-file -p $(stg id) \
85 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
86 stg delete ..
89 test_expect_success \
90 'Apply a patch from an 8bit-encoded e-mail' \
92 stg import -m $STG_ROOT/t/t1800-import/email-8bit &&
93 [ $(git cat-file -p $(stg id) \
94 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
95 [ $(git cat-file -p $(stg id) \
96 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
97 stg delete ..
100 test_expect_success \
101 'Apply a patch from latin1-encoded email specifying utf-8 charset' \
103 iconv -f UTF8 -t LATIN1 -o email-latin1 $STG_ROOT/t/t1800-import/email-8bit &&
104 stg import -m email-latin1 &&
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 stg delete ..
112 test_expect_success \
113 'Apply a patch from email with quoted "From" header' \
115 stg import -m $STG_ROOT/t/t1800-import/email-quoted-from &&
116 [ $(git cat-file -p $(stg id) \
117 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
118 [ $(git cat-file -p $(stg id) \
119 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
120 stg delete ..
123 test_expect_success \
124 'Apply a patch from a QP-encoded e-mail' \
126 stg import -m $STG_ROOT/t/t1800-import/email-qp &&
127 [ $(git cat-file -p $(stg id) \
128 | grep -c "tree 030be42660323ff2a1958f9ee79589a4f3fbee2f") = 1 ] &&
129 [ $(git cat-file -p $(stg id) \
130 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
131 stg delete ..
134 test_expect_success \
135 'Apply several patches from an mbox file' \
137 stg import -M $STG_ROOT/t/t1800-import/email-mbox &&
138 [ $(git cat-file -p $(stg id change-1) \
139 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
140 [ $(git cat-file -p $(stg id change-1) \
141 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
142 [ $(git cat-file -p $(stg id change-2) \
143 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
144 [ $(git cat-file -p $(stg id change-2) \
145 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
146 [ $(git cat-file -p $(stg id change-3) \
147 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
148 [ $(git cat-file -p $(stg id change-3) \
149 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
150 stg delete ..
153 test_expect_success \
154 'Apply several patches from an mbox file from stdin' \
156 cat $STG_ROOT/t/t1800-import/email-mbox | stg import -M &&
157 [ $(git cat-file -p $(stg id change-1) \
158 | grep -c "tree 401bef82cd9fb403aba18f480a63844416a2e023") = 1 ] &&
159 [ $(git cat-file -p $(stg id change-1) \
160 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
161 [ $(git cat-file -p $(stg id change-2) \
162 | grep -c "tree e49dbce010ec7f441015a8c64bce0b99108af4cc") = 1 ] &&
163 [ $(git cat-file -p $(stg id change-2) \
164 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
165 [ $(git cat-file -p $(stg id change-3) \
166 | grep -c "tree 166bbaf27a44aee21ba78c98822a741e6f7d78f5") = 1 ] &&
167 [ $(git cat-file -p $(stg id change-3) \
168 | grep -c "author Inge Ström <inge@power.com>") = 1 ] &&
169 stg delete ..
172 test_expect_success \
173 'Apply a bzip2 patch created with "git diff"' \
175 bzip2 -c $STG_ROOT/t/t1800-import/git-diff > \
176 $STG_ROOT/t/t1800-import/bzip2-git-diff &&
177 stg import $STG_ROOT/t/t1800-import/bzip2-git-diff &&
178 [ $(git cat-file -p $(stg id) \
179 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
180 rm $STG_ROOT/t/t1800-import/bzip2-git-diff &&
181 stg delete ..
183 test_expect_success \
184 'Apply a bzip2 patch with a .bz2 suffix' \
186 bzip2 -c $STG_ROOT/t/t1800-import/git-diff > \
187 $STG_ROOT/t/t1800-import/git-diff.bz2 &&
188 stg import $STG_ROOT/t/t1800-import/git-diff.bz2 &&
189 [ $(git cat-file -p $(stg id) \
190 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
191 rm $STG_ROOT/t/t1800-import/git-diff.bz2 &&
192 stg delete ..
195 test_expect_success \
196 'Apply a gzip patch created with GNU diff' \
198 gzip -c $STG_ROOT/t/t1800-import/gnu-diff > \
199 $STG_ROOT/t/t1800-import/gzip-gnu-diff &&
200 stg import $STG_ROOT/t/t1800-import/gzip-gnu-diff &&
201 [ $(git cat-file -p $(stg id) \
202 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
203 rm $STG_ROOT/t/t1800-import/gzip-gnu-diff &&
204 stg delete ..
206 test_expect_success \
207 'Apply a gzip patch with a .gz suffix' \
209 gzip -c $STG_ROOT/t/t1800-import/gnu-diff > \
210 $STG_ROOT/t/t1800-import/gnu-diff.gz &&
211 stg import $STG_ROOT/t/t1800-import/gnu-diff.gz &&
212 [ $(git cat-file -p $(stg id) \
213 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
214 rm $STG_ROOT/t/t1800-import/gnu-diff.gz &&
215 stg delete ..
218 test_expect_success \
219 'apply a series from a tarball' \
221 rm -f jabberwocky.txt && touch jabberwocky.txt &&
222 stg add jabberwocky.txt && git commit -m "empty file" jabberwocky.txt &&
223 (cd $STG_ROOT/t/t1800-import; tar -cjf jabberwocky.tar.bz2 patches) &&
224 stg import --series $STG_ROOT/t/t1800-import/jabberwocky.tar.bz2
225 [ $(git cat-file -p $(stg id) \
226 | grep -c "tree 2c33937252a21f1550c0bf21f1de534b68f69635") = 1 ] &&
227 rm $STG_ROOT/t/t1800-import/jabberwocky.tar.bz2
230 test_expect_success \
231 'Import from git format-patch output' '
233 test_create_repo upstream &&
234 cd upstream &&
235 echo "something" > some.txt &&
236 git add some.txt &&
237 git commit -m "Add something"
238 stg init
239 ) &&
241 git clone upstream downstream
242 cd downstream &&
243 echo "else µ" >> some.txt &&
244 git commit -a --author "Éd <ed@example.com>" -m "something else" &&
245 git format-patch --stdout HEAD~1 > ../downstream.mbox
246 ) &&
248 cd upstream &&
249 stg import --mbox ../downstream.mbox &&
250 stg top | grep "something-else" &&
251 grep "else µ" some.txt
255 test_done