git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
From: Nguyễn Thái Ngọc Duy  <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: Stefan Beller <sbeller@google.com>,
	tsniatowski@vewd.com, Jonathan Nieder <jrnieder@gmail.com>,
	marcnarc@xiplink.com, Junio C Hamano <gitster@pobox.com>,
	Nguyễn Thái Ngọc Duy  <pclouds@gmail.com>
Subject: [PATCH 06/10] submodule sync: support multiple worktrees
Date: Wed, 16 Jan 2019 17:31:55 +0700
Message-ID: <20190116103159.9305-7-pclouds@gmail.com> (raw)
In-Reply-To: <20190116103159.9305-1-pclouds@gmail.com>

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/submodule--helper.c    | 12 +++++++-----
 t/t2405-worktree-submodules.sh | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6b749b41fb..288858af83 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -939,6 +939,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;
@@ -979,7 +980,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);
 
@@ -1000,14 +1001,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, path))
+		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;
 
diff --git a/t/t2405-worktree-submodules.sh b/t/t2405-worktree-submodules.sh
index c1b19ad613..55daace672 100755
--- a/t/t2405-worktree-submodules.sh
+++ b/t/t2405-worktree-submodules.sh
@@ -78,4 +78,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
-- 
2.20.0.482.g66447595a7


  parent reply index

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 10:31 [RFC/PATCH 00/10] Support using submodules with worktrees Nguyễn Thái Ngọc Duy
2019-01-16 10:31 ` [PATCH 01/10] doc: about submodule support with multiple worktrees Nguyễn Thái Ngọc Duy
2019-01-16 22:06   ` Stefan Beller
2019-01-17 10:22     ` Duy Nguyen
2019-01-16 10:31 ` [PATCH 02/10] submodule--helper: add missing \n Nguyễn Thái Ngọc Duy
2019-01-16 10:31 ` [PATCH 03/10] submodule add: support multiple worktrees Nguyễn Thái Ngọc Duy
2019-01-16 22:27   ` Stefan Beller
2019-01-16 10:31 ` [PATCH 04/10] submodule init: " Nguyễn Thái Ngọc Duy
2019-01-16 10:31 ` [PATCH 05/10] submodule update: add tests for " Nguyễn Thái Ngọc Duy
2019-01-16 10:31 ` Nguyễn Thái Ngọc Duy [this message]
2019-01-16 10:31 ` [PATCH 07/10] submodule deinit: support " Nguyễn Thái Ngọc Duy
2019-01-16 10:31 ` [PATCH 08/10] submodule clone: use repo_config_set() Nguyễn Thái Ngọc Duy
2019-01-16 10:31 ` [PATCH 09/10] submodule clone: propagate extensions.worktreeConfig Nguyễn Thái Ngọc Duy
2019-01-16 10:31 ` [PATCH 10/10] submodule ensure-core-worktree: write to config.worktree Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190116103159.9305-7-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=marcnarc@xiplink.com \
    --cc=sbeller@google.com \
    --cc=tsniatowski@vewd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox