]>
git.ipfire.org Git - thirdparty/git.git/blob - contrib/completion/git-completion.bash
1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 # Compatible with bash 3.2.57.
34 # You can set the following environment variables to influence the behavior of
35 # the completion routines:
37 # GIT_COMPLETION_CHECKOUT_NO_GUESS
39 # When set to "1", do not include "DWIM" suggestions in git-checkout
40 # completion (e.g., completing "foo" when "origin/foo" exists).
42 case "$COMP_WORDBREAKS" in
44 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
47 # Discovers the path to the git repository taking any '--git-dir=<path>' and
48 # '-C <path>' options into account and stores it in the $__git_repo_path
50 __git_find_repo_path
()
52 if [ -n "$__git_repo_path" ]; then
53 # we already know where it is
57 if [ -n "${__git_C_args-}" ]; then
58 __git_repo_path
="$(git "${__git_C_args[@]}" \
59 ${__git_dir:+--git-dir="$__git_dir"} \
60 rev-parse --absolute-git-dir 2>/dev/null)"
61 elif [ -n "${__git_dir-}" ]; then
62 test -d "$__git_dir" &&
63 __git_repo_path
="$__git_dir"
64 elif [ -n "${GIT_DIR-}" ]; then
65 test -d "${GIT_DIR-}" &&
66 __git_repo_path
="$GIT_DIR"
67 elif [ -d .git
]; then
70 __git_repo_path
="$(git rev-parse --git-dir 2>/dev/null)"
74 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
75 # __gitdir accepts 0 or 1 arguments (i.e., location)
76 # returns location of .git repo
79 if [ -z "${1-}" ]; then
80 __git_find_repo_path ||
return 1
81 echo "$__git_repo_path"
82 elif [ -d "$1/.git" ]; then
89 # Runs git with all the options given as argument, respecting any
90 # '--git-dir=<path>' and '-C <path>' options present on the command line
93 git
${__git_C_args:+"${__git_C_args[@]}"} \
94 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev
/null
97 # Removes backslash escaping, single quotes and double quotes from a word,
98 # stores the result in the variable $dequoted_word.
99 # 1: The word to dequote.
102 local rest
="$1" len ch
106 while test -n "$rest"; do
107 len
=${#dequoted_word}
108 dequoted_word
="$dequoted_word${rest%%[\\\'\"]*}"
109 rest
="${rest:$((${#dequoted_word}-$len))}"
111 case "${rest:0:1}" in
118 dequoted_word
="$dequoted_word$ch"
125 len
=${#dequoted_word}
126 dequoted_word
="$dequoted_word${rest%%\'*}"
127 rest
="${rest:$((${#dequoted_word}-$len+1))}"
131 while test -n "$rest" ; do
132 len
=${#dequoted_word}
133 dequoted_word
="$dequoted_word${rest%%[\\\"]*}"
134 rest
="${rest:$((${#dequoted_word}-$len))}"
135 case "${rest:0:1}" in
140 dequoted_word="$dequoted_word$ch"
145 dequoted_word="$dequoted_word\\$ch"
161 # The following function is based on code from:
163 # bash_completion - programmable completion functions for bash 3.2+
165 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
166 # © 2009-2010, Bash Completion Maintainers
167 # <bash-completion-devel@lists.alioth.debian.org>
169 # This program is free software; you can redistribute it and/or modify
170 # it under the terms of the GNU General Public License as published by
171 # the Free Software Foundation; either version 2, or (at your option)
174 # This program is distributed in the hope that it will be useful,
175 # but WITHOUT ANY WARRANTY; without even the implied warranty of
176 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
177 # GNU General Public License for more details.
179 # You should have received a copy of the GNU General Public License
180 # along with this program; if not, see <http://www.gnu.org/licenses/>.
182 # The latest version of this software can be obtained here:
184 # http://bash-completion.alioth.debian.org/
188 # This function can be used to access a tokenized list of words
189 # on the command line:
191 # __git_reassemble_comp_words_by_ref '=:'
192 # if test "${words_[cword_-1]}" = -w
197 # The argument should be a collection of characters from the list of
198 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
201 # This is roughly equivalent to going back in time and setting
202 # COMP_WORDBREAKS to exclude those characters. The intent is to
203 # make option types like --date=<type> and <rev>:<path> easy to
204 # recognize by treating each shell word as a single token.
206 # It is best not to set COMP_WORDBREAKS directly because the value is
207 # shared with other completion scripts. By the time the completion
208 # function gets called, COMP_WORDS has already been populated so local
209 # changes to COMP_WORDBREAKS have no effect.
211 # Output: words_, cword_, cur_.
213 __git_reassemble_comp_words_by_ref()
215 local exclude i j first
216 # Which word separators to exclude?
217 exclude="${1//[^$COMP_WORDBREAKS]}"
219 if [ -z "$exclude" ]; then
220 words_=("${COMP_WORDS[@]}")
223 # List of word completion separators has shrunk;
224 # re-assemble words to complete.
225 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
226 # Append each nonempty word consisting of just
227 # word separator characters to the current word.
231 [ -n "${COMP_WORDS[$i]}" ] &&
232 # word consists of excluded word separators
233 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
235 # Attach to the previous token,
236 # unless the previous token is the command name.
237 if [ $j -ge 2 ] && [ -n "$first" ]; then
241 words_[$j]=${words_[j]}${COMP_WORDS[i]}
242 if [ $i = $COMP_CWORD ]; then
245 if (($i < ${#COMP_WORDS[@]} - 1)); then
252 words_[$j]=${words_[j]}${COMP_WORDS[i]}
253 if [ $i = $COMP_CWORD ]; then
259 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
260 _get_comp_words_by_ref ()
262 local exclude cur_ words_ cword_
263 if [ "$1" = "-n" ]; then
267 __git_reassemble_comp_words_by_ref "$exclude"
268 cur_=${words_[cword_]}
269 while [ $# -gt 0 ]; do
275 prev=${words_[$cword_-1]}
278 words=("${words_[@]}")
289 # Fills the COMPREPLY array with prefiltered words without any additional
291 # Callers must take care of providing only words that match the current word
292 # to be completed and adding any prefix and/or suffix (trailing space!), if
294 # 1: List of newline-separated matching completion words, complete with
305 local x i=${#COMPREPLY[@]}
307 if [[ "$x" == "$3"* ]]; then
308 COMPREPLY[i++]="$2$x$4"
319 # Generates completion reply, appending a space to possible completion words,
321 # It accepts 1 to 4 arguments:
322 # 1: List of possible completion words.
323 # 2: A prefix to be added to each possible completion word (optional).
324 # 3: Generate possible completion matches for this word (optional).
325 # 4: A suffix to be appended to each possible completion word (optional).
328 local cur_="${3-$cur}"
334 local c i=0 IFS=$' \t\n'
337 if [[ $c == "$cur_"* ]]; then
342 COMPREPLY[i++]="${2-}$c"
349 # Clear the variables caching builtins' options when (re-)sourcing
350 # the completion script.
351 unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
353 # This function is equivalent to
355 # __gitcomp "$(git xxx --git-completion-helper) ..."
357 # except that the output is cached. Accept 1-3 arguments:
358 # 1: the git command to execute, this is also the cache key
359 # 2: extra options to be added on top (e.g. negative forms)
360 # 3: options to be excluded
363 # spaces must be replaced with underscore for multi-word
364 # commands, e.g. "git remote add" becomes remote_add.
369 local var=__gitcomp_builtin_"${cmd/-/_}"
371 eval "options=\$$var"
373 if [ -z "$options" ]; then
374 # leading and trailing spaces are significant to make
375 # option removal work correctly.
376 options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
378 options="${options/ $i / }"
380 eval "$var=\"$options\""
386 # Variation of __gitcomp_nl () that appends to the existing list of
387 # completion candidates, COMPREPLY.
388 __gitcomp_nl_append ()
391 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
394 # Generates completion reply from newline-separated possible completion words
395 # by appending a space to all of them.
396 # It accepts 1 to 4 arguments:
397 # 1: List of possible completion words, separated by a single newline.
398 # 2: A prefix to be added to each possible completion word (optional).
399 # 3: Generate possible completion matches for this word (optional).
400 # 4: A suffix to be appended to each possible completion word instead of
401 # the default space (optional). If specified but empty, nothing is
406 __gitcomp_nl_append "$@"
409 # Generates completion reply with compgen from newline-separated possible
410 # completion filenames.
411 # It accepts 1 to 3 arguments:
412 # 1: List of possible completion filenames, separated by a single newline.
413 # 2: A directory prefix to be added to each possible completion filename
415 # 3: Generate possible completion matches for this word (optional).
420 # XXX does not work when the directory prefix contains a tilde,
421 # since tilde expansion is not applied.
422 # This means that COMPREPLY will be empty and Bash default
423 # completion will be used.
424 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
426 # use a hack to enable file mode in bash < 4
427 compopt -o filenames +o nospace 2>/dev/null ||
428 compgen -f /non-existing-dir/ > /dev/null
431 # Execute 'git ls-files', unless the --committable option is specified, in
432 # which case it runs 'git diff-index' to find out the files that can be
433 # committed. It return paths relative to the directory specified in the first
434 # argument, and using the options specified in the second argument.
435 __git_ls_files_helper ()
437 if [ "$2" == "--committable" ]; then
438 __git -C "$1" -c core.quotePath=false diff-index \
439 --name-only --relative HEAD -- "${3//\\/\\\\}*"
441 # NOTE: $2 is not quoted in order to support multiple options
442 __git -C "$1" -c core.quotePath=false ls-files \
443 --exclude-standard $2 -- "${3//\\/\\\\}*"
448 # __git_index_files accepts 1 or 2 arguments:
449 # 1: Options to pass to ls-files (required).
450 # 2: A directory path (optional).
451 # If provided, only files within the specified directory are listed.
452 # Sub directories are never recursed. Path must have a trailing
454 # 3: List only paths matching this path component (optional).
457 local root="$2" match="$3" file
459 __git_ls_files_helper "$root" "$1" "$match" |
460 while read -r file; do
462 ?*/*) echo "${file%%/*}" ;;
468 # __git_complete_index_file requires 1 argument:
469 # 1: the options to pass to ls-file
471 # The exception is --committable, which finds the files appropriate commit.
472 __git_complete_index_file ()
474 local dequoted_word pfx="" cur_
478 case "$dequoted_word" in
480 pfx="${dequoted_word%/*}/"
481 cur_="${dequoted_word##*/}"
484 cur_="$dequoted_word"
487 __gitcomp_file "$(__git_index_files "$1" "$pfx" "$cur_")" "$pfx" "$cur_"
490 # Lists branches from the local repository.
491 # 1: A prefix to be added to each listed branch (optional).
492 # 2: List only branches matching this word (optional; list all branches if
494 # 3: A suffix to be appended to each listed branch (optional).
497 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
499 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
500 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
503 # Lists tags from the local repository.
504 # Accepts the same positional parameters as __git_heads() above.
507 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
509 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
510 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
513 # Lists refs from the local (by default) or from a remote repository.
514 # It accepts 0, 1 or 2 arguments:
515 # 1: The remote to list refs from (optional; ignored, if set but empty).
516 # Can be the name of a configured remote, a path, or a URL.
517 # 2: In addition to local refs, list unique branches from refs/remotes/ for
518 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
519 # 3: A prefix to be added to each listed ref (optional).
520 # 4: List only refs matching this word (optional; list all refs if unset or
522 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
525 # Use __git_complete_refs() instead.
528 local i hash dir track="${2-}"
529 local list_refs_from=path remote="${1-}"
531 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
533 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
536 dir="$__git_repo_path"
538 if [ -z "$remote" ]; then
539 if [ -z "$dir" ]; then
543 if __git_is_configured_remote "$remote"; then
544 # configured remote takes precedence over a
545 # local directory with the same name
546 list_refs_from=remote
547 elif [ -d "$remote/.git" ]; then
549 elif [ -d "$remote" ]; then
556 if [ "$list_refs_from" = path ]; then
557 if [[ "$cur_" == ^* ]]; then
566 refs=("$match*" "$match*/**")
570 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
573 if [ -e "$dir/$i" ]; then
579 format="refname:strip=2"
580 refs=("refs/tags/$match*" "refs/tags/$match*/**"
581 "refs/heads/$match*" "refs/heads/$match*/**"
582 "refs/remotes/$match*" "refs/remotes/$match*/**")
585 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
587 if [ -n "$track" ]; then
588 # employ the heuristic used by git checkout
589 # Try to find a remote branch that matches the completion word
590 # but only output if the branch name is unique
591 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
592 --sort="refname:strip=3" \
593 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
600 __git ls-remote "$remote" "$match*" | \
601 while read -r hash i; do
604 *) echo "$pfx$i$sfx" ;;
609 if [ "$list_refs_from" = remote ]; then
611 $match*) echo "${pfx}HEAD$sfx" ;;
613 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
614 "refs/remotes/$remote/$match*" \
615 "refs/remotes/$remote/$match*/**"
619 $match*) query_symref="HEAD" ;;
621 __git ls-remote "$remote" $query_symref \
622 "refs/tags/$match*" "refs/heads/$match*" \
623 "refs/remotes/$match*" |
624 while read -r hash i; do
627 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
628 *) echo "$pfx$i$sfx" ;; # symbolic refs
636 # Completes refs, short and long, local and remote, symbolic and pseudo.
638 # Usage: __git_complete_refs [<option>]...
639 # --remote=<remote>: The remote to list refs from, can be the name of a
640 # configured remote, a path, or a URL.
641 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
642 # --pfx=<prefix>: A prefix to be added to each ref.
643 # --cur=<word>: The current ref to be completed. Defaults to the current
644 # word to be completed.
645 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
647 __git_complete_refs ()
649 local remote track pfx cur_="$cur" sfx=" "
651 while test $# != 0; do
653 --remote=*) remote="${1##--remote=}" ;;
654 --track) track="yes" ;;
655 --pfx=*) pfx="${1##--pfx=}" ;;
656 --cur=*) cur_="${1##--cur=}" ;;
657 --sfx=*) sfx="${1##--sfx=}" ;;
663 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
666 # __git_refs2 requires 1 argument (to pass to __git_refs)
667 # Deprecated: use __git_complete_fetch_refspecs() instead.
671 for i in $(__git_refs "$1"); do
676 # Completes refspecs for fetching from a remote repository.
677 # 1: The remote repository.
678 # 2: A prefix to be added to each listed refspec (optional).
679 # 3: The ref to be completed as a refspec instead of the current word to be
680 # completed (optional)
681 # 4: A suffix to be appended to each listed refspec instead of the default
683 __git_complete_fetch_refspecs ()
685 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
688 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
694 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
695 __git_refs_remotes ()
698 __git ls-remote "$1" 'refs/heads/*' | \
699 while read -r hash i; do
700 echo "$i:refs/remotes/$1/${i#refs/heads/}"
707 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
711 # Returns true if $1 matches the name of a configured remote, false otherwise.
712 __git_is_configured_remote ()
715 for remote in $(__git_remotes); do
716 if [ "$remote" = "$1" ]; then
723 __git_list_merge_strategies ()
725 LANG=C LC_ALL=C git merge -s help 2>&1 |
726 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
735 __git_merge_strategies=
736 # 'git merge -s help' (and thus detection of the merge strategy
737 # list) fails, unfortunately, if run outside of any git working
738 # tree. __git_merge_strategies is set to the empty string in
739 # that case, and the detection will be repeated the next time it
741 __git_compute_merge_strategies ()
743 test -n "$__git_merge_strategies" ||
744 __git_merge_strategies=$(__git_list_merge_strategies)
747 __git_complete_revlist_file ()
749 local pfx ls ref cur_="$cur"
769 case "$COMP_WORDBREAKS" in
771 *) pfx="$ref:$pfx" ;;
774 __gitcomp_nl "$(__git ls-tree "$ls" \
775 | sed '/^100... blob /{
791 pfx="${cur_%...*}..."
793 __git_complete_refs --pfx="$pfx" --cur="$cur_"
798 __git_complete_refs --pfx="$pfx" --cur="$cur_"
806 __git_complete_file ()
808 __git_complete_revlist_file
811 __git_complete_revlist ()
813 __git_complete_revlist_file
816 __git_complete_remote_or_refspec ()
818 local cur_="$cur" cmd="${words[1]}"
819 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
820 if [ "$cmd" = "remote" ]; then
823 while [ $c -lt $cword ]; do
826 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
827 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
830 push) no_complete_refspec=1 ;;
838 *) remote="$i"; break ;;
842 if [ -z "$remote" ]; then
843 __gitcomp_nl "$(__git_remotes)"
846 if [ $no_complete_refspec = 1 ]; then
849 [ "$remote" = "." ] && remote=
852 case "$COMP_WORDBREAKS" in
854 *) pfx="${cur_%%:*}:" ;;
866 if [ $lhs = 1 ]; then
867 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
869 __git_complete_refs --pfx="$pfx" --cur="$cur_"
873 if [ $lhs = 1 ]; then
874 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
876 __git_complete_refs --pfx="$pfx" --cur="$cur_"
880 if [ $lhs = 1 ]; then
881 __git_complete_refs --pfx="$pfx" --cur="$cur_"
883 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
889 __git_complete_strategy ()
891 __git_compute_merge_strategies
894 __gitcomp "$__git_merge_strategies"
899 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
907 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
909 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
911 git help -a|egrep '^ [a-zA-Z0-9]'
915 __git_list_all_commands ()
918 for i in $(__git_commands)
921 *--*) : helper pattern;;
928 __git_compute_all_commands ()
930 test -n "$__git_all_commands" ||
931 __git_all_commands=$(__git_list_all_commands)
934 __git_list_porcelain_commands ()
937 __git_compute_all_commands
938 for i in $__git_all_commands
941 *--*) : helper pattern;;
942 applymbox) : ask gittus;;
943 applypatch) : ask gittus;;
944 archimport) : import;;
945 cat-file) : plumbing;;
946 check-attr) : plumbing;;
947 check-ignore) : plumbing;;
948 check-mailmap) : plumbing;;
949 check-ref-format) : plumbing;;
950 checkout-index) : plumbing;;
951 column) : internal helper;;
952 commit-tree) : plumbing;;
953 count-objects) : infrequent;;
954 credential) : credentials;;
955 credential-*) : credentials helper;;
956 cvsexportcommit) : export;;
957 cvsimport) : import;;
958 cvsserver) : daemon;;
960 diff-files) : plumbing;;
961 diff-index) : plumbing;;
962 diff-tree) : plumbing;;
963 fast-import) : import;;
964 fast-export) : export;;
965 fsck-objects) : plumbing;;
966 fetch-pack) : plumbing;;
967 fmt-merge-msg) : plumbing;;
968 for-each-ref) : plumbing;;
969 hash-object) : plumbing;;
970 http-*) : transport;;
971 index-pack) : plumbing;;
972 init-db) : deprecated;;
973 local-fetch) : plumbing;;
974 ls-files) : plumbing;;
975 ls-remote) : plumbing;;
976 ls-tree) : plumbing;;
977 mailinfo) : plumbing;;
978 mailsplit) : plumbing;;
979 merge-*) : plumbing;;
982 pack-objects) : plumbing;;
983 pack-redundant) : plumbing;;
984 pack-refs) : plumbing;;
985 parse-remote) : plumbing;;
986 patch-id) : plumbing;;
988 prune-packed) : plumbing;;
989 quiltimport) : import;;
990 read-tree) : plumbing;;
991 receive-pack) : plumbing;;
992 remote-*) : transport;;
994 rev-list) : plumbing;;
995 rev-parse) : plumbing;;
996 runstatus) : plumbing;;
997 sh-setup) : internal;;
999 show-ref) : plumbing;;
1000 send-pack) : plumbing;;
1001 show-index) : plumbing;;
1002 ssh-*) : transport;;
1003 stripspace) : plumbing;;
1004 symbolic-ref) : plumbing;;
1005 unpack-file) : plumbing;;
1006 unpack-objects) : plumbing;;
1007 update-index) : plumbing;;
1008 update-ref) : plumbing;;
1009 update-server-info) : daemon;;
1010 upload-archive) : plumbing;;
1011 upload-pack) : plumbing;;
1012 write-tree) : plumbing;;
1014 verify-pack) : infrequent;;
1015 verify-tag) : plumbing;;
1021 __git_porcelain_commands=
1022 __git_compute_porcelain_commands ()
1024 test -n "$__git_porcelain_commands" ||
1025 __git_porcelain_commands=$(__git_list_porcelain_commands)
1028 # Lists all set config variables starting with the given section prefix,
1029 # with the prefix removed.
1030 __git_get_config_variables ()
1032 local section="$1" i IFS=$'\n'
1033 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1034 echo "${i#$section.}"
1038 __git_pretty_aliases ()
1040 __git_get_config_variables "pretty"
1045 __git_get_config_variables "alias"
1048 # __git_aliased_command requires 1 argument
1049 __git_aliased_command ()
1051 local word cmdline=$(__git config --get "alias.$1")
1052 for word in $cmdline; do
1058 \!*) : shell command alias ;;
1060 *=*) : setting env ;;
1061 git) : git itself ;;
1062 \(\)) : skip parens of shell function definition ;;
1063 {) : skip start of shell helper function ;;
1064 :) : skip null command ;;
1065 \'*) : skip opening quote after sh -c ;;
1073 # __git_find_on_cmdline requires 1 argument
1074 __git_find_on_cmdline ()
1076 local word subcommand c=1
1077 while [ $c -lt $cword ]; do
1079 for subcommand in $1; do
1080 if [ "$subcommand" = "$word" ]; then
1089 # Echo the value of an option set on the command line or config
1091 # $1: short option name
1092 # $2: long option name including =
1093 # $3: list of possible values
1094 # $4: config string (optional)
1097 # result="$(__git_get_option_value "-d" "--do-something=" \
1098 # "yes no" "core.doSomething")"
1100 # result is then either empty (no option set) or "yes" or "no"
1102 # __git_get_option_value requires 3 arguments
1103 __git_get_option_value ()
1105 local c short_opt long_opt val
1106 local result= values config_key word
1114 while [ $c -ge 0 ]; do
1116 for val in $values; do
1117 if [ "$short_opt$val" = "$word" ] ||
1118 [ "$long_opt$val" = "$word" ]; then
1126 if [ -n "$config_key" ] && [ -z "$result" ]; then
1127 result="$(__git config "$config_key")"
1133 __git_has_doubledash ()
1136 while [ $c -lt $cword ]; do
1137 if [ "--" = "${words[c]}" ]; then
1145 # Try to count non option arguments passed on the command line for the
1146 # specified git command.
1147 # When options are used, it is necessary to use the special -- option to
1148 # tell the implementation were non option arguments begin.
1149 # XXX this can not be improved, since options can appear everywhere, as
1153 # __git_count_arguments requires 1 argument: the git command executed.
1154 __git_count_arguments ()
1158 # Skip "git" (first argument)
1159 for ((i=1; i < ${#words[@]}; i++)); do
1164 # Good; we can assume that the following are only non
1169 # Skip the specified git command and discard git
1182 __git_whitespacelist="nowarn warn error error-all fix"
1183 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1187 __git_find_repo_path
1188 if [ -d "$__git_repo_path"/rebase-apply ]; then
1189 __gitcomp "$__git_am_inprogress_options"
1194 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1198 __gitcomp_builtin am "--no-utf8" \
1199 "$__git_am_inprogress_options"
1208 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1212 __gitcomp_builtin apply
1221 __gitcomp_builtin add
1225 local complete_opt="--others --modified --directory --no-empty-directory"
1226 if test -n "$(__git_find_on_cmdline "-u --update")"
1228 complete_opt="--modified"
1230 __git_complete_index_file "$complete_opt"
1237 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1241 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1246 --format= --list --verbose
1247 --prefix= --remote= --exec= --output
1257 __git_has_doubledash && return
1259 local subcommands="start bad good skip reset visualize replay log run"
1260 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1261 if [ -z "$subcommand" ]; then
1262 __git_find_repo_path
1263 if [ -f "$__git_repo_path"/BISECT_START ]; then
1264 __gitcomp "$subcommands"
1266 __gitcomp "replay start"
1271 case "$subcommand" in
1272 bad|good|reset|skip|start)
1282 local i c=1 only_local_ref="n" has_r="n"
1284 while [ $c -lt $cword ]; do
1287 -d|--delete|-m|--move) only_local_ref="y" ;;
1288 -r|--remotes) has_r="y" ;;
1294 --set-upstream-to=*)
1295 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1298 __gitcomp_builtin branch "--no-color --no-abbrev
1299 --no-track --no-column
1303 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1304 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1314 local cmd="${words[2]}"
1317 __gitcomp "create list-heads verify unbundle"
1320 # looking for a file
1325 __git_complete_revlist
1334 __git_has_doubledash && return
1338 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1341 __gitcomp_builtin checkout "--no-track --no-recurse-submodules"
1344 # check if --track, --no-track, or --no-guess was specified
1345 # if so, disable DWIM mode
1346 local flags="--track --no-track --no-guess" track_opt="--track"
1347 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1348 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1351 __git_complete_refs $track_opt
1360 __gitcomp_builtin cherry
1367 __git_cherry_pick_inprogress_options="--continue --quit --abort"
1371 __git_find_repo_path
1372 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1373 __gitcomp "$__git_cherry_pick_inprogress_options"
1378 __gitcomp_builtin cherry-pick "" \
1379 "$__git_cherry_pick_inprogress_options"
1391 __gitcomp_builtin clean
1396 # XXX should we check for -x option ?
1397 __git_complete_index_file "--others --directory"
1404 __gitcomp_builtin clone "--no-single-branch"
1410 __git_untracked_file_modes="all no normal"
1423 __gitcomp "default scissors strip verbatim whitespace
1424 " "" "${cur##--cleanup=}"
1427 --reuse-message=*|--reedit-message=*|\
1428 --fixup=*|--squash=*)
1429 __git_complete_refs --cur="${cur#*=}"
1432 --untracked-files=*)
1433 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1437 __gitcomp_builtin commit "--no-edit --verify"
1441 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1442 __git_complete_index_file "--committable"
1444 # This is the first commit
1445 __git_complete_index_file "--cached"
1453 __gitcomp_builtin describe
1459 __git_diff_algorithms="myers minimal patience histogram"
1461 __git_diff_submodule_formats="diff log short"
1463 __git_diff_common_options="--stat --numstat --shortstat --summary
1464 --patch-with-stat --name-only --name-status --color
1465 --no-color --color-words --no-renames --check
1466 --full-index --binary --abbrev --diff-filter=
1467 --find-copies-harder --ignore-cr-at-eol
1468 --text --ignore-space-at-eol --ignore-space-change
1469 --ignore-all-space --ignore-blank-lines --exit-code
1470 --quiet --ext-diff --no-ext-diff
1471 --no-prefix --src-prefix= --dst-prefix=
1472 --inter-hunk-context=
1473 --patience --histogram --minimal
1474 --raw --word-diff --word-diff-regex=
1475 --dirstat --dirstat= --dirstat-by-file
1476 --dirstat-by-file= --cumulative
1478 --submodule --submodule= --ignore-submodules
1483 __git_has_doubledash && return
1487 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1491 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1495 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1496 --base --ours --theirs --no-index
1497 $__git_diff_common_options
1502 __git_complete_revlist_file
1505 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1506 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1511 __git_has_doubledash && return
1515 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1519 __gitcomp_builtin difftool "$__git_diff_common_options
1520 --base --cached --ours --theirs
1521 --pickaxe-all --pickaxe-regex
1527 __git_complete_revlist_file
1530 __git_fetch_recurse_submodules="yes on-demand no"
1535 --recurse-submodules=*)
1536 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1540 __gitcomp_builtin fetch "--no-tags"
1544 __git_complete_remote_or_refspec
1547 __git_format_patch_options="
1548 --stdout --attach --no-attach --thread --thread= --no-thread
1549 --numbered --start-number --numbered-files --keep-subject --signoff
1550 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1551 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1552 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1553 --output-directory --reroll-count --to= --quiet --notes
1556 _git_format_patch ()
1562 " "" "${cur##--thread=}"
1566 __gitcomp "$__git_format_patch_options"
1570 __git_complete_revlist
1577 __gitcomp_builtin fsck "--no-reflogs"
1588 # Lists matching symbol names from a tag (as in ctags) file.
1589 # 1: List symbol names matching this word.
1590 # 2: The tag file to list symbol names from.
1591 # 3: A prefix to be added to each listed symbol name (optional).
1592 # 4: A suffix to be appended to each listed symbol name (optional).
1593 __git_match_ctag () {
1594 awk -v pfx="${3-}" -v sfx="${4-}" "
1595 /^${1//\//\\/}/ { print pfx \$1 sfx }
1599 # Complete symbol names from a tag file.
1600 # Usage: __git_complete_symbol [<option>]...
1601 # --tags=<file>: The tag file to list symbol names from instead of the
1603 # --pfx=<prefix>: A prefix to be added to each symbol name.
1604 # --cur=<word>: The current symbol name to be completed. Defaults to
1605 # the current word to be completed.
1606 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1607 # of the default space.
1608 __git_complete_symbol () {
1609 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1611 while test $# != 0; do
1613 --tags=*) tags="${1##--tags=}" ;;
1614 --pfx=*) pfx="${1##--pfx=}" ;;
1615 --cur=*) cur_="${1##--cur=}" ;;
1616 --sfx=*) sfx="${1##--sfx=}" ;;
1622 if test -r "$tags"; then
1623 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1629 __git_has_doubledash && return
1633 __gitcomp_builtin grep
1638 case "$cword,$prev" in
1640 __git_complete_symbol && return
1651 __gitcomp_builtin help
1655 __git_compute_all_commands
1656 __gitcomp "$__git_all_commands $(__git_aliases)
1657 attributes cli core-tutorial cvs-migration
1658 diffcore everyday gitk glossary hooks ignore modules
1659 namespaces repository-layout revisions tutorial tutorial-2
1669 false true umask group all world everybody
1670 " "" "${cur##--shared=}"
1674 __gitcomp_builtin init
1684 __gitcomp_builtin ls-files "--no-empty-directory"
1689 # XXX ignore options like --modified and always suggest all cached
1691 __git_complete_index_file "--cached"
1698 __gitcomp_builtin ls-remote
1702 __gitcomp_nl "$(__git_remotes)"
1709 __gitcomp_builtin ls-tree
1717 # Options that go well for log, shortlog and gitk
1718 __git_log_common_options="
1720 --branches --tags --remotes
1721 --first-parent --merges --no-merges
1723 --max-age= --since= --after=
1724 --min-age= --until= --before=
1725 --min-parents= --max-parents=
1726 --no-min-parents --no-max-parents
1728 # Options that go well for log and gitk (not shortlog)
1729 __git_log_gitk_options="
1730 --dense --sparse --full-history
1731 --simplify-merges --simplify-by-decoration
1732 --left-right --notes --no-notes
1734 # Options that go well for log and shortlog (not gitk)
1735 __git_log_shortlog_options="
1736 --author= --committer= --grep=
1737 --all-match --invert-grep
1740 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1741 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1745 __git_has_doubledash && return
1746 __git_find_repo_path
1749 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1752 case "$prev,$cur" in
1754 return # fall back to Bash filename completion
1757 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1761 __git_complete_symbol
1766 --pretty=*|--format=*)
1767 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1772 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1776 __gitcomp "full short no" "" "${cur##--decorate=}"
1780 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1784 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1789 $__git_log_common_options
1790 $__git_log_shortlog_options
1791 $__git_log_gitk_options
1792 --root --topo-order --date-order --reverse
1793 --follow --full-diff
1794 --abbrev-commit --abbrev=
1795 --relative-date --date=
1796 --pretty= --format= --oneline
1801 --decorate --decorate=
1803 --parents --children
1805 $__git_diff_common_options
1806 --pickaxe-all --pickaxe-regex
1811 return # fall back to Bash filename completion
1814 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1818 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1822 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1826 __git_complete_revlist
1831 __git_complete_strategy && return
1835 __gitcomp_builtin merge "--no-rerere-autoupdate
1836 --no-commit --no-edit --no-ff
1837 --no-log --no-progress
1838 --no-squash --no-stat
1839 --no-verify-signatures
1850 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1854 __gitcomp "--tool= --prompt --no-prompt"
1864 __gitcomp_builtin merge-base
1875 __gitcomp_builtin mv
1880 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1881 # We need to show both cached and untracked files (including
1882 # empty directories) since this may not be the last argument.
1883 __git_complete_index_file "--cached --others --directory"
1885 __git_complete_index_file "--cached"
1891 local subcommands='add append copy edit get-ref list merge prune remove show'
1892 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1894 case "$subcommand,$cur" in
1896 __gitcomp_builtin notes
1904 __gitcomp "$subcommands --ref"
1908 *,--reuse-message=*|*,--reedit-message=*)
1909 __git_complete_refs --cur="${cur#*=}"
1912 __gitcomp_builtin notes_$subcommand
1915 # this command does not take a ref, do not complete it
1931 __git_complete_strategy && return
1934 --recurse-submodules=*)
1935 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1939 __gitcomp_builtin pull "--no-autostash --no-commit --no-edit
1940 --no-ff --no-log --no-progress --no-rebase
1941 --no-squash --no-stat --no-tags
1942 --no-verify-signatures"
1947 __git_complete_remote_or_refspec
1950 __git_push_recurse_submodules="check on-demand only"
1952 __git_complete_force_with_lease ()
1960 __git_complete_refs --cur="${cur_#*:}"
1963 __git_complete_refs --cur="$cur_"
1972 __gitcomp_nl "$(__git_remotes)"
1975 --recurse-submodules)
1976 __gitcomp "$__git_push_recurse_submodules"
1982 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1985 --recurse-submodules=*)
1986 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1989 --force-with-lease=*)
1990 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1994 __gitcomp_builtin push
1998 __git_complete_remote_or_refspec
2003 __git_find_repo_path
2004 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2005 __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
2007 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2008 [ -d "$__git_repo_path"/rebase-merge ]; then
2009 __gitcomp "--continue --skip --abort --quit --show-current-patch"
2012 __git_complete_strategy && return
2015 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2020 --onto --merge --strategy --interactive
2021 --preserve-merges --stat --no-stat
2022 --committer-date-is-author-date --ignore-date
2023 --ignore-whitespace --whitespace=
2024 --autosquash --no-autosquash
2025 --fork-point --no-fork-point
2026 --autostash --no-autostash
2027 --verify --no-verify
2028 --keep-empty --root --force-rebase --no-ff
2040 local subcommands="show delete expire"
2041 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2043 if [ -z "$subcommand" ]; then
2044 __gitcomp "$subcommands"
2050 __git_send_email_confirm_options="always never auto cc compose"
2051 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2056 --to|--cc|--bcc|--from)
2057 __gitcomp "$(__git send-email --dump-aliases)"
2065 $__git_send_email_confirm_options
2066 " "" "${cur##--confirm=}"
2071 $__git_send_email_suppresscc_options
2072 " "" "${cur##--suppress-cc=}"
2076 --smtp-encryption=*)
2077 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2083 " "" "${cur##--thread=}"
2086 --to=*|--cc=*|--bcc=*|--from=*)
2087 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2091 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2092 --compose --confirm= --dry-run --envelope-sender
2094 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2095 --no-suppress-from --no-thread --quiet --reply-to
2096 --signed-off-by-cc --smtp-pass --smtp-server
2097 --smtp-server-port --smtp-encryption= --smtp-user
2098 --subject --suppress-cc= --suppress-from --thread --to
2099 --validate --no-validate
2100 $__git_format_patch_options"
2104 __git_complete_revlist
2115 local untracked_state
2118 --ignore-submodules=*)
2119 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2122 --untracked-files=*)
2123 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2128 always never auto column row plain dense nodense
2129 " "" "${cur##--column=}"
2133 __gitcomp_builtin status "--no-column"
2138 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2139 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2141 case "$untracked_state" in
2143 # --ignored option does not matter
2147 complete_opt="--cached --directory --no-empty-directory --others"
2149 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2150 complete_opt="$complete_opt --ignored --exclude=*"
2155 __git_complete_index_file "$complete_opt"
2158 __git_config_get_set_variables ()
2160 local prevword word config_file= c=$cword
2161 while [ $c -gt 1 ]; do
2164 --system|--global|--local|--file=*)
2169 config_file="$word $prevword"
2177 __git config $config_file --name-only --list
2183 branch.*.remote|branch.*.pushremote)
2184 __gitcomp_nl "$(__git_remotes)"
2192 __gitcomp "false true preserve interactive"
2196 __gitcomp_nl "$(__git_remotes)"
2200 local remote="${prev#remote.}"
2201 remote="${remote%.fetch}"
2202 if [ -z "$cur" ]; then
2203 __gitcomp_nl "refs/heads/" "" "" ""
2206 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2210 local remote="${prev#remote.}"
2211 remote="${remote%.push}"
2212 __gitcomp_nl "$(__git for-each-ref \
2213 --format='%(refname):%(refname)' refs/heads)"
2216 pull.twohead|pull.octopus)
2217 __git_compute_merge_strategies
2218 __gitcomp "$__git_merge_strategies"
2221 color.branch|color.diff|color.interactive|\
2222 color.showbranch|color.status|color.ui)
2223 __gitcomp "always never auto"
2227 __gitcomp "false true"
2232 normal black red green yellow blue magenta cyan white
2233 bold dim ul blink reverse
2238 __gitcomp "log short"
2242 __gitcomp "man info web html"
2246 __gitcomp "$__git_log_date_formats"
2249 sendemail.aliasesfiletype)
2250 __gitcomp "mutt mailrc pine elm gnus"
2254 __gitcomp "$__git_send_email_confirm_options"
2257 sendemail.suppresscc)
2258 __gitcomp "$__git_send_email_suppresscc_options"
2261 sendemail.transferencoding)
2262 __gitcomp "7bit 8bit quoted-printable base64"
2265 --get|--get-all|--unset|--unset-all)
2266 __gitcomp_nl "$(__git_config_get_set_variables)"
2275 __gitcomp_builtin config
2279 local pfx="${cur%.*}." cur_="${cur##*.}"
2280 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2284 local pfx="${cur%.*}." cur_="${cur#*.}"
2285 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2286 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2290 local pfx="${cur%.*}." cur_="${cur##*.}"
2292 argprompt cmd confirm needsfile noconsole norescan
2293 prompt revprompt revunmerged title
2298 local pfx="${cur%.*}." cur_="${cur##*.}"
2299 __gitcomp "cmd path" "$pfx" "$cur_"
2303 local pfx="${cur%.*}." cur_="${cur##*.}"
2304 __gitcomp "cmd path" "$pfx" "$cur_"
2308 local pfx="${cur%.*}." cur_="${cur##*.}"
2309 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2313 local pfx="${cur%.*}." cur_="${cur#*.}"
2314 __git_compute_all_commands
2315 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2319 local pfx="${cur%.*}." cur_="${cur##*.}"
2321 url proxy fetch push mirror skipDefaultUpdate
2322 receivepack uploadpack tagopt pushurl
2327 local pfx="${cur%.*}." cur_="${cur#*.}"
2328 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2329 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2333 local pfx="${cur%.*}." cur_="${cur##*.}"
2334 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2341 advice.commitBeforeMerge
2343 advice.implicitIdentity
2344 advice.pushAlreadyExists
2345 advice.pushFetchFirst
2346 advice.pushNeedsForce
2347 advice.pushNonFFCurrent
2348 advice.pushNonFFMatching
2349 advice.pushUpdateRejected
2350 advice.resolveConflict
2353 advice.statusUoption
2358 apply.ignorewhitespace
2360 branch.autosetupmerge
2361 branch.autosetuprebase
2365 color.branch.current
2370 color.decorate.branch
2371 color.decorate.remoteBranch
2372 color.decorate.stash
2382 color.diff.whitespace
2387 color.grep.linenumber
2390 color.grep.separator
2392 color.interactive.error
2393 color.interactive.header
2394 color.interactive.help
2395 color.interactive.prompt
2400 color.status.changed
2402 color.status.localBranch
2403 color.status.nobranch
2404 color.status.remoteBranch
2405 color.status.unmerged
2406 color.status.untracked
2407 color.status.updated
2419 core.bigFileThreshold
2424 core.deltaBaseCacheLimit
2429 core.fsyncobjectfiles
2435 core.logAllRefUpdates
2436 core.loosecompression
2439 core.packedGitWindowSize
2440 core.packedRefsTimeout
2442 core.precomposeUnicode
2443 core.preferSymlinkRefs
2448 core.repositoryFormatVersion
2450 core.sharedRepository
2457 core.warnAmbiguousRefs
2461 credential.useHttpPath
2463 credentialCache.ignoreSIGHUP
2464 diff.autorefreshindex
2466 diff.ignoreSubmodules
2473 diff.suppressBlankEmpty
2479 fetch.recurseSubmodules
2490 format.subjectprefix
2504 gc.reflogexpireunreachable
2507 gc.worktreePruneExpire
2509 gitcvs.commitmsgannotation
2510 gitcvs.dbTableNamePrefix
2521 gui.copyblamethreshold
2525 gui.matchtrackingbranch
2526 gui.newbranchtemplate
2527 gui.pruneduringfetch
2528 gui.spellingdictionary
2545 http.sslCertPasswordProtected
2550 i18n.logOutputEncoding
2556 imap.preformattedHTML
2566 interactive.singlekey
2582 mergetool.keepBackup
2583 mergetool.keepTemporaries
2588 notes.rewrite.rebase
2592 pack.deltaCacheLimit
2609 receive.denyCurrentBranch
2610 receive.denyDeleteCurrent
2612 receive.denyNonFastForwards
2615 receive.updateserverinfo
2618 repack.usedeltabaseoffset
2622 sendemail.aliasesfile
2623 sendemail.aliasfiletype
2627 sendemail.chainreplyto
2629 sendemail.envelopesender
2633 sendemail.signedoffbycc
2634 sendemail.smtpdomain
2635 sendemail.smtpencryption
2637 sendemail.smtpserver
2638 sendemail.smtpserveroption
2639 sendemail.smtpserverport
2641 sendemail.suppresscc
2642 sendemail.suppressfrom
2647 sendemail.smtpbatchsize
2648 sendemail.smtprelogindelay
2650 status.relativePaths
2651 status.showUntrackedFiles
2652 status.submodulesummary
2655 transfer.unpackLimit
2668 add rename remove set-head set-branches
2669 get-url set-url show prune update
2671 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2672 if [ -z "$subcommand" ]; then
2675 __gitcomp_builtin remote
2678 __gitcomp "$subcommands"
2684 case "$subcommand,$cur" in
2686 __gitcomp_builtin remote_add "--no-tags"
2691 __gitcomp_builtin remote_set-head
2694 __gitcomp_builtin remote_set-branches
2696 set-head,*|set-branches,*)
2697 __git_complete_remote_or_refspec
2700 __gitcomp_builtin remote_update
2703 __gitcomp "$(__git_get_config_variables "remotes")"
2706 __gitcomp_builtin remote_set-url
2709 __gitcomp_builtin remote_get-url
2712 __gitcomp_builtin remote_prune
2715 __gitcomp_nl "$(__git_remotes)"
2724 __gitcomp_builtin replace
2733 local subcommands="clear forget diff remaining status gc"
2734 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2735 if test -z "$subcommand"
2737 __gitcomp "$subcommands"
2744 __git_has_doubledash && return
2748 __gitcomp_builtin reset
2755 __git_revert_inprogress_options="--continue --quit --abort"
2759 __git_find_repo_path
2760 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2761 __gitcomp "$__git_revert_inprogress_options"
2766 __gitcomp_builtin revert "--no-edit" \
2767 "$__git_revert_inprogress_options"
2778 __gitcomp_builtin rm
2783 __git_complete_index_file "--cached"
2788 __git_has_doubledash && return
2793 $__git_log_common_options
2794 $__git_log_shortlog_options
2795 --numbered --summary --email
2800 __git_complete_revlist
2805 __git_has_doubledash && return
2808 --pretty=*|--format=*)
2809 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2814 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2818 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2822 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2824 $__git_diff_common_options
2829 __git_complete_revlist_file
2836 __gitcomp_builtin show-branch "--no-color"
2840 __git_complete_revlist
2845 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2846 local subcommands='push save list show apply clear drop pop create branch'
2847 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2848 if [ -z "$subcommand" ]; then
2851 __gitcomp "$save_opts"
2854 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2855 __gitcomp "$subcommands"
2860 case "$subcommand,$cur" in
2862 __gitcomp "$save_opts --message"
2865 __gitcomp "$save_opts"
2868 __gitcomp "--index --quiet"
2873 show,--*|branch,--*)
2876 if [ $cword -eq 3 ]; then
2879 __gitcomp_nl "$(__git stash list \
2880 | sed -n -e 's/:.*//p')"
2883 show,*|apply,*|drop,*|pop,*)
2884 __gitcomp_nl "$(__git stash list \
2885 | sed -n -e 's/:.*//p')"
2895 __git_has_doubledash && return
2897 local subcommands="add status init deinit update summary foreach sync"
2898 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2899 if [ -z "$subcommand" ]; then
2905 __gitcomp "$subcommands"
2911 case "$subcommand,$cur" in
2913 __gitcomp "--branch --force --name --reference --depth"
2916 __gitcomp "--cached --recursive"
2919 __gitcomp "--force --all"
2923 --init --remote --no-fetch
2924 --recommend-shallow --no-recommend-shallow
2925 --force --rebase --merge --reference --depth --recursive --jobs
2929 __gitcomp "--cached --files --summary-limit"
2931 foreach,--*|sync,--*)
2932 __gitcomp "--recursive"
2942 init fetch clone rebase dcommit log find-rev
2943 set-tree commit-diff info create-ignore propget
2944 proplist show-ignore show-externals branch tag blame
2945 migrate mkdirs reset gc
2947 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2948 if [ -z "$subcommand" ]; then
2949 __gitcomp "$subcommands"
2951 local remote_opts="--username= --config-dir= --no-auth-cache"
2953 --follow-parent --authors-file= --repack=
2954 --no-metadata --use-svm-props --use-svnsync-props
2955 --log-window-size= --no-checkout --quiet
2956 --repack-flags --use-log-author --localtime
2958 --ignore-paths= --include-paths= $remote_opts
2961 --template= --shared= --trunk= --tags=
2962 --branches= --stdlayout --minimize-url
2963 --no-metadata --use-svm-props --use-svnsync-props
2964 --rewrite-root= --prefix= $remote_opts
2967 --edit --rmdir --find-copies-harder --copy-similarity=
2970 case "$subcommand,$cur" in
2972 __gitcomp "--revision= --fetch-all $fc_opts"
2975 __gitcomp "--revision= $fc_opts $init_opts"
2978 __gitcomp "$init_opts"
2982 --merge --strategy= --verbose --dry-run
2983 --fetch-all --no-rebase --commit-url
2984 --revision --interactive $cmt_opts $fc_opts
2988 __gitcomp "--stdin $cmt_opts $fc_opts"
2990 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2991 show-externals,--*|mkdirs,--*)
2992 __gitcomp "--revision="
2996 --limit= --revision= --verbose --incremental
2997 --oneline --show-commit --non-recursive
2998 --authors-file= --color
3003 --merge --verbose --strategy= --local
3004 --fetch-all --dry-run $fc_opts
3008 __gitcomp "--message= --file= --revision= $cmt_opts"
3014 __gitcomp "--dry-run --message --tag"
3017 __gitcomp "--dry-run --message"
3020 __gitcomp "--git-format"
3024 --config-dir= --ignore-paths= --minimize
3025 --no-auth-cache --username=
3029 __gitcomp "--revision= --parent"
3040 while [ $c -lt $cword ]; do
3043 -d|--delete|-v|--verify)
3044 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3059 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3069 __gitcomp_builtin tag
3081 local subcommands="add list lock move prune remove unlock"
3082 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3083 if [ -z "$subcommand" ]; then
3084 __gitcomp "$subcommands"
3086 case "$subcommand,$cur" in
3088 __gitcomp_builtin worktree_add
3091 __gitcomp_builtin worktree_list
3094 __gitcomp_builtin worktree_lock
3097 __gitcomp_builtin worktree_prune
3108 __git_complete_common () {
3113 __gitcomp_builtin "$command"
3118 __git_cmds_with_parseopt_helper=
3119 __git_support_parseopt_helper () {
3120 test -n "$__git_cmds_with_parseopt_helper" ||
3121 __git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
3123 case " $__git_cmds_with_parseopt_helper " in
3133 __git_complete_command () {
3135 local completion_func="_git_${command//-/_}"
3136 if declare -f $completion_func >/dev/null 2>/dev/null; then
3139 elif __git_support_parseopt_helper "$command"; then
3140 __git_complete_common "$command"
3149 local i c=1 command __git_dir __git_repo_path
3150 local __git_C_args C_args_count=0
3152 while [ $c -lt $cword ]; do
3155 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
3156 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
3157 --bare) __git_dir="." ;;
3158 --help) command="help"; break ;;
3159 -c|--work-tree|--namespace) ((c++)) ;;
3160 -C) __git_C_args[C_args_count++]=-C
3162 __git_C_args[C_args_count++]="${words[c]}"
3165 *) command="$i"; break ;;
3170 if [ -z "$command" ]; then
3172 --git-dir|-C|--work-tree)
3173 # these need a path argument, let's fall back to
3174 # Bash filename completion
3178 # we don't support completing these options' arguments
3196 --no-replace-objects
3200 *) __git_compute_porcelain_commands
3201 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
3206 __git_complete_command "$command" && return
3208 local expansion=$(__git_aliased_command "$command")
3209 if [ -n "$expansion" ]; then
3211 __git_complete_command "$expansion"
3217 __git_has_doubledash && return
3219 local __git_repo_path
3220 __git_find_repo_path
3223 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3229 $__git_log_common_options
3230 $__git_log_gitk_options
3236 __git_complete_revlist
3239 if [[ -n ${ZSH_VERSION-} ]]; then
3240 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3242 autoload -U +X compinit && compinit
3248 local cur_="${3-$cur}"
3254 local c IFS=$' \t\n'
3262 array[${#array[@]}+1]="$c"
3265 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3276 compadd -Q -- ${=1} && _ret=0
3285 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3294 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3299 local _ret=1 cur cword prev
3300 cur=${words[CURRENT]}
3301 prev=${words[CURRENT-1]}
3303 emulate ksh -c __${service}_main
3304 let _ret && _default && _ret=0
3308 compdef _git git gitk
3314 local cur words cword prev
3315 _get_comp_words_by_ref -n =: cur words cword prev
3319 # Setup completion for certain functions defined above by setting common
3320 # variables and workarounds.
3321 # This is NOT a public function; use at your own risk.
3324 local wrapper="__git_wrap${2}"
3325 eval "$wrapper () { __git_func_wrap $2 ; }"
3326 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3327 || complete -o default -o nospace -F $wrapper $1
3330 # wrapper for backwards compatibility
3333 __git_wrap__git_main
3336 # wrapper for backwards compatibility
3339 __git_wrap__gitk_main
3342 __git_complete git __git_main
3343 __git_complete gitk __gitk_main
3345 # The following are necessary only for Cygwin, and only are needed
3346 # when the user has tab-completed the executable name and consequently
3347 # included the '.exe' suffix.
3349 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3350 __git_complete git.exe __git_main