clone: do not let --depth imply --shallow-submodules
authorJunio C Hamano <gitster@pobox.com>
Sun, 19 Jun 2016 20:51:56 +0000 (13:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Jun 2016 18:35:28 +0000 (11:35 -0700)
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>
Documentation/git-clone.txt
builtin/clone.c
t/t5614-clone-submodules.sh
index e1a21b7de176bf7782ee5b3c7346f5a232f2b211..c5a1ce2f59d31ab559b2ffce42ddcbc85d83d319 100644 (file)
@@ -192,9 +192,8 @@ objects from the source repository into a pack in the cloned repository.
        Create a 'shallow' clone with a history truncated to the
        specified number of revisions. Implies `--single-branch` unless
        `--no-single-branch` is given to fetch the histories near the
-       tips of all branches. This implies `--shallow-submodules`. If
-       you want to have a shallow superproject clone, but full submodules,
-       also pass `--no-shallow-submodules`.
+       tips of all branches. If you want to clone submodules shallowly,
+       also pass `--shallow-submodules`.
 
 --[no-]single-branch::
        Clone only the history leading to the tip of a single branch,
index ecdf3080a50103adba0dd1dfcff48bb6efe9f32b..f267742e9e81a4577dfdf87ba80dc1ee424f1bc5 100644 (file)
@@ -40,7 +40,7 @@ static const char * const builtin_clone_usage[] = {
 
 static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;
 static int option_local = -1, option_no_hardlinks, option_shared, option_recursive;
-static int option_shallow_submodules = -1;
+static int option_shallow_submodules;
 static char *option_template, *option_depth;
 static char *option_origin = NULL;
 static char *option_branch = NULL;
@@ -730,8 +730,7 @@ static int checkout(void)
                struct argv_array args = ARGV_ARRAY_INIT;
                argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
 
-               if (option_shallow_submodules == 1
-                   || (option_shallow_submodules == -1 && option_depth))
+               if (option_shallow_submodules == 1)
                        argv_array_push(&args, "--depth=1");
 
                if (max_jobs != -1)
index 62044c5a024726b4411b042789e0d8acfde43718..a9aaa018ed2a09ff0561751923c459454d349cf2 100755 (executable)
@@ -37,9 +37,9 @@ test_expect_success 'nonshallow clone implies nonshallow submodule' '
        )
 '
 
-test_expect_success 'shallow clone implies shallow submodule' '
+test_expect_success 'shallow clone with shallow submodule' '
        test_when_finished "rm -rf super_clone" &&
-       git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&
+       git clone --recurse-submodules --depth 2 --shallow-submodules "file://$pwd/." super_clone &&
        (
                cd super_clone &&
                git log --oneline >lines &&
@@ -52,6 +52,21 @@ test_expect_success 'shallow clone implies shallow submodule' '
        )
 '
 
+test_expect_success 'shallow clone does not imply shallow submodule' '
+       test_when_finished "rm -rf super_clone" &&
+       git clone --recurse-submodules --depth 2 "file://$pwd/." super_clone &&
+       (
+               cd super_clone &&
+               git log --oneline >lines &&
+               test_line_count = 2 lines
+       ) &&
+       (
+               cd super_clone/sub &&
+               git log --oneline >lines &&
+               test_line_count = 3 lines
+       )
+'
+
 test_expect_success 'shallow clone with non shallow submodule' '
        test_when_finished "rm -rf super_clone" &&
        git clone --recurse-submodules --depth 2 --no-shallow-submodules "file://$pwd/." super_clone &&