1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 # Compatible with bash 3.2.57.
34 # You can set the following environment variables to influence the behavior of
35 # the completion routines:
37 # GIT_COMPLETION_CHECKOUT_NO_GUESS
39 # When set to "1", do not include "DWIM" suggestions in git-checkout
40 # completion (e.g., completing "foo" when "origin/foo" exists).
42 case "$COMP_WORDBREAKS" in
44 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
47 # Discovers the path to the git repository taking any '--git-dir=<path>' and
48 # '-C <path>' options into account and stores it in the $__git_repo_path
50 __git_find_repo_path ()
52 if [ -n "$__git_repo_path" ]; then
53 # we already know where it is
57 if [ -n "${__git_C_args-}" ]; then
58 __git_repo_path="$(git "${__git_C_args[@]}" \
59 ${__git_dir:+--git-dir="$__git_dir"} \
60 rev-parse --absolute-git-dir 2>/dev/null)"
61 elif [ -n "${__git_dir-}" ]; then
62 test -d "$__git_dir" &&
63 __git_repo_path="$__git_dir"
64 elif [ -n "${GIT_DIR-}" ]; then
65 test -d "${GIT_DIR-}" &&
66 __git_repo_path="$GIT_DIR"
67 elif [ -d .git ]; then
70 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
74 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
75 # __gitdir accepts 0 or 1 arguments (i.e., location)
76 # returns location of .git repo
79 if [ -z "${1-}" ]; then
80 __git_find_repo_path || return 1
81 echo "$__git_repo_path"
82 elif [ -d "$1/.git" ]; then
89 # Runs git with all the options given as argument, respecting any
90 # '--git-dir=<path>' and '-C <path>' options present on the command line
93 git ${__git_C_args:+"${__git_C_args[@]}"} \
94 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
97 # The following function is based on code from:
99 # bash_completion - programmable completion functions for bash 3.2+
101 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
102 # © 2009-2010, Bash Completion Maintainers
103 # <bash-completion-devel@lists.alioth.debian.org>
105 # This program is free software; you can redistribute it and/or modify
106 # it under the terms of the GNU General Public License as published by
107 # the Free Software Foundation; either version 2, or (at your option)
110 # This program is distributed in the hope that it will be useful,
111 # but WITHOUT ANY WARRANTY; without even the implied warranty of
112 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113 # GNU General Public License for more details.
115 # You should have received a copy of the GNU General Public License
116 # along with this program; if not, see <http://www.gnu.org/licenses/>.
118 # The latest version of this software can be obtained here:
120 # http://bash-completion.alioth.debian.org/
124 # This function can be used to access a tokenized list of words
125 # on the command line:
127 # __git_reassemble_comp_words_by_ref '=:'
128 # if test "${words_[cword_-1]}" = -w
133 # The argument should be a collection of characters from the list of
134 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
137 # This is roughly equivalent to going back in time and setting
138 # COMP_WORDBREAKS to exclude those characters. The intent is to
139 # make option types like --date=<type> and <rev>:<path> easy to
140 # recognize by treating each shell word as a single token.
142 # It is best not to set COMP_WORDBREAKS directly because the value is
143 # shared with other completion scripts. By the time the completion
144 # function gets called, COMP_WORDS has already been populated so local
145 # changes to COMP_WORDBREAKS have no effect.
147 # Output: words_, cword_, cur_.
149 __git_reassemble_comp_words_by_ref()
151 local exclude i j first
152 # Which word separators to exclude?
153 exclude="${1//[^$COMP_WORDBREAKS]}"
155 if [ -z "$exclude" ]; then
156 words_=("${COMP_WORDS[@]}")
159 # List of word completion separators has shrunk;
160 # re-assemble words to complete.
161 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
162 # Append each nonempty word consisting of just
163 # word separator characters to the current word.
167 [ -n "${COMP_WORDS[$i]}" ] &&
168 # word consists of excluded word separators
169 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
171 # Attach to the previous token,
172 # unless the previous token is the command name.
173 if [ $j -ge 2 ] && [ -n "$first" ]; then
177 words_[$j]=${words_[j]}${COMP_WORDS[i]}
178 if [ $i = $COMP_CWORD ]; then
181 if (($i < ${#COMP_WORDS[@]} - 1)); then
188 words_[$j]=${words_[j]}${COMP_WORDS[i]}
189 if [ $i = $COMP_CWORD ]; then
195 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
196 _get_comp_words_by_ref ()
198 local exclude cur_ words_ cword_
199 if [ "$1" = "-n" ]; then
203 __git_reassemble_comp_words_by_ref "$exclude"
204 cur_=${words_[cword_]}
205 while [ $# -gt 0 ]; do
211 prev=${words_[$cword_-1]}
214 words=("${words_[@]}")
225 # Fills the COMPREPLY array with prefiltered words without any additional
227 # Callers must take care of providing only words that match the current word
228 # to be completed and adding any prefix and/or suffix (trailing space!), if
230 # 1: List of newline-separated matching completion words, complete with
241 local x i=${#COMPREPLY[@]}
243 if [[ "$x" == "$3"* ]]; then
244 COMPREPLY[i++]="$2$x$4"
255 # Generates completion reply, appending a space to possible completion words,
257 # It accepts 1 to 4 arguments:
258 # 1: List of possible completion words.
259 # 2: A prefix to be added to each possible completion word (optional).
260 # 3: Generate possible completion matches for this word (optional).
261 # 4: A suffix to be appended to each possible completion word (optional).
264 local cur_="${3-$cur}"
270 local c i=0 IFS=$' \t\n'
273 if [[ $c == "$cur_"* ]]; then
278 COMPREPLY[i++]="${2-}$c"
285 # Clear the variables caching builtins' options when (re-)sourcing
286 # the completion script.
287 unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
289 # This function is equivalent to
291 # __gitcomp "$(git xxx --git-completion-helper) ..."
293 # except that the output is cached. Accept 1-3 arguments:
294 # 1: the git command to execute, this is also the cache key
295 # 2: extra options to be added on top (e.g. negative forms)
296 # 3: options to be excluded
299 # spaces must be replaced with underscore for multi-word
300 # commands, e.g. "git remote add" becomes remote_add.
305 local var=__gitcomp_builtin_"${cmd/-/_}"
307 eval "options=\$$var"
309 if [ -z "$options" ]; then
310 # leading and trailing spaces are significant to make
311 # option removal work correctly.
312 options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
314 options="${options/ $i / }"
316 eval "$var=\"$options\""
322 # Variation of __gitcomp_nl () that appends to the existing list of
323 # completion candidates, COMPREPLY.
324 __gitcomp_nl_append ()
327 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
330 # Generates completion reply from newline-separated possible completion words
331 # by appending a space to all of them.
332 # It accepts 1 to 4 arguments:
333 # 1: List of possible completion words, separated by a single newline.
334 # 2: A prefix to be added to each possible completion word (optional).
335 # 3: Generate possible completion matches for this word (optional).
336 # 4: A suffix to be appended to each possible completion word instead of
337 # the default space (optional). If specified but empty, nothing is
342 __gitcomp_nl_append "$@"
345 # Generates completion reply with compgen from newline-separated possible
346 # completion filenames.
347 # It accepts 1 to 3 arguments:
348 # 1: List of possible completion filenames, separated by a single newline.
349 # 2: A directory prefix to be added to each possible completion filename
351 # 3: Generate possible completion matches for this word (optional).
356 # XXX does not work when the directory prefix contains a tilde,
357 # since tilde expansion is not applied.
358 # This means that COMPREPLY will be empty and Bash default
359 # completion will be used.
360 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
362 # use a hack to enable file mode in bash < 4
363 compopt -o filenames +o nospace 2>/dev/null ||
364 compgen -f /non-existing-dir/ > /dev/null
367 # Execute 'git ls-files', unless the --committable option is specified, in
368 # which case it runs 'git diff-index' to find out the files that can be
369 # committed. It return paths relative to the directory specified in the first
370 # argument, and using the options specified in the second argument.
371 __git_ls_files_helper ()
373 if [ "$2" == "--committable" ]; then
374 __git -C "$1" diff-index --name-only --relative HEAD
376 # NOTE: $2 is not quoted in order to support multiple options
377 __git -C "$1" ls-files --exclude-standard $2
382 # __git_index_files accepts 1 or 2 arguments:
383 # 1: Options to pass to ls-files (required).
384 # 2: A directory path (optional).
385 # If provided, only files within the specified directory are listed.
386 # Sub directories are never recursed. Path must have a trailing
390 local root="${2-.}" file
392 __git_ls_files_helper "$root" "$1" |
393 while read -r file; do
395 ?*/*) echo "${file%%/*}" ;;
401 # Lists branches from the local repository.
402 # 1: A prefix to be added to each listed branch (optional).
403 # 2: List only branches matching this word (optional; list all branches if
405 # 3: A suffix to be appended to each listed branch (optional).
408 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
410 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
411 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
414 # Lists tags from the local repository.
415 # Accepts the same positional parameters as __git_heads() above.
418 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
420 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
421 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
424 # Lists refs from the local (by default) or from a remote repository.
425 # It accepts 0, 1 or 2 arguments:
426 # 1: The remote to list refs from (optional; ignored, if set but empty).
427 # Can be the name of a configured remote, a path, or a URL.
428 # 2: In addition to local refs, list unique branches from refs/remotes/ for
429 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
430 # 3: A prefix to be added to each listed ref (optional).
431 # 4: List only refs matching this word (optional; list all refs if unset or
433 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
436 # Use __git_complete_refs() instead.
439 local i hash dir track="${2-}"
440 local list_refs_from=path remote="${1-}"
442 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
444 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
447 dir="$__git_repo_path"
449 if [ -z "$remote" ]; then
450 if [ -z "$dir" ]; then
454 if __git_is_configured_remote "$remote"; then
455 # configured remote takes precedence over a
456 # local directory with the same name
457 list_refs_from=remote
458 elif [ -d "$remote/.git" ]; then
460 elif [ -d "$remote" ]; then
467 if [ "$list_refs_from" = path ]; then
468 if [[ "$cur_" == ^* ]]; then
477 refs=("$match*" "$match*/**")
481 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
484 if [ -e "$dir/$i" ]; then
490 format="refname:strip=2"
491 refs=("refs/tags/$match*" "refs/tags/$match*/**"
492 "refs/heads/$match*" "refs/heads/$match*/**"
493 "refs/remotes/$match*" "refs/remotes/$match*/**")
496 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
498 if [ -n "$track" ]; then
499 # employ the heuristic used by git checkout
500 # Try to find a remote branch that matches the completion word
501 # but only output if the branch name is unique
502 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
503 --sort="refname:strip=3" \
504 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
511 __git ls-remote "$remote" "$match*" | \
512 while read -r hash i; do
515 *) echo "$pfx$i$sfx" ;;
520 if [ "$list_refs_from" = remote ]; then
522 $match*) echo "${pfx}HEAD$sfx" ;;
524 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
525 "refs/remotes/$remote/$match*" \
526 "refs/remotes/$remote/$match*/**"
530 $match*) query_symref="HEAD" ;;
532 __git ls-remote "$remote" $query_symref \
533 "refs/tags/$match*" "refs/heads/$match*" \
534 "refs/remotes/$match*" |
535 while read -r hash i; do
538 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
539 *) echo "$pfx$i$sfx" ;; # symbolic refs
547 # Completes refs, short and long, local and remote, symbolic and pseudo.
549 # Usage: __git_complete_refs [<option>]...
550 # --remote=<remote>: The remote to list refs from, can be the name of a
551 # configured remote, a path, or a URL.
552 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
553 # --pfx=<prefix>: A prefix to be added to each ref.
554 # --cur=<word>: The current ref to be completed. Defaults to the current
555 # word to be completed.
556 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
558 __git_complete_refs ()
560 local remote track pfx cur_="$cur" sfx=" "
562 while test $# != 0; do
564 --remote=*) remote="${1##--remote=}" ;;
565 --track) track="yes" ;;
566 --pfx=*) pfx="${1##--pfx=}" ;;
567 --cur=*) cur_="${1##--cur=}" ;;
568 --sfx=*) sfx="${1##--sfx=}" ;;
574 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
577 # __git_refs2 requires 1 argument (to pass to __git_refs)
578 # Deprecated: use __git_complete_fetch_refspecs() instead.
582 for i in $(__git_refs "$1"); do
587 # Completes refspecs for fetching from a remote repository.
588 # 1: The remote repository.
589 # 2: A prefix to be added to each listed refspec (optional).
590 # 3: The ref to be completed as a refspec instead of the current word to be
591 # completed (optional)
592 # 4: A suffix to be appended to each listed refspec instead of the default
594 __git_complete_fetch_refspecs ()
596 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
599 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
605 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
606 __git_refs_remotes ()
609 __git ls-remote "$1" 'refs/heads/*' | \
610 while read -r hash i; do
611 echo "$i:refs/remotes/$1/${i#refs/heads/}"
618 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
622 # Returns true if $1 matches the name of a configured remote, false otherwise.
623 __git_is_configured_remote ()
626 for remote in $(__git_remotes); do
627 if [ "$remote" = "$1" ]; then
634 __git_list_merge_strategies ()
636 LANG=C LC_ALL=C git merge -s help 2>&1 |
637 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
646 __git_merge_strategies=
647 # 'git merge -s help' (and thus detection of the merge strategy
648 # list) fails, unfortunately, if run outside of any git working
649 # tree. __git_merge_strategies is set to the empty string in
650 # that case, and the detection will be repeated the next time it
652 __git_compute_merge_strategies ()
654 test -n "$__git_merge_strategies" ||
655 __git_merge_strategies=$(__git_list_merge_strategies)
658 __git_complete_revlist_file ()
660 local pfx ls ref cur_="$cur"
680 case "$COMP_WORDBREAKS" in
682 *) pfx="$ref:$pfx" ;;
685 __gitcomp_nl "$(__git ls-tree "$ls" \
686 | sed '/^100... blob /{
702 pfx="${cur_%...*}..."
704 __git_complete_refs --pfx="$pfx" --cur="$cur_"
709 __git_complete_refs --pfx="$pfx" --cur="$cur_"
718 # __git_complete_index_file requires 1 argument:
719 # 1: the options to pass to ls-file
721 # The exception is --committable, which finds the files appropriate commit.
722 __git_complete_index_file ()
724 local pfx="" cur_="$cur"
734 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
737 __git_complete_file ()
739 __git_complete_revlist_file
742 __git_complete_revlist ()
744 __git_complete_revlist_file
747 __git_complete_remote_or_refspec ()
749 local cur_="$cur" cmd="${words[1]}"
750 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
751 if [ "$cmd" = "remote" ]; then
754 while [ $c -lt $cword ]; do
757 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
758 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
761 push) no_complete_refspec=1 ;;
769 *) remote="$i"; break ;;
773 if [ -z "$remote" ]; then
774 __gitcomp_nl "$(__git_remotes)"
777 if [ $no_complete_refspec = 1 ]; then
780 [ "$remote" = "." ] && remote=
783 case "$COMP_WORDBREAKS" in
785 *) pfx="${cur_%%:*}:" ;;
797 if [ $lhs = 1 ]; then
798 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
800 __git_complete_refs --pfx="$pfx" --cur="$cur_"
804 if [ $lhs = 1 ]; then
805 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
807 __git_complete_refs --pfx="$pfx" --cur="$cur_"
811 if [ $lhs = 1 ]; then
812 __git_complete_refs --pfx="$pfx" --cur="$cur_"
814 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
820 __git_complete_strategy ()
822 __git_compute_merge_strategies
825 __gitcomp "$__git_merge_strategies"
830 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
838 __git_compute_all_commands ()
840 test -n "$__git_all_commands" ||
841 __git_all_commands=$(git --list-cmds=main,others,alias,nohelpers)
844 # Lists all set config variables starting with the given section prefix,
845 # with the prefix removed.
846 __git_get_config_variables ()
848 local section="$1" i IFS=$'\n'
849 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
850 echo "${i#$section.}"
854 __git_pretty_aliases ()
856 __git_get_config_variables "pretty"
859 # __git_aliased_command requires 1 argument
860 __git_aliased_command ()
862 local word cmdline=$(__git config --get "alias.$1")
863 for word in $cmdline; do
869 \!*) : shell command alias ;;
871 *=*) : setting env ;;
873 \(\)) : skip parens of shell function definition ;;
874 {) : skip start of shell helper function ;;
875 :) : skip null command ;;
876 \'*) : skip opening quote after sh -c ;;
884 # __git_find_on_cmdline requires 1 argument
885 __git_find_on_cmdline ()
887 local word subcommand c=1
888 while [ $c -lt $cword ]; do
890 for subcommand in $1; do
891 if [ "$subcommand" = "$word" ]; then
900 # Echo the value of an option set on the command line or config
902 # $1: short option name
903 # $2: long option name including =
904 # $3: list of possible values
905 # $4: config string (optional)
908 # result="$(__git_get_option_value "-d" "--do-something=" \
909 # "yes no" "core.doSomething")"
911 # result is then either empty (no option set) or "yes" or "no"
913 # __git_get_option_value requires 3 arguments
914 __git_get_option_value ()
916 local c short_opt long_opt val
917 local result= values config_key word
925 while [ $c -ge 0 ]; do
927 for val in $values; do
928 if [ "$short_opt$val" = "$word" ] ||
929 [ "$long_opt$val" = "$word" ]; then
937 if [ -n "$config_key" ] && [ -z "$result" ]; then
938 result="$(__git config "$config_key")"
944 __git_has_doubledash ()
947 while [ $c -lt $cword ]; do
948 if [ "--" = "${words[c]}" ]; then
956 # Try to count non option arguments passed on the command line for the
957 # specified git command.
958 # When options are used, it is necessary to use the special -- option to
959 # tell the implementation were non option arguments begin.
960 # XXX this can not be improved, since options can appear everywhere, as
964 # __git_count_arguments requires 1 argument: the git command executed.
965 __git_count_arguments ()
969 # Skip "git" (first argument)
970 for ((i=1; i < ${#words[@]}; i++)); do
975 # Good; we can assume that the following are only non
980 # Skip the specified git command and discard git
993 __git_whitespacelist="nowarn warn error error-all fix"
994 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
999 if [ -d "$__git_repo_path"/rebase-apply ]; then
1000 __gitcomp "$__git_am_inprogress_options"
1005 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1009 __gitcomp_builtin am "--no-utf8" \
1010 "$__git_am_inprogress_options"
1019 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1023 __gitcomp_builtin apply
1032 __gitcomp_builtin add
1036 local complete_opt="--others --modified --directory --no-empty-directory"
1037 if test -n "$(__git_find_on_cmdline "-u --update")"
1039 complete_opt="--modified"
1041 __git_complete_index_file "$complete_opt"
1048 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1052 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1057 --format= --list --verbose
1058 --prefix= --remote= --exec= --output
1068 __git_has_doubledash && return
1070 local subcommands="start bad good skip reset visualize replay log run"
1071 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1072 if [ -z "$subcommand" ]; then
1073 __git_find_repo_path
1074 if [ -f "$__git_repo_path"/BISECT_START ]; then
1075 __gitcomp "$subcommands"
1077 __gitcomp "replay start"
1082 case "$subcommand" in
1083 bad|good|reset|skip|start)
1093 local i c=1 only_local_ref="n" has_r="n"
1095 while [ $c -lt $cword ]; do
1098 -d|--delete|-m|--move) only_local_ref="y" ;;
1099 -r|--remotes) has_r="y" ;;
1105 --set-upstream-to=*)
1106 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1109 __gitcomp_builtin branch "--no-color --no-abbrev
1110 --no-track --no-column
1114 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1115 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1125 local cmd="${words[2]}"
1128 __gitcomp "create list-heads verify unbundle"
1131 # looking for a file
1136 __git_complete_revlist
1145 __git_has_doubledash && return
1149 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1152 __gitcomp_builtin checkout "--no-track --no-recurse-submodules"
1155 # check if --track, --no-track, or --no-guess was specified
1156 # if so, disable DWIM mode
1157 local flags="--track --no-track --no-guess" track_opt="--track"
1158 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1159 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1162 __git_complete_refs $track_opt
1171 __gitcomp_builtin cherry
1178 __git_cherry_pick_inprogress_options="--continue --quit --abort"
1182 __git_find_repo_path
1183 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1184 __gitcomp "$__git_cherry_pick_inprogress_options"
1189 __gitcomp_builtin cherry-pick "" \
1190 "$__git_cherry_pick_inprogress_options"
1202 __gitcomp_builtin clean
1207 # XXX should we check for -x option ?
1208 __git_complete_index_file "--others --directory"
1215 __gitcomp_builtin clone "--no-single-branch"
1221 __git_untracked_file_modes="all no normal"
1234 __gitcomp "default scissors strip verbatim whitespace
1235 " "" "${cur##--cleanup=}"
1238 --reuse-message=*|--reedit-message=*|\
1239 --fixup=*|--squash=*)
1240 __git_complete_refs --cur="${cur#*=}"
1243 --untracked-files=*)
1244 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1248 __gitcomp_builtin commit "--no-edit --verify"
1252 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1253 __git_complete_index_file "--committable"
1255 # This is the first commit
1256 __git_complete_index_file "--cached"
1264 __gitcomp_builtin describe
1270 __git_diff_algorithms="myers minimal patience histogram"
1272 __git_diff_submodule_formats="diff log short"
1274 __git_diff_common_options="--stat --numstat --shortstat --summary
1275 --patch-with-stat --name-only --name-status --color
1276 --no-color --color-words --no-renames --check
1277 --full-index --binary --abbrev --diff-filter=
1278 --find-copies-harder --ignore-cr-at-eol
1279 --text --ignore-space-at-eol --ignore-space-change
1280 --ignore-all-space --ignore-blank-lines --exit-code
1281 --quiet --ext-diff --no-ext-diff
1282 --no-prefix --src-prefix= --dst-prefix=
1283 --inter-hunk-context=
1284 --patience --histogram --minimal
1285 --raw --word-diff --word-diff-regex=
1286 --dirstat --dirstat= --dirstat-by-file
1287 --dirstat-by-file= --cumulative
1289 --submodule --submodule= --ignore-submodules
1294 __git_has_doubledash && return
1298 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1302 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1306 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1307 --base --ours --theirs --no-index
1308 $__git_diff_common_options
1313 __git_complete_revlist_file
1316 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1317 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1322 __git_has_doubledash && return
1326 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1330 __gitcomp_builtin difftool "$__git_diff_common_options
1331 --base --cached --ours --theirs
1332 --pickaxe-all --pickaxe-regex
1338 __git_complete_revlist_file
1341 __git_fetch_recurse_submodules="yes on-demand no"
1346 --recurse-submodules=*)
1347 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1351 __gitcomp_builtin fetch "--no-tags"
1355 __git_complete_remote_or_refspec
1358 __git_format_patch_options="
1359 --stdout --attach --no-attach --thread --thread= --no-thread
1360 --numbered --start-number --numbered-files --keep-subject --signoff
1361 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1362 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1363 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1364 --output-directory --reroll-count --to= --quiet --notes
1367 _git_format_patch ()
1373 " "" "${cur##--thread=}"
1377 __gitcomp "$__git_format_patch_options"
1381 __git_complete_revlist
1388 __gitcomp_builtin fsck "--no-reflogs"
1399 # Lists matching symbol names from a tag (as in ctags) file.
1400 # 1: List symbol names matching this word.
1401 # 2: The tag file to list symbol names from.
1402 # 3: A prefix to be added to each listed symbol name (optional).
1403 # 4: A suffix to be appended to each listed symbol name (optional).
1404 __git_match_ctag () {
1405 awk -v pfx="${3-}" -v sfx="${4-}" "
1406 /^${1//\//\\/}/ { print pfx \$1 sfx }
1410 # Complete symbol names from a tag file.
1411 # Usage: __git_complete_symbol [<option>]...
1412 # --tags=<file>: The tag file to list symbol names from instead of the
1414 # --pfx=<prefix>: A prefix to be added to each symbol name.
1415 # --cur=<word>: The current symbol name to be completed. Defaults to
1416 # the current word to be completed.
1417 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1418 # of the default space.
1419 __git_complete_symbol () {
1420 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1422 while test $# != 0; do
1424 --tags=*) tags="${1##--tags=}" ;;
1425 --pfx=*) pfx="${1##--pfx=}" ;;
1426 --cur=*) cur_="${1##--cur=}" ;;
1427 --sfx=*) sfx="${1##--sfx=}" ;;
1433 if test -r "$tags"; then
1434 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1440 __git_has_doubledash && return
1444 __gitcomp_builtin grep
1449 case "$cword,$prev" in
1451 __git_complete_symbol && return
1462 __gitcomp_builtin help
1466 if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
1468 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(git --list-cmds=alias,list-guide) gitk"
1470 __gitcomp "$(git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1479 false true umask group all world everybody
1480 " "" "${cur##--shared=}"
1484 __gitcomp_builtin init
1494 __gitcomp_builtin ls-files "--no-empty-directory"
1499 # XXX ignore options like --modified and always suggest all cached
1501 __git_complete_index_file "--cached"
1508 __gitcomp_builtin ls-remote
1512 __gitcomp_nl "$(__git_remotes)"
1519 __gitcomp_builtin ls-tree
1527 # Options that go well for log, shortlog and gitk
1528 __git_log_common_options="
1530 --branches --tags --remotes
1531 --first-parent --merges --no-merges
1533 --max-age= --since= --after=
1534 --min-age= --until= --before=
1535 --min-parents= --max-parents=
1536 --no-min-parents --no-max-parents
1538 # Options that go well for log and gitk (not shortlog)
1539 __git_log_gitk_options="
1540 --dense --sparse --full-history
1541 --simplify-merges --simplify-by-decoration
1542 --left-right --notes --no-notes
1544 # Options that go well for log and shortlog (not gitk)
1545 __git_log_shortlog_options="
1546 --author= --committer= --grep=
1547 --all-match --invert-grep
1550 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1551 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1555 __git_has_doubledash && return
1556 __git_find_repo_path
1559 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1562 case "$prev,$cur" in
1564 return # fall back to Bash filename completion
1567 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1571 __git_complete_symbol
1576 --pretty=*|--format=*)
1577 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1582 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1586 __gitcomp "full short no" "" "${cur##--decorate=}"
1590 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1594 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1599 $__git_log_common_options
1600 $__git_log_shortlog_options
1601 $__git_log_gitk_options
1602 --root --topo-order --date-order --reverse
1603 --follow --full-diff
1604 --abbrev-commit --abbrev=
1605 --relative-date --date=
1606 --pretty= --format= --oneline
1611 --decorate --decorate=
1613 --parents --children
1615 $__git_diff_common_options
1616 --pickaxe-all --pickaxe-regex
1621 return # fall back to Bash filename completion
1624 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1628 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1632 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1636 __git_complete_revlist
1641 __git_complete_strategy && return
1645 __gitcomp_builtin merge "--no-rerere-autoupdate
1646 --no-commit --no-edit --no-ff
1647 --no-log --no-progress
1648 --no-squash --no-stat
1649 --no-verify-signatures
1660 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1664 __gitcomp "--tool= --prompt --no-prompt"
1674 __gitcomp_builtin merge-base
1685 __gitcomp_builtin mv
1690 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1691 # We need to show both cached and untracked files (including
1692 # empty directories) since this may not be the last argument.
1693 __git_complete_index_file "--cached --others --directory"
1695 __git_complete_index_file "--cached"
1701 local subcommands='add append copy edit get-ref list merge prune remove show'
1702 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1704 case "$subcommand,$cur" in
1706 __gitcomp_builtin notes
1714 __gitcomp "$subcommands --ref"
1718 *,--reuse-message=*|*,--reedit-message=*)
1719 __git_complete_refs --cur="${cur#*=}"
1722 __gitcomp_builtin notes_$subcommand
1725 # this command does not take a ref, do not complete it
1741 __git_complete_strategy && return
1744 --recurse-submodules=*)
1745 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1749 __gitcomp_builtin pull "--no-autostash --no-commit --no-edit
1750 --no-ff --no-log --no-progress --no-rebase
1751 --no-squash --no-stat --no-tags
1752 --no-verify-signatures"
1757 __git_complete_remote_or_refspec
1760 __git_push_recurse_submodules="check on-demand only"
1762 __git_complete_force_with_lease ()
1770 __git_complete_refs --cur="${cur_#*:}"
1773 __git_complete_refs --cur="$cur_"
1782 __gitcomp_nl "$(__git_remotes)"
1785 --recurse-submodules)
1786 __gitcomp "$__git_push_recurse_submodules"
1792 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1795 --recurse-submodules=*)
1796 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1799 --force-with-lease=*)
1800 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1804 __gitcomp_builtin push
1808 __git_complete_remote_or_refspec
1813 __git_find_repo_path
1814 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1815 __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
1817 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1818 [ -d "$__git_repo_path"/rebase-merge ]; then
1819 __gitcomp "--continue --skip --abort --quit --show-current-patch"
1822 __git_complete_strategy && return
1825 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1830 --onto --merge --strategy --interactive
1831 --preserve-merges --stat --no-stat
1832 --committer-date-is-author-date --ignore-date
1833 --ignore-whitespace --whitespace=
1834 --autosquash --no-autosquash
1835 --fork-point --no-fork-point
1836 --autostash --no-autostash
1837 --verify --no-verify
1838 --keep-empty --root --force-rebase --no-ff
1850 local subcommands="show delete expire"
1851 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1853 if [ -z "$subcommand" ]; then
1854 __gitcomp "$subcommands"
1860 __git_send_email_confirm_options="always never auto cc compose"
1861 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1866 --to|--cc|--bcc|--from)
1867 __gitcomp "$(__git send-email --dump-aliases)"
1875 $__git_send_email_confirm_options
1876 " "" "${cur##--confirm=}"
1881 $__git_send_email_suppresscc_options
1882 " "" "${cur##--suppress-cc=}"
1886 --smtp-encryption=*)
1887 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1893 " "" "${cur##--thread=}"
1896 --to=*|--cc=*|--bcc=*|--from=*)
1897 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
1901 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1902 --compose --confirm= --dry-run --envelope-sender
1904 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1905 --no-suppress-from --no-thread --quiet --reply-to
1906 --signed-off-by-cc --smtp-pass --smtp-server
1907 --smtp-server-port --smtp-encryption= --smtp-user
1908 --subject --suppress-cc= --suppress-from --thread --to
1909 --validate --no-validate
1910 $__git_format_patch_options"
1914 __git_complete_revlist
1925 local untracked_state
1928 --ignore-submodules=*)
1929 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1932 --untracked-files=*)
1933 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1938 always never auto column row plain dense nodense
1939 " "" "${cur##--column=}"
1943 __gitcomp_builtin status "--no-column"
1948 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1949 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
1951 case "$untracked_state" in
1953 # --ignored option does not matter
1957 complete_opt="--cached --directory --no-empty-directory --others"
1959 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1960 complete_opt="$complete_opt --ignored --exclude=*"
1965 __git_complete_index_file "$complete_opt"
1968 __git_config_get_set_variables ()
1970 local prevword word config_file= c=$cword
1971 while [ $c -gt 1 ]; do
1974 --system|--global|--local|--file=*)
1979 config_file="$word $prevword"
1987 __git config $config_file --name-only --list
1993 branch.*.remote|branch.*.pushremote)
1994 __gitcomp_nl "$(__git_remotes)"
2002 __gitcomp "false true preserve interactive"
2006 __gitcomp_nl "$(__git_remotes)"
2010 local remote="${prev#remote.}"
2011 remote="${remote%.fetch}"
2012 if [ -z "$cur" ]; then
2013 __gitcomp_nl "refs/heads/" "" "" ""
2016 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2020 local remote="${prev#remote.}"
2021 remote="${remote%.push}"
2022 __gitcomp_nl "$(__git for-each-ref \
2023 --format='%(refname):%(refname)' refs/heads)"
2026 pull.twohead|pull.octopus)
2027 __git_compute_merge_strategies
2028 __gitcomp "$__git_merge_strategies"
2031 color.branch|color.diff|color.interactive|\
2032 color.showbranch|color.status|color.ui)
2033 __gitcomp "always never auto"
2037 __gitcomp "false true"
2042 normal black red green yellow blue magenta cyan white
2043 bold dim ul blink reverse
2048 __gitcomp "log short"
2052 __gitcomp "man info web html"
2056 __gitcomp "$__git_log_date_formats"
2059 sendemail.aliasesfiletype)
2060 __gitcomp "mutt mailrc pine elm gnus"
2064 __gitcomp "$__git_send_email_confirm_options"
2067 sendemail.suppresscc)
2068 __gitcomp "$__git_send_email_suppresscc_options"
2071 sendemail.transferencoding)
2072 __gitcomp "7bit 8bit quoted-printable base64"
2075 --get|--get-all|--unset|--unset-all)
2076 __gitcomp_nl "$(__git_config_get_set_variables)"
2085 __gitcomp_builtin config
2089 local pfx="${cur%.*}." cur_="${cur##*.}"
2090 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2094 local pfx="${cur%.*}." cur_="${cur#*.}"
2095 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2096 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2100 local pfx="${cur%.*}." cur_="${cur##*.}"
2102 argprompt cmd confirm needsfile noconsole norescan
2103 prompt revprompt revunmerged title
2108 local pfx="${cur%.*}." cur_="${cur##*.}"
2109 __gitcomp "cmd path" "$pfx" "$cur_"
2113 local pfx="${cur%.*}." cur_="${cur##*.}"
2114 __gitcomp "cmd path" "$pfx" "$cur_"
2118 local pfx="${cur%.*}." cur_="${cur##*.}"
2119 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2123 local pfx="${cur%.*}." cur_="${cur#*.}"
2124 __git_compute_all_commands
2125 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2129 local pfx="${cur%.*}." cur_="${cur##*.}"
2131 url proxy fetch push mirror skipDefaultUpdate
2132 receivepack uploadpack tagopt pushurl
2137 local pfx="${cur%.*}." cur_="${cur#*.}"
2138 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2139 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2143 local pfx="${cur%.*}." cur_="${cur##*.}"
2144 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2151 advice.commitBeforeMerge
2153 advice.implicitIdentity
2154 advice.pushAlreadyExists
2155 advice.pushFetchFirst
2156 advice.pushNeedsForce
2157 advice.pushNonFFCurrent
2158 advice.pushNonFFMatching
2159 advice.pushUpdateRejected
2160 advice.resolveConflict
2163 advice.statusUoption
2168 apply.ignorewhitespace
2170 branch.autosetupmerge
2171 branch.autosetuprebase
2175 color.branch.current
2180 color.decorate.branch
2181 color.decorate.remoteBranch
2182 color.decorate.stash
2192 color.diff.whitespace
2197 color.grep.linenumber
2200 color.grep.separator
2202 color.interactive.error
2203 color.interactive.header
2204 color.interactive.help
2205 color.interactive.prompt
2210 color.status.changed
2212 color.status.localBranch
2213 color.status.nobranch
2214 color.status.remoteBranch
2215 color.status.unmerged
2216 color.status.untracked
2217 color.status.updated
2229 core.bigFileThreshold
2234 core.deltaBaseCacheLimit
2239 core.fsyncobjectfiles
2245 core.logAllRefUpdates
2246 core.loosecompression
2249 core.packedGitWindowSize
2250 core.packedRefsTimeout
2252 core.precomposeUnicode
2253 core.preferSymlinkRefs
2258 core.repositoryFormatVersion
2260 core.sharedRepository
2267 core.warnAmbiguousRefs
2271 credential.useHttpPath
2273 credentialCache.ignoreSIGHUP
2274 diff.autorefreshindex
2276 diff.ignoreSubmodules
2283 diff.suppressBlankEmpty
2289 fetch.recurseSubmodules
2300 format.subjectprefix
2314 gc.reflogexpireunreachable
2317 gc.worktreePruneExpire
2319 gitcvs.commitmsgannotation
2320 gitcvs.dbTableNamePrefix
2331 gui.copyblamethreshold
2335 gui.matchtrackingbranch
2336 gui.newbranchtemplate
2337 gui.pruneduringfetch
2338 gui.spellingdictionary
2355 http.sslCertPasswordProtected
2360 i18n.logOutputEncoding
2366 imap.preformattedHTML
2376 interactive.singlekey
2392 mergetool.keepBackup
2393 mergetool.keepTemporaries
2398 notes.rewrite.rebase
2402 pack.deltaCacheLimit
2419 receive.denyCurrentBranch
2420 receive.denyDeleteCurrent
2422 receive.denyNonFastForwards
2425 receive.updateserverinfo
2428 repack.usedeltabaseoffset
2432 sendemail.aliasesfile
2433 sendemail.aliasfiletype
2437 sendemail.chainreplyto
2439 sendemail.envelopesender
2443 sendemail.signedoffbycc
2444 sendemail.smtpdomain
2445 sendemail.smtpencryption
2447 sendemail.smtpserver
2448 sendemail.smtpserveroption
2449 sendemail.smtpserverport
2451 sendemail.suppresscc
2452 sendemail.suppressfrom
2457 sendemail.smtpbatchsize
2458 sendemail.smtprelogindelay
2460 status.relativePaths
2461 status.showUntrackedFiles
2462 status.submodulesummary
2465 transfer.unpackLimit
2478 add rename remove set-head set-branches
2479 get-url set-url show prune update
2481 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2482 if [ -z "$subcommand" ]; then
2485 __gitcomp_builtin remote
2488 __gitcomp "$subcommands"
2494 case "$subcommand,$cur" in
2496 __gitcomp_builtin remote_add "--no-tags"
2501 __gitcomp_builtin remote_set-head
2504 __gitcomp_builtin remote_set-branches
2506 set-head,*|set-branches,*)
2507 __git_complete_remote_or_refspec
2510 __gitcomp_builtin remote_update
2513 __gitcomp "$(__git_get_config_variables "remotes")"
2516 __gitcomp_builtin remote_set-url
2519 __gitcomp_builtin remote_get-url
2522 __gitcomp_builtin remote_prune
2525 __gitcomp_nl "$(__git_remotes)"
2534 __gitcomp_builtin replace
2543 local subcommands="clear forget diff remaining status gc"
2544 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2545 if test -z "$subcommand"
2547 __gitcomp "$subcommands"
2554 __git_has_doubledash && return
2558 __gitcomp_builtin reset
2565 __git_revert_inprogress_options="--continue --quit --abort"
2569 __git_find_repo_path
2570 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2571 __gitcomp "$__git_revert_inprogress_options"
2576 __gitcomp_builtin revert "--no-edit" \
2577 "$__git_revert_inprogress_options"
2588 __gitcomp_builtin rm
2593 __git_complete_index_file "--cached"
2598 __git_has_doubledash && return
2603 $__git_log_common_options
2604 $__git_log_shortlog_options
2605 --numbered --summary --email
2610 __git_complete_revlist
2615 __git_has_doubledash && return
2618 --pretty=*|--format=*)
2619 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2624 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2628 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2632 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2634 $__git_diff_common_options
2639 __git_complete_revlist_file
2646 __gitcomp_builtin show-branch "--no-color"
2650 __git_complete_revlist
2655 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2656 local subcommands='push save list show apply clear drop pop create branch'
2657 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2658 if [ -z "$subcommand" ]; then
2661 __gitcomp "$save_opts"
2664 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2665 __gitcomp "$subcommands"
2670 case "$subcommand,$cur" in
2672 __gitcomp "$save_opts --message"
2675 __gitcomp "$save_opts"
2678 __gitcomp "--index --quiet"
2683 show,--*|branch,--*)
2686 if [ $cword -eq 3 ]; then
2689 __gitcomp_nl "$(__git stash list \
2690 | sed -n -e 's/:.*//p')"
2693 show,*|apply,*|drop,*|pop,*)
2694 __gitcomp_nl "$(__git stash list \
2695 | sed -n -e 's/:.*//p')"
2705 __git_has_doubledash && return
2707 local subcommands="add status init deinit update summary foreach sync"
2708 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2709 if [ -z "$subcommand" ]; then
2715 __gitcomp "$subcommands"
2721 case "$subcommand,$cur" in
2723 __gitcomp "--branch --force --name --reference --depth"
2726 __gitcomp "--cached --recursive"
2729 __gitcomp "--force --all"
2733 --init --remote --no-fetch
2734 --recommend-shallow --no-recommend-shallow
2735 --force --rebase --merge --reference --depth --recursive --jobs
2739 __gitcomp "--cached --files --summary-limit"
2741 foreach,--*|sync,--*)
2742 __gitcomp "--recursive"
2752 init fetch clone rebase dcommit log find-rev
2753 set-tree commit-diff info create-ignore propget
2754 proplist show-ignore show-externals branch tag blame
2755 migrate mkdirs reset gc
2757 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2758 if [ -z "$subcommand" ]; then
2759 __gitcomp "$subcommands"
2761 local remote_opts="--username= --config-dir= --no-auth-cache"
2763 --follow-parent --authors-file= --repack=
2764 --no-metadata --use-svm-props --use-svnsync-props
2765 --log-window-size= --no-checkout --quiet
2766 --repack-flags --use-log-author --localtime
2768 --ignore-paths= --include-paths= $remote_opts
2771 --template= --shared= --trunk= --tags=
2772 --branches= --stdlayout --minimize-url
2773 --no-metadata --use-svm-props --use-svnsync-props
2774 --rewrite-root= --prefix= $remote_opts
2777 --edit --rmdir --find-copies-harder --copy-similarity=
2780 case "$subcommand,$cur" in
2782 __gitcomp "--revision= --fetch-all $fc_opts"
2785 __gitcomp "--revision= $fc_opts $init_opts"
2788 __gitcomp "$init_opts"
2792 --merge --strategy= --verbose --dry-run
2793 --fetch-all --no-rebase --commit-url
2794 --revision --interactive $cmt_opts $fc_opts
2798 __gitcomp "--stdin $cmt_opts $fc_opts"
2800 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2801 show-externals,--*|mkdirs,--*)
2802 __gitcomp "--revision="
2806 --limit= --revision= --verbose --incremental
2807 --oneline --show-commit --non-recursive
2808 --authors-file= --color
2813 --merge --verbose --strategy= --local
2814 --fetch-all --dry-run $fc_opts
2818 __gitcomp "--message= --file= --revision= $cmt_opts"
2824 __gitcomp "--dry-run --message --tag"
2827 __gitcomp "--dry-run --message"
2830 __gitcomp "--git-format"
2834 --config-dir= --ignore-paths= --minimize
2835 --no-auth-cache --username=
2839 __gitcomp "--revision= --parent"
2850 while [ $c -lt $cword ]; do
2853 -d|--delete|-v|--verify)
2854 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2869 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2879 __gitcomp_builtin tag
2891 local subcommands="add list lock move prune remove unlock"
2892 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2893 if [ -z "$subcommand" ]; then
2894 __gitcomp "$subcommands"
2896 case "$subcommand,$cur" in
2898 __gitcomp_builtin worktree_add
2901 __gitcomp_builtin worktree_list
2904 __gitcomp_builtin worktree_lock
2907 __gitcomp_builtin worktree_prune
2918 __git_complete_common () {
2923 __gitcomp_builtin "$command"
2928 __git_cmds_with_parseopt_helper=
2929 __git_support_parseopt_helper () {
2930 test -n "$__git_cmds_with_parseopt_helper" ||
2931 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
2933 case " $__git_cmds_with_parseopt_helper " in
2943 __git_complete_command () {
2945 local completion_func="_git_${command//-/_}"
2946 if declare -f $completion_func >/dev/null 2>/dev/null; then
2949 elif __git_support_parseopt_helper "$command"; then
2950 __git_complete_common "$command"
2959 local i c=1 command __git_dir __git_repo_path
2960 local __git_C_args C_args_count=0
2962 while [ $c -lt $cword ]; do
2965 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2966 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2967 --bare) __git_dir="." ;;
2968 --help) command="help"; break ;;
2969 -c|--work-tree|--namespace) ((c++)) ;;
2970 -C) __git_C_args[C_args_count++]=-C
2972 __git_C_args[C_args_count++]="${words[c]}"
2975 *) command="$i"; break ;;
2980 if [ -z "$command" ]; then
2982 --git-dir|-C|--work-tree)
2983 # these need a path argument, let's fall back to
2984 # Bash filename completion
2988 # we don't support completing these options' arguments
3006 --no-replace-objects
3011 if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3013 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3015 __gitcomp "$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
3022 __git_complete_command "$command" && return
3024 local expansion=$(__git_aliased_command "$command")
3025 if [ -n "$expansion" ]; then
3027 __git_complete_command "$expansion"
3033 __git_has_doubledash && return
3035 local __git_repo_path
3036 __git_find_repo_path
3039 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3045 $__git_log_common_options
3046 $__git_log_gitk_options
3052 __git_complete_revlist
3055 if [[ -n ${ZSH_VERSION-} ]]; then
3056 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3058 autoload -U +X compinit && compinit
3064 local cur_="${3-$cur}"
3070 local c IFS=$' \t\n'
3078 array[${#array[@]}+1]="$c"
3081 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3092 compadd -Q -- ${=1} && _ret=0
3101 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3110 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3115 local _ret=1 cur cword prev
3116 cur=${words[CURRENT]}
3117 prev=${words[CURRENT-1]}
3119 emulate ksh -c __${service}_main
3120 let _ret && _default && _ret=0
3124 compdef _git git gitk
3130 local cur words cword prev
3131 _get_comp_words_by_ref -n =: cur words cword prev
3135 # Setup completion for certain functions defined above by setting common
3136 # variables and workarounds.
3137 # This is NOT a public function; use at your own risk.
3140 local wrapper="__git_wrap${2}"
3141 eval "$wrapper () { __git_func_wrap $2 ; }"
3142 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3143 || complete -o default -o nospace -F $wrapper $1
3146 # wrapper for backwards compatibility
3149 __git_wrap__git_main
3152 # wrapper for backwards compatibility
3155 __git_wrap__gitk_main
3158 __git_complete git __git_main
3159 __git_complete gitk __gitk_main
3161 # The following are necessary only for Cygwin, and only are needed
3162 # when the user has tab-completed the executable name and consequently
3163 # included the '.exe' suffix.
3165 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3166 __git_complete git.exe __git_main