From: Yoichi NAKAYAMA <yoic…@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 <yoic…@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