]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'fc/zsh-completion'
authorJunio C Hamano <gitster@pobox.com>
Mon, 9 Nov 2020 22:06:29 +0000 (14:06 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Nov 2020 22:06:29 +0000 (14:06 -0800)
Zsh autocompletion (in contrib/) update.

* fc/zsh-completion: (29 commits)
  zsh: update copyright notices
  completion: bash: remove old compat wrappers
  completion: bash: cleanup cygwin check
  completion: bash: trivial cleanup
  completion: zsh: add simple version check
  completion: zsh: trivial simplification
  completion: zsh: add alias descriptions
  completion: zsh: improve command tags
  completion: zsh: refactor command completion
  completion: zsh: shuffle functions around
  completion: zsh: simplify file_direct
  completion: zsh: simplify nl_append
  completion: zsh: trivial cleanup
  completion: zsh: simplify direct compadd
  completion: zsh: simplify compadd functions
  completion: zsh: fix splitting of words
  completion: zsh: add missing direct_append
  completion: fix conflict with bashcomp
  completion: zsh: fix completion for --no-.. options
  completion: bash: remove zsh wrapper
  ...

1  2 
contrib/completion/git-completion.bash
t/t9902-completion.sh

index 36f5a91c7a9859c2fa9a976b0f663b2c7fb31cf8,49a6ef423683f3ee253175b6f2cb28ee2173ed87..7c81e4ba497fb6ab1b9b32a40336f5995b0b5b55
@@@ -416,14 -416,13 +416,13 @@@ __gitcomp_builtin (
        local options
        eval "options=\${$var-}"
  
-       local completion_helper
-       if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
-               completion_helper="--git-completion-helper-all"
-       else
-               completion_helper="--git-completion-helper"
-       fi
        if [ -z "$options" ]; then
+               local completion_helper
+               if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
+                       completion_helper="--git-completion-helper-all"
+               else
+                       completion_helper="--git-completion-helper"
+               fi
                # leading and trailing spaces are significant to make
                # option removal work correctly.
                options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
@@@ -1467,15 -1466,14 +1466,15 @@@ _git_bundle (
  # Helper function to decide whether or not we should enable DWIM logic for
  # git-switch and git-checkout.
  #
 -# To decide between the following rules in priority order
 -# 1) the last provided of "--guess" or "--no-guess" explicitly enable or
 -#    disable completion of DWIM logic respectively.
 -# 2) If the --no-track option is provided, take this as a hint to disable the
 -#    DWIM completion logic
 -# 3) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
 -#    logic, as requested by the user.
 -# 4) Enable DWIM logic otherwise.
 +# To decide between the following rules in decreasing priority order:
 +# - the last provided of "--guess" or "--no-guess" explicitly enable or
 +#   disable completion of DWIM logic respectively.
 +# - If checkout.guess is false, disable completion of DWIM logic.
 +# - If the --no-track option is provided, take this as a hint to disable the
 +#   DWIM completion logic
 +# - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
 +#   logic, as requested by the user.
 +# - Enable DWIM logic otherwise.
  #
  __git_checkout_default_dwim_mode ()
  {
        fi
  
        # --no-track disables DWIM, but with lower priority than
 -      # --guess/--no-guess
 +      # --guess/--no-guess/checkout.guess
        if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
                dwim_opt=""
        fi
  
 +      # checkout.guess = false disables DWIM, but with lower priority than
 +      # --guess/--no-guess
 +      if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
 +              dwim_opt=""
 +      fi
 +
        # Find the last provided --guess or --no-guess
        last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
        case "$last_option" in
@@@ -1695,13 -1687,8 +1694,13 @@@ __git_diff_common_options="--stat --num
                        --submodule --submodule= --ignore-submodules
                        --indent-heuristic --no-indent-heuristic
                        --textconv --no-textconv
 +                      --patch --no-patch
  "
  
 +__git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex
 +                      --base --ours --theirs --no-index --relative --merge-base
 +                      $__git_diff_common_options"
 +
  _git_diff ()
  {
        __git_has_doubledash && return
                return
                ;;
        --*)
 -              __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
 -                      --base --ours --theirs --no-index
 -                      $__git_diff_common_options
 -                      "
 +              __gitcomp "$__git_diff_difftool_options"
                return
                ;;
        esac
@@@ -1746,7 -1736,11 +1745,7 @@@ _git_difftool (
                return
                ;;
        --*)
 -              __gitcomp_builtin difftool "$__git_diff_common_options
 -                                      --base --cached --ours --theirs
 -                                      --pickaxe-all --pickaxe-regex
 -                                      --relative --staged
 -                                      "
 +              __gitcomp_builtin difftool "$__git_diff_difftool_options"
                return
                ;;
        esac
@@@ -2036,9 -2030,11 +2035,9 @@@ _git_log (
                        --no-walk --no-walk= --do-walk
                        --parents --children
                        --expand-tabs --expand-tabs= --no-expand-tabs
 -                      --patch
                        $merge
                        $__git_diff_common_options
                        --pickaxe-all --pickaxe-regex
 -                      --patch --no-patch
                        "
                return
                ;;
@@@ -2941,7 -2937,7 +2940,7 @@@ _git_show (
                ;;
        --*)
                __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
 -                      --oneline --show-signature --patch
 +                      --oneline --show-signature
                        --expand-tabs --expand-tabs= --no-expand-tabs
                        $__git_diff_common_options
                        "
@@@ -3024,10 -3020,7 +3023,10 @@@ _git_stash (
                list,--*)
                        __gitcomp "--name-status --oneline --patch-with-stat"
                        ;;
 -              show,--*|branch,--*)
 +              show,--*)
 +                      __gitcomp "$__git_diff_common_options"
 +                      ;;
 +              branch,--*)
                        ;;
                branch,*)
                        if [ $cword -eq 3 ]; then
@@@ -3464,88 -3457,8 +3463,8 @@@ __gitk_main (
        __git_complete_revlist
  }
  
- if [[ -n ${ZSH_VERSION-} ]] &&
-    # Don't define these functions when sourced from 'git-completion.zsh',
-    # it has its own implementations.
-    [[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
-       echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
-       autoload -U +X compinit && compinit
-       __gitcomp ()
-       {
-               emulate -L zsh
-               local cur_="${3-$cur}"
-               case "$cur_" in
-               --*=)
-                       ;;
-               *)
-                       local c IFS=$' \t\n'
-                       local -a array
-                       for c in ${=1}; do
-                               c="$c${4-}"
-                               case $c in
-                               --*=*|*.) ;;
-                               *) c="$c " ;;
-                               esac
-                               array[${#array[@]}+1]="$c"
-                       done
-                       compset -P '*[=:]'
-                       compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
-                       ;;
-               esac
-       }
-       __gitcomp_direct ()
-       {
-               emulate -L zsh
-               local IFS=$'\n'
-               compset -P '*[=:]'
-               compadd -Q -- ${=1} && _ret=0
-       }
-       __gitcomp_nl ()
-       {
-               emulate -L zsh
-               local IFS=$'\n'
-               compset -P '*[=:]'
-               compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
-       }
-       __gitcomp_file_direct ()
-       {
-               emulate -L zsh
-               local IFS=$'\n'
-               compset -P '*[=:]'
-               compadd -f -- ${=1} && _ret=0
-       }
-       __gitcomp_file ()
-       {
-               emulate -L zsh
-               local IFS=$'\n'
-               compset -P '*[=:]'
-               compadd -p "${2-}" -f -- ${=1} && _ret=0
-       }
-       _git ()
-       {
-               local _ret=1 cur cword prev
-               cur=${words[CURRENT]}
-               prev=${words[CURRENT-1]}
-               let cword=CURRENT-1
-               emulate ksh -c __${service}_main
-               let _ret && _default && _ret=0
-               return _ret
-       }
-       compdef _git git gitk
+ if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
+       echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
        return
  fi
  
@@@ -3567,18 -3480,6 +3486,6 @@@ __git_complete (
                || complete -o default -o nospace -F $wrapper $1
  }
  
- # wrapper for backwards compatibility
- _git ()
- {
-       __git_wrap__git_main
- }
- # wrapper for backwards compatibility
- _gitk ()
- {
-       __git_wrap__gitk_main
- }
  __git_complete git __git_main
  __git_complete gitk __gitk_main
  
  # when the user has tab-completed the executable name and consequently
  # included the '.exe' suffix.
  #
- if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
- __git_complete git.exe __git_main
+ if [ "$OSTYPE" = cygwin ]; then
      __git_complete git.exe __git_main
  fi
diff --combined t/t9902-completion.sh
index 4e943393cffa48a4c4b520d74ef2ff48c6f84f11,caf4e9101f99c5567caef5c02689a105a6f0d86f..2be9190425bb1dc6f9ab0eb1b8e030c99e0d2920
@@@ -1,6 -1,6 +1,6 @@@
  #!/bin/sh
  #
- # Copyright (c) 2012 Felipe Contreras
+ # Copyright (c) 2012-2020 Felipe Contreras
  #
  
  test_description='test bash completion'
@@@ -1055,13 -1055,13 +1055,13 @@@ test_expect_success 'teardown after fil
        git -C otherrepo branch -D matching/branch-in-other
  '
  
 -test_expect_success '__git_refs - for-each-ref format specifiers in prefix' '
 +test_expect_success PREPARE_FOR_MAIN_BRANCH '__git_refs - for-each-ref format specifiers in prefix' '
        cat >expected <<-EOF &&
        evil-%%-%42-%(refname)..master
        EOF
        (
 -              cur="evil-%%-%42-%(refname)..mas" &&
 -              __git_refs "" "" "evil-%%-%42-%(refname).." mas >"$actual"
 +              cur="evil-%%-%42-%(refname)..mai" &&
 +              __git_refs "" "" "evil-%%-%42-%(refname).." mai >"$actual"
        ) &&
        test_cmp expected "$actual"
  '
@@@ -1360,58 -1360,6 +1360,58 @@@ test_expect_success 'git checkout - a l
        EOF
  '
  
 +test_expect_success 'git checkout - with checkout.guess = false, only completes refs' '
 +      test_config checkout.guess false &&
 +      test_completion "git checkout " <<-\EOF
 +      HEAD Z
 +      master Z
 +      matching-branch Z
 +      matching-tag Z
 +      other/branch-in-other Z
 +      other/master-in-other Z
 +      EOF
 +'
 +
 +test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' '
 +      test_config checkout.guess true &&
 +      test_completion "git checkout " <<-\EOF
 +      HEAD Z
 +      branch-in-other Z
 +      master Z
 +      master-in-other Z
 +      matching-branch Z
 +      matching-tag Z
 +      other/branch-in-other Z
 +      other/master-in-other Z
 +      EOF
 +'
 +
 +test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' '
 +      test_config checkout.guess false &&
 +      test_completion "git checkout --guess " <<-\EOF
 +      HEAD Z
 +      branch-in-other Z
 +      master Z
 +      master-in-other Z
 +      matching-branch Z
 +      matching-tag Z
 +      other/branch-in-other Z
 +      other/master-in-other Z
 +      EOF
 +'
 +
 +test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' '
 +      test_config checkout.guess true &&
 +      test_completion "git checkout --no-guess " <<-\EOF
 +      HEAD Z
 +      master Z
 +      matching-branch Z
 +      matching-tag Z
 +      other/branch-in-other Z
 +      other/master-in-other Z
 +      EOF
 +'
 +
  test_expect_success 'git switch - with --detach, complete all references' '
        test_completion "git switch --detach " <<-\EOF
        HEAD Z