@@ -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+
478576test_expect_success ' merge, cherry-pick, and rebase' '
479577 init_repos &&
480578
0 commit comments