git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / 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 03/10] submodule add: support multiple worktrees
Date: Wed, 16 Jan 2019 17:31:52 +0700	[thread overview]
Message-ID: <20190116103159.9305-4-pclouds@gmail.com> (raw)
In-Reply-To: <20190116103159.9305-1-pclouds@gmail.com>

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

'submodule-helper config --check-writable' also checks if it's
supported worktree configuration.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/submodule--helper.c    | 17 +++++++++++++-
 git-submodule.sh               |  8 +++----
 t/t2405-worktree-submodules.sh | 42 ++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 6 deletions(-)
 create mode 100755 t/t2405-worktree-submodules.sh

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 232bfaac7f..7b328ec060 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -18,6 +18,7 @@
 #include "diffcore.h"
 #include "diff.h"
 #include "object-store.h"
+#include "worktree.h"
 
 #define OPT_QUIET (1 << 0)
 #define OPT_CACHED (1 << 1)
@@ -27,6 +28,18 @@
 typedef void (*each_submodule_fn)(const struct cache_entry *list_item,
 				  void *cb_data);
 
+static void check_multi_worktree_support(void)
+{
+	char *worktree_config = get_worktree_config(the_repository);
+	if (!worktree_config)
+		die(_("submodules cannot be used with multiple "
+		      "working trees unless the config\n"
+		      "extension worktreeConfig is enabled. "
+		      "Please read \"CONFIGURATION FILE\"\n"
+		      "section in \"git help worktree\" for details"));
+	free(worktree_config);
+}
+
 static char *get_default_remote(void)
 {
 	char *dest = NULL, *ret;
@@ -2162,8 +2175,10 @@ static int module_config(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, module_config_options,
 			     git_submodule_helper_usage, PARSE_OPT_KEEP_ARGV0);
 
-	if (argc == 1 && command == CHECK_WRITEABLE)
+	if (argc == 1 && command == CHECK_WRITEABLE) {
+		check_multi_worktree_support();
 		return is_writing_gitmodules_ok() ? 0 : -1;
+	}
 
 	/* Equivalent to ACTION_GET in builtin/config.c */
 	if (argc == 2)
diff --git a/git-submodule.sh b/git-submodule.sh
index 5e608f8bad..695939eff9 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -288,7 +288,7 @@ or you are unsure what this means choose another name with the '--name' option."
 			esac
 		) || die "$(eval_gettext "Unable to checkout submodule '\$sm_path'")"
 	fi
-	git config submodule."$sm_name".url "$realrepo"
+	git config --worktree submodule."$sm_name".url "$realrepo"
 
 	git add --no-warn-embedded-repo $force "$sm_path" ||
 	die "$(eval_gettext "Failed to add submodule '\$sm_path'")"
@@ -302,18 +302,16 @@ or you are unsure what this means choose another name with the '--name' option."
 	git add --force .gitmodules ||
 	die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
 
-	# NEEDSWORK: In a multi-working-tree world, this needs to be
-	# set in the per-worktree config.
 	if git config --get submodule.active >/dev/null
 	then
 		# If the submodule being adding isn't already covered by the
 		# current configured pathspec, set the submodule's active flag
 		if ! git submodule--helper is-active "$sm_path"
 		then
-			git config submodule."$sm_name".active "true"
+			git config --worktree submodule."$sm_name".active "true"
 		fi
 	else
-		git config submodule."$sm_name".active "true"
+		git config --worktree submodule."$sm_name".active "true"
 	fi
 }
 
diff --git a/t/t2405-worktree-submodules.sh b/t/t2405-worktree-submodules.sh
new file mode 100755
index 0000000000..3ee5380e88
--- /dev/null
+++ b/t/t2405-worktree-submodules.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+test_description='multiple worktrees as superprojects'
+
+. ./test-lib.sh
+
+test_expect_success 'set up submodule source' '
+	test_create_repo submodsrc &&
+	(
+		cd submodsrc &&
+		test_commit one
+	) &&
+	test_commit initial &&
+	git worktree add -b secondary secondary HEAD &&
+	git config extensions.worktreeConfig true
+'
+
+test_expect_success 'add submodules' '
+	SRC="$(pwd)/submodsrc" &&
+	git submodule add "$SRC" sub1 &&
+	git commit -m sub1 &&
+	git -C secondary submodule add "$SRC" sub2 &&
+	git -C secondary commit -m sub2 &&
+
+	git config --get-regexp "submodule.*" | sort >actual1 &&
+	cat >expected1 <<-EOF &&
+	submodule.sub1.active true
+	submodule.sub1.url $(pwd)/submodsrc
+	EOF
+	test_cmp expected1 actual1 &&
+	test -d .git/modules/sub1 &&
+
+	git -C secondary config --get-regexp "submodule.*" | sort >actual2 &&
+	cat >expected2 <<-EOF &&
+	submodule.sub2.active true
+	submodule.sub2.url $(pwd)/submodsrc
+	EOF
+	test_cmp expected2 actual2 &&
+	test -d .git/worktrees/secondary/modules/sub2
+'
+
+test_done
-- 
2.20.0.482.g66447595a7


  parent reply	other threads:[~2019-01-16 10:32 UTC|newest]

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 ` Nguyễn Thái Ngọc Duy [this message]
2019-01-16 22:27   ` [PATCH 03/10] submodule add: support multiple worktrees 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 ` [PATCH 06/10] submodule sync: support " Nguyễn Thái Ngọc Duy
2019-01-16 10:31 ` [PATCH 07/10] submodule deinit: " 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 publicly 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-4-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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).