1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 case "$COMP_WORDBREAKS" in
34 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
37 # Discovers the path to the git repository taking any '--git-dir=<path>' and
38 # '-C <path>' options into account and stores it in the $__git_repo_path
40 __git_find_repo_path ()
42 if [ -n "$__git_repo_path" ]; then
43 # we already know where it is
47 if [ -n "${__git_C_args-}" ]; then
48 __git_repo_path="$(git "${__git_C_args[@]}" \
49 ${__git_dir:+--git-dir="$__git_dir"} \
50 rev-parse --absolute-git-dir 2>/dev/null)"
51 elif [ -n "${__git_dir-}" ]; then
52 test -d "$__git_dir" &&
53 __git_repo_path="$__git_dir"
54 elif [ -n "${GIT_DIR-}" ]; then
55 test -d "${GIT_DIR-}" &&
56 __git_repo_path="$GIT_DIR"
57 elif [ -d .git ]; then
60 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
64 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
65 # __gitdir accepts 0 or 1 arguments (i.e., location)
66 # returns location of .git repo
69 if [ -z "${1-}" ]; then
70 __git_find_repo_path || return 1
71 echo "$__git_repo_path"
72 elif [ -d "$1/.git" ]; then
79 # Runs git with all the options given as argument, respecting any
80 # '--git-dir=<path>' and '-C <path>' options present on the command line
83 git ${__git_C_args:+"${__git_C_args[@]}"} \
84 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
87 # The following function is based on code from:
89 # bash_completion - programmable completion functions for bash 3.2+
91 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
92 # © 2009-2010, Bash Completion Maintainers
93 # <bash-completion-devel@lists.alioth.debian.org>
95 # This program is free software; you can redistribute it and/or modify
96 # it under the terms of the GNU General Public License as published by
97 # the Free Software Foundation; either version 2, or (at your option)
100 # This program is distributed in the hope that it will be useful,
101 # but WITHOUT ANY WARRANTY; without even the implied warranty of
102 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103 # GNU General Public License for more details.
105 # You should have received a copy of the GNU General Public License
106 # along with this program; if not, write to the Free Software Foundation,
107 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
109 # The latest version of this software can be obtained here:
111 # http://bash-completion.alioth.debian.org/
115 # This function can be used to access a tokenized list of words
116 # on the command line:
118 # __git_reassemble_comp_words_by_ref '=:'
119 # if test "${words_[cword_-1]}" = -w
124 # The argument should be a collection of characters from the list of
125 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
128 # This is roughly equivalent to going back in time and setting
129 # COMP_WORDBREAKS to exclude those characters. The intent is to
130 # make option types like --date=<type> and <rev>:<path> easy to
131 # recognize by treating each shell word as a single token.
133 # It is best not to set COMP_WORDBREAKS directly because the value is
134 # shared with other completion scripts. By the time the completion
135 # function gets called, COMP_WORDS has already been populated so local
136 # changes to COMP_WORDBREAKS have no effect.
138 # Output: words_, cword_, cur_.
140 __git_reassemble_comp_words_by_ref()
142 local exclude i j first
143 # Which word separators to exclude?
144 exclude="${1//[^$COMP_WORDBREAKS]}"
146 if [ -z "$exclude" ]; then
147 words_=("${COMP_WORDS[@]}")
150 # List of word completion separators has shrunk;
151 # re-assemble words to complete.
152 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
153 # Append each nonempty word consisting of just
154 # word separator characters to the current word.
158 [ -n "${COMP_WORDS[$i]}" ] &&
159 # word consists of excluded word separators
160 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
162 # Attach to the previous token,
163 # unless the previous token is the command name.
164 if [ $j -ge 2 ] && [ -n "$first" ]; then
168 words_[$j]=${words_[j]}${COMP_WORDS[i]}
169 if [ $i = $COMP_CWORD ]; then
172 if (($i < ${#COMP_WORDS[@]} - 1)); then
179 words_[$j]=${words_[j]}${COMP_WORDS[i]}
180 if [ $i = $COMP_CWORD ]; then
186 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
187 _get_comp_words_by_ref ()
189 local exclude cur_ words_ cword_
190 if [ "$1" = "-n" ]; then
194 __git_reassemble_comp_words_by_ref "$exclude"
195 cur_=${words_[cword_]}
196 while [ $# -gt 0 ]; do
202 prev=${words_[$cword_-1]}
205 words=("${words_[@]}")
218 local x i=${#COMPREPLY[@]}
220 if [[ "$x" == "$3"* ]]; then
221 COMPREPLY[i++]="$2$x$4"
232 # Generates completion reply, appending a space to possible completion words,
234 # It accepts 1 to 4 arguments:
235 # 1: List of possible completion words.
236 # 2: A prefix to be added to each possible completion word (optional).
237 # 3: Generate possible completion matches for this word (optional).
238 # 4: A suffix to be appended to each possible completion word (optional).
241 local cur_="${3-$cur}"
247 local c i=0 IFS=$' \t\n'
250 if [[ $c == "$cur_"* ]]; then
255 COMPREPLY[i++]="${2-}$c"
262 # Variation of __gitcomp_nl () that appends to the existing list of
263 # completion candidates, COMPREPLY.
264 __gitcomp_nl_append ()
267 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
270 # Generates completion reply from newline-separated possible completion words
271 # by appending a space to all of them.
272 # It accepts 1 to 4 arguments:
273 # 1: List of possible completion words, separated by a single newline.
274 # 2: A prefix to be added to each possible completion word (optional).
275 # 3: Generate possible completion matches for this word (optional).
276 # 4: A suffix to be appended to each possible completion word instead of
277 # the default space (optional). If specified but empty, nothing is
282 __gitcomp_nl_append "$@"
285 # Generates completion reply with compgen from newline-separated possible
286 # completion filenames.
287 # It accepts 1 to 3 arguments:
288 # 1: List of possible completion filenames, separated by a single newline.
289 # 2: A directory prefix to be added to each possible completion filename
291 # 3: Generate possible completion matches for this word (optional).
296 # XXX does not work when the directory prefix contains a tilde,
297 # since tilde expansion is not applied.
298 # This means that COMPREPLY will be empty and Bash default
299 # completion will be used.
300 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
302 # use a hack to enable file mode in bash < 4
303 compopt -o filenames +o nospace 2>/dev/null ||
304 compgen -f /non-existing-dir/ > /dev/null
307 # Execute 'git ls-files', unless the --committable option is specified, in
308 # which case it runs 'git diff-index' to find out the files that can be
309 # committed. It return paths relative to the directory specified in the first
310 # argument, and using the options specified in the second argument.
311 __git_ls_files_helper ()
313 if [ "$2" == "--committable" ]; then
314 __git -C "$1" diff-index --name-only --relative HEAD
316 # NOTE: $2 is not quoted in order to support multiple options
317 __git -C "$1" ls-files --exclude-standard $2
322 # __git_index_files accepts 1 or 2 arguments:
323 # 1: Options to pass to ls-files (required).
324 # 2: A directory path (optional).
325 # If provided, only files within the specified directory are listed.
326 # Sub directories are never recursed. Path must have a trailing
330 local root="${2-.}" file
332 __git_ls_files_helper "$root" "$1" |
333 while read -r file; do
335 ?*/*) echo "${file%%/*}" ;;
343 __git for-each-ref --format='%(refname:short)' refs/heads
348 __git for-each-ref --format='%(refname:short)' refs/tags
351 # Lists refs from the local (by default) or from a remote repository.
352 # It accepts 0, 1 or 2 arguments:
353 # 1: The remote to list refs from (optional; ignored, if set but empty).
354 # Can be the name of a configured remote, a path, or a URL.
355 # 2: In addition to local refs, list unique branches from refs/remotes/ for
356 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
358 # Use __git_complete_refs() instead.
361 local i hash dir track="${2-}"
362 local list_refs_from=path remote="${1-}"
363 local format refs pfx
366 dir="$__git_repo_path"
368 if [ -z "$remote" ]; then
369 if [ -z "$dir" ]; then
373 if __git_is_configured_remote "$remote"; then
374 # configured remote takes precedence over a
375 # local directory with the same name
376 list_refs_from=remote
377 elif [ -d "$remote/.git" ]; then
379 elif [ -d "$remote" ]; then
386 if [ "$list_refs_from" = path ]; then
394 [[ "$cur" == ^* ]] && pfx="^"
395 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
396 if [ -e "$dir/$i" ]; then echo $pfx$i; fi
398 format="refname:short"
399 refs="refs/tags refs/heads refs/remotes"
402 __git_dir="$dir" __git for-each-ref --format="$pfx%($format)" \
404 if [ -n "$track" ]; then
405 # employ the heuristic used by git checkout
406 # Try to find a remote branch that matches the completion word
407 # but only output if the branch name is unique
409 __git for-each-ref --shell --format="ref=%(refname:short)" \
411 while read -r entry; do
414 if [[ "$ref" == "$cur"* ]]; then
417 done | sort | uniq -u
423 __git ls-remote "$remote" "$cur*" | \
424 while read -r hash i; do
432 if [ "$list_refs_from" = remote ]; then
434 __git for-each-ref --format="%(refname:short)" \
435 "refs/remotes/$remote/" | sed -e "s#^$remote/##"
437 __git ls-remote "$remote" HEAD \
438 "refs/tags/*" "refs/heads/*" "refs/remotes/*" |
439 while read -r hash i; do
442 refs/*) echo "${i#refs/*/}" ;;
443 *) echo "$i" ;; # symbolic refs
451 # Completes refs, short and long, local and remote, symbolic and pseudo.
453 # Usage: __git_complete_refs [<option>]...
454 # --remote=<remote>: The remote to list refs from, can be the name of a
455 # configured remote, a path, or a URL.
456 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
457 # --pfx=<prefix>: A prefix to be added to each ref.
458 # --cur=<word>: The current ref to be completed. Defaults to the current
459 # word to be completed.
460 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
462 __git_complete_refs ()
464 local remote track pfx cur_="$cur" sfx=" "
466 while test $# != 0; do
468 --remote=*) remote="${1##--remote=}" ;;
469 --track) track="yes" ;;
470 --pfx=*) pfx="${1##--pfx=}" ;;
471 --cur=*) cur_="${1##--cur=}" ;;
472 --sfx=*) sfx="${1##--sfx=}" ;;
478 __gitcomp_nl "$(__git_refs "$remote" "$track")" "$pfx" "$cur_" "$sfx"
481 # __git_refs2 requires 1 argument (to pass to __git_refs)
485 for i in $(__git_refs "$1"); do
490 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
491 __git_refs_remotes ()
494 __git ls-remote "$1" 'refs/heads/*' | \
495 while read -r hash i; do
496 echo "$i:refs/remotes/$1/${i#refs/heads/}"
503 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
507 # Returns true if $1 matches the name of a configured remote, false otherwise.
508 __git_is_configured_remote ()
511 for remote in $(__git_remotes); do
512 if [ "$remote" = "$1" ]; then
519 __git_list_merge_strategies ()
521 git merge -s help 2>&1 |
522 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
531 __git_merge_strategies=
532 # 'git merge -s help' (and thus detection of the merge strategy
533 # list) fails, unfortunately, if run outside of any git working
534 # tree. __git_merge_strategies is set to the empty string in
535 # that case, and the detection will be repeated the next time it
537 __git_compute_merge_strategies ()
539 test -n "$__git_merge_strategies" ||
540 __git_merge_strategies=$(__git_list_merge_strategies)
543 __git_complete_revlist_file ()
545 local pfx ls ref cur_="$cur"
565 case "$COMP_WORDBREAKS" in
567 *) pfx="$ref:$pfx" ;;
570 __gitcomp_nl "$(__git ls-tree "$ls" \
571 | sed '/^100... blob /{
587 pfx="${cur_%...*}..."
589 __git_complete_refs --pfx="$pfx" --cur="$cur_"
594 __git_complete_refs --pfx="$pfx" --cur="$cur_"
603 # __git_complete_index_file requires 1 argument:
604 # 1: the options to pass to ls-file
606 # The exception is --committable, which finds the files appropriate commit.
607 __git_complete_index_file ()
609 local pfx="" cur_="$cur"
619 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
622 __git_complete_file ()
624 __git_complete_revlist_file
627 __git_complete_revlist ()
629 __git_complete_revlist_file
632 __git_complete_remote_or_refspec ()
634 local cur_="$cur" cmd="${words[1]}"
635 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
636 if [ "$cmd" = "remote" ]; then
639 while [ $c -lt $cword ]; do
642 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
645 push) no_complete_refspec=1 ;;
653 *) remote="$i"; break ;;
657 if [ -z "$remote" ]; then
658 __gitcomp_nl "$(__git_remotes)"
661 if [ $no_complete_refspec = 1 ]; then
664 [ "$remote" = "." ] && remote=
667 case "$COMP_WORDBREAKS" in
669 *) pfx="${cur_%%:*}:" ;;
681 if [ $lhs = 1 ]; then
682 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
684 __git_complete_refs --pfx="$pfx" --cur="$cur_"
688 if [ $lhs = 1 ]; then
689 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
691 __git_complete_refs --pfx="$pfx" --cur="$cur_"
695 if [ $lhs = 1 ]; then
696 __git_complete_refs --pfx="$pfx" --cur="$cur_"
698 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
704 __git_complete_strategy ()
706 __git_compute_merge_strategies
709 __gitcomp "$__git_merge_strategies"
714 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
722 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
724 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
726 git help -a|egrep '^ [a-zA-Z0-9]'
730 __git_list_all_commands ()
733 for i in $(__git_commands)
736 *--*) : helper pattern;;
743 __git_compute_all_commands ()
745 test -n "$__git_all_commands" ||
746 __git_all_commands=$(__git_list_all_commands)
749 __git_list_porcelain_commands ()
752 __git_compute_all_commands
753 for i in $__git_all_commands
756 *--*) : helper pattern;;
757 applymbox) : ask gittus;;
758 applypatch) : ask gittus;;
759 archimport) : import;;
760 cat-file) : plumbing;;
761 check-attr) : plumbing;;
762 check-ignore) : plumbing;;
763 check-mailmap) : plumbing;;
764 check-ref-format) : plumbing;;
765 checkout-index) : plumbing;;
766 column) : internal helper;;
767 commit-tree) : plumbing;;
768 count-objects) : infrequent;;
769 credential) : credentials;;
770 credential-*) : credentials helper;;
771 cvsexportcommit) : export;;
772 cvsimport) : import;;
773 cvsserver) : daemon;;
775 diff-files) : plumbing;;
776 diff-index) : plumbing;;
777 diff-tree) : plumbing;;
778 fast-import) : import;;
779 fast-export) : export;;
780 fsck-objects) : plumbing;;
781 fetch-pack) : plumbing;;
782 fmt-merge-msg) : plumbing;;
783 for-each-ref) : plumbing;;
784 hash-object) : plumbing;;
785 http-*) : transport;;
786 index-pack) : plumbing;;
787 init-db) : deprecated;;
788 local-fetch) : plumbing;;
789 ls-files) : plumbing;;
790 ls-remote) : plumbing;;
791 ls-tree) : plumbing;;
792 mailinfo) : plumbing;;
793 mailsplit) : plumbing;;
794 merge-*) : plumbing;;
797 pack-objects) : plumbing;;
798 pack-redundant) : plumbing;;
799 pack-refs) : plumbing;;
800 parse-remote) : plumbing;;
801 patch-id) : plumbing;;
803 prune-packed) : plumbing;;
804 quiltimport) : import;;
805 read-tree) : plumbing;;
806 receive-pack) : plumbing;;
807 remote-*) : transport;;
809 rev-list) : plumbing;;
810 rev-parse) : plumbing;;
811 runstatus) : plumbing;;
812 sh-setup) : internal;;
814 show-ref) : plumbing;;
815 send-pack) : plumbing;;
816 show-index) : plumbing;;
818 stripspace) : plumbing;;
819 symbolic-ref) : plumbing;;
820 unpack-file) : plumbing;;
821 unpack-objects) : plumbing;;
822 update-index) : plumbing;;
823 update-ref) : plumbing;;
824 update-server-info) : daemon;;
825 upload-archive) : plumbing;;
826 upload-pack) : plumbing;;
827 write-tree) : plumbing;;
829 verify-pack) : infrequent;;
830 verify-tag) : plumbing;;
836 __git_porcelain_commands=
837 __git_compute_porcelain_commands ()
839 test -n "$__git_porcelain_commands" ||
840 __git_porcelain_commands=$(__git_list_porcelain_commands)
843 # Lists all set config variables starting with the given section prefix,
844 # with the prefix removed.
845 __git_get_config_variables ()
847 local section="$1" i IFS=$'\n'
848 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
849 echo "${i#$section.}"
853 __git_pretty_aliases ()
855 __git_get_config_variables "pretty"
860 __git_get_config_variables "alias"
863 # __git_aliased_command requires 1 argument
864 __git_aliased_command ()
866 local word cmdline=$(__git config --get "alias.$1")
867 for word in $cmdline; do
873 \!*) : shell command alias ;;
875 *=*) : setting env ;;
877 \(\)) : skip parens of shell function definition ;;
878 {) : skip start of shell helper function ;;
879 :) : skip null command ;;
880 \'*) : skip opening quote after sh -c ;;
888 # __git_find_on_cmdline requires 1 argument
889 __git_find_on_cmdline ()
891 local word subcommand c=1
892 while [ $c -lt $cword ]; do
894 for subcommand in $1; do
895 if [ "$subcommand" = "$word" ]; then
904 # Echo the value of an option set on the command line or config
906 # $1: short option name
907 # $2: long option name including =
908 # $3: list of possible values
909 # $4: config string (optional)
912 # result="$(__git_get_option_value "-d" "--do-something=" \
913 # "yes no" "core.doSomething")"
915 # result is then either empty (no option set) or "yes" or "no"
917 # __git_get_option_value requires 3 arguments
918 __git_get_option_value ()
920 local c short_opt long_opt val
921 local result= values config_key word
929 while [ $c -ge 0 ]; do
931 for val in $values; do
932 if [ "$short_opt$val" = "$word" ] ||
933 [ "$long_opt$val" = "$word" ]; then
941 if [ -n "$config_key" ] && [ -z "$result" ]; then
942 result="$(__git config "$config_key")"
948 __git_has_doubledash ()
951 while [ $c -lt $cword ]; do
952 if [ "--" = "${words[c]}" ]; then
960 # Try to count non option arguments passed on the command line for the
961 # specified git command.
962 # When options are used, it is necessary to use the special -- option to
963 # tell the implementation were non option arguments begin.
964 # XXX this can not be improved, since options can appear everywhere, as
968 # __git_count_arguments requires 1 argument: the git command executed.
969 __git_count_arguments ()
973 # Skip "git" (first argument)
974 for ((i=1; i < ${#words[@]}; i++)); do
979 # Good; we can assume that the following are only non
984 # Skip the specified git command and discard git
997 __git_whitespacelist="nowarn warn error error-all fix"
1001 __git_find_repo_path
1002 if [ -d "$__git_repo_path"/rebase-apply ]; then
1003 __gitcomp "--skip --continue --resolved --abort"
1008 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1013 --3way --committer-date-is-author-date --ignore-date
1014 --ignore-whitespace --ignore-space-change
1015 --interactive --keep --no-utf8 --signoff --utf8
1016 --whitespace= --scissors
1026 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1031 --stat --numstat --summary --check --index
1032 --cached --index-info --reverse --reject --unidiff-zero
1033 --apply --no-add --exclude=
1034 --ignore-whitespace --ignore-space-change
1035 --whitespace= --inaccurate-eof --verbose
1046 --interactive --refresh --patch --update --dry-run
1047 --ignore-errors --intent-to-add
1052 # XXX should we check for --update and --all options ?
1053 __git_complete_index_file "--others --modified --directory --no-empty-directory"
1060 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1064 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1069 --format= --list --verbose
1070 --prefix= --remote= --exec=
1080 __git_has_doubledash && return
1082 local subcommands="start bad good skip reset visualize replay log run"
1083 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1084 if [ -z "$subcommand" ]; then
1085 __git_find_repo_path
1086 if [ -f "$__git_repo_path"/BISECT_START ]; then
1087 __gitcomp "$subcommands"
1089 __gitcomp "replay start"
1094 case "$subcommand" in
1095 bad|good|reset|skip|start)
1105 local i c=1 only_local_ref="n" has_r="n"
1107 while [ $c -lt $cword ]; do
1110 -d|--delete|-m|--move) only_local_ref="y" ;;
1111 -r|--remotes) has_r="y" ;;
1117 --set-upstream-to=*)
1118 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1122 --color --no-color --verbose --abbrev= --no-abbrev
1123 --track --no-track --contains --merged --no-merged
1124 --set-upstream-to= --edit-description --list
1125 --unset-upstream --delete --move --remotes
1129 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1130 __gitcomp_nl "$(__git_heads)"
1140 local cmd="${words[2]}"
1143 __gitcomp "create list-heads verify unbundle"
1146 # looking for a file
1151 __git_complete_revlist
1160 __git_has_doubledash && return
1164 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1168 --quiet --ours --theirs --track --no-track --merge
1169 --conflict= --orphan --patch
1173 # check if --track, --no-track, or --no-guess was specified
1174 # if so, disable DWIM mode
1175 local flags="--track --no-track --no-guess" track_opt="--track"
1176 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1179 __git_complete_refs $track_opt
1191 __git_find_repo_path
1192 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1193 __gitcomp "--continue --quit --abort"
1198 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1210 __gitcomp "--dry-run --quiet"
1215 # XXX should we check for -x option ?
1216 __git_complete_index_file "--others --directory"
1238 --recurse-submodules
1245 __git_untracked_file_modes="all no normal"
1258 __gitcomp "default scissors strip verbatim whitespace
1259 " "" "${cur##--cleanup=}"
1262 --reuse-message=*|--reedit-message=*|\
1263 --fixup=*|--squash=*)
1264 __git_complete_refs --cur="${cur#*=}"
1267 --untracked-files=*)
1268 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1273 --all --author= --signoff --verify --no-verify
1275 --amend --include --only --interactive
1276 --dry-run --reuse-message= --reedit-message=
1277 --reset-author --file= --message= --template=
1278 --cleanup= --untracked-files --untracked-files=
1279 --verbose --quiet --fixup= --squash=
1284 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1285 __git_complete_index_file "--committable"
1287 # This is the first commit
1288 __git_complete_index_file "--cached"
1297 --all --tags --contains --abbrev= --candidates=
1298 --exact-match --debug --long --match --always
1305 __git_diff_algorithms="myers minimal patience histogram"
1307 __git_diff_submodule_formats="diff log short"
1309 __git_diff_common_options="--stat --numstat --shortstat --summary
1310 --patch-with-stat --name-only --name-status --color
1311 --no-color --color-words --no-renames --check
1312 --full-index --binary --abbrev --diff-filter=
1313 --find-copies-harder
1314 --text --ignore-space-at-eol --ignore-space-change
1315 --ignore-all-space --ignore-blank-lines --exit-code
1316 --quiet --ext-diff --no-ext-diff
1317 --no-prefix --src-prefix= --dst-prefix=
1318 --inter-hunk-context=
1319 --patience --histogram --minimal
1320 --raw --word-diff --word-diff-regex=
1321 --dirstat --dirstat= --dirstat-by-file
1322 --dirstat-by-file= --cumulative
1324 --submodule --submodule=
1329 __git_has_doubledash && return
1333 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1337 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1341 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1342 --base --ours --theirs --no-index
1343 $__git_diff_common_options
1348 __git_complete_revlist_file
1351 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1352 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1357 __git_has_doubledash && return
1361 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1365 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1366 --base --ours --theirs
1367 --no-renames --diff-filter= --find-copies-harder
1368 --relative --ignore-submodules
1373 __git_complete_revlist_file
1376 __git_fetch_recurse_submodules="yes on-demand no"
1378 __git_fetch_options="
1379 --quiet --verbose --append --upload-pack --force --keep --depth=
1380 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1386 --recurse-submodules=*)
1387 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1391 __gitcomp "$__git_fetch_options"
1395 __git_complete_remote_or_refspec
1398 __git_format_patch_options="
1399 --stdout --attach --no-attach --thread --thread= --no-thread
1400 --numbered --start-number --numbered-files --keep-subject --signoff
1401 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1402 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1403 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1404 --output-directory --reroll-count --to= --quiet --notes
1407 _git_format_patch ()
1413 " "" "${cur##--thread=}"
1417 __gitcomp "$__git_format_patch_options"
1421 __git_complete_revlist
1429 --tags --root --unreachable --cache --no-reflogs --full
1430 --strict --verbose --lost-found
1441 __gitcomp "--prune --aggressive"
1452 __git_match_ctag() {
1453 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1458 __git_has_doubledash && return
1464 --text --ignore-case --word-regexp --invert-match
1465 --full-name --line-number
1466 --extended-regexp --basic-regexp --fixed-strings
1469 --files-with-matches --name-only
1470 --files-without-match
1473 --and --or --not --all-match
1479 case "$cword,$prev" in
1481 if test -r tags; then
1482 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1495 __gitcomp "--all --guides --info --man --web"
1499 __git_compute_all_commands
1500 __gitcomp "$__git_all_commands $(__git_aliases)
1501 attributes cli core-tutorial cvs-migration
1502 diffcore everyday gitk glossary hooks ignore modules
1503 namespaces repository-layout revisions tutorial tutorial-2
1513 false true umask group all world everybody
1514 " "" "${cur##--shared=}"
1518 __gitcomp "--quiet --bare --template= --shared --shared="
1528 __gitcomp "--cached --deleted --modified --others --ignored
1529 --stage --directory --no-empty-directory --unmerged
1530 --killed --exclude= --exclude-from=
1531 --exclude-per-directory= --exclude-standard
1532 --error-unmatch --with-tree= --full-name
1533 --abbrev --ignored --exclude-per-directory
1539 # XXX ignore options like --modified and always suggest all cached
1541 __git_complete_index_file "--cached"
1546 __gitcomp_nl "$(__git_remotes)"
1554 # Options that go well for log, shortlog and gitk
1555 __git_log_common_options="
1557 --branches --tags --remotes
1558 --first-parent --merges --no-merges
1560 --max-age= --since= --after=
1561 --min-age= --until= --before=
1562 --min-parents= --max-parents=
1563 --no-min-parents --no-max-parents
1565 # Options that go well for log and gitk (not shortlog)
1566 __git_log_gitk_options="
1567 --dense --sparse --full-history
1568 --simplify-merges --simplify-by-decoration
1569 --left-right --notes --no-notes
1571 # Options that go well for log and shortlog (not gitk)
1572 __git_log_shortlog_options="
1573 --author= --committer= --grep=
1574 --all-match --invert-grep
1577 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1578 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1582 __git_has_doubledash && return
1583 __git_find_repo_path
1586 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1590 --pretty=*|--format=*)
1591 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1596 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1600 __gitcomp "full short no" "" "${cur##--decorate=}"
1604 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1608 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1613 $__git_log_common_options
1614 $__git_log_shortlog_options
1615 $__git_log_gitk_options
1616 --root --topo-order --date-order --reverse
1617 --follow --full-diff
1618 --abbrev-commit --abbrev=
1619 --relative-date --date=
1620 --pretty= --format= --oneline
1625 --decorate --decorate=
1627 --parents --children
1629 $__git_diff_common_options
1630 --pickaxe-all --pickaxe-regex
1635 __git_complete_revlist
1638 # Common merge options shared by git-merge(1) and git-pull(1).
1639 __git_merge_options="
1640 --no-commit --no-stat --log --no-log --squash --strategy
1641 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1642 --verify-signatures --no-verify-signatures --gpg-sign
1643 --quiet --verbose --progress --no-progress
1648 __git_complete_strategy && return
1652 __gitcomp "$__git_merge_options
1653 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1663 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1677 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1688 __gitcomp "--dry-run"
1693 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1694 # We need to show both cached and untracked files (including
1695 # empty directories) since this may not be the last argument.
1696 __git_complete_index_file "--cached --others --directory"
1698 __git_complete_index_file "--cached"
1704 __gitcomp "--tags --all --stdin"
1709 local subcommands='add append copy edit list prune remove show'
1710 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1712 case "$subcommand,$cur" in
1722 __gitcomp "$subcommands --ref"
1726 add,--reuse-message=*|append,--reuse-message=*|\
1727 add,--reedit-message=*|append,--reedit-message=*)
1728 __git_complete_refs --cur="${cur#*=}"
1731 __gitcomp '--file= --message= --reedit-message=
1738 __gitcomp '--dry-run --verbose'
1756 __git_complete_strategy && return
1759 --recurse-submodules=*)
1760 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1765 --rebase --no-rebase
1766 $__git_merge_options
1767 $__git_fetch_options
1772 __git_complete_remote_or_refspec
1775 __git_push_recurse_submodules="check on-demand"
1777 __git_complete_force_with_lease ()
1785 __git_complete_refs --cur="${cur_#*:}"
1788 __git_complete_refs --cur="$cur_"
1797 __gitcomp_nl "$(__git_remotes)"
1800 --recurse-submodules)
1801 __gitcomp "$__git_push_recurse_submodules"
1807 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1810 --recurse-submodules=*)
1811 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1814 --force-with-lease=*)
1815 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1820 --all --mirror --tags --dry-run --force --verbose
1821 --quiet --prune --delete --follow-tags
1822 --receive-pack= --repo= --set-upstream
1823 --force-with-lease --force-with-lease= --recurse-submodules=
1828 __git_complete_remote_or_refspec
1833 __git_find_repo_path
1834 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1835 __gitcomp "--continue --skip --abort --quit --edit-todo"
1837 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1838 [ -d "$__git_repo_path"/rebase-merge ]; then
1839 __gitcomp "--continue --skip --abort --quit"
1842 __git_complete_strategy && return
1845 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1850 --onto --merge --strategy --interactive
1851 --preserve-merges --stat --no-stat
1852 --committer-date-is-author-date --ignore-date
1853 --ignore-whitespace --whitespace=
1854 --autosquash --no-autosquash
1855 --fork-point --no-fork-point
1856 --autostash --no-autostash
1857 --verify --no-verify
1858 --keep-empty --root --force-rebase --no-ff
1869 local subcommands="show delete expire"
1870 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1872 if [ -z "$subcommand" ]; then
1873 __gitcomp "$subcommands"
1879 __git_send_email_confirm_options="always never auto cc compose"
1880 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1885 --to|--cc|--bcc|--from)
1886 __gitcomp "$(__git send-email --dump-aliases)"
1894 $__git_send_email_confirm_options
1895 " "" "${cur##--confirm=}"
1900 $__git_send_email_suppresscc_options
1901 " "" "${cur##--suppress-cc=}"
1905 --smtp-encryption=*)
1906 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1912 " "" "${cur##--thread=}"
1915 --to=*|--cc=*|--bcc=*|--from=*)
1916 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
1920 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1921 --compose --confirm= --dry-run --envelope-sender
1923 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1924 --no-suppress-from --no-thread --quiet
1925 --signed-off-by-cc --smtp-pass --smtp-server
1926 --smtp-server-port --smtp-encryption= --smtp-user
1927 --subject --suppress-cc= --suppress-from --thread --to
1928 --validate --no-validate
1929 $__git_format_patch_options"
1933 __git_complete_revlist
1944 local untracked_state
1947 --ignore-submodules=*)
1948 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1951 --untracked-files=*)
1952 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1957 always never auto column row plain dense nodense
1958 " "" "${cur##--column=}"
1963 --short --branch --porcelain --long --verbose
1964 --untracked-files= --ignore-submodules= --ignored
1965 --column= --no-column
1971 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1972 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
1974 case "$untracked_state" in
1976 # --ignored option does not matter
1980 complete_opt="--cached --directory --no-empty-directory --others"
1982 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1983 complete_opt="$complete_opt --ignored --exclude=*"
1988 __git_complete_index_file "$complete_opt"
1991 __git_config_get_set_variables ()
1993 local prevword word config_file= c=$cword
1994 while [ $c -gt 1 ]; do
1997 --system|--global|--local|--file=*)
2002 config_file="$word $prevword"
2010 __git config $config_file --name-only --list
2016 branch.*.remote|branch.*.pushremote)
2017 __gitcomp_nl "$(__git_remotes)"
2025 __gitcomp "false true preserve interactive"
2029 __gitcomp_nl "$(__git_remotes)"
2033 local remote="${prev#remote.}"
2034 remote="${remote%.fetch}"
2035 if [ -z "$cur" ]; then
2036 __gitcomp_nl "refs/heads/" "" "" ""
2039 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2043 local remote="${prev#remote.}"
2044 remote="${remote%.push}"
2045 __gitcomp_nl "$(__git for-each-ref \
2046 --format='%(refname):%(refname)' refs/heads)"
2049 pull.twohead|pull.octopus)
2050 __git_compute_merge_strategies
2051 __gitcomp "$__git_merge_strategies"
2054 color.branch|color.diff|color.interactive|\
2055 color.showbranch|color.status|color.ui)
2056 __gitcomp "always never auto"
2060 __gitcomp "false true"
2065 normal black red green yellow blue magenta cyan white
2066 bold dim ul blink reverse
2071 __gitcomp "log short"
2075 __gitcomp "man info web html"
2079 __gitcomp "$__git_log_date_formats"
2082 sendemail.aliasesfiletype)
2083 __gitcomp "mutt mailrc pine elm gnus"
2087 __gitcomp "$__git_send_email_confirm_options"
2090 sendemail.suppresscc)
2091 __gitcomp "$__git_send_email_suppresscc_options"
2094 sendemail.transferencoding)
2095 __gitcomp "7bit 8bit quoted-printable base64"
2098 --get|--get-all|--unset|--unset-all)
2099 __gitcomp_nl "$(__git_config_get_set_variables)"
2109 --system --global --local --file=
2110 --list --replace-all
2111 --get --get-all --get-regexp
2112 --add --unset --unset-all
2113 --remove-section --rename-section
2119 local pfx="${cur%.*}." cur_="${cur##*.}"
2120 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2124 local pfx="${cur%.*}." cur_="${cur#*.}"
2125 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
2126 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2130 local pfx="${cur%.*}." cur_="${cur##*.}"
2132 argprompt cmd confirm needsfile noconsole norescan
2133 prompt revprompt revunmerged title
2138 local pfx="${cur%.*}." cur_="${cur##*.}"
2139 __gitcomp "cmd path" "$pfx" "$cur_"
2143 local pfx="${cur%.*}." cur_="${cur##*.}"
2144 __gitcomp "cmd path" "$pfx" "$cur_"
2148 local pfx="${cur%.*}." cur_="${cur##*.}"
2149 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2153 local pfx="${cur%.*}." cur_="${cur#*.}"
2154 __git_compute_all_commands
2155 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2159 local pfx="${cur%.*}." cur_="${cur##*.}"
2161 url proxy fetch push mirror skipDefaultUpdate
2162 receivepack uploadpack tagopt pushurl
2167 local pfx="${cur%.*}." cur_="${cur#*.}"
2168 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2169 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2173 local pfx="${cur%.*}." cur_="${cur##*.}"
2174 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2180 advice.commitBeforeMerge
2182 advice.implicitIdentity
2183 advice.pushNonFastForward
2184 advice.resolveConflict
2188 apply.ignorewhitespace
2190 branch.autosetupmerge
2191 branch.autosetuprebase
2195 color.branch.current
2200 color.decorate.branch
2201 color.decorate.remoteBranch
2202 color.decorate.stash
2212 color.diff.whitespace
2217 color.grep.linenumber
2220 color.grep.separator
2222 color.interactive.error
2223 color.interactive.header
2224 color.interactive.help
2225 color.interactive.prompt
2230 color.status.changed
2232 color.status.nobranch
2233 color.status.unmerged
2234 color.status.untracked
2235 color.status.updated
2244 core.bigFileThreshold
2247 core.deltaBaseCacheLimit
2252 core.fsyncobjectfiles
2256 core.logAllRefUpdates
2257 core.loosecompression
2260 core.packedGitWindowSize
2262 core.preferSymlinkRefs
2265 core.repositoryFormatVersion
2267 core.sharedRepository
2272 core.warnAmbiguousRefs
2275 diff.autorefreshindex
2277 diff.ignoreSubmodules
2284 diff.suppressBlankEmpty
2290 fetch.recurseSubmodules
2301 format.subjectprefix
2312 gc.reflogexpireunreachable
2316 gitcvs.commitmsgannotation
2317 gitcvs.dbTableNamePrefix
2328 gui.copyblamethreshold
2332 gui.matchtrackingbranch
2333 gui.newbranchtemplate
2334 gui.pruneduringfetch
2335 gui.spellingdictionary
2352 http.sslCertPasswordProtected
2357 i18n.logOutputEncoding
2363 imap.preformattedHTML
2373 interactive.singlekey
2389 mergetool.keepBackup
2390 mergetool.keepTemporaries
2395 notes.rewrite.rebase
2399 pack.deltaCacheLimit
2416 receive.denyCurrentBranch
2417 receive.denyDeleteCurrent
2419 receive.denyNonFastForwards
2422 receive.updateserverinfo
2425 repack.usedeltabaseoffset
2429 sendemail.aliasesfile
2430 sendemail.aliasfiletype
2434 sendemail.chainreplyto
2436 sendemail.envelopesender
2440 sendemail.signedoffbycc
2441 sendemail.smtpdomain
2442 sendemail.smtpencryption
2444 sendemail.smtpserver
2445 sendemail.smtpserveroption
2446 sendemail.smtpserverport
2448 sendemail.suppresscc
2449 sendemail.suppressfrom
2454 status.relativePaths
2455 status.showUntrackedFiles
2456 status.submodulesummary
2459 transfer.unpackLimit
2471 local subcommands="add rename remove set-head set-branches set-url show prune update"
2472 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2473 if [ -z "$subcommand" ]; then
2474 __gitcomp "$subcommands"
2478 case "$subcommand" in
2479 rename|remove|set-url|show|prune)
2480 __gitcomp_nl "$(__git_remotes)"
2482 set-head|set-branches)
2483 __git_complete_remote_or_refspec
2486 __gitcomp "$(__git_get_config_variables "remotes")"
2500 __git_has_doubledash && return
2504 __gitcomp "--merge --mixed --hard --soft --patch"
2513 __git_find_repo_path
2514 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2515 __gitcomp "--continue --quit --abort"
2520 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2531 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2536 __git_complete_index_file "--cached"
2541 __git_has_doubledash && return
2546 $__git_log_common_options
2547 $__git_log_shortlog_options
2548 --numbered --summary
2553 __git_complete_revlist
2558 __git_has_doubledash && return
2561 --pretty=*|--format=*)
2562 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2567 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2571 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2575 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2577 $__git_diff_common_options
2582 __git_complete_revlist_file
2590 --all --remotes --topo-order --date-order --current --more=
2591 --list --independent --merge-base --no-name
2593 --sha1-name --sparse --topics --reflog
2598 __git_complete_revlist
2603 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2604 local subcommands='save list show apply clear drop pop create branch'
2605 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2606 if [ -z "$subcommand" ]; then
2609 __gitcomp "$save_opts"
2612 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2613 __gitcomp "$subcommands"
2618 case "$subcommand,$cur" in
2620 __gitcomp "$save_opts"
2623 __gitcomp "--index --quiet"
2628 show,--*|branch,--*)
2631 if [ $cword -eq 3 ]; then
2634 __gitcomp_nl "$(__git stash list \
2635 | sed -n -e 's/:.*//p')"
2638 show,*|apply,*|drop,*|pop,*)
2639 __gitcomp_nl "$(__git stash list \
2640 | sed -n -e 's/:.*//p')"
2650 __git_has_doubledash && return
2652 local subcommands="add status init deinit update summary foreach sync"
2653 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2656 __gitcomp "--quiet --cached"
2659 __gitcomp "$subcommands"
2669 init fetch clone rebase dcommit log find-rev
2670 set-tree commit-diff info create-ignore propget
2671 proplist show-ignore show-externals branch tag blame
2672 migrate mkdirs reset gc
2674 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2675 if [ -z "$subcommand" ]; then
2676 __gitcomp "$subcommands"
2678 local remote_opts="--username= --config-dir= --no-auth-cache"
2680 --follow-parent --authors-file= --repack=
2681 --no-metadata --use-svm-props --use-svnsync-props
2682 --log-window-size= --no-checkout --quiet
2683 --repack-flags --use-log-author --localtime
2684 --ignore-paths= --include-paths= $remote_opts
2687 --template= --shared= --trunk= --tags=
2688 --branches= --stdlayout --minimize-url
2689 --no-metadata --use-svm-props --use-svnsync-props
2690 --rewrite-root= --prefix= --use-log-author
2691 --add-author-from $remote_opts
2694 --edit --rmdir --find-copies-harder --copy-similarity=
2697 case "$subcommand,$cur" in
2699 __gitcomp "--revision= --fetch-all $fc_opts"
2702 __gitcomp "--revision= $fc_opts $init_opts"
2705 __gitcomp "$init_opts"
2709 --merge --strategy= --verbose --dry-run
2710 --fetch-all --no-rebase --commit-url
2711 --revision --interactive $cmt_opts $fc_opts
2715 __gitcomp "--stdin $cmt_opts $fc_opts"
2717 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2718 show-externals,--*|mkdirs,--*)
2719 __gitcomp "--revision="
2723 --limit= --revision= --verbose --incremental
2724 --oneline --show-commit --non-recursive
2725 --authors-file= --color
2730 --merge --verbose --strategy= --local
2731 --fetch-all --dry-run $fc_opts
2735 __gitcomp "--message= --file= --revision= $cmt_opts"
2741 __gitcomp "--dry-run --message --tag"
2744 __gitcomp "--dry-run --message"
2747 __gitcomp "--git-format"
2751 --config-dir= --ignore-paths= --minimize
2752 --no-auth-cache --username=
2756 __gitcomp "--revision= --parent"
2767 while [ $c -lt $cword ]; do
2771 __gitcomp_nl "$(__git_tags)"
2786 __gitcomp_nl "$(__git_tags)"
2797 --list --delete --verify --annotate --message --file
2798 --sign --cleanup --local-user --force --column --sort
2799 --contains --points-at
2812 local subcommands="add list lock prune unlock"
2813 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2814 if [ -z "$subcommand" ]; then
2815 __gitcomp "$subcommands"
2817 case "$subcommand,$cur" in
2819 __gitcomp "--detach"
2822 __gitcomp "--porcelain"
2825 __gitcomp "--reason"
2828 __gitcomp "--dry-run --expire --verbose"
2838 local i c=1 command __git_dir __git_repo_path
2839 local __git_C_args C_args_count=0
2841 while [ $c -lt $cword ]; do
2844 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2845 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2846 --bare) __git_dir="." ;;
2847 --help) command="help"; break ;;
2848 -c|--work-tree|--namespace) ((c++)) ;;
2849 -C) __git_C_args[C_args_count++]=-C
2851 __git_C_args[C_args_count++]="${words[c]}"
2854 *) command="$i"; break ;;
2859 if [ -z "$command" ]; then
2861 --git-dir|-C|--work-tree)
2862 # these need a path argument, let's fall back to
2863 # Bash filename completion
2867 # we don't support completing these options' arguments
2885 --no-replace-objects
2889 *) __git_compute_porcelain_commands
2890 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2895 local completion_func="_git_${command//-/_}"
2896 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
2898 local expansion=$(__git_aliased_command "$command")
2899 if [ -n "$expansion" ]; then
2901 completion_func="_git_${expansion//-/_}"
2902 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
2908 __git_has_doubledash && return
2910 local __git_repo_path
2911 __git_find_repo_path
2914 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2920 $__git_log_common_options
2921 $__git_log_gitk_options
2927 __git_complete_revlist
2930 if [[ -n ${ZSH_VERSION-} ]]; then
2931 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2933 autoload -U +X compinit && compinit
2939 local cur_="${3-$cur}"
2945 local c IFS=$' \t\n'
2953 array[${#array[@]}+1]="$c"
2956 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2967 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2976 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2981 local _ret=1 cur cword prev
2982 cur=${words[CURRENT]}
2983 prev=${words[CURRENT-1]}
2985 emulate ksh -c __${service}_main
2986 let _ret && _default && _ret=0
2990 compdef _git git gitk
2996 local cur words cword prev
2997 _get_comp_words_by_ref -n =: cur words cword prev
3001 # Setup completion for certain functions defined above by setting common
3002 # variables and workarounds.
3003 # This is NOT a public function; use at your own risk.
3006 local wrapper="__git_wrap${2}"
3007 eval "$wrapper () { __git_func_wrap $2 ; }"
3008 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3009 || complete -o default -o nospace -F $wrapper $1
3012 # wrapper for backwards compatibility
3015 __git_wrap__git_main
3018 # wrapper for backwards compatibility
3021 __git_wrap__gitk_main
3024 __git_complete git __git_main
3025 __git_complete gitk __gitk_main
3027 # The following are necessary only for Cygwin, and only are needed
3028 # when the user has tab-completed the executable name and consequently
3029 # included the '.exe' suffix.
3031 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3032 __git_complete git.exe __git_main