Merge branch 'cy/zsh-completion-SP-in-path'

With zsh, "git cmd path<TAB>" was completed to "git cmd path name"
when the completed path has a special character like SP in it,
without any attempt to keep "path name" a single filename.  This
has been fixed to complete it to "git cmd path\ name" just like
Bash completion does.

* cy/zsh-completion-SP-in-path:
  completion: treat results of git ls-tree as file paths
  zsh: complete unquoted paths with spaces correctly
This commit is contained in:
Junio C Hamano
2019-01-18 13:49:54 -08:00
3 changed files with 21 additions and 28 deletions

View File

@ -855,7 +855,7 @@ __git_compute_merge_strategies ()
__git_complete_revlist_file () __git_complete_revlist_file ()
{ {
local pfx ls ref cur_="$cur" local dequoted_word pfx ls ref cur_="$cur"
case "$cur_" in case "$cur_" in
*..?*:*) *..?*:*)
return return
@ -863,14 +863,18 @@ __git_complete_revlist_file ()
?*:*) ?*:*)
ref="${cur_%%:*}" ref="${cur_%%:*}"
cur_="${cur_#*:}" cur_="${cur_#*:}"
case "$cur_" in
__git_dequote "$cur_"
case "$dequoted_word" in
?*/*) ?*/*)
pfx="${cur_%/*}" pfx="${dequoted_word%/*}"
cur_="${cur_##*/}" cur_="${dequoted_word##*/}"
ls="$ref:$pfx" ls="$ref:$pfx"
pfx="$pfx/" pfx="$pfx/"
;; ;;
*) *)
cur_="$dequoted_word"
ls="$ref" ls="$ref"
;; ;;
esac esac
@ -880,21 +884,10 @@ __git_complete_revlist_file ()
*) pfx="$ref:$pfx" ;; *) pfx="$ref:$pfx" ;;
esac esac
__gitcomp_nl "$(__git ls-tree "$ls" \ __gitcomp_file "$(__git ls-tree "$ls" \
| sed '/^100... blob /{ | sed 's/^.* //
s,^.* ,, s/$//')" \
s,$, , "$pfx" "$cur_"
}
/^120000 blob /{
s,^.* ,,
s,$, ,
}
/^040000 tree /{
s,^.* ,,
s,$,/,
}
s/^.* //')" \
"$pfx" "$cur_" ""
;; ;;
*...*) *...*)
pfx="${cur_%...*}..." pfx="${cur_%...*}..."
@ -2993,7 +2986,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
local IFS=$'\n' local IFS=$'\n'
compset -P '*[=:]' compset -P '*[=:]'
compadd -Q -f -- ${=1} && _ret=0 compadd -f -- ${=1} && _ret=0
} }
__gitcomp_file () __gitcomp_file ()
@ -3002,7 +2995,7 @@ if [[ -n ${ZSH_VERSION-} ]] &&
local IFS=$'\n' local IFS=$'\n'
compset -P '*[=:]' compset -P '*[=:]'
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 compadd -p "${2-}" -f -- ${=1} && _ret=0
} }
_git () _git ()

View File

@ -99,7 +99,7 @@ __gitcomp_file_direct ()
local IFS=$'\n' local IFS=$'\n'
compset -P '*[=:]' compset -P '*[=:]'
compadd -Q -f -- ${=1} && _ret=0 compadd -f -- ${=1} && _ret=0
} }
__gitcomp_file () __gitcomp_file ()
@ -108,7 +108,7 @@ __gitcomp_file ()
local IFS=$'\n' local IFS=$'\n'
compset -P '*[=:]' compset -P '*[=:]'
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 compadd -p "${2-}" -f -- ${=1} && _ret=0
} }
__git_zsh_bash_func () __git_zsh_bash_func ()

View File

@ -1516,8 +1516,8 @@ test_expect_success 'show completes all refs' '
test_expect_success '<ref>: completes paths' ' test_expect_success '<ref>: completes paths' '
test_completion "git show mytag:f" <<-\EOF test_completion "git show mytag:f" <<-\EOF
file1 Z file1Z
file2 Z file2Z
EOF EOF
' '
@ -1526,7 +1526,7 @@ test_expect_success 'complete tree filename with spaces' '
git add "name with spaces" && git add "name with spaces" &&
git commit -m spaces && git commit -m spaces &&
test_completion "git show HEAD:nam" <<-\EOF test_completion "git show HEAD:nam" <<-\EOF
name with spaces Z name with spacesZ
EOF EOF
' '
@ -1535,8 +1535,8 @@ test_expect_success 'complete tree filename with metacharacters' '
git add "name with \${meta}" && git add "name with \${meta}" &&
git commit -m meta && git commit -m meta &&
test_completion "git show HEAD:nam" <<-\EOF test_completion "git show HEAD:nam" <<-\EOF
name with ${meta} Z name with ${meta}Z
name with spaces Z name with spacesZ
EOF EOF
' '