Does gitpython (or at a pinch any of the python git APIs) provide a way to stage selected hunks from a file in the working tree, like git add -i
lets you do?
I think I can sort of see how to get an iterable of hunked changes by using difflib
on the git.diff.Diff
's a_blob
and b_blob
properties, but then how do I stage a particular hunk?
And, for bonus points, is there a better way to iterate over changes in a file than:
diff = repo.head.commit.diff(None)[0]
a = diff.a_blob.read().split(b'\n')
b = diff.b_blob.read().split(b'\n')
diff_generator = difflib.Differ().compare(a, b)
I'm thinking something that compares the streams, rather than having to load the whole lot into memory and then splitting it into lines.