Test for generated patchname with trailing period
[stgit.git] / t / t1800-import.sh
blob493052c198c52d4cd7267f804d73c3ba31e8c75a
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 "$TEST_DIRECTORY"/t1800/foo.txt . &&
10 stg add foo.txt &&
11 git commit -a -m "initial version" &&
12 stg init
15 test_expect_success 'setup fake editor' '
16 write_script fake-editor <<-\EOF
17 echo "fake edit" >"$1"
18 EOF
21 # Ensure editor is not run. Editor should only run if explicit --edit option is
22 # passed to `stg import`.
23 test_set_editor false
25 test_expect_success \
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 ] &&
31 stg delete ..
34 test_expect_success \
35 'Attempt import same patch twice' \
37 stg import "$TEST_DIRECTORY"/t1800/git-diff &&
38 stg pop &&
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
44 test_expect_success \
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 ] &&
53 stg delete ..
56 test_expect_success \
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 ] &&
62 stg delete ..
65 test_expect_success \
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 ] &&
71 stg delete ..
74 test_expect_success \
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 ] &&
83 stg delete ..
86 test_expect_success \
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 ] &&
92 stg delete ..
95 test_expect_success \
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 ] &&
101 stg delete ..
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 ] &&
111 stg delete .. &&
112 cd ..
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 ] &&
121 stg delete ..
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 ] &&
130 stg delete ..
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 ] &&
141 stg delete ..
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 ] &&
150 stg delete ..
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 ] &&
160 stg delete ..
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 ] &&
169 stg delete ..
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
182 ) &&
183 stg import --series jabberwocky.tar.bz2 &&
184 [ $(git cat-file -p $(stg id) \
185 | grep -c "tree 2c33937252a21f1550c0bf21f1de534b68f69635") = 1 ] &&
186 stg delete ..
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 \
208 --stripname \
209 -C5 \
210 some.patch &&
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" &&
213 stg delete --top
216 test_expect_success \
217 'Import with bad author_date option' \
219 stg delete --top &&
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' \
227 cat some.patch |
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' \
238 stg pop xxx &&
239 stg import --replace \
240 --name xxx \
241 --author "Different Author <diff@example.com>" \
242 some.patch &&
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>" &&
254 stg delete --top
257 test_expect_success \
258 'Import from stdin no name' \
260 cat some.patch |
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>" &&
264 stg delete --top
267 test_expect_success \
268 'Import empty patch with sign-off' \
270 echo "" |
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" &&
275 stg clean &&
276 stg top | grep -v -e "empty"
279 test_expect_success \
280 'Import series from stdin' \
282 echo "some.patch" |
283 stg import --series &&
284 stg top | grep -e "some.patch" &&
285 stg delete --top
288 test_expect_success \
289 'Attempt url' \
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"
302 test_done