Merge branch 'nd/completion-negation'
[git.git] / contrib / completion / git-completion.bash
blob94c95516ebec7f32787cc5a2fb45cae83c7e28e3
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
43 *:*) : great ;;
44 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
45 esac
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
49 # variable.
50 __git_find_repo_path ()
52 if [ -n "$__git_repo_path" ]; then
53 # we already know where it is
54 return
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
68 __git_repo_path=.git
69 else
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
77 __gitdir ()
79 if [ -z "${1-}" ]; then
80 __git_find_repo_path || return 1
81 echo "$__git_repo_path"
82 elif [ -d "$1/.git" ]; then
83 echo "$1/.git"
84 else
85 echo "$1"
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
91 __git ()
93 git ${__git_C_args:+"${__git_C_args[@]}"} \
94 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
97 # Removes backslash escaping, single quotes and double quotes from a word,
98 # stores the result in the variable $dequoted_word.
99 # 1: The word to dequote.
100 __git_dequote ()
102 local rest="$1" len ch
104 dequoted_word=""
106 while test -n "$rest"; do
107 len=${#dequoted_word}
108 dequoted_word="$dequoted_word${rest%%[\\\'\"]*}"
109 rest="${rest:$((${#dequoted_word}-$len))}"
111 case "${rest:0:1}" in
113 ch="${rest:1:1}"
114 case "$ch" in
115 $'\n')
118 dequoted_word="$dequoted_word$ch"
120 esac
121 rest="${rest:2}"
124 rest="${rest:1}"
125 len=${#dequoted_word}
126 dequoted_word="$dequoted_word${rest%%\'*}"
127 rest="${rest:$((${#dequoted_word}-$len+1))}"
130 rest="${rest:1}"
131 while test -n "$rest" ; do
132 len=${#dequoted_word}
133 dequoted_word="$dequoted_word${rest%%[\\\"]*}"
134 rest="${rest:$((${#dequoted_word}-$len))}"
135 case "${rest:0:1}" in
137 ch="${rest:1:1}"
138 case "$ch" in
139 \"|\\|\$|\`)
140 dequoted_word="$dequoted_word$ch"
142 $'\n')
145 dequoted_word="$dequoted_word\\$ch"
147 esac
148 rest="${rest:2}"
151 rest="${rest:1}"
152 break
154 esac
155 done
157 esac
158 done
161 # The following function is based on code from:
163 # bash_completion - programmable completion functions for bash 3.2+
165 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
166 # © 2009-2010, Bash Completion Maintainers
167 # <bash-completion-devel@lists.alioth.debian.org>
169 # This program is free software; you can redistribute it and/or modify
170 # it under the terms of the GNU General Public License as published by
171 # the Free Software Foundation; either version 2, or (at your option)
172 # any later version.
174 # This program is distributed in the hope that it will be useful,
175 # but WITHOUT ANY WARRANTY; without even the implied warranty of
176 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
177 # GNU General Public License for more details.
179 # You should have received a copy of the GNU General Public License
180 # along with this program; if not, see <http://www.gnu.org/licenses/>.
182 # The latest version of this software can be obtained here:
184 # http://bash-completion.alioth.debian.org/
186 # RELEASE: 2.x
188 # This function can be used to access a tokenized list of words
189 # on the command line:
191 # __git_reassemble_comp_words_by_ref '=:'
192 # if test "${words_[cword_-1]}" = -w
193 # then
194 # ...
195 # fi
197 # The argument should be a collection of characters from the list of
198 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
199 # characters.
201 # This is roughly equivalent to going back in time and setting
202 # COMP_WORDBREAKS to exclude those characters. The intent is to
203 # make option types like --date=<type> and <rev>:<path> easy to
204 # recognize by treating each shell word as a single token.
206 # It is best not to set COMP_WORDBREAKS directly because the value is
207 # shared with other completion scripts. By the time the completion
208 # function gets called, COMP_WORDS has already been populated so local
209 # changes to COMP_WORDBREAKS have no effect.
211 # Output: words_, cword_, cur_.
213 __git_reassemble_comp_words_by_ref()
215 local exclude i j first
216 # Which word separators to exclude?
217 exclude="${1//[^$COMP_WORDBREAKS]}"
218 cword_=$COMP_CWORD
219 if [ -z "$exclude" ]; then
220 words_=("${COMP_WORDS[@]}")
221 return
223 # List of word completion separators has shrunk;
224 # re-assemble words to complete.
225 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
226 # Append each nonempty word consisting of just
227 # word separator characters to the current word.
228 first=t
229 while
230 [ $i -gt 0 ] &&
231 [ -n "${COMP_WORDS[$i]}" ] &&
232 # word consists of excluded word separators
233 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
235 # Attach to the previous token,
236 # unless the previous token is the command name.
237 if [ $j -ge 2 ] && [ -n "$first" ]; then
238 ((j--))
240 first=
241 words_[$j]=${words_[j]}${COMP_WORDS[i]}
242 if [ $i = $COMP_CWORD ]; then
243 cword_=$j
245 if (($i < ${#COMP_WORDS[@]} - 1)); then
246 ((i++))
247 else
248 # Done.
249 return
251 done
252 words_[$j]=${words_[j]}${COMP_WORDS[i]}
253 if [ $i = $COMP_CWORD ]; then
254 cword_=$j
256 done
259 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
260 _get_comp_words_by_ref ()
262 local exclude cur_ words_ cword_
263 if [ "$1" = "-n" ]; then
264 exclude=$2
265 shift 2
267 __git_reassemble_comp_words_by_ref "$exclude"
268 cur_=${words_[cword_]}
269 while [ $# -gt 0 ]; do
270 case "$1" in
271 cur)
272 cur=$cur_
274 prev)
275 prev=${words_[$cword_-1]}
277 words)
278 words=("${words_[@]}")
280 cword)
281 cword=$cword_
283 esac
284 shift
285 done
289 # Fills the COMPREPLY array with prefiltered words without any additional
290 # processing.
291 # Callers must take care of providing only words that match the current word
292 # to be completed and adding any prefix and/or suffix (trailing space!), if
293 # necessary.
294 # 1: List of newline-separated matching completion words, complete with
295 # prefix and suffix.
296 __gitcomp_direct ()
298 local IFS=$'\n'
300 COMPREPLY=($1)
303 __gitcompappend ()
305 local x i=${#COMPREPLY[@]}
306 for x in $1; do
307 if [[ "$x" == "$3"* ]]; then
308 COMPREPLY[i++]="$2$x$4"
310 done
313 __gitcompadd ()
315 COMPREPLY=()
316 __gitcompappend "$@"
319 # Generates completion reply, appending a space to possible completion words,
320 # if necessary.
321 # It accepts 1 to 4 arguments:
322 # 1: List of possible completion words.
323 # 2: A prefix to be added to each possible completion word (optional).
324 # 3: Generate possible completion matches for this word (optional).
325 # 4: A suffix to be appended to each possible completion word (optional).
326 __gitcomp ()
328 local cur_="${3-$cur}"
330 case "$cur_" in
331 --*=)
333 --no-*)
334 local c i=0 IFS=$' \t\n'
335 for c in $1; do
336 if [[ $c == "--" ]]; then
337 continue
339 c="$c${4-}"
340 if [[ $c == "$cur_"* ]]; then
341 case $c in
342 --*=*|*.) ;;
343 *) c="$c " ;;
344 esac
345 COMPREPLY[i++]="${2-}$c"
347 done
350 local c i=0 IFS=$' \t\n'
351 for c in $1; do
352 if [[ $c == "--" ]]; then
353 c="--no-...${4-}"
354 if [[ $c == "$cur_"* ]]; then
355 COMPREPLY[i++]="${2-}$c "
357 break
359 c="$c${4-}"
360 if [[ $c == "$cur_"* ]]; then
361 case $c in
362 --*=*|*.) ;;
363 *) c="$c " ;;
364 esac
365 COMPREPLY[i++]="${2-}$c"
367 done
369 esac
372 # Clear the variables caching builtins' options when (re-)sourcing
373 # the completion script.
374 if [[ -n ${ZSH_VERSION-} ]]; then
375 unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
376 else
377 unset $(compgen -v __gitcomp_builtin_)
380 # This function is equivalent to
382 # __gitcomp "$(git xxx --git-completion-helper) ..."
384 # except that the output is cached. Accept 1-3 arguments:
385 # 1: the git command to execute, this is also the cache key
386 # 2: extra options to be added on top (e.g. negative forms)
387 # 3: options to be excluded
388 __gitcomp_builtin ()
390 # spaces must be replaced with underscore for multi-word
391 # commands, e.g. "git remote add" becomes remote_add.
392 local cmd="$1"
393 local incl="$2"
394 local excl="$3"
396 local var=__gitcomp_builtin_"${cmd/-/_}"
397 local options
398 eval "options=\$$var"
400 if [ -z "$options" ]; then
401 # leading and trailing spaces are significant to make
402 # option removal work correctly.
403 options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
404 for i in $excl; do
405 options="${options/ $i / }"
406 done
407 eval "$var=\"$options\""
410 __gitcomp "$options"
413 # Variation of __gitcomp_nl () that appends to the existing list of
414 # completion candidates, COMPREPLY.
415 __gitcomp_nl_append ()
417 local IFS=$'\n'
418 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
421 # Generates completion reply from newline-separated possible completion words
422 # by appending a space to all of them.
423 # It accepts 1 to 4 arguments:
424 # 1: List of possible completion words, separated by a single newline.
425 # 2: A prefix to be added to each possible completion word (optional).
426 # 3: Generate possible completion matches for this word (optional).
427 # 4: A suffix to be appended to each possible completion word instead of
428 # the default space (optional). If specified but empty, nothing is
429 # appended.
430 __gitcomp_nl ()
432 COMPREPLY=()
433 __gitcomp_nl_append "$@"
436 # Fills the COMPREPLY array with prefiltered paths without any additional
437 # processing.
438 # Callers must take care of providing only paths that match the current path
439 # to be completed and adding any prefix path components, if necessary.
440 # 1: List of newline-separated matching paths, complete with all prefix
441 # path componens.
442 __gitcomp_file_direct ()
444 local IFS=$'\n'
446 COMPREPLY=($1)
448 # use a hack to enable file mode in bash < 4
449 compopt -o filenames +o nospace 2>/dev/null ||
450 compgen -f /non-existing-dir/ >/dev/null ||
451 true
454 # Generates completion reply with compgen from newline-separated possible
455 # completion filenames.
456 # It accepts 1 to 3 arguments:
457 # 1: List of possible completion filenames, separated by a single newline.
458 # 2: A directory prefix to be added to each possible completion filename
459 # (optional).
460 # 3: Generate possible completion matches for this word (optional).
461 __gitcomp_file ()
463 local IFS=$'\n'
465 # XXX does not work when the directory prefix contains a tilde,
466 # since tilde expansion is not applied.
467 # This means that COMPREPLY will be empty and Bash default
468 # completion will be used.
469 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
471 # use a hack to enable file mode in bash < 4
472 compopt -o filenames +o nospace 2>/dev/null ||
473 compgen -f /non-existing-dir/ >/dev/null ||
474 true
477 # Execute 'git ls-files', unless the --committable option is specified, in
478 # which case it runs 'git diff-index' to find out the files that can be
479 # committed. It return paths relative to the directory specified in the first
480 # argument, and using the options specified in the second argument.
481 __git_ls_files_helper ()
483 if [ "$2" == "--committable" ]; then
484 __git -C "$1" -c core.quotePath=false diff-index \
485 --name-only --relative HEAD -- "${3//\\/\\\\}*"
486 else
487 # NOTE: $2 is not quoted in order to support multiple options
488 __git -C "$1" -c core.quotePath=false ls-files \
489 --exclude-standard $2 -- "${3//\\/\\\\}*"
494 # __git_index_files accepts 1 or 2 arguments:
495 # 1: Options to pass to ls-files (required).
496 # 2: A directory path (optional).
497 # If provided, only files within the specified directory are listed.
498 # Sub directories are never recursed. Path must have a trailing
499 # slash.
500 # 3: List only paths matching this path component (optional).
501 __git_index_files ()
503 local root="$2" match="$3"
505 __git_ls_files_helper "$root" "$1" "$match" |
506 awk -F / -v pfx="${2//\\/\\\\}" '{
507 paths[$1] = 1
509 END {
510 for (p in paths) {
511 if (substr(p, 1, 1) != "\"") {
512 # No special characters, easy!
513 print pfx p
514 continue
517 # The path is quoted.
518 p = dequote(p)
519 if (p == "")
520 continue
522 # Even when a directory name itself does not contain
523 # any special characters, it will still be quoted if
524 # any of its (stripped) trailing path components do.
525 # Because of this we may have seen the same direcory
526 # both quoted and unquoted.
527 if (p in paths)
528 # We have seen the same directory unquoted,
529 # skip it.
530 continue
531 else
532 print pfx p
535 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
536 # Skip opening double quote.
537 p = substr(p, 2)
539 # Interpret backslash escape sequences.
540 while ((bs_idx = index(p, "\\")) != 0) {
541 out = out substr(p, 1, bs_idx - 1)
542 esc = substr(p, bs_idx + 1, 1)
543 p = substr(p, bs_idx + 2)
545 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
546 # C-style one-character escape sequence.
547 out = out substr("\a\b\t\v\f\r\"\\",
548 esc_idx, 1)
549 } else if (esc == "n") {
550 # Uh-oh, a newline character.
551 # We cant reliably put a pathname
552 # containing a newline into COMPREPLY,
553 # and the newline would create a mess.
554 # Skip this path.
555 return ""
556 } else {
557 # Must be a \nnn octal value, then.
558 dec = esc * 64 + \
559 substr(p, 1, 1) * 8 + \
560 substr(p, 2, 1)
561 out = out sprintf("%c", dec)
562 p = substr(p, 3)
565 # Drop closing double quote, if there is one.
566 # (There isnt any if this is a directory, as it was
567 # already stripped with the trailing path components.)
568 if (substr(p, length(p), 1) == "\"")
569 out = out substr(p, 1, length(p) - 1)
570 else
571 out = out p
573 return out
577 # __git_complete_index_file requires 1 argument:
578 # 1: the options to pass to ls-file
580 # The exception is --committable, which finds the files appropriate commit.
581 __git_complete_index_file ()
583 local dequoted_word pfx="" cur_
585 __git_dequote "$cur"
587 case "$dequoted_word" in
588 ?*/*)
589 pfx="${dequoted_word%/*}/"
590 cur_="${dequoted_word##*/}"
593 cur_="$dequoted_word"
594 esac
596 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
599 # Lists branches from the local repository.
600 # 1: A prefix to be added to each listed branch (optional).
601 # 2: List only branches matching this word (optional; list all branches if
602 # unset or empty).
603 # 3: A suffix to be appended to each listed branch (optional).
604 __git_heads ()
606 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
608 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
609 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
612 # Lists tags from the local repository.
613 # Accepts the same positional parameters as __git_heads() above.
614 __git_tags ()
616 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
618 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
619 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
622 # Lists refs from the local (by default) or from a remote repository.
623 # It accepts 0, 1 or 2 arguments:
624 # 1: The remote to list refs from (optional; ignored, if set but empty).
625 # Can be the name of a configured remote, a path, or a URL.
626 # 2: In addition to local refs, list unique branches from refs/remotes/ for
627 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
628 # 3: A prefix to be added to each listed ref (optional).
629 # 4: List only refs matching this word (optional; list all refs if unset or
630 # empty).
631 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
632 # but empty).
634 # Use __git_complete_refs() instead.
635 __git_refs ()
637 local i hash dir track="${2-}"
638 local list_refs_from=path remote="${1-}"
639 local format refs
640 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
641 local match="${4-}"
642 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
644 __git_find_repo_path
645 dir="$__git_repo_path"
647 if [ -z "$remote" ]; then
648 if [ -z "$dir" ]; then
649 return
651 else
652 if __git_is_configured_remote "$remote"; then
653 # configured remote takes precedence over a
654 # local directory with the same name
655 list_refs_from=remote
656 elif [ -d "$remote/.git" ]; then
657 dir="$remote/.git"
658 elif [ -d "$remote" ]; then
659 dir="$remote"
660 else
661 list_refs_from=url
665 if [ "$list_refs_from" = path ]; then
666 if [[ "$cur_" == ^* ]]; then
667 pfx="$pfx^"
668 fer_pfx="$fer_pfx^"
669 cur_=${cur_#^}
670 match=${match#^}
672 case "$cur_" in
673 refs|refs/*)
674 format="refname"
675 refs=("$match*" "$match*/**")
676 track=""
679 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
680 case "$i" in
681 $match*)
682 if [ -e "$dir/$i" ]; then
683 echo "$pfx$i$sfx"
686 esac
687 done
688 format="refname:strip=2"
689 refs=("refs/tags/$match*" "refs/tags/$match*/**"
690 "refs/heads/$match*" "refs/heads/$match*/**"
691 "refs/remotes/$match*" "refs/remotes/$match*/**")
693 esac
694 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
695 "${refs[@]}"
696 if [ -n "$track" ]; then
697 # employ the heuristic used by git checkout
698 # Try to find a remote branch that matches the completion word
699 # but only output if the branch name is unique
700 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
701 --sort="refname:strip=3" \
702 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
703 uniq -u
705 return
707 case "$cur_" in
708 refs|refs/*)
709 __git ls-remote "$remote" "$match*" | \
710 while read -r hash i; do
711 case "$i" in
712 *^{}) ;;
713 *) echo "$pfx$i$sfx" ;;
714 esac
715 done
718 if [ "$list_refs_from" = remote ]; then
719 case "HEAD" in
720 $match*) echo "${pfx}HEAD$sfx" ;;
721 esac
722 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
723 "refs/remotes/$remote/$match*" \
724 "refs/remotes/$remote/$match*/**"
725 else
726 local query_symref
727 case "HEAD" in
728 $match*) query_symref="HEAD" ;;
729 esac
730 __git ls-remote "$remote" $query_symref \
731 "refs/tags/$match*" "refs/heads/$match*" \
732 "refs/remotes/$match*" |
733 while read -r hash i; do
734 case "$i" in
735 *^{}) ;;
736 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
737 *) echo "$pfx$i$sfx" ;; # symbolic refs
738 esac
739 done
742 esac
745 # Completes refs, short and long, local and remote, symbolic and pseudo.
747 # Usage: __git_complete_refs [<option>]...
748 # --remote=<remote>: The remote to list refs from, can be the name of a
749 # configured remote, a path, or a URL.
750 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
751 # --pfx=<prefix>: A prefix to be added to each ref.
752 # --cur=<word>: The current ref to be completed. Defaults to the current
753 # word to be completed.
754 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
755 # space.
756 __git_complete_refs ()
758 local remote track pfx cur_="$cur" sfx=" "
760 while test $# != 0; do
761 case "$1" in
762 --remote=*) remote="${1##--remote=}" ;;
763 --track) track="yes" ;;
764 --pfx=*) pfx="${1##--pfx=}" ;;
765 --cur=*) cur_="${1##--cur=}" ;;
766 --sfx=*) sfx="${1##--sfx=}" ;;
767 *) return 1 ;;
768 esac
769 shift
770 done
772 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
775 # __git_refs2 requires 1 argument (to pass to __git_refs)
776 # Deprecated: use __git_complete_fetch_refspecs() instead.
777 __git_refs2 ()
779 local i
780 for i in $(__git_refs "$1"); do
781 echo "$i:$i"
782 done
785 # Completes refspecs for fetching from a remote repository.
786 # 1: The remote repository.
787 # 2: A prefix to be added to each listed refspec (optional).
788 # 3: The ref to be completed as a refspec instead of the current word to be
789 # completed (optional)
790 # 4: A suffix to be appended to each listed refspec instead of the default
791 # space (optional).
792 __git_complete_fetch_refspecs ()
794 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
796 __gitcomp_direct "$(
797 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
798 echo "$pfx$i:$i$sfx"
799 done
803 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
804 __git_refs_remotes ()
806 local i hash
807 __git ls-remote "$1" 'refs/heads/*' | \
808 while read -r hash i; do
809 echo "$i:refs/remotes/$1/${i#refs/heads/}"
810 done
813 __git_remotes ()
815 __git_find_repo_path
816 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
817 __git remote
820 # Returns true if $1 matches the name of a configured remote, false otherwise.
821 __git_is_configured_remote ()
823 local remote
824 for remote in $(__git_remotes); do
825 if [ "$remote" = "$1" ]; then
826 return 0
828 done
829 return 1
832 __git_list_merge_strategies ()
834 LANG=C LC_ALL=C git merge -s help 2>&1 |
835 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
836 s/\.$//
837 s/.*://
838 s/^[ ]*//
839 s/[ ]*$//
844 __git_merge_strategies=
845 # 'git merge -s help' (and thus detection of the merge strategy
846 # list) fails, unfortunately, if run outside of any git working
847 # tree. __git_merge_strategies is set to the empty string in
848 # that case, and the detection will be repeated the next time it
849 # is needed.
850 __git_compute_merge_strategies ()
852 test -n "$__git_merge_strategies" ||
853 __git_merge_strategies=$(__git_list_merge_strategies)
856 __git_complete_revlist_file ()
858 local pfx ls ref cur_="$cur"
859 case "$cur_" in
860 *..?*:*)
861 return
863 ?*:*)
864 ref="${cur_%%:*}"
865 cur_="${cur_#*:}"
866 case "$cur_" in
867 ?*/*)
868 pfx="${cur_%/*}"
869 cur_="${cur_##*/}"
870 ls="$ref:$pfx"
871 pfx="$pfx/"
874 ls="$ref"
876 esac
878 case "$COMP_WORDBREAKS" in
879 *:*) : great ;;
880 *) pfx="$ref:$pfx" ;;
881 esac
883 __gitcomp_nl "$(__git ls-tree "$ls" \
884 | sed '/^100... blob /{
885 s,^.* ,,
886 s,$, ,
888 /^120000 blob /{
889 s,^.* ,,
890 s,$, ,
892 /^040000 tree /{
893 s,^.* ,,
894 s,$,/,
896 s/^.* //')" \
897 "$pfx" "$cur_" ""
899 *...*)
900 pfx="${cur_%...*}..."
901 cur_="${cur_#*...}"
902 __git_complete_refs --pfx="$pfx" --cur="$cur_"
904 *..*)
905 pfx="${cur_%..*}.."
906 cur_="${cur_#*..}"
907 __git_complete_refs --pfx="$pfx" --cur="$cur_"
910 __git_complete_refs
912 esac
915 __git_complete_file ()
917 __git_complete_revlist_file
920 __git_complete_revlist ()
922 __git_complete_revlist_file
925 __git_complete_remote_or_refspec ()
927 local cur_="$cur" cmd="${words[1]}"
928 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
929 if [ "$cmd" = "remote" ]; then
930 ((c++))
932 while [ $c -lt $cword ]; do
933 i="${words[c]}"
934 case "$i" in
935 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
936 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
937 --all)
938 case "$cmd" in
939 push) no_complete_refspec=1 ;;
940 fetch)
941 return
943 *) ;;
944 esac
946 -*) ;;
947 *) remote="$i"; break ;;
948 esac
949 ((c++))
950 done
951 if [ -z "$remote" ]; then
952 __gitcomp_nl "$(__git_remotes)"
953 return
955 if [ $no_complete_refspec = 1 ]; then
956 return
958 [ "$remote" = "." ] && remote=
959 case "$cur_" in
960 *:*)
961 case "$COMP_WORDBREAKS" in
962 *:*) : great ;;
963 *) pfx="${cur_%%:*}:" ;;
964 esac
965 cur_="${cur_#*:}"
966 lhs=0
969 pfx="+"
970 cur_="${cur_#+}"
972 esac
973 case "$cmd" in
974 fetch)
975 if [ $lhs = 1 ]; then
976 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
977 else
978 __git_complete_refs --pfx="$pfx" --cur="$cur_"
981 pull|remote)
982 if [ $lhs = 1 ]; then
983 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
984 else
985 __git_complete_refs --pfx="$pfx" --cur="$cur_"
988 push)
989 if [ $lhs = 1 ]; then
990 __git_complete_refs --pfx="$pfx" --cur="$cur_"
991 else
992 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
995 esac
998 __git_complete_strategy ()
1000 __git_compute_merge_strategies
1001 case "$prev" in
1002 -s|--strategy)
1003 __gitcomp "$__git_merge_strategies"
1004 return 0
1005 esac
1006 case "$cur" in
1007 --strategy=*)
1008 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1009 return 0
1011 esac
1012 return 1
1015 __git_all_commands=
1016 __git_compute_all_commands ()
1018 test -n "$__git_all_commands" ||
1019 __git_all_commands=$(git --list-cmds=main,others,alias,nohelpers)
1022 # Lists all set config variables starting with the given section prefix,
1023 # with the prefix removed.
1024 __git_get_config_variables ()
1026 local section="$1" i IFS=$'\n'
1027 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1028 echo "${i#$section.}"
1029 done
1032 __git_pretty_aliases ()
1034 __git_get_config_variables "pretty"
1037 # __git_aliased_command requires 1 argument
1038 __git_aliased_command ()
1040 local word cmdline=$(__git config --get "alias.$1")
1041 for word in $cmdline; do
1042 case "$word" in
1043 \!gitk|gitk)
1044 echo "gitk"
1045 return
1047 \!*) : shell command alias ;;
1048 -*) : option ;;
1049 *=*) : setting env ;;
1050 git) : git itself ;;
1051 \(\)) : skip parens of shell function definition ;;
1052 {) : skip start of shell helper function ;;
1053 :) : skip null command ;;
1054 \'*) : skip opening quote after sh -c ;;
1056 echo "$word"
1057 return
1058 esac
1059 done
1062 # __git_find_on_cmdline requires 1 argument
1063 __git_find_on_cmdline ()
1065 local word subcommand c=1
1066 while [ $c -lt $cword ]; do
1067 word="${words[c]}"
1068 for subcommand in $1; do
1069 if [ "$subcommand" = "$word" ]; then
1070 echo "$subcommand"
1071 return
1073 done
1074 ((c++))
1075 done
1078 # Echo the value of an option set on the command line or config
1080 # $1: short option name
1081 # $2: long option name including =
1082 # $3: list of possible values
1083 # $4: config string (optional)
1085 # example:
1086 # result="$(__git_get_option_value "-d" "--do-something=" \
1087 # "yes no" "core.doSomething")"
1089 # result is then either empty (no option set) or "yes" or "no"
1091 # __git_get_option_value requires 3 arguments
1092 __git_get_option_value ()
1094 local c short_opt long_opt val
1095 local result= values config_key word
1097 short_opt="$1"
1098 long_opt="$2"
1099 values="$3"
1100 config_key="$4"
1102 ((c = $cword - 1))
1103 while [ $c -ge 0 ]; do
1104 word="${words[c]}"
1105 for val in $values; do
1106 if [ "$short_opt$val" = "$word" ] ||
1107 [ "$long_opt$val" = "$word" ]; then
1108 result="$val"
1109 break 2
1111 done
1112 ((c--))
1113 done
1115 if [ -n "$config_key" ] && [ -z "$result" ]; then
1116 result="$(__git config "$config_key")"
1119 echo "$result"
1122 __git_has_doubledash ()
1124 local c=1
1125 while [ $c -lt $cword ]; do
1126 if [ "--" = "${words[c]}" ]; then
1127 return 0
1129 ((c++))
1130 done
1131 return 1
1134 # Try to count non option arguments passed on the command line for the
1135 # specified git command.
1136 # When options are used, it is necessary to use the special -- option to
1137 # tell the implementation were non option arguments begin.
1138 # XXX this can not be improved, since options can appear everywhere, as
1139 # an example:
1140 # git mv x -n y
1142 # __git_count_arguments requires 1 argument: the git command executed.
1143 __git_count_arguments ()
1145 local word i c=0
1147 # Skip "git" (first argument)
1148 for ((i=1; i < ${#words[@]}; i++)); do
1149 word="${words[i]}"
1151 case "$word" in
1153 # Good; we can assume that the following are only non
1154 # option arguments.
1155 ((c = 0))
1157 "$1")
1158 # Skip the specified git command and discard git
1159 # main options
1160 ((c = 0))
1163 ((c++))
1165 esac
1166 done
1168 printf "%d" $c
1171 __git_whitespacelist="nowarn warn error error-all fix"
1172 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1174 _git_am ()
1176 __git_find_repo_path
1177 if [ -d "$__git_repo_path"/rebase-apply ]; then
1178 __gitcomp "$__git_am_inprogress_options"
1179 return
1181 case "$cur" in
1182 --whitespace=*)
1183 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1184 return
1186 --*)
1187 __gitcomp_builtin am "" \
1188 "$__git_am_inprogress_options"
1189 return
1190 esac
1193 _git_apply ()
1195 case "$cur" in
1196 --whitespace=*)
1197 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1198 return
1200 --*)
1201 __gitcomp_builtin apply
1202 return
1203 esac
1206 _git_add ()
1208 case "$cur" in
1209 --*)
1210 __gitcomp_builtin add
1211 return
1212 esac
1214 local complete_opt="--others --modified --directory --no-empty-directory"
1215 if test -n "$(__git_find_on_cmdline "-u --update")"
1216 then
1217 complete_opt="--modified"
1219 __git_complete_index_file "$complete_opt"
1222 _git_archive ()
1224 case "$cur" in
1225 --format=*)
1226 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1227 return
1229 --remote=*)
1230 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1231 return
1233 --*)
1234 __gitcomp "
1235 --format= --list --verbose
1236 --prefix= --remote= --exec= --output
1238 return
1240 esac
1241 __git_complete_file
1244 _git_bisect ()
1246 __git_has_doubledash && return
1248 local subcommands="start bad good skip reset visualize replay log run"
1249 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1250 if [ -z "$subcommand" ]; then
1251 __git_find_repo_path
1252 if [ -f "$__git_repo_path"/BISECT_START ]; then
1253 __gitcomp "$subcommands"
1254 else
1255 __gitcomp "replay start"
1257 return
1260 case "$subcommand" in
1261 bad|good|reset|skip|start)
1262 __git_complete_refs
1266 esac
1269 _git_branch ()
1271 local i c=1 only_local_ref="n" has_r="n"
1273 while [ $c -lt $cword ]; do
1274 i="${words[c]}"
1275 case "$i" in
1276 -d|--delete|-m|--move) only_local_ref="y" ;;
1277 -r|--remotes) has_r="y" ;;
1278 esac
1279 ((c++))
1280 done
1282 case "$cur" in
1283 --set-upstream-to=*)
1284 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1286 --*)
1287 __gitcomp_builtin branch
1290 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1291 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1292 else
1293 __git_complete_refs
1296 esac
1299 _git_bundle ()
1301 local cmd="${words[2]}"
1302 case "$cword" in
1304 __gitcomp "create list-heads verify unbundle"
1307 # looking for a file
1310 case "$cmd" in
1311 create)
1312 __git_complete_revlist
1314 esac
1316 esac
1319 _git_checkout ()
1321 __git_has_doubledash && return
1323 case "$cur" in
1324 --conflict=*)
1325 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1327 --*)
1328 __gitcomp_builtin checkout
1331 # check if --track, --no-track, or --no-guess was specified
1332 # if so, disable DWIM mode
1333 local flags="--track --no-track --no-guess" track_opt="--track"
1334 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1335 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1336 track_opt=''
1338 __git_complete_refs $track_opt
1340 esac
1343 _git_cherry ()
1345 case "$cur" in
1346 --*)
1347 __gitcomp_builtin cherry
1348 return
1349 esac
1351 __git_complete_refs
1354 __git_cherry_pick_inprogress_options="--continue --quit --abort"
1356 _git_cherry_pick ()
1358 __git_find_repo_path
1359 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1360 __gitcomp "$__git_cherry_pick_inprogress_options"
1361 return
1363 case "$cur" in
1364 --*)
1365 __gitcomp_builtin cherry-pick "" \
1366 "$__git_cherry_pick_inprogress_options"
1369 __git_complete_refs
1371 esac
1374 _git_clean ()
1376 case "$cur" in
1377 --*)
1378 __gitcomp_builtin clean
1379 return
1381 esac
1383 # XXX should we check for -x option ?
1384 __git_complete_index_file "--others --directory"
1387 _git_clone ()
1389 case "$cur" in
1390 --*)
1391 __gitcomp_builtin clone
1392 return
1394 esac
1397 __git_untracked_file_modes="all no normal"
1399 _git_commit ()
1401 case "$prev" in
1402 -c|-C)
1403 __git_complete_refs
1404 return
1406 esac
1408 case "$cur" in
1409 --cleanup=*)
1410 __gitcomp "default scissors strip verbatim whitespace
1411 " "" "${cur##--cleanup=}"
1412 return
1414 --reuse-message=*|--reedit-message=*|\
1415 --fixup=*|--squash=*)
1416 __git_complete_refs --cur="${cur#*=}"
1417 return
1419 --untracked-files=*)
1420 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1421 return
1423 --*)
1424 __gitcomp_builtin commit
1425 return
1426 esac
1428 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1429 __git_complete_index_file "--committable"
1430 else
1431 # This is the first commit
1432 __git_complete_index_file "--cached"
1436 _git_describe ()
1438 case "$cur" in
1439 --*)
1440 __gitcomp_builtin describe
1441 return
1442 esac
1443 __git_complete_refs
1446 __git_diff_algorithms="myers minimal patience histogram"
1448 __git_diff_submodule_formats="diff log short"
1450 __git_diff_common_options="--stat --numstat --shortstat --summary
1451 --patch-with-stat --name-only --name-status --color
1452 --no-color --color-words --no-renames --check
1453 --full-index --binary --abbrev --diff-filter=
1454 --find-copies-harder --ignore-cr-at-eol
1455 --text --ignore-space-at-eol --ignore-space-change
1456 --ignore-all-space --ignore-blank-lines --exit-code
1457 --quiet --ext-diff --no-ext-diff
1458 --no-prefix --src-prefix= --dst-prefix=
1459 --inter-hunk-context=
1460 --patience --histogram --minimal
1461 --raw --word-diff --word-diff-regex=
1462 --dirstat --dirstat= --dirstat-by-file
1463 --dirstat-by-file= --cumulative
1464 --diff-algorithm=
1465 --submodule --submodule= --ignore-submodules
1468 _git_diff ()
1470 __git_has_doubledash && return
1472 case "$cur" in
1473 --diff-algorithm=*)
1474 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1475 return
1477 --submodule=*)
1478 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1479 return
1481 --*)
1482 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1483 --base --ours --theirs --no-index
1484 $__git_diff_common_options
1486 return
1488 esac
1489 __git_complete_revlist_file
1492 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1493 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1496 _git_difftool ()
1498 __git_has_doubledash && return
1500 case "$cur" in
1501 --tool=*)
1502 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1503 return
1505 --*)
1506 __gitcomp_builtin difftool "$__git_diff_common_options
1507 --base --cached --ours --theirs
1508 --pickaxe-all --pickaxe-regex
1509 --relative --staged
1511 return
1513 esac
1514 __git_complete_revlist_file
1517 __git_fetch_recurse_submodules="yes on-demand no"
1519 _git_fetch ()
1521 case "$cur" in
1522 --recurse-submodules=*)
1523 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1524 return
1526 --*)
1527 __gitcomp_builtin fetch
1528 return
1530 esac
1531 __git_complete_remote_or_refspec
1534 __git_format_patch_options="
1535 --stdout --attach --no-attach --thread --thread= --no-thread
1536 --numbered --start-number --numbered-files --keep-subject --signoff
1537 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1538 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1539 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1540 --output-directory --reroll-count --to= --quiet --notes
1543 _git_format_patch ()
1545 case "$cur" in
1546 --thread=*)
1547 __gitcomp "
1548 deep shallow
1549 " "" "${cur##--thread=}"
1550 return
1552 --*)
1553 __gitcomp "$__git_format_patch_options"
1554 return
1556 esac
1557 __git_complete_revlist
1560 _git_fsck ()
1562 case "$cur" in
1563 --*)
1564 __gitcomp_builtin fsck
1565 return
1567 esac
1570 _git_gitk ()
1572 _gitk
1575 # Lists matching symbol names from a tag (as in ctags) file.
1576 # 1: List symbol names matching this word.
1577 # 2: The tag file to list symbol names from.
1578 # 3: A prefix to be added to each listed symbol name (optional).
1579 # 4: A suffix to be appended to each listed symbol name (optional).
1580 __git_match_ctag () {
1581 awk -v pfx="${3-}" -v sfx="${4-}" "
1582 /^${1//\//\\/}/ { print pfx \$1 sfx }
1583 " "$2"
1586 # Complete symbol names from a tag file.
1587 # Usage: __git_complete_symbol [<option>]...
1588 # --tags=<file>: The tag file to list symbol names from instead of the
1589 # default "tags".
1590 # --pfx=<prefix>: A prefix to be added to each symbol name.
1591 # --cur=<word>: The current symbol name to be completed. Defaults to
1592 # the current word to be completed.
1593 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1594 # of the default space.
1595 __git_complete_symbol () {
1596 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1598 while test $# != 0; do
1599 case "$1" in
1600 --tags=*) tags="${1##--tags=}" ;;
1601 --pfx=*) pfx="${1##--pfx=}" ;;
1602 --cur=*) cur_="${1##--cur=}" ;;
1603 --sfx=*) sfx="${1##--sfx=}" ;;
1604 *) return 1 ;;
1605 esac
1606 shift
1607 done
1609 if test -r "$tags"; then
1610 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1614 _git_grep ()
1616 __git_has_doubledash && return
1618 case "$cur" in
1619 --*)
1620 __gitcomp_builtin grep
1621 return
1623 esac
1625 case "$cword,$prev" in
1626 2,*|*,-*)
1627 __git_complete_symbol && return
1629 esac
1631 __git_complete_refs
1634 _git_help ()
1636 case "$cur" in
1637 --*)
1638 __gitcomp_builtin help
1639 return
1641 esac
1642 if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
1643 then
1644 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(git --list-cmds=alias,list-guide) gitk"
1645 else
1646 __gitcomp "$(git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1650 _git_init ()
1652 case "$cur" in
1653 --shared=*)
1654 __gitcomp "
1655 false true umask group all world everybody
1656 " "" "${cur##--shared=}"
1657 return
1659 --*)
1660 __gitcomp_builtin init
1661 return
1663 esac
1666 _git_ls_files ()
1668 case "$cur" in
1669 --*)
1670 __gitcomp_builtin ls-files
1671 return
1673 esac
1675 # XXX ignore options like --modified and always suggest all cached
1676 # files.
1677 __git_complete_index_file "--cached"
1680 _git_ls_remote ()
1682 case "$cur" in
1683 --*)
1684 __gitcomp_builtin ls-remote
1685 return
1687 esac
1688 __gitcomp_nl "$(__git_remotes)"
1691 _git_ls_tree ()
1693 case "$cur" in
1694 --*)
1695 __gitcomp_builtin ls-tree
1696 return
1698 esac
1700 __git_complete_file
1703 # Options that go well for log, shortlog and gitk
1704 __git_log_common_options="
1705 --not --all
1706 --branches --tags --remotes
1707 --first-parent --merges --no-merges
1708 --max-count=
1709 --max-age= --since= --after=
1710 --min-age= --until= --before=
1711 --min-parents= --max-parents=
1712 --no-min-parents --no-max-parents
1714 # Options that go well for log and gitk (not shortlog)
1715 __git_log_gitk_options="
1716 --dense --sparse --full-history
1717 --simplify-merges --simplify-by-decoration
1718 --left-right --notes --no-notes
1720 # Options that go well for log and shortlog (not gitk)
1721 __git_log_shortlog_options="
1722 --author= --committer= --grep=
1723 --all-match --invert-grep
1726 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1727 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1729 _git_log ()
1731 __git_has_doubledash && return
1732 __git_find_repo_path
1734 local merge=""
1735 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1736 merge="--merge"
1738 case "$prev,$cur" in
1739 -L,:*:*)
1740 return # fall back to Bash filename completion
1742 -L,:*)
1743 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1744 return
1746 -G,*|-S,*)
1747 __git_complete_symbol
1748 return
1750 esac
1751 case "$cur" in
1752 --pretty=*|--format=*)
1753 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1754 " "" "${cur#*=}"
1755 return
1757 --date=*)
1758 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1759 return
1761 --decorate=*)
1762 __gitcomp "full short no" "" "${cur##--decorate=}"
1763 return
1765 --diff-algorithm=*)
1766 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1767 return
1769 --submodule=*)
1770 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1771 return
1773 --*)
1774 __gitcomp "
1775 $__git_log_common_options
1776 $__git_log_shortlog_options
1777 $__git_log_gitk_options
1778 --root --topo-order --date-order --reverse
1779 --follow --full-diff
1780 --abbrev-commit --abbrev=
1781 --relative-date --date=
1782 --pretty= --format= --oneline
1783 --show-signature
1784 --cherry-mark
1785 --cherry-pick
1786 --graph
1787 --decorate --decorate=
1788 --walk-reflogs
1789 --parents --children
1790 $merge
1791 $__git_diff_common_options
1792 --pickaxe-all --pickaxe-regex
1794 return
1796 -L:*:*)
1797 return # fall back to Bash filename completion
1799 -L:*)
1800 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1801 return
1803 -G*)
1804 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1805 return
1807 -S*)
1808 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1809 return
1811 esac
1812 __git_complete_revlist
1815 _git_merge ()
1817 __git_complete_strategy && return
1819 case "$cur" in
1820 --*)
1821 __gitcomp_builtin merge
1822 return
1823 esac
1824 __git_complete_refs
1827 _git_mergetool ()
1829 case "$cur" in
1830 --tool=*)
1831 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1832 return
1834 --*)
1835 __gitcomp "--tool= --prompt --no-prompt"
1836 return
1838 esac
1841 _git_merge_base ()
1843 case "$cur" in
1844 --*)
1845 __gitcomp_builtin merge-base
1846 return
1848 esac
1849 __git_complete_refs
1852 _git_mv ()
1854 case "$cur" in
1855 --*)
1856 __gitcomp_builtin mv
1857 return
1859 esac
1861 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1862 # We need to show both cached and untracked files (including
1863 # empty directories) since this may not be the last argument.
1864 __git_complete_index_file "--cached --others --directory"
1865 else
1866 __git_complete_index_file "--cached"
1870 _git_notes ()
1872 local subcommands='add append copy edit get-ref list merge prune remove show'
1873 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1875 case "$subcommand,$cur" in
1876 ,--*)
1877 __gitcomp_builtin notes
1880 case "$prev" in
1881 --ref)
1882 __git_complete_refs
1885 __gitcomp "$subcommands --ref"
1887 esac
1889 *,--reuse-message=*|*,--reedit-message=*)
1890 __git_complete_refs --cur="${cur#*=}"
1892 *,--*)
1893 __gitcomp_builtin notes_$subcommand
1895 prune,*|get-ref,*)
1896 # this command does not take a ref, do not complete it
1899 case "$prev" in
1900 -m|-F)
1903 __git_complete_refs
1905 esac
1907 esac
1910 _git_pull ()
1912 __git_complete_strategy && return
1914 case "$cur" in
1915 --recurse-submodules=*)
1916 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1917 return
1919 --*)
1920 __gitcomp_builtin pull
1922 return
1924 esac
1925 __git_complete_remote_or_refspec
1928 __git_push_recurse_submodules="check on-demand only"
1930 __git_complete_force_with_lease ()
1932 local cur_=$1
1934 case "$cur_" in
1935 --*=)
1937 *:*)
1938 __git_complete_refs --cur="${cur_#*:}"
1941 __git_complete_refs --cur="$cur_"
1943 esac
1946 _git_push ()
1948 case "$prev" in
1949 --repo)
1950 __gitcomp_nl "$(__git_remotes)"
1951 return
1953 --recurse-submodules)
1954 __gitcomp "$__git_push_recurse_submodules"
1955 return
1957 esac
1958 case "$cur" in
1959 --repo=*)
1960 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1961 return
1963 --recurse-submodules=*)
1964 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1965 return
1967 --force-with-lease=*)
1968 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1969 return
1971 --*)
1972 __gitcomp_builtin push
1973 return
1975 esac
1976 __git_complete_remote_or_refspec
1979 _git_rebase ()
1981 __git_find_repo_path
1982 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1983 __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
1984 return
1985 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1986 [ -d "$__git_repo_path"/rebase-merge ]; then
1987 __gitcomp "--continue --skip --abort --quit --show-current-patch"
1988 return
1990 __git_complete_strategy && return
1991 case "$cur" in
1992 --whitespace=*)
1993 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1994 return
1996 --*)
1997 __gitcomp "
1998 --onto --merge --strategy --interactive
1999 --rebase-merges --preserve-merges --stat --no-stat
2000 --committer-date-is-author-date --ignore-date
2001 --ignore-whitespace --whitespace=
2002 --autosquash --no-autosquash
2003 --fork-point --no-fork-point
2004 --autostash --no-autostash
2005 --verify --no-verify
2006 --keep-empty --root --force-rebase --no-ff
2007 --rerere-autoupdate
2008 --exec
2011 return
2012 esac
2013 __git_complete_refs
2016 _git_reflog ()
2018 local subcommands="show delete expire"
2019 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2021 if [ -z "$subcommand" ]; then
2022 __gitcomp "$subcommands"
2023 else
2024 __git_complete_refs
2028 __git_send_email_confirm_options="always never auto cc compose"
2029 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2031 _git_send_email ()
2033 case "$prev" in
2034 --to|--cc|--bcc|--from)
2035 __gitcomp "$(__git send-email --dump-aliases)"
2036 return
2038 esac
2040 case "$cur" in
2041 --confirm=*)
2042 __gitcomp "
2043 $__git_send_email_confirm_options
2044 " "" "${cur##--confirm=}"
2045 return
2047 --suppress-cc=*)
2048 __gitcomp "
2049 $__git_send_email_suppresscc_options
2050 " "" "${cur##--suppress-cc=}"
2052 return
2054 --smtp-encryption=*)
2055 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2056 return
2058 --thread=*)
2059 __gitcomp "
2060 deep shallow
2061 " "" "${cur##--thread=}"
2062 return
2064 --to=*|--cc=*|--bcc=*|--from=*)
2065 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2066 return
2068 --*)
2069 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2070 --compose --confirm= --dry-run --envelope-sender
2071 --from --identity
2072 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2073 --no-suppress-from --no-thread --quiet --reply-to
2074 --signed-off-by-cc --smtp-pass --smtp-server
2075 --smtp-server-port --smtp-encryption= --smtp-user
2076 --subject --suppress-cc= --suppress-from --thread --to
2077 --validate --no-validate
2078 $__git_format_patch_options"
2079 return
2081 esac
2082 __git_complete_revlist
2085 _git_stage ()
2087 _git_add
2090 _git_status ()
2092 local complete_opt
2093 local untracked_state
2095 case "$cur" in
2096 --ignore-submodules=*)
2097 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2098 return
2100 --untracked-files=*)
2101 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2102 return
2104 --column=*)
2105 __gitcomp "
2106 always never auto column row plain dense nodense
2107 " "" "${cur##--column=}"
2108 return
2110 --*)
2111 __gitcomp_builtin status
2112 return
2114 esac
2116 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2117 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2119 case "$untracked_state" in
2121 # --ignored option does not matter
2122 complete_opt=
2124 all|normal|*)
2125 complete_opt="--cached --directory --no-empty-directory --others"
2127 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2128 complete_opt="$complete_opt --ignored --exclude=*"
2131 esac
2133 __git_complete_index_file "$complete_opt"
2136 __git_config_get_set_variables ()
2138 local prevword word config_file= c=$cword
2139 while [ $c -gt 1 ]; do
2140 word="${words[c]}"
2141 case "$word" in
2142 --system|--global|--local|--file=*)
2143 config_file="$word"
2144 break
2146 -f|--file)
2147 config_file="$word $prevword"
2148 break
2150 esac
2151 prevword=$word
2152 c=$((--c))
2153 done
2155 __git config $config_file --name-only --list
2158 __git_config_vars=
2159 __git_compute_config_vars ()
2161 test -n "$__git_config_vars" ||
2162 __git_config_vars="$(git help --config-for-completion | sort | uniq)"
2165 _git_config ()
2167 local varname
2169 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2170 varname="${prev,,}"
2171 else
2172 varname="$(echo "$prev" |tr A-Z a-z)"
2175 case "$varname" in
2176 branch.*.remote|branch.*.pushremote)
2177 __gitcomp_nl "$(__git_remotes)"
2178 return
2180 branch.*.merge)
2181 __git_complete_refs
2182 return
2184 branch.*.rebase)
2185 __gitcomp "false true merges preserve interactive"
2186 return
2188 remote.pushdefault)
2189 __gitcomp_nl "$(__git_remotes)"
2190 return
2192 remote.*.fetch)
2193 local remote="${prev#remote.}"
2194 remote="${remote%.fetch}"
2195 if [ -z "$cur" ]; then
2196 __gitcomp_nl "refs/heads/" "" "" ""
2197 return
2199 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2200 return
2202 remote.*.push)
2203 local remote="${prev#remote.}"
2204 remote="${remote%.push}"
2205 __gitcomp_nl "$(__git for-each-ref \
2206 --format='%(refname):%(refname)' refs/heads)"
2207 return
2209 pull.twohead|pull.octopus)
2210 __git_compute_merge_strategies
2211 __gitcomp "$__git_merge_strategies"
2212 return
2214 color.branch|color.diff|color.interactive|\
2215 color.showbranch|color.status|color.ui)
2216 __gitcomp "always never auto"
2217 return
2219 color.pager)
2220 __gitcomp "false true"
2221 return
2223 color.*.*)
2224 __gitcomp "
2225 normal black red green yellow blue magenta cyan white
2226 bold dim ul blink reverse
2228 return
2230 diff.submodule)
2231 __gitcomp "log short"
2232 return
2234 help.format)
2235 __gitcomp "man info web html"
2236 return
2238 log.date)
2239 __gitcomp "$__git_log_date_formats"
2240 return
2242 sendemail.aliasfiletype)
2243 __gitcomp "mutt mailrc pine elm gnus"
2244 return
2246 sendemail.confirm)
2247 __gitcomp "$__git_send_email_confirm_options"
2248 return
2250 sendemail.suppresscc)
2251 __gitcomp "$__git_send_email_suppresscc_options"
2252 return
2254 sendemail.transferencoding)
2255 __gitcomp "7bit 8bit quoted-printable base64"
2256 return
2258 --get|--get-all|--unset|--unset-all)
2259 __gitcomp_nl "$(__git_config_get_set_variables)"
2260 return
2262 *.*)
2263 return
2265 esac
2266 case "$cur" in
2267 --*)
2268 __gitcomp_builtin config
2269 return
2271 branch.*.*)
2272 local pfx="${cur%.*}." cur_="${cur##*.}"
2273 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_"
2274 return
2276 branch.*)
2277 local pfx="${cur%.*}." cur_="${cur#*.}"
2278 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2279 __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_"
2280 return
2282 guitool.*.*)
2283 local pfx="${cur%.*}." cur_="${cur##*.}"
2284 __gitcomp "
2285 argPrompt cmd confirm needsFile noConsole noRescan
2286 prompt revPrompt revUnmerged title
2287 " "$pfx" "$cur_"
2288 return
2290 difftool.*.*)
2291 local pfx="${cur%.*}." cur_="${cur##*.}"
2292 __gitcomp "cmd path" "$pfx" "$cur_"
2293 return
2295 man.*.*)
2296 local pfx="${cur%.*}." cur_="${cur##*.}"
2297 __gitcomp "cmd path" "$pfx" "$cur_"
2298 return
2300 mergetool.*.*)
2301 local pfx="${cur%.*}." cur_="${cur##*.}"
2302 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2303 return
2305 pager.*)
2306 local pfx="${cur%.*}." cur_="${cur#*.}"
2307 __git_compute_all_commands
2308 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2309 return
2311 remote.*.*)
2312 local pfx="${cur%.*}." cur_="${cur##*.}"
2313 __gitcomp "
2314 url proxy fetch push mirror skipDefaultUpdate
2315 receivepack uploadpack tagOpt pushurl
2316 " "$pfx" "$cur_"
2317 return
2319 remote.*)
2320 local pfx="${cur%.*}." cur_="${cur#*.}"
2321 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2322 __gitcomp_nl_append "pushDefault" "$pfx" "$cur_"
2323 return
2325 url.*.*)
2326 local pfx="${cur%.*}." cur_="${cur##*.}"
2327 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2328 return
2330 *.*)
2331 __git_compute_config_vars
2332 __gitcomp "$__git_config_vars"
2335 __git_compute_config_vars
2336 __gitcomp "$(echo "$__git_config_vars" | sed 's/\.[^ ]*/./g')"
2337 esac
2340 _git_remote ()
2342 local subcommands="
2343 add rename remove set-head set-branches
2344 get-url set-url show prune update
2346 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2347 if [ -z "$subcommand" ]; then
2348 case "$cur" in
2349 --*)
2350 __gitcomp_builtin remote
2353 __gitcomp "$subcommands"
2355 esac
2356 return
2359 case "$subcommand,$cur" in
2360 add,--*)
2361 __gitcomp_builtin remote_add
2363 add,*)
2365 set-head,--*)
2366 __gitcomp_builtin remote_set-head
2368 set-branches,--*)
2369 __gitcomp_builtin remote_set-branches
2371 set-head,*|set-branches,*)
2372 __git_complete_remote_or_refspec
2374 update,--*)
2375 __gitcomp_builtin remote_update
2377 update,*)
2378 __gitcomp "$(__git_remotes) $(__git_get_config_variables "remotes")"
2380 set-url,--*)
2381 __gitcomp_builtin remote_set-url
2383 get-url,--*)
2384 __gitcomp_builtin remote_get-url
2386 prune,--*)
2387 __gitcomp_builtin remote_prune
2390 __gitcomp_nl "$(__git_remotes)"
2392 esac
2395 _git_replace ()
2397 case "$cur" in
2398 --*)
2399 __gitcomp_builtin replace
2400 return
2402 esac
2403 __git_complete_refs
2406 _git_rerere ()
2408 local subcommands="clear forget diff remaining status gc"
2409 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2410 if test -z "$subcommand"
2411 then
2412 __gitcomp "$subcommands"
2413 return
2417 _git_reset ()
2419 __git_has_doubledash && return
2421 case "$cur" in
2422 --*)
2423 __gitcomp_builtin reset
2424 return
2426 esac
2427 __git_complete_refs
2430 __git_revert_inprogress_options="--continue --quit --abort"
2432 _git_revert ()
2434 __git_find_repo_path
2435 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2436 __gitcomp "$__git_revert_inprogress_options"
2437 return
2439 case "$cur" in
2440 --*)
2441 __gitcomp_builtin revert "" \
2442 "$__git_revert_inprogress_options"
2443 return
2445 esac
2446 __git_complete_refs
2449 _git_rm ()
2451 case "$cur" in
2452 --*)
2453 __gitcomp_builtin rm
2454 return
2456 esac
2458 __git_complete_index_file "--cached"
2461 _git_shortlog ()
2463 __git_has_doubledash && return
2465 case "$cur" in
2466 --*)
2467 __gitcomp "
2468 $__git_log_common_options
2469 $__git_log_shortlog_options
2470 --numbered --summary --email
2472 return
2474 esac
2475 __git_complete_revlist
2478 _git_show ()
2480 __git_has_doubledash && return
2482 case "$cur" in
2483 --pretty=*|--format=*)
2484 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2485 " "" "${cur#*=}"
2486 return
2488 --diff-algorithm=*)
2489 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2490 return
2492 --submodule=*)
2493 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2494 return
2496 --*)
2497 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2498 --show-signature
2499 $__git_diff_common_options
2501 return
2503 esac
2504 __git_complete_revlist_file
2507 _git_show_branch ()
2509 case "$cur" in
2510 --*)
2511 __gitcomp_builtin show-branch
2512 return
2514 esac
2515 __git_complete_revlist
2518 _git_stash ()
2520 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2521 local subcommands='push list show apply clear drop pop create branch'
2522 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
2523 if [ -n "$(__git_find_on_cmdline "-p")" ]; then
2524 subcommand="push"
2526 if [ -z "$subcommand" ]; then
2527 case "$cur" in
2528 --*)
2529 __gitcomp "$save_opts"
2531 sa*)
2532 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2533 __gitcomp "save"
2537 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2538 __gitcomp "$subcommands"
2541 esac
2542 else
2543 case "$subcommand,$cur" in
2544 push,--*)
2545 __gitcomp "$save_opts --message"
2547 save,--*)
2548 __gitcomp "$save_opts"
2550 apply,--*|pop,--*)
2551 __gitcomp "--index --quiet"
2553 drop,--*)
2554 __gitcomp "--quiet"
2556 show,--*|branch,--*)
2558 branch,*)
2559 if [ $cword -eq 3 ]; then
2560 __git_complete_refs
2561 else
2562 __gitcomp_nl "$(__git stash list \
2563 | sed -n -e 's/:.*//p')"
2566 show,*|apply,*|drop,*|pop,*)
2567 __gitcomp_nl "$(__git stash list \
2568 | sed -n -e 's/:.*//p')"
2572 esac
2576 _git_submodule ()
2578 __git_has_doubledash && return
2580 local subcommands="add status init deinit update summary foreach sync"
2581 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2582 if [ -z "$subcommand" ]; then
2583 case "$cur" in
2584 --*)
2585 __gitcomp "--quiet"
2588 __gitcomp "$subcommands"
2590 esac
2591 return
2594 case "$subcommand,$cur" in
2595 add,--*)
2596 __gitcomp "--branch --force --name --reference --depth"
2598 status,--*)
2599 __gitcomp "--cached --recursive"
2601 deinit,--*)
2602 __gitcomp "--force --all"
2604 update,--*)
2605 __gitcomp "
2606 --init --remote --no-fetch
2607 --recommend-shallow --no-recommend-shallow
2608 --force --rebase --merge --reference --depth --recursive --jobs
2611 summary,--*)
2612 __gitcomp "--cached --files --summary-limit"
2614 foreach,--*|sync,--*)
2615 __gitcomp "--recursive"
2619 esac
2622 _git_svn ()
2624 local subcommands="
2625 init fetch clone rebase dcommit log find-rev
2626 set-tree commit-diff info create-ignore propget
2627 proplist show-ignore show-externals branch tag blame
2628 migrate mkdirs reset gc
2630 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2631 if [ -z "$subcommand" ]; then
2632 __gitcomp "$subcommands"
2633 else
2634 local remote_opts="--username= --config-dir= --no-auth-cache"
2635 local fc_opts="
2636 --follow-parent --authors-file= --repack=
2637 --no-metadata --use-svm-props --use-svnsync-props
2638 --log-window-size= --no-checkout --quiet
2639 --repack-flags --use-log-author --localtime
2640 --add-author-from
2641 --ignore-paths= --include-paths= $remote_opts
2643 local init_opts="
2644 --template= --shared= --trunk= --tags=
2645 --branches= --stdlayout --minimize-url
2646 --no-metadata --use-svm-props --use-svnsync-props
2647 --rewrite-root= --prefix= $remote_opts
2649 local cmt_opts="
2650 --edit --rmdir --find-copies-harder --copy-similarity=
2653 case "$subcommand,$cur" in
2654 fetch,--*)
2655 __gitcomp "--revision= --fetch-all $fc_opts"
2657 clone,--*)
2658 __gitcomp "--revision= $fc_opts $init_opts"
2660 init,--*)
2661 __gitcomp "$init_opts"
2663 dcommit,--*)
2664 __gitcomp "
2665 --merge --strategy= --verbose --dry-run
2666 --fetch-all --no-rebase --commit-url
2667 --revision --interactive $cmt_opts $fc_opts
2670 set-tree,--*)
2671 __gitcomp "--stdin $cmt_opts $fc_opts"
2673 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2674 show-externals,--*|mkdirs,--*)
2675 __gitcomp "--revision="
2677 log,--*)
2678 __gitcomp "
2679 --limit= --revision= --verbose --incremental
2680 --oneline --show-commit --non-recursive
2681 --authors-file= --color
2684 rebase,--*)
2685 __gitcomp "
2686 --merge --verbose --strategy= --local
2687 --fetch-all --dry-run $fc_opts
2690 commit-diff,--*)
2691 __gitcomp "--message= --file= --revision= $cmt_opts"
2693 info,--*)
2694 __gitcomp "--url"
2696 branch,--*)
2697 __gitcomp "--dry-run --message --tag"
2699 tag,--*)
2700 __gitcomp "--dry-run --message"
2702 blame,--*)
2703 __gitcomp "--git-format"
2705 migrate,--*)
2706 __gitcomp "
2707 --config-dir= --ignore-paths= --minimize
2708 --no-auth-cache --username=
2711 reset,--*)
2712 __gitcomp "--revision= --parent"
2716 esac
2720 _git_tag ()
2722 local i c=1 f=0
2723 while [ $c -lt $cword ]; do
2724 i="${words[c]}"
2725 case "$i" in
2726 -d|--delete|-v|--verify)
2727 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2728 return
2733 esac
2734 ((c++))
2735 done
2737 case "$prev" in
2738 -m|-F)
2740 -*|tag)
2741 if [ $f = 1 ]; then
2742 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2746 __git_complete_refs
2748 esac
2750 case "$cur" in
2751 --*)
2752 __gitcomp_builtin tag
2754 esac
2757 _git_whatchanged ()
2759 _git_log
2762 _git_worktree ()
2764 local subcommands="add list lock move prune remove unlock"
2765 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2766 if [ -z "$subcommand" ]; then
2767 __gitcomp "$subcommands"
2768 else
2769 case "$subcommand,$cur" in
2770 add,--*)
2771 __gitcomp_builtin worktree_add
2773 list,--*)
2774 __gitcomp_builtin worktree_list
2776 lock,--*)
2777 __gitcomp_builtin worktree_lock
2779 prune,--*)
2780 __gitcomp_builtin worktree_prune
2782 remove,--*)
2783 __gitcomp "--force"
2787 esac
2791 __git_complete_common () {
2792 local command="$1"
2794 case "$cur" in
2795 --*)
2796 __gitcomp_builtin "$command"
2798 esac
2801 __git_cmds_with_parseopt_helper=
2802 __git_support_parseopt_helper () {
2803 test -n "$__git_cmds_with_parseopt_helper" ||
2804 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
2806 case " $__git_cmds_with_parseopt_helper " in
2807 *" $1 "*)
2808 return 0
2811 return 1
2813 esac
2816 __git_complete_command () {
2817 local command="$1"
2818 local completion_func="_git_${command//-/_}"
2819 if ! declare -f $completion_func >/dev/null 2>/dev/null &&
2820 declare -f _completion_loader >/dev/null 2>/dev/null
2821 then
2822 _completion_loader "git-$command"
2824 if declare -f $completion_func >/dev/null 2>/dev/null
2825 then
2826 $completion_func
2827 return 0
2828 elif __git_support_parseopt_helper "$command"
2829 then
2830 __git_complete_common "$command"
2831 return 0
2832 else
2833 return 1
2837 __git_main ()
2839 local i c=1 command __git_dir __git_repo_path
2840 local __git_C_args C_args_count=0
2842 while [ $c -lt $cword ]; do
2843 i="${words[c]}"
2844 case "$i" in
2845 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2846 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2847 --bare) __git_dir="." ;;
2848 --help) command="help"; break ;;
2849 -c|--work-tree|--namespace) ((c++)) ;;
2850 -C) __git_C_args[C_args_count++]=-C
2851 ((c++))
2852 __git_C_args[C_args_count++]="${words[c]}"
2854 -*) ;;
2855 *) command="$i"; break ;;
2856 esac
2857 ((c++))
2858 done
2860 if [ -z "$command" ]; then
2861 case "$prev" in
2862 --git-dir|-C|--work-tree)
2863 # these need a path argument, let's fall back to
2864 # Bash filename completion
2865 return
2867 -c|--namespace)
2868 # we don't support completing these options' arguments
2869 return
2871 esac
2872 case "$cur" in
2873 --*) __gitcomp "
2874 --paginate
2875 --no-pager
2876 --git-dir=
2877 --bare
2878 --version
2879 --exec-path
2880 --exec-path=
2881 --html-path
2882 --man-path
2883 --info-path
2884 --work-tree=
2885 --namespace=
2886 --no-replace-objects
2887 --help
2891 if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
2892 then
2893 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
2894 else
2895 __gitcomp "$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
2898 esac
2899 return
2902 __git_complete_command "$command" && return
2904 local expansion=$(__git_aliased_command "$command")
2905 if [ -n "$expansion" ]; then
2906 words[1]=$expansion
2907 __git_complete_command "$expansion"
2911 __gitk_main ()
2913 __git_has_doubledash && return
2915 local __git_repo_path
2916 __git_find_repo_path
2918 local merge=""
2919 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2920 merge="--merge"
2922 case "$cur" in
2923 --*)
2924 __gitcomp "
2925 $__git_log_common_options
2926 $__git_log_gitk_options
2927 $merge
2929 return
2931 esac
2932 __git_complete_revlist
2935 if [[ -n ${ZSH_VERSION-} ]] &&
2936 # Don't define these functions when sourced from 'git-completion.zsh',
2937 # it has its own implementations.
2938 [[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
2939 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2941 autoload -U +X compinit && compinit
2943 __gitcomp ()
2945 emulate -L zsh
2947 local cur_="${3-$cur}"
2949 case "$cur_" in
2950 --*=)
2953 local c IFS=$' \t\n'
2954 local -a array
2955 for c in ${=1}; do
2956 c="$c${4-}"
2957 case $c in
2958 --*=*|*.) ;;
2959 *) c="$c " ;;
2960 esac
2961 array[${#array[@]}+1]="$c"
2962 done
2963 compset -P '*[=:]'
2964 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2966 esac
2969 __gitcomp_direct ()
2971 emulate -L zsh
2973 local IFS=$'\n'
2974 compset -P '*[=:]'
2975 compadd -Q -- ${=1} && _ret=0
2978 __gitcomp_nl ()
2980 emulate -L zsh
2982 local IFS=$'\n'
2983 compset -P '*[=:]'
2984 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2987 __gitcomp_file_direct ()
2989 emulate -L zsh
2991 local IFS=$'\n'
2992 compset -P '*[=:]'
2993 compadd -Q -f -- ${=1} && _ret=0
2996 __gitcomp_file ()
2998 emulate -L zsh
3000 local IFS=$'\n'
3001 compset -P '*[=:]'
3002 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3005 _git ()
3007 local _ret=1 cur cword prev
3008 cur=${words[CURRENT]}
3009 prev=${words[CURRENT-1]}
3010 let cword=CURRENT-1
3011 emulate ksh -c __${service}_main
3012 let _ret && _default && _ret=0
3013 return _ret
3016 compdef _git git gitk
3017 return
3020 __git_func_wrap ()
3022 local cur words cword prev
3023 _get_comp_words_by_ref -n =: cur words cword prev
3027 # Setup completion for certain functions defined above by setting common
3028 # variables and workarounds.
3029 # This is NOT a public function; use at your own risk.
3030 __git_complete ()
3032 local wrapper="__git_wrap${2}"
3033 eval "$wrapper () { __git_func_wrap $2 ; }"
3034 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3035 || complete -o default -o nospace -F $wrapper $1
3038 # wrapper for backwards compatibility
3039 _git ()
3041 __git_wrap__git_main
3044 # wrapper for backwards compatibility
3045 _gitk ()
3047 __git_wrap__gitk_main
3050 __git_complete git __git_main
3051 __git_complete gitk __gitk_main
3053 # The following are necessary only for Cygwin, and only are needed
3054 # when the user has tab-completed the executable name and consequently
3055 # included the '.exe' suffix.
3057 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3058 __git_complete git.exe __git_main