Git development
 help / color / mirror / Atom feed
From: "Yoichi NAKAYAMA via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>,
	Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Subject: [PATCH 1/2] submodule deinit: handle regexp metacharacters in names
Date: Sun, 29 Nov 2026 22:02:52 +0000	[thread overview]
Message-ID: <005c3d4428442e930935341e246d971f0f7883a3.1795989773.git.gitgitgadget@gmail.com> (raw)
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


  reply	other threads:[~2026-11-29 22:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=005c3d4428442e930935341e246d971f0f7883a3.1795989773.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=yoichi.nakayama@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox