completion: don't disambiguate tags and branches
[git/debian.git] / contrib / completion / git-completion.bash
blobe129f674e3ebd3b1ae928358ae8d1aad9223fc3d
1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 case "$COMP_WORDBREAKS" in
33 *:*) : great ;;
34 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
35 esac
37 # Discovers the path to the git repository taking any '--git-dir=<path>' and
38 # '-C <path>' options into account and stores it in the $__git_repo_path
39 # variable.
40 __git_find_repo_path ()
42 if [ -n "$__git_repo_path" ]; then
43 # we already know where it is
44 return
47 if [ -n "${__git_C_args-}" ]; then
48 __git_repo_path="$(git "${__git_C_args[@]}" \
49 ${__git_dir:+--git-dir="$__git_dir"} \
50 rev-parse --absolute-git-dir 2>/dev/null)"
51 elif [ -n "${__git_dir-}" ]; then
52 test -d "$__git_dir" &&
53 __git_repo_path="$__git_dir"
54 elif [ -n "${GIT_DIR-}" ]; then
55 test -d "${GIT_DIR-}" &&
56 __git_repo_path="$GIT_DIR"
57 elif [ -d .git ]; then
58 __git_repo_path=.git
59 else
60 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
64 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
65 # __gitdir accepts 0 or 1 arguments (i.e., location)
66 # returns location of .git repo
67 __gitdir ()
69 if [ -z "${1-}" ]; then
70 __git_find_repo_path || return 1
71 echo "$__git_repo_path"
72 elif [ -d "$1/.git" ]; then
73 echo "$1/.git"
74 else
75 echo "$1"
79 # Runs git with all the options given as argument, respecting any
80 # '--git-dir=<path>' and '-C <path>' options present on the command line
81 __git ()
83 git ${__git_C_args:+"${__git_C_args[@]}"} \
84 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
87 # The following function is based on code from:
89 # bash_completion - programmable completion functions for bash 3.2+
91 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
92 # © 2009-2010, Bash Completion Maintainers
93 # <bash-completion-devel@lists.alioth.debian.org>
95 # This program is free software; you can redistribute it and/or modify
96 # it under the terms of the GNU General Public License as published by
97 # the Free Software Foundation; either version 2, or (at your option)
98 # any later version.
100 # This program is distributed in the hope that it will be useful,
101 # but WITHOUT ANY WARRANTY; without even the implied warranty of
102 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103 # GNU General Public License for more details.
105 # You should have received a copy of the GNU General Public License
106 # along with this program; if not, write to the Free Software Foundation,
107 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
109 # The latest version of this software can be obtained here:
111 # http://bash-completion.alioth.debian.org/
113 # RELEASE: 2.x
115 # This function can be used to access a tokenized list of words
116 # on the command line:
118 # __git_reassemble_comp_words_by_ref '=:'
119 # if test "${words_[cword_-1]}" = -w
120 # then
121 # ...
122 # fi
124 # The argument should be a collection of characters from the list of
125 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
126 # characters.
128 # This is roughly equivalent to going back in time and setting
129 # COMP_WORDBREAKS to exclude those characters. The intent is to
130 # make option types like --date=<type> and <rev>:<path> easy to
131 # recognize by treating each shell word as a single token.
133 # It is best not to set COMP_WORDBREAKS directly because the value is
134 # shared with other completion scripts. By the time the completion
135 # function gets called, COMP_WORDS has already been populated so local
136 # changes to COMP_WORDBREAKS have no effect.
138 # Output: words_, cword_, cur_.
140 __git_reassemble_comp_words_by_ref()
142 local exclude i j first
143 # Which word separators to exclude?
144 exclude="${1//[^$COMP_WORDBREAKS]}"
145 cword_=$COMP_CWORD
146 if [ -z "$exclude" ]; then
147 words_=("${COMP_WORDS[@]}")
148 return
150 # List of word completion separators has shrunk;
151 # re-assemble words to complete.
152 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
153 # Append each nonempty word consisting of just
154 # word separator characters to the current word.
155 first=t
156 while
157 [ $i -gt 0 ] &&
158 [ -n "${COMP_WORDS[$i]}" ] &&
159 # word consists of excluded word separators
160 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
162 # Attach to the previous token,
163 # unless the previous token is the command name.
164 if [ $j -ge 2 ] && [ -n "$first" ]; then
165 ((j--))
167 first=
168 words_[$j]=${words_[j]}${COMP_WORDS[i]}
169 if [ $i = $COMP_CWORD ]; then
170 cword_=$j
172 if (($i < ${#COMP_WORDS[@]} - 1)); then
173 ((i++))
174 else
175 # Done.
176 return
178 done
179 words_[$j]=${words_[j]}${COMP_WORDS[i]}
180 if [ $i = $COMP_CWORD ]; then
181 cword_=$j
183 done
186 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
187 _get_comp_words_by_ref ()
189 local exclude cur_ words_ cword_
190 if [ "$1" = "-n" ]; then
191 exclude=$2
192 shift 2
194 __git_reassemble_comp_words_by_ref "$exclude"
195 cur_=${words_[cword_]}
196 while [ $# -gt 0 ]; do
197 case "$1" in
198 cur)
199 cur=$cur_
201 prev)
202 prev=${words_[$cword_-1]}
204 words)
205 words=("${words_[@]}")
207 cword)
208 cword=$cword_
210 esac
211 shift
212 done
216 __gitcompappend ()
218 local x i=${#COMPREPLY[@]}
219 for x in $1; do
220 if [[ "$x" == "$3"* ]]; then
221 COMPREPLY[i++]="$2$x$4"
223 done
226 __gitcompadd ()
228 COMPREPLY=()
229 __gitcompappend "$@"
232 # Generates completion reply, appending a space to possible completion words,
233 # if necessary.
234 # It accepts 1 to 4 arguments:
235 # 1: List of possible completion words.
236 # 2: A prefix to be added to each possible completion word (optional).
237 # 3: Generate possible completion matches for this word (optional).
238 # 4: A suffix to be appended to each possible completion word (optional).
239 __gitcomp ()
241 local cur_="${3-$cur}"
243 case "$cur_" in
244 --*=)
247 local c i=0 IFS=$' \t\n'
248 for c in $1; do
249 c="$c${4-}"
250 if [[ $c == "$cur_"* ]]; then
251 case $c in
252 --*=*|*.) ;;
253 *) c="$c " ;;
254 esac
255 COMPREPLY[i++]="${2-}$c"
257 done
259 esac
262 # Variation of __gitcomp_nl () that appends to the existing list of
263 # completion candidates, COMPREPLY.
264 __gitcomp_nl_append ()
266 local IFS=$'\n'
267 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
270 # Generates completion reply from newline-separated possible completion words
271 # by appending a space to all of them.
272 # It accepts 1 to 4 arguments:
273 # 1: List of possible completion words, separated by a single newline.
274 # 2: A prefix to be added to each possible completion word (optional).
275 # 3: Generate possible completion matches for this word (optional).
276 # 4: A suffix to be appended to each possible completion word instead of
277 # the default space (optional). If specified but empty, nothing is
278 # appended.
279 __gitcomp_nl ()
281 COMPREPLY=()
282 __gitcomp_nl_append "$@"
285 # Generates completion reply with compgen from newline-separated possible
286 # completion filenames.
287 # It accepts 1 to 3 arguments:
288 # 1: List of possible completion filenames, separated by a single newline.
289 # 2: A directory prefix to be added to each possible completion filename
290 # (optional).
291 # 3: Generate possible completion matches for this word (optional).
292 __gitcomp_file ()
294 local IFS=$'\n'
296 # XXX does not work when the directory prefix contains a tilde,
297 # since tilde expansion is not applied.
298 # This means that COMPREPLY will be empty and Bash default
299 # completion will be used.
300 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
302 # use a hack to enable file mode in bash < 4
303 compopt -o filenames +o nospace 2>/dev/null ||
304 compgen -f /non-existing-dir/ > /dev/null
307 # Execute 'git ls-files', unless the --committable option is specified, in
308 # which case it runs 'git diff-index' to find out the files that can be
309 # committed. It return paths relative to the directory specified in the first
310 # argument, and using the options specified in the second argument.
311 __git_ls_files_helper ()
313 if [ "$2" == "--committable" ]; then
314 __git -C "$1" diff-index --name-only --relative HEAD
315 else
316 # NOTE: $2 is not quoted in order to support multiple options
317 __git -C "$1" ls-files --exclude-standard $2
322 # __git_index_files accepts 1 or 2 arguments:
323 # 1: Options to pass to ls-files (required).
324 # 2: A directory path (optional).
325 # If provided, only files within the specified directory are listed.
326 # Sub directories are never recursed. Path must have a trailing
327 # slash.
328 __git_index_files ()
330 local root="${2-.}" file
332 __git_ls_files_helper "$root" "$1" |
333 while read -r file; do
334 case "$file" in
335 ?*/*) echo "${file%%/*}" ;;
336 *) echo "$file" ;;
337 esac
338 done | sort | uniq
341 __git_heads ()
343 __git for-each-ref --format='%(refname:strip=2)' refs/heads
346 __git_tags ()
348 __git for-each-ref --format='%(refname:strip=2)' refs/tags
351 # Lists refs from the local (by default) or from a remote repository.
352 # It accepts 0, 1 or 2 arguments:
353 # 1: The remote to list refs from (optional; ignored, if set but empty).
354 # Can be the name of a configured remote, a path, or a URL.
355 # 2: In addition to local refs, list unique branches from refs/remotes/ for
356 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
357 # 3: Currently ignored.
358 # 4: The current ref to be completed (optional).
360 # Use __git_complete_refs() instead.
361 __git_refs ()
363 local i hash dir track="${2-}"
364 local list_refs_from=path remote="${1-}"
365 local format refs pfx
366 local cur_="${4-$cur}"
368 __git_find_repo_path
369 dir="$__git_repo_path"
371 if [ -z "$remote" ]; then
372 if [ -z "$dir" ]; then
373 return
375 else
376 if __git_is_configured_remote "$remote"; then
377 # configured remote takes precedence over a
378 # local directory with the same name
379 list_refs_from=remote
380 elif [ -d "$remote/.git" ]; then
381 dir="$remote/.git"
382 elif [ -d "$remote" ]; then
383 dir="$remote"
384 else
385 list_refs_from=url
389 if [ "$list_refs_from" = path ]; then
390 if [[ "$cur_" == ^* ]]; then
391 pfx="^"
392 cur_=${cur_#^}
394 case "$cur_" in
395 refs|refs/*)
396 format="refname"
397 refs="${cur_%/*}"
398 track=""
401 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
402 if [ -e "$dir/$i" ]; then echo $pfx$i; fi
403 done
404 format="refname:short"
405 refs="refs/tags refs/heads refs/remotes"
407 esac
408 __git_dir="$dir" __git for-each-ref --format="$pfx%($format)" \
409 $refs
410 if [ -n "$track" ]; then
411 # employ the heuristic used by git checkout
412 # Try to find a remote branch that matches the completion word
413 # but only output if the branch name is unique
414 local ref entry
415 __git for-each-ref --shell --format="ref=%(refname:short)" \
416 "refs/remotes/" | \
417 while read -r entry; do
418 eval "$entry"
419 ref="${ref#*/}"
420 if [[ "$ref" == "$cur_"* ]]; then
421 echo "$ref"
423 done | sort | uniq -u
425 return
427 case "$cur_" in
428 refs|refs/*)
429 __git ls-remote "$remote" "$cur_*" | \
430 while read -r hash i; do
431 case "$i" in
432 *^{}) ;;
433 *) echo "$i" ;;
434 esac
435 done
438 if [ "$list_refs_from" = remote ]; then
439 echo "HEAD"
440 __git for-each-ref --format="%(refname:short)" \
441 "refs/remotes/$remote/" | sed -e "s#^$remote/##"
442 else
443 __git ls-remote "$remote" HEAD \
444 "refs/tags/*" "refs/heads/*" "refs/remotes/*" |
445 while read -r hash i; do
446 case "$i" in
447 *^{}) ;;
448 refs/*) echo "${i#refs/*/}" ;;
449 *) echo "$i" ;; # symbolic refs
450 esac
451 done
454 esac
457 # Completes refs, short and long, local and remote, symbolic and pseudo.
459 # Usage: __git_complete_refs [<option>]...
460 # --remote=<remote>: The remote to list refs from, can be the name of a
461 # configured remote, a path, or a URL.
462 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
463 # --pfx=<prefix>: A prefix to be added to each ref.
464 # --cur=<word>: The current ref to be completed. Defaults to the current
465 # word to be completed.
466 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
467 # space.
468 __git_complete_refs ()
470 local remote track pfx cur_="$cur" sfx=" "
472 while test $# != 0; do
473 case "$1" in
474 --remote=*) remote="${1##--remote=}" ;;
475 --track) track="yes" ;;
476 --pfx=*) pfx="${1##--pfx=}" ;;
477 --cur=*) cur_="${1##--cur=}" ;;
478 --sfx=*) sfx="${1##--sfx=}" ;;
479 *) return 1 ;;
480 esac
481 shift
482 done
484 __gitcomp_nl "$(__git_refs "$remote" "$track" "" "$cur_")" \
485 "$pfx" "$cur_" "$sfx"
488 # __git_refs2 requires 1 argument (to pass to __git_refs)
489 # Deprecated: use __git_complete_fetch_refspecs() instead.
490 __git_refs2 ()
492 local i
493 for i in $(__git_refs "$1"); do
494 echo "$i:$i"
495 done
498 # Completes refspecs for fetching from a remote repository.
499 # 1: The remote repository.
500 # 2: A prefix to be added to each listed refspec (optional).
501 # 3: The ref to be completed as a refspec instead of the current word to be
502 # completed (optional)
503 # 4: A suffix to be appended to each listed refspec instead of the default
504 # space (optional).
505 __git_complete_fetch_refspecs ()
507 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
509 __gitcomp_nl "$(
510 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
511 echo "$i:$i"
512 done
513 )" "$pfx" "$cur_" "$sfx"
516 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
517 __git_refs_remotes ()
519 local i hash
520 __git ls-remote "$1" 'refs/heads/*' | \
521 while read -r hash i; do
522 echo "$i:refs/remotes/$1/${i#refs/heads/}"
523 done
526 __git_remotes ()
528 __git_find_repo_path
529 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
530 __git remote
533 # Returns true if $1 matches the name of a configured remote, false otherwise.
534 __git_is_configured_remote ()
536 local remote
537 for remote in $(__git_remotes); do
538 if [ "$remote" = "$1" ]; then
539 return 0
541 done
542 return 1
545 __git_list_merge_strategies ()
547 git merge -s help 2>&1 |
548 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
549 s/\.$//
550 s/.*://
551 s/^[ ]*//
552 s/[ ]*$//
557 __git_merge_strategies=
558 # 'git merge -s help' (and thus detection of the merge strategy
559 # list) fails, unfortunately, if run outside of any git working
560 # tree. __git_merge_strategies is set to the empty string in
561 # that case, and the detection will be repeated the next time it
562 # is needed.
563 __git_compute_merge_strategies ()
565 test -n "$__git_merge_strategies" ||
566 __git_merge_strategies=$(__git_list_merge_strategies)
569 __git_complete_revlist_file ()
571 local pfx ls ref cur_="$cur"
572 case "$cur_" in
573 *..?*:*)
574 return
576 ?*:*)
577 ref="${cur_%%:*}"
578 cur_="${cur_#*:}"
579 case "$cur_" in
580 ?*/*)
581 pfx="${cur_%/*}"
582 cur_="${cur_##*/}"
583 ls="$ref:$pfx"
584 pfx="$pfx/"
587 ls="$ref"
589 esac
591 case "$COMP_WORDBREAKS" in
592 *:*) : great ;;
593 *) pfx="$ref:$pfx" ;;
594 esac
596 __gitcomp_nl "$(__git ls-tree "$ls" \
597 | sed '/^100... blob /{
598 s,^.* ,,
599 s,$, ,
601 /^120000 blob /{
602 s,^.* ,,
603 s,$, ,
605 /^040000 tree /{
606 s,^.* ,,
607 s,$,/,
609 s/^.* //')" \
610 "$pfx" "$cur_" ""
612 *...*)
613 pfx="${cur_%...*}..."
614 cur_="${cur_#*...}"
615 __git_complete_refs --pfx="$pfx" --cur="$cur_"
617 *..*)
618 pfx="${cur_%..*}.."
619 cur_="${cur_#*..}"
620 __git_complete_refs --pfx="$pfx" --cur="$cur_"
623 __git_complete_refs
625 esac
629 # __git_complete_index_file requires 1 argument:
630 # 1: the options to pass to ls-file
632 # The exception is --committable, which finds the files appropriate commit.
633 __git_complete_index_file ()
635 local pfx="" cur_="$cur"
637 case "$cur_" in
638 ?*/*)
639 pfx="${cur_%/*}"
640 cur_="${cur_##*/}"
641 pfx="${pfx}/"
643 esac
645 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
648 __git_complete_file ()
650 __git_complete_revlist_file
653 __git_complete_revlist ()
655 __git_complete_revlist_file
658 __git_complete_remote_or_refspec ()
660 local cur_="$cur" cmd="${words[1]}"
661 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
662 if [ "$cmd" = "remote" ]; then
663 ((c++))
665 while [ $c -lt $cword ]; do
666 i="${words[c]}"
667 case "$i" in
668 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
669 --all)
670 case "$cmd" in
671 push) no_complete_refspec=1 ;;
672 fetch)
673 return
675 *) ;;
676 esac
678 -*) ;;
679 *) remote="$i"; break ;;
680 esac
681 ((c++))
682 done
683 if [ -z "$remote" ]; then
684 __gitcomp_nl "$(__git_remotes)"
685 return
687 if [ $no_complete_refspec = 1 ]; then
688 return
690 [ "$remote" = "." ] && remote=
691 case "$cur_" in
692 *:*)
693 case "$COMP_WORDBREAKS" in
694 *:*) : great ;;
695 *) pfx="${cur_%%:*}:" ;;
696 esac
697 cur_="${cur_#*:}"
698 lhs=0
701 pfx="+"
702 cur_="${cur_#+}"
704 esac
705 case "$cmd" in
706 fetch)
707 if [ $lhs = 1 ]; then
708 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
709 else
710 __git_complete_refs --pfx="$pfx" --cur="$cur_"
713 pull|remote)
714 if [ $lhs = 1 ]; then
715 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
716 else
717 __git_complete_refs --pfx="$pfx" --cur="$cur_"
720 push)
721 if [ $lhs = 1 ]; then
722 __git_complete_refs --pfx="$pfx" --cur="$cur_"
723 else
724 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
727 esac
730 __git_complete_strategy ()
732 __git_compute_merge_strategies
733 case "$prev" in
734 -s|--strategy)
735 __gitcomp "$__git_merge_strategies"
736 return 0
737 esac
738 case "$cur" in
739 --strategy=*)
740 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
741 return 0
743 esac
744 return 1
747 __git_commands () {
748 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
749 then
750 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
751 else
752 git help -a|egrep '^ [a-zA-Z0-9]'
756 __git_list_all_commands ()
758 local i IFS=" "$'\n'
759 for i in $(__git_commands)
761 case $i in
762 *--*) : helper pattern;;
763 *) echo $i;;
764 esac
765 done
768 __git_all_commands=
769 __git_compute_all_commands ()
771 test -n "$__git_all_commands" ||
772 __git_all_commands=$(__git_list_all_commands)
775 __git_list_porcelain_commands ()
777 local i IFS=" "$'\n'
778 __git_compute_all_commands
779 for i in $__git_all_commands
781 case $i in
782 *--*) : helper pattern;;
783 applymbox) : ask gittus;;
784 applypatch) : ask gittus;;
785 archimport) : import;;
786 cat-file) : plumbing;;
787 check-attr) : plumbing;;
788 check-ignore) : plumbing;;
789 check-mailmap) : plumbing;;
790 check-ref-format) : plumbing;;
791 checkout-index) : plumbing;;
792 column) : internal helper;;
793 commit-tree) : plumbing;;
794 count-objects) : infrequent;;
795 credential) : credentials;;
796 credential-*) : credentials helper;;
797 cvsexportcommit) : export;;
798 cvsimport) : import;;
799 cvsserver) : daemon;;
800 daemon) : daemon;;
801 diff-files) : plumbing;;
802 diff-index) : plumbing;;
803 diff-tree) : plumbing;;
804 fast-import) : import;;
805 fast-export) : export;;
806 fsck-objects) : plumbing;;
807 fetch-pack) : plumbing;;
808 fmt-merge-msg) : plumbing;;
809 for-each-ref) : plumbing;;
810 hash-object) : plumbing;;
811 http-*) : transport;;
812 index-pack) : plumbing;;
813 init-db) : deprecated;;
814 local-fetch) : plumbing;;
815 ls-files) : plumbing;;
816 ls-remote) : plumbing;;
817 ls-tree) : plumbing;;
818 mailinfo) : plumbing;;
819 mailsplit) : plumbing;;
820 merge-*) : plumbing;;
821 mktree) : plumbing;;
822 mktag) : plumbing;;
823 pack-objects) : plumbing;;
824 pack-redundant) : plumbing;;
825 pack-refs) : plumbing;;
826 parse-remote) : plumbing;;
827 patch-id) : plumbing;;
828 prune) : plumbing;;
829 prune-packed) : plumbing;;
830 quiltimport) : import;;
831 read-tree) : plumbing;;
832 receive-pack) : plumbing;;
833 remote-*) : transport;;
834 rerere) : plumbing;;
835 rev-list) : plumbing;;
836 rev-parse) : plumbing;;
837 runstatus) : plumbing;;
838 sh-setup) : internal;;
839 shell) : daemon;;
840 show-ref) : plumbing;;
841 send-pack) : plumbing;;
842 show-index) : plumbing;;
843 ssh-*) : transport;;
844 stripspace) : plumbing;;
845 symbolic-ref) : plumbing;;
846 unpack-file) : plumbing;;
847 unpack-objects) : plumbing;;
848 update-index) : plumbing;;
849 update-ref) : plumbing;;
850 update-server-info) : daemon;;
851 upload-archive) : plumbing;;
852 upload-pack) : plumbing;;
853 write-tree) : plumbing;;
854 var) : infrequent;;
855 verify-pack) : infrequent;;
856 verify-tag) : plumbing;;
857 *) echo $i;;
858 esac
859 done
862 __git_porcelain_commands=
863 __git_compute_porcelain_commands ()
865 test -n "$__git_porcelain_commands" ||
866 __git_porcelain_commands=$(__git_list_porcelain_commands)
869 # Lists all set config variables starting with the given section prefix,
870 # with the prefix removed.
871 __git_get_config_variables ()
873 local section="$1" i IFS=$'\n'
874 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
875 echo "${i#$section.}"
876 done
879 __git_pretty_aliases ()
881 __git_get_config_variables "pretty"
884 __git_aliases ()
886 __git_get_config_variables "alias"
889 # __git_aliased_command requires 1 argument
890 __git_aliased_command ()
892 local word cmdline=$(__git config --get "alias.$1")
893 for word in $cmdline; do
894 case "$word" in
895 \!gitk|gitk)
896 echo "gitk"
897 return
899 \!*) : shell command alias ;;
900 -*) : option ;;
901 *=*) : setting env ;;
902 git) : git itself ;;
903 \(\)) : skip parens of shell function definition ;;
904 {) : skip start of shell helper function ;;
905 :) : skip null command ;;
906 \'*) : skip opening quote after sh -c ;;
908 echo "$word"
909 return
910 esac
911 done
914 # __git_find_on_cmdline requires 1 argument
915 __git_find_on_cmdline ()
917 local word subcommand c=1
918 while [ $c -lt $cword ]; do
919 word="${words[c]}"
920 for subcommand in $1; do
921 if [ "$subcommand" = "$word" ]; then
922 echo "$subcommand"
923 return
925 done
926 ((c++))
927 done
930 # Echo the value of an option set on the command line or config
932 # $1: short option name
933 # $2: long option name including =
934 # $3: list of possible values
935 # $4: config string (optional)
937 # example:
938 # result="$(__git_get_option_value "-d" "--do-something=" \
939 # "yes no" "core.doSomething")"
941 # result is then either empty (no option set) or "yes" or "no"
943 # __git_get_option_value requires 3 arguments
944 __git_get_option_value ()
946 local c short_opt long_opt val
947 local result= values config_key word
949 short_opt="$1"
950 long_opt="$2"
951 values="$3"
952 config_key="$4"
954 ((c = $cword - 1))
955 while [ $c -ge 0 ]; do
956 word="${words[c]}"
957 for val in $values; do
958 if [ "$short_opt$val" = "$word" ] ||
959 [ "$long_opt$val" = "$word" ]; then
960 result="$val"
961 break 2
963 done
964 ((c--))
965 done
967 if [ -n "$config_key" ] && [ -z "$result" ]; then
968 result="$(__git config "$config_key")"
971 echo "$result"
974 __git_has_doubledash ()
976 local c=1
977 while [ $c -lt $cword ]; do
978 if [ "--" = "${words[c]}" ]; then
979 return 0
981 ((c++))
982 done
983 return 1
986 # Try to count non option arguments passed on the command line for the
987 # specified git command.
988 # When options are used, it is necessary to use the special -- option to
989 # tell the implementation were non option arguments begin.
990 # XXX this can not be improved, since options can appear everywhere, as
991 # an example:
992 # git mv x -n y
994 # __git_count_arguments requires 1 argument: the git command executed.
995 __git_count_arguments ()
997 local word i c=0
999 # Skip "git" (first argument)
1000 for ((i=1; i < ${#words[@]}; i++)); do
1001 word="${words[i]}"
1003 case "$word" in
1005 # Good; we can assume that the following are only non
1006 # option arguments.
1007 ((c = 0))
1009 "$1")
1010 # Skip the specified git command and discard git
1011 # main options
1012 ((c = 0))
1015 ((c++))
1017 esac
1018 done
1020 printf "%d" $c
1023 __git_whitespacelist="nowarn warn error error-all fix"
1025 _git_am ()
1027 __git_find_repo_path
1028 if [ -d "$__git_repo_path"/rebase-apply ]; then
1029 __gitcomp "--skip --continue --resolved --abort"
1030 return
1032 case "$cur" in
1033 --whitespace=*)
1034 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1035 return
1037 --*)
1038 __gitcomp "
1039 --3way --committer-date-is-author-date --ignore-date
1040 --ignore-whitespace --ignore-space-change
1041 --interactive --keep --no-utf8 --signoff --utf8
1042 --whitespace= --scissors
1044 return
1045 esac
1048 _git_apply ()
1050 case "$cur" in
1051 --whitespace=*)
1052 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1053 return
1055 --*)
1056 __gitcomp "
1057 --stat --numstat --summary --check --index
1058 --cached --index-info --reverse --reject --unidiff-zero
1059 --apply --no-add --exclude=
1060 --ignore-whitespace --ignore-space-change
1061 --whitespace= --inaccurate-eof --verbose
1063 return
1064 esac
1067 _git_add ()
1069 case "$cur" in
1070 --*)
1071 __gitcomp "
1072 --interactive --refresh --patch --update --dry-run
1073 --ignore-errors --intent-to-add
1075 return
1076 esac
1078 # XXX should we check for --update and --all options ?
1079 __git_complete_index_file "--others --modified --directory --no-empty-directory"
1082 _git_archive ()
1084 case "$cur" in
1085 --format=*)
1086 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1087 return
1089 --remote=*)
1090 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1091 return
1093 --*)
1094 __gitcomp "
1095 --format= --list --verbose
1096 --prefix= --remote= --exec=
1098 return
1100 esac
1101 __git_complete_file
1104 _git_bisect ()
1106 __git_has_doubledash && return
1108 local subcommands="start bad good skip reset visualize replay log run"
1109 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1110 if [ -z "$subcommand" ]; then
1111 __git_find_repo_path
1112 if [ -f "$__git_repo_path"/BISECT_START ]; then
1113 __gitcomp "$subcommands"
1114 else
1115 __gitcomp "replay start"
1117 return
1120 case "$subcommand" in
1121 bad|good|reset|skip|start)
1122 __git_complete_refs
1126 esac
1129 _git_branch ()
1131 local i c=1 only_local_ref="n" has_r="n"
1133 while [ $c -lt $cword ]; do
1134 i="${words[c]}"
1135 case "$i" in
1136 -d|--delete|-m|--move) only_local_ref="y" ;;
1137 -r|--remotes) has_r="y" ;;
1138 esac
1139 ((c++))
1140 done
1142 case "$cur" in
1143 --set-upstream-to=*)
1144 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1146 --*)
1147 __gitcomp "
1148 --color --no-color --verbose --abbrev= --no-abbrev
1149 --track --no-track --contains --merged --no-merged
1150 --set-upstream-to= --edit-description --list
1151 --unset-upstream --delete --move --remotes
1155 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1156 __gitcomp_nl "$(__git_heads)"
1157 else
1158 __git_complete_refs
1161 esac
1164 _git_bundle ()
1166 local cmd="${words[2]}"
1167 case "$cword" in
1169 __gitcomp "create list-heads verify unbundle"
1172 # looking for a file
1175 case "$cmd" in
1176 create)
1177 __git_complete_revlist
1179 esac
1181 esac
1184 _git_checkout ()
1186 __git_has_doubledash && return
1188 case "$cur" in
1189 --conflict=*)
1190 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1192 --*)
1193 __gitcomp "
1194 --quiet --ours --theirs --track --no-track --merge
1195 --conflict= --orphan --patch
1199 # check if --track, --no-track, or --no-guess was specified
1200 # if so, disable DWIM mode
1201 local flags="--track --no-track --no-guess" track_opt="--track"
1202 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1203 track_opt=''
1205 __git_complete_refs $track_opt
1207 esac
1210 _git_cherry ()
1212 __git_complete_refs
1215 _git_cherry_pick ()
1217 __git_find_repo_path
1218 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1219 __gitcomp "--continue --quit --abort"
1220 return
1222 case "$cur" in
1223 --*)
1224 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1227 __git_complete_refs
1229 esac
1232 _git_clean ()
1234 case "$cur" in
1235 --*)
1236 __gitcomp "--dry-run --quiet"
1237 return
1239 esac
1241 # XXX should we check for -x option ?
1242 __git_complete_index_file "--others --directory"
1245 _git_clone ()
1247 case "$cur" in
1248 --*)
1249 __gitcomp "
1250 --local
1251 --no-hardlinks
1252 --shared
1253 --reference
1254 --quiet
1255 --no-checkout
1256 --bare
1257 --mirror
1258 --origin
1259 --upload-pack
1260 --template=
1261 --depth
1262 --single-branch
1263 --branch
1264 --recurse-submodules
1266 return
1268 esac
1271 __git_untracked_file_modes="all no normal"
1273 _git_commit ()
1275 case "$prev" in
1276 -c|-C)
1277 __git_complete_refs
1278 return
1280 esac
1282 case "$cur" in
1283 --cleanup=*)
1284 __gitcomp "default scissors strip verbatim whitespace
1285 " "" "${cur##--cleanup=}"
1286 return
1288 --reuse-message=*|--reedit-message=*|\
1289 --fixup=*|--squash=*)
1290 __git_complete_refs --cur="${cur#*=}"
1291 return
1293 --untracked-files=*)
1294 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1295 return
1297 --*)
1298 __gitcomp "
1299 --all --author= --signoff --verify --no-verify
1300 --edit --no-edit
1301 --amend --include --only --interactive
1302 --dry-run --reuse-message= --reedit-message=
1303 --reset-author --file= --message= --template=
1304 --cleanup= --untracked-files --untracked-files=
1305 --verbose --quiet --fixup= --squash=
1307 return
1308 esac
1310 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1311 __git_complete_index_file "--committable"
1312 else
1313 # This is the first commit
1314 __git_complete_index_file "--cached"
1318 _git_describe ()
1320 case "$cur" in
1321 --*)
1322 __gitcomp "
1323 --all --tags --contains --abbrev= --candidates=
1324 --exact-match --debug --long --match --always
1326 return
1327 esac
1328 __git_complete_refs
1331 __git_diff_algorithms="myers minimal patience histogram"
1333 __git_diff_submodule_formats="diff log short"
1335 __git_diff_common_options="--stat --numstat --shortstat --summary
1336 --patch-with-stat --name-only --name-status --color
1337 --no-color --color-words --no-renames --check
1338 --full-index --binary --abbrev --diff-filter=
1339 --find-copies-harder
1340 --text --ignore-space-at-eol --ignore-space-change
1341 --ignore-all-space --ignore-blank-lines --exit-code
1342 --quiet --ext-diff --no-ext-diff
1343 --no-prefix --src-prefix= --dst-prefix=
1344 --inter-hunk-context=
1345 --patience --histogram --minimal
1346 --raw --word-diff --word-diff-regex=
1347 --dirstat --dirstat= --dirstat-by-file
1348 --dirstat-by-file= --cumulative
1349 --diff-algorithm=
1350 --submodule --submodule=
1353 _git_diff ()
1355 __git_has_doubledash && return
1357 case "$cur" in
1358 --diff-algorithm=*)
1359 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1360 return
1362 --submodule=*)
1363 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1364 return
1366 --*)
1367 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1368 --base --ours --theirs --no-index
1369 $__git_diff_common_options
1371 return
1373 esac
1374 __git_complete_revlist_file
1377 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1378 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1381 _git_difftool ()
1383 __git_has_doubledash && return
1385 case "$cur" in
1386 --tool=*)
1387 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1388 return
1390 --*)
1391 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1392 --base --ours --theirs
1393 --no-renames --diff-filter= --find-copies-harder
1394 --relative --ignore-submodules
1395 --tool="
1396 return
1398 esac
1399 __git_complete_revlist_file
1402 __git_fetch_recurse_submodules="yes on-demand no"
1404 __git_fetch_options="
1405 --quiet --verbose --append --upload-pack --force --keep --depth=
1406 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1409 _git_fetch ()
1411 case "$cur" in
1412 --recurse-submodules=*)
1413 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1414 return
1416 --*)
1417 __gitcomp "$__git_fetch_options"
1418 return
1420 esac
1421 __git_complete_remote_or_refspec
1424 __git_format_patch_options="
1425 --stdout --attach --no-attach --thread --thread= --no-thread
1426 --numbered --start-number --numbered-files --keep-subject --signoff
1427 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1428 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1429 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1430 --output-directory --reroll-count --to= --quiet --notes
1433 _git_format_patch ()
1435 case "$cur" in
1436 --thread=*)
1437 __gitcomp "
1438 deep shallow
1439 " "" "${cur##--thread=}"
1440 return
1442 --*)
1443 __gitcomp "$__git_format_patch_options"
1444 return
1446 esac
1447 __git_complete_revlist
1450 _git_fsck ()
1452 case "$cur" in
1453 --*)
1454 __gitcomp "
1455 --tags --root --unreachable --cache --no-reflogs --full
1456 --strict --verbose --lost-found
1458 return
1460 esac
1463 _git_gc ()
1465 case "$cur" in
1466 --*)
1467 __gitcomp "--prune --aggressive"
1468 return
1470 esac
1473 _git_gitk ()
1475 _gitk
1478 __git_match_ctag() {
1479 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1482 _git_grep ()
1484 __git_has_doubledash && return
1486 case "$cur" in
1487 --*)
1488 __gitcomp "
1489 --cached
1490 --text --ignore-case --word-regexp --invert-match
1491 --full-name --line-number
1492 --extended-regexp --basic-regexp --fixed-strings
1493 --perl-regexp
1494 --threads
1495 --files-with-matches --name-only
1496 --files-without-match
1497 --max-depth
1498 --count
1499 --and --or --not --all-match
1501 return
1503 esac
1505 case "$cword,$prev" in
1506 2,*|*,-*)
1507 if test -r tags; then
1508 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1509 return
1512 esac
1514 __git_complete_refs
1517 _git_help ()
1519 case "$cur" in
1520 --*)
1521 __gitcomp "--all --guides --info --man --web"
1522 return
1524 esac
1525 __git_compute_all_commands
1526 __gitcomp "$__git_all_commands $(__git_aliases)
1527 attributes cli core-tutorial cvs-migration
1528 diffcore everyday gitk glossary hooks ignore modules
1529 namespaces repository-layout revisions tutorial tutorial-2
1530 workflows
1534 _git_init ()
1536 case "$cur" in
1537 --shared=*)
1538 __gitcomp "
1539 false true umask group all world everybody
1540 " "" "${cur##--shared=}"
1541 return
1543 --*)
1544 __gitcomp "--quiet --bare --template= --shared --shared="
1545 return
1547 esac
1550 _git_ls_files ()
1552 case "$cur" in
1553 --*)
1554 __gitcomp "--cached --deleted --modified --others --ignored
1555 --stage --directory --no-empty-directory --unmerged
1556 --killed --exclude= --exclude-from=
1557 --exclude-per-directory= --exclude-standard
1558 --error-unmatch --with-tree= --full-name
1559 --abbrev --ignored --exclude-per-directory
1561 return
1563 esac
1565 # XXX ignore options like --modified and always suggest all cached
1566 # files.
1567 __git_complete_index_file "--cached"
1570 _git_ls_remote ()
1572 __gitcomp_nl "$(__git_remotes)"
1575 _git_ls_tree ()
1577 __git_complete_file
1580 # Options that go well for log, shortlog and gitk
1581 __git_log_common_options="
1582 --not --all
1583 --branches --tags --remotes
1584 --first-parent --merges --no-merges
1585 --max-count=
1586 --max-age= --since= --after=
1587 --min-age= --until= --before=
1588 --min-parents= --max-parents=
1589 --no-min-parents --no-max-parents
1591 # Options that go well for log and gitk (not shortlog)
1592 __git_log_gitk_options="
1593 --dense --sparse --full-history
1594 --simplify-merges --simplify-by-decoration
1595 --left-right --notes --no-notes
1597 # Options that go well for log and shortlog (not gitk)
1598 __git_log_shortlog_options="
1599 --author= --committer= --grep=
1600 --all-match --invert-grep
1603 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1604 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1606 _git_log ()
1608 __git_has_doubledash && return
1609 __git_find_repo_path
1611 local merge=""
1612 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1613 merge="--merge"
1615 case "$cur" in
1616 --pretty=*|--format=*)
1617 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1618 " "" "${cur#*=}"
1619 return
1621 --date=*)
1622 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1623 return
1625 --decorate=*)
1626 __gitcomp "full short no" "" "${cur##--decorate=}"
1627 return
1629 --diff-algorithm=*)
1630 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1631 return
1633 --submodule=*)
1634 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1635 return
1637 --*)
1638 __gitcomp "
1639 $__git_log_common_options
1640 $__git_log_shortlog_options
1641 $__git_log_gitk_options
1642 --root --topo-order --date-order --reverse
1643 --follow --full-diff
1644 --abbrev-commit --abbrev=
1645 --relative-date --date=
1646 --pretty= --format= --oneline
1647 --show-signature
1648 --cherry-mark
1649 --cherry-pick
1650 --graph
1651 --decorate --decorate=
1652 --walk-reflogs
1653 --parents --children
1654 $merge
1655 $__git_diff_common_options
1656 --pickaxe-all --pickaxe-regex
1658 return
1660 esac
1661 __git_complete_revlist
1664 # Common merge options shared by git-merge(1) and git-pull(1).
1665 __git_merge_options="
1666 --no-commit --no-stat --log --no-log --squash --strategy
1667 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1668 --verify-signatures --no-verify-signatures --gpg-sign
1669 --quiet --verbose --progress --no-progress
1672 _git_merge ()
1674 __git_complete_strategy && return
1676 case "$cur" in
1677 --*)
1678 __gitcomp "$__git_merge_options
1679 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1680 return
1681 esac
1682 __git_complete_refs
1685 _git_mergetool ()
1687 case "$cur" in
1688 --tool=*)
1689 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1690 return
1692 --*)
1693 __gitcomp "--tool="
1694 return
1696 esac
1699 _git_merge_base ()
1701 case "$cur" in
1702 --*)
1703 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1704 return
1706 esac
1707 __git_complete_refs
1710 _git_mv ()
1712 case "$cur" in
1713 --*)
1714 __gitcomp "--dry-run"
1715 return
1717 esac
1719 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1720 # We need to show both cached and untracked files (including
1721 # empty directories) since this may not be the last argument.
1722 __git_complete_index_file "--cached --others --directory"
1723 else
1724 __git_complete_index_file "--cached"
1728 _git_name_rev ()
1730 __gitcomp "--tags --all --stdin"
1733 _git_notes ()
1735 local subcommands='add append copy edit list prune remove show'
1736 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1738 case "$subcommand,$cur" in
1739 ,--*)
1740 __gitcomp '--ref'
1743 case "$prev" in
1744 --ref)
1745 __git_complete_refs
1748 __gitcomp "$subcommands --ref"
1750 esac
1752 add,--reuse-message=*|append,--reuse-message=*|\
1753 add,--reedit-message=*|append,--reedit-message=*)
1754 __git_complete_refs --cur="${cur#*=}"
1756 add,--*|append,--*)
1757 __gitcomp '--file= --message= --reedit-message=
1758 --reuse-message='
1760 copy,--*)
1761 __gitcomp '--stdin'
1763 prune,--*)
1764 __gitcomp '--dry-run --verbose'
1766 prune,*)
1769 case "$prev" in
1770 -m|-F)
1773 __git_complete_refs
1775 esac
1777 esac
1780 _git_pull ()
1782 __git_complete_strategy && return
1784 case "$cur" in
1785 --recurse-submodules=*)
1786 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1787 return
1789 --*)
1790 __gitcomp "
1791 --rebase --no-rebase
1792 $__git_merge_options
1793 $__git_fetch_options
1795 return
1797 esac
1798 __git_complete_remote_or_refspec
1801 __git_push_recurse_submodules="check on-demand"
1803 __git_complete_force_with_lease ()
1805 local cur_=$1
1807 case "$cur_" in
1808 --*=)
1810 *:*)
1811 __git_complete_refs --cur="${cur_#*:}"
1814 __git_complete_refs --cur="$cur_"
1816 esac
1819 _git_push ()
1821 case "$prev" in
1822 --repo)
1823 __gitcomp_nl "$(__git_remotes)"
1824 return
1826 --recurse-submodules)
1827 __gitcomp "$__git_push_recurse_submodules"
1828 return
1830 esac
1831 case "$cur" in
1832 --repo=*)
1833 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1834 return
1836 --recurse-submodules=*)
1837 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1838 return
1840 --force-with-lease=*)
1841 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1842 return
1844 --*)
1845 __gitcomp "
1846 --all --mirror --tags --dry-run --force --verbose
1847 --quiet --prune --delete --follow-tags
1848 --receive-pack= --repo= --set-upstream
1849 --force-with-lease --force-with-lease= --recurse-submodules=
1851 return
1853 esac
1854 __git_complete_remote_or_refspec
1857 _git_rebase ()
1859 __git_find_repo_path
1860 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1861 __gitcomp "--continue --skip --abort --quit --edit-todo"
1862 return
1863 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1864 [ -d "$__git_repo_path"/rebase-merge ]; then
1865 __gitcomp "--continue --skip --abort --quit"
1866 return
1868 __git_complete_strategy && return
1869 case "$cur" in
1870 --whitespace=*)
1871 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1872 return
1874 --*)
1875 __gitcomp "
1876 --onto --merge --strategy --interactive
1877 --preserve-merges --stat --no-stat
1878 --committer-date-is-author-date --ignore-date
1879 --ignore-whitespace --whitespace=
1880 --autosquash --no-autosquash
1881 --fork-point --no-fork-point
1882 --autostash --no-autostash
1883 --verify --no-verify
1884 --keep-empty --root --force-rebase --no-ff
1885 --exec
1888 return
1889 esac
1890 __git_complete_refs
1893 _git_reflog ()
1895 local subcommands="show delete expire"
1896 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1898 if [ -z "$subcommand" ]; then
1899 __gitcomp "$subcommands"
1900 else
1901 __git_complete_refs
1905 __git_send_email_confirm_options="always never auto cc compose"
1906 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1908 _git_send_email ()
1910 case "$prev" in
1911 --to|--cc|--bcc|--from)
1912 __gitcomp "$(__git send-email --dump-aliases)"
1913 return
1915 esac
1917 case "$cur" in
1918 --confirm=*)
1919 __gitcomp "
1920 $__git_send_email_confirm_options
1921 " "" "${cur##--confirm=}"
1922 return
1924 --suppress-cc=*)
1925 __gitcomp "
1926 $__git_send_email_suppresscc_options
1927 " "" "${cur##--suppress-cc=}"
1929 return
1931 --smtp-encryption=*)
1932 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1933 return
1935 --thread=*)
1936 __gitcomp "
1937 deep shallow
1938 " "" "${cur##--thread=}"
1939 return
1941 --to=*|--cc=*|--bcc=*|--from=*)
1942 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
1943 return
1945 --*)
1946 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1947 --compose --confirm= --dry-run --envelope-sender
1948 --from --identity
1949 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1950 --no-suppress-from --no-thread --quiet
1951 --signed-off-by-cc --smtp-pass --smtp-server
1952 --smtp-server-port --smtp-encryption= --smtp-user
1953 --subject --suppress-cc= --suppress-from --thread --to
1954 --validate --no-validate
1955 $__git_format_patch_options"
1956 return
1958 esac
1959 __git_complete_revlist
1962 _git_stage ()
1964 _git_add
1967 _git_status ()
1969 local complete_opt
1970 local untracked_state
1972 case "$cur" in
1973 --ignore-submodules=*)
1974 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1975 return
1977 --untracked-files=*)
1978 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1979 return
1981 --column=*)
1982 __gitcomp "
1983 always never auto column row plain dense nodense
1984 " "" "${cur##--column=}"
1985 return
1987 --*)
1988 __gitcomp "
1989 --short --branch --porcelain --long --verbose
1990 --untracked-files= --ignore-submodules= --ignored
1991 --column= --no-column
1993 return
1995 esac
1997 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1998 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2000 case "$untracked_state" in
2002 # --ignored option does not matter
2003 complete_opt=
2005 all|normal|*)
2006 complete_opt="--cached --directory --no-empty-directory --others"
2008 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2009 complete_opt="$complete_opt --ignored --exclude=*"
2012 esac
2014 __git_complete_index_file "$complete_opt"
2017 __git_config_get_set_variables ()
2019 local prevword word config_file= c=$cword
2020 while [ $c -gt 1 ]; do
2021 word="${words[c]}"
2022 case "$word" in
2023 --system|--global|--local|--file=*)
2024 config_file="$word"
2025 break
2027 -f|--file)
2028 config_file="$word $prevword"
2029 break
2031 esac
2032 prevword=$word
2033 c=$((--c))
2034 done
2036 __git config $config_file --name-only --list
2039 _git_config ()
2041 case "$prev" in
2042 branch.*.remote|branch.*.pushremote)
2043 __gitcomp_nl "$(__git_remotes)"
2044 return
2046 branch.*.merge)
2047 __git_complete_refs
2048 return
2050 branch.*.rebase)
2051 __gitcomp "false true preserve interactive"
2052 return
2054 remote.pushdefault)
2055 __gitcomp_nl "$(__git_remotes)"
2056 return
2058 remote.*.fetch)
2059 local remote="${prev#remote.}"
2060 remote="${remote%.fetch}"
2061 if [ -z "$cur" ]; then
2062 __gitcomp_nl "refs/heads/" "" "" ""
2063 return
2065 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2066 return
2068 remote.*.push)
2069 local remote="${prev#remote.}"
2070 remote="${remote%.push}"
2071 __gitcomp_nl "$(__git for-each-ref \
2072 --format='%(refname):%(refname)' refs/heads)"
2073 return
2075 pull.twohead|pull.octopus)
2076 __git_compute_merge_strategies
2077 __gitcomp "$__git_merge_strategies"
2078 return
2080 color.branch|color.diff|color.interactive|\
2081 color.showbranch|color.status|color.ui)
2082 __gitcomp "always never auto"
2083 return
2085 color.pager)
2086 __gitcomp "false true"
2087 return
2089 color.*.*)
2090 __gitcomp "
2091 normal black red green yellow blue magenta cyan white
2092 bold dim ul blink reverse
2094 return
2096 diff.submodule)
2097 __gitcomp "log short"
2098 return
2100 help.format)
2101 __gitcomp "man info web html"
2102 return
2104 log.date)
2105 __gitcomp "$__git_log_date_formats"
2106 return
2108 sendemail.aliasesfiletype)
2109 __gitcomp "mutt mailrc pine elm gnus"
2110 return
2112 sendemail.confirm)
2113 __gitcomp "$__git_send_email_confirm_options"
2114 return
2116 sendemail.suppresscc)
2117 __gitcomp "$__git_send_email_suppresscc_options"
2118 return
2120 sendemail.transferencoding)
2121 __gitcomp "7bit 8bit quoted-printable base64"
2122 return
2124 --get|--get-all|--unset|--unset-all)
2125 __gitcomp_nl "$(__git_config_get_set_variables)"
2126 return
2128 *.*)
2129 return
2131 esac
2132 case "$cur" in
2133 --*)
2134 __gitcomp "
2135 --system --global --local --file=
2136 --list --replace-all
2137 --get --get-all --get-regexp
2138 --add --unset --unset-all
2139 --remove-section --rename-section
2140 --name-only
2142 return
2144 branch.*.*)
2145 local pfx="${cur%.*}." cur_="${cur##*.}"
2146 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2147 return
2149 branch.*)
2150 local pfx="${cur%.*}." cur_="${cur#*.}"
2151 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
2152 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2153 return
2155 guitool.*.*)
2156 local pfx="${cur%.*}." cur_="${cur##*.}"
2157 __gitcomp "
2158 argprompt cmd confirm needsfile noconsole norescan
2159 prompt revprompt revunmerged title
2160 " "$pfx" "$cur_"
2161 return
2163 difftool.*.*)
2164 local pfx="${cur%.*}." cur_="${cur##*.}"
2165 __gitcomp "cmd path" "$pfx" "$cur_"
2166 return
2168 man.*.*)
2169 local pfx="${cur%.*}." cur_="${cur##*.}"
2170 __gitcomp "cmd path" "$pfx" "$cur_"
2171 return
2173 mergetool.*.*)
2174 local pfx="${cur%.*}." cur_="${cur##*.}"
2175 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2176 return
2178 pager.*)
2179 local pfx="${cur%.*}." cur_="${cur#*.}"
2180 __git_compute_all_commands
2181 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2182 return
2184 remote.*.*)
2185 local pfx="${cur%.*}." cur_="${cur##*.}"
2186 __gitcomp "
2187 url proxy fetch push mirror skipDefaultUpdate
2188 receivepack uploadpack tagopt pushurl
2189 " "$pfx" "$cur_"
2190 return
2192 remote.*)
2193 local pfx="${cur%.*}." cur_="${cur#*.}"
2194 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2195 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2196 return
2198 url.*.*)
2199 local pfx="${cur%.*}." cur_="${cur##*.}"
2200 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2201 return
2203 esac
2204 __gitcomp "
2205 add.ignoreErrors
2206 advice.commitBeforeMerge
2207 advice.detachedHead
2208 advice.implicitIdentity
2209 advice.pushNonFastForward
2210 advice.resolveConflict
2211 advice.statusHints
2212 alias.
2213 am.keepcr
2214 apply.ignorewhitespace
2215 apply.whitespace
2216 branch.autosetupmerge
2217 branch.autosetuprebase
2218 browser.
2219 clean.requireForce
2220 color.branch
2221 color.branch.current
2222 color.branch.local
2223 color.branch.plain
2224 color.branch.remote
2225 color.decorate.HEAD
2226 color.decorate.branch
2227 color.decorate.remoteBranch
2228 color.decorate.stash
2229 color.decorate.tag
2230 color.diff
2231 color.diff.commit
2232 color.diff.frag
2233 color.diff.func
2234 color.diff.meta
2235 color.diff.new
2236 color.diff.old
2237 color.diff.plain
2238 color.diff.whitespace
2239 color.grep
2240 color.grep.context
2241 color.grep.filename
2242 color.grep.function
2243 color.grep.linenumber
2244 color.grep.match
2245 color.grep.selected
2246 color.grep.separator
2247 color.interactive
2248 color.interactive.error
2249 color.interactive.header
2250 color.interactive.help
2251 color.interactive.prompt
2252 color.pager
2253 color.showbranch
2254 color.status
2255 color.status.added
2256 color.status.changed
2257 color.status.header
2258 color.status.nobranch
2259 color.status.unmerged
2260 color.status.untracked
2261 color.status.updated
2262 color.ui
2263 commit.status
2264 commit.template
2265 core.abbrev
2266 core.askpass
2267 core.attributesfile
2268 core.autocrlf
2269 core.bare
2270 core.bigFileThreshold
2271 core.compression
2272 core.createObject
2273 core.deltaBaseCacheLimit
2274 core.editor
2275 core.eol
2276 core.excludesfile
2277 core.fileMode
2278 core.fsyncobjectfiles
2279 core.gitProxy
2280 core.ignoreStat
2281 core.ignorecase
2282 core.logAllRefUpdates
2283 core.loosecompression
2284 core.notesRef
2285 core.packedGitLimit
2286 core.packedGitWindowSize
2287 core.pager
2288 core.preferSymlinkRefs
2289 core.preloadindex
2290 core.quotepath
2291 core.repositoryFormatVersion
2292 core.safecrlf
2293 core.sharedRepository
2294 core.sparseCheckout
2295 core.symlinks
2296 core.trustctime
2297 core.untrackedCache
2298 core.warnAmbiguousRefs
2299 core.whitespace
2300 core.worktree
2301 diff.autorefreshindex
2302 diff.external
2303 diff.ignoreSubmodules
2304 diff.mnemonicprefix
2305 diff.noprefix
2306 diff.renameLimit
2307 diff.renames
2308 diff.statGraphWidth
2309 diff.submodule
2310 diff.suppressBlankEmpty
2311 diff.tool
2312 diff.wordRegex
2313 diff.algorithm
2314 difftool.
2315 difftool.prompt
2316 fetch.recurseSubmodules
2317 fetch.unpackLimit
2318 format.attach
2319 format.cc
2320 format.coverLetter
2321 format.from
2322 format.headers
2323 format.numbered
2324 format.pretty
2325 format.signature
2326 format.signoff
2327 format.subjectprefix
2328 format.suffix
2329 format.thread
2330 format.to
2332 gc.aggressiveWindow
2333 gc.auto
2334 gc.autopacklimit
2335 gc.packrefs
2336 gc.pruneexpire
2337 gc.reflogexpire
2338 gc.reflogexpireunreachable
2339 gc.rerereresolved
2340 gc.rerereunresolved
2341 gitcvs.allbinary
2342 gitcvs.commitmsgannotation
2343 gitcvs.dbTableNamePrefix
2344 gitcvs.dbdriver
2345 gitcvs.dbname
2346 gitcvs.dbpass
2347 gitcvs.dbuser
2348 gitcvs.enabled
2349 gitcvs.logfile
2350 gitcvs.usecrlfattr
2351 guitool.
2352 gui.blamehistoryctx
2353 gui.commitmsgwidth
2354 gui.copyblamethreshold
2355 gui.diffcontext
2356 gui.encoding
2357 gui.fastcopyblame
2358 gui.matchtrackingbranch
2359 gui.newbranchtemplate
2360 gui.pruneduringfetch
2361 gui.spellingdictionary
2362 gui.trustmtime
2363 help.autocorrect
2364 help.browser
2365 help.format
2366 http.lowSpeedLimit
2367 http.lowSpeedTime
2368 http.maxRequests
2369 http.minSessions
2370 http.noEPSV
2371 http.postBuffer
2372 http.proxy
2373 http.sslCipherList
2374 http.sslVersion
2375 http.sslCAInfo
2376 http.sslCAPath
2377 http.sslCert
2378 http.sslCertPasswordProtected
2379 http.sslKey
2380 http.sslVerify
2381 http.useragent
2382 i18n.commitEncoding
2383 i18n.logOutputEncoding
2384 imap.authMethod
2385 imap.folder
2386 imap.host
2387 imap.pass
2388 imap.port
2389 imap.preformattedHTML
2390 imap.sslverify
2391 imap.tunnel
2392 imap.user
2393 init.templatedir
2394 instaweb.browser
2395 instaweb.httpd
2396 instaweb.local
2397 instaweb.modulepath
2398 instaweb.port
2399 interactive.singlekey
2400 log.date
2401 log.decorate
2402 log.showroot
2403 mailmap.file
2404 man.
2405 man.viewer
2406 merge.
2407 merge.conflictstyle
2408 merge.log
2409 merge.renameLimit
2410 merge.renormalize
2411 merge.stat
2412 merge.tool
2413 merge.verbosity
2414 mergetool.
2415 mergetool.keepBackup
2416 mergetool.keepTemporaries
2417 mergetool.prompt
2418 notes.displayRef
2419 notes.rewrite.
2420 notes.rewrite.amend
2421 notes.rewrite.rebase
2422 notes.rewriteMode
2423 notes.rewriteRef
2424 pack.compression
2425 pack.deltaCacheLimit
2426 pack.deltaCacheSize
2427 pack.depth
2428 pack.indexVersion
2429 pack.packSizeLimit
2430 pack.threads
2431 pack.window
2432 pack.windowMemory
2433 pager.
2434 pretty.
2435 pull.octopus
2436 pull.twohead
2437 push.default
2438 push.followTags
2439 rebase.autosquash
2440 rebase.stat
2441 receive.autogc
2442 receive.denyCurrentBranch
2443 receive.denyDeleteCurrent
2444 receive.denyDeletes
2445 receive.denyNonFastForwards
2446 receive.fsckObjects
2447 receive.unpackLimit
2448 receive.updateserverinfo
2449 remote.pushdefault
2450 remotes.
2451 repack.usedeltabaseoffset
2452 rerere.autoupdate
2453 rerere.enabled
2454 sendemail.
2455 sendemail.aliasesfile
2456 sendemail.aliasfiletype
2457 sendemail.bcc
2458 sendemail.cc
2459 sendemail.cccmd
2460 sendemail.chainreplyto
2461 sendemail.confirm
2462 sendemail.envelopesender
2463 sendemail.from
2464 sendemail.identity
2465 sendemail.multiedit
2466 sendemail.signedoffbycc
2467 sendemail.smtpdomain
2468 sendemail.smtpencryption
2469 sendemail.smtppass
2470 sendemail.smtpserver
2471 sendemail.smtpserveroption
2472 sendemail.smtpserverport
2473 sendemail.smtpuser
2474 sendemail.suppresscc
2475 sendemail.suppressfrom
2476 sendemail.thread
2477 sendemail.to
2478 sendemail.validate
2479 showbranch.default
2480 status.relativePaths
2481 status.showUntrackedFiles
2482 status.submodulesummary
2483 submodule.
2484 tar.umask
2485 transfer.unpackLimit
2486 url.
2487 user.email
2488 user.name
2489 user.signingkey
2490 web.browser
2491 branch. remote.
2495 _git_remote ()
2497 local subcommands="add rename remove set-head set-branches set-url show prune update"
2498 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2499 if [ -z "$subcommand" ]; then
2500 __gitcomp "$subcommands"
2501 return
2504 case "$subcommand" in
2505 rename|remove|set-url|show|prune)
2506 __gitcomp_nl "$(__git_remotes)"
2508 set-head|set-branches)
2509 __git_complete_remote_or_refspec
2511 update)
2512 __gitcomp "$(__git_get_config_variables "remotes")"
2516 esac
2519 _git_replace ()
2521 __git_complete_refs
2524 _git_reset ()
2526 __git_has_doubledash && return
2528 case "$cur" in
2529 --*)
2530 __gitcomp "--merge --mixed --hard --soft --patch"
2531 return
2533 esac
2534 __git_complete_refs
2537 _git_revert ()
2539 __git_find_repo_path
2540 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2541 __gitcomp "--continue --quit --abort"
2542 return
2544 case "$cur" in
2545 --*)
2546 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2547 return
2549 esac
2550 __git_complete_refs
2553 _git_rm ()
2555 case "$cur" in
2556 --*)
2557 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2558 return
2560 esac
2562 __git_complete_index_file "--cached"
2565 _git_shortlog ()
2567 __git_has_doubledash && return
2569 case "$cur" in
2570 --*)
2571 __gitcomp "
2572 $__git_log_common_options
2573 $__git_log_shortlog_options
2574 --numbered --summary
2576 return
2578 esac
2579 __git_complete_revlist
2582 _git_show ()
2584 __git_has_doubledash && return
2586 case "$cur" in
2587 --pretty=*|--format=*)
2588 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2589 " "" "${cur#*=}"
2590 return
2592 --diff-algorithm=*)
2593 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2594 return
2596 --submodule=*)
2597 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2598 return
2600 --*)
2601 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2602 --show-signature
2603 $__git_diff_common_options
2605 return
2607 esac
2608 __git_complete_revlist_file
2611 _git_show_branch ()
2613 case "$cur" in
2614 --*)
2615 __gitcomp "
2616 --all --remotes --topo-order --date-order --current --more=
2617 --list --independent --merge-base --no-name
2618 --color --no-color
2619 --sha1-name --sparse --topics --reflog
2621 return
2623 esac
2624 __git_complete_revlist
2627 _git_stash ()
2629 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2630 local subcommands='save list show apply clear drop pop create branch'
2631 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2632 if [ -z "$subcommand" ]; then
2633 case "$cur" in
2634 --*)
2635 __gitcomp "$save_opts"
2638 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2639 __gitcomp "$subcommands"
2642 esac
2643 else
2644 case "$subcommand,$cur" in
2645 save,--*)
2646 __gitcomp "$save_opts"
2648 apply,--*|pop,--*)
2649 __gitcomp "--index --quiet"
2651 drop,--*)
2652 __gitcomp "--quiet"
2654 show,--*|branch,--*)
2656 branch,*)
2657 if [ $cword -eq 3 ]; then
2658 __git_complete_refs
2659 else
2660 __gitcomp_nl "$(__git stash list \
2661 | sed -n -e 's/:.*//p')"
2664 show,*|apply,*|drop,*|pop,*)
2665 __gitcomp_nl "$(__git stash list \
2666 | sed -n -e 's/:.*//p')"
2670 esac
2674 _git_submodule ()
2676 __git_has_doubledash && return
2678 local subcommands="add status init deinit update summary foreach sync"
2679 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2680 case "$cur" in
2681 --*)
2682 __gitcomp "--quiet --cached"
2685 __gitcomp "$subcommands"
2687 esac
2688 return
2692 _git_svn ()
2694 local subcommands="
2695 init fetch clone rebase dcommit log find-rev
2696 set-tree commit-diff info create-ignore propget
2697 proplist show-ignore show-externals branch tag blame
2698 migrate mkdirs reset gc
2700 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2701 if [ -z "$subcommand" ]; then
2702 __gitcomp "$subcommands"
2703 else
2704 local remote_opts="--username= --config-dir= --no-auth-cache"
2705 local fc_opts="
2706 --follow-parent --authors-file= --repack=
2707 --no-metadata --use-svm-props --use-svnsync-props
2708 --log-window-size= --no-checkout --quiet
2709 --repack-flags --use-log-author --localtime
2710 --ignore-paths= --include-paths= $remote_opts
2712 local init_opts="
2713 --template= --shared= --trunk= --tags=
2714 --branches= --stdlayout --minimize-url
2715 --no-metadata --use-svm-props --use-svnsync-props
2716 --rewrite-root= --prefix= --use-log-author
2717 --add-author-from $remote_opts
2719 local cmt_opts="
2720 --edit --rmdir --find-copies-harder --copy-similarity=
2723 case "$subcommand,$cur" in
2724 fetch,--*)
2725 __gitcomp "--revision= --fetch-all $fc_opts"
2727 clone,--*)
2728 __gitcomp "--revision= $fc_opts $init_opts"
2730 init,--*)
2731 __gitcomp "$init_opts"
2733 dcommit,--*)
2734 __gitcomp "
2735 --merge --strategy= --verbose --dry-run
2736 --fetch-all --no-rebase --commit-url
2737 --revision --interactive $cmt_opts $fc_opts
2740 set-tree,--*)
2741 __gitcomp "--stdin $cmt_opts $fc_opts"
2743 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2744 show-externals,--*|mkdirs,--*)
2745 __gitcomp "--revision="
2747 log,--*)
2748 __gitcomp "
2749 --limit= --revision= --verbose --incremental
2750 --oneline --show-commit --non-recursive
2751 --authors-file= --color
2754 rebase,--*)
2755 __gitcomp "
2756 --merge --verbose --strategy= --local
2757 --fetch-all --dry-run $fc_opts
2760 commit-diff,--*)
2761 __gitcomp "--message= --file= --revision= $cmt_opts"
2763 info,--*)
2764 __gitcomp "--url"
2766 branch,--*)
2767 __gitcomp "--dry-run --message --tag"
2769 tag,--*)
2770 __gitcomp "--dry-run --message"
2772 blame,--*)
2773 __gitcomp "--git-format"
2775 migrate,--*)
2776 __gitcomp "
2777 --config-dir= --ignore-paths= --minimize
2778 --no-auth-cache --username=
2781 reset,--*)
2782 __gitcomp "--revision= --parent"
2786 esac
2790 _git_tag ()
2792 local i c=1 f=0
2793 while [ $c -lt $cword ]; do
2794 i="${words[c]}"
2795 case "$i" in
2796 -d|-v)
2797 __gitcomp_nl "$(__git_tags)"
2798 return
2803 esac
2804 ((c++))
2805 done
2807 case "$prev" in
2808 -m|-F)
2810 -*|tag)
2811 if [ $f = 1 ]; then
2812 __gitcomp_nl "$(__git_tags)"
2816 __git_complete_refs
2818 esac
2820 case "$cur" in
2821 --*)
2822 __gitcomp "
2823 --list --delete --verify --annotate --message --file
2824 --sign --cleanup --local-user --force --column --sort
2825 --contains --points-at
2828 esac
2831 _git_whatchanged ()
2833 _git_log
2836 _git_worktree ()
2838 local subcommands="add list lock prune unlock"
2839 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2840 if [ -z "$subcommand" ]; then
2841 __gitcomp "$subcommands"
2842 else
2843 case "$subcommand,$cur" in
2844 add,--*)
2845 __gitcomp "--detach"
2847 list,--*)
2848 __gitcomp "--porcelain"
2850 lock,--*)
2851 __gitcomp "--reason"
2853 prune,--*)
2854 __gitcomp "--dry-run --expire --verbose"
2858 esac
2862 __git_main ()
2864 local i c=1 command __git_dir __git_repo_path
2865 local __git_C_args C_args_count=0
2867 while [ $c -lt $cword ]; do
2868 i="${words[c]}"
2869 case "$i" in
2870 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2871 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2872 --bare) __git_dir="." ;;
2873 --help) command="help"; break ;;
2874 -c|--work-tree|--namespace) ((c++)) ;;
2875 -C) __git_C_args[C_args_count++]=-C
2876 ((c++))
2877 __git_C_args[C_args_count++]="${words[c]}"
2879 -*) ;;
2880 *) command="$i"; break ;;
2881 esac
2882 ((c++))
2883 done
2885 if [ -z "$command" ]; then
2886 case "$prev" in
2887 --git-dir|-C|--work-tree)
2888 # these need a path argument, let's fall back to
2889 # Bash filename completion
2890 return
2892 -c|--namespace)
2893 # we don't support completing these options' arguments
2894 return
2896 esac
2897 case "$cur" in
2898 --*) __gitcomp "
2899 --paginate
2900 --no-pager
2901 --git-dir=
2902 --bare
2903 --version
2904 --exec-path
2905 --exec-path=
2906 --html-path
2907 --man-path
2908 --info-path
2909 --work-tree=
2910 --namespace=
2911 --no-replace-objects
2912 --help
2915 *) __git_compute_porcelain_commands
2916 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2917 esac
2918 return
2921 local completion_func="_git_${command//-/_}"
2922 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
2924 local expansion=$(__git_aliased_command "$command")
2925 if [ -n "$expansion" ]; then
2926 words[1]=$expansion
2927 completion_func="_git_${expansion//-/_}"
2928 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
2932 __gitk_main ()
2934 __git_has_doubledash && return
2936 local __git_repo_path
2937 __git_find_repo_path
2939 local merge=""
2940 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2941 merge="--merge"
2943 case "$cur" in
2944 --*)
2945 __gitcomp "
2946 $__git_log_common_options
2947 $__git_log_gitk_options
2948 $merge
2950 return
2952 esac
2953 __git_complete_revlist
2956 if [[ -n ${ZSH_VERSION-} ]]; then
2957 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2959 autoload -U +X compinit && compinit
2961 __gitcomp ()
2963 emulate -L zsh
2965 local cur_="${3-$cur}"
2967 case "$cur_" in
2968 --*=)
2971 local c IFS=$' \t\n'
2972 local -a array
2973 for c in ${=1}; do
2974 c="$c${4-}"
2975 case $c in
2976 --*=*|*.) ;;
2977 *) c="$c " ;;
2978 esac
2979 array[${#array[@]}+1]="$c"
2980 done
2981 compset -P '*[=:]'
2982 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2984 esac
2987 __gitcomp_nl ()
2989 emulate -L zsh
2991 local IFS=$'\n'
2992 compset -P '*[=:]'
2993 compadd -Q -S "${4- }" -p "${2-}" -- ${=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