merge-index: ensure full index

Before iterating over all cache entries, ensure that a sparse index is expanded to a full one to avoid unexpected behavior. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Apr 1, 2021 at 01:49 UTC 299e2c4561ba6eb99e367b1f73b8ffb3cead5efa
1 file changed +5
builtin/merge-index.c
+5
@@ -58,6 +58,8 @@ static void merge_one_path(const char *path)
58 static void merge_all(void)
59 {
60 int i;
61 + /* TODO: audit for interaction with sparse-index. */
62 + ensure_full_index(&the_index);
63 for (i = 0; i < active_nr; i++) {
64 const struct cache_entry *ce = active_cache[i];
65 if (!ce_stage(ce))
@@ -80,6 +82,9 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix)
82
83 read_cache();
84
85 + /* TODO: audit for interaction with sparse-index. */
86 + ensure_full_index(&the_index);
87 +
88 i = 1;
89 if (!strcmp(argv[i], "-o")) {
90 one_shot = 1;