{"thread":{"id":"66954","subject":"[PATCH 0/2] submodule: fix handling of unusual submodule names","startedAt":"2026-11-29T22:02:51Z","lastAt":"2026-11-30T13:42:20Z","messageCount":4,"participants":["Yoichi NAKAYAMA via GitGitGadget","Ben Knoble"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"559655","messageId":"pull.2340.git.1795989773.gitgitgadget@gmail.com","threadId":"66954","inReplyTo":null,"subject":"[PATCH 0/2] submodule: fix handling of unusual submodule names","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-29T22:02:51Z","receivedAt":"2026-11-29T22:02:51Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"This series fixes issues with unusual submodule names.\n\nThe first patch fixes 'git submodule deinit' failing to remove the\nconfiguration section for submodules whose names contain regexp\nmetacharacters.\n\nThe second patch rejects \".\" as a submodule name in 'git submodule add'.\nThis avoids a confusing error and prevents an invalid submodule...gitdir\nentry from being written to the configuration when\nextensions.submodulePathConfig is enabled.\n\n * [1/2] submodule deinit: handle regexp metacharacters in names\n * [2/2] submodule add: reject \".\" as submodule name\n\nYoichi NAKAYAMA (2):\n  submodule deinit: handle regexp metacharacters in names\n  submodule add: reject \".\" as submodule name\n\n builtin/submodule--helper.c | 26 +++++++++++++++++++++++---\n submodule-config.c          |  4 ++--\n t/t7400-submodule-basic.sh  | 28 ++++++++++++++++++++++++++++\n 3 files changed, 53 insertions(+), 5 deletions(-)\n\n\nbase-commit: acba8bf9753134d9bde89f94369f775838a8c5fe\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2340%2Fyoichi%2Fhandle-unusual-submodule-name-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2340/yoichi/handle-unusual-submodule-name-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2340\n-- \ngitgitgadget\n\n"},{"id":"559656","messageId":"005c3d4428442e930935341e246d971f0f7883a3.1795989773.git.gitgitgadget@gmail.com","threadId":"66954","inReplyTo":"pull.2340.git.1795989773.gitgitgadget@gmail.com","subject":"[PATCH 1/2] submodule deinit: handle regexp metacharacters in names","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-29T22:02:52Z","receivedAt":"2026-11-29T22:02:52Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>\n\n'git submodule deinit' internally calls 'git config --get-regexp' to\ndetermine whether the configuration section for the submodule should\nbe removed. Since the submodule name is included directly in the\nregular expression, names containing regexp metacharacters may cause\nthe `submodule.<name>` section to remain in the configuration after\n'git submodule deinit'.\n\nChange the arguments passed to the internal 'git config' call to\nretrieve matching configuration keys without including the submodule\nname in the regular expression.\n\nSigned-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>\n---\n builtin/submodule--helper.c | 26 +++++++++++++++++++++++---\n t/t7400-submodule-basic.sh  | 16 ++++++++++++++++\n 2 files changed, 39 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 461b682d0d..a09afd6630 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1589,6 +1589,8 @@ static void deinit_submodule(const char *path, const char *prefix,\n \tstruct child_process cp_config = CHILD_PROCESS_INIT;\n \tstruct strbuf sb_config = STRBUF_INIT;\n \tchar *sub_git_dir = xstrfmt(\"%s/.git\", path);\n+\tstruct strbuf **names, **ptr;\n+\tbool found = false;\n \n \tif (validate_submodule_path(path) < 0)\n \t\tdie(NULL);\n@@ -1649,11 +1651,29 @@ static void deinit_submodule(const char *path, const char *prefix,\n \t\t      displaypath);\n \n \tcp_config.git_cmd = 1;\n-\tstrvec_pushl(&cp_config.args, \"config\", \"--get-regexp\", NULL);\n-\tstrvec_pushf(&cp_config.args, \"submodule.%s\\\\.\", sub->name);\n+\tstrvec_pushl(&cp_config.args, \"config\", \"get\", \"--all\", \"--show-names\",\n+\t\t     \"--name-only\", \"-z\", \"--regexp\", \"submodule\\\\.\", NULL);\n \n \t/* remove the .git/config entries (unless the user already did it) */\n-\tif (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) {\n+\tif (capture_command(&cp_config, &sb_config, 0) || !sb_config.len)\n+\t\tgoto cleanup;\n+\n+\tnames = strbuf_split_buf(sb_config.buf, sb_config.len - 1, '\\0', 0);\n+\tfor (ptr = names; *ptr; ptr++) {\n+\t\tconst char *subsection, *key;\n+\t\tsize_t subsection_len;\n+\n+\t\tif (!parse_config_key((*ptr)->buf, \"submodule\",\n+\t\t\t\t      &subsection, &subsection_len, &key) &&\n+\t\t    subsection_len == strlen(sub->name) &&\n+\t\t    !strncmp(subsection, sub->name, subsection_len)) {\n+\t\t\tfound = true;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tstrbuf_list_free(names);\n+\n+\tif (found) {\n \t\tchar *sub_key = xstrfmt(\"submodule.%s\", sub->name);\n \n \t\t/*\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 345c257829..2b3aff4cb1 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -1283,6 +1283,22 @@ test_expect_success 'submodule deinit absorbs .git directory if .git is a direct\n \ttest -z \"$(git config --get-regexp \"submodule\\.example\\.\")\"\n '\n \n+test_expect_success 'deinit with regexp metacharacters in submodule name' '\n+\ttest_when_finished \"rm -rf submodule-name-with-metachar\" &&\n+\tgit init submodule-name-with-metachar &&\n+\t(\n+\t\tcd submodule-name-with-metachar &&\n+\t\tgit submodule add --name \"(\" \"$submodurl\" paren &&\n+\t\tgit submodule add --name \"[\" \"$submodurl\" bra &&\n+\t\tgit submodule add --name \"^\" \"$submodurl\" hat &&\n+\t\tgit submodule add --name \"$\" \"$submodurl\" dollar &&\n+\t\tgit commit -m \"add submodules\" &&\n+\t\tgit submodule deinit --all &&\n+\t\t(git config --get-regexp \"submodule\\.\" || true) >config &&\n+\t\ttest_must_be_empty config\n+\t)\n+'\n+\n test_expect_success 'submodule with UTF-8 name' '\n \tsvname=$(printf \"\\303\\245 \\303\\244\\303\\266\") &&\n \tmkdir \"$svname\" &&\n-- \ngitgitgadget\n\n\n"},{"id":"559657","messageId":"2677cb1cfa506bb1f2f83b0dce952f9a887f66af.1795989773.git.gitgitgadget@gmail.com","threadId":"66954","inReplyTo":"pull.2340.git.1795989773.gitgitgadget@gmail.com","subject":"[PATCH 2/2] submodule add: reject \".\" as submodule name","fromName":"Yoichi NAKAYAMA via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-29T22:02:53Z","receivedAt":"2026-11-29T22:02:53Z","isPatch":true,"sender":{"key":"yoichi.nakayama@gmail.com","avatar":"https://avatars.githubusercontent.com/u/107537?v=4"},"body":"From: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>\n\nSpecifying \".\" as the submodule name for 'git submodule add' causes\nthe command to fail with a confusing error:\n    fatal: not a git repository: '.git/modules/.'\n\nAdditionally, when `extensions.submodulePathConfig` is set to true,\na `submodule...gitdir` entry is written to the configuration.\n\nReject \".\" as a submodule name early in 'git submodule add' to avoid\nthese problems.\n\nSigned-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>\n---\n submodule-config.c         |  4 ++--\n t/t7400-submodule-basic.sh | 12 ++++++++++++\n 2 files changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/submodule-config.c b/submodule-config.c\nindex 37c3be377b..2f4cff0a78 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -214,8 +214,8 @@ static struct submodule *cache_lookup_name(struct submodule_cache *cache,\n \n int check_submodule_name(const char *name)\n {\n-\t/* Disallow empty names */\n-\tif (!*name)\n+\t/* Disallow empty names and \".\" */\n+\tif (!*name || !strcmp(name, \".\"))\n \t\treturn -1;\n \n \t/*\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 2b3aff4cb1..de474d94b8 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -1122,6 +1122,18 @@ test_expect_success 'submodule add with an existing name fails unless forced' '\n \t)\n '\n \n+test_expect_success 'submodule add with invalid name fails' '\n+\ttest_when_finished \"rm -rf invalid-submodule-name\" &&\n+\tgit init invalid-submodule-name &&\n+\t(\n+\t\tcd invalid-submodule-name &&\n+\t\ttest_must_fail git submodule add --name \".\" \"$submodurl\" dot 2>err &&\n+\t\ttest_grep \"not a valid submodule name\" err &&\n+\t\t(git config --get-regexp \"submodule\\.\" || true) >config &&\n+\t\ttest_must_be_empty config\n+\t)\n+'\n+\n test_expect_success 'set up a second submodule' '\n \tgit submodule add ./init2 example2 &&\n \tgit commit -m \"submodule example2 added\"\n-- \ngitgitgadget\n\n"},{"id":"559678","messageId":"370F0F71-B529-4970-8F19-97D6E399DAEC@gmail.com","threadId":"66954","inReplyTo":"pull.2340.git.1795989773.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/2] submodule: fix handling of unusual submodule names","fromName":"Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-11-30T13:42:20Z","receivedAt":"2026-11-30T13:42:20Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"\n> Le 29 nov. 2026 à 17:02, Yoichi NAKAYAMA via GitGitGadget <gitgitgadget@gmail.com> a écrit :\n> \n> ﻿This series fixes issues with unusual submodule names.\n> \n> The first patch fixes 'git submodule deinit' failing to remove the\n> configuration section for submodules whose names contain regexp\n> metacharacters.\n> \n> The second patch rejects \".\" as a submodule name in 'git submodule add'.\n> This avoids a confusing error and prevents an invalid submodule...gitdir\n> entry from being written to the configuration when\n> extensions.submodulePathConfig is enabled.\n> \n> * [1/2] submodule deinit: handle regexp metacharacters in names\n> * [2/2] submodule add: reject \".\" as submodule name\n> \n> Yoichi NAKAYAMA (2):\n>  submodule deinit: handle regexp metacharacters in names\n>  submodule add: reject \".\" as submodule name\n> \n> builtin/submodule--helper.c | 26 +++++++++++++++++++++++---\n> submodule-config.c          |  4 ++--\n> t/t7400-submodule-basic.sh  | 28 ++++++++++++++++++++++++++++\n> 3 files changed, 53 insertions(+), 5 deletions(-)\n\nI gave this series a quick read, and the comments + code seem\nlike the right direction to me. A more detailed review is probably warranted,\nbut I figured a positive ack was better than nothing. \n"}]}