Skip to content

Commit 291d77e

Browse files
vdyederrickstolee
authored andcommitted
reset: expand test coverage for sparse checkouts
Add new tests for `--merge` and `--keep` modes, as well as mixed reset with pathspecs. New performance test cases exercise various execution paths for `reset`. Co-authored-by: Derrick Stolee <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Victoria Dye <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 86609db commit 291d77e

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

t/perf/p2000-sparse-operations.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,8 @@ test_perf_on_all git add -A
110110
test_perf_on_all git add .
111111
test_perf_on_all git commit -a -m A
112112
test_perf_on_all git checkout -f -
113+
test_perf_on_all git reset
114+
test_perf_on_all git reset --hard
115+
test_perf_on_all git reset -- does-not-exist
113116

114117
test_done

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,104 @@ test_expect_success 'checkout and reset (mixed)' '
475475
run_on_sparse test_path_is_missing folder1
476476
'
477477

478+
test_expect_success 'checkout and reset (merge)' '
479+
init_repos &&
480+
481+
write_script edit-contents <<-\EOF &&
482+
echo text >>$1
483+
EOF
484+
485+
test_all_match git checkout -b reset-test update-deep &&
486+
run_on_all ../edit-contents a &&
487+
test_all_match git reset --merge deepest &&
488+
test_all_match git status --porcelain=v2 &&
489+
490+
test_all_match git reset --hard update-deep &&
491+
run_on_all ../edit-contents deep/a &&
492+
test_all_match test_must_fail git reset --merge deepest
493+
'
494+
495+
test_expect_success 'checkout and reset (keep)' '
496+
init_repos &&
497+
498+
write_script edit-contents <<-\EOF &&
499+
echo text >>$1
500+
EOF
501+
502+
test_all_match git checkout -b reset-test update-deep &&
503+
run_on_all ../edit-contents a &&
504+
test_all_match git reset --keep deepest &&
505+
test_all_match git status --porcelain=v2 &&
506+
507+
test_all_match git reset --hard update-deep &&
508+
run_on_all ../edit-contents deep/a &&
509+
test_all_match test_must_fail git reset --keep deepest
510+
'
511+
512+
test_expect_success 'reset with pathspecs inside sparse definition' '
513+
init_repos &&
514+
515+
write_script edit-contents <<-\EOF &&
516+
echo text >>$1
517+
EOF
518+
519+
test_all_match git checkout -b reset-test update-deep &&
520+
run_on_all ../edit-contents deep/a &&
521+
522+
test_all_match git reset base -- deep/a &&
523+
test_all_match git status --porcelain=v2 &&
524+
525+
test_all_match git reset base -- nonexistent-file &&
526+
test_all_match git status --porcelain=v2 &&
527+
528+
test_all_match git reset deepest -- deep &&
529+
test_all_match git status --porcelain=v2
530+
'
531+
532+
# Although the working tree differs between full and sparse checkouts after
533+
# reset, the state of the index is the same.
534+
test_expect_success 'reset with pathspecs outside sparse definition' '
535+
init_repos &&
536+
test_all_match git checkout -b reset-test base &&
537+
538+
test_sparse_match git reset update-folder1 -- folder1 &&
539+
git -C full-checkout reset update-folder1 -- folder1 &&
540+
test_sparse_match git status --porcelain=v2 &&
541+
test_all_match git rev-parse HEAD:folder1 &&
542+
543+
test_sparse_match git reset update-folder2 -- folder2/a &&
544+
git -C full-checkout reset update-folder2 -- folder2/a &&
545+
test_sparse_match git status --porcelain=v2 &&
546+
test_all_match git rev-parse HEAD:folder2/a
547+
'
548+
549+
test_expect_success 'reset with wildcard pathspec' '
550+
init_repos &&
551+
552+
test_all_match git reset update-deep -- deep\* &&
553+
test_all_match git ls-files -s -- deep &&
554+
555+
test_all_match git reset deepest -- deep\*\*\* &&
556+
test_all_match git ls-files -s -- deep &&
557+
558+
# The following `git reset`s result in updating the index on files with
559+
# `skip-worktree` enabled. To avoid failing due to discrepencies in reported
560+
# "modified" files, `test_sparse_match` reset is performed separately from
561+
# "full-checkout" reset, then the index contents of all repos are verified.
562+
563+
test_sparse_match git reset update-folder1 -- \*/a &&
564+
git -C full-checkout reset update-folder1 -- \*/a &&
565+
test_all_match git ls-files -s -- deep/a folder1/a &&
566+
567+
test_sparse_match git reset update-folder2 -- folder\* &&
568+
git -C full-checkout reset update-folder2 -- folder\* &&
569+
test_all_match git ls-files -s -- folder10 folder1 folder2 &&
570+
571+
test_sparse_match git reset base -- folder1/\* &&
572+
git -C full-checkout reset base -- folder1/\* &&
573+
test_all_match git ls-files -s -- folder1
574+
'
575+
478576
test_expect_success 'merge, cherry-pick, and rebase' '
479577
init_repos &&
480578

0 commit comments

Comments
 (0)