提交 a3552aba 编写于 作者: R Ralf Thielow 提交者: Jonathan Nieder

clone --branch: refuse to clone if upstream repo is empty

Since 920b691f (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: NRobert Mitwicki <robert.mitwicki@opensoftware.pl>
Signed-off-by: NRalf Thielow <ralf.thielow@gmail.com>
Acked-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
上级 02a110ad
......@@ -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;
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册