@@ -541,6 +541,45 @@ test_expect_success 'diff --cached' '
541541 test_all_match git diff --cached
542542'
543543
544+ test_expect_success ' diff partially-staged' '
545+ init_repos &&
546+
547+ git -C full-checkout config advice.sparseIndexExpanded false &&
548+
549+ write_script edit-contents <<-\EOF &&
550+ echo text >>$1
551+ EOF
552+
553+ # Add file within cone
554+ test_all_match git sparse-checkout set deep &&
555+ run_on_all ../edit-contents deep/testfile &&
556+ test_all_match git add deep/testfile &&
557+ run_on_all ../edit-contents deep/testfile &&
558+
559+ test_all_match git diff &&
560+ test_all_match git diff --staged &&
561+
562+ # Add file outside cone
563+ test_all_match git reset --hard &&
564+ run_on_all mkdir newdirectory &&
565+ run_on_all ../edit-contents newdirectory/testfile &&
566+ test_all_match git sparse-checkout set newdirectory &&
567+ test_all_match git add newdirectory/testfile &&
568+ run_on_all ../edit-contents newdirectory/testfile &&
569+ test_all_match git sparse-checkout set &&
570+
571+ test_all_match git diff &&
572+ test_all_match git diff --staged &&
573+
574+ # Merge conflict outside cone
575+ test_all_match git reset --hard &&
576+ test_all_match git checkout merge-left &&
577+ test_all_match test_must_fail git merge merge-right &&
578+
579+ test_all_match git diff &&
580+ test_all_match git diff --staged
581+ '
582+
544583# NEEDSWORK: sparse-checkout behaves differently from full-checkout when
545584# running this test with 'df-conflict-2' after 'df-conflict-1'.
546585test_expect_success ' diff with renames and conflicts' '
@@ -1482,6 +1521,11 @@ test_expect_success 'sparse-index is not expanded' '
14821521 ensure_not_expanded reset --merge update-deep &&
14831522 ensure_not_expanded reset --hard &&
14841523
1524+ echo a test change >>sparse-index/README.md &&
1525+ ensure_not_expanded diff &&
1526+ git -C sparse-index add README.md &&
1527+ ensure_not_expanded diff --staged &&
1528+
14851529 ensure_not_expanded reset base -- deep/a &&
14861530 ensure_not_expanded reset base -- nonexistent-file &&
14871531 ensure_not_expanded reset deepest -- deep &&
0 commit comments