我正在尝试使用python中的dulwich来执行相当于git fetch -a的操作。
使用https://www.dulwich.io/docs/tutorial/remote.html上的文档,我创建了以下脚本:
from dulwich.client import LocalGitClient
from dulwich.repo import Repo
import os
home = os.path.expanduser('~')
local_folder = os.path.join(home, 'temp/local'
local = Repo(local_folder)
remote = os.path.join(home, 'temp/remote')
remote_refs = LocalGitClient().fetch(remote, local)
local_refs = LocalGitClient().get_refs(local_folder)
print(remote_refs)
print(local_refs)在~/temp/remote有一个现有的git存储库,在~/temp/local有一个新初始化的回购
remote_refs显示了我所期望的一切,但是local_refs是一个空字典,本地回购上的git branch -a什么也不返回。
我漏掉了什么明显的东西吗?
这是在Dulwich0.12.0和Python3.5上。
编辑#1
在讨论python irc通道之后,我更新了我的脚本,使其包括了determine_wants_all的使用。
from dulwich.client import LocalGitClient
from dulwich.repo import Repo
home = os.path.expanduser('~')
local_folder = os.path.join(home, 'temp/local'
local = Repo(local_folder)
remote = os.path.join(home, 'temp/remote')
wants = local.object_store.determine_wants_all
remote_refs = LocalGitClient().fetch(remote, local, wants)
local_refs = LocalGitClient().get_refs(local_folder)
print(remote_refs)
print(local_refs)但这并没有影响:
编辑#2
同样,在讨论python通道之后,我尝试在本地回购系统中运行dulwich fetch。它给出了与我的脚本相同的结果,即远程参考被正确地打印到控制台,但是git branch -a没有显示任何内容。
编辑解决
一个更新本地裁判的简单循环完成了这一任务:
from dulwich.client import LocalGitClient
from dulwich.repo import Repo
import os
home = os.path.expanduser('~')
local_folder = os.path.join(home, 'temp/local')
local = Repo(local_folder)
remote = os.path.join(home, 'temp/remote')
remote_refs = LocalGitClient().fetch(remote, local)
for key, value in remote_refs.items():
local.refs[key] = value
local_refs = LocalGitClient().get_refs(local_folder)
print(remote_refs)
print(local_refs)发布于 2016-01-05 13:15:43
LocalGitClient.fetch()不更新refs,它只是获取对象,然后返回远程参考,以便您可以使用它来更新目标存储库推荐。
https://stackoverflow.com/questions/34609308
复制相似问题