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 # You can set the following environment variables to influence the behavior of
33 # the completion routines:
35 # GIT_COMPLETION_CHECKOUT_NO_GUESS
37 # When set to "1", do not include "DWIM" suggestions in git-checkout
38 # completion (e.g., completing "foo" when "origin/foo" exists).
40 case "$COMP_WORDBREAKS" in
42 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
45 # Discovers the path to the git repository taking any '--git-dir=<path>' and
46 # '-C <path>' options into account and stores it in the $__git_repo_path
48 __git_find_repo_path ()
50 if [ -n "$__git_repo_path" ]; then
51 # we already know where it is
55 if [ -n "${__git_C_args-}" ]; then
56 __git_repo_path="$(git "${__git_C_args[@]}" \
57 ${__git_dir:+--git-dir="$__git_dir"} \
58 rev-parse --absolute-git-dir 2>/dev/null)"
59 elif [ -n "${__git_dir-}" ]; then
60 test -d "$__git_dir" &&
61 __git_repo_path="$__git_dir"
62 elif [ -n "${GIT_DIR-}" ]; then
63 test -d "${GIT_DIR-}" &&
64 __git_repo_path="$GIT_DIR"
65 elif [ -d .git ]; then
68 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
72 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
73 # __gitdir accepts 0 or 1 arguments (i.e., location)
74 # returns location of .git repo
77 if [ -z "${1-}" ]; then
78 __git_find_repo_path || return 1
79 echo "$__git_repo_path"
80 elif [ -d "$1/.git" ]; then
87 # Runs git with all the options given as argument, respecting any
88 # '--git-dir=<path>' and '-C <path>' options present on the command line
91 git ${__git_C_args:+"${__git_C_args[@]}"} \
92 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
95 # The following function is based on code from:
97 # bash_completion - programmable completion functions for bash 3.2+
99 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
100 # © 2009-2010, Bash Completion Maintainers
101 # <bash-completion-devel@lists.alioth.debian.org>
103 # This program is free software; you can redistribute it and/or modify
104 # it under the terms of the GNU General Public License as published by
105 # the Free Software Foundation; either version 2, or (at your option)
108 # This program is distributed in the hope that it will be useful,
109 # but WITHOUT ANY WARRANTY; without even the implied warranty of
110 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111 # GNU General Public License for more details.
113 # You should have received a copy of the GNU General Public License
114 # along with this program; if not, see <http://www.gnu.org/licenses/>.
116 # The latest version of this software can be obtained here:
118 # http://bash-completion.alioth.debian.org/
122 # This function can be used to access a tokenized list of words
123 # on the command line:
125 # __git_reassemble_comp_words_by_ref '=:'
126 # if test "${words_[cword_-1]}" = -w
131 # The argument should be a collection of characters from the list of
132 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
135 # This is roughly equivalent to going back in time and setting
136 # COMP_WORDBREAKS to exclude those characters. The intent is to
137 # make option types like --date=<type> and <rev>:<path> easy to
138 # recognize by treating each shell word as a single token.
140 # It is best not to set COMP_WORDBREAKS directly because the value is
141 # shared with other completion scripts. By the time the completion
142 # function gets called, COMP_WORDS has already been populated so local
143 # changes to COMP_WORDBREAKS have no effect.
145 # Output: words_, cword_, cur_.
147 __git_reassemble_comp_words_by_ref()
149 local exclude i j first
150 # Which word separators to exclude?
151 exclude="${1//[^$COMP_WORDBREAKS]}"
153 if [ -z "$exclude" ]; then
154 words_=("${COMP_WORDS[@]}")
157 # List of word completion separators has shrunk;
158 # re-assemble words to complete.
159 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
160 # Append each nonempty word consisting of just
161 # word separator characters to the current word.
165 [ -n "${COMP_WORDS[$i]}" ] &&
166 # word consists of excluded word separators
167 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
169 # Attach to the previous token,
170 # unless the previous token is the command name.
171 if [ $j -ge 2 ] && [ -n "$first" ]; then
175 words_[$j]=${words_[j]}${COMP_WORDS[i]}
176 if [ $i = $COMP_CWORD ]; then
179 if (($i < ${#COMP_WORDS[@]} - 1)); then
186 words_[$j]=${words_[j]}${COMP_WORDS[i]}
187 if [ $i = $COMP_CWORD ]; then
193 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
194 _get_comp_words_by_ref ()
196 local exclude cur_ words_ cword_
197 if [ "$1" = "-n" ]; then
201 __git_reassemble_comp_words_by_ref "$exclude"
202 cur_=${words_[cword_]}
203 while [ $# -gt 0 ]; do
209 prev=${words_[$cword_-1]}
212 words=("${words_[@]}")
223 # Fills the COMPREPLY array with prefiltered words without any additional
225 # Callers must take care of providing only words that match the current word
226 # to be completed and adding any prefix and/or suffix (trailing space!), if
228 # 1: List of newline-separated matching completion words, complete with
239 local x i=${#COMPREPLY[@]}
241 if [[ "$x" == "$3"* ]]; then
242 COMPREPLY[i++]="$2$x$4"
253 # Generates completion reply, appending a space to possible completion words,
255 # It accepts 1 to 4 arguments:
256 # 1: List of possible completion words.
257 # 2: A prefix to be added to each possible completion word (optional).
258 # 3: Generate possible completion matches for this word (optional).
259 # 4: A suffix to be appended to each possible completion word (optional).
262 local cur_="${3-$cur}"
268 local c i=0 IFS=$' \t\n'
271 if [[ $c == "$cur_"* ]]; then
276 COMPREPLY[i++]="${2-}$c"
283 # Clear the variables caching builtins' options when (re-)sourcing
284 # the completion script.
285 unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
287 # This function is equivalent to
289 # __gitcomp "$(git xxx --git-completion-helper) ..."
291 # except that the output is cached. Accept 1-3 arguments:
292 # 1: the git command to execute, this is also the cache key
293 # 2: extra options to be added on top (e.g. negative forms)
294 # 3: options to be excluded
297 # spaces must be replaced with underscore for multi-word
298 # commands, e.g. "git remote add" becomes remote_add.
303 local var=__gitcomp_builtin_"${cmd/-/_}"
305 eval "options=\$$var"
307 if [ -z "$options" ]; then
308 # leading and trailing spaces are significant to make
309 # option removal work correctly.
310 options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
312 options="${options/ $i / }"
314 eval "$var=\"$options\""
320 # Variation of __gitcomp_nl () that appends to the existing list of
321 # completion candidates, COMPREPLY.
322 __gitcomp_nl_append ()
325 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
328 # Generates completion reply from newline-separated possible completion words
329 # by appending a space to all of them.
330 # It accepts 1 to 4 arguments:
331 # 1: List of possible completion words, separated by a single newline.
332 # 2: A prefix to be added to each possible completion word (optional).
333 # 3: Generate possible completion matches for this word (optional).
334 # 4: A suffix to be appended to each possible completion word instead of
335 # the default space (optional). If specified but empty, nothing is
340 __gitcomp_nl_append "$@"
343 # Generates completion reply with compgen from newline-separated possible
344 # completion filenames.
345 # It accepts 1 to 3 arguments:
346 # 1: List of possible completion filenames, separated by a single newline.
347 # 2: A directory prefix to be added to each possible completion filename
349 # 3: Generate possible completion matches for this word (optional).
354 # XXX does not work when the directory prefix contains a tilde,
355 # since tilde expansion is not applied.
356 # This means that COMPREPLY will be empty and Bash default
357 # completion will be used.
358 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
360 # use a hack to enable file mode in bash < 4
361 compopt -o filenames +o nospace 2>/dev/null ||
362 compgen -f /non-existing-dir/ > /dev/null
365 # Execute 'git ls-files', unless the --committable option is specified, in
366 # which case it runs 'git diff-index' to find out the files that can be
367 # committed. It return paths relative to the directory specified in the first
368 # argument, and using the options specified in the second argument.
369 __git_ls_files_helper ()
371 if [ "$2" == "--committable" ]; then
372 __git -C "$1" diff-index --name-only --relative HEAD
374 # NOTE: $2 is not quoted in order to support multiple options
375 __git -C "$1" ls-files --exclude-standard $2
380 # __git_index_files accepts 1 or 2 arguments:
381 # 1: Options to pass to ls-files (required).
382 # 2: A directory path (optional).
383 # If provided, only files within the specified directory are listed.
384 # Sub directories are never recursed. Path must have a trailing
388 local root="${2-.}" file
390 __git_ls_files_helper "$root" "$1" |
391 while read -r file; do
393 ?*/*) echo "${file%%/*}" ;;
399 # Lists branches from the local repository.
400 # 1: A prefix to be added to each listed branch (optional).
401 # 2: List only branches matching this word (optional; list all branches if
403 # 3: A suffix to be appended to each listed branch (optional).
406 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
408 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
409 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
412 # Lists tags from the local repository.
413 # Accepts the same positional parameters as __git_heads() above.
416 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
418 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
419 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
422 # Lists refs from the local (by default) or from a remote repository.
423 # It accepts 0, 1 or 2 arguments:
424 # 1: The remote to list refs from (optional; ignored, if set but empty).
425 # Can be the name of a configured remote, a path, or a URL.
426 # 2: In addition to local refs, list unique branches from refs/remotes/ for
427 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
428 # 3: A prefix to be added to each listed ref (optional).
429 # 4: List only refs matching this word (optional; list all refs if unset or
431 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
434 # Use __git_complete_refs() instead.
437 local i hash dir track="${2-}"
438 local list_refs_from=path remote="${1-}"
440 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
442 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
445 dir="$__git_repo_path"
447 if [ -z "$remote" ]; then
448 if [ -z "$dir" ]; then
452 if __git_is_configured_remote "$remote"; then
453 # configured remote takes precedence over a
454 # local directory with the same name
455 list_refs_from=remote
456 elif [ -d "$remote/.git" ]; then
458 elif [ -d "$remote" ]; then
465 if [ "$list_refs_from" = path ]; then
466 if [[ "$cur_" == ^* ]]; then
475 refs=("$match*" "$match*/**")
479 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
482 if [ -e "$dir/$i" ]; then
488 format="refname:strip=2"
489 refs=("refs/tags/$match*" "refs/tags/$match*/**"
490 "refs/heads/$match*" "refs/heads/$match*/**"
491 "refs/remotes/$match*" "refs/remotes/$match*/**")
494 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
496 if [ -n "$track" ]; then
497 # employ the heuristic used by git checkout
498 # Try to find a remote branch that matches the completion word
499 # but only output if the branch name is unique
500 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
501 --sort="refname:strip=3" \
502 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
509 __git ls-remote "$remote" "$match*" | \
510 while read -r hash i; do
513 *) echo "$pfx$i$sfx" ;;
518 if [ "$list_refs_from" = remote ]; then
520 $match*) echo "${pfx}HEAD$sfx" ;;
522 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
523 "refs/remotes/$remote/$match*" \
524 "refs/remotes/$remote/$match*/**"
528 $match*) query_symref="HEAD" ;;
530 __git ls-remote "$remote" $query_symref \
531 "refs/tags/$match*" "refs/heads/$match*" \
532 "refs/remotes/$match*" |
533 while read -r hash i; do
536 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
537 *) echo "$pfx$i$sfx" ;; # symbolic refs
545 # Completes refs, short and long, local and remote, symbolic and pseudo.
547 # Usage: __git_complete_refs [<option>]...
548 # --remote=<remote>: The remote to list refs from, can be the name of a
549 # configured remote, a path, or a URL.
550 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
551 # --pfx=<prefix>: A prefix to be added to each ref.
552 # --cur=<word>: The current ref to be completed. Defaults to the current
553 # word to be completed.
554 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
556 __git_complete_refs ()
558 local remote track pfx cur_="$cur" sfx=" "
560 while test $# != 0; do
562 --remote=*) remote="${1##--remote=}" ;;
563 --track) track="yes" ;;
564 --pfx=*) pfx="${1##--pfx=}" ;;
565 --cur=*) cur_="${1##--cur=}" ;;
566 --sfx=*) sfx="${1##--sfx=}" ;;
572 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
575 # __git_refs2 requires 1 argument (to pass to __git_refs)
576 # Deprecated: use __git_complete_fetch_refspecs() instead.
580 for i in $(__git_refs "$1"); do
585 # Completes refspecs for fetching from a remote repository.
586 # 1: The remote repository.
587 # 2: A prefix to be added to each listed refspec (optional).
588 # 3: The ref to be completed as a refspec instead of the current word to be
589 # completed (optional)
590 # 4: A suffix to be appended to each listed refspec instead of the default
592 __git_complete_fetch_refspecs ()
594 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
597 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
603 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
604 __git_refs_remotes ()
607 __git ls-remote "$1" 'refs/heads/*' | \
608 while read -r hash i; do
609 echo "$i:refs/remotes/$1/${i#refs/heads/}"
616 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
620 # Returns true if $1 matches the name of a configured remote, false otherwise.
621 __git_is_configured_remote ()
624 for remote in $(__git_remotes); do
625 if [ "$remote" = "$1" ]; then
632 __git_list_merge_strategies ()
634 LANG=C LC_ALL=C git merge -s help 2>&1 |
635 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
644 __git_merge_strategies=
645 # 'git merge -s help' (and thus detection of the merge strategy
646 # list) fails, unfortunately, if run outside of any git working
647 # tree. __git_merge_strategies is set to the empty string in
648 # that case, and the detection will be repeated the next time it
650 __git_compute_merge_strategies ()
652 test -n "$__git_merge_strategies" ||
653 __git_merge_strategies=$(__git_list_merge_strategies)
656 __git_complete_revlist_file ()
658 local pfx ls ref cur_="$cur"
678 case "$COMP_WORDBREAKS" in
680 *) pfx="$ref:$pfx" ;;
683 __gitcomp_nl "$(__git ls-tree "$ls" \
684 | sed '/^100... blob /{
700 pfx="${cur_%...*}..."
702 __git_complete_refs --pfx="$pfx" --cur="$cur_"
707 __git_complete_refs --pfx="$pfx" --cur="$cur_"
716 # __git_complete_index_file requires 1 argument:
717 # 1: the options to pass to ls-file
719 # The exception is --committable, which finds the files appropriate commit.
720 __git_complete_index_file ()
722 local pfx="" cur_="$cur"
732 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
735 __git_complete_file ()
737 __git_complete_revlist_file
740 __git_complete_revlist ()
742 __git_complete_revlist_file
745 __git_complete_remote_or_refspec ()
747 local cur_="$cur" cmd="${words[1]}"
748 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
749 if [ "$cmd" = "remote" ]; then
752 while [ $c -lt $cword ]; do
755 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
756 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
759 push) no_complete_refspec=1 ;;
767 *) remote="$i"; break ;;
771 if [ -z "$remote" ]; then
772 __gitcomp_nl "$(__git_remotes)"
775 if [ $no_complete_refspec = 1 ]; then
778 [ "$remote" = "." ] && remote=
781 case "$COMP_WORDBREAKS" in
783 *) pfx="${cur_%%:*}:" ;;
795 if [ $lhs = 1 ]; then
796 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
798 __git_complete_refs --pfx="$pfx" --cur="$cur_"
802 if [ $lhs = 1 ]; then
803 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
805 __git_complete_refs --pfx="$pfx" --cur="$cur_"
809 if [ $lhs = 1 ]; then
810 __git_complete_refs --pfx="$pfx" --cur="$cur_"
812 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
818 __git_complete_strategy ()
820 __git_compute_merge_strategies
823 __gitcomp "$__git_merge_strategies"
828 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
836 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
838 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
840 git help -a|egrep '^ [a-zA-Z0-9]'
844 __git_list_all_commands ()
847 for i in $(__git_commands)
850 *--*) : helper pattern;;
857 __git_compute_all_commands ()
859 test -n "$__git_all_commands" ||
860 __git_all_commands=$(__git_list_all_commands)
863 __git_list_porcelain_commands ()
866 __git_compute_all_commands
867 for i in $__git_all_commands
870 *--*) : helper pattern;;
871 applymbox) : ask gittus;;
872 applypatch) : ask gittus;;
873 archimport) : import;;
874 cat-file) : plumbing;;
875 check-attr) : plumbing;;
876 check-ignore) : plumbing;;
877 check-mailmap) : plumbing;;
878 check-ref-format) : plumbing;;
879 checkout-index) : plumbing;;
880 column) : internal helper;;
881 commit-tree) : plumbing;;
882 count-objects) : infrequent;;
883 credential) : credentials;;
884 credential-*) : credentials helper;;
885 cvsexportcommit) : export;;
886 cvsimport) : import;;
887 cvsserver) : daemon;;
889 diff-files) : plumbing;;
890 diff-index) : plumbing;;
891 diff-tree) : plumbing;;
892 fast-import) : import;;
893 fast-export) : export;;
894 fsck-objects) : plumbing;;
895 fetch-pack) : plumbing;;
896 fmt-merge-msg) : plumbing;;
897 for-each-ref) : plumbing;;
898 hash-object) : plumbing;;
899 http-*) : transport;;
900 index-pack) : plumbing;;
901 init-db) : deprecated;;
902 local-fetch) : plumbing;;
903 ls-files) : plumbing;;
904 ls-remote) : plumbing;;
905 ls-tree) : plumbing;;
906 mailinfo) : plumbing;;
907 mailsplit) : plumbing;;
908 merge-*) : plumbing;;
911 pack-objects) : plumbing;;
912 pack-redundant) : plumbing;;
913 pack-refs) : plumbing;;
914 parse-remote) : plumbing;;
915 patch-id) : plumbing;;
917 prune-packed) : plumbing;;
918 quiltimport) : import;;
919 read-tree) : plumbing;;
920 receive-pack) : plumbing;;
921 remote-*) : transport;;
923 rev-list) : plumbing;;
924 rev-parse) : plumbing;;
925 runstatus) : plumbing;;
926 sh-setup) : internal;;
928 show-ref) : plumbing;;
929 send-pack) : plumbing;;
930 show-index) : plumbing;;
932 stripspace) : plumbing;;
933 symbolic-ref) : plumbing;;
934 unpack-file) : plumbing;;
935 unpack-objects) : plumbing;;
936 update-index) : plumbing;;
937 update-ref) : plumbing;;
938 update-server-info) : daemon;;
939 upload-archive) : plumbing;;
940 upload-pack) : plumbing;;
941 write-tree) : plumbing;;
943 verify-pack) : infrequent;;
944 verify-tag) : plumbing;;
950 __git_porcelain_commands=
951 __git_compute_porcelain_commands ()
953 test -n "$__git_porcelain_commands" ||
954 __git_porcelain_commands=$(__git_list_porcelain_commands)
957 # Lists all set config variables starting with the given section prefix,
958 # with the prefix removed.
959 __git_get_config_variables ()
961 local section="$1" i IFS=$'\n'
962 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
963 echo "${i#$section.}"
967 __git_pretty_aliases ()
969 __git_get_config_variables "pretty"
974 __git_get_config_variables "alias"
977 # __git_aliased_command requires 1 argument
978 __git_aliased_command ()
980 local word cmdline=$(__git config --get "alias.$1")
981 for word in $cmdline; do
987 \!*) : shell command alias ;;
989 *=*) : setting env ;;
991 \(\)) : skip parens of shell function definition ;;
992 {) : skip start of shell helper function ;;
993 :) : skip null command ;;
994 \'*) : skip opening quote after sh -c ;;
1002 # __git_find_on_cmdline requires 1 argument
1003 __git_find_on_cmdline ()
1005 local word subcommand c=1
1006 while [ $c -lt $cword ]; do
1008 for subcommand in $1; do
1009 if [ "$subcommand" = "$word" ]; then
1018 # Echo the value of an option set on the command line or config
1020 # $1: short option name
1021 # $2: long option name including =
1022 # $3: list of possible values
1023 # $4: config string (optional)
1026 # result="$(__git_get_option_value "-d" "--do-something=" \
1027 # "yes no" "core.doSomething")"
1029 # result is then either empty (no option set) or "yes" or "no"
1031 # __git_get_option_value requires 3 arguments
1032 __git_get_option_value ()
1034 local c short_opt long_opt val
1035 local result= values config_key word
1043 while [ $c -ge 0 ]; do
1045 for val in $values; do
1046 if [ "$short_opt$val" = "$word" ] ||
1047 [ "$long_opt$val" = "$word" ]; then
1055 if [ -n "$config_key" ] && [ -z "$result" ]; then
1056 result="$(__git config "$config_key")"
1062 __git_has_doubledash ()
1065 while [ $c -lt $cword ]; do
1066 if [ "--" = "${words[c]}" ]; then
1074 # Try to count non option arguments passed on the command line for the
1075 # specified git command.
1076 # When options are used, it is necessary to use the special -- option to
1077 # tell the implementation were non option arguments begin.
1078 # XXX this can not be improved, since options can appear everywhere, as
1082 # __git_count_arguments requires 1 argument: the git command executed.
1083 __git_count_arguments ()
1087 # Skip "git" (first argument)
1088 for ((i=1; i < ${#words[@]}; i++)); do
1093 # Good; we can assume that the following are only non
1098 # Skip the specified git command and discard git
1111 __git_whitespacelist="nowarn warn error error-all fix"
1112 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1116 __git_find_repo_path
1117 if [ -d "$__git_repo_path"/rebase-apply ]; then
1118 __gitcomp "$__git_am_inprogress_options"
1123 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1127 __gitcomp_builtin am "--no-utf8" \
1128 "$__git_am_inprogress_options"
1137 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1141 __gitcomp_builtin apply
1150 __gitcomp_builtin add
1154 local complete_opt="--others --modified --directory --no-empty-directory"
1155 if test -n "$(__git_find_on_cmdline "-u --update")"
1157 complete_opt="--modified"
1159 __git_complete_index_file "$complete_opt"
1166 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1170 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1175 --format= --list --verbose
1176 --prefix= --remote= --exec= --output
1186 __git_has_doubledash && return
1188 local subcommands="start bad good skip reset visualize replay log run"
1189 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1190 if [ -z "$subcommand" ]; then
1191 __git_find_repo_path
1192 if [ -f "$__git_repo_path"/BISECT_START ]; then
1193 __gitcomp "$subcommands"
1195 __gitcomp "replay start"
1200 case "$subcommand" in
1201 bad|good|reset|skip|start)
1211 local i c=1 only_local_ref="n" has_r="n"
1213 while [ $c -lt $cword ]; do
1216 -d|--delete|-m|--move) only_local_ref="y" ;;
1217 -r|--remotes) has_r="y" ;;
1223 --set-upstream-to=*)
1224 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1227 __gitcomp_builtin branch "--no-color --no-abbrev
1228 --no-track --no-column
1232 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1233 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1243 local cmd="${words[2]}"
1246 __gitcomp "create list-heads verify unbundle"
1249 # looking for a file
1254 __git_complete_revlist
1263 __git_has_doubledash && return
1267 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1270 __gitcomp_builtin checkout "--no-track --no-recurse-submodules"
1273 # check if --track, --no-track, or --no-guess was specified
1274 # if so, disable DWIM mode
1275 local flags="--track --no-track --no-guess" track_opt="--track"
1276 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1277 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1280 __git_complete_refs $track_opt
1290 __git_cherry_pick_inprogress_options="--continue --quit --abort"
1294 __git_find_repo_path
1295 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1296 __gitcomp "$__git_cherry_pick_inprogress_options"
1301 __gitcomp_builtin cherry-pick "" \
1302 "$__git_cherry_pick_inprogress_options"
1314 __gitcomp_builtin clean
1319 # XXX should we check for -x option ?
1320 __git_complete_index_file "--others --directory"
1327 __gitcomp_builtin clone "--no-single-branch"
1333 __git_untracked_file_modes="all no normal"
1346 __gitcomp "default scissors strip verbatim whitespace
1347 " "" "${cur##--cleanup=}"
1350 --reuse-message=*|--reedit-message=*|\
1351 --fixup=*|--squash=*)
1352 __git_complete_refs --cur="${cur#*=}"
1355 --untracked-files=*)
1356 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1360 __gitcomp_builtin commit "--no-edit --verify"
1364 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1365 __git_complete_index_file "--committable"
1367 # This is the first commit
1368 __git_complete_index_file "--cached"
1376 __gitcomp_builtin describe
1382 __git_diff_algorithms="myers minimal patience histogram"
1384 __git_diff_submodule_formats="diff log short"
1386 __git_diff_common_options="--stat --numstat --shortstat --summary
1387 --patch-with-stat --name-only --name-status --color
1388 --no-color --color-words --no-renames --check
1389 --full-index --binary --abbrev --diff-filter=
1390 --find-copies-harder --ignore-cr-at-eol
1391 --text --ignore-space-at-eol --ignore-space-change
1392 --ignore-all-space --ignore-blank-lines --exit-code
1393 --quiet --ext-diff --no-ext-diff
1394 --no-prefix --src-prefix= --dst-prefix=
1395 --inter-hunk-context=
1396 --patience --histogram --minimal
1397 --raw --word-diff --word-diff-regex=
1398 --dirstat --dirstat= --dirstat-by-file
1399 --dirstat-by-file= --cumulative
1401 --submodule --submodule= --ignore-submodules
1406 __git_has_doubledash && return
1410 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1414 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1418 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1419 --base --ours --theirs --no-index
1420 $__git_diff_common_options
1425 __git_complete_revlist_file
1428 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1429 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1434 __git_has_doubledash && return
1438 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1442 __gitcomp_builtin difftool "$__git_diff_common_options
1443 --base --cached --ours --theirs
1444 --pickaxe-all --pickaxe-regex
1450 __git_complete_revlist_file
1453 __git_fetch_recurse_submodules="yes on-demand no"
1458 --recurse-submodules=*)
1459 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1463 __gitcomp_builtin fetch "--no-tags"
1467 __git_complete_remote_or_refspec
1470 __git_format_patch_options="
1471 --stdout --attach --no-attach --thread --thread= --no-thread
1472 --numbered --start-number --numbered-files --keep-subject --signoff
1473 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1474 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1475 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1476 --output-directory --reroll-count --to= --quiet --notes
1479 _git_format_patch ()
1485 " "" "${cur##--thread=}"
1489 __gitcomp "$__git_format_patch_options"
1493 __git_complete_revlist
1500 __gitcomp_builtin fsck "--no-reflogs"
1510 __gitcomp_builtin gc
1521 # Lists matching symbol names from a tag (as in ctags) file.
1522 # 1: List symbol names matching this word.
1523 # 2: The tag file to list symbol names from.
1524 # 3: A prefix to be added to each listed symbol name (optional).
1525 # 4: A suffix to be appended to each listed symbol name (optional).
1526 __git_match_ctag () {
1527 awk -v pfx="${3-}" -v sfx="${4-}" "
1528 /^${1//\//\\/}/ { print pfx \$1 sfx }
1532 # Complete symbol names from a tag file.
1533 # Usage: __git_complete_symbol [<option>]...
1534 # --tags=<file>: The tag file to list symbol names from instead of the
1536 # --pfx=<prefix>: A prefix to be added to each symbol name.
1537 # --cur=<word>: The current symbol name to be completed. Defaults to
1538 # the current word to be completed.
1539 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1540 # of the default space.
1541 __git_complete_symbol () {
1542 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1544 while test $# != 0; do
1546 --tags=*) tags="${1##--tags=}" ;;
1547 --pfx=*) pfx="${1##--pfx=}" ;;
1548 --cur=*) cur_="${1##--cur=}" ;;
1549 --sfx=*) sfx="${1##--sfx=}" ;;
1555 if test -r "$tags"; then
1556 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1562 __git_has_doubledash && return
1566 __gitcomp_builtin grep
1571 case "$cword,$prev" in
1573 __git_complete_symbol && return
1584 __gitcomp_builtin help
1588 __git_compute_all_commands
1589 __gitcomp "$__git_all_commands $(__git_aliases)
1590 attributes cli core-tutorial cvs-migration
1591 diffcore everyday gitk glossary hooks ignore modules
1592 namespaces repository-layout revisions tutorial tutorial-2
1602 false true umask group all world everybody
1603 " "" "${cur##--shared=}"
1607 __gitcomp_builtin init
1617 __gitcomp_builtin ls-files "--no-empty-directory"
1622 # XXX ignore options like --modified and always suggest all cached
1624 __git_complete_index_file "--cached"
1631 __gitcomp_builtin ls-remote
1635 __gitcomp_nl "$(__git_remotes)"
1643 # Options that go well for log, shortlog and gitk
1644 __git_log_common_options="
1646 --branches --tags --remotes
1647 --first-parent --merges --no-merges
1649 --max-age= --since= --after=
1650 --min-age= --until= --before=
1651 --min-parents= --max-parents=
1652 --no-min-parents --no-max-parents
1654 # Options that go well for log and gitk (not shortlog)
1655 __git_log_gitk_options="
1656 --dense --sparse --full-history
1657 --simplify-merges --simplify-by-decoration
1658 --left-right --notes --no-notes
1660 # Options that go well for log and shortlog (not gitk)
1661 __git_log_shortlog_options="
1662 --author= --committer= --grep=
1663 --all-match --invert-grep
1666 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1667 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1671 __git_has_doubledash && return
1672 __git_find_repo_path
1675 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1678 case "$prev,$cur" in
1680 return # fall back to Bash filename completion
1683 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1687 __git_complete_symbol
1692 --pretty=*|--format=*)
1693 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1698 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1702 __gitcomp "full short no" "" "${cur##--decorate=}"
1706 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1710 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1715 $__git_log_common_options
1716 $__git_log_shortlog_options
1717 $__git_log_gitk_options
1718 --root --topo-order --date-order --reverse
1719 --follow --full-diff
1720 --abbrev-commit --abbrev=
1721 --relative-date --date=
1722 --pretty= --format= --oneline
1727 --decorate --decorate=
1729 --parents --children
1731 $__git_diff_common_options
1732 --pickaxe-all --pickaxe-regex
1737 return # fall back to Bash filename completion
1740 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1744 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1748 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1752 __git_complete_revlist
1757 __git_complete_strategy && return
1761 __gitcomp_builtin merge "--no-rerere-autoupdate
1762 --no-commit --no-edit --no-ff
1763 --no-log --no-progress
1764 --no-squash --no-stat
1765 --no-verify-signatures
1776 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1780 __gitcomp "--tool= --prompt --no-prompt"
1790 __gitcomp_builtin merge-base
1801 __gitcomp_builtin mv
1806 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1807 # We need to show both cached and untracked files (including
1808 # empty directories) since this may not be the last argument.
1809 __git_complete_index_file "--cached --others --directory"
1811 __git_complete_index_file "--cached"
1817 __gitcomp_builtin name-rev
1822 local subcommands='add append copy edit get-ref list merge prune remove show'
1823 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1825 case "$subcommand,$cur" in
1827 __gitcomp_builtin notes
1835 __gitcomp "$subcommands --ref"
1839 *,--reuse-message=*|*,--reedit-message=*)
1840 __git_complete_refs --cur="${cur#*=}"
1843 __gitcomp_builtin notes_$subcommand
1846 # this command does not take a ref, do not complete it
1862 __git_complete_strategy && return
1865 --recurse-submodules=*)
1866 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1870 __gitcomp_builtin pull "--no-autostash --no-commit --no-edit
1871 --no-ff --no-log --no-progress --no-rebase
1872 --no-squash --no-stat --no-tags
1873 --no-verify-signatures"
1878 __git_complete_remote_or_refspec
1881 __git_push_recurse_submodules="check on-demand only"
1883 __git_complete_force_with_lease ()
1891 __git_complete_refs --cur="${cur_#*:}"
1894 __git_complete_refs --cur="$cur_"
1903 __gitcomp_nl "$(__git_remotes)"
1906 --recurse-submodules)
1907 __gitcomp "$__git_push_recurse_submodules"
1913 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1916 --recurse-submodules=*)
1917 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1920 --force-with-lease=*)
1921 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1925 __gitcomp_builtin push
1929 __git_complete_remote_or_refspec
1934 __git_find_repo_path
1935 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1936 __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
1938 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1939 [ -d "$__git_repo_path"/rebase-merge ]; then
1940 __gitcomp "--continue --skip --abort --quit --show-current-patch"
1943 __git_complete_strategy && return
1946 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1951 --onto --merge --strategy --interactive
1952 --preserve-merges --stat --no-stat
1953 --committer-date-is-author-date --ignore-date
1954 --ignore-whitespace --whitespace=
1955 --autosquash --no-autosquash
1956 --fork-point --no-fork-point
1957 --autostash --no-autostash
1958 --verify --no-verify
1959 --keep-empty --root --force-rebase --no-ff
1971 local subcommands="show delete expire"
1972 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1974 if [ -z "$subcommand" ]; then
1975 __gitcomp "$subcommands"
1981 __git_send_email_confirm_options="always never auto cc compose"
1982 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1987 --to|--cc|--bcc|--from)
1988 __gitcomp "$(__git send-email --dump-aliases)"
1996 $__git_send_email_confirm_options
1997 " "" "${cur##--confirm=}"
2002 $__git_send_email_suppresscc_options
2003 " "" "${cur##--suppress-cc=}"
2007 --smtp-encryption=*)
2008 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2014 " "" "${cur##--thread=}"
2017 --to=*|--cc=*|--bcc=*|--from=*)
2018 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2022 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2023 --compose --confirm= --dry-run --envelope-sender
2025 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2026 --no-suppress-from --no-thread --quiet --reply-to
2027 --signed-off-by-cc --smtp-pass --smtp-server
2028 --smtp-server-port --smtp-encryption= --smtp-user
2029 --subject --suppress-cc= --suppress-from --thread --to
2030 --validate --no-validate
2031 $__git_format_patch_options"
2035 __git_complete_revlist
2046 local untracked_state
2049 --ignore-submodules=*)
2050 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2053 --untracked-files=*)
2054 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2059 always never auto column row plain dense nodense
2060 " "" "${cur##--column=}"
2064 __gitcomp_builtin status "--no-column"
2069 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2070 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2072 case "$untracked_state" in
2074 # --ignored option does not matter
2078 complete_opt="--cached --directory --no-empty-directory --others"
2080 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2081 complete_opt="$complete_opt --ignored --exclude=*"
2086 __git_complete_index_file "$complete_opt"
2089 __git_config_get_set_variables ()
2091 local prevword word config_file= c=$cword
2092 while [ $c -gt 1 ]; do
2095 --system|--global|--local|--file=*)
2100 config_file="$word $prevword"
2108 __git config $config_file --name-only --list
2114 branch.*.remote|branch.*.pushremote)
2115 __gitcomp_nl "$(__git_remotes)"
2123 __gitcomp "false true preserve interactive"
2127 __gitcomp_nl "$(__git_remotes)"
2131 local remote="${prev#remote.}"
2132 remote="${remote%.fetch}"
2133 if [ -z "$cur" ]; then
2134 __gitcomp_nl "refs/heads/" "" "" ""
2137 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2141 local remote="${prev#remote.}"
2142 remote="${remote%.push}"
2143 __gitcomp_nl "$(__git for-each-ref \
2144 --format='%(refname):%(refname)' refs/heads)"
2147 pull.twohead|pull.octopus)
2148 __git_compute_merge_strategies
2149 __gitcomp "$__git_merge_strategies"
2152 color.branch|color.diff|color.interactive|\
2153 color.showbranch|color.status|color.ui)
2154 __gitcomp "always never auto"
2158 __gitcomp "false true"
2163 normal black red green yellow blue magenta cyan white
2164 bold dim ul blink reverse
2169 __gitcomp "log short"
2173 __gitcomp "man info web html"
2177 __gitcomp "$__git_log_date_formats"
2180 sendemail.aliasesfiletype)
2181 __gitcomp "mutt mailrc pine elm gnus"
2185 __gitcomp "$__git_send_email_confirm_options"
2188 sendemail.suppresscc)
2189 __gitcomp "$__git_send_email_suppresscc_options"
2192 sendemail.transferencoding)
2193 __gitcomp "7bit 8bit quoted-printable base64"
2196 --get|--get-all|--unset|--unset-all)
2197 __gitcomp_nl "$(__git_config_get_set_variables)"
2206 __gitcomp_builtin config
2210 local pfx="${cur%.*}." cur_="${cur##*.}"
2211 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2215 local pfx="${cur%.*}." cur_="${cur#*.}"
2216 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2217 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2221 local pfx="${cur%.*}." cur_="${cur##*.}"
2223 argprompt cmd confirm needsfile noconsole norescan
2224 prompt revprompt revunmerged title
2229 local pfx="${cur%.*}." cur_="${cur##*.}"
2230 __gitcomp "cmd path" "$pfx" "$cur_"
2234 local pfx="${cur%.*}." cur_="${cur##*.}"
2235 __gitcomp "cmd path" "$pfx" "$cur_"
2239 local pfx="${cur%.*}." cur_="${cur##*.}"
2240 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2244 local pfx="${cur%.*}." cur_="${cur#*.}"
2245 __git_compute_all_commands
2246 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2250 local pfx="${cur%.*}." cur_="${cur##*.}"
2252 url proxy fetch push mirror skipDefaultUpdate
2253 receivepack uploadpack tagopt pushurl
2258 local pfx="${cur%.*}." cur_="${cur#*.}"
2259 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2260 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2264 local pfx="${cur%.*}." cur_="${cur##*.}"
2265 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2272 advice.commitBeforeMerge
2274 advice.implicitIdentity
2275 advice.pushAlreadyExists
2276 advice.pushFetchFirst
2277 advice.pushNeedsForce
2278 advice.pushNonFFCurrent
2279 advice.pushNonFFMatching
2280 advice.pushUpdateRejected
2281 advice.resolveConflict
2284 advice.statusUoption
2289 apply.ignorewhitespace
2291 branch.autosetupmerge
2292 branch.autosetuprebase
2296 color.branch.current
2301 color.decorate.branch
2302 color.decorate.remoteBranch
2303 color.decorate.stash
2313 color.diff.whitespace
2318 color.grep.linenumber
2321 color.grep.separator
2323 color.interactive.error
2324 color.interactive.header
2325 color.interactive.help
2326 color.interactive.prompt
2331 color.status.changed
2333 color.status.localBranch
2334 color.status.nobranch
2335 color.status.remoteBranch
2336 color.status.unmerged
2337 color.status.untracked
2338 color.status.updated
2350 core.bigFileThreshold
2355 core.deltaBaseCacheLimit
2360 core.fsyncobjectfiles
2366 core.logAllRefUpdates
2367 core.loosecompression
2370 core.packedGitWindowSize
2371 core.packedRefsTimeout
2373 core.precomposeUnicode
2374 core.preferSymlinkRefs
2379 core.repositoryFormatVersion
2381 core.sharedRepository
2388 core.warnAmbiguousRefs
2392 credential.useHttpPath
2394 credentialCache.ignoreSIGHUP
2395 diff.autorefreshindex
2397 diff.ignoreSubmodules
2404 diff.suppressBlankEmpty
2410 fetch.recurseSubmodules
2421 format.subjectprefix
2435 gc.reflogexpireunreachable
2438 gc.worktreePruneExpire
2440 gitcvs.commitmsgannotation
2441 gitcvs.dbTableNamePrefix
2452 gui.copyblamethreshold
2456 gui.matchtrackingbranch
2457 gui.newbranchtemplate
2458 gui.pruneduringfetch
2459 gui.spellingdictionary
2476 http.sslCertPasswordProtected
2481 i18n.logOutputEncoding
2487 imap.preformattedHTML
2497 interactive.singlekey
2513 mergetool.keepBackup
2514 mergetool.keepTemporaries
2519 notes.rewrite.rebase
2523 pack.deltaCacheLimit
2540 receive.denyCurrentBranch
2541 receive.denyDeleteCurrent
2543 receive.denyNonFastForwards
2546 receive.updateserverinfo
2549 repack.usedeltabaseoffset
2553 sendemail.aliasesfile
2554 sendemail.aliasfiletype
2558 sendemail.chainreplyto
2560 sendemail.envelopesender
2564 sendemail.signedoffbycc
2565 sendemail.smtpdomain
2566 sendemail.smtpencryption
2568 sendemail.smtpserver
2569 sendemail.smtpserveroption
2570 sendemail.smtpserverport
2572 sendemail.suppresscc
2573 sendemail.suppressfrom
2578 sendemail.smtpbatchsize
2579 sendemail.smtprelogindelay
2581 status.relativePaths
2582 status.showUntrackedFiles
2583 status.submodulesummary
2586 transfer.unpackLimit
2599 add rename remove set-head set-branches
2600 get-url set-url show prune update
2602 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2603 if [ -z "$subcommand" ]; then
2606 __gitcomp_builtin remote
2609 __gitcomp "$subcommands"
2615 case "$subcommand,$cur" in
2617 __gitcomp_builtin remote_add "--no-tags"
2622 __gitcomp_builtin remote_set-head
2625 __gitcomp_builtin remote_set-branches
2627 set-head,*|set-branches,*)
2628 __git_complete_remote_or_refspec
2631 __gitcomp_builtin remote_update
2634 __gitcomp "$(__git_get_config_variables "remotes")"
2637 __gitcomp_builtin remote_set-url
2640 __gitcomp_builtin remote_get-url
2643 __gitcomp_builtin remote_prune
2646 __gitcomp_nl "$(__git_remotes)"
2655 __gitcomp_builtin replace
2664 local subcommands="clear forget diff remaining status gc"
2665 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2666 if test -z "$subcommand"
2668 __gitcomp "$subcommands"
2675 __git_has_doubledash && return
2679 __gitcomp_builtin reset
2686 __git_revert_inprogress_options="--continue --quit --abort"
2690 __git_find_repo_path
2691 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2692 __gitcomp "$__git_revert_inprogress_options"
2697 __gitcomp_builtin revert "--no-edit" \
2698 "$__git_revert_inprogress_options"
2709 __gitcomp_builtin rm
2714 __git_complete_index_file "--cached"
2719 __git_has_doubledash && return
2724 $__git_log_common_options
2725 $__git_log_shortlog_options
2726 --numbered --summary --email
2731 __git_complete_revlist
2736 __git_has_doubledash && return
2739 --pretty=*|--format=*)
2740 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2745 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2749 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2753 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2755 $__git_diff_common_options
2760 __git_complete_revlist_file
2767 __gitcomp_builtin show-branch "--no-color"
2771 __git_complete_revlist
2776 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2777 local subcommands='push save list show apply clear drop pop create branch'
2778 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2779 if [ -z "$subcommand" ]; then
2782 __gitcomp "$save_opts"
2785 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2786 __gitcomp "$subcommands"
2791 case "$subcommand,$cur" in
2793 __gitcomp "$save_opts --message"
2796 __gitcomp "$save_opts"
2799 __gitcomp "--index --quiet"
2804 show,--*|branch,--*)
2807 if [ $cword -eq 3 ]; then
2810 __gitcomp_nl "$(__git stash list \
2811 | sed -n -e 's/:.*//p')"
2814 show,*|apply,*|drop,*|pop,*)
2815 __gitcomp_nl "$(__git stash list \
2816 | sed -n -e 's/:.*//p')"
2826 __git_has_doubledash && return
2828 local subcommands="add status init deinit update summary foreach sync"
2829 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2830 if [ -z "$subcommand" ]; then
2836 __gitcomp "$subcommands"
2842 case "$subcommand,$cur" in
2844 __gitcomp "--branch --force --name --reference --depth"
2847 __gitcomp "--cached --recursive"
2850 __gitcomp "--force --all"
2854 --init --remote --no-fetch
2855 --recommend-shallow --no-recommend-shallow
2856 --force --rebase --merge --reference --depth --recursive --jobs
2860 __gitcomp "--cached --files --summary-limit"
2862 foreach,--*|sync,--*)
2863 __gitcomp "--recursive"
2873 init fetch clone rebase dcommit log find-rev
2874 set-tree commit-diff info create-ignore propget
2875 proplist show-ignore show-externals branch tag blame
2876 migrate mkdirs reset gc
2878 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2879 if [ -z "$subcommand" ]; then
2880 __gitcomp "$subcommands"
2882 local remote_opts="--username= --config-dir= --no-auth-cache"
2884 --follow-parent --authors-file= --repack=
2885 --no-metadata --use-svm-props --use-svnsync-props
2886 --log-window-size= --no-checkout --quiet
2887 --repack-flags --use-log-author --localtime
2889 --ignore-paths= --include-paths= $remote_opts
2892 --template= --shared= --trunk= --tags=
2893 --branches= --stdlayout --minimize-url
2894 --no-metadata --use-svm-props --use-svnsync-props
2895 --rewrite-root= --prefix= $remote_opts
2898 --edit --rmdir --find-copies-harder --copy-similarity=
2901 case "$subcommand,$cur" in
2903 __gitcomp "--revision= --fetch-all $fc_opts"
2906 __gitcomp "--revision= $fc_opts $init_opts"
2909 __gitcomp "$init_opts"
2913 --merge --strategy= --verbose --dry-run
2914 --fetch-all --no-rebase --commit-url
2915 --revision --interactive $cmt_opts $fc_opts
2919 __gitcomp "--stdin $cmt_opts $fc_opts"
2921 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2922 show-externals,--*|mkdirs,--*)
2923 __gitcomp "--revision="
2927 --limit= --revision= --verbose --incremental
2928 --oneline --show-commit --non-recursive
2929 --authors-file= --color
2934 --merge --verbose --strategy= --local
2935 --fetch-all --dry-run $fc_opts
2939 __gitcomp "--message= --file= --revision= $cmt_opts"
2945 __gitcomp "--dry-run --message --tag"
2948 __gitcomp "--dry-run --message"
2951 __gitcomp "--git-format"
2955 --config-dir= --ignore-paths= --minimize
2956 --no-auth-cache --username=
2960 __gitcomp "--revision= --parent"
2971 while [ $c -lt $cword ]; do
2974 -d|--delete|-v|--verify)
2975 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2990 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3000 __gitcomp_builtin tag
3012 local subcommands="add list lock move prune remove unlock"
3013 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3014 if [ -z "$subcommand" ]; then
3015 __gitcomp "$subcommands"
3017 case "$subcommand,$cur" in
3019 __gitcomp_builtin worktree_add
3022 __gitcomp_builtin worktree_list
3025 __gitcomp_builtin worktree_lock
3028 __gitcomp_builtin worktree_prune
3041 local i c=1 command __git_dir __git_repo_path
3042 local __git_C_args C_args_count=0
3044 while [ $c -lt $cword ]; do
3047 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
3048 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
3049 --bare) __git_dir="." ;;
3050 --help) command="help"; break ;;
3051 -c|--work-tree|--namespace) ((c++)) ;;
3052 -C) __git_C_args[C_args_count++]=-C
3054 __git_C_args[C_args_count++]="${words[c]}"
3057 *) command="$i"; break ;;
3062 if [ -z "$command" ]; then
3064 --git-dir|-C|--work-tree)
3065 # these need a path argument, let's fall back to
3066 # Bash filename completion
3070 # we don't support completing these options' arguments
3088 --no-replace-objects
3092 *) __git_compute_porcelain_commands
3093 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
3098 local completion_func="_git_${command//-/_}"
3099 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
3101 local expansion=$(__git_aliased_command "$command")
3102 if [ -n "$expansion" ]; then
3104 completion_func="_git_${expansion//-/_}"
3105 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
3111 __git_has_doubledash && return
3113 local __git_repo_path
3114 __git_find_repo_path
3117 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3123 $__git_log_common_options
3124 $__git_log_gitk_options
3130 __git_complete_revlist
3133 if [[ -n ${ZSH_VERSION-} ]]; then
3134 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3136 autoload -U +X compinit && compinit
3142 local cur_="${3-$cur}"
3148 local c IFS=$' \t\n'
3156 array[${#array[@]}+1]="$c"
3159 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3170 compadd -Q -- ${=1} && _ret=0
3179 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3188 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3193 local _ret=1 cur cword prev
3194 cur=${words[CURRENT]}
3195 prev=${words[CURRENT-1]}
3197 emulate ksh -c __${service}_main
3198 let _ret && _default && _ret=0
3202 compdef _git git gitk
3208 local cur words cword prev
3209 _get_comp_words_by_ref -n =: cur words cword prev
3213 # Setup completion for certain functions defined above by setting common
3214 # variables and workarounds.
3215 # This is NOT a public function; use at your own risk.
3218 local wrapper="__git_wrap${2}"
3219 eval "$wrapper () { __git_func_wrap $2 ; }"
3220 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3221 || complete -o default -o nospace -F $wrapper $1
3224 # wrapper for backwards compatibility
3227 __git_wrap__git_main
3230 # wrapper for backwards compatibility
3233 __git_wrap__gitk_main
3236 __git_complete git __git_main
3237 __git_complete gitk __gitk_main
3239 # The following are necessary only for Cygwin, and only are needed
3240 # when the user has tab-completed the executable name and consequently
3241 # included the '.exe' suffix.
3243 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3244 __git_complete git.exe __git_main