diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index cdcf8b9c37..a46c176e18 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -436,11 +436,11 @@ __git_ls_files_helper () { if [ "$2" == "--committable" ]; then __git -C "$1" -c core.quotePath=false diff-index \ - --name-only --relative HEAD + --name-only --relative HEAD -- "${3//\\/\\\\}*" else # NOTE: $2 is not quoted in order to support multiple options __git -C "$1" -c core.quotePath=false ls-files \ - --exclude-standard $2 + --exclude-standard $2 -- "${3//\\/\\\\}*" fi } @@ -451,11 +451,12 @@ __git_ls_files_helper () # If provided, only files within the specified directory are listed. # Sub directories are never recursed. Path must have a trailing # slash. +# 3: List only paths matching this path component (optional). __git_index_files () { - local root="$2" file + local root="$2" match="$3" file - __git_ls_files_helper "$root" "$1" | + __git_ls_files_helper "$root" "$1" "$match" | while read -r file; do case "$file" in ?*/*) echo "${file%%/*}" ;; @@ -483,7 +484,7 @@ __git_complete_index_file () cur_="$dequoted_word" esac - __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_" + __gitcomp_file "$(__git_index_files "$1" "$pfx" "$cur_")" "$pfx" "$cur_" } # Lists branches from the local repository. diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index f8fcedae2c..562c88e9a9 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1515,6 +1515,7 @@ test_expect_success 'complete files - UTF-8 in ls-files output' ' "árvíztűrő/Сайн яваарай" ' +# Testing with a path containing a backslash is important. if test_have_prereq !MINGW && mkdir 'New\Dir' 2>/dev/null && touch 'New\Dir/New"File.c' 2>/dev/null