zsh: complete unquoted paths with spaces correctly
authorChayoung You <yousbe@gmail.com>
Tue, 1 Jan 2019 14:05:08 +0000 (23:05 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Jan 2019 19:48:13 +0000 (11:48 -0800)
The following is the description of -Q flag of zsh compadd [1]:

This flag instructs the completion code not to quote any
metacharacters in the words when inserting them into the command
line.

Let's say there is a file named 'foo bar.txt' in repository, but it's
not yet added to the repository. Then the following command triggers a
completion:

git add fo<Tab>
git add 'fo<Tab>
git add "fo<Tab>

The completion results in bash:

git add foo\ bar.txt
git add 'foo bar.txt'
git add "foo bar.txt"

While them in zsh:

git add foo bar.txt
git add 'foo bar.txt'
git add "foo bar.txt"

The first one, where the pathname is not enclosed in quotes, should
escape the space with a backslash, just like bash completion does.
Otherwise, this leads git to think there are two files; foo, and
bar.txt.

The main cause of this behavior is __gitcomp_file_direct(). The both
implementions of bash and zsh are called with an argument 'foo bar.txt',
but only bash adds a backslash before a space on command line.

[1]: http://zsh.sourceforge.net/Doc/Release/Completion-Widgets.html

Signed-off-by: Chayoung You <yousbe@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
contrib/completion/git-completion.zsh
index 9e8ec95c3c7adb2956435ded43b020532aafa1c2..816ee32805d18aeec46bc78e82cfeea975c43032 100644 (file)
@@ -2993,7 +2993,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
 
                local IFS=$'\n'
                compset -P '*[=:]'
-               compadd -Q -f -- ${=1} && _ret=0
+               compadd -f -- ${=1} && _ret=0
        }
 
        __gitcomp_file ()
@@ -3002,7 +3002,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
 
                local IFS=$'\n'
                compset -P '*[=:]'
-               compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+               compadd -p "${2-}" -f -- ${=1} && _ret=0
        }
 
        _git ()
index 049d6b80f650717f20e68568251c21098f598d80..886bf95d1f5940987f5c4411097fd09b000be037 100644 (file)
@@ -99,7 +99,7 @@ __gitcomp_file_direct ()
 
        local IFS=$'\n'
        compset -P '*[=:]'
-       compadd -Q -f -- ${=1} && _ret=0
+       compadd -f -- ${=1} && _ret=0
 }
 
 __gitcomp_file ()
@@ -108,7 +108,7 @@ __gitcomp_file ()
 
        local IFS=$'\n'
        compset -P '*[=:]'
-       compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+       compadd -p "${2-}" -f -- ${=1} && _ret=0
 }
 
 __git_zsh_bash_func ()