Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix diffs of files that have quoted paths #450

Closed
wants to merge 2 commits into from
Closed

Fix diffs of files that have quoted paths #450

wants to merge 2 commits into from

Conversation

jcouball
Copy link
Member

Your checklist for this pull request

🚨Please review the guidelines for contributing to this repository.

  • Ensure all commits include DCO sign-off.
  • Ensure that your contributions pass unit testing.
  • Ensure that your contributions contain documentation if applicable.

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:

$ git -c core.quotePath=false diff -p '@^'
diff --git "a/asdf\"asdf" "b/asdf\"asdf"
new file mode 100644
index 0000000..e69de29
diff --git a/my_other_file_☠ b/my_other_file_☠
new file mode 100644
index 0000000..e69de29
$

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 to my_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.

Signed-off-by: James Couball <jcouball@yahoo.com>
@stale
Copy link

stale bot commented Jun 5, 2020

A friendly reminder that this issue had no activity for 60 days.

@stale stale bot added the stale label Jun 5, 2020
@jcouball
Copy link
Member Author

Since the origin branch was deleted, this PR was re-created in #504

@jcouball jcouball closed this Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant