]>
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 # GIT_COMPLETION_IGNORE_CASE
64 # When set, uses for-each-ref '--ignore-case' to find refs that match
65 # case insensitively, even on systems with case sensitive file systems
66 # (e.g., completing tag name "FOO" on "git checkout f<TAB>").
68 case "$COMP_WORDBREAKS" in
70 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
73 # Discovers the path to the git repository taking any '--git-dir=<path>' and
74 # '-C <path>' options into account and stores it in the $__git_repo_path
76 __git_find_repo_path
()
78 if [ -n "${__git_repo_path-}" ]; then
79 # we already know where it is
83 if [ -n "${__git_C_args-}" ]; then
84 __git_repo_path
="$(git "${__git_C_args[@]}" \
85 ${__git_dir:+--git-dir="$__git_dir"} \
86 rev-parse --absolute-git-dir 2>/dev/null)"
87 elif [ -n "${__git_dir-}" ]; then
88 test -d "$__git_dir" &&
89 __git_repo_path
="$__git_dir"
90 elif [ -n "${GIT_DIR-}" ]; then
92 __git_repo_path
="$GIT_DIR"
93 elif [ -d .git
]; then
96 __git_repo_path
="$(git rev-parse --git-dir 2>/dev/null)"
100 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
101 # __gitdir accepts 0 or 1 arguments (i.e., location)
102 # returns location of .git repo
105 if [ -z "${1-}" ]; then
106 __git_find_repo_path ||
return 1
107 echo "$__git_repo_path"
108 elif [ -d "$1/.git" ]; then
115 # Runs git with all the options given as argument, respecting any
116 # '--git-dir=<path>' and '-C <path>' options present on the command line
119 git
${__git_C_args:+"${__git_C_args[@]}"} \
120 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev
/null
123 # Removes backslash escaping, single quotes and double quotes from a word,
124 # stores the result in the variable $dequoted_word.
125 # 1: The word to dequote.
128 local rest
="$1" len ch
132 while test -n "$rest"; do
133 len
=${#dequoted_word}
134 dequoted_word
="$dequoted_word${rest%%[\\\'\"]*}"
135 rest
="${rest:$((${#dequoted_word}-$len))}"
137 case "${rest:0:1}" in
144 dequoted_word
="$dequoted_word$ch"
151 len
=${#dequoted_word}
152 dequoted_word
="$dequoted_word${rest%%\'*}"
153 rest
="${rest:$((${#dequoted_word}-$len+1))}"
157 while test -n "$rest" ; do
158 len
=${#dequoted_word}
159 dequoted_word
="$dequoted_word${rest%%[\\\"]*}"
160 rest
="${rest:$((${#dequoted_word}-$len))}"
161 case "${rest:0:1}" in
166 dequoted_word="$dequoted_word$ch"
171 dequoted_word="$dequoted_word\\$ch"
187 # The following function is based on code from:
189 # bash_completion - programmable completion functions for bash 3.2+
191 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
192 # © 2009-2010, Bash Completion Maintainers
193 # <bash-completion-devel@lists.alioth.debian.org>
195 # This program is free software; you can redistribute it and/or modify
196 # it under the terms of the GNU General Public License as published by
197 # the Free Software Foundation; either version 2, or (at your option)
200 # This program is distributed in the hope that it will be useful,
201 # but WITHOUT ANY WARRANTY; without even the implied warranty of
202 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
203 # GNU General Public License for more details.
205 # You should have received a copy of the GNU General Public License
206 # along with this program; if not, see <http://www.gnu.org/licenses/>.
208 # The latest version of this software can be obtained here:
210 # http://bash-completion.alioth.debian.org/
214 # This function can be used to access a tokenized list of words
215 # on the command line:
217 # __git_reassemble_comp_words_by_ref '=:'
218 # if test "${words_[cword_-1]}" = -w
223 # The argument should be a collection of characters from the list of
224 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
227 # This is roughly equivalent to going back in time and setting
228 # COMP_WORDBREAKS to exclude those characters. The intent is to
229 # make option types like --date=<type> and <rev>:<path> easy to
230 # recognize by treating each shell word as a single token.
232 # It is best not to set COMP_WORDBREAKS directly because the value is
233 # shared with other completion scripts. By the time the completion
234 # function gets called, COMP_WORDS has already been populated so local
235 # changes to COMP_WORDBREAKS have no effect.
237 # Output: words_, cword_, cur_.
239 __git_reassemble_comp_words_by_ref()
241 local exclude i j first
242 # Which word separators to exclude?
243 exclude="${1//[^$COMP_WORDBREAKS]}"
245 if [ -z "$exclude" ]; then
246 words_=("${COMP_WORDS[@]}")
249 # List of word completion separators has shrunk;
250 # re-assemble words to complete.
251 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
252 # Append each nonempty word consisting of just
253 # word separator characters to the current word.
257 [ -n "${COMP_WORDS[$i]}" ] &&
258 # word consists of excluded word separators
259 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
261 # Attach to the previous token,
262 # unless the previous token is the command name.
263 if [ $j -ge 2 ] && [ -n "$first" ]; then
267 words_[$j]=${words_[j]}${COMP_WORDS[i]}
268 if [ $i = $COMP_CWORD ]; then
271 if (($i < ${#COMP_WORDS[@]} - 1)); then
278 words_[$j]=${words_[j]}${COMP_WORDS[i]}
279 if [ $i = $COMP_CWORD ]; then
285 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
286 _get_comp_words_by_ref ()
288 local exclude cur_ words_ cword_
289 if [ "$1" = "-n" ]; then
293 __git_reassemble_comp_words_by_ref "$exclude"
294 cur_=${words_[cword_]}
295 while [ $# -gt 0 ]; do
301 prev=${words_[$cword_-1]}
304 words=("${words_[@]}")
315 # Fills the COMPREPLY array with prefiltered words without any additional
317 # Callers must take care of providing only words that match the current word
318 # to be completed and adding any prefix and/or suffix (trailing space!), if
320 # 1: List of newline-separated matching completion words, complete with
329 # Similar to __gitcomp_direct, but appends to COMPREPLY instead.
330 # Callers must take care of providing only words that match the current word
331 # to be completed and adding any prefix and/or suffix (trailing space!), if
333 # 1: List of newline-separated matching completion words, complete with
335 __gitcomp_direct_append ()
344 local x i=${#COMPREPLY[@]}
346 if [[ "$x" == "$3"* ]]; then
347 COMPREPLY[i++]="$2$x$4"
358 # Generates completion reply, appending a space to possible completion words,
360 # It accepts 1 to 4 arguments:
361 # 1: List of possible completion words.
362 # 2: A prefix to be added to each possible completion word (optional).
363 # 3: Generate possible completion matches for this word (optional).
364 # 4: A suffix to be appended to each possible completion word (optional).
367 local cur_="${3-$cur}"
373 local c i=0 IFS=$' \t\n'
375 if [[ $c == "--" ]]; then
379 if [[ $c == "$cur_"* ]]; then
384 COMPREPLY[i++]="${2-}$c"
389 local c i=0 IFS=$' \t\n'
391 if [[ $c == "--" ]]; then
393 if [[ $c == "$cur_"* ]]; then
394 COMPREPLY[i++]="${2-}$c "
399 if [[ $c == "$cur_"* ]]; then
404 COMPREPLY[i++]="${2-}$c"
411 # Clear the variables caching builtins' options when (re-)sourcing
412 # the completion script.
413 if [[ -n ${ZSH_VERSION-} ]]; then
414 unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
416 unset $(compgen -v __gitcomp_builtin_)
419 # This function is equivalent to
421 # __gitcomp "$(git xxx --git-completion-helper) ..."
423 # except that the output is cached. Accept 1-3 arguments:
424 # 1: the git command to execute, this is also the cache key
425 # 2: extra options to be added on top (e.g. negative forms)
426 # 3: options to be excluded
429 # spaces must be replaced with underscore for multi-word
430 # commands, e.g. "git remote add" becomes remote_add.
435 local var=__gitcomp_builtin_"${cmd//-/_}"
437 eval "options=\${$var-}"
439 if [ -z "$options" ]; then
440 local completion_helper
441 if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
442 completion_helper="--git-completion-helper-all"
444 completion_helper="--git-completion-helper"
446 # leading and trailing spaces are significant to make
447 # option removal work correctly.
448 options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
451 options="${options/ $i / }"
453 eval "$var=\"$options\""
459 # Variation of __gitcomp_nl () that appends to the existing list of
460 # completion candidates, COMPREPLY.
461 __gitcomp_nl_append ()
464 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
467 # Generates completion reply from newline-separated possible completion words
468 # by appending a space to all of them.
469 # It accepts 1 to 4 arguments:
470 # 1: List of possible completion words, separated by a single newline.
471 # 2: A prefix to be added to each possible completion word (optional).
472 # 3: Generate possible completion matches for this word (optional).
473 # 4: A suffix to be appended to each possible completion word instead of
474 # the default space (optional). If specified but empty, nothing is
479 __gitcomp_nl_append "$@"
482 # Fills the COMPREPLY array with prefiltered paths without any additional
484 # Callers must take care of providing only paths that match the current path
485 # to be completed and adding any prefix path components, if necessary.
486 # 1: List of newline-separated matching paths, complete with all prefix
488 __gitcomp_file_direct ()
494 # use a hack to enable file mode in bash < 4
495 compopt -o filenames +o nospace 2>/dev/null ||
496 compgen -f /non-existing-dir/ >/dev/null ||
500 # Generates completion reply with compgen from newline-separated possible
501 # completion filenames.
502 # It accepts 1 to 3 arguments:
503 # 1: List of possible completion filenames, separated by a single newline.
504 # 2: A directory prefix to be added to each possible completion filename
506 # 3: Generate possible completion matches for this word (optional).
511 # XXX does not work when the directory prefix contains a tilde,
512 # since tilde expansion is not applied.
513 # This means that COMPREPLY will be empty and Bash default
514 # completion will be used.
515 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
517 # use a hack to enable file mode in bash < 4
518 compopt -o filenames +o nospace 2>/dev/null ||
519 compgen -f /non-existing-dir/ >/dev/null ||
523 # Execute 'git ls-files', unless the --committable option is specified, in
524 # which case it runs 'git diff-index' to find out the files that can be
525 # committed. It return paths relative to the directory specified in the first
526 # argument, and using the options specified in the second argument.
527 __git_ls_files_helper ()
529 if [ "$2" = "--committable" ]; then
530 __git -C "$1" -c core.quotePath=false diff-index \
531 --name-only --relative HEAD -- "${3//\\/\\\\}*"
533 # NOTE: $2 is not quoted in order to support multiple options
534 __git -C "$1" -c core.quotePath=false ls-files \
535 --exclude-standard $2 -- "${3//\\/\\\\}*"
540 # __git_index_files accepts 1 or 2 arguments:
541 # 1: Options to pass to ls-files (required).
542 # 2: A directory path (optional).
543 # If provided, only files within the specified directory are listed.
544 # Sub directories are never recursed. Path must have a trailing
546 # 3: List only paths matching this path component (optional).
549 local root="$2" match="$3"
551 __git_ls_files_helper "$root" "$1" "${match:-?}" |
552 awk -F / -v pfx="${2//\\/\\\\}" '{
557 if (substr(p, 1, 1) != "\"") {
558 # No special characters, easy!
563 # The path is quoted.
568 # Even when a directory name itself does not contain
569 # any special characters, it will still be quoted if
570 # any of its (stripped) trailing path components do.
571 # Because of this we may have seen the same directory
572 # both quoted and unquoted.
574 # We have seen the same directory unquoted,
581 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
582 # Skip opening double quote.
585 # Interpret backslash escape sequences.
586 while ((bs_idx = index(p, "\\")) != 0) {
587 out = out substr(p, 1, bs_idx - 1)
588 esc = substr(p, bs_idx + 1, 1)
589 p = substr(p, bs_idx + 2)
591 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
592 # C-style one-character escape sequence.
593 out = out substr("\a\b\t\v\f\r\"\\",
595 } else if (esc == "n") {
596 # Uh-oh, a newline character.
597 # We cannot reliably put a pathname
598 # containing a newline into COMPREPLY,
599 # and the newline would create a mess.
603 # Must be a \nnn octal value, then.
605 substr(p, 1, 1) * 8 + \
607 out = out sprintf("%c", dec)
611 # Drop closing double quote, if there is one.
612 # (There is not any if this is a directory, as it was
613 # already stripped with the trailing path components.)
614 if (substr(p, length(p), 1) == "\"")
615 out = out substr(p, 1, length(p) - 1)
623 # __git_complete_index_file requires 1 argument:
624 # 1: the options to pass to ls-file
626 # The exception is --committable, which finds the files appropriate commit.
627 __git_complete_index_file ()
629 local dequoted_word pfx="" cur_
633 case "$dequoted_word" in
635 pfx="${dequoted_word%/*}/"
636 cur_="${dequoted_word##*/}"
639 cur_="$dequoted_word"
642 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
645 # Lists branches from the local repository.
646 # 1: A prefix to be added to each listed branch (optional).
647 # 2: List only branches matching this word (optional; list all branches if
649 # 3: A suffix to be appended to each listed branch (optional).
652 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
654 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
655 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
656 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
659 # Lists branches from remote repositories.
660 # 1: A prefix to be added to each listed branch (optional).
661 # 2: List only branches matching this word (optional; list all branches if
663 # 3: A suffix to be appended to each listed branch (optional).
664 __git_remote_heads ()
666 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
668 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
669 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
670 "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
673 # Lists tags from the local repository.
674 # Accepts the same positional parameters as __git_heads() above.
677 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
679 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
680 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
681 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
684 # List unique branches from refs/remotes used for 'git checkout' and 'git
685 # switch' tracking DWIMery.
686 # 1: A prefix to be added to each listed branch (optional)
687 # 2: List only branches matching this word (optional; list all branches if
689 # 3: A suffix to be appended to each listed branch (optional).
690 __git_dwim_remote_heads ()
692 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
693 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
695 # employ the heuristic used by git checkout and git switch
696 # Try to find a remote branch that cur_es the completion word
697 # but only output if the branch name is unique
698 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
699 --sort="refname:strip=3" \
700 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
701 "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
705 # Lists refs from the local (by default) or from a remote repository.
706 # It accepts 0, 1 or 2 arguments:
707 # 1: The remote to list refs from (optional; ignored, if set but empty).
708 # Can be the name of a configured remote, a path, or a URL.
709 # 2: In addition to local refs, list unique branches from refs/remotes/ for
710 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
711 # 3: A prefix to be added to each listed ref (optional).
712 # 4: List only refs matching this word (optional; list all refs if unset or
714 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
717 # Use __git_complete_refs() instead.
720 local i hash dir track="${2-}"
721 local list_refs_from=path remote="${1-}"
723 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
726 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
729 dir="$__git_repo_path"
731 if [ -z "$remote" ]; then
732 if [ -z "$dir" ]; then
736 if __git_is_configured_remote "$remote"; then
737 # configured remote takes precedence over a
738 # local directory with the same name
739 list_refs_from=remote
740 elif [ -d "$remote/.git" ]; then
742 elif [ -d "$remote" ]; then
749 if test "${GIT_COMPLETION_IGNORE_CASE:+1}" = "1"
751 # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility
752 umatch=$(echo "$match" | tr a-z A-Z 2>/dev/null || echo "$match")
755 if [ "$list_refs_from" = path ]; then
756 if [[ "$cur_" == ^* ]]; then
766 refs=("$match*" "$match*/**")
770 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do
773 if [ -e "$dir/$i" ]; then
779 format="refname:strip=2"
780 refs=("refs/tags/$match*" "refs/tags/$match*/**"
781 "refs/heads/$match*" "refs/heads/$match*/**"
782 "refs/remotes/$match*" "refs/remotes/$match*/**")
785 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
786 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
788 if [ -n "$track" ]; then
789 __git_dwim_remote_heads "$pfx" "$match" "$sfx"
795 __git ls-remote "$remote" "$match*" | \
796 while read -r hash i; do
799 *) echo "$pfx$i$sfx" ;;
804 if [ "$list_refs_from" = remote ]; then
806 $match*|$umatch*) echo "${pfx}HEAD$sfx" ;;
808 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
809 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
810 "refs/remotes/$remote/$match*" \
811 "refs/remotes/$remote/$match*/**"
815 $match*|$umatch*) query_symref="HEAD" ;;
817 __git ls-remote "$remote" $query_symref \
818 "refs/tags/$match*" "refs/heads/$match*" \
819 "refs/remotes/$match*" |
820 while read -r hash i; do
823 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
824 *) echo "$pfx$i$sfx" ;; # symbolic refs
832 # Completes refs, short and long, local and remote, symbolic and pseudo.
834 # Usage: __git_complete_refs [<option>]...
835 # --remote=<remote>: The remote to list refs from, can be the name of a
836 # configured remote, a path, or a URL.
837 # --dwim: List unique remote branches for 'git switch's tracking DWIMery.
838 # --pfx=<prefix>: A prefix to be added to each ref.
839 # --cur=<word>: The current ref to be completed. Defaults to the current
840 # word to be completed.
841 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
843 # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
844 # complete all refs, 'heads' to complete only branches, or
845 # 'remote-heads' to complete only remote branches. Note that
846 # --remote is only compatible with --mode=refs.
847 __git_complete_refs ()
849 local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
851 while test $# != 0; do
853 --remote=*) remote="${1##--remote=}" ;;
854 --dwim) dwim="yes" ;;
855 # --track is an old spelling of --dwim
856 --track) dwim="yes" ;;
857 --pfx=*) pfx="${1##--pfx=}" ;;
858 --cur=*) cur_="${1##--cur=}" ;;
859 --sfx=*) sfx="${1##--sfx=}" ;;
860 --mode=*) mode="${1##--mode=}" ;;
866 # complete references based on the specified mode
869 __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
871 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
873 __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
878 # Append DWIM remote branch names if requested
879 if [ "$dwim" = "yes" ]; then
880 __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
884 # __git_refs2 requires 1 argument (to pass to __git_refs)
885 # Deprecated: use __git_complete_fetch_refspecs() instead.
889 for i in $(__git_refs "$1"); do
894 # Completes refspecs for fetching from a remote repository.
895 # 1: The remote repository.
896 # 2: A prefix to be added to each listed refspec (optional).
897 # 3: The ref to be completed as a refspec instead of the current word to be
898 # completed (optional)
899 # 4: A suffix to be appended to each listed refspec instead of the default
901 __git_complete_fetch_refspecs ()
903 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
906 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
912 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
913 __git_refs_remotes ()
916 __git ls-remote "$1" 'refs/heads/*' | \
917 while read -r hash i; do
918 echo "$i:refs/remotes/$1/${i#refs/heads/}"
925 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
929 # Returns true if $1 matches the name of a configured remote, false otherwise.
930 __git_is_configured_remote ()
933 for remote in $(__git_remotes); do
934 if [ "$remote" = "$1" ]; then
941 __git_list_merge_strategies ()
943 LANG=C LC_ALL=C git merge -s help 2>&1 |
944 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
953 __git_merge_strategies=
954 # 'git merge -s help' (and thus detection of the merge strategy
955 # list) fails, unfortunately, if run outside of any git working
956 # tree. __git_merge_strategies is set to the empty string in
957 # that case, and the detection will be repeated the next time it
959 __git_compute_merge_strategies ()
961 test -n "$__git_merge_strategies" ||
962 __git_merge_strategies=$(__git_list_merge_strategies)
965 __git_merge_strategy_options="ours theirs subtree subtree= patience
966 histogram diff-algorithm= ignore-space-change ignore-all-space
967 ignore-space-at-eol renormalize no-renormalize no-renames
968 find-renames find-renames= rename-threshold="
970 __git_complete_revlist_file ()
972 local dequoted_word pfx ls ref cur_="$cur"
981 __git_dequote "$cur_"
983 case "$dequoted_word" in
985 pfx="${dequoted_word%/*}"
986 cur_="${dequoted_word##*/}"
991 cur_="$dequoted_word"
996 case "$COMP_WORDBREAKS" in
998 *) pfx="$ref:$pfx" ;;
1001 __gitcomp_file "$(__git ls-tree "$ls" \
1007 pfx="${cur_%...*}..."
1009 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1014 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1022 __git_complete_file ()
1024 __git_complete_revlist_file
1027 __git_complete_revlist ()
1029 __git_complete_revlist_file
1032 __git_complete_remote_or_refspec ()
1034 local cur_="$cur" cmd="${words[__git_cmd_idx]}"
1035 local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
1036 if [ "$cmd" = "remote" ]; then
1039 while [ $c -lt $cword ]; do
1042 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
1043 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
1046 push) no_complete_refspec=1 ;;
1053 --multiple) no_complete_refspec=1; break ;;
1055 *) remote="$i"; break ;;
1059 if [ -z "$remote" ]; then
1060 __gitcomp_nl "$(__git_remotes)"
1063 if [ $no_complete_refspec = 1 ]; then
1066 [ "$remote" = "." ] && remote=
1069 case "$COMP_WORDBREAKS" in
1071 *) pfx="${cur_%%:*}:" ;;
1083 if [ $lhs = 1 ]; then
1084 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
1086 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1090 if [ $lhs = 1 ]; then
1091 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1093 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1097 if [ $lhs = 1 ]; then
1098 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1100 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1106 __git_complete_strategy ()
1108 __git_compute_merge_strategies
1111 __gitcomp "$__git_merge_strategies"
1115 __gitcomp "$__git_merge_strategy_options"
1121 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1124 --strategy-option=*)
1125 __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1133 __git_compute_all_commands ()
1135 test -n "$__git_all_commands" ||
1136 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1139 # Lists all set config variables starting with the given section prefix,
1140 # with the prefix removed.
1141 __git_get_config_variables ()
1143 local section="$1" i IFS=$'\n'
1144 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1145 echo "${i#$section.}"
1149 __git_pretty_aliases ()
1151 __git_get_config_variables "pretty"
1154 # __git_aliased_command requires 1 argument
1155 __git_aliased_command ()
1157 local cur=$1 last list= word cmdline
1159 while [[ -n "$cur" ]]; do
1160 if [[ "$list" == *" $cur "* ]]; then
1165 cmdline=$(__git config --get "alias.$cur")
1170 for word in $cmdline; do
1176 \!*) : shell command alias ;;
1178 *=*) : setting env ;;
1179 git) : git itself ;;
1180 \(\)) : skip parens of shell function definition ;;
1181 {) : skip start of shell helper function ;;
1182 :) : skip null command ;;
1183 \'*) : skip opening quote after sh -c ;;
1192 if [[ "$cur" != "$1" ]]; then
1197 # Check whether one of the given words is present on the command line,
1198 # and print the first word found.
1200 # Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
1201 # --show-idx: Optionally show the index of the found word in the $words array.
1202 __git_find_on_cmdline ()
1204 local word c="$__git_cmd_idx" show_idx
1206 while test $# -gt 1; do
1208 --show-idx) show_idx=y ;;
1215 while [ $c -lt $cword ]; do
1216 for word in $wordlist; do
1217 if [ "$word" = "${words[c]}" ]; then
1218 if [ -n "${show_idx-}" ]; then
1230 # Similar to __git_find_on_cmdline, except that it loops backwards and thus
1231 # prints the *last* word found. Useful for finding which of two options that
1232 # supersede each other came last, such as "--guess" and "--no-guess".
1234 # Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
1235 # --show-idx: Optionally show the index of the found word in the $words array.
1236 __git_find_last_on_cmdline ()
1238 local word c=$cword show_idx
1240 while test $# -gt 1; do
1242 --show-idx) show_idx=y ;;
1249 while [ $c -gt "$__git_cmd_idx" ]; do
1251 for word in $wordlist; do
1252 if [ "$word" = "${words[c]}" ]; then
1253 if [ -n "$show_idx" ]; then
1264 # Echo the value of an option set on the command line or config
1266 # $1: short option name
1267 # $2: long option name including =
1268 # $3: list of possible values
1269 # $4: config string (optional)
1272 # result="$(__git_get_option_value "-d" "--do-something=" \
1273 # "yes no" "core.doSomething")"
1275 # result is then either empty (no option set) or "yes" or "no"
1277 # __git_get_option_value requires 3 arguments
1278 __git_get_option_value ()
1280 local c short_opt long_opt val
1281 local result= values config_key word
1289 while [ $c -ge 0 ]; do
1291 for val in $values; do
1292 if [ "$short_opt$val" = "$word" ] ||
1293 [ "$long_opt$val" = "$word" ]; then
1301 if [ -n "$config_key" ] && [ -z "$result" ]; then
1302 result="$(__git config "$config_key")"
1308 __git_has_doubledash ()
1311 while [ $c -lt $cword ]; do
1312 if [ "--" = "${words[c]}" ]; then
1320 # Try to count non option arguments passed on the command line for the
1321 # specified git command.
1322 # When options are used, it is necessary to use the special -- option to
1323 # tell the implementation were non option arguments begin.
1324 # XXX this can not be improved, since options can appear everywhere, as
1328 # __git_count_arguments requires 1 argument: the git command executed.
1329 __git_count_arguments ()
1333 # Skip "git" (first argument)
1334 for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
1339 # Good; we can assume that the following are only non
1344 # Skip the specified git command and discard git
1357 __git_whitespacelist="nowarn warn error error-all fix"
1358 __git_patchformat="mbox stgit stgit-series hg mboxrd"
1359 __git_showcurrentpatch="diff raw"
1360 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1361 __git_quoted_cr="nowarn warn strip"
1365 __git_find_repo_path
1366 if [ -d "$__git_repo_path"/rebase-apply ]; then
1367 __gitcomp "$__git_am_inprogress_options"
1372 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1376 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1379 --show-current-patch=*)
1380 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
1384 __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}"
1388 __gitcomp_builtin am "" \
1389 "$__git_am_inprogress_options"
1398 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1402 __gitcomp_builtin apply
1411 __gitcomp "+x -x" "" "${cur##--chmod=}"
1415 __gitcomp_builtin add
1419 local complete_opt="--others --modified --directory --no-empty-directory"
1420 if test -n "$(__git_find_on_cmdline "-u --update")"
1422 complete_opt="--modified"
1424 __git_complete_index_file "$complete_opt"
1431 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1435 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1439 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
1448 __git_has_doubledash && return
1450 local subcommands="start bad good skip reset visualize replay log run"
1451 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1452 if [ -z "$subcommand" ]; then
1453 __git_find_repo_path
1454 if [ -f "$__git_repo_path"/BISECT_START ]; then
1455 __gitcomp "$subcommands"
1457 __gitcomp "replay start"
1462 case "$subcommand" in
1463 bad|good|reset|skip|start)
1471 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1475 local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
1477 while [ $c -lt $cword ]; do
1480 -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
1481 only_local_ref="y" ;;
1489 --set-upstream-to=*)
1490 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1493 __gitcomp_builtin branch
1496 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1497 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1507 local cmd="${words[__git_cmd_idx+1]}"
1509 $((__git_cmd_idx+1)))
1510 __gitcomp "create list-heads verify unbundle"
1512 $((__git_cmd_idx+2)))
1513 # looking for a file
1518 __git_complete_revlist
1525 # Helper function to decide whether or not we should enable DWIM logic for
1526 # git-switch and git-checkout.
1528 # To decide between the following rules in decreasing priority order:
1529 # - the last provided of "--guess" or "--no-guess" explicitly enable or
1530 # disable completion of DWIM logic respectively.
1531 # - If checkout.guess is false, disable completion of DWIM logic.
1532 # - If the --no-track option is provided, take this as a hint to disable the
1533 # DWIM completion logic
1534 # - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
1535 # logic, as requested by the user.
1536 # - Enable DWIM logic otherwise.
1538 __git_checkout_default_dwim_mode ()
1540 local last_option dwim_opt="--dwim"
1542 if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1546 # --no-track disables DWIM, but with lower priority than
1547 # --guess/--no-guess/checkout.guess
1548 if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
1552 # checkout.guess = false disables DWIM, but with lower priority than
1553 # --guess/--no-guess
1554 if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
1558 # Find the last provided --guess or --no-guess
1559 last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
1560 case "$last_option" in
1574 __git_has_doubledash && return
1576 local dwim_opt="$(__git_checkout_default_dwim_mode)"
1580 # Complete local branches (and DWIM branch
1581 # remote branch names) for an option argument
1582 # specifying a new branch name. This is for
1583 # convenience, assuming new branches are
1584 # possibly based on pre-existing branch names.
1585 __git_complete_refs $dwim_opt --mode="heads"
1594 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
1597 __gitcomp_builtin checkout
1600 # At this point, we've already handled special completion for
1601 # the arguments to -b/-B, and --orphan. There are 3 main
1602 # things left we can possibly complete:
1603 # 1) a start-point for -b/-B, -d/--detach, or --orphan
1604 # 2) a remote head, for --track
1605 # 3) an arbitrary reference, possibly including DWIM names
1608 if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
1609 __git_complete_refs --mode="refs"
1610 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
1611 __git_complete_refs --mode="remote-heads"
1613 __git_complete_refs $dwim_opt --mode="refs"
1619 __git_sequencer_inprogress_options="--continue --quit --abort --skip"
1621 __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1625 __git_find_repo_path
1626 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1627 __gitcomp "$__git_cherry_pick_inprogress_options"
1631 __git_complete_strategy && return
1635 __gitcomp_builtin cherry-pick "" \
1636 "$__git_cherry_pick_inprogress_options"
1648 __gitcomp_builtin clean
1653 # XXX should we check for -x option ?
1654 __git_complete_index_file "--others --directory"
1661 __git_complete_config_variable_name_and_value
1667 __git_complete_config_variable_name_and_value \
1668 --cur="${cur##--config=}"
1672 __gitcomp_builtin clone
1678 __git_untracked_file_modes="all no normal"
1691 __gitcomp "default scissors strip verbatim whitespace
1692 " "" "${cur##--cleanup=}"
1695 --reuse-message=*|--reedit-message=*|\
1696 --fixup=*|--squash=*)
1697 __git_complete_refs --cur="${cur#*=}"
1700 --untracked-files=*)
1701 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1705 __gitcomp_builtin commit
1709 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1710 __git_complete_index_file "--committable"
1712 # This is the first commit
1713 __git_complete_index_file "--cached"
1721 __gitcomp_builtin describe
1727 __git_diff_algorithms="myers minimal patience histogram"
1729 __git_diff_submodule_formats="diff log short"
1731 __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
1733 __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
1734 ignore-all-space allow-indentation-change"
1736 __git_diff_common_options="--stat --numstat --shortstat --summary
1737 --patch-with-stat --name-only --name-status --color
1738 --no-color --color-words --no-renames --check
1739 --color-moved --color-moved= --no-color-moved
1740 --color-moved-ws= --no-color-moved-ws
1741 --full-index --binary --abbrev --diff-filter=
1742 --find-copies-harder --ignore-cr-at-eol
1743 --text --ignore-space-at-eol --ignore-space-change
1744 --ignore-all-space --ignore-blank-lines --exit-code
1745 --quiet --ext-diff --no-ext-diff
1746 --no-prefix --src-prefix= --dst-prefix=
1747 --inter-hunk-context=
1748 --patience --histogram --minimal
1749 --raw --word-diff --word-diff-regex=
1750 --dirstat --dirstat= --dirstat-by-file
1751 --dirstat-by-file= --cumulative
1753 --submodule --submodule= --ignore-submodules
1754 --indent-heuristic --no-indent-heuristic
1755 --textconv --no-textconv
1760 __git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex
1761 --base --ours --theirs --no-index --relative --merge-base
1762 $__git_diff_common_options"
1766 __git_has_doubledash && return
1770 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1774 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1778 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
1782 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
1786 __gitcomp "$__git_diff_difftool_options"
1790 __git_complete_revlist_file
1793 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1794 tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1795 bc codecompare smerge
1800 __git_has_doubledash && return
1804 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1808 __gitcomp_builtin difftool "$__git_diff_difftool_options"
1812 __git_complete_revlist_file
1815 __git_fetch_recurse_submodules="yes on-demand no"
1820 --recurse-submodules=*)
1821 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1825 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1829 __gitcomp_builtin fetch
1833 __git_complete_remote_or_refspec
1836 __git_format_patch_extra_options="
1837 --full-index --not --all --no-prefix --src-prefix=
1838 --dst-prefix= --notes
1841 _git_format_patch ()
1847 " "" "${cur##--thread=}"
1850 --base=*|--interdiff=*|--range-diff=*)
1851 __git_complete_refs --cur="${cur#--*=}"
1855 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1859 __git_complete_revlist
1866 __gitcomp_builtin fsck
1877 # Lists matching symbol names from a tag (as in ctags) file.
1878 # 1: List symbol names matching this word.
1879 # 2: The tag file to list symbol names from.
1880 # 3: A prefix to be added to each listed symbol name (optional).
1881 # 4: A suffix to be appended to each listed symbol name (optional).
1882 __git_match_ctag () {
1883 awk -v pfx="${3-}" -v sfx="${4-}" "
1884 /^${1//\//\\/}/ { print pfx \$1 sfx }
1888 # Complete symbol names from a tag file.
1889 # Usage: __git_complete_symbol [<option>]...
1890 # --tags=<file>: The tag file to list symbol names from instead of the
1892 # --pfx=<prefix>: A prefix to be added to each symbol name.
1893 # --cur=<word>: The current symbol name to be completed. Defaults to
1894 # the current word to be completed.
1895 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1896 # of the default space.
1897 __git_complete_symbol () {
1898 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1900 while test $# != 0; do
1902 --tags=*) tags="${1##--tags=}" ;;
1903 --pfx=*) pfx="${1##--pfx=}" ;;
1904 --cur=*) cur_="${1##--cur=}" ;;
1905 --sfx=*) sfx="${1##--sfx=}" ;;
1911 if test -r "$tags"; then
1912 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1918 __git_has_doubledash && return
1922 __gitcomp_builtin grep
1927 case "$cword,$prev" in
1928 $((__git_cmd_idx+1)),*|*,-*)
1929 __git_complete_symbol && return
1940 __gitcomp_builtin help
1944 if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
1946 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
1948 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1957 false true umask group all world everybody
1958 " "" "${cur##--shared=}"
1962 __gitcomp_builtin init
1972 __gitcomp_builtin ls-files
1977 # XXX ignore options like --modified and always suggest all cached
1979 __git_complete_index_file "--cached"
1986 __gitcomp_builtin ls-remote
1990 __gitcomp_nl "$(__git_remotes)"
1997 __gitcomp_builtin ls-tree
2005 # Options that go well for log, shortlog and gitk
2006 __git_log_common_options="
2008 --branches --tags --remotes
2009 --first-parent --merges --no-merges
2011 --max-age= --since= --after=
2012 --min-age= --until= --before=
2013 --min-parents= --max-parents=
2014 --no-min-parents --no-max-parents
2016 # Options that go well for log and gitk (not shortlog)
2017 __git_log_gitk_options="
2018 --dense --sparse --full-history
2019 --simplify-merges --simplify-by-decoration
2020 --left-right --notes --no-notes
2022 # Options that go well for log and shortlog (not gitk)
2023 __git_log_shortlog_options="
2024 --author= --committer= --grep=
2025 --all-match --invert-grep
2028 __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
2029 __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
2033 __git_has_doubledash && return
2034 __git_find_repo_path
2037 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2040 case "$prev,$cur" in
2042 return # fall back to Bash filename completion
2045 __git_complete_symbol --cur="${cur#:}" --sfx=":"
2049 __git_complete_symbol
2054 --pretty=*|--format=*)
2055 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2060 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
2064 __gitcomp "full short no" "" "${cur##--decorate=}"
2068 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2072 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2076 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
2081 $__git_log_common_options
2082 $__git_log_shortlog_options
2083 $__git_log_gitk_options
2084 --root --topo-order --date-order --reverse
2085 --follow --full-diff
2086 --abbrev-commit --no-abbrev-commit --abbrev=
2087 --relative-date --date=
2088 --pretty= --format= --oneline
2093 --decorate --decorate= --no-decorate
2095 --no-walk --no-walk= --do-walk
2096 --parents --children
2097 --expand-tabs --expand-tabs= --no-expand-tabs
2099 $__git_diff_common_options
2100 --pickaxe-all --pickaxe-regex
2105 return # fall back to Bash filename completion
2108 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
2112 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
2116 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
2120 __git_complete_revlist
2125 __git_complete_strategy && return
2129 __gitcomp_builtin merge
2139 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
2143 __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
2153 __gitcomp_builtin merge-base
2164 __gitcomp_builtin mv
2169 if [ $(__git_count_arguments "mv") -gt 0 ]; then
2170 # We need to show both cached and untracked files (including
2171 # empty directories) since this may not be the last argument.
2172 __git_complete_index_file "--cached --others --directory"
2174 __git_complete_index_file "--cached"
2180 local subcommands='add append copy edit get-ref list merge prune remove show'
2181 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2183 case "$subcommand,$cur" in
2185 __gitcomp_builtin notes
2193 __gitcomp "$subcommands --ref"
2197 *,--reuse-message=*|*,--reedit-message=*)
2198 __git_complete_refs --cur="${cur#*=}"
2201 __gitcomp_builtin notes_$subcommand
2204 # this command does not take a ref, do not complete it
2220 __git_complete_strategy && return
2223 --recurse-submodules=*)
2224 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
2228 __gitcomp_builtin pull
2233 __git_complete_remote_or_refspec
2236 __git_push_recurse_submodules="check on-demand only"
2238 __git_complete_force_with_lease ()
2246 __git_complete_refs --cur="${cur_#*:}"
2249 __git_complete_refs --cur="$cur_"
2258 __gitcomp_nl "$(__git_remotes)"
2261 --recurse-submodules)
2262 __gitcomp "$__git_push_recurse_submodules"
2268 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
2271 --recurse-submodules=*)
2272 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
2275 --force-with-lease=*)
2276 __git_complete_force_with_lease "${cur##--force-with-lease=}"
2280 __gitcomp_builtin push
2284 __git_complete_remote_or_refspec
2292 --creation-factor= --no-dual-color
2293 $__git_diff_common_options
2298 __git_complete_revlist
2301 __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
2302 __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
2306 __git_find_repo_path
2307 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2308 __gitcomp "$__git_rebase_interactive_inprogress_options"
2310 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2311 [ -d "$__git_repo_path"/rebase-merge ]; then
2312 __gitcomp "$__git_rebase_inprogress_options"
2315 __git_complete_strategy && return
2318 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2322 __git_complete_refs --cur="${cur##--onto=}"
2326 __gitcomp_builtin rebase "" \
2327 "$__git_rebase_interactive_inprogress_options"
2336 local subcommands="show delete expire"
2337 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2339 if [ -z "$subcommand" ]; then
2340 __gitcomp "$subcommands"
2346 __git_send_email_confirm_options="always never auto cc compose"
2347 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2352 --to|--cc|--bcc|--from)
2353 __gitcomp "$(__git send-email --dump-aliases)"
2361 $__git_send_email_confirm_options
2362 " "" "${cur##--confirm=}"
2367 $__git_send_email_suppresscc_options
2368 " "" "${cur##--suppress-cc=}"
2372 --smtp-encryption=*)
2373 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2379 " "" "${cur##--thread=}"
2382 --to=*|--cc=*|--bcc=*|--from=*)
2383 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2387 __gitcomp_builtin send-email "$__git_format_patch_extra_options"
2391 __git_complete_revlist
2402 local untracked_state
2405 --ignore-submodules=*)
2406 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2409 --untracked-files=*)
2410 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2415 always never auto column row plain dense nodense
2416 " "" "${cur##--column=}"
2420 __gitcomp_builtin status
2425 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2426 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2428 case "$untracked_state" in
2430 # --ignored option does not matter
2434 complete_opt="--cached --directory --no-empty-directory --others"
2436 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2437 complete_opt="$complete_opt --ignored --exclude=*"
2442 __git_complete_index_file "$complete_opt"
2447 local dwim_opt="$(__git_checkout_default_dwim_mode)"
2451 # Complete local branches (and DWIM branch
2452 # remote branch names) for an option argument
2453 # specifying a new branch name. This is for
2454 # convenience, assuming new branches are
2455 # possibly based on pre-existing branch names.
2456 __git_complete_refs $dwim_opt --mode="heads"
2465 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2468 __gitcomp_builtin switch
2471 # Unlike in git checkout, git switch --orphan does not take
2472 # a start point. Thus we really have nothing to complete after
2474 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
2478 # At this point, we've already handled special completion for
2479 # -c/-C, and --orphan. There are 3 main things left to
2481 # 1) a start-point for -c/-C or -d/--detach
2482 # 2) a remote head, for --track
2483 # 3) a branch name, possibly including DWIM remote branches
2485 if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
2486 __git_complete_refs --mode="refs"
2487 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
2488 __git_complete_refs --mode="remote-heads"
2490 __git_complete_refs $dwim_opt --mode="heads"
2496 __git_config_get_set_variables ()
2498 local prevword word config_file= c=$cword
2499 while [ $c -gt "$__git_cmd_idx" ]; do
2502 --system|--global|--local|--file=*)
2507 config_file="$word $prevword"
2515 __git config $config_file --name-only --list
2519 __git_compute_config_vars ()
2521 test -n "$__git_config_vars" ||
2522 __git_config_vars="$(git help --config-for-completion)"
2525 __git_config_sections=
2526 __git_compute_config_sections ()
2528 test -n "$__git_config_sections" ||
2529 __git_config_sections="$(git help --config-sections-for-completion)"
2532 # Completes possible values of various configuration variables.
2534 # Usage: __git_complete_config_variable_value [<option>]...
2535 # --varname=<word>: The name of the configuration variable whose value is
2536 # to be completed. Defaults to the previous word on the
2538 # --cur=<word>: The current value to be completed. Defaults to the current
2539 # word to be completed.
2540 __git_complete_config_variable_value ()
2542 local varname="$prev" cur_="$cur"
2544 while test $# != 0; do
2546 --varname=*) varname="${1##--varname=}" ;;
2547 --cur=*) cur_="${1##--cur=}" ;;
2553 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2554 varname="${varname,,}"
2556 varname="$(echo "$varname" |tr A-Z a-z)"
2560 branch.*.remote|branch.*.pushremote)
2561 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2565 __git_complete_refs --cur="$cur_"
2569 __gitcomp "false true merges interactive" "" "$cur_"
2573 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2577 local remote="${varname#remote.}"
2578 remote="${remote%.fetch}"
2579 if [ -z "$cur_" ]; then
2580 __gitcomp_nl "refs/heads/" "" "" ""
2583 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2587 local remote="${varname#remote.}"
2588 remote="${remote%.push}"
2589 __gitcomp_nl "$(__git for-each-ref \
2590 --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2593 pull.twohead|pull.octopus)
2594 __git_compute_merge_strategies
2595 __gitcomp "$__git_merge_strategies" "" "$cur_"
2599 __gitcomp "false true" "" "$cur_"
2604 normal black red green yellow blue magenta cyan white
2605 bold dim ul blink reverse
2610 __gitcomp "false true always never auto" "" "$cur_"
2614 __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2618 __gitcomp "man info web html" "" "$cur_"
2622 __gitcomp "$__git_log_date_formats" "" "$cur_"
2625 sendemail.aliasfiletype)
2626 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2630 __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2633 sendemail.suppresscc)
2634 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2637 sendemail.transferencoding)
2638 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2647 # Completes configuration sections, subsections, variable names.
2649 # Usage: __git_complete_config_variable_name [<option>]...
2650 # --cur=<word>: The current configuration section/variable name to be
2651 # completed. Defaults to the current word to be completed.
2652 # --sfx=<suffix>: A suffix to be appended to each fully completed
2653 # configuration variable name (but not to sections or
2654 # subsections) instead of the default space.
2655 __git_complete_config_variable_name ()
2657 local cur_="$cur" sfx
2659 while test $# != 0; do
2661 --cur=*) cur_="${1##--cur=}" ;;
2662 --sfx=*) sfx="${1##--sfx=}" ;;
2670 local pfx="${cur_%.*}."
2672 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2676 local pfx="${cur_%.*}."
2678 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2679 __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
2683 local pfx="${cur_%.*}."
2686 argPrompt cmd confirm needsFile noConsole noRescan
2687 prompt revPrompt revUnmerged title
2688 " "$pfx" "$cur_" "$sfx"
2692 local pfx="${cur_%.*}."
2694 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2698 local pfx="${cur_%.*}."
2700 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2704 local pfx="${cur_%.*}."
2706 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2710 local pfx="${cur_%.*}."
2712 __git_compute_all_commands
2713 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
2717 local pfx="${cur_%.*}."
2720 url proxy fetch push mirror skipDefaultUpdate
2721 receivepack uploadpack tagOpt pushurl
2722 " "$pfx" "$cur_" "$sfx"
2726 local pfx="${cur_%.*}."
2728 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2729 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
2733 local pfx="${cur_%.*}."
2735 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2739 __git_compute_config_vars
2740 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
2743 __git_compute_config_sections
2744 __gitcomp "$__git_config_sections" "" "$cur_" "."
2749 # Completes '='-separated configuration sections/variable names and values
2750 # for 'git -c section.name=value'.
2752 # Usage: __git_complete_config_variable_name_and_value [<option>]...
2753 # --cur=<word>: The current configuration section/variable name/value to be
2754 # completed. Defaults to the current word to be completed.
2755 __git_complete_config_variable_name_and_value ()
2759 while test $# != 0; do
2761 --cur=*) cur_="${1##--cur=}" ;;
2769 __git_complete_config_variable_value \
2770 --varname="${cur_%%=*}" --cur="${cur_#*=}"
2773 __git_complete_config_variable_name --cur="$cur_" --sfx='='
2781 --get|--get-all|--unset|--unset-all)
2782 __gitcomp_nl "$(__git_config_get_set_variables)"
2786 __git_complete_config_variable_value
2792 __gitcomp_builtin config
2795 __git_complete_config_variable_name
2803 add rename remove set-head set-branches
2804 get-url set-url show prune update
2806 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2807 if [ -z "$subcommand" ]; then
2810 __gitcomp_builtin remote
2813 __gitcomp "$subcommands"
2819 case "$subcommand,$cur" in
2821 __gitcomp_builtin remote_add
2826 __gitcomp_builtin remote_set-head
2829 __gitcomp_builtin remote_set-branches
2831 set-head,*|set-branches,*)
2832 __git_complete_remote_or_refspec
2835 __gitcomp_builtin remote_update
2838 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
2841 __gitcomp_builtin remote_set-url
2844 __gitcomp_builtin remote_get-url
2847 __gitcomp_builtin remote_prune
2850 __gitcomp_nl "$(__git_remotes)"
2859 __gitcomp "short medium long" "" "${cur##--format=}"
2863 __gitcomp_builtin replace
2872 local subcommands="clear forget diff remaining status gc"
2873 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2874 if test -z "$subcommand"
2876 __gitcomp "$subcommands"
2883 __git_has_doubledash && return
2887 __gitcomp_builtin reset
2905 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2908 __git_complete_refs --cur="${cur##--source=}"
2911 __gitcomp_builtin restore
2914 if __git rev-parse --verify --quiet HEAD >/dev/null; then
2915 __git_complete_index_file "--modified"
2920 __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2924 __git_find_repo_path
2925 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2926 __gitcomp "$__git_revert_inprogress_options"
2929 __git_complete_strategy && return
2932 __gitcomp_builtin revert "" \
2933 "$__git_revert_inprogress_options"
2944 __gitcomp_builtin rm
2949 __git_complete_index_file "--cached"
2954 __git_has_doubledash && return
2959 $__git_log_common_options
2960 $__git_log_shortlog_options
2961 --numbered --summary --email
2966 __git_complete_revlist
2971 __git_has_doubledash && return
2974 --pretty=*|--format=*)
2975 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2980 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2984 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2988 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
2992 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
2996 __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
2997 --oneline --show-signature
2998 --expand-tabs --expand-tabs= --no-expand-tabs
2999 $__git_diff_common_options
3004 __git_complete_revlist_file
3011 __gitcomp_builtin show-branch
3015 __git_complete_revlist
3018 __gitcomp_directories ()
3020 local _tmp_dir _tmp_completions _found=0
3022 # Get the directory of the current token; this differs from dirname
3023 # in that it keeps up to the final trailing slash. If no slash found
3026 _tmp_dir=$BASH_REMATCH
3028 # Find possible directory completions, adding trailing '/' characters,
3029 # de-quoting, and handling unusual characters.
3030 while IFS= read -r -d $'\0' c ; do
3031 # If there are directory completions, find ones that start
3032 # with "$cur", the current token, and put those in COMPREPLY
3033 if [[ $c == "$cur"* ]]; then
3037 done < <(git ls-tree -z -d --name-only HEAD $_tmp_dir)
3039 if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then
3040 # No possible further completions any deeper, so assume we're at
3041 # a leaf directory and just consider it complete
3042 __gitcomp_direct_append "$cur "
3046 _git_sparse_checkout ()
3048 local subcommands="list init set disable add reapply"
3049 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3050 if [ -z "$subcommand" ]; then
3051 __gitcomp "$subcommands"
3055 case "$subcommand,$cur" in
3057 __gitcomp_builtin sparse-checkout_$subcommand "" "--"
3060 if [ "$(__git config core.sparseCheckoutCone)" == "true" ] ||
3061 [ -n "$(__git_find_on_cmdline --cone)" ]; then
3062 __gitcomp_directories
3069 local subcommands='push list show apply clear drop pop create branch'
3070 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3072 if [ -z "$subcommand" ]; then
3073 case "$((cword - __git_cmd_idx)),$cur" in
3075 __gitcomp_builtin stash_push
3081 __gitcomp "$subcommands"
3087 case "$subcommand,$cur" in
3089 # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3090 __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
3093 __gitcomp_builtin stash_show "$__git_diff_common_options"
3096 __gitcomp_builtin "stash_$subcommand"
3099 if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3102 __gitcomp_nl "$(__git stash list \
3103 | sed -n -e 's/:.*//p')"
3106 show,*|apply,*|drop,*|pop,*)
3107 __gitcomp_nl "$(__git stash list \
3108 | sed -n -e 's/:.*//p')"
3115 __git_has_doubledash && return
3117 local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
3118 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3119 if [ -z "$subcommand" ]; then
3125 __gitcomp "$subcommands"
3131 case "$subcommand,$cur" in
3133 __gitcomp "--branch --force --name --reference --depth"
3136 __gitcomp "--cached --recursive"
3139 __gitcomp "--force --all"
3143 --init --remote --no-fetch
3144 --recommend-shallow --no-recommend-shallow
3145 --force --rebase --merge --reference --depth --recursive --jobs
3149 __gitcomp "--default --branch"
3152 __gitcomp "--cached --files --summary-limit"
3154 foreach,--*|sync,--*)
3155 __gitcomp "--recursive"
3165 init fetch clone rebase dcommit log find-rev
3166 set-tree commit-diff info create-ignore propget
3167 proplist show-ignore show-externals branch tag blame
3168 migrate mkdirs reset gc
3170 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3171 if [ -z "$subcommand" ]; then
3172 __gitcomp "$subcommands"
3174 local remote_opts="--username= --config-dir= --no-auth-cache"
3176 --follow-parent --authors-file= --repack=
3177 --no-metadata --use-svm-props --use-svnsync-props
3178 --log-window-size= --no-checkout --quiet
3179 --repack-flags --use-log-author --localtime
3182 --ignore-paths= --include-paths= $remote_opts
3185 --template= --shared= --trunk= --tags=
3186 --branches= --stdlayout --minimize-url
3187 --no-metadata --use-svm-props --use-svnsync-props
3188 --rewrite-root= --prefix= $remote_opts
3191 --edit --rmdir --find-copies-harder --copy-similarity=
3194 case "$subcommand,$cur" in
3196 __gitcomp "--revision= --fetch-all $fc_opts"
3199 __gitcomp "--revision= $fc_opts $init_opts"
3202 __gitcomp "$init_opts"
3206 --merge --strategy= --verbose --dry-run
3207 --fetch-all --no-rebase --commit-url
3208 --revision --interactive $cmt_opts $fc_opts
3212 __gitcomp "--stdin $cmt_opts $fc_opts"
3214 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
3215 show-externals,--*|mkdirs,--*)
3216 __gitcomp "--revision="
3220 --limit= --revision= --verbose --incremental
3221 --oneline --show-commit --non-recursive
3222 --authors-file= --color
3227 --merge --verbose --strategy= --local
3228 --fetch-all --dry-run $fc_opts
3232 __gitcomp "--message= --file= --revision= $cmt_opts"
3238 __gitcomp "--dry-run --message --tag"
3241 __gitcomp "--dry-run --message"
3244 __gitcomp "--git-format"
3248 --config-dir= --ignore-paths= --minimize
3249 --no-auth-cache --username=
3253 __gitcomp "--revision= --parent"
3263 local i c="$__git_cmd_idx" f=0
3264 while [ $c -lt $cword ]; do
3267 -d|--delete|-v|--verify)
3268 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3283 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3293 __gitcomp_builtin tag
3303 __git_complete_worktree_paths ()
3306 # Generate completion reply from worktree list skipping the first
3307 # entry: it's the path of the main worktree, which can't be moved,
3308 # removed, locked, etc.
3309 __gitcomp_nl "$(git worktree list --porcelain |
3310 sed -n -e '2,$ s/^worktree //p')"
3315 local subcommands="add list lock move prune remove unlock"
3316 local subcommand subcommand_idx
3318 subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3319 subcommand_idx="${subcommand% *}"
3320 subcommand="${subcommand#* }"
3322 case "$subcommand,$cur" in
3324 __gitcomp "$subcommands"
3327 __gitcomp_builtin worktree_$subcommand
3329 add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
3330 # Here we are not completing an --option, it's either the
3333 -b|-B) # Complete refs for branch to be created/reseted.
3336 -*) # The previous word is an -o|--option without an
3337 # unstuck argument: have to complete the path for
3338 # the new worktree, so don't list anything, but let
3339 # Bash fall back to filename completion.
3341 *) # The previous word is not an --option, so it must
3342 # be either the 'add' subcommand, the unstuck
3343 # argument of an option (e.g. branch for -b|-B), or
3344 # the path for the new worktree.
3345 if [ $cword -eq $((subcommand_idx+1)) ]; then
3346 # Right after the 'add' subcommand: have to
3347 # complete the path, so fall back to Bash
3348 # filename completion.
3351 case "${words[cword-2]}" in
3352 -b|-B) # After '-b <branch>': have to
3353 # complete the path, so fall back
3354 # to Bash filename completion.
3356 *) # After the path: have to complete
3357 # the ref to be checked out.
3365 lock,*|remove,*|unlock,*)
3366 __git_complete_worktree_paths
3369 if [ $cword -eq $((subcommand_idx+1)) ]; then
3370 # The first parameter must be an existing working
3372 __git_complete_worktree_paths
3374 # The second parameter is the destination: it could
3375 # be any path, so don't list anything, but let Bash
3376 # fall back to filename completion.
3383 __git_complete_common () {
3388 __gitcomp_builtin "$command"
3393 __git_cmds_with_parseopt_helper=
3394 __git_support_parseopt_helper () {
3395 test -n "$__git_cmds_with_parseopt_helper" ||
3396 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
3398 case " $__git_cmds_with_parseopt_helper " in
3408 __git_have_func () {
3409 declare -f -- "$1" >/dev/null 2>&1
3412 __git_complete_command () {
3414 local completion_func="_git_${command//-/_}"
3415 if ! __git_have_func $completion_func &&
3416 __git_have_func _completion_loader
3418 _completion_loader "git-$command"
3420 if __git_have_func $completion_func
3424 elif __git_support_parseopt_helper "$command"
3426 __git_complete_common "$command"
3435 local i c=1 command __git_dir __git_repo_path
3436 local __git_C_args C_args_count=0
3439 while [ $c -lt $cword ]; do
3443 __git_dir="${i#--git-dir=}"
3447 __git_dir="${words[c]}"
3456 -c|--work-tree|--namespace)
3460 __git_C_args[C_args_count++]=-C
3462 __git_C_args[C_args_count++]="${words[c]}"
3475 if [ -z "${command-}" ]; then
3477 --git-dir|-C|--work-tree)
3478 # these need a path argument, let's fall back to
3479 # Bash filename completion
3483 __git_complete_config_variable_name_and_value
3487 # we don't support completing these options' arguments
3506 --no-replace-objects
3511 if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3513 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3515 local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
3517 if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
3519 list_cmds=builtins,$list_cmds
3521 __gitcomp "$(__git --list-cmds=$list_cmds)"
3528 __git_complete_command "$command" && return
3530 local expansion=$(__git_aliased_command "$command")
3531 if [ -n "$expansion" ]; then
3533 __git_complete_command "$expansion"
3539 __git_has_doubledash && return
3541 local __git_repo_path
3542 __git_find_repo_path
3545 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3551 $__git_log_common_options
3552 $__git_log_gitk_options
3558 __git_complete_revlist
3561 if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
3562 echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
3568 local cur words cword prev
3569 local __git_cmd_idx=0
3570 _get_comp_words_by_ref -n =: cur words cword prev
3576 local wrapper="__git_wrap${2}"
3577 eval "$wrapper () { __git_func_wrap $2 ; }"
3578 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3579 || complete -o default -o nospace -F $wrapper $1
3582 # Setup the completion for git commands
3583 # 1: command or alias
3584 # 2: function to call (e.g. `git
`, `gitk
`, `git_fetch
`)
3589 if __git_have_func $2; then
3591 elif __git_have_func __$2_main; then
3593 elif __git_have_func _$2; then
3596 echo "ERROR: could not find function '$2'" 1>&2
3599 ___git_complete $1 $func
3602 ___git_complete git __git_main
3603 ___git_complete gitk __gitk_main
3605 # The following are necessary only for Cygwin, and only are needed
3606 # when the user has tab-completed the executable name and consequently
3607 # included the '.exe' suffix.
3609 if [ "$OSTYPE" = cygwin ]; then
3610 ___git_complete git.exe __git_main