Merge branch 'jk/clone-local'
[gitweb.git] / contrib / completion / git-completion.bash
index 9f56ec7a6bde4b195b6e960e38e5403ce0b001b0..2e1b5e14b92fe61e02df94ab165c8aab6c06c9cb 100755 (executable)
@@ -676,9 +676,7 @@ __git_complete_revlist_file ()
                *)   pfx="$ref:$pfx" ;;
                esac
 
-               local IFS=$'\n'
-               COMPREPLY=($(compgen -P "$pfx" \
-                       -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
+               __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
                                | sed '/^100... blob /{
                                           s,^.*        ,,
                                           s,$, ,
@@ -692,7 +690,7 @@ __git_complete_revlist_file ()
                                           s,$,/,
                                       }
                                       s/^.*    //')" \
-                       -- "$cur_"))
+                       "$pfx" "$cur_" ""
                ;;
        *...*)
                pfx="${cur_%...*}..."
@@ -848,6 +846,8 @@ __git_list_porcelain_commands ()
                checkout-index)   : plumbing;;
                commit-tree)      : plumbing;;
                count-objects)    : infrequent;;
+               credential-cache) : credentials helper;;
+               credential-store) : credentials helper;;
                cvsexportcommit)  : export;;
                cvsimport)        : import;;
                cvsserver)        : daemon;;
@@ -2599,25 +2599,10 @@ _git_whatchanged ()
        _git_log
 }
 
-_git ()
+__git_main ()
 {
        local i c=1 command __git_dir
 
-       if [[ -n ${ZSH_VERSION-} ]]; then
-               emulate -L bash
-               setopt KSH_TYPESET
-
-               # workaround zsh's bug that leaves 'words' as a special
-               # variable in versions < 4.3.12
-               typeset -h words
-
-               # workaround zsh's bug that quotes spaces in the COMPREPLY
-               # array if IFS doesn't contain spaces.
-               typeset -h IFS
-       fi
-
-       local cur words cword prev
-       _get_comp_words_by_ref -n =: cur words cword prev
        while [ $c -lt $cword ]; do
                i="${words[c]}"
                case "$i" in
@@ -2665,24 +2650,8 @@ _git ()
        fi
 }
 
-_gitk ()
+__gitk_main ()
 {
-       if [[ -n ${ZSH_VERSION-} ]]; then
-               emulate -L bash
-               setopt KSH_TYPESET
-
-               # workaround zsh's bug that leaves 'words' as a special
-               # variable in versions < 4.3.12
-               typeset -h words
-
-               # workaround zsh's bug that quotes spaces in the COMPREPLY
-               # array if IFS doesn't contain spaces.
-               typeset -h IFS
-       fi
-
-       local cur words cword prev
-       _get_comp_words_by_ref -n =: cur words cword prev
-
        __git_has_doubledash && return
 
        local g="$(__gitdir)"
@@ -2703,16 +2672,55 @@ _gitk ()
        __git_complete_revlist
 }
 
-complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
-       || complete -o default -o nospace -F _git git
-complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
-       || complete -o default -o nospace -F _gitk gitk
+__git_func_wrap ()
+{
+       if [[ -n ${ZSH_VERSION-} ]]; then
+               emulate -L bash
+               setopt KSH_TYPESET
+
+               # workaround zsh's bug that leaves 'words' as a special
+               # variable in versions < 4.3.12
+               typeset -h words
+
+               # workaround zsh's bug that quotes spaces in the COMPREPLY
+               # array if IFS doesn't contain spaces.
+               typeset -h IFS
+       fi
+       local cur words cword prev
+       _get_comp_words_by_ref -n =: cur words cword prev
+       $1
+}
+
+# Setup completion for certain functions defined above by setting common
+# variables and workarounds.
+# This is NOT a public function; use at your own risk.
+__git_complete ()
+{
+       local wrapper="__git_wrap${2}"
+       eval "$wrapper () { __git_func_wrap $2 ; }"
+       complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
+               || 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
 
 # The following are necessary only for Cygwin, and only are needed
 # when the user has tab-completed the executable name and consequently
 # included the '.exe' suffix.
 #
 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
-complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
-       || complete -o default -o nospace -F _git git.exe
+__git_complete git.exe __git_main
 fi