Skip to content

Commit a3552ab

Browse files
ralfthjrn
authored andcommitted
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 <[email protected]> Signed-off-by: Ralf Thielow <[email protected]> Acked-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]>
1 parent 02a110a commit a3552ab

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

builtin/clone.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
946946
our_head_points_at = remote_head_points_at;
947947
}
948948
else {
949+
if (option_branch)
950+
die(_("Remote branch %s not found in upstream %s"),
951+
option_branch, option_origin);
952+
949953
warning(_("You appear to have cloned an empty repository."));
950954
mapped_refs = NULL;
951955
our_head_points_at = NULL;

t/t5706-clone-branch.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ test_expect_success 'setup' '
2020
echo one >file && git add file && git commit -m one &&
2121
git checkout -b two &&
2222
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)
2426
'
2527

2628
test_expect_success 'vanilla clone chooses HEAD' '
@@ -61,4 +63,8 @@ test_expect_success 'clone -b with bogus branch' '
6163
test_must_fail git clone -b bogus parent clone-bogus
6264
'
6365

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+
6470
test_done

0 commit comments

Comments
 (0)