3 test_description
='compare full workdir to sparse workdir'
10 test_expect_success
'setup' '
11 git init initial-repo &&
13 GIT_TEST_SPARSE_INDEX=0 &&
16 echo "after deep" >e &&
17 echo "after folder1" >g &&
19 mkdir folder1 folder2 deep x &&
20 mkdir deep/deeper1 deep/deeper2 deep/before deep/later &&
21 mkdir deep/deeper1/deepest &&
22 echo "after deeper1" >deep/e &&
23 echo "after deepest" >deep/deeper1/e &&
32 cp a deep/deeper1/deepest &&
33 cp -r deep/deeper1/deepest deep/deeper2 &&
34 mkdir deep/deeper1/0 &&
35 mkdir deep/deeper1/0/0 &&
36 touch deep/deeper1/0/1 &&
37 touch deep/deeper1/0/0/0 &&
41 cp -r deep/deeper1/0 folder1 &&
42 cp -r deep/deeper1/0 folder2 &&
43 echo >>folder1/0/0/0 &&
46 git commit -m "initial commit" &&
47 git checkout -b base &&
48 for dir in folder1 folder2 deep
50 git checkout -b update-$dir &&
51 echo "updated $dir" >$dir/a &&
52 git commit -a -m "update $dir" || return 1
55 git checkout -b rename-base base &&
56 cat >folder1/larger-content <<-\EOF &&
63 cp folder1/larger-content folder2/ &&
64 cp folder1/larger-content deep/deeper1/ &&
66 git commit -m "add interesting rename content" &&
68 git checkout -b rename-out-to-out rename-base &&
69 mv folder1/a folder2/b &&
70 mv folder1/larger-content folder2/edited-content &&
71 echo >>folder2/edited-content &&
73 echo stuff >>deep/deeper1/a &&
75 git commit -m "rename folder1/... to folder2/..." &&
77 git checkout -b rename-out-to-in rename-base &&
78 mv folder1/a deep/deeper1/b &&
79 echo more stuff >>deep/deeper1/a &&
82 echo >>folder2/0/1/1 &&
83 mv folder1/larger-content deep/deeper1/edited-content &&
84 echo >>deep/deeper1/edited-content &&
86 git commit -m "rename folder1/... to deep/deeper1/..." &&
88 git checkout -b rename-in-to-out rename-base &&
89 mv deep/deeper1/a folder1/b &&
93 mv deep/deeper1/larger-content folder1/edited-content &&
94 echo >>folder1/edited-content &&
96 git commit -m "rename deep/deeper1/... to folder1/..." &&
98 git checkout -b deepest base &&
99 echo "updated deepest" >deep/deeper1/deepest/a &&
100 git commit -a -m "update deepest" &&
102 git checkout -f base &&
108 rm -rf full-checkout sparse-checkout sparse-index
&&
110 # create repos in initial state
111 cp -r initial-repo full-checkout
&&
112 git
-C full-checkout
reset --hard &&
114 cp -r initial-repo sparse-checkout
&&
115 git
-C sparse-checkout
reset --hard &&
117 cp -r initial-repo sparse-index
&&
118 git
-C sparse-index
reset --hard &&
120 # initialize sparse-checkout definitions
121 git
-C sparse-checkout sparse-checkout init
--cone &&
122 git
-C sparse-checkout sparse-checkout
set deep
&&
123 git
-C sparse-index sparse-checkout init
--cone --sparse-index &&
124 test_cmp_config
-C sparse-index true index.sparse
&&
125 git
-C sparse-index sparse-checkout
set deep
130 cd sparse-checkout
&&
131 GIT_PROGRESS_DELAY
=100000 "$@" >..
/sparse-checkout-out
2>..
/sparse-checkout-err
135 GIT_PROGRESS_DELAY
=100000 "$@" >..
/sparse-index-out
2>..
/sparse-index-err
142 GIT_PROGRESS_DELAY
=100000 "$@" >..
/full-checkout-out
2>..
/full-checkout-err
149 test_cmp full-checkout-out sparse-checkout-out
&&
150 test_cmp full-checkout-out sparse-index-out
&&
151 test_cmp full-checkout-err sparse-checkout-err
&&
152 test_cmp full-checkout-err sparse-index-err
155 test_sparse_match
() {
156 run_on_sparse
"$@" &&
157 test_cmp sparse-checkout-out sparse-index-out
&&
158 test_cmp sparse-checkout-err sparse-index-err
161 test_expect_success
'sparse-index contents' '
164 test-tool -C sparse-index read-cache --table >cache &&
165 for dir in folder1 folder2 x
167 TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
168 grep "040000 tree $TREE $dir/" cache \
172 git -C sparse-index sparse-checkout set folder1 &&
174 test-tool -C sparse-index read-cache --table >cache &&
175 for dir in deep folder2 x
177 TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
178 grep "040000 tree $TREE $dir/" cache \
182 git -C sparse-index sparse-checkout set deep/deeper1 &&
184 test-tool -C sparse-index read-cache --table >cache &&
185 for dir in deep/deeper2 folder1 folder2 x
187 TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
188 grep "040000 tree $TREE $dir/" cache \
192 # Disabling the sparse-index removes tree entries with full ones
193 git -C sparse-index sparse-checkout init --no-sparse-index &&
195 test-tool -C sparse-index read-cache --table >cache &&
196 ! grep "040000 tree" cache &&
197 test_sparse_match test-tool read-cache --table
200 test_expect_success
'expanded in-memory index matches full index' '
202 test_sparse_match test-tool read-cache --expand --table
205 test_expect_success
'status with options' '
207 test_sparse_match ls &&
208 test_all_match git status --porcelain=v2 &&
209 test_all_match git status --porcelain=v2 -z -u &&
210 test_all_match git status --porcelain=v2 -uno &&
211 run_on_all touch README.md &&
212 test_all_match git status --porcelain=v2 &&
213 test_all_match git status --porcelain=v2 -z -u &&
214 test_all_match git status --porcelain=v2 -uno &&
215 test_all_match git add README.md &&
216 test_all_match git status --porcelain=v2 &&
217 test_all_match git status --porcelain=v2 -z -u &&
218 test_all_match git status --porcelain=v2 -uno
221 test_expect_success
'status reports sparse-checkout' '
223 git -C sparse-checkout status >full &&
224 git -C sparse-index status >sparse &&
225 test_i18ngrep "You are in a sparse checkout with " full &&
226 test_i18ngrep "You are in a sparse checkout." sparse
229 test_expect_success
'add, commit, checkout' '
232 write_script edit-contents <<-\EOF &&
235 run_on_all ../edit-contents README.md &&
237 test_all_match git add README.md &&
238 test_all_match git status --porcelain=v2 &&
239 test_all_match git commit -m "Add README.md" &&
241 test_all_match git checkout HEAD~1 &&
242 test_all_match git checkout - &&
244 run_on_all ../edit-contents README.md &&
246 test_all_match git add -A &&
247 test_all_match git status --porcelain=v2 &&
248 test_all_match git commit -m "Extend README.md" &&
250 test_all_match git checkout HEAD~1 &&
251 test_all_match git checkout - &&
253 run_on_all ../edit-contents deep/newfile &&
255 test_all_match git status --porcelain=v2 -uno &&
256 test_all_match git status --porcelain=v2 &&
257 test_all_match git add . &&
258 test_all_match git status --porcelain=v2 &&
259 test_all_match git commit -m "add deep/newfile" &&
261 test_all_match git checkout HEAD~1 &&
262 test_all_match git checkout -
265 test_expect_success
'status/add: outside sparse cone' '
268 # adding a "missing" file outside the cone should fail
269 test_sparse_match test_must_fail git add folder1/a &&
271 # folder1 is at HEAD, but outside the sparse cone
272 run_on_sparse mkdir folder1 &&
273 cp initial-repo/folder1/a sparse-checkout/folder1/a &&
274 cp initial-repo/folder1/a sparse-index/folder1/a &&
276 test_sparse_match git status &&
278 write_script edit-contents <<-\EOF &&
281 run_on_sparse ../edit-contents folder1/a &&
282 run_on_all ../edit-contents folder1/new &&
284 test_sparse_match git status --porcelain=v2 &&
286 # This "git add folder1/a" fails with a warning
287 # in the sparse repos, differing from the full
288 # repo. This is intentional.
289 test_sparse_match test_must_fail git add folder1/a &&
290 test_sparse_match test_must_fail git add --refresh folder1/a &&
291 test_all_match git status --porcelain=v2 &&
293 test_all_match git add . &&
294 test_all_match git status --porcelain=v2 &&
295 test_all_match git commit -m folder1/new &&
297 run_on_all ../edit-contents folder1/newer &&
298 test_all_match git add folder1/ &&
299 test_all_match git status --porcelain=v2 &&
300 test_all_match git commit -m folder1/newer
303 test_expect_success
'checkout and reset --hard' '
306 test_all_match git checkout update-folder1 &&
307 test_all_match git status --porcelain=v2 &&
309 test_all_match git checkout update-deep &&
310 test_all_match git status --porcelain=v2 &&
312 test_all_match git checkout -b reset-test &&
313 test_all_match git reset --hard deepest &&
314 test_all_match git reset --hard update-folder1 &&
315 test_all_match git reset --hard update-folder2
318 test_expect_success
'diff --staged' '
321 write_script edit-contents <<-\EOF &&
322 echo text >>README.md
324 run_on_all ../edit-contents &&
326 test_all_match git diff &&
327 test_all_match git diff --staged &&
328 test_all_match git add README.md &&
329 test_all_match git diff &&
330 test_all_match git diff --staged
333 test_expect_success
'diff with renames and conflicts' '
336 for branch in rename-out-to-out rename-out-to-in rename-in-to-out
338 test_all_match git checkout rename-base &&
339 test_all_match git checkout $branch -- . &&
340 test_all_match git status --porcelain=v2 &&
341 test_all_match git diff --staged --no-renames &&
342 test_all_match git diff --staged --find-renames || return 1
346 test_expect_success
'diff with directory/file conflicts' '
349 for branch in rename-out-to-out rename-out-to-in rename-in-to-out
351 git -C full-checkout reset --hard &&
352 test_sparse_match git reset --hard &&
353 test_all_match git checkout $branch &&
354 test_all_match git checkout rename-base -- . &&
355 test_all_match git status --porcelain=v2 &&
356 test_all_match git diff --staged --no-renames &&
357 test_all_match git diff --staged --find-renames || return 1
361 test_expect_success
'log with pathspec outside sparse definition' '
364 test_all_match git log -- a &&
365 test_all_match git log -- folder1/a &&
366 test_all_match git log -- folder2/a &&
367 test_all_match git log -- deep/a &&
368 test_all_match git log -- deep/deeper1/a &&
369 test_all_match git log -- deep/deeper1/deepest/a &&
371 test_all_match git checkout update-folder1 &&
372 test_all_match git log -- folder1/a
375 test_expect_success
'blame with pathspec inside sparse definition' '
378 test_all_match git blame a &&
379 test_all_match git blame deep/a &&
380 test_all_match git blame deep/deeper1/a &&
381 test_all_match git blame deep/deeper1/deepest/a
384 # TODO: blame currently does not support blaming files outside of the
385 # sparse definition. It complains that the file doesn't exist locally.
386 test_expect_failure
'blame with pathspec outside sparse definition' '
389 test_all_match git blame folder1/a &&
390 test_all_match git blame folder2/a &&
391 test_all_match git blame deep/deeper2/a &&
392 test_all_match git blame deep/deeper2/deepest/a
395 # TODO: reset currently does not behave as expected when in a
397 test_expect_failure
'checkout and reset (mixed)' '
400 test_all_match git checkout -b reset-test update-deep &&
401 test_all_match git reset deepest &&
402 test_all_match git reset update-folder1 &&
403 test_all_match git reset update-folder2
406 # Ensure that sparse-index behaves identically to
407 # sparse-checkout with a full index.
408 test_expect_success
'checkout and reset (mixed) [sparse]' '
411 test_sparse_match git checkout -b reset-test update-deep &&
412 test_sparse_match git reset deepest &&
413 test_sparse_match git reset update-folder1 &&
414 test_sparse_match git reset update-folder2
417 test_expect_success
'merge' '
420 test_all_match git checkout -b merge update-deep &&
421 test_all_match git merge -m "folder1" update-folder1 &&
422 test_all_match git rev-parse HEAD^{tree} &&
423 test_all_match git merge -m "folder2" update-folder2 &&
424 test_all_match git rev-parse HEAD^{tree}
427 test_expect_success
'merge with outside renames' '
430 for type in out-to-out out-to-in in-to-out
432 test_all_match git reset --hard &&
433 test_all_match git checkout -f -b merge-$type update-deep &&
434 test_all_match git merge -m "$type" rename-$type &&
435 test_all_match git rev-parse HEAD^{tree} || return 1
439 # Sparse-index fails to convert the index in the
440 # final 'git cherry-pick' command.
441 test_expect_success
'cherry-pick with conflicts' '
444 write_script edit-conflict <<-\EOF &&
448 test_all_match git checkout -b to-cherry-pick &&
449 run_on_all ../edit-conflict ABC &&
450 test_all_match git add conflict &&
451 test_all_match git commit -m "conflict to pick" &&
453 test_all_match git checkout -B base HEAD~1 &&
454 run_on_all ../edit-conflict DEF &&
455 test_all_match git add conflict &&
456 test_all_match git commit -m "conflict in base" &&
458 test_all_match test_must_fail git cherry-pick to-cherry-pick
461 test_expect_success
'clean' '
464 echo bogus >>.gitignore &&
465 run_on_all cp ../.gitignore . &&
466 test_all_match git add .gitignore &&
467 test_all_match git commit -m "ignore bogus files" &&
469 run_on_sparse mkdir folder1 &&
470 run_on_all touch folder1/bogus &&
472 test_all_match git status --porcelain=v2 &&
473 test_all_match git clean -f &&
474 test_all_match git status --porcelain=v2 &&
475 test_sparse_match ls &&
476 test_sparse_match ls folder1 &&
478 test_all_match git clean -xf &&
479 test_all_match git status --porcelain=v2 &&
480 test_sparse_match ls &&
481 test_sparse_match ls folder1 &&
483 test_all_match git clean -xdf &&
484 test_all_match git status --porcelain=v2 &&
485 test_sparse_match ls &&
486 test_sparse_match ls folder1 &&
488 test_sparse_match test_path_is_dir folder1
491 test_expect_success
'submodule handling' '
494 test_all_match mkdir modules &&
495 test_all_match touch modules/a &&
496 test_all_match git add modules &&
497 test_all_match git commit -m "add modules directory" &&
499 run_on_all git submodule add "$(pwd)/initial-repo" modules/sub &&
500 test_all_match git commit -m "add submodule" &&
502 # having a submodule prevents "modules" from collapse
503 test-tool -C sparse-index read-cache --table >cache &&
504 grep "100644 blob .* modules/a" cache &&
505 grep "160000 commit $(git -C initial-repo rev-parse HEAD) modules/sub" cache
508 test_expect_success
'sparse-index is expanded and converted back' '
511 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
512 git -C sparse-index -c core.fsmonitor="" reset --hard &&
513 test_region index convert_to_sparse trace2.txt &&
514 test_region index ensure_full_index trace2.txt
517 test_expect_success
'sparse-index is not expanded' '
521 echo >>sparse-index/untracked.txt &&
522 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
523 git -C sparse-index status &&
524 test_region ! index ensure_full_index trace2.txt
527 test_expect_success
'reset mixed and checkout orphan' '
530 test_all_match git checkout rename-out-to-in &&
532 # Sparse checkouts do not agree with full checkouts about
533 # how to report a directory/file conflict during a reset.
534 # This command would fail with test_all_match because the
535 # full checkout reports "T folder1/0/1" while a sparse
536 # checkout reports "D folder1/0/1". This matches because
537 # the sparse checkouts skip "adding" the other side of
539 test_sparse_match git reset --mixed HEAD~1 &&
540 test_sparse_match test-tool read-cache --table --expand &&
541 test_sparse_match git status --porcelain=v2 &&
543 # At this point, sparse-checkouts behave differently
544 # from the full-checkout.
545 test_sparse_match git checkout --orphan new-branch &&
546 test_sparse_match test-tool read-cache --table --expand &&
547 test_sparse_match git status --porcelain=v2
550 test_expect_success
'add everything with deep new file' '
553 run_on_sparse git sparse-checkout set deep/deeper1/deepest &&
555 run_on_all touch deep/deeper1/x &&
556 test_all_match git add . &&
557 test_all_match git status --porcelain=v2