clone: do not let --depth imply --shallow-submodules

In v2.9.0, we prematurely flipped the default to force cloning submodules shallowly, when the superproject is getting cloned shallowly. This is likely to fail when the upstream repositories submodules are cloned from a repository that is not prepared to serve histories that ends at a commit that is not at the tip of a branch, and we know the world is not yet ready. Use a safer default to clone the submodules fully, unless the user tells us that she knows that the upstream repository of the submodules are willing to cooperate with "--shallow-submodules" option. Noticed-by: Vadim Eisenberg <VADIME@il.ibm.com> Helped-by: Jeff King <peff@peff.net> Helped-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 19, 2016 at 13:51 UTC 18a74a092bff41f1ffe10bd2463d3eed9a04435d
3 files changed +21 -8
Documentation/git-clone.txt
+2 -3
@@ -192,9 +192,8 @@ objects from the source repository into a pack in the cloned repository.
192 Create a 'shallow' clone with a history truncated to the
193 specified number of revisions. Implies `--single-branch` unless
194 `--no-single-branch` is given to fetch the histories near the
195 - tips of all branches. This implies `--shallow-submodules`. If
196 - you want to have a shallow superproject clone, but full submodules,
197 - also pass `--no-shallow-submodules`.
195 + tips of all branches. If you want to clone submodules shallowly,
196 + also pass `--shallow-submodules`.
197
198 --[no-]single-branch::
199 Clone only the history leading to the tip of a single branch,
builtin/clone.c
+2 -3
@@ -40,7 +40,7 @@ static const char * const builtin_clone_usage[] = {
40
41 static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;
42 static int option_local = -1, option_no_hardlinks, option_shared, option_recursive;
43 -static int option_shallow_submodules = -1;
43 +static int option_shallow_submodules;
44 static char *option_template, *option_depth;
45 static char *option_origin = NULL;
46 static char *option_branch = NULL;
@@ -730,8 +730,7 @@ static int checkout(void)
730 struct argv_array args = ARGV_ARRAY_INIT;
731 argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
732
733 - if (option_shallow_submodules == 1
734 - || (option_shallow_submodules == -1 && option_depth))
733 + if (option_shallow_submodules == 1)
734 argv_array_push(&args, "--depth=1");
735
736 if (max_jobs != -1)
t/t5614-clone-submodules.sh
+17 -2
@@ -37,9 +37,9 @@ test_expect_success 'nonshallow clone implies nonshallow submodule' '
37 )
38 '
39
40 -test_expect_success 'shallow clone implies shallow submodule' '
40 +test_expect_success 'shallow clone with shallow submodule' '
41 test_when_finished "rm -rf super_clone" &&
42 - git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&
42 + git clone --recurse-submodules --depth 2 --shallow-submodules "file://$pwd/." super_clone &&
43 (
44 cd super_clone &&
45 git log --oneline >lines &&
@@ -52,6 +52,21 @@ test_expect_success 'shallow clone implies shallow submodule' '
52 )
53 '
54
55 +test_expect_success 'shallow clone does not imply shallow submodule' '
56 + test_when_finished "rm -rf super_clone" &&
57 + git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&
58 + (
59 + cd super_clone &&
60 + git log --oneline >lines &&
61 + test_line_count = 2 lines
62 + ) &&
63 + (
64 + cd super_clone/sub &&
65 + git log --oneline >lines &&
66 + test_line_count = 3 lines
67 + )
68 +'
69 +
70 test_expect_success 'shallow clone with non shallow submodule' '
71 test_when_finished "rm -rf super_clone" &&
72 git clone --recurse-submodules --depth 2 --no-shallow-submodules "file://$pwd/." super_clone &&