Commit 17238436 authored by Duy Nguyen's avatar Duy Nguyen

submodule deinit: support multiple worktrees

This is the reverse of 'init' or 'add', config from superproject is
removed from config.worktree (or just config in standard single
worktree setup)
parent d8e680cb
......@@ -1098,6 +1098,8 @@ static void deinit_submodule(const char *path, const char *prefix,
struct strbuf sb_config = STRBUF_INIT;
char *sub_git_dir = xstrfmt("%s/.git", path);
check_multi_worktree_support();
sub = submodule_from_path(the_repository, &null_oid, path);
if (!sub || !sub->name)
......@@ -1153,21 +1155,23 @@ static void deinit_submodule(const char *path, const char *prefix,
displaypath);
cp_config.git_cmd = 1;
argv_array_pushl(&cp_config.args, "config", "--get-regexp", NULL);
argv_array_pushl(&cp_config.args, "config", "--worktree", "--get-regexp", NULL);
argv_array_pushf(&cp_config.args, "submodule.%s\\.", sub->name);
/* remove the .git/config entries (unless the user already did it) */
if (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) {
char *config_file = get_worktree_config(the_repository);
char *sub_key = xstrfmt("submodule.%s", sub->name);
/*
* remove the whole section so we have a clean state when
* the user later decides to init this submodule again
*/
git_config_rename_section_in_file(NULL, sub_key, NULL);
git_config_rename_section_in_file(config_file, sub_key, NULL);
if (!(flags & OPT_QUIET))
printf(_("Submodule '%s' (%s) unregistered for path '%s'\n"),
sub->name, sub->url, displaypath);
free(sub_key);
free(config_file);
}
cleanup:
......
......@@ -118,4 +118,15 @@ test_expect_success 'reset sync submodules' '
git -C secondary submodule sync
'
test_expect_success 'deinit submodules' '
git submodule deinit sub1 &&
git -C secondary submodule deinit sub2 &&
git config --get-regexp "submodule.*" | sort >actual1 &&
test_must_be_empty actual1 &&
test -d .git/modules/sub1 &&
git -C secondary config --get-regexp "submodule.*" | sort >actual2 &&
test_must_be_empty actual2 &&
test -d .git/worktrees/secondary/modules/sub2
'
test_done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment