clone --branch: refuse to clone if upstream repo is empty
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>
Ralf Thielow committed
Oct 11, 2013 at 18:49 UTC
a3552aba55b9ed2860b8eb0581c73fc0e996369d
2 files changed
+11
-1
builtin/clone.c
+4
@@ -946,6 +946,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
946
our_head_points_at = remote_head_points_at;
947
}
948
else {
949
+ if (option_branch)
950
+ die(_("Remote branch %s not found in upstream %s"),
951
+ option_branch, option_origin);
952
+
953
warning(_("You appear to have cloned an empty repository."));
954
mapped_refs = NULL;
955
our_head_points_at = NULL;
t/t5706-clone-branch.sh
+7
-1
@@ -20,7 +20,9 @@ test_expect_success 'setup' '
20
echo one >file && git add file && git commit -m one &&
21
git checkout -b two &&
22
echo two >file && git add file && git commit -m two &&
23
- git checkout master)
23
+ git checkout master) &&
24
+ mkdir empty &&
25
+ (cd empty && git init)
26
'
27
28
test_expect_success 'vanilla clone chooses HEAD' '
@@ -61,4 +63,8 @@ test_expect_success 'clone -b with bogus branch' '
63
test_must_fail git clone -b bogus parent clone-bogus
64
'
65
66
+test_expect_success 'clone -b not allowed with empty repos' '
67
+ test_must_fail git clone -b branch empty clone-branch-empty
68
+'
69
+
70
test_done