Fix diffs of files that have quoted paths #450
Closed
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.
Your checklist for this pull request
🚨Please review the guidelines for contributing to this repository.
Description
As was reported in #418, if
git diff
reports a file path that has special characters like unicode, backslash, double quotes, etc. then the diff fails.lib/git/diff.rb
The problem was found to be in the diff parser not knowing how to deal with quoted paths.
lib/git/lib.rb
Additionally, we always tell git not to quote the paths in most cases so that Unicode characters come through without any special parsing. This is done by adding the
-c core.quotePath=false
to the global ops of all git commands. See the details of this option in the core.quotePath documentation.tests/units/test_diff_with_quoted_path.rb
This test runs a diff containing two files: one whose path contains a backslash and double quote and one whose path with a non-ascii, unicode character in the filename. The diff should list first path with quotes and the second path without quotes like this:
Note the different between the lines beginning with
diff --git
.tests/files/quoted_path/**/*
This is the test repository who last commit has two changes: one to
asdf\"asdf
and one tomy_other_file_☠
.tests/units/test_logger.rb
Since the
-c core.quotePath
was added to every command line, the logger tests had to be changed to ignore changes in global options.