Skip to content

Commit

Permalink
Merge branch 'sr/clone-empty'
Browse files Browse the repository at this point in the history
* sr/clone-empty:
  Allow cloning an empty repository
  • Loading branch information
Junio C Hamano committed Jan 26, 2009
2 parents ec74042 + 86ac751 commit 45099df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
17 changes: 13 additions & 4 deletions builtin-clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,23 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
option_upload_pack);

refs = transport_get_remote_refs(transport);
transport_fetch_refs(transport, refs);
if(refs)
transport_fetch_refs(transport, refs);
}

clear_extra_refs();
if (refs) {
clear_extra_refs();

mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);

head_points_at = locate_head(refs, mapped_refs, &remote_head);
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 */
Expand Down
16 changes: 16 additions & 0 deletions t/t5701-clone-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 45099df

Please sign in to comment.