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 case "$COMP_WORDBREAKS" in
34 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
37 # Discovers the path to the git repository taking any '--git-dir=<path>' and
38 # '-C <path>' options into account and stores it in the $__git_repo_path
40 __git_find_repo_path
()
42 if [ -n "$__git_repo_path" ]; then
43 # we already know where it is
47 if [ -n "${__git_C_args-}" ]; then
48 __git_repo_path
="$(git "${__git_C_args[@]}" \
49 ${__git_dir:+--git-dir="$__git_dir"} \
50 rev-parse --absolute-git-dir 2>/dev/null)"
51 elif [ -n "${__git_dir-}" ]; then
52 test -d "$__git_dir" &&
53 __git_repo_path
="$__git_dir"
54 elif [ -n "${GIT_DIR-}" ]; then
55 test -d "${GIT_DIR-}" &&
56 __git_repo_path
="$GIT_DIR"
57 elif [ -d .git
]; then
60 __git_repo_path
="$(git rev-parse --git-dir 2>/dev/null)"
64 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
65 # __gitdir accepts 0 or 1 arguments (i.e., location)
66 # returns location of .git repo
69 if [ -z "${1-}" ]; then
70 __git_find_repo_path ||
return 1
71 echo "$__git_repo_path"
72 elif [ -d "$1/.git" ]; then
79 # Runs git with all the options given as argument, respecting any
80 # '--git-dir=<path>' and '-C <path>' options present on the command line
83 git
${__git_C_args:+"${__git_C_args[@]}"} \
84 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev
/null
87 # The following function is based on code from:
89 # bash_completion - programmable completion functions for bash 3.2+
91 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
92 # © 2009-2010, Bash Completion Maintainers
93 # <bash-completion-devel@lists.alioth.debian.org>
95 # This program is free software; you can redistribute it and/or modify
96 # it under the terms of the GNU General Public License as published by
97 # the Free Software Foundation; either version 2, or (at your option)
100 # This program is distributed in the hope that it will be useful,
101 # but WITHOUT ANY WARRANTY; without even the implied warranty of
102 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103 # GNU General Public License for more details.
105 # You should have received a copy of the GNU General Public License
106 # along with this program; if not, write to the Free Software Foundation,
107 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
109 # The latest version of this software can be obtained here:
111 # http://bash-completion.alioth.debian.org/
115 # This function can be used to access a tokenized list of words
116 # on the command line:
118 # __git_reassemble_comp_words_by_ref '=:'
119 # if test "${words_[cword_-1]}" = -w
124 # The argument should be a collection of characters from the list of
125 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
128 # This is roughly equivalent to going back in time and setting
129 # COMP_WORDBREAKS to exclude those characters. The intent is to
130 # make option types like --date=<type> and <rev>:<path> easy to
131 # recognize by treating each shell word as a single token.
133 # It is best not to set COMP_WORDBREAKS directly because the value is
134 # shared with other completion scripts. By the time the completion
135 # function gets called, COMP_WORDS has already been populated so local
136 # changes to COMP_WORDBREAKS have no effect.
138 # Output: words_, cword_, cur_.
140 __git_reassemble_comp_words_by_ref
()
142 local exclude i j first
143 # Which word separators to exclude?
144 exclude
="${1//[^$COMP_WORDBREAKS]}"
146 if [ -z "$exclude" ]; then
147 words_
=("${COMP_WORDS[@]}")
150 # List of word completion separators has shrunk;
151 # re-assemble words to complete.
152 for ((i
=0, j
=0; i
< ${#COMP_WORDS[@]}; i
++, j
++)); do
153 # Append each nonempty word consisting of just
154 # word separator characters to the current word.
158 [ -n "${COMP_WORDS[$i]}" ] &&
159 # word consists of excluded word separators
160 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
162 # Attach to the previous token,
163 # unless the previous token is the command name.
164 if [ $j -ge 2 ] && [ -n "$first" ]; then
168 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
169 if [ $i = $COMP_CWORD ]; then
172 if (($i < ${#COMP_WORDS[@]} - 1)); then
179 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
180 if [ $i = $COMP_CWORD ]; then
186 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
187 _get_comp_words_by_ref
()
189 local exclude cur_ words_ cword_
190 if [ "$1" = "-n" ]; then
194 __git_reassemble_comp_words_by_ref
"$exclude"
195 cur_
=${words_[cword_]}
196 while [ $# -gt 0 ]; do
202 prev
=${words_[$cword_-1]}
205 words
=("${words_[@]}")
216 # Fills the COMPREPLY array with prefiltered words without any additional
218 # Callers must take care of providing only words that match the current word
219 # to be completed and adding any prefix and/or suffix (trailing space!), if
221 # 1: List of newline-separated matching completion words, complete with
232 local x i
=${#COMPREPLY[@]}
234 if [[ "$x" == "$3"* ]]; then
235 COMPREPLY
[i
++]="$2$x$4"
246 # Generates completion reply, appending a space to possible completion words,
248 # It accepts 1 to 4 arguments:
249 # 1: List of possible completion words.
250 # 2: A prefix to be added to each possible completion word (optional).
251 # 3: Generate possible completion matches for this word (optional).
252 # 4: A suffix to be appended to each possible completion word (optional).
255 local cur_
="${3-$cur}"
261 local c i
=0 IFS
=$
' \t\n'
264 if [[ $c == "$cur_"* ]]; then
269 COMPREPLY
[i
++]="${2-}$c"
276 # Variation of __gitcomp_nl () that appends to the existing list of
277 # completion candidates, COMPREPLY.
278 __gitcomp_nl_append
()
281 __gitcompappend
"$1" "${2-}" "${3-$cur}" "${4- }"
284 # Generates completion reply from newline-separated possible completion words
285 # by appending a space to all of them.
286 # It accepts 1 to 4 arguments:
287 # 1: List of possible completion words, separated by a single newline.
288 # 2: A prefix to be added to each possible completion word (optional).
289 # 3: Generate possible completion matches for this word (optional).
290 # 4: A suffix to be appended to each possible completion word instead of
291 # the default space (optional). If specified but empty, nothing is
296 __gitcomp_nl_append
"$@"
299 # Generates completion reply with compgen from newline-separated possible
300 # completion filenames.
301 # It accepts 1 to 3 arguments:
302 # 1: List of possible completion filenames, separated by a single newline.
303 # 2: A directory prefix to be added to each possible completion filename
305 # 3: Generate possible completion matches for this word (optional).
310 # XXX does not work when the directory prefix contains a tilde,
311 # since tilde expansion is not applied.
312 # This means that COMPREPLY will be empty and Bash default
313 # completion will be used.
314 __gitcompadd
"$1" "${2-}" "${3-$cur}" ""
316 # use a hack to enable file mode in bash < 4
317 compopt
-o filenames
+o nospace
2>/dev
/null ||
318 compgen
-f /non-existing-dir
/ > /dev
/null
321 # Execute 'git ls-files', unless the --committable option is specified, in
322 # which case it runs 'git diff-index' to find out the files that can be
323 # committed. It return paths relative to the directory specified in the first
324 # argument, and using the options specified in the second argument.
325 __git_ls_files_helper
()
327 if [ "$2" == "--committable" ]; then
328 __git
-C "$1" diff-index
--name-only --relative HEAD
330 # NOTE: $2 is not quoted in order to support multiple options
331 __git
-C "$1" ls-files
--exclude-standard $2
336 # __git_index_files accepts 1 or 2 arguments:
337 # 1: Options to pass to ls-files (required).
338 # 2: A directory path (optional).
339 # If provided, only files within the specified directory are listed.
340 # Sub directories are never recursed. Path must have a trailing
344 local root
="${2-.}" file
346 __git_ls_files_helper
"$root" "$1" |
347 while read -r file; do
349 ?
*/*) echo "${file%%/*}" ;;
355 # Lists branches from the local repository.
356 # 1: A prefix to be added to each listed branch (optional).
357 # 2: List only branches matching this word (optional; list all branches if
359 # 3: A suffix to be appended to each listed branch (optional).
362 local pfx
="${1-}" cur_="${2-}" sfx="${3-}"
364 __git for-each-ref
--format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
365 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
368 # Lists tags from the local repository.
369 # Accepts the same positional parameters as __git_heads() above.
372 local pfx
="${1-}" cur_="${2-}" sfx="${3-}"
374 __git for-each-ref
--format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
375 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
378 # Lists refs from the local (by default) or from a remote repository.
379 # It accepts 0, 1 or 2 arguments:
380 # 1: The remote to list refs from (optional; ignored, if set but empty).
381 # Can be the name of a configured remote, a path, or a URL.
382 # 2: In addition to local refs, list unique branches from refs/remotes/ for
383 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
384 # 3: A prefix to be added to each listed ref (optional).
385 # 4: List only refs matching this word (optional; list all refs if unset or
387 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
390 # Use __git_complete_refs() instead.
393 local i
hash dir track
="${2-}"
394 local list_refs_from
=path remote
="${1-}"
396 local pfx
="${3-}" cur_="${4-$cur}" sfx="${5-}"
398 local fer_pfx
="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
401 dir
="$__git_repo_path"
403 if [ -z "$remote" ]; then
404 if [ -z "$dir" ]; then
408 if __git_is_configured_remote
"$remote"; then
409 # configured remote takes precedence over a
410 # local directory with the same name
411 list_refs_from
=remote
412 elif [ -d "$remote/.git" ]; then
414 elif [ -d "$remote" ]; then
421 if [ "$list_refs_from" = path
]; then
422 if [[ "$cur_" == ^
* ]]; then
431 refs
=("$match*" "$match*/**")
435 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
438 if [ -e "$dir/$i" ]; then
444 format
="refname:strip=2"
445 refs
=("refs/tags/$match*" "refs/tags/$match*/**"
446 "refs/heads/$match*" "refs/heads/$match*/**"
447 "refs/remotes/$match*" "refs/remotes/$match*/**")
450 __git_dir
="$dir" __git for-each-ref
--format="$fer_pfx%($format)$sfx" \
452 if [ -n "$track" ]; then
453 # employ the heuristic used by git checkout
454 # Try to find a remote branch that matches the completion word
455 # but only output if the branch name is unique
456 __git for-each-ref
--format="$fer_pfx%(refname:strip=3)$sfx" \
457 --sort="refname:strip=3" \
458 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
465 __git ls-remote
"$remote" "$match*" | \
466 while read -r hash i
; do
469 *) echo "$pfx$i$sfx" ;;
474 if [ "$list_refs_from" = remote
]; then
476 $match*) echo "${pfx}HEAD$sfx" ;;
478 __git for-each-ref
--format="$fer_pfx%(refname:strip=3)$sfx" \
479 "refs/remotes/$remote/$match*" \
480 "refs/remotes/$remote/$match*/**"
484 $match*) query_symref
="HEAD" ;;
486 __git ls-remote
"$remote" $query_symref \
487 "refs/tags/$match*" "refs/heads/$match*" \
488 "refs/remotes/$match*" |
489 while read -r hash i
; do
492 refs
/*) echo "$pfx${i#refs/*/}$sfx" ;;
493 *) echo "$pfx$i$sfx" ;; # symbolic refs
501 # Completes refs, short and long, local and remote, symbolic and pseudo.
503 # Usage: __git_complete_refs [<option>]...
504 # --remote=<remote>: The remote to list refs from, can be the name of a
505 # configured remote, a path, or a URL.
506 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
507 # --pfx=<prefix>: A prefix to be added to each ref.
508 # --cur=<word>: The current ref to be completed. Defaults to the current
509 # word to be completed.
510 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
512 __git_complete_refs
()
514 local remote track pfx cur_
="$cur" sfx
=" "
516 while test $# != 0; do
518 --remote=*) remote
="${1##--remote=}" ;;
519 --track) track
="yes" ;;
520 --pfx=*) pfx
="${1##--pfx=}" ;;
521 --cur=*) cur_
="${1##--cur=}" ;;
522 --sfx=*) sfx
="${1##--sfx=}" ;;
528 __gitcomp_direct
"$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
531 # __git_refs2 requires 1 argument (to pass to __git_refs)
532 # Deprecated: use __git_complete_fetch_refspecs() instead.
536 for i
in $
(__git_refs
"$1"); do
541 # Completes refspecs for fetching from a remote repository.
542 # 1: The remote repository.
543 # 2: A prefix to be added to each listed refspec (optional).
544 # 3: The ref to be completed as a refspec instead of the current word to be
545 # completed (optional)
546 # 4: A suffix to be appended to each listed refspec instead of the default
548 __git_complete_fetch_refspecs
()
550 local i remote
="$1" pfx
="${2-}" cur_="${3-$cur}" sfx="${4- }"
553 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
559 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
560 __git_refs_remotes
()
563 __git ls-remote
"$1" 'refs/heads/*' | \
564 while read -r hash i
; do
565 echo "$i:refs/remotes/$1/${i#refs/heads/}"
572 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
576 # Returns true if $1 matches the name of a configured remote, false otherwise.
577 __git_is_configured_remote
()
580 for remote
in $
(__git_remotes
); do
581 if [ "$remote" = "$1" ]; then
588 __git_list_merge_strategies
()
590 git merge
-s help 2>&1 |
591 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
600 __git_merge_strategies
=
601 # 'git merge -s help' (and thus detection of the merge strategy
602 # list) fails, unfortunately, if run outside of any git working
603 # tree. __git_merge_strategies is set to the empty string in
604 # that case, and the detection will be repeated the next time it
606 __git_compute_merge_strategies
()
608 test -n "$__git_merge_strategies" ||
609 __git_merge_strategies
=$
(__git_list_merge_strategies
)
612 __git_complete_revlist_file
()
614 local pfx
ls ref cur_
="$cur"
634 case "$COMP_WORDBREAKS" in
636 *) pfx
="$ref:$pfx" ;;
639 __gitcomp_nl
"$(__git ls-tree "$ls" \
640 | sed '/^100... blob /{
656 pfx
="${cur_%...*}..."
658 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
663 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
672 # __git_complete_index_file requires 1 argument:
673 # 1: the options to pass to ls-file
675 # The exception is --committable, which finds the files appropriate commit.
676 __git_complete_index_file
()
678 local pfx
="" cur_
="$cur"
688 __gitcomp_file
"$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
691 __git_complete_file
()
693 __git_complete_revlist_file
696 __git_complete_revlist
()
698 __git_complete_revlist_file
701 __git_complete_remote_or_refspec
()
703 local cur_
="$cur" cmd
="${words[1]}"
704 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
705 if [ "$cmd" = "remote" ]; then
708 while [ $c -lt $cword ]; do
711 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
712 -d|
--delete) [ "$cmd" = "push" ] && lhs
=0 ;;
715 push
) no_complete_refspec
=1 ;;
723 *) remote
="$i"; break ;;
727 if [ -z "$remote" ]; then
728 __gitcomp_nl
"$(__git_remotes)"
731 if [ $no_complete_refspec = 1 ]; then
734 [ "$remote" = "." ] && remote
=
737 case "$COMP_WORDBREAKS" in
739 *) pfx
="${cur_%%:*}:" ;;
751 if [ $lhs = 1 ]; then
752 __git_complete_fetch_refspecs
"$remote" "$pfx" "$cur_"
754 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
758 if [ $lhs = 1 ]; then
759 __git_complete_refs
--remote="$remote" --pfx="$pfx" --cur="$cur_"
761 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
765 if [ $lhs = 1 ]; then
766 __git_complete_refs
--pfx="$pfx" --cur="$cur_"
768 __git_complete_refs
--remote="$remote" --pfx="$pfx" --cur="$cur_"
774 __git_complete_strategy
()
776 __git_compute_merge_strategies
779 __gitcomp
"$__git_merge_strategies"
784 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
792 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
794 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
796 git
help -a|
egrep '^ [a-zA-Z0-9]'
800 __git_list_all_commands
()
803 for i
in $
(__git_commands
)
806 *--*) : helper pattern
;;
813 __git_compute_all_commands
()
815 test -n "$__git_all_commands" ||
816 __git_all_commands
=$
(__git_list_all_commands
)
819 __git_list_porcelain_commands
()
822 __git_compute_all_commands
823 for i
in $__git_all_commands
826 *--*) : helper pattern
;;
827 applymbox
) : ask gittus
;;
828 applypatch
) : ask gittus
;;
829 archimport
) : import
;;
830 cat-file
) : plumbing
;;
831 check-attr
) : plumbing
;;
832 check-ignore
) : plumbing
;;
833 check-mailmap
) : plumbing
;;
834 check-ref-format
) : plumbing
;;
835 checkout-index
) : plumbing
;;
836 column) : internal helper
;;
837 commit-tree
) : plumbing
;;
838 count-objects
) : infrequent
;;
839 credential
) : credentials
;;
840 credential-
*) : credentials helper
;;
841 cvsexportcommit
) : export;;
842 cvsimport
) : import
;;
843 cvsserver
) : daemon
;;
845 diff-files
) : plumbing
;;
846 diff-index
) : plumbing
;;
847 diff-tree
) : plumbing
;;
848 fast-import
) : import
;;
849 fast-export
) : export;;
850 fsck-objects
) : plumbing
;;
851 fetch-pack
) : plumbing
;;
852 fmt-merge-msg
) : plumbing
;;
853 for-each-ref
) : plumbing
;;
854 hash-object
) : plumbing
;;
855 http-
*) : transport
;;
856 index-pack
) : plumbing
;;
857 init-db
) : deprecated
;;
858 local-fetch
) : plumbing
;;
859 ls-files
) : plumbing
;;
860 ls-remote
) : plumbing
;;
861 ls-tree
) : plumbing
;;
862 mailinfo
) : plumbing
;;
863 mailsplit
) : plumbing
;;
864 merge-
*) : plumbing
;;
867 pack-objects
) : plumbing
;;
868 pack-redundant
) : plumbing
;;
869 pack-refs
) : plumbing
;;
870 parse-remote
) : plumbing
;;
871 patch-id
) : plumbing
;;
873 prune-packed
) : plumbing
;;
874 quiltimport
) : import
;;
875 read-tree
) : plumbing
;;
876 receive-pack
) : plumbing
;;
877 remote-
*) : transport
;;
879 rev-list
) : plumbing
;;
880 rev-parse
) : plumbing
;;
881 runstatus
) : plumbing
;;
882 sh-setup
) : internal
;;
884 show-ref
) : plumbing
;;
885 send-pack
) : plumbing
;;
886 show-index
) : plumbing
;;
888 stripspace
) : plumbing
;;
889 symbolic-ref
) : plumbing
;;
890 unpack-file
) : plumbing
;;
891 unpack-objects
) : plumbing
;;
892 update-index
) : plumbing
;;
893 update-ref
) : plumbing
;;
894 update-server-info
) : daemon
;;
895 upload-archive
) : plumbing
;;
896 upload-pack
) : plumbing
;;
897 write-tree
) : plumbing
;;
899 verify-pack
) : infrequent
;;
900 verify-tag
) : plumbing
;;
906 __git_porcelain_commands
=
907 __git_compute_porcelain_commands
()
909 test -n "$__git_porcelain_commands" ||
910 __git_porcelain_commands
=$
(__git_list_porcelain_commands
)
913 # Lists all set config variables starting with the given section prefix,
914 # with the prefix removed.
915 __git_get_config_variables
()
917 local section
="$1" i IFS
=$
'\n'
918 for i
in $
(__git config
--name-only --get-regexp "^$section\..*"); do
919 echo "${i#$section.}"
923 __git_pretty_aliases
()
925 __git_get_config_variables
"pretty"
930 __git_get_config_variables
"alias"
933 # __git_aliased_command requires 1 argument
934 __git_aliased_command
()
936 local word cmdline
=$
(__git config
--get "alias.$1")
937 for word
in $cmdline; do
943 \
!*) : shell
command alias ;;
945 *=*) : setting env
;;
947 \
(\
)) : skip parens of shell
function definition
;;
948 {) : skip start of shell helper
function ;;
949 :) : skip null
command ;;
950 \'*) : skip opening quote after sh
-c ;;
958 # __git_find_on_cmdline requires 1 argument
959 __git_find_on_cmdline
()
961 local word subcommand c
=1
962 while [ $c -lt $cword ]; do
964 for subcommand
in $1; do
965 if [ "$subcommand" = "$word" ]; then
974 # Echo the value of an option set on the command line or config
976 # $1: short option name
977 # $2: long option name including =
978 # $3: list of possible values
979 # $4: config string (optional)
982 # result="$(__git_get_option_value "-d" "--do-something=" \
983 # "yes no" "core.doSomething")"
985 # result is then either empty (no option set) or "yes" or "no"
987 # __git_get_option_value requires 3 arguments
988 __git_get_option_value
()
990 local c short_opt long_opt val
991 local result
= values config_key word
999 while [ $c -ge 0 ]; do
1001 for val
in $values; do
1002 if [ "$short_opt$val" = "$word" ] ||
1003 [ "$long_opt$val" = "$word" ]; then
1011 if [ -n "$config_key" ] && [ -z "$result" ]; then
1012 result
="$(__git config "$config_key")"
1018 __git_has_doubledash
()
1021 while [ $c -lt $cword ]; do
1022 if [ "--" = "${words[c]}" ]; then
1030 # Try to count non option arguments passed on the command line for the
1031 # specified git command.
1032 # When options are used, it is necessary to use the special -- option to
1033 # tell the implementation were non option arguments begin.
1034 # XXX this can not be improved, since options can appear everywhere, as
1038 # __git_count_arguments requires 1 argument: the git command executed.
1039 __git_count_arguments
()
1043 # Skip "git" (first argument)
1044 for ((i
=1; i
< ${#words[@]}; i
++)); do
1049 # Good; we can assume that the following are only non
1054 # Skip the specified git command and discard git
1067 __git_whitespacelist
="nowarn warn error error-all fix"
1071 __git_find_repo_path
1072 if [ -d "$__git_repo_path"/rebase-apply
]; then
1073 __gitcomp
"--skip --continue --resolved --abort"
1078 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1083 --3way --committer-date-is-author-date --ignore-date
1084 --ignore-whitespace --ignore-space-change
1085 --interactive --keep --no-utf8 --signoff --utf8
1086 --whitespace= --scissors
1096 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1101 --stat --numstat --summary --check --index
1102 --cached --index-info --reverse --reject --unidiff-zero
1103 --apply --no-add --exclude=
1104 --ignore-whitespace --ignore-space-change
1105 --whitespace= --inaccurate-eof --verbose
1106 --recount --directory=
1117 --interactive --refresh --patch --update --dry-run
1118 --ignore-errors --intent-to-add --force --edit --chmod=
1123 local complete_opt
="--others --modified --directory --no-empty-directory"
1124 if test -n "$(__git_find_on_cmdline "-u --update")"
1126 complete_opt
="--modified"
1128 __git_complete_index_file
"$complete_opt"
1135 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
1139 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--remote=}"
1144 --format= --list --verbose
1145 --prefix= --remote= --exec= --output
1155 __git_has_doubledash
&& return
1157 local subcommands
="start bad good skip reset visualize replay log run"
1158 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1159 if [ -z "$subcommand" ]; then
1160 __git_find_repo_path
1161 if [ -f "$__git_repo_path"/BISECT_START
]; then
1162 __gitcomp
"$subcommands"
1164 __gitcomp
"replay start"
1169 case "$subcommand" in
1170 bad|good|
reset|skip|start
)
1180 local i c
=1 only_local_ref
="n" has_r
="n"
1182 while [ $c -lt $cword ]; do
1185 -d|
--delete|
-m|
--move) only_local_ref
="y" ;;
1186 -r|
--remotes) has_r
="y" ;;
1192 --set-upstream-to=*)
1193 __git_complete_refs
--cur="${cur##--set-upstream-to=}"
1197 --color --no-color --verbose --abbrev= --no-abbrev
1198 --track --no-track --contains --no-contains --merged --no-merged
1199 --set-upstream-to= --edit-description --list
1200 --unset-upstream --delete --move --remotes
1201 --column --no-column --sort= --points-at
1205 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1206 __gitcomp_direct
"$(__git_heads "" "$cur" " ")"
1216 local cmd
="${words[2]}"
1219 __gitcomp
"create list-heads verify unbundle"
1222 # looking for a file
1227 __git_complete_revlist
1236 __git_has_doubledash
&& return
1240 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1244 --quiet --ours --theirs --track --no-track --merge
1245 --conflict= --orphan --patch
1249 # check if --track, --no-track, or --no-guess was specified
1250 # if so, disable DWIM mode
1251 local flags
="--track --no-track --no-guess" track_opt
="--track"
1252 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1255 __git_complete_refs
$track_opt
1267 __git_find_repo_path
1268 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD
]; then
1269 __gitcomp
"--continue --quit --abort"
1274 __gitcomp
"--edit --no-commit --signoff --strategy= --mainline"
1286 __gitcomp
"--dry-run --quiet"
1291 # XXX should we check for -x option ?
1292 __git_complete_index_file
"--others --directory"
1314 --recurse-submodules
1316 --shallow-submodules
1323 __git_untracked_file_modes
="all no normal"
1336 __gitcomp
"default scissors strip verbatim whitespace
1337 " "" "${cur##--cleanup=}"
1340 --reuse-message=*|
--reedit-message=*|\
1341 --fixup=*|
--squash=*)
1342 __git_complete_refs
--cur="${cur#*=}"
1345 --untracked-files=*)
1346 __gitcomp
"$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1351 --all --author= --signoff --verify --no-verify
1353 --amend --include --only --interactive
1354 --dry-run --reuse-message= --reedit-message=
1355 --reset-author --file= --message= --template=
1356 --cleanup= --untracked-files --untracked-files=
1357 --verbose --quiet --fixup= --squash=
1358 --patch --short --date --allow-empty
1363 if __git rev-parse
--verify --quiet HEAD
>/dev
/null
; then
1364 __git_complete_index_file
"--committable"
1366 # This is the first commit
1367 __git_complete_index_file
"--cached"
1376 --all --tags --contains --abbrev= --candidates=
1377 --exact-match --debug --long --match --always --first-parent
1385 __git_diff_algorithms
="myers minimal patience histogram"
1387 __git_diff_submodule_formats
="diff log short"
1389 __git_diff_common_options
="--stat --numstat --shortstat --summary
1390 --patch-with-stat --name-only --name-status --color
1391 --no-color --color-words --no-renames --check
1392 --full-index --binary --abbrev --diff-filter=
1393 --find-copies-harder
1394 --text --ignore-space-at-eol --ignore-space-change
1395 --ignore-all-space --ignore-blank-lines --exit-code
1396 --quiet --ext-diff --no-ext-diff
1397 --no-prefix --src-prefix= --dst-prefix=
1398 --inter-hunk-context=
1399 --patience --histogram --minimal
1400 --raw --word-diff --word-diff-regex=
1401 --dirstat --dirstat= --dirstat-by-file
1402 --dirstat-by-file= --cumulative
1404 --submodule --submodule=
1409 __git_has_doubledash
&& return
1413 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1417 __gitcomp
"$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1421 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1422 --base --ours --theirs --no-index
1423 $__git_diff_common_options
1428 __git_complete_revlist_file
1431 __git_mergetools_common
="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1432 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1437 __git_has_doubledash
&& return
1441 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1445 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1446 --base --ours --theirs
1447 --no-renames --diff-filter= --find-copies-harder
1448 --relative --ignore-submodules
1453 __git_complete_revlist_file
1456 __git_fetch_recurse_submodules
="yes on-demand no"
1458 __git_fetch_options
="
1459 --quiet --verbose --append --upload-pack --force --keep --depth=
1460 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1461 --unshallow --update-shallow
1467 --recurse-submodules=*)
1468 __gitcomp
"$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1472 __gitcomp
"$__git_fetch_options"
1476 __git_complete_remote_or_refspec
1479 __git_format_patch_options
="
1480 --stdout --attach --no-attach --thread --thread= --no-thread
1481 --numbered --start-number --numbered-files --keep-subject --signoff
1482 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1483 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1484 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1485 --output-directory --reroll-count --to= --quiet --notes
1488 _git_format_patch
()
1494 " "" "${cur##--thread=}"
1498 __gitcomp
"$__git_format_patch_options"
1502 __git_complete_revlist
1510 --tags --root --unreachable --cache --no-reflogs --full
1511 --strict --verbose --lost-found --name-objects
1522 __gitcomp
"--prune --aggressive"
1533 # Lists matching symbol names from a tag (as in ctags) file.
1534 # 1: List symbol names matching this word.
1535 # 2: The tag file to list symbol names from.
1536 # 3: A prefix to be added to each listed symbol name (optional).
1537 # 4: A suffix to be appended to each listed symbol name (optional).
1538 __git_match_ctag
() {
1539 awk -v pfx
="${3-}" -v sfx
="${4-}" "
1540 /^${1//\//\\/}/ { print pfx \$1 sfx }
1544 # Complete symbol names from a tag file.
1545 # Usage: __git_complete_symbol [<option>]...
1546 # --tags=<file>: The tag file to list symbol names from instead of the
1548 # --pfx=<prefix>: A prefix to be added to each symbol name.
1549 # --cur=<word>: The current symbol name to be completed. Defaults to
1550 # the current word to be completed.
1551 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1552 # of the default space.
1553 __git_complete_symbol
() {
1554 local tags
=tags pfx
="" cur_
="${cur-}" sfx
=" "
1556 while test $# != 0; do
1558 --tags=*) tags
="${1##--tags=}" ;;
1559 --pfx=*) pfx
="${1##--pfx=}" ;;
1560 --cur=*) cur_
="${1##--cur=}" ;;
1561 --sfx=*) sfx
="${1##--sfx=}" ;;
1567 if test -r "$tags"; then
1568 __gitcomp_direct
"$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1574 __git_has_doubledash
&& return
1580 --text --ignore-case --word-regexp --invert-match
1581 --full-name --line-number
1582 --extended-regexp --basic-regexp --fixed-strings
1585 --files-with-matches --name-only
1586 --files-without-match
1589 --and --or --not --all-match
1590 --break --heading --show-function --function-context
1591 --untracked --no-index
1597 case "$cword,$prev" in
1599 __git_complete_symbol
&& return
1610 __gitcomp
"--all --guides --info --man --web"
1614 __git_compute_all_commands
1615 __gitcomp
"$__git_all_commands $(__git_aliases)
1616 attributes cli core-tutorial cvs-migration
1617 diffcore everyday gitk glossary hooks ignore modules
1618 namespaces repository-layout revisions tutorial tutorial-2
1628 false true umask group all world everybody
1629 " "" "${cur##--shared=}"
1633 __gitcomp
"--quiet --bare --template= --shared --shared="
1643 __gitcomp
"--cached --deleted --modified --others --ignored
1644 --stage --directory --no-empty-directory --unmerged
1645 --killed --exclude= --exclude-from=
1646 --exclude-per-directory= --exclude-standard
1647 --error-unmatch --with-tree= --full-name
1648 --abbrev --ignored --exclude-per-directory
1654 # XXX ignore options like --modified and always suggest all cached
1656 __git_complete_index_file
"--cached"
1663 __gitcomp
"--heads --tags --refs --get-url --symref"
1667 __gitcomp_nl
"$(__git_remotes)"
1675 # Options that go well for log, shortlog and gitk
1676 __git_log_common_options
="
1678 --branches --tags --remotes
1679 --first-parent --merges --no-merges
1681 --max-age= --since= --after=
1682 --min-age= --until= --before=
1683 --min-parents= --max-parents=
1684 --no-min-parents --no-max-parents
1686 # Options that go well for log and gitk (not shortlog)
1687 __git_log_gitk_options
="
1688 --dense --sparse --full-history
1689 --simplify-merges --simplify-by-decoration
1690 --left-right --notes --no-notes
1692 # Options that go well for log and shortlog (not gitk)
1693 __git_log_shortlog_options
="
1694 --author= --committer= --grep=
1695 --all-match --invert-grep
1698 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1699 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1703 __git_has_doubledash
&& return
1704 __git_find_repo_path
1707 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1710 case "$prev,$cur" in
1712 return # fall back to Bash filename completion
1715 __git_complete_symbol
--cur="${cur#:}" --sfx=":"
1719 __git_complete_symbol
1724 --pretty=*|
--format=*)
1725 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1730 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1734 __gitcomp
"full short no" "" "${cur##--decorate=}"
1738 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1742 __gitcomp
"$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1747 $__git_log_common_options
1748 $__git_log_shortlog_options
1749 $__git_log_gitk_options
1750 --root --topo-order --date-order --reverse
1751 --follow --full-diff
1752 --abbrev-commit --abbrev=
1753 --relative-date --date=
1754 --pretty= --format= --oneline
1759 --decorate --decorate=
1761 --parents --children
1763 $__git_diff_common_options
1764 --pickaxe-all --pickaxe-regex
1769 return # fall back to Bash filename completion
1772 __git_complete_symbol
--cur="${cur#-L:}" --sfx=":"
1776 __git_complete_symbol
--pfx="-G" --cur="${cur#-G}"
1780 __git_complete_symbol
--pfx="-S" --cur="${cur#-S}"
1784 __git_complete_revlist
1787 # Common merge options shared by git-merge(1) and git-pull(1).
1788 __git_merge_options
="
1789 --no-commit --no-stat --log --no-log --squash --strategy
1790 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1791 --verify-signatures --no-verify-signatures --gpg-sign
1792 --quiet --verbose --progress --no-progress
1797 __git_complete_strategy
&& return
1801 __gitcomp
"$__git_merge_options
1802 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1812 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1816 __gitcomp
"--tool= --prompt --no-prompt"
1826 __gitcomp
"--octopus --independent --is-ancestor --fork-point"
1837 __gitcomp
"--dry-run"
1842 if [ $
(__git_count_arguments
"mv") -gt 0 ]; then
1843 # We need to show both cached and untracked files (including
1844 # empty directories) since this may not be the last argument.
1845 __git_complete_index_file
"--cached --others --directory"
1847 __git_complete_index_file
"--cached"
1853 __gitcomp
"--tags --all --stdin"
1858 local subcommands
='add append copy edit list prune remove show'
1859 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1861 case "$subcommand,$cur" in
1871 __gitcomp
"$subcommands --ref"
1875 add
,--reuse-message=*|append
,--reuse-message=*|\
1876 add
,--reedit-message=*|append
,--reedit-message=*)
1877 __git_complete_refs
--cur="${cur#*=}"
1880 __gitcomp
'--file= --message= --reedit-message=
1887 __gitcomp
'--dry-run --verbose'
1905 __git_complete_strategy
&& return
1908 --recurse-submodules=*)
1909 __gitcomp
"$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1914 --rebase --no-rebase
1915 $__git_merge_options
1916 $__git_fetch_options
1921 __git_complete_remote_or_refspec
1924 __git_push_recurse_submodules
="check on-demand only"
1926 __git_complete_force_with_lease
()
1934 __git_complete_refs
--cur="${cur_#*:}"
1937 __git_complete_refs
--cur="$cur_"
1946 __gitcomp_nl
"$(__git_remotes)"
1949 --recurse-submodules)
1950 __gitcomp
"$__git_push_recurse_submodules"
1956 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--repo=}"
1959 --recurse-submodules=*)
1960 __gitcomp
"$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1963 --force-with-lease=*)
1964 __git_complete_force_with_lease
"${cur##--force-with-lease=}"
1969 --all --mirror --tags --dry-run --force --verbose
1970 --quiet --prune --delete --follow-tags
1971 --receive-pack= --repo= --set-upstream
1972 --force-with-lease --force-with-lease= --recurse-submodules=
1977 __git_complete_remote_or_refspec
1982 __git_find_repo_path
1983 if [ -f "$__git_repo_path"/rebase-merge
/interactive
]; then
1984 __gitcomp
"--continue --skip --abort --quit --edit-todo"
1986 elif [ -d "$__git_repo_path"/rebase-apply
] || \
1987 [ -d "$__git_repo_path"/rebase-merge
]; then
1988 __gitcomp
"--continue --skip --abort --quit"
1991 __git_complete_strategy
&& return
1994 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1999 --onto --merge --strategy --interactive
2000 --preserve-merges --stat --no-stat
2001 --committer-date-is-author-date --ignore-date
2002 --ignore-whitespace --whitespace=
2003 --autosquash --no-autosquash
2004 --fork-point --no-fork-point
2005 --autostash --no-autostash
2006 --verify --no-verify
2007 --keep-empty --root --force-rebase --no-ff
2018 local subcommands
="show delete expire"
2019 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2021 if [ -z "$subcommand" ]; then
2022 __gitcomp
"$subcommands"
2028 __git_send_email_confirm_options
="always never auto cc compose"
2029 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
2034 --to|
--cc|
--bcc|
--from)
2035 __gitcomp
"$(__git send-email --dump-aliases)"
2043 $__git_send_email_confirm_options
2044 " "" "${cur##--confirm=}"
2049 $__git_send_email_suppresscc_options
2050 " "" "${cur##--suppress-cc=}"
2054 --smtp-encryption=*)
2055 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
2061 " "" "${cur##--thread=}"
2064 --to=*|
--cc=*|
--bcc=*|
--from=*)
2065 __gitcomp
"$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2069 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
2070 --compose --confirm= --dry-run --envelope-sender
2072 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2073 --no-suppress-from --no-thread --quiet
2074 --signed-off-by-cc --smtp-pass --smtp-server
2075 --smtp-server-port --smtp-encryption= --smtp-user
2076 --subject --suppress-cc= --suppress-from --thread --to
2077 --validate --no-validate
2078 $__git_format_patch_options"
2082 __git_complete_revlist
2093 local untracked_state
2096 --ignore-submodules=*)
2097 __gitcomp
"none untracked dirty all" "" "${cur##--ignore-submodules=}"
2100 --untracked-files=*)
2101 __gitcomp
"$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2106 always never auto column row plain dense nodense
2107 " "" "${cur##--column=}"
2112 --short --branch --porcelain --long --verbose
2113 --untracked-files= --ignore-submodules= --ignored
2114 --column= --no-column
2120 untracked_state
="$(__git_get_option_value "-u" "--untracked-files=" \
2121 "$__git_untracked_file_modes" "status.showUntrackedFiles
")"
2123 case "$untracked_state" in
2125 # --ignored option does not matter
2129 complete_opt
="--cached --directory --no-empty-directory --others"
2131 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2132 complete_opt
="$complete_opt --ignored --exclude=*"
2137 __git_complete_index_file
"$complete_opt"
2140 __git_config_get_set_variables
()
2142 local prevword word config_file
= c
=$cword
2143 while [ $c -gt 1 ]; do
2146 --system|
--global|
--local|
--file=*)
2151 config_file
="$word $prevword"
2159 __git config
$config_file --name-only --list
2165 branch.
*.remote|branch.
*.pushremote
)
2166 __gitcomp_nl
"$(__git_remotes)"
2174 __gitcomp
"false true preserve interactive"
2178 __gitcomp_nl
"$(__git_remotes)"
2182 local remote
="${prev#remote.}"
2183 remote
="${remote%.fetch}"
2184 if [ -z "$cur" ]; then
2185 __gitcomp_nl
"refs/heads/" "" "" ""
2188 __gitcomp_nl
"$(__git_refs_remotes "$remote")"
2192 local remote
="${prev#remote.}"
2193 remote
="${remote%.push}"
2194 __gitcomp_nl
"$(__git for-each-ref \
2195 --format='%(refname):%(refname)' refs/heads)"
2198 pull.twohead|pull.octopus
)
2199 __git_compute_merge_strategies
2200 __gitcomp
"$__git_merge_strategies"
2203 color.branch|color.
diff|color.interactive|\
2204 color.showbranch|color.status|color.ui
)
2205 __gitcomp
"always never auto"
2209 __gitcomp
"false true"
2214 normal black red green yellow blue magenta cyan white
2215 bold dim ul blink reverse
2220 __gitcomp
"log short"
2224 __gitcomp
"man info web html"
2228 __gitcomp
"$__git_log_date_formats"
2231 sendemail.aliasesfiletype
)
2232 __gitcomp
"mutt mailrc pine elm gnus"
2236 __gitcomp
"$__git_send_email_confirm_options"
2239 sendemail.suppresscc
)
2240 __gitcomp
"$__git_send_email_suppresscc_options"
2243 sendemail.transferencoding
)
2244 __gitcomp
"7bit 8bit quoted-printable base64"
2247 --get|
--get-all|
--unset|
--unset-all)
2248 __gitcomp_nl
"$(__git_config_get_set_variables)"
2258 --system --global --local --file=
2259 --list --replace-all
2260 --get --get-all --get-regexp
2261 --add --unset --unset-all
2262 --remove-section --rename-section
2268 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2269 __gitcomp
"remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2273 local pfx
="${cur%.*}." cur_
="${cur#*.}"
2274 __gitcomp_direct
"$(__git_heads "$pfx" "$cur_" ".
")"
2275 __gitcomp_nl_append $
'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2279 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2281 argprompt cmd confirm needsfile noconsole norescan
2282 prompt revprompt revunmerged title
2287 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2288 __gitcomp
"cmd path" "$pfx" "$cur_"
2292 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2293 __gitcomp
"cmd path" "$pfx" "$cur_"
2297 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2298 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur_"
2302 local pfx
="${cur%.*}." cur_
="${cur#*.}"
2303 __git_compute_all_commands
2304 __gitcomp_nl
"$__git_all_commands" "$pfx" "$cur_"
2308 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2310 url proxy fetch push mirror skipDefaultUpdate
2311 receivepack uploadpack tagopt pushurl
2316 local pfx
="${cur%.*}." cur_
="${cur#*.}"
2317 __gitcomp_nl
"$(__git_remotes)" "$pfx" "$cur_" "."
2318 __gitcomp_nl_append
"pushdefault" "$pfx" "$cur_"
2322 local pfx
="${cur%.*}." cur_
="${cur##*.}"
2323 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur_"
2329 advice.commitBeforeMerge
2331 advice.implicitIdentity
2332 advice.pushNonFastForward
2333 advice.resolveConflict
2337 apply.ignorewhitespace
2339 branch.autosetupmerge
2340 branch.autosetuprebase
2344 color.branch.current
2349 color.decorate.branch
2350 color.decorate.remoteBranch
2351 color.decorate.stash
2361 color.diff.whitespace
2366 color.grep.linenumber
2369 color.grep.separator
2371 color.interactive.error
2372 color.interactive.header
2373 color.interactive.help
2374 color.interactive.prompt
2379 color.status.changed
2381 color.status.nobranch
2382 color.status.unmerged
2383 color.status.untracked
2384 color.status.updated
2393 core.bigFileThreshold
2396 core.deltaBaseCacheLimit
2401 core.fsyncobjectfiles
2405 core.logAllRefUpdates
2406 core.loosecompression
2409 core.packedGitWindowSize
2411 core.preferSymlinkRefs
2414 core.repositoryFormatVersion
2416 core.sharedRepository
2421 core.warnAmbiguousRefs
2424 diff.autorefreshindex
2426 diff.ignoreSubmodules
2433 diff.suppressBlankEmpty
2439 fetch.recurseSubmodules
2450 format.subjectprefix
2461 gc.reflogexpireunreachable
2465 gitcvs.commitmsgannotation
2466 gitcvs.dbTableNamePrefix
2477 gui.copyblamethreshold
2481 gui.matchtrackingbranch
2482 gui.newbranchtemplate
2483 gui.pruneduringfetch
2484 gui.spellingdictionary
2501 http.sslCertPasswordProtected
2506 i18n.logOutputEncoding
2512 imap.preformattedHTML
2522 interactive.singlekey
2538 mergetool.keepBackup
2539 mergetool.keepTemporaries
2544 notes.rewrite.rebase
2548 pack.deltaCacheLimit
2565 receive.denyCurrentBranch
2566 receive.denyDeleteCurrent
2568 receive.denyNonFastForwards
2571 receive.updateserverinfo
2574 repack.usedeltabaseoffset
2578 sendemail.aliasesfile
2579 sendemail.aliasfiletype
2583 sendemail.chainreplyto
2585 sendemail.envelopesender
2589 sendemail.signedoffbycc
2590 sendemail.smtpdomain
2591 sendemail.smtpencryption
2593 sendemail.smtpserver
2594 sendemail.smtpserveroption
2595 sendemail.smtpserverport
2597 sendemail.suppresscc
2598 sendemail.suppressfrom
2603 status.relativePaths
2604 status.showUntrackedFiles
2605 status.submodulesummary
2608 transfer.unpackLimit
2621 add rename remove set-head set-branches
2622 get-url set-url show prune update
2624 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2625 if [ -z "$subcommand" ]; then
2628 __gitcomp
"--verbose"
2631 __gitcomp
"$subcommands"
2637 case "$subcommand,$cur" in
2639 __gitcomp
"--track --master --fetch --tags --no-tags --mirror="
2644 __gitcomp
"--auto --delete"
2649 set-head
,*|set-branches
,*)
2650 __git_complete_remote_or_refspec
2656 __gitcomp
"$(__git_get_config_variables "remotes
")"
2659 __gitcomp
"--push --add --delete"
2662 __gitcomp
"--push --all"
2665 __gitcomp
"--dry-run"
2668 __gitcomp_nl
"$(__git_remotes)"
2677 __gitcomp
"--edit --graft --format= --list --delete"
2686 local subcommands
="clear forget diff remaining status gc"
2687 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2688 if test -z "$subcommand"
2690 __gitcomp
"$subcommands"
2697 __git_has_doubledash
&& return
2701 __gitcomp
"--merge --mixed --hard --soft --patch --keep"
2710 __git_find_repo_path
2711 if [ -f "$__git_repo_path"/REVERT_HEAD
]; then
2712 __gitcomp
"--continue --quit --abort"
2718 --edit --mainline --no-edit --no-commit --signoff
2719 --strategy= --strategy-option=
2731 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2736 __git_complete_index_file
"--cached"
2741 __git_has_doubledash
&& return
2746 $__git_log_common_options
2747 $__git_log_shortlog_options
2748 --numbered --summary --email
2753 __git_complete_revlist
2758 __git_has_doubledash
&& return
2761 --pretty=*|
--format=*)
2762 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2767 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2771 __gitcomp
"$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2775 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2777 $__git_diff_common_options
2782 __git_complete_revlist_file
2790 --all --remotes --topo-order --date-order --current --more=
2791 --list --independent --merge-base --no-name
2793 --sha1-name --sparse --topics --reflog
2798 __git_complete_revlist
2803 local save_opts
='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2804 local subcommands
='save list show apply clear drop pop create branch'
2805 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2806 if [ -z "$subcommand" ]; then
2809 __gitcomp
"$save_opts"
2812 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2813 __gitcomp
"$subcommands"
2818 case "$subcommand,$cur" in
2820 __gitcomp
"$save_opts"
2823 __gitcomp
"--index --quiet"
2828 show
,--*|branch
,--*)
2831 if [ $cword -eq 3 ]; then
2834 __gitcomp_nl
"$(__git stash list \
2835 | sed -n -e 's/:.*//p')"
2838 show
,*|apply
,*|drop
,*|pop
,*)
2839 __gitcomp_nl
"$(__git stash list \
2840 | sed -n -e 's/:.*//p')"
2850 __git_has_doubledash
&& return
2852 local subcommands
="add status init deinit update summary foreach sync"
2853 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2854 if [ -z "$subcommand" ]; then
2860 __gitcomp
"$subcommands"
2866 case "$subcommand,$cur" in
2868 __gitcomp
"--branch --force --name --reference --depth"
2871 __gitcomp
"--cached --recursive"
2874 __gitcomp
"--force --all"
2878 --init --remote --no-fetch
2879 --recommend-shallow --no-recommend-shallow
2880 --force --rebase --merge --reference --depth --recursive --jobs
2884 __gitcomp
"--cached --files --summary-limit"
2886 foreach
,--*|sync
,--*)
2887 __gitcomp
"--recursive"
2897 init fetch clone rebase dcommit log find-rev
2898 set-tree commit-diff info create-ignore propget
2899 proplist show-ignore show-externals branch tag blame
2900 migrate mkdirs reset gc
2902 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2903 if [ -z "$subcommand" ]; then
2904 __gitcomp
"$subcommands"
2906 local remote_opts
="--username= --config-dir= --no-auth-cache"
2908 --follow-parent --authors-file= --repack=
2909 --no-metadata --use-svm-props --use-svnsync-props
2910 --log-window-size= --no-checkout --quiet
2911 --repack-flags --use-log-author --localtime
2913 --ignore-paths= --include-paths= $remote_opts
2916 --template= --shared= --trunk= --tags=
2917 --branches= --stdlayout --minimize-url
2918 --no-metadata --use-svm-props --use-svnsync-props
2919 --rewrite-root= --prefix= $remote_opts
2922 --edit --rmdir --find-copies-harder --copy-similarity=
2925 case "$subcommand,$cur" in
2927 __gitcomp
"--revision= --fetch-all $fc_opts"
2930 __gitcomp
"--revision= $fc_opts $init_opts"
2933 __gitcomp
"$init_opts"
2937 --merge --strategy= --verbose --dry-run
2938 --fetch-all --no-rebase --commit-url
2939 --revision --interactive $cmt_opts $fc_opts
2943 __gitcomp
"--stdin $cmt_opts $fc_opts"
2945 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2946 show-externals
,--*|mkdirs
,--*)
2947 __gitcomp
"--revision="
2951 --limit= --revision= --verbose --incremental
2952 --oneline --show-commit --non-recursive
2953 --authors-file= --color
2958 --merge --verbose --strategy= --local
2959 --fetch-all --dry-run $fc_opts
2963 __gitcomp
"--message= --file= --revision= $cmt_opts"
2969 __gitcomp
"--dry-run --message --tag"
2972 __gitcomp
"--dry-run --message"
2975 __gitcomp
"--git-format"
2979 --config-dir= --ignore-paths= --minimize
2980 --no-auth-cache --username=
2984 __gitcomp
"--revision= --parent"
2995 while [ $c -lt $cword ]; do
2999 __gitcomp_direct
"$(__git_tags "" "$cur" " ")"
3014 __gitcomp_direct
"$(__git_tags "" "$cur" " ")"
3025 --list --delete --verify --annotate --message --file
3026 --sign --cleanup --local-user --force --column --sort=
3027 --contains --no-contains --points-at --merged --no-merged --create-reflog
3040 local subcommands
="add list lock prune unlock"
3041 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
3042 if [ -z "$subcommand" ]; then
3043 __gitcomp
"$subcommands"
3045 case "$subcommand,$cur" in
3047 __gitcomp
"--detach"
3050 __gitcomp
"--porcelain"
3053 __gitcomp
"--reason"
3056 __gitcomp
"--dry-run --expire --verbose"
3066 local i c
=1 command __git_dir __git_repo_path
3067 local __git_C_args C_args_count
=0
3069 while [ $c -lt $cword ]; do
3072 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
3073 --git-dir) ((c
++)) ; __git_dir
="${words[c]}" ;;
3074 --bare) __git_dir
="." ;;
3075 --help) command="help"; break ;;
3076 -c|
--work-tree|
--namespace) ((c
++)) ;;
3077 -C) __git_C_args
[C_args_count
++]=-C
3079 __git_C_args
[C_args_count
++]="${words[c]}"
3082 *) command="$i"; break ;;
3087 if [ -z "$command" ]; then
3089 --git-dir|
-C|
--work-tree)
3090 # these need a path argument, let's fall back to
3091 # Bash filename completion
3095 # we don't support completing these options' arguments
3113 --no-replace-objects
3117 *) __git_compute_porcelain_commands
3118 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
3123 local completion_func
="_git_${command//-/_}"
3124 declare -f $completion_func >/dev
/null
2>/dev
/null
&& $completion_func && return
3126 local expansion
=$
(__git_aliased_command
"$command")
3127 if [ -n "$expansion" ]; then
3129 completion_func
="_git_${expansion//-/_}"
3130 declare -f $completion_func >/dev
/null
2>/dev
/null
&& $completion_func
3136 __git_has_doubledash
&& return
3138 local __git_repo_path
3139 __git_find_repo_path
3142 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3148 $__git_log_common_options
3149 $__git_log_gitk_options
3155 __git_complete_revlist
3158 if [[ -n ${ZSH_VERSION-} ]]; then
3159 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3161 autoload
-U +X compinit
&& compinit
3167 local cur_
="${3-$cur}"
3173 local c IFS
=$
' \t\n'
3181 array
[${#array[@]}+1]="$c"
3184 compadd
-Q -S '' -p "${2-}" -a -- array
&& _ret
=0
3195 compadd
-Q -- ${=1} && _ret
=0
3204 compadd
-Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3213 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3218 local _ret=1 cur cword prev
3219 cur=${words[CURRENT]}
3220 prev=${words[CURRENT-1]}
3222 emulate ksh -c __${service}_main
3223 let _ret && _default && _ret=0
3227 compdef _git git gitk
3233 local cur words cword prev
3234 _get_comp_words_by_ref -n =: cur words cword prev
3238 # Setup completion for certain functions defined above by setting common
3239 # variables and workarounds.
3240 # This is NOT a public function; use at your own risk.
3243 local wrapper="__git_wrap
${2}"
3244 eval "$wrapper () { __git_func_wrap
$2 ; }"
3245 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3246 || complete -o default -o nospace -F $wrapper $1
3249 # wrapper for backwards compatibility
3252 __git_wrap__git_main
3255 # wrapper for backwards compatibility
3258 __git_wrap__gitk_main
3261 __git_complete git __git_main
3262 __git_complete gitk __gitk_main
3264 # The following are necessary only for Cygwin, and only are needed
3265 # when the user has tab-completed the executable name and consequently
3266 # included the '.exe' suffix.
3268 if [ Cygwin = "$
(uname
-o 2>/dev
/null
)" ]; then
3269 __git_complete git.exe __git_main