Skip to content

Commit 8f3b5eb

Browse files
jayatheerthkulkarnigitster
authored andcommitted
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. Introduce a single helper 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf82364 commit 8f3b5eb

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

builtin/submodule--helper.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "advice.h"
3333
#include "branch.h"
3434
#include "list-objects-filter-options.h"
35+
#include "wildmatch.h"
36+
#include "strbuf.h"
3537

3638
#define OPT_QUIET (1 << 0)
3739
#define OPT_CACHED (1 << 1)
@@ -3323,6 +3325,24 @@ static int config_submodule_in_gitmodules(const char *name, const char *var, con
33233325
return ret;
33243326
}
33253327

3328+
static int submodule_active_matches_path(const char *path)
3329+
{
3330+
const struct string_list *values;
3331+
size_t i;
3332+
3333+
if (git_config_get_string_multi("submodule.active", &values))
3334+
return 0;
3335+
3336+
for (i = 0; i < values->nr; i++) {
3337+
const char *pat = values->items[i].string;
3338+
if (!wildmatch(pat, path, 0))
3339+
return 1;
3340+
}
3341+
3342+
return 0;
3343+
}
3344+
3345+
33263346
static void configure_added_submodule(struct add_data *add_data)
33273347
{
33283348
char *key;
@@ -3370,17 +3390,7 @@ static void configure_added_submodule(struct add_data *add_data)
33703390
* is_submodule_active(), since that function needs to find
33713391
* out the value of "submodule.active" again anyway.
33723392
*/
3373-
if (!git_config_get("submodule.active")) {
3374-
/*
3375-
* If the submodule being added isn't already covered by the
3376-
* current configured pathspec, set the submodule's active flag
3377-
*/
3378-
if (!is_submodule_active(the_repository, add_data->sm_path)) {
3379-
key = xstrfmt("submodule.%s.active", add_data->sm_name);
3380-
git_config_set_gently(key, "true");
3381-
free(key);
3382-
}
3383-
} else {
3393+
if (!submodule_active_matches_path(add_data->sm_path)) {
33843394
key = xstrfmt("submodule.%s.active", add_data->sm_name);
33853395
git_config_set_gently(key, "true");
33863396
free(key);

t/t7413-submodule-is-active.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,19 @@ test_expect_success 'is-active, submodule.active and submodule add' '
124124
git -C super2 config --get submodule.mod.active
125125
'
126126

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+
! git config --get submodule.lib/foo.active
139+
)
140+
'
141+
127142
test_done

0 commit comments

Comments
 (0)