Fix diff patch parser for paths with unsafe chars #415
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 specifically covers the cases where unsafe chars occur in path names, and git-diff -p will escape those.
From the git-diff-tree manpage:
This patch checks whether or not this has happened and will unescape those paths accordingly.
One thing to note here is that, depending on the position in the patch format, those paths may be prefixed with an
a/
orb/
. I've specifically made sure to never interpret a path that actually starts witha/
orb/
incorrectly.Example of that subtlety below. Here, the actual file path is
b/normal
. On the diff file that gets encoded asb/b/normal
.Here, we prefer the
---
and+++
lines' values. Note that these paths start witha/
orb/
. The only exception is the value/dev/null
, which is handled as a special case.Suppose now the file gets moved
b/moved
, the output of that diff would then be this:We prefer the
rename
lines' values in this case (thediff
line is always a last resort). Take note that those lines are not prefixed witha/
orb/
, but the ones in thediff
line are (just like the ones in---
or+++
lines).