completion: complete format.coverLetter
[git.git] / contrib / completion / git-completion.bash
blob39b81f7a685beccd0b291a2deb50a7fb0285e953
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 # *) tree paths within 'ref:path/to/file' expressions
14 # *) file paths within current working directory and index
15 # *) common --long-options
17 # To use these routines:
19 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
20 # 2) Add the following line to your .bashrc/.zshrc:
21 # source ~/.git-completion.sh
22 # 3) Consider changing your PS1 to also show the current branch,
23 # see git-prompt.sh for details.
25 case "$COMP_WORDBREAKS" in
26 *:*) : great ;;
27 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
28 esac
30 # __gitdir accepts 0 or 1 arguments (i.e., location)
31 # returns location of .git repo
32 __gitdir ()
34 if [ -z "${1-}" ]; then
35 if [ -n "${__git_dir-}" ]; then
36 echo "$__git_dir"
37 elif [ -n "${GIT_DIR-}" ]; then
38 test -d "${GIT_DIR-}" || return 1
39 echo "$GIT_DIR"
40 elif [ -d .git ]; then
41 echo .git
42 else
43 git rev-parse --git-dir 2>/dev/null
45 elif [ -d "$1/.git" ]; then
46 echo "$1/.git"
47 else
48 echo "$1"
52 # The following function is based on code from:
54 # bash_completion - programmable completion functions for bash 3.2+
56 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
57 # © 2009-2010, Bash Completion Maintainers
58 # <bash-completion-devel@lists.alioth.debian.org>
60 # This program is free software; you can redistribute it and/or modify
61 # it under the terms of the GNU General Public License as published by
62 # the Free Software Foundation; either version 2, or (at your option)
63 # any later version.
65 # This program is distributed in the hope that it will be useful,
66 # but WITHOUT ANY WARRANTY; without even the implied warranty of
67 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68 # GNU General Public License for more details.
70 # You should have received a copy of the GNU General Public License
71 # along with this program; if not, write to the Free Software Foundation,
72 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
74 # The latest version of this software can be obtained here:
76 # http://bash-completion.alioth.debian.org/
78 # RELEASE: 2.x
80 # This function can be used to access a tokenized list of words
81 # on the command line:
83 # __git_reassemble_comp_words_by_ref '=:'
84 # if test "${words_[cword_-1]}" = -w
85 # then
86 # ...
87 # fi
89 # The argument should be a collection of characters from the list of
90 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
91 # characters.
93 # This is roughly equivalent to going back in time and setting
94 # COMP_WORDBREAKS to exclude those characters. The intent is to
95 # make option types like --date=<type> and <rev>:<path> easy to
96 # recognize by treating each shell word as a single token.
98 # It is best not to set COMP_WORDBREAKS directly because the value is
99 # shared with other completion scripts. By the time the completion
100 # function gets called, COMP_WORDS has already been populated so local
101 # changes to COMP_WORDBREAKS have no effect.
103 # Output: words_, cword_, cur_.
105 __git_reassemble_comp_words_by_ref()
107 local exclude i j first
108 # Which word separators to exclude?
109 exclude="${1//[^$COMP_WORDBREAKS]}"
110 cword_=$COMP_CWORD
111 if [ -z "$exclude" ]; then
112 words_=("${COMP_WORDS[@]}")
113 return
115 # List of word completion separators has shrunk;
116 # re-assemble words to complete.
117 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
118 # Append each nonempty word consisting of just
119 # word separator characters to the current word.
120 first=t
121 while
122 [ $i -gt 0 ] &&
123 [ -n "${COMP_WORDS[$i]}" ] &&
124 # word consists of excluded word separators
125 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
127 # Attach to the previous token,
128 # unless the previous token is the command name.
129 if [ $j -ge 2 ] && [ -n "$first" ]; then
130 ((j--))
132 first=
133 words_[$j]=${words_[j]}${COMP_WORDS[i]}
134 if [ $i = $COMP_CWORD ]; then
135 cword_=$j
137 if (($i < ${#COMP_WORDS[@]} - 1)); then
138 ((i++))
139 else
140 # Done.
141 return
143 done
144 words_[$j]=${words_[j]}${COMP_WORDS[i]}
145 if [ $i = $COMP_CWORD ]; then
146 cword_=$j
148 done
151 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
152 _get_comp_words_by_ref ()
154 local exclude cur_ words_ cword_
155 if [ "$1" = "-n" ]; then
156 exclude=$2
157 shift 2
159 __git_reassemble_comp_words_by_ref "$exclude"
160 cur_=${words_[cword_]}
161 while [ $# -gt 0 ]; do
162 case "$1" in
163 cur)
164 cur=$cur_
166 prev)
167 prev=${words_[$cword_-1]}
169 words)
170 words=("${words_[@]}")
172 cword)
173 cword=$cword_
175 esac
176 shift
177 done
181 __gitcompadd ()
183 local i=0
184 for x in $1; do
185 if [[ "$x" == "$3"* ]]; then
186 COMPREPLY[i++]="$2$x$4"
188 done
191 # Generates completion reply, appending a space to possible completion words,
192 # if necessary.
193 # It accepts 1 to 4 arguments:
194 # 1: List of possible completion words.
195 # 2: A prefix to be added to each possible completion word (optional).
196 # 3: Generate possible completion matches for this word (optional).
197 # 4: A suffix to be appended to each possible completion word (optional).
198 __gitcomp ()
200 local cur_="${3-$cur}"
202 case "$cur_" in
203 --*=)
206 local c i=0 IFS=$' \t\n'
207 for c in $1; do
208 c="$c${4-}"
209 if [[ $c == "$cur_"* ]]; then
210 case $c in
211 --*=*|*.) ;;
212 *) c="$c " ;;
213 esac
214 COMPREPLY[i++]="${2-}$c"
216 done
218 esac
221 # Generates completion reply from newline-separated possible completion words
222 # by appending a space to all of them.
223 # It accepts 1 to 4 arguments:
224 # 1: List of possible completion words, separated by a single newline.
225 # 2: A prefix to be added to each possible completion word (optional).
226 # 3: Generate possible completion matches for this word (optional).
227 # 4: A suffix to be appended to each possible completion word instead of
228 # the default space (optional). If specified but empty, nothing is
229 # appended.
230 __gitcomp_nl ()
232 local IFS=$'\n'
233 __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
236 # Generates completion reply with compgen from newline-separated possible
237 # completion filenames.
238 # It accepts 1 to 3 arguments:
239 # 1: List of possible completion filenames, separated by a single newline.
240 # 2: A directory prefix to be added to each possible completion filename
241 # (optional).
242 # 3: Generate possible completion matches for this word (optional).
243 __gitcomp_file ()
245 local IFS=$'\n'
247 # XXX does not work when the directory prefix contains a tilde,
248 # since tilde expansion is not applied.
249 # This means that COMPREPLY will be empty and Bash default
250 # completion will be used.
251 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
253 # use a hack to enable file mode in bash < 4
254 compopt -o filenames +o nospace 2>/dev/null ||
255 compgen -f /non-existing-dir/ > /dev/null
258 # Execute 'git ls-files', unless the --committable option is specified, in
259 # which case it runs 'git diff-index' to find out the files that can be
260 # committed. It return paths relative to the directory specified in the first
261 # argument, and using the options specified in the second argument.
262 __git_ls_files_helper ()
265 test -n "${CDPATH+set}" && unset CDPATH
266 cd "$1"
267 if [ "$2" == "--committable" ]; then
268 git diff-index --name-only --relative HEAD
269 else
270 # NOTE: $2 is not quoted in order to support multiple options
271 git ls-files --exclude-standard $2
273 ) 2>/dev/null
277 # __git_index_files accepts 1 or 2 arguments:
278 # 1: Options to pass to ls-files (required).
279 # 2: A directory path (optional).
280 # If provided, only files within the specified directory are listed.
281 # Sub directories are never recursed. Path must have a trailing
282 # slash.
283 __git_index_files ()
285 local dir="$(__gitdir)" root="${2-.}" file
287 if [ -d "$dir" ]; then
288 __git_ls_files_helper "$root" "$1" |
289 while read -r file; do
290 case "$file" in
291 ?*/*) echo "${file%%/*}" ;;
292 *) echo "$file" ;;
293 esac
294 done | sort | uniq
298 __git_heads ()
300 local dir="$(__gitdir)"
301 if [ -d "$dir" ]; then
302 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
303 refs/heads
304 return
308 __git_tags ()
310 local dir="$(__gitdir)"
311 if [ -d "$dir" ]; then
312 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
313 refs/tags
314 return
318 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
319 # presence of 2nd argument means use the guess heuristic employed
320 # by checkout for tracking branches
321 __git_refs ()
323 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
324 local format refs
325 if [ -d "$dir" ]; then
326 case "$cur" in
327 refs|refs/*)
328 format="refname"
329 refs="${cur%/*}"
330 track=""
333 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
334 if [ -e "$dir/$i" ]; then echo $i; fi
335 done
336 format="refname:short"
337 refs="refs/tags refs/heads refs/remotes"
339 esac
340 git --git-dir="$dir" for-each-ref --format="%($format)" \
341 $refs
342 if [ -n "$track" ]; then
343 # employ the heuristic used by git checkout
344 # Try to find a remote branch that matches the completion word
345 # but only output if the branch name is unique
346 local ref entry
347 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
348 "refs/remotes/" | \
349 while read -r entry; do
350 eval "$entry"
351 ref="${ref#*/}"
352 if [[ "$ref" == "$cur"* ]]; then
353 echo "$ref"
355 done | sort | uniq -u
357 return
359 case "$cur" in
360 refs|refs/*)
361 git ls-remote "$dir" "$cur*" 2>/dev/null | \
362 while read -r hash i; do
363 case "$i" in
364 *^{}) ;;
365 *) echo "$i" ;;
366 esac
367 done
370 echo "HEAD"
371 git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
373 esac
376 # __git_refs2 requires 1 argument (to pass to __git_refs)
377 __git_refs2 ()
379 local i
380 for i in $(__git_refs "$1"); do
381 echo "$i:$i"
382 done
385 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
386 __git_refs_remotes ()
388 local i hash
389 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
390 while read -r hash i; do
391 echo "$i:refs/remotes/$1/${i#refs/heads/}"
392 done
395 __git_remotes ()
397 local i IFS=$'\n' d="$(__gitdir)"
398 test -d "$d/remotes" && ls -1 "$d/remotes"
399 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
400 i="${i#remote.}"
401 echo "${i/.url*/}"
402 done
405 __git_list_merge_strategies ()
407 git merge -s help 2>&1 |
408 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
409 s/\.$//
410 s/.*://
411 s/^[ ]*//
412 s/[ ]*$//
417 __git_merge_strategies=
418 # 'git merge -s help' (and thus detection of the merge strategy
419 # list) fails, unfortunately, if run outside of any git working
420 # tree. __git_merge_strategies is set to the empty string in
421 # that case, and the detection will be repeated the next time it
422 # is needed.
423 __git_compute_merge_strategies ()
425 test -n "$__git_merge_strategies" ||
426 __git_merge_strategies=$(__git_list_merge_strategies)
429 __git_complete_revlist_file ()
431 local pfx ls ref cur_="$cur"
432 case "$cur_" in
433 *..?*:*)
434 return
436 ?*:*)
437 ref="${cur_%%:*}"
438 cur_="${cur_#*:}"
439 case "$cur_" in
440 ?*/*)
441 pfx="${cur_%/*}"
442 cur_="${cur_##*/}"
443 ls="$ref:$pfx"
444 pfx="$pfx/"
447 ls="$ref"
449 esac
451 case "$COMP_WORDBREAKS" in
452 *:*) : great ;;
453 *) pfx="$ref:$pfx" ;;
454 esac
456 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
457 | sed '/^100... blob /{
458 s,^.* ,,
459 s,$, ,
461 /^120000 blob /{
462 s,^.* ,,
463 s,$, ,
465 /^040000 tree /{
466 s,^.* ,,
467 s,$,/,
469 s/^.* //')" \
470 "$pfx" "$cur_" ""
472 *...*)
473 pfx="${cur_%...*}..."
474 cur_="${cur_#*...}"
475 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
477 *..*)
478 pfx="${cur_%..*}.."
479 cur_="${cur_#*..}"
480 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
483 __gitcomp_nl "$(__git_refs)"
485 esac
489 # __git_complete_index_file requires 1 argument:
490 # 1: the options to pass to ls-file
492 # The exception is --committable, which finds the files appropriate commit.
493 __git_complete_index_file ()
495 local pfx="" cur_="$cur"
497 case "$cur_" in
498 ?*/*)
499 pfx="${cur_%/*}"
500 cur_="${cur_##*/}"
501 pfx="${pfx}/"
503 esac
505 __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
508 __git_complete_file ()
510 __git_complete_revlist_file
513 __git_complete_revlist ()
515 __git_complete_revlist_file
518 __git_complete_remote_or_refspec ()
520 local cur_="$cur" cmd="${words[1]}"
521 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
522 if [ "$cmd" = "remote" ]; then
523 ((c++))
525 while [ $c -lt $cword ]; do
526 i="${words[c]}"
527 case "$i" in
528 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
529 --all)
530 case "$cmd" in
531 push) no_complete_refspec=1 ;;
532 fetch)
533 return
535 *) ;;
536 esac
538 -*) ;;
539 *) remote="$i"; break ;;
540 esac
541 ((c++))
542 done
543 if [ -z "$remote" ]; then
544 __gitcomp_nl "$(__git_remotes)"
545 return
547 if [ $no_complete_refspec = 1 ]; then
548 return
550 [ "$remote" = "." ] && remote=
551 case "$cur_" in
552 *:*)
553 case "$COMP_WORDBREAKS" in
554 *:*) : great ;;
555 *) pfx="${cur_%%:*}:" ;;
556 esac
557 cur_="${cur_#*:}"
558 lhs=0
561 pfx="+"
562 cur_="${cur_#+}"
564 esac
565 case "$cmd" in
566 fetch)
567 if [ $lhs = 1 ]; then
568 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
569 else
570 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
573 pull|remote)
574 if [ $lhs = 1 ]; then
575 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
576 else
577 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
580 push)
581 if [ $lhs = 1 ]; then
582 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
583 else
584 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
587 esac
590 __git_complete_strategy ()
592 __git_compute_merge_strategies
593 case "$prev" in
594 -s|--strategy)
595 __gitcomp "$__git_merge_strategies"
596 return 0
597 esac
598 case "$cur" in
599 --strategy=*)
600 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
601 return 0
603 esac
604 return 1
607 __git_commands () {
608 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
609 then
610 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
611 else
612 git help -a|egrep '^ [a-zA-Z0-9]'
616 __git_list_all_commands ()
618 local i IFS=" "$'\n'
619 for i in $(__git_commands)
621 case $i in
622 *--*) : helper pattern;;
623 *) echo $i;;
624 esac
625 done
628 __git_all_commands=
629 __git_compute_all_commands ()
631 test -n "$__git_all_commands" ||
632 __git_all_commands=$(__git_list_all_commands)
635 __git_list_porcelain_commands ()
637 local i IFS=" "$'\n'
638 __git_compute_all_commands
639 for i in $__git_all_commands
641 case $i in
642 *--*) : helper pattern;;
643 applymbox) : ask gittus;;
644 applypatch) : ask gittus;;
645 archimport) : import;;
646 cat-file) : plumbing;;
647 check-attr) : plumbing;;
648 check-ignore) : plumbing;;
649 check-mailmap) : plumbing;;
650 check-ref-format) : plumbing;;
651 checkout-index) : plumbing;;
652 commit-tree) : plumbing;;
653 count-objects) : infrequent;;
654 credential-cache) : credentials helper;;
655 credential-store) : credentials helper;;
656 cvsexportcommit) : export;;
657 cvsimport) : import;;
658 cvsserver) : daemon;;
659 daemon) : daemon;;
660 diff-files) : plumbing;;
661 diff-index) : plumbing;;
662 diff-tree) : plumbing;;
663 fast-import) : import;;
664 fast-export) : export;;
665 fsck-objects) : plumbing;;
666 fetch-pack) : plumbing;;
667 fmt-merge-msg) : plumbing;;
668 for-each-ref) : plumbing;;
669 hash-object) : plumbing;;
670 http-*) : transport;;
671 index-pack) : plumbing;;
672 init-db) : deprecated;;
673 local-fetch) : plumbing;;
674 ls-files) : plumbing;;
675 ls-remote) : plumbing;;
676 ls-tree) : plumbing;;
677 mailinfo) : plumbing;;
678 mailsplit) : plumbing;;
679 merge-*) : plumbing;;
680 mktree) : plumbing;;
681 mktag) : plumbing;;
682 pack-objects) : plumbing;;
683 pack-redundant) : plumbing;;
684 pack-refs) : plumbing;;
685 parse-remote) : plumbing;;
686 patch-id) : plumbing;;
687 prune) : plumbing;;
688 prune-packed) : plumbing;;
689 quiltimport) : import;;
690 read-tree) : plumbing;;
691 receive-pack) : plumbing;;
692 remote-*) : transport;;
693 rerere) : plumbing;;
694 rev-list) : plumbing;;
695 rev-parse) : plumbing;;
696 runstatus) : plumbing;;
697 sh-setup) : internal;;
698 shell) : daemon;;
699 show-ref) : plumbing;;
700 send-pack) : plumbing;;
701 show-index) : plumbing;;
702 ssh-*) : transport;;
703 stripspace) : plumbing;;
704 symbolic-ref) : plumbing;;
705 unpack-file) : plumbing;;
706 unpack-objects) : plumbing;;
707 update-index) : plumbing;;
708 update-ref) : plumbing;;
709 update-server-info) : daemon;;
710 upload-archive) : plumbing;;
711 upload-pack) : plumbing;;
712 write-tree) : plumbing;;
713 var) : infrequent;;
714 verify-pack) : infrequent;;
715 verify-tag) : plumbing;;
716 *) echo $i;;
717 esac
718 done
721 __git_porcelain_commands=
722 __git_compute_porcelain_commands ()
724 __git_compute_all_commands
725 test -n "$__git_porcelain_commands" ||
726 __git_porcelain_commands=$(__git_list_porcelain_commands)
729 __git_pretty_aliases ()
731 local i IFS=$'\n'
732 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
733 case "$i" in
734 pretty.*)
735 i="${i#pretty.}"
736 echo "${i/ */}"
738 esac
739 done
742 __git_aliases ()
744 local i IFS=$'\n'
745 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
746 case "$i" in
747 alias.*)
748 i="${i#alias.}"
749 echo "${i/ */}"
751 esac
752 done
755 # __git_aliased_command requires 1 argument
756 __git_aliased_command ()
758 local word cmdline=$(git --git-dir="$(__gitdir)" \
759 config --get "alias.$1")
760 for word in $cmdline; do
761 case "$word" in
762 \!gitk|gitk)
763 echo "gitk"
764 return
766 \!*) : shell command alias ;;
767 -*) : option ;;
768 *=*) : setting env ;;
769 git) : git itself ;;
771 echo "$word"
772 return
773 esac
774 done
777 # __git_find_on_cmdline requires 1 argument
778 __git_find_on_cmdline ()
780 local word subcommand c=1
781 while [ $c -lt $cword ]; do
782 word="${words[c]}"
783 for subcommand in $1; do
784 if [ "$subcommand" = "$word" ]; then
785 echo "$subcommand"
786 return
788 done
789 ((c++))
790 done
793 __git_has_doubledash ()
795 local c=1
796 while [ $c -lt $cword ]; do
797 if [ "--" = "${words[c]}" ]; then
798 return 0
800 ((c++))
801 done
802 return 1
805 # Try to count non option arguments passed on the command line for the
806 # specified git command.
807 # When options are used, it is necessary to use the special -- option to
808 # tell the implementation were non option arguments begin.
809 # XXX this can not be improved, since options can appear everywhere, as
810 # an example:
811 # git mv x -n y
813 # __git_count_arguments requires 1 argument: the git command executed.
814 __git_count_arguments ()
816 local word i c=0
818 # Skip "git" (first argument)
819 for ((i=1; i < ${#words[@]}; i++)); do
820 word="${words[i]}"
822 case "$word" in
824 # Good; we can assume that the following are only non
825 # option arguments.
826 ((c = 0))
828 "$1")
829 # Skip the specified git command and discard git
830 # main options
831 ((c = 0))
834 ((c++))
836 esac
837 done
839 printf "%d" $c
842 __git_whitespacelist="nowarn warn error error-all fix"
844 _git_am ()
846 local dir="$(__gitdir)"
847 if [ -d "$dir"/rebase-apply ]; then
848 __gitcomp "--skip --continue --resolved --abort"
849 return
851 case "$cur" in
852 --whitespace=*)
853 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
854 return
856 --*)
857 __gitcomp "
858 --3way --committer-date-is-author-date --ignore-date
859 --ignore-whitespace --ignore-space-change
860 --interactive --keep --no-utf8 --signoff --utf8
861 --whitespace= --scissors
863 return
864 esac
867 _git_apply ()
869 case "$cur" in
870 --whitespace=*)
871 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
872 return
874 --*)
875 __gitcomp "
876 --stat --numstat --summary --check --index
877 --cached --index-info --reverse --reject --unidiff-zero
878 --apply --no-add --exclude=
879 --ignore-whitespace --ignore-space-change
880 --whitespace= --inaccurate-eof --verbose
882 return
883 esac
886 _git_add ()
888 case "$cur" in
889 --*)
890 __gitcomp "
891 --interactive --refresh --patch --update --dry-run
892 --ignore-errors --intent-to-add
894 return
895 esac
897 # XXX should we check for --update and --all options ?
898 __git_complete_index_file "--others --modified --directory --no-empty-directory"
901 _git_archive ()
903 case "$cur" in
904 --format=*)
905 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
906 return
908 --remote=*)
909 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
910 return
912 --*)
913 __gitcomp "
914 --format= --list --verbose
915 --prefix= --remote= --exec=
917 return
919 esac
920 __git_complete_file
923 _git_bisect ()
925 __git_has_doubledash && return
927 local subcommands="start bad good skip reset visualize replay log run"
928 local subcommand="$(__git_find_on_cmdline "$subcommands")"
929 if [ -z "$subcommand" ]; then
930 if [ -f "$(__gitdir)"/BISECT_START ]; then
931 __gitcomp "$subcommands"
932 else
933 __gitcomp "replay start"
935 return
938 case "$subcommand" in
939 bad|good|reset|skip|start)
940 __gitcomp_nl "$(__git_refs)"
944 esac
947 _git_branch ()
949 local i c=1 only_local_ref="n" has_r="n"
951 while [ $c -lt $cword ]; do
952 i="${words[c]}"
953 case "$i" in
954 -d|-m) only_local_ref="y" ;;
955 -r) has_r="y" ;;
956 esac
957 ((c++))
958 done
960 case "$cur" in
961 --set-upstream-to=*)
962 __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
964 --*)
965 __gitcomp "
966 --color --no-color --verbose --abbrev= --no-abbrev
967 --track --no-track --contains --merged --no-merged
968 --set-upstream-to= --edit-description --list
969 --unset-upstream
973 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
974 __gitcomp_nl "$(__git_heads)"
975 else
976 __gitcomp_nl "$(__git_refs)"
979 esac
982 _git_bundle ()
984 local cmd="${words[2]}"
985 case "$cword" in
987 __gitcomp "create list-heads verify unbundle"
990 # looking for a file
993 case "$cmd" in
994 create)
995 __git_complete_revlist
997 esac
999 esac
1002 _git_checkout ()
1004 __git_has_doubledash && return
1006 case "$cur" in
1007 --conflict=*)
1008 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1010 --*)
1011 __gitcomp "
1012 --quiet --ours --theirs --track --no-track --merge
1013 --conflict= --orphan --patch
1017 # check if --track, --no-track, or --no-guess was specified
1018 # if so, disable DWIM mode
1019 local flags="--track --no-track --no-guess" track=1
1020 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1021 track=''
1023 __gitcomp_nl "$(__git_refs '' $track)"
1025 esac
1028 _git_cherry ()
1030 __gitcomp "$(__git_refs)"
1033 _git_cherry_pick ()
1035 local dir="$(__gitdir)"
1036 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1037 __gitcomp "--continue --quit --abort"
1038 return
1040 case "$cur" in
1041 --*)
1042 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1045 __gitcomp_nl "$(__git_refs)"
1047 esac
1050 _git_clean ()
1052 case "$cur" in
1053 --*)
1054 __gitcomp "--dry-run --quiet"
1055 return
1057 esac
1059 # XXX should we check for -x option ?
1060 __git_complete_index_file "--others --directory"
1063 _git_clone ()
1065 case "$cur" in
1066 --*)
1067 __gitcomp "
1068 --local
1069 --no-hardlinks
1070 --shared
1071 --reference
1072 --quiet
1073 --no-checkout
1074 --bare
1075 --mirror
1076 --origin
1077 --upload-pack
1078 --template=
1079 --depth
1080 --single-branch
1081 --branch
1083 return
1085 esac
1088 _git_commit ()
1090 case "$prev" in
1091 -c|-C)
1092 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1093 return
1095 esac
1097 case "$cur" in
1098 --cleanup=*)
1099 __gitcomp "default strip verbatim whitespace
1100 " "" "${cur##--cleanup=}"
1101 return
1103 --reuse-message=*|--reedit-message=*|\
1104 --fixup=*|--squash=*)
1105 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1106 return
1108 --untracked-files=*)
1109 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1110 return
1112 --*)
1113 __gitcomp "
1114 --all --author= --signoff --verify --no-verify
1115 --edit --no-edit
1116 --amend --include --only --interactive
1117 --dry-run --reuse-message= --reedit-message=
1118 --reset-author --file= --message= --template=
1119 --cleanup= --untracked-files --untracked-files=
1120 --verbose --quiet --fixup= --squash=
1122 return
1123 esac
1125 if git rev-parse --verify --quiet HEAD >/dev/null; then
1126 __git_complete_index_file "--committable"
1127 else
1128 # This is the first commit
1129 __git_complete_index_file "--cached"
1133 _git_describe ()
1135 case "$cur" in
1136 --*)
1137 __gitcomp "
1138 --all --tags --contains --abbrev= --candidates=
1139 --exact-match --debug --long --match --always
1141 return
1142 esac
1143 __gitcomp_nl "$(__git_refs)"
1146 __git_diff_algorithms="myers minimal patience histogram"
1148 __git_diff_common_options="--stat --numstat --shortstat --summary
1149 --patch-with-stat --name-only --name-status --color
1150 --no-color --color-words --no-renames --check
1151 --full-index --binary --abbrev --diff-filter=
1152 --find-copies-harder
1153 --text --ignore-space-at-eol --ignore-space-change
1154 --ignore-all-space --exit-code --quiet --ext-diff
1155 --no-ext-diff
1156 --no-prefix --src-prefix= --dst-prefix=
1157 --inter-hunk-context=
1158 --patience --histogram --minimal
1159 --raw --word-diff
1160 --dirstat --dirstat= --dirstat-by-file
1161 --dirstat-by-file= --cumulative
1162 --diff-algorithm=
1165 _git_diff ()
1167 __git_has_doubledash && return
1169 case "$cur" in
1170 --diff-algorithm=*)
1171 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1172 return
1174 --*)
1175 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1176 --base --ours --theirs --no-index
1177 $__git_diff_common_options
1179 return
1181 esac
1182 __git_complete_revlist_file
1185 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1186 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1189 _git_difftool ()
1191 __git_has_doubledash && return
1193 case "$cur" in
1194 --tool=*)
1195 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1196 return
1198 --*)
1199 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1200 --base --ours --theirs
1201 --no-renames --diff-filter= --find-copies-harder
1202 --relative --ignore-submodules
1203 --tool="
1204 return
1206 esac
1207 __git_complete_revlist_file
1210 __git_fetch_options="
1211 --quiet --verbose --append --upload-pack --force --keep --depth=
1212 --tags --no-tags --all --prune --dry-run
1215 _git_fetch ()
1217 case "$cur" in
1218 --*)
1219 __gitcomp "$__git_fetch_options"
1220 return
1222 esac
1223 __git_complete_remote_or_refspec
1226 __git_format_patch_options="
1227 --stdout --attach --no-attach --thread --thread= --no-thread
1228 --numbered --start-number --numbered-files --keep-subject --signoff
1229 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1230 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1231 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1232 --output-directory --reroll-count --to= --quiet --notes
1235 _git_format_patch ()
1237 case "$cur" in
1238 --thread=*)
1239 __gitcomp "
1240 deep shallow
1241 " "" "${cur##--thread=}"
1242 return
1244 --*)
1245 __gitcomp "$__git_format_patch_options"
1246 return
1248 esac
1249 __git_complete_revlist
1252 _git_fsck ()
1254 case "$cur" in
1255 --*)
1256 __gitcomp "
1257 --tags --root --unreachable --cache --no-reflogs --full
1258 --strict --verbose --lost-found
1260 return
1262 esac
1265 _git_gc ()
1267 case "$cur" in
1268 --*)
1269 __gitcomp "--prune --aggressive"
1270 return
1272 esac
1275 _git_gitk ()
1277 _gitk
1280 __git_match_ctag() {
1281 awk "/^${1////\\/}/ { print \$1 }" "$2"
1284 _git_grep ()
1286 __git_has_doubledash && return
1288 case "$cur" in
1289 --*)
1290 __gitcomp "
1291 --cached
1292 --text --ignore-case --word-regexp --invert-match
1293 --full-name --line-number
1294 --extended-regexp --basic-regexp --fixed-strings
1295 --perl-regexp
1296 --files-with-matches --name-only
1297 --files-without-match
1298 --max-depth
1299 --count
1300 --and --or --not --all-match
1302 return
1304 esac
1306 case "$cword,$prev" in
1307 2,*|*,-*)
1308 if test -r tags; then
1309 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1310 return
1313 esac
1315 __gitcomp_nl "$(__git_refs)"
1318 _git_help ()
1320 case "$cur" in
1321 --*)
1322 __gitcomp "--all --info --man --web"
1323 return
1325 esac
1326 __git_compute_all_commands
1327 __gitcomp "$__git_all_commands $(__git_aliases)
1328 attributes cli core-tutorial cvs-migration
1329 diffcore gitk glossary hooks ignore modules
1330 namespaces repository-layout tutorial tutorial-2
1331 workflows
1335 _git_init ()
1337 case "$cur" in
1338 --shared=*)
1339 __gitcomp "
1340 false true umask group all world everybody
1341 " "" "${cur##--shared=}"
1342 return
1344 --*)
1345 __gitcomp "--quiet --bare --template= --shared --shared="
1346 return
1348 esac
1351 _git_ls_files ()
1353 case "$cur" in
1354 --*)
1355 __gitcomp "--cached --deleted --modified --others --ignored
1356 --stage --directory --no-empty-directory --unmerged
1357 --killed --exclude= --exclude-from=
1358 --exclude-per-directory= --exclude-standard
1359 --error-unmatch --with-tree= --full-name
1360 --abbrev --ignored --exclude-per-directory
1362 return
1364 esac
1366 # XXX ignore options like --modified and always suggest all cached
1367 # files.
1368 __git_complete_index_file "--cached"
1371 _git_ls_remote ()
1373 __gitcomp_nl "$(__git_remotes)"
1376 _git_ls_tree ()
1378 __git_complete_file
1381 # Options that go well for log, shortlog and gitk
1382 __git_log_common_options="
1383 --not --all
1384 --branches --tags --remotes
1385 --first-parent --merges --no-merges
1386 --max-count=
1387 --max-age= --since= --after=
1388 --min-age= --until= --before=
1389 --min-parents= --max-parents=
1390 --no-min-parents --no-max-parents
1392 # Options that go well for log and gitk (not shortlog)
1393 __git_log_gitk_options="
1394 --dense --sparse --full-history
1395 --simplify-merges --simplify-by-decoration
1396 --left-right --notes --no-notes
1398 # Options that go well for log and shortlog (not gitk)
1399 __git_log_shortlog_options="
1400 --author= --committer= --grep=
1401 --all-match
1404 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1405 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1407 _git_log ()
1409 __git_has_doubledash && return
1411 local g="$(git rev-parse --git-dir 2>/dev/null)"
1412 local merge=""
1413 if [ -f "$g/MERGE_HEAD" ]; then
1414 merge="--merge"
1416 case "$cur" in
1417 --pretty=*|--format=*)
1418 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1419 " "" "${cur#*=}"
1420 return
1422 --date=*)
1423 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1424 return
1426 --decorate=*)
1427 __gitcomp "long short" "" "${cur##--decorate=}"
1428 return
1430 --*)
1431 __gitcomp "
1432 $__git_log_common_options
1433 $__git_log_shortlog_options
1434 $__git_log_gitk_options
1435 --root --topo-order --date-order --reverse
1436 --follow --full-diff
1437 --abbrev-commit --abbrev=
1438 --relative-date --date=
1439 --pretty= --format= --oneline
1440 --cherry-pick
1441 --graph
1442 --decorate --decorate=
1443 --walk-reflogs
1444 --parents --children
1445 $merge
1446 $__git_diff_common_options
1447 --pickaxe-all --pickaxe-regex
1449 return
1451 esac
1452 __git_complete_revlist
1455 __git_merge_options="
1456 --no-commit --no-stat --log --no-log --squash --strategy
1457 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1460 _git_merge ()
1462 __git_complete_strategy && return
1464 case "$cur" in
1465 --*)
1466 __gitcomp "$__git_merge_options"
1467 return
1468 esac
1469 __gitcomp_nl "$(__git_refs)"
1472 _git_mergetool ()
1474 case "$cur" in
1475 --tool=*)
1476 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1477 return
1479 --*)
1480 __gitcomp "--tool="
1481 return
1483 esac
1486 _git_merge_base ()
1488 __gitcomp_nl "$(__git_refs)"
1491 _git_mv ()
1493 case "$cur" in
1494 --*)
1495 __gitcomp "--dry-run"
1496 return
1498 esac
1500 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1501 # We need to show both cached and untracked files (including
1502 # empty directories) since this may not be the last argument.
1503 __git_complete_index_file "--cached --others --directory"
1504 else
1505 __git_complete_index_file "--cached"
1509 _git_name_rev ()
1511 __gitcomp "--tags --all --stdin"
1514 _git_notes ()
1516 local subcommands='add append copy edit list prune remove show'
1517 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1519 case "$subcommand,$cur" in
1520 ,--*)
1521 __gitcomp '--ref'
1524 case "$prev" in
1525 --ref)
1526 __gitcomp_nl "$(__git_refs)"
1529 __gitcomp "$subcommands --ref"
1531 esac
1533 add,--reuse-message=*|append,--reuse-message=*|\
1534 add,--reedit-message=*|append,--reedit-message=*)
1535 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1537 add,--*|append,--*)
1538 __gitcomp '--file= --message= --reedit-message=
1539 --reuse-message='
1541 copy,--*)
1542 __gitcomp '--stdin'
1544 prune,--*)
1545 __gitcomp '--dry-run --verbose'
1547 prune,*)
1550 case "$prev" in
1551 -m|-F)
1554 __gitcomp_nl "$(__git_refs)"
1556 esac
1558 esac
1561 _git_pull ()
1563 __git_complete_strategy && return
1565 case "$cur" in
1566 --*)
1567 __gitcomp "
1568 --rebase --no-rebase
1569 $__git_merge_options
1570 $__git_fetch_options
1572 return
1574 esac
1575 __git_complete_remote_or_refspec
1578 _git_push ()
1580 case "$prev" in
1581 --repo)
1582 __gitcomp_nl "$(__git_remotes)"
1583 return
1584 esac
1585 case "$cur" in
1586 --repo=*)
1587 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1588 return
1590 --*)
1591 __gitcomp "
1592 --all --mirror --tags --dry-run --force --verbose
1593 --receive-pack= --repo= --set-upstream
1595 return
1597 esac
1598 __git_complete_remote_or_refspec
1601 _git_rebase ()
1603 local dir="$(__gitdir)"
1604 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1605 __gitcomp "--continue --skip --abort"
1606 return
1608 __git_complete_strategy && return
1609 case "$cur" in
1610 --whitespace=*)
1611 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1612 return
1614 --*)
1615 __gitcomp "
1616 --onto --merge --strategy --interactive
1617 --preserve-merges --stat --no-stat
1618 --committer-date-is-author-date --ignore-date
1619 --ignore-whitespace --whitespace=
1620 --autosquash
1623 return
1624 esac
1625 __gitcomp_nl "$(__git_refs)"
1628 _git_reflog ()
1630 local subcommands="show delete expire"
1631 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1633 if [ -z "$subcommand" ]; then
1634 __gitcomp "$subcommands"
1635 else
1636 __gitcomp_nl "$(__git_refs)"
1640 __git_send_email_confirm_options="always never auto cc compose"
1641 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1643 _git_send_email ()
1645 case "$cur" in
1646 --confirm=*)
1647 __gitcomp "
1648 $__git_send_email_confirm_options
1649 " "" "${cur##--confirm=}"
1650 return
1652 --suppress-cc=*)
1653 __gitcomp "
1654 $__git_send_email_suppresscc_options
1655 " "" "${cur##--suppress-cc=}"
1657 return
1659 --smtp-encryption=*)
1660 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1661 return
1663 --thread=*)
1664 __gitcomp "
1665 deep shallow
1666 " "" "${cur##--thread=}"
1667 return
1669 --*)
1670 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1671 --compose --confirm= --dry-run --envelope-sender
1672 --from --identity
1673 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1674 --no-suppress-from --no-thread --quiet
1675 --signed-off-by-cc --smtp-pass --smtp-server
1676 --smtp-server-port --smtp-encryption= --smtp-user
1677 --subject --suppress-cc= --suppress-from --thread --to
1678 --validate --no-validate
1679 $__git_format_patch_options"
1680 return
1682 esac
1683 __git_complete_revlist
1686 _git_stage ()
1688 _git_add
1691 __git_config_get_set_variables ()
1693 local prevword word config_file= c=$cword
1694 while [ $c -gt 1 ]; do
1695 word="${words[c]}"
1696 case "$word" in
1697 --system|--global|--local|--file=*)
1698 config_file="$word"
1699 break
1701 -f|--file)
1702 config_file="$word $prevword"
1703 break
1705 esac
1706 prevword=$word
1707 c=$((--c))
1708 done
1710 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1711 while read -r line
1713 case "$line" in
1714 *.*=*)
1715 echo "${line/=*/}"
1717 esac
1718 done
1721 _git_config ()
1723 case "$prev" in
1724 branch.*.remote|branch.*.pushremote)
1725 __gitcomp_nl "$(__git_remotes)"
1726 return
1728 branch.*.merge)
1729 __gitcomp_nl "$(__git_refs)"
1730 return
1732 branch.*.rebase)
1733 __gitcomp "false true"
1734 return
1736 remote.pushdefault)
1737 __gitcomp_nl "$(__git_remotes)"
1738 return
1740 remote.*.fetch)
1741 local remote="${prev#remote.}"
1742 remote="${remote%.fetch}"
1743 if [ -z "$cur" ]; then
1744 __gitcomp_nl "refs/heads/" "" "" ""
1745 return
1747 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1748 return
1750 remote.*.push)
1751 local remote="${prev#remote.}"
1752 remote="${remote%.push}"
1753 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1754 for-each-ref --format='%(refname):%(refname)' \
1755 refs/heads)"
1756 return
1758 pull.twohead|pull.octopus)
1759 __git_compute_merge_strategies
1760 __gitcomp "$__git_merge_strategies"
1761 return
1763 color.branch|color.diff|color.interactive|\
1764 color.showbranch|color.status|color.ui)
1765 __gitcomp "always never auto"
1766 return
1768 color.pager)
1769 __gitcomp "false true"
1770 return
1772 color.*.*)
1773 __gitcomp "
1774 normal black red green yellow blue magenta cyan white
1775 bold dim ul blink reverse
1777 return
1779 diff.submodule)
1780 __gitcomp "log short"
1781 return
1783 help.format)
1784 __gitcomp "man info web html"
1785 return
1787 log.date)
1788 __gitcomp "$__git_log_date_formats"
1789 return
1791 sendemail.aliasesfiletype)
1792 __gitcomp "mutt mailrc pine elm gnus"
1793 return
1795 sendemail.confirm)
1796 __gitcomp "$__git_send_email_confirm_options"
1797 return
1799 sendemail.suppresscc)
1800 __gitcomp "$__git_send_email_suppresscc_options"
1801 return
1803 --get|--get-all|--unset|--unset-all)
1804 __gitcomp_nl "$(__git_config_get_set_variables)"
1805 return
1807 *.*)
1808 return
1810 esac
1811 case "$cur" in
1812 --*)
1813 __gitcomp "
1814 --system --global --local --file=
1815 --list --replace-all
1816 --get --get-all --get-regexp
1817 --add --unset --unset-all
1818 --remove-section --rename-section
1820 return
1822 branch.*.*)
1823 local pfx="${cur%.*}." cur_="${cur##*.}"
1824 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
1825 return
1827 branch.*)
1828 local pfx="${cur%.*}." cur_="${cur#*.}"
1829 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1830 return
1832 guitool.*.*)
1833 local pfx="${cur%.*}." cur_="${cur##*.}"
1834 __gitcomp "
1835 argprompt cmd confirm needsfile noconsole norescan
1836 prompt revprompt revunmerged title
1837 " "$pfx" "$cur_"
1838 return
1840 difftool.*.*)
1841 local pfx="${cur%.*}." cur_="${cur##*.}"
1842 __gitcomp "cmd path" "$pfx" "$cur_"
1843 return
1845 man.*.*)
1846 local pfx="${cur%.*}." cur_="${cur##*.}"
1847 __gitcomp "cmd path" "$pfx" "$cur_"
1848 return
1850 mergetool.*.*)
1851 local pfx="${cur%.*}." cur_="${cur##*.}"
1852 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1853 return
1855 pager.*)
1856 local pfx="${cur%.*}." cur_="${cur#*.}"
1857 __git_compute_all_commands
1858 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1859 return
1861 remote.*.*)
1862 local pfx="${cur%.*}." cur_="${cur##*.}"
1863 __gitcomp "
1864 url proxy fetch push mirror skipDefaultUpdate
1865 receivepack uploadpack tagopt pushurl
1866 " "$pfx" "$cur_"
1867 return
1869 remote.*)
1870 local pfx="${cur%.*}." cur_="${cur#*.}"
1871 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1872 return
1874 url.*.*)
1875 local pfx="${cur%.*}." cur_="${cur##*.}"
1876 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1877 return
1879 esac
1880 __gitcomp "
1881 add.ignoreErrors
1882 advice.commitBeforeMerge
1883 advice.detachedHead
1884 advice.implicitIdentity
1885 advice.pushNonFastForward
1886 advice.resolveConflict
1887 advice.statusHints
1888 alias.
1889 am.keepcr
1890 apply.ignorewhitespace
1891 apply.whitespace
1892 branch.autosetupmerge
1893 branch.autosetuprebase
1894 browser.
1895 clean.requireForce
1896 color.branch
1897 color.branch.current
1898 color.branch.local
1899 color.branch.plain
1900 color.branch.remote
1901 color.decorate.HEAD
1902 color.decorate.branch
1903 color.decorate.remoteBranch
1904 color.decorate.stash
1905 color.decorate.tag
1906 color.diff
1907 color.diff.commit
1908 color.diff.frag
1909 color.diff.func
1910 color.diff.meta
1911 color.diff.new
1912 color.diff.old
1913 color.diff.plain
1914 color.diff.whitespace
1915 color.grep
1916 color.grep.context
1917 color.grep.filename
1918 color.grep.function
1919 color.grep.linenumber
1920 color.grep.match
1921 color.grep.selected
1922 color.grep.separator
1923 color.interactive
1924 color.interactive.error
1925 color.interactive.header
1926 color.interactive.help
1927 color.interactive.prompt
1928 color.pager
1929 color.showbranch
1930 color.status
1931 color.status.added
1932 color.status.changed
1933 color.status.header
1934 color.status.nobranch
1935 color.status.untracked
1936 color.status.updated
1937 color.ui
1938 commit.status
1939 commit.template
1940 core.abbrev
1941 core.askpass
1942 core.attributesfile
1943 core.autocrlf
1944 core.bare
1945 core.bigFileThreshold
1946 core.compression
1947 core.createObject
1948 core.deltaBaseCacheLimit
1949 core.editor
1950 core.eol
1951 core.excludesfile
1952 core.fileMode
1953 core.fsyncobjectfiles
1954 core.gitProxy
1955 core.ignoreStat
1956 core.ignorecase
1957 core.logAllRefUpdates
1958 core.loosecompression
1959 core.notesRef
1960 core.packedGitLimit
1961 core.packedGitWindowSize
1962 core.pager
1963 core.preferSymlinkRefs
1964 core.preloadindex
1965 core.quotepath
1966 core.repositoryFormatVersion
1967 core.safecrlf
1968 core.sharedRepository
1969 core.sparseCheckout
1970 core.symlinks
1971 core.trustctime
1972 core.warnAmbiguousRefs
1973 core.whitespace
1974 core.worktree
1975 diff.autorefreshindex
1976 diff.external
1977 diff.ignoreSubmodules
1978 diff.mnemonicprefix
1979 diff.noprefix
1980 diff.renameLimit
1981 diff.renames
1982 diff.statGraphWidth
1983 diff.submodule
1984 diff.suppressBlankEmpty
1985 diff.tool
1986 diff.wordRegex
1987 diff.algorithm
1988 difftool.
1989 difftool.prompt
1990 fetch.recurseSubmodules
1991 fetch.unpackLimit
1992 format.attach
1993 format.cc
1994 format.coverLetter
1995 format.headers
1996 format.numbered
1997 format.pretty
1998 format.signature
1999 format.signoff
2000 format.subjectprefix
2001 format.suffix
2002 format.thread
2003 format.to
2005 gc.aggressiveWindow
2006 gc.auto
2007 gc.autopacklimit
2008 gc.packrefs
2009 gc.pruneexpire
2010 gc.reflogexpire
2011 gc.reflogexpireunreachable
2012 gc.rerereresolved
2013 gc.rerereunresolved
2014 gitcvs.allbinary
2015 gitcvs.commitmsgannotation
2016 gitcvs.dbTableNamePrefix
2017 gitcvs.dbdriver
2018 gitcvs.dbname
2019 gitcvs.dbpass
2020 gitcvs.dbuser
2021 gitcvs.enabled
2022 gitcvs.logfile
2023 gitcvs.usecrlfattr
2024 guitool.
2025 gui.blamehistoryctx
2026 gui.commitmsgwidth
2027 gui.copyblamethreshold
2028 gui.diffcontext
2029 gui.encoding
2030 gui.fastcopyblame
2031 gui.matchtrackingbranch
2032 gui.newbranchtemplate
2033 gui.pruneduringfetch
2034 gui.spellingdictionary
2035 gui.trustmtime
2036 help.autocorrect
2037 help.browser
2038 help.format
2039 http.lowSpeedLimit
2040 http.lowSpeedTime
2041 http.maxRequests
2042 http.minSessions
2043 http.noEPSV
2044 http.postBuffer
2045 http.proxy
2046 http.sslCAInfo
2047 http.sslCAPath
2048 http.sslCert
2049 http.sslCertPasswordProtected
2050 http.sslKey
2051 http.sslVerify
2052 http.useragent
2053 i18n.commitEncoding
2054 i18n.logOutputEncoding
2055 imap.authMethod
2056 imap.folder
2057 imap.host
2058 imap.pass
2059 imap.port
2060 imap.preformattedHTML
2061 imap.sslverify
2062 imap.tunnel
2063 imap.user
2064 init.templatedir
2065 instaweb.browser
2066 instaweb.httpd
2067 instaweb.local
2068 instaweb.modulepath
2069 instaweb.port
2070 interactive.singlekey
2071 log.date
2072 log.decorate
2073 log.showroot
2074 mailmap.file
2075 man.
2076 man.viewer
2077 merge.
2078 merge.conflictstyle
2079 merge.log
2080 merge.renameLimit
2081 merge.renormalize
2082 merge.stat
2083 merge.tool
2084 merge.verbosity
2085 mergetool.
2086 mergetool.keepBackup
2087 mergetool.keepTemporaries
2088 mergetool.prompt
2089 notes.displayRef
2090 notes.rewrite.
2091 notes.rewrite.amend
2092 notes.rewrite.rebase
2093 notes.rewriteMode
2094 notes.rewriteRef
2095 pack.compression
2096 pack.deltaCacheLimit
2097 pack.deltaCacheSize
2098 pack.depth
2099 pack.indexVersion
2100 pack.packSizeLimit
2101 pack.threads
2102 pack.window
2103 pack.windowMemory
2104 pager.
2105 pretty.
2106 pull.octopus
2107 pull.twohead
2108 push.default
2109 rebase.autosquash
2110 rebase.stat
2111 receive.autogc
2112 receive.denyCurrentBranch
2113 receive.denyDeleteCurrent
2114 receive.denyDeletes
2115 receive.denyNonFastForwards
2116 receive.fsckObjects
2117 receive.unpackLimit
2118 receive.updateserverinfo
2119 remote.pushdefault
2120 remotes.
2121 repack.usedeltabaseoffset
2122 rerere.autoupdate
2123 rerere.enabled
2124 sendemail.
2125 sendemail.aliasesfile
2126 sendemail.aliasfiletype
2127 sendemail.bcc
2128 sendemail.cc
2129 sendemail.cccmd
2130 sendemail.chainreplyto
2131 sendemail.confirm
2132 sendemail.envelopesender
2133 sendemail.from
2134 sendemail.identity
2135 sendemail.multiedit
2136 sendemail.signedoffbycc
2137 sendemail.smtpdomain
2138 sendemail.smtpencryption
2139 sendemail.smtppass
2140 sendemail.smtpserver
2141 sendemail.smtpserveroption
2142 sendemail.smtpserverport
2143 sendemail.smtpuser
2144 sendemail.suppresscc
2145 sendemail.suppressfrom
2146 sendemail.thread
2147 sendemail.to
2148 sendemail.validate
2149 showbranch.default
2150 status.relativePaths
2151 status.showUntrackedFiles
2152 status.submodulesummary
2153 submodule.
2154 tar.umask
2155 transfer.unpackLimit
2156 url.
2157 user.email
2158 user.name
2159 user.signingkey
2160 web.browser
2161 branch. remote.
2165 _git_remote ()
2167 local subcommands="add rename remove set-head set-branches set-url show prune update"
2168 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2169 if [ -z "$subcommand" ]; then
2170 __gitcomp "$subcommands"
2171 return
2174 case "$subcommand" in
2175 rename|remove|set-url|show|prune)
2176 __gitcomp_nl "$(__git_remotes)"
2178 set-head|set-branches)
2179 __git_complete_remote_or_refspec
2181 update)
2182 local i c='' IFS=$'\n'
2183 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2184 i="${i#remotes.}"
2185 c="$c ${i/ */}"
2186 done
2187 __gitcomp "$c"
2191 esac
2194 _git_replace ()
2196 __gitcomp_nl "$(__git_refs)"
2199 _git_reset ()
2201 __git_has_doubledash && return
2203 case "$cur" in
2204 --*)
2205 __gitcomp "--merge --mixed --hard --soft --patch"
2206 return
2208 esac
2209 __gitcomp_nl "$(__git_refs)"
2212 _git_revert ()
2214 case "$cur" in
2215 --*)
2216 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2217 return
2219 esac
2220 __gitcomp_nl "$(__git_refs)"
2223 _git_rm ()
2225 case "$cur" in
2226 --*)
2227 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2228 return
2230 esac
2232 __git_complete_index_file "--cached"
2235 _git_shortlog ()
2237 __git_has_doubledash && return
2239 case "$cur" in
2240 --*)
2241 __gitcomp "
2242 $__git_log_common_options
2243 $__git_log_shortlog_options
2244 --numbered --summary
2246 return
2248 esac
2249 __git_complete_revlist
2252 _git_show ()
2254 __git_has_doubledash && return
2256 case "$cur" in
2257 --pretty=*|--format=*)
2258 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2259 " "" "${cur#*=}"
2260 return
2262 --diff-algorithm=*)
2263 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2264 return
2266 --*)
2267 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2268 $__git_diff_common_options
2270 return
2272 esac
2273 __git_complete_revlist_file
2276 _git_show_branch ()
2278 case "$cur" in
2279 --*)
2280 __gitcomp "
2281 --all --remotes --topo-order --current --more=
2282 --list --independent --merge-base --no-name
2283 --color --no-color
2284 --sha1-name --sparse --topics --reflog
2286 return
2288 esac
2289 __git_complete_revlist
2292 _git_stash ()
2294 local save_opts='--keep-index --no-keep-index --quiet --patch'
2295 local subcommands='save list show apply clear drop pop create branch'
2296 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2297 if [ -z "$subcommand" ]; then
2298 case "$cur" in
2299 --*)
2300 __gitcomp "$save_opts"
2303 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2304 __gitcomp "$subcommands"
2307 esac
2308 else
2309 case "$subcommand,$cur" in
2310 save,--*)
2311 __gitcomp "$save_opts"
2313 apply,--*|pop,--*)
2314 __gitcomp "--index --quiet"
2316 show,--*|drop,--*|branch,--*)
2318 show,*|apply,*|drop,*|pop,*|branch,*)
2319 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2320 | sed -n -e 's/:.*//p')"
2324 esac
2328 _git_submodule ()
2330 __git_has_doubledash && return
2332 local subcommands="add status init deinit update summary foreach sync"
2333 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2334 case "$cur" in
2335 --*)
2336 __gitcomp "--quiet --cached"
2339 __gitcomp "$subcommands"
2341 esac
2342 return
2346 _git_svn ()
2348 local subcommands="
2349 init fetch clone rebase dcommit log find-rev
2350 set-tree commit-diff info create-ignore propget
2351 proplist show-ignore show-externals branch tag blame
2352 migrate mkdirs reset gc
2354 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2355 if [ -z "$subcommand" ]; then
2356 __gitcomp "$subcommands"
2357 else
2358 local remote_opts="--username= --config-dir= --no-auth-cache"
2359 local fc_opts="
2360 --follow-parent --authors-file= --repack=
2361 --no-metadata --use-svm-props --use-svnsync-props
2362 --log-window-size= --no-checkout --quiet
2363 --repack-flags --use-log-author --localtime
2364 --ignore-paths= --include-paths= $remote_opts
2366 local init_opts="
2367 --template= --shared= --trunk= --tags=
2368 --branches= --stdlayout --minimize-url
2369 --no-metadata --use-svm-props --use-svnsync-props
2370 --rewrite-root= --prefix= --use-log-author
2371 --add-author-from $remote_opts
2373 local cmt_opts="
2374 --edit --rmdir --find-copies-harder --copy-similarity=
2377 case "$subcommand,$cur" in
2378 fetch,--*)
2379 __gitcomp "--revision= --fetch-all $fc_opts"
2381 clone,--*)
2382 __gitcomp "--revision= $fc_opts $init_opts"
2384 init,--*)
2385 __gitcomp "$init_opts"
2387 dcommit,--*)
2388 __gitcomp "
2389 --merge --strategy= --verbose --dry-run
2390 --fetch-all --no-rebase --commit-url
2391 --revision --interactive $cmt_opts $fc_opts
2394 set-tree,--*)
2395 __gitcomp "--stdin $cmt_opts $fc_opts"
2397 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2398 show-externals,--*|mkdirs,--*)
2399 __gitcomp "--revision="
2401 log,--*)
2402 __gitcomp "
2403 --limit= --revision= --verbose --incremental
2404 --oneline --show-commit --non-recursive
2405 --authors-file= --color
2408 rebase,--*)
2409 __gitcomp "
2410 --merge --verbose --strategy= --local
2411 --fetch-all --dry-run $fc_opts
2414 commit-diff,--*)
2415 __gitcomp "--message= --file= --revision= $cmt_opts"
2417 info,--*)
2418 __gitcomp "--url"
2420 branch,--*)
2421 __gitcomp "--dry-run --message --tag"
2423 tag,--*)
2424 __gitcomp "--dry-run --message"
2426 blame,--*)
2427 __gitcomp "--git-format"
2429 migrate,--*)
2430 __gitcomp "
2431 --config-dir= --ignore-paths= --minimize
2432 --no-auth-cache --username=
2435 reset,--*)
2436 __gitcomp "--revision= --parent"
2440 esac
2444 _git_tag ()
2446 local i c=1 f=0
2447 while [ $c -lt $cword ]; do
2448 i="${words[c]}"
2449 case "$i" in
2450 -d|-v)
2451 __gitcomp_nl "$(__git_tags)"
2452 return
2457 esac
2458 ((c++))
2459 done
2461 case "$prev" in
2462 -m|-F)
2464 -*|tag)
2465 if [ $f = 1 ]; then
2466 __gitcomp_nl "$(__git_tags)"
2470 __gitcomp_nl "$(__git_refs)"
2472 esac
2475 _git_whatchanged ()
2477 _git_log
2480 __git_main ()
2482 local i c=1 command __git_dir
2484 while [ $c -lt $cword ]; do
2485 i="${words[c]}"
2486 case "$i" in
2487 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2488 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2489 --bare) __git_dir="." ;;
2490 --help) command="help"; break ;;
2491 -c|--work-tree|--namespace) ((c++)) ;;
2492 -*) ;;
2493 *) command="$i"; break ;;
2494 esac
2495 ((c++))
2496 done
2498 if [ -z "$command" ]; then
2499 case "$cur" in
2500 --*) __gitcomp "
2501 --paginate
2502 --no-pager
2503 --git-dir=
2504 --bare
2505 --version
2506 --exec-path
2507 --exec-path=
2508 --html-path
2509 --man-path
2510 --info-path
2511 --work-tree=
2512 --namespace=
2513 --no-replace-objects
2514 --help
2517 *) __git_compute_porcelain_commands
2518 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2519 esac
2520 return
2523 local completion_func="_git_${command//-/_}"
2524 declare -f $completion_func >/dev/null && $completion_func && return
2526 local expansion=$(__git_aliased_command "$command")
2527 if [ -n "$expansion" ]; then
2528 completion_func="_git_${expansion//-/_}"
2529 declare -f $completion_func >/dev/null && $completion_func
2533 __gitk_main ()
2535 __git_has_doubledash && return
2537 local g="$(__gitdir)"
2538 local merge=""
2539 if [ -f "$g/MERGE_HEAD" ]; then
2540 merge="--merge"
2542 case "$cur" in
2543 --*)
2544 __gitcomp "
2545 $__git_log_common_options
2546 $__git_log_gitk_options
2547 $merge
2549 return
2551 esac
2552 __git_complete_revlist
2555 if [[ -n ${ZSH_VERSION-} ]]; then
2556 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2558 autoload -U +X compinit && compinit
2560 __gitcomp ()
2562 emulate -L zsh
2564 local cur_="${3-$cur}"
2566 case "$cur_" in
2567 --*=)
2570 local c IFS=$' \t\n'
2571 local -a array
2572 for c in ${=1}; do
2573 c="$c${4-}"
2574 case $c in
2575 --*=*|*.) ;;
2576 *) c="$c " ;;
2577 esac
2578 array[${#array[@]}+1]="$c"
2579 done
2580 compset -P '*[=:]'
2581 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2583 esac
2586 __gitcomp_nl ()
2588 emulate -L zsh
2590 local IFS=$'\n'
2591 compset -P '*[=:]'
2592 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2595 __gitcomp_file ()
2597 emulate -L zsh
2599 local IFS=$'\n'
2600 compset -P '*[=:]'
2601 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2604 _git ()
2606 local _ret=1 cur cword prev
2607 cur=${words[CURRENT]}
2608 prev=${words[CURRENT-1]}
2609 let cword=CURRENT-1
2610 emulate ksh -c __${service}_main
2611 let _ret && _default && _ret=0
2612 return _ret
2615 compdef _git git gitk
2616 return
2619 __git_func_wrap ()
2621 local cur words cword prev
2622 _get_comp_words_by_ref -n =: cur words cword prev
2626 # Setup completion for certain functions defined above by setting common
2627 # variables and workarounds.
2628 # This is NOT a public function; use at your own risk.
2629 __git_complete ()
2631 local wrapper="__git_wrap${2}"
2632 eval "$wrapper () { __git_func_wrap $2 ; }"
2633 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2634 || complete -o default -o nospace -F $wrapper $1
2637 # wrapper for backwards compatibility
2638 _git ()
2640 __git_wrap__git_main
2643 # wrapper for backwards compatibility
2644 _gitk ()
2646 __git_wrap__gitk_main
2649 __git_complete git __git_main
2650 __git_complete gitk __gitk_main
2652 # The following are necessary only for Cygwin, and only are needed
2653 # when the user has tab-completed the executable name and consequently
2654 # included the '.exe' suffix.
2656 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2657 __git_complete git.exe __git_main