When the user recursively clones a repository with submodules and one or more of those submodules is marked with the submodule.<name>.update=none configuration, the submodule will end up being active. This is a problem because we will have skipped cloning or checking out the submodule, and as a result, other commands, such as git reset or git checkout, will fail if they are invoked with --recurse-submodules (or when submodule.recurse is true). This is obviously not the behavior the user wanted, so let's fix this by specifically setting the submodule as inactive in this case when we're initializing the repository. That will make us properly ignore the submodule when performing recursive operations. We only do this when initializing a submodule, since git submodule update can update the submodule with various options despite the setting of "none" and we want those options to override it as they currently do. Reported-by: Rose Kunkel <rose@xxxxxxxxxxxxx> Helped-by: Philippe Blain <levraiphilippeblain@xxxxxxxxx> Signed-off-by: brian m. carlson <sandals@xxxxxxxxxxxxxxxxxxxx> --- builtin/submodule--helper.c | 6 ++++++ t/t5601-clone.sh | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index ae6174ab05..a3f8c45d97 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -686,6 +686,12 @@ static void init_submodule(const char *path, const char *prefix, if (git_config_set_gently(sb.buf, upd)) die(_("Failed to register update mode for submodule path '%s'"), displaypath); + + if (sub->update_strategy.type == SM_UPDATE_NONE) { + strbuf_reset(&sb); + strbuf_addf(&sb, "submodule.%s.active", sub->name); + git_config_set_gently(sb.buf, "false"); + } } strbuf_release(&sb); free(displaypath); diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index c0688467e7..efe6b13be0 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -752,6 +752,30 @@ test_expect_success 'batch missing blob request does not inadvertently try to fe git clone --filter=blob:limit=0 "file://$(pwd)/server" client ' +test_expect_success 'clone with submodule with update=none is not active' ' + rm -rf server client && + + test_create_repo server && + echo a >server/a && + echo b >server/b && + git -C server add a b && + git -C server commit -m x && + + echo aa >server/a && + echo bb >server/b && + git -C server submodule add --name c "$(pwd)/repo_for_submodule" c && + git -C server config -f .gitmodules submodule.c.update none && + git -C server add a b c .gitmodules && + git -C server commit -m x && + + git clone --recurse-submodules server client && + git -C client config submodule.c.active >actual && + echo false >expected && + test_cmp actual expected && + # This would fail if the submodule were active, since it is not checked out. + git -C client reset --recurse-submodules --hard +' + . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd