-->

如何从远程使用德威拉?(How to pull from the remote using dulw

2019-09-21 06:01发布

如何做类似git pull在Python库德威。

Answer 1:

我没有使用德威,但是从这些文件的浏览 ,可能是这样的:

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

在这一点上,没有加载文件,但我可以从本地路径做“git的结帐”,它的文件更新。

此外,看到了这些:

  • https://lists.launchpad.net/dulwich-users/msg00118.html
  • 编程`git的结帐.`与德威


Answer 2:

完整的例子。 工程与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,用户名,密码。



文章来源: How to pull from the remote using dulwich?