completion: improve __git_refs()'s in-code documentation
[git/raj.git] / contrib / completion / git-completion.bash
bloba43322b04a8e923edc7c2567a118966b35f6caa1
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 # __gitdir accepts 0 or 1 arguments (i.e., location)
38 # returns location of .git repo
39 __gitdir ()
41 if [ -z "${1-}" ]; then
42 if [ -n "${__git_dir-}" ]; then
43 echo "$__git_dir"
44 elif [ -n "${GIT_DIR-}" ]; then
45 test -d "${GIT_DIR-}" || return 1
46 echo "$GIT_DIR"
47 elif [ -d .git ]; then
48 echo .git
49 else
50 git rev-parse --git-dir 2>/dev/null
52 elif [ -d "$1/.git" ]; then
53 echo "$1/.git"
54 else
55 echo "$1"
59 # The following function is based on code from:
61 # bash_completion - programmable completion functions for bash 3.2+
63 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
64 # © 2009-2010, Bash Completion Maintainers
65 # <bash-completion-devel@lists.alioth.debian.org>
67 # This program is free software; you can redistribute it and/or modify
68 # it under the terms of the GNU General Public License as published by
69 # the Free Software Foundation; either version 2, or (at your option)
70 # any later version.
72 # This program is distributed in the hope that it will be useful,
73 # but WITHOUT ANY WARRANTY; without even the implied warranty of
74 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75 # GNU General Public License for more details.
77 # You should have received a copy of the GNU General Public License
78 # along with this program; if not, write to the Free Software Foundation,
79 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81 # The latest version of this software can be obtained here:
83 # http://bash-completion.alioth.debian.org/
85 # RELEASE: 2.x
87 # This function can be used to access a tokenized list of words
88 # on the command line:
90 # __git_reassemble_comp_words_by_ref '=:'
91 # if test "${words_[cword_-1]}" = -w
92 # then
93 # ...
94 # fi
96 # The argument should be a collection of characters from the list of
97 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
98 # characters.
100 # This is roughly equivalent to going back in time and setting
101 # COMP_WORDBREAKS to exclude those characters. The intent is to
102 # make option types like --date=<type> and <rev>:<path> easy to
103 # recognize by treating each shell word as a single token.
105 # It is best not to set COMP_WORDBREAKS directly because the value is
106 # shared with other completion scripts. By the time the completion
107 # function gets called, COMP_WORDS has already been populated so local
108 # changes to COMP_WORDBREAKS have no effect.
110 # Output: words_, cword_, cur_.
112 __git_reassemble_comp_words_by_ref()
114 local exclude i j first
115 # Which word separators to exclude?
116 exclude="${1//[^$COMP_WORDBREAKS]}"
117 cword_=$COMP_CWORD
118 if [ -z "$exclude" ]; then
119 words_=("${COMP_WORDS[@]}")
120 return
122 # List of word completion separators has shrunk;
123 # re-assemble words to complete.
124 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
125 # Append each nonempty word consisting of just
126 # word separator characters to the current word.
127 first=t
128 while
129 [ $i -gt 0 ] &&
130 [ -n "${COMP_WORDS[$i]}" ] &&
131 # word consists of excluded word separators
132 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
134 # Attach to the previous token,
135 # unless the previous token is the command name.
136 if [ $j -ge 2 ] && [ -n "$first" ]; then
137 ((j--))
139 first=
140 words_[$j]=${words_[j]}${COMP_WORDS[i]}
141 if [ $i = $COMP_CWORD ]; then
142 cword_=$j
144 if (($i < ${#COMP_WORDS[@]} - 1)); then
145 ((i++))
146 else
147 # Done.
148 return
150 done
151 words_[$j]=${words_[j]}${COMP_WORDS[i]}
152 if [ $i = $COMP_CWORD ]; then
153 cword_=$j
155 done
158 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
159 _get_comp_words_by_ref ()
161 local exclude cur_ words_ cword_
162 if [ "$1" = "-n" ]; then
163 exclude=$2
164 shift 2
166 __git_reassemble_comp_words_by_ref "$exclude"
167 cur_=${words_[cword_]}
168 while [ $# -gt 0 ]; do
169 case "$1" in
170 cur)
171 cur=$cur_
173 prev)
174 prev=${words_[$cword_-1]}
176 words)
177 words=("${words_[@]}")
179 cword)
180 cword=$cword_
182 esac
183 shift
184 done
188 __gitcompappend ()
190 local x i=${#COMPREPLY[@]}
191 for x in $1; do
192 if [[ "$x" == "$3"* ]]; then
193 COMPREPLY[i++]="$2$x$4"
195 done
198 __gitcompadd ()
200 COMPREPLY=()
201 __gitcompappend "$@"
204 # Generates completion reply, appending a space to possible completion words,
205 # if necessary.
206 # It accepts 1 to 4 arguments:
207 # 1: List of possible completion words.
208 # 2: A prefix to be added to each possible completion word (optional).
209 # 3: Generate possible completion matches for this word (optional).
210 # 4: A suffix to be appended to each possible completion word (optional).
211 __gitcomp ()
213 local cur_="${3-$cur}"
215 case "$cur_" in
216 --*=)
219 local c i=0 IFS=$' \t\n'
220 for c in $1; do
221 c="$c${4-}"
222 if [[ $c == "$cur_"* ]]; then
223 case $c in
224 --*=*|*.) ;;
225 *) c="$c " ;;
226 esac
227 COMPREPLY[i++]="${2-}$c"
229 done
231 esac
234 # Variation of __gitcomp_nl () that appends to the existing list of
235 # completion candidates, COMPREPLY.
236 __gitcomp_nl_append ()
238 local IFS=$'\n'
239 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
242 # Generates completion reply from newline-separated possible completion words
243 # by appending a space to all of them.
244 # It accepts 1 to 4 arguments:
245 # 1: List of possible completion words, separated by a single newline.
246 # 2: A prefix to be added to each possible completion word (optional).
247 # 3: Generate possible completion matches for this word (optional).
248 # 4: A suffix to be appended to each possible completion word instead of
249 # the default space (optional). If specified but empty, nothing is
250 # appended.
251 __gitcomp_nl ()
253 COMPREPLY=()
254 __gitcomp_nl_append "$@"
257 # Generates completion reply with compgen from newline-separated possible
258 # completion filenames.
259 # It accepts 1 to 3 arguments:
260 # 1: List of possible completion filenames, separated by a single newline.
261 # 2: A directory prefix to be added to each possible completion filename
262 # (optional).
263 # 3: Generate possible completion matches for this word (optional).
264 __gitcomp_file ()
266 local IFS=$'\n'
268 # XXX does not work when the directory prefix contains a tilde,
269 # since tilde expansion is not applied.
270 # This means that COMPREPLY will be empty and Bash default
271 # completion will be used.
272 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
274 # use a hack to enable file mode in bash < 4
275 compopt -o filenames +o nospace 2>/dev/null ||
276 compgen -f /non-existing-dir/ > /dev/null
279 # Execute 'git ls-files', unless the --committable option is specified, in
280 # which case it runs 'git diff-index' to find out the files that can be
281 # committed. It return paths relative to the directory specified in the first
282 # argument, and using the options specified in the second argument.
283 __git_ls_files_helper ()
285 if [ "$2" == "--committable" ]; then
286 git -C "$1" diff-index --name-only --relative HEAD
287 else
288 # NOTE: $2 is not quoted in order to support multiple options
289 git -C "$1" ls-files --exclude-standard $2
290 fi 2>/dev/null
294 # __git_index_files accepts 1 or 2 arguments:
295 # 1: Options to pass to ls-files (required).
296 # 2: A directory path (optional).
297 # If provided, only files within the specified directory are listed.
298 # Sub directories are never recursed. Path must have a trailing
299 # slash.
300 __git_index_files ()
302 local dir="$(__gitdir)" root="${2-.}" file
304 if [ -d "$dir" ]; then
305 __git_ls_files_helper "$root" "$1" |
306 while read -r file; do
307 case "$file" in
308 ?*/*) echo "${file%%/*}" ;;
309 *) echo "$file" ;;
310 esac
311 done | sort | uniq
315 __git_heads ()
317 local dir="$(__gitdir)"
318 if [ -d "$dir" ]; then
319 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
320 refs/heads
321 return
325 __git_tags ()
327 local dir="$(__gitdir)"
328 if [ -d "$dir" ]; then
329 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
330 refs/tags
331 return
335 # Lists refs from the local (by default) or from a remote repository.
336 # It accepts 0, 1 or 2 arguments:
337 # 1: The remote to list refs from (optional; ignored, if set but empty).
338 # 2: In addition to local refs, list unique branches from refs/remotes/ for
339 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
340 __git_refs ()
342 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
343 local format refs pfx
344 if [ -d "$dir" ]; then
345 case "$cur" in
346 refs|refs/*)
347 format="refname"
348 refs="${cur%/*}"
349 track=""
352 [[ "$cur" == ^* ]] && pfx="^"
353 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
354 if [ -e "$dir/$i" ]; then echo $pfx$i; fi
355 done
356 format="refname:short"
357 refs="refs/tags refs/heads refs/remotes"
359 esac
360 git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \
361 $refs
362 if [ -n "$track" ]; then
363 # employ the heuristic used by git checkout
364 # Try to find a remote branch that matches the completion word
365 # but only output if the branch name is unique
366 local ref entry
367 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
368 "refs/remotes/" | \
369 while read -r entry; do
370 eval "$entry"
371 ref="${ref#*/}"
372 if [[ "$ref" == "$cur"* ]]; then
373 echo "$ref"
375 done | sort | uniq -u
377 return
379 case "$cur" in
380 refs|refs/*)
381 git ls-remote "$dir" "$cur*" 2>/dev/null | \
382 while read -r hash i; do
383 case "$i" in
384 *^{}) ;;
385 *) echo "$i" ;;
386 esac
387 done
390 echo "HEAD"
391 git for-each-ref --format="%(refname:short)" -- \
392 "refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##"
394 esac
397 # __git_refs2 requires 1 argument (to pass to __git_refs)
398 __git_refs2 ()
400 local i
401 for i in $(__git_refs "$1"); do
402 echo "$i:$i"
403 done
406 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
407 __git_refs_remotes ()
409 local i hash
410 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
411 while read -r hash i; do
412 echo "$i:refs/remotes/$1/${i#refs/heads/}"
413 done
416 __git_remotes ()
418 local d="$(__gitdir)"
419 test -d "$d/remotes" && ls -1 "$d/remotes"
420 git --git-dir="$d" remote
423 __git_list_merge_strategies ()
425 git merge -s help 2>&1 |
426 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
427 s/\.$//
428 s/.*://
429 s/^[ ]*//
430 s/[ ]*$//
435 __git_merge_strategies=
436 # 'git merge -s help' (and thus detection of the merge strategy
437 # list) fails, unfortunately, if run outside of any git working
438 # tree. __git_merge_strategies is set to the empty string in
439 # that case, and the detection will be repeated the next time it
440 # is needed.
441 __git_compute_merge_strategies ()
443 test -n "$__git_merge_strategies" ||
444 __git_merge_strategies=$(__git_list_merge_strategies)
447 __git_complete_revlist_file ()
449 local pfx ls ref cur_="$cur"
450 case "$cur_" in
451 *..?*:*)
452 return
454 ?*:*)
455 ref="${cur_%%:*}"
456 cur_="${cur_#*:}"
457 case "$cur_" in
458 ?*/*)
459 pfx="${cur_%/*}"
460 cur_="${cur_##*/}"
461 ls="$ref:$pfx"
462 pfx="$pfx/"
465 ls="$ref"
467 esac
469 case "$COMP_WORDBREAKS" in
470 *:*) : great ;;
471 *) pfx="$ref:$pfx" ;;
472 esac
474 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
475 | sed '/^100... blob /{
476 s,^.* ,,
477 s,$, ,
479 /^120000 blob /{
480 s,^.* ,,
481 s,$, ,
483 /^040000 tree /{
484 s,^.* ,,
485 s,$,/,
487 s/^.* //')" \
488 "$pfx" "$cur_" ""
490 *...*)
491 pfx="${cur_%...*}..."
492 cur_="${cur_#*...}"
493 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
495 *..*)
496 pfx="${cur_%..*}.."
497 cur_="${cur_#*..}"
498 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
501 __gitcomp_nl "$(__git_refs)"
503 esac
507 # __git_complete_index_file requires 1 argument:
508 # 1: the options to pass to ls-file
510 # The exception is --committable, which finds the files appropriate commit.
511 __git_complete_index_file ()
513 local pfx="" cur_="$cur"
515 case "$cur_" in
516 ?*/*)
517 pfx="${cur_%/*}"
518 cur_="${cur_##*/}"
519 pfx="${pfx}/"
521 esac
523 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
526 __git_complete_file ()
528 __git_complete_revlist_file
531 __git_complete_revlist ()
533 __git_complete_revlist_file
536 __git_complete_remote_or_refspec ()
538 local cur_="$cur" cmd="${words[1]}"
539 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
540 if [ "$cmd" = "remote" ]; then
541 ((c++))
543 while [ $c -lt $cword ]; do
544 i="${words[c]}"
545 case "$i" in
546 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
547 --all)
548 case "$cmd" in
549 push) no_complete_refspec=1 ;;
550 fetch)
551 return
553 *) ;;
554 esac
556 -*) ;;
557 *) remote="$i"; break ;;
558 esac
559 ((c++))
560 done
561 if [ -z "$remote" ]; then
562 __gitcomp_nl "$(__git_remotes)"
563 return
565 if [ $no_complete_refspec = 1 ]; then
566 return
568 [ "$remote" = "." ] && remote=
569 case "$cur_" in
570 *:*)
571 case "$COMP_WORDBREAKS" in
572 *:*) : great ;;
573 *) pfx="${cur_%%:*}:" ;;
574 esac
575 cur_="${cur_#*:}"
576 lhs=0
579 pfx="+"
580 cur_="${cur_#+}"
582 esac
583 case "$cmd" in
584 fetch)
585 if [ $lhs = 1 ]; then
586 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
587 else
588 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
591 pull|remote)
592 if [ $lhs = 1 ]; then
593 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
594 else
595 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
598 push)
599 if [ $lhs = 1 ]; then
600 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
601 else
602 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
605 esac
608 __git_complete_strategy ()
610 __git_compute_merge_strategies
611 case "$prev" in
612 -s|--strategy)
613 __gitcomp "$__git_merge_strategies"
614 return 0
615 esac
616 case "$cur" in
617 --strategy=*)
618 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
619 return 0
621 esac
622 return 1
625 __git_commands () {
626 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
627 then
628 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
629 else
630 git help -a|egrep '^ [a-zA-Z0-9]'
634 __git_list_all_commands ()
636 local i IFS=" "$'\n'
637 for i in $(__git_commands)
639 case $i in
640 *--*) : helper pattern;;
641 *) echo $i;;
642 esac
643 done
646 __git_all_commands=
647 __git_compute_all_commands ()
649 test -n "$__git_all_commands" ||
650 __git_all_commands=$(__git_list_all_commands)
653 __git_list_porcelain_commands ()
655 local i IFS=" "$'\n'
656 __git_compute_all_commands
657 for i in $__git_all_commands
659 case $i in
660 *--*) : helper pattern;;
661 applymbox) : ask gittus;;
662 applypatch) : ask gittus;;
663 archimport) : import;;
664 cat-file) : plumbing;;
665 check-attr) : plumbing;;
666 check-ignore) : plumbing;;
667 check-mailmap) : plumbing;;
668 check-ref-format) : plumbing;;
669 checkout-index) : plumbing;;
670 column) : internal helper;;
671 commit-tree) : plumbing;;
672 count-objects) : infrequent;;
673 credential) : credentials;;
674 credential-*) : credentials helper;;
675 cvsexportcommit) : export;;
676 cvsimport) : import;;
677 cvsserver) : daemon;;
678 daemon) : daemon;;
679 diff-files) : plumbing;;
680 diff-index) : plumbing;;
681 diff-tree) : plumbing;;
682 fast-import) : import;;
683 fast-export) : export;;
684 fsck-objects) : plumbing;;
685 fetch-pack) : plumbing;;
686 fmt-merge-msg) : plumbing;;
687 for-each-ref) : plumbing;;
688 hash-object) : plumbing;;
689 http-*) : transport;;
690 index-pack) : plumbing;;
691 init-db) : deprecated;;
692 local-fetch) : plumbing;;
693 ls-files) : plumbing;;
694 ls-remote) : plumbing;;
695 ls-tree) : plumbing;;
696 mailinfo) : plumbing;;
697 mailsplit) : plumbing;;
698 merge-*) : plumbing;;
699 mktree) : plumbing;;
700 mktag) : plumbing;;
701 pack-objects) : plumbing;;
702 pack-redundant) : plumbing;;
703 pack-refs) : plumbing;;
704 parse-remote) : plumbing;;
705 patch-id) : plumbing;;
706 prune) : plumbing;;
707 prune-packed) : plumbing;;
708 quiltimport) : import;;
709 read-tree) : plumbing;;
710 receive-pack) : plumbing;;
711 remote-*) : transport;;
712 rerere) : plumbing;;
713 rev-list) : plumbing;;
714 rev-parse) : plumbing;;
715 runstatus) : plumbing;;
716 sh-setup) : internal;;
717 shell) : daemon;;
718 show-ref) : plumbing;;
719 send-pack) : plumbing;;
720 show-index) : plumbing;;
721 ssh-*) : transport;;
722 stripspace) : plumbing;;
723 symbolic-ref) : plumbing;;
724 unpack-file) : plumbing;;
725 unpack-objects) : plumbing;;
726 update-index) : plumbing;;
727 update-ref) : plumbing;;
728 update-server-info) : daemon;;
729 upload-archive) : plumbing;;
730 upload-pack) : plumbing;;
731 write-tree) : plumbing;;
732 var) : infrequent;;
733 verify-pack) : infrequent;;
734 verify-tag) : plumbing;;
735 *) echo $i;;
736 esac
737 done
740 __git_porcelain_commands=
741 __git_compute_porcelain_commands ()
743 test -n "$__git_porcelain_commands" ||
744 __git_porcelain_commands=$(__git_list_porcelain_commands)
747 # Lists all set config variables starting with the given section prefix,
748 # with the prefix removed.
749 __git_get_config_variables ()
751 local section="$1" i IFS=$'\n'
752 for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
753 echo "${i#$section.}"
754 done
757 __git_pretty_aliases ()
759 __git_get_config_variables "pretty"
762 __git_aliases ()
764 __git_get_config_variables "alias"
767 # __git_aliased_command requires 1 argument
768 __git_aliased_command ()
770 local word cmdline=$(git --git-dir="$(__gitdir)" \
771 config --get "alias.$1")
772 for word in $cmdline; do
773 case "$word" in
774 \!gitk|gitk)
775 echo "gitk"
776 return
778 \!*) : shell command alias ;;
779 -*) : option ;;
780 *=*) : setting env ;;
781 git) : git itself ;;
782 \(\)) : skip parens of shell function definition ;;
783 {) : skip start of shell helper function ;;
784 :) : skip null command ;;
785 \'*) : skip opening quote after sh -c ;;
787 echo "$word"
788 return
789 esac
790 done
793 # __git_find_on_cmdline requires 1 argument
794 __git_find_on_cmdline ()
796 local word subcommand c=1
797 while [ $c -lt $cword ]; do
798 word="${words[c]}"
799 for subcommand in $1; do
800 if [ "$subcommand" = "$word" ]; then
801 echo "$subcommand"
802 return
804 done
805 ((c++))
806 done
809 # Echo the value of an option set on the command line or config
811 # $1: short option name
812 # $2: long option name including =
813 # $3: list of possible values
814 # $4: config string (optional)
816 # example:
817 # result="$(__git_get_option_value "-d" "--do-something=" \
818 # "yes no" "core.doSomething")"
820 # result is then either empty (no option set) or "yes" or "no"
822 # __git_get_option_value requires 3 arguments
823 __git_get_option_value ()
825 local c short_opt long_opt val
826 local result= values config_key word
828 short_opt="$1"
829 long_opt="$2"
830 values="$3"
831 config_key="$4"
833 ((c = $cword - 1))
834 while [ $c -ge 0 ]; do
835 word="${words[c]}"
836 for val in $values; do
837 if [ "$short_opt$val" = "$word" ] ||
838 [ "$long_opt$val" = "$word" ]; then
839 result="$val"
840 break 2
842 done
843 ((c--))
844 done
846 if [ -n "$config_key" ] && [ -z "$result" ]; then
847 result="$(git --git-dir="$(__gitdir)" config "$config_key")"
850 echo "$result"
853 __git_has_doubledash ()
855 local c=1
856 while [ $c -lt $cword ]; do
857 if [ "--" = "${words[c]}" ]; then
858 return 0
860 ((c++))
861 done
862 return 1
865 # Try to count non option arguments passed on the command line for the
866 # specified git command.
867 # When options are used, it is necessary to use the special -- option to
868 # tell the implementation were non option arguments begin.
869 # XXX this can not be improved, since options can appear everywhere, as
870 # an example:
871 # git mv x -n y
873 # __git_count_arguments requires 1 argument: the git command executed.
874 __git_count_arguments ()
876 local word i c=0
878 # Skip "git" (first argument)
879 for ((i=1; i < ${#words[@]}; i++)); do
880 word="${words[i]}"
882 case "$word" in
884 # Good; we can assume that the following are only non
885 # option arguments.
886 ((c = 0))
888 "$1")
889 # Skip the specified git command and discard git
890 # main options
891 ((c = 0))
894 ((c++))
896 esac
897 done
899 printf "%d" $c
902 __git_whitespacelist="nowarn warn error error-all fix"
904 _git_am ()
906 local dir="$(__gitdir)"
907 if [ -d "$dir"/rebase-apply ]; then
908 __gitcomp "--skip --continue --resolved --abort"
909 return
911 case "$cur" in
912 --whitespace=*)
913 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
914 return
916 --*)
917 __gitcomp "
918 --3way --committer-date-is-author-date --ignore-date
919 --ignore-whitespace --ignore-space-change
920 --interactive --keep --no-utf8 --signoff --utf8
921 --whitespace= --scissors
923 return
924 esac
927 _git_apply ()
929 case "$cur" in
930 --whitespace=*)
931 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
932 return
934 --*)
935 __gitcomp "
936 --stat --numstat --summary --check --index
937 --cached --index-info --reverse --reject --unidiff-zero
938 --apply --no-add --exclude=
939 --ignore-whitespace --ignore-space-change
940 --whitespace= --inaccurate-eof --verbose
942 return
943 esac
946 _git_add ()
948 case "$cur" in
949 --*)
950 __gitcomp "
951 --interactive --refresh --patch --update --dry-run
952 --ignore-errors --intent-to-add
954 return
955 esac
957 # XXX should we check for --update and --all options ?
958 __git_complete_index_file "--others --modified --directory --no-empty-directory"
961 _git_archive ()
963 case "$cur" in
964 --format=*)
965 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
966 return
968 --remote=*)
969 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
970 return
972 --*)
973 __gitcomp "
974 --format= --list --verbose
975 --prefix= --remote= --exec=
977 return
979 esac
980 __git_complete_file
983 _git_bisect ()
985 __git_has_doubledash && return
987 local subcommands="start bad good skip reset visualize replay log run"
988 local subcommand="$(__git_find_on_cmdline "$subcommands")"
989 if [ -z "$subcommand" ]; then
990 if [ -f "$(__gitdir)"/BISECT_START ]; then
991 __gitcomp "$subcommands"
992 else
993 __gitcomp "replay start"
995 return
998 case "$subcommand" in
999 bad|good|reset|skip|start)
1000 __gitcomp_nl "$(__git_refs)"
1004 esac
1007 _git_branch ()
1009 local i c=1 only_local_ref="n" has_r="n"
1011 while [ $c -lt $cword ]; do
1012 i="${words[c]}"
1013 case "$i" in
1014 -d|--delete|-m|--move) only_local_ref="y" ;;
1015 -r|--remotes) has_r="y" ;;
1016 esac
1017 ((c++))
1018 done
1020 case "$cur" in
1021 --set-upstream-to=*)
1022 __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1024 --*)
1025 __gitcomp "
1026 --color --no-color --verbose --abbrev= --no-abbrev
1027 --track --no-track --contains --merged --no-merged
1028 --set-upstream-to= --edit-description --list
1029 --unset-upstream --delete --move --remotes
1033 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1034 __gitcomp_nl "$(__git_heads)"
1035 else
1036 __gitcomp_nl "$(__git_refs)"
1039 esac
1042 _git_bundle ()
1044 local cmd="${words[2]}"
1045 case "$cword" in
1047 __gitcomp "create list-heads verify unbundle"
1050 # looking for a file
1053 case "$cmd" in
1054 create)
1055 __git_complete_revlist
1057 esac
1059 esac
1062 _git_checkout ()
1064 __git_has_doubledash && return
1066 case "$cur" in
1067 --conflict=*)
1068 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1070 --*)
1071 __gitcomp "
1072 --quiet --ours --theirs --track --no-track --merge
1073 --conflict= --orphan --patch
1077 # check if --track, --no-track, or --no-guess was specified
1078 # if so, disable DWIM mode
1079 local flags="--track --no-track --no-guess" track=1
1080 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1081 track=''
1083 __gitcomp_nl "$(__git_refs '' $track)"
1085 esac
1088 _git_cherry ()
1090 __gitcomp_nl "$(__git_refs)"
1093 _git_cherry_pick ()
1095 local dir="$(__gitdir)"
1096 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1097 __gitcomp "--continue --quit --abort"
1098 return
1100 case "$cur" in
1101 --*)
1102 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1105 __gitcomp_nl "$(__git_refs)"
1107 esac
1110 _git_clean ()
1112 case "$cur" in
1113 --*)
1114 __gitcomp "--dry-run --quiet"
1115 return
1117 esac
1119 # XXX should we check for -x option ?
1120 __git_complete_index_file "--others --directory"
1123 _git_clone ()
1125 case "$cur" in
1126 --*)
1127 __gitcomp "
1128 --local
1129 --no-hardlinks
1130 --shared
1131 --reference
1132 --quiet
1133 --no-checkout
1134 --bare
1135 --mirror
1136 --origin
1137 --upload-pack
1138 --template=
1139 --depth
1140 --single-branch
1141 --branch
1142 --recurse-submodules
1144 return
1146 esac
1149 __git_untracked_file_modes="all no normal"
1151 _git_commit ()
1153 case "$prev" in
1154 -c|-C)
1155 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1156 return
1158 esac
1160 case "$cur" in
1161 --cleanup=*)
1162 __gitcomp "default scissors strip verbatim whitespace
1163 " "" "${cur##--cleanup=}"
1164 return
1166 --reuse-message=*|--reedit-message=*|\
1167 --fixup=*|--squash=*)
1168 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1169 return
1171 --untracked-files=*)
1172 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1173 return
1175 --*)
1176 __gitcomp "
1177 --all --author= --signoff --verify --no-verify
1178 --edit --no-edit
1179 --amend --include --only --interactive
1180 --dry-run --reuse-message= --reedit-message=
1181 --reset-author --file= --message= --template=
1182 --cleanup= --untracked-files --untracked-files=
1183 --verbose --quiet --fixup= --squash=
1185 return
1186 esac
1188 if git rev-parse --verify --quiet HEAD >/dev/null; then
1189 __git_complete_index_file "--committable"
1190 else
1191 # This is the first commit
1192 __git_complete_index_file "--cached"
1196 _git_describe ()
1198 case "$cur" in
1199 --*)
1200 __gitcomp "
1201 --all --tags --contains --abbrev= --candidates=
1202 --exact-match --debug --long --match --always
1204 return
1205 esac
1206 __gitcomp_nl "$(__git_refs)"
1209 __git_diff_algorithms="myers minimal patience histogram"
1211 __git_diff_submodule_formats="diff log short"
1213 __git_diff_common_options="--stat --numstat --shortstat --summary
1214 --patch-with-stat --name-only --name-status --color
1215 --no-color --color-words --no-renames --check
1216 --full-index --binary --abbrev --diff-filter=
1217 --find-copies-harder
1218 --text --ignore-space-at-eol --ignore-space-change
1219 --ignore-all-space --ignore-blank-lines --exit-code
1220 --quiet --ext-diff --no-ext-diff
1221 --no-prefix --src-prefix= --dst-prefix=
1222 --inter-hunk-context=
1223 --patience --histogram --minimal
1224 --raw --word-diff --word-diff-regex=
1225 --dirstat --dirstat= --dirstat-by-file
1226 --dirstat-by-file= --cumulative
1227 --diff-algorithm=
1228 --submodule --submodule=
1231 _git_diff ()
1233 __git_has_doubledash && return
1235 case "$cur" in
1236 --diff-algorithm=*)
1237 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1238 return
1240 --submodule=*)
1241 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1242 return
1244 --*)
1245 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1246 --base --ours --theirs --no-index
1247 $__git_diff_common_options
1249 return
1251 esac
1252 __git_complete_revlist_file
1255 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1256 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1259 _git_difftool ()
1261 __git_has_doubledash && return
1263 case "$cur" in
1264 --tool=*)
1265 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1266 return
1268 --*)
1269 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1270 --base --ours --theirs
1271 --no-renames --diff-filter= --find-copies-harder
1272 --relative --ignore-submodules
1273 --tool="
1274 return
1276 esac
1277 __git_complete_revlist_file
1280 __git_fetch_recurse_submodules="yes on-demand no"
1282 __git_fetch_options="
1283 --quiet --verbose --append --upload-pack --force --keep --depth=
1284 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1287 _git_fetch ()
1289 case "$cur" in
1290 --recurse-submodules=*)
1291 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1292 return
1294 --*)
1295 __gitcomp "$__git_fetch_options"
1296 return
1298 esac
1299 __git_complete_remote_or_refspec
1302 __git_format_patch_options="
1303 --stdout --attach --no-attach --thread --thread= --no-thread
1304 --numbered --start-number --numbered-files --keep-subject --signoff
1305 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1306 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1307 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1308 --output-directory --reroll-count --to= --quiet --notes
1311 _git_format_patch ()
1313 case "$cur" in
1314 --thread=*)
1315 __gitcomp "
1316 deep shallow
1317 " "" "${cur##--thread=}"
1318 return
1320 --*)
1321 __gitcomp "$__git_format_patch_options"
1322 return
1324 esac
1325 __git_complete_revlist
1328 _git_fsck ()
1330 case "$cur" in
1331 --*)
1332 __gitcomp "
1333 --tags --root --unreachable --cache --no-reflogs --full
1334 --strict --verbose --lost-found
1336 return
1338 esac
1341 _git_gc ()
1343 case "$cur" in
1344 --*)
1345 __gitcomp "--prune --aggressive"
1346 return
1348 esac
1351 _git_gitk ()
1353 _gitk
1356 __git_match_ctag() {
1357 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1360 _git_grep ()
1362 __git_has_doubledash && return
1364 case "$cur" in
1365 --*)
1366 __gitcomp "
1367 --cached
1368 --text --ignore-case --word-regexp --invert-match
1369 --full-name --line-number
1370 --extended-regexp --basic-regexp --fixed-strings
1371 --perl-regexp
1372 --threads
1373 --files-with-matches --name-only
1374 --files-without-match
1375 --max-depth
1376 --count
1377 --and --or --not --all-match
1379 return
1381 esac
1383 case "$cword,$prev" in
1384 2,*|*,-*)
1385 if test -r tags; then
1386 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1387 return
1390 esac
1392 __gitcomp_nl "$(__git_refs)"
1395 _git_help ()
1397 case "$cur" in
1398 --*)
1399 __gitcomp "--all --guides --info --man --web"
1400 return
1402 esac
1403 __git_compute_all_commands
1404 __gitcomp "$__git_all_commands $(__git_aliases)
1405 attributes cli core-tutorial cvs-migration
1406 diffcore everyday gitk glossary hooks ignore modules
1407 namespaces repository-layout revisions tutorial tutorial-2
1408 workflows
1412 _git_init ()
1414 case "$cur" in
1415 --shared=*)
1416 __gitcomp "
1417 false true umask group all world everybody
1418 " "" "${cur##--shared=}"
1419 return
1421 --*)
1422 __gitcomp "--quiet --bare --template= --shared --shared="
1423 return
1425 esac
1428 _git_ls_files ()
1430 case "$cur" in
1431 --*)
1432 __gitcomp "--cached --deleted --modified --others --ignored
1433 --stage --directory --no-empty-directory --unmerged
1434 --killed --exclude= --exclude-from=
1435 --exclude-per-directory= --exclude-standard
1436 --error-unmatch --with-tree= --full-name
1437 --abbrev --ignored --exclude-per-directory
1439 return
1441 esac
1443 # XXX ignore options like --modified and always suggest all cached
1444 # files.
1445 __git_complete_index_file "--cached"
1448 _git_ls_remote ()
1450 __gitcomp_nl "$(__git_remotes)"
1453 _git_ls_tree ()
1455 __git_complete_file
1458 # Options that go well for log, shortlog and gitk
1459 __git_log_common_options="
1460 --not --all
1461 --branches --tags --remotes
1462 --first-parent --merges --no-merges
1463 --max-count=
1464 --max-age= --since= --after=
1465 --min-age= --until= --before=
1466 --min-parents= --max-parents=
1467 --no-min-parents --no-max-parents
1469 # Options that go well for log and gitk (not shortlog)
1470 __git_log_gitk_options="
1471 --dense --sparse --full-history
1472 --simplify-merges --simplify-by-decoration
1473 --left-right --notes --no-notes
1475 # Options that go well for log and shortlog (not gitk)
1476 __git_log_shortlog_options="
1477 --author= --committer= --grep=
1478 --all-match --invert-grep
1481 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1482 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1484 _git_log ()
1486 __git_has_doubledash && return
1488 local g="$(git rev-parse --git-dir 2>/dev/null)"
1489 local merge=""
1490 if [ -f "$g/MERGE_HEAD" ]; then
1491 merge="--merge"
1493 case "$cur" in
1494 --pretty=*|--format=*)
1495 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1496 " "" "${cur#*=}"
1497 return
1499 --date=*)
1500 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1501 return
1503 --decorate=*)
1504 __gitcomp "full short no" "" "${cur##--decorate=}"
1505 return
1507 --diff-algorithm=*)
1508 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1509 return
1511 --submodule=*)
1512 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1513 return
1515 --*)
1516 __gitcomp "
1517 $__git_log_common_options
1518 $__git_log_shortlog_options
1519 $__git_log_gitk_options
1520 --root --topo-order --date-order --reverse
1521 --follow --full-diff
1522 --abbrev-commit --abbrev=
1523 --relative-date --date=
1524 --pretty= --format= --oneline
1525 --show-signature
1526 --cherry-mark
1527 --cherry-pick
1528 --graph
1529 --decorate --decorate=
1530 --walk-reflogs
1531 --parents --children
1532 $merge
1533 $__git_diff_common_options
1534 --pickaxe-all --pickaxe-regex
1536 return
1538 esac
1539 __git_complete_revlist
1542 # Common merge options shared by git-merge(1) and git-pull(1).
1543 __git_merge_options="
1544 --no-commit --no-stat --log --no-log --squash --strategy
1545 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1546 --verify-signatures --no-verify-signatures --gpg-sign
1547 --quiet --verbose --progress --no-progress
1550 _git_merge ()
1552 __git_complete_strategy && return
1554 case "$cur" in
1555 --*)
1556 __gitcomp "$__git_merge_options
1557 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1558 return
1559 esac
1560 __gitcomp_nl "$(__git_refs)"
1563 _git_mergetool ()
1565 case "$cur" in
1566 --tool=*)
1567 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1568 return
1570 --*)
1571 __gitcomp "--tool="
1572 return
1574 esac
1577 _git_merge_base ()
1579 case "$cur" in
1580 --*)
1581 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1582 return
1584 esac
1585 __gitcomp_nl "$(__git_refs)"
1588 _git_mv ()
1590 case "$cur" in
1591 --*)
1592 __gitcomp "--dry-run"
1593 return
1595 esac
1597 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1598 # We need to show both cached and untracked files (including
1599 # empty directories) since this may not be the last argument.
1600 __git_complete_index_file "--cached --others --directory"
1601 else
1602 __git_complete_index_file "--cached"
1606 _git_name_rev ()
1608 __gitcomp "--tags --all --stdin"
1611 _git_notes ()
1613 local subcommands='add append copy edit list prune remove show'
1614 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1616 case "$subcommand,$cur" in
1617 ,--*)
1618 __gitcomp '--ref'
1621 case "$prev" in
1622 --ref)
1623 __gitcomp_nl "$(__git_refs)"
1626 __gitcomp "$subcommands --ref"
1628 esac
1630 add,--reuse-message=*|append,--reuse-message=*|\
1631 add,--reedit-message=*|append,--reedit-message=*)
1632 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1634 add,--*|append,--*)
1635 __gitcomp '--file= --message= --reedit-message=
1636 --reuse-message='
1638 copy,--*)
1639 __gitcomp '--stdin'
1641 prune,--*)
1642 __gitcomp '--dry-run --verbose'
1644 prune,*)
1647 case "$prev" in
1648 -m|-F)
1651 __gitcomp_nl "$(__git_refs)"
1653 esac
1655 esac
1658 _git_pull ()
1660 __git_complete_strategy && return
1662 case "$cur" in
1663 --recurse-submodules=*)
1664 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1665 return
1667 --*)
1668 __gitcomp "
1669 --rebase --no-rebase
1670 $__git_merge_options
1671 $__git_fetch_options
1673 return
1675 esac
1676 __git_complete_remote_or_refspec
1679 __git_push_recurse_submodules="check on-demand"
1681 __git_complete_force_with_lease ()
1683 local cur_=$1
1685 case "$cur_" in
1686 --*=)
1688 *:*)
1689 __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
1692 __gitcomp_nl "$(__git_refs)" "" "$cur_"
1694 esac
1697 _git_push ()
1699 case "$prev" in
1700 --repo)
1701 __gitcomp_nl "$(__git_remotes)"
1702 return
1704 --recurse-submodules)
1705 __gitcomp "$__git_push_recurse_submodules"
1706 return
1708 esac
1709 case "$cur" in
1710 --repo=*)
1711 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1712 return
1714 --recurse-submodules=*)
1715 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1716 return
1718 --force-with-lease=*)
1719 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1720 return
1722 --*)
1723 __gitcomp "
1724 --all --mirror --tags --dry-run --force --verbose
1725 --quiet --prune --delete --follow-tags
1726 --receive-pack= --repo= --set-upstream
1727 --force-with-lease --force-with-lease= --recurse-submodules=
1729 return
1731 esac
1732 __git_complete_remote_or_refspec
1735 _git_rebase ()
1737 local dir="$(__gitdir)"
1738 if [ -f "$dir"/rebase-merge/interactive ]; then
1739 __gitcomp "--continue --skip --abort --quit --edit-todo"
1740 return
1741 elif [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1742 __gitcomp "--continue --skip --abort --quit"
1743 return
1745 __git_complete_strategy && return
1746 case "$cur" in
1747 --whitespace=*)
1748 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1749 return
1751 --*)
1752 __gitcomp "
1753 --onto --merge --strategy --interactive
1754 --preserve-merges --stat --no-stat
1755 --committer-date-is-author-date --ignore-date
1756 --ignore-whitespace --whitespace=
1757 --autosquash --no-autosquash
1758 --fork-point --no-fork-point
1759 --autostash --no-autostash
1760 --verify --no-verify
1761 --keep-empty --root --force-rebase --no-ff
1762 --exec
1765 return
1766 esac
1767 __gitcomp_nl "$(__git_refs)"
1770 _git_reflog ()
1772 local subcommands="show delete expire"
1773 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1775 if [ -z "$subcommand" ]; then
1776 __gitcomp "$subcommands"
1777 else
1778 __gitcomp_nl "$(__git_refs)"
1782 __git_send_email_confirm_options="always never auto cc compose"
1783 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1785 _git_send_email ()
1787 case "$prev" in
1788 --to|--cc|--bcc|--from)
1789 __gitcomp "
1790 $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
1792 return
1794 esac
1796 case "$cur" in
1797 --confirm=*)
1798 __gitcomp "
1799 $__git_send_email_confirm_options
1800 " "" "${cur##--confirm=}"
1801 return
1803 --suppress-cc=*)
1804 __gitcomp "
1805 $__git_send_email_suppresscc_options
1806 " "" "${cur##--suppress-cc=}"
1808 return
1810 --smtp-encryption=*)
1811 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1812 return
1814 --thread=*)
1815 __gitcomp "
1816 deep shallow
1817 " "" "${cur##--thread=}"
1818 return
1820 --to=*|--cc=*|--bcc=*|--from=*)
1821 __gitcomp "
1822 $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
1823 " "" "${cur#--*=}"
1824 return
1826 --*)
1827 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1828 --compose --confirm= --dry-run --envelope-sender
1829 --from --identity
1830 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1831 --no-suppress-from --no-thread --quiet
1832 --signed-off-by-cc --smtp-pass --smtp-server
1833 --smtp-server-port --smtp-encryption= --smtp-user
1834 --subject --suppress-cc= --suppress-from --thread --to
1835 --validate --no-validate
1836 $__git_format_patch_options"
1837 return
1839 esac
1840 __git_complete_revlist
1843 _git_stage ()
1845 _git_add
1848 _git_status ()
1850 local complete_opt
1851 local untracked_state
1853 case "$cur" in
1854 --ignore-submodules=*)
1855 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1856 return
1858 --untracked-files=*)
1859 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1860 return
1862 --column=*)
1863 __gitcomp "
1864 always never auto column row plain dense nodense
1865 " "" "${cur##--column=}"
1866 return
1868 --*)
1869 __gitcomp "
1870 --short --branch --porcelain --long --verbose
1871 --untracked-files= --ignore-submodules= --ignored
1872 --column= --no-column
1874 return
1876 esac
1878 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1879 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
1881 case "$untracked_state" in
1883 # --ignored option does not matter
1884 complete_opt=
1886 all|normal|*)
1887 complete_opt="--cached --directory --no-empty-directory --others"
1889 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1890 complete_opt="$complete_opt --ignored --exclude=*"
1893 esac
1895 __git_complete_index_file "$complete_opt"
1898 __git_config_get_set_variables ()
1900 local prevword word config_file= c=$cword
1901 while [ $c -gt 1 ]; do
1902 word="${words[c]}"
1903 case "$word" in
1904 --system|--global|--local|--file=*)
1905 config_file="$word"
1906 break
1908 -f|--file)
1909 config_file="$word $prevword"
1910 break
1912 esac
1913 prevword=$word
1914 c=$((--c))
1915 done
1917 git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null
1920 _git_config ()
1922 case "$prev" in
1923 branch.*.remote|branch.*.pushremote)
1924 __gitcomp_nl "$(__git_remotes)"
1925 return
1927 branch.*.merge)
1928 __gitcomp_nl "$(__git_refs)"
1929 return
1931 branch.*.rebase)
1932 __gitcomp "false true preserve interactive"
1933 return
1935 remote.pushdefault)
1936 __gitcomp_nl "$(__git_remotes)"
1937 return
1939 remote.*.fetch)
1940 local remote="${prev#remote.}"
1941 remote="${remote%.fetch}"
1942 if [ -z "$cur" ]; then
1943 __gitcomp_nl "refs/heads/" "" "" ""
1944 return
1946 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1947 return
1949 remote.*.push)
1950 local remote="${prev#remote.}"
1951 remote="${remote%.push}"
1952 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1953 for-each-ref --format='%(refname):%(refname)' \
1954 refs/heads)"
1955 return
1957 pull.twohead|pull.octopus)
1958 __git_compute_merge_strategies
1959 __gitcomp "$__git_merge_strategies"
1960 return
1962 color.branch|color.diff|color.interactive|\
1963 color.showbranch|color.status|color.ui)
1964 __gitcomp "always never auto"
1965 return
1967 color.pager)
1968 __gitcomp "false true"
1969 return
1971 color.*.*)
1972 __gitcomp "
1973 normal black red green yellow blue magenta cyan white
1974 bold dim ul blink reverse
1976 return
1978 diff.submodule)
1979 __gitcomp "log short"
1980 return
1982 help.format)
1983 __gitcomp "man info web html"
1984 return
1986 log.date)
1987 __gitcomp "$__git_log_date_formats"
1988 return
1990 sendemail.aliasesfiletype)
1991 __gitcomp "mutt mailrc pine elm gnus"
1992 return
1994 sendemail.confirm)
1995 __gitcomp "$__git_send_email_confirm_options"
1996 return
1998 sendemail.suppresscc)
1999 __gitcomp "$__git_send_email_suppresscc_options"
2000 return
2002 sendemail.transferencoding)
2003 __gitcomp "7bit 8bit quoted-printable base64"
2004 return
2006 --get|--get-all|--unset|--unset-all)
2007 __gitcomp_nl "$(__git_config_get_set_variables)"
2008 return
2010 *.*)
2011 return
2013 esac
2014 case "$cur" in
2015 --*)
2016 __gitcomp "
2017 --system --global --local --file=
2018 --list --replace-all
2019 --get --get-all --get-regexp
2020 --add --unset --unset-all
2021 --remove-section --rename-section
2022 --name-only
2024 return
2026 branch.*.*)
2027 local pfx="${cur%.*}." cur_="${cur##*.}"
2028 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2029 return
2031 branch.*)
2032 local pfx="${cur%.*}." cur_="${cur#*.}"
2033 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
2034 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2035 return
2037 guitool.*.*)
2038 local pfx="${cur%.*}." cur_="${cur##*.}"
2039 __gitcomp "
2040 argprompt cmd confirm needsfile noconsole norescan
2041 prompt revprompt revunmerged title
2042 " "$pfx" "$cur_"
2043 return
2045 difftool.*.*)
2046 local pfx="${cur%.*}." cur_="${cur##*.}"
2047 __gitcomp "cmd path" "$pfx" "$cur_"
2048 return
2050 man.*.*)
2051 local pfx="${cur%.*}." cur_="${cur##*.}"
2052 __gitcomp "cmd path" "$pfx" "$cur_"
2053 return
2055 mergetool.*.*)
2056 local pfx="${cur%.*}." cur_="${cur##*.}"
2057 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2058 return
2060 pager.*)
2061 local pfx="${cur%.*}." cur_="${cur#*.}"
2062 __git_compute_all_commands
2063 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2064 return
2066 remote.*.*)
2067 local pfx="${cur%.*}." cur_="${cur##*.}"
2068 __gitcomp "
2069 url proxy fetch push mirror skipDefaultUpdate
2070 receivepack uploadpack tagopt pushurl
2071 " "$pfx" "$cur_"
2072 return
2074 remote.*)
2075 local pfx="${cur%.*}." cur_="${cur#*.}"
2076 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2077 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2078 return
2080 url.*.*)
2081 local pfx="${cur%.*}." cur_="${cur##*.}"
2082 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2083 return
2085 esac
2086 __gitcomp "
2087 add.ignoreErrors
2088 advice.commitBeforeMerge
2089 advice.detachedHead
2090 advice.implicitIdentity
2091 advice.pushNonFastForward
2092 advice.resolveConflict
2093 advice.statusHints
2094 alias.
2095 am.keepcr
2096 apply.ignorewhitespace
2097 apply.whitespace
2098 branch.autosetupmerge
2099 branch.autosetuprebase
2100 browser.
2101 clean.requireForce
2102 color.branch
2103 color.branch.current
2104 color.branch.local
2105 color.branch.plain
2106 color.branch.remote
2107 color.decorate.HEAD
2108 color.decorate.branch
2109 color.decorate.remoteBranch
2110 color.decorate.stash
2111 color.decorate.tag
2112 color.diff
2113 color.diff.commit
2114 color.diff.frag
2115 color.diff.func
2116 color.diff.meta
2117 color.diff.new
2118 color.diff.old
2119 color.diff.plain
2120 color.diff.whitespace
2121 color.grep
2122 color.grep.context
2123 color.grep.filename
2124 color.grep.function
2125 color.grep.linenumber
2126 color.grep.match
2127 color.grep.selected
2128 color.grep.separator
2129 color.interactive
2130 color.interactive.error
2131 color.interactive.header
2132 color.interactive.help
2133 color.interactive.prompt
2134 color.pager
2135 color.showbranch
2136 color.status
2137 color.status.added
2138 color.status.changed
2139 color.status.header
2140 color.status.nobranch
2141 color.status.unmerged
2142 color.status.untracked
2143 color.status.updated
2144 color.ui
2145 commit.status
2146 commit.template
2147 core.abbrev
2148 core.askpass
2149 core.attributesfile
2150 core.autocrlf
2151 core.bare
2152 core.bigFileThreshold
2153 core.compression
2154 core.createObject
2155 core.deltaBaseCacheLimit
2156 core.editor
2157 core.eol
2158 core.excludesfile
2159 core.fileMode
2160 core.fsyncobjectfiles
2161 core.gitProxy
2162 core.ignoreStat
2163 core.ignorecase
2164 core.logAllRefUpdates
2165 core.loosecompression
2166 core.notesRef
2167 core.packedGitLimit
2168 core.packedGitWindowSize
2169 core.pager
2170 core.preferSymlinkRefs
2171 core.preloadindex
2172 core.quotepath
2173 core.repositoryFormatVersion
2174 core.safecrlf
2175 core.sharedRepository
2176 core.sparseCheckout
2177 core.symlinks
2178 core.trustctime
2179 core.untrackedCache
2180 core.warnAmbiguousRefs
2181 core.whitespace
2182 core.worktree
2183 diff.autorefreshindex
2184 diff.external
2185 diff.ignoreSubmodules
2186 diff.mnemonicprefix
2187 diff.noprefix
2188 diff.renameLimit
2189 diff.renames
2190 diff.statGraphWidth
2191 diff.submodule
2192 diff.suppressBlankEmpty
2193 diff.tool
2194 diff.wordRegex
2195 diff.algorithm
2196 difftool.
2197 difftool.prompt
2198 fetch.recurseSubmodules
2199 fetch.unpackLimit
2200 format.attach
2201 format.cc
2202 format.coverLetter
2203 format.from
2204 format.headers
2205 format.numbered
2206 format.pretty
2207 format.signature
2208 format.signoff
2209 format.subjectprefix
2210 format.suffix
2211 format.thread
2212 format.to
2214 gc.aggressiveWindow
2215 gc.auto
2216 gc.autopacklimit
2217 gc.packrefs
2218 gc.pruneexpire
2219 gc.reflogexpire
2220 gc.reflogexpireunreachable
2221 gc.rerereresolved
2222 gc.rerereunresolved
2223 gitcvs.allbinary
2224 gitcvs.commitmsgannotation
2225 gitcvs.dbTableNamePrefix
2226 gitcvs.dbdriver
2227 gitcvs.dbname
2228 gitcvs.dbpass
2229 gitcvs.dbuser
2230 gitcvs.enabled
2231 gitcvs.logfile
2232 gitcvs.usecrlfattr
2233 guitool.
2234 gui.blamehistoryctx
2235 gui.commitmsgwidth
2236 gui.copyblamethreshold
2237 gui.diffcontext
2238 gui.encoding
2239 gui.fastcopyblame
2240 gui.matchtrackingbranch
2241 gui.newbranchtemplate
2242 gui.pruneduringfetch
2243 gui.spellingdictionary
2244 gui.trustmtime
2245 help.autocorrect
2246 help.browser
2247 help.format
2248 http.lowSpeedLimit
2249 http.lowSpeedTime
2250 http.maxRequests
2251 http.minSessions
2252 http.noEPSV
2253 http.postBuffer
2254 http.proxy
2255 http.sslCipherList
2256 http.sslVersion
2257 http.sslCAInfo
2258 http.sslCAPath
2259 http.sslCert
2260 http.sslCertPasswordProtected
2261 http.sslKey
2262 http.sslVerify
2263 http.useragent
2264 i18n.commitEncoding
2265 i18n.logOutputEncoding
2266 imap.authMethod
2267 imap.folder
2268 imap.host
2269 imap.pass
2270 imap.port
2271 imap.preformattedHTML
2272 imap.sslverify
2273 imap.tunnel
2274 imap.user
2275 init.templatedir
2276 instaweb.browser
2277 instaweb.httpd
2278 instaweb.local
2279 instaweb.modulepath
2280 instaweb.port
2281 interactive.singlekey
2282 log.date
2283 log.decorate
2284 log.showroot
2285 mailmap.file
2286 man.
2287 man.viewer
2288 merge.
2289 merge.conflictstyle
2290 merge.log
2291 merge.renameLimit
2292 merge.renormalize
2293 merge.stat
2294 merge.tool
2295 merge.verbosity
2296 mergetool.
2297 mergetool.keepBackup
2298 mergetool.keepTemporaries
2299 mergetool.prompt
2300 notes.displayRef
2301 notes.rewrite.
2302 notes.rewrite.amend
2303 notes.rewrite.rebase
2304 notes.rewriteMode
2305 notes.rewriteRef
2306 pack.compression
2307 pack.deltaCacheLimit
2308 pack.deltaCacheSize
2309 pack.depth
2310 pack.indexVersion
2311 pack.packSizeLimit
2312 pack.threads
2313 pack.window
2314 pack.windowMemory
2315 pager.
2316 pretty.
2317 pull.octopus
2318 pull.twohead
2319 push.default
2320 push.followTags
2321 rebase.autosquash
2322 rebase.stat
2323 receive.autogc
2324 receive.denyCurrentBranch
2325 receive.denyDeleteCurrent
2326 receive.denyDeletes
2327 receive.denyNonFastForwards
2328 receive.fsckObjects
2329 receive.unpackLimit
2330 receive.updateserverinfo
2331 remote.pushdefault
2332 remotes.
2333 repack.usedeltabaseoffset
2334 rerere.autoupdate
2335 rerere.enabled
2336 sendemail.
2337 sendemail.aliasesfile
2338 sendemail.aliasfiletype
2339 sendemail.bcc
2340 sendemail.cc
2341 sendemail.cccmd
2342 sendemail.chainreplyto
2343 sendemail.confirm
2344 sendemail.envelopesender
2345 sendemail.from
2346 sendemail.identity
2347 sendemail.multiedit
2348 sendemail.signedoffbycc
2349 sendemail.smtpdomain
2350 sendemail.smtpencryption
2351 sendemail.smtppass
2352 sendemail.smtpserver
2353 sendemail.smtpserveroption
2354 sendemail.smtpserverport
2355 sendemail.smtpuser
2356 sendemail.suppresscc
2357 sendemail.suppressfrom
2358 sendemail.thread
2359 sendemail.to
2360 sendemail.validate
2361 showbranch.default
2362 status.relativePaths
2363 status.showUntrackedFiles
2364 status.submodulesummary
2365 submodule.
2366 tar.umask
2367 transfer.unpackLimit
2368 url.
2369 user.email
2370 user.name
2371 user.signingkey
2372 web.browser
2373 branch. remote.
2377 _git_remote ()
2379 local subcommands="add rename remove set-head set-branches set-url show prune update"
2380 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2381 if [ -z "$subcommand" ]; then
2382 __gitcomp "$subcommands"
2383 return
2386 case "$subcommand" in
2387 rename|remove|set-url|show|prune)
2388 __gitcomp_nl "$(__git_remotes)"
2390 set-head|set-branches)
2391 __git_complete_remote_or_refspec
2393 update)
2394 __gitcomp "$(__git_get_config_variables "remotes")"
2398 esac
2401 _git_replace ()
2403 __gitcomp_nl "$(__git_refs)"
2406 _git_reset ()
2408 __git_has_doubledash && return
2410 case "$cur" in
2411 --*)
2412 __gitcomp "--merge --mixed --hard --soft --patch"
2413 return
2415 esac
2416 __gitcomp_nl "$(__git_refs)"
2419 _git_revert ()
2421 local dir="$(__gitdir)"
2422 if [ -f "$dir"/REVERT_HEAD ]; then
2423 __gitcomp "--continue --quit --abort"
2424 return
2426 case "$cur" in
2427 --*)
2428 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2429 return
2431 esac
2432 __gitcomp_nl "$(__git_refs)"
2435 _git_rm ()
2437 case "$cur" in
2438 --*)
2439 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2440 return
2442 esac
2444 __git_complete_index_file "--cached"
2447 _git_shortlog ()
2449 __git_has_doubledash && return
2451 case "$cur" in
2452 --*)
2453 __gitcomp "
2454 $__git_log_common_options
2455 $__git_log_shortlog_options
2456 --numbered --summary
2458 return
2460 esac
2461 __git_complete_revlist
2464 _git_show ()
2466 __git_has_doubledash && return
2468 case "$cur" in
2469 --pretty=*|--format=*)
2470 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2471 " "" "${cur#*=}"
2472 return
2474 --diff-algorithm=*)
2475 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2476 return
2478 --submodule=*)
2479 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2480 return
2482 --*)
2483 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2484 --show-signature
2485 $__git_diff_common_options
2487 return
2489 esac
2490 __git_complete_revlist_file
2493 _git_show_branch ()
2495 case "$cur" in
2496 --*)
2497 __gitcomp "
2498 --all --remotes --topo-order --date-order --current --more=
2499 --list --independent --merge-base --no-name
2500 --color --no-color
2501 --sha1-name --sparse --topics --reflog
2503 return
2505 esac
2506 __git_complete_revlist
2509 _git_stash ()
2511 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2512 local subcommands='save list show apply clear drop pop create branch'
2513 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2514 if [ -z "$subcommand" ]; then
2515 case "$cur" in
2516 --*)
2517 __gitcomp "$save_opts"
2520 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2521 __gitcomp "$subcommands"
2524 esac
2525 else
2526 case "$subcommand,$cur" in
2527 save,--*)
2528 __gitcomp "$save_opts"
2530 apply,--*|pop,--*)
2531 __gitcomp "--index --quiet"
2533 drop,--*)
2534 __gitcomp "--quiet"
2536 show,--*|branch,--*)
2538 branch,*)
2539 if [ $cword -eq 3 ]; then
2540 __gitcomp_nl "$(__git_refs)";
2541 else
2542 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2543 | sed -n -e 's/:.*//p')"
2546 show,*|apply,*|drop,*|pop,*)
2547 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2548 | sed -n -e 's/:.*//p')"
2552 esac
2556 _git_submodule ()
2558 __git_has_doubledash && return
2560 local subcommands="add status init deinit update summary foreach sync"
2561 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2562 case "$cur" in
2563 --*)
2564 __gitcomp "--quiet --cached"
2567 __gitcomp "$subcommands"
2569 esac
2570 return
2574 _git_svn ()
2576 local subcommands="
2577 init fetch clone rebase dcommit log find-rev
2578 set-tree commit-diff info create-ignore propget
2579 proplist show-ignore show-externals branch tag blame
2580 migrate mkdirs reset gc
2582 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2583 if [ -z "$subcommand" ]; then
2584 __gitcomp "$subcommands"
2585 else
2586 local remote_opts="--username= --config-dir= --no-auth-cache"
2587 local fc_opts="
2588 --follow-parent --authors-file= --repack=
2589 --no-metadata --use-svm-props --use-svnsync-props
2590 --log-window-size= --no-checkout --quiet
2591 --repack-flags --use-log-author --localtime
2592 --ignore-paths= --include-paths= $remote_opts
2594 local init_opts="
2595 --template= --shared= --trunk= --tags=
2596 --branches= --stdlayout --minimize-url
2597 --no-metadata --use-svm-props --use-svnsync-props
2598 --rewrite-root= --prefix= --use-log-author
2599 --add-author-from $remote_opts
2601 local cmt_opts="
2602 --edit --rmdir --find-copies-harder --copy-similarity=
2605 case "$subcommand,$cur" in
2606 fetch,--*)
2607 __gitcomp "--revision= --fetch-all $fc_opts"
2609 clone,--*)
2610 __gitcomp "--revision= $fc_opts $init_opts"
2612 init,--*)
2613 __gitcomp "$init_opts"
2615 dcommit,--*)
2616 __gitcomp "
2617 --merge --strategy= --verbose --dry-run
2618 --fetch-all --no-rebase --commit-url
2619 --revision --interactive $cmt_opts $fc_opts
2622 set-tree,--*)
2623 __gitcomp "--stdin $cmt_opts $fc_opts"
2625 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2626 show-externals,--*|mkdirs,--*)
2627 __gitcomp "--revision="
2629 log,--*)
2630 __gitcomp "
2631 --limit= --revision= --verbose --incremental
2632 --oneline --show-commit --non-recursive
2633 --authors-file= --color
2636 rebase,--*)
2637 __gitcomp "
2638 --merge --verbose --strategy= --local
2639 --fetch-all --dry-run $fc_opts
2642 commit-diff,--*)
2643 __gitcomp "--message= --file= --revision= $cmt_opts"
2645 info,--*)
2646 __gitcomp "--url"
2648 branch,--*)
2649 __gitcomp "--dry-run --message --tag"
2651 tag,--*)
2652 __gitcomp "--dry-run --message"
2654 blame,--*)
2655 __gitcomp "--git-format"
2657 migrate,--*)
2658 __gitcomp "
2659 --config-dir= --ignore-paths= --minimize
2660 --no-auth-cache --username=
2663 reset,--*)
2664 __gitcomp "--revision= --parent"
2668 esac
2672 _git_tag ()
2674 local i c=1 f=0
2675 while [ $c -lt $cword ]; do
2676 i="${words[c]}"
2677 case "$i" in
2678 -d|-v)
2679 __gitcomp_nl "$(__git_tags)"
2680 return
2685 esac
2686 ((c++))
2687 done
2689 case "$prev" in
2690 -m|-F)
2692 -*|tag)
2693 if [ $f = 1 ]; then
2694 __gitcomp_nl "$(__git_tags)"
2698 __gitcomp_nl "$(__git_refs)"
2700 esac
2702 case "$cur" in
2703 --*)
2704 __gitcomp "
2705 --list --delete --verify --annotate --message --file
2706 --sign --cleanup --local-user --force --column --sort
2707 --contains --points-at
2710 esac
2713 _git_whatchanged ()
2715 _git_log
2718 _git_worktree ()
2720 local subcommands="add list lock prune unlock"
2721 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2722 if [ -z "$subcommand" ]; then
2723 __gitcomp "$subcommands"
2724 else
2725 case "$subcommand,$cur" in
2726 add,--*)
2727 __gitcomp "--detach"
2729 list,--*)
2730 __gitcomp "--porcelain"
2732 lock,--*)
2733 __gitcomp "--reason"
2735 prune,--*)
2736 __gitcomp "--dry-run --expire --verbose"
2740 esac
2744 __git_main ()
2746 local i c=1 command __git_dir
2748 while [ $c -lt $cword ]; do
2749 i="${words[c]}"
2750 case "$i" in
2751 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2752 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2753 --bare) __git_dir="." ;;
2754 --help) command="help"; break ;;
2755 -c|--work-tree|--namespace) ((c++)) ;;
2756 -*) ;;
2757 *) command="$i"; break ;;
2758 esac
2759 ((c++))
2760 done
2762 if [ -z "$command" ]; then
2763 case "$cur" in
2764 --*) __gitcomp "
2765 --paginate
2766 --no-pager
2767 --git-dir=
2768 --bare
2769 --version
2770 --exec-path
2771 --exec-path=
2772 --html-path
2773 --man-path
2774 --info-path
2775 --work-tree=
2776 --namespace=
2777 --no-replace-objects
2778 --help
2781 *) __git_compute_porcelain_commands
2782 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2783 esac
2784 return
2787 local completion_func="_git_${command//-/_}"
2788 declare -f $completion_func >/dev/null && $completion_func && return
2790 local expansion=$(__git_aliased_command "$command")
2791 if [ -n "$expansion" ]; then
2792 words[1]=$expansion
2793 completion_func="_git_${expansion//-/_}"
2794 declare -f $completion_func >/dev/null && $completion_func
2798 __gitk_main ()
2800 __git_has_doubledash && return
2802 local g="$(__gitdir)"
2803 local merge=""
2804 if [ -f "$g/MERGE_HEAD" ]; then
2805 merge="--merge"
2807 case "$cur" in
2808 --*)
2809 __gitcomp "
2810 $__git_log_common_options
2811 $__git_log_gitk_options
2812 $merge
2814 return
2816 esac
2817 __git_complete_revlist
2820 if [[ -n ${ZSH_VERSION-} ]]; then
2821 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2823 autoload -U +X compinit && compinit
2825 __gitcomp ()
2827 emulate -L zsh
2829 local cur_="${3-$cur}"
2831 case "$cur_" in
2832 --*=)
2835 local c IFS=$' \t\n'
2836 local -a array
2837 for c in ${=1}; do
2838 c="$c${4-}"
2839 case $c in
2840 --*=*|*.) ;;
2841 *) c="$c " ;;
2842 esac
2843 array[${#array[@]}+1]="$c"
2844 done
2845 compset -P '*[=:]'
2846 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2848 esac
2851 __gitcomp_nl ()
2853 emulate -L zsh
2855 local IFS=$'\n'
2856 compset -P '*[=:]'
2857 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2860 __gitcomp_file ()
2862 emulate -L zsh
2864 local IFS=$'\n'
2865 compset -P '*[=:]'
2866 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2869 _git ()
2871 local _ret=1 cur cword prev
2872 cur=${words[CURRENT]}
2873 prev=${words[CURRENT-1]}
2874 let cword=CURRENT-1
2875 emulate ksh -c __${service}_main
2876 let _ret && _default && _ret=0
2877 return _ret
2880 compdef _git git gitk
2881 return
2884 __git_func_wrap ()
2886 local cur words cword prev
2887 _get_comp_words_by_ref -n =: cur words cword prev
2891 # Setup completion for certain functions defined above by setting common
2892 # variables and workarounds.
2893 # This is NOT a public function; use at your own risk.
2894 __git_complete ()
2896 local wrapper="__git_wrap${2}"
2897 eval "$wrapper () { __git_func_wrap $2 ; }"
2898 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2899 || complete -o default -o nospace -F $wrapper $1
2902 # wrapper for backwards compatibility
2903 _git ()
2905 __git_wrap__git_main
2908 # wrapper for backwards compatibility
2909 _gitk ()
2911 __git_wrap__gitk_main
2914 __git_complete git __git_main
2915 __git_complete gitk __gitk_main
2917 # The following are necessary only for Cygwin, and only are needed
2918 # when the user has tab-completed the executable name and consequently
2919 # included the '.exe' suffix.
2921 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2922 __git_complete git.exe __git_main