]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule: sparse-index should not collapse links
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 30 Mar 2021 13:10:56 +0000 (13:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Mar 2021 19:57:47 +0000 (12:57 -0700)
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>
sparse-index.c
t/t1092-sparse-checkout-compatibility.sh

index 619ff7c2e217ae060aebb6e3ce2396c3cd0d9dc7..7631f7bd00b78e9064ce113472db2c961dc17c14 100644 (file)
@@ -52,6 +52,7 @@ static int convert_to_sparse_rec(struct index_state *istate,
                struct cache_entry *ce = istate->cache[i];
 
                if (ce_stage(ce) ||
+                   S_ISGITLINK(ce->ce_mode) ||
                    !(ce->ce_flags & CE_SKIP_WORKTREE))
                        can_convert = 0;
        }
index 1e888d1951226b4c7923e9e374de7f198b55ba23..cba5f89b1e96e6ed9148ae1f534ac907d8875fc1 100755 (executable)
@@ -376,4 +376,21 @@ test_expect_success 'clean' '
        test_sparse_match test_path_is_dir folder1
 '
 
+test_expect_success 'submodule handling' '
+       init_repos &&
+
+       test_all_match mkdir modules &&
+       test_all_match touch modules/a &&
+       test_all_match git add modules &&
+       test_all_match git commit -m "add modules directory" &&
+
+       run_on_all git submodule add "$(pwd)/initial-repo" modules/sub &&
+       test_all_match git commit -m "add submodule" &&
+
+       # having a submodule prevents "modules" from collapse
+       test-tool -C sparse-index read-cache --table >cache &&
+       grep "100644 blob .*    modules/a" cache &&
+       grep "160000 commit $(git -C initial-repo rev-parse HEAD)       modules/sub" cache
+'
+
 test_done