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