Fix: preview for add and clean when file names contain backslashes #465
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.
Check list
Description
While playing around with #464, I noticed that the preview of
forgit add
andforgit clean
do not work with files that have backslashes in their names. The preview just shows something likeThis is due to the same issue we tried to address with #388 (git escapes special characters in its output, but does not expect them to be escaped when used for input). Since #388 we use the
-z
option with most git commands that have this "issue" to prevent them from escaping their output. Inforgit add
andforgit clean
we use thecore.quotePath false
config option instead. Inforgit add
because we make use of the colors of the output ofgit status
and inforgit clean
becausegit clean
does not have a-z
option.I noticed that (in contrast to my previous belief),
-z
does not remove the colors fromgit status
, so it can be used inforgit add
. However, I could not find a way to get things working with our current implementation, but I found a simpler approach to what we're trying to achieve that actually does work. We try to filter out added files usinggrep
by matching lines with changed, unmerged and untracked files. Instead we can just do an inverse match for added files.For
forgit clean
I've modified the command to use_forgit_list_files
instead ofgit clean -n
. This comes with a minor breaking change: flag arguments provided toforgit clean
are now passed togit ls-files
instead ofgit clean -n
. However, git ls-files is way more flexible than git clean, so all use cases covered by git clean (and more) should still be possible. This will even allow us to introduce an environment variable in the future to modify which files are included when cleaning (I'll explain my use case in another PR, this text is already way too long 😉).Type of change
Test environment