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