Merge branch 'cy/zsh-completion-SP-in-path'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2019 21:49:54 +0000 (13:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2019 21:49:54 +0000 (13:49 -0800)
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

1  2 
contrib/completion/git-completion.bash
t/t9902-completion.sh
index 86a9719a51f37bf2c89b6c7ad6c45370ba3b0225,26ea310fdac606cde6ca1f1e191c09d93473025f..499e56f83d0a0592abd53686612c79358780eef2
@@@ -438,7 -438,7 +438,7 @@@ __gitcomp_nl (
  # Callers must take care of providing only paths that match the current path
  # to be completed and adding any prefix path components, if necessary.
  # 1: List of newline-separated matching paths, complete with all prefix
 -#    path componens.
 +#    path components.
  __gitcomp_file_direct ()
  {
        local IFS=$'\n'
@@@ -855,7 -855,7 +855,7 @@@ __git_compute_merge_strategies (
  
  __git_complete_revlist_file ()
  {
-       local pfx ls ref cur_="$cur"
+       local dequoted_word pfx ls ref cur_="$cur"
        case "$cur_" in
        *..?*:*)
                return
        ?*:*)
                ref="${cur_%%:*}"
                cur_="${cur_#*:}"
-               case "$cur_" in
+               __git_dequote "$cur_"
+               case "$dequoted_word" in
                ?*/*)
-                       pfx="${cur_%/*}"
-                       cur_="${cur_##*/}"
+                       pfx="${dequoted_word%/*}"
+                       cur_="${dequoted_word##*/}"
                        ls="$ref:$pfx"
                        pfx="$pfx/"
                        ;;
                *)
+                       cur_="$dequoted_word"
                        ls="$ref"
                        ;;
                esac
                *)   pfx="$ref:$pfx" ;;
                esac
  
-               __gitcomp_nl "$(__git ls-tree "$ls" \
-                               | sed '/^100... blob /{
-                                          s,^.*        ,,
-                                          s,$, ,
-                                      }
-                                      /^120000 blob /{
-                                          s,^.*        ,,
-                                          s,$, ,
-                                      }
-                                      /^040000 tree /{
-                                          s,^.*        ,,
-                                          s,$,/,
-                                      }
-                                      s/^.*    //')" \
-                       "$pfx" "$cur_" ""
+               __gitcomp_file "$(__git ls-tree "$ls" \
+                               | sed 's/^.*    //
+                                      s/$//')" \
+                       "$pfx" "$cur_"
                ;;
        *...*)
                pfx="${cur_%...*}..."
@@@ -2993,7 -2986,7 +2986,7 @@@ if [[ -n ${ZSH_VERSION-} ]] &
  
                local IFS=$'\n'
                compset -P '*[=:]'
-               compadd -Q -f -- ${=1} && _ret=0
+               compadd -f -- ${=1} && _ret=0
        }
  
        __gitcomp_file ()
  
                local IFS=$'\n'
                compset -P '*[=:]'
-               compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+               compadd -p "${2-}" -f -- ${=1} && _ret=0
        }
  
        _git ()
diff --combined t/t9902-completion.sh
index 6558eee4996e21a64a1b43b5d293cab683686429,94157e58793b811cefc0751fa2daeac8d6036421..3a2c6326d83b760194c600e2ccde619438200508
@@@ -1434,8 -1434,7 +1434,8 @@@ test_expect_success 'double dash "git c
        --ignore-other-worktrees Z
        --recurse-submodules Z
        --progress Z
 -      --no-quiet Z
 +      --guess Z
 +      --no-guess Z
        --no-... Z
        EOF
  '
@@@ -1516,8 -1515,8 +1516,8 @@@ test_expect_success 'show completes al
  
  test_expect_success '<ref>: completes paths' '
        test_completion "git show mytag:f" <<-\EOF
-       file1 Z
-       file2 Z
+       file1Z
+       file2Z
        EOF
  '
  
@@@ -1526,7 -1525,7 +1526,7 @@@ test_expect_success 'complete tree file
        git add "name with spaces" &&
        git commit -m spaces &&
        test_completion "git show HEAD:nam" <<-\EOF
-       name with spaces Z
+       name with spacesZ
        EOF
  '
  
@@@ -1535,8 -1534,8 +1535,8 @@@ test_expect_success 'complete tree file
        git add "name with \${meta}" &&
        git commit -m meta &&
        test_completion "git show HEAD:nam" <<-\EOF
-       name with ${meta} Z
-       name with spaces Z
+       name with ${meta}Z
+       name with spacesZ
        EOF
  '