如何在python dulwich库中做一些类似git pull的事情。
发布于 2012-08-15 15:42:13
我没有用过达利奇,但来自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"]在这一点上,它没有加载文件,但我可以从本地路径执行"git checkout“,它会更新文件。
此外,还看到了以下内容:
发布于 2017-02-24 01:19:36
完整的示例。与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、用户名、密码替换为您的数据。
https://stackoverflow.com/questions/11965471
复制相似问题