I'm wondering how I can perform the equivalent of git status
with dulwich?
After adding/changing/renaming some files and staging them for commit, this is what I've tried doing:
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)
Outputs the following:
>>> 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...'))
But this output requires that I further process it to detect:
README.txt
.Makefile
to Makefile.mk
.TEST.txt
to the repository.The functions in dulwich.diff_tree
provide a much nicer interface to tree changes... is this not possible before actually committing?
You should be able to use dulwich.diff_tree.tree_changes
to detect the changes between two trees.
One of the requirements for this is that you add the relevant tree objects to the object store - you can use dulwich.index.commit_index
for this.