From 2cabbc85aad583bf6017e59914ee112359203b4d Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Mon, 3 Oct 2022 10:31:13 -0700 Subject: [PATCH 01/18] wipe test, change example --- functions/_fzf_preview_changed_file.fish | 2 +- .../{renamed_in_index.fish => renamed.fish} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/preview_changed_file/{renamed_in_index.fish => renamed.fish} (100%) diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index 3c3df80a..935d829d 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -2,7 +2,7 @@ # arg should be a line from git status --short, e.g. # MM functions/_fzf_preview_changed_file.fish # D README.md -# R LICENSE.md -> LICENSE +# R LICENSE -> "New License" function _fzf_preview_changed_file --argument-names path_status --description "Show the git diff of the given file." # remove quotes because they'll be interpreted literally by git diff # no need to requote when referencing $path because fish does not perform word splitting diff --git a/tests/preview_changed_file/renamed_in_index.fish b/tests/preview_changed_file/renamed.fish similarity index 100% rename from tests/preview_changed_file/renamed_in_index.fish rename to tests/preview_changed_file/renamed.fish From 80080213c6ec1a8cdc87df352ad19559b288227e Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Mon, 3 Oct 2022 14:09:46 -0700 Subject: [PATCH 02/18] fix using special logic if rename detected --- functions/_fzf_preview_changed_file.fish | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index 935d829d..f54651ef 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -24,6 +24,11 @@ function _fzf_preview_changed_file --argument-names path_status --description "S _fzf_report_diff_type Unmerged git diff $diff_opts -- $path else + if test $index_status = R + # path currently has the form of "file -> renamed_file" so we need to perform more logic to get the correct path + set path (string split -- ' -> ')[-1] + end + if test $index_status != ' ' _fzf_report_diff_type Staged git diff --staged $diff_opts -- $path From 82e1a3397c8e9bd5084e16cd6b5f00e12b506823 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Mon, 3 Oct 2022 22:24:39 -0700 Subject: [PATCH 03/18] start work on test --- functions/_fzf_preview_changed_file.fish | 1 + ...spaces.fish => modified_path_with_spaces.fish} | 2 +- tests/preview_changed_file/renamed.fish | 15 --------------- .../renamed_path_with_spaces.fish | 11 +++++++++++ 4 files changed, 13 insertions(+), 16 deletions(-) rename tests/preview_changed_file/{path_with_spaces.fish => modified_path_with_spaces.fish} (80%) delete mode 100644 tests/preview_changed_file/renamed.fish create mode 100644 tests/preview_changed_file/renamed_path_with_spaces.fish diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index f54651ef..6c9b1cda 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -12,6 +12,7 @@ function _fzf_preview_changed_file --argument-names path_status --description "S # https://git-scm.com/docs/git-status/2.35.0#_output set -l index_status (string sub --length 1 $path_status) set -l working_tree_status (string sub --start 2 --length 1 $path_status) + # no-prefix because the file is always being compared to itself so is unecessary set diff_opts --color=always --no-prefix diff --git a/tests/preview_changed_file/path_with_spaces.fish b/tests/preview_changed_file/modified_path_with_spaces.fish similarity index 80% rename from tests/preview_changed_file/path_with_spaces.fish rename to tests/preview_changed_file/modified_path_with_spaces.fish index bf97feba..8c5e40a7 100644 --- a/tests/preview_changed_file/path_with_spaces.fish +++ b/tests/preview_changed_file/modified_path_with_spaces.fish @@ -4,6 +4,6 @@ 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 +@test "successfully previews modified path with spaces" $status -eq 0 git restore $path_with_space diff --git a/tests/preview_changed_file/renamed.fish b/tests/preview_changed_file/renamed.fish deleted file mode 100644 index a868450c..00000000 --- a/tests/preview_changed_file/renamed.fish +++ /dev/null @@ -1,15 +0,0 @@ -set --export diff_working_called 0 -set --export diff_staged_called 0 -function git - if test $argv[1] != diff - echo "$argv[1] is unsupported" >&2 - exit 1 - else if contains -- --staged $argv - set diff_staged_called 1 - else - set diff_working_called 1 - end -end - -_fzf_preview_changed_file "R file1 -> file2" >/dev/null -@test "only calls git diff staged for renamed files" $diff_working_called -eq 0 -a $diff_staged_called -eq 1 diff --git a/tests/preview_changed_file/renamed_path_with_spaces.fish b/tests/preview_changed_file/renamed_path_with_spaces.fish new file mode 100644 index 00000000..2782369c --- /dev/null +++ b/tests/preview_changed_file/renamed_path_with_spaces.fish @@ -0,0 +1,11 @@ +set orig_path "_resources/multi word dir/file 1.txt" +set renamed_path "_resources/multi word dir/renamed 1.txt" +git mv $orig_path $renamed_path + +set output (_fzf_preview_changed_file "R \"$orig_path\" -> \"$renamed_path\"") + +# similarity index is printed by git diff in renames +string match --entire --quiet "similarity index 100%" $output +@test "successfully previews renamed path with spaces" $status -eq 0 + +git mv $renamed_path $orig_path From fd55607b6e0bc5ec9d52538e33e6009937150616 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Mon, 3 Oct 2022 22:52:22 -0700 Subject: [PATCH 04/18] fix test --- tests/preview_changed_file/renamed_path_with_spaces.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/preview_changed_file/renamed_path_with_spaces.fish b/tests/preview_changed_file/renamed_path_with_spaces.fish index 2782369c..bb370c08 100644 --- a/tests/preview_changed_file/renamed_path_with_spaces.fish +++ b/tests/preview_changed_file/renamed_path_with_spaces.fish @@ -1,5 +1,5 @@ -set orig_path "_resources/multi word dir/file 1.txt" -set renamed_path "_resources/multi word dir/renamed 1.txt" +set orig_path "tests/_resources/multi word dir/file 1.txt" +set renamed_path "tests/_resources/multi word dir/renamed 1.txt" git mv $orig_path $renamed_path set output (_fzf_preview_changed_file "R \"$orig_path\" -> \"$renamed_path\"") From 3d3223b418b0e8ce15f2f0a1ab812a465a226fac Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Tue, 4 Oct 2022 14:53:21 -0700 Subject: [PATCH 05/18] slightly optimize --- functions/_fzf_preview_changed_file.fish | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index f0344b6b..e6f8e9d5 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -26,12 +26,11 @@ function _fzf_preview_changed_file --argument-names path_status --description "S _fzf_report_diff_type Unmerged git diff $diff_opts -- $path else - if test $index_status = R - # path currently has the form of "file -> renamed_file" so we need to perform more logic to get the correct path - set path (string split -- ' -> ')[-1] - end - if test $index_status != ' ' + if test $index_status = R + # path currently has the form of "file -> renamed_file" so we need to correct $path + set path (string split -- ' -> ')[-1] + end _fzf_report_diff_type Staged git diff --staged $diff_opts -- $path end From 7d9e404ae300ec7a732b1a909843e01011e87c75 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Fri, 7 Oct 2022 17:02:55 -0700 Subject: [PATCH 06/18] comment --- functions/_fzf_preview_changed_file.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index e6f8e9d5..d18db0e8 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -28,7 +28,7 @@ function _fzf_preview_changed_file --argument-names path_status --description "S else if test $index_status != ' ' if test $index_status = R - # path currently has the form of "file -> renamed_file" so we need to correct $path + # path currently has the form of "file -> renamed_file" so we need to correct it set path (string split -- ' -> ')[-1] end _fzf_report_diff_type Staged From a50f5d47ab8f234bbc99f1d4fe1af6010d481604 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Fri, 7 Oct 2022 17:12:48 -0700 Subject: [PATCH 07/18] completely forgot to pass to string split --- functions/_fzf_preview_changed_file.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index d18db0e8..80327f5b 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -29,7 +29,7 @@ function _fzf_preview_changed_file --argument-names path_status --description "S if test $index_status != ' ' if test $index_status = R # path currently has the form of "file -> renamed_file" so we need to correct it - set path (string split -- ' -> ')[-1] + set path (string split -- ' -> ' $path)[-1] end _fzf_report_diff_type Staged git diff --staged $diff_opts -- $path From cf686b9682d649143563883bbe7df70d669404be Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Fri, 7 Oct 2022 17:53:06 -0700 Subject: [PATCH 08/18] show only changes post-rename --- functions/_fzf_preview_changed_file.fish | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index 80327f5b..c35d6940 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -26,11 +26,15 @@ function _fzf_preview_changed_file --argument-names path_status --description "S _fzf_report_diff_type Unmerged git diff $diff_opts -- $path else - if test $index_status != ' ' - if test $index_status = R - # path currently has the form of "file -> renamed_file" so we need to correct it - set path (string split -- ' -> ' $path)[-1] - end + if test $index_status = R + # to show only modifications to the file post-rename, need to diff it with the old path + set orig_and_new_path (string split -- ' -> ' $path) + # path currently has the form of '"original path" -> renamed path"', so we need to correct it + set path $orig_and_new_path[2] + + _fzf_report_diff_type Staged + git diff --staged $diff_opts -- $orig_and_new_path[1] $orig_and_new_path[2] + else if test $index_status != ' ' _fzf_report_diff_type Staged git diff --staged $diff_opts -- $path end From 66797bb45d8272b28f73e7accf76f05223591de2 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Fri, 7 Oct 2022 17:55:09 -0700 Subject: [PATCH 09/18] reorder logic for separation --- functions/_fzf_parse_git_status.fish | 2 ++ functions/_fzf_preview_changed_file.fish | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 functions/_fzf_parse_git_status.fish diff --git a/functions/_fzf_parse_git_status.fish b/functions/_fzf_parse_git_status.fish new file mode 100644 index 00000000..e46f14d7 --- /dev/null +++ b/functions/_fzf_parse_git_status.fish @@ -0,0 +1,2 @@ +function _fzf_parse_git_status --argument-names path_status --description "Parse the status info and path(s) from a line of git status output." +end diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index c35d6940..5333fc67 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -29,11 +29,12 @@ function _fzf_preview_changed_file --argument-names path_status --description "S if test $index_status = R # to show only modifications to the file post-rename, need to diff it with the old path set orig_and_new_path (string split -- ' -> ' $path) - # path currently has the form of '"original path" -> renamed path"', so we need to correct it - set path $orig_and_new_path[2] - _fzf_report_diff_type Staged git diff --staged $diff_opts -- $orig_and_new_path[1] $orig_and_new_path[2] + + # path currently has the form of '"original path" -> renamed path"', so we need to correct it + # before it's used for the working tree diff + set path $orig_and_new_path[2] else if test $index_status != ' ' _fzf_report_diff_type Staged git diff --staged $diff_opts -- $path From 5d6762fa02d9783b18f54b5c056ae1088d25dd1e Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sat, 8 Oct 2022 21:46:44 -0700 Subject: [PATCH 10/18] partial regex solution --- functions/_fzf_parse_git_status.fish | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/functions/_fzf_parse_git_status.fish b/functions/_fzf_parse_git_status.fish index e46f14d7..c26fe9dd 100644 --- a/functions/_fzf_parse_git_status.fish +++ b/functions/_fzf_parse_git_status.fish @@ -1,2 +1,9 @@ -function _fzf_parse_git_status --argument-names path_status --description "Parse the status info and path(s) from a line of git status output." +function _fzf_parse_git_status_paths --argument-names path_status --description "Parse the path from a line of git status output. If the path was renamed, then return both the original and new path." + string match --regex --groups-only '(?[ MADRU])(?[ MADRU])' (string sub --length 2 $path_status) + if test $status -neq 0 + false + end + + set raw_paths (string split -- ' -> ') + string match --regex --groups-only '((?.*) -> )?(?.*)$' end From dd599d139c79ab072c25a70db778f446fbf9027d Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sat, 8 Oct 2022 22:15:12 -0700 Subject: [PATCH 11/18] more regex solution, untested --- functions/_fzf_parse_git_status.fish | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/functions/_fzf_parse_git_status.fish b/functions/_fzf_parse_git_status.fish index c26fe9dd..6364ed02 100644 --- a/functions/_fzf_parse_git_status.fish +++ b/functions/_fzf_parse_git_status.fish @@ -1,9 +1,15 @@ function _fzf_parse_git_status_paths --argument-names path_status --description "Parse the path from a line of git status output. If the path was renamed, then return both the original and new path." + set --function output string match --regex --groups-only '(?[ MADRU])(?[ MADRU])' (string sub --length 2 $path_status) if test $status -neq 0 false + else + set output $index_status $working_tree_status end - set raw_paths (string split -- ' -> ') - string match --regex --groups-only '((?.*) -> )?(?.*)$' + set raw_paths (string split --max 1 -- ' -> ') + for path in $raw_paths + # grab the path without + set output --append string match --regex --groups-only '^"?(.*?)"?$' + end end From c20f23c19aebafb48032da8d670edb201543bd55 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sun, 9 Oct 2022 19:51:09 -0700 Subject: [PATCH 12/18] append in reverse order --- functions/_fzf_parse_git_status.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/_fzf_parse_git_status.fish b/functions/_fzf_parse_git_status.fish index 6364ed02..a9a948db 100644 --- a/functions/_fzf_parse_git_status.fish +++ b/functions/_fzf_parse_git_status.fish @@ -8,8 +8,8 @@ function _fzf_parse_git_status_paths --argument-names path_status --description end set raw_paths (string split --max 1 -- ' -> ') - for path in $raw_paths - # grab the path without + # append the paths without any quotes + for path in $raw_paths[-1..1] set output --append string match --regex --groups-only '^"?(.*?)"?$' end end From 987e7188d999885f56ee23d0832ef798f4413111 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sun, 9 Oct 2022 20:28:49 -0700 Subject: [PATCH 13/18] don't use --no-prefix now that diffing against itself sometimes --- functions/_fzf_preview_changed_file.fish | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index 5333fc67..71f3f824 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -13,8 +13,7 @@ function _fzf_preview_changed_file --argument-names path_status --description "S set -l index_status (string sub --length 1 $path_status) set -l working_tree_status (string sub --start 2 --length 1 $path_status) - # no-prefix because the file is always being compared to itself so is unecessary - set diff_opts --color=always --no-prefix + set diff_opts --color=always if test $index_status = '?' _fzf_report_diff_type Untracked @@ -26,14 +25,15 @@ function _fzf_preview_changed_file --argument-names path_status --description "S _fzf_report_diff_type Unmerged git diff $diff_opts -- $path else + # renames are only detected in the index, never working tree so only need to test for it in one place + # https://stackoverflow.com/questions/73954214/is-it-possible-to-rename-a-file-in-work-tree-without-staging if test $index_status = R - # to show only modifications to the file post-rename, need to diff it with the old path + # diff the post-rename path with the original path, otherwise the diff will show the entire file as being added set orig_and_new_path (string split -- ' -> ' $path) _fzf_report_diff_type Staged git diff --staged $diff_opts -- $orig_and_new_path[1] $orig_and_new_path[2] - # path currently has the form of '"original path" -> renamed path"', so we need to correct it - # before it's used for the working tree diff + # path currently has the form of "original -> current", so we need to correct it before it's used below set path $orig_and_new_path[2] else if test $index_status != ' ' _fzf_report_diff_type Staged From dd563bd2be782ebc24a64ba4c3eaecc1828d4633 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sun, 9 Oct 2022 20:29:15 -0700 Subject: [PATCH 14/18] try parse git status in separate PR --- functions/_fzf_parse_git_status.fish | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 functions/_fzf_parse_git_status.fish diff --git a/functions/_fzf_parse_git_status.fish b/functions/_fzf_parse_git_status.fish deleted file mode 100644 index a9a948db..00000000 --- a/functions/_fzf_parse_git_status.fish +++ /dev/null @@ -1,15 +0,0 @@ -function _fzf_parse_git_status_paths --argument-names path_status --description "Parse the path from a line of git status output. If the path was renamed, then return both the original and new path." - set --function output - string match --regex --groups-only '(?[ MADRU])(?[ MADRU])' (string sub --length 2 $path_status) - if test $status -neq 0 - false - else - set output $index_status $working_tree_status - end - - set raw_paths (string split --max 1 -- ' -> ') - # append the paths without any quotes - for path in $raw_paths[-1..1] - set output --append string match --regex --groups-only '^"?(.*?)"?$' - end -end From afe3828cca0387c59ee37880f69e034ab6589af5 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sun, 9 Oct 2022 20:37:08 -0700 Subject: [PATCH 15/18] reduce one possible if statement test --- README.md | 2 +- functions/_fzf_preview_changed_file.fish | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 70a9fe4d..6b765c91 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ They are always appended last to fzf's argument list. Because fzf uses the optio ### Change the commands used to preview directories and regular files -The search directory feature, by default, calls `ls` to preview directories and `bat` to preview [regular files](https://stackoverflow.com/questions/6858452/what-is-a-regular-file-on-unix). +The search directory feature, by default, calls `ls` to preview directories and `bat` to preview [regular files](https://stackoverflow.com/questions/6858452). To change the directory preview command (e.g. to use one of the many `ls` replacements such as `exa`), set the command in the `fzf_preview_dir_cmd` variable: diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index 71f3f824..ebe863d3 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -25,19 +25,20 @@ function _fzf_preview_changed_file --argument-names path_status --description "S _fzf_report_diff_type Unmerged git diff $diff_opts -- $path else - # renames are only detected in the index, never working tree so only need to test for it in one place - # https://stackoverflow.com/questions/73954214/is-it-possible-to-rename-a-file-in-work-tree-without-staging - if test $index_status = R - # diff the post-rename path with the original path, otherwise the diff will show the entire file as being added - set orig_and_new_path (string split -- ' -> ' $path) + if test $index_status != ' ' _fzf_report_diff_type Staged - git diff --staged $diff_opts -- $orig_and_new_path[1] $orig_and_new_path[2] - # path currently has the form of "original -> current", so we need to correct it before it's used below - set path $orig_and_new_path[2] - else if test $index_status != ' ' - _fzf_report_diff_type Staged - git diff --staged $diff_opts -- $path + # renames are only detected in the index, never working tree, so only need to test for it here + # https://stackoverflow.com/questions/73954214 + if test $index_status = R + # diff the post-rename path with the original path, otherwise the diff will show the entire file as being added + set orig_and_new_path (string split -- ' -> ' $path) + git diff --staged $diff_opts -- $orig_and_new_path[1] $orig_and_new_path[2] + # path currently has the form of "original -> current", so we need to correct it before it's used below + set path $orig_and_new_path[2] + else + git diff --staged $diff_opts -- $path + end end if test $working_tree_status != ' ' From bd7fee6c699a172ea60ed29874a0ca952c142926 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sun, 9 Oct 2022 20:52:19 -0700 Subject: [PATCH 16/18] update test --- tests/_resources/alphabet 26 lines | 26 +++++++++++++++++++ .../renamed_path_modifications.fish | 17 ++++++++++++ .../renamed_path_with_spaces.fish | 11 -------- 3 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 tests/_resources/alphabet 26 lines create mode 100644 tests/preview_changed_file/renamed_path_modifications.fish delete mode 100644 tests/preview_changed_file/renamed_path_with_spaces.fish diff --git a/tests/_resources/alphabet 26 lines b/tests/_resources/alphabet 26 lines new file mode 100644 index 00000000..b2768947 --- /dev/null +++ b/tests/_resources/alphabet 26 lines @@ -0,0 +1,26 @@ +aaaaaaaaaaa +bbbbbbbbbbb +ccccccccccc +ddddddddddd +eeeeeeeeeee +fffffffffff +ggggggggggg +hhhhhhhhhhh +iiiiiiiiiii +jjjjjjjjjjj +kkkkkkkkkkk +lllllllllll +mmmmmmmmmmm +nnnnnnnnnnn +ooooooooooo +ppppppppppp +qqqqqqqqqqq +rrrrrrrrrrr +sssssssssss +ttttttttttt +uuuuuuuuuuu +vvvvvvvvvvv +wwwwwwwwwww +xxxxxxxxxxx +yyyyyyyyyyy +zzzzzzzzzzz diff --git a/tests/preview_changed_file/renamed_path_modifications.fish b/tests/preview_changed_file/renamed_path_modifications.fish new file mode 100644 index 00000000..7b70650d --- /dev/null +++ b/tests/preview_changed_file/renamed_path_modifications.fish @@ -0,0 +1,17 @@ +set orig_path "tests/_resources/alphabet 26 lines" +set renamed_path "tests/_resources/alphabet lines" +set added_line a-very-unique-line +git mv $orig_path $renamed_path +echo $added_line >>$renamed_path +git add $renamed_path + +set output (_fzf_preview_changed_file "R \"$orig_path\" -> \"$renamed_path\"") + +# test that the added line shows up in the diff but not the entire file +# "aaaaaaaaaa" is the first line in the file +string match --entire --quiet $added_line $output && + not string match --entire aaaaaaaaaa $output +@test "shows only the modifications made to renamed file" $status -eq 0 + +git mv $renamed_path $orig_path +git restore --staged --worktree $orig_path diff --git a/tests/preview_changed_file/renamed_path_with_spaces.fish b/tests/preview_changed_file/renamed_path_with_spaces.fish deleted file mode 100644 index bb370c08..00000000 --- a/tests/preview_changed_file/renamed_path_with_spaces.fish +++ /dev/null @@ -1,11 +0,0 @@ -set orig_path "tests/_resources/multi word dir/file 1.txt" -set renamed_path "tests/_resources/multi word dir/renamed 1.txt" -git mv $orig_path $renamed_path - -set output (_fzf_preview_changed_file "R \"$orig_path\" -> \"$renamed_path\"") - -# similarity index is printed by git diff in renames -string match --entire --quiet "similarity index 100%" $output -@test "successfully previews renamed path with spaces" $status -eq 0 - -git mv $renamed_path $orig_path From 3fc3dd0d587a439d6a8e099b99484078eb0b169b Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sun, 9 Oct 2022 21:13:22 -0700 Subject: [PATCH 17/18] add txt extension or it'll be identified as ruby file --- tests/_resources/{alphabet 26 lines => alphabet 26 lines.txt} | 0 tests/preview_changed_file/renamed_path_modifications.fish | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename tests/_resources/{alphabet 26 lines => alphabet 26 lines.txt} (100%) diff --git a/tests/_resources/alphabet 26 lines b/tests/_resources/alphabet 26 lines.txt similarity index 100% rename from tests/_resources/alphabet 26 lines rename to tests/_resources/alphabet 26 lines.txt diff --git a/tests/preview_changed_file/renamed_path_modifications.fish b/tests/preview_changed_file/renamed_path_modifications.fish index 7b70650d..6d9b1fd1 100644 --- a/tests/preview_changed_file/renamed_path_modifications.fish +++ b/tests/preview_changed_file/renamed_path_modifications.fish @@ -1,5 +1,5 @@ -set orig_path "tests/_resources/alphabet 26 lines" -set renamed_path "tests/_resources/alphabet lines" +set orig_path "tests/_resources/alphabet 26 lines.txt" +set renamed_path "tests/_resources/alphabet lines.txt" set added_line a-very-unique-line git mv $orig_path $renamed_path echo $added_line >>$renamed_path From f719ec679fe5cf7b5eeb5357d489b16facc957c8 Mon Sep 17 00:00:00 2001 From: Patrick Fong Date: Sun, 9 Oct 2022 21:17:38 -0700 Subject: [PATCH 18/18] string split max 1 --- functions/_fzf_preview_changed_file.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/_fzf_preview_changed_file.fish b/functions/_fzf_preview_changed_file.fish index ebe863d3..a13219b2 100644 --- a/functions/_fzf_preview_changed_file.fish +++ b/functions/_fzf_preview_changed_file.fish @@ -32,7 +32,7 @@ function _fzf_preview_changed_file --argument-names path_status --description "S # https://stackoverflow.com/questions/73954214 if test $index_status = R # diff the post-rename path with the original path, otherwise the diff will show the entire file as being added - set orig_and_new_path (string split -- ' -> ' $path) + set orig_and_new_path (string split --max 1 -- ' -> ' $path) git diff --staged $diff_opts -- $orig_and_new_path[1] $orig_and_new_path[2] # path currently has the form of "original -> current", so we need to correct it before it's used below set path $orig_and_new_path[2]