2 # Copyright (c) 2006 Karl Hasselström
3 test_description
='Test the import command'
7 'Initialize the StGIT repository' \
9 cp $STG_ROOT/t/t1800-import/foo.txt . &&
11 git commit -a -m "initial version" &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 ] &&
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 &&
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 &&
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 &&
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 &&
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 &&
235 echo "something" > some.txt &&
237 git commit -m "Add something"
241 git clone upstream 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
249 stg import --mbox ../downstream.mbox &&
250 stg top | grep "something-else" &&
251 grep "else µ" some.txt