|
32 | 32 | #include "advice.h"
|
33 | 33 | #include "branch.h"
|
34 | 34 | #include "list-objects-filter-options.h"
|
| 35 | +#include "wildmatch.h" |
| 36 | +#include "strbuf.h" |
35 | 37 |
|
36 | 38 | #define OPT_QUIET (1 << 0)
|
37 | 39 | #define OPT_CACHED (1 << 1)
|
@@ -3323,6 +3325,24 @@ static int config_submodule_in_gitmodules(const char *name, const char *var, con
|
3323 | 3325 | return ret;
|
3324 | 3326 | }
|
3325 | 3327 |
|
| 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 | + |
3326 | 3346 | static void configure_added_submodule(struct add_data *add_data)
|
3327 | 3347 | {
|
3328 | 3348 | char *key;
|
@@ -3370,17 +3390,7 @@ static void configure_added_submodule(struct add_data *add_data)
|
3370 | 3390 | * is_submodule_active(), since that function needs to find
|
3371 | 3391 | * out the value of "submodule.active" again anyway.
|
3372 | 3392 | */
|
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)) { |
3384 | 3394 | key = xstrfmt("submodule.%s.active", add_data->sm_name);
|
3385 | 3395 | git_config_set_gently(key, "true");
|
3386 | 3396 | free(key);
|
|
0 commit comments