1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 # Compatible with bash 3.2.57.
34 # You can set the following environment variables to influence the behavior of
35 # the completion routines:
37 # GIT_COMPLETION_CHECKOUT_NO_GUESS
39 # When set to "1", do not include "DWIM" suggestions in git-checkout
40 # completion (e.g., completing "foo" when "origin/foo" exists).
42 case "$COMP_WORDBREAKS" in
44 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
47 # Discovers the path to the git repository taking any '--git-dir=<path>' and
48 # '-C <path>' options into account and stores it in the $__git_repo_path
50 __git_find_repo_path ()
52 if [ -n "$__git_repo_path" ]; then
53 # we already know where it is
57 if [ -n "${__git_C_args-}" ]; then
58 __git_repo_path="$(git "${__git_C_args[@]}" \
59 ${__git_dir:+--git-dir="$__git_dir"} \
60 rev-parse --absolute-git-dir 2>/dev/null)"
61 elif [ -n "${__git_dir-}" ]; then
62 test -d "$__git_dir" &&
63 __git_repo_path="$__git_dir"
64 elif [ -n "${GIT_DIR-}" ]; then
65 test -d "${GIT_DIR-}" &&
66 __git_repo_path="$GIT_DIR"
67 elif [ -d .git ]; then
70 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
74 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
75 # __gitdir accepts 0 or 1 arguments (i.e., location)
76 # returns location of .git repo
79 if [ -z "${1-}" ]; then
80 __git_find_repo_path || return 1
81 echo "$__git_repo_path"
82 elif [ -d "$1/.git" ]; then
89 # Runs git with all the options given as argument, respecting any
90 # '--git-dir=<path>' and '-C <path>' options present on the command line
93 git ${__git_C_args:+"${__git_C_args[@]}"} \
94 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
97 # The following function is based on code from:
99 # bash_completion - programmable completion functions for bash 3.2+
101 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
102 # © 2009-2010, Bash Completion Maintainers
103 # <bash-completion-devel@lists.alioth.debian.org>
105 # This program is free software; you can redistribute it and/or modify
106 # it under the terms of the GNU General Public License as published by
107 # the Free Software Foundation; either version 2, or (at your option)
110 # This program is distributed in the hope that it will be useful,
111 # but WITHOUT ANY WARRANTY; without even the implied warranty of
112 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113 # GNU General Public License for more details.
115 # You should have received a copy of the GNU General Public License
116 # along with this program; if not, see <http://www.gnu.org/licenses/>.
118 # The latest version of this software can be obtained here:
120 # http://bash-completion.alioth.debian.org/
124 # This function can be used to access a tokenized list of words
125 # on the command line:
127 # __git_reassemble_comp_words_by_ref '=:'
128 # if test "${words_[cword_-1]}" = -w
133 # The argument should be a collection of characters from the list of
134 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
137 # This is roughly equivalent to going back in time and setting
138 # COMP_WORDBREAKS to exclude those characters. The intent is to
139 # make option types like --date=<type> and <rev>:<path> easy to
140 # recognize by treating each shell word as a single token.
142 # It is best not to set COMP_WORDBREAKS directly because the value is
143 # shared with other completion scripts. By the time the completion
144 # function gets called, COMP_WORDS has already been populated so local
145 # changes to COMP_WORDBREAKS have no effect.
147 # Output: words_, cword_, cur_.
149 __git_reassemble_comp_words_by_ref()
151 local exclude i j first
152 # Which word separators to exclude?
153 exclude="${1//[^$COMP_WORDBREAKS]}"
155 if [ -z "$exclude" ]; then
156 words_=("${COMP_WORDS[@]}")
159 # List of word completion separators has shrunk;
160 # re-assemble words to complete.
161 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
162 # Append each nonempty word consisting of just
163 # word separator characters to the current word.
167 [ -n "${COMP_WORDS[$i]}" ] &&
168 # word consists of excluded word separators
169 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
171 # Attach to the previous token,
172 # unless the previous token is the command name.
173 if [ $j -ge 2 ] && [ -n "$first" ]; then
177 words_[$j]=${words_[j]}${COMP_WORDS[i]}
178 if [ $i = $COMP_CWORD ]; then
181 if (($i < ${#COMP_WORDS[@]} - 1)); then
188 words_[$j]=${words_[j]}${COMP_WORDS[i]}
189 if [ $i = $COMP_CWORD ]; then
195 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
196 _get_comp_words_by_ref ()
198 local exclude cur_ words_ cword_
199 if [ "$1" = "-n" ]; then
203 __git_reassemble_comp_words_by_ref "$exclude"
204 cur_=${words_[cword_]}
205 while [ $# -gt 0 ]; do
211 prev=${words_[$cword_-1]}
214 words=("${words_[@]}")
225 # Fills the COMPREPLY array with prefiltered words without any additional
227 # Callers must take care of providing only words that match the current word
228 # to be completed and adding any prefix and/or suffix (trailing space!), if
230 # 1: List of newline-separated matching completion words, complete with
241 local x i=${#COMPREPLY[@]}
243 if [[ "$x" == "$3"* ]]; then
244 COMPREPLY[i++]="$2$x$4"
255 # Generates completion reply, appending a space to possible completion words,
257 # It accepts 1 to 4 arguments:
258 # 1: List of possible completion words.
259 # 2: A prefix to be added to each possible completion word (optional).
260 # 3: Generate possible completion matches for this word (optional).
261 # 4: A suffix to be appended to each possible completion word (optional).
264 local cur_="${3-$cur}"
270 local c i=0 IFS=$' \t\n'
272 if [[ $c == "--" ]]; then
276 if [[ $c == "$cur_"* ]]; then
281 COMPREPLY[i++]="${2-}$c"
286 local c i=0 IFS=$' \t\n'
288 if [[ $c == "--" ]]; then
290 if [[ $c == "$cur_"* ]]; then
291 COMPREPLY[i++]="${2-}$c "
296 if [[ $c == "$cur_"* ]]; then
301 COMPREPLY[i++]="${2-}$c"
308 # Clear the variables caching builtins' options when (re-)sourcing
309 # the completion script.
310 if [[ -n ${ZSH_VERSION-} ]]; then
311 unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
313 unset $(compgen -v __gitcomp_builtin_)
316 # This function is equivalent to
318 # __gitcomp "$(git xxx --git-completion-helper) ..."
320 # except that the output is cached. Accept 1-3 arguments:
321 # 1: the git command to execute, this is also the cache key
322 # 2: extra options to be added on top (e.g. negative forms)
323 # 3: options to be excluded
326 # spaces must be replaced with underscore for multi-word
327 # commands, e.g. "git remote add" becomes remote_add.
332 local var=__gitcomp_builtin_"${cmd/-/_}"
334 eval "options=\$$var"
336 if [ -z "$options" ]; then
337 # leading and trailing spaces are significant to make
338 # option removal work correctly.
339 options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
341 options="${options/ $i / }"
343 eval "$var=\"$options\""
349 # Variation of __gitcomp_nl () that appends to the existing list of
350 # completion candidates, COMPREPLY.
351 __gitcomp_nl_append ()
354 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
357 # Generates completion reply from newline-separated possible completion words
358 # by appending a space to all of them.
359 # It accepts 1 to 4 arguments:
360 # 1: List of possible completion words, separated by a single newline.
361 # 2: A prefix to be added to each possible completion word (optional).
362 # 3: Generate possible completion matches for this word (optional).
363 # 4: A suffix to be appended to each possible completion word instead of
364 # the default space (optional). If specified but empty, nothing is
369 __gitcomp_nl_append "$@"
372 # Generates completion reply with compgen from newline-separated possible
373 # completion filenames.
374 # It accepts 1 to 3 arguments:
375 # 1: List of possible completion filenames, separated by a single newline.
376 # 2: A directory prefix to be added to each possible completion filename
378 # 3: Generate possible completion matches for this word (optional).
383 # XXX does not work when the directory prefix contains a tilde,
384 # since tilde expansion is not applied.
385 # This means that COMPREPLY will be empty and Bash default
386 # completion will be used.
387 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
389 # use a hack to enable file mode in bash < 4
390 compopt -o filenames +o nospace 2>/dev/null ||
391 compgen -f /non-existing-dir/ > /dev/null
394 # Execute 'git ls-files', unless the --committable option is specified, in
395 # which case it runs 'git diff-index' to find out the files that can be
396 # committed. It return paths relative to the directory specified in the first
397 # argument, and using the options specified in the second argument.
398 __git_ls_files_helper ()
400 if [ "$2" == "--committable" ]; then
401 __git -C "$1" diff-index --name-only --relative HEAD
403 # NOTE: $2 is not quoted in order to support multiple options
404 __git -C "$1" ls-files --exclude-standard $2
409 # __git_index_files accepts 1 or 2 arguments:
410 # 1: Options to pass to ls-files (required).
411 # 2: A directory path (optional).
412 # If provided, only files within the specified directory are listed.
413 # Sub directories are never recursed. Path must have a trailing
417 local root="${2-.}" file
419 __git_ls_files_helper "$root" "$1" |
420 cut -f1 -d/ | sort | uniq
423 # Lists branches from the local repository.
424 # 1: A prefix to be added to each listed branch (optional).
425 # 2: List only branches matching this word (optional; list all branches if
427 # 3: A suffix to be appended to each listed branch (optional).
430 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
432 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
433 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
436 # Lists tags from the local repository.
437 # Accepts the same positional parameters as __git_heads() above.
440 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
442 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
443 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
446 # Lists refs from the local (by default) or from a remote repository.
447 # It accepts 0, 1 or 2 arguments:
448 # 1: The remote to list refs from (optional; ignored, if set but empty).
449 # Can be the name of a configured remote, a path, or a URL.
450 # 2: In addition to local refs, list unique branches from refs/remotes/ for
451 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
452 # 3: A prefix to be added to each listed ref (optional).
453 # 4: List only refs matching this word (optional; list all refs if unset or
455 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
458 # Use __git_complete_refs() instead.
461 local i hash dir track="${2-}"
462 local list_refs_from=path remote="${1-}"
464 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
466 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
469 dir="$__git_repo_path"
471 if [ -z "$remote" ]; then
472 if [ -z "$dir" ]; then
476 if __git_is_configured_remote "$remote"; then
477 # configured remote takes precedence over a
478 # local directory with the same name
479 list_refs_from=remote
480 elif [ -d "$remote/.git" ]; then
482 elif [ -d "$remote" ]; then
489 if [ "$list_refs_from" = path ]; then
490 if [[ "$cur_" == ^* ]]; then
499 refs=("$match*" "$match*/**")
503 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
506 if [ -e "$dir/$i" ]; then
512 format="refname:strip=2"
513 refs=("refs/tags/$match*" "refs/tags/$match*/**"
514 "refs/heads/$match*" "refs/heads/$match*/**"
515 "refs/remotes/$match*" "refs/remotes/$match*/**")
518 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
520 if [ -n "$track" ]; then
521 # employ the heuristic used by git checkout
522 # Try to find a remote branch that matches the completion word
523 # but only output if the branch name is unique
524 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
525 --sort="refname:strip=3" \
526 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
533 __git ls-remote "$remote" "$match*" | \
534 while read -r hash i; do
537 *) echo "$pfx$i$sfx" ;;
542 if [ "$list_refs_from" = remote ]; then
544 $match*) echo "${pfx}HEAD$sfx" ;;
546 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
547 "refs/remotes/$remote/$match*" \
548 "refs/remotes/$remote/$match*/**"
552 $match*) query_symref="HEAD" ;;
554 __git ls-remote "$remote" $query_symref \
555 "refs/tags/$match*" "refs/heads/$match*" \
556 "refs/remotes/$match*" |
557 while read -r hash i; do
560 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
561 *) echo "$pfx$i$sfx" ;; # symbolic refs
569 # Completes refs, short and long, local and remote, symbolic and pseudo.
571 # Usage: __git_complete_refs [<option>]...
572 # --remote=<remote>: The remote to list refs from, can be the name of a
573 # configured remote, a path, or a URL.
574 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
575 # --pfx=<prefix>: A prefix to be added to each ref.
576 # --cur=<word>: The current ref to be completed. Defaults to the current
577 # word to be completed.
578 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
580 __git_complete_refs ()
582 local remote track pfx cur_="$cur" sfx=" "
584 while test $# != 0; do
586 --remote=*) remote="${1##--remote=}" ;;
587 --track) track="yes" ;;
588 --pfx=*) pfx="${1##--pfx=}" ;;
589 --cur=*) cur_="${1##--cur=}" ;;
590 --sfx=*) sfx="${1##--sfx=}" ;;
596 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
599 # __git_refs2 requires 1 argument (to pass to __git_refs)
600 # Deprecated: use __git_complete_fetch_refspecs() instead.
604 for i in $(__git_refs "$1"); do
609 # Completes refspecs for fetching from a remote repository.
610 # 1: The remote repository.
611 # 2: A prefix to be added to each listed refspec (optional).
612 # 3: The ref to be completed as a refspec instead of the current word to be
613 # completed (optional)
614 # 4: A suffix to be appended to each listed refspec instead of the default
616 __git_complete_fetch_refspecs ()
618 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
621 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
627 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
628 __git_refs_remotes ()
631 __git ls-remote "$1" 'refs/heads/*' | \
632 while read -r hash i; do
633 echo "$i:refs/remotes/$1/${i#refs/heads/}"
640 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
644 # Returns true if $1 matches the name of a configured remote, false otherwise.
645 __git_is_configured_remote ()
648 for remote in $(__git_remotes); do
649 if [ "$remote" = "$1" ]; then
656 __git_list_merge_strategies ()
658 LANG=C LC_ALL=C git merge -s help 2>&1 |
659 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
668 __git_merge_strategies=
669 # 'git merge -s help' (and thus detection of the merge strategy
670 # list) fails, unfortunately, if run outside of any git working
671 # tree. __git_merge_strategies is set to the empty string in
672 # that case, and the detection will be repeated the next time it
674 __git_compute_merge_strategies ()
676 test -n "$__git_merge_strategies" ||
677 __git_merge_strategies=$(__git_list_merge_strategies)
680 __git_complete_revlist_file ()
682 local pfx ls ref cur_="$cur"
702 case "$COMP_WORDBREAKS" in
704 *) pfx="$ref:$pfx" ;;
707 __gitcomp_nl "$(__git ls-tree "$ls" \
708 | sed '/^100... blob /{
724 pfx="${cur_%...*}..."
726 __git_complete_refs --pfx="$pfx" --cur="$cur_"
731 __git_complete_refs --pfx="$pfx" --cur="$cur_"
740 # __git_complete_index_file requires 1 argument:
741 # 1: the options to pass to ls-file
743 # The exception is --committable, which finds the files appropriate commit.
744 __git_complete_index_file ()
746 local pfx="" cur_="$cur"
756 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
759 __git_complete_file ()
761 __git_complete_revlist_file
764 __git_complete_revlist ()
766 __git_complete_revlist_file
769 __git_complete_remote_or_refspec ()
771 local cur_="$cur" cmd="${words[1]}"
772 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
773 if [ "$cmd" = "remote" ]; then
776 while [ $c -lt $cword ]; do
779 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
780 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
783 push) no_complete_refspec=1 ;;
791 *) remote="$i"; break ;;
795 if [ -z "$remote" ]; then
796 __gitcomp_nl "$(__git_remotes)"
799 if [ $no_complete_refspec = 1 ]; then
802 [ "$remote" = "." ] && remote=
805 case "$COMP_WORDBREAKS" in
807 *) pfx="${cur_%%:*}:" ;;
819 if [ $lhs = 1 ]; then
820 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
822 __git_complete_refs --pfx="$pfx" --cur="$cur_"
826 if [ $lhs = 1 ]; then
827 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
829 __git_complete_refs --pfx="$pfx" --cur="$cur_"
833 if [ $lhs = 1 ]; then
834 __git_complete_refs --pfx="$pfx" --cur="$cur_"
836 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
842 __git_complete_strategy ()
844 __git_compute_merge_strategies
847 __gitcomp "$__git_merge_strategies"
852 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
860 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
862 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
864 git help -a|egrep '^ [a-zA-Z0-9]'
868 __git_list_all_commands ()
871 for i in $(__git_commands)
874 *--*) : helper pattern;;
881 __git_compute_all_commands ()
883 test -n "$__git_all_commands" ||
884 __git_all_commands=$(__git_list_all_commands)
887 __git_list_porcelain_commands ()
890 __git_compute_all_commands
891 for i in $__git_all_commands
894 *--*) : helper pattern;;
895 applymbox) : ask gittus;;
896 applypatch) : ask gittus;;
897 archimport) : import;;
898 cat-file) : plumbing;;
899 check-attr) : plumbing;;
900 check-ignore) : plumbing;;
901 check-mailmap) : plumbing;;
902 check-ref-format) : plumbing;;
903 checkout-index) : plumbing;;
904 column) : internal helper;;
905 commit-graph) : plumbing;;
906 commit-tree) : plumbing;;
907 count-objects) : infrequent;;
908 credential) : credentials;;
909 credential-*) : credentials helper;;
910 cvsexportcommit) : export;;
911 cvsimport) : import;;
912 cvsserver) : daemon;;
914 diff-files) : plumbing;;
915 diff-index) : plumbing;;
916 diff-tree) : plumbing;;
917 fast-import) : import;;
918 fast-export) : export;;
919 fsck-objects) : plumbing;;
920 fetch-pack) : plumbing;;
921 fmt-merge-msg) : plumbing;;
922 for-each-ref) : plumbing;;
923 hash-object) : plumbing;;
924 http-*) : transport;;
925 index-pack) : plumbing;;
926 init-db) : deprecated;;
927 local-fetch) : plumbing;;
928 ls-files) : plumbing;;
929 ls-remote) : plumbing;;
930 ls-tree) : plumbing;;
931 mailinfo) : plumbing;;
932 mailsplit) : plumbing;;
933 merge-*) : plumbing;;
936 pack-objects) : plumbing;;
937 pack-redundant) : plumbing;;
938 pack-refs) : plumbing;;
939 parse-remote) : plumbing;;
940 patch-id) : plumbing;;
942 prune-packed) : plumbing;;
943 quiltimport) : import;;
944 read-tree) : plumbing;;
945 receive-pack) : plumbing;;
946 remote-*) : transport;;
948 rev-list) : plumbing;;
949 rev-parse) : plumbing;;
950 runstatus) : plumbing;;
951 sh-setup) : internal;;
953 show-ref) : plumbing;;
954 send-pack) : plumbing;;
955 show-index) : plumbing;;
957 stripspace) : plumbing;;
958 symbolic-ref) : plumbing;;
959 unpack-file) : plumbing;;
960 unpack-objects) : plumbing;;
961 update-index) : plumbing;;
962 update-ref) : plumbing;;
963 update-server-info) : daemon;;
964 upload-archive) : plumbing;;
965 upload-pack) : plumbing;;
966 write-tree) : plumbing;;
968 verify-pack) : infrequent;;
969 verify-tag) : plumbing;;
975 __git_porcelain_commands=
976 __git_compute_porcelain_commands ()
978 test -n "$__git_porcelain_commands" ||
979 __git_porcelain_commands=$(__git_list_porcelain_commands)
982 # Lists all set config variables starting with the given section prefix,
983 # with the prefix removed.
984 __git_get_config_variables ()
986 local section="$1" i IFS=$'\n'
987 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
988 echo "${i#$section.}"
992 __git_pretty_aliases ()
994 __git_get_config_variables "pretty"
999 __git_get_config_variables "alias"
1002 # __git_aliased_command requires 1 argument
1003 __git_aliased_command ()
1005 local word cmdline=$(__git config --get "alias.$1")
1006 for word in $cmdline; do
1012 \!*) : shell command alias ;;
1014 *=*) : setting env ;;
1015 git) : git itself ;;
1016 \(\)) : skip parens of shell function definition ;;
1017 {) : skip start of shell helper function ;;
1018 :) : skip null command ;;
1019 \'*) : skip opening quote after sh -c ;;
1027 # __git_find_on_cmdline requires 1 argument
1028 __git_find_on_cmdline ()
1030 local word subcommand c=1
1031 while [ $c -lt $cword ]; do
1033 for subcommand in $1; do
1034 if [ "$subcommand" = "$word" ]; then
1043 # Echo the value of an option set on the command line or config
1045 # $1: short option name
1046 # $2: long option name including =
1047 # $3: list of possible values
1048 # $4: config string (optional)
1051 # result="$(__git_get_option_value "-d" "--do-something=" \
1052 # "yes no" "core.doSomething")"
1054 # result is then either empty (no option set) or "yes" or "no"
1056 # __git_get_option_value requires 3 arguments
1057 __git_get_option_value ()
1059 local c short_opt long_opt val
1060 local result= values config_key word
1068 while [ $c -ge 0 ]; do
1070 for val in $values; do
1071 if [ "$short_opt$val" = "$word" ] ||
1072 [ "$long_opt$val" = "$word" ]; then
1080 if [ -n "$config_key" ] && [ -z "$result" ]; then
1081 result="$(__git config "$config_key")"
1087 __git_has_doubledash ()
1090 while [ $c -lt $cword ]; do
1091 if [ "--" = "${words[c]}" ]; then
1099 # Try to count non option arguments passed on the command line for the
1100 # specified git command.
1101 # When options are used, it is necessary to use the special -- option to
1102 # tell the implementation were non option arguments begin.
1103 # XXX this can not be improved, since options can appear everywhere, as
1107 # __git_count_arguments requires 1 argument: the git command executed.
1108 __git_count_arguments ()
1112 # Skip "git" (first argument)
1113 for ((i=1; i < ${#words[@]}; i++)); do
1118 # Good; we can assume that the following are only non
1123 # Skip the specified git command and discard git
1136 __git_whitespacelist="nowarn warn error error-all fix"
1137 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1141 __git_find_repo_path
1142 if [ -d "$__git_repo_path"/rebase-apply ]; then
1143 __gitcomp "$__git_am_inprogress_options"
1148 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1152 __gitcomp_builtin am "" \
1153 "$__git_am_inprogress_options"
1162 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1166 __gitcomp_builtin apply
1175 __gitcomp_builtin add
1179 local complete_opt="--others --modified --directory --no-empty-directory"
1180 if test -n "$(__git_find_on_cmdline "-u --update")"
1182 complete_opt="--modified"
1184 __git_complete_index_file "$complete_opt"
1191 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1195 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1200 --format= --list --verbose
1201 --prefix= --remote= --exec= --output
1211 __git_has_doubledash && return
1213 local subcommands="start bad good skip reset visualize replay log run"
1214 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1215 if [ -z "$subcommand" ]; then
1216 __git_find_repo_path
1217 if [ -f "$__git_repo_path"/BISECT_START ]; then
1218 __gitcomp "$subcommands"
1220 __gitcomp "replay start"
1225 case "$subcommand" in
1226 bad|good|reset|skip|start)
1236 local i c=1 only_local_ref="n" has_r="n"
1238 while [ $c -lt $cword ]; do
1241 -d|--delete|-m|--move) only_local_ref="y" ;;
1242 -r|--remotes) has_r="y" ;;
1248 --set-upstream-to=*)
1249 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1252 __gitcomp_builtin branch
1255 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1256 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1266 local cmd="${words[2]}"
1269 __gitcomp "create list-heads verify unbundle"
1272 # looking for a file
1277 __git_complete_revlist
1286 __git_has_doubledash && return
1290 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1293 __gitcomp_builtin checkout
1296 # check if --track, --no-track, or --no-guess was specified
1297 # if so, disable DWIM mode
1298 local flags="--track --no-track --no-guess" track_opt="--track"
1299 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1300 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1303 __git_complete_refs $track_opt
1312 __gitcomp_builtin cherry
1319 __git_cherry_pick_inprogress_options="--continue --quit --abort"
1323 __git_find_repo_path
1324 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1325 __gitcomp "$__git_cherry_pick_inprogress_options"
1330 __gitcomp_builtin cherry-pick "" \
1331 "$__git_cherry_pick_inprogress_options"
1343 __gitcomp_builtin clean
1348 # XXX should we check for -x option ?
1349 __git_complete_index_file "--others --directory"
1356 __gitcomp_builtin clone
1362 __git_untracked_file_modes="all no normal"
1375 __gitcomp "default scissors strip verbatim whitespace
1376 " "" "${cur##--cleanup=}"
1379 --reuse-message=*|--reedit-message=*|\
1380 --fixup=*|--squash=*)
1381 __git_complete_refs --cur="${cur#*=}"
1384 --untracked-files=*)
1385 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1389 __gitcomp_builtin commit
1393 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1394 __git_complete_index_file "--committable"
1396 # This is the first commit
1397 __git_complete_index_file "--cached"
1405 __gitcomp_builtin describe
1411 __git_diff_algorithms="myers minimal patience histogram"
1413 __git_diff_submodule_formats="diff log short"
1415 __git_diff_common_options="--stat --numstat --shortstat --summary
1416 --patch-with-stat --name-only --name-status --color
1417 --no-color --color-words --no-renames --check
1418 --full-index --binary --abbrev --diff-filter=
1419 --find-copies-harder --ignore-cr-at-eol
1420 --text --ignore-space-at-eol --ignore-space-change
1421 --ignore-all-space --ignore-blank-lines --exit-code
1422 --quiet --ext-diff --no-ext-diff
1423 --no-prefix --src-prefix= --dst-prefix=
1424 --inter-hunk-context=
1425 --patience --histogram --minimal
1426 --raw --word-diff --word-diff-regex=
1427 --dirstat --dirstat= --dirstat-by-file
1428 --dirstat-by-file= --cumulative
1430 --submodule --submodule= --ignore-submodules
1435 __git_has_doubledash && return
1439 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1443 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1447 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1448 --base --ours --theirs --no-index
1449 $__git_diff_common_options
1454 __git_complete_revlist_file
1457 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1458 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1463 __git_has_doubledash && return
1467 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1471 __gitcomp_builtin difftool "$__git_diff_common_options
1472 --base --cached --ours --theirs
1473 --pickaxe-all --pickaxe-regex
1479 __git_complete_revlist_file
1482 __git_fetch_recurse_submodules="yes on-demand no"
1487 --recurse-submodules=*)
1488 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1492 __gitcomp_builtin fetch
1496 __git_complete_remote_or_refspec
1499 __git_format_patch_options="
1500 --stdout --attach --no-attach --thread --thread= --no-thread
1501 --numbered --start-number --numbered-files --keep-subject --signoff
1502 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1503 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1504 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1505 --output-directory --reroll-count --to= --quiet --notes
1508 _git_format_patch ()
1514 " "" "${cur##--thread=}"
1518 __gitcomp "$__git_format_patch_options"
1522 __git_complete_revlist
1529 __gitcomp_builtin fsck
1540 # Lists matching symbol names from a tag (as in ctags) file.
1541 # 1: List symbol names matching this word.
1542 # 2: The tag file to list symbol names from.
1543 # 3: A prefix to be added to each listed symbol name (optional).
1544 # 4: A suffix to be appended to each listed symbol name (optional).
1545 __git_match_ctag () {
1546 awk -v pfx="${3-}" -v sfx="${4-}" "
1547 /^${1//\//\\/}/ { print pfx \$1 sfx }
1551 # Complete symbol names from a tag file.
1552 # Usage: __git_complete_symbol [<option>]...
1553 # --tags=<file>: The tag file to list symbol names from instead of the
1555 # --pfx=<prefix>: A prefix to be added to each symbol name.
1556 # --cur=<word>: The current symbol name to be completed. Defaults to
1557 # the current word to be completed.
1558 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1559 # of the default space.
1560 __git_complete_symbol () {
1561 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1563 while test $# != 0; do
1565 --tags=*) tags="${1##--tags=}" ;;
1566 --pfx=*) pfx="${1##--pfx=}" ;;
1567 --cur=*) cur_="${1##--cur=}" ;;
1568 --sfx=*) sfx="${1##--sfx=}" ;;
1574 if test -r "$tags"; then
1575 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1581 __git_has_doubledash && return
1585 __gitcomp_builtin grep
1590 case "$cword,$prev" in
1592 __git_complete_symbol && return
1603 __gitcomp_builtin help
1607 __git_compute_all_commands
1608 __gitcomp "$__git_all_commands $(__git_aliases)
1609 attributes cli core-tutorial cvs-migration
1610 diffcore everyday gitk glossary hooks ignore modules
1611 namespaces repository-layout revisions tutorial tutorial-2
1621 false true umask group all world everybody
1622 " "" "${cur##--shared=}"
1626 __gitcomp_builtin init
1636 __gitcomp_builtin ls-files
1641 # XXX ignore options like --modified and always suggest all cached
1643 __git_complete_index_file "--cached"
1650 __gitcomp_builtin ls-remote
1654 __gitcomp_nl "$(__git_remotes)"
1661 __gitcomp_builtin ls-tree
1669 # Options that go well for log, shortlog and gitk
1670 __git_log_common_options="
1672 --branches --tags --remotes
1673 --first-parent --merges --no-merges
1675 --max-age= --since= --after=
1676 --min-age= --until= --before=
1677 --min-parents= --max-parents=
1678 --no-min-parents --no-max-parents
1680 # Options that go well for log and gitk (not shortlog)
1681 __git_log_gitk_options="
1682 --dense --sparse --full-history
1683 --simplify-merges --simplify-by-decoration
1684 --left-right --notes --no-notes
1686 # Options that go well for log and shortlog (not gitk)
1687 __git_log_shortlog_options="
1688 --author= --committer= --grep=
1689 --all-match --invert-grep
1692 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1693 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1697 __git_has_doubledash && return
1698 __git_find_repo_path
1701 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1704 case "$prev,$cur" in
1706 return # fall back to Bash filename completion
1709 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1713 __git_complete_symbol
1718 --pretty=*|--format=*)
1719 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1724 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1728 __gitcomp "full short no" "" "${cur##--decorate=}"
1732 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1736 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1741 $__git_log_common_options
1742 $__git_log_shortlog_options
1743 $__git_log_gitk_options
1744 --root --topo-order --date-order --reverse
1745 --follow --full-diff
1746 --abbrev-commit --abbrev=
1747 --relative-date --date=
1748 --pretty= --format= --oneline
1753 --decorate --decorate=
1755 --parents --children
1757 $__git_diff_common_options
1758 --pickaxe-all --pickaxe-regex
1763 return # fall back to Bash filename completion
1766 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1770 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1774 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1778 __git_complete_revlist
1783 __git_complete_strategy && return
1787 __gitcomp_builtin merge
1797 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1801 __gitcomp "--tool= --prompt --no-prompt"
1811 __gitcomp_builtin merge-base
1822 __gitcomp_builtin mv
1827 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1828 # We need to show both cached and untracked files (including
1829 # empty directories) since this may not be the last argument.
1830 __git_complete_index_file "--cached --others --directory"
1832 __git_complete_index_file "--cached"
1838 local subcommands='add append copy edit get-ref list merge prune remove show'
1839 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1841 case "$subcommand,$cur" in
1843 __gitcomp_builtin notes
1851 __gitcomp "$subcommands --ref"
1855 *,--reuse-message=*|*,--reedit-message=*)
1856 __git_complete_refs --cur="${cur#*=}"
1859 __gitcomp_builtin notes_$subcommand
1862 # this command does not take a ref, do not complete it
1878 __git_complete_strategy && return
1881 --recurse-submodules=*)
1882 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1886 __gitcomp_builtin pull
1891 __git_complete_remote_or_refspec
1894 __git_push_recurse_submodules="check on-demand only"
1896 __git_complete_force_with_lease ()
1904 __git_complete_refs --cur="${cur_#*:}"
1907 __git_complete_refs --cur="$cur_"
1916 __gitcomp_nl "$(__git_remotes)"
1919 --recurse-submodules)
1920 __gitcomp "$__git_push_recurse_submodules"
1926 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1929 --recurse-submodules=*)
1930 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1933 --force-with-lease=*)
1934 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1938 __gitcomp_builtin push
1942 __git_complete_remote_or_refspec
1947 __git_find_repo_path
1948 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1949 __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
1951 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1952 [ -d "$__git_repo_path"/rebase-merge ]; then
1953 __gitcomp "--continue --skip --abort --quit --show-current-patch"
1956 __git_complete_strategy && return
1959 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1964 --onto --merge --strategy --interactive
1965 --rebase-merges --preserve-merges --stat --no-stat
1966 --committer-date-is-author-date --ignore-date
1967 --ignore-whitespace --whitespace=
1968 --autosquash --no-autosquash
1969 --fork-point --no-fork-point
1970 --autostash --no-autostash
1971 --verify --no-verify
1972 --keep-empty --root --force-rebase --no-ff
1984 local subcommands="show delete expire"
1985 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1987 if [ -z "$subcommand" ]; then
1988 __gitcomp "$subcommands"
1994 __git_send_email_confirm_options="always never auto cc compose"
1995 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2000 --to|--cc|--bcc|--from)
2001 __gitcomp "$(__git send-email --dump-aliases)"
2009 $__git_send_email_confirm_options
2010 " "" "${cur##--confirm=}"
2015 $__git_send_email_suppresscc_options
2016 " "" "${cur##--suppress-cc=}"
2020 --smtp-encryption=*)
2021 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2027 " "" "${cur##--thread=}"
2030 --to=*|--cc=*|--bcc=*|--from=*)
2031 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2035 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2036 --compose --confirm= --dry-run --envelope-sender
2038 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2039 --no-suppress-from --no-thread --quiet --reply-to
2040 --signed-off-by-cc --smtp-pass --smtp-server
2041 --smtp-server-port --smtp-encryption= --smtp-user
2042 --subject --suppress-cc= --suppress-from --thread --to
2043 --validate --no-validate
2044 $__git_format_patch_options"
2048 __git_complete_revlist
2059 local untracked_state
2062 --ignore-submodules=*)
2063 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2066 --untracked-files=*)
2067 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2072 always never auto column row plain dense nodense
2073 " "" "${cur##--column=}"
2077 __gitcomp_builtin status
2082 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2083 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2085 case "$untracked_state" in
2087 # --ignored option does not matter
2091 complete_opt="--cached --directory --no-empty-directory --others"
2093 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2094 complete_opt="$complete_opt --ignored --exclude=*"
2099 __git_complete_index_file "$complete_opt"
2102 __git_config_get_set_variables ()
2104 local prevword word config_file= c=$cword
2105 while [ $c -gt 1 ]; do
2108 --system|--global|--local|--file=*)
2113 config_file="$word $prevword"
2121 __git config $config_file --name-only --list
2127 branch.*.remote|branch.*.pushremote)
2128 __gitcomp_nl "$(__git_remotes)"
2136 __gitcomp "false true merges preserve interactive"
2140 __gitcomp_nl "$(__git_remotes)"
2144 local remote="${prev#remote.}"
2145 remote="${remote%.fetch}"
2146 if [ -z "$cur" ]; then
2147 __gitcomp_nl "refs/heads/" "" "" ""
2150 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2154 local remote="${prev#remote.}"
2155 remote="${remote%.push}"
2156 __gitcomp_nl "$(__git for-each-ref \
2157 --format='%(refname):%(refname)' refs/heads)"
2160 pull.twohead|pull.octopus)
2161 __git_compute_merge_strategies
2162 __gitcomp "$__git_merge_strategies"
2165 color.branch|color.diff|color.interactive|\
2166 color.showbranch|color.status|color.ui)
2167 __gitcomp "always never auto"
2171 __gitcomp "false true"
2176 normal black red green yellow blue magenta cyan white
2177 bold dim ul blink reverse
2182 __gitcomp "log short"
2186 __gitcomp "man info web html"
2190 __gitcomp "$__git_log_date_formats"
2193 sendemail.aliasfiletype)
2194 __gitcomp "mutt mailrc pine elm gnus"
2198 __gitcomp "$__git_send_email_confirm_options"
2201 sendemail.suppresscc)
2202 __gitcomp "$__git_send_email_suppresscc_options"
2205 sendemail.transferencoding)
2206 __gitcomp "7bit 8bit quoted-printable base64"
2209 --get|--get-all|--unset|--unset-all)
2210 __gitcomp_nl "$(__git_config_get_set_variables)"
2219 __gitcomp_builtin config
2223 local pfx="${cur%.*}." cur_="${cur##*.}"
2224 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2228 local pfx="${cur%.*}." cur_="${cur#*.}"
2229 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2230 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2234 local pfx="${cur%.*}." cur_="${cur##*.}"
2236 argprompt cmd confirm needsfile noconsole norescan
2237 prompt revprompt revunmerged title
2242 local pfx="${cur%.*}." cur_="${cur##*.}"
2243 __gitcomp "cmd path" "$pfx" "$cur_"
2247 local pfx="${cur%.*}." cur_="${cur##*.}"
2248 __gitcomp "cmd path" "$pfx" "$cur_"
2252 local pfx="${cur%.*}." cur_="${cur##*.}"
2253 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2257 local pfx="${cur%.*}." cur_="${cur#*.}"
2258 __git_compute_all_commands
2259 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2263 local pfx="${cur%.*}." cur_="${cur##*.}"
2265 url proxy fetch push mirror skipDefaultUpdate
2266 receivepack uploadpack tagopt pushurl
2271 local pfx="${cur%.*}." cur_="${cur#*.}"
2272 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2273 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2277 local pfx="${cur%.*}." cur_="${cur##*.}"
2278 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2285 advice.commitBeforeMerge
2287 advice.implicitIdentity
2288 advice.pushAlreadyExists
2289 advice.pushFetchFirst
2290 advice.pushNeedsForce
2291 advice.pushNonFFCurrent
2292 advice.pushNonFFMatching
2293 advice.pushUpdateRejected
2294 advice.resolveConflict
2297 advice.statusUoption
2302 apply.ignorewhitespace
2304 branch.autosetupmerge
2305 branch.autosetuprebase
2309 color.branch.current
2314 color.decorate.branch
2315 color.decorate.remoteBranch
2316 color.decorate.stash
2326 color.diff.whitespace
2331 color.grep.linenumber
2334 color.grep.separator
2336 color.interactive.error
2337 color.interactive.header
2338 color.interactive.help
2339 color.interactive.prompt
2344 color.status.changed
2346 color.status.localBranch
2347 color.status.nobranch
2348 color.status.remoteBranch
2349 color.status.unmerged
2350 color.status.untracked
2351 color.status.updated
2363 core.bigFileThreshold
2369 core.deltaBaseCacheLimit
2374 core.fsyncobjectfiles
2380 core.logAllRefUpdates
2381 core.loosecompression
2384 core.packedGitWindowSize
2385 core.packedRefsTimeout
2387 core.precomposeUnicode
2388 core.preferSymlinkRefs
2393 core.repositoryFormatVersion
2395 core.sharedRepository
2402 core.warnAmbiguousRefs
2406 credential.useHttpPath
2408 credentialCache.ignoreSIGHUP
2409 diff.autorefreshindex
2411 diff.ignoreSubmodules
2418 diff.suppressBlankEmpty
2424 fetch.recurseSubmodules
2435 format.subjectprefix
2449 gc.reflogexpireunreachable
2452 gc.worktreePruneExpire
2454 gitcvs.commitmsgannotation
2455 gitcvs.dbTableNamePrefix
2466 gui.copyblamethreshold
2470 gui.matchtrackingbranch
2471 gui.newbranchtemplate
2472 gui.pruneduringfetch
2473 gui.spellingdictionary
2490 http.sslCertPasswordProtected
2495 i18n.logOutputEncoding
2501 imap.preformattedHTML
2511 interactive.singlekey
2527 mergetool.keepBackup
2528 mergetool.keepTemporaries
2533 notes.rewrite.rebase
2537 pack.deltaCacheLimit
2554 receive.denyCurrentBranch
2555 receive.denyDeleteCurrent
2557 receive.denyNonFastForwards
2560 receive.updateserverinfo
2563 repack.usedeltabaseoffset
2567 sendemail.aliasesfile
2568 sendemail.aliasfiletype
2572 sendemail.chainreplyto
2574 sendemail.envelopesender
2578 sendemail.signedoffbycc
2579 sendemail.smtpdomain
2580 sendemail.smtpencryption
2582 sendemail.smtpserver
2583 sendemail.smtpserveroption
2584 sendemail.smtpserverport
2586 sendemail.suppresscc
2587 sendemail.suppressfrom
2592 sendemail.smtpbatchsize
2593 sendemail.smtprelogindelay
2595 status.relativePaths
2596 status.showUntrackedFiles
2597 status.submodulesummary
2600 transfer.unpackLimit
2613 add rename remove set-head set-branches
2614 get-url set-url show prune update
2616 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2617 if [ -z "$subcommand" ]; then
2620 __gitcomp_builtin remote
2623 __gitcomp "$subcommands"
2629 case "$subcommand,$cur" in
2631 __gitcomp_builtin remote_add
2636 __gitcomp_builtin remote_set-head
2639 __gitcomp_builtin remote_set-branches
2641 set-head,*|set-branches,*)
2642 __git_complete_remote_or_refspec
2645 __gitcomp_builtin remote_update
2648 __gitcomp "$(__git_get_config_variables "remotes")"
2651 __gitcomp_builtin remote_set-url
2654 __gitcomp_builtin remote_get-url
2657 __gitcomp_builtin remote_prune
2660 __gitcomp_nl "$(__git_remotes)"
2669 __gitcomp_builtin replace
2678 local subcommands="clear forget diff remaining status gc"
2679 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2680 if test -z "$subcommand"
2682 __gitcomp "$subcommands"
2689 __git_has_doubledash && return
2693 __gitcomp_builtin reset
2700 __git_revert_inprogress_options="--continue --quit --abort"
2704 __git_find_repo_path
2705 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2706 __gitcomp "$__git_revert_inprogress_options"
2711 __gitcomp_builtin revert "" \
2712 "$__git_revert_inprogress_options"
2723 __gitcomp_builtin rm
2728 __git_complete_index_file "--cached"
2733 __git_has_doubledash && return
2738 $__git_log_common_options
2739 $__git_log_shortlog_options
2740 --numbered --summary --email
2745 __git_complete_revlist
2750 __git_has_doubledash && return
2753 --pretty=*|--format=*)
2754 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2759 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2763 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2767 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2769 $__git_diff_common_options
2774 __git_complete_revlist_file
2781 __gitcomp_builtin show-branch
2785 __git_complete_revlist
2790 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2791 local subcommands='push list show apply clear drop pop create branch'
2792 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
2793 if [ -n "$(__git_find_on_cmdline "-p")" ]; then
2796 if [ -z "$subcommand" ]; then
2799 __gitcomp "$save_opts"
2802 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2807 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2808 __gitcomp "$subcommands"
2813 case "$subcommand,$cur" in
2815 __gitcomp "$save_opts --message"
2818 __gitcomp "$save_opts"
2821 __gitcomp "--index --quiet"
2826 show,--*|branch,--*)
2829 if [ $cword -eq 3 ]; then
2832 __gitcomp_nl "$(__git stash list \
2833 | sed -n -e 's/:.*//p')"
2836 show,*|apply,*|drop,*|pop,*)
2837 __gitcomp_nl "$(__git stash list \
2838 | sed -n -e 's/:.*//p')"
2848 __git_has_doubledash && return
2850 local subcommands="add status init deinit update summary foreach sync"
2851 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2852 if [ -z "$subcommand" ]; then
2858 __gitcomp "$subcommands"
2864 case "$subcommand,$cur" in
2866 __gitcomp "--branch --force --name --reference --depth"
2869 __gitcomp "--cached --recursive"
2872 __gitcomp "--force --all"
2876 --init --remote --no-fetch
2877 --recommend-shallow --no-recommend-shallow
2878 --force --rebase --merge --reference --depth --recursive --jobs
2882 __gitcomp "--cached --files --summary-limit"
2884 foreach,--*|sync,--*)
2885 __gitcomp "--recursive"
2895 init fetch clone rebase dcommit log find-rev
2896 set-tree commit-diff info create-ignore propget
2897 proplist show-ignore show-externals branch tag blame
2898 migrate mkdirs reset gc
2900 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2901 if [ -z "$subcommand" ]; then
2902 __gitcomp "$subcommands"
2904 local remote_opts="--username= --config-dir= --no-auth-cache"
2906 --follow-parent --authors-file= --repack=
2907 --no-metadata --use-svm-props --use-svnsync-props
2908 --log-window-size= --no-checkout --quiet
2909 --repack-flags --use-log-author --localtime
2911 --ignore-paths= --include-paths= $remote_opts
2914 --template= --shared= --trunk= --tags=
2915 --branches= --stdlayout --minimize-url
2916 --no-metadata --use-svm-props --use-svnsync-props
2917 --rewrite-root= --prefix= $remote_opts
2920 --edit --rmdir --find-copies-harder --copy-similarity=
2923 case "$subcommand,$cur" in
2925 __gitcomp "--revision= --fetch-all $fc_opts"
2928 __gitcomp "--revision= $fc_opts $init_opts"
2931 __gitcomp "$init_opts"
2935 --merge --strategy= --verbose --dry-run
2936 --fetch-all --no-rebase --commit-url
2937 --revision --interactive $cmt_opts $fc_opts
2941 __gitcomp "--stdin $cmt_opts $fc_opts"
2943 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2944 show-externals,--*|mkdirs,--*)
2945 __gitcomp "--revision="
2949 --limit= --revision= --verbose --incremental
2950 --oneline --show-commit --non-recursive
2951 --authors-file= --color
2956 --merge --verbose --strategy= --local
2957 --fetch-all --dry-run $fc_opts
2961 __gitcomp "--message= --file= --revision= $cmt_opts"
2967 __gitcomp "--dry-run --message --tag"
2970 __gitcomp "--dry-run --message"
2973 __gitcomp "--git-format"
2977 --config-dir= --ignore-paths= --minimize
2978 --no-auth-cache --username=
2982 __gitcomp "--revision= --parent"
2993 while [ $c -lt $cword ]; do
2996 -d|--delete|-v|--verify)
2997 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3012 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3022 __gitcomp_builtin tag
3034 local subcommands="add list lock move prune remove unlock"
3035 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3036 if [ -z "$subcommand" ]; then
3037 __gitcomp "$subcommands"
3039 case "$subcommand,$cur" in
3041 __gitcomp_builtin worktree_add
3044 __gitcomp_builtin worktree_list
3047 __gitcomp_builtin worktree_lock
3050 __gitcomp_builtin worktree_prune
3061 __git_complete_common () {
3066 __gitcomp_builtin "$command"
3071 __git_cmds_with_parseopt_helper=
3072 __git_support_parseopt_helper () {
3073 test -n "$__git_cmds_with_parseopt_helper" ||
3074 __git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
3076 case " $__git_cmds_with_parseopt_helper " in
3086 __git_complete_command () {
3088 local completion_func="_git_${command//-/_}"
3089 if ! declare -f $completion_func >/dev/null 2>/dev/null &&
3090 declare -f _completion_loader >/dev/null 2>/dev/null
3092 _completion_loader "git-$command"
3094 if declare -f $completion_func >/dev/null 2>/dev/null
3098 elif __git_support_parseopt_helper "$command"
3100 __git_complete_common "$command"
3109 local i c=1 command __git_dir __git_repo_path
3110 local __git_C_args C_args_count=0
3112 while [ $c -lt $cword ]; do
3115 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
3116 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
3117 --bare) __git_dir="." ;;
3118 --help) command="help"; break ;;
3119 -c|--work-tree|--namespace) ((c++)) ;;
3120 -C) __git_C_args[C_args_count++]=-C
3122 __git_C_args[C_args_count++]="${words[c]}"
3125 *) command="$i"; break ;;
3130 if [ -z "$command" ]; then
3132 --git-dir|-C|--work-tree)
3133 # these need a path argument, let's fall back to
3134 # Bash filename completion
3138 # we don't support completing these options' arguments
3156 --no-replace-objects
3160 *) __git_compute_porcelain_commands
3161 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
3166 __git_complete_command "$command" && return
3168 local expansion=$(__git_aliased_command "$command")
3169 if [ -n "$expansion" ]; then
3171 __git_complete_command "$expansion"
3177 __git_has_doubledash && return
3179 local __git_repo_path
3180 __git_find_repo_path
3183 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3189 $__git_log_common_options
3190 $__git_log_gitk_options
3196 __git_complete_revlist
3199 if [[ -n ${ZSH_VERSION-} ]]; then
3200 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3202 autoload -U +X compinit && compinit
3208 local cur_="${3-$cur}"
3214 local c IFS=$' \t\n'
3222 array[${#array[@]}+1]="$c"
3225 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3236 compadd -Q -- ${=1} && _ret=0
3245 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3254 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3259 local _ret=1 cur cword prev
3260 cur=${words[CURRENT]}
3261 prev=${words[CURRENT-1]}
3263 emulate ksh -c __${service}_main
3264 let _ret && _default && _ret=0
3268 compdef _git git gitk
3274 local cur words cword prev
3275 _get_comp_words_by_ref -n =: cur words cword prev
3279 # Setup completion for certain functions defined above by setting common
3280 # variables and workarounds.
3281 # This is NOT a public function; use at your own risk.
3284 local wrapper="__git_wrap${2}"
3285 eval "$wrapper () { __git_func_wrap $2 ; }"
3286 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3287 || complete -o default -o nospace -F $wrapper $1
3290 # wrapper for backwards compatibility
3293 __git_wrap__git_main
3296 # wrapper for backwards compatibility
3299 __git_wrap__gitk_main
3302 __git_complete git __git_main
3303 __git_complete gitk __gitk_main
3305 # The following are necessary only for Cygwin, and only are needed
3306 # when the user has tab-completed the executable name and consequently
3307 # included the '.exe' suffix.
3309 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3310 __git_complete git.exe __git_main