1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 # Compatible with bash 3.2.57.
34 # You can set the following environment variables to influence the behavior of
35 # the completion routines:
37 # GIT_COMPLETION_CHECKOUT_NO_GUESS
39 # When set to "1", do not include "DWIM" suggestions in git-checkout
40 # and git-switch completion (e.g., completing "foo" when "origin/foo"
43 # GIT_COMPLETION_SHOW_ALL
45 # When set to "1" suggest all options, including options which are
46 # typically hidden (e.g. '--allow-empty' for 'git commit').
48 case "$COMP_WORDBREAKS" in
50 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
53 # Discovers the path to the git repository taking any '--git-dir=<path>' and
54 # '-C <path>' options into account and stores it in the $__git_repo_path
56 __git_find_repo_path ()
58 if [ -n "${__git_repo_path-}" ]; then
59 # we already know where it is
63 if [ -n "${__git_C_args-}" ]; then
64 __git_repo_path="$(git "${__git_C_args[@]}" \
65 ${__git_dir:+--git-dir="$__git_dir"} \
66 rev-parse --absolute-git-dir 2>/dev/null)"
67 elif [ -n "${__git_dir-}" ]; then
68 test -d "$__git_dir" &&
69 __git_repo_path="$__git_dir"
70 elif [ -n "${GIT_DIR-}" ]; then
71 test -d "${GIT_DIR-}" &&
72 __git_repo_path="$GIT_DIR"
73 elif [ -d .git ]; then
76 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
80 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
81 # __gitdir accepts 0 or 1 arguments (i.e., location)
82 # returns location of .git repo
85 if [ -z "${1-}" ]; then
86 __git_find_repo_path || return 1
87 echo "$__git_repo_path"
88 elif [ -d "$1/.git" ]; then
95 # Runs git with all the options given as argument, respecting any
96 # '--git-dir=<path>' and '-C <path>' options present on the command line
99 git ${__git_C_args:+"${__git_C_args[@]}"} \
100 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
103 # Removes backslash escaping, single quotes and double quotes from a word,
104 # stores the result in the variable $dequoted_word.
105 # 1: The word to dequote.
108 local rest="$1" len ch
112 while test -n "$rest"; do
113 len=${#dequoted_word}
114 dequoted_word="$dequoted_word${rest%%[\\\'\"]*}"
115 rest="${rest:$((${#dequoted_word}-$len))}"
117 case "${rest:0:1}" in
124 dequoted_word="$dequoted_word$ch"
131 len=${#dequoted_word}
132 dequoted_word="$dequoted_word${rest%%\'*}"
133 rest="${rest:$((${#dequoted_word}-$len+1))}"
137 while test -n "$rest" ; do
138 len=${#dequoted_word}
139 dequoted_word="$dequoted_word${rest%%[\\\"]*}"
140 rest="${rest:$((${#dequoted_word}-$len))}"
141 case "${rest:0:1}" in
146 dequoted_word="$dequoted_word$ch"
151 dequoted_word="$dequoted_word\\$ch"
167 # The following function is based on code from:
169 # bash_completion - programmable completion functions for bash 3.2+
171 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
172 # © 2009-2010, Bash Completion Maintainers
173 # <bash-completion-devel@lists.alioth.debian.org>
175 # This program is free software; you can redistribute it and/or modify
176 # it under the terms of the GNU General Public License as published by
177 # the Free Software Foundation; either version 2, or (at your option)
180 # This program is distributed in the hope that it will be useful,
181 # but WITHOUT ANY WARRANTY; without even the implied warranty of
182 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
183 # GNU General Public License for more details.
185 # You should have received a copy of the GNU General Public License
186 # along with this program; if not, see <http://www.gnu.org/licenses/>.
188 # The latest version of this software can be obtained here:
190 # http://bash-completion.alioth.debian.org/
194 # This function can be used to access a tokenized list of words
195 # on the command line:
197 # __git_reassemble_comp_words_by_ref '=:'
198 # if test "${words_[cword_-1]}" = -w
203 # The argument should be a collection of characters from the list of
204 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
207 # This is roughly equivalent to going back in time and setting
208 # COMP_WORDBREAKS to exclude those characters. The intent is to
209 # make option types like --date=<type> and <rev>:<path> easy to
210 # recognize by treating each shell word as a single token.
212 # It is best not to set COMP_WORDBREAKS directly because the value is
213 # shared with other completion scripts. By the time the completion
214 # function gets called, COMP_WORDS has already been populated so local
215 # changes to COMP_WORDBREAKS have no effect.
217 # Output: words_, cword_, cur_.
219 __git_reassemble_comp_words_by_ref()
221 local exclude i j first
222 # Which word separators to exclude?
223 exclude="${1//[^$COMP_WORDBREAKS]}"
225 if [ -z "$exclude" ]; then
226 words_=("${COMP_WORDS[@]}")
229 # List of word completion separators has shrunk;
230 # re-assemble words to complete.
231 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
232 # Append each nonempty word consisting of just
233 # word separator characters to the current word.
237 [ -n "${COMP_WORDS[$i]}" ] &&
238 # word consists of excluded word separators
239 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
241 # Attach to the previous token,
242 # unless the previous token is the command name.
243 if [ $j -ge 2 ] && [ -n "$first" ]; then
247 words_[$j]=${words_[j]}${COMP_WORDS[i]}
248 if [ $i = $COMP_CWORD ]; then
251 if (($i < ${#COMP_WORDS[@]} - 1)); then
258 words_[$j]=${words_[j]}${COMP_WORDS[i]}
259 if [ $i = $COMP_CWORD ]; then
265 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
266 _get_comp_words_by_ref ()
268 local exclude cur_ words_ cword_
269 if [ "$1" = "-n" ]; then
273 __git_reassemble_comp_words_by_ref "$exclude"
274 cur_=${words_[cword_]}
275 while [ $# -gt 0 ]; do
281 prev=${words_[$cword_-1]}
284 words=("${words_[@]}")
295 # Fills the COMPREPLY array with prefiltered words without any additional
297 # Callers must take care of providing only words that match the current word
298 # to be completed and adding any prefix and/or suffix (trailing space!), if
300 # 1: List of newline-separated matching completion words, complete with
309 # Similar to __gitcomp_direct, but appends to COMPREPLY instead.
310 # Callers must take care of providing only words that match the current word
311 # to be completed and adding any prefix and/or suffix (trailing space!), if
313 # 1: List of newline-separated matching completion words, complete with
315 __gitcomp_direct_append ()
324 local x i=${#COMPREPLY[@]}
326 if [[ "$x" == "$3"* ]]; then
327 COMPREPLY[i++]="$2$x$4"
338 # Generates completion reply, appending a space to possible completion words,
340 # It accepts 1 to 4 arguments:
341 # 1: List of possible completion words.
342 # 2: A prefix to be added to each possible completion word (optional).
343 # 3: Generate possible completion matches for this word (optional).
344 # 4: A suffix to be appended to each possible completion word (optional).
347 local cur_="${3-$cur}"
353 local c i=0 IFS=$' \t\n'
355 if [[ $c == "--" ]]; then
359 if [[ $c == "$cur_"* ]]; then
364 COMPREPLY[i++]="${2-}$c"
369 local c i=0 IFS=$' \t\n'
371 if [[ $c == "--" ]]; then
373 if [[ $c == "$cur_"* ]]; then
374 COMPREPLY[i++]="${2-}$c "
379 if [[ $c == "$cur_"* ]]; then
384 COMPREPLY[i++]="${2-}$c"
391 # Clear the variables caching builtins' options when (re-)sourcing
392 # the completion script.
393 if [[ -n ${ZSH_VERSION-} ]]; then
394 unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
396 unset $(compgen -v __gitcomp_builtin_)
399 # This function is equivalent to
401 # __gitcomp "$(git xxx --git-completion-helper) ..."
403 # except that the output is cached. Accept 1-3 arguments:
404 # 1: the git command to execute, this is also the cache key
405 # 2: extra options to be added on top (e.g. negative forms)
406 # 3: options to be excluded
409 # spaces must be replaced with underscore for multi-word
410 # commands, e.g. "git remote add" becomes remote_add.
415 local var=__gitcomp_builtin_"${cmd/-/_}"
417 eval "options=\${$var-}"
419 local completion_helper
420 if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
421 completion_helper="--git-completion-helper-all"
423 completion_helper="--git-completion-helper"
426 if [ -z "$options" ]; then
427 # leading and trailing spaces are significant to make
428 # option removal work correctly.
429 options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
432 options="${options/ $i / }"
434 eval "$var=\"$options\""
440 # Variation of __gitcomp_nl () that appends to the existing list of
441 # completion candidates, COMPREPLY.
442 __gitcomp_nl_append ()
445 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
448 # Generates completion reply from newline-separated possible completion words
449 # by appending a space to all of them.
450 # It accepts 1 to 4 arguments:
451 # 1: List of possible completion words, separated by a single newline.
452 # 2: A prefix to be added to each possible completion word (optional).
453 # 3: Generate possible completion matches for this word (optional).
454 # 4: A suffix to be appended to each possible completion word instead of
455 # the default space (optional). If specified but empty, nothing is
460 __gitcomp_nl_append "$@"
463 # Fills the COMPREPLY array with prefiltered paths without any additional
465 # Callers must take care of providing only paths that match the current path
466 # to be completed and adding any prefix path components, if necessary.
467 # 1: List of newline-separated matching paths, complete with all prefix
469 __gitcomp_file_direct ()
475 # use a hack to enable file mode in bash < 4
476 compopt -o filenames +o nospace 2>/dev/null ||
477 compgen -f /non-existing-dir/ >/dev/null ||
481 # Generates completion reply with compgen from newline-separated possible
482 # completion filenames.
483 # It accepts 1 to 3 arguments:
484 # 1: List of possible completion filenames, separated by a single newline.
485 # 2: A directory prefix to be added to each possible completion filename
487 # 3: Generate possible completion matches for this word (optional).
492 # XXX does not work when the directory prefix contains a tilde,
493 # since tilde expansion is not applied.
494 # This means that COMPREPLY will be empty and Bash default
495 # completion will be used.
496 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
498 # use a hack to enable file mode in bash < 4
499 compopt -o filenames +o nospace 2>/dev/null ||
500 compgen -f /non-existing-dir/ >/dev/null ||
504 # Execute 'git ls-files', unless the --committable option is specified, in
505 # which case it runs 'git diff-index' to find out the files that can be
506 # committed. It return paths relative to the directory specified in the first
507 # argument, and using the options specified in the second argument.
508 __git_ls_files_helper ()
510 if [ "$2" == "--committable" ]; then
511 __git -C "$1" -c core.quotePath=false diff-index \
512 --name-only --relative HEAD -- "${3//\\/\\\\}*"
514 # NOTE: $2 is not quoted in order to support multiple options
515 __git -C "$1" -c core.quotePath=false ls-files \
516 --exclude-standard $2 -- "${3//\\/\\\\}*"
521 # __git_index_files accepts 1 or 2 arguments:
522 # 1: Options to pass to ls-files (required).
523 # 2: A directory path (optional).
524 # If provided, only files within the specified directory are listed.
525 # Sub directories are never recursed. Path must have a trailing
527 # 3: List only paths matching this path component (optional).
530 local root="$2" match="$3"
532 __git_ls_files_helper "$root" "$1" "${match:-?}" |
533 awk -F / -v pfx="${2//\\/\\\\}" '{
538 if (substr(p, 1, 1) != "\"") {
539 # No special characters, easy!
544 # The path is quoted.
549 # Even when a directory name itself does not contain
550 # any special characters, it will still be quoted if
551 # any of its (stripped) trailing path components do.
552 # Because of this we may have seen the same directory
553 # both quoted and unquoted.
555 # We have seen the same directory unquoted,
562 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
563 # Skip opening double quote.
566 # Interpret backslash escape sequences.
567 while ((bs_idx = index(p, "\\")) != 0) {
568 out = out substr(p, 1, bs_idx - 1)
569 esc = substr(p, bs_idx + 1, 1)
570 p = substr(p, bs_idx + 2)
572 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
573 # C-style one-character escape sequence.
574 out = out substr("\a\b\t\v\f\r\"\\",
576 } else if (esc == "n") {
577 # Uh-oh, a newline character.
578 # We cannot reliably put a pathname
579 # containing a newline into COMPREPLY,
580 # and the newline would create a mess.
584 # Must be a \nnn octal value, then.
586 substr(p, 1, 1) * 8 + \
588 out = out sprintf("%c", dec)
592 # Drop closing double quote, if there is one.
593 # (There is not any if this is a directory, as it was
594 # already stripped with the trailing path components.)
595 if (substr(p, length(p), 1) == "\"")
596 out = out substr(p, 1, length(p) - 1)
604 # __git_complete_index_file requires 1 argument:
605 # 1: the options to pass to ls-file
607 # The exception is --committable, which finds the files appropriate commit.
608 __git_complete_index_file ()
610 local dequoted_word pfx="" cur_
614 case "$dequoted_word" in
616 pfx="${dequoted_word%/*}/"
617 cur_="${dequoted_word##*/}"
620 cur_="$dequoted_word"
623 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
626 # Lists branches from the local repository.
627 # 1: A prefix to be added to each listed branch (optional).
628 # 2: List only branches matching this word (optional; list all branches if
630 # 3: A suffix to be appended to each listed branch (optional).
633 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
635 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
636 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
639 # Lists branches from remote repositories.
640 # 1: A prefix to be added to each listed branch (optional).
641 # 2: List only branches matching this word (optional; list all branches if
643 # 3: A suffix to be appended to each listed branch (optional).
644 __git_remote_heads ()
646 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
648 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
649 "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
652 # Lists tags from the local repository.
653 # Accepts the same positional parameters as __git_heads() above.
656 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
658 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
659 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
662 # List unique branches from refs/remotes used for 'git checkout' and 'git
663 # switch' tracking DWIMery.
664 # 1: A prefix to be added to each listed branch (optional)
665 # 2: List only branches matching this word (optional; list all branches if
667 # 3: A suffix to be appended to each listed branch (optional).
668 __git_dwim_remote_heads ()
670 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
671 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
673 # employ the heuristic used by git checkout and git switch
674 # Try to find a remote branch that cur_es the completion word
675 # but only output if the branch name is unique
676 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
677 --sort="refname:strip=3" \
678 "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
682 # Lists refs from the local (by default) or from a remote repository.
683 # It accepts 0, 1 or 2 arguments:
684 # 1: The remote to list refs from (optional; ignored, if set but empty).
685 # Can be the name of a configured remote, a path, or a URL.
686 # 2: In addition to local refs, list unique branches from refs/remotes/ for
687 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
688 # 3: A prefix to be added to each listed ref (optional).
689 # 4: List only refs matching this word (optional; list all refs if unset or
691 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
694 # Use __git_complete_refs() instead.
697 local i hash dir track="${2-}"
698 local list_refs_from=path remote="${1-}"
700 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
702 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
705 dir="$__git_repo_path"
707 if [ -z "$remote" ]; then
708 if [ -z "$dir" ]; then
712 if __git_is_configured_remote "$remote"; then
713 # configured remote takes precedence over a
714 # local directory with the same name
715 list_refs_from=remote
716 elif [ -d "$remote/.git" ]; then
718 elif [ -d "$remote" ]; then
725 if [ "$list_refs_from" = path ]; then
726 if [[ "$cur_" == ^* ]]; then
735 refs=("$match*" "$match*/**")
739 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
742 if [ -e "$dir/$i" ]; then
748 format="refname:strip=2"
749 refs=("refs/tags/$match*" "refs/tags/$match*/**"
750 "refs/heads/$match*" "refs/heads/$match*/**"
751 "refs/remotes/$match*" "refs/remotes/$match*/**")
754 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
756 if [ -n "$track" ]; then
757 __git_dwim_remote_heads "$pfx" "$match" "$sfx"
763 __git ls-remote "$remote" "$match*" | \
764 while read -r hash i; do
767 *) echo "$pfx$i$sfx" ;;
772 if [ "$list_refs_from" = remote ]; then
774 $match*) echo "${pfx}HEAD$sfx" ;;
776 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
777 "refs/remotes/$remote/$match*" \
778 "refs/remotes/$remote/$match*/**"
782 $match*) query_symref="HEAD" ;;
784 __git ls-remote "$remote" $query_symref \
785 "refs/tags/$match*" "refs/heads/$match*" \
786 "refs/remotes/$match*" |
787 while read -r hash i; do
790 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
791 *) echo "$pfx$i$sfx" ;; # symbolic refs
799 # Completes refs, short and long, local and remote, symbolic and pseudo.
801 # Usage: __git_complete_refs [<option>]...
802 # --remote=<remote>: The remote to list refs from, can be the name of a
803 # configured remote, a path, or a URL.
804 # --dwim: List unique remote branches for 'git switch's tracking DWIMery.
805 # --pfx=<prefix>: A prefix to be added to each ref.
806 # --cur=<word>: The current ref to be completed. Defaults to the current
807 # word to be completed.
808 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
810 # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
811 # complete all refs, 'heads' to complete only branches, or
812 # 'remote-heads' to complete only remote branches. Note that
813 # --remote is only compatible with --mode=refs.
814 __git_complete_refs ()
816 local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
818 while test $# != 0; do
820 --remote=*) remote="${1##--remote=}" ;;
821 --dwim) dwim="yes" ;;
822 # --track is an old spelling of --dwim
823 --track) dwim="yes" ;;
824 --pfx=*) pfx="${1##--pfx=}" ;;
825 --cur=*) cur_="${1##--cur=}" ;;
826 --sfx=*) sfx="${1##--sfx=}" ;;
827 --mode=*) mode="${1##--mode=}" ;;
833 # complete references based on the specified mode
836 __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
838 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
840 __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
845 # Append DWIM remote branch names if requested
846 if [ "$dwim" = "yes" ]; then
847 __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
851 # __git_refs2 requires 1 argument (to pass to __git_refs)
852 # Deprecated: use __git_complete_fetch_refspecs() instead.
856 for i in $(__git_refs "$1"); do
861 # Completes refspecs for fetching from a remote repository.
862 # 1: The remote repository.
863 # 2: A prefix to be added to each listed refspec (optional).
864 # 3: The ref to be completed as a refspec instead of the current word to be
865 # completed (optional)
866 # 4: A suffix to be appended to each listed refspec instead of the default
868 __git_complete_fetch_refspecs ()
870 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
873 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
879 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
880 __git_refs_remotes ()
883 __git ls-remote "$1" 'refs/heads/*' | \
884 while read -r hash i; do
885 echo "$i:refs/remotes/$1/${i#refs/heads/}"
892 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
896 # Returns true if $1 matches the name of a configured remote, false otherwise.
897 __git_is_configured_remote ()
900 for remote in $(__git_remotes); do
901 if [ "$remote" = "$1" ]; then
908 __git_list_merge_strategies ()
910 LANG=C LC_ALL=C git merge -s help 2>&1 |
911 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
920 __git_merge_strategies=
921 # 'git merge -s help' (and thus detection of the merge strategy
922 # list) fails, unfortunately, if run outside of any git working
923 # tree. __git_merge_strategies is set to the empty string in
924 # that case, and the detection will be repeated the next time it
926 __git_compute_merge_strategies ()
928 test -n "$__git_merge_strategies" ||
929 __git_merge_strategies=$(__git_list_merge_strategies)
932 __git_merge_strategy_options="ours theirs subtree subtree= patience
933 histogram diff-algorithm= ignore-space-change ignore-all-space
934 ignore-space-at-eol renormalize no-renormalize no-renames
935 find-renames find-renames= rename-threshold="
937 __git_complete_revlist_file ()
939 local dequoted_word pfx ls ref cur_="$cur"
948 __git_dequote "$cur_"
950 case "$dequoted_word" in
952 pfx="${dequoted_word%/*}"
953 cur_="${dequoted_word##*/}"
958 cur_="$dequoted_word"
963 case "$COMP_WORDBREAKS" in
965 *) pfx="$ref:$pfx" ;;
968 __gitcomp_file "$(__git ls-tree "$ls" \
974 pfx="${cur_%...*}..."
976 __git_complete_refs --pfx="$pfx" --cur="$cur_"
981 __git_complete_refs --pfx="$pfx" --cur="$cur_"
989 __git_complete_file ()
991 __git_complete_revlist_file
994 __git_complete_revlist ()
996 __git_complete_revlist_file
999 __git_complete_remote_or_refspec ()
1001 local cur_="$cur" cmd="${words[1]}"
1002 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
1003 if [ "$cmd" = "remote" ]; then
1006 while [ $c -lt $cword ]; do
1009 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
1010 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
1013 push) no_complete_refspec=1 ;;
1020 --multiple) no_complete_refspec=1; break ;;
1022 *) remote="$i"; break ;;
1026 if [ -z "$remote" ]; then
1027 __gitcomp_nl "$(__git_remotes)"
1030 if [ $no_complete_refspec = 1 ]; then
1033 [ "$remote" = "." ] && remote=
1036 case "$COMP_WORDBREAKS" in
1038 *) pfx="${cur_%%:*}:" ;;
1050 if [ $lhs = 1 ]; then
1051 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
1053 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1057 if [ $lhs = 1 ]; then
1058 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1060 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1064 if [ $lhs = 1 ]; then
1065 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1067 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1073 __git_complete_strategy ()
1075 __git_compute_merge_strategies
1078 __gitcomp "$__git_merge_strategies"
1082 __gitcomp "$__git_merge_strategy_options"
1088 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1091 --strategy-option=*)
1092 __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1100 __git_compute_all_commands ()
1102 test -n "$__git_all_commands" ||
1103 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1106 # Lists all set config variables starting with the given section prefix,
1107 # with the prefix removed.
1108 __git_get_config_variables ()
1110 local section="$1" i IFS=$'\n'
1111 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1112 echo "${i#$section.}"
1116 __git_pretty_aliases ()
1118 __git_get_config_variables "pretty"
1121 # __git_aliased_command requires 1 argument
1122 __git_aliased_command ()
1124 local word cmdline=$(__git config --get "alias.$1")
1125 for word in $cmdline; do
1131 \!*) : shell command alias ;;
1133 *=*) : setting env ;;
1134 git) : git itself ;;
1135 \(\)) : skip parens of shell function definition ;;
1136 {) : skip start of shell helper function ;;
1137 :) : skip null command ;;
1138 \'*) : skip opening quote after sh -c ;;
1146 # Check whether one of the given words is present on the command line,
1147 # and print the first word found.
1149 # Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
1150 # --show-idx: Optionally show the index of the found word in the $words array.
1151 __git_find_on_cmdline ()
1153 local word c=1 show_idx
1155 while test $# -gt 1; do
1157 --show-idx) show_idx=y ;;
1164 while [ $c -lt $cword ]; do
1165 for word in $wordlist; do
1166 if [ "$word" = "${words[c]}" ]; then
1167 if [ -n "${show_idx-}" ]; then
1179 # Similar to __git_find_on_cmdline, except that it loops backwards and thus
1180 # prints the *last* word found. Useful for finding which of two options that
1181 # supersede each other came last, such as "--guess" and "--no-guess".
1183 # Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
1184 # --show-idx: Optionally show the index of the found word in the $words array.
1185 __git_find_last_on_cmdline ()
1187 local word c=$cword show_idx
1189 while test $# -gt 1; do
1191 --show-idx) show_idx=y ;;
1198 while [ $c -gt 1 ]; do
1200 for word in $wordlist; do
1201 if [ "$word" = "${words[c]}" ]; then
1202 if [ -n "$show_idx" ]; then
1213 # Echo the value of an option set on the command line or config
1215 # $1: short option name
1216 # $2: long option name including =
1217 # $3: list of possible values
1218 # $4: config string (optional)
1221 # result="$(__git_get_option_value "-d" "--do-something=" \
1222 # "yes no" "core.doSomething")"
1224 # result is then either empty (no option set) or "yes" or "no"
1226 # __git_get_option_value requires 3 arguments
1227 __git_get_option_value ()
1229 local c short_opt long_opt val
1230 local result= values config_key word
1238 while [ $c -ge 0 ]; do
1240 for val in $values; do
1241 if [ "$short_opt$val" = "$word" ] ||
1242 [ "$long_opt$val" = "$word" ]; then
1250 if [ -n "$config_key" ] && [ -z "$result" ]; then
1251 result="$(__git config "$config_key")"
1257 __git_has_doubledash ()
1260 while [ $c -lt $cword ]; do
1261 if [ "--" = "${words[c]}" ]; then
1269 # Try to count non option arguments passed on the command line for the
1270 # specified git command.
1271 # When options are used, it is necessary to use the special -- option to
1272 # tell the implementation were non option arguments begin.
1273 # XXX this can not be improved, since options can appear everywhere, as
1277 # __git_count_arguments requires 1 argument: the git command executed.
1278 __git_count_arguments ()
1282 # Skip "git" (first argument)
1283 for ((i=1; i < ${#words[@]}; i++)); do
1288 # Good; we can assume that the following are only non
1293 # Skip the specified git command and discard git
1306 __git_whitespacelist="nowarn warn error error-all fix"
1307 __git_patchformat="mbox stgit stgit-series hg mboxrd"
1308 __git_showcurrentpatch="diff raw"
1309 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1313 __git_find_repo_path
1314 if [ -d "$__git_repo_path"/rebase-apply ]; then
1315 __gitcomp "$__git_am_inprogress_options"
1320 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1324 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1327 --show-current-patch=*)
1328 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
1332 __gitcomp_builtin am "" \
1333 "$__git_am_inprogress_options"
1342 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1346 __gitcomp_builtin apply
1355 __gitcomp "+x -x" "" "${cur##--chmod=}"
1359 __gitcomp_builtin add
1363 local complete_opt="--others --modified --directory --no-empty-directory"
1364 if test -n "$(__git_find_on_cmdline "-u --update")"
1366 complete_opt="--modified"
1368 __git_complete_index_file "$complete_opt"
1375 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1379 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1383 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
1392 __git_has_doubledash && return
1394 local subcommands="start bad good skip reset visualize replay log run"
1395 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1396 if [ -z "$subcommand" ]; then
1397 __git_find_repo_path
1398 if [ -f "$__git_repo_path"/BISECT_START ]; then
1399 __gitcomp "$subcommands"
1401 __gitcomp "replay start"
1406 case "$subcommand" in
1407 bad|good|reset|skip|start)
1415 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1419 local i c=1 only_local_ref="n" has_r="n"
1421 while [ $c -lt $cword ]; do
1424 -d|--delete|-m|--move) only_local_ref="y" ;;
1425 -r|--remotes) has_r="y" ;;
1431 --set-upstream-to=*)
1432 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1435 __gitcomp_builtin branch
1438 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1439 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1449 local cmd="${words[2]}"
1452 __gitcomp "create list-heads verify unbundle"
1455 # looking for a file
1460 __git_complete_revlist
1467 # Helper function to decide whether or not we should enable DWIM logic for
1468 # git-switch and git-checkout.
1470 # To decide between the following rules in decreasing priority order:
1471 # - the last provided of "--guess" or "--no-guess" explicitly enable or
1472 # disable completion of DWIM logic respectively.
1473 # - If checkout.guess is false, disable completion of DWIM logic.
1474 # - If the --no-track option is provided, take this as a hint to disable the
1475 # DWIM completion logic
1476 # - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
1477 # logic, as requested by the user.
1478 # - Enable DWIM logic otherwise.
1480 __git_checkout_default_dwim_mode ()
1482 local last_option dwim_opt="--dwim"
1484 if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1488 # --no-track disables DWIM, but with lower priority than
1489 # --guess/--no-guess/checkout.guess
1490 if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
1494 # checkout.guess = false disables DWIM, but with lower priority than
1495 # --guess/--no-guess
1496 if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
1500 # Find the last provided --guess or --no-guess
1501 last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
1502 case "$last_option" in
1516 __git_has_doubledash && return
1518 local dwim_opt="$(__git_checkout_default_dwim_mode)"
1522 # Complete local branches (and DWIM branch
1523 # remote branch names) for an option argument
1524 # specifying a new branch name. This is for
1525 # convenience, assuming new branches are
1526 # possibly based on pre-existing branch names.
1527 __git_complete_refs $dwim_opt --mode="heads"
1536 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1539 __gitcomp_builtin checkout
1542 # At this point, we've already handled special completion for
1543 # the arguments to -b/-B, and --orphan. There are 3 main
1544 # things left we can possibly complete:
1545 # 1) a start-point for -b/-B, -d/--detach, or --orphan
1546 # 2) a remote head, for --track
1547 # 3) an arbitrary reference, possibly including DWIM names
1550 if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
1551 __git_complete_refs --mode="refs"
1552 elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
1553 __git_complete_refs --mode="remote-heads"
1555 __git_complete_refs $dwim_opt --mode="refs"
1561 __git_sequencer_inprogress_options="--continue --quit --abort --skip"
1563 __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1567 __git_find_repo_path
1568 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1569 __gitcomp "$__git_cherry_pick_inprogress_options"
1573 __git_complete_strategy && return
1577 __gitcomp_builtin cherry-pick "" \
1578 "$__git_cherry_pick_inprogress_options"
1590 __gitcomp_builtin clean
1595 # XXX should we check for -x option ?
1596 __git_complete_index_file "--others --directory"
1603 __git_complete_config_variable_name_and_value
1609 __git_complete_config_variable_name_and_value \
1610 --cur="${cur##--config=}"
1614 __gitcomp_builtin clone
1620 __git_untracked_file_modes="all no normal"
1633 __gitcomp "default scissors strip verbatim whitespace
1634 " "" "${cur##--cleanup=}"
1637 --reuse-message=*|--reedit-message=*|\
1638 --fixup=*|--squash=*)
1639 __git_complete_refs --cur="${cur#*=}"
1642 --untracked-files=*)
1643 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1647 __gitcomp_builtin commit
1651 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1652 __git_complete_index_file "--committable"
1654 # This is the first commit
1655 __git_complete_index_file "--cached"
1663 __gitcomp_builtin describe
1669 __git_diff_algorithms="myers minimal patience histogram"
1671 __git_diff_submodule_formats="diff log short"
1673 __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
1675 __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
1676 ignore-all-space allow-indentation-change"
1678 __git_diff_common_options="--stat --numstat --shortstat --summary
1679 --patch-with-stat --name-only --name-status --color
1680 --no-color --color-words --no-renames --check
1681 --color-moved --color-moved= --no-color-moved
1682 --color-moved-ws= --no-color-moved-ws
1683 --full-index --binary --abbrev --diff-filter=
1684 --find-copies-harder --ignore-cr-at-eol
1685 --text --ignore-space-at-eol --ignore-space-change
1686 --ignore-all-space --ignore-blank-lines --exit-code
1687 --quiet --ext-diff --no-ext-diff
1688 --no-prefix --src-prefix= --dst-prefix=
1689 --inter-hunk-context=
1690 --patience --histogram --minimal
1691 --raw --word-diff --word-diff-regex=
1692 --dirstat --dirstat= --dirstat-by-file
1693 --dirstat-by-file= --cumulative
1695 --submodule --submodule= --ignore-submodules
1696 --indent-heuristic --no-indent-heuristic
1697 --textconv --no-textconv
1703 __git_has_doubledash && return
1707 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1711 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1715 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
1719 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
1723 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1724 --base --ours --theirs --no-index
1725 $__git_diff_common_options
1730 __git_complete_revlist_file
1733 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1734 tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1735 bc codecompare smerge
1740 __git_has_doubledash && return
1744 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1748 __gitcomp_builtin difftool "$__git_diff_common_options
1749 --base --cached --ours --theirs
1750 --pickaxe-all --pickaxe-regex
1756 __git_complete_revlist_file
1759 __git_fetch_recurse_submodules="yes on-demand no"
1764 --recurse-submodules=*)
1765 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1769 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1773 __gitcomp_builtin fetch
1777 __git_complete_remote_or_refspec
1780 __git_format_patch_extra_options="
1781 --full-index --not --all --no-prefix --src-prefix=
1782 --dst-prefix= --notes
1785 _git_format_patch ()
1791 " "" "${cur##--thread=}"
1794 --base=*|--interdiff=*|--range-diff=*)
1795 __git_complete_refs --cur="${cur#--*=}"
1799 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1803 __git_complete_revlist
1810 __gitcomp_builtin fsck
1821 # Lists matching symbol names from a tag (as in ctags) file.
1822 # 1: List symbol names matching this word.
1823 # 2: The tag file to list symbol names from.
1824 # 3: A prefix to be added to each listed symbol name (optional).
1825 # 4: A suffix to be appended to each listed symbol name (optional).
1826 __git_match_ctag () {
1827 awk -v pfx="${3-}" -v sfx="${4-}" "
1828 /^${1//\//\\/}/ { print pfx \$1 sfx }
1832 # Complete symbol names from a tag file.
1833 # Usage: __git_complete_symbol [<option>]...
1834 # --tags=<file>: The tag file to list symbol names from instead of the
1836 # --pfx=<prefix>: A prefix to be added to each symbol name.
1837 # --cur=<word>: The current symbol name to be completed. Defaults to
1838 # the current word to be completed.
1839 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1840 # of the default space.
1841 __git_complete_symbol () {
1842 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1844 while test $# != 0; do
1846 --tags=*) tags="${1##--tags=}" ;;
1847 --pfx=*) pfx="${1##--pfx=}" ;;
1848 --cur=*) cur_="${1##--cur=}" ;;
1849 --sfx=*) sfx="${1##--sfx=}" ;;
1855 if test -r "$tags"; then
1856 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1862 __git_has_doubledash && return
1866 __gitcomp_builtin grep
1871 case "$cword,$prev" in
1873 __git_complete_symbol && return
1884 __gitcomp_builtin help
1888 if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
1890 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
1892 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1901 false true umask group all world everybody
1902 " "" "${cur##--shared=}"
1906 __gitcomp_builtin init
1916 __gitcomp_builtin ls-files
1921 # XXX ignore options like --modified and always suggest all cached
1923 __git_complete_index_file "--cached"
1930 __gitcomp_builtin ls-remote
1934 __gitcomp_nl "$(__git_remotes)"
1941 __gitcomp_builtin ls-tree
1949 # Options that go well for log, shortlog and gitk
1950 __git_log_common_options="
1952 --branches --tags --remotes
1953 --first-parent --merges --no-merges
1955 --max-age= --since= --after=
1956 --min-age= --until= --before=
1957 --min-parents= --max-parents=
1958 --no-min-parents --no-max-parents
1960 # Options that go well for log and gitk (not shortlog)
1961 __git_log_gitk_options="
1962 --dense --sparse --full-history
1963 --simplify-merges --simplify-by-decoration
1964 --left-right --notes --no-notes
1966 # Options that go well for log and shortlog (not gitk)
1967 __git_log_shortlog_options="
1968 --author= --committer= --grep=
1969 --all-match --invert-grep
1972 __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
1973 __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default raw unix format:"
1977 __git_has_doubledash && return
1978 __git_find_repo_path
1981 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1984 case "$prev,$cur" in
1986 return # fall back to Bash filename completion
1989 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1993 __git_complete_symbol
1998 --pretty=*|--format=*)
1999 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2004 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
2008 __gitcomp "full short no" "" "${cur##--decorate=}"
2012 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2016 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2020 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
2025 $__git_log_common_options
2026 $__git_log_shortlog_options
2027 $__git_log_gitk_options
2028 --root --topo-order --date-order --reverse
2029 --follow --full-diff
2030 --abbrev-commit --no-abbrev-commit --abbrev=
2031 --relative-date --date=
2032 --pretty= --format= --oneline
2037 --decorate --decorate= --no-decorate
2039 --no-walk --no-walk= --do-walk
2040 --parents --children
2041 --expand-tabs --expand-tabs= --no-expand-tabs
2043 $__git_diff_common_options
2044 --pickaxe-all --pickaxe-regex
2049 return # fall back to Bash filename completion
2052 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
2056 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
2060 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
2064 __git_complete_revlist
2069 __git_complete_strategy && return
2073 __gitcomp_builtin merge
2083 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
2087 __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
2097 __gitcomp_builtin merge-base
2108 __gitcomp_builtin mv
2113 if [ $(__git_count_arguments "mv") -gt 0 ]; then
2114 # We need to show both cached and untracked files (including
2115 # empty directories) since this may not be the last argument.
2116 __git_complete_index_file "--cached --others --directory"
2118 __git_complete_index_file "--cached"
2124 local subcommands='add append copy edit get-ref list merge prune remove show'
2125 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2127 case "$subcommand,$cur" in
2129 __gitcomp_builtin notes
2137 __gitcomp "$subcommands --ref"
2141 *,--reuse-message=*|*,--reedit-message=*)
2142 __git_complete_refs --cur="${cur#*=}"
2145 __gitcomp_builtin notes_$subcommand
2148 # this command does not take a ref, do not complete it
2164 __git_complete_strategy && return
2167 --recurse-submodules=*)
2168 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
2172 __gitcomp_builtin pull
2177 __git_complete_remote_or_refspec
2180 __git_push_recurse_submodules="check on-demand only"
2182 __git_complete_force_with_lease ()
2190 __git_complete_refs --cur="${cur_#*:}"
2193 __git_complete_refs --cur="$cur_"
2202 __gitcomp_nl "$(__git_remotes)"
2205 --recurse-submodules)
2206 __gitcomp "$__git_push_recurse_submodules"
2212 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
2215 --recurse-submodules=*)
2216 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
2219 --force-with-lease=*)
2220 __git_complete_force_with_lease "${cur##--force-with-lease=}"
2224 __gitcomp_builtin push
2228 __git_complete_remote_or_refspec
2236 --creation-factor= --no-dual-color
2237 $__git_diff_common_options
2242 __git_complete_revlist
2245 __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
2246 __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
2250 __git_find_repo_path
2251 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2252 __gitcomp "$__git_rebase_interactive_inprogress_options"
2254 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2255 [ -d "$__git_repo_path"/rebase-merge ]; then
2256 __gitcomp "$__git_rebase_inprogress_options"
2259 __git_complete_strategy && return
2262 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2266 __git_complete_refs --cur="${cur##--onto=}"
2270 __gitcomp_builtin rebase "" \
2271 "$__git_rebase_interactive_inprogress_options"
2280 local subcommands="show delete expire"
2281 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2283 if [ -z "$subcommand" ]; then
2284 __gitcomp "$subcommands"
2290 __git_send_email_confirm_options="always never auto cc compose"
2291 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2296 --to|--cc|--bcc|--from)
2297 __gitcomp "$(__git send-email --dump-aliases)"
2305 $__git_send_email_confirm_options
2306 " "" "${cur##--confirm=}"
2311 $__git_send_email_suppresscc_options
2312 " "" "${cur##--suppress-cc=}"
2316 --smtp-encryption=*)
2317 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2323 " "" "${cur##--thread=}"
2326 --to=*|--cc=*|--bcc=*|--from=*)
2327 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2331 __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
2332 --compose --confirm= --dry-run --envelope-sender
2334 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2335 --no-suppress-from --no-thread --quiet --reply-to
2336 --signed-off-by-cc --smtp-pass --smtp-server
2337 --smtp-server-port --smtp-encryption= --smtp-user
2338 --subject --suppress-cc= --suppress-from --thread --to
2339 --validate --no-validate
2340 $__git_format_patch_extra_options"
2344 __git_complete_revlist
2355 local untracked_state
2358 --ignore-submodules=*)
2359 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2362 --untracked-files=*)
2363 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2368 always never auto column row plain dense nodense
2369 " "" "${cur##--column=}"
2373 __gitcomp_builtin status
2378 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2379 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2381 case "$untracked_state" in
2383 # --ignored option does not matter
2387 complete_opt="--cached --directory --no-empty-directory --others"
2389 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2390 complete_opt="$complete_opt --ignored --exclude=*"
2395 __git_complete_index_file "$complete_opt"
2400 local dwim_opt="$(__git_checkout_default_dwim_mode)"
2404 # Complete local branches (and DWIM branch
2405 # remote branch names) for an option argument
2406 # specifying a new branch name. This is for
2407 # convenience, assuming new branches are
2408 # possibly based on pre-existing branch names.
2409 __git_complete_refs $dwim_opt --mode="heads"
2418 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
2421 __gitcomp_builtin switch
2424 # Unlike in git checkout, git switch --orphan does not take
2425 # a start point. Thus we really have nothing to complete after
2427 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
2431 # At this point, we've already handled special completion for
2432 # -c/-C, and --orphan. There are 3 main things left to
2434 # 1) a start-point for -c/-C or -d/--detach
2435 # 2) a remote head, for --track
2436 # 3) a branch name, possibly including DWIM remote branches
2438 if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
2439 __git_complete_refs --mode="refs"
2440 elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
2441 __git_complete_refs --mode="remote-heads"
2443 __git_complete_refs $dwim_opt --mode="heads"
2449 __git_config_get_set_variables ()
2451 local prevword word config_file= c=$cword
2452 while [ $c -gt 1 ]; do
2455 --system|--global|--local|--file=*)
2460 config_file="$word $prevword"
2468 __git config $config_file --name-only --list
2472 __git_compute_config_vars ()
2474 test -n "$__git_config_vars" ||
2475 __git_config_vars="$(git help --config-for-completion | sort -u)"
2478 # Completes possible values of various configuration variables.
2480 # Usage: __git_complete_config_variable_value [<option>]...
2481 # --varname=<word>: The name of the configuration variable whose value is
2482 # to be completed. Defaults to the previous word on the
2484 # --cur=<word>: The current value to be completed. Defaults to the current
2485 # word to be completed.
2486 __git_complete_config_variable_value ()
2488 local varname="$prev" cur_="$cur"
2490 while test $# != 0; do
2492 --varname=*) varname="${1##--varname=}" ;;
2493 --cur=*) cur_="${1##--cur=}" ;;
2499 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2500 varname="${varname,,}"
2502 varname="$(echo "$varname" |tr A-Z a-z)"
2506 branch.*.remote|branch.*.pushremote)
2507 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2511 __git_complete_refs --cur="$cur_"
2515 __gitcomp "false true merges preserve interactive" "" "$cur_"
2519 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2523 local remote="${varname#remote.}"
2524 remote="${remote%.fetch}"
2525 if [ -z "$cur_" ]; then
2526 __gitcomp_nl "refs/heads/" "" "" ""
2529 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2533 local remote="${varname#remote.}"
2534 remote="${remote%.push}"
2535 __gitcomp_nl "$(__git for-each-ref \
2536 --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2539 pull.twohead|pull.octopus)
2540 __git_compute_merge_strategies
2541 __gitcomp "$__git_merge_strategies" "" "$cur_"
2545 __gitcomp "false true" "" "$cur_"
2550 normal black red green yellow blue magenta cyan white
2551 bold dim ul blink reverse
2556 __gitcomp "false true always never auto" "" "$cur_"
2560 __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2564 __gitcomp "man info web html" "" "$cur_"
2568 __gitcomp "$__git_log_date_formats" "" "$cur_"
2571 sendemail.aliasfiletype)
2572 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2576 __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2579 sendemail.suppresscc)
2580 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2583 sendemail.transferencoding)
2584 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2593 # Completes configuration sections, subsections, variable names.
2595 # Usage: __git_complete_config_variable_name [<option>]...
2596 # --cur=<word>: The current configuration section/variable name to be
2597 # completed. Defaults to the current word to be completed.
2598 # --sfx=<suffix>: A suffix to be appended to each fully completed
2599 # configuration variable name (but not to sections or
2600 # subsections) instead of the default space.
2601 __git_complete_config_variable_name ()
2603 local cur_="$cur" sfx
2605 while test $# != 0; do
2607 --cur=*) cur_="${1##--cur=}" ;;
2608 --sfx=*) sfx="${1##--sfx=}" ;;
2616 local pfx="${cur_%.*}."
2618 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2622 local pfx="${cur%.*}."
2624 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2625 __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
2629 local pfx="${cur_%.*}."
2632 argPrompt cmd confirm needsFile noConsole noRescan
2633 prompt revPrompt revUnmerged title
2634 " "$pfx" "$cur_" "$sfx"
2638 local pfx="${cur_%.*}."
2640 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2644 local pfx="${cur_%.*}."
2646 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2650 local pfx="${cur_%.*}."
2652 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2656 local pfx="${cur_%.*}."
2658 __git_compute_all_commands
2659 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
2663 local pfx="${cur_%.*}."
2666 url proxy fetch push mirror skipDefaultUpdate
2667 receivepack uploadpack tagOpt pushurl
2668 " "$pfx" "$cur_" "$sfx"
2672 local pfx="${cur_%.*}."
2674 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2675 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
2679 local pfx="${cur_%.*}."
2681 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2685 __git_compute_config_vars
2686 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
2689 __git_compute_config_vars
2690 __gitcomp "$(echo "$__git_config_vars" |
2703 # Completes '='-separated configuration sections/variable names and values
2704 # for 'git -c section.name=value'.
2706 # Usage: __git_complete_config_variable_name_and_value [<option>]...
2707 # --cur=<word>: The current configuration section/variable name/value to be
2708 # completed. Defaults to the current word to be completed.
2709 __git_complete_config_variable_name_and_value ()
2713 while test $# != 0; do
2715 --cur=*) cur_="${1##--cur=}" ;;
2723 __git_complete_config_variable_value \
2724 --varname="${cur_%%=*}" --cur="${cur_#*=}"
2727 __git_complete_config_variable_name --cur="$cur_" --sfx='='
2735 --get|--get-all|--unset|--unset-all)
2736 __gitcomp_nl "$(__git_config_get_set_variables)"
2740 __git_complete_config_variable_value
2746 __gitcomp_builtin config
2749 __git_complete_config_variable_name
2757 add rename remove set-head set-branches
2758 get-url set-url show prune update
2760 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2761 if [ -z "$subcommand" ]; then
2764 __gitcomp_builtin remote
2767 __gitcomp "$subcommands"
2773 case "$subcommand,$cur" in
2775 __gitcomp_builtin remote_add
2780 __gitcomp_builtin remote_set-head
2783 __gitcomp_builtin remote_set-branches
2785 set-head,*|set-branches,*)
2786 __git_complete_remote_or_refspec
2789 __gitcomp_builtin remote_update
2792 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
2795 __gitcomp_builtin remote_set-url
2798 __gitcomp_builtin remote_get-url
2801 __gitcomp_builtin remote_prune
2804 __gitcomp_nl "$(__git_remotes)"
2813 __gitcomp "short medium long" "" "${cur##--format=}"
2817 __gitcomp_builtin replace
2826 local subcommands="clear forget diff remaining status gc"
2827 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2828 if test -z "$subcommand"
2830 __gitcomp "$subcommands"
2837 __git_has_doubledash && return
2841 __gitcomp_builtin reset
2859 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
2862 __git_complete_refs --cur="${cur##--source=}"
2865 __gitcomp_builtin restore
2870 __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2874 __git_find_repo_path
2875 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2876 __gitcomp "$__git_revert_inprogress_options"
2879 __git_complete_strategy && return
2882 __gitcomp_builtin revert "" \
2883 "$__git_revert_inprogress_options"
2894 __gitcomp_builtin rm
2899 __git_complete_index_file "--cached"
2904 __git_has_doubledash && return
2909 $__git_log_common_options
2910 $__git_log_shortlog_options
2911 --numbered --summary --email
2916 __git_complete_revlist
2921 __git_has_doubledash && return
2924 --pretty=*|--format=*)
2925 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2930 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2934 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2938 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
2942 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
2946 __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
2947 --oneline --show-signature
2948 --expand-tabs --expand-tabs= --no-expand-tabs
2949 $__git_diff_common_options
2954 __git_complete_revlist_file
2961 __gitcomp_builtin show-branch
2965 __git_complete_revlist
2968 _git_sparse_checkout ()
2970 local subcommands="list init set disable"
2971 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2972 if [ -z "$subcommand" ]; then
2973 __gitcomp "$subcommands"
2977 case "$subcommand,$cur" in
2991 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2992 local subcommands='push list show apply clear drop pop create branch'
2993 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
2994 if [ -z "$subcommand" -a -n "$(__git_find_on_cmdline "-p")" ]; then
2997 if [ -z "$subcommand" ]; then
3000 __gitcomp "$save_opts"
3003 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
3008 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
3009 __gitcomp "$subcommands"
3014 case "$subcommand,$cur" in
3016 __gitcomp "$save_opts --message"
3019 __gitcomp "$save_opts"
3022 __gitcomp "--index --quiet"
3028 __gitcomp "--name-status --oneline --patch-with-stat"
3031 __gitcomp "$__git_diff_common_options"
3036 if [ $cword -eq 3 ]; then
3039 __gitcomp_nl "$(__git stash list \
3040 | sed -n -e 's/:.*//p')"
3043 show,*|apply,*|drop,*|pop,*)
3044 __gitcomp_nl "$(__git stash list \
3045 | sed -n -e 's/:.*//p')"
3055 __git_has_doubledash && return
3057 local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
3058 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3059 if [ -z "$subcommand" ]; then
3065 __gitcomp "$subcommands"
3071 case "$subcommand,$cur" in
3073 __gitcomp "--branch --force --name --reference --depth"
3076 __gitcomp "--cached --recursive"
3079 __gitcomp "--force --all"
3083 --init --remote --no-fetch
3084 --recommend-shallow --no-recommend-shallow
3085 --force --rebase --merge --reference --depth --recursive --jobs
3089 __gitcomp "--default --branch"
3092 __gitcomp "--cached --files --summary-limit"
3094 foreach,--*|sync,--*)
3095 __gitcomp "--recursive"
3105 init fetch clone rebase dcommit log find-rev
3106 set-tree commit-diff info create-ignore propget
3107 proplist show-ignore show-externals branch tag blame
3108 migrate mkdirs reset gc
3110 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3111 if [ -z "$subcommand" ]; then
3112 __gitcomp "$subcommands"
3114 local remote_opts="--username= --config-dir= --no-auth-cache"
3116 --follow-parent --authors-file= --repack=
3117 --no-metadata --use-svm-props --use-svnsync-props
3118 --log-window-size= --no-checkout --quiet
3119 --repack-flags --use-log-author --localtime
3122 --ignore-paths= --include-paths= $remote_opts
3125 --template= --shared= --trunk= --tags=
3126 --branches= --stdlayout --minimize-url
3127 --no-metadata --use-svm-props --use-svnsync-props
3128 --rewrite-root= --prefix= $remote_opts
3131 --edit --rmdir --find-copies-harder --copy-similarity=
3134 case "$subcommand,$cur" in
3136 __gitcomp "--revision= --fetch-all $fc_opts"
3139 __gitcomp "--revision= $fc_opts $init_opts"
3142 __gitcomp "$init_opts"
3146 --merge --strategy= --verbose --dry-run
3147 --fetch-all --no-rebase --commit-url
3148 --revision --interactive $cmt_opts $fc_opts
3152 __gitcomp "--stdin $cmt_opts $fc_opts"
3154 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
3155 show-externals,--*|mkdirs,--*)
3156 __gitcomp "--revision="
3160 --limit= --revision= --verbose --incremental
3161 --oneline --show-commit --non-recursive
3162 --authors-file= --color
3167 --merge --verbose --strategy= --local
3168 --fetch-all --dry-run $fc_opts
3172 __gitcomp "--message= --file= --revision= $cmt_opts"
3178 __gitcomp "--dry-run --message --tag"
3181 __gitcomp "--dry-run --message"
3184 __gitcomp "--git-format"
3188 --config-dir= --ignore-paths= --minimize
3189 --no-auth-cache --username=
3193 __gitcomp "--revision= --parent"
3204 while [ $c -lt $cword ]; do
3207 -d|--delete|-v|--verify)
3208 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3223 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3233 __gitcomp_builtin tag
3243 __git_complete_worktree_paths ()
3246 __gitcomp_nl "$(git worktree list --porcelain |
3247 # Skip the first entry: it's the path of the main worktree,
3248 # which can't be moved, removed, locked, etc.
3249 sed -n -e '2,$ s/^worktree //p')"
3254 local subcommands="add list lock move prune remove unlock"
3255 local subcommand subcommand_idx
3257 subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3258 subcommand_idx="${subcommand% *}"
3259 subcommand="${subcommand#* }"
3261 case "$subcommand,$cur" in
3263 __gitcomp "$subcommands"
3266 __gitcomp_builtin worktree_$subcommand
3268 add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
3269 # Here we are not completing an --option, it's either the
3272 -b|-B) # Complete refs for branch to be created/reseted.
3275 -*) # The previous word is an -o|--option without an
3276 # unstuck argument: have to complete the path for
3277 # the new worktree, so don't list anything, but let
3278 # Bash fall back to filename completion.
3280 *) # The previous word is not an --option, so it must
3281 # be either the 'add' subcommand, the unstuck
3282 # argument of an option (e.g. branch for -b|-B), or
3283 # the path for the new worktree.
3284 if [ $cword -eq $((subcommand_idx+1)) ]; then
3285 # Right after the 'add' subcommand: have to
3286 # complete the path, so fall back to Bash
3287 # filename completion.
3290 case "${words[cword-2]}" in
3291 -b|-B) # After '-b <branch>': have to
3292 # complete the path, so fall back
3293 # to Bash filename completion.
3295 *) # After the path: have to complete
3296 # the ref to be checked out.
3304 lock,*|remove,*|unlock,*)
3305 __git_complete_worktree_paths
3308 if [ $cword -eq $((subcommand_idx+1)) ]; then
3309 # The first parameter must be an existing working
3311 __git_complete_worktree_paths
3313 # The second parameter is the destination: it could
3314 # be any path, so don't list anything, but let Bash
3315 # fall back to filename completion.
3322 __git_complete_common () {
3327 __gitcomp_builtin "$command"
3332 __git_cmds_with_parseopt_helper=
3333 __git_support_parseopt_helper () {
3334 test -n "$__git_cmds_with_parseopt_helper" ||
3335 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
3337 case " $__git_cmds_with_parseopt_helper " in
3347 __git_complete_command () {
3349 local completion_func="_git_${command//-/_}"
3350 if ! declare -f $completion_func >/dev/null 2>/dev/null &&
3351 declare -f _completion_loader >/dev/null 2>/dev/null
3353 _completion_loader "git-$command"
3355 if declare -f $completion_func >/dev/null 2>/dev/null
3359 elif __git_support_parseopt_helper "$command"
3361 __git_complete_common "$command"
3370 local i c=1 command __git_dir __git_repo_path
3371 local __git_C_args C_args_count=0
3373 while [ $c -lt $cword ]; do
3376 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
3377 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
3378 --bare) __git_dir="." ;;
3379 --help) command="help"; break ;;
3380 -c|--work-tree|--namespace) ((c++)) ;;
3381 -C) __git_C_args[C_args_count++]=-C
3383 __git_C_args[C_args_count++]="${words[c]}"
3386 *) command="$i"; break ;;
3391 if [ -z "${command-}" ]; then
3393 --git-dir|-C|--work-tree)
3394 # these need a path argument, let's fall back to
3395 # Bash filename completion
3399 __git_complete_config_variable_name_and_value
3403 # we don't support completing these options' arguments
3421 --no-replace-objects
3426 if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3428 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3430 __gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
3437 __git_complete_command "$command" && return
3439 local expansion=$(__git_aliased_command "$command")
3440 if [ -n "$expansion" ]; then
3442 __git_complete_command "$expansion"
3448 __git_has_doubledash && return
3450 local __git_repo_path
3451 __git_find_repo_path
3454 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3460 $__git_log_common_options
3461 $__git_log_gitk_options
3467 __git_complete_revlist
3470 if [[ -n ${ZSH_VERSION-} ]] &&
3471 # Don't define these functions when sourced from 'git-completion.zsh',
3472 # it has its own implementations.
3473 [[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
3474 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3476 autoload -U +X compinit && compinit
3482 local cur_="${3-$cur}"
3488 local c IFS=$' \t\n'
3496 array[${#array[@]}+1]="$c"
3499 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3510 compadd -Q -- ${=1} && _ret=0
3519 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3522 __gitcomp_file_direct ()
3528 compadd -f -- ${=1} && _ret=0
3537 compadd -p "${2-}" -f -- ${=1} && _ret=0
3542 local _ret=1 cur cword prev
3543 cur=${words[CURRENT]}
3544 prev=${words[CURRENT-1]}
3546 emulate ksh -c __${service}_main
3547 let _ret && _default && _ret=0
3551 compdef _git git gitk
3557 local cur words cword prev
3558 _get_comp_words_by_ref -n =: cur words cword prev
3562 # Setup completion for certain functions defined above by setting common
3563 # variables and workarounds.
3564 # This is NOT a public function; use at your own risk.
3567 local wrapper="__git_wrap${2}"
3568 eval "$wrapper () { __git_func_wrap $2 ; }"
3569 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3570 || complete -o default -o nospace -F $wrapper $1
3573 # wrapper for backwards compatibility
3576 __git_wrap__git_main
3579 # wrapper for backwards compatibility
3582 __git_wrap__gitk_main
3585 __git_complete git __git_main
3586 __git_complete gitk __gitk_main
3588 # The following are necessary only for Cygwin, and only are needed
3589 # when the user has tab-completed the executable name and consequently
3590 # included the '.exe' suffix.
3592 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3593 __git_complete git.exe __git_main