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 2/2] submodule add: reject "." as submodule name
Date: Sun, 29 Nov 2026 22:02:53 +0000 [thread overview]
Message-ID: <2677cb1cfa506bb1f2f83b0dce952f9a887f66af.1795989773.git.gitgitgadget@gmail.com> (raw)
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
next prev parent 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 ` [PATCH 1/2] submodule deinit: handle regexp metacharacters in names Yoichi NAKAYAMA via GitGitGadget
2026-11-29 22:02 ` Yoichi NAKAYAMA via GitGitGadget [this message]
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=2677cb1cfa506bb1f2f83b0dce952f9a887f66af.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.