5
如何在python dulwich庫中做類似git pull
的操作。如何從遠程使用德威公司拉動?
如何在python dulwich庫中做類似git pull
的操作。如何從遠程使用德威公司拉動?
我沒有使用德威,但是從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"]
在這一點上,沒有加載文件,但我可以從本地路徑做到「混帳結賬」 ,並更新了文件。
而且,看到了這些:
完整的示例。適用於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。
是的,獲取函數將拉入'.git'目錄下的包文件。我只是不知道如何將它合併到主分支。 – Determinant 2012-08-15 07:50:51
聽起來像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
恐怕不是... – Determinant 2012-08-15 08:49:49