completions/git: Fix relative paths for older git

If the first file presented was in the current directory, this would
error out.

Fixes #5728.

[ci skip]
This commit is contained in:
Fabian Homborg 2019-03-08 16:03:08 +01:00
parent 49ba7f8c01
commit 62526a3ac8

View file

@ -272,7 +272,6 @@ function __fish_git_files
# Cache the previous relative path because these are sorted, so we can reuse it
# often for files in the same directory.
set -l previous
set -l previousfile
# Note that we can't use space as a delimiter between status and filename, because
# the status can contain spaces - " M" is different from "M ".
command git $git_opt status --porcelain -z $status_opt \
@ -356,8 +355,14 @@ function __fish_git_files
# Computing relative path by hand.
set -l abs (string split / -- $relfile)
# If it's in the same directory, we just need to change the filename.
if test "$abs[1..-2]" = "$previousfile[1..-2]"
set previous[-1] $abs[-1]
if test "$abs[1..-2]" = "$previous[1..-2]"
# If we didn't have a previous file, and the current file is in the current directory,
# this would error out.
#
# See #5728.
set -q previous[1]
and set previous[-1] $abs[-1]
or set previous $abs
else
set -l pwd_list $_pwd_list
# Remove common prefix