git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Markus Klein via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Markus Klein <masmiseim@gmx.de>, Markus <masmiseim@gmx.de>
Subject: [PATCH] clone: use submodules.recurse option for automatically clone submodules
Date: Fri, 31 Jan 2020 21:11:31 +0000	[thread overview]
Message-ID: <pull.695.git.git.1580505092071.gitgitgadget@gmail.com> (raw)

From: Markus <masmiseim@gmx.de>

Simplify cloning repositories with submodules when the option
submodules.recurse is set by the user. This makes it transparent to the
user if submodules are used. The user doesn’t have to know if he has to add
an extra parameter to get the full project including the used submodules.
This makes clone behave identical to other commands like fetch, pull,
checkout, ... which include the submodules automatically if this option is
set.

It is implemented analog to the pull command by using an own config
function instead of using just the default config. In contrast to the pull
command, the submodule.recurse state is saved as an array of strings as it
can take an optionally pathspec argument which describes which submodules
should be recursively initialized and cloned. To recursively initialize and
clone all submodules a pathspec of "." has to be used.
The regression test is simplified compared to the test for "git clone
--recursive" as the general functionality is already checked there.

Signed-off-by: Markus Klein <masmiseim@gmx.de>
---
    Add the usage of the submodules.recurse parameter on clone
    
    I try to finish the pullrequest #573 from Maddimax. This adds the usage
    of the submodules.recurse parameter on clone

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-695%2FMasmiseim36%2Fdev%2FCloneWithSubmodule-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-695/Masmiseim36/dev/CloneWithSubmodule-v1
Pull-Request: https://github.com/git/git/pull/695

 builtin/clone.c              | 16 +++++++++++++++-
 t/t7407-submodule-foreach.sh | 11 +++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 0fc89ae2b9..21b9d927a2 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -26,6 +26,8 @@
 #include "dir-iterator.h"
 #include "iterator.h"
 #include "sigchain.h"
+#include "submodule-config.h"
+#include "submodule.h"
 #include "branch.h"
 #include "remote.h"
 #include "run-command.h"
@@ -929,6 +931,18 @@ static int path_exists(const char *path)
 	return !stat(path, &sb);
 }
 
+/**
+ * Read config variables.
+ */
+static int git_clone_config(const char *var, const char *value, void *cb)
+{
+	if (!strcmp(var, "submodule.recurse") && git_config_bool(var, value)) {
+		string_list_append(&option_recurse_submodules, "true");
+		return 0;
+	}
+	return git_default_config(var, value, cb);
+}
+
 int cmd_clone(int argc, const char **argv, const char *prefix)
 {
 	int is_bundle = 0, is_local;
@@ -1103,7 +1117,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 	write_config(&option_config);
 
-	git_config(git_default_config, NULL);
+	git_config(git_clone_config, NULL);
 
 	if (option_bare) {
 		if (option_mirror)
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index 6b2aa917e1..44b32f7b27 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -383,6 +383,17 @@ test_expect_success 'use "update --recursive nested1" to checkout all submodules
 		git rev-parse --resolve-git-dir nested1/nested2/nested3/submodule/.git
 	)
 '
+test_expect_success 'use "git clone" with submodule.recurse=true to checkout all submodules' '
+	git clone -c submodule.recurse=true super clone7 &&
+	(
+		git -C clone7 rev-parse --resolve-git-dir .git --resolve-git-dir nested1/nested2/nested3/submodule/.git >actual &&
+		cat >expect <<-EOF &&
+		.git
+		$(pwd)/clone7/.git/modules/nested1/modules/nested2/modules/nested3/modules/submodule
+		EOF
+		test_cmp expect actual
+	)
+'
 
 test_expect_success 'command passed to foreach retains notion of stdin' '
 	(

base-commit: d0654dc308b0ba76dd8ed7bbb33c8d8f7aacd783
-- 
gitgitgadget

             reply	other threads:[~2020-01-31 21:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31 21:11 Markus Klein via GitGitGadget [this message]
2020-02-01 21:19 ` [PATCH] clone: use submodules.recurse option for automatically clone submodules Johannes Schindelin
2020-02-04 21:32 ` [PATCH v2] " Markus Klein via GitGitGadget
2020-02-05 10:37   ` Johannes Schindelin
2020-02-06 19:03   ` Junio C Hamano
2020-02-07 15:45     ` Johannes Schindelin
2020-02-07 18:17       ` Junio C Hamano
2020-02-07 18:33     ` Junio C Hamano
2020-02-24 22:19     ` AW: " masmiseim
2020-02-24 23:06   ` [PATCH v3] clone: use submodule.recurse " Markus Klein via GitGitGadget
2020-05-01 13:54     ` [PATCH v4] " Markus Klein via GitGitGadget

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=pull.695.git.git.1580505092071.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=masmiseim@gmx.de \
    /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).