]>
Commit | Line | Data |
---|---|---|
94c0956b DS |
1 | #!/bin/sh |
2 | ||
3 | test_description='sparse checkout builtin tests' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
761e3d26 EM |
7 | list_files() { |
8 | # Do not replace this with 'ls "$1"', as "ls" with BSD-lineage | |
9 | # enables "-A" by default for root and ends up including ".git" and | |
10 | # such in its output. (Note, though, that running the test suite as | |
11 | # root is generally not recommended.) | |
12 | (cd "$1" && printf '%s\n' *) | |
13 | } | |
14 | ||
522e6417 DS |
15 | check_files() { |
16 | list_files "$1" >actual && | |
17 | shift && | |
18 | printf "%s\n" $@ >expect && | |
19 | test_cmp expect actual | |
20 | } | |
21 | ||
94c0956b DS |
22 | test_expect_success 'setup' ' |
23 | git init repo && | |
24 | ( | |
25 | cd repo && | |
26 | echo "initial" >a && | |
27 | mkdir folder1 folder2 deep && | |
28 | mkdir deep/deeper1 deep/deeper2 && | |
29 | mkdir deep/deeper1/deepest && | |
30 | cp a folder1 && | |
31 | cp a folder2 && | |
32 | cp a deep && | |
33 | cp a deep/deeper1 && | |
34 | cp a deep/deeper2 && | |
35 | cp a deep/deeper1/deepest && | |
36 | git add . && | |
37 | git commit -m "initial commit" | |
38 | ) | |
39 | ' | |
40 | ||
41 | test_expect_success 'git sparse-checkout list (empty)' ' | |
42 | git -C repo sparse-checkout list >list 2>err && | |
43 | test_must_be_empty list && | |
44 | test_i18ngrep "this worktree is not sparse (sparse-checkout file may not exist)" err | |
45 | ' | |
46 | ||
47 | test_expect_success 'git sparse-checkout list (populated)' ' | |
48 | test_when_finished rm -f repo/.git/info/sparse-checkout && | |
d622c343 DS |
49 | cat >repo/.git/info/sparse-checkout <<-\EOF && |
50 | /folder1/* | |
51 | /deep/ | |
52 | **/a | |
53 | !*bin* | |
94c0956b DS |
54 | EOF |
55 | cp repo/.git/info/sparse-checkout expect && | |
56 | git -C repo sparse-checkout list >list && | |
57 | test_cmp expect list | |
58 | ' | |
59 | ||
bab3c359 DS |
60 | test_expect_success 'git sparse-checkout init' ' |
61 | git -C repo sparse-checkout init && | |
d622c343 DS |
62 | cat >expect <<-\EOF && |
63 | /* | |
64 | !/*/ | |
bab3c359 DS |
65 | EOF |
66 | test_cmp expect repo/.git/info/sparse-checkout && | |
67 | test_cmp_config -C repo true core.sparsecheckout && | |
522e6417 | 68 | check_files repo a |
bab3c359 DS |
69 | ' |
70 | ||
71 | test_expect_success 'git sparse-checkout list after init' ' | |
72 | git -C repo sparse-checkout list >actual && | |
d622c343 DS |
73 | cat >expect <<-\EOF && |
74 | /* | |
75 | !/*/ | |
bab3c359 DS |
76 | EOF |
77 | test_cmp expect actual | |
78 | ' | |
79 | ||
80 | test_expect_success 'init with existing sparse-checkout' ' | |
81 | echo "*folder*" >> repo/.git/info/sparse-checkout && | |
82 | git -C repo sparse-checkout init && | |
d622c343 DS |
83 | cat >expect <<-\EOF && |
84 | /* | |
85 | !/*/ | |
86 | *folder* | |
bab3c359 DS |
87 | EOF |
88 | test_cmp expect repo/.git/info/sparse-checkout && | |
522e6417 | 89 | check_files repo a folder1 folder2 |
bab3c359 DS |
90 | ' |
91 | ||
d89f09c8 | 92 | test_expect_success 'clone --sparse' ' |
47dbf10d | 93 | git clone --sparse "file://$(pwd)/repo" clone && |
d89f09c8 | 94 | git -C clone sparse-checkout list >actual && |
d622c343 DS |
95 | cat >expect <<-\EOF && |
96 | /* | |
97 | !/*/ | |
d89f09c8 DS |
98 | EOF |
99 | test_cmp expect actual && | |
522e6417 | 100 | check_files clone a |
d89f09c8 DS |
101 | ' |
102 | ||
f6039a94 DS |
103 | test_expect_success 'set enables config' ' |
104 | git init empty-config && | |
105 | ( | |
106 | cd empty-config && | |
107 | test_commit test file && | |
108 | test_path_is_missing .git/config.worktree && | |
ace224ac | 109 | git sparse-checkout set nothing && |
f6039a94 | 110 | test_path_is_file .git/config.worktree && |
f6039a94 DS |
111 | test_cmp_config true core.sparseCheckout |
112 | ) | |
113 | ' | |
114 | ||
115 | test_expect_success 'set sparse-checkout using builtin' ' | |
116 | git -C repo sparse-checkout set "/*" "!/*/" "*folder*" && | |
d622c343 DS |
117 | cat >expect <<-\EOF && |
118 | /* | |
119 | !/*/ | |
120 | *folder* | |
f6039a94 DS |
121 | EOF |
122 | git -C repo sparse-checkout list >actual && | |
123 | test_cmp expect actual && | |
124 | test_cmp expect repo/.git/info/sparse-checkout && | |
522e6417 | 125 | check_files repo a folder1 folder2 |
f6039a94 DS |
126 | ' |
127 | ||
7bffca95 | 128 | test_expect_success 'set sparse-checkout using --stdin' ' |
d622c343 DS |
129 | cat >expect <<-\EOF && |
130 | /* | |
131 | !/*/ | |
132 | /folder1/ | |
133 | /folder2/ | |
7bffca95 DS |
134 | EOF |
135 | git -C repo sparse-checkout set --stdin <expect && | |
136 | git -C repo sparse-checkout list >actual && | |
137 | test_cmp expect actual && | |
138 | test_cmp expect repo/.git/info/sparse-checkout && | |
522e6417 | 139 | check_files repo "a folder1 folder2" |
7bffca95 DS |
140 | ' |
141 | ||
2631dc87 DS |
142 | test_expect_success 'add to sparse-checkout' ' |
143 | cat repo/.git/info/sparse-checkout >expect && | |
144 | cat >add <<-\EOF && | |
145 | pattern1 | |
146 | /folder1/ | |
147 | pattern2 | |
148 | EOF | |
149 | cat add >>expect && | |
150 | git -C repo sparse-checkout add --stdin <add && | |
151 | git -C repo sparse-checkout list >actual && | |
152 | test_cmp expect actual && | |
153 | test_cmp expect repo/.git/info/sparse-checkout && | |
154 | check_files repo "a folder1 folder2" | |
155 | ' | |
156 | ||
879321eb DS |
157 | test_expect_success 'cone mode: match patterns' ' |
158 | git -C repo config --worktree core.sparseCheckoutCone true && | |
159 | rm -rf repo/a repo/folder1 repo/folder2 && | |
96cc8ab5 DS |
160 | git -C repo read-tree -mu HEAD 2>err && |
161 | test_i18ngrep ! "disabling cone patterns" err && | |
879321eb | 162 | git -C repo reset --hard && |
522e6417 | 163 | check_files repo a folder1 folder2 |
879321eb DS |
164 | ' |
165 | ||
96cc8ab5 DS |
166 | test_expect_success 'cone mode: warn on bad pattern' ' |
167 | test_when_finished mv sparse-checkout repo/.git/info/ && | |
168 | cp repo/.git/info/sparse-checkout . && | |
169 | echo "!/deep/deeper/*" >>repo/.git/info/sparse-checkout && | |
170 | git -C repo read-tree -mu HEAD 2>err && | |
171 | test_i18ngrep "unrecognized negative pattern" err | |
172 | ' | |
173 | ||
72918c1a | 174 | test_expect_success 'sparse-checkout disable' ' |
99dfa6f9 | 175 | test_when_finished rm -rf repo/.git/info/sparse-checkout && |
72918c1a | 176 | git -C repo sparse-checkout disable && |
99dfa6f9 | 177 | test_path_is_file repo/.git/info/sparse-checkout && |
72918c1a DS |
178 | git -C repo config --list >config && |
179 | test_must_fail git config core.sparseCheckout && | |
522e6417 | 180 | check_files repo a deep folder1 folder2 |
72918c1a DS |
181 | ' |
182 | ||
af09ce24 DS |
183 | test_expect_success 'cone mode: init and set' ' |
184 | git -C repo sparse-checkout init --cone && | |
185 | git -C repo config --list >config && | |
186 | test_i18ngrep "core.sparsecheckoutcone=true" config && | |
761e3d26 | 187 | list_files repo >dir && |
af09ce24 DS |
188 | echo a >expect && |
189 | test_cmp expect dir && | |
190 | git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err && | |
191 | test_must_be_empty err && | |
522e6417 DS |
192 | check_files repo a deep && |
193 | check_files repo/deep a deeper1 && | |
194 | check_files repo/deep/deeper1 a deepest && | |
d622c343 DS |
195 | cat >expect <<-\EOF && |
196 | /* | |
197 | !/*/ | |
198 | /deep/ | |
199 | !/deep/*/ | |
200 | /deep/deeper1/ | |
201 | !/deep/deeper1/*/ | |
202 | /deep/deeper1/deepest/ | |
af09ce24 DS |
203 | EOF |
204 | test_cmp expect repo/.git/info/sparse-checkout && | |
d622c343 DS |
205 | git -C repo sparse-checkout set --stdin 2>err <<-\EOF && |
206 | folder1 | |
207 | folder2 | |
af09ce24 DS |
208 | EOF |
209 | test_must_be_empty err && | |
522e6417 | 210 | check_files repo a folder1 folder2 |
af09ce24 DS |
211 | ' |
212 | ||
de11951b | 213 | test_expect_success 'cone mode: list' ' |
d622c343 DS |
214 | cat >expect <<-\EOF && |
215 | folder1 | |
216 | folder2 | |
de11951b DS |
217 | EOF |
218 | git -C repo sparse-checkout set --stdin <expect && | |
219 | git -C repo sparse-checkout list >actual 2>err && | |
220 | test_must_be_empty err && | |
221 | test_cmp expect actual | |
222 | ' | |
223 | ||
e9de487a DS |
224 | test_expect_success 'cone mode: set with nested folders' ' |
225 | git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err && | |
226 | test_line_count = 0 err && | |
d622c343 DS |
227 | cat >expect <<-\EOF && |
228 | /* | |
229 | !/*/ | |
230 | /deep/ | |
e9de487a DS |
231 | EOF |
232 | test_cmp repo/.git/info/sparse-checkout expect | |
233 | ' | |
234 | ||
2631dc87 DS |
235 | test_expect_success 'cone mode: add independent path' ' |
236 | git -C repo sparse-checkout set deep/deeper1 && | |
237 | git -C repo sparse-checkout add folder1 && | |
238 | cat >expect <<-\EOF && | |
239 | /* | |
240 | !/*/ | |
241 | /deep/ | |
242 | !/deep/*/ | |
243 | /deep/deeper1/ | |
244 | /folder1/ | |
245 | EOF | |
246 | test_cmp expect repo/.git/info/sparse-checkout && | |
247 | check_files repo a deep folder1 | |
248 | ' | |
249 | ||
250 | test_expect_success 'cone mode: add sibling path' ' | |
251 | git -C repo sparse-checkout set deep/deeper1 && | |
252 | git -C repo sparse-checkout add deep/deeper2 && | |
253 | cat >expect <<-\EOF && | |
254 | /* | |
255 | !/*/ | |
256 | /deep/ | |
257 | !/deep/*/ | |
258 | /deep/deeper1/ | |
259 | /deep/deeper2/ | |
260 | EOF | |
261 | test_cmp expect repo/.git/info/sparse-checkout && | |
262 | check_files repo a deep | |
263 | ' | |
264 | ||
265 | test_expect_success 'cone mode: add parent path' ' | |
266 | git -C repo sparse-checkout set deep/deeper1 folder1 && | |
267 | git -C repo sparse-checkout add deep && | |
268 | cat >expect <<-\EOF && | |
269 | /* | |
270 | !/*/ | |
271 | /deep/ | |
272 | /folder1/ | |
273 | EOF | |
274 | test_cmp expect repo/.git/info/sparse-checkout && | |
275 | check_files repo a deep folder1 | |
276 | ' | |
277 | ||
f56f31af | 278 | test_expect_success 'not-up-to-date does not block rest of sparsification' ' |
72064ee5 | 279 | test_when_finished git -C repo sparse-checkout disable && |
cff4e913 | 280 | test_when_finished git -C repo reset --hard && |
2631dc87 | 281 | git -C repo sparse-checkout set deep && |
f56f31af | 282 | |
e091228e DS |
283 | echo update >repo/deep/deeper2/a && |
284 | cp repo/.git/info/sparse-checkout expect && | |
f56f31af EN |
285 | test_write_lines "!/deep/*/" "/deep/deeper1/" >>expect && |
286 | ||
287 | git -C repo sparse-checkout set deep/deeper1 2>err && | |
288 | ||
22ab0b37 | 289 | test_i18ngrep "The following paths are not up to date" err && |
f56f31af EN |
290 | test_cmp expect repo/.git/info/sparse-checkout && |
291 | check_files repo/deep a deeper1 deeper2 && | |
292 | check_files repo/deep/deeper1 a deepest && | |
293 | check_files repo/deep/deeper1/deepest a && | |
294 | check_files repo/deep/deeper2 a | |
e091228e DS |
295 | ' |
296 | ||
297 | test_expect_success 'revert to old sparse-checkout on empty update' ' | |
298 | git init empty-test && | |
299 | ( | |
300 | echo >file && | |
301 | git add file && | |
302 | git commit -m "test" && | |
ace224ac DS |
303 | git sparse-checkout set nothing 2>err && |
304 | test_i18ngrep ! "Sparse checkout leaves no entry on working directory" err && | |
e091228e DS |
305 | test_i18ngrep ! ".git/index.lock" err && |
306 | git sparse-checkout set file | |
307 | ) | |
308 | ' | |
309 | ||
fb10ca5b DS |
310 | test_expect_success 'fail when lock is taken' ' |
311 | test_when_finished rm -rf repo/.git/info/sparse-checkout.lock && | |
312 | touch repo/.git/info/sparse-checkout.lock && | |
313 | test_must_fail git -C repo sparse-checkout set deep 2>err && | |
4605a730 | 314 | test_i18ngrep "Unable to create .*\.lock" err |
fb10ca5b DS |
315 | ' |
316 | ||
f75a69f8 DS |
317 | test_expect_success '.gitignore should not warn about cone mode' ' |
318 | git -C repo config --worktree core.sparseCheckoutCone true && | |
319 | echo "**/bin/*" >repo/.gitignore && | |
320 | git -C repo reset --hard 2>err && | |
321 | test_i18ngrep ! "disabling cone patterns" err | |
322 | ' | |
323 | ||
f56f31af | 324 | test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' ' |
cff4e913 DS |
325 | git clone repo dirty && |
326 | echo dirty >dirty/folder1/a && | |
f56f31af EN |
327 | |
328 | git -C dirty sparse-checkout init 2>err && | |
22ab0b37 | 329 | test_i18ngrep "warning.*The following paths are not up to date" err && |
f56f31af EN |
330 | |
331 | git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err && | |
22ab0b37 | 332 | test_i18ngrep "warning.*The following paths are not up to date" err && |
f56f31af EN |
333 | test_path_is_file dirty/folder1/a && |
334 | ||
335 | git -C dirty sparse-checkout disable 2>err && | |
336 | test_must_be_empty err && | |
337 | ||
cff4e913 DS |
338 | git -C dirty reset --hard && |
339 | git -C dirty sparse-checkout init && | |
340 | git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* && | |
f56f31af EN |
341 | test_path_is_missing dirty/folder1/a && |
342 | git -C dirty sparse-checkout disable && | |
343 | test_path_is_file dirty/folder1/a | |
cff4e913 DS |
344 | ' |
345 | ||
ebb568b9 EN |
346 | test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged status' ' |
347 | git clone repo unmerged && | |
348 | ||
349 | cat >input <<-EOF && | |
350 | 0 0000000000000000000000000000000000000000 folder1/a | |
351 | 100644 $(git -C unmerged rev-parse HEAD:folder1/a) 1 folder1/a | |
352 | EOF | |
353 | git -C unmerged update-index --index-info <input && | |
354 | ||
355 | git -C unmerged sparse-checkout init 2>err && | |
356 | test_i18ngrep "warning.*The following paths are unmerged" err && | |
357 | ||
358 | git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* 2>err && | |
359 | test_i18ngrep "warning.*The following paths are unmerged" err && | |
360 | test_path_is_file dirty/folder1/a && | |
361 | ||
362 | git -C unmerged sparse-checkout disable 2>err && | |
363 | test_i18ngrep "warning.*The following paths are unmerged" err && | |
364 | ||
365 | git -C unmerged reset --hard && | |
366 | git -C unmerged sparse-checkout init && | |
367 | git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* && | |
368 | git -C unmerged sparse-checkout disable | |
369 | ' | |
370 | ||
5644ca28 EN |
371 | test_expect_success 'sparse-checkout reapply' ' |
372 | git clone repo tweak && | |
373 | ||
374 | echo dirty >tweak/deep/deeper2/a && | |
375 | ||
376 | cat >input <<-EOF && | |
377 | 0 0000000000000000000000000000000000000000 folder1/a | |
378 | 100644 $(git -C tweak rev-parse HEAD:folder1/a) 1 folder1/a | |
379 | EOF | |
380 | git -C tweak update-index --index-info <input && | |
381 | ||
382 | git -C tweak sparse-checkout init --cone 2>err && | |
383 | test_i18ngrep "warning.*The following paths are not up to date" err && | |
384 | test_i18ngrep "warning.*The following paths are unmerged" err && | |
385 | ||
386 | git -C tweak sparse-checkout set folder2 deep/deeper1 2>err && | |
387 | test_i18ngrep "warning.*The following paths are not up to date" err && | |
388 | test_i18ngrep "warning.*The following paths are unmerged" err && | |
389 | ||
390 | git -C tweak sparse-checkout reapply 2>err && | |
391 | test_i18ngrep "warning.*The following paths are not up to date" err && | |
392 | test_path_is_file tweak/deep/deeper2/a && | |
393 | test_i18ngrep "warning.*The following paths are unmerged" err && | |
394 | test_path_is_file tweak/folder1/a && | |
395 | ||
396 | git -C tweak checkout HEAD deep/deeper2/a && | |
397 | git -C tweak sparse-checkout reapply 2>err && | |
398 | test_i18ngrep ! "warning.*The following paths are not up to date" err && | |
399 | test_path_is_missing tweak/deep/deeper2/a && | |
400 | test_i18ngrep "warning.*The following paths are unmerged" err && | |
401 | test_path_is_file tweak/folder1/a && | |
402 | ||
403 | git -C tweak add folder1/a && | |
404 | git -C tweak sparse-checkout reapply 2>err && | |
405 | test_must_be_empty err && | |
406 | test_path_is_missing tweak/deep/deeper2/a && | |
407 | test_path_is_missing tweak/folder1/a && | |
408 | ||
409 | git -C tweak sparse-checkout disable | |
410 | ' | |
411 | ||
190a65f9 | 412 | test_expect_success 'cone mode: set with core.ignoreCase=true' ' |
72064ee5 | 413 | rm repo/.git/info/sparse-checkout && |
190a65f9 DS |
414 | git -C repo sparse-checkout init --cone && |
415 | git -C repo -c core.ignoreCase=true sparse-checkout set folder1 && | |
d622c343 DS |
416 | cat >expect <<-\EOF && |
417 | /* | |
418 | !/*/ | |
419 | /folder1/ | |
190a65f9 DS |
420 | EOF |
421 | test_cmp expect repo/.git/info/sparse-checkout && | |
522e6417 | 422 | check_files repo a folder1 |
190a65f9 DS |
423 | ' |
424 | ||
4fd683b6 DS |
425 | test_expect_success 'interaction with submodules' ' |
426 | git clone repo super && | |
427 | ( | |
428 | cd super && | |
429 | mkdir modules && | |
430 | git submodule add ../repo modules/child && | |
431 | git add . && | |
432 | git commit -m "add submodule" && | |
433 | git sparse-checkout init --cone && | |
434 | git sparse-checkout set folder1 | |
435 | ) && | |
522e6417 DS |
436 | check_files super a folder1 modules && |
437 | check_files super/modules/child a deep folder1 folder2 | |
4fd683b6 DS |
438 | ' |
439 | ||
3c754067 DS |
440 | test_expect_success 'different sparse-checkouts with worktrees' ' |
441 | git -C repo worktree add --detach ../worktree && | |
442 | check_files worktree "a deep folder1 folder2" && | |
443 | git -C worktree sparse-checkout init --cone && | |
444 | git -C repo sparse-checkout set folder1 && | |
445 | git -C worktree sparse-checkout set deep/deeper1 && | |
446 | check_files repo a folder1 && | |
447 | check_files worktree a deep | |
448 | ' | |
449 | ||
f998a3f1 DS |
450 | test_expect_success 'set using filename keeps file on-disk' ' |
451 | git -C repo sparse-checkout set a deep && | |
452 | cat >expect <<-\EOF && | |
453 | /* | |
454 | !/*/ | |
455 | /a/ | |
456 | /deep/ | |
457 | EOF | |
458 | test_cmp expect repo/.git/info/sparse-checkout && | |
459 | check_files repo a deep | |
460 | ' | |
461 | ||
41de0c6f DS |
462 | check_read_tree_errors () { |
463 | REPO=$1 | |
464 | FILES=$2 | |
465 | ERRORS=$3 | |
d585f0e7 DS |
466 | git -C $REPO -c core.sparseCheckoutCone=false read-tree -mu HEAD 2>err && |
467 | test_must_be_empty err && | |
468 | check_files $REPO "$FILES" && | |
41de0c6f DS |
469 | git -C $REPO read-tree -mu HEAD 2>err && |
470 | if test -z "$ERRORS" | |
471 | then | |
472 | test_must_be_empty err | |
473 | else | |
474 | test_i18ngrep "$ERRORS" err | |
475 | fi && | |
476 | check_files $REPO $FILES | |
477 | } | |
478 | ||
479 | test_expect_success 'pattern-checks: /A/**' ' | |
480 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
481 | /* | |
482 | !/*/ | |
483 | /folder1/** | |
484 | EOF | |
485 | check_read_tree_errors repo "a folder1" "disabling cone pattern matching" | |
486 | ' | |
487 | ||
488 | test_expect_success 'pattern-checks: /A/**/B/' ' | |
489 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
490 | /* | |
491 | !/*/ | |
492 | /deep/**/deepest | |
493 | EOF | |
494 | check_read_tree_errors repo "a deep" "disabling cone pattern matching" && | |
495 | check_files repo/deep "deeper1" && | |
496 | check_files repo/deep/deeper1 "deepest" | |
497 | ' | |
498 | ||
9e6d3e64 DS |
499 | test_expect_success 'pattern-checks: too short' ' |
500 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
501 | /* | |
502 | !/*/ | |
6c11c6a1 | 503 | / |
9e6d3e64 DS |
504 | EOF |
505 | check_read_tree_errors repo "a" "disabling cone pattern matching" | |
506 | ' | |
6c11c6a1 DS |
507 | test_expect_success 'pattern-checks: not too short' ' |
508 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
509 | /* | |
510 | !/*/ | |
511 | /b/ | |
512 | EOF | |
513 | git -C repo read-tree -mu HEAD 2>err && | |
514 | test_must_be_empty err && | |
515 | check_files repo a | |
516 | ' | |
9e6d3e64 | 517 | |
9abc60f8 DS |
518 | test_expect_success 'pattern-checks: trailing "*"' ' |
519 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
520 | /* | |
521 | !/*/ | |
522 | /a* | |
523 | EOF | |
524 | check_read_tree_errors repo "a" "disabling cone pattern matching" | |
525 | ' | |
526 | ||
527 | test_expect_success 'pattern-checks: starting "*"' ' | |
528 | cat >repo/.git/info/sparse-checkout <<-\EOF && | |
529 | /* | |
530 | !/*/ | |
531 | *eep/ | |
532 | EOF | |
533 | check_read_tree_errors repo "a deep" "disabling cone pattern matching" | |
534 | ' | |
535 | ||
536 | test_expect_success 'pattern-checks: contained glob characters' ' | |
537 | for c in "[a]" "\\" "?" "*" | |
538 | do | |
539 | cat >repo/.git/info/sparse-checkout <<-EOF && | |
540 | /* | |
541 | !/*/ | |
542 | something$c-else/ | |
543 | EOF | |
544 | check_read_tree_errors repo "a" "disabling cone pattern matching" | |
545 | done | |
546 | ' | |
547 | ||
e53ffe27 | 548 | test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' ' |
4f52c2ce DS |
549 | git clone repo escaped && |
550 | TREEOID=$(git -C escaped rev-parse HEAD:folder1) && | |
551 | NEWTREE=$(git -C escaped mktree <<-EOF | |
552 | $(git -C escaped ls-tree HEAD) | |
553 | 040000 tree $TREEOID zbad\\dir | |
554 | 040000 tree $TREEOID zdoes*exist | |
e53ffe27 | 555 | 040000 tree $TREEOID zglob[!a]? |
4f52c2ce DS |
556 | EOF |
557 | ) && | |
558 | COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) && | |
559 | git -C escaped reset --hard $COMMIT && | |
e53ffe27 | 560 | check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? && |
4f52c2ce | 561 | git -C escaped sparse-checkout init --cone && |
e53ffe27 | 562 | git -C escaped sparse-checkout set zbad\\dir/bogus "zdoes*not*exist" "zdoes*exist" "zglob[!a]?" && |
d585f0e7 | 563 | cat >expect <<-\EOF && |
9abc60f8 DS |
564 | /* |
565 | !/*/ | |
4f52c2ce DS |
566 | /zbad\\dir/ |
567 | !/zbad\\dir/*/ | |
d585f0e7 | 568 | /zbad\\dir/bogus/ |
4f52c2ce | 569 | /zdoes\*exist/ |
d585f0e7 | 570 | /zdoes\*not\*exist/ |
e53ffe27 | 571 | /zglob\[!a]\?/ |
9abc60f8 | 572 | EOF |
d585f0e7 | 573 | test_cmp expect escaped/.git/info/sparse-checkout && |
e53ffe27 | 574 | check_read_tree_errors escaped "a zbad\\dir zdoes*exist zglob[!a]?" && |
e55682ea DS |
575 | git -C escaped ls-tree -d --name-only HEAD >list-expect && |
576 | git -C escaped sparse-checkout set --stdin <list-expect && | |
bd64de42 DS |
577 | cat >expect <<-\EOF && |
578 | /* | |
579 | !/*/ | |
580 | /deep/ | |
581 | /folder1/ | |
582 | /folder2/ | |
583 | /zbad\\dir/ | |
584 | /zdoes\*exist/ | |
e53ffe27 | 585 | /zglob\[!a]\?/ |
bd64de42 DS |
586 | EOF |
587 | test_cmp expect escaped/.git/info/sparse-checkout && | |
e53ffe27 | 588 | check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" zglob[!a]? && |
e55682ea DS |
589 | git -C escaped sparse-checkout list >list-actual && |
590 | test_cmp list-expect list-actual | |
9abc60f8 DS |
591 | ' |
592 | ||
ef076599 DS |
593 | test_expect_success MINGW 'cone mode replaces backslashes with slashes' ' |
594 | git -C repo sparse-checkout set deep\\deeper1 && | |
595 | cat >expect <<-\EOF && | |
596 | /* | |
597 | !/*/ | |
598 | /deep/ | |
599 | !/deep/*/ | |
600 | /deep/deeper1/ | |
601 | EOF | |
602 | test_cmp expect repo/.git/info/sparse-checkout && | |
603 | check_files repo a deep && | |
604 | check_files repo/deep a deeper1 | |
605 | ' | |
606 | ||
94c0956b | 607 | test_done |