git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] submodule add: reject "." as submodule name

From
Yoichi NAKAYAMA via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 29, 2026, 22:02 UTC
Message-ID
<2677cb1cfa506bb1f2f83b0dce952f9a887f66af.1795989773.git.gitgitgadget@gmail.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
Previous: Yoichi NAKAYAMA via GitGitGadgetNext: Ben Knoble
Message 3 of 4 in “submodule: fix handling of unusual submodule names”
  1. 0/2 submodule: fix handling of unusual submodule namesYoichi NAKAYAMA via GitGitGadget, Nov 29, 2026
  2. 1/2 submodule deinit: handle regexp metacharacters in namesYoichi NAKAYAMA via GitGitGadget, Nov 29, 2026
  3. 2/2 submodule add: reject "." as submodule nameYoichi NAKAYAMA via GitGitGadget, Nov 29, 2026
  4. Ben KnobleNov 30, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.