]>
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 ; ... '".
31 # Note that "git" is optional --- '!f() { : commit; ...}; f' would complete
32 # just like the 'git commit' command.
34 # If you have a command that is not part of git, but you would still
35 # like completion, you can use __git_complete:
37 # __git_complete gl git_log
39 # Or if it's a main command (i.e. git or gitk):
41 # __git_complete gk gitk
43 # Compatible with bash 3.2.57.
45 # You can set the following environment variables to influence the behavior of
46 # the completion routines:
48 # GIT_COMPLETION_CHECKOUT_NO_GUESS
50 # When set to "1", do not include "DWIM" suggestions in git-checkout
51 # and git-switch completion (e.g., completing "foo" when "origin/foo"
54 # GIT_COMPLETION_SHOW_ALL_COMMANDS
56 # When set to "1" suggest all commands, including plumbing commands
57 # which are hidden by default (e.g. "cat-file" on "git ca<TAB>").
59 # GIT_COMPLETION_SHOW_ALL
61 # When set to "1" suggest all options, including options which are
62 # typically hidden (e.g. '--allow-empty' for 'git commit').
64 # GIT_COMPLETION_IGNORE_CASE
66 # When set, uses for-each-ref '--ignore-case' to find refs that match
67 # case insensitively, even on systems with case sensitive file systems
68 # (e.g., completing tag name "FOO" on "git checkout f<TAB>").
70 case "$COMP_WORDBREAKS" in
72 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
75 # Discovers the path to the git repository taking any '--git-dir=<path>' and
76 # '-C <path>' options into account and stores it in the $__git_repo_path
78 __git_find_repo_path
()
80 if [ -n "${__git_repo_path-}" ]; then
81 # we already know where it is
85 if [ -n "${__git_C_args-}" ]; then
86 __git_repo_path
="$(git "${__git_C_args[@]}" \
87 ${__git_dir:+--git-dir="$__git_dir"} \
88 rev-parse --absolute-git-dir 2>/dev/null)"
89 elif [ -n "${__git_dir-}" ]; then
90 test -d "$__git_dir" &&
91 __git_repo_path
="$__git_dir"
92 elif [ -n "${GIT_DIR-}" ]; then
94 __git_repo_path
="$GIT_DIR"
95 elif [ -d .git
]; then
98 __git_repo_path
="$(git rev-parse --git-dir 2>/dev/null)"
102 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
103 # __gitdir accepts 0 or 1 arguments (i.e., location)
104 # returns location of .git repo
107 if [ -z "${1-}" ]; then
108 __git_find_repo_path ||
return 1
109 echo "$__git_repo_path"
110 elif [ -d "$1/.git" ]; then
117 # Runs git with all the options given as argument, respecting any
118 # '--git-dir=<path>' and '-C <path>' options present on the command line
121 git
${__git_C_args:+"${__git_C_args[@]}"} \
122 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev
/null
125 # Removes backslash escaping, single quotes and double quotes from a word,
126 # stores the result in the variable $dequoted_word.
127 # 1: The word to dequote.
130 local rest
="$1" len ch
134 while test -n "$rest"; do
135 len
=${#dequoted_word}
136 dequoted_word
="$dequoted_word${rest%%[\\\'\"]*}"
137 rest
="${rest:$((${#dequoted_word}-$len))}"
139 case "${rest:0:1}" in
146 dequoted_word
="$dequoted_word$ch"
153 len
=${#dequoted_word}
154 dequoted_word
="$dequoted_word${rest%%\'*}"
155 rest
="${rest:$((${#dequoted_word}-$len+1))}"
159 while test -n "$rest" ; do
160 len
=${#dequoted_word}
161 dequoted_word
="$dequoted_word${rest%%[\\\"]*}"
162 rest
="${rest:$((${#dequoted_word}-$len))}"
163 case "${rest:0:1}" in
168 dequoted_word="$dequoted_word$ch"
173 dequoted_word="$dequoted_word\\$ch"
189 # The following function is based on code from:
191 # bash_completion - programmable completion functions for bash 3.2+
193 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
194 # © 2009-2010, Bash Completion Maintainers
195 # <bash-completion-devel@lists.alioth.debian.org>
197 # This program is free software; you can redistribute it and/or modify
198 # it under the terms of the GNU General Public License as published by
199 # the Free Software Foundation; either version 2, or (at your option)
202 # This program is distributed in the hope that it will be useful,
203 # but WITHOUT ANY WARRANTY; without even the implied warranty of
204 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
205 # GNU General Public License for more details.
207 # You should have received a copy of the GNU General Public License
208 # along with this program; if not, see <http://www.gnu.org/licenses/>.
210 # The latest version of this software can be obtained here:
212 # http://bash-completion.alioth.debian.org/
216 # This function can be used to access a tokenized list of words
217 # on the command line:
219 # __git_reassemble_comp_words_by_ref '=:'
220 # if test "${words_[cword_-1]}" = -w
225 # The argument should be a collection of characters from the list of
226 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
229 # This is roughly equivalent to going back in time and setting
230 # COMP_WORDBREAKS to exclude those characters. The intent is to
231 # make option types like --date=<type> and <rev>:<path> easy to
232 # recognize by treating each shell word as a single token.
234 # It is best not to set COMP_WORDBREAKS directly because the value is
235 # shared with other completion scripts. By the time the completion
236 # function gets called, COMP_WORDS has already been populated so local
237 # changes to COMP_WORDBREAKS have no effect.
239 # Output: words_, cword_, cur_.
241 __git_reassemble_comp_words_by_ref()
243 local exclude i j first
244 # Which word separators to exclude?
245 exclude="${1//[^$COMP_WORDBREAKS]}"
247 if [ -z "$exclude" ]; then
248 words_=("${COMP_WORDS[@]}")
251 # List of word completion separators has shrunk;
252 # re-assemble words to complete.
253 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
254 # Append each nonempty word consisting of just
255 # word separator characters to the current word.
259 [ -n "${COMP_WORDS[$i]}" ] &&
260 # word consists of excluded word separators
261 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
263 # Attach to the previous token,
264 # unless the previous token is the command name.
265 if [ $j -ge 2 ] && [ -n "$first" ]; then
269 words_[$j]=${words_[j]}${COMP_WORDS[i]}
270 if [ $i = $COMP_CWORD ]; then
273 if (($i < ${#COMP_WORDS[@]} - 1)); then
280 words_[$j]=${words_[j]}${COMP_WORDS[i]}
281 if [ $i = $COMP_CWORD ]; then
287 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
288 _get_comp_words_by_ref ()
290 local exclude cur_ words_ cword_
291 if [ "$1" = "-n" ]; then
295 __git_reassemble_comp_words_by_ref "$exclude"
296 cur_=${words_[cword_]}
297 while [ $# -gt 0 ]; do
303 prev=${words_[$cword_-1]}
306 words=("${words_[@]}")
317 # Fills the COMPREPLY array with prefiltered words without any additional
319 # Callers must take care of providing only words that match the current word
320 # to be completed and adding any prefix and/or suffix (trailing space!), if
322 # 1: List of newline-separated matching completion words, complete with
331 # Similar to __gitcomp_direct, but appends to COMPREPLY instead.
332 # Callers must take care of providing only words that match the current word
333 # to be completed and adding any prefix and/or suffix (trailing space!), if
335 # 1: List of newline-separated matching completion words, complete with
337 __gitcomp_direct_append ()
346 local x i=${#COMPREPLY[@]}
348 if [[ "$x" == "$3"* ]]; then
349 COMPREPLY[i++]="$2$x$4"
360 # Generates completion reply, appending a space to possible completion words,
362 # It accepts 1 to 4 arguments:
363 # 1: List of possible completion words.
364 # 2: A prefix to be added to each possible completion word (optional).
365 # 3: Generate possible completion matches for this word (optional).
366 # 4: A suffix to be appended to each possible completion word (optional).
369 local cur_="${3-$cur}"
375 local c i=0 IFS=$' \t\n'
377 if [[ $c == "--" ]]; then
381 if [[ $c == "$cur_"* ]]; then
386 COMPREPLY[i++]="${2-}$c"
391 local c i=0 IFS=$' \t\n'
393 if [[ $c == "--" ]]; then
395 if [[ $c == "$cur_"* ]]; then
396 COMPREPLY[i++]="${2-}$c "
401 if [[ $c == "$cur_"* ]]; then
406 COMPREPLY[i++]="${2-}$c"
413 # Clear the variables caching builtins' options when (re-)sourcing
414 # the completion script.
415 if [[ -n ${ZSH_VERSION-} ]]; then
416 unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
418 unset $(compgen -v __gitcomp_builtin_)
421 # This function is equivalent to
423 # __gitcomp "$(git xxx --git-completion-helper) ..."
425 # except that the output is cached. Accept 1-3 arguments:
426 # 1: the git command to execute, this is also the cache key
427 # 2: extra options to be added on top (e.g. negative forms)
428 # 3: options to be excluded
431 # spaces must be replaced with underscore for multi-word
432 # commands, e.g. "git remote add" becomes remote_add.
437 local var=__gitcomp_builtin_"${cmd//-/_}"
439 eval "options=\${$var-}"
441 if [ -z "$options" ]; then
442 local completion_helper
443 if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
444 completion_helper="--git-completion-helper-all"
446 completion_helper="--git-completion-helper"
448 # leading and trailing spaces are significant to make
449 # option removal work correctly.
450 options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
453 options="${options/ $i / }"
455 eval "$var=\"$options\""
461 # Variation of __gitcomp_nl () that appends to the existing list of
462 # completion candidates, COMPREPLY.
463 __gitcomp_nl_append ()
466 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
469 # Generates completion reply from newline-separated possible completion words
470 # by appending a space to all of them.
471 # It accepts 1 to 4 arguments:
472 # 1: List of possible completion words, separated by a single newline.
473 # 2: A prefix to be added to each possible completion word (optional).
474 # 3: Generate possible completion matches for this word (optional).
475 # 4: A suffix to be appended to each possible completion word instead of
476 # the default space (optional). If specified but empty, nothing is
481 __gitcomp_nl_append "$@"
484 # Fills the COMPREPLY array with prefiltered paths without any additional
486 # Callers must take care of providing only paths that match the current path
487 # to be completed and adding any prefix path components, if necessary.
488 # 1: List of newline-separated matching paths, complete with all prefix
490 __gitcomp_file_direct ()
496 # use a hack to enable file mode in bash < 4
497 compopt -o filenames +o nospace 2>/dev/null ||
498 compgen -f /non-existing-dir/ >/dev/null ||
502 # Generates completion reply with compgen from newline-separated possible
503 # completion filenames.
504 # It accepts 1 to 3 arguments:
505 # 1: List of possible completion filenames, separated by a single newline.
506 # 2: A directory prefix to be added to each possible completion filename
508 # 3: Generate possible completion matches for this word (optional).
513 # XXX does not work when the directory prefix contains a tilde,
514 # since tilde expansion is not applied.
515 # This means that COMPREPLY will be empty and Bash default
516 # completion will be used.
517 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
519 # use a hack to enable file mode in bash < 4
520 compopt -o filenames +o nospace 2>/dev/null ||
521 compgen -f /non-existing-dir/ >/dev/null ||
525 # Execute 'git ls-files', unless the --committable option is specified, in
526 # which case it runs 'git diff-index' to find out the files that can be
527 # committed. It return paths relative to the directory specified in the first
528 # argument, and using the options specified in the second argument.
529 __git_ls_files_helper ()
531 if [ "$2" = "--committable" ]; then
532 __git -C "$1" -c core.quotePath=false diff-index \
533 --name-only --relative HEAD -- "${3//\\/\\\\}*"
535 # NOTE: $2 is not quoted in order to support multiple options
536 __git -C "$1" -c core.quotePath=false ls-files \
537 --exclude-standard $2 -- "${3//\\/\\\\}*"
542 # __git_index_files accepts 1 or 2 arguments:
543 # 1: Options to pass to ls-files (required).
544 # 2: A directory path (optional).
545 # If provided, only files within the specified directory are listed.
546 # Sub directories are never recursed. Path must have a trailing
548 # 3: List only paths matching this path component (optional).
551 local root="$2" match="$3"
553 __git_ls_files_helper "$root" "$1" "${match:-?}" |
554 awk -F / -v pfx="${2//\\/\\\\}" '{
559 if (substr(p, 1, 1) != "\"") {
560 # No special characters, easy!
565 # The path is quoted.
570 # Even when a directory name itself does not contain
571 # any special characters, it will still be quoted if
572 # any of its (stripped) trailing path components do.
573 # Because of this we may have seen the same directory
574 # both quoted and unquoted.
576 # We have seen the same directory unquoted,
583 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
584 # Skip opening double quote.
587 # Interpret backslash escape sequences.
588 while ((bs_idx = index(p, "\\")) != 0) {
589 out = out substr(p, 1, bs_idx - 1)
590 esc = substr(p, bs_idx + 1, 1)
591 p = substr(p, bs_idx + 2)
593 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
594 # C-style one-character escape sequence.
595 out = out substr("\a\b\t\v\f\r\"\\",
597 } else if (esc == "n") {
598 # Uh-oh, a newline character.
599 # We cannot reliably put a pathname
600 # containing a newline into COMPREPLY,
601 # and the newline would create a mess.
605 # Must be a \nnn octal value, then.
607 substr(p, 1, 1) * 8 + \
609 out = out sprintf("%c", dec)
613 # Drop closing double quote, if there is one.
614 # (There is not any if this is a directory, as it was
615 # already stripped with the trailing path components.)
616 if (substr(p, length(p), 1) == "\"")
617 out = out substr(p, 1, length(p) - 1)
625 # __git_complete_index_file requires 1 argument:
626 # 1: the options to pass to ls-file
628 # The exception is --committable, which finds the files appropriate commit.
629 __git_complete_index_file ()
631 local dequoted_word pfx="" cur_
635 case "$dequoted_word" in
637 pfx="${dequoted_word%/*}/"
638 cur_="${dequoted_word##*/}"
641 cur_="$dequoted_word"
644 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
647 # Lists branches from the local repository.
648 # 1: A prefix to be added to each listed branch (optional).
649 # 2: List only branches matching this word (optional; list all branches if
651 # 3: A suffix to be appended to each listed branch (optional).
654 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
656 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
657 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
658 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
661 # Lists branches from remote repositories.
662 # 1: A prefix to be added to each listed branch (optional).
663 # 2: List only branches matching this word (optional; list all branches if
665 # 3: A suffix to be appended to each listed branch (optional).
666 __git_remote_heads ()
668 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
670 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
671 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
672 "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
675 # Lists tags from the local repository.
676 # Accepts the same positional parameters as __git_heads() above.
679 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
681 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
682 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
683 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
686 # List unique branches from refs/remotes used for 'git checkout' and 'git
687 # switch' tracking DWIMery.
688 # 1: A prefix to be added to each listed branch (optional)
689 # 2: List only branches matching this word (optional; list all branches if
691 # 3: A suffix to be appended to each listed branch (optional).
692 __git_dwim_remote_heads ()
694 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
695 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
697 # employ the heuristic used by git checkout and git switch
698 # Try to find a remote branch that cur_es the completion word
699 # but only output if the branch name is unique
700 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
701 --sort="refname:strip=3" \
702 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
703 "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
707 # Lists refs from the local (by default) or from a remote repository.
708 # It accepts 0, 1 or 2 arguments:
709 # 1: The remote to list refs from (optional; ignored, if set but empty).
710 # Can be the name of a configured remote, a path, or a URL.
711 # 2: In addition to local refs, list unique branches from refs/remotes/ for
712 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
713 # 3: A prefix to be added to each listed ref (optional).
714 # 4: List only refs matching this word (optional; list all refs if unset or
716 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
719 # Use __git_complete_refs() instead.
722 local i hash dir track="${2-}"
723 local list_refs_from=path remote="${1-}"
725 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
728 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
731 dir="$__git_repo_path"
733 if [ -z "$remote" ]; then
734 if [ -z "$dir" ]; then
738 if __git_is_configured_remote "$remote"; then
739 # configured remote takes precedence over a
740 # local directory with the same name
741 list_refs_from=remote
742 elif [ -d "$remote/.git" ]; then
744 elif [ -d "$remote" ]; then
751 if test "${GIT_COMPLETION_IGNORE_CASE:+1}" = "1"
753 # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility
754 umatch=$(echo "$match" | tr a-z A-Z 2>/dev/null || echo "$match")
757 if [ "$list_refs_from" = path ]; then
758 if [[ "$cur_" == ^* ]]; then
768 refs=("$match*" "$match*/**")
772 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD AUTO_MERGE; do
775 if [ -e "$dir/$i" ]; then
781 format="refname:strip=2"
782 refs=("refs/tags/$match*" "refs/tags/$match*/**"
783 "refs/heads/$match*" "refs/heads/$match*/**"
784 "refs/remotes/$match*" "refs/remotes/$match*/**")
787 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
788 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
790 if [ -n "$track" ]; then
791 __git_dwim_remote_heads "$pfx" "$match" "$sfx"
797 __git ls-remote "$remote" "$match*" | \
798 while read -r hash i; do
801 *) echo "$pfx$i$sfx" ;;
806 if [ "$list_refs_from" = remote ]; then
808 $match*|$umatch*) echo "${pfx}HEAD$sfx" ;;
810 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
811 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
812 "refs/remotes/$remote/$match*" \
813 "refs/remotes/$remote/$match*/**"
817 $match*|$umatch*) query_symref="HEAD" ;;
819 __git ls-remote "$remote" $query_symref \
820 "refs/tags/$match*" "refs/heads/$match*" \
821 "refs/remotes/$match*" |
822 while read -r hash i; do
825 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
826 *) echo "$pfx$i$sfx" ;; # symbolic refs
834 # Completes refs, short and long, local and remote, symbolic and pseudo.
836 # Usage: __git_complete_refs [<option>]...
837 # --remote=<remote>: The remote to list refs from, can be the name of a
838 # configured remote, a path, or a URL.
839 # --dwim: List unique remote branches for 'git switch's tracking DWIMery.
840 # --pfx=<prefix>: A prefix to be added to each ref.
841 # --cur=<word>: The current ref to be completed. Defaults to the current
842 # word to be completed.
843 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
845 # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
846 # complete all refs, 'heads' to complete only branches, or
847 # 'remote-heads' to complete only remote branches. Note that
848 # --remote is only compatible with --mode=refs.
849 __git_complete_refs ()
851 local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
853 while test $# != 0; do
855 --remote=*) remote="${1##--remote=}" ;;
856 --dwim) dwim="yes" ;;
857 # --track is an old spelling of --dwim
858 --track) dwim="yes" ;;
859 --pfx=*) pfx="${1##--pfx=}" ;;
860 --cur=*) cur_="${1##--cur=}" ;;
861 --sfx=*) sfx="${1##--sfx=}" ;;
862 --mode=*) mode="${1##--mode=}" ;;
868 # complete references based on the specified mode
871 __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
873 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
875 __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
880 # Append DWIM remote branch names if requested
881 if [ "$dwim" = "yes" ]; then
882 __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
886 # __git_refs2 requires 1 argument (to pass to __git_refs)
887 # Deprecated: use __git_complete_fetch_refspecs() instead.
891 for i in $(__git_refs "$1"); do
896 # Completes refspecs for fetching from a remote repository.
897 # 1: The remote repository.
898 # 2: A prefix to be added to each listed refspec (optional).
899 # 3: The ref to be completed as a refspec instead of the current word to be
900 # completed (optional)
901 # 4: A suffix to be appended to each listed refspec instead of the default
903 __git_complete_fetch_refspecs ()
905 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
908 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
914 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
915 __git_refs_remotes ()
918 __git ls-remote "$1" 'refs/heads/*' | \
919 while read -r hash i; do
920 echo "$i:refs/remotes/$1/${i#refs/heads/}"
927 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
931 # Returns true if $1 matches the name of a configured remote, false otherwise.
932 __git_is_configured_remote ()
935 for remote in $(__git_remotes); do
936 if [ "$remote" = "$1" ]; then
943 __git_list_merge_strategies ()
945 LANG=C LC_ALL=C git merge -s help 2>&1 |
946 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
955 __git_merge_strategies=
956 # 'git merge -s help' (and thus detection of the merge strategy
957 # list) fails, unfortunately, if run outside of any git working
958 # tree. __git_merge_strategies is set to the empty string in
959 # that case, and the detection will be repeated the next time it
961 __git_compute_merge_strategies ()
963 test -n "$__git_merge_strategies" ||
964 __git_merge_strategies=$(__git_list_merge_strategies)
967 __git_merge_strategy_options="ours theirs subtree subtree= patience
968 histogram diff-algorithm= ignore-space-change ignore-all-space
969 ignore-space-at-eol renormalize no-renormalize no-renames
970 find-renames find-renames= rename-threshold="
972 __git_complete_revlist_file ()
974 local dequoted_word pfx ls ref cur_="$cur"
983 __git_dequote "$cur_"
985 case "$dequoted_word" in
987 pfx="${dequoted_word%/*}"
988 cur_="${dequoted_word##*/}"
993 cur_="$dequoted_word"
998 case "$COMP_WORDBREAKS" in
1000 *) pfx="$ref:$pfx" ;;
1003 __gitcomp_file "$(__git ls-tree "$ls" \
1009 pfx="${cur_%...*}..."
1011 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1016 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1024 __git_complete_file ()
1026 __git_complete_revlist_file
1029 __git_complete_revlist ()
1031 __git_complete_revlist_file
1034 __git_complete_remote_or_refspec ()
1036 local cur_="$cur" cmd="${words[__git_cmd_idx]}"
1037 local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
1038 if [ "$cmd" = "remote" ]; then
1041 while [ $c -lt $cword ]; do
1044 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
1045 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
1048 push) no_complete_refspec=1 ;;
1055 --multiple) no_complete_refspec=1; break ;;
1057 *) remote="$i"; break ;;
1061 if [ -z "$remote" ]; then
1062 __gitcomp_nl "$(__git_remotes)"
1065 if [ $no_complete_refspec = 1 ]; then
1068 [ "$remote" = "." ] && remote=
1071 case "$COMP_WORDBREAKS" in
1073 *) pfx="${cur_%%:*}:" ;;
1085 if [ $lhs = 1 ]; then
1086 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
1088 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1092 if [ $lhs = 1 ]; then
1093 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1095 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1099 if [ $lhs = 1 ]; then
1100 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1102 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1108 __git_complete_strategy ()
1110 __git_compute_merge_strategies
1113 __gitcomp "$__git_merge_strategies"
1117 __gitcomp "$__git_merge_strategy_options"
1123 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1126 --strategy-option=*)
1127 __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1135 __git_compute_all_commands ()
1137 test -n "$__git_all_commands" ||
1138 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1141 # Lists all set config variables starting with the given section prefix,
1142 # with the prefix removed.
1143 __git_get_config_variables ()
1145 local section="$1" i IFS=$'\n'
1146 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1147 echo "${i#$section.}"
1151 __git_pretty_aliases ()
1153 __git_get_config_variables "pretty"
1156 # __git_aliased_command requires 1 argument
1157 __git_aliased_command ()
1159 local cur=$1 last list= word cmdline
1161 while [[ -n "$cur" ]]; do
1162 if [[ "$list" == *" $cur "* ]]; then
1167 cmdline=$(__git config --get "alias.$cur")
1172 for word in $cmdline; do
1178 \!*) : shell command alias ;;
1180 *=*) : setting env ;;
1181 git) : git itself ;;
1182 \(\)) : skip parens of shell function definition ;;
1183 {) : skip start of shell helper function ;;
1184 :) : skip null command ;;
1185 \'*) : skip opening quote after sh -c ;;
1194 if [[ "$cur" != "$1" ]]; then
1199 # Check whether one of the given words is present on the command line,
1200 # and print the first word found.
1202 # Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
1203 # --show-idx: Optionally show the index of the found word in the $words array.
1204 __git_find_on_cmdline ()
1206 local word c="$__git_cmd_idx" show_idx
1208 while test $# -gt 1; do
1210 --show-idx) show_idx=y ;;
1217 while [ $c -lt $cword ]; do
1218 for word in $wordlist; do
1219 if [ "$word" = "${words[c]}" ]; then
1220 if [ -n "${show_idx-}" ]; then
1232 # Similar to __git_find_on_cmdline, except that it loops backwards and thus
1233 # prints the *last* word found. Useful for finding which of two options that
1234 # supersede each other came last, such as "--guess" and "--no-guess".
1236 # Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
1237 # --show-idx: Optionally show the index of the found word in the $words array.
1238 __git_find_last_on_cmdline ()
1240 local word c=$cword show_idx
1242 while test $# -gt 1; do
1244 --show-idx) show_idx=y ;;
1251 while [ $c -gt "$__git_cmd_idx" ]; do
1253 for word in $wordlist; do
1254 if [ "$word" = "${words[c]}" ]; then
1255 if [ -n "$show_idx" ]; then
1266 # Echo the value of an option set on the command line or config
1268 # $1: short option name
1269 # $2: long option name including =
1270 # $3: list of possible values
1271 # $4: config string (optional)
1274 # result="$(__git_get_option_value "-d" "--do-something=" \
1275 # "yes no" "core.doSomething")"
1277 # result is then either empty (no option set) or "yes" or "no"
1279 # __git_get_option_value requires 3 arguments
1280 __git_get_option_value ()
1282 local c short_opt long_opt val
1283 local result= values config_key word
1291 while [ $c -ge 0 ]; do
1293 for val in $values; do
1294 if [ "$short_opt$val" = "$word" ] ||
1295 [ "$long_opt$val" = "$word" ]; then
1303 if [ -n "$config_key" ] && [ -z "$result" ]; then
1304 result="$(__git config "$config_key")"
1310 __git_has_doubledash ()
1313 while [ $c -lt $cword ]; do
1314 if [ "--" = "${words[c]}" ]; then
1322 # Try to count non option arguments passed on the command line for the
1323 # specified git command.
1324 # When options are used, it is necessary to use the special -- option to
1325 # tell the implementation were non option arguments begin.
1326 # XXX this can not be improved, since options can appear everywhere, as
1330 # __git_count_arguments requires 1 argument: the git command executed.
1331 __git_count_arguments ()
1335 # Skip "git" (first argument)
1336 for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
1341 # Good; we can assume that the following are only non
1346 # Skip the specified git command and discard git
1359 __git_whitespacelist="nowarn warn error error-all fix"
1360 __git_patchformat="mbox stgit stgit-series hg mboxrd"
1361 __git_showcurrentpatch="diff raw"
1362 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1363 __git_quoted_cr="nowarn warn strip"
1367 __git_find_repo_path
1368 if [ -d "$__git_repo_path"/rebase-apply ]; then
1369 __gitcomp "$__git_am_inprogress_options"
1374 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1378 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1381 --show-current-patch=*)
1382 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
1386 __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}"
1390 __gitcomp_builtin am "" \
1391 "$__git_am_inprogress_options"
1400 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1404 __gitcomp_builtin apply
1413 __gitcomp "+x -x" "" "${cur##--chmod=}"
1417 __gitcomp_builtin add
1421 local complete_opt="--others --modified --directory --no-empty-directory"
1422 if test -n "$(__git_find_on_cmdline "-u --update")"
1424 complete_opt="--modified"
1426 __git_complete_index_file "$complete_opt"
1433 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1437 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1441 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
1450 __git_has_doubledash && return
1452 local subcommands="start bad good skip reset visualize replay log run"
1453 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1454 if [ -z "$subcommand" ]; then
1455 __git_find_repo_path
1456 if [ -f "$__git_repo_path"/BISECT_START ]; then
1457 __gitcomp "$subcommands"
1459 __gitcomp "replay start"
1464 case "$subcommand" in
1465 bad|good|reset|skip|start)
1473 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1477 local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
1479 while [ $c -lt $cword ]; do
1482 -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
1483 only_local_ref="y" ;;
1491 --set-upstream-to=*)
1492 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1495 __gitcomp_builtin branch
1498 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1499 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1509 local cmd="${words[__git_cmd_idx+1]}"
1511 $((__git_cmd_idx+1)))
1512 __gitcomp "create list-heads verify unbundle"
1514 $((__git_cmd_idx+2)))
1515 # looking for a file
1520 __git_complete_revlist
1527 # Helper function to decide whether or not we should enable DWIM logic for
1528 # git-switch and git-checkout.
1530 # To decide between the following rules in decreasing priority order:
1531 # - the last provided of "--guess" or "--no-guess" explicitly enable or
1532 # disable completion of DWIM logic respectively.
1533 # - If checkout.guess is false, disable completion of DWIM logic.
1534 # - If the --no-track option is provided, take this as a hint to disable the
1535 # DWIM completion logic
1536 # - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
1537 # logic, as requested by the user.
1538 # - Enable DWIM logic otherwise.
1540 __git_checkout_default_dwim_mode ()
1542 local last_option dwim_opt="--dwim"
1544 if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1548 # --no-track disables DWIM, but with lower priority than
1549 # --guess/--no-guess/checkout.guess
1550 if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
1554 # checkout.guess = false disables DWIM, but with lower priority than
1555 # --guess/--no-guess
1556 if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
1560 # Find the last provided --guess or --no-guess
1561 last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
1562 case "$last_option" in
1576 __git_has_doubledash && return
1578 local dwim_opt="$(__git_checkout_default_dwim_mode)"
1582 # Complete local branches (and DWIM branch
1583 # remote branch names) for an option argument
1584 # specifying a new branch name. This is for
1585 # convenience, assuming new branches are
1586 # possibly based on pre-existing branch names.
1587 __git_complete_refs $dwim_opt --mode="heads"
1596 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
1599 __gitcomp_builtin checkout
1602 # At this point, we've already handled special completion for
1603 # the arguments to -b/-B, and --orphan. There are 3 main
1604 # things left we can possibly complete:
1605 # 1) a start-point for -b/-B, -d/--detach, or --orphan
1606 # 2) a remote head, for --track
1607 # 3) an arbitrary reference, possibly including DWIM names
1610 if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
1611 __git_complete_refs --mode="refs"
1612 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
1613 __git_complete_refs --mode="remote-heads"
1615 __git_complete_refs $dwim_opt --mode="refs"
1621 __git_sequencer_inprogress_options="--continue --quit --abort --skip"
1623 __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1627 __git_find_repo_path
1628 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1629 __gitcomp "$__git_cherry_pick_inprogress_options"
1633 __git_complete_strategy && return
1637 __gitcomp_builtin cherry-pick "" \
1638 "$__git_cherry_pick_inprogress_options"
1650 __gitcomp_builtin clean
1655 # XXX should we check for -x option ?
1656 __git_complete_index_file "--others --directory"
1663 __git_complete_config_variable_name_and_value
1669 __git_complete_config_variable_name_and_value \
1670 --cur="${cur##--config=}"
1674 __gitcomp_builtin clone
1680 __git_untracked_file_modes="all no normal"
1682 __git_trailer_tokens ()
1684 __git config --name-only --get-regexp '^trailer\..*\.key$' | cut -d. -f 2- | rev | cut -d. -f2- | rev
1698 __gitcomp "default scissors strip verbatim whitespace
1699 " "" "${cur##--cleanup=}"
1702 --reuse-message=*|--reedit-message=*|\
1703 --fixup=*|--squash=*)
1704 __git_complete_refs --cur="${cur#*=}"
1707 --untracked-files=*)
1708 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1712 __gitcomp_nl "$(__git_trailer_tokens)" "" "${cur##--trailer=}" ":"
1716 __gitcomp_builtin commit
1720 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1721 __git_complete_index_file "--committable"
1723 # This is the first commit
1724 __git_complete_index_file "--cached"
1732 __gitcomp_builtin describe
1738 __git_diff_algorithms="myers minimal patience histogram"
1740 __git_diff_submodule_formats="diff log short"
1742 __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
1744 __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
1745 ignore-all-space allow-indentation-change"
1747 __git_ws_error_highlight_opts="context old new all default"
1749 # Options for the diff machinery (diff, log, show, stash, range-diff, ...)
1750 __git_diff_common_options="--stat --numstat --shortstat --summary
1751 --patch-with-stat --name-only --name-status --color
1752 --no-color --color-words --no-renames --check
1753 --color-moved --color-moved= --no-color-moved
1754 --color-moved-ws= --no-color-moved-ws
1755 --full-index --binary --abbrev --diff-filter=
1756 --find-copies --find-object --find-renames
1757 --no-relative --relative
1758 --find-copies-harder --ignore-cr-at-eol
1759 --text --ignore-space-at-eol --ignore-space-change
1760 --ignore-all-space --ignore-blank-lines --exit-code
1761 --quiet --ext-diff --no-ext-diff --unified=
1762 --no-prefix --src-prefix= --dst-prefix=
1763 --inter-hunk-context= --function-context
1764 --patience --histogram --minimal
1765 --raw --word-diff --word-diff-regex=
1766 --dirstat --dirstat= --dirstat-by-file
1767 --dirstat-by-file= --cumulative
1768 --diff-algorithm= --default-prefix
1769 --submodule --submodule= --ignore-submodules
1770 --indent-heuristic --no-indent-heuristic
1771 --textconv --no-textconv --break-rewrites
1772 --patch --no-patch --cc --combined-all-paths
1773 --anchored= --compact-summary --ignore-matching-lines=
1774 --irreversible-delete --line-prefix --no-stat
1775 --output= --output-indicator-context=
1776 --output-indicator-new= --output-indicator-old=
1777 --ws-error-highlight=
1778 --pickaxe-all --pickaxe-regex
1781 # Options for diff/difftool
1782 __git_diff_difftool_options="--cached --staged
1783 --base --ours --theirs --no-index --merge-base
1784 --ita-invisible-in-index --ita-visible-in-index
1785 $__git_diff_common_options"
1789 __git_has_doubledash && return
1793 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1797 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1801 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
1805 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
1808 --ws-error-highlight=*)
1809 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
1813 __gitcomp "$__git_diff_difftool_options"
1817 __git_complete_revlist_file
1820 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1821 tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1822 bc codecompare smerge
1827 __git_has_doubledash && return
1831 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1835 __gitcomp_builtin difftool "$__git_diff_difftool_options"
1839 __git_complete_revlist_file
1842 __git_fetch_recurse_submodules="yes on-demand no"
1847 --recurse-submodules=*)
1848 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1852 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1856 __gitcomp_builtin fetch
1860 __git_complete_remote_or_refspec
1863 __git_format_patch_extra_options="
1864 --full-index --not --all --no-prefix --src-prefix=
1865 --dst-prefix= --notes
1868 _git_format_patch ()
1874 " "" "${cur##--thread=}"
1877 --base=*|--interdiff=*|--range-diff=*)
1878 __git_complete_refs --cur="${cur#--*=}"
1882 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1886 __git_complete_revlist
1893 __gitcomp_builtin fsck
1904 # Lists matching symbol names from a tag (as in ctags) file.
1905 # 1: List symbol names matching this word.
1906 # 2: The tag file to list symbol names from.
1907 # 3: A prefix to be added to each listed symbol name (optional).
1908 # 4: A suffix to be appended to each listed symbol name (optional).
1909 __git_match_ctag () {
1910 awk -v pfx="${3-}" -v sfx="${4-}" "
1911 /^${1//\//\\/}/ { print pfx \$1 sfx }
1915 # Complete symbol names from a tag file.
1916 # Usage: __git_complete_symbol [<option>]...
1917 # --tags=<file>: The tag file to list symbol names from instead of the
1919 # --pfx=<prefix>: A prefix to be added to each symbol name.
1920 # --cur=<word>: The current symbol name to be completed. Defaults to
1921 # the current word to be completed.
1922 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1923 # of the default space.
1924 __git_complete_symbol () {
1925 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1927 while test $# != 0; do
1929 --tags=*) tags="${1##--tags=}" ;;
1930 --pfx=*) pfx="${1##--pfx=}" ;;
1931 --cur=*) cur_="${1##--cur=}" ;;
1932 --sfx=*) sfx="${1##--sfx=}" ;;
1938 if test -r "$tags"; then
1939 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1945 __git_has_doubledash && return
1949 __gitcomp_builtin grep
1954 case "$cword,$prev" in
1955 $((__git_cmd_idx+1)),*|*,-*)
1956 __git_complete_symbol && return
1967 __gitcomp_builtin help
1971 if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
1973 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
1975 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1984 false true umask group all world everybody
1985 " "" "${cur##--shared=}"
1989 __gitcomp_builtin init
1999 __gitcomp_builtin ls-files
2004 # XXX ignore options like --modified and always suggest all cached
2006 __git_complete_index_file "--cached"
2013 __gitcomp_builtin ls-remote
2017 __gitcomp_nl "$(__git_remotes)"
2024 __gitcomp_builtin ls-tree
2032 # Options that go well for log, shortlog and gitk
2033 __git_log_common_options="
2035 --branches --tags --remotes
2036 --first-parent --merges --no-merges
2038 --max-age= --since= --after=
2039 --min-age= --until= --before=
2040 --min-parents= --max-parents=
2041 --no-min-parents --no-max-parents
2043 # Options that go well for log and gitk (not shortlog)
2044 __git_log_gitk_options="
2045 --dense --sparse --full-history
2046 --simplify-merges --simplify-by-decoration
2047 --left-right --notes --no-notes
2049 # Options that go well for log and shortlog (not gitk)
2050 __git_log_shortlog_options="
2051 --author= --committer= --grep=
2052 --all-match --invert-grep
2054 # Options accepted by log and show
2055 __git_log_show_options="
2056 --diff-merges --diff-merges= --no-diff-merges --dd --remerge-diff
2059 __git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-combined cc remerge r"
2061 __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
2062 __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
2066 __git_has_doubledash && return
2067 __git_find_repo_path
2070 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2073 case "$prev,$cur" in
2075 return # fall back to Bash filename completion
2078 __git_complete_symbol --cur="${cur#:}" --sfx=":"
2082 __git_complete_symbol
2087 --pretty=*|--format=*)
2088 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2093 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
2097 __gitcomp "full short no" "" "${cur##--decorate=}"
2101 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2105 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2108 --ws-error-highlight=*)
2109 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
2113 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
2117 __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
2122 $__git_log_common_options
2123 $__git_log_shortlog_options
2124 $__git_log_gitk_options
2125 $__git_log_show_options
2126 --root --topo-order --date-order --reverse
2127 --follow --full-diff
2128 --abbrev-commit --no-abbrev-commit --abbrev=
2129 --relative-date --date=
2130 --pretty= --format= --oneline
2135 --decorate --decorate= --no-decorate
2137 --no-walk --no-walk= --do-walk
2138 --parents --children
2139 --expand-tabs --expand-tabs= --no-expand-tabs
2141 $__git_diff_common_options
2146 return # fall back to Bash filename completion
2149 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
2153 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
2157 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
2161 __git_complete_revlist
2166 __git_complete_strategy && return
2170 __gitcomp_builtin merge
2180 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
2184 __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
2194 __gitcomp_builtin merge-base
2205 __gitcomp_builtin mv
2210 if [ $(__git_count_arguments "mv") -gt 0 ]; then
2211 # We need to show both cached and untracked files (including
2212 # empty directories) since this may not be the last argument.
2213 __git_complete_index_file "--cached --others --directory"
2215 __git_complete_index_file "--cached"
2221 local subcommands='add append copy edit get-ref list merge prune remove show'
2222 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2224 case "$subcommand,$cur" in
2226 __gitcomp_builtin notes
2234 __gitcomp "$subcommands --ref"
2238 *,--reuse-message=*|*,--reedit-message=*)
2239 __git_complete_refs --cur="${cur#*=}"
2242 __gitcomp_builtin notes_$subcommand
2245 # this command does not take a ref, do not complete it
2261 __git_complete_strategy && return
2264 --recurse-submodules=*)
2265 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
2269 __gitcomp_builtin pull
2274 __git_complete_remote_or_refspec
2277 __git_push_recurse_submodules="check on-demand only"
2279 __git_complete_force_with_lease ()
2287 __git_complete_refs --cur="${cur_#*:}"
2290 __git_complete_refs --cur="$cur_"
2299 __gitcomp_nl "$(__git_remotes)"
2302 --recurse-submodules)
2303 __gitcomp "$__git_push_recurse_submodules"
2309 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
2312 --recurse-submodules=*)
2313 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
2316 --force-with-lease=*)
2317 __git_complete_force_with_lease "${cur##--force-with-lease=}"
2321 __gitcomp_builtin push
2325 __git_complete_remote_or_refspec
2333 --creation-factor= --no-dual-color
2334 $__git_diff_common_options
2339 __git_complete_revlist
2342 __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
2343 __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
2347 __git_find_repo_path
2348 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2349 __gitcomp "$__git_rebase_interactive_inprogress_options"
2351 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2352 [ -d "$__git_repo_path"/rebase-merge ]; then
2353 __gitcomp "$__git_rebase_inprogress_options"
2356 __git_complete_strategy && return
2359 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2363 __git_complete_refs --cur="${cur##--onto=}"
2367 __gitcomp_builtin rebase "" \
2368 "$__git_rebase_interactive_inprogress_options"
2377 local subcommands="show delete expire"
2378 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2380 if [ -z "$subcommand" ]; then
2381 __gitcomp "$subcommands"
2387 __git_send_email_confirm_options="always never auto cc compose"
2388 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2393 --to|--cc|--bcc|--from)
2394 __gitcomp "$(__git send-email --dump-aliases)"
2402 $__git_send_email_confirm_options
2403 " "" "${cur##--confirm=}"
2408 $__git_send_email_suppresscc_options
2409 " "" "${cur##--suppress-cc=}"
2413 --smtp-encryption=*)
2414 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2420 " "" "${cur##--thread=}"
2423 --to=*|--cc=*|--bcc=*|--from=*)
2424 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2428 __gitcomp_builtin send-email "$__git_format_patch_extra_options"
2432 __git_complete_revlist
2443 local untracked_state
2446 --ignore-submodules=*)
2447 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2450 --untracked-files=*)
2451 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2456 always never auto column row plain dense nodense
2457 " "" "${cur##--column=}"
2461 __gitcomp_builtin status
2466 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2467 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2469 case "$untracked_state" in
2471 # --ignored option does not matter
2475 complete_opt="--cached --directory --no-empty-directory --others"
2477 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2478 complete_opt="$complete_opt --ignored --exclude=*"
2483 __git_complete_index_file "$complete_opt"
2488 local dwim_opt="$(__git_checkout_default_dwim_mode)"
2492 # Complete local branches (and DWIM branch
2493 # remote branch names) for an option argument
2494 # specifying a new branch name. This is for
2495 # convenience, assuming new branches are
2496 # possibly based on pre-existing branch names.
2497 __git_complete_refs $dwim_opt --mode="heads"
2506 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2509 __gitcomp_builtin switch
2512 # Unlike in git checkout, git switch --orphan does not take
2513 # a start point. Thus we really have nothing to complete after
2515 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
2519 # At this point, we've already handled special completion for
2520 # -c/-C, and --orphan. There are 3 main things left to
2522 # 1) a start-point for -c/-C or -d/--detach
2523 # 2) a remote head, for --track
2524 # 3) a branch name, possibly including DWIM remote branches
2526 if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
2527 __git_complete_refs --mode="refs"
2528 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
2529 __git_complete_refs --mode="remote-heads"
2531 __git_complete_refs $dwim_opt --mode="heads"
2537 __git_config_get_set_variables ()
2539 local prevword word config_file= c=$cword
2540 while [ $c -gt "$__git_cmd_idx" ]; do
2543 --system|--global|--local|--file=*)
2548 config_file="$word $prevword"
2556 __git config $config_file --name-only --list
2560 __git_compute_config_vars ()
2562 test -n "$__git_config_vars" ||
2563 __git_config_vars="$(git help --config-for-completion)"
2566 __git_config_sections=
2567 __git_compute_config_sections ()
2569 test -n "$__git_config_sections" ||
2570 __git_config_sections="$(git help --config-sections-for-completion)"
2573 # Completes possible values of various configuration variables.
2575 # Usage: __git_complete_config_variable_value [<option>]...
2576 # --varname=<word>: The name of the configuration variable whose value is
2577 # to be completed. Defaults to the previous word on the
2579 # --cur=<word>: The current value to be completed. Defaults to the current
2580 # word to be completed.
2581 __git_complete_config_variable_value ()
2583 local varname="$prev" cur_="$cur"
2585 while test $# != 0; do
2587 --varname=*) varname="${1##--varname=}" ;;
2588 --cur=*) cur_="${1##--cur=}" ;;
2594 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2595 varname="${varname,,}"
2597 varname="$(echo "$varname" |tr A-Z a-z)"
2601 branch.*.remote|branch.*.pushremote)
2602 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2606 __git_complete_refs --cur="$cur_"
2610 __gitcomp "false true merges interactive" "" "$cur_"
2614 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2618 local remote="${varname#remote.}"
2619 remote="${remote%.fetch}"
2620 if [ -z "$cur_" ]; then
2621 __gitcomp_nl "refs/heads/" "" "" ""
2624 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2628 local remote="${varname#remote.}"
2629 remote="${remote%.push}"
2630 __gitcomp_nl "$(__git for-each-ref \
2631 --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2634 pull.twohead|pull.octopus)
2635 __git_compute_merge_strategies
2636 __gitcomp "$__git_merge_strategies" "" "$cur_"
2640 __gitcomp "false true" "" "$cur_"
2645 normal black red green yellow blue magenta cyan white
2646 bold dim ul blink reverse
2651 __gitcomp "false true always never auto" "" "$cur_"
2655 __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2659 __gitcomp "man info web html" "" "$cur_"
2663 __gitcomp "$__git_log_date_formats" "" "$cur_"
2666 sendemail.aliasfiletype)
2667 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2671 __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2674 sendemail.suppresscc)
2675 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2678 sendemail.transferencoding)
2679 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2688 # Completes configuration sections, subsections, variable names.
2690 # Usage: __git_complete_config_variable_name [<option>]...
2691 # --cur=<word>: The current configuration section/variable name to be
2692 # completed. Defaults to the current word to be completed.
2693 # --sfx=<suffix>: A suffix to be appended to each fully completed
2694 # configuration variable name (but not to sections or
2695 # subsections) instead of the default space.
2696 __git_complete_config_variable_name ()
2698 local cur_="$cur" sfx
2700 while test $# != 0; do
2702 --cur=*) cur_="${1##--cur=}" ;;
2703 --sfx=*) sfx="${1##--sfx=}" ;;
2711 local pfx="${cur_%.*}."
2713 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2717 local pfx="${cur_%.*}."
2719 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2720 __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
2724 local pfx="${cur_%.*}."
2727 argPrompt cmd confirm needsFile noConsole noRescan
2728 prompt revPrompt revUnmerged title
2729 " "$pfx" "$cur_" "$sfx"
2733 local pfx="${cur_%.*}."
2735 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2739 local pfx="${cur_%.*}."
2741 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2745 local pfx="${cur_%.*}."
2747 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2751 local pfx="${cur_%.*}."
2753 __git_compute_all_commands
2754 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
2758 local pfx="${cur_%.*}."
2761 url proxy fetch push mirror skipDefaultUpdate
2762 receivepack uploadpack tagOpt pushurl
2763 " "$pfx" "$cur_" "$sfx"
2767 local pfx="${cur_%.*}."
2769 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2770 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
2774 local pfx="${cur_%.*}."
2776 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2780 __git_compute_config_vars
2781 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
2784 __git_compute_config_sections
2785 __gitcomp "$__git_config_sections" "" "$cur_" "."
2790 # Completes '='-separated configuration sections/variable names and values
2791 # for 'git -c section.name=value'.
2793 # Usage: __git_complete_config_variable_name_and_value [<option>]...
2794 # --cur=<word>: The current configuration section/variable name/value to be
2795 # completed. Defaults to the current word to be completed.
2796 __git_complete_config_variable_name_and_value ()
2800 while test $# != 0; do
2802 --cur=*) cur_="${1##--cur=}" ;;
2810 __git_complete_config_variable_value \
2811 --varname="${cur_%%=*}" --cur="${cur_#*=}"
2814 __git_complete_config_variable_name --cur="$cur_" --sfx='='
2822 --get|--get-all|--unset|--unset-all)
2823 __gitcomp_nl "$(__git_config_get_set_variables)"
2827 __git_complete_config_variable_value
2833 __gitcomp_builtin config
2836 __git_complete_config_variable_name
2844 add rename remove set-head set-branches
2845 get-url set-url show prune update
2847 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2848 if [ -z "$subcommand" ]; then
2851 __gitcomp_builtin remote
2854 __gitcomp "$subcommands"
2860 case "$subcommand,$cur" in
2862 __gitcomp_builtin remote_add
2867 __gitcomp_builtin remote_set-head
2870 __gitcomp_builtin remote_set-branches
2872 set-head,*|set-branches,*)
2873 __git_complete_remote_or_refspec
2876 __gitcomp_builtin remote_update
2879 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
2882 __gitcomp_builtin remote_set-url
2885 __gitcomp_builtin remote_get-url
2888 __gitcomp_builtin remote_prune
2891 __gitcomp_nl "$(__git_remotes)"
2900 __gitcomp "short medium long" "" "${cur##--format=}"
2904 __gitcomp_builtin replace
2913 local subcommands="clear forget diff remaining status gc"
2914 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2915 if test -z "$subcommand"
2917 __gitcomp "$subcommands"
2924 __git_has_doubledash && return
2928 __gitcomp_builtin reset
2946 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2949 __git_complete_refs --cur="${cur##--source=}"
2952 __gitcomp_builtin restore
2955 if __git rev-parse --verify --quiet HEAD >/dev/null; then
2956 __git_complete_index_file "--modified"
2961 __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2965 __git_find_repo_path
2966 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2967 __gitcomp "$__git_revert_inprogress_options"
2970 __git_complete_strategy && return
2973 __gitcomp_builtin revert "" \
2974 "$__git_revert_inprogress_options"
2985 __gitcomp_builtin rm
2990 __git_complete_index_file "--cached"
2995 __git_has_doubledash && return
3000 $__git_log_common_options
3001 $__git_log_shortlog_options
3002 --numbered --summary --email
3007 __git_complete_revlist
3012 __git_has_doubledash && return
3015 --pretty=*|--format=*)
3016 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
3021 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
3025 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
3029 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
3033 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
3036 --ws-error-highlight=*)
3037 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
3041 __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
3045 __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
3046 --oneline --show-signature
3047 --expand-tabs --expand-tabs= --no-expand-tabs
3048 $__git_log_show_options
3049 $__git_diff_common_options
3054 __git_complete_revlist_file
3061 __gitcomp_builtin show-branch
3065 __git_complete_revlist
3068 __gitcomp_directories ()
3070 local _tmp_dir _tmp_completions _found=0
3072 # Get the directory of the current token; this differs from dirname
3073 # in that it keeps up to the final trailing slash. If no slash found
3076 _tmp_dir=$BASH_REMATCH
3078 # Find possible directory completions, adding trailing '/' characters,
3079 # de-quoting, and handling unusual characters.
3080 while IFS= read -r -d $'\0' c ; do
3081 # If there are directory completions, find ones that start
3082 # with "$cur", the current token, and put those in COMPREPLY
3083 if [[ $c == "$cur"* ]]; then
3087 done < <(git ls-tree -z -d --name-only HEAD $_tmp_dir)
3089 if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then
3090 # No possible further completions any deeper, so assume we're at
3091 # a leaf directory and just consider it complete
3092 __gitcomp_direct_append "$cur "
3096 _git_sparse_checkout ()
3098 local subcommands="list init set disable add reapply"
3099 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3100 if [ -z "$subcommand" ]; then
3101 __gitcomp "$subcommands"
3105 case "$subcommand,$cur" in
3107 __gitcomp_builtin sparse-checkout_$subcommand "" "--"
3110 if [ "$(__git config core.sparseCheckoutCone)" == "true" ] ||
3111 [ -n "$(__git_find_on_cmdline --cone)" ]; then
3112 __gitcomp_directories
3119 local subcommands='push list show apply clear drop pop create branch'
3120 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3122 if [ -z "$subcommand" ]; then
3123 case "$((cword - __git_cmd_idx)),$cur" in
3125 __gitcomp_builtin stash_push
3131 __gitcomp "$subcommands"
3137 case "$subcommand,$cur" in
3139 # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3140 __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
3143 __gitcomp_builtin stash_show "$__git_diff_common_options"
3146 __gitcomp_builtin "stash_$subcommand"
3149 if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3152 __gitcomp_nl "$(__git stash list \
3153 | sed -n -e 's/:.*//p')"
3156 show,*|apply,*|drop,*|pop,*)
3157 __gitcomp_nl "$(__git stash list \
3158 | sed -n -e 's/:.*//p')"
3165 __git_has_doubledash && return
3167 local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
3168 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3169 if [ -z "$subcommand" ]; then
3175 __gitcomp "$subcommands"
3181 case "$subcommand,$cur" in
3183 __gitcomp "--branch --force --name --reference --depth"
3186 __gitcomp "--cached --recursive"
3189 __gitcomp "--force --all"
3193 --init --remote --no-fetch
3194 --recommend-shallow --no-recommend-shallow
3195 --force --rebase --merge --reference --depth --recursive --jobs
3199 __gitcomp "--default --branch"
3202 __gitcomp "--cached --files --summary-limit"
3204 foreach,--*|sync,--*)
3205 __gitcomp "--recursive"
3215 init fetch clone rebase dcommit log find-rev
3216 set-tree commit-diff info create-ignore propget
3217 proplist show-ignore show-externals branch tag blame
3218 migrate mkdirs reset gc
3220 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3221 if [ -z "$subcommand" ]; then
3222 __gitcomp "$subcommands"
3224 local remote_opts="--username= --config-dir= --no-auth-cache"
3226 --follow-parent --authors-file= --repack=
3227 --no-metadata --use-svm-props --use-svnsync-props
3228 --log-window-size= --no-checkout --quiet
3229 --repack-flags --use-log-author --localtime
3232 --ignore-paths= --include-paths= $remote_opts
3235 --template= --shared= --trunk= --tags=
3236 --branches= --stdlayout --minimize-url
3237 --no-metadata --use-svm-props --use-svnsync-props
3238 --rewrite-root= --prefix= $remote_opts
3241 --edit --rmdir --find-copies-harder --copy-similarity=
3244 case "$subcommand,$cur" in
3246 __gitcomp "--revision= --fetch-all $fc_opts"
3249 __gitcomp "--revision= $fc_opts $init_opts"
3252 __gitcomp "$init_opts"
3256 --merge --strategy= --verbose --dry-run
3257 --fetch-all --no-rebase --commit-url
3258 --revision --interactive $cmt_opts $fc_opts
3262 __gitcomp "--stdin $cmt_opts $fc_opts"
3264 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
3265 show-externals,--*|mkdirs,--*)
3266 __gitcomp "--revision="
3270 --limit= --revision= --verbose --incremental
3271 --oneline --show-commit --non-recursive
3272 --authors-file= --color
3277 --merge --verbose --strategy= --local
3278 --fetch-all --dry-run $fc_opts
3282 __gitcomp "--message= --file= --revision= $cmt_opts"
3288 __gitcomp "--dry-run --message --tag"
3291 __gitcomp "--dry-run --message"
3294 __gitcomp "--git-format"
3298 --config-dir= --ignore-paths= --minimize
3299 --no-auth-cache --username=
3303 __gitcomp "--revision= --parent"
3313 local i c="$__git_cmd_idx" f=0
3314 while [ $c -lt $cword ]; do
3317 -d|--delete|-v|--verify)
3318 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3333 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3343 __gitcomp_builtin tag
3353 __git_complete_worktree_paths ()
3356 # Generate completion reply from worktree list skipping the first
3357 # entry: it's the path of the main worktree, which can't be moved,
3358 # removed, locked, etc.
3359 __gitcomp_nl "$(git worktree list --porcelain |
3360 sed -n -e '2,$ s/^worktree //p')"
3365 local subcommands="add list lock move prune remove unlock"
3366 local subcommand subcommand_idx
3368 subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3369 subcommand_idx="${subcommand% *}"
3370 subcommand="${subcommand#* }"
3372 case "$subcommand,$cur" in
3374 __gitcomp "$subcommands"
3377 __gitcomp_builtin worktree_$subcommand
3379 add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
3380 # Here we are not completing an --option, it's either the
3383 -b|-B) # Complete refs for branch to be created/reseted.
3386 -*) # The previous word is an -o|--option without an
3387 # unstuck argument: have to complete the path for
3388 # the new worktree, so don't list anything, but let
3389 # Bash fall back to filename completion.
3391 *) # The previous word is not an --option, so it must
3392 # be either the 'add' subcommand, the unstuck
3393 # argument of an option (e.g. branch for -b|-B), or
3394 # the path for the new worktree.
3395 if [ $cword -eq $((subcommand_idx+1)) ]; then
3396 # Right after the 'add' subcommand: have to
3397 # complete the path, so fall back to Bash
3398 # filename completion.
3401 case "${words[cword-2]}" in
3402 -b|-B) # After '-b <branch>': have to
3403 # complete the path, so fall back
3404 # to Bash filename completion.
3406 *) # After the path: have to complete
3407 # the ref to be checked out.
3415 lock,*|remove,*|unlock,*)
3416 __git_complete_worktree_paths
3419 if [ $cword -eq $((subcommand_idx+1)) ]; then
3420 # The first parameter must be an existing working
3422 __git_complete_worktree_paths
3424 # The second parameter is the destination: it could
3425 # be any path, so don't list anything, but let Bash
3426 # fall back to filename completion.
3433 __git_complete_common () {
3438 __gitcomp_builtin "$command"
3443 __git_cmds_with_parseopt_helper=
3444 __git_support_parseopt_helper () {
3445 test -n "$__git_cmds_with_parseopt_helper" ||
3446 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
3448 case " $__git_cmds_with_parseopt_helper " in
3458 __git_have_func () {
3459 declare -f -- "$1" >/dev/null 2>&1
3462 __git_complete_command () {
3464 local completion_func="_git_${command//-/_}"
3465 if ! __git_have_func $completion_func &&
3466 __git_have_func _completion_loader
3468 _completion_loader "git-$command"
3470 if __git_have_func $completion_func
3474 elif __git_support_parseopt_helper "$command"
3476 __git_complete_common "$command"
3485 local i c=1 command __git_dir __git_repo_path
3486 local __git_C_args C_args_count=0
3489 while [ $c -lt $cword ]; do
3493 __git_dir="${i#--git-dir=}"
3497 __git_dir="${words[c]}"
3506 -c|--work-tree|--namespace)
3510 __git_C_args[C_args_count++]=-C
3512 __git_C_args[C_args_count++]="${words[c]}"
3525 if [ -z "${command-}" ]; then
3527 --git-dir|-C|--work-tree)
3528 # these need a path argument, let's fall back to
3529 # Bash filename completion
3533 __git_complete_config_variable_name_and_value
3537 # we don't support completing these options' arguments
3556 --no-replace-objects
3561 if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3563 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3565 local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
3567 if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
3569 list_cmds=builtins,$list_cmds
3571 __gitcomp "$(__git --list-cmds=$list_cmds)"
3578 __git_complete_command "$command" && return
3580 local expansion=$(__git_aliased_command "$command")
3581 if [ -n "$expansion" ]; then
3583 __git_complete_command "$expansion"
3589 __git_has_doubledash && return
3591 local __git_repo_path
3592 __git_find_repo_path
3595 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3601 $__git_log_common_options
3602 $__git_log_gitk_options
3608 __git_complete_revlist
3611 if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
3612 echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
3618 local cur words cword prev
3619 local __git_cmd_idx=0
3620 _get_comp_words_by_ref -n =: cur words cword prev
3626 local wrapper="__git_wrap${2}"
3627 eval "$wrapper () { __git_func_wrap $2 ; }"
3628 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3629 || complete -o default -o nospace -F $wrapper $1
3632 # Setup the completion for git commands
3633 # 1: command or alias
3634 # 2: function to call (e.g. `git
`, `gitk
`, `git_fetch
`)
3639 if __git_have_func $2; then
3641 elif __git_have_func __$2_main; then
3643 elif __git_have_func _$2; then
3646 echo "ERROR: could not find function '$2'" 1>&2
3649 ___git_complete $1 $func
3652 ___git_complete git __git_main
3653 ___git_complete gitk __gitk_main
3655 # The following are necessary only for Cygwin, and only are needed
3656 # when the user has tab-completed the executable name and consequently
3657 # included the '.exe' suffix.
3659 if [ "$OSTYPE" = cygwin ]; then
3660 ___git_complete git.exe __git_main