mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
Allow cloning an empty repository
Cloning an empty repository manually (that is, doing 'git init' and then doing all configuration by hand) can be a lot of work. Save the user this work by allowing the cloning of empty repositories. Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
9a01387b97
commit
86ac751859
|
@ -522,14 +522,23 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
|
|||
option_upload_pack);
|
||||
|
||||
refs = transport_get_remote_refs(transport);
|
||||
if(refs)
|
||||
transport_fetch_refs(transport, refs);
|
||||
}
|
||||
|
||||
if (refs) {
|
||||
clear_extra_refs();
|
||||
|
||||
mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
|
||||
|
||||
head_points_at = locate_head(refs, mapped_refs, &remote_head);
|
||||
}
|
||||
else {
|
||||
warning("You appear to have cloned an empty repository.");
|
||||
head_points_at = NULL;
|
||||
remote_head = NULL;
|
||||
option_no_checkout = 1;
|
||||
}
|
||||
|
||||
if (head_points_at) {
|
||||
/* Local default branch link */
|
||||
|
|
|
@ -116,4 +116,20 @@ test_expect_success 'bundle clone with nonexistent HEAD' '
|
|||
test ! -e .git/refs/heads/master
|
||||
'
|
||||
|
||||
test_expect_success 'clone empty repository' '
|
||||
cd "$D" &&
|
||||
mkdir empty &&
|
||||
(cd empty && git init) &&
|
||||
git clone empty empty-clone &&
|
||||
test_tick &&
|
||||
(cd empty-clone
|
||||
echo "content" >> foo &&
|
||||
git add foo &&
|
||||
git commit -m "Initial commit" &&
|
||||
git push origin master &&
|
||||
expected=$(git rev-parse master) &&
|
||||
actual=$(git --git-dir=../empty/.git rev-parse master) &&
|
||||
test $actual = $expected)
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Loading…
Reference in a new issue