* [PATCH 1/2] submodule deinit: handle regexp metacharacters in names
2026-11-29 22:02 [PATCH 0/2] submodule: fix handling of unusual submodule names Yoichi NAKAYAMA via GitGitGadget
@ 2026-11-29 22:02 ` Yoichi NAKAYAMA via GitGitGadget
2026-11-29 22:02 ` [PATCH 2/2] submodule add: reject "." as submodule name Yoichi NAKAYAMA via GitGitGadget
2026-11-30 13:42 ` [PATCH 0/2] submodule: fix handling of unusual submodule names Ben Knoble
2 siblings, 0 replies; 4+ messages in thread
From: Yoichi NAKAYAMA via GitGitGadget @ 2026-11-29 22:02 UTC (permalink / raw)
To: git; +Cc: Yoichi NAKAYAMA, Yoichi NAKAYAMA
From: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
'git submodule deinit' internally calls 'git config --get-regexp' to
determine whether the configuration section for the submodule should
be removed. Since the submodule name is included directly in the
regular expression, names containing regexp metacharacters may cause
the `submodule.<name>` section to remain in the configuration after
'git submodule deinit'.
Change the arguments passed to the internal 'git config' call to
retrieve matching configuration keys without including the submodule
name in the regular expression.
Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
---
builtin/submodule--helper.c | 26 +++++++++++++++++++++++---
t/t7400-submodule-basic.sh | 16 ++++++++++++++++
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 461b682d0d..a09afd6630 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1589,6 +1589,8 @@ static void deinit_submodule(const char *path, const char *prefix,
struct child_process cp_config = CHILD_PROCESS_INIT;
struct strbuf sb_config = STRBUF_INIT;
char *sub_git_dir = xstrfmt("%s/.git", path);
+ struct strbuf **names, **ptr;
+ bool found = false;
if (validate_submodule_path(path) < 0)
die(NULL);
@@ -1649,11 +1651,29 @@ static void deinit_submodule(const char *path, const char *prefix,
displaypath);
cp_config.git_cmd = 1;
- strvec_pushl(&cp_config.args, "config", "--get-regexp", NULL);
- strvec_pushf(&cp_config.args, "submodule.%s\\.", sub->name);
+ strvec_pushl(&cp_config.args, "config", "get", "--all", "--show-names",
+ "--name-only", "-z", "--regexp", "submodule\\.", NULL);
/* remove the .git/config entries (unless the user already did it) */
- if (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) {
+ if (capture_command(&cp_config, &sb_config, 0) || !sb_config.len)
+ goto cleanup;
+
+ names = strbuf_split_buf(sb_config.buf, sb_config.len - 1, '\0', 0);
+ for (ptr = names; *ptr; ptr++) {
+ const char *subsection, *key;
+ size_t subsection_len;
+
+ if (!parse_config_key((*ptr)->buf, "submodule",
+ &subsection, &subsection_len, &key) &&
+ subsection_len == strlen(sub->name) &&
+ !strncmp(subsection, sub->name, subsection_len)) {
+ found = true;
+ break;
+ }
+ }
+ strbuf_list_free(names);
+
+ if (found) {
char *sub_key = xstrfmt("submodule.%s", sub->name);
/*
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 345c257829..2b3aff4cb1 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1283,6 +1283,22 @@ test_expect_success 'submodule deinit absorbs .git directory if .git is a direct
test -z "$(git config --get-regexp "submodule\.example\.")"
'
+test_expect_success 'deinit with regexp metacharacters in submodule name' '
+ test_when_finished "rm -rf submodule-name-with-metachar" &&
+ git init submodule-name-with-metachar &&
+ (
+ cd submodule-name-with-metachar &&
+ git submodule add --name "(" "$submodurl" paren &&
+ git submodule add --name "[" "$submodurl" bra &&
+ git submodule add --name "^" "$submodurl" hat &&
+ git submodule add --name "$" "$submodurl" dollar &&
+ git commit -m "add submodules" &&
+ git submodule deinit --all &&
+ (git config --get-regexp "submodule\." || true) >config &&
+ test_must_be_empty config
+ )
+'
+
test_expect_success 'submodule with UTF-8 name' '
svname=$(printf "\303\245 \303\244\303\266") &&
mkdir "$svname" &&
--
gitgitgadget
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] submodule add: reject "." as submodule name
2026-11-29 22:02 [PATCH 0/2] submodule: fix handling of unusual submodule names Yoichi NAKAYAMA via GitGitGadget
2026-11-29 22:02 ` [PATCH 1/2] submodule deinit: handle regexp metacharacters in names Yoichi NAKAYAMA via GitGitGadget
@ 2026-11-29 22:02 ` Yoichi NAKAYAMA via GitGitGadget
2026-11-30 13:42 ` [PATCH 0/2] submodule: fix handling of unusual submodule names Ben Knoble
2 siblings, 0 replies; 4+ messages in thread
From: Yoichi NAKAYAMA via GitGitGadget @ 2026-11-29 22:02 UTC (permalink / raw)
To: git; +Cc: Yoichi NAKAYAMA, Yoichi NAKAYAMA
From: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Specifying "." as the submodule name for 'git submodule add' causes
the command to fail with a confusing error:
fatal: not a git repository: '.git/modules/.'
Additionally, when `extensions.submodulePathConfig` is set to true,
a `submodule...gitdir` entry is written to the configuration.
Reject "." as a submodule name early in 'git submodule add' to avoid
these problems.
Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
---
submodule-config.c | 4 ++--
t/t7400-submodule-basic.sh | 12 ++++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/submodule-config.c b/submodule-config.c
index 37c3be377b..2f4cff0a78 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -214,8 +214,8 @@ static struct submodule *cache_lookup_name(struct submodule_cache *cache,
int check_submodule_name(const char *name)
{
- /* Disallow empty names */
- if (!*name)
+ /* Disallow empty names and "." */
+ if (!*name || !strcmp(name, "."))
return -1;
/*
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 2b3aff4cb1..de474d94b8 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1122,6 +1122,18 @@ test_expect_success 'submodule add with an existing name fails unless forced' '
)
'
+test_expect_success 'submodule add with invalid name fails' '
+ test_when_finished "rm -rf invalid-submodule-name" &&
+ git init invalid-submodule-name &&
+ (
+ cd invalid-submodule-name &&
+ test_must_fail git submodule add --name "." "$submodurl" dot 2>err &&
+ test_grep "not a valid submodule name" err &&
+ (git config --get-regexp "submodule\." || true) >config &&
+ test_must_be_empty config
+ )
+'
+
test_expect_success 'set up a second submodule' '
git submodule add ./init2 example2 &&
git commit -m "submodule example2 added"
--
gitgitgadget
^ permalink raw reply related [flat|nested] 4+ messages in thread