t1092: test 'git restore' with sparse index

A user reported that 'git restore --staged .' causes the sparse index to expand. This is somewhat natural because the '.' pathspec means 'check every path'. However, the restore will not update paths marked with the SKIP_WORKTREE bit, so we shouldn't need to process such entries. For now, establish the current behavior, including the sparse index expansion, in the t1092 test case as a baseline. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed May 26, 2026 at 20:26 UTC ca7b9ae3403b1a46fffbdae312092c4029470eee
1 file changed +50
t/t1092-sparse-checkout-compatibility.sh
+50
@@ -2573,4 +2573,54 @@ test_expect_success 'sparse-index is not expanded: merge-ours' '
2573 ensure_not_expanded merge -s ours merge-right
2574 '
2575
2576 +test_expect_success 'restore --staged with sparse definition' '
2577 + init_repos &&
2578 +
2579 + # Stage changes within the sparse definition
2580 + test_all_match git checkout -b restore-staged-1 base &&
2581 + test_all_match git reset --soft update-deep &&
2582 + test_all_match git restore --staged . &&
2583 + test_all_match git status --porcelain=v2 &&
2584 + test_all_match git diff --cached
2585 +'
2586 +
2587 +test_expect_success 'restore --staged with outside sparse definition' '
2588 + init_repos &&
2589 +
2590 + # Stage changes that include paths outside the sparse definition.
2591 + # Although the working tree differs between full and sparse checkouts
2592 + # after restore, the state of the index should be the same.
2593 + test_all_match git checkout -b restore-staged-2 base &&
2594 + test_all_match git reset --soft update-folder1 &&
2595 + test_sparse_match git restore --staged . &&
2596 + git -C full-checkout restore --staged . &&
2597 + test_all_match git ls-files -s -- folder1 &&
2598 + test_all_match git diff --cached -- folder1
2599 +'
2600 +
2601 +test_expect_success 'restore --staged with wildcards' '
2602 + init_repos &&
2603 +
2604 + test_all_match git checkout -b restore-staged-3 base &&
2605 + test_all_match git reset --soft update-deep &&
2606 + test_all_match git restore --staged "deep/*" &&
2607 + test_all_match git status --porcelain=v2 &&
2608 + test_all_match git diff --cached
2609 +'
2610 +
2611 +test_expect_success 'sparse-index is expanded: restore --staged' '
2612 + init_repos &&
2613 +
2614 + git -C sparse-index checkout -b restore-staged-exp base &&
2615 + git -C sparse-index reset --soft update-folder1 &&
2616 + ensure_expanded restore --staged .
2617 +'
2618 +
2619 +test_expect_success 'sparse-index is expanded: restore --source --staged' '
2620 + init_repos &&
2621 +
2622 + git -C sparse-index checkout -b restore-source-staged base &&
2623 + ensure_expanded restore --source update-folder1 --staged .
2624 +'
2625 +
2626 test_done