completion: delete option-only completion commands
[alt-git.git] / contrib / completion / git-completion.bash
blob0080932b2971d7151b052058bc204241781271c2
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 # The following function is based on code from:
99 # bash_completion - programmable completion functions for bash 3.2+
101 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
102 # © 2009-2010, Bash Completion Maintainers
103 # <bash-completion-devel@lists.alioth.debian.org>
105 # This program is free software; you can redistribute it and/or modify
106 # it under the terms of the GNU General Public License as published by
107 # the Free Software Foundation; either version 2, or (at your option)
108 # any later version.
110 # This program is distributed in the hope that it will be useful,
111 # but WITHOUT ANY WARRANTY; without even the implied warranty of
112 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113 # GNU General Public License for more details.
115 # You should have received a copy of the GNU General Public License
116 # along with this program; if not, see <http://www.gnu.org/licenses/>.
118 # The latest version of this software can be obtained here:
120 # http://bash-completion.alioth.debian.org/
122 # RELEASE: 2.x
124 # This function can be used to access a tokenized list of words
125 # on the command line:
127 # __git_reassemble_comp_words_by_ref '=:'
128 # if test "${words_[cword_-1]}" = -w
129 # then
130 # ...
131 # fi
133 # The argument should be a collection of characters from the list of
134 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
135 # characters.
137 # This is roughly equivalent to going back in time and setting
138 # COMP_WORDBREAKS to exclude those characters. The intent is to
139 # make option types like --date=<type> and <rev>:<path> easy to
140 # recognize by treating each shell word as a single token.
142 # It is best not to set COMP_WORDBREAKS directly because the value is
143 # shared with other completion scripts. By the time the completion
144 # function gets called, COMP_WORDS has already been populated so local
145 # changes to COMP_WORDBREAKS have no effect.
147 # Output: words_, cword_, cur_.
149 __git_reassemble_comp_words_by_ref()
151 local exclude i j first
152 # Which word separators to exclude?
153 exclude="${1//[^$COMP_WORDBREAKS]}"
154 cword_=$COMP_CWORD
155 if [ -z "$exclude" ]; then
156 words_=("${COMP_WORDS[@]}")
157 return
159 # List of word completion separators has shrunk;
160 # re-assemble words to complete.
161 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
162 # Append each nonempty word consisting of just
163 # word separator characters to the current word.
164 first=t
165 while
166 [ $i -gt 0 ] &&
167 [ -n "${COMP_WORDS[$i]}" ] &&
168 # word consists of excluded word separators
169 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
171 # Attach to the previous token,
172 # unless the previous token is the command name.
173 if [ $j -ge 2 ] && [ -n "$first" ]; then
174 ((j--))
176 first=
177 words_[$j]=${words_[j]}${COMP_WORDS[i]}
178 if [ $i = $COMP_CWORD ]; then
179 cword_=$j
181 if (($i < ${#COMP_WORDS[@]} - 1)); then
182 ((i++))
183 else
184 # Done.
185 return
187 done
188 words_[$j]=${words_[j]}${COMP_WORDS[i]}
189 if [ $i = $COMP_CWORD ]; then
190 cword_=$j
192 done
195 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
196 _get_comp_words_by_ref ()
198 local exclude cur_ words_ cword_
199 if [ "$1" = "-n" ]; then
200 exclude=$2
201 shift 2
203 __git_reassemble_comp_words_by_ref "$exclude"
204 cur_=${words_[cword_]}
205 while [ $# -gt 0 ]; do
206 case "$1" in
207 cur)
208 cur=$cur_
210 prev)
211 prev=${words_[$cword_-1]}
213 words)
214 words=("${words_[@]}")
216 cword)
217 cword=$cword_
219 esac
220 shift
221 done
225 # Fills the COMPREPLY array with prefiltered words without any additional
226 # processing.
227 # Callers must take care of providing only words that match the current word
228 # to be completed and adding any prefix and/or suffix (trailing space!), if
229 # necessary.
230 # 1: List of newline-separated matching completion words, complete with
231 # prefix and suffix.
232 __gitcomp_direct ()
234 local IFS=$'\n'
236 COMPREPLY=($1)
239 __gitcompappend ()
241 local x i=${#COMPREPLY[@]}
242 for x in $1; do
243 if [[ "$x" == "$3"* ]]; then
244 COMPREPLY[i++]="$2$x$4"
246 done
249 __gitcompadd ()
251 COMPREPLY=()
252 __gitcompappend "$@"
255 # Generates completion reply, appending a space to possible completion words,
256 # if necessary.
257 # It accepts 1 to 4 arguments:
258 # 1: List of possible completion words.
259 # 2: A prefix to be added to each possible completion word (optional).
260 # 3: Generate possible completion matches for this word (optional).
261 # 4: A suffix to be appended to each possible completion word (optional).
262 __gitcomp ()
264 local cur_="${3-$cur}"
266 case "$cur_" in
267 --*=)
270 local c i=0 IFS=$' \t\n'
271 for c in $1; do
272 c="$c${4-}"
273 if [[ $c == "$cur_"* ]]; then
274 case $c in
275 --*=*|*.) ;;
276 *) c="$c " ;;
277 esac
278 COMPREPLY[i++]="${2-}$c"
280 done
282 esac
285 # Clear the variables caching builtins' options when (re-)sourcing
286 # the completion script.
287 unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
289 # This function is equivalent to
291 # __gitcomp "$(git xxx --git-completion-helper) ..."
293 # except that the output is cached. Accept 1-3 arguments:
294 # 1: the git command to execute, this is also the cache key
295 # 2: extra options to be added on top (e.g. negative forms)
296 # 3: options to be excluded
297 __gitcomp_builtin ()
299 # spaces must be replaced with underscore for multi-word
300 # commands, e.g. "git remote add" becomes remote_add.
301 local cmd="$1"
302 local incl="$2"
303 local excl="$3"
305 local var=__gitcomp_builtin_"${cmd/-/_}"
306 local options
307 eval "options=\$$var"
309 if [ -z "$options" ]; then
310 # leading and trailing spaces are significant to make
311 # option removal work correctly.
312 options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
313 for i in $excl; do
314 options="${options/ $i / }"
315 done
316 eval "$var=\"$options\""
319 __gitcomp "$options"
322 # Variation of __gitcomp_nl () that appends to the existing list of
323 # completion candidates, COMPREPLY.
324 __gitcomp_nl_append ()
326 local IFS=$'\n'
327 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
330 # Generates completion reply from newline-separated possible completion words
331 # by appending a space to all of them.
332 # It accepts 1 to 4 arguments:
333 # 1: List of possible completion words, separated by a single newline.
334 # 2: A prefix to be added to each possible completion word (optional).
335 # 3: Generate possible completion matches for this word (optional).
336 # 4: A suffix to be appended to each possible completion word instead of
337 # the default space (optional). If specified but empty, nothing is
338 # appended.
339 __gitcomp_nl ()
341 COMPREPLY=()
342 __gitcomp_nl_append "$@"
345 # Generates completion reply with compgen from newline-separated possible
346 # completion filenames.
347 # It accepts 1 to 3 arguments:
348 # 1: List of possible completion filenames, separated by a single newline.
349 # 2: A directory prefix to be added to each possible completion filename
350 # (optional).
351 # 3: Generate possible completion matches for this word (optional).
352 __gitcomp_file ()
354 local IFS=$'\n'
356 # XXX does not work when the directory prefix contains a tilde,
357 # since tilde expansion is not applied.
358 # This means that COMPREPLY will be empty and Bash default
359 # completion will be used.
360 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
362 # use a hack to enable file mode in bash < 4
363 compopt -o filenames +o nospace 2>/dev/null ||
364 compgen -f /non-existing-dir/ > /dev/null
367 # Execute 'git ls-files', unless the --committable option is specified, in
368 # which case it runs 'git diff-index' to find out the files that can be
369 # committed. It return paths relative to the directory specified in the first
370 # argument, and using the options specified in the second argument.
371 __git_ls_files_helper ()
373 if [ "$2" == "--committable" ]; then
374 __git -C "$1" diff-index --name-only --relative HEAD
375 else
376 # NOTE: $2 is not quoted in order to support multiple options
377 __git -C "$1" ls-files --exclude-standard $2
382 # __git_index_files accepts 1 or 2 arguments:
383 # 1: Options to pass to ls-files (required).
384 # 2: A directory path (optional).
385 # If provided, only files within the specified directory are listed.
386 # Sub directories are never recursed. Path must have a trailing
387 # slash.
388 __git_index_files ()
390 local root="${2-.}" file
392 __git_ls_files_helper "$root" "$1" |
393 while read -r file; do
394 case "$file" in
395 ?*/*) echo "${file%%/*}" ;;
396 *) echo "$file" ;;
397 esac
398 done | sort | uniq
401 # Lists branches from the local repository.
402 # 1: A prefix to be added to each listed branch (optional).
403 # 2: List only branches matching this word (optional; list all branches if
404 # unset or empty).
405 # 3: A suffix to be appended to each listed branch (optional).
406 __git_heads ()
408 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
410 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
411 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
414 # Lists tags from the local repository.
415 # Accepts the same positional parameters as __git_heads() above.
416 __git_tags ()
418 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
420 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
421 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
424 # Lists refs from the local (by default) or from a remote repository.
425 # It accepts 0, 1 or 2 arguments:
426 # 1: The remote to list refs from (optional; ignored, if set but empty).
427 # Can be the name of a configured remote, a path, or a URL.
428 # 2: In addition to local refs, list unique branches from refs/remotes/ for
429 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
430 # 3: A prefix to be added to each listed ref (optional).
431 # 4: List only refs matching this word (optional; list all refs if unset or
432 # empty).
433 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
434 # but empty).
436 # Use __git_complete_refs() instead.
437 __git_refs ()
439 local i hash dir track="${2-}"
440 local list_refs_from=path remote="${1-}"
441 local format refs
442 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
443 local match="${4-}"
444 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
446 __git_find_repo_path
447 dir="$__git_repo_path"
449 if [ -z "$remote" ]; then
450 if [ -z "$dir" ]; then
451 return
453 else
454 if __git_is_configured_remote "$remote"; then
455 # configured remote takes precedence over a
456 # local directory with the same name
457 list_refs_from=remote
458 elif [ -d "$remote/.git" ]; then
459 dir="$remote/.git"
460 elif [ -d "$remote" ]; then
461 dir="$remote"
462 else
463 list_refs_from=url
467 if [ "$list_refs_from" = path ]; then
468 if [[ "$cur_" == ^* ]]; then
469 pfx="$pfx^"
470 fer_pfx="$fer_pfx^"
471 cur_=${cur_#^}
472 match=${match#^}
474 case "$cur_" in
475 refs|refs/*)
476 format="refname"
477 refs=("$match*" "$match*/**")
478 track=""
481 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
482 case "$i" in
483 $match*)
484 if [ -e "$dir/$i" ]; then
485 echo "$pfx$i$sfx"
488 esac
489 done
490 format="refname:strip=2"
491 refs=("refs/tags/$match*" "refs/tags/$match*/**"
492 "refs/heads/$match*" "refs/heads/$match*/**"
493 "refs/remotes/$match*" "refs/remotes/$match*/**")
495 esac
496 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
497 "${refs[@]}"
498 if [ -n "$track" ]; then
499 # employ the heuristic used by git checkout
500 # Try to find a remote branch that matches the completion word
501 # but only output if the branch name is unique
502 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
503 --sort="refname:strip=3" \
504 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
505 uniq -u
507 return
509 case "$cur_" in
510 refs|refs/*)
511 __git ls-remote "$remote" "$match*" | \
512 while read -r hash i; do
513 case "$i" in
514 *^{}) ;;
515 *) echo "$pfx$i$sfx" ;;
516 esac
517 done
520 if [ "$list_refs_from" = remote ]; then
521 case "HEAD" in
522 $match*) echo "${pfx}HEAD$sfx" ;;
523 esac
524 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
525 "refs/remotes/$remote/$match*" \
526 "refs/remotes/$remote/$match*/**"
527 else
528 local query_symref
529 case "HEAD" in
530 $match*) query_symref="HEAD" ;;
531 esac
532 __git ls-remote "$remote" $query_symref \
533 "refs/tags/$match*" "refs/heads/$match*" \
534 "refs/remotes/$match*" |
535 while read -r hash i; do
536 case "$i" in
537 *^{}) ;;
538 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
539 *) echo "$pfx$i$sfx" ;; # symbolic refs
540 esac
541 done
544 esac
547 # Completes refs, short and long, local and remote, symbolic and pseudo.
549 # Usage: __git_complete_refs [<option>]...
550 # --remote=<remote>: The remote to list refs from, can be the name of a
551 # configured remote, a path, or a URL.
552 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
553 # --pfx=<prefix>: A prefix to be added to each ref.
554 # --cur=<word>: The current ref to be completed. Defaults to the current
555 # word to be completed.
556 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
557 # space.
558 __git_complete_refs ()
560 local remote track pfx cur_="$cur" sfx=" "
562 while test $# != 0; do
563 case "$1" in
564 --remote=*) remote="${1##--remote=}" ;;
565 --track) track="yes" ;;
566 --pfx=*) pfx="${1##--pfx=}" ;;
567 --cur=*) cur_="${1##--cur=}" ;;
568 --sfx=*) sfx="${1##--sfx=}" ;;
569 *) return 1 ;;
570 esac
571 shift
572 done
574 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
577 # __git_refs2 requires 1 argument (to pass to __git_refs)
578 # Deprecated: use __git_complete_fetch_refspecs() instead.
579 __git_refs2 ()
581 local i
582 for i in $(__git_refs "$1"); do
583 echo "$i:$i"
584 done
587 # Completes refspecs for fetching from a remote repository.
588 # 1: The remote repository.
589 # 2: A prefix to be added to each listed refspec (optional).
590 # 3: The ref to be completed as a refspec instead of the current word to be
591 # completed (optional)
592 # 4: A suffix to be appended to each listed refspec instead of the default
593 # space (optional).
594 __git_complete_fetch_refspecs ()
596 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
598 __gitcomp_direct "$(
599 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
600 echo "$pfx$i:$i$sfx"
601 done
605 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
606 __git_refs_remotes ()
608 local i hash
609 __git ls-remote "$1" 'refs/heads/*' | \
610 while read -r hash i; do
611 echo "$i:refs/remotes/$1/${i#refs/heads/}"
612 done
615 __git_remotes ()
617 __git_find_repo_path
618 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
619 __git remote
622 # Returns true if $1 matches the name of a configured remote, false otherwise.
623 __git_is_configured_remote ()
625 local remote
626 for remote in $(__git_remotes); do
627 if [ "$remote" = "$1" ]; then
628 return 0
630 done
631 return 1
634 __git_list_merge_strategies ()
636 git merge -s help 2>&1 |
637 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
638 s/\.$//
639 s/.*://
640 s/^[ ]*//
641 s/[ ]*$//
646 __git_merge_strategies=
647 # 'git merge -s help' (and thus detection of the merge strategy
648 # list) fails, unfortunately, if run outside of any git working
649 # tree. __git_merge_strategies is set to the empty string in
650 # that case, and the detection will be repeated the next time it
651 # is needed.
652 __git_compute_merge_strategies ()
654 test -n "$__git_merge_strategies" ||
655 __git_merge_strategies=$(__git_list_merge_strategies)
658 __git_complete_revlist_file ()
660 local pfx ls ref cur_="$cur"
661 case "$cur_" in
662 *..?*:*)
663 return
665 ?*:*)
666 ref="${cur_%%:*}"
667 cur_="${cur_#*:}"
668 case "$cur_" in
669 ?*/*)
670 pfx="${cur_%/*}"
671 cur_="${cur_##*/}"
672 ls="$ref:$pfx"
673 pfx="$pfx/"
676 ls="$ref"
678 esac
680 case "$COMP_WORDBREAKS" in
681 *:*) : great ;;
682 *) pfx="$ref:$pfx" ;;
683 esac
685 __gitcomp_nl "$(__git ls-tree "$ls" \
686 | sed '/^100... blob /{
687 s,^.* ,,
688 s,$, ,
690 /^120000 blob /{
691 s,^.* ,,
692 s,$, ,
694 /^040000 tree /{
695 s,^.* ,,
696 s,$,/,
698 s/^.* //')" \
699 "$pfx" "$cur_" ""
701 *...*)
702 pfx="${cur_%...*}..."
703 cur_="${cur_#*...}"
704 __git_complete_refs --pfx="$pfx" --cur="$cur_"
706 *..*)
707 pfx="${cur_%..*}.."
708 cur_="${cur_#*..}"
709 __git_complete_refs --pfx="$pfx" --cur="$cur_"
712 __git_complete_refs
714 esac
718 # __git_complete_index_file requires 1 argument:
719 # 1: the options to pass to ls-file
721 # The exception is --committable, which finds the files appropriate commit.
722 __git_complete_index_file ()
724 local pfx="" cur_="$cur"
726 case "$cur_" in
727 ?*/*)
728 pfx="${cur_%/*}"
729 cur_="${cur_##*/}"
730 pfx="${pfx}/"
732 esac
734 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
737 __git_complete_file ()
739 __git_complete_revlist_file
742 __git_complete_revlist ()
744 __git_complete_revlist_file
747 __git_complete_remote_or_refspec ()
749 local cur_="$cur" cmd="${words[1]}"
750 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
751 if [ "$cmd" = "remote" ]; then
752 ((c++))
754 while [ $c -lt $cword ]; do
755 i="${words[c]}"
756 case "$i" in
757 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
758 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
759 --all)
760 case "$cmd" in
761 push) no_complete_refspec=1 ;;
762 fetch)
763 return
765 *) ;;
766 esac
768 -*) ;;
769 *) remote="$i"; break ;;
770 esac
771 ((c++))
772 done
773 if [ -z "$remote" ]; then
774 __gitcomp_nl "$(__git_remotes)"
775 return
777 if [ $no_complete_refspec = 1 ]; then
778 return
780 [ "$remote" = "." ] && remote=
781 case "$cur_" in
782 *:*)
783 case "$COMP_WORDBREAKS" in
784 *:*) : great ;;
785 *) pfx="${cur_%%:*}:" ;;
786 esac
787 cur_="${cur_#*:}"
788 lhs=0
791 pfx="+"
792 cur_="${cur_#+}"
794 esac
795 case "$cmd" in
796 fetch)
797 if [ $lhs = 1 ]; then
798 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
799 else
800 __git_complete_refs --pfx="$pfx" --cur="$cur_"
803 pull|remote)
804 if [ $lhs = 1 ]; then
805 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
806 else
807 __git_complete_refs --pfx="$pfx" --cur="$cur_"
810 push)
811 if [ $lhs = 1 ]; then
812 __git_complete_refs --pfx="$pfx" --cur="$cur_"
813 else
814 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
817 esac
820 __git_complete_strategy ()
822 __git_compute_merge_strategies
823 case "$prev" in
824 -s|--strategy)
825 __gitcomp "$__git_merge_strategies"
826 return 0
827 esac
828 case "$cur" in
829 --strategy=*)
830 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
831 return 0
833 esac
834 return 1
837 __git_commands () {
838 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
839 then
840 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
841 else
842 git help -a|egrep '^ [a-zA-Z0-9]'
846 __git_list_all_commands ()
848 local i IFS=" "$'\n'
849 for i in $(__git_commands)
851 case $i in
852 *--*) : helper pattern;;
853 *) echo $i;;
854 esac
855 done
858 __git_all_commands=
859 __git_compute_all_commands ()
861 test -n "$__git_all_commands" ||
862 __git_all_commands=$(__git_list_all_commands)
865 __git_list_porcelain_commands ()
867 local i IFS=" "$'\n'
868 __git_compute_all_commands
869 for i in $__git_all_commands
871 case $i in
872 *--*) : helper pattern;;
873 applymbox) : ask gittus;;
874 applypatch) : ask gittus;;
875 archimport) : import;;
876 cat-file) : plumbing;;
877 check-attr) : plumbing;;
878 check-ignore) : plumbing;;
879 check-mailmap) : plumbing;;
880 check-ref-format) : plumbing;;
881 checkout-index) : plumbing;;
882 column) : internal helper;;
883 commit-tree) : plumbing;;
884 count-objects) : infrequent;;
885 credential) : credentials;;
886 credential-*) : credentials helper;;
887 cvsexportcommit) : export;;
888 cvsimport) : import;;
889 cvsserver) : daemon;;
890 daemon) : daemon;;
891 diff-files) : plumbing;;
892 diff-index) : plumbing;;
893 diff-tree) : plumbing;;
894 fast-import) : import;;
895 fast-export) : export;;
896 fsck-objects) : plumbing;;
897 fetch-pack) : plumbing;;
898 fmt-merge-msg) : plumbing;;
899 for-each-ref) : plumbing;;
900 hash-object) : plumbing;;
901 http-*) : transport;;
902 index-pack) : plumbing;;
903 init-db) : deprecated;;
904 local-fetch) : plumbing;;
905 ls-files) : plumbing;;
906 ls-remote) : plumbing;;
907 ls-tree) : plumbing;;
908 mailinfo) : plumbing;;
909 mailsplit) : plumbing;;
910 merge-*) : plumbing;;
911 mktree) : plumbing;;
912 mktag) : plumbing;;
913 pack-objects) : plumbing;;
914 pack-redundant) : plumbing;;
915 pack-refs) : plumbing;;
916 parse-remote) : plumbing;;
917 patch-id) : plumbing;;
918 prune) : plumbing;;
919 prune-packed) : plumbing;;
920 quiltimport) : import;;
921 read-tree) : plumbing;;
922 receive-pack) : plumbing;;
923 remote-*) : transport;;
924 rerere) : plumbing;;
925 rev-list) : plumbing;;
926 rev-parse) : plumbing;;
927 runstatus) : plumbing;;
928 sh-setup) : internal;;
929 shell) : daemon;;
930 show-ref) : plumbing;;
931 send-pack) : plumbing;;
932 show-index) : plumbing;;
933 ssh-*) : transport;;
934 stripspace) : plumbing;;
935 symbolic-ref) : plumbing;;
936 unpack-file) : plumbing;;
937 unpack-objects) : plumbing;;
938 update-index) : plumbing;;
939 update-ref) : plumbing;;
940 update-server-info) : daemon;;
941 upload-archive) : plumbing;;
942 upload-pack) : plumbing;;
943 write-tree) : plumbing;;
944 var) : infrequent;;
945 verify-pack) : infrequent;;
946 verify-tag) : plumbing;;
947 *) echo $i;;
948 esac
949 done
952 __git_porcelain_commands=
953 __git_compute_porcelain_commands ()
955 test -n "$__git_porcelain_commands" ||
956 __git_porcelain_commands=$(__git_list_porcelain_commands)
959 # Lists all set config variables starting with the given section prefix,
960 # with the prefix removed.
961 __git_get_config_variables ()
963 local section="$1" i IFS=$'\n'
964 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
965 echo "${i#$section.}"
966 done
969 __git_pretty_aliases ()
971 __git_get_config_variables "pretty"
974 __git_aliases ()
976 __git_get_config_variables "alias"
979 # __git_aliased_command requires 1 argument
980 __git_aliased_command ()
982 local word cmdline=$(__git config --get "alias.$1")
983 for word in $cmdline; do
984 case "$word" in
985 \!gitk|gitk)
986 echo "gitk"
987 return
989 \!*) : shell command alias ;;
990 -*) : option ;;
991 *=*) : setting env ;;
992 git) : git itself ;;
993 \(\)) : skip parens of shell function definition ;;
994 {) : skip start of shell helper function ;;
995 :) : skip null command ;;
996 \'*) : skip opening quote after sh -c ;;
998 echo "$word"
999 return
1000 esac
1001 done
1004 # __git_find_on_cmdline requires 1 argument
1005 __git_find_on_cmdline ()
1007 local word subcommand c=1
1008 while [ $c -lt $cword ]; do
1009 word="${words[c]}"
1010 for subcommand in $1; do
1011 if [ "$subcommand" = "$word" ]; then
1012 echo "$subcommand"
1013 return
1015 done
1016 ((c++))
1017 done
1020 # Echo the value of an option set on the command line or config
1022 # $1: short option name
1023 # $2: long option name including =
1024 # $3: list of possible values
1025 # $4: config string (optional)
1027 # example:
1028 # result="$(__git_get_option_value "-d" "--do-something=" \
1029 # "yes no" "core.doSomething")"
1031 # result is then either empty (no option set) or "yes" or "no"
1033 # __git_get_option_value requires 3 arguments
1034 __git_get_option_value ()
1036 local c short_opt long_opt val
1037 local result= values config_key word
1039 short_opt="$1"
1040 long_opt="$2"
1041 values="$3"
1042 config_key="$4"
1044 ((c = $cword - 1))
1045 while [ $c -ge 0 ]; do
1046 word="${words[c]}"
1047 for val in $values; do
1048 if [ "$short_opt$val" = "$word" ] ||
1049 [ "$long_opt$val" = "$word" ]; then
1050 result="$val"
1051 break 2
1053 done
1054 ((c--))
1055 done
1057 if [ -n "$config_key" ] && [ -z "$result" ]; then
1058 result="$(__git config "$config_key")"
1061 echo "$result"
1064 __git_has_doubledash ()
1066 local c=1
1067 while [ $c -lt $cword ]; do
1068 if [ "--" = "${words[c]}" ]; then
1069 return 0
1071 ((c++))
1072 done
1073 return 1
1076 # Try to count non option arguments passed on the command line for the
1077 # specified git command.
1078 # When options are used, it is necessary to use the special -- option to
1079 # tell the implementation were non option arguments begin.
1080 # XXX this can not be improved, since options can appear everywhere, as
1081 # an example:
1082 # git mv x -n y
1084 # __git_count_arguments requires 1 argument: the git command executed.
1085 __git_count_arguments ()
1087 local word i c=0
1089 # Skip "git" (first argument)
1090 for ((i=1; i < ${#words[@]}; i++)); do
1091 word="${words[i]}"
1093 case "$word" in
1095 # Good; we can assume that the following are only non
1096 # option arguments.
1097 ((c = 0))
1099 "$1")
1100 # Skip the specified git command and discard git
1101 # main options
1102 ((c = 0))
1105 ((c++))
1107 esac
1108 done
1110 printf "%d" $c
1113 __git_whitespacelist="nowarn warn error error-all fix"
1114 __git_am_inprogress_options="--skip --continue --resolved --abort"
1116 _git_am ()
1118 __git_find_repo_path
1119 if [ -d "$__git_repo_path"/rebase-apply ]; then
1120 __gitcomp "$__git_am_inprogress_options"
1121 return
1123 case "$cur" in
1124 --whitespace=*)
1125 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1126 return
1128 --*)
1129 __gitcomp_builtin am "--no-utf8" \
1130 "$__git_am_inprogress_options"
1131 return
1132 esac
1135 _git_apply ()
1137 case "$cur" in
1138 --whitespace=*)
1139 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1140 return
1142 --*)
1143 __gitcomp_builtin apply
1144 return
1145 esac
1148 _git_add ()
1150 case "$cur" in
1151 --*)
1152 __gitcomp_builtin add
1153 return
1154 esac
1156 local complete_opt="--others --modified --directory --no-empty-directory"
1157 if test -n "$(__git_find_on_cmdline "-u --update")"
1158 then
1159 complete_opt="--modified"
1161 __git_complete_index_file "$complete_opt"
1164 _git_archive ()
1166 case "$cur" in
1167 --format=*)
1168 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1169 return
1171 --remote=*)
1172 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1173 return
1175 --*)
1176 __gitcomp "
1177 --format= --list --verbose
1178 --prefix= --remote= --exec= --output
1180 return
1182 esac
1183 __git_complete_file
1186 _git_bisect ()
1188 __git_has_doubledash && return
1190 local subcommands="start bad good skip reset visualize replay log run"
1191 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1192 if [ -z "$subcommand" ]; then
1193 __git_find_repo_path
1194 if [ -f "$__git_repo_path"/BISECT_START ]; then
1195 __gitcomp "$subcommands"
1196 else
1197 __gitcomp "replay start"
1199 return
1202 case "$subcommand" in
1203 bad|good|reset|skip|start)
1204 __git_complete_refs
1208 esac
1211 _git_branch ()
1213 local i c=1 only_local_ref="n" has_r="n"
1215 while [ $c -lt $cword ]; do
1216 i="${words[c]}"
1217 case "$i" in
1218 -d|--delete|-m|--move) only_local_ref="y" ;;
1219 -r|--remotes) has_r="y" ;;
1220 esac
1221 ((c++))
1222 done
1224 case "$cur" in
1225 --set-upstream-to=*)
1226 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1228 --*)
1229 __gitcomp_builtin branch "--no-color --no-abbrev
1230 --no-track --no-column
1234 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1235 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1236 else
1237 __git_complete_refs
1240 esac
1243 _git_bundle ()
1245 local cmd="${words[2]}"
1246 case "$cword" in
1248 __gitcomp "create list-heads verify unbundle"
1251 # looking for a file
1254 case "$cmd" in
1255 create)
1256 __git_complete_revlist
1258 esac
1260 esac
1263 _git_checkout ()
1265 __git_has_doubledash && return
1267 case "$cur" in
1268 --conflict=*)
1269 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1271 --*)
1272 __gitcomp_builtin checkout "--no-track --no-recurse-submodules"
1275 # check if --track, --no-track, or --no-guess was specified
1276 # if so, disable DWIM mode
1277 local flags="--track --no-track --no-guess" track_opt="--track"
1278 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1279 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1280 track_opt=''
1282 __git_complete_refs $track_opt
1284 esac
1287 _git_cherry ()
1289 __git_complete_refs
1292 __git_cherry_pick_inprogress_options="--continue --quit --abort"
1294 _git_cherry_pick ()
1296 __git_find_repo_path
1297 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1298 __gitcomp "$__git_cherry_pick_inprogress_options"
1299 return
1301 case "$cur" in
1302 --*)
1303 __gitcomp_builtin cherry-pick "" \
1304 "$__git_cherry_pick_inprogress_options"
1307 __git_complete_refs
1309 esac
1312 _git_clean ()
1314 case "$cur" in
1315 --*)
1316 __gitcomp_builtin clean
1317 return
1319 esac
1321 # XXX should we check for -x option ?
1322 __git_complete_index_file "--others --directory"
1325 _git_clone ()
1327 case "$cur" in
1328 --*)
1329 __gitcomp_builtin clone "--no-single-branch"
1330 return
1332 esac
1335 __git_untracked_file_modes="all no normal"
1337 _git_commit ()
1339 case "$prev" in
1340 -c|-C)
1341 __git_complete_refs
1342 return
1344 esac
1346 case "$cur" in
1347 --cleanup=*)
1348 __gitcomp "default scissors strip verbatim whitespace
1349 " "" "${cur##--cleanup=}"
1350 return
1352 --reuse-message=*|--reedit-message=*|\
1353 --fixup=*|--squash=*)
1354 __git_complete_refs --cur="${cur#*=}"
1355 return
1357 --untracked-files=*)
1358 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1359 return
1361 --*)
1362 __gitcomp_builtin commit "--no-edit --verify"
1363 return
1364 esac
1366 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1367 __git_complete_index_file "--committable"
1368 else
1369 # This is the first commit
1370 __git_complete_index_file "--cached"
1374 _git_describe ()
1376 case "$cur" in
1377 --*)
1378 __gitcomp_builtin describe
1379 return
1380 esac
1381 __git_complete_refs
1384 __git_diff_algorithms="myers minimal patience histogram"
1386 __git_diff_submodule_formats="diff log short"
1388 __git_diff_common_options="--stat --numstat --shortstat --summary
1389 --patch-with-stat --name-only --name-status --color
1390 --no-color --color-words --no-renames --check
1391 --full-index --binary --abbrev --diff-filter=
1392 --find-copies-harder --ignore-cr-at-eol
1393 --text --ignore-space-at-eol --ignore-space-change
1394 --ignore-all-space --ignore-blank-lines --exit-code
1395 --quiet --ext-diff --no-ext-diff
1396 --no-prefix --src-prefix= --dst-prefix=
1397 --inter-hunk-context=
1398 --patience --histogram --minimal
1399 --raw --word-diff --word-diff-regex=
1400 --dirstat --dirstat= --dirstat-by-file
1401 --dirstat-by-file= --cumulative
1402 --diff-algorithm=
1403 --submodule --submodule= --ignore-submodules
1406 _git_diff ()
1408 __git_has_doubledash && return
1410 case "$cur" in
1411 --diff-algorithm=*)
1412 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1413 return
1415 --submodule=*)
1416 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1417 return
1419 --*)
1420 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1421 --base --ours --theirs --no-index
1422 $__git_diff_common_options
1424 return
1426 esac
1427 __git_complete_revlist_file
1430 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1431 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1434 _git_difftool ()
1436 __git_has_doubledash && return
1438 case "$cur" in
1439 --tool=*)
1440 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1441 return
1443 --*)
1444 __gitcomp_builtin difftool "$__git_diff_common_options
1445 --base --cached --ours --theirs
1446 --pickaxe-all --pickaxe-regex
1447 --relative --staged
1449 return
1451 esac
1452 __git_complete_revlist_file
1455 __git_fetch_recurse_submodules="yes on-demand no"
1457 _git_fetch ()
1459 case "$cur" in
1460 --recurse-submodules=*)
1461 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1462 return
1464 --*)
1465 __gitcomp_builtin fetch "--no-tags"
1466 return
1468 esac
1469 __git_complete_remote_or_refspec
1472 __git_format_patch_options="
1473 --stdout --attach --no-attach --thread --thread= --no-thread
1474 --numbered --start-number --numbered-files --keep-subject --signoff
1475 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1476 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1477 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1478 --output-directory --reroll-count --to= --quiet --notes
1481 _git_format_patch ()
1483 case "$cur" in
1484 --thread=*)
1485 __gitcomp "
1486 deep shallow
1487 " "" "${cur##--thread=}"
1488 return
1490 --*)
1491 __gitcomp "$__git_format_patch_options"
1492 return
1494 esac
1495 __git_complete_revlist
1498 _git_fsck ()
1500 case "$cur" in
1501 --*)
1502 __gitcomp_builtin fsck "--no-reflogs"
1503 return
1505 esac
1508 _git_gitk ()
1510 _gitk
1513 # Lists matching symbol names from a tag (as in ctags) file.
1514 # 1: List symbol names matching this word.
1515 # 2: The tag file to list symbol names from.
1516 # 3: A prefix to be added to each listed symbol name (optional).
1517 # 4: A suffix to be appended to each listed symbol name (optional).
1518 __git_match_ctag () {
1519 awk -v pfx="${3-}" -v sfx="${4-}" "
1520 /^${1//\//\\/}/ { print pfx \$1 sfx }
1521 " "$2"
1524 # Complete symbol names from a tag file.
1525 # Usage: __git_complete_symbol [<option>]...
1526 # --tags=<file>: The tag file to list symbol names from instead of the
1527 # default "tags".
1528 # --pfx=<prefix>: A prefix to be added to each symbol name.
1529 # --cur=<word>: The current symbol name to be completed. Defaults to
1530 # the current word to be completed.
1531 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1532 # of the default space.
1533 __git_complete_symbol () {
1534 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1536 while test $# != 0; do
1537 case "$1" in
1538 --tags=*) tags="${1##--tags=}" ;;
1539 --pfx=*) pfx="${1##--pfx=}" ;;
1540 --cur=*) cur_="${1##--cur=}" ;;
1541 --sfx=*) sfx="${1##--sfx=}" ;;
1542 *) return 1 ;;
1543 esac
1544 shift
1545 done
1547 if test -r "$tags"; then
1548 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1552 _git_grep ()
1554 __git_has_doubledash && return
1556 case "$cur" in
1557 --*)
1558 __gitcomp_builtin grep
1559 return
1561 esac
1563 case "$cword,$prev" in
1564 2,*|*,-*)
1565 __git_complete_symbol && return
1567 esac
1569 __git_complete_refs
1572 _git_help ()
1574 case "$cur" in
1575 --*)
1576 __gitcomp_builtin help
1577 return
1579 esac
1580 __git_compute_all_commands
1581 __gitcomp "$__git_all_commands $(__git_aliases)
1582 attributes cli core-tutorial cvs-migration
1583 diffcore everyday gitk glossary hooks ignore modules
1584 namespaces repository-layout revisions tutorial tutorial-2
1585 workflows
1589 _git_init ()
1591 case "$cur" in
1592 --shared=*)
1593 __gitcomp "
1594 false true umask group all world everybody
1595 " "" "${cur##--shared=}"
1596 return
1598 --*)
1599 __gitcomp_builtin init
1600 return
1602 esac
1605 _git_ls_files ()
1607 case "$cur" in
1608 --*)
1609 __gitcomp_builtin ls-files "--no-empty-directory"
1610 return
1612 esac
1614 # XXX ignore options like --modified and always suggest all cached
1615 # files.
1616 __git_complete_index_file "--cached"
1619 _git_ls_remote ()
1621 case "$cur" in
1622 --*)
1623 __gitcomp_builtin ls-remote
1624 return
1626 esac
1627 __gitcomp_nl "$(__git_remotes)"
1630 _git_ls_tree ()
1632 __git_complete_file
1635 # Options that go well for log, shortlog and gitk
1636 __git_log_common_options="
1637 --not --all
1638 --branches --tags --remotes
1639 --first-parent --merges --no-merges
1640 --max-count=
1641 --max-age= --since= --after=
1642 --min-age= --until= --before=
1643 --min-parents= --max-parents=
1644 --no-min-parents --no-max-parents
1646 # Options that go well for log and gitk (not shortlog)
1647 __git_log_gitk_options="
1648 --dense --sparse --full-history
1649 --simplify-merges --simplify-by-decoration
1650 --left-right --notes --no-notes
1652 # Options that go well for log and shortlog (not gitk)
1653 __git_log_shortlog_options="
1654 --author= --committer= --grep=
1655 --all-match --invert-grep
1658 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1659 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1661 _git_log ()
1663 __git_has_doubledash && return
1664 __git_find_repo_path
1666 local merge=""
1667 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1668 merge="--merge"
1670 case "$prev,$cur" in
1671 -L,:*:*)
1672 return # fall back to Bash filename completion
1674 -L,:*)
1675 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1676 return
1678 -G,*|-S,*)
1679 __git_complete_symbol
1680 return
1682 esac
1683 case "$cur" in
1684 --pretty=*|--format=*)
1685 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1686 " "" "${cur#*=}"
1687 return
1689 --date=*)
1690 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1691 return
1693 --decorate=*)
1694 __gitcomp "full short no" "" "${cur##--decorate=}"
1695 return
1697 --diff-algorithm=*)
1698 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1699 return
1701 --submodule=*)
1702 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1703 return
1705 --*)
1706 __gitcomp "
1707 $__git_log_common_options
1708 $__git_log_shortlog_options
1709 $__git_log_gitk_options
1710 --root --topo-order --date-order --reverse
1711 --follow --full-diff
1712 --abbrev-commit --abbrev=
1713 --relative-date --date=
1714 --pretty= --format= --oneline
1715 --show-signature
1716 --cherry-mark
1717 --cherry-pick
1718 --graph
1719 --decorate --decorate=
1720 --walk-reflogs
1721 --parents --children
1722 $merge
1723 $__git_diff_common_options
1724 --pickaxe-all --pickaxe-regex
1726 return
1728 -L:*:*)
1729 return # fall back to Bash filename completion
1731 -L:*)
1732 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1733 return
1735 -G*)
1736 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1737 return
1739 -S*)
1740 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1741 return
1743 esac
1744 __git_complete_revlist
1747 _git_merge ()
1749 __git_complete_strategy && return
1751 case "$cur" in
1752 --*)
1753 __gitcomp_builtin merge "--no-rerere-autoupdate
1754 --no-commit --no-edit --no-ff
1755 --no-log --no-progress
1756 --no-squash --no-stat
1757 --no-verify-signatures
1759 return
1760 esac
1761 __git_complete_refs
1764 _git_mergetool ()
1766 case "$cur" in
1767 --tool=*)
1768 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1769 return
1771 --*)
1772 __gitcomp "--tool= --prompt --no-prompt"
1773 return
1775 esac
1778 _git_merge_base ()
1780 case "$cur" in
1781 --*)
1782 __gitcomp_builtin merge-base
1783 return
1785 esac
1786 __git_complete_refs
1789 _git_mv ()
1791 case "$cur" in
1792 --*)
1793 __gitcomp_builtin mv
1794 return
1796 esac
1798 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1799 # We need to show both cached and untracked files (including
1800 # empty directories) since this may not be the last argument.
1801 __git_complete_index_file "--cached --others --directory"
1802 else
1803 __git_complete_index_file "--cached"
1807 _git_notes ()
1809 local subcommands='add append copy edit get-ref list merge prune remove show'
1810 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1812 case "$subcommand,$cur" in
1813 ,--*)
1814 __gitcomp_builtin notes
1817 case "$prev" in
1818 --ref)
1819 __git_complete_refs
1822 __gitcomp "$subcommands --ref"
1824 esac
1826 *,--reuse-message=*|*,--reedit-message=*)
1827 __git_complete_refs --cur="${cur#*=}"
1829 *,--*)
1830 __gitcomp_builtin notes_$subcommand
1832 prune,*|get-ref,*)
1833 # this command does not take a ref, do not complete it
1836 case "$prev" in
1837 -m|-F)
1840 __git_complete_refs
1842 esac
1844 esac
1847 _git_pull ()
1849 __git_complete_strategy && return
1851 case "$cur" in
1852 --recurse-submodules=*)
1853 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1854 return
1856 --*)
1857 __gitcomp_builtin pull "--no-autostash --no-commit --no-edit
1858 --no-ff --no-log --no-progress --no-rebase
1859 --no-squash --no-stat --no-tags
1860 --no-verify-signatures"
1862 return
1864 esac
1865 __git_complete_remote_or_refspec
1868 __git_push_recurse_submodules="check on-demand only"
1870 __git_complete_force_with_lease ()
1872 local cur_=$1
1874 case "$cur_" in
1875 --*=)
1877 *:*)
1878 __git_complete_refs --cur="${cur_#*:}"
1881 __git_complete_refs --cur="$cur_"
1883 esac
1886 _git_push ()
1888 case "$prev" in
1889 --repo)
1890 __gitcomp_nl "$(__git_remotes)"
1891 return
1893 --recurse-submodules)
1894 __gitcomp "$__git_push_recurse_submodules"
1895 return
1897 esac
1898 case "$cur" in
1899 --repo=*)
1900 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1901 return
1903 --recurse-submodules=*)
1904 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1905 return
1907 --force-with-lease=*)
1908 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1909 return
1911 --*)
1912 __gitcomp_builtin push
1913 return
1915 esac
1916 __git_complete_remote_or_refspec
1919 _git_rebase ()
1921 __git_find_repo_path
1922 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1923 __gitcomp "--continue --skip --abort --quit --edit-todo"
1924 return
1925 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1926 [ -d "$__git_repo_path"/rebase-merge ]; then
1927 __gitcomp "--continue --skip --abort --quit"
1928 return
1930 __git_complete_strategy && return
1931 case "$cur" in
1932 --whitespace=*)
1933 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1934 return
1936 --*)
1937 __gitcomp "
1938 --onto --merge --strategy --interactive
1939 --preserve-merges --stat --no-stat
1940 --committer-date-is-author-date --ignore-date
1941 --ignore-whitespace --whitespace=
1942 --autosquash --no-autosquash
1943 --fork-point --no-fork-point
1944 --autostash --no-autostash
1945 --verify --no-verify
1946 --keep-empty --root --force-rebase --no-ff
1947 --rerere-autoupdate
1948 --exec
1951 return
1952 esac
1953 __git_complete_refs
1956 _git_reflog ()
1958 local subcommands="show delete expire"
1959 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1961 if [ -z "$subcommand" ]; then
1962 __gitcomp "$subcommands"
1963 else
1964 __git_complete_refs
1968 __git_send_email_confirm_options="always never auto cc compose"
1969 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1971 _git_send_email ()
1973 case "$prev" in
1974 --to|--cc|--bcc|--from)
1975 __gitcomp "$(__git send-email --dump-aliases)"
1976 return
1978 esac
1980 case "$cur" in
1981 --confirm=*)
1982 __gitcomp "
1983 $__git_send_email_confirm_options
1984 " "" "${cur##--confirm=}"
1985 return
1987 --suppress-cc=*)
1988 __gitcomp "
1989 $__git_send_email_suppresscc_options
1990 " "" "${cur##--suppress-cc=}"
1992 return
1994 --smtp-encryption=*)
1995 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1996 return
1998 --thread=*)
1999 __gitcomp "
2000 deep shallow
2001 " "" "${cur##--thread=}"
2002 return
2004 --to=*|--cc=*|--bcc=*|--from=*)
2005 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2006 return
2008 --*)
2009 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2010 --compose --confirm= --dry-run --envelope-sender
2011 --from --identity
2012 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2013 --no-suppress-from --no-thread --quiet
2014 --signed-off-by-cc --smtp-pass --smtp-server
2015 --smtp-server-port --smtp-encryption= --smtp-user
2016 --subject --suppress-cc= --suppress-from --thread --to
2017 --validate --no-validate
2018 $__git_format_patch_options"
2019 return
2021 esac
2022 __git_complete_revlist
2025 _git_stage ()
2027 _git_add
2030 _git_status ()
2032 local complete_opt
2033 local untracked_state
2035 case "$cur" in
2036 --ignore-submodules=*)
2037 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2038 return
2040 --untracked-files=*)
2041 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2042 return
2044 --column=*)
2045 __gitcomp "
2046 always never auto column row plain dense nodense
2047 " "" "${cur##--column=}"
2048 return
2050 --*)
2051 __gitcomp_builtin status "--no-column"
2052 return
2054 esac
2056 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2057 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2059 case "$untracked_state" in
2061 # --ignored option does not matter
2062 complete_opt=
2064 all|normal|*)
2065 complete_opt="--cached --directory --no-empty-directory --others"
2067 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2068 complete_opt="$complete_opt --ignored --exclude=*"
2071 esac
2073 __git_complete_index_file "$complete_opt"
2076 __git_config_get_set_variables ()
2078 local prevword word config_file= c=$cword
2079 while [ $c -gt 1 ]; do
2080 word="${words[c]}"
2081 case "$word" in
2082 --system|--global|--local|--file=*)
2083 config_file="$word"
2084 break
2086 -f|--file)
2087 config_file="$word $prevword"
2088 break
2090 esac
2091 prevword=$word
2092 c=$((--c))
2093 done
2095 __git config $config_file --name-only --list
2098 _git_config ()
2100 case "$prev" in
2101 branch.*.remote|branch.*.pushremote)
2102 __gitcomp_nl "$(__git_remotes)"
2103 return
2105 branch.*.merge)
2106 __git_complete_refs
2107 return
2109 branch.*.rebase)
2110 __gitcomp "false true preserve interactive"
2111 return
2113 remote.pushdefault)
2114 __gitcomp_nl "$(__git_remotes)"
2115 return
2117 remote.*.fetch)
2118 local remote="${prev#remote.}"
2119 remote="${remote%.fetch}"
2120 if [ -z "$cur" ]; then
2121 __gitcomp_nl "refs/heads/" "" "" ""
2122 return
2124 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2125 return
2127 remote.*.push)
2128 local remote="${prev#remote.}"
2129 remote="${remote%.push}"
2130 __gitcomp_nl "$(__git for-each-ref \
2131 --format='%(refname):%(refname)' refs/heads)"
2132 return
2134 pull.twohead|pull.octopus)
2135 __git_compute_merge_strategies
2136 __gitcomp "$__git_merge_strategies"
2137 return
2139 color.branch|color.diff|color.interactive|\
2140 color.showbranch|color.status|color.ui)
2141 __gitcomp "always never auto"
2142 return
2144 color.pager)
2145 __gitcomp "false true"
2146 return
2148 color.*.*)
2149 __gitcomp "
2150 normal black red green yellow blue magenta cyan white
2151 bold dim ul blink reverse
2153 return
2155 diff.submodule)
2156 __gitcomp "log short"
2157 return
2159 help.format)
2160 __gitcomp "man info web html"
2161 return
2163 log.date)
2164 __gitcomp "$__git_log_date_formats"
2165 return
2167 sendemail.aliasesfiletype)
2168 __gitcomp "mutt mailrc pine elm gnus"
2169 return
2171 sendemail.confirm)
2172 __gitcomp "$__git_send_email_confirm_options"
2173 return
2175 sendemail.suppresscc)
2176 __gitcomp "$__git_send_email_suppresscc_options"
2177 return
2179 sendemail.transferencoding)
2180 __gitcomp "7bit 8bit quoted-printable base64"
2181 return
2183 --get|--get-all|--unset|--unset-all)
2184 __gitcomp_nl "$(__git_config_get_set_variables)"
2185 return
2187 *.*)
2188 return
2190 esac
2191 case "$cur" in
2192 --*)
2193 __gitcomp_builtin config
2194 return
2196 branch.*.*)
2197 local pfx="${cur%.*}." cur_="${cur##*.}"
2198 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2199 return
2201 branch.*)
2202 local pfx="${cur%.*}." cur_="${cur#*.}"
2203 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2204 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2205 return
2207 guitool.*.*)
2208 local pfx="${cur%.*}." cur_="${cur##*.}"
2209 __gitcomp "
2210 argprompt cmd confirm needsfile noconsole norescan
2211 prompt revprompt revunmerged title
2212 " "$pfx" "$cur_"
2213 return
2215 difftool.*.*)
2216 local pfx="${cur%.*}." cur_="${cur##*.}"
2217 __gitcomp "cmd path" "$pfx" "$cur_"
2218 return
2220 man.*.*)
2221 local pfx="${cur%.*}." cur_="${cur##*.}"
2222 __gitcomp "cmd path" "$pfx" "$cur_"
2223 return
2225 mergetool.*.*)
2226 local pfx="${cur%.*}." cur_="${cur##*.}"
2227 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2228 return
2230 pager.*)
2231 local pfx="${cur%.*}." cur_="${cur#*.}"
2232 __git_compute_all_commands
2233 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2234 return
2236 remote.*.*)
2237 local pfx="${cur%.*}." cur_="${cur##*.}"
2238 __gitcomp "
2239 url proxy fetch push mirror skipDefaultUpdate
2240 receivepack uploadpack tagopt pushurl
2241 " "$pfx" "$cur_"
2242 return
2244 remote.*)
2245 local pfx="${cur%.*}." cur_="${cur#*.}"
2246 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2247 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2248 return
2250 url.*.*)
2251 local pfx="${cur%.*}." cur_="${cur##*.}"
2252 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2253 return
2255 esac
2256 __gitcomp "
2257 add.ignoreErrors
2258 advice.amWorkDir
2259 advice.commitBeforeMerge
2260 advice.detachedHead
2261 advice.implicitIdentity
2262 advice.pushAlreadyExists
2263 advice.pushFetchFirst
2264 advice.pushNeedsForce
2265 advice.pushNonFFCurrent
2266 advice.pushNonFFMatching
2267 advice.pushUpdateRejected
2268 advice.resolveConflict
2269 advice.rmHints
2270 advice.statusHints
2271 advice.statusUoption
2272 advice.ignoredHook
2273 alias.
2274 am.keepcr
2275 am.threeWay
2276 apply.ignorewhitespace
2277 apply.whitespace
2278 branch.autosetupmerge
2279 branch.autosetuprebase
2280 browser.
2281 clean.requireForce
2282 color.branch
2283 color.branch.current
2284 color.branch.local
2285 color.branch.plain
2286 color.branch.remote
2287 color.decorate.HEAD
2288 color.decorate.branch
2289 color.decorate.remoteBranch
2290 color.decorate.stash
2291 color.decorate.tag
2292 color.diff
2293 color.diff.commit
2294 color.diff.frag
2295 color.diff.func
2296 color.diff.meta
2297 color.diff.new
2298 color.diff.old
2299 color.diff.plain
2300 color.diff.whitespace
2301 color.grep
2302 color.grep.context
2303 color.grep.filename
2304 color.grep.function
2305 color.grep.linenumber
2306 color.grep.match
2307 color.grep.selected
2308 color.grep.separator
2309 color.interactive
2310 color.interactive.error
2311 color.interactive.header
2312 color.interactive.help
2313 color.interactive.prompt
2314 color.pager
2315 color.showbranch
2316 color.status
2317 color.status.added
2318 color.status.changed
2319 color.status.header
2320 color.status.localBranch
2321 color.status.nobranch
2322 color.status.remoteBranch
2323 color.status.unmerged
2324 color.status.untracked
2325 color.status.updated
2326 color.ui
2327 commit.cleanup
2328 commit.gpgSign
2329 commit.status
2330 commit.template
2331 commit.verbose
2332 core.abbrev
2333 core.askpass
2334 core.attributesfile
2335 core.autocrlf
2336 core.bare
2337 core.bigFileThreshold
2338 core.checkStat
2339 core.commentChar
2340 core.compression
2341 core.createObject
2342 core.deltaBaseCacheLimit
2343 core.editor
2344 core.eol
2345 core.excludesfile
2346 core.fileMode
2347 core.fsyncobjectfiles
2348 core.gitProxy
2349 core.hideDotFiles
2350 core.hooksPath
2351 core.ignoreStat
2352 core.ignorecase
2353 core.logAllRefUpdates
2354 core.loosecompression
2355 core.notesRef
2356 core.packedGitLimit
2357 core.packedGitWindowSize
2358 core.packedRefsTimeout
2359 core.pager
2360 core.precomposeUnicode
2361 core.preferSymlinkRefs
2362 core.preloadindex
2363 core.protectHFS
2364 core.protectNTFS
2365 core.quotepath
2366 core.repositoryFormatVersion
2367 core.safecrlf
2368 core.sharedRepository
2369 core.sparseCheckout
2370 core.splitIndex
2371 core.sshCommand
2372 core.symlinks
2373 core.trustctime
2374 core.untrackedCache
2375 core.warnAmbiguousRefs
2376 core.whitespace
2377 core.worktree
2378 credential.helper
2379 credential.useHttpPath
2380 credential.username
2381 credentialCache.ignoreSIGHUP
2382 diff.autorefreshindex
2383 diff.external
2384 diff.ignoreSubmodules
2385 diff.mnemonicprefix
2386 diff.noprefix
2387 diff.renameLimit
2388 diff.renames
2389 diff.statGraphWidth
2390 diff.submodule
2391 diff.suppressBlankEmpty
2392 diff.tool
2393 diff.wordRegex
2394 diff.algorithm
2395 difftool.
2396 difftool.prompt
2397 fetch.recurseSubmodules
2398 fetch.unpackLimit
2399 format.attach
2400 format.cc
2401 format.coverLetter
2402 format.from
2403 format.headers
2404 format.numbered
2405 format.pretty
2406 format.signature
2407 format.signoff
2408 format.subjectprefix
2409 format.suffix
2410 format.thread
2411 format.to
2413 gc.aggressiveDepth
2414 gc.aggressiveWindow
2415 gc.auto
2416 gc.autoDetach
2417 gc.autopacklimit
2418 gc.logExpiry
2419 gc.packrefs
2420 gc.pruneexpire
2421 gc.reflogexpire
2422 gc.reflogexpireunreachable
2423 gc.rerereresolved
2424 gc.rerereunresolved
2425 gc.worktreePruneExpire
2426 gitcvs.allbinary
2427 gitcvs.commitmsgannotation
2428 gitcvs.dbTableNamePrefix
2429 gitcvs.dbdriver
2430 gitcvs.dbname
2431 gitcvs.dbpass
2432 gitcvs.dbuser
2433 gitcvs.enabled
2434 gitcvs.logfile
2435 gitcvs.usecrlfattr
2436 guitool.
2437 gui.blamehistoryctx
2438 gui.commitmsgwidth
2439 gui.copyblamethreshold
2440 gui.diffcontext
2441 gui.encoding
2442 gui.fastcopyblame
2443 gui.matchtrackingbranch
2444 gui.newbranchtemplate
2445 gui.pruneduringfetch
2446 gui.spellingdictionary
2447 gui.trustmtime
2448 help.autocorrect
2449 help.browser
2450 help.format
2451 http.lowSpeedLimit
2452 http.lowSpeedTime
2453 http.maxRequests
2454 http.minSessions
2455 http.noEPSV
2456 http.postBuffer
2457 http.proxy
2458 http.sslCipherList
2459 http.sslVersion
2460 http.sslCAInfo
2461 http.sslCAPath
2462 http.sslCert
2463 http.sslCertPasswordProtected
2464 http.sslKey
2465 http.sslVerify
2466 http.useragent
2467 i18n.commitEncoding
2468 i18n.logOutputEncoding
2469 imap.authMethod
2470 imap.folder
2471 imap.host
2472 imap.pass
2473 imap.port
2474 imap.preformattedHTML
2475 imap.sslverify
2476 imap.tunnel
2477 imap.user
2478 init.templatedir
2479 instaweb.browser
2480 instaweb.httpd
2481 instaweb.local
2482 instaweb.modulepath
2483 instaweb.port
2484 interactive.singlekey
2485 log.date
2486 log.decorate
2487 log.showroot
2488 mailmap.file
2489 man.
2490 man.viewer
2491 merge.
2492 merge.conflictstyle
2493 merge.log
2494 merge.renameLimit
2495 merge.renormalize
2496 merge.stat
2497 merge.tool
2498 merge.verbosity
2499 mergetool.
2500 mergetool.keepBackup
2501 mergetool.keepTemporaries
2502 mergetool.prompt
2503 notes.displayRef
2504 notes.rewrite.
2505 notes.rewrite.amend
2506 notes.rewrite.rebase
2507 notes.rewriteMode
2508 notes.rewriteRef
2509 pack.compression
2510 pack.deltaCacheLimit
2511 pack.deltaCacheSize
2512 pack.depth
2513 pack.indexVersion
2514 pack.packSizeLimit
2515 pack.threads
2516 pack.window
2517 pack.windowMemory
2518 pager.
2519 pretty.
2520 pull.octopus
2521 pull.twohead
2522 push.default
2523 push.followTags
2524 rebase.autosquash
2525 rebase.stat
2526 receive.autogc
2527 receive.denyCurrentBranch
2528 receive.denyDeleteCurrent
2529 receive.denyDeletes
2530 receive.denyNonFastForwards
2531 receive.fsckObjects
2532 receive.unpackLimit
2533 receive.updateserverinfo
2534 remote.pushdefault
2535 remotes.
2536 repack.usedeltabaseoffset
2537 rerere.autoupdate
2538 rerere.enabled
2539 sendemail.
2540 sendemail.aliasesfile
2541 sendemail.aliasfiletype
2542 sendemail.bcc
2543 sendemail.cc
2544 sendemail.cccmd
2545 sendemail.chainreplyto
2546 sendemail.confirm
2547 sendemail.envelopesender
2548 sendemail.from
2549 sendemail.identity
2550 sendemail.multiedit
2551 sendemail.signedoffbycc
2552 sendemail.smtpdomain
2553 sendemail.smtpencryption
2554 sendemail.smtppass
2555 sendemail.smtpserver
2556 sendemail.smtpserveroption
2557 sendemail.smtpserverport
2558 sendemail.smtpuser
2559 sendemail.suppresscc
2560 sendemail.suppressfrom
2561 sendemail.thread
2562 sendemail.to
2563 sendemail.tocmd
2564 sendemail.validate
2565 sendemail.smtpbatchsize
2566 sendemail.smtprelogindelay
2567 showbranch.default
2568 status.relativePaths
2569 status.showUntrackedFiles
2570 status.submodulesummary
2571 submodule.
2572 tar.umask
2573 transfer.unpackLimit
2574 url.
2575 user.email
2576 user.name
2577 user.signingkey
2578 web.browser
2579 branch. remote.
2583 _git_remote ()
2585 local subcommands="
2586 add rename remove set-head set-branches
2587 get-url set-url show prune update
2589 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2590 if [ -z "$subcommand" ]; then
2591 case "$cur" in
2592 --*)
2593 __gitcomp_builtin remote
2596 __gitcomp "$subcommands"
2598 esac
2599 return
2602 case "$subcommand,$cur" in
2603 add,--*)
2604 __gitcomp_builtin remote_add "--no-tags"
2606 add,*)
2608 set-head,--*)
2609 __gitcomp_builtin remote_set-head
2611 set-branches,--*)
2612 __gitcomp_builtin remote_set-branches
2614 set-head,*|set-branches,*)
2615 __git_complete_remote_or_refspec
2617 update,--*)
2618 __gitcomp_builtin remote_update
2620 update,*)
2621 __gitcomp "$(__git_get_config_variables "remotes")"
2623 set-url,--*)
2624 __gitcomp_builtin remote_set-url
2626 get-url,--*)
2627 __gitcomp_builtin remote_get-url
2629 prune,--*)
2630 __gitcomp_builtin remote_prune
2633 __gitcomp_nl "$(__git_remotes)"
2635 esac
2638 _git_replace ()
2640 case "$cur" in
2641 --*)
2642 __gitcomp_builtin replace
2643 return
2645 esac
2646 __git_complete_refs
2649 _git_rerere ()
2651 local subcommands="clear forget diff remaining status gc"
2652 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2653 if test -z "$subcommand"
2654 then
2655 __gitcomp "$subcommands"
2656 return
2660 _git_reset ()
2662 __git_has_doubledash && return
2664 case "$cur" in
2665 --*)
2666 __gitcomp_builtin reset
2667 return
2669 esac
2670 __git_complete_refs
2673 __git_revert_inprogress_options="--continue --quit --abort"
2675 _git_revert ()
2677 __git_find_repo_path
2678 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2679 __gitcomp "$__git_revert_inprogress_options"
2680 return
2682 case "$cur" in
2683 --*)
2684 __gitcomp_builtin revert "--no-edit" \
2685 "$__git_revert_inprogress_options"
2686 return
2688 esac
2689 __git_complete_refs
2692 _git_rm ()
2694 case "$cur" in
2695 --*)
2696 __gitcomp_builtin rm
2697 return
2699 esac
2701 __git_complete_index_file "--cached"
2704 _git_shortlog ()
2706 __git_has_doubledash && return
2708 case "$cur" in
2709 --*)
2710 __gitcomp "
2711 $__git_log_common_options
2712 $__git_log_shortlog_options
2713 --numbered --summary --email
2715 return
2717 esac
2718 __git_complete_revlist
2721 _git_show ()
2723 __git_has_doubledash && return
2725 case "$cur" in
2726 --pretty=*|--format=*)
2727 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2728 " "" "${cur#*=}"
2729 return
2731 --diff-algorithm=*)
2732 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2733 return
2735 --submodule=*)
2736 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2737 return
2739 --*)
2740 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2741 --show-signature
2742 $__git_diff_common_options
2744 return
2746 esac
2747 __git_complete_revlist_file
2750 _git_show_branch ()
2752 case "$cur" in
2753 --*)
2754 __gitcomp_builtin show-branch "--no-color"
2755 return
2757 esac
2758 __git_complete_revlist
2761 _git_stash ()
2763 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2764 local subcommands='push save list show apply clear drop pop create branch'
2765 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2766 if [ -z "$subcommand" ]; then
2767 case "$cur" in
2768 --*)
2769 __gitcomp "$save_opts"
2772 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2773 __gitcomp "$subcommands"
2776 esac
2777 else
2778 case "$subcommand,$cur" in
2779 push,--*)
2780 __gitcomp "$save_opts --message"
2782 save,--*)
2783 __gitcomp "$save_opts"
2785 apply,--*|pop,--*)
2786 __gitcomp "--index --quiet"
2788 drop,--*)
2789 __gitcomp "--quiet"
2791 show,--*|branch,--*)
2793 branch,*)
2794 if [ $cword -eq 3 ]; then
2795 __git_complete_refs
2796 else
2797 __gitcomp_nl "$(__git stash list \
2798 | sed -n -e 's/:.*//p')"
2801 show,*|apply,*|drop,*|pop,*)
2802 __gitcomp_nl "$(__git stash list \
2803 | sed -n -e 's/:.*//p')"
2807 esac
2811 _git_submodule ()
2813 __git_has_doubledash && return
2815 local subcommands="add status init deinit update summary foreach sync"
2816 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2817 if [ -z "$subcommand" ]; then
2818 case "$cur" in
2819 --*)
2820 __gitcomp "--quiet"
2823 __gitcomp "$subcommands"
2825 esac
2826 return
2829 case "$subcommand,$cur" in
2830 add,--*)
2831 __gitcomp "--branch --force --name --reference --depth"
2833 status,--*)
2834 __gitcomp "--cached --recursive"
2836 deinit,--*)
2837 __gitcomp "--force --all"
2839 update,--*)
2840 __gitcomp "
2841 --init --remote --no-fetch
2842 --recommend-shallow --no-recommend-shallow
2843 --force --rebase --merge --reference --depth --recursive --jobs
2846 summary,--*)
2847 __gitcomp "--cached --files --summary-limit"
2849 foreach,--*|sync,--*)
2850 __gitcomp "--recursive"
2854 esac
2857 _git_svn ()
2859 local subcommands="
2860 init fetch clone rebase dcommit log find-rev
2861 set-tree commit-diff info create-ignore propget
2862 proplist show-ignore show-externals branch tag blame
2863 migrate mkdirs reset gc
2865 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2866 if [ -z "$subcommand" ]; then
2867 __gitcomp "$subcommands"
2868 else
2869 local remote_opts="--username= --config-dir= --no-auth-cache"
2870 local fc_opts="
2871 --follow-parent --authors-file= --repack=
2872 --no-metadata --use-svm-props --use-svnsync-props
2873 --log-window-size= --no-checkout --quiet
2874 --repack-flags --use-log-author --localtime
2875 --add-author-from
2876 --ignore-paths= --include-paths= $remote_opts
2878 local init_opts="
2879 --template= --shared= --trunk= --tags=
2880 --branches= --stdlayout --minimize-url
2881 --no-metadata --use-svm-props --use-svnsync-props
2882 --rewrite-root= --prefix= $remote_opts
2884 local cmt_opts="
2885 --edit --rmdir --find-copies-harder --copy-similarity=
2888 case "$subcommand,$cur" in
2889 fetch,--*)
2890 __gitcomp "--revision= --fetch-all $fc_opts"
2892 clone,--*)
2893 __gitcomp "--revision= $fc_opts $init_opts"
2895 init,--*)
2896 __gitcomp "$init_opts"
2898 dcommit,--*)
2899 __gitcomp "
2900 --merge --strategy= --verbose --dry-run
2901 --fetch-all --no-rebase --commit-url
2902 --revision --interactive $cmt_opts $fc_opts
2905 set-tree,--*)
2906 __gitcomp "--stdin $cmt_opts $fc_opts"
2908 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2909 show-externals,--*|mkdirs,--*)
2910 __gitcomp "--revision="
2912 log,--*)
2913 __gitcomp "
2914 --limit= --revision= --verbose --incremental
2915 --oneline --show-commit --non-recursive
2916 --authors-file= --color
2919 rebase,--*)
2920 __gitcomp "
2921 --merge --verbose --strategy= --local
2922 --fetch-all --dry-run $fc_opts
2925 commit-diff,--*)
2926 __gitcomp "--message= --file= --revision= $cmt_opts"
2928 info,--*)
2929 __gitcomp "--url"
2931 branch,--*)
2932 __gitcomp "--dry-run --message --tag"
2934 tag,--*)
2935 __gitcomp "--dry-run --message"
2937 blame,--*)
2938 __gitcomp "--git-format"
2940 migrate,--*)
2941 __gitcomp "
2942 --config-dir= --ignore-paths= --minimize
2943 --no-auth-cache --username=
2946 reset,--*)
2947 __gitcomp "--revision= --parent"
2951 esac
2955 _git_tag ()
2957 local i c=1 f=0
2958 while [ $c -lt $cword ]; do
2959 i="${words[c]}"
2960 case "$i" in
2961 -d|-v)
2962 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2963 return
2968 esac
2969 ((c++))
2970 done
2972 case "$prev" in
2973 -m|-F)
2975 -*|tag)
2976 if [ $f = 1 ]; then
2977 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2981 __git_complete_refs
2983 esac
2985 case "$cur" in
2986 --*)
2987 __gitcomp_builtin tag
2989 esac
2992 _git_whatchanged ()
2994 _git_log
2997 _git_worktree ()
2999 local subcommands="add list lock prune unlock"
3000 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3001 if [ -z "$subcommand" ]; then
3002 __gitcomp "$subcommands"
3003 else
3004 case "$subcommand,$cur" in
3005 add,--*)
3006 __gitcomp_builtin worktree_add
3008 list,--*)
3009 __gitcomp_builtin worktree_list
3011 lock,--*)
3012 __gitcomp_builtin worktree_lock
3014 prune,--*)
3015 __gitcomp_builtin worktree_prune
3019 esac
3023 __git_complete_common () {
3024 local command="$1"
3026 case "$cur" in
3027 --*)
3028 __gitcomp_builtin "$command"
3030 esac
3033 __git_cmds_with_parseopt_helper=
3034 __git_support_parseopt_helper () {
3035 test -n "$__git_cmds_with_parseopt_helper" ||
3036 __git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
3038 case " $__git_cmds_with_parseopt_helper " in
3039 *" $1 "*)
3040 return 0
3043 return 1
3045 esac
3048 __git_complete_command () {
3049 local command="$1"
3050 local completion_func="_git_${command//-/_}"
3051 if declare -f $completion_func >/dev/null 2>/dev/null; then
3052 $completion_func
3053 return 0
3054 elif __git_support_parseopt_helper "$command"; then
3055 __git_complete_common "$command"
3056 return 0
3057 else
3058 return 1
3062 __git_main ()
3064 local i c=1 command __git_dir __git_repo_path
3065 local __git_C_args C_args_count=0
3067 while [ $c -lt $cword ]; do
3068 i="${words[c]}"
3069 case "$i" in
3070 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
3071 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
3072 --bare) __git_dir="." ;;
3073 --help) command="help"; break ;;
3074 -c|--work-tree|--namespace) ((c++)) ;;
3075 -C) __git_C_args[C_args_count++]=-C
3076 ((c++))
3077 __git_C_args[C_args_count++]="${words[c]}"
3079 -*) ;;
3080 *) command="$i"; break ;;
3081 esac
3082 ((c++))
3083 done
3085 if [ -z "$command" ]; then
3086 case "$prev" in
3087 --git-dir|-C|--work-tree)
3088 # these need a path argument, let's fall back to
3089 # Bash filename completion
3090 return
3092 -c|--namespace)
3093 # we don't support completing these options' arguments
3094 return
3096 esac
3097 case "$cur" in
3098 --*) __gitcomp "
3099 --paginate
3100 --no-pager
3101 --git-dir=
3102 --bare
3103 --version
3104 --exec-path
3105 --exec-path=
3106 --html-path
3107 --man-path
3108 --info-path
3109 --work-tree=
3110 --namespace=
3111 --no-replace-objects
3112 --help
3115 *) __git_compute_porcelain_commands
3116 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
3117 esac
3118 return
3121 __git_complete_command "$command" && return
3123 local expansion=$(__git_aliased_command "$command")
3124 if [ -n "$expansion" ]; then
3125 words[1]=$expansion
3126 __git_complete_command "$expansion"
3130 __gitk_main ()
3132 __git_has_doubledash && return
3134 local __git_repo_path
3135 __git_find_repo_path
3137 local merge=""
3138 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3139 merge="--merge"
3141 case "$cur" in
3142 --*)
3143 __gitcomp "
3144 $__git_log_common_options
3145 $__git_log_gitk_options
3146 $merge
3148 return
3150 esac
3151 __git_complete_revlist
3154 if [[ -n ${ZSH_VERSION-} ]]; then
3155 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3157 autoload -U +X compinit && compinit
3159 __gitcomp ()
3161 emulate -L zsh
3163 local cur_="${3-$cur}"
3165 case "$cur_" in
3166 --*=)
3169 local c IFS=$' \t\n'
3170 local -a array
3171 for c in ${=1}; do
3172 c="$c${4-}"
3173 case $c in
3174 --*=*|*.) ;;
3175 *) c="$c " ;;
3176 esac
3177 array[${#array[@]}+1]="$c"
3178 done
3179 compset -P '*[=:]'
3180 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3182 esac
3185 __gitcomp_direct ()
3187 emulate -L zsh
3189 local IFS=$'\n'
3190 compset -P '*[=:]'
3191 compadd -Q -- ${=1} && _ret=0
3194 __gitcomp_nl ()
3196 emulate -L zsh
3198 local IFS=$'\n'
3199 compset -P '*[=:]'
3200 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3203 __gitcomp_file ()
3205 emulate -L zsh
3207 local IFS=$'\n'
3208 compset -P '*[=:]'
3209 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3212 _git ()
3214 local _ret=1 cur cword prev
3215 cur=${words[CURRENT]}
3216 prev=${words[CURRENT-1]}
3217 let cword=CURRENT-1
3218 emulate ksh -c __${service}_main
3219 let _ret && _default && _ret=0
3220 return _ret
3223 compdef _git git gitk
3224 return
3227 __git_func_wrap ()
3229 local cur words cword prev
3230 _get_comp_words_by_ref -n =: cur words cword prev
3234 # Setup completion for certain functions defined above by setting common
3235 # variables and workarounds.
3236 # This is NOT a public function; use at your own risk.
3237 __git_complete ()
3239 local wrapper="__git_wrap${2}"
3240 eval "$wrapper () { __git_func_wrap $2 ; }"
3241 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3242 || complete -o default -o nospace -F $wrapper $1
3245 # wrapper for backwards compatibility
3246 _git ()
3248 __git_wrap__git_main
3251 # wrapper for backwards compatibility
3252 _gitk ()
3254 __git_wrap__gitk_main
3257 __git_complete git __git_main
3258 __git_complete gitk __gitk_main
3260 # The following are necessary only for Cygwin, and only are needed
3261 # when the user has tab-completed the executable name and consequently
3262 # included the '.exe' suffix.
3264 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3265 __git_complete git.exe __git_main