@@ -481,6 +481,113 @@ test_expect_success 'checkout and reset (mixed) [sparse]' '
481
481
test_sparse_match git reset update-folder2
482
482
'
483
483
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
+
484
591
test_expect_success ' merge, cherry-pick, and rebase' '
485
592
init_repos &&
486
593
@@ -644,7 +751,7 @@ test_expect_success 'sparse-index is expanded and converted back' '
644
751
init_repos &&
645
752
646
753
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 &&
648
755
test_region index convert_to_sparse trace2.txt &&
649
756
test_region index ensure_full_index trace2.txt
650
757
'
@@ -681,9 +788,9 @@ test_expect_success 'sparse-index is not expanded' '
681
788
ensure_not_expanded checkout - &&
682
789
ensure_not_expanded switch rename-out-to-out &&
683
790
ensure_not_expanded switch - &&
684
- git -C sparse-index reset --hard &&
791
+ ensure_not_expanded reset --hard &&
685
792
ensure_not_expanded checkout rename-out-to-out -- deep/deeper1 &&
686
- git -C sparse-index reset --hard &&
793
+ ensure_not_expanded reset --hard &&
687
794
ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
688
795
689
796
echo >>sparse-index/README.md &&
@@ -693,6 +800,28 @@ test_expect_success 'sparse-index is not expanded' '
693
800
echo >>sparse-index/untracked.txt &&
694
801
ensure_not_expanded add . &&
695
802
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 &&
696
825
ensure_not_expanded checkout -f update-deep &&
697
826
(
698
827
sane_unset GIT_TEST_MERGE_ALGORITHM &&
0 commit comments