From 62526a3ac8e1b189d04032d7b997c5dd6968de75 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 8 Mar 2019 16:03:08 +0100 Subject: [PATCH] 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] --- share/completions/git.fish | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/share/completions/git.fish b/share/completions/git.fish index 067143253..3edea1aa2 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -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