From: Junio C Hamano Date: Wed, 6 Jul 2016 20:38:13 +0000 (-0700) Subject: Merge branch 'sb/clone-shallow-passthru' X-Git-Tag: v2.10.0-rc0~153 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9f1027d18a23e7c2ae60d3fb0a943e7b3342c532?ds=inline;hp=-c Merge branch 'sb/clone-shallow-passthru' Fix an unintended regression in v2.9 that breaks "clone --depth" that recurses down to submodules by forcing the submodules to also be cloned shallowly, which many server instances that host upstream of the submodules are not prepared for. * sb/clone-shallow-passthru: clone: do not let --depth imply --shallow-submodules --- 9f1027d18a23e7c2ae60d3fb0a943e7b3342c532 diff --combined Documentation/git-clone.txt index 1b15cd7b16,c5a1ce2f59..ec41d3d698 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@@ -115,7 -115,8 +115,7 @@@ objects from the source repository int --quiet:: -q:: Operate quietly. Progress is not reported to the standard - error stream. This flag is also passed to the `rsync' - command when given. + error stream. --verbose:: -v:: @@@ -189,16 -190,18 +189,15 @@@ --depth :: Create a 'shallow' clone with a history truncated to the - specified number of revisions. Implies `--single-branch` unless + specified number of commits. 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, either specified by the `--branch` option or the primary - branch remote's `HEAD` points at. When creating a shallow - clone with the `--depth` option, this is the default, unless - `--no-single-branch` is given to fetch the histories near the - tips of all branches. + branch remote's `HEAD` points at. Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any diff --combined builtin/clone.c index 70d8213472,f267742e9e..31ea247e3f --- a/builtin/clone.c +++ b/builtin/clone.c @@@ -40,7 -40,7 +40,7 @@@ static const char * const builtin_clone 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; @@@ -48,9 -48,8 +48,9 @@@ static const char *real_git_dir static char *option_upload_pack = "git-upload-pack"; static int option_verbosity; static int option_progress = -1; -static struct string_list option_config; -static struct string_list option_reference; +static enum transport_family family; +static struct string_list option_config = STRING_LIST_INIT_NODUP; +static struct string_list option_reference = STRING_LIST_INIT_NODUP; static int option_dissociate; static int max_jobs = -1; @@@ -99,10 -98,6 +99,10 @@@ static struct option builtin_clone_opti N_("separate git dir from working tree")), OPT_STRING_LIST('c', "config", &option_config, N_("key=value"), N_("set config inside the new repository")), + OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"), + TRANSPORT_FAMILY_IPV4), + OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"), + TRANSPORT_FAMILY_IPV6), OPT_END() }; @@@ -238,8 -233,8 +238,8 @@@ static char *guess_dir_name(const char strip_suffix_mem(start, &len, is_bundle ? ".bundle" : ".git"); if (!len || (len == 1 && *start == '/')) - die("No directory name could be guessed.\n" - "Please specify a directory on the command line"); + die(_("No directory name could be guessed.\n" + "Please specify a directory on the command line")); if (is_bare) dir = xstrfmt("%.*s.git", (int)len, start); @@@ -346,7 -341,7 +346,7 @@@ static void copy_alternates(struct strb FILE *in = fopen(src->buf, "r"); struct strbuf line = STRBUF_INIT; - while (strbuf_getline(&line, in, '\n') != EOF) { + while (strbuf_getline(&line, in) != EOF) { char *abs_path; if (!line.len || line.buf[0] == '#') continue; @@@ -643,11 -638,9 +643,11 @@@ static void update_remote_refs(const st struct strbuf head_ref = STRBUF_INIT; strbuf_addstr(&head_ref, branch_top); strbuf_addstr(&head_ref, "HEAD"); - create_symref(head_ref.buf, - remote_head_points_at->peer_ref->name, - msg); + if (create_symref(head_ref.buf, + remote_head_points_at->peer_ref->name, + msg) < 0) + die(_("unable to update %s"), head_ref.buf); + strbuf_release(&head_ref); } } @@@ -657,8 -650,7 +657,8 @@@ static void update_head(const struct re const char *head; if (our && skip_prefix(our->name, "refs/heads/", &head)) { /* Local default branch link */ - create_symref("HEAD", our->name, NULL); + if (create_symref("HEAD", our->name, NULL) < 0) + die(_("unable to update HEAD")); if (!option_bare) { update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR); @@@ -738,8 -730,7 +738,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) @@@ -754,7 -745,7 +753,7 @@@ static int write_one_config(const char *key, const char *value, void *data) { - return git_config_set_multivar(key, value ? value : "true", "^$", 0); + return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0); } static void write_config(struct string_list *config) @@@ -764,7 -755,7 +763,7 @@@ for (i = 0; i < config->nr; i++) { if (git_config_parse_parameter(config->items[i].string, write_one_config, NULL) < 0) - die("unable to write parameters to config file"); + die(_("unable to write parameters to config file")); } } @@@ -989,7 -980,6 +988,7 @@@ int cmd_clone(int argc, const char **ar remote = remote_get(option_origin); transport = transport_get(remote, remote->url[0]); transport_set_verbosity(transport, option_verbosity, option_progress); + transport->family = family; path = get_repo_path(remote->url[0], &is_bundle); is_local = option_local != 0 && path && !is_bundle; diff --combined t/t5614-clone-submodules.sh index 32d83e2694,a9aaa018ed..ea78f1ff31 --- a/t/t5614-clone-submodules.sh +++ b/t/t5614-clone-submodules.sh @@@ -37,9 -37,9 +37,9 @@@ test_expect_success 'nonshallow clone i ) ' - 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 +52,21 @@@ ) ' + 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 && @@@ -82,56 -97,4 +97,56 @@@ test_expect_success 'non shallow clone ) ' +test_expect_success 'clone follows shallow recommendation' ' + test_when_finished "rm -rf super_clone" && + git config -f .gitmodules submodule.sub.shallow true && + git add .gitmodules && + git commit -m "recommed shallow for sub" && + git clone --recurse-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 >lines && + test_line_count = 1 lines + ) +' + +test_expect_success 'get unshallow recommended shallow submodule' ' + test_when_finished "rm -rf super_clone" && + git clone --no-local "file://$pwd/." super_clone && + ( + cd super_clone && + git submodule update --init --no-recommend-shallow && + git log --oneline >lines && + test_line_count = 4 lines + ) && + ( + cd super_clone/sub && + git log --oneline >lines && + test_line_count = 3 lines + ) +' + +test_expect_success 'clone follows non shallow recommendation' ' + test_when_finished "rm -rf super_clone" && + git config -f .gitmodules submodule.sub.shallow false && + git add .gitmodules && + git commit -m "recommed non shallow for sub" && + git clone --recurse-submodules --no-local "file://$pwd/." super_clone && + ( + cd super_clone && + git log --oneline >lines && + test_line_count = 5 lines + ) && + ( + cd super_clone/sub && + git log --oneline >lines && + test_line_count = 3 lines + ) +' + test_done