Fix repo.index.diff("HEAD", create_patch=True) always returning an empty list#948
Merged
Byron merged 2 commits intogitpython-developers:masterfrom Oct 22, 2019
thetwoj:master
Merged
Fix repo.index.diff("HEAD", create_patch=True) always returning an empty list#948Byron merged 2 commits intogitpython-developers:masterfrom thetwoj:master
Byron merged 2 commits intogitpython-developers:masterfrom
thetwoj:master
Conversation
Byron
approved these changes
Oct 22, 2019
Member
Byron
left a comment
There was a problem hiding this comment.
I am absolutely amazed by your contribution, and truly value the time and energy you must put into them!
Please let me know if you can think of anything that I can do to make your life as a contributor easier.
Contributor
Author
|
Thanks @Byron! I appreciate your willingness to entertain these PRs and how promptly you review them, it makes contributing fun 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR resolves the issue reported in #852
As @jadinm correctly identified in #852, this bug centers around the fact that the regex utilized by
_index_from_patch_format()ingit/diff.pyalways expects the first line of the diff to have theafile first, thenb:When the
otherpassed torepo.index.diff(other)is notNonethe-Rargument is added to the git command, resulting in the positions of theaandbfiles being flipped in the output and causing the_index_from_patch_format()function invoked by thecreate_patchoption to not find a regex match:This fix makes the regex slightly more permissive, allowing it to match either order of the
aandbfiles in the output ofgit diff.For test coverage of this change I added assertions to an existing test within
test_diff.pythat set up everything needed to reproduce this bug.Massive props to @jadinm, their troubleshooting and feedback on the issue significantly shortened the investigation required to get this one sorted out 🎉