diff --git a/builtin/update-index.c b/builtin/update-index.c index bd96c716d16602..5b1ae4bdfdf163 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -747,17 +747,23 @@ static int do_reupdate(int ac, const char **av, * commit. Update everything in the index. */ has_head = 0; + redo: - /* TODO: audit for interaction with sparse-index. */ - ensure_full_index(&the_index); for (pos = 0; pos < active_nr; pos++) { const struct cache_entry *ce = active_cache[pos]; struct cache_entry *old = NULL; int save_nr; char *path; - if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL)) + /* + * We can safely skip re-updating sparse directories because if there + * were any changes to re-update inside of the sparse directory, it + * would not be sparse. + */ + if (S_ISSPARSEDIR(ce->ce_mode) || ce_stage(ce) || + !ce_path_match(&the_index, ce, &pathspec, NULL)) continue; + if (has_head) old = read_one_ent(NULL, &head_oid, ce->name, ce_namelen(ce), 0); diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 08d87b68352a52..8ddacab279185b 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1392,6 +1392,9 @@ test_expect_success 'sparse index is not expanded: update-index' ' ensure_not_expanded update-index --add README.md && ensure_not_expanded update-index a && ensure_not_expanded update-index --remove deep/a && + + rm -f sparse-index/README.md sparse-index/a && + ensure_not_expanded update-index --add --remove --again ' # NEEDSWORK: a sparse-checkout behaves differently from a full checkout