Skip to content

Commit b713582

Browse files
authored
Merge pull request #419 from ldennington/sparse-index-diff
diff: enable and test the sparse index
2 parents f28fc01 + 73c2e9a commit b713582

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,39 @@ test_expect_success 'diff --staged' '
387387
test_all_match git diff --staged
388388
'
389389

390+
test_expect_success 'diff partially-staged' '
391+
init_repos &&
392+
393+
# Add file within cone
394+
test_all_match git sparse-checkout set deep &&
395+
run_on_all 'echo >deep/testfile' &&
396+
test_all_match git add deep/testfile &&
397+
run_on_all 'echo a new line >>deep/testfile' &&
398+
399+
test_all_match git diff &&
400+
test_all_match git diff --staged &&
401+
402+
# Add file outside cone
403+
test_all_match git reset --hard &&
404+
run_on_all mkdir newdirectory &&
405+
run_on_all 'echo >newdirectory/testfile' &&
406+
test_all_match git sparse-checkout set newdirectory &&
407+
test_all_match git add newdirectory/testfile &&
408+
run_on_all 'echo a new line >>newdirectory/testfile' &&
409+
test_all_match git sparse-checkout set &&
410+
411+
test_all_match git diff &&
412+
test_all_match git diff --staged &&
413+
414+
# Merge conflict outside cone
415+
test_all_match git reset --hard &&
416+
test_all_match git checkout merge-left &&
417+
test_all_match test_must_fail git merge merge-right &&
418+
419+
test_all_match git diff &&
420+
test_all_match git diff --staged
421+
'
422+
390423
# NEEDSWORK: sparse-checkout behaves differently from full-checkout when
391424
# running this test with 'df-conflict-2' after 'df-conflict-1'.
392425
test_expect_success 'diff with renames and conflicts' '
@@ -822,6 +855,12 @@ test_expect_success 'sparse-index is not expanded' '
822855
ensure_not_expanded reset base -- folder1 &&
823856
824857
ensure_not_expanded reset --hard update-deep &&
858+
859+
echo a test change >>sparse-index/README.md &&
860+
ensure_not_expanded diff &&
861+
git -C sparse-index add README.md &&
862+
ensure_not_expanded diff --staged &&
863+
825864
ensure_not_expanded checkout -f update-deep &&
826865
(
827866
sane_unset GIT_TEST_MERGE_ALGORITHM &&

0 commit comments

Comments
 (0)