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 # The following function is based on code from:
99 # bash_completion - programmable completion functions for bash 3.2+
101 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
102 # © 2009-2010, Bash Completion Maintainers
103 # <bash-completion-devel@lists.alioth.debian.org>
105 # This program is free software; you can redistribute it and/or modify
106 # it under the terms of the GNU General Public License as published by
107 # the Free Software Foundation; either version 2, or (at your option)
110 # This program is distributed in the hope that it will be useful,
111 # but WITHOUT ANY WARRANTY; without even the implied warranty of
112 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113 # GNU General Public License for more details.
115 # You should have received a copy of the GNU General Public License
116 # along with this program; if not, see <http://www.gnu.org/licenses/>.
118 # The latest version of this software can be obtained here:
120 # http://bash-completion.alioth.debian.org/
124 # This function can be used to access a tokenized list of words
125 # on the command line:
127 # __git_reassemble_comp_words_by_ref '=:'
128 # if test "${words_[cword_-1]}" = -w
133 # The argument should be a collection of characters from the list of
134 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
137 # This is roughly equivalent to going back in time and setting
138 # COMP_WORDBREAKS to exclude those characters. The intent is to
139 # make option types like --date=<type> and <rev>:<path> easy to
140 # recognize by treating each shell word as a single token.
142 # It is best not to set COMP_WORDBREAKS directly because the value is
143 # shared with other completion scripts. By the time the completion
144 # function gets called, COMP_WORDS has already been populated so local
145 # changes to COMP_WORDBREAKS have no effect.
147 # Output: words_, cword_, cur_.
149 __git_reassemble_comp_words_by_ref
()
151 local exclude i j first
152 # Which word separators to exclude?
153 exclude
="${1//[^$COMP_WORDBREAKS]}"
155 if [ -z "$exclude" ]; then
156 words_
=("${COMP_WORDS[@]}")
159 # List of word completion separators has shrunk;
160 # re-assemble words to complete.
161 for ((i
=0, j
=0; i
< ${#COMP_WORDS[@]}; i
++, j
++)); do
162 # Append each nonempty word consisting of just
163 # word separator characters to the current word.
167 [ -n "${COMP_WORDS[$i]}" ] &&
168 # word consists of excluded word separators
169 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
171 # Attach to the previous token,
172 # unless the previous token is the command name.
173 if [ $j -ge 2 ] && [ -n "$first" ]; then
177 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
178 if [ $i = $COMP_CWORD ]; then
181 if (($i < ${#COMP_WORDS[@]} - 1)); then
188 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
189 if [ $i = $COMP_CWORD ]; then
195 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
196 _get_comp_words_by_ref
()
198 local exclude cur_ words_ cword_
199 if [ "$1" = "-n" ]; then
203 __git_reassemble_comp_words_by_ref
"$exclude"
204 cur_
=${words_[cword_]}
205 while [ $# -gt 0 ]; do
211 prev
=${words_[$cword_-1]}
214 words
=("${words_[@]}")
225 # Fills the COMPREPLY array with prefiltered words without any additional
227 # Callers must take care of providing only words that match the current word
228 # to be completed and adding any prefix and/or suffix (trailing space!), if
230 # 1: List of newline-separated matching completion words, complete with
241 local x i
=${#COMPREPLY[@]}
243 if [[ "$x" == "$3"* ]]; then
244 COMPREPLY
[i
++]="$2$x$4"
255 # Generates completion reply, appending a space to possible completion words,
257 # It accepts 1 to 4 arguments:
258 # 1: List of possible completion words.
259 # 2: A prefix to be added to each possible completion word (optional).
260 # 3: Generate possible completion matches for this word (optional).
261 # 4: A suffix to be appended to each possible completion word (optional).
264 local cur_
="${3-$cur}"
270 local c i
=0 IFS
=$
' \t\n'
273 if [[ $c == "$cur_"* ]]; then
278 COMPREPLY
[i
++]="${2-}$c"
285 # Clear the variables caching builtins' options when (re-)sourcing
286 # the completion script.
287 if [[ -n ${ZSH_VERSION-} ]]; then
288 unset $
(set |
sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev
/null
290 unset $
(compgen
-v __gitcomp_builtin_
)
293 # This function is equivalent to
295 # __gitcomp "$(git xxx --git-completion-helper) ..."
297 # except that the output is cached. Accept 1-3 arguments:
298 # 1: the git command to execute, this is also the cache key
299 # 2: extra options to be added on top (e.g. negative forms)
300 # 3: options to be excluded
303 # spaces must be replaced with underscore for multi-word
304 # commands, e.g. "git remote add" becomes remote_add.
309 local var
=__gitcomp_builtin_
"${cmd/-/_}"
311 eval "options=\$$var"
313 if [ -z "$options" ]; then
314 # leading and trailing spaces are significant to make
315 # option removal work correctly.
316 options
=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
318 options
="${options/ $i / }"
320 eval "$var=\"$options\""
326 # Variation of __gitcomp_nl () that appends to the existing list of
327 # completion candidates, COMPREPLY.
328 __gitcomp_nl_append
()
331 __gitcompappend
"$1" "${2-}" "${3-$cur}" "${4- }"
334 # Generates completion reply from newline-separated possible completion words
335 # by appending a space to all of them.
336 # It accepts 1 to 4 arguments:
337 # 1: List of possible completion words, separated by a single newline.
338 # 2: A prefix to be added to each possible completion word (optional).
339 # 3: Generate possible completion matches for this word (optional).
340 # 4: A suffix to be appended to each possible completion word instead of
341 # the default space (optional). If specified but empty, nothing is
346 __gitcomp_nl_append
"$@"
349 # Generates completion reply with compgen from newline-separated possible
350 # completion filenames.
351 # It accepts 1 to 3 arguments:
352 # 1: List of possible completion filenames, separated by a single newline.
353 # 2: A directory prefix to be added to each possible completion filename
355 # 3: Generate possible completion matches for this word (optional).
360 # XXX does not work when the directory prefix contains a tilde,
361 # since tilde expansion is not applied.
362 # This means that COMPREPLY will be empty and Bash default
363 # completion will be used.
364 __gitcompadd
"$1" "${2-}" "${3-$cur}" ""
366 # use a hack to enable file mode in bash < 4
367 compopt
-o filenames
+o nospace
2>/dev
/null ||
368 compgen
-f /non-existing-dir
/ > /dev
/null
371 # Execute 'git ls-files', unless the --committable option is specified, in
372 # which case it runs 'git diff-index' to find out the files that can be
373 # committed. It return paths relative to the directory specified in the first
374 # argument, and using the options specified in the second argument.
375 __git_ls_files_helper
()
377 if [ "$2" == "--committable" ]; then
378 __git
-C "$1" diff-index
--name-only --relative HEAD
380 # NOTE: $2 is not quoted in order to support multiple options
381 __git
-C "$1" ls-files
--exclude-standard $2
386 # __git_index_files accepts 1 or 2 arguments:
387 # 1: Options to pass to ls-files (required).
388 # 2: A directory path (optional).
389 # If provided, only files within the specified directory are listed.
390 # Sub directories are never recursed. Path must have a trailing
394 local root
="${2-.}" file
396 __git_ls_files_helper
"$root" "$1" |
397 cut
-f1 -d/ |
sort |
uniq
400 # Lists branches from the local repository.
401 # 1: A prefix to be added to each listed branch (optional).
402 # 2: List only branches matching this word (optional; list all branches if
404 # 3: A suffix to be appended to each listed branch (optional).
407 local pfx
="${1-}" cur_="${2-}" sfx="${3-}"
409 __git for-each-ref
--format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
410 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
413 # Lists tags from the local repository.
414 # Accepts the same positional parameters as __git_heads() above.
417 local pfx
="${1-}" cur_="${2-}" sfx="${3-}"
419 __git for-each-ref
--format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
420 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
423 # Lists refs from the local (by default) or from a remote repository.
424 # It accepts 0, 1 or 2 arguments:
425 # 1: The remote to list refs from (optional; ignored, if set but empty).
426 # Can be the name of a configured remote, a path, or a URL.
427 # 2: In addition to local refs, list unique branches from refs/remotes/ for
428 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
429 # 3: A prefix to be added to each listed ref (optional).
430 # 4: List only refs matching this word (optional; list all refs if unset or
432 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
435 # Use __git_complete_refs() instead.
438 local i
hash dir track
="${2-}"
439 local list_refs_from
=path remote
="${1-}"
441 local pfx
="${3-}" cur_="${4-$cur}" sfx="${5-}"
443 local fer_pfx
="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
446 dir
="$__git_repo_path"
448 if [ -z "$remote" ]; then
449 if [ -z "$dir" ]; then
453 if __git_is_configured_remote
"$remote"; then
454 # configured remote takes precedence over a
455 # local directory with the same name
456 list_refs_from
=remote
457 elif [ -d "$remote/.git" ]; then
459 elif [ -d "$remote" ]; then
466 if [ "$list_refs_from" = path
]; then
467 if [[ "$cur_" == ^
* ]]; then
476 refs
=("$match*" "$match*/**")
480 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD
; do
483 if [ -e "$dir/$i" ]; then
489 format
="refname:strip=2"
490 refs
=("refs/tags/$match*" "refs/tags/$match*/**"
491 "refs/heads/$match*" "refs/heads/$match*/**"
492 "refs/remotes/$match*" "refs/remotes/$match*/**")
495 __git_dir
="$dir" __git for-each-ref
--format="$fer_pfx%($format)$sfx" \
497 if [ -n "$track" ]; then
498 # employ the heuristic used by git checkout
499 # Try to find a remote branch that matches the completion word
500 # but only output if the branch name is unique
501 __git for-each-ref
--format="$fer_pfx%(refname:strip=3)$sfx" \
502 --sort="refname:strip=3" \
503 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
510 __git ls-remote
"$remote" "$match*" | \
511 while read -r hash i
; do
514 *) echo "$pfx$i$sfx" ;;
519 if [ "$list_refs_from" = remote
]; then
521 $match*) echo "${pfx}HEAD$sfx" ;;
523 __git for-each-ref
--format="$fer_pfx%(refname:strip=3)$sfx" \
524 "refs/remotes/$remote/$match*" \
525 "refs/remotes/$remote/$match*/**"
529 $match*) query_symref
="HEAD" ;;
531 __git ls-remote
"$remote" $query_symref \
532 "refs/tags/$match*" "refs/heads/$match*" \
533 "refs/remotes/$match*" |
534 while read -r hash i
; do
537 refs
/*) echo "$pfx${i#refs/*/}$sfx" ;;
538 *) echo "$pfx$i$sfx" ;; # symbolic refs
546 # Completes refs, short and long, local and remote, symbolic and pseudo.
548 # Usage: __git_complete_refs [<option>]...
549 # --remote=<remote>: The remote to list refs from, can be the name of a
550 # configured remote, a path, or a URL.
551 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
552 # --pfx=<prefix>: A prefix to be added to each ref.
553 # --cur=<word>: The current ref to be completed. Defaults to the current
554 # word to be completed.
555 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
557 __git_complete_refs
()
559 local remote track pfx cur_
="$cur" sfx
=" "
561 while test $# != 0; do
563 --remote=*) remote
="${1##--remote=}" ;;
564 --track) track
="yes" ;;
565 --pfx=*) pfx
="${1##--pfx=}" ;;
566 --cur=*) cur_
="${1##--cur=}" ;;
567 --sfx=*) sfx
="${1##--sfx=}" ;;
573 __gitcomp_direct
"$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
576 # __git_refs2 requires 1 argument (to pass to __git_refs)
577 # Deprecated: use __git_complete_fetch_refspecs() instead.
581 for i
in $
(__git_refs
"$1"); do
586 # Completes refspecs for fetching from a remote repository.
587 # 1: The remote repository.
588 # 2: A prefix to be added to each listed refspec (optional).
589 # 3: The ref to be completed as a refspec instead of the current word to be
590 # completed (optional)
591 # 4: A suffix to be appended to each listed refspec instead of the default
593 __git_complete_fetch_refspecs
()
595 local i remote
="$1" pfx
="${2-}" cur_="${3-$cur}" sfx="${4- }"
598 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
604 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
605 __git_refs_remotes
()
608 __git ls-remote
"$1" 'refs/heads/*' | \
609 while read -r hash i
; do
610 echo "$i:refs/remotes/$1/${i#refs/heads/}"
617 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
621 # Returns true if $1 matches the name of a configured remote, false otherwise.
622 __git_is_configured_remote
()
625 for remote
in $
(__git_remotes
); do
626 if [ "$remote" = "$1" ]; then
633 __git_list_merge_strategies
()
635 LANG
=C LC_ALL
=C git merge
-s help 2>&1 |
636 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
645 __git_merge_strategies
=
646 # 'git merge -s help' (and thus detection of the merge strategy
647 # list) fails, unfortunately, if run outside of any git working
648 # tree. __git_merge_strategies is set to the empty string in
649 # that case, and the detection will be repeated the next time it
651 __git_compute_merge_strategies
()
653 test -n "$__git_merge_strategies" ||
654 __git_merge_strategies
=$
(__git_list_merge_strategies
)
657 __git_complete_revlist_file
()
659 local pfx
ls ref cur_
="$cur"
679 case "$COMP_WORDBREAKS" in
681 *) pfx
="$ref:$pfx" ;;
684 __gitcomp_nl
"$(__git ls-tree "$ls" \
685 | sed '/^100... blob /{
701 pfx
="${cur_%...*}..."
703 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
708 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
717 # __git_complete_index_file requires 1 argument:
718 # 1: the options to pass to ls-file
720 # The exception is --committable, which finds the files appropriate commit.
721 __git_complete_index_file
()
723 local pfx
="" cur_
="$cur"
733 __gitcomp_file
"$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
736 __git_complete_file
()
738 __git_complete_revlist_file
741 __git_complete_revlist
()
743 __git_complete_revlist_file
746 __git_complete_remote_or_refspec
()
748 local cur_
="$cur" cmd
="${words[1]}"
749 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
750 if [ "$cmd" = "remote" ]; then
753 while [ $c -lt $cword ]; do
756 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
757 -d|
--delete) [ "$cmd" = "push" ] && lhs
=0 ;;
760 push
) no_complete_refspec
=1 ;;
768 *) remote
="$i"; break ;;
772 if [ -z "$remote" ]; then
773 __gitcomp_nl
"$(__git_remotes)"
776 if [ $no_complete_refspec = 1 ]; then
779 [ "$remote" = "." ] && remote
=
782 case "$COMP_WORDBREAKS" in
784 *) pfx
="${cur_%%:*}:" ;;
796 if [ $lhs = 1 ]; then
797 __git_complete_fetch_refspecs
"$remote" "$pfx" "$cur_"
799 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
803 if [ $lhs = 1 ]; then
804 __git_complete_refs
--remote="$remote" --pfx="$pfx" --cur="$cur_"
806 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
810 if [ $lhs = 1 ]; then
811 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
813 __git_complete_refs
--remote="$remote" --pfx="$pfx" --cur="$cur_"
819 __git_complete_strategy
()
821 __git_compute_merge_strategies
824 __gitcomp
"$__git_merge_strategies"
829 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
837 __git_compute_all_commands
()
839 test -n "$__git_all_commands" ||
840 __git_all_commands
=$
(git
--list-cmds=main
,others
,alias,nohelpers
)
843 # Lists all set config variables starting with the given section prefix,
844 # with the prefix removed.
845 __git_get_config_variables
()
847 local section
="$1" i IFS
=$
'\n'
848 for i
in $
(__git config
--name-only --get-regexp "^$section\..*"); do
849 echo "${i#$section.}"
853 __git_pretty_aliases
()
855 __git_get_config_variables
"pretty"
858 # __git_aliased_command requires 1 argument
859 __git_aliased_command
()
861 local word cmdline
=$
(__git config
--get "alias.$1")
862 for word
in $cmdline; do
868 \
!*) : shell
command alias ;;
870 *=*) : setting env
;;
872 \
(\
)) : skip parens of shell
function definition
;;
873 {) : skip start of shell helper
function ;;
874 :) : skip null
command ;;
875 \'*) : skip opening quote after sh
-c ;;
883 # __git_find_on_cmdline requires 1 argument
884 __git_find_on_cmdline
()
886 local word subcommand c
=1
887 while [ $c -lt $cword ]; do
889 for subcommand
in $1; do
890 if [ "$subcommand" = "$word" ]; then
899 # Echo the value of an option set on the command line or config
901 # $1: short option name
902 # $2: long option name including =
903 # $3: list of possible values
904 # $4: config string (optional)
907 # result="$(__git_get_option_value "-d" "--do-something=" \
908 # "yes no" "core.doSomething")"
910 # result is then either empty (no option set) or "yes" or "no"
912 # __git_get_option_value requires 3 arguments
913 __git_get_option_value
()
915 local c short_opt long_opt val
916 local result
= values config_key word
924 while [ $c -ge 0 ]; do
926 for val
in $values; do
927 if [ "$short_opt$val" = "$word" ] ||
928 [ "$long_opt$val" = "$word" ]; then
936 if [ -n "$config_key" ] && [ -z "$result" ]; then
937 result
="$(__git config "$config_key")"
943 __git_has_doubledash
()
946 while [ $c -lt $cword ]; do
947 if [ "--" = "${words[c]}" ]; then
955 # Try to count non option arguments passed on the command line for the
956 # specified git command.
957 # When options are used, it is necessary to use the special -- option to
958 # tell the implementation were non option arguments begin.
959 # XXX this can not be improved, since options can appear everywhere, as
963 # __git_count_arguments requires 1 argument: the git command executed.
964 __git_count_arguments
()
968 # Skip "git" (first argument)
969 for ((i
=1; i
< ${#words[@]}; i
++)); do
974 # Good; we can assume that the following are only non
979 # Skip the specified git command and discard git
992 __git_whitespacelist
="nowarn warn error error-all fix"
993 __git_am_inprogress_options
="--skip --continue --resolved --abort --quit --show-current-patch"
998 if [ -d "$__git_repo_path"/rebase-apply
]; then
999 __gitcomp
"$__git_am_inprogress_options"
1004 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1008 __gitcomp_builtin am
"--no-utf8" \
1009 "$__git_am_inprogress_options"
1018 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1022 __gitcomp_builtin apply
1031 __gitcomp_builtin add
1035 local complete_opt
="--others --modified --directory --no-empty-directory"
1036 if test -n "$(__git_find_on_cmdline "-u --update")"
1038 complete_opt
="--modified"
1040 __git_complete_index_file
"$complete_opt"
1047 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
1051 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--remote=}"
1056 --format= --list --verbose
1057 --prefix= --remote= --exec= --output
1067 __git_has_doubledash
&& return
1069 local subcommands
="start bad good skip reset visualize replay log run"
1070 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1071 if [ -z "$subcommand" ]; then
1072 __git_find_repo_path
1073 if [ -f "$__git_repo_path"/BISECT_START
]; then
1074 __gitcomp
"$subcommands"
1076 __gitcomp
"replay start"
1081 case "$subcommand" in
1082 bad|good|
reset|skip|start
)
1092 local i c
=1 only_local_ref
="n" has_r
="n"
1094 while [ $c -lt $cword ]; do
1097 -d|
--delete|
-m|
--move) only_local_ref
="y" ;;
1098 -r|
--remotes) has_r
="y" ;;
1104 --set-upstream-to=*)
1105 __git_complete_refs
--cur="${cur##--set-upstream-to=}"
1108 __gitcomp_builtin branch
"--no-color --no-abbrev
1109 --no-track --no-column
1113 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1114 __gitcomp_direct
"$(__git_heads "" "$cur" " ")"
1124 local cmd
="${words[2]}"
1127 __gitcomp
"create list-heads verify unbundle"
1130 # looking for a file
1135 __git_complete_revlist
1144 __git_has_doubledash
&& return
1148 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1151 __gitcomp_builtin checkout
"--no-track --no-recurse-submodules"
1154 # check if --track, --no-track, or --no-guess was specified
1155 # if so, disable DWIM mode
1156 local flags
="--track --no-track --no-guess" track_opt
="--track"
1157 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1158 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1161 __git_complete_refs
$track_opt
1170 __gitcomp_builtin cherry
1177 __git_cherry_pick_inprogress_options
="--continue --quit --abort"
1181 __git_find_repo_path
1182 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD
]; then
1183 __gitcomp
"$__git_cherry_pick_inprogress_options"
1188 __gitcomp_builtin cherry-pick
"" \
1189 "$__git_cherry_pick_inprogress_options"
1201 __gitcomp_builtin clean
1206 # XXX should we check for -x option ?
1207 __git_complete_index_file
"--others --directory"
1214 __gitcomp_builtin clone
"--no-single-branch"
1220 __git_untracked_file_modes
="all no normal"
1233 __gitcomp
"default scissors strip verbatim whitespace
1234 " "" "${cur##--cleanup=}"
1237 --reuse-message=*|
--reedit-message=*|\
1238 --fixup=*|
--squash=*)
1239 __git_complete_refs
--cur="${cur#*=}"
1242 --untracked-files=*)
1243 __gitcomp
"$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1247 __gitcomp_builtin commit
"--no-edit --verify"
1251 if __git rev-parse
--verify --quiet HEAD
>/dev
/null
; then
1252 __git_complete_index_file
"--committable"
1254 # This is the first commit
1255 __git_complete_index_file
"--cached"
1263 __gitcomp_builtin describe
1269 __git_diff_algorithms
="myers minimal patience histogram"
1271 __git_diff_submodule_formats
="diff log short"
1273 __git_diff_common_options
="--stat --numstat --shortstat --summary
1274 --patch-with-stat --name-only --name-status --color
1275 --no-color --color-words --no-renames --check
1276 --full-index --binary --abbrev --diff-filter=
1277 --find-copies-harder --ignore-cr-at-eol
1278 --text --ignore-space-at-eol --ignore-space-change
1279 --ignore-all-space --ignore-blank-lines --exit-code
1280 --quiet --ext-diff --no-ext-diff
1281 --no-prefix --src-prefix= --dst-prefix=
1282 --inter-hunk-context=
1283 --patience --histogram --minimal
1284 --raw --word-diff --word-diff-regex=
1285 --dirstat --dirstat= --dirstat-by-file
1286 --dirstat-by-file= --cumulative
1288 --submodule --submodule= --ignore-submodules
1293 __git_has_doubledash
&& return
1297 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1301 __gitcomp
"$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1305 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1306 --base --ours --theirs --no-index
1307 $__git_diff_common_options
1312 __git_complete_revlist_file
1315 __git_mergetools_common
="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1316 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1321 __git_has_doubledash
&& return
1325 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1329 __gitcomp_builtin difftool
"$__git_diff_common_options
1330 --base --cached --ours --theirs
1331 --pickaxe-all --pickaxe-regex
1337 __git_complete_revlist_file
1340 __git_fetch_recurse_submodules
="yes on-demand no"
1345 --recurse-submodules=*)
1346 __gitcomp
"$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1350 __gitcomp_builtin fetch
"--no-tags"
1354 __git_complete_remote_or_refspec
1357 __git_format_patch_options
="
1358 --stdout --attach --no-attach --thread --thread= --no-thread
1359 --numbered --start-number --numbered-files --keep-subject --signoff
1360 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1361 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1362 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1363 --output-directory --reroll-count --to= --quiet --notes
1366 _git_format_patch
()
1372 " "" "${cur##--thread=}"
1376 __gitcomp
"$__git_format_patch_options"
1380 __git_complete_revlist
1387 __gitcomp_builtin fsck
"--no-reflogs"
1398 # Lists matching symbol names from a tag (as in ctags) file.
1399 # 1: List symbol names matching this word.
1400 # 2: The tag file to list symbol names from.
1401 # 3: A prefix to be added to each listed symbol name (optional).
1402 # 4: A suffix to be appended to each listed symbol name (optional).
1403 __git_match_ctag
() {
1404 awk -v pfx
="${3-}" -v sfx
="${4-}" "
1405 /^${1//\//\\/}/ { print pfx \$1 sfx }
1409 # Complete symbol names from a tag file.
1410 # Usage: __git_complete_symbol [<option>]...
1411 # --tags=<file>: The tag file to list symbol names from instead of the
1413 # --pfx=<prefix>: A prefix to be added to each symbol name.
1414 # --cur=<word>: The current symbol name to be completed. Defaults to
1415 # the current word to be completed.
1416 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1417 # of the default space.
1418 __git_complete_symbol
() {
1419 local tags
=tags pfx
="" cur_
="${cur-}" sfx
=" "
1421 while test $# != 0; do
1423 --tags=*) tags
="${1##--tags=}" ;;
1424 --pfx=*) pfx
="${1##--pfx=}" ;;
1425 --cur=*) cur_
="${1##--cur=}" ;;
1426 --sfx=*) sfx
="${1##--sfx=}" ;;
1432 if test -r "$tags"; then
1433 __gitcomp_direct
"$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1439 __git_has_doubledash
&& return
1443 __gitcomp_builtin
grep
1448 case "$cword,$prev" in
1450 __git_complete_symbol
&& return
1461 __gitcomp_builtin
help
1465 if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
1467 __gitcomp
"$GIT_TESTING_ALL_COMMAND_LIST $(git --list-cmds=alias,list-guide) gitk"
1469 __gitcomp
"$(git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1478 false true umask group all world everybody
1479 " "" "${cur##--shared=}"
1483 __gitcomp_builtin init
1493 __gitcomp_builtin ls-files
"--no-empty-directory"
1498 # XXX ignore options like --modified and always suggest all cached
1500 __git_complete_index_file
"--cached"
1507 __gitcomp_builtin ls-remote
1511 __gitcomp_nl
"$(__git_remotes)"
1518 __gitcomp_builtin ls-tree
1526 # Options that go well for log, shortlog and gitk
1527 __git_log_common_options
="
1529 --branches --tags --remotes
1530 --first-parent --merges --no-merges
1532 --max-age= --since= --after=
1533 --min-age= --until= --before=
1534 --min-parents= --max-parents=
1535 --no-min-parents --no-max-parents
1537 # Options that go well for log and gitk (not shortlog)
1538 __git_log_gitk_options
="
1539 --dense --sparse --full-history
1540 --simplify-merges --simplify-by-decoration
1541 --left-right --notes --no-notes
1543 # Options that go well for log and shortlog (not gitk)
1544 __git_log_shortlog_options
="
1545 --author= --committer= --grep=
1546 --all-match --invert-grep
1549 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1550 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1554 __git_has_doubledash
&& return
1555 __git_find_repo_path
1558 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1561 case "$prev,$cur" in
1563 return # fall back to Bash filename completion
1566 __git_complete_symbol
--cur="${cur#:}" --sfx=":"
1570 __git_complete_symbol
1575 --pretty=*|
--format=*)
1576 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1581 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1585 __gitcomp
"full short no" "" "${cur##--decorate=}"
1589 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1593 __gitcomp
"$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1598 $__git_log_common_options
1599 $__git_log_shortlog_options
1600 $__git_log_gitk_options
1601 --root --topo-order --date-order --reverse
1602 --follow --full-diff
1603 --abbrev-commit --abbrev=
1604 --relative-date --date=
1605 --pretty= --format= --oneline
1610 --decorate --decorate=
1612 --parents --children
1614 $__git_diff_common_options
1615 --pickaxe-all --pickaxe-regex
1620 return # fall back to Bash filename completion
1623 __git_complete_symbol
--cur="${cur#-L:}" --sfx=":"
1627 __git_complete_symbol
--pfx="-G" --cur="${cur#-G}"
1631 __git_complete_symbol
--pfx="-S" --cur="${cur#-S}"
1635 __git_complete_revlist
1640 __git_complete_strategy
&& return
1644 __gitcomp_builtin merge
"--no-rerere-autoupdate
1645 --no-commit --no-edit --no-ff
1646 --no-log --no-progress
1647 --no-squash --no-stat
1648 --no-verify-signatures
1659 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1663 __gitcomp
"--tool= --prompt --no-prompt"
1673 __gitcomp_builtin merge-base
1684 __gitcomp_builtin
mv
1689 if [ $
(__git_count_arguments
"mv") -gt 0 ]; then
1690 # We need to show both cached and untracked files (including
1691 # empty directories) since this may not be the last argument.
1692 __git_complete_index_file
"--cached --others --directory"
1694 __git_complete_index_file
"--cached"
1700 local subcommands
='add append copy edit get-ref list merge prune remove show'
1701 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1703 case "$subcommand,$cur" in
1705 __gitcomp_builtin notes
1713 __gitcomp
"$subcommands --ref"
1717 *,--reuse-message=*|
*,--reedit-message=*)
1718 __git_complete_refs
--cur="${cur#*=}"
1721 __gitcomp_builtin notes_
$subcommand
1724 # this command does not take a ref, do not complete it
1740 __git_complete_strategy
&& return
1743 --recurse-submodules=*)
1744 __gitcomp
"$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1748 __gitcomp_builtin pull
"--no-autostash --no-commit --no-edit
1749 --no-ff --no-log --no-progress --no-rebase
1750 --no-squash --no-stat --no-tags
1751 --no-verify-signatures"
1756 __git_complete_remote_or_refspec
1759 __git_push_recurse_submodules
="check on-demand only"
1761 __git_complete_force_with_lease
()
1769 __git_complete_refs
--cur="${cur_#*:}"
1772 __git_complete_refs
--cur="$cur_"
1781 __gitcomp_nl
"$(__git_remotes)"
1784 --recurse-submodules)
1785 __gitcomp
"$__git_push_recurse_submodules"
1791 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--repo=}"
1794 --recurse-submodules=*)
1795 __gitcomp
"$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1798 --force-with-lease=*)
1799 __git_complete_force_with_lease
"${cur##--force-with-lease=}"
1803 __gitcomp_builtin push
1807 __git_complete_remote_or_refspec
1812 __git_find_repo_path
1813 if [ -f "$__git_repo_path"/rebase-merge
/interactive
]; then
1814 __gitcomp
"--continue --skip --abort --quit --edit-todo --show-current-patch"
1816 elif [ -d "$__git_repo_path"/rebase-apply
] || \
1817 [ -d "$__git_repo_path"/rebase-merge
]; then
1818 __gitcomp
"--continue --skip --abort --quit --show-current-patch"
1821 __git_complete_strategy
&& return
1824 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1829 --onto --merge --strategy --interactive
1830 --rebase-merges --preserve-merges --stat --no-stat
1831 --committer-date-is-author-date --ignore-date
1832 --ignore-whitespace --whitespace=
1833 --autosquash --no-autosquash
1834 --fork-point --no-fork-point
1835 --autostash --no-autostash
1836 --verify --no-verify
1837 --keep-empty --root --force-rebase --no-ff
1849 local subcommands
="show delete expire"
1850 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1852 if [ -z "$subcommand" ]; then
1853 __gitcomp
"$subcommands"
1859 __git_send_email_confirm_options
="always never auto cc compose"
1860 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1865 --to|
--cc|
--bcc|
--from)
1866 __gitcomp
"$(__git send-email --dump-aliases)"
1874 $__git_send_email_confirm_options
1875 " "" "${cur##--confirm=}"
1880 $__git_send_email_suppresscc_options
1881 " "" "${cur##--suppress-cc=}"
1885 --smtp-encryption=*)
1886 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1892 " "" "${cur##--thread=}"
1895 --to=*|
--cc=*|
--bcc=*|
--from=*)
1896 __gitcomp
"$(__git send-email --dump-aliases)" "" "${cur#--*=}"
1900 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1901 --compose --confirm= --dry-run --envelope-sender
1903 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1904 --no-suppress-from --no-thread --quiet --reply-to
1905 --signed-off-by-cc --smtp-pass --smtp-server
1906 --smtp-server-port --smtp-encryption= --smtp-user
1907 --subject --suppress-cc= --suppress-from --thread --to
1908 --validate --no-validate
1909 $__git_format_patch_options"
1913 __git_complete_revlist
1924 local untracked_state
1927 --ignore-submodules=*)
1928 __gitcomp
"none untracked dirty all" "" "${cur##--ignore-submodules=}"
1931 --untracked-files=*)
1932 __gitcomp
"$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1937 always never auto column row plain dense nodense
1938 " "" "${cur##--column=}"
1942 __gitcomp_builtin status
"--no-column"
1947 untracked_state
="$(__git_get_option_value "-u" "--untracked-files=" \
1948 "$__git_untracked_file_modes" "status.showUntrackedFiles
")"
1950 case "$untracked_state" in
1952 # --ignored option does not matter
1956 complete_opt
="--cached --directory --no-empty-directory --others"
1958 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1959 complete_opt
="$complete_opt --ignored --exclude=*"
1964 __git_complete_index_file
"$complete_opt"
1967 __git_config_get_set_variables
()
1969 local prevword word config_file
= c
=$cword
1970 while [ $c -gt 1 ]; do
1973 --system|
--global|
--local|
--file=*)
1978 config_file
="$word $prevword"
1986 __git config
$config_file --name-only --list
1990 __git_compute_config_vars
()
1992 test -n "$__git_config_vars" ||
1993 __git_config_vars
="$(git help --config-for-completion | sort | uniq)"
1999 branch.
*.remote|branch.
*.pushremote
)
2000 __gitcomp_nl
"$(__git_remotes)"
2008 __gitcomp
"false true merges preserve interactive"
2012 __gitcomp_nl
"$(__git_remotes)"
2016 local remote
="${prev#remote.}"
2017 remote
="${remote%.fetch}"
2018 if [ -z "$cur" ]; then
2019 __gitcomp_nl
"refs/heads/" "" "" ""
2022 __gitcomp_nl
"$(__git_refs_remotes "$remote")"
2026 local remote
="${prev#remote.}"
2027 remote
="${remote%.push}"
2028 __gitcomp_nl
"$(__git for-each-ref \
2029 --format='%(refname):%(refname)' refs/heads)"
2032 pull.twohead|pull.octopus
)
2033 __git_compute_merge_strategies
2034 __gitcomp
"$__git_merge_strategies"
2037 color.branch|color.
diff|color.interactive|\
2038 color.showbranch|color.status|color.ui
)
2039 __gitcomp
"always never auto"
2043 __gitcomp
"false true"
2048 normal black red green yellow blue magenta cyan white
2049 bold dim ul blink reverse
2054 __gitcomp
"log short"
2058 __gitcomp
"man info web html"
2062 __gitcomp
"$__git_log_date_formats"
2065 sendemail.aliasfiletype
)
2066 __gitcomp
"mutt mailrc pine elm gnus"
2070 __gitcomp
"$__git_send_email_confirm_options"
2073 sendemail.suppresscc
)
2074 __gitcomp
"$__git_send_email_suppresscc_options"
2077 sendemail.transferencoding
)
2078 __gitcomp
"7bit 8bit quoted-printable base64"
2081 --get|
--get-all|
--unset|
--unset-all)
2082 __gitcomp_nl
"$(__git_config_get_set_variables)"
2091 __gitcomp_builtin config
2095 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2096 __gitcomp
"remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2100 local pfx
="${cur%.*}." cur_
="${cur#*.}"
2101 __gitcomp_direct
"$(__git_heads "$pfx" "$cur_" ".
")"
2102 __gitcomp_nl_append $
'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2106 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2108 argprompt cmd confirm needsfile noconsole norescan
2109 prompt revprompt revunmerged title
2114 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2115 __gitcomp
"cmd path" "$pfx" "$cur_"
2119 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2120 __gitcomp
"cmd path" "$pfx" "$cur_"
2124 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2125 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur_"
2129 local pfx
="${cur%.*}." cur_
="${cur#*.}"
2130 __git_compute_all_commands
2131 __gitcomp_nl
"$__git_all_commands" "$pfx" "$cur_"
2135 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2137 url proxy fetch push mirror skipDefaultUpdate
2138 receivepack uploadpack tagopt pushurl
2143 local pfx
="${cur%.*}." cur_
="${cur#*.}"
2144 __gitcomp_nl
"$(__git_remotes)" "$pfx" "$cur_" "."
2145 __gitcomp_nl_append
"pushdefault" "$pfx" "$cur_"
2149 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2150 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur_"
2154 __git_compute_config_vars
2155 __gitcomp
"$__git_config_vars"
2161 add rename remove set-head set-branches
2162 get-url set-url show prune update
2164 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2165 if [ -z "$subcommand" ]; then
2168 __gitcomp_builtin remote
2171 __gitcomp
"$subcommands"
2177 case "$subcommand,$cur" in
2179 __gitcomp_builtin remote_add
"--no-tags"
2184 __gitcomp_builtin remote_set-head
2187 __gitcomp_builtin remote_set-branches
2189 set-head
,*|set-branches
,*)
2190 __git_complete_remote_or_refspec
2193 __gitcomp_builtin remote_update
2196 __gitcomp
"$(__git_get_config_variables "remotes
")"
2199 __gitcomp_builtin remote_set-url
2202 __gitcomp_builtin remote_get-url
2205 __gitcomp_builtin remote_prune
2208 __gitcomp_nl
"$(__git_remotes)"
2217 __gitcomp_builtin replace
2226 local subcommands
="clear forget diff remaining status gc"
2227 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2228 if test -z "$subcommand"
2230 __gitcomp
"$subcommands"
2237 __git_has_doubledash
&& return
2241 __gitcomp_builtin
reset
2248 __git_revert_inprogress_options
="--continue --quit --abort"
2252 __git_find_repo_path
2253 if [ -f "$__git_repo_path"/REVERT_HEAD
]; then
2254 __gitcomp
"$__git_revert_inprogress_options"
2259 __gitcomp_builtin revert
"--no-edit" \
2260 "$__git_revert_inprogress_options"
2271 __gitcomp_builtin
rm
2276 __git_complete_index_file
"--cached"
2281 __git_has_doubledash
&& return
2286 $__git_log_common_options
2287 $__git_log_shortlog_options
2288 --numbered --summary --email
2293 __git_complete_revlist
2298 __git_has_doubledash
&& return
2301 --pretty=*|
--format=*)
2302 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2307 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2311 __gitcomp
"$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2315 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2317 $__git_diff_common_options
2322 __git_complete_revlist_file
2329 __gitcomp_builtin show-branch
"--no-color"
2333 __git_complete_revlist
2338 local save_opts
='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2339 local subcommands
='push list show apply clear drop pop create branch'
2340 local subcommand
="$(__git_find_on_cmdline "$subcommands save
")"
2341 if [ -n "$(__git_find_on_cmdline "-p")" ]; then
2344 if [ -z "$subcommand" ]; then
2347 __gitcomp
"$save_opts"
2350 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2355 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2356 __gitcomp
"$subcommands"
2361 case "$subcommand,$cur" in
2363 __gitcomp
"$save_opts --message"
2366 __gitcomp
"$save_opts"
2369 __gitcomp
"--index --quiet"
2374 show
,--*|branch
,--*)
2377 if [ $cword -eq 3 ]; then
2380 __gitcomp_nl
"$(__git stash list \
2381 | sed -n -e 's/:.*//p')"
2384 show
,*|apply
,*|drop
,*|pop
,*)
2385 __gitcomp_nl
"$(__git stash list \
2386 | sed -n -e 's/:.*//p')"
2396 __git_has_doubledash
&& return
2398 local subcommands
="add status init deinit update summary foreach sync"
2399 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2400 if [ -z "$subcommand" ]; then
2406 __gitcomp
"$subcommands"
2412 case "$subcommand,$cur" in
2414 __gitcomp
"--branch --force --name --reference --depth"
2417 __gitcomp
"--cached --recursive"
2420 __gitcomp
"--force --all"
2424 --init --remote --no-fetch
2425 --recommend-shallow --no-recommend-shallow
2426 --force --rebase --merge --reference --depth --recursive --jobs
2430 __gitcomp
"--cached --files --summary-limit"
2432 foreach
,--*|sync
,--*)
2433 __gitcomp
"--recursive"
2443 init fetch clone rebase dcommit log find-rev
2444 set-tree commit-diff info create-ignore propget
2445 proplist show-ignore show-externals branch tag blame
2446 migrate mkdirs reset gc
2448 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2449 if [ -z "$subcommand" ]; then
2450 __gitcomp
"$subcommands"
2452 local remote_opts
="--username= --config-dir= --no-auth-cache"
2454 --follow-parent --authors-file= --repack=
2455 --no-metadata --use-svm-props --use-svnsync-props
2456 --log-window-size= --no-checkout --quiet
2457 --repack-flags --use-log-author --localtime
2459 --ignore-paths= --include-paths= $remote_opts
2462 --template= --shared= --trunk= --tags=
2463 --branches= --stdlayout --minimize-url
2464 --no-metadata --use-svm-props --use-svnsync-props
2465 --rewrite-root= --prefix= $remote_opts
2468 --edit --rmdir --find-copies-harder --copy-similarity=
2471 case "$subcommand,$cur" in
2473 __gitcomp
"--revision= --fetch-all $fc_opts"
2476 __gitcomp
"--revision= $fc_opts $init_opts"
2479 __gitcomp
"$init_opts"
2483 --merge --strategy= --verbose --dry-run
2484 --fetch-all --no-rebase --commit-url
2485 --revision --interactive $cmt_opts $fc_opts
2489 __gitcomp
"--stdin $cmt_opts $fc_opts"
2491 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2492 show-externals
,--*|mkdirs
,--*)
2493 __gitcomp
"--revision="
2497 --limit= --revision= --verbose --incremental
2498 --oneline --show-commit --non-recursive
2499 --authors-file= --color
2504 --merge --verbose --strategy= --local
2505 --fetch-all --dry-run $fc_opts
2509 __gitcomp
"--message= --file= --revision= $cmt_opts"
2515 __gitcomp
"--dry-run --message --tag"
2518 __gitcomp
"--dry-run --message"
2521 __gitcomp
"--git-format"
2525 --config-dir= --ignore-paths= --minimize
2526 --no-auth-cache --username=
2530 __gitcomp
"--revision= --parent"
2541 while [ $c -lt $cword ]; do
2544 -d|
--delete|
-v|
--verify)
2545 __gitcomp_direct
"$(__git_tags "" "$cur" " ")"
2560 __gitcomp_direct
"$(__git_tags "" "$cur" " ")"
2570 __gitcomp_builtin tag
2582 local subcommands
="add list lock move prune remove unlock"
2583 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2584 if [ -z "$subcommand" ]; then
2585 __gitcomp
"$subcommands"
2587 case "$subcommand,$cur" in
2589 __gitcomp_builtin worktree_add
2592 __gitcomp_builtin worktree_list
2595 __gitcomp_builtin worktree_lock
2598 __gitcomp_builtin worktree_prune
2609 __git_complete_common
() {
2614 __gitcomp_builtin
"$command"
2619 __git_cmds_with_parseopt_helper
=
2620 __git_support_parseopt_helper
() {
2621 test -n "$__git_cmds_with_parseopt_helper" ||
2622 __git_cmds_with_parseopt_helper
="$(__git --list-cmds=parseopt)"
2624 case " $__git_cmds_with_parseopt_helper " in
2634 __git_complete_command
() {
2636 local completion_func
="_git_${command//-/_}"
2637 if ! declare -f $completion_func >/dev
/null
2>/dev
/null
&&
2638 declare -f _completion_loader
>/dev
/null
2>/dev
/null
2640 _completion_loader
"git-$command"
2642 if declare -f $completion_func >/dev
/null
2>/dev
/null
2646 elif __git_support_parseopt_helper
"$command"
2648 __git_complete_common
"$command"
2657 local i c
=1 command __git_dir __git_repo_path
2658 local __git_C_args C_args_count
=0
2660 while [ $c -lt $cword ]; do
2663 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2664 --git-dir) ((c
++)) ; __git_dir
="${words[c]}" ;;
2665 --bare) __git_dir
="." ;;
2666 --help) command="help"; break ;;
2667 -c|
--work-tree|
--namespace) ((c
++)) ;;
2668 -C) __git_C_args
[C_args_count
++]=-C
2670 __git_C_args
[C_args_count
++]="${words[c]}"
2673 *) command="$i"; break ;;
2678 if [ -z "$command" ]; then
2680 --git-dir|
-C|
--work-tree)
2681 # these need a path argument, let's fall back to
2682 # Bash filename completion
2686 # we don't support completing these options' arguments
2704 --no-replace-objects
2709 if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
2711 __gitcomp
"$GIT_TESTING_PORCELAIN_COMMAND_LIST"
2713 __gitcomp
"$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
2720 __git_complete_command
"$command" && return
2722 local expansion
=$
(__git_aliased_command
"$command")
2723 if [ -n "$expansion" ]; then
2725 __git_complete_command
"$expansion"
2731 __git_has_doubledash
&& return
2733 local __git_repo_path
2734 __git_find_repo_path
2737 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2743 $__git_log_common_options
2744 $__git_log_gitk_options
2750 __git_complete_revlist
2753 if [[ -n ${ZSH_VERSION-} ]]; then
2754 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2756 autoload
-U +X compinit
&& compinit
2762 local cur_
="${3-$cur}"
2768 local c IFS
=$
' \t\n'
2776 array
[${#array[@]}+1]="$c"
2779 compadd
-Q -S '' -p "${2-}" -a -- array
&& _ret
=0
2790 compadd
-Q -- ${=1} && _ret
=0
2799 compadd
-Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2808 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2813 local _ret=1 cur cword prev
2814 cur=${words[CURRENT]}
2815 prev=${words[CURRENT-1]}
2817 emulate ksh -c __${service}_main
2818 let _ret && _default && _ret=0
2822 compdef _git git gitk
2828 local cur words cword prev
2829 _get_comp_words_by_ref -n =: cur words cword prev
2833 # Setup completion for certain functions defined above by setting common
2834 # variables and workarounds.
2835 # This is NOT a public function; use at your own risk.
2838 local wrapper="__git_wrap
${2}"
2839 eval "$wrapper () { __git_func_wrap
$2 ; }"
2840 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2841 || complete -o default -o nospace -F $wrapper $1
2844 # wrapper for backwards compatibility
2847 __git_wrap__git_main
2850 # wrapper for backwards compatibility
2853 __git_wrap__gitk_main
2856 __git_complete git __git_main
2857 __git_complete gitk __gitk_main
2859 # The following are necessary only for Cygwin, and only are needed
2860 # when the user has tab-completed the executable name and consequently
2861 # included the '.exe' suffix.
2863 if [ Cygwin = "$
(uname
-o 2>/dev
/null
)" ]; then
2864 __git_complete git.exe __git_main