Skip to content

Commit a18dbe2

Browse files
ldenningtonderrickstolee
authored andcommitted
Merge pull request #419 from ldennington/sparse-index-diff
diff: enable and test the sparse index
2 parents 279ee77 + 3ff52f4 commit a18dbe2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

builtin/diff.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
437437

438438
prefix = setup_git_directory_gently(&nongit);
439439

440+
prepare_repo_settings(the_repository);
441+
the_repository->settings.command_requires_full_index = 0;
442+
440443
if (!no_index) {
441444
/*
442445
* Treat git diff with at least one path outside of the

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,43 @@ test_expect_success 'diff --staged' '
417417
test_all_match git diff --staged
418418
'
419419

420+
test_expect_success 'diff partially-staged' '
421+
init_repos &&
422+
423+
write_script edit-contents <<-\EOF &&
424+
echo text >>$1
425+
EOF
426+
427+
# Add file within cone
428+
test_all_match git sparse-checkout set deep &&
429+
run_on_all ../edit-contents deep/testfile &&
430+
test_all_match git add deep/testfile &&
431+
run_on_all ../edit-contents deep/testfile &&
432+
433+
test_all_match git diff &&
434+
test_all_match git diff --staged &&
435+
436+
# Add file outside cone
437+
test_all_match git reset --hard &&
438+
run_on_all mkdir newdirectory &&
439+
run_on_all ../edit-contents newdirectory/testfile &&
440+
test_all_match git sparse-checkout set newdirectory &&
441+
test_all_match git add newdirectory/testfile &&
442+
run_on_all ../edit-contents newdirectory/testfile &&
443+
test_all_match git sparse-checkout set &&
444+
445+
test_all_match git diff &&
446+
test_all_match git diff --staged &&
447+
448+
# Merge conflict outside cone
449+
test_all_match git reset --hard &&
450+
test_all_match git checkout merge-left &&
451+
test_all_match test_must_fail git merge merge-right &&
452+
453+
test_all_match git diff &&
454+
test_all_match git diff --staged
455+
'
456+
420457
# NEEDSWORK: sparse-checkout behaves differently from full-checkout when
421458
# running this test with 'df-conflict-2' after 'df-conflict-1'.
422459
test_expect_success 'diff with renames and conflicts' '
@@ -872,6 +909,11 @@ test_expect_success 'sparse-index is not expanded' '
872909
873910
ensure_not_expanded reset --hard update-deep &&
874911
912+
echo a test change >>sparse-index/README.md &&
913+
ensure_not_expanded diff &&
914+
git -C sparse-index add README.md &&
915+
ensure_not_expanded diff --staged &&
916+
875917
ensure_not_expanded reset base -- deep/a &&
876918
ensure_not_expanded reset base -- nonexistent-file &&
877919
ensure_not_expanded reset deepest -- deep &&

0 commit comments

Comments
 (0)