Skip to content

Commit

Permalink
[Search git status] cover all possible unmerged statuses
Browse files Browse the repository at this point in the history
In PatrickF1#262, my research showed
that only 4 of the 7 unmerged statuses listed in git status' help were
possible. However, upon experimentation, I realized all 7 are possible.
The three I left out are easily reproducible by merging two branches
that renamed the same file but to different names. In this commit, I
add them back in.
  • Loading branch information
PatrickF1 committed Oct 4, 2022
1 parent 1a0bf6c commit 309975c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions functions/_fzf_preview_changed_file.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function _fzf_preview_changed_file --argument-names path_status --description "S
# https://fishshell.com/docs/current/fish_for_bash_users.html
set -l path (string unescape (string sub --start 4 $path_status))
# first letter of short format shows index, second letter shows working tree
# https://git-scm.com/docs/git-status/2.35.0#_output
# https://git-scm.com/docs/git-status/2.35.0#_short_format
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
Expand All @@ -18,9 +18,10 @@ function _fzf_preview_changed_file --argument-names path_status --description "S
if test $index_status = '?'
_fzf_report_diff_type Untracked
_fzf_preview_file $path
else if contains {$index_status}$working_tree_status UD DU UU AA
# inferred from # https://stackoverflow.com/questions/22792906/how-do-i-produce-every-possible-git-status
# the above 4 statuses are the only possible ones for a merge conflict
else if contains {$index_status}$working_tree_status DD AU UD UA DU AA UU
# Unmerged statuses taken directly from git status help's short format table
# Unmerged statuses are mutually exclusive with other statuses, so if we see
# these, then safe to assume the path is unmerged
_fzf_report_diff_type Unmerged
git diff $diff_opts -- $path
else
Expand Down

0 comments on commit 309975c

Please sign in to comment.