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 'Apply a patch and edit message' \
37 test_set_editor "$(pwd)/fake-editor" &&
38 test_when_finished test_set_editor false &&
39 stg import --edit "$TEST_DIRECTORY"/t1800/git-diff &&
40 [ $(git cat-file -p $(stg id) \
41 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
42 [ $(git cat-file -p $(stg id) | grep -c "fake edit") = 1 ] &&
47 'Apply a patch from a URL' \
49 stg import -u "file://$TEST_DIRECTORY/t1800/git-diff" &&
50 [ $(git cat-file -p $(stg id) \
51 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
56 'Apply a patch created with "git diff" using -p1' \
58 stg import -p1 "$TEST_DIRECTORY"/t1800/git-diff &&
59 [ $(git cat-file -p $(stg id) \
60 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
65 'Apply a patch created with "git diff" using -p0' \
67 stg import -p0 "$TEST_DIRECTORY"/t1800/git-diff-p0 &&
68 [ $(git cat-file -p $(stg id) \
69 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
74 'Apply a patch created with "git diff" using -p2' \
76 command_error stg import -p2 "$TEST_DIRECTORY"/t1800/git-diff &&
77 [ $(git cat-file -p $(stg id) \
78 | grep -c "tree a5850c97490398571d41d6304dd940800550f507") = 1 ] &&
83 'Apply a patch created with "git diff" from a subdirectory' \
85 mkdir subdir && cd subdir &&
86 stg import "$TEST_DIRECTORY"/t1800/git-diff &&
87 [ $(git cat-file -p $(stg id) \
88 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
94 'Apply a patch created with GNU diff' \
96 stg import "$TEST_DIRECTORY"/t1800/gnu-diff &&
97 [ $(git cat-file -p $(stg id) \
98 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
102 test_expect_success \
103 'Apply a patch created with "stg export"' \
105 stg import "$TEST_DIRECTORY"/t1800/stg-export &&
106 [ $(git cat-file -p $(stg id) \
107 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
112 test_expect_success \
113 'Apply a bzip2 patch created with "git diff"' \
115 bzip2 -c "$TEST_DIRECTORY"/t1800/git-diff > bzip2-git-diff &&
116 stg import bzip2-git-diff &&
117 [ $(git cat-file -p $(stg id) \
118 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
121 test_expect_success \
122 'Apply a bzip2 patch with a .bz2 suffix' \
124 bzip2 -c "$TEST_DIRECTORY"/t1800/git-diff > git-diff.bz2 &&
125 stg import git-diff.bz2 &&
126 [ $(git cat-file -p $(stg id) \
127 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
131 test_expect_success \
132 'Apply a gzip patch created with GNU diff' \
134 gzip -c "$TEST_DIRECTORY"/t1800/gnu-diff > gzip-gnu-diff &&
135 stg import gzip-gnu-diff &&
136 [ $(git cat-file -p $(stg id) \
137 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
140 test_expect_success \
141 'Apply a gzip patch with a .gz suffix' \
143 gzip -c "$TEST_DIRECTORY"/t1800/gnu-diff > gnu-diff.gz &&
144 stg import gnu-diff.gz &&
145 [ $(git cat-file -p $(stg id) \
146 | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
150 test_expect_success \
151 'apply a series from a tarball' \
153 rm -f jabberwocky.txt &&
154 touch jabberwocky.txt &&
155 stg add jabberwocky.txt &&
156 git commit -m "empty file" jabberwocky.txt &&
158 cd "$TEST_DIRECTORY"/t1800 &&
159 tar -cjf "$HOME"/jabberwocky.tar.bz2 patches
161 stg import --series jabberwocky.tar.bz2 &&
162 [ $(git cat-file -p $(stg id) \
163 | grep -c "tree 2c33937252a21f1550c0bf21f1de534b68f69635") = 1 ]
166 test_expect_success \
167 'Import with author options' \
169 stg show | grep -e "Author: Clark Williams <williams@redhat.com>" &&
170 stg delete --top --spill &&
171 stg diff > some.patch &&
172 git reset jabberwocky.txt &&
173 git checkout jabberwocky.txt &&
174 stg import --authname "Some Author" \
175 --authemail "some@example.com" \
176 --authdate 2005-04-07T22:13:13 \
179 stg show | grep -e "Author: Some Author <some@example.com>" &&
180 stg show | grep -E "Date: +Thu Apr 7 22:13:13 2005 \+0000" &&
184 test_expect_success \
185 'Import with bad author_date option' \
188 command_error stg import --authdate "a long time ago" some.patch 2>&1 |
189 grep -e "\"a long time ago\" is not a valid date"
192 test_expect_success \
193 'Import from stdin' \
196 stg import --name xxx \
197 --authname "Some Author" \
198 --authemail "some@example.com" &&
199 test "$(echo $(stg top))" = "xxx" &&
200 stg show | grep -e "Author: Some Author <some@example.com>"
203 test_expect_success \
204 'Replace existing patch' \
207 stg import --replace \
209 --author "Different Author <diff@example.com>" \
211 test "$(echo $(stg top))" = "xxx" &&
212 stg show | grep -e "Author: Different Author <diff@example.com>"
215 test_expect_success \
216 'Ignore patch reapplication' \
218 stg top | grep -e "xxx" &&
219 stg import --ignore --name xxx some.patch &&
220 test "$(echo $(stg top))" = "xxx" &&
221 stg show | grep -e "Author: Different Author <diff@example.com>" &&
225 test_expect_success \
226 'Import from stdin no name' \
229 stg import --ignore --author "Some Author <some@example.com>" &&
230 stg top | grep -e "unknown" &&
231 stg show | grep -e "Author: Some Author <some@example.com>" &&
235 test_expect_success \
236 'Import empty patch with sign-off' \
239 stg import -n empty --sign 2>&1 |
240 grep -e "No diff found, creating empty patch" &&
241 stg show | grep -e "Signed-off-by: C Ó Mitter <committer@example.com>" &&
242 stg top | grep -e "empty" &&
244 stg top | grep -v -e "empty"
247 test_expect_success \
248 'Import series from stdin' \
251 stg import --series &&
252 stg top | grep -e "some.patch" &&
256 test_expect_success \
259 command_error stg import --url 2>&1 |
260 grep -e "URL argument required"
263 test_expect_success \
264 'Too many arguments' \
266 command_error stg import some.patch some.patch 2>&1 |
267 grep -e "incorrect number of arguments"