clone: --bundle-uri cannot be combined with --depth

A previous change added the '--bundle-uri' option, but did not check if the --depth parameter was included. Since bundles are not compatible with shallow clones, provide an error message to the user who is attempting this combination. I am leaving this as its own change, separate from the one that implements '--bundle-uri', because this is more of an advisory for the user. There is nothing wrong with bootstrapping with bundles and then fetching a shallow clone. However, that is likely going to involve too much work for the client _and_ the server. The client will download all of this bundle information containing the full history of the repository only to ignore most of it. The server will get a shallow fetch request, but with a list of haves that might cause a more painful computation of that shallow pack-file. Reviewed-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Aug 9, 2022 at 13:11 UTC e21e663cd1942df29979d3e01f7eacb532727bb7
3 files changed +13 -1
Documentation/git-clone.txt
+2 -1
@@ -327,7 +327,8 @@ or `--mirror` is given)
327 Before fetching from the remote, fetch a bundle from the given
328 `<uri>` and unbundle the data into the local repository. The refs
329 in the bundle will be stored under the hidden `refs/bundle/*`
330 - namespace.
330 + namespace. This option is incompatible with `--depth`,
331 + `--shallow-since`, and `--shallow-exclude`.
332
333 :git-clone: 1
334 include::urls.txt[]
builtin/clone.c
+3
@@ -937,6 +937,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
937 option_no_checkout = 1;
938 }
939
940 + if (bundle_uri && deepen)
941 + die(_("--bundle-uri is incompatible with --depth, --shallow-since, and --shallow-exclude"));
942 +
943 repo_name = argv[0];
944
945 path = get_repo_path(repo_name, &is_bundle);
t/t5606-clone-options.sh
+8
@@ -58,6 +58,14 @@ test_expect_success 'disallows --bare with --separate-git-dir' '
58
59 '
60
61 +test_expect_success 'disallows --bundle-uri with shallow options' '
62 + for option in --depth=1 --shallow-since=01-01-2000 --shallow-exclude=HEAD
63 + do
64 + test_must_fail git clone --bundle-uri=bundle $option from to 2>err &&
65 + grep "bundle-uri is incompatible" err || return 1
66 + done
67 +'
68 +
69 test_expect_success 'reject cloning shallow repository' '
70 test_when_finished "rm -rf repo" &&
71 test_must_fail git clone --reject-shallow shallow-repo out 2>err &&