1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 # Compatible with bash 3.2.57.
34 # You can set the following environment variables to influence the behavior of
35 # the completion routines:
37 # GIT_COMPLETION_CHECKOUT_NO_GUESS
39 # When set to "1", do not include "DWIM" suggestions in git-checkout
40 # completion (e.g., completing "foo" when "origin/foo" exists).
42 case "$COMP_WORDBREAKS" in
44 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
47 # Discovers the path to the git repository taking any '--git-dir=<path>' and
48 # '-C <path>' options into account and stores it in the $__git_repo_path
50 __git_find_repo_path
()
52 if [ -n "$__git_repo_path" ]; then
53 # we already know where it is
57 if [ -n "${__git_C_args-}" ]; then
58 __git_repo_path
="$(git "${__git_C_args[@]}" \
59 ${__git_dir:+--git-dir="$__git_dir"} \
60 rev-parse --absolute-git-dir 2>/dev/null)"
61 elif [ -n "${__git_dir-}" ]; then
62 test -d "$__git_dir" &&
63 __git_repo_path
="$__git_dir"
64 elif [ -n "${GIT_DIR-}" ]; then
65 test -d "${GIT_DIR-}" &&
66 __git_repo_path
="$GIT_DIR"
67 elif [ -d .git
]; then
70 __git_repo_path
="$(git rev-parse --git-dir 2>/dev/null)"
74 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
75 # __gitdir accepts 0 or 1 arguments (i.e., location)
76 # returns location of .git repo
79 if [ -z "${1-}" ]; then
80 __git_find_repo_path ||
return 1
81 echo "$__git_repo_path"
82 elif [ -d "$1/.git" ]; then
89 # Runs git with all the options given as argument, respecting any
90 # '--git-dir=<path>' and '-C <path>' options present on the command line
93 git
${__git_C_args:+"${__git_C_args[@]}"} \
94 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev
/null
97 # Removes backslash escaping, single quotes and double quotes from a word,
98 # stores the result in the variable $dequoted_word.
99 # 1: The word to dequote.
102 local rest
="$1" len ch
106 while test -n "$rest"; do
107 len
=${#dequoted_word}
108 dequoted_word
="$dequoted_word${rest%%[\\\'\"]*}"
109 rest
="${rest:$((${#dequoted_word}-$len))}"
111 case "${rest:0:1}" in
118 dequoted_word
="$dequoted_word$ch"
125 len
=${#dequoted_word}
126 dequoted_word
="$dequoted_word${rest%%\'*}"
127 rest
="${rest:$((${#dequoted_word}-$len+1))}"
131 while test -n "$rest" ; do
132 len
=${#dequoted_word}
133 dequoted_word
="$dequoted_word${rest%%[\\\"]*}"
134 rest
="${rest:$((${#dequoted_word}-$len))}"
135 case "${rest:0:1}" in
140 dequoted_word="$dequoted_word$ch"
145 dequoted_word="$dequoted_word\\$ch"
161 # The following function is based on code from:
163 # bash_completion - programmable completion functions for bash 3.2+
165 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
166 # © 2009-2010, Bash Completion Maintainers
167 # <bash-completion-devel@lists.alioth.debian.org>
169 # This program is free software; you can redistribute it and/or modify
170 # it under the terms of the GNU General Public License as published by
171 # the Free Software Foundation; either version 2, or (at your option)
174 # This program is distributed in the hope that it will be useful,
175 # but WITHOUT ANY WARRANTY; without even the implied warranty of
176 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
177 # GNU General Public License for more details.
179 # You should have received a copy of the GNU General Public License
180 # along with this program; if not, see <http://www.gnu.org/licenses/>.
182 # The latest version of this software can be obtained here:
184 # http://bash-completion.alioth.debian.org/
188 # This function can be used to access a tokenized list of words
189 # on the command line:
191 # __git_reassemble_comp_words_by_ref '=:'
192 # if test "${words_[cword_-1]}" = -w
197 # The argument should be a collection of characters from the list of
198 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
201 # This is roughly equivalent to going back in time and setting
202 # COMP_WORDBREAKS to exclude those characters. The intent is to
203 # make option types like --date=<type> and <rev>:<path> easy to
204 # recognize by treating each shell word as a single token.
206 # It is best not to set COMP_WORDBREAKS directly because the value is
207 # shared with other completion scripts. By the time the completion
208 # function gets called, COMP_WORDS has already been populated so local
209 # changes to COMP_WORDBREAKS have no effect.
211 # Output: words_, cword_, cur_.
213 __git_reassemble_comp_words_by_ref()
215 local exclude i j first
216 # Which word separators to exclude?
217 exclude="${1//[^$COMP_WORDBREAKS]}"
219 if [ -z "$exclude" ]; then
220 words_=("${COMP_WORDS[@]}")
223 # List of word completion separators has shrunk;
224 # re-assemble words to complete.
225 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
226 # Append each nonempty word consisting of just
227 # word separator characters to the current word.
231 [ -n "${COMP_WORDS[$i]}" ] &&
232 # word consists of excluded word separators
233 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
235 # Attach to the previous token,
236 # unless the previous token is the command name.
237 if [ $j -ge 2 ] && [ -n "$first" ]; then
241 words_[$j]=${words_[j]}${COMP_WORDS[i]}
242 if [ $i = $COMP_CWORD ]; then
245 if (($i < ${#COMP_WORDS[@]} - 1)); then
252 words_[$j]=${words_[j]}${COMP_WORDS[i]}
253 if [ $i = $COMP_CWORD ]; then
259 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
260 _get_comp_words_by_ref ()
262 local exclude cur_ words_ cword_
263 if [ "$1" = "-n" ]; then
267 __git_reassemble_comp_words_by_ref "$exclude"
268 cur_=${words_[cword_]}
269 while [ $# -gt 0 ]; do
275 prev=${words_[$cword_-1]}
278 words=("${words_[@]}")
289 # Fills the COMPREPLY array with prefiltered words without any additional
291 # Callers must take care of providing only words that match the current word
292 # to be completed and adding any prefix and/or suffix (trailing space!), if
294 # 1: List of newline-separated matching completion words, complete with
305 local x i=${#COMPREPLY[@]}
307 if [[ "$x" == "$3"* ]]; then
308 COMPREPLY[i++]="$2$x$4"
319 # Generates completion reply, appending a space to possible completion words,
321 # It accepts 1 to 4 arguments:
322 # 1: List of possible completion words.
323 # 2: A prefix to be added to each possible completion word (optional).
324 # 3: Generate possible completion matches for this word (optional).
325 # 4: A suffix to be appended to each possible completion word (optional).
328 local cur_="${3-$cur}"
334 local c i=0 IFS=$' \t\n'
336 if [[ $c == "--" ]]; then
340 if [[ $c == "$cur_"* ]]; then
345 COMPREPLY[i++]="${2-}$c"
350 local c i=0 IFS=$' \t\n'
352 if [[ $c == "--" ]]; then
354 if [[ $c == "$cur_"* ]]; then
355 COMPREPLY[i++]="${2-}$c "
360 if [[ $c == "$cur_"* ]]; then
365 COMPREPLY[i++]="${2-}$c"
372 # Clear the variables caching builtins' options when (re-)sourcing
373 # the completion script.
374 if [[ -n ${ZSH_VERSION-} ]]; then
375 unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
377 unset $(compgen -v __gitcomp_builtin_)
380 # This function is equivalent to
382 # __gitcomp "$(git xxx --git-completion-helper) ..."
384 # except that the output is cached. Accept 1-3 arguments:
385 # 1: the git command to execute, this is also the cache key
386 # 2: extra options to be added on top (e.g. negative forms)
387 # 3: options to be excluded
390 # spaces must be replaced with underscore for multi-word
391 # commands, e.g. "git remote add" becomes remote_add.
396 local var=__gitcomp_builtin_"${cmd/-/_}"
398 eval "options=\$$var"
400 if [ -z "$options" ]; then
401 # leading and trailing spaces are significant to make
402 # option removal work correctly.
403 options=" $incl $(__git ${cmd/_/ } --git-completion-helper) "
405 options="${options/ $i / }"
407 eval "$var=\"$options\""
413 # Variation of __gitcomp_nl () that appends to the existing list of
414 # completion candidates, COMPREPLY.
415 __gitcomp_nl_append ()
418 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
421 # Generates completion reply from newline-separated possible completion words
422 # by appending a space to all of them.
423 # It accepts 1 to 4 arguments:
424 # 1: List of possible completion words, separated by a single newline.
425 # 2: A prefix to be added to each possible completion word (optional).
426 # 3: Generate possible completion matches for this word (optional).
427 # 4: A suffix to be appended to each possible completion word instead of
428 # the default space (optional). If specified but empty, nothing is
433 __gitcomp_nl_append "$@"
436 # Fills the COMPREPLY array with prefiltered paths without any additional
438 # Callers must take care of providing only paths that match the current path
439 # to be completed and adding any prefix path components, if necessary.
440 # 1: List of newline-separated matching paths, complete with all prefix
442 __gitcomp_file_direct ()
448 # use a hack to enable file mode in bash < 4
449 compopt -o filenames +o nospace 2>/dev/null ||
450 compgen -f /non-existing-dir/ >/dev/null ||
454 # Generates completion reply with compgen from newline-separated possible
455 # completion filenames.
456 # It accepts 1 to 3 arguments:
457 # 1: List of possible completion filenames, separated by a single newline.
458 # 2: A directory prefix to be added to each possible completion filename
460 # 3: Generate possible completion matches for this word (optional).
465 # XXX does not work when the directory prefix contains a tilde,
466 # since tilde expansion is not applied.
467 # This means that COMPREPLY will be empty and Bash default
468 # completion will be used.
469 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
471 # use a hack to enable file mode in bash < 4
472 compopt -o filenames +o nospace 2>/dev/null ||
473 compgen -f /non-existing-dir/ >/dev/null ||
477 # Execute 'git ls-files', unless the --committable option is specified, in
478 # which case it runs 'git diff-index' to find out the files that can be
479 # committed. It return paths relative to the directory specified in the first
480 # argument, and using the options specified in the second argument.
481 __git_ls_files_helper ()
483 if [ "$2" == "--committable" ]; then
484 __git -C "$1" -c core.quotePath=false diff-index \
485 --name-only --relative HEAD -- "${3//\\/\\\\}*"
487 # NOTE: $2 is not quoted in order to support multiple options
488 __git -C "$1" -c core.quotePath=false ls-files \
489 --exclude-standard $2 -- "${3//\\/\\\\}*"
494 # __git_index_files accepts 1 or 2 arguments:
495 # 1: Options to pass to ls-files (required).
496 # 2: A directory path (optional).
497 # If provided, only files within the specified directory are listed.
498 # Sub directories are never recursed. Path must have a trailing
500 # 3: List only paths matching this path component (optional).
503 local root="$2" match="$3"
505 __git_ls_files_helper "$root" "$1" "$match" |
506 awk -F / -v pfx="${2//\\/\\\\}" '{
511 if (substr(p, 1, 1) != "\"") {
512 # No special characters, easy!
517 # The path is quoted.
522 # Even when a directory name itself does not contain
523 # any special characters, it will still be quoted if
524 # any of its (stripped) trailing path components do.
525 # Because of this we may have seen the same direcory
526 # both quoted and unquoted.
528 # We have seen the same directory unquoted,
535 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
536 # Skip opening double quote.
539 # Interpret backslash escape sequences.
540 while ((bs_idx = index(p, "\\")) != 0) {
541 out = out substr(p, 1, bs_idx - 1)
542 esc = substr(p, bs_idx + 1, 1)
543 p = substr(p, bs_idx + 2)
545 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
546 # C-style one-character escape sequence.
547 out = out substr("\a\b\t\v\f\r\"\\",
549 } else if (esc == "n") {
550 # Uh-oh, a newline character.
551 # We cant reliably put a pathname
552 # containing a newline into COMPREPLY,
553 # and the newline would create a mess.
557 # Must be a \nnn octal value, then.
559 substr(p, 1, 1) * 8 + \
561 out = out sprintf("%c", dec)
565 # Drop closing double quote, if there is one.
566 # (There isnt any if this is a directory, as it was
567 # already stripped with the trailing path components.)
568 if (substr(p, length(p), 1) == "\"")
569 out = out substr(p, 1, length(p) - 1)
577 # __git_complete_index_file requires 1 argument:
578 # 1: the options to pass to ls-file
580 # The exception is --committable, which finds the files appropriate commit.
581 __git_complete_index_file ()
583 local dequoted_word pfx="" cur_
587 case "$dequoted_word" in
589 pfx="${dequoted_word%/*}/"
590 cur_="${dequoted_word##*/}"
593 cur_="$dequoted_word"
596 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
599 # Lists branches from the local repository.
600 # 1: A prefix to be added to each listed branch (optional).
601 # 2: List only branches matching this word (optional; list all branches if
603 # 3: A suffix to be appended to each listed branch (optional).
606 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
608 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
609 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
612 # Lists tags from the local repository.
613 # Accepts the same positional parameters as __git_heads() above.
616 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
618 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
619 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
622 # Lists refs from the local (by default) or from a remote repository.
623 # It accepts 0, 1 or 2 arguments:
624 # 1: The remote to list refs from (optional; ignored, if set but empty).
625 # Can be the name of a configured remote, a path, or a URL.
626 # 2: In addition to local refs, list unique branches from refs/remotes/ for
627 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
628 # 3: A prefix to be added to each listed ref (optional).
629 # 4: List only refs matching this word (optional; list all refs if unset or
631 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
634 # Use __git_complete_refs() instead.
637 local i hash dir track="${2-}"
638 local list_refs_from=path remote="${1-}"
640 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
642 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
645 dir="$__git_repo_path"
647 if [ -z "$remote" ]; then
648 if [ -z "$dir" ]; then
652 if __git_is_configured_remote "$remote"; then
653 # configured remote takes precedence over a
654 # local directory with the same name
655 list_refs_from=remote
656 elif [ -d "$remote/.git" ]; then
658 elif [ -d "$remote" ]; then
665 if [ "$list_refs_from" = path ]; then
666 if [[ "$cur_" == ^* ]]; then
675 refs=("$match*" "$match*/**")
679 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
682 if [ -e "$dir/$i" ]; then
688 format="refname:strip=2"
689 refs=("refs/tags/$match*" "refs/tags/$match*/**"
690 "refs/heads/$match*" "refs/heads/$match*/**"
691 "refs/remotes/$match*" "refs/remotes/$match*/**")
694 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
696 if [ -n "$track" ]; then
697 # employ the heuristic used by git checkout
698 # Try to find a remote branch that matches the completion word
699 # but only output if the branch name is unique
700 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
701 --sort="refname:strip=3" \
702 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
709 __git ls-remote "$remote" "$match*" | \
710 while read -r hash i; do
713 *) echo "$pfx$i$sfx" ;;
718 if [ "$list_refs_from" = remote ]; then
720 $match*) echo "${pfx}HEAD$sfx" ;;
722 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
723 "refs/remotes/$remote/$match*" \
724 "refs/remotes/$remote/$match*/**"
728 $match*) query_symref="HEAD" ;;
730 __git ls-remote "$remote" $query_symref \
731 "refs/tags/$match*" "refs/heads/$match*" \
732 "refs/remotes/$match*" |
733 while read -r hash i; do
736 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
737 *) echo "$pfx$i$sfx" ;; # symbolic refs
745 # Completes refs, short and long, local and remote, symbolic and pseudo.
747 # Usage: __git_complete_refs [<option>]...
748 # --remote=<remote>: The remote to list refs from, can be the name of a
749 # configured remote, a path, or a URL.
750 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
751 # --pfx=<prefix>: A prefix to be added to each ref.
752 # --cur=<word>: The current ref to be completed. Defaults to the current
753 # word to be completed.
754 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
756 __git_complete_refs ()
758 local remote track pfx cur_="$cur" sfx=" "
760 while test $# != 0; do
762 --remote=*) remote="${1##--remote=}" ;;
763 --track) track="yes" ;;
764 --pfx=*) pfx="${1##--pfx=}" ;;
765 --cur=*) cur_="${1##--cur=}" ;;
766 --sfx=*) sfx="${1##--sfx=}" ;;
772 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
775 # __git_refs2 requires 1 argument (to pass to __git_refs)
776 # Deprecated: use __git_complete_fetch_refspecs() instead.
780 for i in $(__git_refs "$1"); do
785 # Completes refspecs for fetching from a remote repository.
786 # 1: The remote repository.
787 # 2: A prefix to be added to each listed refspec (optional).
788 # 3: The ref to be completed as a refspec instead of the current word to be
789 # completed (optional)
790 # 4: A suffix to be appended to each listed refspec instead of the default
792 __git_complete_fetch_refspecs ()
794 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
797 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
803 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
804 __git_refs_remotes ()
807 __git ls-remote "$1" 'refs/heads/*' | \
808 while read -r hash i; do
809 echo "$i:refs/remotes/$1/${i#refs/heads/}"
816 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
820 # Returns true if $1 matches the name of a configured remote, false otherwise.
821 __git_is_configured_remote ()
824 for remote in $(__git_remotes); do
825 if [ "$remote" = "$1" ]; then
832 __git_list_merge_strategies ()
834 LANG=C LC_ALL=C git merge -s help 2>&1 |
835 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
844 __git_merge_strategies=
845 # 'git merge -s help' (and thus detection of the merge strategy
846 # list) fails, unfortunately, if run outside of any git working
847 # tree. __git_merge_strategies is set to the empty string in
848 # that case, and the detection will be repeated the next time it
850 __git_compute_merge_strategies ()
852 test -n "$__git_merge_strategies" ||
853 __git_merge_strategies=$(__git_list_merge_strategies)
856 __git_merge_strategy_options="ours theirs subtree subtree= patience
857 histogram diff-algorithm= ignore-space-change ignore-all-space
858 ignore-space-at-eol renormalize no-renormalize no-renames
859 find-renames find-renames= rename-threshold="
861 __git_complete_revlist_file ()
863 local dequoted_word pfx ls ref cur_="$cur"
872 __git_dequote "$cur_"
874 case "$dequoted_word" in
876 pfx="${dequoted_word%/*}"
877 cur_="${dequoted_word##*/}"
882 cur_="$dequoted_word"
887 case "$COMP_WORDBREAKS" in
889 *) pfx="$ref:$pfx" ;;
892 __gitcomp_file "$(__git ls-tree "$ls" \
898 pfx="${cur_%...*}..."
900 __git_complete_refs --pfx="$pfx" --cur="$cur_"
905 __git_complete_refs --pfx="$pfx" --cur="$cur_"
913 __git_complete_file ()
915 __git_complete_revlist_file
918 __git_complete_revlist ()
920 __git_complete_revlist_file
923 __git_complete_remote_or_refspec ()
925 local cur_="$cur" cmd="${words[1]}"
926 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
927 if [ "$cmd" = "remote" ]; then
930 while [ $c -lt $cword ]; do
933 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
934 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
937 push) no_complete_refspec=1 ;;
944 --multiple) no_complete_refspec=1; break ;;
946 *) remote="$i"; break ;;
950 if [ -z "$remote" ]; then
951 __gitcomp_nl "$(__git_remotes)"
954 if [ $no_complete_refspec = 1 ]; then
957 [ "$remote" = "." ] && remote=
960 case "$COMP_WORDBREAKS" in
962 *) pfx="${cur_%%:*}:" ;;
974 if [ $lhs = 1 ]; then
975 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
977 __git_complete_refs --pfx="$pfx" --cur="$cur_"
981 if [ $lhs = 1 ]; then
982 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
984 __git_complete_refs --pfx="$pfx" --cur="$cur_"
988 if [ $lhs = 1 ]; then
989 __git_complete_refs --pfx="$pfx" --cur="$cur_"
991 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
997 __git_complete_strategy ()
999 __git_compute_merge_strategies
1002 __gitcomp "$__git_merge_strategies"
1006 __gitcomp "$__git_merge_strategy_options"
1012 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1015 --strategy-option=*)
1016 __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1024 __git_compute_all_commands ()
1026 test -n "$__git_all_commands" ||
1027 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1030 # Lists all set config variables starting with the given section prefix,
1031 # with the prefix removed.
1032 __git_get_config_variables ()
1034 local section="$1" i IFS=$'\n'
1035 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1036 echo "${i#$section.}"
1040 __git_pretty_aliases ()
1042 __git_get_config_variables "pretty"
1045 # __git_aliased_command requires 1 argument
1046 __git_aliased_command ()
1048 local word cmdline=$(__git config --get "alias.$1")
1049 for word in $cmdline; do
1055 \!*) : shell command alias ;;
1057 *=*) : setting env ;;
1058 git) : git itself ;;
1059 \(\)) : skip parens of shell function definition ;;
1060 {) : skip start of shell helper function ;;
1061 :) : skip null command ;;
1062 \'*) : skip opening quote after sh -c ;;
1070 # __git_find_on_cmdline requires 1 argument
1071 __git_find_on_cmdline ()
1073 local word subcommand c=1
1074 while [ $c -lt $cword ]; do
1076 for subcommand in $1; do
1077 if [ "$subcommand" = "$word" ]; then
1086 # Echo the value of an option set on the command line or config
1088 # $1: short option name
1089 # $2: long option name including =
1090 # $3: list of possible values
1091 # $4: config string (optional)
1094 # result="$(__git_get_option_value "-d" "--do-something=" \
1095 # "yes no" "core.doSomething")"
1097 # result is then either empty (no option set) or "yes" or "no"
1099 # __git_get_option_value requires 3 arguments
1100 __git_get_option_value ()
1102 local c short_opt long_opt val
1103 local result= values config_key word
1111 while [ $c -ge 0 ]; do
1113 for val in $values; do
1114 if [ "$short_opt$val" = "$word" ] ||
1115 [ "$long_opt$val" = "$word" ]; then
1123 if [ -n "$config_key" ] && [ -z "$result" ]; then
1124 result="$(__git config "$config_key")"
1130 __git_has_doubledash ()
1133 while [ $c -lt $cword ]; do
1134 if [ "--" = "${words[c]}" ]; then
1142 # Try to count non option arguments passed on the command line for the
1143 # specified git command.
1144 # When options are used, it is necessary to use the special -- option to
1145 # tell the implementation were non option arguments begin.
1146 # XXX this can not be improved, since options can appear everywhere, as
1150 # __git_count_arguments requires 1 argument: the git command executed.
1151 __git_count_arguments ()
1155 # Skip "git" (first argument)
1156 for ((i=1; i < ${#words[@]}; i++)); do
1161 # Good; we can assume that the following are only non
1166 # Skip the specified git command and discard git
1179 __git_whitespacelist="nowarn warn error error-all fix"
1180 __git_patchformat="mbox stgit stgit-series hg mboxrd"
1181 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1185 __git_find_repo_path
1186 if [ -d "$__git_repo_path"/rebase-apply ]; then
1187 __gitcomp "$__git_am_inprogress_options"
1192 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1196 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1200 __gitcomp_builtin am "" \
1201 "$__git_am_inprogress_options"
1210 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1214 __gitcomp_builtin apply
1223 __gitcomp "+x -x" "" "${cur##--chmod=}"
1227 __gitcomp_builtin add
1231 local complete_opt="--others --modified --directory --no-empty-directory"
1232 if test -n "$(__git_find_on_cmdline "-u --update")"
1234 complete_opt="--modified"
1236 __git_complete_index_file "$complete_opt"
1243 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1247 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1252 --format= --list --verbose
1253 --prefix= --remote= --exec= --output
1263 __git_has_doubledash && return
1265 local subcommands="start bad good skip reset visualize replay log run"
1266 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1267 if [ -z "$subcommand" ]; then
1268 __git_find_repo_path
1269 if [ -f "$__git_repo_path"/BISECT_START ]; then
1270 __gitcomp "$subcommands"
1272 __gitcomp "replay start"
1277 case "$subcommand" in
1278 bad|good|reset|skip|start)
1286 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1290 local i c=1 only_local_ref="n" has_r="n"
1292 while [ $c -lt $cword ]; do
1295 -d|--delete|-m|--move) only_local_ref="y" ;;
1296 -r|--remotes) has_r="y" ;;
1302 --set-upstream-to=*)
1303 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1306 __gitcomp_builtin branch
1309 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1310 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1320 local cmd="${words[2]}"
1323 __gitcomp "create list-heads verify unbundle"
1326 # looking for a file
1331 __git_complete_revlist
1340 __git_has_doubledash && return
1344 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1347 __gitcomp_builtin checkout
1350 # check if --track, --no-track, or --no-guess was specified
1351 # if so, disable DWIM mode
1352 local flags="--track --no-track --no-guess" track_opt="--track"
1353 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1354 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1357 __git_complete_refs $track_opt
1362 __git_cherry_pick_inprogress_options="--continue --quit --abort"
1366 __git_find_repo_path
1367 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1368 __gitcomp "$__git_cherry_pick_inprogress_options"
1372 __git_complete_strategy && return
1376 __gitcomp_builtin cherry-pick "" \
1377 "$__git_cherry_pick_inprogress_options"
1389 __gitcomp_builtin clean
1394 # XXX should we check for -x option ?
1395 __git_complete_index_file "--others --directory"
1402 __gitcomp_builtin clone
1408 __git_untracked_file_modes="all no normal"
1421 __gitcomp "default scissors strip verbatim whitespace
1422 " "" "${cur##--cleanup=}"
1425 --reuse-message=*|--reedit-message=*|\
1426 --fixup=*|--squash=*)
1427 __git_complete_refs --cur="${cur#*=}"
1430 --untracked-files=*)
1431 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1435 __gitcomp_builtin commit
1439 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1440 __git_complete_index_file "--committable"
1442 # This is the first commit
1443 __git_complete_index_file "--cached"
1451 __gitcomp_builtin describe
1457 __git_diff_algorithms="myers minimal patience histogram"
1459 __git_diff_submodule_formats="diff log short"
1461 __git_diff_common_options="--stat --numstat --shortstat --summary
1462 --patch-with-stat --name-only --name-status --color
1463 --no-color --color-words --no-renames --check
1464 --full-index --binary --abbrev --diff-filter=
1465 --find-copies-harder --ignore-cr-at-eol
1466 --text --ignore-space-at-eol --ignore-space-change
1467 --ignore-all-space --ignore-blank-lines --exit-code
1468 --quiet --ext-diff --no-ext-diff
1469 --no-prefix --src-prefix= --dst-prefix=
1470 --inter-hunk-context=
1471 --patience --histogram --minimal
1472 --raw --word-diff --word-diff-regex=
1473 --dirstat --dirstat= --dirstat-by-file
1474 --dirstat-by-file= --cumulative
1476 --submodule --submodule= --ignore-submodules
1481 __git_has_doubledash && return
1485 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1489 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1493 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1494 --base --ours --theirs --no-index
1495 $__git_diff_common_options
1500 __git_complete_revlist_file
1503 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1504 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc
1510 __git_has_doubledash && return
1514 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1518 __gitcomp_builtin difftool "$__git_diff_common_options
1519 --base --cached --ours --theirs
1520 --pickaxe-all --pickaxe-regex
1526 __git_complete_revlist_file
1529 __git_fetch_recurse_submodules="yes on-demand no"
1534 --recurse-submodules=*)
1535 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1539 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1543 __gitcomp_builtin fetch
1547 __git_complete_remote_or_refspec
1550 __git_format_patch_extra_options="
1551 --full-index --not --all --no-prefix --src-prefix=
1552 --dst-prefix= --notes
1555 _git_format_patch ()
1561 " "" "${cur##--thread=}"
1565 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1569 __git_complete_revlist
1576 __gitcomp_builtin fsck
1587 # Lists matching symbol names from a tag (as in ctags) file.
1588 # 1: List symbol names matching this word.
1589 # 2: The tag file to list symbol names from.
1590 # 3: A prefix to be added to each listed symbol name (optional).
1591 # 4: A suffix to be appended to each listed symbol name (optional).
1592 __git_match_ctag () {
1593 awk -v pfx="${3-}" -v sfx="${4-}" "
1594 /^${1//\//\\/}/ { print pfx \$1 sfx }
1598 # Complete symbol names from a tag file.
1599 # Usage: __git_complete_symbol [<option>]...
1600 # --tags=<file>: The tag file to list symbol names from instead of the
1602 # --pfx=<prefix>: A prefix to be added to each symbol name.
1603 # --cur=<word>: The current symbol name to be completed. Defaults to
1604 # the current word to be completed.
1605 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1606 # of the default space.
1607 __git_complete_symbol () {
1608 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1610 while test $# != 0; do
1612 --tags=*) tags="${1##--tags=}" ;;
1613 --pfx=*) pfx="${1##--pfx=}" ;;
1614 --cur=*) cur_="${1##--cur=}" ;;
1615 --sfx=*) sfx="${1##--sfx=}" ;;
1621 if test -r "$tags"; then
1622 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1628 __git_has_doubledash && return
1632 __gitcomp_builtin grep
1637 case "$cword,$prev" in
1639 __git_complete_symbol && return
1650 __gitcomp_builtin help
1654 if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
1656 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
1658 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1667 false true umask group all world everybody
1668 " "" "${cur##--shared=}"
1672 __gitcomp_builtin init
1682 __gitcomp_builtin ls-files
1687 # XXX ignore options like --modified and always suggest all cached
1689 __git_complete_index_file "--cached"
1696 __gitcomp_builtin ls-remote
1700 __gitcomp_nl "$(__git_remotes)"
1707 __gitcomp_builtin ls-tree
1715 # Options that go well for log, shortlog and gitk
1716 __git_log_common_options="
1718 --branches --tags --remotes
1719 --first-parent --merges --no-merges
1721 --max-age= --since= --after=
1722 --min-age= --until= --before=
1723 --min-parents= --max-parents=
1724 --no-min-parents --no-max-parents
1726 # Options that go well for log and gitk (not shortlog)
1727 __git_log_gitk_options="
1728 --dense --sparse --full-history
1729 --simplify-merges --simplify-by-decoration
1730 --left-right --notes --no-notes
1732 # Options that go well for log and shortlog (not gitk)
1733 __git_log_shortlog_options="
1734 --author= --committer= --grep=
1735 --all-match --invert-grep
1738 __git_log_pretty_formats="oneline short medium full fuller email raw format: mboxrd"
1739 __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default raw unix format:"
1743 __git_has_doubledash && return
1744 __git_find_repo_path
1747 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1750 case "$prev,$cur" in
1752 return # fall back to Bash filename completion
1755 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1759 __git_complete_symbol
1764 --pretty=*|--format=*)
1765 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1770 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1774 __gitcomp "full short no" "" "${cur##--decorate=}"
1778 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1782 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1787 $__git_log_common_options
1788 $__git_log_shortlog_options
1789 $__git_log_gitk_options
1790 --root --topo-order --date-order --reverse
1791 --follow --full-diff
1792 --abbrev-commit --abbrev=
1793 --relative-date --date=
1794 --pretty= --format= --oneline
1799 --decorate --decorate=
1801 --parents --children
1803 $__git_diff_common_options
1804 --pickaxe-all --pickaxe-regex
1809 return # fall back to Bash filename completion
1812 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1816 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1820 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1824 __git_complete_revlist
1829 __git_complete_strategy && return
1833 __gitcomp_builtin merge
1843 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1847 __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
1857 __gitcomp_builtin merge-base
1868 __gitcomp_builtin mv
1873 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1874 # We need to show both cached and untracked files (including
1875 # empty directories) since this may not be the last argument.
1876 __git_complete_index_file "--cached --others --directory"
1878 __git_complete_index_file "--cached"
1884 local subcommands='add append copy edit get-ref list merge prune remove show'
1885 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1887 case "$subcommand,$cur" in
1889 __gitcomp_builtin notes
1897 __gitcomp "$subcommands --ref"
1901 *,--reuse-message=*|*,--reedit-message=*)
1902 __git_complete_refs --cur="${cur#*=}"
1905 __gitcomp_builtin notes_$subcommand
1908 # this command does not take a ref, do not complete it
1924 __git_complete_strategy && return
1927 --recurse-submodules=*)
1928 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1932 __gitcomp_builtin pull
1937 __git_complete_remote_or_refspec
1940 __git_push_recurse_submodules="check on-demand only"
1942 __git_complete_force_with_lease ()
1950 __git_complete_refs --cur="${cur_#*:}"
1953 __git_complete_refs --cur="$cur_"
1962 __gitcomp_nl "$(__git_remotes)"
1965 --recurse-submodules)
1966 __gitcomp "$__git_push_recurse_submodules"
1972 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1975 --recurse-submodules=*)
1976 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1979 --force-with-lease=*)
1980 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1984 __gitcomp_builtin push
1988 __git_complete_remote_or_refspec
1996 --creation-factor= --no-dual-color
1997 $__git_diff_common_options
2002 __git_complete_revlist
2007 __git_find_repo_path
2008 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2009 __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
2011 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2012 [ -d "$__git_repo_path"/rebase-merge ]; then
2013 __gitcomp "--continue --skip --abort --quit --show-current-patch"
2016 __git_complete_strategy && return
2019 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2024 --onto --merge --strategy --interactive
2025 --rebase-merges --preserve-merges --stat --no-stat
2026 --committer-date-is-author-date --ignore-date
2027 --ignore-whitespace --whitespace=
2028 --autosquash --no-autosquash
2029 --fork-point --no-fork-point
2030 --autostash --no-autostash
2031 --verify --no-verify
2032 --keep-empty --root --force-rebase --no-ff
2044 local subcommands="show delete expire"
2045 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2047 if [ -z "$subcommand" ]; then
2048 __gitcomp "$subcommands"
2054 __git_send_email_confirm_options="always never auto cc compose"
2055 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2060 --to|--cc|--bcc|--from)
2061 __gitcomp "$(__git send-email --dump-aliases)"
2069 $__git_send_email_confirm_options
2070 " "" "${cur##--confirm=}"
2075 $__git_send_email_suppresscc_options
2076 " "" "${cur##--suppress-cc=}"
2080 --smtp-encryption=*)
2081 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2087 " "" "${cur##--thread=}"
2090 --to=*|--cc=*|--bcc=*|--from=*)
2091 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2095 __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
2096 --compose --confirm= --dry-run --envelope-sender
2098 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2099 --no-suppress-from --no-thread --quiet --reply-to
2100 --signed-off-by-cc --smtp-pass --smtp-server
2101 --smtp-server-port --smtp-encryption= --smtp-user
2102 --subject --suppress-cc= --suppress-from --thread --to
2103 --validate --no-validate
2104 $__git_format_patch_extra_options"
2108 __git_complete_revlist
2119 local untracked_state
2122 --ignore-submodules=*)
2123 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2126 --untracked-files=*)
2127 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2132 always never auto column row plain dense nodense
2133 " "" "${cur##--column=}"
2137 __gitcomp_builtin status
2142 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2143 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2145 case "$untracked_state" in
2147 # --ignored option does not matter
2151 complete_opt="--cached --directory --no-empty-directory --others"
2153 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2154 complete_opt="$complete_opt --ignored --exclude=*"
2159 __git_complete_index_file "$complete_opt"
2162 __git_config_get_set_variables ()
2164 local prevword word config_file= c=$cword
2165 while [ $c -gt 1 ]; do
2168 --system|--global|--local|--file=*)
2173 config_file="$word $prevword"
2181 __git config $config_file --name-only --list
2185 __git_compute_config_vars ()
2187 test -n "$__git_config_vars" ||
2188 __git_config_vars="$(git help --config-for-completion | sort | uniq)"
2195 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2198 varname="$(echo "$prev" |tr A-Z a-z)"
2202 branch.*.remote|branch.*.pushremote)
2203 __gitcomp_nl "$(__git_remotes)"
2211 __gitcomp "false true merges preserve interactive"
2215 __gitcomp_nl "$(__git_remotes)"
2219 local remote="${prev#remote.}"
2220 remote="${remote%.fetch}"
2221 if [ -z "$cur" ]; then
2222 __gitcomp_nl "refs/heads/" "" "" ""
2225 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2229 local remote="${prev#remote.}"
2230 remote="${remote%.push}"
2231 __gitcomp_nl "$(__git for-each-ref \
2232 --format='%(refname):%(refname)' refs/heads)"
2235 pull.twohead|pull.octopus)
2236 __git_compute_merge_strategies
2237 __gitcomp "$__git_merge_strategies"
2240 color.branch|color.diff|color.interactive|\
2241 color.showbranch|color.status|color.ui)
2242 __gitcomp "always never auto"
2246 __gitcomp "false true"
2251 normal black red green yellow blue magenta cyan white
2252 bold dim ul blink reverse
2257 __gitcomp "$__git_diff_submodule_formats"
2261 __gitcomp "man info web html"
2265 __gitcomp "$__git_log_date_formats"
2268 sendemail.aliasfiletype)
2269 __gitcomp "mutt mailrc pine elm gnus"
2273 __gitcomp "$__git_send_email_confirm_options"
2276 sendemail.suppresscc)
2277 __gitcomp "$__git_send_email_suppresscc_options"
2280 sendemail.transferencoding)
2281 __gitcomp "7bit 8bit quoted-printable base64"
2284 --get|--get-all|--unset|--unset-all)
2285 __gitcomp_nl "$(__git_config_get_set_variables)"
2294 __gitcomp_builtin config
2298 local pfx="${cur%.*}." cur_="${cur##*.}"
2299 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_"
2303 local pfx="${cur%.*}." cur_="${cur#*.}"
2304 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2305 __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_"
2309 local pfx="${cur%.*}." cur_="${cur##*.}"
2311 argPrompt cmd confirm needsFile noConsole noRescan
2312 prompt revPrompt revUnmerged title
2317 local pfx="${cur%.*}." cur_="${cur##*.}"
2318 __gitcomp "cmd path" "$pfx" "$cur_"
2322 local pfx="${cur%.*}." cur_="${cur##*.}"
2323 __gitcomp "cmd path" "$pfx" "$cur_"
2327 local pfx="${cur%.*}." cur_="${cur##*.}"
2328 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2332 local pfx="${cur%.*}." cur_="${cur#*.}"
2333 __git_compute_all_commands
2334 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2338 local pfx="${cur%.*}." cur_="${cur##*.}"
2340 url proxy fetch push mirror skipDefaultUpdate
2341 receivepack uploadpack tagOpt pushurl
2346 local pfx="${cur%.*}." cur_="${cur#*.}"
2347 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2348 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_"
2352 local pfx="${cur%.*}." cur_="${cur##*.}"
2353 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2357 __git_compute_config_vars
2358 __gitcomp "$__git_config_vars"
2361 __git_compute_config_vars
2362 __gitcomp "$(echo "$__git_config_vars" | sed 's/\.[^ ]*/./g')"
2369 add rename remove set-head set-branches
2370 get-url set-url show prune update
2372 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2373 if [ -z "$subcommand" ]; then
2376 __gitcomp_builtin remote
2379 __gitcomp "$subcommands"
2385 case "$subcommand,$cur" in
2387 __gitcomp_builtin remote_add
2392 __gitcomp_builtin remote_set-head
2395 __gitcomp_builtin remote_set-branches
2397 set-head,*|set-branches,*)
2398 __git_complete_remote_or_refspec
2401 __gitcomp_builtin remote_update
2404 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
2407 __gitcomp_builtin remote_set-url
2410 __gitcomp_builtin remote_get-url
2413 __gitcomp_builtin remote_prune
2416 __gitcomp_nl "$(__git_remotes)"
2425 __gitcomp "short medium long" "" "${cur##--format=}"
2429 __gitcomp_builtin replace
2438 local subcommands="clear forget diff remaining status gc"
2439 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2440 if test -z "$subcommand"
2442 __gitcomp "$subcommands"
2449 __git_has_doubledash && return
2453 __gitcomp_builtin reset
2460 __git_revert_inprogress_options="--continue --quit --abort"
2464 __git_find_repo_path
2465 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2466 __gitcomp "$__git_revert_inprogress_options"
2469 __git_complete_strategy && return
2472 __gitcomp_builtin revert "" \
2473 "$__git_revert_inprogress_options"
2484 __gitcomp_builtin rm
2489 __git_complete_index_file "--cached"
2494 __git_has_doubledash && return
2499 $__git_log_common_options
2500 $__git_log_shortlog_options
2501 --numbered --summary --email
2506 __git_complete_revlist
2511 __git_has_doubledash && return
2514 --pretty=*|--format=*)
2515 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2520 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2524 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2528 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2530 $__git_diff_common_options
2535 __git_complete_revlist_file
2542 __gitcomp_builtin show-branch
2546 __git_complete_revlist
2551 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2552 local subcommands='push list show apply clear drop pop create branch'
2553 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
2554 if [ -n "$(__git_find_on_cmdline "-p")" ]; then
2557 if [ -z "$subcommand" ]; then
2560 __gitcomp "$save_opts"
2563 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2568 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2569 __gitcomp "$subcommands"
2574 case "$subcommand,$cur" in
2576 __gitcomp "$save_opts --message"
2579 __gitcomp "$save_opts"
2582 __gitcomp "--index --quiet"
2588 __gitcomp "--name-status --oneline --patch-with-stat"
2590 show,--*|branch,--*)
2593 if [ $cword -eq 3 ]; then
2596 __gitcomp_nl "$(__git stash list \
2597 | sed -n -e 's/:.*//p')"
2600 show,*|apply,*|drop,*|pop,*)
2601 __gitcomp_nl "$(__git stash list \
2602 | sed -n -e 's/:.*//p')"
2612 __git_has_doubledash && return
2614 local subcommands="add status init deinit update set-branch summary foreach sync absorbgitdirs"
2615 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2616 if [ -z "$subcommand" ]; then
2622 __gitcomp "$subcommands"
2628 case "$subcommand,$cur" in
2630 __gitcomp "--branch --force --name --reference --depth"
2633 __gitcomp "--cached --recursive"
2636 __gitcomp "--force --all"
2640 --init --remote --no-fetch
2641 --recommend-shallow --no-recommend-shallow
2642 --force --rebase --merge --reference --depth --recursive --jobs
2646 __gitcomp "--default --branch"
2649 __gitcomp "--cached --files --summary-limit"
2651 foreach,--*|sync,--*)
2652 __gitcomp "--recursive"
2662 init fetch clone rebase dcommit log find-rev
2663 set-tree commit-diff info create-ignore propget
2664 proplist show-ignore show-externals branch tag blame
2665 migrate mkdirs reset gc
2667 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2668 if [ -z "$subcommand" ]; then
2669 __gitcomp "$subcommands"
2671 local remote_opts="--username= --config-dir= --no-auth-cache"
2673 --follow-parent --authors-file= --repack=
2674 --no-metadata --use-svm-props --use-svnsync-props
2675 --log-window-size= --no-checkout --quiet
2676 --repack-flags --use-log-author --localtime
2678 --ignore-paths= --include-paths= $remote_opts
2681 --template= --shared= --trunk= --tags=
2682 --branches= --stdlayout --minimize-url
2683 --no-metadata --use-svm-props --use-svnsync-props
2684 --rewrite-root= --prefix= $remote_opts
2687 --edit --rmdir --find-copies-harder --copy-similarity=
2690 case "$subcommand,$cur" in
2692 __gitcomp "--revision= --fetch-all $fc_opts"
2695 __gitcomp "--revision= $fc_opts $init_opts"
2698 __gitcomp "$init_opts"
2702 --merge --strategy= --verbose --dry-run
2703 --fetch-all --no-rebase --commit-url
2704 --revision --interactive $cmt_opts $fc_opts
2708 __gitcomp "--stdin $cmt_opts $fc_opts"
2710 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2711 show-externals,--*|mkdirs,--*)
2712 __gitcomp "--revision="
2716 --limit= --revision= --verbose --incremental
2717 --oneline --show-commit --non-recursive
2718 --authors-file= --color
2723 --merge --verbose --strategy= --local
2724 --fetch-all --dry-run $fc_opts
2728 __gitcomp "--message= --file= --revision= $cmt_opts"
2734 __gitcomp "--dry-run --message --tag"
2737 __gitcomp "--dry-run --message"
2740 __gitcomp "--git-format"
2744 --config-dir= --ignore-paths= --minimize
2745 --no-auth-cache --username=
2749 __gitcomp "--revision= --parent"
2760 while [ $c -lt $cword ]; do
2763 -d|--delete|-v|--verify)
2764 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2779 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2789 __gitcomp_builtin tag
2801 local subcommands="add list lock move prune remove unlock"
2802 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2803 if [ -z "$subcommand" ]; then
2804 __gitcomp "$subcommands"
2806 case "$subcommand,$cur" in
2808 __gitcomp_builtin worktree_add
2811 __gitcomp_builtin worktree_list
2814 __gitcomp_builtin worktree_lock
2817 __gitcomp_builtin worktree_prune
2828 __git_complete_common () {
2833 __gitcomp_builtin "$command"
2838 __git_cmds_with_parseopt_helper=
2839 __git_support_parseopt_helper () {
2840 test -n "$__git_cmds_with_parseopt_helper" ||
2841 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
2843 case " $__git_cmds_with_parseopt_helper " in
2853 __git_complete_command () {
2855 local completion_func="_git_${command//-/_}"
2856 if ! declare -f $completion_func >/dev/null 2>/dev/null &&
2857 declare -f _completion_loader >/dev/null 2>/dev/null
2859 _completion_loader "git-$command"
2861 if declare -f $completion_func >/dev/null 2>/dev/null
2865 elif __git_support_parseopt_helper "$command"
2867 __git_complete_common "$command"
2876 local i c=1 command __git_dir __git_repo_path
2877 local __git_C_args C_args_count=0
2879 while [ $c -lt $cword ]; do
2882 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2883 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2884 --bare) __git_dir="." ;;
2885 --help) command="help"; break ;;
2886 -c|--work-tree|--namespace) ((c++)) ;;
2887 -C) __git_C_args[C_args_count++]=-C
2889 __git_C_args[C_args_count++]="${words[c]}"
2892 *) command="$i"; break ;;
2897 if [ -z "$command" ]; then
2899 --git-dir|-C|--work-tree)
2900 # these need a path argument, let's fall back to
2901 # Bash filename completion
2905 # we don't support completing these options' arguments
2923 --no-replace-objects
2928 if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
2930 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
2932 __gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
2939 __git_complete_command "$command" && return
2941 local expansion=$(__git_aliased_command "$command")
2942 if [ -n "$expansion" ]; then
2944 __git_complete_command "$expansion"
2950 __git_has_doubledash && return
2952 local __git_repo_path
2953 __git_find_repo_path
2956 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2962 $__git_log_common_options
2963 $__git_log_gitk_options
2969 __git_complete_revlist
2972 if [[ -n ${ZSH_VERSION-} ]] &&
2973 # Don't define these functions when sourced from 'git-completion.zsh',
2974 # it has its own implementations.
2975 [[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
2976 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2978 autoload -U +X compinit && compinit
2984 local cur_="${3-$cur}"
2990 local c IFS=$' \t\n'
2998 array[${#array[@]}+1]="$c"
3001 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3012 compadd -Q -- ${=1} && _ret=0
3021 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3024 __gitcomp_file_direct ()
3030 compadd -f -- ${=1} && _ret=0
3039 compadd -p "${2-}" -f -- ${=1} && _ret=0
3044 local _ret=1 cur cword prev
3045 cur=${words[CURRENT]}
3046 prev=${words[CURRENT-1]}
3048 emulate ksh -c __${service}_main
3049 let _ret && _default && _ret=0
3053 compdef _git git gitk
3059 local cur words cword prev
3060 _get_comp_words_by_ref -n =: cur words cword prev
3064 # Setup completion for certain functions defined above by setting common
3065 # variables and workarounds.
3066 # This is NOT a public function; use at your own risk.
3069 local wrapper="__git_wrap${2}"
3070 eval "$wrapper () { __git_func_wrap $2 ; }"
3071 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3072 || complete -o default -o nospace -F $wrapper $1
3075 # wrapper for backwards compatibility
3078 __git_wrap__git_main
3081 # wrapper for backwards compatibility
3084 __git_wrap__gitk_main
3087 __git_complete git __git_main
3088 __git_complete gitk __gitk_main
3090 # The following are necessary only for Cygwin, and only are needed
3091 # when the user has tab-completed the executable name and consequently
3092 # included the '.exe' suffix.
3094 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3095 __git_complete git.exe __git_main