Skip to content

Commit

Permalink
[Search git status] Fix previewing paths with spaces
Browse files Browse the repository at this point in the history
Previously, paths containing spaces broke the preview. Turns out the
qutoes added by git status for paths containing spaces were being passed
literally to git diff as part of the path and thus git diff could not
find the file.
  • Loading branch information
PatrickF1 committed Sep 26, 2022
1 parent 2bb6f71 commit 38896f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion functions/_fzf_preview_changed_file.fish
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# D README.md
# R LICENSE.md -> LICENSE
function _fzf_preview_changed_file --description "Show the untracked, staged, and/or unstaged changes in the given file."
set -l path (string split ' ' $argv)[-1]
# remove quotes because they'll be interpreted literally by git diff
# don't requote when referencing $path because fish does not perform word splitting
# https://fishshell.com/docs/current/fish_for_bash_users.html
set -l path (string unescape (string sub --start 4 $argv))
# first letter of short format shows index, second letter shows working tree
# https://git-scm.com/docs/git-status/2.35.0#_output
set -l index_status (string sub --length 1 $argv)
Expand Down
9 changes: 9 additions & 0 deletions tests/preview_changed_file/path_with_spaces.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set path_with_space "tests/_resources/multi word dir/file 1.txt"
set expected_diff a-very-unique-line
echo $expected_diff >>$path_with_space
set output (_fzf_preview_changed_file " M \"$path_with_space\"")

string match --entire --quiet $expected_diff $output
@test "git diff successfully invoked on path with space" $status -eq 0

git restore $path_with_space

0 comments on commit 38896f2

Please sign in to comment.