pygit2 icon indicating copy to clipboard operation
pygit2 copied to clipboard

how to diff one file in working dir against a Blob?

Open barry-scott opened this issue 8 years ago • 3 comments

pygit2 version python3-pygit2-0.23.3-2.fc23.x86_64

I cannot figure out how I can get a diff for only one file.

How do I arrange to have pygit2 return the diff of a Blob against the working dir file?

I looked at calling diff_to_working on a new Index(), but that fails because the new Index() does not self._repo filled in.

TreeBuilder() seems is unable to help as it requires putting tree objects into the repo to allow for the folder structure, for example to diff Source/file.py. needs a tree for Source. I clearly do not want to be writting files into the repo to do a diff.

Did I miss something in API?

barry-scott avatar Mar 11 '16 10:03 barry-scott

There's git_diff_blob_to_buffer() which lets you choose an arbitrary buffer and an arbitrary blob to compare.

But if you want to perform a diff but filter for a single file, the diff options allow you to pass in a list of pathspecs to limit the diff.

Neither of these have wrapped in pygit2 yet.

carlosmn avatar Mar 15 '16 16:03 carlosmn

please consider this a request to wrap that API

barry-scott avatar Mar 25 '16 10:03 barry-scott

An option to pass in a list of pathspecs to limit the diff would be a good feature to have 👍

jnareb avatar Nov 22 '17 11:11 jnareb