completion: support completing non-ASCII pathnames
authorSZEDER Gábor <szeder.dev@gmail.com>
Mon, 16 Apr 2018 22:41:08 +0000 (00:41 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Apr 2018 03:49:36 +0000 (12:49 +0900)
Unless the user has 'core.quotePath=false' somewhere in the
configuration, both 'git ls-files' and 'git diff-index' will by
default quote any pathnames that contain bytes with values higher than
0x80, and escape those bytes as '\nnn' octal values. This prevents
completing paths when the current path component to be completed
contains any non-ASCII, most notably UTF-8, characters, because none
of the listed quoted paths will match the current word on the command
line.

Set 'core.quotePath=false' for those 'git ls-files' and 'git
diff-index' invocations, so they won't consider bytes higher than 0x80
as "unusual", and won't quote pathnames containing such characters.

Note that pathnames containing backslash, double quote, or control
characters will still be quoted; a later patch in this series will
deal with those.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
t/t9902-completion.sh
index 57fc7417f9bfd30710de5d84ca0ef461663b98c4..2a8fe2aa18e087adbcd80a3b17a6a774ababa979 100644 (file)
@@ -371,10 +371,12 @@ __gitcomp_file ()
 __git_ls_files_helper ()
 {
        if [ "$2" == "--committable" ]; then
-               __git -C "$1" diff-index --name-only --relative HEAD
+               __git -C "$1" -c core.quotePath=false diff-index \
+                       --name-only --relative HEAD
        else
                # NOTE: $2 is not quoted in order to support multiple options
-               __git -C "$1" ls-files --exclude-standard $2
+               __git -C "$1" -c core.quotePath=false ls-files \
+                       --exclude-standard $2
        fi
 }
 
index 98a672ce3203cfa8c68529fcc269b9eab3383719..f7d7becbb9fdbb36b2ea32bd461c537c2e3b3274 100755 (executable)
@@ -1463,7 +1463,7 @@ test_expect_failure 'complete files - quoted characters on cmdline' '
                        "New(Dir/New)File.c"
 '
 
-test_expect_failure 'complete files - UTF-8 in ls-files output' '
+test_expect_success 'complete files - UTF-8 in ls-files output' '
        test_when_finished "rm -r árvíztűrő" &&
        mkdir árvíztűrő &&
        >"árvíztűrő/Сайн яваарай" &&