← Back to team overview

dulwich-users team mailing list archive

Re: Cloning/Pulling from a Remote Git Repository

 

Hi Matthew,

On Thu, 2010-03-11 at 15:51 +0000, Matthew Richardson wrote:
> I'm currently trying to use dulwich to pull or clone from a remote Git
> repository.  I've been working through the API, /usr/bin/dulwich, and
> the source, but have got stuck.
> 
> What I have so far (assuming a git-daemon running on
> git-server.example.com):
> 
> #######
> 
> from dulwich.repo import Repo
> from dulwich.client import TCPGitClient
> 
> src = "/git/test"
> target = "/tmp/repo"
> 
> client = TCPGitClient("git-server.example.com")
> 
> os.mkdir(target)
> Repo.init(target)
> r = Repo(target)
> 
> graph_walker = r.get_graph_walker()
> determine_wants = r.object_store.determine_wants_all
> 
> f, commit = r.object_store.add_pack()
> client.fetch_pack(src, determine_wants, graph_walker,
>                                    f.write, sys.stdout.write)
> 
> commit()
> 
> ########
> 
> 
> This is as far as the example in /usr/bin/dulwich goes (for cloning).
> This results in a pack file in .git/objects/pack/, but I can't find a
> way of extracting this pack file to make the repository 'useable', and
> I'm not sure how to update the refs for the target repository once this
> has been done (something with repo.refs ?)
> 
> Can someone give me some pointers on how to do a pull from a remote
> repository?
Perhaps easier is:

client = TCPGitClient("git-server.example.com")

os.mkdir(target)
r = Repo.init(target)

remote_refs = client.fetch(src, r)
r["HEAD"] = remote_refs["HEAD"]

Cheers,

Jelmer

Attachment: signature.asc
Description: This is a digitally signed message part


References