@@ -481,6 +481,113 @@ test_expect_success 'checkout and reset (mixed) [sparse]' '
481481 test_sparse_match git reset update-folder2
482482'
483483
484+ # NEEDSWORK: with mixed reset, files with differences between HEAD and <commit>
485+ # will be added to the work tree even if outside the sparse checkout
486+ # definition, and even if the file is modified to a state of having no local
487+ # changes. The file is "re-ignored" if a hard reset is executed. We may want to
488+ # change this behavior in the future and enforce that files are not written
489+ # outside of the sparse checkout definition.
490+ test_expect_success ' checkout and mixed reset file tracking [sparse]' '
491+ init_repos &&
492+
493+ test_all_match git checkout -b reset-test update-deep &&
494+ test_all_match git reset update-folder1 &&
495+ test_all_match git reset update-deep &&
496+
497+ # At this point, there are no changes in the working tree. However,
498+ # folder1/a now exists locally (even though it is outside of the sparse
499+ # paths).
500+ run_on_sparse test_path_exists folder1 &&
501+
502+ run_on_all rm folder1/a &&
503+ test_all_match git status --porcelain=v2 &&
504+
505+ test_all_match git reset --hard update-deep &&
506+ run_on_sparse test_path_is_missing folder1 &&
507+ test_path_exists full-checkout/folder1
508+ '
509+
510+ test_expect_success ' checkout and reset (merge)' '
511+ init_repos &&
512+
513+ write_script edit-contents <<-\EOF &&
514+ echo text >>$1
515+ EOF
516+
517+ test_all_match git checkout -b reset-test update-deep &&
518+ run_on_all ../edit-contents a &&
519+ test_all_match git reset --merge deepest &&
520+ test_all_match git status --porcelain=v2 &&
521+
522+ test_all_match git reset --hard update-deep &&
523+ run_on_all ../edit-contents deep/a &&
524+ test_all_match test_must_fail git reset --merge deepest
525+ '
526+
527+ test_expect_success ' checkout and reset (keep)' '
528+ init_repos &&
529+
530+ write_script edit-contents <<-\EOF &&
531+ echo text >>$1
532+ EOF
533+
534+ test_all_match git checkout -b reset-test update-deep &&
535+ run_on_all ../edit-contents a &&
536+ test_all_match git reset --keep deepest &&
537+ test_all_match git status --porcelain=v2 &&
538+
539+ test_all_match git reset --hard update-deep &&
540+ run_on_all ../edit-contents deep/a &&
541+ test_all_match test_must_fail git reset --keep deepest
542+ '
543+
544+ test_expect_success ' reset with pathspecs inside sparse definition' '
545+ init_repos &&
546+
547+ write_script edit-contents <<-\EOF &&
548+ echo text >>$1
549+ EOF
550+
551+ test_all_match git checkout -b reset-test update-deep &&
552+ run_on_all ../edit-contents deep/a &&
553+
554+ test_all_match git reset base -- deep/a &&
555+ test_all_match git status --porcelain=v2 &&
556+
557+ test_all_match git reset base -- nonexistent-file &&
558+ test_all_match git status --porcelain=v2 &&
559+
560+ test_all_match git reset deepest -- deep &&
561+ test_all_match git status --porcelain=v2
562+ '
563+
564+ test_expect_success ' reset with sparse directory pathspec outside definition' '
565+ init_repos &&
566+
567+ test_all_match git checkout -b reset-test update-deep &&
568+ test_all_match git reset --hard update-folder1 &&
569+ test_all_match git reset base -- folder1 &&
570+ test_all_match git status --porcelain=v2
571+ '
572+
573+ test_expect_success ' reset with pathspec match in sparse directory' '
574+ init_repos &&
575+
576+ test_all_match git checkout -b reset-test update-deep &&
577+ test_all_match git reset --hard update-folder1 &&
578+ test_all_match git reset base -- folder1/a &&
579+ test_all_match git status --porcelain=v2
580+ '
581+
582+ test_expect_success ' reset with wildcard pathspec' '
583+ init_repos &&
584+
585+ test_all_match git checkout -b reset-test update-deep &&
586+ test_all_match git reset --hard update-folder1 &&
587+ test_all_match git reset base -- */a &&
588+ test_all_match git status --porcelain=v2
589+ '
590+
484591test_expect_success ' merge, cherry-pick, and rebase' '
485592 init_repos &&
486593
@@ -644,7 +751,7 @@ test_expect_success 'sparse-index is expanded and converted back' '
644751 init_repos &&
645752
646753 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
647- git -C sparse-index -c core.fsmonitor="" reset --hard &&
754+ git -C sparse-index -c core.fsmonitor="" read-tree -mu HEAD &&
648755 test_region index convert_to_sparse trace2.txt &&
649756 test_region index ensure_full_index trace2.txt
650757'
@@ -681,9 +788,9 @@ test_expect_success 'sparse-index is not expanded' '
681788 ensure_not_expanded checkout - &&
682789 ensure_not_expanded switch rename-out-to-out &&
683790 ensure_not_expanded switch - &&
684- git -C sparse-index reset --hard &&
791+ ensure_not_expanded reset --hard &&
685792 ensure_not_expanded checkout rename-out-to-out -- deep/deeper1 &&
686- git -C sparse-index reset --hard &&
793+ ensure_not_expanded reset --hard &&
687794 ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
688795
689796 echo >>sparse-index/README.md &&
@@ -693,6 +800,28 @@ test_expect_success 'sparse-index is not expanded' '
693800 echo >>sparse-index/untracked.txt &&
694801 ensure_not_expanded add . &&
695802
803+ for ref in update-deep update-folder1 update-folder2 update-deep
804+ do
805+ echo >>sparse-index/README.md &&
806+ ensure_not_expanded reset --mixed $ref
807+ ensure_not_expanded reset --hard $ref
808+ done &&
809+
810+ ensure_not_expanded reset --hard update-deep &&
811+ ensure_not_expanded reset --keep base &&
812+ ensure_not_expanded reset --merge update-deep &&
813+
814+ ensure_not_expanded reset base -- deep/a &&
815+ ensure_not_expanded reset base -- nonexistent-file &&
816+ ensure_not_expanded reset deepest -- deep &&
817+
818+ # Although folder1 is outside the sparse definition, it exists as a
819+ # directory entry in the index, so it will be reset without needing to
820+ # expand the full index.
821+ ensure_not_expanded reset --hard update-folder1 &&
822+ ensure_not_expanded reset base -- folder1 &&
823+
824+ ensure_not_expanded reset --hard update-deep &&
696825 ensure_not_expanded checkout -f update-deep &&
697826 (
698827 sane_unset GIT_TEST_MERGE_ALGORITHM &&
0 commit comments