]>
git.ipfire.org Git - thirdparty/git.git/blob - contrib/completion/git-completion.bash
8c40ade49411bb883799d79983ad33a696651aa8
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 # Helper function to read the first line of a file into a variable.
126 # __git_eread requires 2 arguments, the file path and the name of the
127 # variable, in that order.
129 # This is taken from git-prompt.sh.
132 test -r "$1" && IFS
=$
'\r\n' read -r "$2" <"$1"
135 # Runs git in $__git_repo_path to determine whether a pseudoref exists.
136 # 1: The pseudo-ref to search
137 __git_pseudoref_exists
()
141 # If the reftable is in use, we have to shell out to 'git rev-parse'
142 # to determine whether the ref exists instead of looking directly in
143 # the filesystem to determine whether the ref exists. Otherwise, use
144 # Bash builtins since executing Git commands are expensive on some
146 if __git_eread
"$__git_repo_path/HEAD" head; then
148 if [ "$b" == "refs/heads/.invalid" ]; then
149 __git
-C "$__git_repo_path" rev-parse
--verify --quiet "$ref" 2>/dev
/null
154 [ -f "$__git_repo_path/$ref" ]
157 # Removes backslash escaping, single quotes and double quotes from a word,
158 # stores the result in the variable $dequoted_word.
159 # 1: The word to dequote.
162 local rest
="$1" len ch
166 while test -n "$rest"; do
167 len
=${#dequoted_word}
168 dequoted_word
="$dequoted_word${rest%%[\\\'\"]*}"
169 rest
="${rest:$((${#dequoted_word}-$len))}"
171 case "${rest:0:1}" in
178 dequoted_word
="$dequoted_word$ch"
185 len
=${#dequoted_word}
186 dequoted_word
="$dequoted_word${rest%%\'*}"
187 rest
="${rest:$((${#dequoted_word}-$len+1))}"
191 while test -n "$rest" ; do
192 len
=${#dequoted_word}
193 dequoted_word
="$dequoted_word${rest%%[\\\"]*}"
194 rest
="${rest:$((${#dequoted_word}-$len))}"
195 case "${rest:0:1}" in
200 dequoted_word="$dequoted_word$ch"
205 dequoted_word="$dequoted_word\\$ch"
221 # The following function is based on code from:
223 # bash_completion - programmable completion functions for bash 3.2+
225 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
226 # © 2009-2010, Bash Completion Maintainers
227 # <bash-completion-devel@lists.alioth.debian.org>
229 # This program is free software; you can redistribute it and/or modify
230 # it under the terms of the GNU General Public License as published by
231 # the Free Software Foundation; either version 2, or (at your option)
234 # This program is distributed in the hope that it will be useful,
235 # but WITHOUT ANY WARRANTY; without even the implied warranty of
236 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
237 # GNU General Public License for more details.
239 # You should have received a copy of the GNU General Public License
240 # along with this program; if not, see <http://www.gnu.org/licenses/>.
242 # The latest version of this software can be obtained here:
244 # http://bash-completion.alioth.debian.org/
248 # This function can be used to access a tokenized list of words
249 # on the command line:
251 # __git_reassemble_comp_words_by_ref '=:'
252 # if test "${words_[cword_-1]}" = -w
257 # The argument should be a collection of characters from the list of
258 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
261 # This is roughly equivalent to going back in time and setting
262 # COMP_WORDBREAKS to exclude those characters. The intent is to
263 # make option types like --date=<type> and <rev>:<path> easy to
264 # recognize by treating each shell word as a single token.
266 # It is best not to set COMP_WORDBREAKS directly because the value is
267 # shared with other completion scripts. By the time the completion
268 # function gets called, COMP_WORDS has already been populated so local
269 # changes to COMP_WORDBREAKS have no effect.
271 # Output: words_, cword_, cur_.
273 __git_reassemble_comp_words_by_ref()
275 local exclude i j first
276 # Which word separators to exclude?
277 exclude="${1//[^$COMP_WORDBREAKS]}"
279 if [ -z "$exclude" ]; then
280 words_=("${COMP_WORDS[@]}")
283 # List of word completion separators has shrunk;
284 # re-assemble words to complete.
285 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
286 # Append each nonempty word consisting of just
287 # word separator characters to the current word.
291 [ -n "${COMP_WORDS[$i]}" ] &&
292 # word consists of excluded word separators
293 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
295 # Attach to the previous token,
296 # unless the previous token is the command name.
297 if [ $j -ge 2 ] && [ -n "$first" ]; then
301 words_[$j]=${words_[j]}${COMP_WORDS[i]}
302 if [ $i = $COMP_CWORD ]; then
305 if (($i < ${#COMP_WORDS[@]} - 1)); then
312 words_[$j]=${words_[j]}${COMP_WORDS[i]}
313 if [ $i = $COMP_CWORD ]; then
319 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
320 _get_comp_words_by_ref ()
322 local exclude cur_ words_ cword_
323 if [ "$1" = "-n" ]; then
327 __git_reassemble_comp_words_by_ref "$exclude"
328 cur_=${words_[cword_]}
329 while [ $# -gt 0 ]; do
335 prev=${words_[$cword_-1]}
338 words=("${words_[@]}")
349 # Fills the COMPREPLY array with prefiltered words without any additional
351 # Callers must take care of providing only words that match the current word
352 # to be completed and adding any prefix and/or suffix (trailing space!), if
354 # 1: List of newline-separated matching completion words, complete with
363 # Similar to __gitcomp_direct, but appends to COMPREPLY instead.
364 # Callers must take care of providing only words that match the current word
365 # to be completed and adding any prefix and/or suffix (trailing space!), if
367 # 1: List of newline-separated matching completion words, complete with
369 __gitcomp_direct_append ()
378 local x i=${#COMPREPLY[@]}
380 if [[ "$x" == "$3"* ]]; then
381 COMPREPLY[i++]="$2$x$4"
392 # Generates completion reply, appending a space to possible completion words,
394 # It accepts 1 to 4 arguments:
395 # 1: List of possible completion words.
396 # 2: A prefix to be added to each possible completion word (optional).
397 # 3: Generate possible completion matches for this word (optional).
398 # 4: A suffix to be appended to each possible completion word (optional).
401 local cur_="${3-$cur}"
407 local c i=0 IFS=$' \t\n'
409 if [[ $c == "--" ]]; then
413 if [[ $c == "$cur_"* ]]; then
418 COMPREPLY[i++]="${2-}$c"
423 local c i=0 IFS=$' \t\n'
425 if [[ $c == "--" ]]; then
427 if [[ $c == "$cur_"* ]]; then
428 COMPREPLY[i++]="${2-}$c "
433 if [[ $c == "$cur_"* ]]; then
438 COMPREPLY[i++]="${2-}$c"
445 # Clear the variables caching builtins' options when (re-)sourcing
446 # the completion script.
447 if [[ -n ${ZSH_VERSION-} ]]; then
448 unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
450 unset $(compgen -v __gitcomp_builtin_)
453 # This function is equivalent to
455 # __gitcomp "$(git xxx --git-completion-helper) ..."
457 # except that the output is cached. Accept 1-3 arguments:
458 # 1: the git command to execute, this is also the cache key
459 # 2: extra options to be added on top (e.g. negative forms)
460 # 3: options to be excluded
463 # spaces must be replaced with underscore for multi-word
464 # commands, e.g. "git remote add" becomes remote_add.
469 local var=__gitcomp_builtin_"${cmd//-/_}"
471 eval "options=\${$var-}"
473 if [ -z "$options" ]; then
474 local completion_helper
475 if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
476 completion_helper="--git-completion-helper-all"
478 completion_helper="--git-completion-helper"
480 # leading and trailing spaces are significant to make
481 # option removal work correctly.
482 options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
485 options="${options/ $i / }"
487 eval "$var=\"$options\""
493 # Variation of __gitcomp_nl () that appends to the existing list of
494 # completion candidates, COMPREPLY.
495 __gitcomp_nl_append ()
498 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
501 # Generates completion reply from newline-separated possible completion words
502 # by appending a space to all of them.
503 # It accepts 1 to 4 arguments:
504 # 1: List of possible completion words, separated by a single newline.
505 # 2: A prefix to be added to each possible completion word (optional).
506 # 3: Generate possible completion matches for this word (optional).
507 # 4: A suffix to be appended to each possible completion word instead of
508 # the default space (optional). If specified but empty, nothing is
513 __gitcomp_nl_append "$@"
516 # Fills the COMPREPLY array with prefiltered paths without any additional
518 # Callers must take care of providing only paths that match the current path
519 # to be completed and adding any prefix path components, if necessary.
520 # 1: List of newline-separated matching paths, complete with all prefix
522 __gitcomp_file_direct ()
528 # use a hack to enable file mode in bash < 4
529 compopt -o filenames +o nospace 2>/dev/null ||
530 compgen -f /non-existing-dir/ >/dev/null ||
534 # Generates completion reply with compgen from newline-separated possible
535 # completion filenames.
536 # It accepts 1 to 3 arguments:
537 # 1: List of possible completion filenames, separated by a single newline.
538 # 2: A directory prefix to be added to each possible completion filename
540 # 3: Generate possible completion matches for this word (optional).
545 # XXX does not work when the directory prefix contains a tilde,
546 # since tilde expansion is not applied.
547 # This means that COMPREPLY will be empty and Bash default
548 # completion will be used.
549 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
551 # use a hack to enable file mode in bash < 4
552 compopt -o filenames +o nospace 2>/dev/null ||
553 compgen -f /non-existing-dir/ >/dev/null ||
557 # Execute 'git ls-files', unless the --committable option is specified, in
558 # which case it runs 'git diff-index' to find out the files that can be
559 # committed. It return paths relative to the directory specified in the first
560 # argument, and using the options specified in the second argument.
561 __git_ls_files_helper ()
563 if [ "$2" = "--committable" ]; then
564 __git -C "$1" -c core.quotePath=false diff-index \
565 --name-only --relative HEAD -- "${3//\\/\\\\}*"
567 # NOTE: $2 is not quoted in order to support multiple options
568 __git -C "$1" -c core.quotePath=false ls-files \
569 --exclude-standard $2 -- "${3//\\/\\\\}*"
574 # __git_index_files accepts 1 or 2 arguments:
575 # 1: Options to pass to ls-files (required).
576 # 2: A directory path (optional).
577 # If provided, only files within the specified directory are listed.
578 # Sub directories are never recursed. Path must have a trailing
580 # 3: List only paths matching this path component (optional).
583 local root="$2" match="$3"
585 __git_ls_files_helper "$root" "$1" "${match:-?}" |
586 awk -F / -v pfx="${2//\\/\\\\}" '{
591 if (substr(p, 1, 1) != "\"") {
592 # No special characters, easy!
597 # The path is quoted.
602 # Even when a directory name itself does not contain
603 # any special characters, it will still be quoted if
604 # any of its (stripped) trailing path components do.
605 # Because of this we may have seen the same directory
606 # both quoted and unquoted.
608 # We have seen the same directory unquoted,
615 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
616 # Skip opening double quote.
619 # Interpret backslash escape sequences.
620 while ((bs_idx = index(p, "\\")) != 0) {
621 out = out substr(p, 1, bs_idx - 1)
622 esc = substr(p, bs_idx + 1, 1)
623 p = substr(p, bs_idx + 2)
625 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
626 # C-style one-character escape sequence.
627 out = out substr("\a\b\t\v\f\r\"\\",
629 } else if (esc == "n") {
630 # Uh-oh, a newline character.
631 # We cannot reliably put a pathname
632 # containing a newline into COMPREPLY,
633 # and the newline would create a mess.
637 # Must be a \nnn octal value, then.
639 substr(p, 1, 1) * 8 + \
641 out = out sprintf("%c", dec)
645 # Drop closing double quote, if there is one.
646 # (There is not any if this is a directory, as it was
647 # already stripped with the trailing path components.)
648 if (substr(p, length(p), 1) == "\"")
649 out = out substr(p, 1, length(p) - 1)
657 # __git_complete_index_file requires 1 argument:
658 # 1: the options to pass to ls-file
660 # The exception is --committable, which finds the files appropriate commit.
661 __git_complete_index_file ()
663 local dequoted_word pfx="" cur_
667 case "$dequoted_word" in
669 pfx="${dequoted_word%/*}/"
670 cur_="${dequoted_word##*/}"
673 cur_="$dequoted_word"
676 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
679 # Lists branches from the local repository.
680 # 1: A prefix to be added to each listed branch (optional).
681 # 2: List only branches matching this word (optional; list all branches if
683 # 3: A suffix to be appended to each listed branch (optional).
686 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
688 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
689 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
690 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
693 # Lists branches from remote repositories.
694 # 1: A prefix to be added to each listed branch (optional).
695 # 2: List only branches matching this word (optional; list all branches if
697 # 3: A suffix to be appended to each listed branch (optional).
698 __git_remote_heads ()
700 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
702 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
703 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
704 "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
707 # Lists tags from the local repository.
708 # Accepts the same positional parameters as __git_heads() above.
711 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
713 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
714 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
715 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
718 # List unique branches from refs/remotes used for 'git checkout' and 'git
719 # switch' tracking DWIMery.
720 # 1: A prefix to be added to each listed branch (optional)
721 # 2: List only branches matching this word (optional; list all branches if
723 # 3: A suffix to be appended to each listed branch (optional).
724 __git_dwim_remote_heads ()
726 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
727 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
729 # employ the heuristic used by git checkout and git switch
730 # Try to find a remote branch that cur_es the completion word
731 # but only output if the branch name is unique
732 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
733 --sort="refname:strip=3" \
734 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
735 "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
739 # Lists refs from the local (by default) or from a remote repository.
740 # It accepts 0, 1 or 2 arguments:
741 # 1: The remote to list refs from (optional; ignored, if set but empty).
742 # Can be the name of a configured remote, a path, or a URL.
743 # 2: In addition to local refs, list unique branches from refs/remotes/ for
744 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
745 # 3: A prefix to be added to each listed ref (optional).
746 # 4: List only refs matching this word (optional; list all refs if unset or
748 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
751 # Use __git_complete_refs() instead.
754 local i hash dir track="${2-}"
755 local list_refs_from=path remote="${1-}"
757 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
760 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
763 dir="$__git_repo_path"
765 if [ -z "$remote" ]; then
766 if [ -z "$dir" ]; then
770 if __git_is_configured_remote "$remote"; then
771 # configured remote takes precedence over a
772 # local directory with the same name
773 list_refs_from=remote
774 elif [ -d "$remote/.git" ]; then
776 elif [ -d "$remote" ]; then
783 if test "${GIT_COMPLETION_IGNORE_CASE:+1}" = "1"
785 # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility
786 umatch=$(echo "$match" | tr a-z A-Z 2>/dev/null || echo "$match")
789 if [ "$list_refs_from" = path ]; then
790 if [[ "$cur_" == ^* ]]; then
800 refs=("$match*" "$match*/**")
804 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD AUTO_MERGE; do
807 if [ -e "$dir/$i" ]; then
813 format="refname:strip=2"
814 refs=("refs/tags/$match*" "refs/tags/$match*/**"
815 "refs/heads/$match*" "refs/heads/$match*/**"
816 "refs/remotes/$match*" "refs/remotes/$match*/**")
819 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
820 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
822 if [ -n "$track" ]; then
823 __git_dwim_remote_heads "$pfx" "$match" "$sfx"
829 __git ls-remote "$remote" "$match*" | \
830 while read -r hash i; do
833 *) echo "$pfx$i$sfx" ;;
838 if [ "$list_refs_from" = remote ]; then
840 $match*|$umatch*) echo "${pfx}HEAD$sfx" ;;
842 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
843 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
844 "refs/remotes/$remote/$match*" \
845 "refs/remotes/$remote/$match*/**"
849 $match*|$umatch*) query_symref="HEAD" ;;
851 __git ls-remote "$remote" $query_symref \
852 "refs/tags/$match*" "refs/heads/$match*" \
853 "refs/remotes/$match*" |
854 while read -r hash i; do
857 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
858 *) echo "$pfx$i$sfx" ;; # symbolic refs
866 # Completes refs, short and long, local and remote, symbolic and pseudo.
868 # Usage: __git_complete_refs [<option>]...
869 # --remote=<remote>: The remote to list refs from, can be the name of a
870 # configured remote, a path, or a URL.
871 # --dwim: List unique remote branches for 'git switch's tracking DWIMery.
872 # --pfx=<prefix>: A prefix to be added to each ref.
873 # --cur=<word>: The current ref to be completed. Defaults to the current
874 # word to be completed.
875 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
877 # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
878 # complete all refs, 'heads' to complete only branches, or
879 # 'remote-heads' to complete only remote branches. Note that
880 # --remote is only compatible with --mode=refs.
881 __git_complete_refs ()
883 local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
885 while test $# != 0; do
887 --remote=*) remote="${1##--remote=}" ;;
888 --dwim) dwim="yes" ;;
889 # --track is an old spelling of --dwim
890 --track) dwim="yes" ;;
891 --pfx=*) pfx="${1##--pfx=}" ;;
892 --cur=*) cur_="${1##--cur=}" ;;
893 --sfx=*) sfx="${1##--sfx=}" ;;
894 --mode=*) mode="${1##--mode=}" ;;
900 # complete references based on the specified mode
903 __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
905 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
907 __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
912 # Append DWIM remote branch names if requested
913 if [ "$dwim" = "yes" ]; then
914 __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
918 # __git_refs2 requires 1 argument (to pass to __git_refs)
919 # Deprecated: use __git_complete_fetch_refspecs() instead.
923 for i in $(__git_refs "$1"); do
928 # Completes refspecs for fetching from a remote repository.
929 # 1: The remote repository.
930 # 2: A prefix to be added to each listed refspec (optional).
931 # 3: The ref to be completed as a refspec instead of the current word to be
932 # completed (optional)
933 # 4: A suffix to be appended to each listed refspec instead of the default
935 __git_complete_fetch_refspecs ()
937 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
940 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
946 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
947 __git_refs_remotes ()
950 __git ls-remote "$1" 'refs/heads/*' | \
951 while read -r hash i; do
952 echo "$i:refs/remotes/$1/${i#refs/heads/}"
959 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
963 # Returns true if $1 matches the name of a configured remote, false otherwise.
964 __git_is_configured_remote ()
967 for remote in $(__git_remotes); do
968 if [ "$remote" = "$1" ]; then
975 __git_list_merge_strategies ()
977 LANG=C LC_ALL=C git merge -s help 2>&1 |
978 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
987 __git_merge_strategies=
988 # 'git merge -s help' (and thus detection of the merge strategy
989 # list) fails, unfortunately, if run outside of any git working
990 # tree. __git_merge_strategies is set to the empty string in
991 # that case, and the detection will be repeated the next time it
993 __git_compute_merge_strategies ()
995 test -n "$__git_merge_strategies" ||
996 __git_merge_strategies=$(__git_list_merge_strategies)
999 __git_merge_strategy_options="ours theirs subtree subtree= patience
1000 histogram diff-algorithm= ignore-space-change ignore-all-space
1001 ignore-space-at-eol renormalize no-renormalize no-renames
1002 find-renames find-renames= rename-threshold="
1004 __git_complete_revlist_file ()
1006 local dequoted_word pfx ls ref cur_="$cur"
1015 __git_dequote "$cur_"
1017 case "$dequoted_word" in
1019 pfx="${dequoted_word%/*}"
1020 cur_="${dequoted_word##*/}"
1025 cur_="$dequoted_word"
1030 case "$COMP_WORDBREAKS" in
1032 *) pfx="$ref:$pfx" ;;
1035 __gitcomp_file "$(__git ls-tree "$ls" \
1041 pfx="${cur_%...*}..."
1043 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1048 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1056 __git_complete_file ()
1058 __git_complete_revlist_file
1061 __git_complete_revlist ()
1063 __git_complete_revlist_file
1066 __git_complete_remote_or_refspec ()
1068 local cur_="$cur" cmd="${words[__git_cmd_idx]}"
1069 local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
1070 if [ "$cmd" = "remote" ]; then
1073 while [ $c -lt $cword ]; do
1076 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
1077 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
1080 push) no_complete_refspec=1 ;;
1087 --multiple) no_complete_refspec=1; break ;;
1089 *) remote="$i"; break ;;
1093 if [ -z "$remote" ]; then
1094 __gitcomp_nl "$(__git_remotes)"
1097 if [ $no_complete_refspec = 1 ]; then
1100 [ "$remote" = "." ] && remote=
1103 case "$COMP_WORDBREAKS" in
1105 *) pfx="${cur_%%:*}:" ;;
1117 if [ $lhs = 1 ]; then
1118 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
1120 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1124 if [ $lhs = 1 ]; then
1125 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1127 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1131 if [ $lhs = 1 ]; then
1132 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1134 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1140 __git_complete_strategy ()
1142 __git_compute_merge_strategies
1145 __gitcomp "$__git_merge_strategies"
1149 __gitcomp "$__git_merge_strategy_options"
1155 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1158 --strategy-option=*)
1159 __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1167 __git_compute_all_commands ()
1169 test -n "$__git_all_commands" ||
1170 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1173 # Lists all set config variables starting with the given section prefix,
1174 # with the prefix removed.
1175 __git_get_config_variables ()
1177 local section="$1" i IFS=$'\n'
1178 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1179 echo "${i#$section.}"
1183 __git_pretty_aliases ()
1185 __git_get_config_variables "pretty"
1188 # __git_aliased_command requires 1 argument
1189 __git_aliased_command ()
1191 local cur=$1 last list= word cmdline
1193 while [[ -n "$cur" ]]; do
1194 if [[ "$list" == *" $cur "* ]]; then
1199 cmdline=$(__git config --get "alias.$cur")
1204 for word in $cmdline; do
1210 \!*) : shell command alias ;;
1212 *=*) : setting env ;;
1213 git) : git itself ;;
1214 \(\)) : skip parens of shell function definition ;;
1215 {) : skip start of shell helper function ;;
1216 :) : skip null command ;;
1217 \'*) : skip opening quote after sh -c ;;
1226 if [[ "$cur" != "$1" ]]; then
1231 # Check whether one of the given words is present on the command line,
1232 # and print the first word found.
1234 # Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
1235 # --show-idx: Optionally show the index of the found word in the $words array.
1236 __git_find_on_cmdline ()
1238 local word c="$__git_cmd_idx" show_idx
1240 while test $# -gt 1; do
1242 --show-idx) show_idx=y ;;
1249 while [ $c -lt $cword ]; do
1250 for word in $wordlist; do
1251 if [ "$word" = "${words[c]}" ]; then
1252 if [ -n "${show_idx-}" ]; then
1264 # Similar to __git_find_on_cmdline, except that it loops backwards and thus
1265 # prints the *last* word found. Useful for finding which of two options that
1266 # supersede each other came last, such as "--guess" and "--no-guess".
1268 # Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
1269 # --show-idx: Optionally show the index of the found word in the $words array.
1270 __git_find_last_on_cmdline ()
1272 local word c=$cword show_idx
1274 while test $# -gt 1; do
1276 --show-idx) show_idx=y ;;
1283 while [ $c -gt "$__git_cmd_idx" ]; do
1285 for word in $wordlist; do
1286 if [ "$word" = "${words[c]}" ]; then
1287 if [ -n "$show_idx" ]; then
1298 # Echo the value of an option set on the command line or config
1300 # $1: short option name
1301 # $2: long option name including =
1302 # $3: list of possible values
1303 # $4: config string (optional)
1306 # result="$(__git_get_option_value "-d" "--do-something=" \
1307 # "yes no" "core.doSomething")"
1309 # result is then either empty (no option set) or "yes" or "no"
1311 # __git_get_option_value requires 3 arguments
1312 __git_get_option_value ()
1314 local c short_opt long_opt val
1315 local result= values config_key word
1323 while [ $c -ge 0 ]; do
1325 for val in $values; do
1326 if [ "$short_opt$val" = "$word" ] ||
1327 [ "$long_opt$val" = "$word" ]; then
1335 if [ -n "$config_key" ] && [ -z "$result" ]; then
1336 result="$(__git config "$config_key")"
1342 __git_has_doubledash ()
1345 while [ $c -lt $cword ]; do
1346 if [ "--" = "${words[c]}" ]; then
1354 # Try to count non option arguments passed on the command line for the
1355 # specified git command.
1356 # When options are used, it is necessary to use the special -- option to
1357 # tell the implementation were non option arguments begin.
1358 # XXX this can not be improved, since options can appear everywhere, as
1362 # __git_count_arguments requires 1 argument: the git command executed.
1363 __git_count_arguments ()
1367 # Skip "git" (first argument)
1368 for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
1373 # Good; we can assume that the following are only non
1378 # Skip the specified git command and discard git
1391 __git_whitespacelist="nowarn warn error error-all fix"
1392 __git_patchformat="mbox stgit stgit-series hg mboxrd"
1393 __git_showcurrentpatch="diff raw"
1394 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1395 __git_quoted_cr="nowarn warn strip"
1399 __git_find_repo_path
1400 if [ -d "$__git_repo_path"/rebase-apply ]; then
1401 __gitcomp "$__git_am_inprogress_options"
1406 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1410 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1413 --show-current-patch=*)
1414 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
1418 __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}"
1422 __gitcomp_builtin am "" \
1423 "$__git_am_inprogress_options"
1432 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1436 __gitcomp_builtin apply
1445 __gitcomp "+x -x" "" "${cur##--chmod=}"
1449 __gitcomp_builtin add
1453 local complete_opt="--others --modified --directory --no-empty-directory"
1454 if test -n "$(__git_find_on_cmdline "-u --update")"
1456 complete_opt="--modified"
1458 __git_complete_index_file "$complete_opt"
1465 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1469 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1473 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
1482 __git_has_doubledash && return
1484 local subcommands="start bad good skip reset visualize replay log run"
1485 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1486 if [ -z "$subcommand" ]; then
1487 __git_find_repo_path
1488 if [ -f "$__git_repo_path"/BISECT_START ]; then
1489 __gitcomp "$subcommands"
1491 __gitcomp "replay start"
1496 case "$subcommand" in
1497 bad|good|reset|skip|start)
1505 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1509 local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
1511 while [ $c -lt $cword ]; do
1514 -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
1515 only_local_ref="y" ;;
1523 --set-upstream-to=*)
1524 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1527 __gitcomp_builtin branch
1530 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1531 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1541 local cmd="${words[__git_cmd_idx+1]}"
1543 $((__git_cmd_idx+1)))
1544 __gitcomp "create list-heads verify unbundle"
1546 $((__git_cmd_idx+2)))
1547 # looking for a file
1552 __git_complete_revlist
1559 # Helper function to decide whether or not we should enable DWIM logic for
1560 # git-switch and git-checkout.
1562 # To decide between the following rules in decreasing priority order:
1563 # - the last provided of "--guess" or "--no-guess" explicitly enable or
1564 # disable completion of DWIM logic respectively.
1565 # - If checkout.guess is false, disable completion of DWIM logic.
1566 # - If the --no-track option is provided, take this as a hint to disable the
1567 # DWIM completion logic
1568 # - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
1569 # logic, as requested by the user.
1570 # - Enable DWIM logic otherwise.
1572 __git_checkout_default_dwim_mode ()
1574 local last_option dwim_opt="--dwim"
1576 if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1580 # --no-track disables DWIM, but with lower priority than
1581 # --guess/--no-guess/checkout.guess
1582 if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
1586 # checkout.guess = false disables DWIM, but with lower priority than
1587 # --guess/--no-guess
1588 if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
1592 # Find the last provided --guess or --no-guess
1593 last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
1594 case "$last_option" in
1608 __git_has_doubledash && return
1610 local dwim_opt="$(__git_checkout_default_dwim_mode)"
1614 # Complete local branches (and DWIM branch
1615 # remote branch names) for an option argument
1616 # specifying a new branch name. This is for
1617 # convenience, assuming new branches are
1618 # possibly based on pre-existing branch names.
1619 __git_complete_refs $dwim_opt --mode="heads"
1628 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
1631 __gitcomp_builtin checkout
1634 # At this point, we've already handled special completion for
1635 # the arguments to -b/-B, and --orphan. There are 3 main
1636 # things left we can possibly complete:
1637 # 1) a start-point for -b/-B, -d/--detach, or --orphan
1638 # 2) a remote head, for --track
1639 # 3) an arbitrary reference, possibly including DWIM names
1642 if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
1643 __git_complete_refs --mode="refs"
1644 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
1645 __git_complete_refs --mode="remote-heads"
1647 __git_complete_refs $dwim_opt --mode="refs"
1653 __git_sequencer_inprogress_options="--continue --quit --abort --skip"
1655 __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1659 __git_find_repo_path
1660 if __git_pseudoref_exists CHERRY_PICK_HEAD; then
1661 __gitcomp "$__git_cherry_pick_inprogress_options"
1665 __git_complete_strategy && return
1669 __gitcomp_builtin cherry-pick "" \
1670 "$__git_cherry_pick_inprogress_options"
1682 __gitcomp_builtin clean
1687 # XXX should we check for -x option ?
1688 __git_complete_index_file "--others --directory"
1695 __git_complete_config_variable_name_and_value
1701 __git_complete_config_variable_name_and_value \
1702 --cur="${cur##--config=}"
1706 __gitcomp_builtin clone
1712 __git_untracked_file_modes="all no normal"
1714 __git_trailer_tokens ()
1716 __git config --name-only --get-regexp '^trailer\..*\.key$' | cut -d. -f 2- | rev | cut -d. -f2- | rev
1730 __gitcomp "default scissors strip verbatim whitespace
1731 " "" "${cur##--cleanup=}"
1734 --reuse-message=*|--reedit-message=*|\
1735 --fixup=*|--squash=*)
1736 __git_complete_refs --cur="${cur#*=}"
1739 --untracked-files=*)
1740 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1744 __gitcomp_nl "$(__git_trailer_tokens)" "" "${cur##--trailer=}" ":"
1748 __gitcomp_builtin commit
1752 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1753 __git_complete_index_file "--committable"
1755 # This is the first commit
1756 __git_complete_index_file "--cached"
1764 __gitcomp_builtin describe
1770 __git_diff_algorithms="myers minimal patience histogram"
1772 __git_diff_submodule_formats="diff log short"
1774 __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
1776 __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
1777 ignore-all-space allow-indentation-change"
1779 __git_ws_error_highlight_opts="context old new all default"
1781 # Options for the diff machinery (diff, log, show, stash, range-diff, ...)
1782 __git_diff_common_options="--stat --numstat --shortstat --summary
1783 --patch-with-stat --name-only --name-status --color
1784 --no-color --color-words --no-renames --check
1785 --color-moved --color-moved= --no-color-moved
1786 --color-moved-ws= --no-color-moved-ws
1787 --full-index --binary --abbrev --diff-filter=
1788 --find-copies --find-object --find-renames
1789 --no-relative --relative
1790 --find-copies-harder --ignore-cr-at-eol
1791 --text --ignore-space-at-eol --ignore-space-change
1792 --ignore-all-space --ignore-blank-lines --exit-code
1793 --quiet --ext-diff --no-ext-diff --unified=
1794 --no-prefix --src-prefix= --dst-prefix=
1795 --inter-hunk-context= --function-context
1796 --patience --histogram --minimal
1797 --raw --word-diff --word-diff-regex=
1798 --dirstat --dirstat= --dirstat-by-file
1799 --dirstat-by-file= --cumulative
1800 --diff-algorithm= --default-prefix
1801 --submodule --submodule= --ignore-submodules
1802 --indent-heuristic --no-indent-heuristic
1803 --textconv --no-textconv --break-rewrites
1804 --patch --no-patch --cc --combined-all-paths
1805 --anchored= --compact-summary --ignore-matching-lines=
1806 --irreversible-delete --line-prefix --no-stat
1807 --output= --output-indicator-context=
1808 --output-indicator-new= --output-indicator-old=
1809 --ws-error-highlight=
1810 --pickaxe-all --pickaxe-regex
1813 # Options for diff/difftool
1814 __git_diff_difftool_options="--cached --staged
1815 --base --ours --theirs --no-index --merge-base
1816 --ita-invisible-in-index --ita-visible-in-index
1817 $__git_diff_common_options"
1821 __git_has_doubledash && return
1825 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1829 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1833 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
1837 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
1840 --ws-error-highlight=*)
1841 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
1845 __gitcomp "$__git_diff_difftool_options"
1849 __git_complete_revlist_file
1852 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1853 tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1854 bc codecompare smerge
1859 __git_has_doubledash && return
1863 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1867 __gitcomp_builtin difftool "$__git_diff_difftool_options"
1871 __git_complete_revlist_file
1874 __git_fetch_recurse_submodules="yes on-demand no"
1879 --recurse-submodules=*)
1880 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1884 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1888 __gitcomp_builtin fetch
1892 __git_complete_remote_or_refspec
1895 __git_format_patch_extra_options="
1896 --full-index --not --all --no-prefix --src-prefix=
1897 --dst-prefix= --notes
1900 _git_format_patch ()
1906 " "" "${cur##--thread=}"
1909 --base=*|--interdiff=*|--range-diff=*)
1910 __git_complete_refs --cur="${cur#--*=}"
1914 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1918 __git_complete_revlist
1925 __gitcomp_builtin fsck
1936 # Lists matching symbol names from a tag (as in ctags) file.
1937 # 1: List symbol names matching this word.
1938 # 2: The tag file to list symbol names from.
1939 # 3: A prefix to be added to each listed symbol name (optional).
1940 # 4: A suffix to be appended to each listed symbol name (optional).
1941 __git_match_ctag () {
1942 awk -v pfx="${3-}" -v sfx="${4-}" "
1943 /^${1//\//\\/}/ { print pfx \$1 sfx }
1947 # Complete symbol names from a tag file.
1948 # Usage: __git_complete_symbol [<option>]...
1949 # --tags=<file>: The tag file to list symbol names from instead of the
1951 # --pfx=<prefix>: A prefix to be added to each symbol name.
1952 # --cur=<word>: The current symbol name to be completed. Defaults to
1953 # the current word to be completed.
1954 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1955 # of the default space.
1956 __git_complete_symbol () {
1957 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1959 while test $# != 0; do
1961 --tags=*) tags="${1##--tags=}" ;;
1962 --pfx=*) pfx="${1##--pfx=}" ;;
1963 --cur=*) cur_="${1##--cur=}" ;;
1964 --sfx=*) sfx="${1##--sfx=}" ;;
1970 if test -r "$tags"; then
1971 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1977 __git_has_doubledash && return
1981 __gitcomp_builtin grep
1986 case "$cword,$prev" in
1987 $((__git_cmd_idx+1)),*|*,-*)
1988 __git_complete_symbol && return
1999 __gitcomp_builtin help
2003 if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
2005 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
2007 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
2016 false true umask group all world everybody
2017 " "" "${cur##--shared=}"
2021 __gitcomp_builtin init
2031 __gitcomp_builtin ls-files
2036 # XXX ignore options like --modified and always suggest all cached
2038 __git_complete_index_file "--cached"
2045 __gitcomp_builtin ls-remote
2049 __gitcomp_nl "$(__git_remotes)"
2056 __gitcomp_builtin ls-tree
2064 # Options that go well for log, shortlog and gitk
2065 __git_log_common_options="
2067 --branches --tags --remotes
2068 --first-parent --merges --no-merges
2070 --max-age= --since= --after=
2071 --min-age= --until= --before=
2072 --min-parents= --max-parents=
2073 --no-min-parents --no-max-parents
2075 # Options that go well for log and gitk (not shortlog)
2076 __git_log_gitk_options="
2077 --dense --sparse --full-history
2078 --simplify-merges --simplify-by-decoration
2079 --left-right --notes --no-notes
2081 # Options that go well for log and shortlog (not gitk)
2082 __git_log_shortlog_options="
2083 --author= --committer= --grep=
2084 --all-match --invert-grep
2086 # Options accepted by log and show
2087 __git_log_show_options="
2088 --diff-merges --diff-merges= --no-diff-merges --dd --remerge-diff
2091 __git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-combined cc remerge r"
2093 __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
2094 __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
2098 __git_has_doubledash && return
2099 __git_find_repo_path
2102 if __git_pseudoref_exists MERGE_HEAD; then
2105 case "$prev,$cur" in
2107 return # fall back to Bash filename completion
2110 __git_complete_symbol --cur="${cur#:}" --sfx=":"
2114 __git_complete_symbol
2119 --pretty=*|--format=*)
2120 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2125 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
2129 __gitcomp "full short no" "" "${cur##--decorate=}"
2133 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2137 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2140 --ws-error-highlight=*)
2141 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
2145 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
2149 __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
2154 $__git_log_common_options
2155 $__git_log_shortlog_options
2156 $__git_log_gitk_options
2157 $__git_log_show_options
2158 --root --topo-order --date-order --reverse
2159 --follow --full-diff
2160 --abbrev-commit --no-abbrev-commit --abbrev=
2161 --relative-date --date=
2162 --pretty= --format= --oneline
2167 --decorate --decorate= --no-decorate
2169 --no-walk --no-walk= --do-walk
2170 --parents --children
2171 --expand-tabs --expand-tabs= --no-expand-tabs
2173 $__git_diff_common_options
2178 return # fall back to Bash filename completion
2181 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
2185 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
2189 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
2193 __git_complete_revlist
2198 __git_complete_strategy && return
2202 __gitcomp_builtin merge
2212 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
2216 __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
2226 __gitcomp_builtin merge-base
2237 __gitcomp_builtin mv
2242 if [ $(__git_count_arguments "mv") -gt 0 ]; then
2243 # We need to show both cached and untracked files (including
2244 # empty directories) since this may not be the last argument.
2245 __git_complete_index_file "--cached --others --directory"
2247 __git_complete_index_file "--cached"
2253 local subcommands='add append copy edit get-ref list merge prune remove show'
2254 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2256 case "$subcommand,$cur" in
2258 __gitcomp_builtin notes
2266 __gitcomp "$subcommands --ref"
2270 *,--reuse-message=*|*,--reedit-message=*)
2271 __git_complete_refs --cur="${cur#*=}"
2274 __gitcomp_builtin notes_$subcommand
2277 # this command does not take a ref, do not complete it
2293 __git_complete_strategy && return
2296 --recurse-submodules=*)
2297 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
2301 __gitcomp_builtin pull
2306 __git_complete_remote_or_refspec
2309 __git_push_recurse_submodules="check on-demand only"
2311 __git_complete_force_with_lease ()
2319 __git_complete_refs --cur="${cur_#*:}"
2322 __git_complete_refs --cur="$cur_"
2331 __gitcomp_nl "$(__git_remotes)"
2334 --recurse-submodules)
2335 __gitcomp "$__git_push_recurse_submodules"
2341 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
2344 --recurse-submodules=*)
2345 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
2348 --force-with-lease=*)
2349 __git_complete_force_with_lease "${cur##--force-with-lease=}"
2353 __gitcomp_builtin push
2357 __git_complete_remote_or_refspec
2365 --creation-factor= --no-dual-color
2366 $__git_diff_common_options
2371 __git_complete_revlist
2374 __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
2375 __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
2379 __git_find_repo_path
2380 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2381 __gitcomp "$__git_rebase_interactive_inprogress_options"
2383 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2384 [ -d "$__git_repo_path"/rebase-merge ]; then
2385 __gitcomp "$__git_rebase_inprogress_options"
2388 __git_complete_strategy && return
2391 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2395 __git_complete_refs --cur="${cur##--onto=}"
2399 __gitcomp_builtin rebase "" \
2400 "$__git_rebase_interactive_inprogress_options"
2409 local subcommands="show delete expire"
2410 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2412 if [ -z "$subcommand" ]; then
2413 __gitcomp "$subcommands"
2419 __git_send_email_confirm_options="always never auto cc compose"
2420 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2425 --to|--cc|--bcc|--from)
2426 __gitcomp "$(__git send-email --dump-aliases)"
2434 $__git_send_email_confirm_options
2435 " "" "${cur##--confirm=}"
2440 $__git_send_email_suppresscc_options
2441 " "" "${cur##--suppress-cc=}"
2445 --smtp-encryption=*)
2446 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2452 " "" "${cur##--thread=}"
2455 --to=*|--cc=*|--bcc=*|--from=*)
2456 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2460 __gitcomp_builtin send-email "$__git_format_patch_extra_options"
2464 __git_complete_revlist
2475 local untracked_state
2478 --ignore-submodules=*)
2479 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2482 --untracked-files=*)
2483 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2488 always never auto column row plain dense nodense
2489 " "" "${cur##--column=}"
2493 __gitcomp_builtin status
2498 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2499 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2501 case "$untracked_state" in
2503 # --ignored option does not matter
2507 complete_opt="--cached --directory --no-empty-directory --others"
2509 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2510 complete_opt="$complete_opt --ignored --exclude=*"
2515 __git_complete_index_file "$complete_opt"
2520 local dwim_opt="$(__git_checkout_default_dwim_mode)"
2524 # Complete local branches (and DWIM branch
2525 # remote branch names) for an option argument
2526 # specifying a new branch name. This is for
2527 # convenience, assuming new branches are
2528 # possibly based on pre-existing branch names.
2529 __git_complete_refs $dwim_opt --mode="heads"
2538 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2541 __gitcomp_builtin switch
2544 # Unlike in git checkout, git switch --orphan does not take
2545 # a start point. Thus we really have nothing to complete after
2547 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
2551 # At this point, we've already handled special completion for
2552 # -c/-C, and --orphan. There are 3 main things left to
2554 # 1) a start-point for -c/-C or -d/--detach
2555 # 2) a remote head, for --track
2556 # 3) a branch name, possibly including DWIM remote branches
2558 if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
2559 __git_complete_refs --mode="refs"
2560 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
2561 __git_complete_refs --mode="remote-heads"
2563 __git_complete_refs $dwim_opt --mode="heads"
2569 __git_config_get_set_variables ()
2571 local prevword word config_file= c=$cword
2572 while [ $c -gt "$__git_cmd_idx" ]; do
2575 --system|--global|--local|--file=*)
2580 config_file="$word $prevword"
2588 __git config $config_file --name-only --list
2592 __git_compute_config_vars ()
2594 test -n "$__git_config_vars" ||
2595 __git_config_vars="$(git help --config-for-completion)"
2598 __git_config_sections=
2599 __git_compute_config_sections ()
2601 test -n "$__git_config_sections" ||
2602 __git_config_sections="$(git help --config-sections-for-completion)"
2605 # Completes possible values of various configuration variables.
2607 # Usage: __git_complete_config_variable_value [<option>]...
2608 # --varname=<word>: The name of the configuration variable whose value is
2609 # to be completed. Defaults to the previous word on the
2611 # --cur=<word>: The current value to be completed. Defaults to the current
2612 # word to be completed.
2613 __git_complete_config_variable_value ()
2615 local varname="$prev" cur_="$cur"
2617 while test $# != 0; do
2619 --varname=*) varname="${1##--varname=}" ;;
2620 --cur=*) cur_="${1##--cur=}" ;;
2626 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2627 varname="${varname,,}"
2629 varname="$(echo "$varname" |tr A-Z a-z)"
2633 branch.*.remote|branch.*.pushremote)
2634 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2638 __git_complete_refs --cur="$cur_"
2642 __gitcomp "false true merges interactive" "" "$cur_"
2646 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2650 local remote="${varname#remote.}"
2651 remote="${remote%.fetch}"
2652 if [ -z "$cur_" ]; then
2653 __gitcomp_nl "refs/heads/" "" "" ""
2656 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2660 local remote="${varname#remote.}"
2661 remote="${remote%.push}"
2662 __gitcomp_nl "$(__git for-each-ref \
2663 --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2666 pull.twohead|pull.octopus)
2667 __git_compute_merge_strategies
2668 __gitcomp "$__git_merge_strategies" "" "$cur_"
2672 __gitcomp "false true" "" "$cur_"
2677 normal black red green yellow blue magenta cyan white
2678 bold dim ul blink reverse
2683 __gitcomp "false true always never auto" "" "$cur_"
2687 __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2691 __gitcomp "man info web html" "" "$cur_"
2695 __gitcomp "$__git_log_date_formats" "" "$cur_"
2698 sendemail.aliasfiletype)
2699 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2703 __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2706 sendemail.suppresscc)
2707 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2710 sendemail.transferencoding)
2711 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2720 # Completes configuration sections, subsections, variable names.
2722 # Usage: __git_complete_config_variable_name [<option>]...
2723 # --cur=<word>: The current configuration section/variable name to be
2724 # completed. Defaults to the current word to be completed.
2725 # --sfx=<suffix>: A suffix to be appended to each fully completed
2726 # configuration variable name (but not to sections or
2727 # subsections) instead of the default space.
2728 __git_complete_config_variable_name ()
2730 local cur_="$cur" sfx
2732 while test $# != 0; do
2734 --cur=*) cur_="${1##--cur=}" ;;
2735 --sfx=*) sfx="${1##--sfx=}" ;;
2743 local pfx="${cur_%.*}."
2745 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2749 local pfx="${cur_%.*}."
2751 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2752 __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
2756 local pfx="${cur_%.*}."
2759 argPrompt cmd confirm needsFile noConsole noRescan
2760 prompt revPrompt revUnmerged title
2761 " "$pfx" "$cur_" "$sfx"
2765 local pfx="${cur_%.*}."
2767 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2771 local pfx="${cur_%.*}."
2773 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2777 local pfx="${cur_%.*}."
2779 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2783 local pfx="${cur_%.*}."
2785 __git_compute_all_commands
2786 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
2790 local pfx="${cur_%.*}."
2793 url proxy fetch push mirror skipDefaultUpdate
2794 receivepack uploadpack tagOpt pushurl
2795 " "$pfx" "$cur_" "$sfx"
2799 local pfx="${cur_%.*}."
2801 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2802 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
2806 local pfx="${cur_%.*}."
2808 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2812 __git_compute_config_vars
2813 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
2816 __git_compute_config_sections
2817 __gitcomp "$__git_config_sections" "" "$cur_" "."
2822 # Completes '='-separated configuration sections/variable names and values
2823 # for 'git -c section.name=value'.
2825 # Usage: __git_complete_config_variable_name_and_value [<option>]...
2826 # --cur=<word>: The current configuration section/variable name/value to be
2827 # completed. Defaults to the current word to be completed.
2828 __git_complete_config_variable_name_and_value ()
2832 while test $# != 0; do
2834 --cur=*) cur_="${1##--cur=}" ;;
2842 __git_complete_config_variable_value \
2843 --varname="${cur_%%=*}" --cur="${cur_#*=}"
2846 __git_complete_config_variable_name --cur="$cur_" --sfx='='
2854 --get|--get-all|--unset|--unset-all)
2855 __gitcomp_nl "$(__git_config_get_set_variables)"
2859 __git_complete_config_variable_value
2865 __gitcomp_builtin config
2868 __git_complete_config_variable_name
2876 add rename remove set-head set-branches
2877 get-url set-url show prune update
2879 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2880 if [ -z "$subcommand" ]; then
2883 __gitcomp_builtin remote
2886 __gitcomp "$subcommands"
2892 case "$subcommand,$cur" in
2894 __gitcomp_builtin remote_add
2899 __gitcomp_builtin remote_set-head
2902 __gitcomp_builtin remote_set-branches
2904 set-head,*|set-branches,*)
2905 __git_complete_remote_or_refspec
2908 __gitcomp_builtin remote_update
2911 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
2914 __gitcomp_builtin remote_set-url
2917 __gitcomp_builtin remote_get-url
2920 __gitcomp_builtin remote_prune
2923 __gitcomp_nl "$(__git_remotes)"
2932 __gitcomp "short medium long" "" "${cur##--format=}"
2936 __gitcomp_builtin replace
2945 local subcommands="clear forget diff remaining status gc"
2946 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2947 if test -z "$subcommand"
2949 __gitcomp "$subcommands"
2956 __git_has_doubledash && return
2960 __gitcomp_builtin reset
2969 __git_find_repo_path
2979 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2982 __git_complete_refs --cur="${cur##--source=}"
2985 __gitcomp_builtin restore
2988 if __git_pseudoref_exists HEAD; then
2989 __git_complete_index_file "--modified"
2994 __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2998 __git_find_repo_path
2999 if __git_pseudoref_exists REVERT_HEAD; then
3000 __gitcomp "$__git_revert_inprogress_options"
3003 __git_complete_strategy && return
3006 __gitcomp_builtin revert "" \
3007 "$__git_revert_inprogress_options"
3018 __gitcomp_builtin rm
3023 __git_complete_index_file "--cached"
3028 __git_has_doubledash && return
3033 $__git_log_common_options
3034 $__git_log_shortlog_options
3035 --numbered --summary --email
3040 __git_complete_revlist
3045 __git_has_doubledash && return
3048 --pretty=*|--format=*)
3049 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
3054 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
3058 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
3062 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
3066 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
3069 --ws-error-highlight=*)
3070 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
3074 __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
3078 __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
3079 --oneline --show-signature
3080 --expand-tabs --expand-tabs= --no-expand-tabs
3081 $__git_log_show_options
3082 $__git_diff_common_options
3087 __git_complete_revlist_file
3094 __gitcomp_builtin show-branch
3098 __git_complete_revlist
3101 __gitcomp_directories ()
3103 local _tmp_dir _tmp_completions _found=0
3105 # Get the directory of the current token; this differs from dirname
3106 # in that it keeps up to the final trailing slash. If no slash found
3109 _tmp_dir=$BASH_REMATCH
3111 # Find possible directory completions, adding trailing '/' characters,
3112 # de-quoting, and handling unusual characters.
3113 while IFS= read -r -d $'\0' c ; do
3114 # If there are directory completions, find ones that start
3115 # with "$cur", the current token, and put those in COMPREPLY
3116 if [[ $c == "$cur"* ]]; then
3120 done < <(__git ls-tree -z -d --name-only HEAD $_tmp_dir)
3122 if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then
3123 # No possible further completions any deeper, so assume we're at
3124 # a leaf directory and just consider it complete
3125 __gitcomp_direct_append "$cur "
3126 elif [[ $_found == 0 ]]; then
3127 # No possible completions found. Avoid falling back to
3128 # bash's default file and directory completion, because all
3129 # valid completions have already been searched and the
3130 # fallbacks can do nothing but mislead. In fact, they can
3131 # mislead in three different ways:
3132 # 1) Fallback file completion makes no sense when asking
3133 # for directory completions, as this function does.
3134 # 2) Fallback directory completion is bad because
3135 # e.g. "/pro" is invalid and should NOT complete to
3137 # 3) Fallback file/directory completion only completes
3138 # on paths that exist in the current working tree,
3139 # i.e. which are *already* part of their
3140 # sparse-checkout. Thus, normal file and directory
3141 # completion is always useless for "git
3142 # sparse-checkout add" and is also probelmatic for
3143 # "git sparse-checkout set" unless using it to
3144 # strictly narrow the checkout.
3149 # In non-cone mode, the arguments to {set,add} are supposed to be
3150 # patterns, relative to the toplevel directory. These can be any kind
3151 # of general pattern, like 'subdir/*.c' and we can't complete on all
3152 # of those. However, if the user presses Tab to get tab completion, we
3153 # presume that they are trying to provide a pattern that names a specific
3155 __gitcomp_slash_leading_paths ()
3157 local dequoted_word pfx="" cur_ toplevel
3159 # Since we are dealing with a sparse-checkout, subdirectories may not
3160 # exist in the local working copy. Therefore, we want to run all
3161 # ls-files commands relative to the repository toplevel.
3162 toplevel="$(git rev-parse --show-toplevel)/"
3164 __git_dequote "$cur"
3166 # If the paths provided by the user already start with '/', then
3167 # they are considered relative to the toplevel of the repository
3168 # already. If they do not start with /, then we need to adjust
3169 # them to start with the appropriate prefix.
3175 pfx="$(__git rev-parse --show-prefix)"
3178 # Since sparse-index is limited to cone-mode, in non-cone-mode the
3179 # list of valid paths is precisely the cached files in the index.
3182 # 1) We probably need to take care of cases where ls-files
3183 # responds with special quoting.
3184 # 2) We probably need to take care of cases where ${cur} has
3185 # some kind of special quoting.
3186 # 3) On top of any quoting from 1 & 2, we have to provide an extra
3187 # level of quoting for any paths that contain a '*', '?', '\',
3188 # '[', ']', or leading '#' or '!' since those will be
3189 # interpreted by sparse-checkout as something other than a
3190 # literal path character.
3191 # Since there are two types of quoting here, this might get really
3192 # complex. For now, just punt on all of this...
3193 completions="$(__git -C "${toplevel}" -c core.quotePath=false \
3194 ls-files --cached -- "${pfx}${cur}*" \
3195 | sed -e s%^%/% -e 's%$% %')"
3196 # Note, above, though that we needed all of the completions to be
3197 # prefixed with a '/', and we want to add a space so that bash
3198 # completion will actually complete an entry and let us move on to
3201 # Return what we've found.
3202 if test -n "$completions"; then
3203 # We found some completions; return them
3205 COMPREPLY=($completions)
3207 # Do NOT fall back to bash-style all-local-files-and-dirs
3208 # when we find no match. Such options are worse than
3210 # 1. "git sparse-checkout add" needs paths that are NOT
3211 # currently in the working copy. "git
3212 # sparse-checkout set" does as well, except in the
3213 # special cases when users are only trying to narrow
3214 # their sparse checkout to a subset of what they
3217 # 2. A path like '.config' is ambiguous as to whether
3218 # the user wants all '.config' files throughout the
3219 # tree, or just the one under the current directory.
3220 # It would result in a warning from the
3221 # sparse-checkout command due to this. As such, all
3222 # completions of paths should be prefixed with a
3225 # 3. We don't want paths prefixed with a '/' to
3226 # complete files in the system root directory, we
3227 # want it to complete on files relative to the
3230 # As such, make sure that NO completions are offered rather
3231 # than falling back to bash's default completions.
3236 _git_sparse_checkout ()
3238 local subcommands="list init set disable add reapply"
3239 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3240 local using_cone=true
3241 if [ -z "$subcommand" ]; then
3242 __gitcomp "$subcommands"
3246 case "$subcommand,$cur" in
3248 __gitcomp_builtin sparse-checkout_$subcommand "" "--"
3251 if [[ "$(__git config core.sparseCheckout)" == "true" &&
3252 "$(__git config core.sparseCheckoutCone)" == "false" &&
3253 -z "$(__git_find_on_cmdline --cone)" ]]; then
3256 if [[ -n "$(__git_find_on_cmdline --no-cone)" ]]; then
3259 if [[ "$using_cone" == "true" ]]; then
3260 __gitcomp_directories
3262 __gitcomp_slash_leading_paths
3269 local subcommands='push list show apply clear drop pop create branch'
3270 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3272 if [ -z "$subcommand" ]; then
3273 case "$((cword - __git_cmd_idx)),$cur" in
3275 __gitcomp_builtin stash_push
3281 __gitcomp "$subcommands"
3287 case "$subcommand,$cur" in
3289 # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3290 __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
3293 __gitcomp_builtin stash_show "$__git_diff_common_options"
3296 __gitcomp_builtin "stash_$subcommand"
3299 if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3302 __gitcomp_nl "$(__git stash list \
3303 | sed -n -e 's/:.*//p')"
3306 show,*|apply,*|drop,*|pop,*)
3307 __gitcomp_nl "$(__git stash list \
3308 | sed -n -e 's/:.*//p')"
3315 __git_has_doubledash && return
3317 local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
3318 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3319 if [ -z "$subcommand" ]; then
3325 __gitcomp "$subcommands"
3331 case "$subcommand,$cur" in
3333 __gitcomp "--branch --force --name --reference --depth"
3336 __gitcomp "--cached --recursive"
3339 __gitcomp "--force --all"
3343 --init --remote --no-fetch
3344 --recommend-shallow --no-recommend-shallow
3345 --force --rebase --merge --reference --depth --recursive --jobs
3349 __gitcomp "--default --branch"
3352 __gitcomp "--cached --files --summary-limit"
3354 foreach,--*|sync,--*)
3355 __gitcomp "--recursive"
3365 init fetch clone rebase dcommit log find-rev
3366 set-tree commit-diff info create-ignore propget
3367 proplist show-ignore show-externals branch tag blame
3368 migrate mkdirs reset gc
3370 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3371 if [ -z "$subcommand" ]; then
3372 __gitcomp "$subcommands"
3374 local remote_opts="--username= --config-dir= --no-auth-cache"
3376 --follow-parent --authors-file= --repack=
3377 --no-metadata --use-svm-props --use-svnsync-props
3378 --log-window-size= --no-checkout --quiet
3379 --repack-flags --use-log-author --localtime
3382 --ignore-paths= --include-paths= $remote_opts
3385 --template= --shared= --trunk= --tags=
3386 --branches= --stdlayout --minimize-url
3387 --no-metadata --use-svm-props --use-svnsync-props
3388 --rewrite-root= --prefix= $remote_opts
3391 --edit --rmdir --find-copies-harder --copy-similarity=
3394 case "$subcommand,$cur" in
3396 __gitcomp "--revision= --fetch-all $fc_opts"
3399 __gitcomp "--revision= $fc_opts $init_opts"
3402 __gitcomp "$init_opts"
3406 --merge --strategy= --verbose --dry-run
3407 --fetch-all --no-rebase --commit-url
3408 --revision --interactive $cmt_opts $fc_opts
3412 __gitcomp "--stdin $cmt_opts $fc_opts"
3414 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
3415 show-externals,--*|mkdirs,--*)
3416 __gitcomp "--revision="
3420 --limit= --revision= --verbose --incremental
3421 --oneline --show-commit --non-recursive
3422 --authors-file= --color
3427 --merge --verbose --strategy= --local
3428 --fetch-all --dry-run $fc_opts
3432 __gitcomp "--message= --file= --revision= $cmt_opts"
3438 __gitcomp "--dry-run --message --tag"
3441 __gitcomp "--dry-run --message"
3444 __gitcomp "--git-format"
3448 --config-dir= --ignore-paths= --minimize
3449 --no-auth-cache --username=
3453 __gitcomp "--revision= --parent"
3463 local i c="$__git_cmd_idx" f=0
3464 while [ $c -lt $cword ]; do
3467 -d|--delete|-v|--verify)
3468 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3483 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3493 __gitcomp_builtin tag
3503 __git_complete_worktree_paths ()
3506 # Generate completion reply from worktree list skipping the first
3507 # entry: it's the path of the main worktree, which can't be moved,
3508 # removed, locked, etc.
3509 __gitcomp_nl "$(git worktree list --porcelain |
3510 sed -n -e '2,$ s/^worktree //p')"
3515 local subcommands="add list lock move prune remove unlock"
3516 local subcommand subcommand_idx
3518 subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3519 subcommand_idx="${subcommand% *}"
3520 subcommand="${subcommand#* }"
3522 case "$subcommand,$cur" in
3524 __gitcomp "$subcommands"
3527 __gitcomp_builtin worktree_$subcommand
3529 add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
3530 # Here we are not completing an --option, it's either the
3533 -b|-B) # Complete refs for branch to be created/reseted.
3536 -*) # The previous word is an -o|--option without an
3537 # unstuck argument: have to complete the path for
3538 # the new worktree, so don't list anything, but let
3539 # Bash fall back to filename completion.
3541 *) # The previous word is not an --option, so it must
3542 # be either the 'add' subcommand, the unstuck
3543 # argument of an option (e.g. branch for -b|-B), or
3544 # the path for the new worktree.
3545 if [ $cword -eq $((subcommand_idx+1)) ]; then
3546 # Right after the 'add' subcommand: have to
3547 # complete the path, so fall back to Bash
3548 # filename completion.
3551 case "${words[cword-2]}" in
3552 -b|-B) # After '-b <branch>': have to
3553 # complete the path, so fall back
3554 # to Bash filename completion.
3556 *) # After the path: have to complete
3557 # the ref to be checked out.
3565 lock,*|remove,*|unlock,*)
3566 __git_complete_worktree_paths
3569 if [ $cword -eq $((subcommand_idx+1)) ]; then
3570 # The first parameter must be an existing working
3572 __git_complete_worktree_paths
3574 # The second parameter is the destination: it could
3575 # be any path, so don't list anything, but let Bash
3576 # fall back to filename completion.
3583 __git_complete_common () {
3588 __gitcomp_builtin "$command"
3593 __git_cmds_with_parseopt_helper=
3594 __git_support_parseopt_helper () {
3595 test -n "$__git_cmds_with_parseopt_helper" ||
3596 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
3598 case " $__git_cmds_with_parseopt_helper " in
3608 __git_have_func () {
3609 declare -f -- "$1" >/dev/null 2>&1
3612 __git_complete_command () {
3614 local completion_func="_git_${command//-/_}"
3615 if ! __git_have_func $completion_func &&
3616 __git_have_func _completion_loader
3618 _completion_loader "git-$command"
3620 if __git_have_func $completion_func
3624 elif __git_support_parseopt_helper "$command"
3626 __git_complete_common "$command"
3635 local i c=1 command __git_dir __git_repo_path
3636 local __git_C_args C_args_count=0
3639 while [ $c -lt $cword ]; do
3643 __git_dir="${i#--git-dir=}"
3647 __git_dir="${words[c]}"
3656 -c|--work-tree|--namespace)
3660 __git_C_args[C_args_count++]=-C
3662 __git_C_args[C_args_count++]="${words[c]}"
3675 if [ -z "${command-}" ]; then
3677 --git-dir|-C|--work-tree)
3678 # these need a path argument, let's fall back to
3679 # Bash filename completion
3683 __git_complete_config_variable_name_and_value
3687 # we don't support completing these options' arguments
3706 --no-replace-objects
3711 if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3713 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3715 local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
3717 if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
3719 list_cmds=builtins,$list_cmds
3721 __gitcomp "$(__git --list-cmds=$list_cmds)"
3728 __git_complete_command "$command" && return
3730 local expansion=$(__git_aliased_command "$command")
3731 if [ -n "$expansion" ]; then
3733 __git_complete_command "$expansion"
3739 __git_has_doubledash && return
3741 local __git_repo_path
3742 __git_find_repo_path
3745 if __git_pseudoref_exists MERGE_HEAD; then
3751 $__git_log_common_options
3752 $__git_log_gitk_options
3758 __git_complete_revlist
3761 if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
3762 echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
3768 local cur words cword prev
3769 local __git_cmd_idx=0
3770 _get_comp_words_by_ref -n =: cur words cword prev
3776 local wrapper="__git_wrap${2}"
3777 eval "$wrapper () { __git_func_wrap $2 ; }"
3778 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3779 || complete -o default -o nospace -F $wrapper $1
3782 # Setup the completion for git commands
3783 # 1: command or alias
3784 # 2: function to call (e.g. `git
`, `gitk
`, `git_fetch
`)
3789 if __git_have_func $2; then
3791 elif __git_have_func __$2_main; then
3793 elif __git_have_func _$2; then
3796 echo "ERROR: could not find function '$2'" 1>&2
3799 ___git_complete $1 $func
3802 ___git_complete git __git_main
3803 ___git_complete gitk __gitk_main
3805 # The following are necessary only for Cygwin, and only are needed
3806 # when the user has tab-completed the executable name and consequently
3807 # included the '.exe' suffix.
3809 if [ "$OSTYPE" = cygwin ]; then
3810 ___git_complete git.exe __git_main