Skip to content

Commit f442313

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6e77352 commit f442313

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

sparse-index.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static int convert_to_sparse_rec(struct index_state *istate,
5252
struct cache_entry *ce = istate->cache[i];
5353

5454
if (ce_stage(ce) ||
55+
S_ISGITLINK(ce->ce_mode) ||
5556
!(ce->ce_flags & CE_SKIP_WORKTREE))
5657
can_convert = 0;
5758
}

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,21 @@ test_expect_success 'clean' '
376376
test_sparse_match test_path_is_dir folder1
377377
'
378378

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+
379396
test_done

0 commit comments

Comments
 (0)