我想知道怎样才能用杜尔威奇来执行相当于git status的操作呢?
我试过这个:
在添加/更改/重命名一些文件并将它们暂存为commit之后,我尝试这样做:
from dulwich.repo import Repo
from dulwich.index import changes_from_tree
r = Repo('my-git-repo')
index = r.open_index()
changes = index.changes_from_tree(r.object_store, r['HEAD'].tree)产出如下:
>>> list(changes)
(('Makefile', None), (33188, None), ('9b20...', None))
(('test/README.txt', 'test/README.txt'), (33188, 33188), ('484b...', '4f89...'))
((None, 'Makefile.mk'), (None, 33188), (None, '9b20...'))
((None, 'TEST.txt'), (None, 33188), (None, '2a02...'))但是,这个输出要求我进一步处理它以检测:
将README.txt.
Makefile到Makefile.mk.
TEST.txt添加到存储库中。dulwich.diff_tree中的函数为树的更改提供了一个更好的接口。在实际执行之前,这不可能吗?
发布于 2012-06-10 11:27:37
您应该能够使用dulwich.diff_tree.tree_changes来检测两个树之间的变化。
这方面的要求之一是将相关的树对象添加到对象存储区--为此可以使用dulwich.index.commit_index。
发布于 2013-09-19 07:46:55
为了完整起见,一个工作样本:
from dulwich.repo import Repo
from dulwich.diff_tree import tree_changes
repo = Repo("./")
index = repo.open_index()
try:
head_tree = repo.head().tree
except KeyError: # in case of empty tree
head_tree = dulwich.objects.Tree()
changes = list(tree_changes(repo, head_tree, index.commit(repo.object_store)))
for change in changes:
print "%s: %s"%(change.type,change.new.path)https://stackoverflow.com/questions/10903803
复制相似问题