Skip to content

Commit 1c4e373

Browse files
committed
Merge branch 'sl/diff-files-sparse' into seen
Teach "diff-files" not to expand sparse-index unless needed. * sl/diff-files-sparse: diff-files: integrate with sparse index t1092: add tests for `git diff-files`
2 parents 6848876 + a727a15 commit 1c4e373

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

builtin/diff-files.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
2727
usage(diff_files_usage);
2828

2929
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
30+
31+
prepare_repo_settings(the_repository);
32+
the_repository->settings.command_requires_full_index = 0;
33+
3034
repo_init_revisions(the_repository, &rev, prefix);
3135
rev.abbrev = 0;
3236

t/perf/p2000-sparse-operations.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,7 @@ test_perf_on_all git checkout-index -f --all
125125
test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
126126
test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
127127
test_perf_on_all git grep --cached --sparse bogus -- "f2/f1/f1/*"
128+
test_perf_on_all git diff-files
129+
test_perf_on_all git diff-files $SPARSE_CONE/a
128130

129131
test_done

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,4 +2055,65 @@ test_expect_success 'grep sparse directory within submodules' '
20552055
test_cmp actual expect
20562056
'
20572057

2058+
test_expect_success 'diff-files with pathspec inside sparse definition' '
2059+
init_repos &&
2060+
2061+
write_script edit-contents <<-\EOF &&
2062+
echo text >>"$1"
2063+
EOF
2064+
2065+
run_on_all ../edit-contents deep/a &&
2066+
2067+
test_all_match git diff-files &&
2068+
2069+
test_all_match git diff-files deep/a
2070+
2071+
'
2072+
2073+
test_expect_success 'diff-files with pathspec outside sparse definition' '
2074+
init_repos &&
2075+
2076+
write_script edit-contents <<-\EOF &&
2077+
echo text >>"$1"
2078+
EOF
2079+
2080+
# add file to the index but outside of cone
2081+
run_on_sparse mkdir newdirectory &&
2082+
run_on_sparse ../edit-contents newdirectory/testfile &&
2083+
test_sparse_match git add --sparse newdirectory/testfile &&
2084+
2085+
# file present on-disk without modifications
2086+
test_sparse_match git diff-files &&
2087+
test_must_be_empty sparse-checkout-out &&
2088+
test_must_be_empty sparse-checkout-err &&
2089+
test_sparse_match git diff-files newdirectory/testfile &&
2090+
test_must_be_empty sparse-checkout-out &&
2091+
test_must_be_empty sparse-checkout-err &&
2092+
2093+
# file present on-disk with modifications
2094+
FN=newdirectory/testfile &&
2095+
OID=$(git -C sparse-checkout hash-object $FN) &&
2096+
ZERO=$(test_oid zero) &&
2097+
echo ":100644 100644 $OID $ZERO M $FN" >expect &&
2098+
2099+
run_on_sparse ../edit-contents newdirectory/testfile &&
2100+
test_sparse_match git diff-files &&
2101+
test_cmp expect sparse-checkout-out &&
2102+
test_sparse_match git diff-files newdirectory/testfile &&
2103+
test_cmp expect sparse-checkout-out
2104+
'
2105+
2106+
test_expect_success 'sparse index is not expanded: diff-files' '
2107+
init_repos &&
2108+
2109+
write_script edit-contents <<-\EOF &&
2110+
echo text >>"$1"
2111+
EOF
2112+
2113+
run_on_all ../edit-contents deep/a &&
2114+
2115+
ensure_not_expanded diff-files &&
2116+
ensure_not_expanded diff-files deep/a
2117+
'
2118+
20582119
test_done

0 commit comments

Comments
 (0)