According to this a clone was possible at least 5 months ago. But I have never seen any code, documentation or examples about how to do it.
The clone operation is basically made of four steps:
- Initialize a new repository
- Add a remote with a fetch refspec
- Fetch the packfile from the remote and update your local references
- Update the content of the workdir from the commit tree of the HEAD
Current version of libgit2 (v0.17.0) allows one to perform the three first steps.
The source code contains some examples. There's a "fetch.c" one as well.
how would I do something equivalent of git checkout master with libgit2
Checkout is not implemented yet. However, the following should help you go forward.
git_reference_name_to_oid()
to retrieve the oid of the master
branch
git_commit_lookup()
to retreive a commit from an oid
git_commit_tree()
to retrieve the tree of a commit
git_iterator_for_tree()
to recursively browse all the leafs of the tree (and its subtrees)
Update
The clone feature has just been merged into the libgit2 repository.
As part of the pull request, the author took care of providing the users with a checkout implementation as well.