# [PATCH 0/2] submodule: fix handling of unusual submodule names

4 messages from 2026-11-29 to 2026-11-30. Participants: Yoichi NAKAYAMA via GitGitGadget, Ben Knoble.
Thread: https://gitlist.dev/t/66954

## Yoichi NAKAYAMA via GitGitGadget, 2026-11-29 22:02

Subject: [PATCH 0/2] submodule: fix handling of unusual submodule names
Message-ID: <pull.2340.git.1795989773.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/pull.2340.git.1795989773.gitgitgadget%40gmail.com

```
This series fixes issues with unusual submodule names.

The first patch fixes 'git submodule deinit' failing to remove the
configuration section for submodules whose names contain regexp
metacharacters.

The second patch rejects "." as a submodule name in 'git submodule add'.
This avoids a confusing error and prevents an invalid submodule...gitdir
entry from being written to the configuration when
extensions.submodulePathConfig is enabled.

 * [1/2] submodule deinit: handle regexp metacharacters in names
 * [2/2] submodule add: reject "." as submodule name

Yoichi NAKAYAMA (2):
  submodule deinit: handle regexp metacharacters in names
  submodule add: reject "." as submodule name

 builtin/submodule--helper.c | 26 +++++++++++++++++++++++---
 submodule-config.c          |  4 ++--
 t/t7400-submodule-basic.sh  | 28 ++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 5 deletions(-)


base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2340%2Fyoichi%2Fhandle-unusual-submodule-name-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2340/yoichi/handle-unusual-submodule-name-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2340
-- 
gitgitgadget


```

## Yoichi NAKAYAMA via GitGitGadget, 2026-11-29 22:02

Subject: [PATCH 1/2] submodule deinit: handle regexp metacharacters in names
Message-ID: <005c3d4428442e930935341e246d971f0f7883a3.1795989773.git.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/005c3d4428442e930935341e246d971f0f7883a3.1795989773.git.gitgitgadget%40gmail.com
In-Reply-To: <pull.2340.git.1795989773.gitgitgadget@gmail.com>

```
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



```

## Yoichi NAKAYAMA via GitGitGadget, 2026-11-29 22:02

Subject: [PATCH 2/2] submodule add: reject "." as submodule name
Message-ID: <2677cb1cfa506bb1f2f83b0dce952f9a887f66af.1795989773.git.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/2677cb1cfa506bb1f2f83b0dce952f9a887f66af.1795989773.git.gitgitgadget%40gmail.com
In-Reply-To: <pull.2340.git.1795989773.gitgitgadget@gmail.com>

```
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


```

## Ben Knoble, 2026-11-30 13:42

Subject: Re: [PATCH 0/2] submodule: fix handling of unusual submodule names
Message-ID: <370F0F71-B529-4970-8F19-97D6E399DAEC@gmail.com>
URL: https://gitlist.dev/e/370F0F71-B529-4970-8F19-97D6E399DAEC%40gmail.com
In-Reply-To: <pull.2340.git.1795989773.gitgitgadget@gmail.com>

```

> Le 29 nov. 2026 à 17:02, Yoichi NAKAYAMA via GitGitGadget <gitgitgadget@gmail.com> a écrit :
> 
> ﻿This series fixes issues with unusual submodule names.
> 
> The first patch fixes 'git submodule deinit' failing to remove the
> configuration section for submodules whose names contain regexp
> metacharacters.
> 
> The second patch rejects "." as a submodule name in 'git submodule add'.
> This avoids a confusing error and prevents an invalid submodule...gitdir
> entry from being written to the configuration when
> extensions.submodulePathConfig is enabled.
> 
> * [1/2] submodule deinit: handle regexp metacharacters in names
> * [2/2] submodule add: reject "." as submodule name
> 
> Yoichi NAKAYAMA (2):
>  submodule deinit: handle regexp metacharacters in names
>  submodule add: reject "." as submodule name
> 
> builtin/submodule--helper.c | 26 +++++++++++++++++++++++---
> submodule-config.c          |  4 ++--
> t/t7400-submodule-basic.sh  | 28 ++++++++++++++++++++++++++++
> 3 files changed, 53 insertions(+), 5 deletions(-)

I gave this series a quick read, and the comments + code seem
like the right direction to me. A more detailed review is probably warranted,
but I figured a positive ack was better than nothing. 

```
