]> git.ipfire.org Git - thirdparty/git.git/commitdiff
clone: fix --sparse option with URLs
authorDerrick Stolee <dstolee@microsoft.com>
Fri, 24 Jan 2020 21:19:34 +0000 (21:19 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Jan 2020 21:26:54 +0000 (13:26 -0800)
The --sparse option was added to the clone builtin in d89f09c (clone:
add --sparse mode, 2019-11-21) and was tested with a local path clone
in t1091-sparse-checkout-builtin.sh. However, due to a difference in
how local paths are handled versus URLs, this mechanism does not work
with URLs.

Modify the test to use a "file://" URL, which would output this error
before the code change:

  Cloning into 'clone'...
  fatal: cannot change to 'file://.../repo': No such file or directory
  error: failed to initialize sparse-checkout

These errors are due to using a "-C <path>" option to call 'git -C
<path> sparse-checkout init' but the URL is being given instead of
the target directory.

Update that target directory to evaluate this correctly. I have also
manually tested that https:// URLs are handled correctly as well.

Acked-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clone.c
t/t1091-sparse-checkout-builtin.sh

index 4348d962c9c81e4f6681eb53163b4f1278952153..2caefc44fb860f93a7e35f2941003e2090a88afe 100644 (file)
@@ -1130,7 +1130,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (option_required_reference.nr || option_optional_reference.nr)
                setup_reference();
 
-       if (option_sparse_checkout && git_sparse_checkout_init(repo))
+       if (option_sparse_checkout && git_sparse_checkout_init(dir))
                return 1;
 
        remote = remote_get(option_origin);
index 43d1f7520ce4263afafbf5f20ecdea392a06cb03..cf4a595c868d8ed429dc557e851a5a95692d999d 100755 (executable)
@@ -90,7 +90,7 @@ test_expect_success 'init with existing sparse-checkout' '
 '
 
 test_expect_success 'clone --sparse' '
-       git clone --sparse repo clone &&
+       git clone --sparse "file://$(pwd)/repo" clone &&
        git -C clone sparse-checkout list >actual &&
        cat >expect <<-\EOF &&
        /*