checkout: ensure full index

Before iterating over all cache entries in the checkout builtin, ensure that we have a full index to avoid any 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 0f6d3ba6bd795b09bf216c267bbf6e3ec2409d1e
1 file changed +5
builtin/checkout.c
+5
@@ -368,6 +368,9 @@ static int checkout_worktree(const struct checkout_opts *opts,
368 NULL);
369
370 enable_delayed_checkout(&state);
371 +
372 + /* TODO: audit for interaction with sparse-index. */
373 + ensure_full_index(&the_index);
374 for (pos = 0; pos < active_nr; pos++) {
375 struct cache_entry *ce = active_cache[pos];
376 if (ce->ce_flags & CE_MATCHED) {
@@ -512,6 +515,8 @@ static int checkout_paths(const struct checkout_opts *opts,
515 * Make sure all pathspecs participated in locating the paths
516 * to be checked out.
517 */
518 + /* TODO: audit for interaction with sparse-index. */
519 + ensure_full_index(&the_index);
520 for (pos = 0; pos < active_nr; pos++)
521 if (opts->overlay_mode)
522 mark_ce_for_checkout_overlay(active_cache[pos],