Commit d8e680cb authored by Duy Nguyen's avatar Duy Nguyen

submodule sync: support multiple worktrees

Both submodule.*.url and remote.*.url are stored per-worktree. If the
remote key is already there (and shared) it will be overriden. We don't
want to change the shared value because that might affect other
worktrees.
parent da0740ea
......@@ -940,6 +940,7 @@ static void sync_submodule(const char *path, const char *prefix,
struct strbuf sb = STRBUF_INIT;
struct child_process cp = CHILD_PROCESS_INIT;
char *sub_config_path = NULL;
struct repository subrepo;
if (!is_submodule_active(the_repository, path))
return;
......@@ -980,7 +981,7 @@ static void sync_submodule(const char *path, const char *prefix,
strbuf_reset(&sb);
strbuf_addf(&sb, "submodule.%s.url", sub->name);
if (git_config_set_gently(sb.buf, super_config_url))
if (repo_config_set_worktree_gently(the_repository, sb.buf, super_config_url))
die(_("failed to register url for submodule path '%s'"),
displaypath);
......@@ -1001,14 +1002,15 @@ static void sync_submodule(const char *path, const char *prefix,
strbuf_strip_suffix(&sb, "\n");
remote_key = xstrfmt("remote.%s.url", sb.buf);
strbuf_reset(&sb);
submodule_to_gitdir(&sb, path);
strbuf_addstr(&sb, "/config");
if (repo_submodule_init(&subrepo, the_repository, sub))
die(_("could not get a repository handle for submodule '%s'"), path);
if (git_config_set_in_file_gently(sb.buf, remote_key, sub_origin_url))
if (repo_config_set_worktree_gently(&subrepo, remote_key, sub_origin_url))
die(_("failed to update remote for submodule '%s'"),
path);
repo_clear(&subrepo);
if (flags & OPT_RECURSIVE) {
struct child_process cpr = CHILD_PROCESS_INIT;
......
......@@ -85,4 +85,37 @@ test_expect_success 'update submodules' '
test -d cloned/.git/worktrees/secondary/modules/sub2
'
test_expect_success 'sync submodules' '
sed s/submodsrc/crsdombus/ .gitmodules >temp &&
mv temp .gitmodules &&
git submodule sync &&
(
cd secondary &&
sed s/submodsrc/crsdombus/ .gitmodules >temp &&
mv temp .gitmodules &&
git submodule sync
) &&
git config --get-regexp "submodule.*" | sort >actual1 &&
cat >expected1 <<-EOF &&
submodule.sub1.active true
submodule.sub1.url $(pwd)/crsdombus
EOF
test_cmp expected1 actual1 &&
git -C secondary config --get-regexp "submodule.*" | sort >actual2 &&
cat >expected2 <<-EOF &&
submodule.sub2.active true
submodule.sub2.url $(pwd)/crsdombus
EOF
test_cmp expected2 actual2
'
test_expect_success 'reset sync submodules' '
git checkout -- .gitmodules &&
git submodule sync &&
git -C secondary checkout -- .gitmodules &&
git -C secondary submodule sync
'
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