{"thread":{"id":"41701","subject":"[PATCH 1/3] clone: add `--shallow-submodules` flag","startedAt":"2016-03-16T01:12:14Z","lastAt":"2016-04-25T17:26:11Z","messageCount":6,"participants":["Stefan Beller","Lars Schneider"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"280867","messageId":"1458090737-14030-1-git-send-email-sbeller@google.com","threadId":"41701","inReplyTo":null,"subject":"[PATCH 0/3] Towards sane shallow clones with submodules","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-03-16T01:12:14Z","receivedAt":"2016-03-16T01:12:14Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"This is a first real series following the RFC-y $gmane/288720.\n\nFor using submodules as they are now, I would imagine this is a strict\nimprovement.  See the tests in last patch to see what a workflow would\nlook like.\n\nThanks,\nStefan\n\nStefan Beller (3):\n  clone: add `--shallow-submodules` flag\n  submodule clone: pass along `local` option\n  clone: Add t5614 to test cloning submodules with shallowness involved\n\n Documentation/git-clone.txt | 13 +++++--\n builtin/clone.c             | 21 ++++++++++++\n builtin/submodule--helper.c | 22 ++++++++++--\n git-submodule.sh            |  7 ++++\n t/t5614-clone-submodules.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++\n 5 files changed, 139 insertions(+), 6 deletions(-)\n create mode 100755 t/t5614-clone-submodules.sh\n\n-- \n2.7.0.rc0.42.g8e9204f.dirty\n"},{"id":"280865","messageId":"1458090737-14030-2-git-send-email-sbeller@google.com","threadId":"41701","inReplyTo":"1458090737-14030-1-git-send-email-sbeller@google.com","subject":"[PATCH 1/3] clone: add `--shallow-submodules` flag","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-03-16T01:12:15Z","receivedAt":"2016-03-16T01:12:15Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"When creating a shallow clone of a repository with submodules, the depth\nargument does not influence the submodules, i.e. the submodules are done\nas non-shallow clones. It is unclear what the best default is for the\ndepth of submodules of a shallow clone, so we need to have the possibility\nto do all kinds of combinations:\n\n* shallow super project with shallow submodules\n  e.g. build bots starting always from scratch. They want to transmit\n  the least amount of network data as well as using the least amount\n  of space on their hard drive.\n* shallow super project with unshallow submodules\n  e.g. The superproject is just there to track a collection of repositories\n  and it is not important to have the relationship between the repositories\n  intact. However the history of the individual submodules matter.\n* unshallow super project with shallow submodules\n  e.g. The superproject is the actual project and the submodule is a\n  library which is rarely touched.\n\nThe new switch to select submodules to be shallow or unshallow supports\nall of these three cases.\n\nIt is easy to transition from the first to the second case by just\nunshallowing the submodules (`git submodule foreach git fetch\n--unshallow`), but it is not possible to transition from the second to the\nfirst case (as we wouldd have already transmitted the non shallow over\nthe network). That is why we want to make the first case the default in\ncase of a shallow super project. This leads to the inconvenience in the\nsecond case with the shallow super project and unshallow submodules,\nas you need to pass `--no-shallow-submodules`.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n Documentation/git-clone.txt | 13 ++++++++++---\n builtin/clone.c             |  7 +++++++\n 2 files changed, 17 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt\nindex 6db7b6d..20a4577 100644\n--- a/Documentation/git-clone.txt\n+++ b/Documentation/git-clone.txt\n@@ -14,8 +14,8 @@ SYNOPSIS\n \t  [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]\n \t  [--dissociate] [--separate-git-dir <git dir>]\n \t  [--depth <depth>] [--[no-]single-branch]\n-\t  [--recursive | --recurse-submodules] [--jobs <n>] [--] <repository>\n-\t  [<directory>]\n+\t  [--recursive | --recurse-submodules] [--[no-]shallow-submodules]\n+\t  [--jobs <n>] [--] <repository> [<directory>]\n \n DESCRIPTION\n -----------\n@@ -190,7 +190,11 @@ objects from the source repository into a pack in the cloned repository.\n \n --depth <depth>::\n \tCreate a 'shallow' clone with a history truncated to the\n-\tspecified number of revisions.\n+\tspecified number of revisions. Implies `--single-branch` unless\n+\t`--no-single-branch` is given to fetch the histories near the\n+\ttips of all branches. This implies `--shallow-submodules`. If\n+\tyou want to have a shallow clone, but full submodules, also pass\n+\t`--no-shallow-submodules`.\n \n --[no-]single-branch::\n \tClone only the history leading to the tip of a single branch,\n@@ -214,6 +218,9 @@ objects from the source repository into a pack in the cloned repository.\n \trepository does not have a worktree/checkout (i.e. if any of\n \t`--no-checkout`/`-n`, `--bare`, or `--mirror` is given)\n \n+--shallow-submodules::\n+\tAll submodules which are cloned, will be shallow.\n+\n --separate-git-dir=<git dir>::\n \tInstead of placing the cloned repository where it is supposed\n \tto be, place the cloned repository at the specified directory,\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex b004fb4..ecdf308 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -40,6 +40,7 @@ static const char * const builtin_clone_usage[] = {\n \n static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;\n static int option_local = -1, option_no_hardlinks, option_shared, option_recursive;\n+static int option_shallow_submodules = -1;\n static char *option_template, *option_depth;\n static char *option_origin = NULL;\n static char *option_branch = NULL;\n@@ -91,6 +92,8 @@ static struct option builtin_clone_options[] = {\n \t\t    N_(\"create a shallow clone of that depth\")),\n \tOPT_BOOL(0, \"single-branch\", &option_single_branch,\n \t\t    N_(\"clone only one branch, HEAD or --branch\")),\n+\tOPT_BOOL(0, \"shallow-submodules\", &option_shallow_submodules,\n+\t\t    N_(\"any cloned submodules will be shallow\")),\n \tOPT_STRING(0, \"separate-git-dir\", &real_git_dir, N_(\"gitdir\"),\n \t\t   N_(\"separate git dir from working tree\")),\n \tOPT_STRING_LIST('c', \"config\", &option_config, N_(\"key=value\"),\n@@ -727,6 +730,10 @@ static int checkout(void)\n \t\tstruct argv_array args = ARGV_ARRAY_INIT;\n \t\targv_array_pushl(&args, \"submodule\", \"update\", \"--init\", \"--recursive\", NULL);\n \n+\t\tif (option_shallow_submodules == 1\n+\t\t    || (option_shallow_submodules == -1 && option_depth))\n+\t\t\targv_array_push(&args, \"--depth=1\");\n+\n \t\tif (max_jobs != -1)\n \t\t\targv_array_pushf(&args, \"--jobs=%d\", max_jobs);\n \n-- \n2.7.0.rc0.42.g8e9204f.dirty\n"},{"id":"280866","messageId":"1458090737-14030-3-git-send-email-sbeller@google.com","threadId":"41701","inReplyTo":"1458090737-14030-1-git-send-email-sbeller@google.com","subject":"[PATCH 2/3] submodule clone: pass along `local` option","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-03-16T01:12:16Z","receivedAt":"2016-03-16T01:12:16Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"When cloning a local repository, the user may choose to use an optimization\nsuch that the transfer uses a Git agnostic protocol. Propagate the users\nchoice to submodules or if they don't choose, propagate nothing.\nA test will be added in a later patch.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n\nNotes:\n        Alternative commit message:\n        When writing tests (as they appear in a later patch), I was forced to make\n        a decision: Either use the file:// protocol and pretend like I never run\n        into problems using the local option when writing tests, or support the\n        local option as a first class citizen and give it some test coverage in\n        combination with the shallow clones. I choose the later as for the\n        file:// protocol I would have needed to muck around with path names.\n        c.f. $gmane/282779\n\n builtin/clone.c             | 14 ++++++++++++++\n builtin/submodule--helper.c | 22 +++++++++++++++++++---\n git-submodule.sh            |  7 +++++++\n 3 files changed, 40 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex ecdf308..0980386 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -734,6 +734,20 @@ static int checkout(void)\n \t\t    || (option_shallow_submodules == -1 && option_depth))\n \t\t\targv_array_push(&args, \"--depth=1\");\n \n+\t\tswitch (option_local) {\n+\t\tcase 1:\n+\t\t\targv_array_push(&args, \"--local\");\n+\t\t\tbreak;\n+\t\tcase 0:\n+\t\t\targv_array_push(&args, \"--no-local\");\n+\t\t\tbreak;\n+\t\tcase -1:\n+\t\t\t/* pass nothing */\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tdie(\"BUG: option_local out of range\");\n+\t\t}\n+\n \t\tif (max_jobs != -1)\n \t\t\targv_array_pushf(&args, \"--jobs=%d\", max_jobs);\n \ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex a484945..822ec69 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -125,7 +125,8 @@ static int module_name(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n static int clone_submodule(const char *path, const char *gitdir, const char *url,\n-\t\t\t   const char *depth, const char *reference, int quiet)\n+\t\t\t   const char *depth, const char *reference, int quiet,\n+\t\t\t   int local)\n {\n \tstruct child_process cp;\n \tchild_process_init(&cp);\n@@ -140,6 +141,10 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url\n \t\targv_array_pushl(&cp.args, \"--reference\", reference, NULL);\n \tif (gitdir && *gitdir)\n \t\targv_array_pushl(&cp.args, \"--separate-git-dir\", gitdir, NULL);\n+\tif (local == 1)\n+\t\targv_array_push(&cp.args, \"--local\");\n+\telse if (!local)\n+\t\targv_array_push(&cp.args, \"--no-local\");\n \n \targv_array_push(&cp.args, url);\n \targv_array_push(&cp.args, path);\n@@ -156,6 +161,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \tconst char *path = NULL, *name = NULL, *url = NULL;\n \tconst char *reference = NULL, *depth = NULL;\n \tint quiet = 0;\n+\tint local = -1;\n \tFILE *submodule_dot_git;\n \tchar *sm_gitdir, *cwd, *p;\n \tstruct strbuf rel_path = STRBUF_INIT;\n@@ -180,6 +186,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \t\tOPT_STRING(0, \"depth\", &depth,\n \t\t\t   N_(\"string\"),\n \t\t\t   N_(\"depth for shallow clones\")),\n+\t\tOPT_BOOL(0, \"local\", &local,\n+\t\t\t N_(\"to clone from a local repository\")),\n \t\tOPT__QUIET(&quiet, \"Suppress output for cloning a submodule\"),\n \t\tOPT_END()\n \t};\n@@ -200,7 +208,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \tif (!file_exists(sm_gitdir)) {\n \t\tif (safe_create_leading_directories_const(sm_gitdir) < 0)\n \t\t\tdie(_(\"could not create directory '%s'\"), sm_gitdir);\n-\t\tif (clone_submodule(path, sm_gitdir, url, depth, reference, quiet))\n+\t\tif (clone_submodule(path, sm_gitdir, url, depth, reference,\n+\t\t\t\t    quiet, local))\n \t\t\tdie(_(\"clone of '%s' into submodule path '%s' failed\"),\n \t\t\t    url, path);\n \t} else {\n@@ -266,6 +275,7 @@ struct submodule_update_clone {\n \n \t/* configuration parameters which are passed on to the children */\n \tint quiet;\n+\tint local;\n \tconst char *reference;\n \tconst char *depth;\n \tconst char *recursive_prefix;\n@@ -278,7 +288,7 @@ struct submodule_update_clone {\n \tunsigned quickstop : 1;\n };\n #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \\\n-\tSUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \\\n+\tSUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, NULL, NULL, NULL, NULL, \\\n \tSTRING_LIST_INIT_DUP, 0}\n \n /**\n@@ -367,6 +377,10 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,\n \tchild->err = -1;\n \targv_array_push(&child->args, \"submodule--helper\");\n \targv_array_push(&child->args, \"clone\");\n+\tif (suc->local == 1)\n+\t\targv_array_push(&child->args, \"--local\");\n+\telse if (!suc->local)\n+\t\targv_array_push(&child->args, \"--no-local\");\n \tif (suc->quiet)\n \t\targv_array_push(&child->args, \"--quiet\");\n \tif (suc->prefix)\n@@ -451,6 +465,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)\n \t\tOPT_STRING(0, \"depth\", &suc.depth, \"<depth>\",\n \t\t\t   N_(\"Create a shallow clone truncated to the \"\n \t\t\t      \"specified number of revisions\")),\n+\t\tOPT_BOOL(0, \"local\", &suc.local,\n+\t\t\t N_(\"to clone from a local repository\")),\n \t\tOPT_INTEGER('j', \"jobs\", &max_jobs,\n \t\t\t    N_(\"parallel jobs\")),\n \t\tOPT__QUIET(&suc.quiet, N_(\"don't print cloning progress\")),\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 86018ee..4d5e8c7 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -653,6 +653,12 @@ cmd_update()\n \t\t--jobs=*)\n \t\t\tjobs=$1\n \t\t\t;;\n+\t\t--local)\n+\t\t\toption_local=\"--local\"\n+\t\t\t;;\n+\t\t--no-local)\n+\t\t\toption_local=\"--no-local\"\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -680,6 +686,7 @@ cmd_update()\n \t\t${reference:+--reference \"$reference\"} \\\n \t\t${depth:+--depth \"$depth\"} \\\n \t\t${jobs:+$jobs} \\\n+\t\t${option_local:+$option_local} \\\n \t\t\"$@\" || echo \"#unmatched\"\n \t} | {\n \terr=\n-- \n2.7.0.rc0.42.g8e9204f.dirty\n"},{"id":"280868","messageId":"1458090737-14030-4-git-send-email-sbeller@google.com","threadId":"41701","inReplyTo":"1458090737-14030-1-git-send-email-sbeller@google.com","subject":"[PATCH 3/3] clone: Add t5614 to test cloning submodules with shallowness involved","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-03-16T01:12:17Z","receivedAt":"2016-03-16T01:12:17Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"There are some inherent issues with shallow clones and submodules, such\nas having not having a commit available the superproject may point to\nin the submodule due to being shallow. Use the new file t5614 to document\nand test expectations in this area.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n\nNotes:\n    $gmane/288916 does renaming operations,\n    \"[PATCH] clone tests: rename t57* => t56*\",\n    such that the first 13 spots in t56* are taken.\n    So we'll go with ..14 to not cause conflicts.\n    (If not having that renaming patch in mind, you\n    may end up aksing yourself \"why ..14?\")\n\n t/t5614-clone-submodules.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 82 insertions(+)\n create mode 100755 t/t5614-clone-submodules.sh\n\ndiff --git a/t/t5614-clone-submodules.sh b/t/t5614-clone-submodules.sh\nnew file mode 100755\nindex 0000000..a66c2db\n--- /dev/null\n+++ b/t/t5614-clone-submodules.sh\n@@ -0,0 +1,82 @@\n+#!/bin/sh\n+\n+test_description='Test shallow cloning of repos with submodules'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'setup' '\n+\tgit checkout -b master &&\n+\ttest_commit commit1 &&\n+\ttest_commit commit2 &&\n+\tmkdir sub &&\n+\t(\n+\t\tcd sub &&\n+\t\tgit init &&\n+\t\ttest_commit subcommit1 &&\n+\t\ttest_commit subcommit2\n+\t) &&\n+\tgit submodule add ./sub &&\n+\tgit commit -m \"add submodule\"\n+'\n+\n+test_expect_success 'nonshallow clone implies nonshallow submodule' '\n+\ttest_when_finished \"rm -rf super_clone\" &&\n+\tgit clone --recurse-submodules . super_clone &&\n+\t(\n+\t\tcd super_clone &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 3 lines\n+\t) &&\n+\t(\n+\t\tcd super_clone/sub &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 2 lines\n+\t)\n+'\n+\n+test_expect_success 'shallow clone implies shallow submodule' '\n+\ttest_when_finished \"rm -rf super_clone\" &&\n+\tgit clone --recurse-submodules --no-local --depth 1 . super_clone &&\n+\t(\n+\t\tcd super_clone &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 1 lines\n+\t) &&\n+\t(\n+\t\tcd super_clone/sub &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 1 lines\n+\t)\n+'\n+\n+test_expect_success 'shallow clone with non shallow submodule' '\n+\ttest_when_finished \"rm -rf super_clone\" &&\n+\tgit clone --recurse-submodules --no-local --depth 1 --no-shallow-submodules . super_clone &&\n+\t(\n+\t\tcd super_clone &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 1 lines\n+\t) &&\n+\t(\n+\t\tcd super_clone/sub &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 2 lines\n+\t)\n+'\n+\n+test_expect_success 'non shallow clone with shallow submodule' '\n+\ttest_when_finished \"rm -rf super_clone\" &&\n+\tgit clone --recurse-submodules --no-local --shallow-submodules . super_clone &&\n+\t(\n+\t\tcd super_clone &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 3 lines\n+\t) &&\n+\t(\n+\t\tcd super_clone/sub &&\n+\t\tgit log --oneline >lines &&\n+\t\ttest_line_count = 1 lines\n+\t)\n+'\n+\n+test_done\n-- \n2.7.0.rc0.42.g8e9204f.dirty\n"},{"id":"284391","messageId":"DC38BBF1-9837-45C6-B744-F95FAA645FE3@gmail.com","threadId":"41701","inReplyTo":"1458090737-14030-2-git-send-email-sbeller@google.com","subject":"Re: [PATCH 1/3] clone: add `--shallow-submodules` flag","fromName":"Lars Schneider","fromEmail":"larsxschneider@gmail.com","sentAt":"2016-04-25T11:50:25Z","receivedAt":"2016-04-25T11:50:25Z","isPatch":true,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"\n> On 16 Mar 2016, at 02:12, Stefan Beller <sbeller@google.com> wrote:\n> \n> When creating a shallow clone of a repository with submodules, the depth\n> argument does not influence the submodules, i.e. the submodules are done\n> as non-shallow clones. It is unclear what the best default is for the\n> depth of submodules of a shallow clone, so we need to have the possibility\n> to do all kinds of combinations:\n> \n> * shallow super project with shallow submodules\n>  e.g. build bots starting always from scratch. They want to transmit\n>  the least amount of network data as well as using the least amount\n>  of space on their hard drive.\n> * shallow super project with unshallow submodules\n>  e.g. The superproject is just there to track a collection of repositories\n>  and it is not important to have the relationship between the repositories\n>  intact. However the history of the individual submodules matter.\n> * unshallow super project with shallow submodules\n>  e.g. The superproject is the actual project and the submodule is a\n>  library which is rarely touched.\n> \n> The new switch to select submodules to be shallow or unshallow supports\n> all of these three cases.\n> \n> It is easy to transition from the first to the second case by just\n> unshallowing the submodules (`git submodule foreach git fetch\n> --unshallow`), but it is not possible to transition from the second to the\n> first case (as we wouldd have already transmitted the non shallow over\ns/wouldd/would/\n\n\n> the network). That is why we want to make the first case the default in\n> case of a shallow super project. This leads to the inconvenience in the\n> second case with the shallow super project and unshallow submodules,\n> as you need to pass `--no-shallow-submodules`.\n> \n> Signed-off-by: Stefan Beller <sbeller@google.com>\n> ---\n> Documentation/git-clone.txt | 13 ++++++++++---\n> builtin/clone.c             |  7 +++++++\n> 2 files changed, 17 insertions(+), 3 deletions(-)\n> \n> diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt\n> index 6db7b6d..20a4577 100644\n> --- a/Documentation/git-clone.txt\n> +++ b/Documentation/git-clone.txt\n> @@ -14,8 +14,8 @@ SYNOPSIS\n> \t  [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]\n> \t  [--dissociate] [--separate-git-dir <git dir>]\n> \t  [--depth <depth>] [--[no-]single-branch]\n> -\t  [--recursive | --recurse-submodules] [--jobs <n>] [--] <repository>\n> -\t  [<directory>]\n> +\t  [--recursive | --recurse-submodules] [--[no-]shallow-submodules]\n> +\t  [--jobs <n>] [--] <repository> [<directory>]\n> \n> DESCRIPTION\n> -----------\n> @@ -190,7 +190,11 @@ objects from the source repository into a pack in the cloned repository.\n> \n> --depth <depth>::\n> \tCreate a 'shallow' clone with a history truncated to the\n> -\tspecified number of revisions.\n> +\tspecified number of revisions. Implies `--single-branch` unless\n> +\t`--no-single-branch` is given to fetch the histories near the\n> +\ttips of all branches. This implies `--shallow-submodules`. If\n> +\tyou want to have a shallow clone, but full submodules, also pass\nCan we make this more explicit. Attention, bikeshedding:\nIf you want to have a shallow parent clone, but full submodules...\n\n\n> +\t`--no-shallow-submodules`.\n> \n> --[no-]single-branch::\n> \tClone only the history leading to the tip of a single branch,\n> @@ -214,6 +218,9 @@ objects from the source repository into a pack in the cloned repository.\n> \trepository does not have a worktree/checkout (i.e. if any of\n> \t`--no-checkout`/`-n`, `--bare`, or `--mirror` is given)\n> \n> +--shallow-submodules::\nShould that be \"--[no-]shallow-submodules\" ?\n\n\n> +\tAll submodules which are cloned, will be shallow.\nMaybe you could extend it with \"... will be shallow with a depth of 1.\" ?\n\n\n> +\n> --separate-git-dir=<git dir>::\n> \tInstead of placing the cloned repository where it is supposed\n> \tto be, place the cloned repository at the specified directory,\n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index b004fb4..ecdf308 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -40,6 +40,7 @@ static const char * const builtin_clone_usage[] = {\n> \n> static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;\n> static int option_local = -1, option_no_hardlinks, option_shared, option_recursive;\n> +static int option_shallow_submodules = -1;\n> static char *option_template, *option_depth;\n> static char *option_origin = NULL;\n> static char *option_branch = NULL;\n> @@ -91,6 +92,8 @@ static struct option builtin_clone_options[] = {\n> \t\t    N_(\"create a shallow clone of that depth\")),\n> \tOPT_BOOL(0, \"single-branch\", &option_single_branch,\n> \t\t    N_(\"clone only one branch, HEAD or --branch\")),\n> +\tOPT_BOOL(0, \"shallow-submodules\", &option_shallow_submodules,\n> +\t\t    N_(\"any cloned submodules will be shallow\")),\nI am not familiar with this code but I assume the \"no-\" prefix flips the bool?\n\n  \n> \tOPT_STRING(0, \"separate-git-dir\", &real_git_dir, N_(\"gitdir\"),\n> \t\t   N_(\"separate git dir from working tree\")),\n> \tOPT_STRING_LIST('c', \"config\", &option_config, N_(\"key=value\"),\n> @@ -727,6 +730,10 @@ static int checkout(void)\n> \t\tstruct argv_array args = ARGV_ARRAY_INIT;\n> \t\targv_array_pushl(&args, \"submodule\", \"update\", \"--init\", \"--recursive\", NULL);\n> \n> +\t\tif (option_shallow_submodules == 1\n> +\t\t    || (option_shallow_submodules == -1 && option_depth))\n> +\t\t\targv_array_push(&args, \"--depth=1\");\n> +\n> \t\tif (max_jobs != -1)\n> \t\t\targv_array_pushf(&args, \"--jobs=%d\", max_jobs);\n> \n> -- \n> 2.7.0.rc0.42.g8e9204f.dirty\n> \n"},{"id":"284452","messageId":"CAGZ79kYJipjCVGFXQkHyLNr4GTZA+vJFv+-8bWDXTrN3VUORuA@mail.gmail.com","threadId":"41701","inReplyTo":"DC38BBF1-9837-45C6-B744-F95FAA645FE3@gmail.com","subject":"Re: [PATCH 1/3] clone: add `--shallow-submodules` flag","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-04-25T17:26:11Z","receivedAt":"2016-04-25T17:26:11Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Apr 25, 2016 at 4:50 AM, Lars Schneider\n<larsxschneider@gmail.com> wrote:\n>> first case (as we wouldd have already transmitted the non shallow over\n> s/wouldd/would/\n\nwill be fixed in a reroll\n\n>> --depth <depth>::\n>>       Create a 'shallow' clone with a history truncated to the\n>> -     specified number of revisions.\n>> +     specified number of revisions. Implies `--single-branch` unless\n>> +     `--no-single-branch` is given to fetch the histories near the\n>> +     tips of all branches. This implies `--shallow-submodules`. If\n>> +     you want to have a shallow clone, but full submodules, also pass\n> Can we make this more explicit. Attention, bikeshedding:\n> If you want to have a shallow parent clone, but full submodules...\n\nGood point, but with s/parent/superproject/ ? (What is a \"parent clone\"?\nIt is not defined in the glossary, so let's not make up more confusing words\nfor Git here :)\n\n>\n>\n>> +     `--no-shallow-submodules`.\n>>\n>> --[no-]single-branch::\n>>       Clone only the history leading to the tip of a single branch,\n>> @@ -214,6 +218,9 @@ objects from the source repository into a pack in the cloned repository.\n>>       repository does not have a worktree/checkout (i.e. if any of\n>>       `--no-checkout`/`-n`, `--bare`, or `--mirror` is given)\n>>\n>> +--shallow-submodules::\n> Should that be \"--[no-]shallow-submodules\" ?\n\nwill be fixed in a reroll\n\n>\n>\n>> +     All submodules which are cloned, will be shallow.\n> Maybe you could extend it with \"... will be shallow with a depth of 1.\" ?\n\ndone\n\n>\n>\n>> +\n>> --separate-git-dir=<git dir>::\n>>       Instead of placing the cloned repository where it is supposed\n>>       to be, place the cloned repository at the specified directory,\n>> diff --git a/builtin/clone.c b/builtin/clone.c\n>> index b004fb4..ecdf308 100644\n>> --- a/builtin/clone.c\n>> +++ b/builtin/clone.c\n>> @@ -40,6 +40,7 @@ static const char * const builtin_clone_usage[] = {\n>>\n>> static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;\n>> static int option_local = -1, option_no_hardlinks, option_shared, option_recursive;\n>> +static int option_shallow_submodules = -1;\n>> static char *option_template, *option_depth;\n>> static char *option_origin = NULL;\n>> static char *option_branch = NULL;\n>> @@ -91,6 +92,8 @@ static struct option builtin_clone_options[] = {\n>>                   N_(\"create a shallow clone of that depth\")),\n>>       OPT_BOOL(0, \"single-branch\", &option_single_branch,\n>>                   N_(\"clone only one branch, HEAD or --branch\")),\n>> +     OPT_BOOL(0, \"shallow-submodules\", &option_shallow_submodules,\n>> +                 N_(\"any cloned submodules will be shallow\")),\n> I am not familiar with this code but I assume the \"no-\" prefix flips the bool?\n\nGiving the --no-option stores an explicit 0 (it is initialized as -1),\nand passing --option stores a 1.\n\n>> @@ -727,6 +730,10 @@ static int checkout(void)\n>>               struct argv_array args = ARGV_ARRAY_INIT;\n>>               argv_array_pushl(&args, \"submodule\", \"update\", \"--init\", \"--recursive\", NULL);\n>>\n>> +             if (option_shallow_submodules == 1\n>> +                 || (option_shallow_submodules == -1 && option_depth))\n>> +                     argv_array_push(&args, \"--depth=1\");\n>> +\n\nwhich explains this here as:\n\n        If  --shallow-submodules was given\n          || (neither --[no-]shallow-submodules was given, but --depth\nwas given,\n            i.e. depth implies --shallow-submodule only if no explicit\nchoice was made\n            by the user.\n\n>>               if (max_jobs != -1)\n>>                       argv_array_pushf(&args, \"--jobs=%d\", max_jobs);\n>>\n>> --\n>> 2.7.0.rc0.42.g8e9204f.dirty\n>>\n>\n"}]}