summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/diff-index.c9
-rwxr-xr-xt/perf/p2000-sparse-operations.sh3
-rwxr-xr-xt/t1092-sparse-checkout-compatibility.sh44
3 files changed, 56 insertions, 0 deletions
diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index b9a19bb7d3..da7b845f1d 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -25,6 +25,14 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
usage(diff_cache_usage);
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
+
+ prepare_repo_settings(the_repository);
+ the_repository->settings.command_requires_full_index = 0;
+
+ if (pathspec_needs_expanded_index(the_repository->index,
+ &rev.diffopt.pathspec))
+ ensure_full_index(the_repository->index);
+
repo_init_revisions(the_repository, &rev, prefix);
rev.abbrev = 0;
prefix = precompose_argv_prefix(argc, argv, prefix);
@@ -70,6 +78,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
perror("repo_read_index");
return -1;
}
+
result = run_diff_index(&rev, option);
result = diff_result_code(&rev.diffopt, result);
release_revisions(&rev);
diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
index e4a132f593..ea884e84bf 100755
--- a/t/perf/p2000-sparse-operations.sh
+++ b/t/perf/p2000-sparse-operations.sh
@@ -125,5 +125,8 @@ test_perf_on_all git checkout-index -f --all
test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
test_perf_on_all git grep --cached bogus -- "f2/f1/f1/*"
+test_perf_on_all 'echo >>a && git diff-index HEAD'
+test_perf_on_all git diff-index HEAD "**a"
+test_perf_on_all git diff-index --cached HEAD
test_done
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index 801919009e..24bc716c48 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -1996,6 +1996,50 @@ test_expect_success 'sparse index is not expanded: rm' '
ensure_not_expanded rm -r deep
'
+test_expect_success 'sparse index is not expanded: diff-index' '
+ init_repos &&
+
+ echo "new" >>sparse-index/g &&
+ git -C sparse-index add g &&
+ git -C sparse-index commit -m "dummy" &&
+ ensure_not_expanded diff-index HEAD~1 &&
+
+ echo "text" >>sparse-index/deep/a &&
+
+ ensure_not_expanded diff-index HEAD deep/a &&
+ ensure_not_expanded diff-index HEAD deep/*
+'
+test_expect_success 'diff-index pathspec expands index when necessary' '
+ init_repos &&
+
+ echo "text" >>sparse-index/deep/a &&
+
+ # pathspec that should expand index
+ ! ensure_not_expanded diff-index "*/a" &&
+ ! ensure_not_expanded diff-index "**a"
+'
+
+test_expect_success 'diff-index with pathspec outside sparse definition' '
+ init_repos &&
+
+ test_sparse_match test_must_fail git diff-index HEAD folder2/a
+'
+
+test_expect_success 'match all: diff-index' '
+ init_repos &&
+
+ test_all_match git diff-index HEAD &&
+ write_script edit-contents <<-\EOF &&
+ echo text >>$1
+ EOF
+ run_on_all ../edit-contents g &&
+ run_on_all git add g &&
+ run_on_all git commit -m "two" &&
+ run_on_all rm g &&
+ test_all_match git diff-index HEAD &&
+ test_all_match git diff-index --cached HEAD~1
+'
+
test_expect_success 'grep with and --cached' '
init_repos &&