]>
git.ipfire.org Git - thirdparty/git.git/blob - contrib/completion/git-completion.bash
1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
31 # Be sure to add a space between the command name and the ';'.
33 # If you have a command that is not part of git, but you would still
34 # like completion, you can use __git_complete:
36 # __git_complete gl git_log
38 # Or if it's a main command (i.e. git or gitk):
40 # __git_complete gk gitk
42 # Compatible with bash 3.2.57.
44 # You can set the following environment variables to influence the behavior of
45 # the completion routines:
47 # GIT_COMPLETION_CHECKOUT_NO_GUESS
49 # When set to "1", do not include "DWIM" suggestions in git-checkout
50 # and git-switch completion (e.g., completing "foo" when "origin/foo"
53 # GIT_COMPLETION_SHOW_ALL_COMMANDS
55 # When set to "1" suggest all commands, including plumbing commands
56 # which are hidden by default (e.g. "cat-file" on "git ca<TAB>").
58 # GIT_COMPLETION_SHOW_ALL
60 # When set to "1" suggest all options, including options which are
61 # typically hidden (e.g. '--allow-empty' for 'git commit').
63 # GIT_COMPLETION_IGNORE_CASE
65 # When set, uses for-each-ref '--ignore-case' to find refs that match
66 # case insensitively, even on systems with case sensitive file systems
67 # (e.g., completing tag name "FOO" on "git checkout f<TAB>").
69 case "$COMP_WORDBREAKS" in
71 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
74 # Discovers the path to the git repository taking any '--git-dir=<path>' and
75 # '-C <path>' options into account and stores it in the $__git_repo_path
77 __git_find_repo_path
()
79 if [ -n "${__git_repo_path-}" ]; then
80 # we already know where it is
84 if [ -n "${__git_C_args-}" ]; then
85 __git_repo_path
="$(git "${__git_C_args[@]}" \
86 ${__git_dir:+--git-dir="$__git_dir"} \
87 rev-parse --absolute-git-dir 2>/dev/null)"
88 elif [ -n "${__git_dir-}" ]; then
89 test -d "$__git_dir" &&
90 __git_repo_path
="$__git_dir"
91 elif [ -n "${GIT_DIR-}" ]; then
93 __git_repo_path
="$GIT_DIR"
94 elif [ -d .git
]; then
97 __git_repo_path
="$(git rev-parse --git-dir 2>/dev/null)"
101 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
102 # __gitdir accepts 0 or 1 arguments (i.e., location)
103 # returns location of .git repo
106 if [ -z "${1-}" ]; then
107 __git_find_repo_path ||
return 1
108 echo "$__git_repo_path"
109 elif [ -d "$1/.git" ]; then
116 # Runs git with all the options given as argument, respecting any
117 # '--git-dir=<path>' and '-C <path>' options present on the command line
120 git
${__git_C_args:+"${__git_C_args[@]}"} \
121 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev
/null
124 # Removes backslash escaping, single quotes and double quotes from a word,
125 # stores the result in the variable $dequoted_word.
126 # 1: The word to dequote.
129 local rest
="$1" len ch
133 while test -n "$rest"; do
134 len
=${#dequoted_word}
135 dequoted_word
="$dequoted_word${rest%%[\\\'\"]*}"
136 rest
="${rest:$((${#dequoted_word}-$len))}"
138 case "${rest:0:1}" in
145 dequoted_word
="$dequoted_word$ch"
152 len
=${#dequoted_word}
153 dequoted_word
="$dequoted_word${rest%%\'*}"
154 rest
="${rest:$((${#dequoted_word}-$len+1))}"
158 while test -n "$rest" ; do
159 len
=${#dequoted_word}
160 dequoted_word
="$dequoted_word${rest%%[\\\"]*}"
161 rest
="${rest:$((${#dequoted_word}-$len))}"
162 case "${rest:0:1}" in
167 dequoted_word="$dequoted_word$ch"
172 dequoted_word="$dequoted_word\\$ch"
188 # The following function is based on code from:
190 # bash_completion - programmable completion functions for bash 3.2+
192 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
193 # © 2009-2010, Bash Completion Maintainers
194 # <bash-completion-devel@lists.alioth.debian.org>
196 # This program is free software; you can redistribute it and/or modify
197 # it under the terms of the GNU General Public License as published by
198 # the Free Software Foundation; either version 2, or (at your option)
201 # This program is distributed in the hope that it will be useful,
202 # but WITHOUT ANY WARRANTY; without even the implied warranty of
203 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
204 # GNU General Public License for more details.
206 # You should have received a copy of the GNU General Public License
207 # along with this program; if not, see <http://www.gnu.org/licenses/>.
209 # The latest version of this software can be obtained here:
211 # http://bash-completion.alioth.debian.org/
215 # This function can be used to access a tokenized list of words
216 # on the command line:
218 # __git_reassemble_comp_words_by_ref '=:'
219 # if test "${words_[cword_-1]}" = -w
224 # The argument should be a collection of characters from the list of
225 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
228 # This is roughly equivalent to going back in time and setting
229 # COMP_WORDBREAKS to exclude those characters. The intent is to
230 # make option types like --date=<type> and <rev>:<path> easy to
231 # recognize by treating each shell word as a single token.
233 # It is best not to set COMP_WORDBREAKS directly because the value is
234 # shared with other completion scripts. By the time the completion
235 # function gets called, COMP_WORDS has already been populated so local
236 # changes to COMP_WORDBREAKS have no effect.
238 # Output: words_, cword_, cur_.
240 __git_reassemble_comp_words_by_ref()
242 local exclude i j first
243 # Which word separators to exclude?
244 exclude="${1//[^$COMP_WORDBREAKS]}"
246 if [ -z "$exclude" ]; then
247 words_=("${COMP_WORDS[@]}")
250 # List of word completion separators has shrunk;
251 # re-assemble words to complete.
252 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
253 # Append each nonempty word consisting of just
254 # word separator characters to the current word.
258 [ -n "${COMP_WORDS[$i]}" ] &&
259 # word consists of excluded word separators
260 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
262 # Attach to the previous token,
263 # unless the previous token is the command name.
264 if [ $j -ge 2 ] && [ -n "$first" ]; then
268 words_[$j]=${words_[j]}${COMP_WORDS[i]}
269 if [ $i = $COMP_CWORD ]; then
272 if (($i < ${#COMP_WORDS[@]} - 1)); then
279 words_[$j]=${words_[j]}${COMP_WORDS[i]}
280 if [ $i = $COMP_CWORD ]; then
286 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
287 _get_comp_words_by_ref ()
289 local exclude cur_ words_ cword_
290 if [ "$1" = "-n" ]; then
294 __git_reassemble_comp_words_by_ref "$exclude"
295 cur_=${words_[cword_]}
296 while [ $# -gt 0 ]; do
302 prev=${words_[$cword_-1]}
305 words=("${words_[@]}")
316 # Fills the COMPREPLY array with prefiltered words without any additional
318 # Callers must take care of providing only words that match the current word
319 # to be completed and adding any prefix and/or suffix (trailing space!), if
321 # 1: List of newline-separated matching completion words, complete with
330 # Similar to __gitcomp_direct, but appends to COMPREPLY instead.
331 # Callers must take care of providing only words that match the current word
332 # to be completed and adding any prefix and/or suffix (trailing space!), if
334 # 1: List of newline-separated matching completion words, complete with
336 __gitcomp_direct_append ()
345 local x i=${#COMPREPLY[@]}
347 if [[ "$x" == "$3"* ]]; then
348 COMPREPLY[i++]="$2$x$4"
359 # Generates completion reply, appending a space to possible completion words,
361 # It accepts 1 to 4 arguments:
362 # 1: List of possible completion words.
363 # 2: A prefix to be added to each possible completion word (optional).
364 # 3: Generate possible completion matches for this word (optional).
365 # 4: A suffix to be appended to each possible completion word (optional).
368 local cur_="${3-$cur}"
374 local c i=0 IFS=$' \t\n'
376 if [[ $c == "--" ]]; then
380 if [[ $c == "$cur_"* ]]; then
385 COMPREPLY[i++]="${2-}$c"
390 local c i=0 IFS=$' \t\n'
392 if [[ $c == "--" ]]; then
394 if [[ $c == "$cur_"* ]]; then
395 COMPREPLY[i++]="${2-}$c "
400 if [[ $c == "$cur_"* ]]; then
405 COMPREPLY[i++]="${2-}$c"
412 # Clear the variables caching builtins' options when (re-)sourcing
413 # the completion script.
414 if [[ -n ${ZSH_VERSION-} ]]; then
415 unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
417 unset $(compgen -v __gitcomp_builtin_)
420 # This function is equivalent to
422 # __gitcomp "$(git xxx --git-completion-helper) ..."
424 # except that the output is cached. Accept 1-3 arguments:
425 # 1: the git command to execute, this is also the cache key
426 # 2: extra options to be added on top (e.g. negative forms)
427 # 3: options to be excluded
430 # spaces must be replaced with underscore for multi-word
431 # commands, e.g. "git remote add" becomes remote_add.
436 local var=__gitcomp_builtin_"${cmd//-/_}"
438 eval "options=\${$var-}"
440 if [ -z "$options" ]; then
441 local completion_helper
442 if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
443 completion_helper="--git-completion-helper-all"
445 completion_helper="--git-completion-helper"
447 # leading and trailing spaces are significant to make
448 # option removal work correctly.
449 options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
452 options="${options/ $i / }"
454 eval "$var=\"$options\""
460 # Variation of __gitcomp_nl () that appends to the existing list of
461 # completion candidates, COMPREPLY.
462 __gitcomp_nl_append ()
465 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
468 # Generates completion reply from newline-separated possible completion words
469 # by appending a space to all of them.
470 # It accepts 1 to 4 arguments:
471 # 1: List of possible completion words, separated by a single newline.
472 # 2: A prefix to be added to each possible completion word (optional).
473 # 3: Generate possible completion matches for this word (optional).
474 # 4: A suffix to be appended to each possible completion word instead of
475 # the default space (optional). If specified but empty, nothing is
480 __gitcomp_nl_append "$@"
483 # Fills the COMPREPLY array with prefiltered paths without any additional
485 # Callers must take care of providing only paths that match the current path
486 # to be completed and adding any prefix path components, if necessary.
487 # 1: List of newline-separated matching paths, complete with all prefix
489 __gitcomp_file_direct ()
495 # use a hack to enable file mode in bash < 4
496 compopt -o filenames +o nospace 2>/dev/null ||
497 compgen -f /non-existing-dir/ >/dev/null ||
501 # Generates completion reply with compgen from newline-separated possible
502 # completion filenames.
503 # It accepts 1 to 3 arguments:
504 # 1: List of possible completion filenames, separated by a single newline.
505 # 2: A directory prefix to be added to each possible completion filename
507 # 3: Generate possible completion matches for this word (optional).
512 # XXX does not work when the directory prefix contains a tilde,
513 # since tilde expansion is not applied.
514 # This means that COMPREPLY will be empty and Bash default
515 # completion will be used.
516 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
518 # use a hack to enable file mode in bash < 4
519 compopt -o filenames +o nospace 2>/dev/null ||
520 compgen -f /non-existing-dir/ >/dev/null ||
524 # Execute 'git ls-files', unless the --committable option is specified, in
525 # which case it runs 'git diff-index' to find out the files that can be
526 # committed. It return paths relative to the directory specified in the first
527 # argument, and using the options specified in the second argument.
528 __git_ls_files_helper ()
530 if [ "$2" = "--committable" ]; then
531 __git -C "$1" -c core.quotePath=false diff-index \
532 --name-only --relative HEAD -- "${3//\\/\\\\}*"
534 # NOTE: $2 is not quoted in order to support multiple options
535 __git -C "$1" -c core.quotePath=false ls-files \
536 --exclude-standard $2 -- "${3//\\/\\\\}*"
541 # __git_index_files accepts 1 or 2 arguments:
542 # 1: Options to pass to ls-files (required).
543 # 2: A directory path (optional).
544 # If provided, only files within the specified directory are listed.
545 # Sub directories are never recursed. Path must have a trailing
547 # 3: List only paths matching this path component (optional).
550 local root="$2" match="$3"
552 __git_ls_files_helper "$root" "$1" "${match:-?}" |
553 awk -F / -v pfx="${2//\\/\\\\}" '{
558 if (substr(p, 1, 1) != "\"") {
559 # No special characters, easy!
564 # The path is quoted.
569 # Even when a directory name itself does not contain
570 # any special characters, it will still be quoted if
571 # any of its (stripped) trailing path components do.
572 # Because of this we may have seen the same directory
573 # both quoted and unquoted.
575 # We have seen the same directory unquoted,
582 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
583 # Skip opening double quote.
586 # Interpret backslash escape sequences.
587 while ((bs_idx = index(p, "\\")) != 0) {
588 out = out substr(p, 1, bs_idx - 1)
589 esc = substr(p, bs_idx + 1, 1)
590 p = substr(p, bs_idx + 2)
592 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
593 # C-style one-character escape sequence.
594 out = out substr("\a\b\t\v\f\r\"\\",
596 } else if (esc == "n") {
597 # Uh-oh, a newline character.
598 # We cannot reliably put a pathname
599 # containing a newline into COMPREPLY,
600 # and the newline would create a mess.
604 # Must be a \nnn octal value, then.
606 substr(p, 1, 1) * 8 + \
608 out = out sprintf("%c", dec)
612 # Drop closing double quote, if there is one.
613 # (There is not any if this is a directory, as it was
614 # already stripped with the trailing path components.)
615 if (substr(p, length(p), 1) == "\"")
616 out = out substr(p, 1, length(p) - 1)
624 # __git_complete_index_file requires 1 argument:
625 # 1: the options to pass to ls-file
627 # The exception is --committable, which finds the files appropriate commit.
628 __git_complete_index_file ()
630 local dequoted_word pfx="" cur_
634 case "$dequoted_word" in
636 pfx="${dequoted_word%/*}/"
637 cur_="${dequoted_word##*/}"
640 cur_="$dequoted_word"
643 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
646 # Lists branches from the local repository.
647 # 1: A prefix to be added to each listed branch (optional).
648 # 2: List only branches matching this word (optional; list all branches if
650 # 3: A suffix to be appended to each listed branch (optional).
653 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
655 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
656 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
657 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
660 # Lists branches from remote repositories.
661 # 1: A prefix to be added to each listed branch (optional).
662 # 2: List only branches matching this word (optional; list all branches if
664 # 3: A suffix to be appended to each listed branch (optional).
665 __git_remote_heads ()
667 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
669 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
670 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
671 "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
674 # Lists tags from the local repository.
675 # Accepts the same positional parameters as __git_heads() above.
678 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
680 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
681 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
682 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
685 # List unique branches from refs/remotes used for 'git checkout' and 'git
686 # switch' tracking DWIMery.
687 # 1: A prefix to be added to each listed branch (optional)
688 # 2: List only branches matching this word (optional; list all branches if
690 # 3: A suffix to be appended to each listed branch (optional).
691 __git_dwim_remote_heads ()
693 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
694 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
696 # employ the heuristic used by git checkout and git switch
697 # Try to find a remote branch that cur_es the completion word
698 # but only output if the branch name is unique
699 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
700 --sort="refname:strip=3" \
701 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
702 "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
706 # Lists refs from the local (by default) or from a remote repository.
707 # It accepts 0, 1 or 2 arguments:
708 # 1: The remote to list refs from (optional; ignored, if set but empty).
709 # Can be the name of a configured remote, a path, or a URL.
710 # 2: In addition to local refs, list unique branches from refs/remotes/ for
711 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
712 # 3: A prefix to be added to each listed ref (optional).
713 # 4: List only refs matching this word (optional; list all refs if unset or
715 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
718 # Use __git_complete_refs() instead.
721 local i hash dir track="${2-}"
722 local list_refs_from=path remote="${1-}"
724 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
727 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
730 dir="$__git_repo_path"
732 if [ -z "$remote" ]; then
733 if [ -z "$dir" ]; then
737 if __git_is_configured_remote "$remote"; then
738 # configured remote takes precedence over a
739 # local directory with the same name
740 list_refs_from=remote
741 elif [ -d "$remote/.git" ]; then
743 elif [ -d "$remote" ]; then
750 if test "${GIT_COMPLETION_IGNORE_CASE:+1}" = "1"
752 # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility
753 umatch=$(echo "$match" | tr a-z A-Z 2>/dev/null || echo "$match")
756 if [ "$list_refs_from" = path ]; then
757 if [[ "$cur_" == ^* ]]; then
767 refs=("$match*" "$match*/**")
771 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD AUTO_MERGE; do
774 if [ -e "$dir/$i" ]; then
780 format="refname:strip=2"
781 refs=("refs/tags/$match*" "refs/tags/$match*/**"
782 "refs/heads/$match*" "refs/heads/$match*/**"
783 "refs/remotes/$match*" "refs/remotes/$match*/**")
786 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
787 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
789 if [ -n "$track" ]; then
790 __git_dwim_remote_heads "$pfx" "$match" "$sfx"
796 __git ls-remote "$remote" "$match*" | \
797 while read -r hash i; do
800 *) echo "$pfx$i$sfx" ;;
805 if [ "$list_refs_from" = remote ]; then
807 $match*|$umatch*) echo "${pfx}HEAD$sfx" ;;
809 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
810 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
811 "refs/remotes/$remote/$match*" \
812 "refs/remotes/$remote/$match*/**"
816 $match*|$umatch*) query_symref="HEAD" ;;
818 __git ls-remote "$remote" $query_symref \
819 "refs/tags/$match*" "refs/heads/$match*" \
820 "refs/remotes/$match*" |
821 while read -r hash i; do
824 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
825 *) echo "$pfx$i$sfx" ;; # symbolic refs
833 # Completes refs, short and long, local and remote, symbolic and pseudo.
835 # Usage: __git_complete_refs [<option>]...
836 # --remote=<remote>: The remote to list refs from, can be the name of a
837 # configured remote, a path, or a URL.
838 # --dwim: List unique remote branches for 'git switch's tracking DWIMery.
839 # --pfx=<prefix>: A prefix to be added to each ref.
840 # --cur=<word>: The current ref to be completed. Defaults to the current
841 # word to be completed.
842 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
844 # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
845 # complete all refs, 'heads' to complete only branches, or
846 # 'remote-heads' to complete only remote branches. Note that
847 # --remote is only compatible with --mode=refs.
848 __git_complete_refs ()
850 local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
852 while test $# != 0; do
854 --remote=*) remote="${1##--remote=}" ;;
855 --dwim) dwim="yes" ;;
856 # --track is an old spelling of --dwim
857 --track) dwim="yes" ;;
858 --pfx=*) pfx="${1##--pfx=}" ;;
859 --cur=*) cur_="${1##--cur=}" ;;
860 --sfx=*) sfx="${1##--sfx=}" ;;
861 --mode=*) mode="${1##--mode=}" ;;
867 # complete references based on the specified mode
870 __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
872 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
874 __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
879 # Append DWIM remote branch names if requested
880 if [ "$dwim" = "yes" ]; then
881 __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
885 # __git_refs2 requires 1 argument (to pass to __git_refs)
886 # Deprecated: use __git_complete_fetch_refspecs() instead.
890 for i in $(__git_refs "$1"); do
895 # Completes refspecs for fetching from a remote repository.
896 # 1: The remote repository.
897 # 2: A prefix to be added to each listed refspec (optional).
898 # 3: The ref to be completed as a refspec instead of the current word to be
899 # completed (optional)
900 # 4: A suffix to be appended to each listed refspec instead of the default
902 __git_complete_fetch_refspecs ()
904 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
907 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
913 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
914 __git_refs_remotes ()
917 __git ls-remote "$1" 'refs/heads/*' | \
918 while read -r hash i; do
919 echo "$i:refs/remotes/$1/${i#refs/heads/}"
926 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
930 # Returns true if $1 matches the name of a configured remote, false otherwise.
931 __git_is_configured_remote ()
934 for remote in $(__git_remotes); do
935 if [ "$remote" = "$1" ]; then
942 __git_list_merge_strategies ()
944 LANG=C LC_ALL=C git merge -s help 2>&1 |
945 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
954 __git_merge_strategies=
955 # 'git merge -s help' (and thus detection of the merge strategy
956 # list) fails, unfortunately, if run outside of any git working
957 # tree. __git_merge_strategies is set to the empty string in
958 # that case, and the detection will be repeated the next time it
960 __git_compute_merge_strategies ()
962 test -n "$__git_merge_strategies" ||
963 __git_merge_strategies=$(__git_list_merge_strategies)
966 __git_merge_strategy_options="ours theirs subtree subtree= patience
967 histogram diff-algorithm= ignore-space-change ignore-all-space
968 ignore-space-at-eol renormalize no-renormalize no-renames
969 find-renames find-renames= rename-threshold="
971 __git_complete_revlist_file ()
973 local dequoted_word pfx ls ref cur_="$cur"
982 __git_dequote "$cur_"
984 case "$dequoted_word" in
986 pfx="${dequoted_word%/*}"
987 cur_="${dequoted_word##*/}"
992 cur_="$dequoted_word"
997 case "$COMP_WORDBREAKS" in
999 *) pfx="$ref:$pfx" ;;
1002 __gitcomp_file "$(__git ls-tree "$ls" \
1008 pfx="${cur_%...*}..."
1010 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1015 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1023 __git_complete_file ()
1025 __git_complete_revlist_file
1028 __git_complete_revlist ()
1030 __git_complete_revlist_file
1033 __git_complete_remote_or_refspec ()
1035 local cur_="$cur" cmd="${words[__git_cmd_idx]}"
1036 local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
1037 if [ "$cmd" = "remote" ]; then
1040 while [ $c -lt $cword ]; do
1043 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
1044 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
1047 push) no_complete_refspec=1 ;;
1054 --multiple) no_complete_refspec=1; break ;;
1056 *) remote="$i"; break ;;
1060 if [ -z "$remote" ]; then
1061 __gitcomp_nl "$(__git_remotes)"
1064 if [ $no_complete_refspec = 1 ]; then
1067 [ "$remote" = "." ] && remote=
1070 case "$COMP_WORDBREAKS" in
1072 *) pfx="${cur_%%:*}:" ;;
1084 if [ $lhs = 1 ]; then
1085 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
1087 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1091 if [ $lhs = 1 ]; then
1092 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1094 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1098 if [ $lhs = 1 ]; then
1099 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1101 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1107 __git_complete_strategy ()
1109 __git_compute_merge_strategies
1112 __gitcomp "$__git_merge_strategies"
1116 __gitcomp "$__git_merge_strategy_options"
1122 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1125 --strategy-option=*)
1126 __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1134 __git_compute_all_commands ()
1136 test -n "$__git_all_commands" ||
1137 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1140 # Lists all set config variables starting with the given section prefix,
1141 # with the prefix removed.
1142 __git_get_config_variables ()
1144 local section="$1" i IFS=$'\n'
1145 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1146 echo "${i#$section.}"
1150 __git_pretty_aliases ()
1152 __git_get_config_variables "pretty"
1155 # __git_aliased_command requires 1 argument
1156 __git_aliased_command ()
1158 local cur=$1 last list= word cmdline
1160 while [[ -n "$cur" ]]; do
1161 if [[ "$list" == *" $cur "* ]]; then
1166 cmdline=$(__git config --get "alias.$cur")
1171 for word in $cmdline; do
1177 \!*) : shell command alias ;;
1179 *=*) : setting env ;;
1180 git) : git itself ;;
1181 \(\)) : skip parens of shell function definition ;;
1182 {) : skip start of shell helper function ;;
1183 :) : skip null command ;;
1184 \'*) : skip opening quote after sh -c ;;
1193 if [[ "$cur" != "$1" ]]; then
1198 # Check whether one of the given words is present on the command line,
1199 # and print the first word found.
1201 # Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
1202 # --show-idx: Optionally show the index of the found word in the $words array.
1203 __git_find_on_cmdline ()
1205 local word c="$__git_cmd_idx" show_idx
1207 while test $# -gt 1; do
1209 --show-idx) show_idx=y ;;
1216 while [ $c -lt $cword ]; do
1217 for word in $wordlist; do
1218 if [ "$word" = "${words[c]}" ]; then
1219 if [ -n "${show_idx-}" ]; then
1231 # Similar to __git_find_on_cmdline, except that it loops backwards and thus
1232 # prints the *last* word found. Useful for finding which of two options that
1233 # supersede each other came last, such as "--guess" and "--no-guess".
1235 # Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
1236 # --show-idx: Optionally show the index of the found word in the $words array.
1237 __git_find_last_on_cmdline ()
1239 local word c=$cword show_idx
1241 while test $# -gt 1; do
1243 --show-idx) show_idx=y ;;
1250 while [ $c -gt "$__git_cmd_idx" ]; do
1252 for word in $wordlist; do
1253 if [ "$word" = "${words[c]}" ]; then
1254 if [ -n "$show_idx" ]; then
1265 # Echo the value of an option set on the command line or config
1267 # $1: short option name
1268 # $2: long option name including =
1269 # $3: list of possible values
1270 # $4: config string (optional)
1273 # result="$(__git_get_option_value "-d" "--do-something=" \
1274 # "yes no" "core.doSomething")"
1276 # result is then either empty (no option set) or "yes" or "no"
1278 # __git_get_option_value requires 3 arguments
1279 __git_get_option_value ()
1281 local c short_opt long_opt val
1282 local result= values config_key word
1290 while [ $c -ge 0 ]; do
1292 for val in $values; do
1293 if [ "$short_opt$val" = "$word" ] ||
1294 [ "$long_opt$val" = "$word" ]; then
1302 if [ -n "$config_key" ] && [ -z "$result" ]; then
1303 result="$(__git config "$config_key")"
1309 __git_has_doubledash ()
1312 while [ $c -lt $cword ]; do
1313 if [ "--" = "${words[c]}" ]; then
1321 # Try to count non option arguments passed on the command line for the
1322 # specified git command.
1323 # When options are used, it is necessary to use the special -- option to
1324 # tell the implementation were non option arguments begin.
1325 # XXX this can not be improved, since options can appear everywhere, as
1329 # __git_count_arguments requires 1 argument: the git command executed.
1330 __git_count_arguments ()
1334 # Skip "git" (first argument)
1335 for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
1340 # Good; we can assume that the following are only non
1345 # Skip the specified git command and discard git
1358 __git_whitespacelist="nowarn warn error error-all fix"
1359 __git_patchformat="mbox stgit stgit-series hg mboxrd"
1360 __git_showcurrentpatch="diff raw"
1361 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1362 __git_quoted_cr="nowarn warn strip"
1366 __git_find_repo_path
1367 if [ -d "$__git_repo_path"/rebase-apply ]; then
1368 __gitcomp "$__git_am_inprogress_options"
1373 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1377 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1380 --show-current-patch=*)
1381 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
1385 __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}"
1389 __gitcomp_builtin am "" \
1390 "$__git_am_inprogress_options"
1399 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1403 __gitcomp_builtin apply
1412 __gitcomp "+x -x" "" "${cur##--chmod=}"
1416 __gitcomp_builtin add
1420 local complete_opt="--others --modified --directory --no-empty-directory"
1421 if test -n "$(__git_find_on_cmdline "-u --update")"
1423 complete_opt="--modified"
1425 __git_complete_index_file "$complete_opt"
1432 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1436 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1440 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
1449 __git_has_doubledash && return
1451 local subcommands="start bad good skip reset visualize replay log run"
1452 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1453 if [ -z "$subcommand" ]; then
1454 __git_find_repo_path
1455 if [ -f "$__git_repo_path"/BISECT_START ]; then
1456 __gitcomp "$subcommands"
1458 __gitcomp "replay start"
1463 case "$subcommand" in
1464 bad|good|reset|skip|start)
1472 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1476 local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
1478 while [ $c -lt $cword ]; do
1481 -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
1482 only_local_ref="y" ;;
1490 --set-upstream-to=*)
1491 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1494 __gitcomp_builtin branch
1497 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1498 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1508 local cmd="${words[__git_cmd_idx+1]}"
1510 $((__git_cmd_idx+1)))
1511 __gitcomp "create list-heads verify unbundle"
1513 $((__git_cmd_idx+2)))
1514 # looking for a file
1519 __git_complete_revlist
1526 # Helper function to decide whether or not we should enable DWIM logic for
1527 # git-switch and git-checkout.
1529 # To decide between the following rules in decreasing priority order:
1530 # - the last provided of "--guess" or "--no-guess" explicitly enable or
1531 # disable completion of DWIM logic respectively.
1532 # - If checkout.guess is false, disable completion of DWIM logic.
1533 # - If the --no-track option is provided, take this as a hint to disable the
1534 # DWIM completion logic
1535 # - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
1536 # logic, as requested by the user.
1537 # - Enable DWIM logic otherwise.
1539 __git_checkout_default_dwim_mode ()
1541 local last_option dwim_opt="--dwim"
1543 if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1547 # --no-track disables DWIM, but with lower priority than
1548 # --guess/--no-guess/checkout.guess
1549 if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
1553 # checkout.guess = false disables DWIM, but with lower priority than
1554 # --guess/--no-guess
1555 if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
1559 # Find the last provided --guess or --no-guess
1560 last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
1561 case "$last_option" in
1575 __git_has_doubledash && return
1577 local dwim_opt="$(__git_checkout_default_dwim_mode)"
1581 # Complete local branches (and DWIM branch
1582 # remote branch names) for an option argument
1583 # specifying a new branch name. This is for
1584 # convenience, assuming new branches are
1585 # possibly based on pre-existing branch names.
1586 __git_complete_refs $dwim_opt --mode="heads"
1595 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
1598 __gitcomp_builtin checkout
1601 # At this point, we've already handled special completion for
1602 # the arguments to -b/-B, and --orphan. There are 3 main
1603 # things left we can possibly complete:
1604 # 1) a start-point for -b/-B, -d/--detach, or --orphan
1605 # 2) a remote head, for --track
1606 # 3) an arbitrary reference, possibly including DWIM names
1609 if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
1610 __git_complete_refs --mode="refs"
1611 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
1612 __git_complete_refs --mode="remote-heads"
1614 __git_complete_refs $dwim_opt --mode="refs"
1620 __git_sequencer_inprogress_options="--continue --quit --abort --skip"
1622 __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1626 __git_find_repo_path
1627 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1628 __gitcomp "$__git_cherry_pick_inprogress_options"
1632 __git_complete_strategy && return
1636 __gitcomp_builtin cherry-pick "" \
1637 "$__git_cherry_pick_inprogress_options"
1649 __gitcomp_builtin clean
1654 # XXX should we check for -x option ?
1655 __git_complete_index_file "--others --directory"
1662 __git_complete_config_variable_name_and_value
1668 __git_complete_config_variable_name_and_value \
1669 --cur="${cur##--config=}"
1673 __gitcomp_builtin clone
1679 __git_untracked_file_modes="all no normal"
1692 __gitcomp "default scissors strip verbatim whitespace
1693 " "" "${cur##--cleanup=}"
1696 --reuse-message=*|--reedit-message=*|\
1697 --fixup=*|--squash=*)
1698 __git_complete_refs --cur="${cur#*=}"
1701 --untracked-files=*)
1702 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1706 __gitcomp_builtin commit
1710 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1711 __git_complete_index_file "--committable"
1713 # This is the first commit
1714 __git_complete_index_file "--cached"
1722 __gitcomp_builtin describe
1728 __git_diff_algorithms="myers minimal patience histogram"
1730 __git_diff_submodule_formats="diff log short"
1732 __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
1734 __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
1735 ignore-all-space allow-indentation-change"
1737 __git_ws_error_highlight_opts="context old new all default"
1739 # Options for the diff machinery (diff, log, show, stash, range-diff, ...)
1740 __git_diff_common_options="--stat --numstat --shortstat --summary
1741 --patch-with-stat --name-only --name-status --color
1742 --no-color --color-words --no-renames --check
1743 --color-moved --color-moved= --no-color-moved
1744 --color-moved-ws= --no-color-moved-ws
1745 --full-index --binary --abbrev --diff-filter=
1746 --find-copies --find-object --find-renames
1747 --no-relative --relative
1748 --find-copies-harder --ignore-cr-at-eol
1749 --text --ignore-space-at-eol --ignore-space-change
1750 --ignore-all-space --ignore-blank-lines --exit-code
1751 --quiet --ext-diff --no-ext-diff --unified=
1752 --no-prefix --src-prefix= --dst-prefix=
1753 --inter-hunk-context= --function-context
1754 --patience --histogram --minimal
1755 --raw --word-diff --word-diff-regex=
1756 --dirstat --dirstat= --dirstat-by-file
1757 --dirstat-by-file= --cumulative
1758 --diff-algorithm= --default-prefix
1759 --submodule --submodule= --ignore-submodules
1760 --indent-heuristic --no-indent-heuristic
1761 --textconv --no-textconv --break-rewrites
1762 --patch --no-patch --cc --combined-all-paths
1763 --anchored= --compact-summary --ignore-matching-lines=
1764 --irreversible-delete --line-prefix --no-stat
1765 --output= --output-indicator-context=
1766 --output-indicator-new= --output-indicator-old=
1767 --ws-error-highlight=
1768 --pickaxe-all --pickaxe-regex
1771 # Options for diff/difftool
1772 __git_diff_difftool_options="--cached --staged
1773 --base --ours --theirs --no-index --merge-base
1774 --ita-invisible-in-index --ita-visible-in-index
1775 $__git_diff_common_options"
1779 __git_has_doubledash && return
1783 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1787 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1791 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
1795 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
1798 --ws-error-highlight=*)
1799 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
1803 __gitcomp "$__git_diff_difftool_options"
1807 __git_complete_revlist_file
1810 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1811 tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1812 bc codecompare smerge
1817 __git_has_doubledash && return
1821 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1825 __gitcomp_builtin difftool "$__git_diff_difftool_options"
1829 __git_complete_revlist_file
1832 __git_fetch_recurse_submodules="yes on-demand no"
1837 --recurse-submodules=*)
1838 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1842 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1846 __gitcomp_builtin fetch
1850 __git_complete_remote_or_refspec
1853 __git_format_patch_extra_options="
1854 --full-index --not --all --no-prefix --src-prefix=
1855 --dst-prefix= --notes
1858 _git_format_patch ()
1864 " "" "${cur##--thread=}"
1867 --base=*|--interdiff=*|--range-diff=*)
1868 __git_complete_refs --cur="${cur#--*=}"
1872 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1876 __git_complete_revlist
1883 __gitcomp_builtin fsck
1894 # Lists matching symbol names from a tag (as in ctags) file.
1895 # 1: List symbol names matching this word.
1896 # 2: The tag file to list symbol names from.
1897 # 3: A prefix to be added to each listed symbol name (optional).
1898 # 4: A suffix to be appended to each listed symbol name (optional).
1899 __git_match_ctag () {
1900 awk -v pfx="${3-}" -v sfx="${4-}" "
1901 /^${1//\//\\/}/ { print pfx \$1 sfx }
1905 # Complete symbol names from a tag file.
1906 # Usage: __git_complete_symbol [<option>]...
1907 # --tags=<file>: The tag file to list symbol names from instead of the
1909 # --pfx=<prefix>: A prefix to be added to each symbol name.
1910 # --cur=<word>: The current symbol name to be completed. Defaults to
1911 # the current word to be completed.
1912 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1913 # of the default space.
1914 __git_complete_symbol () {
1915 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1917 while test $# != 0; do
1919 --tags=*) tags="${1##--tags=}" ;;
1920 --pfx=*) pfx="${1##--pfx=}" ;;
1921 --cur=*) cur_="${1##--cur=}" ;;
1922 --sfx=*) sfx="${1##--sfx=}" ;;
1928 if test -r "$tags"; then
1929 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1935 __git_has_doubledash && return
1939 __gitcomp_builtin grep
1944 case "$cword,$prev" in
1945 $((__git_cmd_idx+1)),*|*,-*)
1946 __git_complete_symbol && return
1957 __gitcomp_builtin help
1961 if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
1963 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
1965 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1974 false true umask group all world everybody
1975 " "" "${cur##--shared=}"
1979 __gitcomp_builtin init
1989 __gitcomp_builtin ls-files
1994 # XXX ignore options like --modified and always suggest all cached
1996 __git_complete_index_file "--cached"
2003 __gitcomp_builtin ls-remote
2007 __gitcomp_nl "$(__git_remotes)"
2014 __gitcomp_builtin ls-tree
2022 # Options that go well for log, shortlog and gitk
2023 __git_log_common_options="
2025 --branches --tags --remotes
2026 --first-parent --merges --no-merges
2028 --max-age= --since= --after=
2029 --min-age= --until= --before=
2030 --min-parents= --max-parents=
2031 --no-min-parents --no-max-parents
2033 # Options that go well for log and gitk (not shortlog)
2034 __git_log_gitk_options="
2035 --dense --sparse --full-history
2036 --simplify-merges --simplify-by-decoration
2037 --left-right --notes --no-notes
2039 # Options that go well for log and shortlog (not gitk)
2040 __git_log_shortlog_options="
2041 --author= --committer= --grep=
2042 --all-match --invert-grep
2044 # Options accepted by log and show
2045 __git_log_show_options="
2046 --diff-merges --diff-merges= --no-diff-merges --remerge-diff
2049 __git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-combined cc remerge r"
2051 __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
2052 __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
2056 __git_has_doubledash && return
2057 __git_find_repo_path
2060 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2063 case "$prev,$cur" in
2065 return # fall back to Bash filename completion
2068 __git_complete_symbol --cur="${cur#:}" --sfx=":"
2072 __git_complete_symbol
2077 --pretty=*|--format=*)
2078 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2083 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
2087 __gitcomp "full short no" "" "${cur##--decorate=}"
2091 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2095 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2098 --ws-error-highlight=*)
2099 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
2103 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
2107 __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
2112 $__git_log_common_options
2113 $__git_log_shortlog_options
2114 $__git_log_gitk_options
2115 $__git_log_show_options
2116 --root --topo-order --date-order --reverse
2117 --follow --full-diff
2118 --abbrev-commit --no-abbrev-commit --abbrev=
2119 --relative-date --date=
2120 --pretty= --format= --oneline
2125 --decorate --decorate= --no-decorate
2127 --no-walk --no-walk= --do-walk
2128 --parents --children
2129 --expand-tabs --expand-tabs= --no-expand-tabs
2131 $__git_diff_common_options
2136 return # fall back to Bash filename completion
2139 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
2143 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
2147 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
2151 __git_complete_revlist
2156 __git_complete_strategy && return
2160 __gitcomp_builtin merge
2170 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
2174 __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
2184 __gitcomp_builtin merge-base
2195 __gitcomp_builtin mv
2200 if [ $(__git_count_arguments "mv") -gt 0 ]; then
2201 # We need to show both cached and untracked files (including
2202 # empty directories) since this may not be the last argument.
2203 __git_complete_index_file "--cached --others --directory"
2205 __git_complete_index_file "--cached"
2211 local subcommands='add append copy edit get-ref list merge prune remove show'
2212 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2214 case "$subcommand,$cur" in
2216 __gitcomp_builtin notes
2224 __gitcomp "$subcommands --ref"
2228 *,--reuse-message=*|*,--reedit-message=*)
2229 __git_complete_refs --cur="${cur#*=}"
2232 __gitcomp_builtin notes_$subcommand
2235 # this command does not take a ref, do not complete it
2251 __git_complete_strategy && return
2254 --recurse-submodules=*)
2255 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
2259 __gitcomp_builtin pull
2264 __git_complete_remote_or_refspec
2267 __git_push_recurse_submodules="check on-demand only"
2269 __git_complete_force_with_lease ()
2277 __git_complete_refs --cur="${cur_#*:}"
2280 __git_complete_refs --cur="$cur_"
2289 __gitcomp_nl "$(__git_remotes)"
2292 --recurse-submodules)
2293 __gitcomp "$__git_push_recurse_submodules"
2299 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
2302 --recurse-submodules=*)
2303 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
2306 --force-with-lease=*)
2307 __git_complete_force_with_lease "${cur##--force-with-lease=}"
2311 __gitcomp_builtin push
2315 __git_complete_remote_or_refspec
2323 --creation-factor= --no-dual-color
2324 $__git_diff_common_options
2329 __git_complete_revlist
2332 __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
2333 __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
2337 __git_find_repo_path
2338 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2339 __gitcomp "$__git_rebase_interactive_inprogress_options"
2341 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2342 [ -d "$__git_repo_path"/rebase-merge ]; then
2343 __gitcomp "$__git_rebase_inprogress_options"
2346 __git_complete_strategy && return
2349 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2353 __git_complete_refs --cur="${cur##--onto=}"
2357 __gitcomp_builtin rebase "" \
2358 "$__git_rebase_interactive_inprogress_options"
2367 local subcommands="show delete expire"
2368 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2370 if [ -z "$subcommand" ]; then
2371 __gitcomp "$subcommands"
2377 __git_send_email_confirm_options="always never auto cc compose"
2378 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2383 --to|--cc|--bcc|--from)
2384 __gitcomp "$(__git send-email --dump-aliases)"
2392 $__git_send_email_confirm_options
2393 " "" "${cur##--confirm=}"
2398 $__git_send_email_suppresscc_options
2399 " "" "${cur##--suppress-cc=}"
2403 --smtp-encryption=*)
2404 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2410 " "" "${cur##--thread=}"
2413 --to=*|--cc=*|--bcc=*|--from=*)
2414 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2418 __gitcomp_builtin send-email "$__git_format_patch_extra_options"
2422 __git_complete_revlist
2433 local untracked_state
2436 --ignore-submodules=*)
2437 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2440 --untracked-files=*)
2441 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2446 always never auto column row plain dense nodense
2447 " "" "${cur##--column=}"
2451 __gitcomp_builtin status
2456 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2457 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2459 case "$untracked_state" in
2461 # --ignored option does not matter
2465 complete_opt="--cached --directory --no-empty-directory --others"
2467 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2468 complete_opt="$complete_opt --ignored --exclude=*"
2473 __git_complete_index_file "$complete_opt"
2478 local dwim_opt="$(__git_checkout_default_dwim_mode)"
2482 # Complete local branches (and DWIM branch
2483 # remote branch names) for an option argument
2484 # specifying a new branch name. This is for
2485 # convenience, assuming new branches are
2486 # possibly based on pre-existing branch names.
2487 __git_complete_refs $dwim_opt --mode="heads"
2496 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2499 __gitcomp_builtin switch
2502 # Unlike in git checkout, git switch --orphan does not take
2503 # a start point. Thus we really have nothing to complete after
2505 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
2509 # At this point, we've already handled special completion for
2510 # -c/-C, and --orphan. There are 3 main things left to
2512 # 1) a start-point for -c/-C or -d/--detach
2513 # 2) a remote head, for --track
2514 # 3) a branch name, possibly including DWIM remote branches
2516 if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
2517 __git_complete_refs --mode="refs"
2518 elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
2519 __git_complete_refs --mode="remote-heads"
2521 __git_complete_refs $dwim_opt --mode="heads"
2527 __git_config_get_set_variables ()
2529 local prevword word config_file= c=$cword
2530 while [ $c -gt "$__git_cmd_idx" ]; do
2533 --system|--global|--local|--file=*)
2538 config_file="$word $prevword"
2546 __git config $config_file --name-only --list
2550 __git_compute_config_vars ()
2552 test -n "$__git_config_vars" ||
2553 __git_config_vars="$(git help --config-for-completion)"
2556 __git_config_sections=
2557 __git_compute_config_sections ()
2559 test -n "$__git_config_sections" ||
2560 __git_config_sections="$(git help --config-sections-for-completion)"
2563 # Completes possible values of various configuration variables.
2565 # Usage: __git_complete_config_variable_value [<option>]...
2566 # --varname=<word>: The name of the configuration variable whose value is
2567 # to be completed. Defaults to the previous word on the
2569 # --cur=<word>: The current value to be completed. Defaults to the current
2570 # word to be completed.
2571 __git_complete_config_variable_value ()
2573 local varname="$prev" cur_="$cur"
2575 while test $# != 0; do
2577 --varname=*) varname="${1##--varname=}" ;;
2578 --cur=*) cur_="${1##--cur=}" ;;
2584 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2585 varname="${varname,,}"
2587 varname="$(echo "$varname" |tr A-Z a-z)"
2591 branch.*.remote|branch.*.pushremote)
2592 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2596 __git_complete_refs --cur="$cur_"
2600 __gitcomp "false true merges interactive" "" "$cur_"
2604 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2608 local remote="${varname#remote.}"
2609 remote="${remote%.fetch}"
2610 if [ -z "$cur_" ]; then
2611 __gitcomp_nl "refs/heads/" "" "" ""
2614 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2618 local remote="${varname#remote.}"
2619 remote="${remote%.push}"
2620 __gitcomp_nl "$(__git for-each-ref \
2621 --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2624 pull.twohead|pull.octopus)
2625 __git_compute_merge_strategies
2626 __gitcomp "$__git_merge_strategies" "" "$cur_"
2630 __gitcomp "false true" "" "$cur_"
2635 normal black red green yellow blue magenta cyan white
2636 bold dim ul blink reverse
2641 __gitcomp "false true always never auto" "" "$cur_"
2645 __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2649 __gitcomp "man info web html" "" "$cur_"
2653 __gitcomp "$__git_log_date_formats" "" "$cur_"
2656 sendemail.aliasfiletype)
2657 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2661 __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2664 sendemail.suppresscc)
2665 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2668 sendemail.transferencoding)
2669 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2678 # Completes configuration sections, subsections, variable names.
2680 # Usage: __git_complete_config_variable_name [<option>]...
2681 # --cur=<word>: The current configuration section/variable name to be
2682 # completed. Defaults to the current word to be completed.
2683 # --sfx=<suffix>: A suffix to be appended to each fully completed
2684 # configuration variable name (but not to sections or
2685 # subsections) instead of the default space.
2686 __git_complete_config_variable_name ()
2688 local cur_="$cur" sfx
2690 while test $# != 0; do
2692 --cur=*) cur_="${1##--cur=}" ;;
2693 --sfx=*) sfx="${1##--sfx=}" ;;
2701 local pfx="${cur_%.*}."
2703 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2707 local pfx="${cur_%.*}."
2709 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2710 __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
2714 local pfx="${cur_%.*}."
2717 argPrompt cmd confirm needsFile noConsole noRescan
2718 prompt revPrompt revUnmerged title
2719 " "$pfx" "$cur_" "$sfx"
2723 local pfx="${cur_%.*}."
2725 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2729 local pfx="${cur_%.*}."
2731 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2735 local pfx="${cur_%.*}."
2737 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2741 local pfx="${cur_%.*}."
2743 __git_compute_all_commands
2744 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
2748 local pfx="${cur_%.*}."
2751 url proxy fetch push mirror skipDefaultUpdate
2752 receivepack uploadpack tagOpt pushurl
2753 " "$pfx" "$cur_" "$sfx"
2757 local pfx="${cur_%.*}."
2759 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2760 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
2764 local pfx="${cur_%.*}."
2766 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2770 __git_compute_config_vars
2771 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
2774 __git_compute_config_sections
2775 __gitcomp "$__git_config_sections" "" "$cur_" "."
2780 # Completes '='-separated configuration sections/variable names and values
2781 # for 'git -c section.name=value'.
2783 # Usage: __git_complete_config_variable_name_and_value [<option>]...
2784 # --cur=<word>: The current configuration section/variable name/value to be
2785 # completed. Defaults to the current word to be completed.
2786 __git_complete_config_variable_name_and_value ()
2790 while test $# != 0; do
2792 --cur=*) cur_="${1##--cur=}" ;;
2800 __git_complete_config_variable_value \
2801 --varname="${cur_%%=*}" --cur="${cur_#*=}"
2804 __git_complete_config_variable_name --cur="$cur_" --sfx='='
2812 --get|--get-all|--unset|--unset-all)
2813 __gitcomp_nl "$(__git_config_get_set_variables)"
2817 __git_complete_config_variable_value
2823 __gitcomp_builtin config
2826 __git_complete_config_variable_name
2834 add rename remove set-head set-branches
2835 get-url set-url show prune update
2837 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2838 if [ -z "$subcommand" ]; then
2841 __gitcomp_builtin remote
2844 __gitcomp "$subcommands"
2850 case "$subcommand,$cur" in
2852 __gitcomp_builtin remote_add
2857 __gitcomp_builtin remote_set-head
2860 __gitcomp_builtin remote_set-branches
2862 set-head,*|set-branches,*)
2863 __git_complete_remote_or_refspec
2866 __gitcomp_builtin remote_update
2869 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
2872 __gitcomp_builtin remote_set-url
2875 __gitcomp_builtin remote_get-url
2878 __gitcomp_builtin remote_prune
2881 __gitcomp_nl "$(__git_remotes)"
2890 __gitcomp "short medium long" "" "${cur##--format=}"
2894 __gitcomp_builtin replace
2903 local subcommands="clear forget diff remaining status gc"
2904 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2905 if test -z "$subcommand"
2907 __gitcomp "$subcommands"
2914 __git_has_doubledash && return
2918 __gitcomp_builtin reset
2936 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2939 __git_complete_refs --cur="${cur##--source=}"
2942 __gitcomp_builtin restore
2945 if __git rev-parse --verify --quiet HEAD >/dev/null; then
2946 __git_complete_index_file "--modified"
2951 __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2955 __git_find_repo_path
2956 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2957 __gitcomp "$__git_revert_inprogress_options"
2960 __git_complete_strategy && return
2963 __gitcomp_builtin revert "" \
2964 "$__git_revert_inprogress_options"
2975 __gitcomp_builtin rm
2980 __git_complete_index_file "--cached"
2985 __git_has_doubledash && return
2990 $__git_log_common_options
2991 $__git_log_shortlog_options
2992 --numbered --summary --email
2997 __git_complete_revlist
3002 __git_has_doubledash && return
3005 --pretty=*|--format=*)
3006 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
3011 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
3015 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
3019 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
3023 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
3026 --ws-error-highlight=*)
3027 __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
3031 __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
3035 __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
3036 --oneline --show-signature
3037 --expand-tabs --expand-tabs= --no-expand-tabs
3038 $__git_log_show_options
3039 $__git_diff_common_options
3044 __git_complete_revlist_file
3051 __gitcomp_builtin show-branch
3055 __git_complete_revlist
3058 __gitcomp_directories ()
3060 local _tmp_dir _tmp_completions _found=0
3062 # Get the directory of the current token; this differs from dirname
3063 # in that it keeps up to the final trailing slash. If no slash found
3066 _tmp_dir=$BASH_REMATCH
3068 # Find possible directory completions, adding trailing '/' characters,
3069 # de-quoting, and handling unusual characters.
3070 while IFS= read -r -d $'\0' c ; do
3071 # If there are directory completions, find ones that start
3072 # with "$cur", the current token, and put those in COMPREPLY
3073 if [[ $c == "$cur"* ]]; then
3077 done < <(git ls-tree -z -d --name-only HEAD $_tmp_dir)
3079 if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then
3080 # No possible further completions any deeper, so assume we're at
3081 # a leaf directory and just consider it complete
3082 __gitcomp_direct_append "$cur "
3086 _git_sparse_checkout ()
3088 local subcommands="list init set disable add reapply"
3089 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3090 if [ -z "$subcommand" ]; then
3091 __gitcomp "$subcommands"
3095 case "$subcommand,$cur" in
3097 __gitcomp_builtin sparse-checkout_$subcommand "" "--"
3100 if [ "$(__git config core.sparseCheckoutCone)" == "true" ] ||
3101 [ -n "$(__git_find_on_cmdline --cone)" ]; then
3102 __gitcomp_directories
3109 local subcommands='push list show apply clear drop pop create branch'
3110 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3112 if [ -z "$subcommand" ]; then
3113 case "$((cword - __git_cmd_idx)),$cur" in
3115 __gitcomp_builtin stash_push
3121 __gitcomp "$subcommands"
3127 case "$subcommand,$cur" in
3129 # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3130 __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
3133 __gitcomp_builtin stash_show "$__git_diff_common_options"
3136 __gitcomp_builtin "stash_$subcommand"
3139 if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3142 __gitcomp_nl "$(__git stash list \
3143 | sed -n -e 's/:.*//p')"
3146 show,*|apply,*|drop,*|pop,*)
3147 __gitcomp_nl "$(__git stash list \
3148 | sed -n -e 's/:.*//p')"
3155 __git_has_doubledash && return
3157 local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
3158 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3159 if [ -z "$subcommand" ]; then
3165 __gitcomp "$subcommands"
3171 case "$subcommand,$cur" in
3173 __gitcomp "--branch --force --name --reference --depth"
3176 __gitcomp "--cached --recursive"
3179 __gitcomp "--force --all"
3183 --init --remote --no-fetch
3184 --recommend-shallow --no-recommend-shallow
3185 --force --rebase --merge --reference --depth --recursive --jobs
3189 __gitcomp "--default --branch"
3192 __gitcomp "--cached --files --summary-limit"
3194 foreach,--*|sync,--*)
3195 __gitcomp "--recursive"
3205 init fetch clone rebase dcommit log find-rev
3206 set-tree commit-diff info create-ignore propget
3207 proplist show-ignore show-externals branch tag blame
3208 migrate mkdirs reset gc
3210 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3211 if [ -z "$subcommand" ]; then
3212 __gitcomp "$subcommands"
3214 local remote_opts="--username= --config-dir= --no-auth-cache"
3216 --follow-parent --authors-file= --repack=
3217 --no-metadata --use-svm-props --use-svnsync-props
3218 --log-window-size= --no-checkout --quiet
3219 --repack-flags --use-log-author --localtime
3222 --ignore-paths= --include-paths= $remote_opts
3225 --template= --shared= --trunk= --tags=
3226 --branches= --stdlayout --minimize-url
3227 --no-metadata --use-svm-props --use-svnsync-props
3228 --rewrite-root= --prefix= $remote_opts
3231 --edit --rmdir --find-copies-harder --copy-similarity=
3234 case "$subcommand,$cur" in
3236 __gitcomp "--revision= --fetch-all $fc_opts"
3239 __gitcomp "--revision= $fc_opts $init_opts"
3242 __gitcomp "$init_opts"
3246 --merge --strategy= --verbose --dry-run
3247 --fetch-all --no-rebase --commit-url
3248 --revision --interactive $cmt_opts $fc_opts
3252 __gitcomp "--stdin $cmt_opts $fc_opts"
3254 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
3255 show-externals,--*|mkdirs,--*)
3256 __gitcomp "--revision="
3260 --limit= --revision= --verbose --incremental
3261 --oneline --show-commit --non-recursive
3262 --authors-file= --color
3267 --merge --verbose --strategy= --local
3268 --fetch-all --dry-run $fc_opts
3272 __gitcomp "--message= --file= --revision= $cmt_opts"
3278 __gitcomp "--dry-run --message --tag"
3281 __gitcomp "--dry-run --message"
3284 __gitcomp "--git-format"
3288 --config-dir= --ignore-paths= --minimize
3289 --no-auth-cache --username=
3293 __gitcomp "--revision= --parent"
3303 local i c="$__git_cmd_idx" f=0
3304 while [ $c -lt $cword ]; do
3307 -d|--delete|-v|--verify)
3308 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3323 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3333 __gitcomp_builtin tag
3343 __git_complete_worktree_paths ()
3346 # Generate completion reply from worktree list skipping the first
3347 # entry: it's the path of the main worktree, which can't be moved,
3348 # removed, locked, etc.
3349 __gitcomp_nl "$(git worktree list --porcelain |
3350 sed -n -e '2,$ s/^worktree //p')"
3355 local subcommands="add list lock move prune remove unlock"
3356 local subcommand subcommand_idx
3358 subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3359 subcommand_idx="${subcommand% *}"
3360 subcommand="${subcommand#* }"
3362 case "$subcommand,$cur" in
3364 __gitcomp "$subcommands"
3367 __gitcomp_builtin worktree_$subcommand
3369 add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
3370 # Here we are not completing an --option, it's either the
3373 -b|-B) # Complete refs for branch to be created/reseted.
3376 -*) # The previous word is an -o|--option without an
3377 # unstuck argument: have to complete the path for
3378 # the new worktree, so don't list anything, but let
3379 # Bash fall back to filename completion.
3381 *) # The previous word is not an --option, so it must
3382 # be either the 'add' subcommand, the unstuck
3383 # argument of an option (e.g. branch for -b|-B), or
3384 # the path for the new worktree.
3385 if [ $cword -eq $((subcommand_idx+1)) ]; then
3386 # Right after the 'add' subcommand: have to
3387 # complete the path, so fall back to Bash
3388 # filename completion.
3391 case "${words[cword-2]}" in
3392 -b|-B) # After '-b <branch>': have to
3393 # complete the path, so fall back
3394 # to Bash filename completion.
3396 *) # After the path: have to complete
3397 # the ref to be checked out.
3405 lock,*|remove,*|unlock,*)
3406 __git_complete_worktree_paths
3409 if [ $cword -eq $((subcommand_idx+1)) ]; then
3410 # The first parameter must be an existing working
3412 __git_complete_worktree_paths
3414 # The second parameter is the destination: it could
3415 # be any path, so don't list anything, but let Bash
3416 # fall back to filename completion.
3423 __git_complete_common () {
3428 __gitcomp_builtin "$command"
3433 __git_cmds_with_parseopt_helper=
3434 __git_support_parseopt_helper () {
3435 test -n "$__git_cmds_with_parseopt_helper" ||
3436 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
3438 case " $__git_cmds_with_parseopt_helper " in
3448 __git_have_func () {
3449 declare -f -- "$1" >/dev/null 2>&1
3452 __git_complete_command () {
3454 local completion_func="_git_${command//-/_}"
3455 if ! __git_have_func $completion_func &&
3456 __git_have_func _completion_loader
3458 _completion_loader "git-$command"
3460 if __git_have_func $completion_func
3464 elif __git_support_parseopt_helper "$command"
3466 __git_complete_common "$command"
3475 local i c=1 command __git_dir __git_repo_path
3476 local __git_C_args C_args_count=0
3479 while [ $c -lt $cword ]; do
3483 __git_dir="${i#--git-dir=}"
3487 __git_dir="${words[c]}"
3496 -c|--work-tree|--namespace)
3500 __git_C_args[C_args_count++]=-C
3502 __git_C_args[C_args_count++]="${words[c]}"
3515 if [ -z "${command-}" ]; then
3517 --git-dir|-C|--work-tree)
3518 # these need a path argument, let's fall back to
3519 # Bash filename completion
3523 __git_complete_config_variable_name_and_value
3527 # we don't support completing these options' arguments
3546 --no-replace-objects
3551 if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3553 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3555 local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
3557 if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
3559 list_cmds=builtins,$list_cmds
3561 __gitcomp "$(__git --list-cmds=$list_cmds)"
3568 __git_complete_command "$command" && return
3570 local expansion=$(__git_aliased_command "$command")
3571 if [ -n "$expansion" ]; then
3573 __git_complete_command "$expansion"
3579 __git_has_doubledash && return
3581 local __git_repo_path
3582 __git_find_repo_path
3585 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3591 $__git_log_common_options
3592 $__git_log_gitk_options
3598 __git_complete_revlist
3601 if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
3602 echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
3608 local cur words cword prev
3609 local __git_cmd_idx=0
3610 _get_comp_words_by_ref -n =: cur words cword prev
3616 local wrapper="__git_wrap${2}"
3617 eval "$wrapper () { __git_func_wrap $2 ; }"
3618 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3619 || complete -o default -o nospace -F $wrapper $1
3622 # Setup the completion for git commands
3623 # 1: command or alias
3624 # 2: function to call (e.g. `git
`, `gitk
`, `git_fetch
`)
3629 if __git_have_func $2; then
3631 elif __git_have_func __$2_main; then
3633 elif __git_have_func _$2; then
3636 echo "ERROR: could not find function '$2'" 1>&2
3639 ___git_complete $1 $func
3642 ___git_complete git __git_main
3643 ___git_complete gitk __gitk_main
3645 # The following are necessary only for Cygwin, and only are needed
3646 # when the user has tab-completed the executable name and consequently
3647 # included the '.exe' suffix.
3649 if [ "$OSTYPE" = cygwin ]; then
3650 ___git_complete git.exe __git_main