Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use libgit2 to clone a git repository?

Tags:

git

libgit2

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 (http://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 ... ?

like image 802
Trent Mick Avatar asked Apr 15 '11 17:04

Trent Mick


2 Answers

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
like image 196
nulltoken Avatar answered Sep 26 '22 11:09

nulltoken


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!

like image 21
user2429739 Avatar answered Sep 24 '22 11:09

user2429739