Skip to content

Commit 0d7d285

Browse files
pcloudsgitster
authored andcommitted
clone: use git protocol for cloning shallow repo locally
clone_local() does not handle $SRC/shallow. It could be made so, but it's simpler to use fetch-pack/upload-pack instead. This used to be caught by the check in upload-pack, which is triggered by transport_get_remote_refs(), even in local clone case. The check is now gone and check_everything_connected() should catch the result incomplete repo. But check_everything_connected() will soon be skipped in local clone case, opening a door to corrupt repo. This patch should close that door. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2c681c commit 0d7d285

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

builtin/clone.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
797797
else
798798
repo = repo_name;
799799
is_local = option_local != 0 && path && !is_bundle;
800-
if (is_local && option_depth)
801-
warning(_("--depth is ignored in local clones; use file:// instead."));
800+
if (is_local) {
801+
if (option_depth)
802+
warning(_("--depth is ignored in local clones; use file:// instead."));
803+
if (!access(mkpath("%s/shallow", path), F_OK)) {
804+
if (option_local > 0)
805+
warning(_("source repository is shallow, ignoring --local"));
806+
is_local = 0;
807+
}
808+
}
802809
if (option_local > 0 && !is_local)
803810
warning(_("--local is ignored"));
804811

t/t5601-clone.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,11 @@ test_expect_success 'clone from a repository with two identical branches' '
340340
341341
'
342342

343+
test_expect_success 'shallow clone locally' '
344+
git clone --depth=1 --no-local src ssrrcc &&
345+
git clone ssrrcc ddsstt &&
346+
test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
347+
( cd ddsstt && git fsck )
348+
'
349+
343350
test_done

0 commit comments

Comments
 (0)