completion: complete --no-relative
[git/debian.git] / contrib / completion / git-completion.bash
blobf4e773cb997fe875fcfb7e1c2a2a092738fde430
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 # If you have a command that is not part of git, but you would still
33 # like completion, you can use __git_complete:
35 # __git_complete gl git_log
37 # Or if it's a main command (i.e. git or gitk):
39 # __git_complete gk gitk
41 # Compatible with bash 3.2.57.
43 # You can set the following environment variables to influence the behavior of
44 # the completion routines:
46 # GIT_COMPLETION_CHECKOUT_NO_GUESS
48 # When set to "1", do not include "DWIM" suggestions in git-checkout
49 # and git-switch completion (e.g., completing "foo" when "origin/foo"
50 # exists).
52 # GIT_COMPLETION_SHOW_ALL_COMMANDS
54 # When set to "1" suggest all commands, including plumbing commands
55 # which are hidden by default (e.g. "cat-file" on "git ca<TAB>").
57 # GIT_COMPLETION_SHOW_ALL
59 # When set to "1" suggest all options, including options which are
60 # typically hidden (e.g. '--allow-empty' for 'git commit').
62 # GIT_COMPLETION_IGNORE_CASE
64 # When set, uses for-each-ref '--ignore-case' to find refs that match
65 # case insensitively, even on systems with case sensitive file systems
66 # (e.g., completing tag name "FOO" on "git checkout f<TAB>").
68 case "$COMP_WORDBREAKS" in
69 *:*) : great ;;
70 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
71 esac
73 # Discovers the path to the git repository taking any '--git-dir=<path>' and
74 # '-C <path>' options into account and stores it in the $__git_repo_path
75 # variable.
76 __git_find_repo_path ()
78 if [ -n "${__git_repo_path-}" ]; then
79 # we already know where it is
80 return
83 if [ -n "${__git_C_args-}" ]; then
84 __git_repo_path="$(git "${__git_C_args[@]}" \
85 ${__git_dir:+--git-dir="$__git_dir"} \
86 rev-parse --absolute-git-dir 2>/dev/null)"
87 elif [ -n "${__git_dir-}" ]; then
88 test -d "$__git_dir" &&
89 __git_repo_path="$__git_dir"
90 elif [ -n "${GIT_DIR-}" ]; then
91 test -d "$GIT_DIR" &&
92 __git_repo_path="$GIT_DIR"
93 elif [ -d .git ]; then
94 __git_repo_path=.git
95 else
96 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
100 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
101 # __gitdir accepts 0 or 1 arguments (i.e., location)
102 # returns location of .git repo
103 __gitdir ()
105 if [ -z "${1-}" ]; then
106 __git_find_repo_path || return 1
107 echo "$__git_repo_path"
108 elif [ -d "$1/.git" ]; then
109 echo "$1/.git"
110 else
111 echo "$1"
115 # Runs git with all the options given as argument, respecting any
116 # '--git-dir=<path>' and '-C <path>' options present on the command line
117 __git ()
119 git ${__git_C_args:+"${__git_C_args[@]}"} \
120 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
123 # Removes backslash escaping, single quotes and double quotes from a word,
124 # stores the result in the variable $dequoted_word.
125 # 1: The word to dequote.
126 __git_dequote ()
128 local rest="$1" len ch
130 dequoted_word=""
132 while test -n "$rest"; do
133 len=${#dequoted_word}
134 dequoted_word="$dequoted_word${rest%%[\\\'\"]*}"
135 rest="${rest:$((${#dequoted_word}-$len))}"
137 case "${rest:0:1}" in
139 ch="${rest:1:1}"
140 case "$ch" in
141 $'\n')
144 dequoted_word="$dequoted_word$ch"
146 esac
147 rest="${rest:2}"
150 rest="${rest:1}"
151 len=${#dequoted_word}
152 dequoted_word="$dequoted_word${rest%%\'*}"
153 rest="${rest:$((${#dequoted_word}-$len+1))}"
156 rest="${rest:1}"
157 while test -n "$rest" ; do
158 len=${#dequoted_word}
159 dequoted_word="$dequoted_word${rest%%[\\\"]*}"
160 rest="${rest:$((${#dequoted_word}-$len))}"
161 case "${rest:0:1}" in
163 ch="${rest:1:1}"
164 case "$ch" in
165 \"|\\|\$|\`)
166 dequoted_word="$dequoted_word$ch"
168 $'\n')
171 dequoted_word="$dequoted_word\\$ch"
173 esac
174 rest="${rest:2}"
177 rest="${rest:1}"
178 break
180 esac
181 done
183 esac
184 done
187 # The following function is based on code from:
189 # bash_completion - programmable completion functions for bash 3.2+
191 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
192 # © 2009-2010, Bash Completion Maintainers
193 # <bash-completion-devel@lists.alioth.debian.org>
195 # This program is free software; you can redistribute it and/or modify
196 # it under the terms of the GNU General Public License as published by
197 # the Free Software Foundation; either version 2, or (at your option)
198 # any later version.
200 # This program is distributed in the hope that it will be useful,
201 # but WITHOUT ANY WARRANTY; without even the implied warranty of
202 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
203 # GNU General Public License for more details.
205 # You should have received a copy of the GNU General Public License
206 # along with this program; if not, see <http://www.gnu.org/licenses/>.
208 # The latest version of this software can be obtained here:
210 # http://bash-completion.alioth.debian.org/
212 # RELEASE: 2.x
214 # This function can be used to access a tokenized list of words
215 # on the command line:
217 # __git_reassemble_comp_words_by_ref '=:'
218 # if test "${words_[cword_-1]}" = -w
219 # then
220 # ...
221 # fi
223 # The argument should be a collection of characters from the list of
224 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
225 # characters.
227 # This is roughly equivalent to going back in time and setting
228 # COMP_WORDBREAKS to exclude those characters. The intent is to
229 # make option types like --date=<type> and <rev>:<path> easy to
230 # recognize by treating each shell word as a single token.
232 # It is best not to set COMP_WORDBREAKS directly because the value is
233 # shared with other completion scripts. By the time the completion
234 # function gets called, COMP_WORDS has already been populated so local
235 # changes to COMP_WORDBREAKS have no effect.
237 # Output: words_, cword_, cur_.
239 __git_reassemble_comp_words_by_ref()
241 local exclude i j first
242 # Which word separators to exclude?
243 exclude="${1//[^$COMP_WORDBREAKS]}"
244 cword_=$COMP_CWORD
245 if [ -z "$exclude" ]; then
246 words_=("${COMP_WORDS[@]}")
247 return
249 # List of word completion separators has shrunk;
250 # re-assemble words to complete.
251 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
252 # Append each nonempty word consisting of just
253 # word separator characters to the current word.
254 first=t
255 while
256 [ $i -gt 0 ] &&
257 [ -n "${COMP_WORDS[$i]}" ] &&
258 # word consists of excluded word separators
259 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
261 # Attach to the previous token,
262 # unless the previous token is the command name.
263 if [ $j -ge 2 ] && [ -n "$first" ]; then
264 ((j--))
266 first=
267 words_[$j]=${words_[j]}${COMP_WORDS[i]}
268 if [ $i = $COMP_CWORD ]; then
269 cword_=$j
271 if (($i < ${#COMP_WORDS[@]} - 1)); then
272 ((i++))
273 else
274 # Done.
275 return
277 done
278 words_[$j]=${words_[j]}${COMP_WORDS[i]}
279 if [ $i = $COMP_CWORD ]; then
280 cword_=$j
282 done
285 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
286 _get_comp_words_by_ref ()
288 local exclude cur_ words_ cword_
289 if [ "$1" = "-n" ]; then
290 exclude=$2
291 shift 2
293 __git_reassemble_comp_words_by_ref "$exclude"
294 cur_=${words_[cword_]}
295 while [ $# -gt 0 ]; do
296 case "$1" in
297 cur)
298 cur=$cur_
300 prev)
301 prev=${words_[$cword_-1]}
303 words)
304 words=("${words_[@]}")
306 cword)
307 cword=$cword_
309 esac
310 shift
311 done
315 # Fills the COMPREPLY array with prefiltered words without any additional
316 # processing.
317 # Callers must take care of providing only words that match the current word
318 # to be completed and adding any prefix and/or suffix (trailing space!), if
319 # necessary.
320 # 1: List of newline-separated matching completion words, complete with
321 # prefix and suffix.
322 __gitcomp_direct ()
324 local IFS=$'\n'
326 COMPREPLY=($1)
329 # Similar to __gitcomp_direct, but appends to COMPREPLY instead.
330 # Callers must take care of providing only words that match the current word
331 # to be completed and adding any prefix and/or suffix (trailing space!), if
332 # necessary.
333 # 1: List of newline-separated matching completion words, complete with
334 # prefix and suffix.
335 __gitcomp_direct_append ()
337 local IFS=$'\n'
339 COMPREPLY+=($1)
342 __gitcompappend ()
344 local x i=${#COMPREPLY[@]}
345 for x in $1; do
346 if [[ "$x" == "$3"* ]]; then
347 COMPREPLY[i++]="$2$x$4"
349 done
352 __gitcompadd ()
354 COMPREPLY=()
355 __gitcompappend "$@"
358 # Generates completion reply, appending a space to possible completion words,
359 # if necessary.
360 # It accepts 1 to 4 arguments:
361 # 1: List of possible completion words.
362 # 2: A prefix to be added to each possible completion word (optional).
363 # 3: Generate possible completion matches for this word (optional).
364 # 4: A suffix to be appended to each possible completion word (optional).
365 __gitcomp ()
367 local cur_="${3-$cur}"
369 case "$cur_" in
372 --no-*)
373 local c i=0 IFS=$' \t\n'
374 for c in $1; do
375 if [[ $c == "--" ]]; then
376 continue
378 c="$c${4-}"
379 if [[ $c == "$cur_"* ]]; then
380 case $c in
381 --*=|*.) ;;
382 *) c="$c " ;;
383 esac
384 COMPREPLY[i++]="${2-}$c"
386 done
389 local c i=0 IFS=$' \t\n'
390 for c in $1; do
391 if [[ $c == "--" ]]; then
392 c="--no-...${4-}"
393 if [[ $c == "$cur_"* ]]; then
394 COMPREPLY[i++]="${2-}$c "
396 break
398 c="$c${4-}"
399 if [[ $c == "$cur_"* ]]; then
400 case $c in
401 *=|*.) ;;
402 *) c="$c " ;;
403 esac
404 COMPREPLY[i++]="${2-}$c"
406 done
408 esac
411 # Clear the variables caching builtins' options when (re-)sourcing
412 # the completion script.
413 if [[ -n ${ZSH_VERSION-} ]]; then
414 unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
415 else
416 unset $(compgen -v __gitcomp_builtin_)
419 # This function is equivalent to
421 # __gitcomp "$(git xxx --git-completion-helper) ..."
423 # except that the output is cached. Accept 1-3 arguments:
424 # 1: the git command to execute, this is also the cache key
425 # 2: extra options to be added on top (e.g. negative forms)
426 # 3: options to be excluded
427 __gitcomp_builtin ()
429 # spaces must be replaced with underscore for multi-word
430 # commands, e.g. "git remote add" becomes remote_add.
431 local cmd="$1"
432 local incl="${2-}"
433 local excl="${3-}"
435 local var=__gitcomp_builtin_"${cmd//-/_}"
436 local options
437 eval "options=\${$var-}"
439 if [ -z "$options" ]; then
440 local completion_helper
441 if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
442 completion_helper="--git-completion-helper-all"
443 else
444 completion_helper="--git-completion-helper"
446 # leading and trailing spaces are significant to make
447 # option removal work correctly.
448 options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
450 for i in $excl; do
451 options="${options/ $i / }"
452 done
453 eval "$var=\"$options\""
456 __gitcomp "$options"
459 # Variation of __gitcomp_nl () that appends to the existing list of
460 # completion candidates, COMPREPLY.
461 __gitcomp_nl_append ()
463 local IFS=$'\n'
464 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
467 # Generates completion reply from newline-separated possible completion words
468 # by appending a space to all of them.
469 # It accepts 1 to 4 arguments:
470 # 1: List of possible completion words, separated by a single newline.
471 # 2: A prefix to be added to each possible completion word (optional).
472 # 3: Generate possible completion matches for this word (optional).
473 # 4: A suffix to be appended to each possible completion word instead of
474 # the default space (optional). If specified but empty, nothing is
475 # appended.
476 __gitcomp_nl ()
478 COMPREPLY=()
479 __gitcomp_nl_append "$@"
482 # Fills the COMPREPLY array with prefiltered paths without any additional
483 # processing.
484 # Callers must take care of providing only paths that match the current path
485 # to be completed and adding any prefix path components, if necessary.
486 # 1: List of newline-separated matching paths, complete with all prefix
487 # path components.
488 __gitcomp_file_direct ()
490 local IFS=$'\n'
492 COMPREPLY=($1)
494 # use a hack to enable file mode in bash < 4
495 compopt -o filenames +o nospace 2>/dev/null ||
496 compgen -f /non-existing-dir/ >/dev/null ||
497 true
500 # Generates completion reply with compgen from newline-separated possible
501 # completion filenames.
502 # It accepts 1 to 3 arguments:
503 # 1: List of possible completion filenames, separated by a single newline.
504 # 2: A directory prefix to be added to each possible completion filename
505 # (optional).
506 # 3: Generate possible completion matches for this word (optional).
507 __gitcomp_file ()
509 local IFS=$'\n'
511 # XXX does not work when the directory prefix contains a tilde,
512 # since tilde expansion is not applied.
513 # This means that COMPREPLY will be empty and Bash default
514 # completion will be used.
515 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
517 # use a hack to enable file mode in bash < 4
518 compopt -o filenames +o nospace 2>/dev/null ||
519 compgen -f /non-existing-dir/ >/dev/null ||
520 true
523 # Execute 'git ls-files', unless the --committable option is specified, in
524 # which case it runs 'git diff-index' to find out the files that can be
525 # committed. It return paths relative to the directory specified in the first
526 # argument, and using the options specified in the second argument.
527 __git_ls_files_helper ()
529 if [ "$2" = "--committable" ]; then
530 __git -C "$1" -c core.quotePath=false diff-index \
531 --name-only --relative HEAD -- "${3//\\/\\\\}*"
532 else
533 # NOTE: $2 is not quoted in order to support multiple options
534 __git -C "$1" -c core.quotePath=false ls-files \
535 --exclude-standard $2 -- "${3//\\/\\\\}*"
540 # __git_index_files accepts 1 or 2 arguments:
541 # 1: Options to pass to ls-files (required).
542 # 2: A directory path (optional).
543 # If provided, only files within the specified directory are listed.
544 # Sub directories are never recursed. Path must have a trailing
545 # slash.
546 # 3: List only paths matching this path component (optional).
547 __git_index_files ()
549 local root="$2" match="$3"
551 __git_ls_files_helper "$root" "$1" "${match:-?}" |
552 awk -F / -v pfx="${2//\\/\\\\}" '{
553 paths[$1] = 1
555 END {
556 for (p in paths) {
557 if (substr(p, 1, 1) != "\"") {
558 # No special characters, easy!
559 print pfx p
560 continue
563 # The path is quoted.
564 p = dequote(p)
565 if (p == "")
566 continue
568 # Even when a directory name itself does not contain
569 # any special characters, it will still be quoted if
570 # any of its (stripped) trailing path components do.
571 # Because of this we may have seen the same directory
572 # both quoted and unquoted.
573 if (p in paths)
574 # We have seen the same directory unquoted,
575 # skip it.
576 continue
577 else
578 print pfx p
581 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
582 # Skip opening double quote.
583 p = substr(p, 2)
585 # Interpret backslash escape sequences.
586 while ((bs_idx = index(p, "\\")) != 0) {
587 out = out substr(p, 1, bs_idx - 1)
588 esc = substr(p, bs_idx + 1, 1)
589 p = substr(p, bs_idx + 2)
591 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
592 # C-style one-character escape sequence.
593 out = out substr("\a\b\t\v\f\r\"\\",
594 esc_idx, 1)
595 } else if (esc == "n") {
596 # Uh-oh, a newline character.
597 # We cannot reliably put a pathname
598 # containing a newline into COMPREPLY,
599 # and the newline would create a mess.
600 # Skip this path.
601 return ""
602 } else {
603 # Must be a \nnn octal value, then.
604 dec = esc * 64 + \
605 substr(p, 1, 1) * 8 + \
606 substr(p, 2, 1)
607 out = out sprintf("%c", dec)
608 p = substr(p, 3)
611 # Drop closing double quote, if there is one.
612 # (There is not any if this is a directory, as it was
613 # already stripped with the trailing path components.)
614 if (substr(p, length(p), 1) == "\"")
615 out = out substr(p, 1, length(p) - 1)
616 else
617 out = out p
619 return out
623 # __git_complete_index_file requires 1 argument:
624 # 1: the options to pass to ls-file
626 # The exception is --committable, which finds the files appropriate commit.
627 __git_complete_index_file ()
629 local dequoted_word pfx="" cur_
631 __git_dequote "$cur"
633 case "$dequoted_word" in
634 ?*/*)
635 pfx="${dequoted_word%/*}/"
636 cur_="${dequoted_word##*/}"
639 cur_="$dequoted_word"
640 esac
642 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
645 # Lists branches from the local repository.
646 # 1: A prefix to be added to each listed branch (optional).
647 # 2: List only branches matching this word (optional; list all branches if
648 # unset or empty).
649 # 3: A suffix to be appended to each listed branch (optional).
650 __git_heads ()
652 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
654 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
655 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
656 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
659 # Lists branches from remote repositories.
660 # 1: A prefix to be added to each listed branch (optional).
661 # 2: List only branches matching this word (optional; list all branches if
662 # unset or empty).
663 # 3: A suffix to be appended to each listed branch (optional).
664 __git_remote_heads ()
666 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
668 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
669 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
670 "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
673 # Lists tags from the local repository.
674 # Accepts the same positional parameters as __git_heads() above.
675 __git_tags ()
677 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
679 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
680 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
681 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
684 # List unique branches from refs/remotes used for 'git checkout' and 'git
685 # switch' tracking DWIMery.
686 # 1: A prefix to be added to each listed branch (optional)
687 # 2: List only branches matching this word (optional; list all branches if
688 # unset or empty).
689 # 3: A suffix to be appended to each listed branch (optional).
690 __git_dwim_remote_heads ()
692 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
693 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
695 # employ the heuristic used by git checkout and git switch
696 # Try to find a remote branch that cur_es the completion word
697 # but only output if the branch name is unique
698 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
699 --sort="refname:strip=3" \
700 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
701 "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
702 uniq -u
705 # Lists refs from the local (by default) or from a remote repository.
706 # It accepts 0, 1 or 2 arguments:
707 # 1: The remote to list refs from (optional; ignored, if set but empty).
708 # Can be the name of a configured remote, a path, or a URL.
709 # 2: In addition to local refs, list unique branches from refs/remotes/ for
710 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
711 # 3: A prefix to be added to each listed ref (optional).
712 # 4: List only refs matching this word (optional; list all refs if unset or
713 # empty).
714 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
715 # but empty).
717 # Use __git_complete_refs() instead.
718 __git_refs ()
720 local i hash dir track="${2-}"
721 local list_refs_from=path remote="${1-}"
722 local format refs
723 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
724 local match="${4-}"
725 local umatch="${4-}"
726 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
728 __git_find_repo_path
729 dir="$__git_repo_path"
731 if [ -z "$remote" ]; then
732 if [ -z "$dir" ]; then
733 return
735 else
736 if __git_is_configured_remote "$remote"; then
737 # configured remote takes precedence over a
738 # local directory with the same name
739 list_refs_from=remote
740 elif [ -d "$remote/.git" ]; then
741 dir="$remote/.git"
742 elif [ -d "$remote" ]; then
743 dir="$remote"
744 else
745 list_refs_from=url
749 if test "${GIT_COMPLETION_IGNORE_CASE:+1}" = "1"
750 then
751 # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility
752 umatch=$(echo "$match" | tr a-z A-Z 2>/dev/null || echo "$match")
755 if [ "$list_refs_from" = path ]; then
756 if [[ "$cur_" == ^* ]]; then
757 pfx="$pfx^"
758 fer_pfx="$fer_pfx^"
759 cur_=${cur_#^}
760 match=${match#^}
761 umatch=${umatch#^}
763 case "$cur_" in
764 refs|refs/*)
765 format="refname"
766 refs=("$match*" "$match*/**")
767 track=""
770 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do
771 case "$i" in
772 $match*|$umatch*)
773 if [ -e "$dir/$i" ]; then
774 echo "$pfx$i$sfx"
777 esac
778 done
779 format="refname:strip=2"
780 refs=("refs/tags/$match*" "refs/tags/$match*/**"
781 "refs/heads/$match*" "refs/heads/$match*/**"
782 "refs/remotes/$match*" "refs/remotes/$match*/**")
784 esac
785 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
786 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
787 "${refs[@]}"
788 if [ -n "$track" ]; then
789 __git_dwim_remote_heads "$pfx" "$match" "$sfx"
791 return
793 case "$cur_" in
794 refs|refs/*)
795 __git ls-remote "$remote" "$match*" | \
796 while read -r hash i; do
797 case "$i" in
798 *^{}) ;;
799 *) echo "$pfx$i$sfx" ;;
800 esac
801 done
804 if [ "$list_refs_from" = remote ]; then
805 case "HEAD" in
806 $match*|$umatch*) echo "${pfx}HEAD$sfx" ;;
807 esac
808 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
809 ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
810 "refs/remotes/$remote/$match*" \
811 "refs/remotes/$remote/$match*/**"
812 else
813 local query_symref
814 case "HEAD" in
815 $match*|$umatch*) query_symref="HEAD" ;;
816 esac
817 __git ls-remote "$remote" $query_symref \
818 "refs/tags/$match*" "refs/heads/$match*" \
819 "refs/remotes/$match*" |
820 while read -r hash i; do
821 case "$i" in
822 *^{}) ;;
823 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
824 *) echo "$pfx$i$sfx" ;; # symbolic refs
825 esac
826 done
829 esac
832 # Completes refs, short and long, local and remote, symbolic and pseudo.
834 # Usage: __git_complete_refs [<option>]...
835 # --remote=<remote>: The remote to list refs from, can be the name of a
836 # configured remote, a path, or a URL.
837 # --dwim: List unique remote branches for 'git switch's tracking DWIMery.
838 # --pfx=<prefix>: A prefix to be added to each ref.
839 # --cur=<word>: The current ref to be completed. Defaults to the current
840 # word to be completed.
841 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
842 # space.
843 # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
844 # complete all refs, 'heads' to complete only branches, or
845 # 'remote-heads' to complete only remote branches. Note that
846 # --remote is only compatible with --mode=refs.
847 __git_complete_refs ()
849 local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
851 while test $# != 0; do
852 case "$1" in
853 --remote=*) remote="${1##--remote=}" ;;
854 --dwim) dwim="yes" ;;
855 # --track is an old spelling of --dwim
856 --track) dwim="yes" ;;
857 --pfx=*) pfx="${1##--pfx=}" ;;
858 --cur=*) cur_="${1##--cur=}" ;;
859 --sfx=*) sfx="${1##--sfx=}" ;;
860 --mode=*) mode="${1##--mode=}" ;;
861 *) return 1 ;;
862 esac
863 shift
864 done
866 # complete references based on the specified mode
867 case "$mode" in
868 refs)
869 __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
870 heads)
871 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
872 remote-heads)
873 __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
875 return 1 ;;
876 esac
878 # Append DWIM remote branch names if requested
879 if [ "$dwim" = "yes" ]; then
880 __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
884 # __git_refs2 requires 1 argument (to pass to __git_refs)
885 # Deprecated: use __git_complete_fetch_refspecs() instead.
886 __git_refs2 ()
888 local i
889 for i in $(__git_refs "$1"); do
890 echo "$i:$i"
891 done
894 # Completes refspecs for fetching from a remote repository.
895 # 1: The remote repository.
896 # 2: A prefix to be added to each listed refspec (optional).
897 # 3: The ref to be completed as a refspec instead of the current word to be
898 # completed (optional)
899 # 4: A suffix to be appended to each listed refspec instead of the default
900 # space (optional).
901 __git_complete_fetch_refspecs ()
903 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
905 __gitcomp_direct "$(
906 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
907 echo "$pfx$i:$i$sfx"
908 done
912 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
913 __git_refs_remotes ()
915 local i hash
916 __git ls-remote "$1" 'refs/heads/*' | \
917 while read -r hash i; do
918 echo "$i:refs/remotes/$1/${i#refs/heads/}"
919 done
922 __git_remotes ()
924 __git_find_repo_path
925 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
926 __git remote
929 # Returns true if $1 matches the name of a configured remote, false otherwise.
930 __git_is_configured_remote ()
932 local remote
933 for remote in $(__git_remotes); do
934 if [ "$remote" = "$1" ]; then
935 return 0
937 done
938 return 1
941 __git_list_merge_strategies ()
943 LANG=C LC_ALL=C git merge -s help 2>&1 |
944 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
945 s/\.$//
946 s/.*://
947 s/^[ ]*//
948 s/[ ]*$//
953 __git_merge_strategies=
954 # 'git merge -s help' (and thus detection of the merge strategy
955 # list) fails, unfortunately, if run outside of any git working
956 # tree. __git_merge_strategies is set to the empty string in
957 # that case, and the detection will be repeated the next time it
958 # is needed.
959 __git_compute_merge_strategies ()
961 test -n "$__git_merge_strategies" ||
962 __git_merge_strategies=$(__git_list_merge_strategies)
965 __git_merge_strategy_options="ours theirs subtree subtree= patience
966 histogram diff-algorithm= ignore-space-change ignore-all-space
967 ignore-space-at-eol renormalize no-renormalize no-renames
968 find-renames find-renames= rename-threshold="
970 __git_complete_revlist_file ()
972 local dequoted_word pfx ls ref cur_="$cur"
973 case "$cur_" in
974 *..?*:*)
975 return
977 ?*:*)
978 ref="${cur_%%:*}"
979 cur_="${cur_#*:}"
981 __git_dequote "$cur_"
983 case "$dequoted_word" in
984 ?*/*)
985 pfx="${dequoted_word%/*}"
986 cur_="${dequoted_word##*/}"
987 ls="$ref:$pfx"
988 pfx="$pfx/"
991 cur_="$dequoted_word"
992 ls="$ref"
994 esac
996 case "$COMP_WORDBREAKS" in
997 *:*) : great ;;
998 *) pfx="$ref:$pfx" ;;
999 esac
1001 __gitcomp_file "$(__git ls-tree "$ls" \
1002 | sed 's/^.* //
1003 s/$//')" \
1004 "$pfx" "$cur_"
1006 *...*)
1007 pfx="${cur_%...*}..."
1008 cur_="${cur_#*...}"
1009 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1011 *..*)
1012 pfx="${cur_%..*}.."
1013 cur_="${cur_#*..}"
1014 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1017 __git_complete_refs
1019 esac
1022 __git_complete_file ()
1024 __git_complete_revlist_file
1027 __git_complete_revlist ()
1029 __git_complete_revlist_file
1032 __git_complete_remote_or_refspec ()
1034 local cur_="$cur" cmd="${words[__git_cmd_idx]}"
1035 local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
1036 if [ "$cmd" = "remote" ]; then
1037 ((c++))
1039 while [ $c -lt $cword ]; do
1040 i="${words[c]}"
1041 case "$i" in
1042 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
1043 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
1044 --all)
1045 case "$cmd" in
1046 push) no_complete_refspec=1 ;;
1047 fetch)
1048 return
1050 *) ;;
1051 esac
1053 --multiple) no_complete_refspec=1; break ;;
1054 -*) ;;
1055 *) remote="$i"; break ;;
1056 esac
1057 ((c++))
1058 done
1059 if [ -z "$remote" ]; then
1060 __gitcomp_nl "$(__git_remotes)"
1061 return
1063 if [ $no_complete_refspec = 1 ]; then
1064 return
1066 [ "$remote" = "." ] && remote=
1067 case "$cur_" in
1068 *:*)
1069 case "$COMP_WORDBREAKS" in
1070 *:*) : great ;;
1071 *) pfx="${cur_%%:*}:" ;;
1072 esac
1073 cur_="${cur_#*:}"
1074 lhs=0
1077 pfx="+"
1078 cur_="${cur_#+}"
1080 esac
1081 case "$cmd" in
1082 fetch)
1083 if [ $lhs = 1 ]; then
1084 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
1085 else
1086 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1089 pull|remote)
1090 if [ $lhs = 1 ]; then
1091 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1092 else
1093 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1096 push)
1097 if [ $lhs = 1 ]; then
1098 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1099 else
1100 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1103 esac
1106 __git_complete_strategy ()
1108 __git_compute_merge_strategies
1109 case "$prev" in
1110 -s|--strategy)
1111 __gitcomp "$__git_merge_strategies"
1112 return 0
1115 __gitcomp "$__git_merge_strategy_options"
1116 return 0
1118 esac
1119 case "$cur" in
1120 --strategy=*)
1121 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1122 return 0
1124 --strategy-option=*)
1125 __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1126 return 0
1128 esac
1129 return 1
1132 __git_all_commands=
1133 __git_compute_all_commands ()
1135 test -n "$__git_all_commands" ||
1136 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1139 # Lists all set config variables starting with the given section prefix,
1140 # with the prefix removed.
1141 __git_get_config_variables ()
1143 local section="$1" i IFS=$'\n'
1144 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1145 echo "${i#$section.}"
1146 done
1149 __git_pretty_aliases ()
1151 __git_get_config_variables "pretty"
1154 # __git_aliased_command requires 1 argument
1155 __git_aliased_command ()
1157 local cur=$1 last list= word cmdline
1159 while [[ -n "$cur" ]]; do
1160 if [[ "$list" == *" $cur "* ]]; then
1161 # loop detected
1162 return
1165 cmdline=$(__git config --get "alias.$cur")
1166 list=" $cur $list"
1167 last=$cur
1168 cur=
1170 for word in $cmdline; do
1171 case "$word" in
1172 \!gitk|gitk)
1173 cur="gitk"
1174 break
1176 \!*) : shell command alias ;;
1177 -*) : option ;;
1178 *=*) : setting env ;;
1179 git) : git itself ;;
1180 \(\)) : skip parens of shell function definition ;;
1181 {) : skip start of shell helper function ;;
1182 :) : skip null command ;;
1183 \'*) : skip opening quote after sh -c ;;
1185 cur="$word"
1186 break
1187 esac
1188 done
1189 done
1191 cur=$last
1192 if [[ "$cur" != "$1" ]]; then
1193 echo "$cur"
1197 # Check whether one of the given words is present on the command line,
1198 # and print the first word found.
1200 # Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
1201 # --show-idx: Optionally show the index of the found word in the $words array.
1202 __git_find_on_cmdline ()
1204 local word c="$__git_cmd_idx" show_idx
1206 while test $# -gt 1; do
1207 case "$1" in
1208 --show-idx) show_idx=y ;;
1209 *) return 1 ;;
1210 esac
1211 shift
1212 done
1213 local wordlist="$1"
1215 while [ $c -lt $cword ]; do
1216 for word in $wordlist; do
1217 if [ "$word" = "${words[c]}" ]; then
1218 if [ -n "${show_idx-}" ]; then
1219 echo "$c $word"
1220 else
1221 echo "$word"
1223 return
1225 done
1226 ((c++))
1227 done
1230 # Similar to __git_find_on_cmdline, except that it loops backwards and thus
1231 # prints the *last* word found. Useful for finding which of two options that
1232 # supersede each other came last, such as "--guess" and "--no-guess".
1234 # Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
1235 # --show-idx: Optionally show the index of the found word in the $words array.
1236 __git_find_last_on_cmdline ()
1238 local word c=$cword show_idx
1240 while test $# -gt 1; do
1241 case "$1" in
1242 --show-idx) show_idx=y ;;
1243 *) return 1 ;;
1244 esac
1245 shift
1246 done
1247 local wordlist="$1"
1249 while [ $c -gt "$__git_cmd_idx" ]; do
1250 ((c--))
1251 for word in $wordlist; do
1252 if [ "$word" = "${words[c]}" ]; then
1253 if [ -n "$show_idx" ]; then
1254 echo "$c $word"
1255 else
1256 echo "$word"
1258 return
1260 done
1261 done
1264 # Echo the value of an option set on the command line or config
1266 # $1: short option name
1267 # $2: long option name including =
1268 # $3: list of possible values
1269 # $4: config string (optional)
1271 # example:
1272 # result="$(__git_get_option_value "-d" "--do-something=" \
1273 # "yes no" "core.doSomething")"
1275 # result is then either empty (no option set) or "yes" or "no"
1277 # __git_get_option_value requires 3 arguments
1278 __git_get_option_value ()
1280 local c short_opt long_opt val
1281 local result= values config_key word
1283 short_opt="$1"
1284 long_opt="$2"
1285 values="$3"
1286 config_key="$4"
1288 ((c = $cword - 1))
1289 while [ $c -ge 0 ]; do
1290 word="${words[c]}"
1291 for val in $values; do
1292 if [ "$short_opt$val" = "$word" ] ||
1293 [ "$long_opt$val" = "$word" ]; then
1294 result="$val"
1295 break 2
1297 done
1298 ((c--))
1299 done
1301 if [ -n "$config_key" ] && [ -z "$result" ]; then
1302 result="$(__git config "$config_key")"
1305 echo "$result"
1308 __git_has_doubledash ()
1310 local c=1
1311 while [ $c -lt $cword ]; do
1312 if [ "--" = "${words[c]}" ]; then
1313 return 0
1315 ((c++))
1316 done
1317 return 1
1320 # Try to count non option arguments passed on the command line for the
1321 # specified git command.
1322 # When options are used, it is necessary to use the special -- option to
1323 # tell the implementation were non option arguments begin.
1324 # XXX this can not be improved, since options can appear everywhere, as
1325 # an example:
1326 # git mv x -n y
1328 # __git_count_arguments requires 1 argument: the git command executed.
1329 __git_count_arguments ()
1331 local word i c=0
1333 # Skip "git" (first argument)
1334 for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
1335 word="${words[i]}"
1337 case "$word" in
1339 # Good; we can assume that the following are only non
1340 # option arguments.
1341 ((c = 0))
1343 "$1")
1344 # Skip the specified git command and discard git
1345 # main options
1346 ((c = 0))
1349 ((c++))
1351 esac
1352 done
1354 printf "%d" $c
1357 __git_whitespacelist="nowarn warn error error-all fix"
1358 __git_patchformat="mbox stgit stgit-series hg mboxrd"
1359 __git_showcurrentpatch="diff raw"
1360 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1361 __git_quoted_cr="nowarn warn strip"
1363 _git_am ()
1365 __git_find_repo_path
1366 if [ -d "$__git_repo_path"/rebase-apply ]; then
1367 __gitcomp "$__git_am_inprogress_options"
1368 return
1370 case "$cur" in
1371 --whitespace=*)
1372 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1373 return
1375 --patch-format=*)
1376 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1377 return
1379 --show-current-patch=*)
1380 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
1381 return
1383 --quoted-cr=*)
1384 __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}"
1385 return
1387 --*)
1388 __gitcomp_builtin am "" \
1389 "$__git_am_inprogress_options"
1390 return
1391 esac
1394 _git_apply ()
1396 case "$cur" in
1397 --whitespace=*)
1398 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1399 return
1401 --*)
1402 __gitcomp_builtin apply
1403 return
1404 esac
1407 _git_add ()
1409 case "$cur" in
1410 --chmod=*)
1411 __gitcomp "+x -x" "" "${cur##--chmod=}"
1412 return
1414 --*)
1415 __gitcomp_builtin add
1416 return
1417 esac
1419 local complete_opt="--others --modified --directory --no-empty-directory"
1420 if test -n "$(__git_find_on_cmdline "-u --update")"
1421 then
1422 complete_opt="--modified"
1424 __git_complete_index_file "$complete_opt"
1427 _git_archive ()
1429 case "$cur" in
1430 --format=*)
1431 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1432 return
1434 --remote=*)
1435 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1436 return
1438 --*)
1439 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
1440 return
1442 esac
1443 __git_complete_file
1446 _git_bisect ()
1448 __git_has_doubledash && return
1450 local subcommands="start bad good skip reset visualize replay log run"
1451 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1452 if [ -z "$subcommand" ]; then
1453 __git_find_repo_path
1454 if [ -f "$__git_repo_path"/BISECT_START ]; then
1455 __gitcomp "$subcommands"
1456 else
1457 __gitcomp "replay start"
1459 return
1462 case "$subcommand" in
1463 bad|good|reset|skip|start)
1464 __git_complete_refs
1468 esac
1471 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1473 _git_branch ()
1475 local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
1477 while [ $c -lt $cword ]; do
1478 i="${words[c]}"
1479 case "$i" in
1480 -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
1481 only_local_ref="y" ;;
1482 -r|--remotes)
1483 has_r="y" ;;
1484 esac
1485 ((c++))
1486 done
1488 case "$cur" in
1489 --set-upstream-to=*)
1490 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1492 --*)
1493 __gitcomp_builtin branch
1496 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1497 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1498 else
1499 __git_complete_refs
1502 esac
1505 _git_bundle ()
1507 local cmd="${words[__git_cmd_idx+1]}"
1508 case "$cword" in
1509 $((__git_cmd_idx+1)))
1510 __gitcomp "create list-heads verify unbundle"
1512 $((__git_cmd_idx+2)))
1513 # looking for a file
1516 case "$cmd" in
1517 create)
1518 __git_complete_revlist
1520 esac
1522 esac
1525 # Helper function to decide whether or not we should enable DWIM logic for
1526 # git-switch and git-checkout.
1528 # To decide between the following rules in decreasing priority order:
1529 # - the last provided of "--guess" or "--no-guess" explicitly enable or
1530 # disable completion of DWIM logic respectively.
1531 # - If checkout.guess is false, disable completion of DWIM logic.
1532 # - If the --no-track option is provided, take this as a hint to disable the
1533 # DWIM completion logic
1534 # - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
1535 # logic, as requested by the user.
1536 # - Enable DWIM logic otherwise.
1538 __git_checkout_default_dwim_mode ()
1540 local last_option dwim_opt="--dwim"
1542 if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1543 dwim_opt=""
1546 # --no-track disables DWIM, but with lower priority than
1547 # --guess/--no-guess/checkout.guess
1548 if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
1549 dwim_opt=""
1552 # checkout.guess = false disables DWIM, but with lower priority than
1553 # --guess/--no-guess
1554 if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
1555 dwim_opt=""
1558 # Find the last provided --guess or --no-guess
1559 last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
1560 case "$last_option" in
1561 --guess)
1562 dwim_opt="--dwim"
1564 --no-guess)
1565 dwim_opt=""
1567 esac
1569 echo "$dwim_opt"
1572 _git_checkout ()
1574 __git_has_doubledash && return
1576 local dwim_opt="$(__git_checkout_default_dwim_mode)"
1578 case "$prev" in
1579 -b|-B|--orphan)
1580 # Complete local branches (and DWIM branch
1581 # remote branch names) for an option argument
1582 # specifying a new branch name. This is for
1583 # convenience, assuming new branches are
1584 # possibly based on pre-existing branch names.
1585 __git_complete_refs $dwim_opt --mode="heads"
1586 return
1590 esac
1592 case "$cur" in
1593 --conflict=*)
1594 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
1596 --*)
1597 __gitcomp_builtin checkout
1600 # At this point, we've already handled special completion for
1601 # the arguments to -b/-B, and --orphan. There are 3 main
1602 # things left we can possibly complete:
1603 # 1) a start-point for -b/-B, -d/--detach, or --orphan
1604 # 2) a remote head, for --track
1605 # 3) an arbitrary reference, possibly including DWIM names
1608 if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
1609 __git_complete_refs --mode="refs"
1610 elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
1611 __git_complete_refs --mode="remote-heads"
1612 else
1613 __git_complete_refs $dwim_opt --mode="refs"
1616 esac
1619 __git_sequencer_inprogress_options="--continue --quit --abort --skip"
1621 __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1623 _git_cherry_pick ()
1625 __git_find_repo_path
1626 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1627 __gitcomp "$__git_cherry_pick_inprogress_options"
1628 return
1631 __git_complete_strategy && return
1633 case "$cur" in
1634 --*)
1635 __gitcomp_builtin cherry-pick "" \
1636 "$__git_cherry_pick_inprogress_options"
1639 __git_complete_refs
1641 esac
1644 _git_clean ()
1646 case "$cur" in
1647 --*)
1648 __gitcomp_builtin clean
1649 return
1651 esac
1653 # XXX should we check for -x option ?
1654 __git_complete_index_file "--others --directory"
1657 _git_clone ()
1659 case "$prev" in
1660 -c|--config)
1661 __git_complete_config_variable_name_and_value
1662 return
1664 esac
1665 case "$cur" in
1666 --config=*)
1667 __git_complete_config_variable_name_and_value \
1668 --cur="${cur##--config=}"
1669 return
1671 --*)
1672 __gitcomp_builtin clone
1673 return
1675 esac
1678 __git_untracked_file_modes="all no normal"
1680 _git_commit ()
1682 case "$prev" in
1683 -c|-C)
1684 __git_complete_refs
1685 return
1687 esac
1689 case "$cur" in
1690 --cleanup=*)
1691 __gitcomp "default scissors strip verbatim whitespace
1692 " "" "${cur##--cleanup=}"
1693 return
1695 --reuse-message=*|--reedit-message=*|\
1696 --fixup=*|--squash=*)
1697 __git_complete_refs --cur="${cur#*=}"
1698 return
1700 --untracked-files=*)
1701 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1702 return
1704 --*)
1705 __gitcomp_builtin commit
1706 return
1707 esac
1709 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1710 __git_complete_index_file "--committable"
1711 else
1712 # This is the first commit
1713 __git_complete_index_file "--cached"
1717 _git_describe ()
1719 case "$cur" in
1720 --*)
1721 __gitcomp_builtin describe
1722 return
1723 esac
1724 __git_complete_refs
1727 __git_diff_algorithms="myers minimal patience histogram"
1729 __git_diff_submodule_formats="diff log short"
1731 __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
1733 __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
1734 ignore-all-space allow-indentation-change"
1736 # Options for the diff machinery (diff, log, show, stash, range-diff, ...)
1737 __git_diff_common_options="--stat --numstat --shortstat --summary
1738 --patch-with-stat --name-only --name-status --color
1739 --no-color --color-words --no-renames --check
1740 --color-moved --color-moved= --no-color-moved
1741 --color-moved-ws= --no-color-moved-ws
1742 --full-index --binary --abbrev --diff-filter=
1743 --find-copies --find-object --find-renames
1744 --no-relative --relative
1745 --find-copies-harder --ignore-cr-at-eol
1746 --text --ignore-space-at-eol --ignore-space-change
1747 --ignore-all-space --ignore-blank-lines --exit-code
1748 --quiet --ext-diff --no-ext-diff
1749 --no-prefix --src-prefix= --dst-prefix=
1750 --inter-hunk-context= --function-context
1751 --patience --histogram --minimal
1752 --raw --word-diff --word-diff-regex=
1753 --dirstat --dirstat= --dirstat-by-file
1754 --dirstat-by-file= --cumulative
1755 --diff-algorithm= --default-prefix
1756 --submodule --submodule= --ignore-submodules
1757 --indent-heuristic --no-indent-heuristic
1758 --textconv --no-textconv --break-rewrites
1759 --patch --no-patch --cc --combined-all-paths
1760 --anchored= --compact-summary --ignore-matching-lines=
1761 --irreversible-delete --line-prefix
1764 # Options for diff/difftool
1765 __git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex
1766 --base --ours --theirs --no-index --merge-base
1767 --ita-invisible-in-index --ita-visible-in-index
1768 $__git_diff_common_options"
1770 _git_diff ()
1772 __git_has_doubledash && return
1774 case "$cur" in
1775 --diff-algorithm=*)
1776 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1777 return
1779 --submodule=*)
1780 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1781 return
1783 --color-moved=*)
1784 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
1785 return
1787 --color-moved-ws=*)
1788 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
1789 return
1791 --*)
1792 __gitcomp "$__git_diff_difftool_options"
1793 return
1795 esac
1796 __git_complete_revlist_file
1799 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1800 tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1801 bc codecompare smerge
1804 _git_difftool ()
1806 __git_has_doubledash && return
1808 case "$cur" in
1809 --tool=*)
1810 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1811 return
1813 --*)
1814 __gitcomp_builtin difftool "$__git_diff_difftool_options"
1815 return
1817 esac
1818 __git_complete_revlist_file
1821 __git_fetch_recurse_submodules="yes on-demand no"
1823 _git_fetch ()
1825 case "$cur" in
1826 --recurse-submodules=*)
1827 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1828 return
1830 --filter=*)
1831 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1832 return
1834 --*)
1835 __gitcomp_builtin fetch
1836 return
1838 esac
1839 __git_complete_remote_or_refspec
1842 __git_format_patch_extra_options="
1843 --full-index --not --all --no-prefix --src-prefix=
1844 --dst-prefix= --notes
1847 _git_format_patch ()
1849 case "$cur" in
1850 --thread=*)
1851 __gitcomp "
1852 deep shallow
1853 " "" "${cur##--thread=}"
1854 return
1856 --base=*|--interdiff=*|--range-diff=*)
1857 __git_complete_refs --cur="${cur#--*=}"
1858 return
1860 --*)
1861 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1862 return
1864 esac
1865 __git_complete_revlist
1868 _git_fsck ()
1870 case "$cur" in
1871 --*)
1872 __gitcomp_builtin fsck
1873 return
1875 esac
1878 _git_gitk ()
1880 __gitk_main
1883 # Lists matching symbol names from a tag (as in ctags) file.
1884 # 1: List symbol names matching this word.
1885 # 2: The tag file to list symbol names from.
1886 # 3: A prefix to be added to each listed symbol name (optional).
1887 # 4: A suffix to be appended to each listed symbol name (optional).
1888 __git_match_ctag () {
1889 awk -v pfx="${3-}" -v sfx="${4-}" "
1890 /^${1//\//\\/}/ { print pfx \$1 sfx }
1891 " "$2"
1894 # Complete symbol names from a tag file.
1895 # Usage: __git_complete_symbol [<option>]...
1896 # --tags=<file>: The tag file to list symbol names from instead of the
1897 # default "tags".
1898 # --pfx=<prefix>: A prefix to be added to each symbol name.
1899 # --cur=<word>: The current symbol name to be completed. Defaults to
1900 # the current word to be completed.
1901 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1902 # of the default space.
1903 __git_complete_symbol () {
1904 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1906 while test $# != 0; do
1907 case "$1" in
1908 --tags=*) tags="${1##--tags=}" ;;
1909 --pfx=*) pfx="${1##--pfx=}" ;;
1910 --cur=*) cur_="${1##--cur=}" ;;
1911 --sfx=*) sfx="${1##--sfx=}" ;;
1912 *) return 1 ;;
1913 esac
1914 shift
1915 done
1917 if test -r "$tags"; then
1918 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1922 _git_grep ()
1924 __git_has_doubledash && return
1926 case "$cur" in
1927 --*)
1928 __gitcomp_builtin grep
1929 return
1931 esac
1933 case "$cword,$prev" in
1934 $((__git_cmd_idx+1)),*|*,-*)
1935 __git_complete_symbol && return
1937 esac
1939 __git_complete_refs
1942 _git_help ()
1944 case "$cur" in
1945 --*)
1946 __gitcomp_builtin help
1947 return
1949 esac
1950 if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
1951 then
1952 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
1953 else
1954 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1958 _git_init ()
1960 case "$cur" in
1961 --shared=*)
1962 __gitcomp "
1963 false true umask group all world everybody
1964 " "" "${cur##--shared=}"
1965 return
1967 --*)
1968 __gitcomp_builtin init
1969 return
1971 esac
1974 _git_ls_files ()
1976 case "$cur" in
1977 --*)
1978 __gitcomp_builtin ls-files
1979 return
1981 esac
1983 # XXX ignore options like --modified and always suggest all cached
1984 # files.
1985 __git_complete_index_file "--cached"
1988 _git_ls_remote ()
1990 case "$cur" in
1991 --*)
1992 __gitcomp_builtin ls-remote
1993 return
1995 esac
1996 __gitcomp_nl "$(__git_remotes)"
1999 _git_ls_tree ()
2001 case "$cur" in
2002 --*)
2003 __gitcomp_builtin ls-tree
2004 return
2006 esac
2008 __git_complete_file
2011 # Options that go well for log, shortlog and gitk
2012 __git_log_common_options="
2013 --not --all
2014 --branches --tags --remotes
2015 --first-parent --merges --no-merges
2016 --max-count=
2017 --max-age= --since= --after=
2018 --min-age= --until= --before=
2019 --min-parents= --max-parents=
2020 --no-min-parents --no-max-parents
2022 # Options that go well for log and gitk (not shortlog)
2023 __git_log_gitk_options="
2024 --dense --sparse --full-history
2025 --simplify-merges --simplify-by-decoration
2026 --left-right --notes --no-notes
2028 # Options that go well for log and shortlog (not gitk)
2029 __git_log_shortlog_options="
2030 --author= --committer= --grep=
2031 --all-match --invert-grep
2034 __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
2035 __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
2037 _git_log ()
2039 __git_has_doubledash && return
2040 __git_find_repo_path
2042 local merge=""
2043 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2044 merge="--merge"
2046 case "$prev,$cur" in
2047 -L,:*:*)
2048 return # fall back to Bash filename completion
2050 -L,:*)
2051 __git_complete_symbol --cur="${cur#:}" --sfx=":"
2052 return
2054 -G,*|-S,*)
2055 __git_complete_symbol
2056 return
2058 esac
2059 case "$cur" in
2060 --pretty=*|--format=*)
2061 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2062 " "" "${cur#*=}"
2063 return
2065 --date=*)
2066 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
2067 return
2069 --decorate=*)
2070 __gitcomp "full short no" "" "${cur##--decorate=}"
2071 return
2073 --diff-algorithm=*)
2074 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2075 return
2077 --submodule=*)
2078 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2079 return
2081 --no-walk=*)
2082 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
2083 return
2085 --*)
2086 __gitcomp "
2087 $__git_log_common_options
2088 $__git_log_shortlog_options
2089 $__git_log_gitk_options
2090 --root --topo-order --date-order --reverse
2091 --follow --full-diff
2092 --abbrev-commit --no-abbrev-commit --abbrev=
2093 --relative-date --date=
2094 --pretty= --format= --oneline
2095 --show-signature
2096 --cherry-mark
2097 --cherry-pick
2098 --graph
2099 --decorate --decorate= --no-decorate
2100 --walk-reflogs
2101 --no-walk --no-walk= --do-walk
2102 --parents --children
2103 --expand-tabs --expand-tabs= --no-expand-tabs
2104 $merge
2105 $__git_diff_common_options
2106 --pickaxe-all --pickaxe-regex
2108 return
2110 -L:*:*)
2111 return # fall back to Bash filename completion
2113 -L:*)
2114 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
2115 return
2117 -G*)
2118 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
2119 return
2121 -S*)
2122 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
2123 return
2125 esac
2126 __git_complete_revlist
2129 _git_merge ()
2131 __git_complete_strategy && return
2133 case "$cur" in
2134 --*)
2135 __gitcomp_builtin merge
2136 return
2137 esac
2138 __git_complete_refs
2141 _git_mergetool ()
2143 case "$cur" in
2144 --tool=*)
2145 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
2146 return
2148 --*)
2149 __gitcomp "--tool= --prompt --no-prompt --gui --no-gui"
2150 return
2152 esac
2155 _git_merge_base ()
2157 case "$cur" in
2158 --*)
2159 __gitcomp_builtin merge-base
2160 return
2162 esac
2163 __git_complete_refs
2166 _git_mv ()
2168 case "$cur" in
2169 --*)
2170 __gitcomp_builtin mv
2171 return
2173 esac
2175 if [ $(__git_count_arguments "mv") -gt 0 ]; then
2176 # We need to show both cached and untracked files (including
2177 # empty directories) since this may not be the last argument.
2178 __git_complete_index_file "--cached --others --directory"
2179 else
2180 __git_complete_index_file "--cached"
2184 _git_notes ()
2186 local subcommands='add append copy edit get-ref list merge prune remove show'
2187 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2189 case "$subcommand,$cur" in
2190 ,--*)
2191 __gitcomp_builtin notes
2194 case "$prev" in
2195 --ref)
2196 __git_complete_refs
2199 __gitcomp "$subcommands --ref"
2201 esac
2203 *,--reuse-message=*|*,--reedit-message=*)
2204 __git_complete_refs --cur="${cur#*=}"
2206 *,--*)
2207 __gitcomp_builtin notes_$subcommand
2209 prune,*|get-ref,*)
2210 # this command does not take a ref, do not complete it
2213 case "$prev" in
2214 -m|-F)
2217 __git_complete_refs
2219 esac
2221 esac
2224 _git_pull ()
2226 __git_complete_strategy && return
2228 case "$cur" in
2229 --recurse-submodules=*)
2230 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
2231 return
2233 --*)
2234 __gitcomp_builtin pull
2236 return
2238 esac
2239 __git_complete_remote_or_refspec
2242 __git_push_recurse_submodules="check on-demand only"
2244 __git_complete_force_with_lease ()
2246 local cur_=$1
2248 case "$cur_" in
2249 --*=)
2251 *:*)
2252 __git_complete_refs --cur="${cur_#*:}"
2255 __git_complete_refs --cur="$cur_"
2257 esac
2260 _git_push ()
2262 case "$prev" in
2263 --repo)
2264 __gitcomp_nl "$(__git_remotes)"
2265 return
2267 --recurse-submodules)
2268 __gitcomp "$__git_push_recurse_submodules"
2269 return
2271 esac
2272 case "$cur" in
2273 --repo=*)
2274 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
2275 return
2277 --recurse-submodules=*)
2278 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
2279 return
2281 --force-with-lease=*)
2282 __git_complete_force_with_lease "${cur##--force-with-lease=}"
2283 return
2285 --*)
2286 __gitcomp_builtin push
2287 return
2289 esac
2290 __git_complete_remote_or_refspec
2293 _git_range_diff ()
2295 case "$cur" in
2296 --*)
2297 __gitcomp "
2298 --creation-factor= --no-dual-color
2299 $__git_diff_common_options
2301 return
2303 esac
2304 __git_complete_revlist
2307 __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
2308 __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
2310 _git_rebase ()
2312 __git_find_repo_path
2313 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2314 __gitcomp "$__git_rebase_interactive_inprogress_options"
2315 return
2316 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2317 [ -d "$__git_repo_path"/rebase-merge ]; then
2318 __gitcomp "$__git_rebase_inprogress_options"
2319 return
2321 __git_complete_strategy && return
2322 case "$cur" in
2323 --whitespace=*)
2324 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2325 return
2327 --onto=*)
2328 __git_complete_refs --cur="${cur##--onto=}"
2329 return
2331 --*)
2332 __gitcomp_builtin rebase "" \
2333 "$__git_rebase_interactive_inprogress_options"
2335 return
2336 esac
2337 __git_complete_refs
2340 _git_reflog ()
2342 local subcommands="show delete expire"
2343 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2345 if [ -z "$subcommand" ]; then
2346 __gitcomp "$subcommands"
2347 else
2348 __git_complete_refs
2352 __git_send_email_confirm_options="always never auto cc compose"
2353 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2355 _git_send_email ()
2357 case "$prev" in
2358 --to|--cc|--bcc|--from)
2359 __gitcomp "$(__git send-email --dump-aliases)"
2360 return
2362 esac
2364 case "$cur" in
2365 --confirm=*)
2366 __gitcomp "
2367 $__git_send_email_confirm_options
2368 " "" "${cur##--confirm=}"
2369 return
2371 --suppress-cc=*)
2372 __gitcomp "
2373 $__git_send_email_suppresscc_options
2374 " "" "${cur##--suppress-cc=}"
2376 return
2378 --smtp-encryption=*)
2379 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2380 return
2382 --thread=*)
2383 __gitcomp "
2384 deep shallow
2385 " "" "${cur##--thread=}"
2386 return
2388 --to=*|--cc=*|--bcc=*|--from=*)
2389 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2390 return
2392 --*)
2393 __gitcomp_builtin send-email "$__git_format_patch_extra_options"
2394 return
2396 esac
2397 __git_complete_revlist
2400 _git_stage ()
2402 _git_add
2405 _git_status ()
2407 local complete_opt
2408 local untracked_state
2410 case "$cur" in
2411 --ignore-submodules=*)
2412 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2413 return
2415 --untracked-files=*)
2416 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2417 return
2419 --column=*)
2420 __gitcomp "
2421 always never auto column row plain dense nodense
2422 " "" "${cur##--column=}"
2423 return
2425 --*)
2426 __gitcomp_builtin status
2427 return
2429 esac
2431 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2432 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2434 case "$untracked_state" in
2436 # --ignored option does not matter
2437 complete_opt=
2439 all|normal|*)
2440 complete_opt="--cached --directory --no-empty-directory --others"
2442 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2443 complete_opt="$complete_opt --ignored --exclude=*"
2446 esac
2448 __git_complete_index_file "$complete_opt"
2451 _git_switch ()
2453 local dwim_opt="$(__git_checkout_default_dwim_mode)"
2455 case "$prev" in
2456 -c|-C|--orphan)
2457 # Complete local branches (and DWIM branch
2458 # remote branch names) for an option argument
2459 # specifying a new branch name. This is for
2460 # convenience, assuming new branches are
2461 # possibly based on pre-existing branch names.
2462 __git_complete_refs $dwim_opt --mode="heads"
2463 return
2467 esac
2469 case "$cur" in
2470 --conflict=*)
2471 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2473 --*)
2474 __gitcomp_builtin switch
2477 # Unlike in git checkout, git switch --orphan does not take
2478 # a start point. Thus we really have nothing to complete after
2479 # the branch name.
2480 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
2481 return
2484 # At this point, we've already handled special completion for
2485 # -c/-C, and --orphan. There are 3 main things left to
2486 # complete:
2487 # 1) a start-point for -c/-C or -d/--detach
2488 # 2) a remote head, for --track
2489 # 3) a branch name, possibly including DWIM remote branches
2491 if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
2492 __git_complete_refs --mode="refs"
2493 elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
2494 __git_complete_refs --mode="remote-heads"
2495 else
2496 __git_complete_refs $dwim_opt --mode="heads"
2499 esac
2502 __git_config_get_set_variables ()
2504 local prevword word config_file= c=$cword
2505 while [ $c -gt "$__git_cmd_idx" ]; do
2506 word="${words[c]}"
2507 case "$word" in
2508 --system|--global|--local|--file=*)
2509 config_file="$word"
2510 break
2512 -f|--file)
2513 config_file="$word $prevword"
2514 break
2516 esac
2517 prevword=$word
2518 c=$((--c))
2519 done
2521 __git config $config_file --name-only --list
2524 __git_config_vars=
2525 __git_compute_config_vars ()
2527 test -n "$__git_config_vars" ||
2528 __git_config_vars="$(git help --config-for-completion)"
2531 __git_config_sections=
2532 __git_compute_config_sections ()
2534 test -n "$__git_config_sections" ||
2535 __git_config_sections="$(git help --config-sections-for-completion)"
2538 # Completes possible values of various configuration variables.
2540 # Usage: __git_complete_config_variable_value [<option>]...
2541 # --varname=<word>: The name of the configuration variable whose value is
2542 # to be completed. Defaults to the previous word on the
2543 # command line.
2544 # --cur=<word>: The current value to be completed. Defaults to the current
2545 # word to be completed.
2546 __git_complete_config_variable_value ()
2548 local varname="$prev" cur_="$cur"
2550 while test $# != 0; do
2551 case "$1" in
2552 --varname=*) varname="${1##--varname=}" ;;
2553 --cur=*) cur_="${1##--cur=}" ;;
2554 *) return 1 ;;
2555 esac
2556 shift
2557 done
2559 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2560 varname="${varname,,}"
2561 else
2562 varname="$(echo "$varname" |tr A-Z a-z)"
2565 case "$varname" in
2566 branch.*.remote|branch.*.pushremote)
2567 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2568 return
2570 branch.*.merge)
2571 __git_complete_refs --cur="$cur_"
2572 return
2574 branch.*.rebase)
2575 __gitcomp "false true merges interactive" "" "$cur_"
2576 return
2578 remote.pushdefault)
2579 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2580 return
2582 remote.*.fetch)
2583 local remote="${varname#remote.}"
2584 remote="${remote%.fetch}"
2585 if [ -z "$cur_" ]; then
2586 __gitcomp_nl "refs/heads/" "" "" ""
2587 return
2589 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2590 return
2592 remote.*.push)
2593 local remote="${varname#remote.}"
2594 remote="${remote%.push}"
2595 __gitcomp_nl "$(__git for-each-ref \
2596 --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2597 return
2599 pull.twohead|pull.octopus)
2600 __git_compute_merge_strategies
2601 __gitcomp "$__git_merge_strategies" "" "$cur_"
2602 return
2604 color.pager)
2605 __gitcomp "false true" "" "$cur_"
2606 return
2608 color.*.*)
2609 __gitcomp "
2610 normal black red green yellow blue magenta cyan white
2611 bold dim ul blink reverse
2612 " "" "$cur_"
2613 return
2615 color.*)
2616 __gitcomp "false true always never auto" "" "$cur_"
2617 return
2619 diff.submodule)
2620 __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2621 return
2623 help.format)
2624 __gitcomp "man info web html" "" "$cur_"
2625 return
2627 log.date)
2628 __gitcomp "$__git_log_date_formats" "" "$cur_"
2629 return
2631 sendemail.aliasfiletype)
2632 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2633 return
2635 sendemail.confirm)
2636 __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2637 return
2639 sendemail.suppresscc)
2640 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2641 return
2643 sendemail.transferencoding)
2644 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2645 return
2647 *.*)
2648 return
2650 esac
2653 # Completes configuration sections, subsections, variable names.
2655 # Usage: __git_complete_config_variable_name [<option>]...
2656 # --cur=<word>: The current configuration section/variable name to be
2657 # completed. Defaults to the current word to be completed.
2658 # --sfx=<suffix>: A suffix to be appended to each fully completed
2659 # configuration variable name (but not to sections or
2660 # subsections) instead of the default space.
2661 __git_complete_config_variable_name ()
2663 local cur_="$cur" sfx
2665 while test $# != 0; do
2666 case "$1" in
2667 --cur=*) cur_="${1##--cur=}" ;;
2668 --sfx=*) sfx="${1##--sfx=}" ;;
2669 *) return 1 ;;
2670 esac
2671 shift
2672 done
2674 case "$cur_" in
2675 branch.*.*)
2676 local pfx="${cur_%.*}."
2677 cur_="${cur_##*.}"
2678 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2679 return
2681 branch.*)
2682 local pfx="${cur_%.*}."
2683 cur_="${cur_#*.}"
2684 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2685 __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
2686 return
2688 guitool.*.*)
2689 local pfx="${cur_%.*}."
2690 cur_="${cur_##*.}"
2691 __gitcomp "
2692 argPrompt cmd confirm needsFile noConsole noRescan
2693 prompt revPrompt revUnmerged title
2694 " "$pfx" "$cur_" "$sfx"
2695 return
2697 difftool.*.*)
2698 local pfx="${cur_%.*}."
2699 cur_="${cur_##*.}"
2700 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2701 return
2703 man.*.*)
2704 local pfx="${cur_%.*}."
2705 cur_="${cur_##*.}"
2706 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2707 return
2709 mergetool.*.*)
2710 local pfx="${cur_%.*}."
2711 cur_="${cur_##*.}"
2712 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2713 return
2715 pager.*)
2716 local pfx="${cur_%.*}."
2717 cur_="${cur_#*.}"
2718 __git_compute_all_commands
2719 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx- }"
2720 return
2722 remote.*.*)
2723 local pfx="${cur_%.*}."
2724 cur_="${cur_##*.}"
2725 __gitcomp "
2726 url proxy fetch push mirror skipDefaultUpdate
2727 receivepack uploadpack tagOpt pushurl
2728 " "$pfx" "$cur_" "$sfx"
2729 return
2731 remote.*)
2732 local pfx="${cur_%.*}."
2733 cur_="${cur_#*.}"
2734 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2735 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
2736 return
2738 url.*.*)
2739 local pfx="${cur_%.*}."
2740 cur_="${cur_##*.}"
2741 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2742 return
2744 *.*)
2745 __git_compute_config_vars
2746 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
2749 __git_compute_config_sections
2750 __gitcomp "$__git_config_sections" "" "$cur_" "."
2752 esac
2755 # Completes '='-separated configuration sections/variable names and values
2756 # for 'git -c section.name=value'.
2758 # Usage: __git_complete_config_variable_name_and_value [<option>]...
2759 # --cur=<word>: The current configuration section/variable name/value to be
2760 # completed. Defaults to the current word to be completed.
2761 __git_complete_config_variable_name_and_value ()
2763 local cur_="$cur"
2765 while test $# != 0; do
2766 case "$1" in
2767 --cur=*) cur_="${1##--cur=}" ;;
2768 *) return 1 ;;
2769 esac
2770 shift
2771 done
2773 case "$cur_" in
2774 *=*)
2775 __git_complete_config_variable_value \
2776 --varname="${cur_%%=*}" --cur="${cur_#*=}"
2779 __git_complete_config_variable_name --cur="$cur_" --sfx='='
2781 esac
2784 _git_config ()
2786 case "$prev" in
2787 --get|--get-all|--unset|--unset-all)
2788 __gitcomp_nl "$(__git_config_get_set_variables)"
2789 return
2791 *.*)
2792 __git_complete_config_variable_value
2793 return
2795 esac
2796 case "$cur" in
2797 --*)
2798 __gitcomp_builtin config
2801 __git_complete_config_variable_name
2803 esac
2806 _git_remote ()
2808 local subcommands="
2809 add rename remove set-head set-branches
2810 get-url set-url show prune update
2812 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2813 if [ -z "$subcommand" ]; then
2814 case "$cur" in
2815 --*)
2816 __gitcomp_builtin remote
2819 __gitcomp "$subcommands"
2821 esac
2822 return
2825 case "$subcommand,$cur" in
2826 add,--*)
2827 __gitcomp_builtin remote_add
2829 add,*)
2831 set-head,--*)
2832 __gitcomp_builtin remote_set-head
2834 set-branches,--*)
2835 __gitcomp_builtin remote_set-branches
2837 set-head,*|set-branches,*)
2838 __git_complete_remote_or_refspec
2840 update,--*)
2841 __gitcomp_builtin remote_update
2843 update,*)
2844 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
2846 set-url,--*)
2847 __gitcomp_builtin remote_set-url
2849 get-url,--*)
2850 __gitcomp_builtin remote_get-url
2852 prune,--*)
2853 __gitcomp_builtin remote_prune
2856 __gitcomp_nl "$(__git_remotes)"
2858 esac
2861 _git_replace ()
2863 case "$cur" in
2864 --format=*)
2865 __gitcomp "short medium long" "" "${cur##--format=}"
2866 return
2868 --*)
2869 __gitcomp_builtin replace
2870 return
2872 esac
2873 __git_complete_refs
2876 _git_rerere ()
2878 local subcommands="clear forget diff remaining status gc"
2879 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2880 if test -z "$subcommand"
2881 then
2882 __gitcomp "$subcommands"
2883 return
2887 _git_reset ()
2889 __git_has_doubledash && return
2891 case "$cur" in
2892 --*)
2893 __gitcomp_builtin reset
2894 return
2896 esac
2897 __git_complete_refs
2900 _git_restore ()
2902 case "$prev" in
2904 __git_complete_refs
2905 return
2907 esac
2909 case "$cur" in
2910 --conflict=*)
2911 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2913 --source=*)
2914 __git_complete_refs --cur="${cur##--source=}"
2916 --*)
2917 __gitcomp_builtin restore
2920 if __git rev-parse --verify --quiet HEAD >/dev/null; then
2921 __git_complete_index_file "--modified"
2923 esac
2926 __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2928 _git_revert ()
2930 __git_find_repo_path
2931 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2932 __gitcomp "$__git_revert_inprogress_options"
2933 return
2935 __git_complete_strategy && return
2936 case "$cur" in
2937 --*)
2938 __gitcomp_builtin revert "" \
2939 "$__git_revert_inprogress_options"
2940 return
2942 esac
2943 __git_complete_refs
2946 _git_rm ()
2948 case "$cur" in
2949 --*)
2950 __gitcomp_builtin rm
2951 return
2953 esac
2955 __git_complete_index_file "--cached"
2958 _git_shortlog ()
2960 __git_has_doubledash && return
2962 case "$cur" in
2963 --*)
2964 __gitcomp "
2965 $__git_log_common_options
2966 $__git_log_shortlog_options
2967 --numbered --summary --email
2969 return
2971 esac
2972 __git_complete_revlist
2975 _git_show ()
2977 __git_has_doubledash && return
2979 case "$cur" in
2980 --pretty=*|--format=*)
2981 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2982 " "" "${cur#*=}"
2983 return
2985 --diff-algorithm=*)
2986 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2987 return
2989 --submodule=*)
2990 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2991 return
2993 --color-moved=*)
2994 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
2995 return
2997 --color-moved-ws=*)
2998 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
2999 return
3001 --*)
3002 __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
3003 --oneline --show-signature
3004 --expand-tabs --expand-tabs= --no-expand-tabs
3005 $__git_diff_common_options
3007 return
3009 esac
3010 __git_complete_revlist_file
3013 _git_show_branch ()
3015 case "$cur" in
3016 --*)
3017 __gitcomp_builtin show-branch
3018 return
3020 esac
3021 __git_complete_revlist
3024 __gitcomp_directories ()
3026 local _tmp_dir _tmp_completions _found=0
3028 # Get the directory of the current token; this differs from dirname
3029 # in that it keeps up to the final trailing slash. If no slash found
3030 # that's fine too.
3031 [[ "$cur" =~ .*/ ]]
3032 _tmp_dir=$BASH_REMATCH
3034 # Find possible directory completions, adding trailing '/' characters,
3035 # de-quoting, and handling unusual characters.
3036 while IFS= read -r -d $'\0' c ; do
3037 # If there are directory completions, find ones that start
3038 # with "$cur", the current token, and put those in COMPREPLY
3039 if [[ $c == "$cur"* ]]; then
3040 COMPREPLY+=("$c/")
3041 _found=1
3043 done < <(git ls-tree -z -d --name-only HEAD $_tmp_dir)
3045 if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then
3046 # No possible further completions any deeper, so assume we're at
3047 # a leaf directory and just consider it complete
3048 __gitcomp_direct_append "$cur "
3052 _git_sparse_checkout ()
3054 local subcommands="list init set disable add reapply"
3055 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3056 if [ -z "$subcommand" ]; then
3057 __gitcomp "$subcommands"
3058 return
3061 case "$subcommand,$cur" in
3062 *,--*)
3063 __gitcomp_builtin sparse-checkout_$subcommand "" "--"
3065 set,*|add,*)
3066 if [ "$(__git config core.sparseCheckoutCone)" == "true" ] ||
3067 [ -n "$(__git_find_on_cmdline --cone)" ]; then
3068 __gitcomp_directories
3070 esac
3073 _git_stash ()
3075 local subcommands='push list show apply clear drop pop create branch'
3076 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3078 if [ -z "$subcommand" ]; then
3079 case "$((cword - __git_cmd_idx)),$cur" in
3080 *,--*)
3081 __gitcomp_builtin stash_push
3083 1,sa*)
3084 __gitcomp "save"
3086 1,*)
3087 __gitcomp "$subcommands"
3089 esac
3090 return
3093 case "$subcommand,$cur" in
3094 list,--*)
3095 # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3096 __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
3098 show,--*)
3099 __gitcomp_builtin stash_show "$__git_diff_common_options"
3101 *,--*)
3102 __gitcomp_builtin "stash_$subcommand"
3104 branch,*)
3105 if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3106 __git_complete_refs
3107 else
3108 __gitcomp_nl "$(__git stash list \
3109 | sed -n -e 's/:.*//p')"
3112 show,*|apply,*|drop,*|pop,*)
3113 __gitcomp_nl "$(__git stash list \
3114 | sed -n -e 's/:.*//p')"
3116 esac
3119 _git_submodule ()
3121 __git_has_doubledash && return
3123 local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
3124 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3125 if [ -z "$subcommand" ]; then
3126 case "$cur" in
3127 --*)
3128 __gitcomp "--quiet"
3131 __gitcomp "$subcommands"
3133 esac
3134 return
3137 case "$subcommand,$cur" in
3138 add,--*)
3139 __gitcomp "--branch --force --name --reference --depth"
3141 status,--*)
3142 __gitcomp "--cached --recursive"
3144 deinit,--*)
3145 __gitcomp "--force --all"
3147 update,--*)
3148 __gitcomp "
3149 --init --remote --no-fetch
3150 --recommend-shallow --no-recommend-shallow
3151 --force --rebase --merge --reference --depth --recursive --jobs
3154 set-branch,--*)
3155 __gitcomp "--default --branch"
3157 summary,--*)
3158 __gitcomp "--cached --files --summary-limit"
3160 foreach,--*|sync,--*)
3161 __gitcomp "--recursive"
3165 esac
3168 _git_svn ()
3170 local subcommands="
3171 init fetch clone rebase dcommit log find-rev
3172 set-tree commit-diff info create-ignore propget
3173 proplist show-ignore show-externals branch tag blame
3174 migrate mkdirs reset gc
3176 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3177 if [ -z "$subcommand" ]; then
3178 __gitcomp "$subcommands"
3179 else
3180 local remote_opts="--username= --config-dir= --no-auth-cache"
3181 local fc_opts="
3182 --follow-parent --authors-file= --repack=
3183 --no-metadata --use-svm-props --use-svnsync-props
3184 --log-window-size= --no-checkout --quiet
3185 --repack-flags --use-log-author --localtime
3186 --add-author-from
3187 --recursive
3188 --ignore-paths= --include-paths= $remote_opts
3190 local init_opts="
3191 --template= --shared= --trunk= --tags=
3192 --branches= --stdlayout --minimize-url
3193 --no-metadata --use-svm-props --use-svnsync-props
3194 --rewrite-root= --prefix= $remote_opts
3196 local cmt_opts="
3197 --edit --rmdir --find-copies-harder --copy-similarity=
3200 case "$subcommand,$cur" in
3201 fetch,--*)
3202 __gitcomp "--revision= --fetch-all $fc_opts"
3204 clone,--*)
3205 __gitcomp "--revision= $fc_opts $init_opts"
3207 init,--*)
3208 __gitcomp "$init_opts"
3210 dcommit,--*)
3211 __gitcomp "
3212 --merge --strategy= --verbose --dry-run
3213 --fetch-all --no-rebase --commit-url
3214 --revision --interactive $cmt_opts $fc_opts
3217 set-tree,--*)
3218 __gitcomp "--stdin $cmt_opts $fc_opts"
3220 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
3221 show-externals,--*|mkdirs,--*)
3222 __gitcomp "--revision="
3224 log,--*)
3225 __gitcomp "
3226 --limit= --revision= --verbose --incremental
3227 --oneline --show-commit --non-recursive
3228 --authors-file= --color
3231 rebase,--*)
3232 __gitcomp "
3233 --merge --verbose --strategy= --local
3234 --fetch-all --dry-run $fc_opts
3237 commit-diff,--*)
3238 __gitcomp "--message= --file= --revision= $cmt_opts"
3240 info,--*)
3241 __gitcomp "--url"
3243 branch,--*)
3244 __gitcomp "--dry-run --message --tag"
3246 tag,--*)
3247 __gitcomp "--dry-run --message"
3249 blame,--*)
3250 __gitcomp "--git-format"
3252 migrate,--*)
3253 __gitcomp "
3254 --config-dir= --ignore-paths= --minimize
3255 --no-auth-cache --username=
3258 reset,--*)
3259 __gitcomp "--revision= --parent"
3263 esac
3267 _git_tag ()
3269 local i c="$__git_cmd_idx" f=0
3270 while [ $c -lt $cword ]; do
3271 i="${words[c]}"
3272 case "$i" in
3273 -d|--delete|-v|--verify)
3274 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3275 return
3280 esac
3281 ((c++))
3282 done
3284 case "$prev" in
3285 -m|-F)
3287 -*|tag)
3288 if [ $f = 1 ]; then
3289 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3293 __git_complete_refs
3295 esac
3297 case "$cur" in
3298 --*)
3299 __gitcomp_builtin tag
3301 esac
3304 _git_whatchanged ()
3306 _git_log
3309 __git_complete_worktree_paths ()
3311 local IFS=$'\n'
3312 # Generate completion reply from worktree list skipping the first
3313 # entry: it's the path of the main worktree, which can't be moved,
3314 # removed, locked, etc.
3315 __gitcomp_nl "$(git worktree list --porcelain |
3316 sed -n -e '2,$ s/^worktree //p')"
3319 _git_worktree ()
3321 local subcommands="add list lock move prune remove unlock"
3322 local subcommand subcommand_idx
3324 subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3325 subcommand_idx="${subcommand% *}"
3326 subcommand="${subcommand#* }"
3328 case "$subcommand,$cur" in
3330 __gitcomp "$subcommands"
3332 *,--*)
3333 __gitcomp_builtin worktree_$subcommand
3335 add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
3336 # Here we are not completing an --option, it's either the
3337 # path or a ref.
3338 case "$prev" in
3339 -b|-B) # Complete refs for branch to be created/reseted.
3340 __git_complete_refs
3342 -*) # The previous word is an -o|--option without an
3343 # unstuck argument: have to complete the path for
3344 # the new worktree, so don't list anything, but let
3345 # Bash fall back to filename completion.
3347 *) # The previous word is not an --option, so it must
3348 # be either the 'add' subcommand, the unstuck
3349 # argument of an option (e.g. branch for -b|-B), or
3350 # the path for the new worktree.
3351 if [ $cword -eq $((subcommand_idx+1)) ]; then
3352 # Right after the 'add' subcommand: have to
3353 # complete the path, so fall back to Bash
3354 # filename completion.
3356 else
3357 case "${words[cword-2]}" in
3358 -b|-B) # After '-b <branch>': have to
3359 # complete the path, so fall back
3360 # to Bash filename completion.
3362 *) # After the path: have to complete
3363 # the ref to be checked out.
3364 __git_complete_refs
3366 esac
3369 esac
3371 lock,*|remove,*|unlock,*)
3372 __git_complete_worktree_paths
3374 move,*)
3375 if [ $cword -eq $((subcommand_idx+1)) ]; then
3376 # The first parameter must be an existing working
3377 # tree to be moved.
3378 __git_complete_worktree_paths
3379 else
3380 # The second parameter is the destination: it could
3381 # be any path, so don't list anything, but let Bash
3382 # fall back to filename completion.
3386 esac
3389 __git_complete_common () {
3390 local command="$1"
3392 case "$cur" in
3393 --*)
3394 __gitcomp_builtin "$command"
3396 esac
3399 __git_cmds_with_parseopt_helper=
3400 __git_support_parseopt_helper () {
3401 test -n "$__git_cmds_with_parseopt_helper" ||
3402 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
3404 case " $__git_cmds_with_parseopt_helper " in
3405 *" $1 "*)
3406 return 0
3409 return 1
3411 esac
3414 __git_have_func () {
3415 declare -f -- "$1" >/dev/null 2>&1
3418 __git_complete_command () {
3419 local command="$1"
3420 local completion_func="_git_${command//-/_}"
3421 if ! __git_have_func $completion_func &&
3422 __git_have_func _completion_loader
3423 then
3424 _completion_loader "git-$command"
3426 if __git_have_func $completion_func
3427 then
3428 $completion_func
3429 return 0
3430 elif __git_support_parseopt_helper "$command"
3431 then
3432 __git_complete_common "$command"
3433 return 0
3434 else
3435 return 1
3439 __git_main ()
3441 local i c=1 command __git_dir __git_repo_path
3442 local __git_C_args C_args_count=0
3443 local __git_cmd_idx
3445 while [ $c -lt $cword ]; do
3446 i="${words[c]}"
3447 case "$i" in
3448 --git-dir=*)
3449 __git_dir="${i#--git-dir=}"
3451 --git-dir)
3452 ((c++))
3453 __git_dir="${words[c]}"
3455 --bare)
3456 __git_dir="."
3458 --help)
3459 command="help"
3460 break
3462 -c|--work-tree|--namespace)
3463 ((c++))
3466 __git_C_args[C_args_count++]=-C
3467 ((c++))
3468 __git_C_args[C_args_count++]="${words[c]}"
3473 command="$i"
3474 __git_cmd_idx="$c"
3475 break
3477 esac
3478 ((c++))
3479 done
3481 if [ -z "${command-}" ]; then
3482 case "$prev" in
3483 --git-dir|-C|--work-tree)
3484 # these need a path argument, let's fall back to
3485 # Bash filename completion
3486 return
3489 __git_complete_config_variable_name_and_value
3490 return
3492 --namespace)
3493 # we don't support completing these options' arguments
3494 return
3496 esac
3497 case "$cur" in
3498 --*)
3499 __gitcomp "
3500 --paginate
3501 --no-pager
3502 --git-dir=
3503 --bare
3504 --version
3505 --exec-path
3506 --exec-path=
3507 --html-path
3508 --man-path
3509 --info-path
3510 --work-tree=
3511 --namespace=
3512 --no-replace-objects
3513 --help
3517 if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3518 then
3519 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3520 else
3521 local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
3523 if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
3524 then
3525 list_cmds=builtins,$list_cmds
3527 __gitcomp "$(__git --list-cmds=$list_cmds)"
3530 esac
3531 return
3534 __git_complete_command "$command" && return
3536 local expansion=$(__git_aliased_command "$command")
3537 if [ -n "$expansion" ]; then
3538 words[1]=$expansion
3539 __git_complete_command "$expansion"
3543 __gitk_main ()
3545 __git_has_doubledash && return
3547 local __git_repo_path
3548 __git_find_repo_path
3550 local merge=""
3551 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3552 merge="--merge"
3554 case "$cur" in
3555 --*)
3556 __gitcomp "
3557 $__git_log_common_options
3558 $__git_log_gitk_options
3559 $merge
3561 return
3563 esac
3564 __git_complete_revlist
3567 if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
3568 echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
3569 return
3572 __git_func_wrap ()
3574 local cur words cword prev
3575 local __git_cmd_idx=0
3576 _get_comp_words_by_ref -n =: cur words cword prev
3580 ___git_complete ()
3582 local wrapper="__git_wrap${2}"
3583 eval "$wrapper () { __git_func_wrap $2 ; }"
3584 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3585 || complete -o default -o nospace -F $wrapper $1
3588 # Setup the completion for git commands
3589 # 1: command or alias
3590 # 2: function to call (e.g. `git`, `gitk`, `git_fetch`)
3591 __git_complete ()
3593 local func
3595 if __git_have_func $2; then
3596 func=$2
3597 elif __git_have_func __$2_main; then
3598 func=__$2_main
3599 elif __git_have_func _$2; then
3600 func=_$2
3601 else
3602 echo "ERROR: could not find function '$2'" 1>&2
3603 return 1
3605 ___git_complete $1 $func
3608 ___git_complete git __git_main
3609 ___git_complete gitk __gitk_main
3611 # The following are necessary only for Cygwin, and only are needed
3612 # when the user has tab-completed the executable name and consequently
3613 # included the '.exe' suffix.
3615 if [ "$OSTYPE" = cygwin ]; then
3616 ___git_complete git.exe __git_main