2 # Copyright (c) 2006 Karl Hasselström
3 test_description
='Test the import command'
7 'Initialize the StGit repository' \
9 cp "$TEST_DIRECTORY"/t1800/foo.txt . &&
11 git commit -a -m "initial version" &&
15 test_expect_success
'setup fake editor' '
16 write_script fake-editor <<-\EOF
17 echo "fake edit" >"$1"
21 # Ensure editor is not run. Editor should only run if explicit --edit option is
22 # passed to `stg import`.
26 'Apply a patch created with "git diff"' \
28 stg import "$TEST_DIRECTORY"/t1800/git-diff &&
29 [ $(git cat-file -p $(stg id) \
30 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
35 'Attempt import same patch twice' \
37 stg import "$TEST_DIRECTORY"/t1800/git-diff &&
39 stg import "$TEST_DIRECTORY"/t1800/git-diff &&
40 test "$(echo $(stg series --noprefix))" = "git-diff-1 git-diff" &&
41 stg delete git-diff git-diff-1
45 'Apply a patch and edit message' \
47 test_set_editor "$(pwd)/fake-editor" &&
48 test_when_finished test_set_editor false &&
49 stg import --edit "$TEST_DIRECTORY"/t1800/git-diff &&
50 [ $(git cat-file -p $(stg id) \
51 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
52 [ $(git cat-file -p $(stg id) | grep -c "fake edit") = 1 ] &&
57 'Apply a patch from a URL' \
59 stg import -u "file://$TEST_DIRECTORY/t1800/git-diff" &&
60 [ $(git cat-file -p $(stg id) \
61 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
66 'Apply a patch created with "git diff" using -p1' \
68 stg import -p1 "$TEST_DIRECTORY"/t1800/git-diff &&
69 [ $(git cat-file -p $(stg id) \
70 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
75 'Apply a patch with ".." in filename' \
77 cp "$TEST_DIRECTORY"/t1800/git-diff git..diff &&
78 test_when_finished rm git..diff &&
79 stg import -p1 git..diff &&
80 test "$(echo $(stg series --noprefix))" = "git.diff" &&
81 [ $(git cat-file -p $(stg id) \
82 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
87 'Apply a patch created with "git diff" using -p0' \
89 stg import -p0 "$TEST_DIRECTORY"/t1800/git-diff-p0 &&
90 [ $(git cat-file -p $(stg id) \
91 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
96 'Apply a patch created with "git diff" using -p2' \
98 command_error stg import -p2 "$TEST_DIRECTORY"/t1800/git-diff &&
99 [ $(git cat-file -p $(stg id) \
100 | grep -c "tree a5850c97490398571d41d6304dd940800550f507") = 1 ] &&
104 test_expect_success \
105 'Apply a patch created with "git diff" from a subdirectory' \
107 mkdir subdir && cd subdir &&
108 stg import "$TEST_DIRECTORY"/t1800/git-diff &&
109 [ $(git cat-file -p $(stg id) \
110 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
115 test_expect_success \
116 'Apply a patch created with GNU diff' \
118 stg import "$TEST_DIRECTORY"/t1800/gnu-diff &&
119 [ $(git cat-file -p $(stg id) \
120 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
124 test_expect_success \
125 'Apply a patch created with "stg export"' \
127 stg import "$TEST_DIRECTORY"/t1800/stg-export &&
128 [ $(git cat-file -p $(stg id) \
129 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
134 test_expect_success \
135 'Apply a bzip2 patch created with "git diff"' \
137 bzip2 -c "$TEST_DIRECTORY"/t1800/git-diff > bzip2-git-diff &&
138 stg import bzip2-git-diff &&
139 [ $(git cat-file -p $(stg id) \
140 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
143 test_expect_success \
144 'Apply a bzip2 patch with a .bz2 suffix' \
146 bzip2 -c "$TEST_DIRECTORY"/t1800/git-diff > git-diff.bz2 &&
147 stg import git-diff.bz2 &&
148 [ $(git cat-file -p $(stg id) \
149 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
153 test_expect_success \
154 'Apply a gzip patch created with GNU diff' \
156 gzip -c "$TEST_DIRECTORY"/t1800/gnu-diff > gzip-gnu-diff &&
157 stg import gzip-gnu-diff &&
158 [ $(git cat-file -p $(stg id) \
159 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
162 test_expect_success \
163 'Apply a gzip patch with a .gz suffix' \
165 gzip -c "$TEST_DIRECTORY"/t1800/gnu-diff > gnu-diff.gz &&
166 stg import gnu-diff.gz &&
167 [ $(git cat-file -p $(stg id) \
168 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
172 test_expect_success \
173 'Apply a series from a tarball' \
175 rm -f jabberwocky.txt &&
176 touch jabberwocky.txt &&
177 stg add jabberwocky.txt &&
178 git commit -m "empty file" jabberwocky.txt &&
180 cd "$TEST_DIRECTORY"/t1800 &&
181 tar -cjf "$HOME"/jabberwocky.tar.bz2 patches
183 stg import --series jabberwocky.tar.bz2 &&
184 [ $(git cat-file -p $(stg id) \
185 | grep -c "tree 2c33937252a21f1550c0bf21f1de534b68f69635") = 1 ] &&
189 test_expect_success \
190 'Apply a series from a tarball url' \
192 stg import --url --series "file://$(pwd)/jabberwocky.tar.bz2" &&
193 [ $(git cat-file -p $(stg id) \
194 | grep -c "tree 2c33937252a21f1550c0bf21f1de534b68f69635") = 1 ]
197 test_expect_success \
198 'Import with author options' \
200 stg show | grep -e "Author: Clark Williams <williams@redhat.com>" &&
201 stg delete --top --spill &&
202 stg diff > some.patch &&
203 git reset jabberwocky.txt &&
204 git checkout jabberwocky.txt &&
205 stg import --authname "Some Author" \
206 --authemail "some@example.com" \
207 --authdate 2005-04-07T22:13:13 \
211 stg show | grep -e "Author: Some Author <some@example.com>" &&
212 stg show | grep -E "Date: +Thu Apr 7 22:13:13 2005 \+0000" &&
216 test_expect_success \
217 'Import with bad author_date option' \
220 command_error stg import --authdate "a long time ago" some.patch 2>&1 |
221 grep -e "\"a long time ago\" is not a valid date"
224 test_expect_success \
225 'Import from stdin' \
228 stg import --name xxx \
229 --authname "Some Author" \
230 --authemail "some@example.com" &&
231 test "$(echo $(stg top))" = "xxx" &&
232 stg show | grep -e "Author: Some Author <some@example.com>"
235 test_expect_success \
236 'Replace existing patch' \
239 stg import --replace \
241 --author "Different Author <diff@example.com>" \
243 test "$(echo $(stg top))" = "xxx" &&
244 stg show | grep -e "Author: Different Author <diff@example.com>"
247 test_expect_success \
248 'Ignore patch reapplication' \
250 stg top | grep -e "xxx" &&
251 stg import --ignore --name xxx some.patch &&
252 test "$(echo $(stg top))" = "xxx" &&
253 stg show | grep -e "Author: Different Author <diff@example.com>" &&
257 test_expect_success \
258 'Import from stdin no name' \
261 stg import --ignore --author "Some Author <some@example.com>" &&
262 stg top | grep -e "patch" &&
263 stg show | grep -e "Author: Some Author <some@example.com>" &&
267 test_expect_success \
268 'Import empty patch with sign-off' \
271 stg import -n empty --sign 2>&1 |
272 grep -e "No diff found, creating empty patch" &&
273 stg show | grep -e "Signed-off-by: C Ó Mitter <committer@example.com>" &&
274 stg top | grep -e "empty" &&
276 stg top | grep -v -e "empty"
279 test_expect_success \
280 'Import series from stdin' \
283 stg import --series &&
284 stg top | grep -e "some.patch" &&
288 test_expect_success \
291 command_error stg import --url 2>&1 |
292 grep -e "URL argument required"
295 test_expect_success \
296 'Too many arguments' \
298 command_error stg import some.patch some.patch 2>&1 |
299 grep -e "incorrect number of arguments"