]> Pileus Git - ~andy/git/commitdiff
clone --branch: refuse to clone if upstream repo is empty
authorRalf Thielow <ralf.thielow@gmail.com>
Fri, 11 Oct 2013 16:49:02 +0000 (18:49 +0200)
committerJonathan Nieder <jrnieder@gmail.com>
Mon, 14 Oct 2013 19:26:15 +0000 (12:26 -0700)
Since 920b691 (clone: refuse to clone if --branch
points to bogus ref) we refuse to clone with option
"-b" if the specified branch does not exist in the
(non-empty) upstream. If the upstream repository is empty,
the branch doesn't exist, either. So refuse the clone too.

Reported-by: Robert Mitwicki <robert.mitwicki@opensoftware.pl>
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
Acked-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
builtin/clone.c
t/t5706-clone-branch.sh

index 430307b298b4f9ea03ff4caea283b133fde0077e..21ad9f945c019625ace5f5dba0d4e54a8b2bb70f 100644 (file)
@@ -946,6 +946,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                        our_head_points_at = remote_head_points_at;
        }
        else {
+               if (option_branch)
+                       die(_("Remote branch %s not found in upstream %s"),
+                                       option_branch, option_origin);
+
                warning(_("You appear to have cloned an empty repository."));
                mapped_refs = NULL;
                our_head_points_at = NULL;
index 56be67e07e3c20f029a0bdeb2179e219ebc0bda1..6e7a7be052276613bf5f83551d93b4d90536ea4e 100755 (executable)
@@ -20,7 +20,9 @@ test_expect_success 'setup' '
         echo one >file && git add file && git commit -m one &&
         git checkout -b two &&
         echo two >file && git add file && git commit -m two &&
-        git checkout master)
+        git checkout master) &&
+       mkdir empty &&
+       (cd empty && git init)
 '
 
 test_expect_success 'vanilla clone chooses HEAD' '
@@ -61,4 +63,8 @@ test_expect_success 'clone -b with bogus branch' '
        test_must_fail git clone -b bogus parent clone-bogus
 '
 
+test_expect_success 'clone -b not allowed with empty repos' '
+       test_must_fail git clone -b branch empty clone-branch-empty
+'
+
 test_done