git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] clone: no-shallow-submodules clone overrides option in gitmodules

From
BGBruce Perry via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 2, 2024, 19:07 UTC
Message-ID
<1679ab7b7a0db40733ad60ada8b226657782d33e.1719947271.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1740.git.git.1719947271.gitgitgadget@gmail.com>
From: Bruce Perry <bruce.perry@nrel.gov>

When the `--no-shallow-submodules` option is used for cloning, pass the `--no-recommend-shallow` option to the internal submodule update command, which will override an option for shallow in .gitmodules if present. This allows the user to force a non-shallow clone of the submodules if desired. It brings the behavior in line with the present documentation, which states the option in gitmodules is used unless explitcitly overridden by the user. Add a test to confirm that the override is done when using the clone command (similar to a current test that validates similar behavior for the submodule update command).

Signed-off-by: Bruce Perry <bruce.perry@nrel.gov>
---
 builtin/clone.c                     |  4 +++-
 t/t5614-clone-submodules-shallow.sh | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 50ccce8902d..63cfb48484c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -61,7 +61,7 @@ static int option_no_checkout, option_bare, option_mirror, option_single_branch
 static int option_single_branch_submodules;
 static int option_local = -1, option_no_hardlinks, option_shared;
 static int option_no_tags;
-static int option_shallow_submodules;
+static int option_shallow_submodules = -1;
 static int option_reject_shallow = -1;    /* unspecified */
 static int config_reject_shallow = -1;    /* unspecified */
 static int deepen;
@@ -798,6 +798,8 @@ static int checkout(int submodule_progress, int filter_submodules)
 
 		if (option_shallow_submodules == 1)
 			strvec_push(&cmd.args, "--depth=1");
+		else if (option_shallow_submodules == 0)
+			strvec_push(&cmd.args, "--no-recommend-shallow");
 
 		if (max_jobs != -1)
 			strvec_pushf(&cmd.args, "--jobs=%d", max_jobs);
diff --git a/t/t5614-clone-submodules-shallow.sh b/t/t5614-clone-submodules-shallow.sh
index b23c7d085aa..8e2965248a2 100755
--- a/t/t5614-clone-submodules-shallow.sh
+++ b/t/t5614-clone-submodules-shallow.sh
@@ -102,6 +102,22 @@ test_expect_success 'clone follows shallow recommendation' '
 	)
 '
 
+test_expect_success 'no-shallow-submodules clone option overrides gitmodules' '
+	test_when_finished "rm -rf super_clone" &&
+	test_config_global protocol.file.allow always &&
+	git clone --recurse-submodules --no-shallow-submodules --no-local "file://$pwd/." super_clone &&
+	(
+		cd super_clone &&
+		git log --oneline >lines &&
+		test_line_count = 4 lines
+	) &&
+	(
+		cd super_clone/sub &&
+		git log --oneline --all >lines &&
+		test_line_count = 5 lines
+	)
+'
+
 test_expect_success 'get unshallow recommended shallow submodule' '
 	test_when_finished "rm -rf super_clone" &&
 	test_config_global protocol.file.allow always &&
-- 
gitgitgadget
Previous: Bruce Perry via GitGitGadgetNext: rsbecker@nexbridge.com
Message 3 of 7 in “clone: shallow-submodules should be single-branch by default”
  1. 0/2 clone: shallow-submodules should be single-branch by defaultBruce Perry via GitGitGadget, Jul 2, 2024
  2. 1/2 clone: shallow-submodules should be single-branch by defaultBruce Perry via GitGitGadget, Jul 2, 2024
  3. 2/2 clone: no-shallow-submodules clone overrides option in gitmodulesBruce Perry via GitGitGadget, Jul 2, 2024
  4. rsbecker@nexbridge.comJul 2, 2024
  5. Bruce PerryJul 3, 2024
  6. rsbecker@nexbridge.comJul 3, 2024
  7. Bruce PerryJul 25, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.