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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Dec 5, 2013 at 20:02 UTC 0d7d285f0e29abb994fe32db87ee81b00f403bd2
2 files changed +16 -2
builtin/clone.c
+9 -2
@@ -797,8 +797,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
797 else
798 repo = repo_name;
799 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 + }
809 if (option_local > 0 && !is_local)
810 warning(_("--local is ignored"));
811
t/t5601-clone.sh
+7
@@ -340,4 +340,11 @@ test_expect_success 'clone from a repository with two identical branches' '
340
341 '
342
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 +
350 test_done