Skip to content

Commit 47dbf10

Browse files
derrickstoleegitster
authored andcommitted
clone: fix --sparse option with URLs
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c75406 commit 47dbf10

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11301130
if (option_required_reference.nr || option_optional_reference.nr)
11311131
setup_reference();
11321132

1133-
if (option_sparse_checkout && git_sparse_checkout_init(repo))
1133+
if (option_sparse_checkout && git_sparse_checkout_init(dir))
11341134
return 1;
11351135

11361136
remote = remote_get(option_origin);

t/t1091-sparse-checkout-builtin.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ test_expect_success 'init with existing sparse-checkout' '
9090
'
9191

9292
test_expect_success 'clone --sparse' '
93-
git clone --sparse repo clone &&
93+
git clone --sparse "file://$(pwd)/repo" clone &&
9494
git -C clone sparse-checkout list >actual &&
9595
cat >expect <<-\EOF &&
9696
/*

0 commit comments

Comments
 (0)