Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull from the remote using dulwich?

How to do something like git pull in python dulwich library.

like image 766
Determinant Avatar asked Aug 15 '12 07:08

Determinant


2 Answers

I haven't used dulwich, but from these doc's, possibly something like:

from dulwich.repo import Repo
from dulwich.client import HttpGitClient
local = Repo.init("local", mkdir=True)
client = HttpGitClient('http://github.com/adammorris/')
remote_refs = client.fetch("history.js.git",local)
local["HEAD"] = remote_refs["refs/heads/master"]

At this point, it didn't load the files, but I could do "git checkout" from the local path, and it updated the files.

Also, saw these:

  • https://lists.launchpad.net/dulwich-users/msg00118.html
  • Programmatically `git checkout .` with dulwich
like image 198
Adam Morris Avatar answered Oct 04 '22 00:10

Adam Morris


Full example. Works with Bitbucket.

from dulwich import index
from dulwich.client import HttpGitClient
from dulwich.repo import Repo

local_repo = Repo.init(LOCAL_FOLDER, mkdir=True)
remote_repo = HttpGitClient(REMOTE_URL, username=USERNAME, password=PASSWORD)
remote_refs = remote_repo.fetch(REMOTE_URL, local_repo)
local_repo[b"HEAD"] = remote_refs[b"refs/heads/master"]

index_file = local_repo.index_path()
tree = local_repo[b"HEAD"].tree
index.build_index_from_tree(local_repo.path, index_file, local_repo.object_store, tree)

Replace LOCAL_FOLDER, REMOTE_URL, USERNAME, PASSWORD with your data.

like image 35
Maxim Korobov Avatar answered Oct 03 '22 22:10

Maxim Korobov