]>
Commit | Line | Data |
---|---|---|
94c0956b DS |
1 | #!/bin/sh |
2 | ||
3 | test_description='sparse checkout builtin tests' | |
4 | ||
06d53148 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
ac873c2b JS |
8 | GIT_TEST_SPLIT_INDEX=false |
9 | export GIT_TEST_SPLIT_INDEX | |
10 | ||
94c0956b DS |
11 | . ./test-lib.sh |
12 | ||
761e3d26 EM |
13 | list_files() { |
14 | # Do not replace this with 'ls "$1"', as "ls" with BSD-lineage | |
15 | # enables "-A" by default for root and ends up including ".git" and | |
16 | # such in its output. (Note, though, that running the test suite as | |
17 | # root is generally not recommended.) | |
18 | (cd "$1" && printf '%s\n' *) | |
19 | } | |
20 | ||
522e6417 DS |
21 | check_files() { |
22 | list_files "$1" >actual && | |
23 | shift && | |
24 | printf "%s\n" $@ >expect && | |
25 | test_cmp expect actual | |
26 | } | |
27 | ||
94c0956b DS |
28 | test_expect_success 'setup' ' |
29 | git init repo && | |
30 | ( | |
31 | cd repo && | |
32 | echo "initial" >a && | |
33 | mkdir folder1 folder2 deep && | |
34 | mkdir deep/deeper1 deep/deeper2 && | |
35 | mkdir deep/deeper1/deepest && | |
36 | cp a folder1 && | |
37 | cp a folder2 && | |
38 | cp a deep && | |
39 | cp a deep/deeper1 && | |
40 | cp a deep/deeper2 && | |
41 | cp a deep/deeper1/deepest && | |
42 | git add . && | |
43 | git commit -m "initial commit" | |
44 | ) | |
45 | ' | |
46 | ||
45c5e470 EN |
47 | test_expect_success 'git sparse-checkout list (not sparse)' ' |
48 | test_must_fail git -C repo sparse-checkout list >list 2>err && | |
49 | test_must_be_empty list && | |
6789275d | 50 | test_grep "this worktree is not sparse" err |
45c5e470 EN |
51 | ' |
52 | ||
53 | test_expect_success 'git sparse-checkout list (not sparse)' ' | |
54 | git -C repo sparse-checkout set && | |
55 | rm repo/.git/info/sparse-checkout && | |
94c0956b DS |
56 | git -C repo sparse-checkout list >list 2>err && |
57 | test_must_be_empty list && | |
6789275d | 58 | test_grep "this worktree is not sparse (sparse-checkout file may not exist)" err |
94c0956b DS |
59 | ' |
60 | ||
61 | test_expect_success 'git sparse-checkout list (populated)' ' | |
62 | test_when_finished rm -f repo/.git/info/sparse-checkout && | |
d622c343 DS |
63 | cat >repo/.git/info/sparse-checkout <<-\EOF && |
64 | /folder1/* | |
65 | /deep/ | |
66 | **/a | |
67 | !*bin* | |
94c0956b DS |
68 | EOF |
69 | cp repo/.git/info/sparse-checkout expect && | |
70 | git -C repo sparse-checkout list >list && | |
71 | test_cmp expect list | |
72 | ' | |
73 | ||
bab3c359 | 74 | test_expect_success 'git sparse-checkout init' ' |
dde13589 | 75 | git -C repo sparse-checkout init --no-cone && |
d622c343 DS |
76 | cat >expect <<-\EOF && |
77 | /* | |
78 | !/*/ | |
bab3c359 DS |
79 | EOF |
80 | test_cmp expect repo/.git/info/sparse-checkout && | |
81 | test_cmp_config -C repo true core.sparsecheckout && | |
522e6417 | 82 | check_files repo a |
bab3c359 DS |
83 | ' |
84 | ||
7f44842a JT |
85 | test_expect_success 'git sparse-checkout init in empty repo' ' |
86 | test_when_finished rm -rf empty-repo blank-template && | |
87 | git init --template= empty-repo && | |
88 | git -C empty-repo sparse-checkout init | |
89 | ' | |
90 | ||
bab3c359 DS |
91 | test_expect_success 'git sparse-checkout list after init' ' |
92 | git -C repo sparse-checkout list >actual && | |
d622c343 DS |
93 | cat >expect <<-\EOF && |
94 | /* | |
95 | !/*/ | |
bab3c359 DS |
96 | EOF |
97 | test_cmp expect actual | |
98 | ' | |
99 | ||
100 | test_expect_success 'init with existing sparse-checkout' ' | |
101 | echo "*folder*" >> repo/.git/info/sparse-checkout && | |
102 | git -C repo sparse-checkout init && | |
d622c343 DS |
103 | cat >expect <<-\EOF && |
104 | /* | |
105 | !/*/ | |
106 | *folder* | |
bab3c359 DS |
107 | EOF |
108 | test_cmp expect repo/.git/info/sparse-checkout && | |
522e6417 | 109 | check_files repo a folder1 folder2 |
bab3c359 DS |
110 | ' |
111 | ||
d89f09c8 | 112 | test_expect_success 'clone --sparse' ' |
47dbf10d | 113 | git clone --sparse "file://$(pwd)/repo" clone && |
dde13589 | 114 | git -C clone sparse-checkout reapply --no-cone && |
d89f09c8 | 115 | git -C clone sparse-checkout list >actual && |
d622c343 DS |
116 | cat >expect <<-\EOF && |
117 | /* | |
118 | !/*/ | |
d89f09c8 DS |
119 | EOF |
120 | test_cmp expect actual && | |
522e6417 | 121 | check_files clone a |
d89f09c8 DS |
122 | ' |
123 | ||
391c3a10 DS |
124 | test_expect_success 'switching to cone mode with non-cone mode patterns' ' |
125 | git init bad-patterns && | |
126 | ( | |
127 | cd bad-patterns && | |
dde13589 | 128 | git sparse-checkout init --no-cone && |
391c3a10 | 129 | git sparse-checkout add dir && |
7316dc5f | 130 | git config --worktree core.sparseCheckoutCone true && |
a3eca584 DS |
131 | test_must_fail git sparse-checkout add dir 2>err && |
132 | grep "existing sparse-checkout patterns do not use cone mode" err | |
391c3a10 DS |
133 | ) |
134 | ' | |
135 | ||
b5bfc08a EN |
136 | test_expect_success 'interaction with clone --no-checkout (unborn index)' ' |
137 | git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout && | |
138 | git -C clone_no_checkout sparse-checkout init --cone && | |
139 | git -C clone_no_checkout sparse-checkout set folder1 && | |
140 | ||
141 | git -C clone_no_checkout sparse-checkout list >actual && | |
142 | cat >expect <<-\EOF && | |
143 | folder1 | |
144 | EOF | |
145 | test_cmp expect actual && | |
146 | ||
147 | # nothing checked out, expect "No such file or directory" | |
148 | ! ls clone_no_checkout/* >actual && | |
149 | test_must_be_empty actual && | |
150 | test_path_is_missing clone_no_checkout/.git/index && | |
151 | ||
152 | # No branch is checked out until we manually switch to one | |
06d53148 | 153 | git -C clone_no_checkout switch main && |
b5bfc08a EN |
154 | test_path_is_file clone_no_checkout/.git/index && |
155 | check_files clone_no_checkout a folder1 | |
156 | ' | |
157 | ||
f6039a94 | 158 | test_expect_success 'set enables config' ' |
53255916 | 159 | git init worktree-config && |
f6039a94 | 160 | ( |
53255916 | 161 | cd worktree-config && |
f6039a94 DS |
162 | test_commit test file && |
163 | test_path_is_missing .git/config.worktree && | |
ace224ac | 164 | git sparse-checkout set nothing && |
f6039a94 | 165 | test_path_is_file .git/config.worktree && |
f6039a94 DS |
166 | test_cmp_config true core.sparseCheckout |
167 | ) | |
168 | ' | |
169 | ||
170 | test_expect_success 'set sparse-checkout using builtin' ' | |
171 | git -C repo sparse-checkout set "/*" "!/*/" "*folder*" && | |
d622c343 DS |
172 | cat >expect <<-\EOF && |
173 | /* | |
174 | !/*/ | |
175 | *folder* | |
f6039a94 DS |
176 | EOF |
177 | git -C repo sparse-checkout list >actual && | |
178 | test_cmp expect actual && | |
179 | test_cmp expect repo/.git/info/sparse-checkout && | |
522e6417 | 180 | check_files repo a folder1 folder2 |
f6039a94 DS |
181 | ' |
182 | ||
7bffca95 | 183 | test_expect_success 'set sparse-checkout using --stdin' ' |
d622c343 DS |
184 | cat >expect <<-\EOF && |
185 | /* | |
186 | !/*/ | |
187 | /folder1/ | |
188 | /folder2/ | |
7bffca95 DS |
189 | EOF |
190 | git -C repo sparse-checkout set --stdin <expect && | |
191 | git -C repo sparse-checkout list >actual && | |
192 | test_cmp expect actual && | |
193 | test_cmp expect repo/.git/info/sparse-checkout && | |
522e6417 | 194 | check_files repo "a folder1 folder2" |
7bffca95 DS |
195 | ' |
196 | ||
2631dc87 | 197 | test_expect_success 'add to sparse-checkout' ' |
a3eca584 DS |
198 | cat repo/.git/info/sparse-checkout >old && |
199 | test_when_finished cp old repo/.git/info/sparse-checkout && | |
2631dc87 DS |
200 | cat >add <<-\EOF && |
201 | pattern1 | |
202 | /folder1/ | |
203 | pattern2 | |
204 | EOF | |
a3eca584 | 205 | cat old >expect && |
2631dc87 DS |
206 | cat add >>expect && |
207 | git -C repo sparse-checkout add --stdin <add && | |
208 | git -C repo sparse-checkout list >actual && | |
209 | test_cmp expect actual && | |
210 | test_cmp expect repo/.git/info/sparse-checkout && | |
211 | check_files repo "a folder1 folder2" | |
212 | ' | |
213 | ||
53255916 DS |
214 | test_expect_success 'worktree: add copies sparse-checkout patterns' ' |
215 | cat repo/.git/info/sparse-checkout >old && | |
216 | test_when_finished cp old repo/.git/info/sparse-checkout && | |
217 | test_when_finished git -C repo worktree remove ../worktree && | |
218 | git -C repo sparse-checkout set --no-cone "/*" && | |
219 | git -C repo worktree add --quiet ../worktree 2>err && | |
220 | test_must_be_empty err && | |
221 | new="$(git -C worktree rev-parse --git-path info/sparse-checkout)" && | |
222 | test_path_is_file "$new" && | |
223 | test_cmp repo/.git/info/sparse-checkout "$new" && | |
224 | git -C worktree sparse-checkout set --cone && | |
225 | test_cmp_config -C worktree true core.sparseCheckoutCone && | |
226 | test_must_fail git -C repo core.sparseCheckoutCone | |
227 | ' | |
228 | ||
879321eb DS |
229 | test_expect_success 'cone mode: match patterns' ' |
230 | git -C repo config --worktree core.sparseCheckoutCone true && | |
231 | rm -rf repo/a repo/folder1 repo/folder2 && | |
96cc8ab5 | 232 | git -C repo read-tree -mu HEAD 2>err && |
6789275d | 233 | test_grep ! "disabling cone patterns" err && |
879321eb | 234 | git -C repo reset --hard && |
522e6417 | 235 | check_files repo a folder1 folder2 |
879321eb DS |
236 | ' |
237 | ||
96cc8ab5 DS |
238 | test_expect_success 'cone mode: warn on bad pattern' ' |
239 | test_when_finished mv sparse-checkout repo/.git/info/ && | |
240 | cp repo/.git/info/sparse-checkout . && | |
5842710d | 241 | echo "!/deep/deeper/*/" >>repo/.git/info/sparse-checkout && |
96cc8ab5 | 242 | git -C repo read-tree -mu HEAD 2>err && |
6789275d | 243 | test_grep "unrecognized negative pattern" err |
96cc8ab5 DS |
244 | ' |
245 | ||
72918c1a | 246 | test_expect_success 'sparse-checkout disable' ' |
99dfa6f9 | 247 | test_when_finished rm -rf repo/.git/info/sparse-checkout && |
72918c1a | 248 | git -C repo sparse-checkout disable && |
99dfa6f9 | 249 | test_path_is_file repo/.git/info/sparse-checkout && |
72918c1a DS |
250 | git -C repo config --list >config && |
251 | test_must_fail git config core.sparseCheckout && | |
522e6417 | 252 | check_files repo a deep folder1 folder2 |
72918c1a DS |
253 | ' |
254 | ||
dcc5fd5f | 255 | test_expect_success 'sparse-index enabled and disabled' ' |
ac873c2b JS |
256 | git -C repo sparse-checkout init --cone --sparse-index && |
257 | test_cmp_config -C repo true index.sparse && | |
258 | git -C repo ls-files --sparse >sparse && | |
259 | git -C repo sparse-checkout disable && | |
260 | git -C repo ls-files --sparse >full && | |
c2a29405 | 261 | |
ac873c2b JS |
262 | cat >expect <<-\EOF && |
263 | @@ -1,4 +1,7 @@ | |
264 | a | |
265 | -deep/ | |
266 | -folder1/ | |
267 | -folder2/ | |
268 | +deep/a | |
269 | +deep/deeper1/a | |
270 | +deep/deeper1/deepest/a | |
271 | +deep/deeper2/a | |
272 | +folder1/a | |
273 | +folder2/a | |
274 | EOF | |
c2a29405 | 275 | |
ac873c2b JS |
276 | diff -u sparse full | tail -n +3 >actual && |
277 | test_cmp expect actual && | |
c2a29405 | 278 | |
ac873c2b | 279 | git -C repo config --list >config && |
6249ce2d | 280 | test_cmp_config -C repo false index.sparse |
dcc5fd5f DS |
281 | ' |
282 | ||
af09ce24 DS |
283 | test_expect_success 'cone mode: init and set' ' |
284 | git -C repo sparse-checkout init --cone && | |
285 | git -C repo config --list >config && | |
6789275d | 286 | test_grep "core.sparsecheckoutcone=true" config && |
761e3d26 | 287 | list_files repo >dir && |
af09ce24 DS |
288 | echo a >expect && |
289 | test_cmp expect dir && | |
290 | git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err && | |
291 | test_must_be_empty err && | |
522e6417 DS |
292 | check_files repo a deep && |
293 | check_files repo/deep a deeper1 && | |
294 | check_files repo/deep/deeper1 a deepest && | |
d622c343 DS |
295 | cat >expect <<-\EOF && |
296 | /* | |
297 | !/*/ | |
298 | /deep/ | |
299 | !/deep/*/ | |
300 | /deep/deeper1/ | |
301 | !/deep/deeper1/*/ | |
302 | /deep/deeper1/deepest/ | |
af09ce24 DS |
303 | EOF |
304 | test_cmp expect repo/.git/info/sparse-checkout && | |
d622c343 DS |
305 | git -C repo sparse-checkout set --stdin 2>err <<-\EOF && |
306 | folder1 | |
307 | folder2 | |
af09ce24 DS |
308 | EOF |
309 | test_must_be_empty err && | |
522e6417 | 310 | check_files repo a folder1 folder2 |
af09ce24 DS |
311 | ' |
312 | ||
de11951b | 313 | test_expect_success 'cone mode: list' ' |
d622c343 DS |
314 | cat >expect <<-\EOF && |
315 | folder1 | |
316 | folder2 | |
de11951b DS |
317 | EOF |
318 | git -C repo sparse-checkout set --stdin <expect && | |
319 | git -C repo sparse-checkout list >actual 2>err && | |
320 | test_must_be_empty err && | |
321 | test_cmp expect actual | |
322 | ' | |
323 | ||
e9de487a DS |
324 | test_expect_success 'cone mode: set with nested folders' ' |
325 | git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err && | |
326 | test_line_count = 0 err && | |
d622c343 DS |
327 | cat >expect <<-\EOF && |
328 | /* | |
329 | !/*/ | |
330 | /deep/ | |
e9de487a DS |
331 | EOF |
332 | test_cmp repo/.git/info/sparse-checkout expect | |
333 | ' | |
334 | ||
2631dc87 DS |
335 | test_expect_success 'cone mode: add independent path' ' |
336 | git -C repo sparse-checkout set deep/deeper1 && | |
f8ab66f9 | 337 | git -C repo sparse-checkout add --end-of-options folder1 && |
2631dc87 DS |
338 | cat >expect <<-\EOF && |
339 | /* | |
340 | !/*/ | |
341 | /deep/ | |
342 | !/deep/*/ | |
343 | /deep/deeper1/ | |
344 | /folder1/ | |
345 | EOF | |
346 | test_cmp expect repo/.git/info/sparse-checkout && | |
347 | check_files repo a deep folder1 | |
348 | ' | |
349 | ||
350 | test_expect_success 'cone mode: add sibling path' ' | |
351 | git -C repo sparse-checkout set deep/deeper1 && | |
352 | git -C repo sparse-checkout add deep/deeper2 && | |
353 | cat >expect <<-\EOF && | |
354 | /* | |
355 | !/*/ | |
356 | /deep/ | |
357 | !/deep/*/ | |
358 | /deep/deeper1/ | |
359 | /deep/deeper2/ | |
360 | EOF | |
361 | test_cmp expect repo/.git/info/sparse-checkout && | |
362 | check_files repo a deep | |
363 | ' | |
364 | ||
365 | test_expect_success 'cone mode: add parent path' ' | |
366 | git -C repo sparse-checkout set deep/deeper1 folder1 && | |
367 | git -C repo sparse-checkout add deep && | |
368 | cat >expect <<-\EOF && | |
369 | /* | |
370 | !/*/ | |
371 | /deep/ | |
372 | /folder1/ | |
373 | EOF | |
374 | test_cmp expect repo/.git/info/sparse-checkout && | |
375 | check_files repo a deep folder1 | |
376 | ' | |
377 | ||
f56f31af | 378 | test_expect_success 'not-up-to-date does not block rest of sparsification' ' |
72064ee5 | 379 | test_when_finished git -C repo sparse-checkout disable && |
cff4e913 | 380 | test_when_finished git -C repo reset --hard && |
2631dc87 | 381 | git -C repo sparse-checkout set deep && |
f56f31af | 382 | |
e091228e DS |
383 | echo update >repo/deep/deeper2/a && |
384 | cp repo/.git/info/sparse-checkout expect && | |
f56f31af EN |
385 | test_write_lines "!/deep/*/" "/deep/deeper1/" >>expect && |
386 | ||
387 | git -C repo sparse-checkout set deep/deeper1 2>err && | |
388 | ||
6789275d | 389 | test_grep "The following paths are not up to date" err && |
f56f31af EN |
390 | test_cmp expect repo/.git/info/sparse-checkout && |
391 | check_files repo/deep a deeper1 deeper2 && | |
392 | check_files repo/deep/deeper1 a deepest && | |
393 | check_files repo/deep/deeper1/deepest a && | |
394 | check_files repo/deep/deeper2 a | |
e091228e DS |
395 | ' |
396 | ||
397 | test_expect_success 'revert to old sparse-checkout on empty update' ' | |
398 | git init empty-test && | |
399 | ( | |
400 | echo >file && | |
401 | git add file && | |
402 | git commit -m "test" && | |
ace224ac | 403 | git sparse-checkout set nothing 2>err && |
6789275d JH |
404 | test_grep ! "Sparse checkout leaves no entry on working directory" err && |
405 | test_grep ! ".git/index.lock" err && | |
dde13589 | 406 | git sparse-checkout set --no-cone file |
e091228e DS |
407 | ) |
408 | ' | |
409 | ||
fb10ca5b DS |
410 | test_expect_success 'fail when lock is taken' ' |
411 | test_when_finished rm -rf repo/.git/info/sparse-checkout.lock && | |
412 | touch repo/.git/info/sparse-checkout.lock && | |
413 | test_must_fail git -C repo sparse-checkout set deep 2>err && | |
6789275d | 414 | test_grep "Unable to create .*\.lock" err |
fb10ca5b DS |
415 | ' |
416 | ||
f75a69f8 DS |
417 | test_expect_success '.gitignore should not warn about cone mode' ' |
418 | git -C repo config --worktree core.sparseCheckoutCone true && | |
419 | echo "**/bin/*" >repo/.gitignore && | |
420 | git -C repo reset --hard 2>err && | |
6789275d | 421 | test_grep ! "disabling cone patterns" err |
f75a69f8 DS |
422 | ' |
423 | ||
f56f31af | 424 | test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' ' |
cff4e913 DS |
425 | git clone repo dirty && |
426 | echo dirty >dirty/folder1/a && | |
f56f31af | 427 | |
dde13589 | 428 | git -C dirty sparse-checkout init --no-cone 2>err && |
6789275d | 429 | test_grep "warning.*The following paths are not up to date" err && |
f56f31af EN |
430 | |
431 | git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err && | |
6789275d | 432 | test_grep "warning.*The following paths are not up to date" err && |
f56f31af EN |
433 | test_path_is_file dirty/folder1/a && |
434 | ||
435 | git -C dirty sparse-checkout disable 2>err && | |
436 | test_must_be_empty err && | |
437 | ||
cff4e913 | 438 | git -C dirty reset --hard && |
dde13589 | 439 | git -C dirty sparse-checkout init --no-cone && |
cff4e913 | 440 | git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* && |
f56f31af EN |
441 | test_path_is_missing dirty/folder1/a && |
442 | git -C dirty sparse-checkout disable && | |
443 | test_path_is_file dirty/folder1/a | |
cff4e913 DS |
444 | ' |
445 | ||
ebb568b9 EN |
446 | test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged status' ' |
447 | git clone repo unmerged && | |
448 | ||
449 | cat >input <<-EOF && | |
d827bce5 | 450 | 0 $ZERO_OID folder1/a |
ebb568b9 EN |
451 | 100644 $(git -C unmerged rev-parse HEAD:folder1/a) 1 folder1/a |
452 | EOF | |
453 | git -C unmerged update-index --index-info <input && | |
454 | ||
dde13589 | 455 | git -C unmerged sparse-checkout init --no-cone 2>err && |
6789275d | 456 | test_grep "warning.*The following paths are unmerged" err && |
ebb568b9 EN |
457 | |
458 | git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* 2>err && | |
6789275d | 459 | test_grep "warning.*The following paths are unmerged" err && |
ebb568b9 EN |
460 | test_path_is_file dirty/folder1/a && |
461 | ||
462 | git -C unmerged sparse-checkout disable 2>err && | |
6789275d | 463 | test_grep "warning.*The following paths are unmerged" err && |
ebb568b9 EN |
464 | |
465 | git -C unmerged reset --hard && | |
dde13589 | 466 | git -C unmerged sparse-checkout init --no-cone && |
ebb568b9 EN |
467 | git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* && |
468 | git -C unmerged sparse-checkout disable | |
469 | ' | |
470 | ||
49fdd51a | 471 | test_expect_failure 'sparse-checkout reapply' ' |
5644ca28 EN |
472 | git clone repo tweak && |
473 | ||
474 | echo dirty >tweak/deep/deeper2/a && | |
475 | ||
476 | cat >input <<-EOF && | |
d827bce5 | 477 | 0 $ZERO_OID folder1/a |
5644ca28 EN |
478 | 100644 $(git -C tweak rev-parse HEAD:folder1/a) 1 folder1/a |
479 | EOF | |
480 | git -C tweak update-index --index-info <input && | |
481 | ||
482 | git -C tweak sparse-checkout init --cone 2>err && | |
6789275d JH |
483 | test_grep "warning.*The following paths are not up to date" err && |
484 | test_grep "warning.*The following paths are unmerged" err && | |
5644ca28 EN |
485 | |
486 | git -C tweak sparse-checkout set folder2 deep/deeper1 2>err && | |
6789275d JH |
487 | test_grep "warning.*The following paths are not up to date" err && |
488 | test_grep "warning.*The following paths are unmerged" err && | |
5644ca28 EN |
489 | |
490 | git -C tweak sparse-checkout reapply 2>err && | |
6789275d | 491 | test_grep "warning.*The following paths are not up to date" err && |
5644ca28 | 492 | test_path_is_file tweak/deep/deeper2/a && |
6789275d | 493 | test_grep "warning.*The following paths are unmerged" err && |
5644ca28 EN |
494 | test_path_is_file tweak/folder1/a && |
495 | ||
496 | git -C tweak checkout HEAD deep/deeper2/a && | |
497 | git -C tweak sparse-checkout reapply 2>err && | |
6789275d | 498 | test_grep ! "warning.*The following paths are not up to date" err && |
5644ca28 | 499 | test_path_is_missing tweak/deep/deeper2/a && |
6789275d | 500 | test_grep "warning.*The following paths are unmerged" err && |
5644ca28 EN |
501 | test_path_is_file tweak/folder1/a && |
502 | ||
49fdd51a DS |
503 | # NEEDSWORK: We are asking to update a file outside of the |
504 | # sparse-checkout cone, but this is no longer allowed. | |
5644ca28 EN |
505 | git -C tweak add folder1/a && |
506 | git -C tweak sparse-checkout reapply 2>err && | |
507 | test_must_be_empty err && | |
508 | test_path_is_missing tweak/deep/deeper2/a && | |
509 | test_path_is_missing tweak/folder1/a && | |
510 | ||
511 | git -C tweak sparse-checkout disable | |
512 | ' | |
513 | ||
f748012e EN |
514 | test_expect_success 'reapply can handle config options' ' |
515 | git -C repo sparse-checkout init --cone --no-sparse-index && | |
516 | git -C repo config --worktree --list >actual && | |
517 | cat >expect <<-\EOF && | |
518 | core.sparsecheckout=true | |
519 | core.sparsecheckoutcone=true | |
96717646 | 520 | index.sparse=false |
f748012e EN |
521 | EOF |
522 | test_cmp expect actual && | |
523 | ||
524 | git -C repo sparse-checkout reapply --no-cone --no-sparse-index && | |
525 | git -C repo config --worktree --list >actual && | |
526 | cat >expect <<-\EOF && | |
527 | core.sparsecheckout=true | |
96717646 JH |
528 | core.sparsecheckoutcone=false |
529 | index.sparse=false | |
f748012e EN |
530 | EOF |
531 | test_cmp expect actual && | |
532 | ||
533 | git -C repo sparse-checkout reapply --cone --sparse-index && | |
534 | git -C repo config --worktree --list >actual && | |
535 | cat >expect <<-\EOF && | |
536 | core.sparsecheckout=true | |
537 | core.sparsecheckoutcone=true | |
538 | index.sparse=true | |
539 | EOF | |
540 | test_cmp expect actual && | |
541 | ||
542 | git -C repo sparse-checkout disable | |
543 | ' | |
544 | ||
190a65f9 | 545 | test_expect_success 'cone mode: set with core.ignoreCase=true' ' |
72064ee5 | 546 | rm repo/.git/info/sparse-checkout && |
190a65f9 DS |
547 | git -C repo sparse-checkout init --cone && |
548 | git -C repo -c core.ignoreCase=true sparse-checkout set folder1 && | |
d622c343 DS |
549 | cat >expect <<-\EOF && |
550 | /* | |
551 | !/*/ | |
552 | /folder1/ | |
190a65f9 DS |
553 | EOF |
554 | test_cmp expect repo/.git/info/sparse-checkout && | |
522e6417 | 555 | check_files repo a folder1 |
190a65f9 DS |
556 | ' |
557 | ||
00408ade | 558 | test_expect_success 'setup submodules' ' |
4fd683b6 DS |
559 | git clone repo super && |
560 | ( | |
561 | cd super && | |
562 | mkdir modules && | |
8a96dbcb TB |
563 | git -c protocol.file.allow=always \ |
564 | submodule add ../repo modules/child && | |
4fd683b6 DS |
565 | git add . && |
566 | git commit -m "add submodule" && | |
567 | git sparse-checkout init --cone && | |
568 | git sparse-checkout set folder1 | |
00408ade WS |
569 | ) |
570 | ' | |
571 | ||
572 | test_expect_success 'interaction with submodules' ' | |
522e6417 DS |
573 | check_files super a folder1 modules && |
574 | check_files super/modules/child a deep folder1 folder2 | |
4fd683b6 DS |
575 | ' |
576 | ||
00408ade WS |
577 | test_expect_success 'check-rules interaction with submodules' ' |
578 | git -C super ls-tree --name-only -r HEAD >all-files && | |
579 | git -C super sparse-checkout check-rules >check-rules-matches <all-files && | |
580 | ||
6789275d JH |
581 | test_grep ! "modules/" check-rules-matches && |
582 | test_grep "folder1/" check-rules-matches | |
00408ade WS |
583 | ' |
584 | ||
3c754067 | 585 | test_expect_success 'different sparse-checkouts with worktrees' ' |
53255916 | 586 | git -C repo sparse-checkout set --cone deep folder1 && |
3c754067 | 587 | git -C repo worktree add --detach ../worktree && |
53255916 DS |
588 | check_files worktree "a deep folder1" && |
589 | git -C repo sparse-checkout set --cone folder1 && | |
590 | git -C worktree sparse-checkout set --cone deep/deeper1 && | |
591 | check_files repo "a folder1" && | |
592 | check_files worktree "a deep" | |
3c754067 DS |
593 | ' |
594 | ||
f998a3f1 | 595 | test_expect_success 'set using filename keeps file on-disk' ' |
4ce50436 | 596 | git -C repo sparse-checkout set --skip-checks a deep && |
f998a3f1 DS |
597 | cat >expect <<-\EOF && |
598 | /* | |
599 | !/*/ | |
600 | /a/ | |
601 | /deep/ | |
602 | EOF | |
603 | test_cmp expect repo/.git/info/sparse-checkout && | |
604 | check_files repo a deep | |
605 | ' | |
606 | ||
41de0c6f DS |
607 | check_read_tree_errors () { |
608 | REPO=$1 | |
609 | FILES=$2 | |
610 | ERRORS=$3 | |
d585f0e7 DS |
611 | git -C $REPO -c core.sparseCheckoutCone=false read-tree -mu HEAD 2>err && |
612 | test_must_be_empty err && | |
613 | check_files $REPO "$FILES" && | |
41de0c6f DS |
614 | git -C $REPO read-tree -mu HEAD 2>err && |
615 | if test -z "$ERRORS" | |
616 | then | |
617 | test_must_be_empty err | |
618 | else | |
6789275d | 619 | test_grep "$ERRORS" err |
41de0c6f DS |
620 | fi && |
621 | check_files $REPO $FILES | |
622 | } | |
623 | ||
624 | test_expect_success 'pattern-checks: /A/**' ' | |
625 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
626 | /* | |
627 | !/*/ | |
628 | /folder1/** | |
629 | EOF | |
630 | check_read_tree_errors repo "a folder1" "disabling cone pattern matching" | |
631 | ' | |
632 | ||
633 | test_expect_success 'pattern-checks: /A/**/B/' ' | |
634 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
635 | /* | |
636 | !/*/ | |
637 | /deep/**/deepest | |
638 | EOF | |
639 | check_read_tree_errors repo "a deep" "disabling cone pattern matching" && | |
640 | check_files repo/deep "deeper1" && | |
641 | check_files repo/deep/deeper1 "deepest" | |
642 | ' | |
643 | ||
9e6d3e64 DS |
644 | test_expect_success 'pattern-checks: too short' ' |
645 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
646 | /* | |
647 | !/*/ | |
6c11c6a1 | 648 | / |
9e6d3e64 DS |
649 | EOF |
650 | check_read_tree_errors repo "a" "disabling cone pattern matching" | |
651 | ' | |
6c11c6a1 DS |
652 | test_expect_success 'pattern-checks: not too short' ' |
653 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
654 | /* | |
655 | !/*/ | |
656 | /b/ | |
657 | EOF | |
658 | git -C repo read-tree -mu HEAD 2>err && | |
659 | test_must_be_empty err && | |
660 | check_files repo a | |
661 | ' | |
9e6d3e64 | 662 | |
9abc60f8 DS |
663 | test_expect_success 'pattern-checks: trailing "*"' ' |
664 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
665 | /* | |
666 | !/*/ | |
667 | /a* | |
668 | EOF | |
669 | check_read_tree_errors repo "a" "disabling cone pattern matching" | |
670 | ' | |
671 | ||
672 | test_expect_success 'pattern-checks: starting "*"' ' | |
673 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
674 | /* | |
675 | !/*/ | |
676 | *eep/ | |
677 | EOF | |
678 | check_read_tree_errors repo "a deep" "disabling cone pattern matching" | |
679 | ' | |
680 | ||
5842710d WS |
681 | test_expect_success 'pattern-checks: non directory pattern' ' |
682 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
683 | /deep/deeper1/a | |
684 | EOF | |
685 | check_read_tree_errors repo deep "disabling cone pattern matching" && | |
686 | check_files repo/deep deeper1 && | |
687 | check_files repo/deep/deeper1 a | |
688 | ' | |
689 | ||
9abc60f8 DS |
690 | test_expect_success 'pattern-checks: contained glob characters' ' |
691 | for c in "[a]" "\\" "?" "*" | |
692 | do | |
693 | cat >repo/.git/info/sparse-checkout <<-EOF && | |
694 | /* | |
695 | !/*/ | |
696 | something$c-else/ | |
697 | EOF | |
db5875aa | 698 | check_read_tree_errors repo "a" "disabling cone pattern matching" || return 1 |
9abc60f8 DS |
699 | done |
700 | ' | |
701 | ||
e53ffe27 | 702 | test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' ' |
4f52c2ce DS |
703 | git clone repo escaped && |
704 | TREEOID=$(git -C escaped rev-parse HEAD:folder1) && | |
705 | NEWTREE=$(git -C escaped mktree <<-EOF | |
706 | $(git -C escaped ls-tree HEAD) | |
707 | 040000 tree $TREEOID zbad\\dir | |
708 | 040000 tree $TREEOID zdoes*exist | |
e53ffe27 | 709 | 040000 tree $TREEOID zglob[!a]? |
4f52c2ce DS |
710 | EOF |
711 | ) && | |
712 | COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) && | |
713 | git -C escaped reset --hard $COMMIT && | |
e53ffe27 | 714 | check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? && |
4f52c2ce | 715 | git -C escaped sparse-checkout init --cone && |
8dd7c473 | 716 | git -C escaped sparse-checkout set --skip-checks zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" && |
d585f0e7 | 717 | cat >expect <<-\EOF && |
9abc60f8 DS |
718 | /* |
719 | !/*/ | |
4f52c2ce DS |
720 | /zbad\\dir/ |
721 | !/zbad\\dir/*/ | |
d585f0e7 | 722 | /zbad\\dir/bogus/ |
4f52c2ce | 723 | /zdoes\*exist/ |
d585f0e7 | 724 | /zdoes\*not\*exist/ |
e53ffe27 | 725 | /zglob\[!a]\?/ |
9abc60f8 | 726 | EOF |
d585f0e7 | 727 | test_cmp expect escaped/.git/info/sparse-checkout && |
e53ffe27 | 728 | check_read_tree_errors escaped "a zbad\\dir zdoes*exist zglob[!a]?" && |
e55682ea DS |
729 | git -C escaped ls-tree -d --name-only HEAD >list-expect && |
730 | git -C escaped sparse-checkout set --stdin <list-expect && | |
bd64de42 DS |
731 | cat >expect <<-\EOF && |
732 | /* | |
733 | !/*/ | |
734 | /deep/ | |
735 | /folder1/ | |
736 | /folder2/ | |
737 | /zbad\\dir/ | |
738 | /zdoes\*exist/ | |
e53ffe27 | 739 | /zglob\[!a]\?/ |
bd64de42 DS |
740 | EOF |
741 | test_cmp expect escaped/.git/info/sparse-checkout && | |
e53ffe27 | 742 | check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? && |
e55682ea DS |
743 | git -C escaped sparse-checkout list >list-actual && |
744 | test_cmp list-expect list-actual | |
9abc60f8 DS |
745 | ' |
746 | ||
ef076599 DS |
747 | test_expect_success MINGW 'cone mode replaces backslashes with slashes' ' |
748 | git -C repo sparse-checkout set deep\\deeper1 && | |
749 | cat >expect <<-\EOF && | |
750 | /* | |
751 | !/*/ | |
752 | /deep/ | |
753 | !/deep/*/ | |
754 | /deep/deeper1/ | |
755 | EOF | |
756 | test_cmp expect repo/.git/info/sparse-checkout && | |
757 | check_files repo a deep && | |
758 | check_files repo/deep a deeper1 | |
759 | ' | |
760 | ||
55dfcf95 DS |
761 | test_expect_success 'cone mode clears ignored subdirectories' ' |
762 | rm repo/.git/info/sparse-checkout && | |
763 | ||
764 | git -C repo sparse-checkout init --cone && | |
765 | git -C repo sparse-checkout set deep/deeper1 && | |
766 | ||
767 | cat >repo/.gitignore <<-\EOF && | |
768 | obj/ | |
769 | *.o | |
770 | EOF | |
771 | ||
772 | git -C repo add .gitignore && | |
773 | git -C repo commit -m ".gitignore" && | |
774 | ||
775 | mkdir -p repo/obj repo/folder1/obj repo/deep/deeper2/obj && | |
776 | for file in folder1/obj/a obj/a folder1/file.o folder1.o \ | |
777 | deep/deeper2/obj/a deep/deeper2/file.o file.o | |
778 | do | |
779 | echo ignored >repo/$file || return 1 | |
780 | done && | |
781 | ||
782 | git -C repo status --porcelain=v2 >out && | |
783 | test_must_be_empty out && | |
784 | ||
785 | git -C repo sparse-checkout reapply && | |
786 | test_path_is_missing repo/folder1 && | |
787 | test_path_is_missing repo/deep/deeper2 && | |
788 | test_path_is_dir repo/obj && | |
789 | test_path_is_file repo/file.o && | |
790 | ||
791 | git -C repo status --porcelain=v2 >out && | |
792 | test_must_be_empty out && | |
793 | ||
794 | git -C repo sparse-checkout set deep/deeper2 && | |
795 | test_path_is_missing repo/deep/deeper1 && | |
796 | test_path_is_dir repo/deep/deeper2 && | |
797 | test_path_is_dir repo/obj && | |
798 | test_path_is_file repo/file.o && | |
799 | ||
800 | >repo/deep/deeper2/ignored.o && | |
801 | >repo/deep/deeper2/untracked && | |
802 | ||
803 | # When an untracked file is in the way, all untracked files | |
804 | # (even ignored files) are preserved. | |
805 | git -C repo sparse-checkout set folder1 2>err && | |
806 | grep "contains untracked files" err && | |
807 | test_path_is_file repo/deep/deeper2/ignored.o && | |
808 | test_path_is_file repo/deep/deeper2/untracked && | |
809 | ||
810 | # The rest of the cone matches expectation | |
811 | test_path_is_missing repo/deep/deeper1 && | |
812 | test_path_is_dir repo/obj && | |
813 | test_path_is_file repo/file.o && | |
814 | ||
815 | git -C repo status --porcelain=v2 >out && | |
816 | echo "? deep/deeper2/untracked" >expect && | |
817 | test_cmp expect out | |
818 | ' | |
819 | ||
a481d437 DS |
820 | test_expect_success 'malformed cone-mode patterns' ' |
821 | git -C repo sparse-checkout init --cone && | |
822 | mkdir -p repo/foo/bar && | |
823 | touch repo/foo/bar/x repo/foo/y && | |
824 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
825 | /* | |
826 | !/*/ | |
827 | /foo/ | |
828 | !/foo/*/ | |
829 | /foo/\*/ | |
830 | EOF | |
831 | ||
832 | # Listing the patterns will notice the duplicate pattern and | |
833 | # emit a warning. It will list the patterns directly instead | |
834 | # of using the cone-mode translation to a set of directories. | |
835 | git -C repo sparse-checkout list >actual 2>err && | |
836 | test_cmp repo/.git/info/sparse-checkout actual && | |
837 | grep "warning: your sparse-checkout file may have issues: pattern .* is repeated" err && | |
838 | grep "warning: disabling cone pattern matching" err | |
839 | ' | |
840 | ||
bb8b5e9a EN |
841 | test_expect_success 'set from subdir pays attention to prefix' ' |
842 | git -C repo sparse-checkout disable && | |
843 | git -C repo/deep sparse-checkout set --cone deeper2 ../folder1 && | |
844 | ||
845 | git -C repo sparse-checkout list >actual && | |
846 | ||
847 | cat >expect <<-\EOF && | |
848 | deep/deeper2 | |
849 | folder1 | |
850 | EOF | |
851 | test_cmp expect actual | |
852 | ' | |
853 | ||
854 | test_expect_success 'add from subdir pays attention to prefix' ' | |
855 | git -C repo sparse-checkout set --cone deep/deeper2 && | |
856 | git -C repo/deep sparse-checkout add deeper1/deepest ../folder1 && | |
857 | ||
858 | git -C repo sparse-checkout list >actual && | |
859 | ||
860 | cat >expect <<-\EOF && | |
861 | deep/deeper1/deepest | |
862 | deep/deeper2 | |
863 | folder1 | |
864 | EOF | |
865 | test_cmp expect actual | |
866 | ' | |
867 | ||
868 | test_expect_success 'set from subdir in non-cone mode throws an error' ' | |
869 | git -C repo sparse-checkout disable && | |
870 | test_must_fail git -C repo/deep sparse-checkout set --no-cone deeper2 ../folder1 2>error && | |
871 | ||
872 | grep "run from the toplevel directory in non-cone mode" error | |
873 | ' | |
874 | ||
875 | test_expect_success 'set from subdir in non-cone mode throws an error' ' | |
876 | git -C repo sparse-checkout set --no-cone deep/deeper2 && | |
877 | test_must_fail git -C repo/deep sparse-checkout add deeper1/deepest ../folder1 2>error && | |
878 | ||
879 | grep "run from the toplevel directory in non-cone mode" error | |
880 | ' | |
881 | ||
4ce50436 EN |
882 | test_expect_success 'by default, cone mode will error out when passed files' ' |
883 | git -C repo sparse-checkout reapply --cone && | |
884 | test_must_fail git -C repo sparse-checkout add .gitignore 2>error && | |
885 | ||
886 | grep ".gitignore.*is not a directory" error | |
887 | ' | |
888 | ||
f8ab66f9 EN |
889 | test_expect_success 'error on mistyped command line options' ' |
890 | test_must_fail git -C repo sparse-checkout add --sikp-checks .gitignore 2>error && | |
891 | ||
892 | grep "unknown option.*sikp-checks" error | |
893 | ' | |
894 | ||
4ce50436 EN |
895 | test_expect_success 'by default, non-cone mode will warn on individual files' ' |
896 | git -C repo sparse-checkout reapply --no-cone && | |
897 | git -C repo sparse-checkout add .gitignore 2>warning && | |
898 | ||
899 | grep "pass a leading slash before paths.*if you want a single file" warning | |
900 | ' | |
901 | ||
24fc2cde WS |
902 | test_expect_success 'setup bare repo' ' |
903 | git clone --bare "file://$(pwd)/repo" bare | |
904 | ' | |
905 | test_expect_success 'list fails outside work tree' ' | |
906 | test_must_fail git -C bare sparse-checkout list 2>err && | |
6789275d | 907 | test_grep "this operation must be run in a work tree" err |
24fc2cde WS |
908 | ' |
909 | ||
910 | test_expect_success 'add fails outside work tree' ' | |
911 | test_must_fail git -C bare sparse-checkout add deeper 2>err && | |
6789275d | 912 | test_grep "this operation must be run in a work tree" err |
24fc2cde WS |
913 | ' |
914 | ||
915 | test_expect_success 'set fails outside work tree' ' | |
916 | test_must_fail git -C bare sparse-checkout set deeper 2>err && | |
6789275d | 917 | test_grep "this operation must be run in a work tree" err |
24fc2cde WS |
918 | ' |
919 | ||
920 | test_expect_success 'init fails outside work tree' ' | |
921 | test_must_fail git -C bare sparse-checkout init 2>err && | |
6789275d | 922 | test_grep "this operation must be run in a work tree" err |
24fc2cde WS |
923 | ' |
924 | ||
925 | test_expect_success 'reapply fails outside work tree' ' | |
926 | test_must_fail git -C bare sparse-checkout reapply 2>err && | |
6789275d | 927 | test_grep "this operation must be run in a work tree" err |
24fc2cde WS |
928 | ' |
929 | ||
930 | test_expect_success 'disable fails outside work tree' ' | |
931 | test_must_fail git -C bare sparse-checkout disable 2>err && | |
6789275d | 932 | test_grep "this operation must be run in a work tree" err |
24fc2cde WS |
933 | ' |
934 | ||
00408ade WS |
935 | test_expect_success 'setup clean' ' |
936 | git -C repo clean -fdx | |
937 | ' | |
938 | ||
939 | test_expect_success 'check-rules cone mode' ' | |
940 | cat >rules <<-\EOF && | |
941 | folder1 | |
942 | deep/deeper1/deepest | |
943 | EOF | |
944 | ||
945 | git -C bare ls-tree -r --name-only HEAD >all-files && | |
946 | git -C bare sparse-checkout check-rules --cone \ | |
947 | --rules-file ../rules >check-rules-file <all-files && | |
948 | ||
949 | git -C repo sparse-checkout set --cone --stdin <rules&& | |
950 | git -C repo ls-files -t >out && | |
951 | sed -n "/^S /!s/^. //p" out >ls-files && | |
952 | ||
953 | git -C repo sparse-checkout check-rules >check-rules-default <all-files && | |
954 | ||
6789275d JH |
955 | test_grep "deep/deeper1/deepest/a" check-rules-file && |
956 | test_grep ! "deep/deeper2" check-rules-file && | |
00408ade WS |
957 | |
958 | test_cmp check-rules-file ls-files && | |
959 | test_cmp check-rules-file check-rules-default | |
960 | ' | |
961 | ||
962 | test_expect_success 'check-rules non-cone mode' ' | |
963 | cat >rules <<-\EOF && | |
964 | deep/deeper1/deepest/a | |
965 | EOF | |
966 | ||
967 | git -C bare ls-tree -r --name-only HEAD >all-files && | |
968 | git -C bare sparse-checkout check-rules --no-cone --rules-file ../rules\ | |
969 | >check-rules-file <all-files && | |
970 | ||
2ed139cc | 971 | git -C repo sparse-checkout set --no-cone --stdin <rules && |
00408ade WS |
972 | git -C repo ls-files -t >out && |
973 | sed -n "/^S /!s/^. //p" out >ls-files && | |
974 | ||
975 | git -C repo sparse-checkout check-rules >check-rules-default <all-files && | |
976 | ||
977 | cat >expect <<-\EOF && | |
978 | deep/deeper1/deepest/a | |
979 | EOF | |
980 | ||
981 | test_cmp expect check-rules-file && | |
982 | test_cmp check-rules-file ls-files && | |
983 | test_cmp check-rules-file check-rules-default | |
984 | ' | |
985 | ||
986 | test_expect_success 'check-rules cone mode is default' ' | |
987 | cat >rules <<-\EOF && | |
988 | folder1 | |
989 | EOF | |
990 | ||
991 | cat >all-files <<-\EOF && | |
992 | toplevel | |
993 | folder2/file | |
994 | folder1/file | |
995 | EOF | |
996 | ||
997 | cat >expect <<-\EOF && | |
998 | toplevel | |
999 | folder1/file | |
1000 | EOF | |
1001 | ||
1002 | git -C repo sparse-checkout set --no-cone && | |
1003 | git -C repo sparse-checkout check-rules \ | |
1004 | --rules-file ../rules >actual <all-files && | |
1005 | ||
1006 | git -C bare sparse-checkout check-rules \ | |
1007 | --rules-file ../rules >actual-bare <all-files && | |
1008 | ||
1009 | test_cmp expect actual && | |
1010 | test_cmp expect actual-bare | |
1011 | ' | |
1012 | ||
1013 | test_expect_success 'check-rules quoting' ' | |
1014 | cat >rules <<-EOF && | |
1015 | "folder\" a" | |
1016 | EOF | |
1017 | cat >files <<-EOF && | |
1018 | "folder\" a/file" | |
1019 | "folder\" b/file" | |
1020 | EOF | |
1021 | cat >expect <<-EOF && | |
1022 | "folder\" a/file" | |
1023 | EOF | |
1024 | git sparse-checkout check-rules --cone \ | |
1025 | --rules-file rules >actual <files && | |
1026 | ||
1027 | test_cmp expect actual | |
1028 | ' | |
1029 | ||
1030 | test_expect_success 'check-rules null termination' ' | |
1031 | cat >rules <<-EOF && | |
1032 | "folder\" a" | |
1033 | EOF | |
1034 | ||
1035 | lf_to_nul >files <<-EOF && | |
1036 | folder" a/a | |
1037 | folder" a/b | |
1038 | folder" b/fileQ | |
1039 | EOF | |
1040 | ||
1041 | cat >expect <<-EOF && | |
1042 | folder" a/aQfolder" a/bQ | |
1043 | EOF | |
1044 | ||
1045 | git sparse-checkout check-rules --cone -z \ | |
1046 | --rules-file rules >actual.nul <files && | |
1047 | nul_to_q <actual.nul >actual && | |
1048 | echo >>actual && | |
1049 | ||
1050 | test_cmp expect actual | |
1051 | ' | |
1052 | ||
1053 | ||
94c0956b | 1054 | test_done |