]>
git.ipfire.org Git - thirdparty/git.git/blob - contrib/completion/git-completion.bash
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 # If you have a command that is not part of git, but you would still
33 # like completion, you can use __git_complete:
35 # __git_complete gl git_log
37 # Or if it's a main command (i.e. git or gitk):
39 # __git_complete gk gitk
41 # Compatible with bash 3.2.57.
43 # You can set the following environment variables to influence the behavior of
44 # the completion routines:
46 # GIT_COMPLETION_CHECKOUT_NO_GUESS
48 # When set to "1", do not include "DWIM" suggestions in git-checkout
49 # and git-switch completion (e.g., completing "foo" when "origin/foo"
52 # GIT_COMPLETION_SHOW_ALL_COMMANDS
54 # When set to "1" suggest all commands, including plumbing commands
55 # which are hidden by default (e.g. "cat-file" on "git ca<TAB>").
57 # GIT_COMPLETION_SHOW_ALL
59 # When set to "1" suggest all options, including options which are
60 # typically hidden (e.g. '--allow-empty' for 'git commit').
62 case "$COMP_WORDBREAKS" in
64 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
67 # Discovers the path to the git repository taking any '--git-dir=<path>' and
68 # '-C <path>' options into account and stores it in the $__git_repo_path
70 __git_find_repo_path
()
72 if [ -n "${__git_repo_path-}" ]; then
73 # we already know where it is
77 if [ -n "${__git_C_args-}" ]; then
78 __git_repo_path
="$(git "${__git_C_args[@]}" \
79 ${__git_dir:+--git-dir="$__git_dir"} \
80 rev-parse --absolute-git-dir 2>/dev/null)"
81 elif [ -n "${__git_dir-}" ]; then
82 test -d "$__git_dir" &&
83 __git_repo_path
="$__git_dir"
84 elif [ -n "${GIT_DIR-}" ]; then
86 __git_repo_path
="$GIT_DIR"
87 elif [ -d .git
]; then
90 __git_repo_path
="$(git rev-parse --git-dir 2>/dev/null)"
94 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
95 # __gitdir accepts 0 or 1 arguments (i.e., location)
96 # returns location of .git repo
99 if [ -z "${1-}" ]; then
100 __git_find_repo_path ||
return 1
101 echo "$__git_repo_path"
102 elif [ -d "$1/.git" ]; then
109 # Runs git with all the options given as argument, respecting any
110 # '--git-dir=<path>' and '-C <path>' options present on the command line
113 git
${__git_C_args:+"${__git_C_args[@]}"} \
114 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev
/null
117 # Removes backslash escaping, single quotes and double quotes from a word,
118 # stores the result in the variable $dequoted_word.
119 # 1: The word to dequote.
122 local rest
="$1" len ch
126 while test -n "$rest"; do
127 len
=${#dequoted_word}
128 dequoted_word
="$dequoted_word${rest%%[\\\'\"]*}"
129 rest
="${rest:$((${#dequoted_word}-$len))}"
131 case "${rest:0:1}" in
138 dequoted_word
="$dequoted_word$ch"
145 len
=${#dequoted_word}
146 dequoted_word
="$dequoted_word${rest%%\'*}"
147 rest
="${rest:$((${#dequoted_word}-$len+1))}"
151 while test -n "$rest" ; do
152 len
=${#dequoted_word}
153 dequoted_word
="$dequoted_word${rest%%[\\\"]*}"
154 rest
="${rest:$((${#dequoted_word}-$len))}"
155 case "${rest:0:1}" in
160 dequoted_word="$dequoted_word$ch"
165 dequoted_word="$dequoted_word\\$ch"
181 # The following function is based on code from:
183 # bash_completion - programmable completion functions for bash 3.2+
185 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
186 # © 2009-2010, Bash Completion Maintainers
187 # <bash-completion-devel@lists.alioth.debian.org>
189 # This program is free software; you can redistribute it and/or modify
190 # it under the terms of the GNU General Public License as published by
191 # the Free Software Foundation; either version 2, or (at your option)
194 # This program is distributed in the hope that it will be useful,
195 # but WITHOUT ANY WARRANTY; without even the implied warranty of
196 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
197 # GNU General Public License for more details.
199 # You should have received a copy of the GNU General Public License
200 # along with this program; if not, see <http://www.gnu.org/licenses/>.
202 # The latest version of this software can be obtained here:
204 # http://bash-completion.alioth.debian.org/
208 # This function can be used to access a tokenized list of words
209 # on the command line:
211 # __git_reassemble_comp_words_by_ref '=:'
212 # if test "${words_[cword_-1]}" = -w
217 # The argument should be a collection of characters from the list of
218 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
221 # This is roughly equivalent to going back in time and setting
222 # COMP_WORDBREAKS to exclude those characters. The intent is to
223 # make option types like --date=<type> and <rev>:<path> easy to
224 # recognize by treating each shell word as a single token.
226 # It is best not to set COMP_WORDBREAKS directly because the value is
227 # shared with other completion scripts. By the time the completion
228 # function gets called, COMP_WORDS has already been populated so local
229 # changes to COMP_WORDBREAKS have no effect.
231 # Output: words_, cword_, cur_.
233 __git_reassemble_comp_words_by_ref()
235 local exclude i j first
236 # Which word separators to exclude?
237 exclude="${1//[^$COMP_WORDBREAKS]}"
239 if [ -z "$exclude" ]; then
240 words_=("${COMP_WORDS[@]}")
243 # List of word completion separators has shrunk;
244 # re-assemble words to complete.
245 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
246 # Append each nonempty word consisting of just
247 # word separator characters to the current word.
251 [ -n "${COMP_WORDS[$i]}" ] &&
252 # word consists of excluded word separators
253 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
255 # Attach to the previous token,
256 # unless the previous token is the command name.
257 if [ $j -ge 2 ] && [ -n "$first" ]; then
261 words_[$j]=${words_[j]}${COMP_WORDS[i]}
262 if [ $i = $COMP_CWORD ]; then
265 if (($i < ${#COMP_WORDS[@]} - 1)); then
272 words_[$j]=${words_[j]}${COMP_WORDS[i]}
273 if [ $i = $COMP_CWORD ]; then
279 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
280 _get_comp_words_by_ref ()
282 local exclude cur_ words_ cword_
283 if [ "$1" = "-n" ]; then
287 __git_reassemble_comp_words_by_ref "$exclude"
288 cur_=${words_[cword_]}
289 while [ $# -gt 0 ]; do
295 prev=${words_[$cword_-1]}
298 words=("${words_[@]}")
309 # Fills the COMPREPLY array with prefiltered words without any additional
311 # Callers must take care of providing only words that match the current word
312 # to be completed and adding any prefix and/or suffix (trailing space!), if
314 # 1: List of newline-separated matching completion words, complete with
323 # Similar to __gitcomp_direct, but appends to COMPREPLY instead.
324 # Callers must take care of providing only words that match the current word
325 # to be completed and adding any prefix and/or suffix (trailing space!), if
327 # 1: List of newline-separated matching completion words, complete with
329 __gitcomp_direct_append ()
338 local x i=${#COMPREPLY[@]}
340 if [[ "$x" == "$3"* ]]; then
341 COMPREPLY[i++]="$2$x$4"
352 # Generates completion reply, appending a space to possible completion words,
354 # It accepts 1 to 4 arguments:
355 # 1: List of possible completion words.
356 # 2: A prefix to be added to each possible completion word (optional).
357 # 3: Generate possible completion matches for this word (optional).
358 # 4: A suffix to be appended to each possible completion word (optional).
361 local cur_="${3-$cur}"
367 local c i=0 IFS=$' \t\n'
369 if [[ $c == "--" ]]; then
373 if [[ $c == "$cur_"* ]]; then
378 COMPREPLY[i++]="${2-}$c"
383 local c i=0 IFS=$' \t\n'
385 if [[ $c == "--" ]]; then
387 if [[ $c == "$cur_"* ]]; then
388 COMPREPLY[i++]="${2-}$c "
393 if [[ $c == "$cur_"* ]]; then
398 COMPREPLY[i++]="${2-}$c"
405 # Clear the variables caching builtins' options when (re-)sourcing
406 # the completion script.
407 if [[ -n ${ZSH_VERSION-} ]]; then
408 unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
410 unset $(compgen -v __gitcomp_builtin_)
413 # This function is equivalent to
415 # __gitcomp "$(git xxx --git-completion-helper) ..."
417 # except that the output is cached. Accept 1-3 arguments:
418 # 1: the git command to execute, this is also the cache key
419 # 2: extra options to be added on top (e.g. negative forms)
420 # 3: options to be excluded
423 # spaces must be replaced with underscore for multi-word
424 # commands, e.g. "git remote add" becomes remote_add.
429 local var=__gitcomp_builtin_"${cmd//-/_}"
431 eval "options=\${$var-}"
433 if [ -z "$options" ]; then
434 local completion_helper
435 if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
436 completion_helper="--git-completion-helper-all"
438 completion_helper="--git-completion-helper"
440 # leading and trailing spaces are significant to make
441 # option removal work correctly.
442 options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
445 options="${options/ $i / }"
447 eval "$var=\"$options\""
453 # Variation of __gitcomp_nl () that appends to the existing list of
454 # completion candidates, COMPREPLY.
455 __gitcomp_nl_append ()
458 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
461 # Generates completion reply from newline-separated possible completion words
462 # by appending a space to all of them.
463 # It accepts 1 to 4 arguments:
464 # 1: List of possible completion words, separated by a single newline.
465 # 2: A prefix to be added to each possible completion word (optional).
466 # 3: Generate possible completion matches for this word (optional).
467 # 4: A suffix to be appended to each possible completion word instead of
468 # the default space (optional). If specified but empty, nothing is
473 __gitcomp_nl_append "$@"
476 # Fills the COMPREPLY array with prefiltered paths without any additional
478 # Callers must take care of providing only paths that match the current path
479 # to be completed and adding any prefix path components, if necessary.
480 # 1: List of newline-separated matching paths, complete with all prefix
482 __gitcomp_file_direct ()
488 # use a hack to enable file mode in bash < 4
489 compopt -o filenames +o nospace 2>/dev/null ||
490 compgen -f /non-existing-dir/ >/dev/null ||
494 # Generates completion reply with compgen from newline-separated possible
495 # completion filenames.
496 # It accepts 1 to 3 arguments:
497 # 1: List of possible completion filenames, separated by a single newline.
498 # 2: A directory prefix to be added to each possible completion filename
500 # 3: Generate possible completion matches for this word (optional).
505 # XXX does not work when the directory prefix contains a tilde,
506 # since tilde expansion is not applied.
507 # This means that COMPREPLY will be empty and Bash default
508 # completion will be used.
509 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
511 # use a hack to enable file mode in bash < 4
512 compopt -o filenames +o nospace 2>/dev/null ||
513 compgen -f /non-existing-dir/ >/dev/null ||
517 # Execute 'git ls-files', unless the --committable option is specified, in
518 # which case it runs 'git diff-index' to find out the files that can be
519 # committed. It return paths relative to the directory specified in the first
520 # argument, and using the options specified in the second argument.
521 __git_ls_files_helper ()
523 if [ "$2" = "--committable" ]; then
524 __git -C "$1" -c core.quotePath=false diff-index \
525 --name-only --relative HEAD -- "${3//\\/\\\\}*"
527 # NOTE: $2 is not quoted in order to support multiple options
528 __git -C "$1" -c core.quotePath=false ls-files \
529 --exclude-standard $2 -- "${3//\\/\\\\}*"
534 # __git_index_files accepts 1 or 2 arguments:
535 # 1: Options to pass to ls-files (required).
536 # 2: A directory path (optional).
537 # If provided, only files within the specified directory are listed.
538 # Sub directories are never recursed. Path must have a trailing
540 # 3: List only paths matching this path component (optional).
543 local root="$2" match="$3"
545 __git_ls_files_helper "$root" "$1" "${match:-?}" |
546 awk -F / -v pfx="${2//\\/\\\\}" '{
551 if (substr(p, 1, 1) != "\"") {
552 # No special characters, easy!
557 # The path is quoted.
562 # Even when a directory name itself does not contain
563 # any special characters, it will still be quoted if
564 # any of its (stripped) trailing path components do.
565 # Because of this we may have seen the same directory
566 # both quoted and unquoted.
568 # We have seen the same directory unquoted,
575 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
576 # Skip opening double quote.
579 # Interpret backslash escape sequences.
580 while ((bs_idx = index(p, "\\")) != 0) {
581 out = out substr(p, 1, bs_idx - 1)
582 esc = substr(p, bs_idx + 1, 1)
583 p = substr(p, bs_idx + 2)
585 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
586 # C-style one-character escape sequence.
587 out = out substr("\a\b\t\v\f\r\"\\",
589 } else if (esc == "n") {
590 # Uh-oh, a newline character.
591 # We cannot reliably put a pathname
592 # containing a newline into COMPREPLY,
593 # and the newline would create a mess.
597 # Must be a \nnn octal value, then.
599 substr(p, 1, 1) * 8 + \
601 out = out sprintf("%c", dec)
605 # Drop closing double quote, if there is one.
606 # (There is not any if this is a directory, as it was
607 # already stripped with the trailing path components.)
608 if (substr(p, length(p), 1) == "\"")
609 out = out substr(p, 1, length(p) - 1)
617 # __git_complete_index_file requires 1 argument:
618 # 1: the options to pass to ls-file
620 # The exception is --committable, which finds the files appropriate commit.
621 __git_complete_index_file ()
623 local dequoted_word pfx="" cur_
627 case "$dequoted_word" in
629 pfx="${dequoted_word%/*}/"
630 cur_="${dequoted_word##*/}"
633 cur_="$dequoted_word"
636 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
639 # Lists branches from the local repository.
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).
646 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
648 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
649 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
652 # Lists branches from remote repositories.
653 # 1: A prefix to be added to each listed branch (optional).
654 # 2: List only branches matching this word (optional; list all branches if
656 # 3: A suffix to be appended to each listed branch (optional).
657 __git_remote_heads ()
659 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
661 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
662 "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
665 # Lists tags from the local repository.
666 # Accepts the same positional parameters as __git_heads() above.
669 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
671 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
672 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
675 # List unique branches from refs/remotes used for 'git checkout' and 'git
676 # switch' tracking DWIMery.
677 # 1: A prefix to be added to each listed branch (optional)
678 # 2: List only branches matching this word (optional; list all branches if
680 # 3: A suffix to be appended to each listed branch (optional).
681 __git_dwim_remote_heads ()
683 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
684 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
686 # employ the heuristic used by git checkout and git switch
687 # Try to find a remote branch that cur_es the completion word
688 # but only output if the branch name is unique
689 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
690 --sort="refname:strip=3" \
691 "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
695 # Lists refs from the local (by default) or from a remote repository.
696 # It accepts 0, 1 or 2 arguments:
697 # 1: The remote to list refs from (optional; ignored, if set but empty).
698 # Can be the name of a configured remote, a path, or a URL.
699 # 2: In addition to local refs, list unique branches from refs/remotes/ for
700 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
701 # 3: A prefix to be added to each listed ref (optional).
702 # 4: List only refs matching this word (optional; list all refs if unset or
704 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
707 # Use __git_complete_refs() instead.
710 local i hash dir track="${2-}"
711 local list_refs_from=path remote="${1-}"
713 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
715 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
718 dir="$__git_repo_path"
720 if [ -z "$remote" ]; then
721 if [ -z "$dir" ]; then
725 if __git_is_configured_remote "$remote"; then
726 # configured remote takes precedence over a
727 # local directory with the same name
728 list_refs_from=remote
729 elif [ -d "$remote/.git" ]; then
731 elif [ -d "$remote" ]; then
738 if [ "$list_refs_from" = path ]; then
739 if [[ "$cur_" == ^* ]]; then
748 refs=("$match*" "$match*/**")
752 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do
755 if [ -e "$dir/$i" ]; then
761 format="refname:strip=2"
762 refs=("refs/tags/$match*" "refs/tags/$match*/**"
763 "refs/heads/$match*" "refs/heads/$match*/**"
764 "refs/remotes/$match*" "refs/remotes/$match*/**")
767 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
769 if [ -n "$track" ]; then
770 __git_dwim_remote_heads "$pfx" "$match" "$sfx"
776 __git ls-remote "$remote" "$match*" | \
777 while read -r hash i; do
780 *) echo "$pfx$i$sfx" ;;
785 if [ "$list_refs_from" = remote ]; then
787 $match*) echo "${pfx}HEAD$sfx" ;;
789 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
790 "refs/remotes/$remote/$match*" \
791 "refs/remotes/$remote/$match*/**"
795 $match*) query_symref="HEAD" ;;
797 __git ls-remote "$remote" $query_symref \
798 "refs/tags/$match*" "refs/heads/$match*" \
799 "refs/remotes/$match*" |
800 while read -r hash i; do
803 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
804 *) echo "$pfx$i$sfx" ;; # symbolic refs
812 # Completes refs, short and long, local and remote, symbolic and pseudo.
814 # Usage: __git_complete_refs [<option>]...
815 # --remote=<remote>: The remote to list refs from, can be the name of a
816 # configured remote, a path, or a URL.
817 # --dwim: List unique remote branches for 'git switch's tracking DWIMery.
818 # --pfx=<prefix>: A prefix to be added to each ref.
819 # --cur=<word>: The current ref to be completed. Defaults to the current
820 # word to be completed.
821 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
823 # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
824 # complete all refs, 'heads' to complete only branches, or
825 # 'remote-heads' to complete only remote branches. Note that
826 # --remote is only compatible with --mode=refs.
827 __git_complete_refs ()
829 local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
831 while test $# != 0; do
833 --remote=*) remote="${1##--remote=}" ;;
834 --dwim) dwim="yes" ;;
835 # --track is an old spelling of --dwim
836 --track) dwim="yes" ;;
837 --pfx=*) pfx="${1##--pfx=}" ;;
838 --cur=*) cur_="${1##--cur=}" ;;
839 --sfx=*) sfx="${1##--sfx=}" ;;
840 --mode=*) mode="${1##--mode=}" ;;
846 # complete references based on the specified mode
849 __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
851 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
853 __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
858 # Append DWIM remote branch names if requested
859 if [ "$dwim" = "yes" ]; then
860 __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
864 # __git_refs2 requires 1 argument (to pass to __git_refs)
865 # Deprecated: use __git_complete_fetch_refspecs() instead.
869 for i in $(__git_refs "$1"); do
874 # Completes refspecs for fetching from a remote repository.
875 # 1: The remote repository.
876 # 2: A prefix to be added to each listed refspec (optional).
877 # 3: The ref to be completed as a refspec instead of the current word to be
878 # completed (optional)
879 # 4: A suffix to be appended to each listed refspec instead of the default
881 __git_complete_fetch_refspecs ()
883 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
886 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
892 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
893 __git_refs_remotes ()
896 __git ls-remote "$1" 'refs/heads/*' | \
897 while read -r hash i; do
898 echo "$i:refs/remotes/$1/${i#refs/heads/}"
905 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
909 # Returns true if $1 matches the name of a configured remote, false otherwise.
910 __git_is_configured_remote ()
913 for remote in $(__git_remotes); do
914 if [ "$remote" = "$1" ]; then
921 __git_list_merge_strategies ()
923 LANG=C LC_ALL=C git merge -s help 2>&1 |
924 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
933 __git_merge_strategies=
934 # 'git merge -s help' (and thus detection of the merge strategy
935 # list) fails, unfortunately, if run outside of any git working
936 # tree. __git_merge_strategies is set to the empty string in
937 # that case, and the detection will be repeated the next time it
939 __git_compute_merge_strategies ()
941 test -n "$__git_merge_strategies" ||
942 __git_merge_strategies=$(__git_list_merge_strategies)
945 __git_merge_strategy_options="ours theirs subtree subtree= patience
946 histogram diff-algorithm= ignore-space-change ignore-all-space
947 ignore-space-at-eol renormalize no-renormalize no-renames
948 find-renames find-renames= rename-threshold="
950 __git_complete_revlist_file ()
952 local dequoted_word pfx ls ref cur_="$cur"
961 __git_dequote "$cur_"
963 case "$dequoted_word" in
965 pfx="${dequoted_word%/*}"
966 cur_="${dequoted_word##*/}"
971 cur_="$dequoted_word"
976 case "$COMP_WORDBREAKS" in
978 *) pfx="$ref:$pfx" ;;
981 __gitcomp_file "$(__git ls-tree "$ls" \
987 pfx="${cur_%...*}..."
989 __git_complete_refs --pfx="$pfx" --cur="$cur_"
994 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1002 __git_complete_file ()
1004 __git_complete_revlist_file
1007 __git_complete_revlist ()
1009 __git_complete_revlist_file
1012 __git_complete_remote_or_refspec ()
1014 local cur_="$cur" cmd="${words[__git_cmd_idx]}"
1015 local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
1016 if [ "$cmd" = "remote" ]; then
1019 while [ $c -lt $cword ]; do
1022 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
1023 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
1026 push) no_complete_refspec=1 ;;
1033 --multiple) no_complete_refspec=1; break ;;
1035 *) remote="$i"; break ;;
1039 if [ -z "$remote" ]; then
1040 __gitcomp_nl "$(__git_remotes)"
1043 if [ $no_complete_refspec = 1 ]; then
1046 [ "$remote" = "." ] && remote=
1049 case "$COMP_WORDBREAKS" in
1051 *) pfx="${cur_%%:*}:" ;;
1063 if [ $lhs = 1 ]; then
1064 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
1066 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1070 if [ $lhs = 1 ]; then
1071 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1073 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1077 if [ $lhs = 1 ]; then
1078 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1080 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1086 __git_complete_strategy ()
1088 __git_compute_merge_strategies
1091 __gitcomp "$__git_merge_strategies"
1095 __gitcomp "$__git_merge_strategy_options"
1101 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1104 --strategy-option=*)
1105 __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1113 __git_compute_all_commands ()
1115 test -n "$__git_all_commands" ||
1116 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1119 # Lists all set config variables starting with the given section prefix,
1120 # with the prefix removed.
1121 __git_get_config_variables ()
1123 local section="$1" i IFS=$'\n'
1124 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1125 echo "${i#$section.}"
1129 __git_pretty_aliases ()
1131 __git_get_config_variables "pretty"
1134 # __git_aliased_command requires 1 argument
1135 __git_aliased_command ()
1137 local cur=$1 last list= word cmdline
1139 while [[ -n "$cur" ]]; do
1140 if [[ "$list" == *" $cur "* ]]; then
1145 cmdline=$(__git config --get "alias.$cur")
1150 for word in $cmdline; do
1156 \!*) : shell command alias ;;
1158 *=*) : setting env ;;
1159 git) : git itself ;;
1160 \(\)) : skip parens of shell function definition ;;
1161 {) : skip start of shell helper function ;;
1162 :) : skip null command ;;
1163 \'*) : skip opening quote after sh -c ;;
1172 if [[ "$cur" != "$1" ]]; then
1177 # Check whether one of the given words is present on the command line,
1178 # and print the first word found.
1180 # Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
1181 # --show-idx: Optionally show the index of the found word in the $words array.
1182 __git_find_on_cmdline ()
1184 local word c="$__git_cmd_idx" show_idx
1186 while test $# -gt 1; do
1188 --show-idx) show_idx=y ;;
1195 while [ $c -lt $cword ]; do
1196 for word in $wordlist; do
1197 if [ "$word" = "${words[c]}" ]; then
1198 if [ -n "${show_idx-}" ]; then
1210 # Similar to __git_find_on_cmdline, except that it loops backwards and thus
1211 # prints the *last* word found. Useful for finding which of two options that
1212 # supersede each other came last, such as "--guess" and "--no-guess".
1214 # Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
1215 # --show-idx: Optionally show the index of the found word in the $words array.
1216 __git_find_last_on_cmdline ()
1218 local word c=$cword show_idx
1220 while test $# -gt 1; do
1222 --show-idx) show_idx=y ;;
1229 while [ $c -gt "$__git_cmd_idx" ]; do
1231 for word in $wordlist; do
1232 if [ "$word" = "${words[c]}" ]; then
1233 if [ -n "$show_idx" ]; then
1244 # Echo the value of an option set on the command line or config
1246 # $1: short option name
1247 # $2: long option name including =
1248 # $3: list of possible values
1249 # $4: config string (optional)
1252 # result="$(__git_get_option_value "-d" "--do-something=" \
1253 # "yes no" "core.doSomething")"
1255 # result is then either empty (no option set) or "yes" or "no"
1257 # __git_get_option_value requires 3 arguments
1258 __git_get_option_value ()
1260 local c short_opt long_opt val
1261 local result= values config_key word
1269 while [ $c -ge 0 ]; do
1271 for val in $values; do
1272 if [ "$short_opt$val" = "$word" ] ||
1273 [ "$long_opt$val" = "$word" ]; then
1281 if [ -n "$config_key" ] && [ -z "$result" ]; then
1282 result="$(__git config "$config_key")"
1288 __git_has_doubledash ()
1291 while [ $c -lt $cword ]; do
1292 if [ "--" = "${words[c]}" ]; then
1300 # Try to count non option arguments passed on the command line for the
1301 # specified git command.
1302 # When options are used, it is necessary to use the special -- option to
1303 # tell the implementation were non option arguments begin.
1304 # XXX this can not be improved, since options can appear everywhere, as
1308 # __git_count_arguments requires 1 argument: the git command executed.
1309 __git_count_arguments ()
1313 # Skip "git" (first argument)
1314 for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
1319 # Good; we can assume that the following are only non
1324 # Skip the specified git command and discard git
1337 __git_whitespacelist="nowarn warn error error-all fix"
1338 __git_patchformat="mbox stgit stgit-series hg mboxrd"
1339 __git_showcurrentpatch="diff raw"
1340 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1341 __git_quoted_cr="nowarn warn strip"
1345 __git_find_repo_path
1346 if [ -d "$__git_repo_path"/rebase-apply ]; then
1347 __gitcomp "$__git_am_inprogress_options"
1352 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1356 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1359 --show-current-patch=*)
1360 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
1364 __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}"
1368 __gitcomp_builtin am "" \
1369 "$__git_am_inprogress_options"
1378 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1382 __gitcomp_builtin apply
1391 __gitcomp "+x -x" "" "${cur##--chmod=}"
1395 __gitcomp_builtin add
1399 local complete_opt="--others --modified --directory --no-empty-directory"
1400 if test -n "$(__git_find_on_cmdline "-u --update")"
1402 complete_opt="--modified"
1404 __git_complete_index_file "$complete_opt"
1411 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1415 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1419 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
1428 __git_has_doubledash && return
1430 local subcommands="start bad good skip reset visualize replay log run"
1431 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1432 if [ -z "$subcommand" ]; then
1433 __git_find_repo_path
1434 if [ -f "$__git_repo_path"/BISECT_START ]; then
1435 __gitcomp "$subcommands"
1437 __gitcomp "replay start"
1442 case "$subcommand" in
1443 bad|good|reset|skip|start)
1451 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1455 local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
1457 while [ $c -lt $cword ]; do
1460 -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
1461 only_local_ref="y" ;;
1469 --set-upstream-to=*)
1470 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1473 __gitcomp_builtin branch
1476 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1477 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1487 local cmd="${words[__git_cmd_idx+1]}"
1489 $((__git_cmd_idx+1)))
1490 __gitcomp "create list-heads verify unbundle"
1492 $((__git_cmd_idx+2)))
1493 # looking for a file
1498 __git_complete_revlist
1505 # Helper function to decide whether or not we should enable DWIM logic for
1506 # git-switch and git-checkout.
1508 # To decide between the following rules in decreasing priority order:
1509 # - the last provided of "--guess" or "--no-guess" explicitly enable or
1510 # disable completion of DWIM logic respectively.
1511 # - If checkout.guess is false, disable completion of DWIM logic.
1512 # - If the --no-track option is provided, take this as a hint to disable the
1513 # DWIM completion logic
1514 # - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
1515 # logic, as requested by the user.
1516 # - Enable DWIM logic otherwise.
1518 __git_checkout_default_dwim_mode ()
1520 local last_option dwim_opt="--dwim"
1522 if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1526 # --no-track disables DWIM, but with lower priority than
1527 # --guess/--no-guess/checkout.guess
1528 if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
1532 # checkout.guess = false disables DWIM, but with lower priority than
1533 # --guess/--no-guess
1534 if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
1538 # Find the last provided --guess or --no-guess
1539 last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
1540 case "$last_option" in
1554 __git_has_doubledash && return
1556 local dwim_opt="$(__git_checkout_default_dwim_mode)"
1560 # Complete local branches (and DWIM branch
1561 # remote branch names) for an option argument
1562 # specifying a new branch name. This is for
1563 # convenience, assuming new branches are
1564 # possibly based on pre-existing branch names.
1565 __git_complete_refs $dwim_opt --mode="heads"
1574 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
1577 __gitcomp_builtin checkout
1580 # At this point, we've already handled special completion for
1581 # the arguments to -b/-B, and --orphan. There are 3 main
1582 # things left we can possibly complete:
1583 # 1) a start-point for -b/-B, -d/--detach, or --orphan
1584 # 2) a remote head, for --track
1585 # 3) an arbitrary reference, possibly including DWIM names
1588 if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
1589 __git_complete_refs --mode="refs"
1590 elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
1591 __git_complete_refs --mode="remote-heads"
1593 __git_complete_refs $dwim_opt --mode="refs"
1599 __git_sequencer_inprogress_options="--continue --quit --abort --skip"
1601 __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1605 __git_find_repo_path
1606 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1607 __gitcomp "$__git_cherry_pick_inprogress_options"
1611 __git_complete_strategy && return
1615 __gitcomp_builtin cherry-pick "" \
1616 "$__git_cherry_pick_inprogress_options"
1628 __gitcomp_builtin clean
1633 # XXX should we check for -x option ?
1634 __git_complete_index_file "--others --directory"
1641 __git_complete_config_variable_name_and_value
1647 __git_complete_config_variable_name_and_value \
1648 --cur="${cur##--config=}"
1652 __gitcomp_builtin clone
1658 __git_untracked_file_modes="all no normal"
1671 __gitcomp "default scissors strip verbatim whitespace
1672 " "" "${cur##--cleanup=}"
1675 --reuse-message=*|--reedit-message=*|\
1676 --fixup=*|--squash=*)
1677 __git_complete_refs --cur="${cur#*=}"
1680 --untracked-files=*)
1681 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1685 __gitcomp_builtin commit
1689 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1690 __git_complete_index_file "--committable"
1692 # This is the first commit
1693 __git_complete_index_file "--cached"
1701 __gitcomp_builtin describe
1707 __git_diff_algorithms="myers minimal patience histogram"
1709 __git_diff_submodule_formats="diff log short"
1711 __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
1713 __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
1714 ignore-all-space allow-indentation-change"
1716 __git_diff_common_options="--stat --numstat --shortstat --summary
1717 --patch-with-stat --name-only --name-status --color
1718 --no-color --color-words --no-renames --check
1719 --color-moved --color-moved= --no-color-moved
1720 --color-moved-ws= --no-color-moved-ws
1721 --full-index --binary --abbrev --diff-filter=
1722 --find-copies-harder --ignore-cr-at-eol
1723 --text --ignore-space-at-eol --ignore-space-change
1724 --ignore-all-space --ignore-blank-lines --exit-code
1725 --quiet --ext-diff --no-ext-diff
1726 --no-prefix --src-prefix= --dst-prefix=
1727 --inter-hunk-context=
1728 --patience --histogram --minimal
1729 --raw --word-diff --word-diff-regex=
1730 --dirstat --dirstat= --dirstat-by-file
1731 --dirstat-by-file= --cumulative
1733 --submodule --submodule= --ignore-submodules
1734 --indent-heuristic --no-indent-heuristic
1735 --textconv --no-textconv
1740 __git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex
1741 --base --ours --theirs --no-index --relative --merge-base
1742 $__git_diff_common_options"
1746 __git_has_doubledash && return
1750 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1754 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1758 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
1762 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
1766 __gitcomp "$__git_diff_difftool_options"
1770 __git_complete_revlist_file
1773 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1774 tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1775 bc codecompare smerge
1780 __git_has_doubledash && return
1784 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1788 __gitcomp_builtin difftool "$__git_diff_difftool_options"
1792 __git_complete_revlist_file
1795 __git_fetch_recurse_submodules="yes on-demand no"
1800 --recurse-submodules=*)
1801 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1805 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1809 __gitcomp_builtin fetch
1813 __git_complete_remote_or_refspec
1816 __git_format_patch_extra_options="
1817 --full-index --not --all --no-prefix --src-prefix=
1818 --dst-prefix= --notes
1821 _git_format_patch ()
1827 " "" "${cur##--thread=}"
1830 --base=*|--interdiff=*|--range-diff=*)
1831 __git_complete_refs --cur="${cur#--*=}"
1835 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1839 __git_complete_revlist
1846 __gitcomp_builtin fsck
1857 # Lists matching symbol names from a tag (as in ctags) file.
1858 # 1: List symbol names matching this word.
1859 # 2: The tag file to list symbol names from.
1860 # 3: A prefix to be added to each listed symbol name (optional).
1861 # 4: A suffix to be appended to each listed symbol name (optional).
1862 __git_match_ctag () {
1863 awk -v pfx="${3-}" -v sfx="${4-}" "
1864 /^${1//\//\\/}/ { print pfx \$1 sfx }
1868 # Complete symbol names from a tag file.
1869 # Usage: __git_complete_symbol [<option>]...
1870 # --tags=<file>: The tag file to list symbol names from instead of the
1872 # --pfx=<prefix>: A prefix to be added to each symbol name.
1873 # --cur=<word>: The current symbol name to be completed. Defaults to
1874 # the current word to be completed.
1875 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1876 # of the default space.
1877 __git_complete_symbol () {
1878 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1880 while test $# != 0; do
1882 --tags=*) tags="${1##--tags=}" ;;
1883 --pfx=*) pfx="${1##--pfx=}" ;;
1884 --cur=*) cur_="${1##--cur=}" ;;
1885 --sfx=*) sfx="${1##--sfx=}" ;;
1891 if test -r "$tags"; then
1892 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1898 __git_has_doubledash && return
1902 __gitcomp_builtin grep
1907 case "$cword,$prev" in
1908 $((__git_cmd_idx+1)),*|*,-*)
1909 __git_complete_symbol && return
1920 __gitcomp_builtin help
1924 if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
1926 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
1928 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1937 false true umask group all world everybody
1938 " "" "${cur##--shared=}"
1942 __gitcomp_builtin init
1952 __gitcomp_builtin ls-files
1957 # XXX ignore options like --modified and always suggest all cached
1959 __git_complete_index_file "--cached"
1966 __gitcomp_builtin ls-remote
1970 __gitcomp_nl "$(__git_remotes)"
1977 __gitcomp_builtin ls-tree
1985 # Options that go well for log, shortlog and gitk
1986 __git_log_common_options="
1988 --branches --tags --remotes
1989 --first-parent --merges --no-merges
1991 --max-age= --since= --after=
1992 --min-age= --until= --before=
1993 --min-parents= --max-parents=
1994 --no-min-parents --no-max-parents
1996 # Options that go well for log and gitk (not shortlog)
1997 __git_log_gitk_options="
1998 --dense --sparse --full-history
1999 --simplify-merges --simplify-by-decoration
2000 --left-right --notes --no-notes
2002 # Options that go well for log and shortlog (not gitk)
2003 __git_log_shortlog_options="
2004 --author= --committer= --grep=
2005 --all-match --invert-grep
2008 __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
2009 __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
2013 __git_has_doubledash && return
2014 __git_find_repo_path
2017 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2020 case "$prev,$cur" in
2022 return # fall back to Bash filename completion
2025 __git_complete_symbol --cur="${cur#:}" --sfx=":"
2029 __git_complete_symbol
2034 --pretty=*|--format=*)
2035 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2040 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
2044 __gitcomp "full short no" "" "${cur##--decorate=}"
2048 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2052 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2056 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
2061 $__git_log_common_options
2062 $__git_log_shortlog_options
2063 $__git_log_gitk_options
2064 --root --topo-order --date-order --reverse
2065 --follow --full-diff
2066 --abbrev-commit --no-abbrev-commit --abbrev=
2067 --relative-date --date=
2068 --pretty= --format= --oneline
2073 --decorate --decorate= --no-decorate
2075 --no-walk --no-walk= --do-walk
2076 --parents --children
2077 --expand-tabs --expand-tabs= --no-expand-tabs
2079 $__git_diff_common_options
2080 --pickaxe-all --pickaxe-regex
2085 return # fall back to Bash filename completion
2088 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
2092 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
2096 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
2100 __git_complete_revlist
2105 __git_complete_strategy && return
2109 __gitcomp_builtin merge
2119 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
2123 __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
2133 __gitcomp_builtin merge-base
2144 __gitcomp_builtin mv
2149 if [ $(__git_count_arguments "mv") -gt 0 ]; then
2150 # We need to show both cached and untracked files (including
2151 # empty directories) since this may not be the last argument.
2152 __git_complete_index_file "--cached --others --directory"
2154 __git_complete_index_file "--cached"
2160 local subcommands='add append copy edit get-ref list merge prune remove show'
2161 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2163 case "$subcommand,$cur" in
2165 __gitcomp_builtin notes
2173 __gitcomp "$subcommands --ref"
2177 *,--reuse-message=*|*,--reedit-message=*)
2178 __git_complete_refs --cur="${cur#*=}"
2181 __gitcomp_builtin notes_$subcommand
2184 # this command does not take a ref, do not complete it
2200 __git_complete_strategy && return
2203 --recurse-submodules=*)
2204 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
2208 __gitcomp_builtin pull
2213 __git_complete_remote_or_refspec
2216 __git_push_recurse_submodules="check on-demand only"
2218 __git_complete_force_with_lease ()
2226 __git_complete_refs --cur="${cur_#*:}"
2229 __git_complete_refs --cur="$cur_"
2238 __gitcomp_nl "$(__git_remotes)"
2241 --recurse-submodules)
2242 __gitcomp "$__git_push_recurse_submodules"
2248 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
2251 --recurse-submodules=*)
2252 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
2255 --force-with-lease=*)
2256 __git_complete_force_with_lease "${cur##--force-with-lease=}"
2260 __gitcomp_builtin push
2264 __git_complete_remote_or_refspec
2272 --creation-factor= --no-dual-color
2273 $__git_diff_common_options
2278 __git_complete_revlist
2281 __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
2282 __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
2286 __git_find_repo_path
2287 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2288 __gitcomp "$__git_rebase_interactive_inprogress_options"
2290 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2291 [ -d "$__git_repo_path"/rebase-merge ]; then
2292 __gitcomp "$__git_rebase_inprogress_options"
2295 __git_complete_strategy && return
2298 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2302 __git_complete_refs --cur="${cur##--onto=}"
2306 __gitcomp_builtin rebase "" \
2307 "$__git_rebase_interactive_inprogress_options"
2316 local subcommands="show delete expire"
2317 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2319 if [ -z "$subcommand" ]; then
2320 __gitcomp "$subcommands"
2326 __git_send_email_confirm_options="always never auto cc compose"
2327 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2332 --to|--cc|--bcc|--from)
2333 __gitcomp "$(__git send-email --dump-aliases)"
2341 $__git_send_email_confirm_options
2342 " "" "${cur##--confirm=}"
2347 $__git_send_email_suppresscc_options
2348 " "" "${cur##--suppress-cc=}"
2352 --smtp-encryption=*)
2353 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2359 " "" "${cur##--thread=}"
2362 --to=*|--cc=*|--bcc=*|--from=*)
2363 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2367 __gitcomp_builtin send-email "$__git_format_patch_extra_options"
2371 __git_complete_revlist
2382 local untracked_state
2385 --ignore-submodules=*)
2386 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2389 --untracked-files=*)
2390 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2395 always never auto column row plain dense nodense
2396 " "" "${cur##--column=}"
2400 __gitcomp_builtin status
2405 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2406 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2408 case "$untracked_state" in
2410 # --ignored option does not matter
2414 complete_opt="--cached --directory --no-empty-directory --others"
2416 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2417 complete_opt="$complete_opt --ignored --exclude=*"
2422 __git_complete_index_file "$complete_opt"
2427 local dwim_opt="$(__git_checkout_default_dwim_mode)"
2431 # Complete local branches (and DWIM branch
2432 # remote branch names) for an option argument
2433 # specifying a new branch name. This is for
2434 # convenience, assuming new branches are
2435 # possibly based on pre-existing branch names.
2436 __git_complete_refs $dwim_opt --mode="heads"
2445 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2448 __gitcomp_builtin switch
2451 # Unlike in git checkout, git switch --orphan does not take
2452 # a start point. Thus we really have nothing to complete after
2454 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
2458 # At this point, we've already handled special completion for
2459 # -c/-C, and --orphan. There are 3 main things left to
2461 # 1) a start-point for -c/-C or -d/--detach
2462 # 2) a remote head, for --track
2463 # 3) a branch name, possibly including DWIM remote branches
2465 if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
2466 __git_complete_refs --mode="refs"
2467 elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
2468 __git_complete_refs --mode="remote-heads"
2470 __git_complete_refs $dwim_opt --mode="heads"
2476 __git_config_get_set_variables ()
2478 local prevword word config_file= c=$cword
2479 while [ $c -gt "$__git_cmd_idx" ]; do
2482 --system|--global|--local|--file=*)
2487 config_file="$word $prevword"
2495 __git config $config_file --name-only --list
2499 __git_compute_config_vars ()
2501 test -n "$__git_config_vars" ||
2502 __git_config_vars="$(git help --config-for-completion)"
2505 __git_config_sections=
2506 __git_compute_config_sections ()
2508 test -n "$__git_config_sections" ||
2509 __git_config_sections="$(git help --config-sections-for-completion)"
2512 # Completes possible values of various configuration variables.
2514 # Usage: __git_complete_config_variable_value [<option>]...
2515 # --varname=<word>: The name of the configuration variable whose value is
2516 # to be completed. Defaults to the previous word on the
2518 # --cur=<word>: The current value to be completed. Defaults to the current
2519 # word to be completed.
2520 __git_complete_config_variable_value ()
2522 local varname="$prev" cur_="$cur"
2524 while test $# != 0; do
2526 --varname=*) varname="${1##--varname=}" ;;
2527 --cur=*) cur_="${1##--cur=}" ;;
2533 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2534 varname="${varname,,}"
2536 varname="$(echo "$varname" |tr A-Z a-z)"
2540 branch.*.remote|branch.*.pushremote)
2541 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2545 __git_complete_refs --cur="$cur_"
2549 __gitcomp "false true merges interactive" "" "$cur_"
2553 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2557 local remote="${varname#remote.}"
2558 remote="${remote%.fetch}"
2559 if [ -z "$cur_" ]; then
2560 __gitcomp_nl "refs/heads/" "" "" ""
2563 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2567 local remote="${varname#remote.}"
2568 remote="${remote%.push}"
2569 __gitcomp_nl "$(__git for-each-ref \
2570 --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2573 pull.twohead|pull.octopus)
2574 __git_compute_merge_strategies
2575 __gitcomp "$__git_merge_strategies" "" "$cur_"
2579 __gitcomp "false true" "" "$cur_"
2584 normal black red green yellow blue magenta cyan white
2585 bold dim ul blink reverse
2590 __gitcomp "false true always never auto" "" "$cur_"
2594 __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2598 __gitcomp "man info web html" "" "$cur_"
2602 __gitcomp "$__git_log_date_formats" "" "$cur_"
2605 sendemail.aliasfiletype)
2606 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2610 __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2613 sendemail.suppresscc)
2614 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2617 sendemail.transferencoding)
2618 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2627 # Completes configuration sections, subsections, variable names.
2629 # Usage: __git_complete_config_variable_name [<option>]...
2630 # --cur=<word>: The current configuration section/variable name to be
2631 # completed. Defaults to the current word to be completed.
2632 # --sfx=<suffix>: A suffix to be appended to each fully completed
2633 # configuration variable name (but not to sections or
2634 # subsections) instead of the default space.
2635 __git_complete_config_variable_name ()
2637 local cur_="$cur" sfx
2639 while test $# != 0; do
2641 --cur=*) cur_="${1##--cur=}" ;;
2642 --sfx=*) sfx="${1##--sfx=}" ;;
2650 local pfx="${cur_%.*}."
2652 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2656 local pfx="${cur_%.*}."
2658 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2659 __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
2663 local pfx="${cur_%.*}."
2666 argPrompt cmd confirm needsFile noConsole noRescan
2667 prompt revPrompt revUnmerged title
2668 " "$pfx" "$cur_" "$sfx"
2672 local pfx="${cur_%.*}."
2674 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2678 local pfx="${cur_%.*}."
2680 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2684 local pfx="${cur_%.*}."
2686 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2690 local pfx="${cur_%.*}."
2692 __git_compute_all_commands
2693 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
2697 local pfx="${cur_%.*}."
2700 url proxy fetch push mirror skipDefaultUpdate
2701 receivepack uploadpack tagOpt pushurl
2702 " "$pfx" "$cur_" "$sfx"
2706 local pfx="${cur_%.*}."
2708 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2709 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
2713 local pfx="${cur_%.*}."
2715 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2719 __git_compute_config_vars
2720 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
2723 __git_compute_config_sections
2724 __gitcomp "$__git_config_sections" "" "$cur_" "."
2729 # Completes '='-separated configuration sections/variable names and values
2730 # for 'git -c section.name=value'.
2732 # Usage: __git_complete_config_variable_name_and_value [<option>]...
2733 # --cur=<word>: The current configuration section/variable name/value to be
2734 # completed. Defaults to the current word to be completed.
2735 __git_complete_config_variable_name_and_value ()
2739 while test $# != 0; do
2741 --cur=*) cur_="${1##--cur=}" ;;
2749 __git_complete_config_variable_value \
2750 --varname="${cur_%%=*}" --cur="${cur_#*=}"
2753 __git_complete_config_variable_name --cur="$cur_" --sfx='='
2761 --get|--get-all|--unset|--unset-all)
2762 __gitcomp_nl "$(__git_config_get_set_variables)"
2766 __git_complete_config_variable_value
2772 __gitcomp_builtin config
2775 __git_complete_config_variable_name
2783 add rename remove set-head set-branches
2784 get-url set-url show prune update
2786 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2787 if [ -z "$subcommand" ]; then
2790 __gitcomp_builtin remote
2793 __gitcomp "$subcommands"
2799 case "$subcommand,$cur" in
2801 __gitcomp_builtin remote_add
2806 __gitcomp_builtin remote_set-head
2809 __gitcomp_builtin remote_set-branches
2811 set-head,*|set-branches,*)
2812 __git_complete_remote_or_refspec
2815 __gitcomp_builtin remote_update
2818 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
2821 __gitcomp_builtin remote_set-url
2824 __gitcomp_builtin remote_get-url
2827 __gitcomp_builtin remote_prune
2830 __gitcomp_nl "$(__git_remotes)"
2839 __gitcomp "short medium long" "" "${cur##--format=}"
2843 __gitcomp_builtin replace
2852 local subcommands="clear forget diff remaining status gc"
2853 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2854 if test -z "$subcommand"
2856 __gitcomp "$subcommands"
2863 __git_has_doubledash && return
2867 __gitcomp_builtin reset
2885 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2888 __git_complete_refs --cur="${cur##--source=}"
2891 __gitcomp_builtin restore
2894 if __git rev-parse --verify --quiet HEAD >/dev/null; then
2895 __git_complete_index_file "--modified"
2900 __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2904 __git_find_repo_path
2905 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2906 __gitcomp "$__git_revert_inprogress_options"
2909 __git_complete_strategy && return
2912 __gitcomp_builtin revert "" \
2913 "$__git_revert_inprogress_options"
2924 __gitcomp_builtin rm
2929 __git_complete_index_file "--cached"
2934 __git_has_doubledash && return
2939 $__git_log_common_options
2940 $__git_log_shortlog_options
2941 --numbered --summary --email
2946 __git_complete_revlist
2951 __git_has_doubledash && return
2954 --pretty=*|--format=*)
2955 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2960 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2964 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2968 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
2972 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
2976 __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
2977 --oneline --show-signature
2978 --expand-tabs --expand-tabs= --no-expand-tabs
2979 $__git_diff_common_options
2984 __git_complete_revlist_file
2991 __gitcomp_builtin show-branch
2995 __git_complete_revlist
2998 __gitcomp_directories ()
3000 local _tmp_dir _tmp_completions _found=0
3002 # Get the directory of the current token; this differs from dirname
3003 # in that it keeps up to the final trailing slash. If no slash found
3006 _tmp_dir=$BASH_REMATCH
3008 # Find possible directory completions, adding trailing '/' characters,
3009 # de-quoting, and handling unusual characters.
3010 while IFS= read -r -d $'\0' c ; do
3011 # If there are directory completions, find ones that start
3012 # with "$cur", the current token, and put those in COMPREPLY
3013 if [[ $c == "$cur"* ]]; then
3017 done < <(git ls-tree -z -d --name-only HEAD $_tmp_dir)
3019 if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then
3020 # No possible further completions any deeper, so assume we're at
3021 # a leaf directory and just consider it complete
3022 __gitcomp_direct_append "$cur "
3026 _git_sparse_checkout ()
3028 local subcommands="list init set disable add reapply"
3029 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3030 if [ -z "$subcommand" ]; then
3031 __gitcomp "$subcommands"
3035 case "$subcommand,$cur" in
3037 __gitcomp_builtin sparse-checkout_$subcommand "" "--"
3040 if [ "$(__git config core.sparseCheckoutCone)" == "true" ] ||
3041 [ -n "$(__git_find_on_cmdline --cone)" ]; then
3042 __gitcomp_directories
3049 local subcommands='push list show apply clear drop pop create branch'
3050 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3052 if [ -z "$subcommand" ]; then
3053 case "$((cword - __git_cmd_idx)),$cur" in
3055 __gitcomp_builtin stash_push
3061 __gitcomp "$subcommands"
3067 case "$subcommand,$cur" in
3069 # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3070 __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
3073 __gitcomp_builtin stash_show "$__git_diff_common_options"
3076 __gitcomp_builtin "stash_$subcommand"
3079 if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3082 __gitcomp_nl "$(__git stash list \
3083 | sed -n -e 's/:.*//p')"
3086 show,*|apply,*|drop,*|pop,*)
3087 __gitcomp_nl "$(__git stash list \
3088 | sed -n -e 's/:.*//p')"
3095 __git_has_doubledash && return
3097 local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
3098 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3099 if [ -z "$subcommand" ]; then
3105 __gitcomp "$subcommands"
3111 case "$subcommand,$cur" in
3113 __gitcomp "--branch --force --name --reference --depth"
3116 __gitcomp "--cached --recursive"
3119 __gitcomp "--force --all"
3123 --init --remote --no-fetch
3124 --recommend-shallow --no-recommend-shallow
3125 --force --rebase --merge --reference --depth --recursive --jobs
3129 __gitcomp "--default --branch"
3132 __gitcomp "--cached --files --summary-limit"
3134 foreach,--*|sync,--*)
3135 __gitcomp "--recursive"
3145 init fetch clone rebase dcommit log find-rev
3146 set-tree commit-diff info create-ignore propget
3147 proplist show-ignore show-externals branch tag blame
3148 migrate mkdirs reset gc
3150 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3151 if [ -z "$subcommand" ]; then
3152 __gitcomp "$subcommands"
3154 local remote_opts="--username= --config-dir= --no-auth-cache"
3156 --follow-parent --authors-file= --repack=
3157 --no-metadata --use-svm-props --use-svnsync-props
3158 --log-window-size= --no-checkout --quiet
3159 --repack-flags --use-log-author --localtime
3162 --ignore-paths= --include-paths= $remote_opts
3165 --template= --shared= --trunk= --tags=
3166 --branches= --stdlayout --minimize-url
3167 --no-metadata --use-svm-props --use-svnsync-props
3168 --rewrite-root= --prefix= $remote_opts
3171 --edit --rmdir --find-copies-harder --copy-similarity=
3174 case "$subcommand,$cur" in
3176 __gitcomp "--revision= --fetch-all $fc_opts"
3179 __gitcomp "--revision= $fc_opts $init_opts"
3182 __gitcomp "$init_opts"
3186 --merge --strategy= --verbose --dry-run
3187 --fetch-all --no-rebase --commit-url
3188 --revision --interactive $cmt_opts $fc_opts
3192 __gitcomp "--stdin $cmt_opts $fc_opts"
3194 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
3195 show-externals,--*|mkdirs,--*)
3196 __gitcomp "--revision="
3200 --limit= --revision= --verbose --incremental
3201 --oneline --show-commit --non-recursive
3202 --authors-file= --color
3207 --merge --verbose --strategy= --local
3208 --fetch-all --dry-run $fc_opts
3212 __gitcomp "--message= --file= --revision= $cmt_opts"
3218 __gitcomp "--dry-run --message --tag"
3221 __gitcomp "--dry-run --message"
3224 __gitcomp "--git-format"
3228 --config-dir= --ignore-paths= --minimize
3229 --no-auth-cache --username=
3233 __gitcomp "--revision= --parent"
3243 local i c="$__git_cmd_idx" f=0
3244 while [ $c -lt $cword ]; do
3247 -d|--delete|-v|--verify)
3248 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3263 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3273 __gitcomp_builtin tag
3283 __git_complete_worktree_paths ()
3286 # Generate completion reply from worktree list skipping the first
3287 # entry: it's the path of the main worktree, which can't be moved,
3288 # removed, locked, etc.
3289 __gitcomp_nl "$(git worktree list --porcelain |
3290 sed -n -e '2,$ s/^worktree //p')"
3295 local subcommands="add list lock move prune remove unlock"
3296 local subcommand subcommand_idx
3298 subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3299 subcommand_idx="${subcommand% *}"
3300 subcommand="${subcommand#* }"
3302 case "$subcommand,$cur" in
3304 __gitcomp "$subcommands"
3307 __gitcomp_builtin worktree_$subcommand
3309 add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
3310 # Here we are not completing an --option, it's either the
3313 -b|-B) # Complete refs for branch to be created/reseted.
3316 -*) # The previous word is an -o|--option without an
3317 # unstuck argument: have to complete the path for
3318 # the new worktree, so don't list anything, but let
3319 # Bash fall back to filename completion.
3321 *) # The previous word is not an --option, so it must
3322 # be either the 'add' subcommand, the unstuck
3323 # argument of an option (e.g. branch for -b|-B), or
3324 # the path for the new worktree.
3325 if [ $cword -eq $((subcommand_idx+1)) ]; then
3326 # Right after the 'add' subcommand: have to
3327 # complete the path, so fall back to Bash
3328 # filename completion.
3331 case "${words[cword-2]}" in
3332 -b|-B) # After '-b <branch>': have to
3333 # complete the path, so fall back
3334 # to Bash filename completion.
3336 *) # After the path: have to complete
3337 # the ref to be checked out.
3345 lock,*|remove,*|unlock,*)
3346 __git_complete_worktree_paths
3349 if [ $cword -eq $((subcommand_idx+1)) ]; then
3350 # The first parameter must be an existing working
3352 __git_complete_worktree_paths
3354 # The second parameter is the destination: it could
3355 # be any path, so don't list anything, but let Bash
3356 # fall back to filename completion.
3363 __git_complete_common () {
3368 __gitcomp_builtin "$command"
3373 __git_cmds_with_parseopt_helper=
3374 __git_support_parseopt_helper () {
3375 test -n "$__git_cmds_with_parseopt_helper" ||
3376 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
3378 case " $__git_cmds_with_parseopt_helper " in
3388 __git_have_func () {
3389 declare -f -- "$1" >/dev/null 2>&1
3392 __git_complete_command () {
3394 local completion_func="_git_${command//-/_}"
3395 if ! __git_have_func $completion_func &&
3396 __git_have_func _completion_loader
3398 _completion_loader "git-$command"
3400 if __git_have_func $completion_func
3404 elif __git_support_parseopt_helper "$command"
3406 __git_complete_common "$command"
3415 local i c=1 command __git_dir __git_repo_path
3416 local __git_C_args C_args_count=0
3419 while [ $c -lt $cword ]; do
3423 __git_dir="${i#--git-dir=}"
3427 __git_dir="${words[c]}"
3436 -c|--work-tree|--namespace)
3440 __git_C_args[C_args_count++]=-C
3442 __git_C_args[C_args_count++]="${words[c]}"
3455 if [ -z "${command-}" ]; then
3457 --git-dir|-C|--work-tree)
3458 # these need a path argument, let's fall back to
3459 # Bash filename completion
3463 __git_complete_config_variable_name_and_value
3467 # we don't support completing these options' arguments
3486 --no-replace-objects
3491 if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3493 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3495 local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
3497 if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
3499 list_cmds=builtins,$list_cmds
3501 __gitcomp "$(__git --list-cmds=$list_cmds)"
3508 __git_complete_command "$command" && return
3510 local expansion=$(__git_aliased_command "$command")
3511 if [ -n "$expansion" ]; then
3513 __git_complete_command "$expansion"
3519 __git_has_doubledash && return
3521 local __git_repo_path
3522 __git_find_repo_path
3525 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3531 $__git_log_common_options
3532 $__git_log_gitk_options
3538 __git_complete_revlist
3541 if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
3542 echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
3548 local cur words cword prev
3549 local __git_cmd_idx=0
3550 _get_comp_words_by_ref -n =: cur words cword prev
3556 local wrapper="__git_wrap${2}"
3557 eval "$wrapper () { __git_func_wrap $2 ; }"
3558 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3559 || complete -o default -o nospace -F $wrapper $1
3562 # Setup the completion for git commands
3563 # 1: command or alias
3564 # 2: function to call (e.g. `git
`, `gitk
`, `git_fetch
`)
3569 if __git_have_func $2; then
3571 elif __git_have_func __$2_main; then
3573 elif __git_have_func _$2; then
3576 echo "ERROR: could not find function '$2'" 1>&2
3579 ___git_complete $1 $func
3582 ___git_complete git __git_main
3583 ___git_complete gitk __gitk_main
3585 # The following are necessary only for Cygwin, and only are needed
3586 # when the user has tab-completed the executable name and consequently
3587 # included the '.exe' suffix.
3589 if [ "$OSTYPE" = cygwin ]; then
3590 ___git_complete git.exe __git_main