Commit 3d3144ec authored by Duy Nguyen's avatar Duy Nguyen

submodule init: support multiple worktrees

The entire submodule section in the superproject will be per-worktree
and written to $GIT_DIR/config.worktree.

The behavior when you only have one worktree (and not enabled
extensions.worktreeConfig) is the same as before, everything is still
written in $GIT_DIR/config
parent 8c0f59ed
......@@ -640,15 +640,11 @@ static void init_submodule(const char *path, const char *prefix,
die(_("No url found for submodule path '%s' in .gitmodules"),
* NEEDSWORK: In a multi-working-tree world, this needs to be
* set in the per-worktree config.
* Set active flag for the submodule being initialized
if (!is_submodule_active(the_repository, path)) {
strbuf_addf(&sb, "", sub->name);
git_config_set_gently(sb.buf, "true");
repo_config_set_worktree_gently(the_repository, sb.buf, "true");
......@@ -673,7 +669,7 @@ static void init_submodule(const char *path, const char *prefix,
if (git_config_set_gently(sb.buf, url))
if (repo_config_set_worktree_gently(the_repository, sb.buf, url))
die(_("Failed to register url for submodule path '%s'"),
if (!(flags & OPT_QUIET))
......@@ -694,7 +690,7 @@ static void init_submodule(const char *path, const char *prefix,
} else
upd = xstrdup(submodule_strategy_to_string(&sub->update_strategy));
if (git_config_set_gently(sb.buf, upd))
if (repo_config_set_worktree_gently(the_repository, sb.buf, upd))
die(_("Failed to register update mode for submodule path '%s'"), displaypath);
......@@ -46,4 +46,32 @@ test_expect_success 'add submodules on unsupported setup' '
test_must_fail git submodule add "$SRC" sub2
test_expect_success 'init submodules' '
git clone --no-local .git cloned &&
cd cloned &&
git config extensions.worktreeConfig true &&
git submodule init sub1 &&
git worktree add secondary origin/secondary &&
cd secondary &&
git submodule init sub2
) &&
git -C cloned config --get-regexp "submodule.*" | sort >actual1 &&
cat >expected1 <<-EOF && true
submodule.sub1.url $(pwd)/submodsrc
test_cmp expected1 actual1 &&
! test -d cloned/.git/modules/sub1 &&
git -C cloned/secondary config --get-regexp "submodule.*" | sort >actual2 &&
cat >expected2 <<-EOF && true
submodule.sub2.url $(pwd)/submodsrc
test_cmp expected2 actual2 &&
! test -d cloned/.git/worktrees/secondary/modules/sub2
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