test-tool: don't force full index

We will use 'test-tool read-cache --table' to check that a sparse index is written as part of init_repos. Since we will no longer always expand a sparse index into a full index, add an '--expand' parameter that adds a call to ensure_full_index() so we can compare a sparse index directly against a full index, or at least what the in-memory index looks like when expanded in this way. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Mar 30, 2021 at 13:10 UTC 2782db3eed808c2a5097ccd5af813d3338c5f313
2 files changed +17 -1
t/helper/test-read-cache.c
+12 -1
@@ -4,6 +4,7 @@
4 #include "blob.h"
5 #include "commit.h"
6 #include "tree.h"
7 +#include "sparse-index.h"
8
9 static void print_cache_entry(struct cache_entry *ce)
10 {
@@ -35,13 +36,19 @@ int cmd__read_cache(int argc, const char **argv)
36 struct repository *r = the_repository;
37 int i, cnt = 1;
38 const char *name = NULL;
38 - int table = 0;
39 + int table = 0, expand = 0;
40 +
41 + initialize_the_repository();
42 + prepare_repo_settings(r);
43 + r->settings.command_requires_full_index = 0;
44
45 for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
46 if (skip_prefix(*argv, "--print-and-refresh=", &name))
47 continue;
48 if (!strcmp(*argv, "--table"))
49 table = 1;
50 + else if (!strcmp(*argv, "--expand"))
51 + expand = 1;
52 }
53
54 if (argc == 1)
@@ -51,6 +58,10 @@ int cmd__read_cache(int argc, const char **argv)
58
59 for (i = 0; i < cnt; i++) {
60 repo_read_index(r);
61 +
62 + if (expand)
63 + ensure_full_index(r->index);
64 +
65 if (name) {
66 int pos;
67
t/t1092-sparse-checkout-compatibility.sh
+5
@@ -130,6 +130,11 @@ test_sparse_match () {
130 test_cmp sparse-checkout-err sparse-index-err
131 }
132
133 +test_expect_success 'expanded in-memory index matches full index' '
134 + init_repos &&
135 + test_sparse_match test-tool read-cache --expand --table
136 +'
137 +
138 test_expect_success 'status with options' '
139 init_repos &&
140 test_all_match git status --porcelain=v2 &&