submodule: sparse-index should not collapse links

A submodule is stored as a "Git link" that actually points to a commit within a submodule. Submodules are populated or not depending on submodule configuration, not sparse-checkout. To ensure that the sparse-index feature integrates correctly with submodules, we should not collapse a directory if there is a Git link within its range. 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 f442313e2e7a2ebf592a5943d4d4392e88153484
2 files changed +18
sparse-index.c
+1
@@ -52,6 +52,7 @@ static int convert_to_sparse_rec(struct index_state *istate,
52 struct cache_entry *ce = istate->cache[i];
53
54 if (ce_stage(ce) ||
55 + S_ISGITLINK(ce->ce_mode) ||
56 !(ce->ce_flags & CE_SKIP_WORKTREE))
57 can_convert = 0;
58 }
t/t1092-sparse-checkout-compatibility.sh
+17
@@ -376,4 +376,21 @@ test_expect_success 'clean' '
376 test_sparse_match test_path_is_dir folder1
377 '
378
379 +test_expect_success 'submodule handling' '
380 + init_repos &&
381 +
382 + test_all_match mkdir modules &&
383 + test_all_match touch modules/a &&
384 + test_all_match git add modules &&
385 + test_all_match git commit -m "add modules directory" &&
386 +
387 + run_on_all git submodule add "$(pwd)/initial-repo" modules/sub &&
388 + test_all_match git commit -m "add submodule" &&
389 +
390 + # having a submodule prevents "modules" from collapse
391 + test-tool -C sparse-index read-cache --table >cache &&
392 + grep "100644 blob .* modules/a" cache &&
393 + grep "160000 commit $(git -C initial-repo rev-parse HEAD) modules/sub" cache
394 +'
395 +
396 test_done