diff mbox series

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

Message ID 1679ab7b7a0db40733ad60ada8b226657782d33e.1719947271.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series clone: shallow-submodules should be single-branch by default | expand

Commit Message

Bruce Perry July 2, 2024, 7:07 p.m. UTC
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 mbox series

Patch

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 &&