clone: use git protocol for cloning shallow repo locally
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 5 Dec 2013 13:02:53 +0000 (20:02 +0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Dec 2013 00:14:18 +0000 (16:14 -0800)
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>
builtin/clone.c
t/t5601-clone.sh
index 0b182cefc24f3ee790cb63a944cb98eb3b7a6206..71ee68b464e52f11f0b2256a2c6e2b6a8927d515 100644 (file)
@@ -797,8 +797,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        else
                repo = repo_name;
        is_local = option_local != 0 && path && !is_bundle;
-       if (is_local && option_depth)
-               warning(_("--depth is ignored in local clones; use file:// instead."));
+       if (is_local) {
+               if (option_depth)
+                       warning(_("--depth is ignored in local clones; use file:// instead."));
+               if (!access(mkpath("%s/shallow", path), F_OK)) {
+                       if (option_local > 0)
+                               warning(_("source repository is shallow, ignoring --local"));
+                       is_local = 0;
+               }
+       }
        if (option_local > 0 && !is_local)
                warning(_("--local is ignored"));
 
index 1d1c8755ead4e432744a82f0d7b8ed7dfc8a6510..c226cff52c8b613105b6183cab35a0ba00fb3e75 100755 (executable)
@@ -340,4 +340,11 @@ test_expect_success 'clone from a repository with two identical branches' '
 
 '
 
+test_expect_success 'shallow clone locally' '
+       git clone --depth=1 --no-local src ssrrcc &&
+       git clone ssrrcc ddsstt &&
+       test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
+       ( cd ddsstt && git fsck )
+'
+
 test_done