2012-08-15 38 views

回答

5

我没有使用德威,但是从these doc's,可能是这样的:

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"] 

在这一点上,没有加载文件,但我可以从本地路径做到“混帐结账” ,并更新了文件。

而且,看到了这些:

+0

是的,获取函数将拉入'.git'目录下的包文件。我只是不知道如何将它合并到主分支。 – Determinant 2012-08-15 07:50:51

+0

听起来像fetch()应该将该包导入与回购相同的分支。可以使用do_commit()将它合并到主分支中吗? http://stackoverflow.com/questions/6904734/in-dulwich-how-do-i-commit-to-a-branch-instead-of-to-head – 2012-08-15 08:13:10

+0

恐怕不是... – Determinant 2012-08-15 08:49:49

1

完整的示例。适用于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) 

用您的数据替换LOCAL_FOLDER,REMOTE_URL,USERNAME,PASSWORD。