]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'kj/renamed-submodule'
authorJunio C Hamano <gitster@pobox.com>
Tue, 5 Aug 2025 18:53:56 +0000 (11:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Aug 2025 18:53:56 +0000 (11:53 -0700)
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

1  2 
builtin/submodule--helper.c

index 28f34f7bc183d2f28125be8d713359da83a35904,10cd65e3435220436c55a18f8b63480076e7e0d7..07a1935cbe1a69d813402430967213d03ab8a128
@@@ -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;
         * 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);
        }
  }