From: Junio C Hamano Date: Tue, 5 Aug 2025 18:53:56 +0000 (-0700) Subject: Merge branch 'kj/renamed-submodule' X-Git-Tag: v2.51.0-rc1~6 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=8982c5e909394a1bb51fc4103875e0e7a2601972;p=thirdparty%2Fgit.git Merge branch 'kj/renamed-submodule' The case where a new submodule takes a path where used to be a completely different subproject is now dealt a bit better than before. * kj/renamed-submodule: fixup! submodule: skip redundant active entries when pattern covers path fixup! submodule: prevent overwriting .gitmodules on path reuse submodule: skip redundant active entries when pattern covers path submodule: prevent overwriting .gitmodules on path reuse --- 8982c5e909394a1bb51fc4103875e0e7a2601972 diff --cc builtin/submodule--helper.c index 28f34f7bc1,10cd65e343..07a1935cbe --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@@ -3307,9 -3330,11 +3309,11 @@@ static void configure_added_submodule(s char *key; struct child_process add_submod = CHILD_PROCESS_INIT; struct child_process add_gitmodules = CHILD_PROCESS_INIT; + const struct string_list *values; + int matched = 0; key = xstrfmt("submodule.%s.url", add_data->sm_name); - git_config_set_gently(key, add_data->realrepo); + repo_config_set_gently(the_repository, key, add_data->realrepo); free(key); add_submod.git_cmd = 1; @@@ -3349,20 -3374,28 +3353,28 @@@ * is_submodule_active(), since that function needs to find * out the value of "submodule.active" again anyway. */ - if (!repo_config_get(the_repository, "submodule.active")) { - if (git_config_get("submodule.active") || /* key absent */ - git_config_get_string_multi("submodule.active", &values)) { ++ if (repo_config_get(the_repository, "submodule.active") || /* key absent */ ++ repo_config_get_string_multi(the_repository, "submodule.active", &values)) { /* * If the submodule being added isn't already covered by the * current configured pathspec, set the submodule's active flag */ - if (!is_submodule_active(the_repository, add_data->sm_path)) { + key = xstrfmt("submodule.%s.active", add_data->sm_name); - git_config_set_gently(key, "true"); ++ repo_config_set_gently(the_repository, key, "true"); + free(key); + } else { + for (size_t i = 0; i < values->nr; i++) { + const char *pat = values->items[i].string; + if (!wildmatch(pat, add_data->sm_path, 0)) { /* match found */ + matched = 1; + break; + } + } + if (!matched) { /* no pattern matched -> force-enable */ key = xstrfmt("submodule.%s.active", add_data->sm_name); - git_config_set_gently(key, "true"); + repo_config_set_gently(the_repository, key, "true"); free(key); } - } else { - key = xstrfmt("submodule.%s.active", add_data->sm_name); - repo_config_set_gently(the_repository, key, "true"); - free(key); } }