Merge branch 'fg/completion-external'
authorJunio C Hamano <gitster@pobox.com>
Wed, 23 May 2018 05:38:25 +0000 (14:38 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 May 2018 05:38:25 +0000 (14:38 +0900)
The command line completion mechanism (in contrib/) learned to load
custom completion file for "git $command" where $command is a
custom "git-$command" that the end user has on the $PATH when using
newer version of bash.

* fg/completion-external:
completion: load completion file for external subcommand

1  2 
contrib/completion/git-completion.bash
index f2f331120bd2c132f90dcf314a9c5065781659b7,604ba2b039a240ea868fdb2e4667055e607ad181..961a0ed76f89133dc01fc86a07be37eb5728651a
@@@ -29,8 -29,6 +29,8 @@@
  # tell the completion to use commit completion.  This also works with aliases
  # of form "!sh -c '...'".  For example, "!sh -c ': git commit ; ... '".
  #
 +# Compatible with bash 3.2.57.
 +#
  # You can set the following environment variables to influence the behavior of
  # the completion routines:
  #
@@@ -284,11 -282,7 +284,11 @@@ __gitcomp (
  
  # Clear the variables caching builtins' options when (re-)sourcing
  # the completion script.
 -unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
 +if [[ -n ${ZSH_VERSION-} ]]; then
 +      unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
 +else
 +      unset $(compgen -v __gitcomp_builtin_)
 +fi
  
  # This function is equivalent to
  #
@@@ -394,7 -388,12 +394,7 @@@ __git_index_files (
        local root="${2-.}" file
  
        __git_ls_files_helper "$root" "$1" |
 -      while read -r file; do
 -              case "$file" in
 -              ?*/*) echo "${file%%/*}" ;;
 -              *) echo "$file" ;;
 -              esac
 -      done | sort | uniq
 +      cut -f1 -d/ | sort | uniq
  }
  
  # Lists branches from the local repository.
@@@ -879,7 -878,6 +879,7 @@@ __git_list_porcelain_commands (
                check-ref-format) : plumbing;;
                checkout-index)   : plumbing;;
                column)           : internal helper;;
 +              commit-graph)     : plumbing;;
                commit-tree)      : plumbing;;
                count-objects)    : infrequent;;
                credential)       : credentials;;
@@@ -1286,12 -1284,6 +1286,12 @@@ _git_checkout (
  
  _git_cherry ()
  {
 +      case "$cur" in
 +      --*)
 +              __gitcomp_builtin cherry
 +              return
 +      esac
 +
        __git_complete_refs
  }
  
@@@ -1511,6 -1503,16 +1511,6 @@@ _git_fsck (
        esac
  }
  
 -_git_gc ()
 -{
 -      case "$cur" in
 -      --*)
 -              __gitcomp_builtin gc
 -              return
 -              ;;
 -      esac
 -}
 -
  _git_gitk ()
  {
        _gitk
@@@ -1635,13 -1637,6 +1635,13 @@@ _git_ls_remote (
  
  _git_ls_tree ()
  {
 +      case "$cur" in
 +      --*)
 +              __gitcomp_builtin ls-tree
 +              return
 +              ;;
 +      esac
 +
        __git_complete_file
  }
  
@@@ -1817,6 -1812,11 +1817,6 @@@ _git_mv (
        fi
  }
  
 -_git_name_rev ()
 -{
 -      __gitcomp_builtin name-rev
 -}
 -
  _git_notes ()
  {
        local subcommands='add append copy edit get-ref list merge prune remove show'
@@@ -1949,7 -1949,7 +1949,7 @@@ _git_rebase (
        --*)
                __gitcomp "
                        --onto --merge --strategy --interactive
 -                      --preserve-merges --stat --no-stat
 +                      --rebase-merges --preserve-merges --stat --no-stat
                        --committer-date-is-author-date --ignore-date
                        --ignore-whitespace --whitespace=
                        --autosquash --no-autosquash
@@@ -2120,7 -2120,7 +2120,7 @@@ _git_config (
                return
                ;;
        branch.*.rebase)
 -              __gitcomp "false true preserve interactive"
 +              __gitcomp "false true merges preserve interactive"
                return
                ;;
        remote.pushdefault)
                __gitcomp "$__git_log_date_formats"
                return
                ;;
 -      sendemail.aliasesfiletype)
 +      sendemail.aliasfiletype)
                __gitcomp "mutt mailrc pine elm gnus"
                return
                ;;
                core.bigFileThreshold
                core.checkStat
                core.commentChar
 +              core.commitGraph
                core.compression
                core.createObject
                core.deltaBaseCacheLimit
@@@ -2775,21 -2774,13 +2775,21 @@@ _git_show_branch (
  _git_stash ()
  {
        local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
 -      local subcommands='push save list show apply clear drop pop create branch'
 -      local subcommand="$(__git_find_on_cmdline "$subcommands")"
 +      local subcommands='push list show apply clear drop pop create branch'
 +      local subcommand="$(__git_find_on_cmdline "$subcommands save")"
 +      if [ -n "$(__git_find_on_cmdline "-p")" ]; then
 +              subcommand="push"
 +      fi
        if [ -z "$subcommand" ]; then
                case "$cur" in
                --*)
                        __gitcomp "$save_opts"
                        ;;
 +              sa*)
 +                      if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
 +                              __gitcomp "save"
 +                      fi
 +                      ;;
                *)
                        if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
                                __gitcomp "$subcommands"
@@@ -3045,45 -3036,6 +3045,52 @@@ _git_worktree (
        fi
  }
  
-       if declare -f $completion_func >/dev/null 2>/dev/null; then
 +__git_complete_common () {
 +      local command="$1"
 +
 +      case "$cur" in
 +      --*)
 +              __gitcomp_builtin "$command"
 +              ;;
 +      esac
 +}
 +
 +__git_cmds_with_parseopt_helper=
 +__git_support_parseopt_helper () {
 +      test -n "$__git_cmds_with_parseopt_helper" ||
 +              __git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
 +
 +      case " $__git_cmds_with_parseopt_helper " in
 +      *" $1 "*)
 +              return 0
 +              ;;
 +      *)
 +              return 1
 +              ;;
 +      esac
 +}
 +
 +__git_complete_command () {
 +      local command="$1"
 +      local completion_func="_git_${command//-/_}"
-       elif __git_support_parseopt_helper "$command"; then
++      if ! declare -f $completion_func >/dev/null 2>/dev/null &&
++              declare -f _completion_loader >/dev/null 2>/dev/null
++      then
++              _completion_loader "git-$command"
++      fi
++      if declare -f $completion_func >/dev/null 2>/dev/null
++      then
 +              $completion_func
 +              return 0
++      elif __git_support_parseopt_helper "$command"
++      then
 +              __git_complete_common "$command"
 +              return 0
 +      else
 +              return 1
 +      fi
 +}
 +
  __git_main ()
  {
        local i c=1 command __git_dir __git_repo_path
                return
        fi
  
 -      local completion_func="_git_${command//-/_}"
 -      if ! declare -f $completion_func >/dev/null 2>/dev/null &&
 -              declare -f _completion_loader >/dev/null 2>/dev/null
 -      then
 -              _completion_loader "git-$command"
 -      fi
 -      declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
 +      __git_complete_command "$command" && return
  
        local expansion=$(__git_aliased_command "$command")
        if [ -n "$expansion" ]; then
                words[1]=$expansion
 -              completion_func="_git_${expansion//-/_}"
 -              if ! declare -f $completion_func >/dev/null 2>/dev/null &&
 -                      declare -f _completion_loader >/dev/null 2>/dev/null
 -              then
 -                      _completion_loader "git-$expansion"
 -              fi
 -              declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
 +              __git_complete_command "$expansion"
        fi
  }