submodule: skip redundant active entries when pattern covers path
configure_added_submodule always writes an explicit submodule.<name>.active entry, even when the new path is already matched by submodule.active patterns. This leads to unnecessary and cluttered configuration. change the logic to centralize wildmatch-based pattern lookup, in configure_added_submodule. Wrap the active-entry write in a conditional that only fires when that helper reports no existing pattern covers the submodule’s path. Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
K Jayatheerth committed
Jul 24, 2025 at 20:54 UTC
bb10dcf5730356b9ef70d40eca2335e9d406954a
2 files changed
+34
-6
builtin/submodule--helper.c
+19
-6
@@ -32,6 +32,8 @@
32
#include "advice.h"
33
#include "branch.h"
34
#include "list-objects-filter-options.h"
35
+#include "wildmatch.h"
36
+#include "strbuf.h"
37
38
#define OPT_QUIET (1 << 0)
39
#define OPT_CACHED (1 << 1)
@@ -3329,6 +3331,9 @@ static void configure_added_submodule(struct add_data *add_data)
3331
struct child_process add_submod = CHILD_PROCESS_INIT;
3332
struct child_process add_gitmodules = CHILD_PROCESS_INIT;
3333
3334
+ const struct string_list *values;
3335
+ size_t i;
3336
+ int matched = 0;
3337
key = xstrfmt("submodule.%s.url", add_data->sm_name);
3338
git_config_set_gently(key, add_data->realrepo);
3339
free(key);
@@ -3370,20 +3375,28 @@ static void configure_added_submodule(struct add_data *add_data)
3375
* is_submodule_active(), since that function needs to find
3376
* out the value of "submodule.active" again anyway.
3377
*/
3373
- if (!git_config_get("submodule.active")) {
3378
+ if (git_config_get("submodule.active") || /* key absent */
3379
+ git_config_get_string_multi("submodule.active", &values)) {
3380
/*
3381
* If the submodule being added isn't already covered by the
3382
* current configured pathspec, set the submodule's active flag
3383
*/
3378
- if (!is_submodule_active(the_repository, add_data->sm_path)) {
3384
+ key = xstrfmt("submodule.%s.active", add_data->sm_name);
3385
+ git_config_set_gently(key, "true");
3386
+ free(key);
3387
+ } else {
3388
+ for (i = 0; i < values->nr; i++) {
3389
+ const char *pat = values->items[i].string;
3390
+ if (!wildmatch(pat, add_data->sm_path, 0)) { /* match found */
3391
+ matched = 1;
3392
+ break;
3393
+ }
3394
+ }
3395
+ if (!matched) { /* no pattern matched -> force-enable */
3396
key = xstrfmt("submodule.%s.active", add_data->sm_name);
3397
git_config_set_gently(key, "true");
3398
free(key);
3399
}
3383
- } else {
3384
- key = xstrfmt("submodule.%s.active", add_data->sm_name);
3385
- git_config_set_gently(key, "true");
3386
- free(key);
3400
}
3401
}
3402
t/t7413-submodule-is-active.sh
+15
@@ -124,4 +124,19 @@ test_expect_success 'is-active, submodule.active and submodule add' '
124
git -C super2 config --get submodule.mod.active
125
'
126
127
+test_expect_success 'submodule add skips redundant active entry' '
128
+ git init repo &&
129
+ (
130
+ cd repo &&
131
+ git config submodule.active "lib/*" &&
132
+ git commit --allow-empty -m init &&
133
+
134
+ git init ../lib-origin &&
135
+ git -C ../lib-origin commit --allow-empty -m init &&
136
+
137
+ git submodule add ../lib-origin lib/foo &&
138
+ test_must_fail git config --get submodule.lib/foo.active
139
+ )
140
+'
141
+
142
test_done