Can you use libgit2 to clone a git repository?
Is there a way to create a new clone of a git repo using libgit2? From the libgit2 usage guide (http://libgit2.github.com/api.html), various examples docs (http://schacon.github.com/libgit2-examples/ etc.) and the "repository" libgit2 api docs (h开发者_运维技巧ttp://libgit2.github.com/libgit2/group__git__repository.html) and other reading... I only see references to either opening an existing git repo dir, git_repository_open
, or creating a new one, git_repository_init
.
Is there something obvious I am missing? Perhaps the api equivalent of "git clone GIT-REPO-URL" is git_repository_init
followed by ... ?
Libgit2 is indeed a work in progress... but it looks like things are moving fast :)
It is now possible to fetch from a remote repository. You can find some pointers to code samples in this StackOverflow answer.
Update
The clone feature has just been merged into the libgit2 repository.
- clone.h header
- sample code usage in examples/network/clone.c
I've contributed this feature to the python binding of libgit2 ;)
Now you can clone in python as well.
repo_path = "git://github.com/libgit2/pygit2.git"
path = "/tmp/pygit2"
repo = clone_repository(repo_path, path)
Hope it helps!
No, that's not yet implemented in libgit2. None of the network protocols are yet implemented in libgit2 as far as I know. libgit2 is still a work in progress; it is useful for inspecting an manipulating a local repository, but not for doing network operations yet. For now, if you want to do network operations like cloning (or even local cloning), you are going to need to just shell out to the regular git
executable.
精彩评论