remove #!interpreter line from shell libraries
[git/gitster.git] / contrib / completion / git-completion.bash
blobbe6193162737bec2fc5eac840f75956dae9e00e5
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 lost-found) : infrequent;;
675 ls-files) : plumbing;;
676 ls-remote) : plumbing;;
677 ls-tree) : plumbing;;
678 mailinfo) : plumbing;;
679 mailsplit) : plumbing;;
680 merge-*) : plumbing;;
681 mktree) : plumbing;;
682 mktag) : plumbing;;
683 pack-objects) : plumbing;;
684 pack-redundant) : plumbing;;
685 pack-refs) : plumbing;;
686 parse-remote) : plumbing;;
687 patch-id) : plumbing;;
688 peek-remote) : plumbing;;
689 prune) : plumbing;;
690 prune-packed) : plumbing;;
691 quiltimport) : import;;
692 read-tree) : plumbing;;
693 receive-pack) : plumbing;;
694 remote-*) : transport;;
695 repo-config) : deprecated;;
696 rerere) : plumbing;;
697 rev-list) : plumbing;;
698 rev-parse) : plumbing;;
699 runstatus) : plumbing;;
700 sh-setup) : internal;;
701 shell) : daemon;;
702 show-ref) : plumbing;;
703 send-pack) : plumbing;;
704 show-index) : plumbing;;
705 ssh-*) : transport;;
706 stripspace) : plumbing;;
707 symbolic-ref) : plumbing;;
708 tar-tree) : deprecated;;
709 unpack-file) : plumbing;;
710 unpack-objects) : plumbing;;
711 update-index) : plumbing;;
712 update-ref) : plumbing;;
713 update-server-info) : daemon;;
714 upload-archive) : plumbing;;
715 upload-pack) : plumbing;;
716 write-tree) : plumbing;;
717 var) : infrequent;;
718 verify-pack) : infrequent;;
719 verify-tag) : plumbing;;
720 *) echo $i;;
721 esac
722 done
725 __git_porcelain_commands=
726 __git_compute_porcelain_commands ()
728 __git_compute_all_commands
729 test -n "$__git_porcelain_commands" ||
730 __git_porcelain_commands=$(__git_list_porcelain_commands)
733 __git_pretty_aliases ()
735 local i IFS=$'\n'
736 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
737 case "$i" in
738 pretty.*)
739 i="${i#pretty.}"
740 echo "${i/ */}"
742 esac
743 done
746 __git_aliases ()
748 local i IFS=$'\n'
749 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
750 case "$i" in
751 alias.*)
752 i="${i#alias.}"
753 echo "${i/ */}"
755 esac
756 done
759 # __git_aliased_command requires 1 argument
760 __git_aliased_command ()
762 local word cmdline=$(git --git-dir="$(__gitdir)" \
763 config --get "alias.$1")
764 for word in $cmdline; do
765 case "$word" in
766 \!gitk|gitk)
767 echo "gitk"
768 return
770 \!*) : shell command alias ;;
771 -*) : option ;;
772 *=*) : setting env ;;
773 git) : git itself ;;
775 echo "$word"
776 return
777 esac
778 done
781 # __git_find_on_cmdline requires 1 argument
782 __git_find_on_cmdline ()
784 local word subcommand c=1
785 while [ $c -lt $cword ]; do
786 word="${words[c]}"
787 for subcommand in $1; do
788 if [ "$subcommand" = "$word" ]; then
789 echo "$subcommand"
790 return
792 done
793 ((c++))
794 done
797 __git_has_doubledash ()
799 local c=1
800 while [ $c -lt $cword ]; do
801 if [ "--" = "${words[c]}" ]; then
802 return 0
804 ((c++))
805 done
806 return 1
809 # Try to count non option arguments passed on the command line for the
810 # specified git command.
811 # When options are used, it is necessary to use the special -- option to
812 # tell the implementation were non option arguments begin.
813 # XXX this can not be improved, since options can appear everywhere, as
814 # an example:
815 # git mv x -n y
817 # __git_count_arguments requires 1 argument: the git command executed.
818 __git_count_arguments ()
820 local word i c=0
822 # Skip "git" (first argument)
823 for ((i=1; i < ${#words[@]}; i++)); do
824 word="${words[i]}"
826 case "$word" in
828 # Good; we can assume that the following are only non
829 # option arguments.
830 ((c = 0))
832 "$1")
833 # Skip the specified git command and discard git
834 # main options
835 ((c = 0))
838 ((c++))
840 esac
841 done
843 printf "%d" $c
846 __git_whitespacelist="nowarn warn error error-all fix"
848 _git_am ()
850 local dir="$(__gitdir)"
851 if [ -d "$dir"/rebase-apply ]; then
852 __gitcomp "--skip --continue --resolved --abort"
853 return
855 case "$cur" in
856 --whitespace=*)
857 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
858 return
860 --*)
861 __gitcomp "
862 --3way --committer-date-is-author-date --ignore-date
863 --ignore-whitespace --ignore-space-change
864 --interactive --keep --no-utf8 --signoff --utf8
865 --whitespace= --scissors
867 return
868 esac
871 _git_apply ()
873 case "$cur" in
874 --whitespace=*)
875 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
876 return
878 --*)
879 __gitcomp "
880 --stat --numstat --summary --check --index
881 --cached --index-info --reverse --reject --unidiff-zero
882 --apply --no-add --exclude=
883 --ignore-whitespace --ignore-space-change
884 --whitespace= --inaccurate-eof --verbose
886 return
887 esac
890 _git_add ()
892 case "$cur" in
893 --*)
894 __gitcomp "
895 --interactive --refresh --patch --update --dry-run
896 --ignore-errors --intent-to-add
898 return
899 esac
901 # XXX should we check for --update and --all options ?
902 __git_complete_index_file "--others --modified --directory --no-empty-directory"
905 _git_archive ()
907 case "$cur" in
908 --format=*)
909 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
910 return
912 --remote=*)
913 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
914 return
916 --*)
917 __gitcomp "
918 --format= --list --verbose
919 --prefix= --remote= --exec=
921 return
923 esac
924 __git_complete_file
927 _git_bisect ()
929 __git_has_doubledash && return
931 local subcommands="start bad good skip reset visualize replay log run"
932 local subcommand="$(__git_find_on_cmdline "$subcommands")"
933 if [ -z "$subcommand" ]; then
934 if [ -f "$(__gitdir)"/BISECT_START ]; then
935 __gitcomp "$subcommands"
936 else
937 __gitcomp "replay start"
939 return
942 case "$subcommand" in
943 bad|good|reset|skip|start)
944 __gitcomp_nl "$(__git_refs)"
948 esac
951 _git_branch ()
953 local i c=1 only_local_ref="n" has_r="n"
955 while [ $c -lt $cword ]; do
956 i="${words[c]}"
957 case "$i" in
958 -d|-m) only_local_ref="y" ;;
959 -r) has_r="y" ;;
960 esac
961 ((c++))
962 done
964 case "$cur" in
965 --set-upstream-to=*)
966 __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
968 --*)
969 __gitcomp "
970 --color --no-color --verbose --abbrev= --no-abbrev
971 --track --no-track --contains --merged --no-merged
972 --set-upstream-to= --edit-description --list
973 --unset-upstream
977 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
978 __gitcomp_nl "$(__git_heads)"
979 else
980 __gitcomp_nl "$(__git_refs)"
983 esac
986 _git_bundle ()
988 local cmd="${words[2]}"
989 case "$cword" in
991 __gitcomp "create list-heads verify unbundle"
994 # looking for a file
997 case "$cmd" in
998 create)
999 __git_complete_revlist
1001 esac
1003 esac
1006 _git_checkout ()
1008 __git_has_doubledash && return
1010 case "$cur" in
1011 --conflict=*)
1012 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1014 --*)
1015 __gitcomp "
1016 --quiet --ours --theirs --track --no-track --merge
1017 --conflict= --orphan --patch
1021 # check if --track, --no-track, or --no-guess was specified
1022 # if so, disable DWIM mode
1023 local flags="--track --no-track --no-guess" track=1
1024 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1025 track=''
1027 __gitcomp_nl "$(__git_refs '' $track)"
1029 esac
1032 _git_cherry ()
1034 __gitcomp "$(__git_refs)"
1037 _git_cherry_pick ()
1039 local dir="$(__gitdir)"
1040 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1041 __gitcomp "--continue --quit --abort"
1042 return
1044 case "$cur" in
1045 --*)
1046 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1049 __gitcomp_nl "$(__git_refs)"
1051 esac
1054 _git_clean ()
1056 case "$cur" in
1057 --*)
1058 __gitcomp "--dry-run --quiet"
1059 return
1061 esac
1063 # XXX should we check for -x option ?
1064 __git_complete_index_file "--others --directory"
1067 _git_clone ()
1069 case "$cur" in
1070 --*)
1071 __gitcomp "
1072 --local
1073 --no-hardlinks
1074 --shared
1075 --reference
1076 --quiet
1077 --no-checkout
1078 --bare
1079 --mirror
1080 --origin
1081 --upload-pack
1082 --template=
1083 --depth
1084 --single-branch
1085 --branch
1087 return
1089 esac
1092 _git_commit ()
1094 case "$prev" in
1095 -c|-C)
1096 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1097 return
1099 esac
1101 case "$cur" in
1102 --cleanup=*)
1103 __gitcomp "default strip verbatim whitespace
1104 " "" "${cur##--cleanup=}"
1105 return
1107 --reuse-message=*|--reedit-message=*|\
1108 --fixup=*|--squash=*)
1109 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1110 return
1112 --untracked-files=*)
1113 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1114 return
1116 --*)
1117 __gitcomp "
1118 --all --author= --signoff --verify --no-verify
1119 --edit --no-edit
1120 --amend --include --only --interactive
1121 --dry-run --reuse-message= --reedit-message=
1122 --reset-author --file= --message= --template=
1123 --cleanup= --untracked-files --untracked-files=
1124 --verbose --quiet --fixup= --squash=
1126 return
1127 esac
1129 if git rev-parse --verify --quiet HEAD >/dev/null; then
1130 __git_complete_index_file "--committable"
1131 else
1132 # This is the first commit
1133 __git_complete_index_file "--cached"
1137 _git_describe ()
1139 case "$cur" in
1140 --*)
1141 __gitcomp "
1142 --all --tags --contains --abbrev= --candidates=
1143 --exact-match --debug --long --match --always
1145 return
1146 esac
1147 __gitcomp_nl "$(__git_refs)"
1150 __git_diff_algorithms="myers minimal patience histogram"
1152 __git_diff_common_options="--stat --numstat --shortstat --summary
1153 --patch-with-stat --name-only --name-status --color
1154 --no-color --color-words --no-renames --check
1155 --full-index --binary --abbrev --diff-filter=
1156 --find-copies-harder
1157 --text --ignore-space-at-eol --ignore-space-change
1158 --ignore-all-space --exit-code --quiet --ext-diff
1159 --no-ext-diff
1160 --no-prefix --src-prefix= --dst-prefix=
1161 --inter-hunk-context=
1162 --patience --histogram --minimal
1163 --raw --word-diff
1164 --dirstat --dirstat= --dirstat-by-file
1165 --dirstat-by-file= --cumulative
1166 --diff-algorithm=
1169 _git_diff ()
1171 __git_has_doubledash && return
1173 case "$cur" in
1174 --diff-algorithm=*)
1175 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1176 return
1178 --*)
1179 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1180 --base --ours --theirs --no-index
1181 $__git_diff_common_options
1183 return
1185 esac
1186 __git_complete_revlist_file
1189 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1190 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1193 _git_difftool ()
1195 __git_has_doubledash && return
1197 case "$cur" in
1198 --tool=*)
1199 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1200 return
1202 --*)
1203 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1204 --base --ours --theirs
1205 --no-renames --diff-filter= --find-copies-harder
1206 --relative --ignore-submodules
1207 --tool="
1208 return
1210 esac
1211 __git_complete_revlist_file
1214 __git_fetch_options="
1215 --quiet --verbose --append --upload-pack --force --keep --depth=
1216 --tags --no-tags --all --prune --dry-run
1219 _git_fetch ()
1221 case "$cur" in
1222 --*)
1223 __gitcomp "$__git_fetch_options"
1224 return
1226 esac
1227 __git_complete_remote_or_refspec
1230 __git_format_patch_options="
1231 --stdout --attach --no-attach --thread --thread= --no-thread
1232 --numbered --start-number --numbered-files --keep-subject --signoff
1233 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1234 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1235 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1236 --output-directory --reroll-count --to= --quiet --notes
1239 _git_format_patch ()
1241 case "$cur" in
1242 --thread=*)
1243 __gitcomp "
1244 deep shallow
1245 " "" "${cur##--thread=}"
1246 return
1248 --*)
1249 __gitcomp "$__git_format_patch_options"
1250 return
1252 esac
1253 __git_complete_revlist
1256 _git_fsck ()
1258 case "$cur" in
1259 --*)
1260 __gitcomp "
1261 --tags --root --unreachable --cache --no-reflogs --full
1262 --strict --verbose --lost-found
1264 return
1266 esac
1269 _git_gc ()
1271 case "$cur" in
1272 --*)
1273 __gitcomp "--prune --aggressive"
1274 return
1276 esac
1279 _git_gitk ()
1281 _gitk
1284 __git_match_ctag() {
1285 awk "/^${1////\\/}/ { print \$1 }" "$2"
1288 _git_grep ()
1290 __git_has_doubledash && return
1292 case "$cur" in
1293 --*)
1294 __gitcomp "
1295 --cached
1296 --text --ignore-case --word-regexp --invert-match
1297 --full-name --line-number
1298 --extended-regexp --basic-regexp --fixed-strings
1299 --perl-regexp
1300 --files-with-matches --name-only
1301 --files-without-match
1302 --max-depth
1303 --count
1304 --and --or --not --all-match
1306 return
1308 esac
1310 case "$cword,$prev" in
1311 2,*|*,-*)
1312 if test -r tags; then
1313 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1314 return
1317 esac
1319 __gitcomp_nl "$(__git_refs)"
1322 _git_help ()
1324 case "$cur" in
1325 --*)
1326 __gitcomp "--all --info --man --web"
1327 return
1329 esac
1330 __git_compute_all_commands
1331 __gitcomp "$__git_all_commands $(__git_aliases)
1332 attributes cli core-tutorial cvs-migration
1333 diffcore gitk glossary hooks ignore modules
1334 namespaces repository-layout tutorial tutorial-2
1335 workflows
1339 _git_init ()
1341 case "$cur" in
1342 --shared=*)
1343 __gitcomp "
1344 false true umask group all world everybody
1345 " "" "${cur##--shared=}"
1346 return
1348 --*)
1349 __gitcomp "--quiet --bare --template= --shared --shared="
1350 return
1352 esac
1355 _git_ls_files ()
1357 case "$cur" in
1358 --*)
1359 __gitcomp "--cached --deleted --modified --others --ignored
1360 --stage --directory --no-empty-directory --unmerged
1361 --killed --exclude= --exclude-from=
1362 --exclude-per-directory= --exclude-standard
1363 --error-unmatch --with-tree= --full-name
1364 --abbrev --ignored --exclude-per-directory
1366 return
1368 esac
1370 # XXX ignore options like --modified and always suggest all cached
1371 # files.
1372 __git_complete_index_file "--cached"
1375 _git_ls_remote ()
1377 __gitcomp_nl "$(__git_remotes)"
1380 _git_ls_tree ()
1382 __git_complete_file
1385 # Options that go well for log, shortlog and gitk
1386 __git_log_common_options="
1387 --not --all
1388 --branches --tags --remotes
1389 --first-parent --merges --no-merges
1390 --max-count=
1391 --max-age= --since= --after=
1392 --min-age= --until= --before=
1393 --min-parents= --max-parents=
1394 --no-min-parents --no-max-parents
1396 # Options that go well for log and gitk (not shortlog)
1397 __git_log_gitk_options="
1398 --dense --sparse --full-history
1399 --simplify-merges --simplify-by-decoration
1400 --left-right --notes --no-notes
1402 # Options that go well for log and shortlog (not gitk)
1403 __git_log_shortlog_options="
1404 --author= --committer= --grep=
1405 --all-match
1408 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1409 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1411 _git_log ()
1413 __git_has_doubledash && return
1415 local g="$(git rev-parse --git-dir 2>/dev/null)"
1416 local merge=""
1417 if [ -f "$g/MERGE_HEAD" ]; then
1418 merge="--merge"
1420 case "$cur" in
1421 --pretty=*|--format=*)
1422 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1423 " "" "${cur#*=}"
1424 return
1426 --date=*)
1427 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1428 return
1430 --decorate=*)
1431 __gitcomp "long short" "" "${cur##--decorate=}"
1432 return
1434 --*)
1435 __gitcomp "
1436 $__git_log_common_options
1437 $__git_log_shortlog_options
1438 $__git_log_gitk_options
1439 --root --topo-order --date-order --reverse
1440 --follow --full-diff
1441 --abbrev-commit --abbrev=
1442 --relative-date --date=
1443 --pretty= --format= --oneline
1444 --cherry-pick
1445 --graph
1446 --decorate --decorate=
1447 --walk-reflogs
1448 --parents --children
1449 $merge
1450 $__git_diff_common_options
1451 --pickaxe-all --pickaxe-regex
1453 return
1455 esac
1456 __git_complete_revlist
1459 __git_merge_options="
1460 --no-commit --no-stat --log --no-log --squash --strategy
1461 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1464 _git_merge ()
1466 __git_complete_strategy && return
1468 case "$cur" in
1469 --*)
1470 __gitcomp "$__git_merge_options"
1471 return
1472 esac
1473 __gitcomp_nl "$(__git_refs)"
1476 _git_mergetool ()
1478 case "$cur" in
1479 --tool=*)
1480 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1481 return
1483 --*)
1484 __gitcomp "--tool="
1485 return
1487 esac
1490 _git_merge_base ()
1492 __gitcomp_nl "$(__git_refs)"
1495 _git_mv ()
1497 case "$cur" in
1498 --*)
1499 __gitcomp "--dry-run"
1500 return
1502 esac
1504 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1505 # We need to show both cached and untracked files (including
1506 # empty directories) since this may not be the last argument.
1507 __git_complete_index_file "--cached --others --directory"
1508 else
1509 __git_complete_index_file "--cached"
1513 _git_name_rev ()
1515 __gitcomp "--tags --all --stdin"
1518 _git_notes ()
1520 local subcommands='add append copy edit list prune remove show'
1521 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1523 case "$subcommand,$cur" in
1524 ,--*)
1525 __gitcomp '--ref'
1528 case "$prev" in
1529 --ref)
1530 __gitcomp_nl "$(__git_refs)"
1533 __gitcomp "$subcommands --ref"
1535 esac
1537 add,--reuse-message=*|append,--reuse-message=*|\
1538 add,--reedit-message=*|append,--reedit-message=*)
1539 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1541 add,--*|append,--*)
1542 __gitcomp '--file= --message= --reedit-message=
1543 --reuse-message='
1545 copy,--*)
1546 __gitcomp '--stdin'
1548 prune,--*)
1549 __gitcomp '--dry-run --verbose'
1551 prune,*)
1554 case "$prev" in
1555 -m|-F)
1558 __gitcomp_nl "$(__git_refs)"
1560 esac
1562 esac
1565 _git_pull ()
1567 __git_complete_strategy && return
1569 case "$cur" in
1570 --*)
1571 __gitcomp "
1572 --rebase --no-rebase
1573 $__git_merge_options
1574 $__git_fetch_options
1576 return
1578 esac
1579 __git_complete_remote_or_refspec
1582 _git_push ()
1584 case "$prev" in
1585 --repo)
1586 __gitcomp_nl "$(__git_remotes)"
1587 return
1588 esac
1589 case "$cur" in
1590 --repo=*)
1591 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1592 return
1594 --*)
1595 __gitcomp "
1596 --all --mirror --tags --dry-run --force --verbose
1597 --receive-pack= --repo= --set-upstream
1599 return
1601 esac
1602 __git_complete_remote_or_refspec
1605 _git_rebase ()
1607 local dir="$(__gitdir)"
1608 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1609 __gitcomp "--continue --skip --abort"
1610 return
1612 __git_complete_strategy && return
1613 case "$cur" in
1614 --whitespace=*)
1615 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1616 return
1618 --*)
1619 __gitcomp "
1620 --onto --merge --strategy --interactive
1621 --preserve-merges --stat --no-stat
1622 --committer-date-is-author-date --ignore-date
1623 --ignore-whitespace --whitespace=
1624 --autosquash
1627 return
1628 esac
1629 __gitcomp_nl "$(__git_refs)"
1632 _git_reflog ()
1634 local subcommands="show delete expire"
1635 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1637 if [ -z "$subcommand" ]; then
1638 __gitcomp "$subcommands"
1639 else
1640 __gitcomp_nl "$(__git_refs)"
1644 __git_send_email_confirm_options="always never auto cc compose"
1645 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1647 _git_send_email ()
1649 case "$cur" in
1650 --confirm=*)
1651 __gitcomp "
1652 $__git_send_email_confirm_options
1653 " "" "${cur##--confirm=}"
1654 return
1656 --suppress-cc=*)
1657 __gitcomp "
1658 $__git_send_email_suppresscc_options
1659 " "" "${cur##--suppress-cc=}"
1661 return
1663 --smtp-encryption=*)
1664 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1665 return
1667 --thread=*)
1668 __gitcomp "
1669 deep shallow
1670 " "" "${cur##--thread=}"
1671 return
1673 --*)
1674 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1675 --compose --confirm= --dry-run --envelope-sender
1676 --from --identity
1677 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1678 --no-suppress-from --no-thread --quiet
1679 --signed-off-by-cc --smtp-pass --smtp-server
1680 --smtp-server-port --smtp-encryption= --smtp-user
1681 --subject --suppress-cc= --suppress-from --thread --to
1682 --validate --no-validate
1683 $__git_format_patch_options"
1684 return
1686 esac
1687 __git_complete_revlist
1690 _git_stage ()
1692 _git_add
1695 __git_config_get_set_variables ()
1697 local prevword word config_file= c=$cword
1698 while [ $c -gt 1 ]; do
1699 word="${words[c]}"
1700 case "$word" in
1701 --system|--global|--local|--file=*)
1702 config_file="$word"
1703 break
1705 -f|--file)
1706 config_file="$word $prevword"
1707 break
1709 esac
1710 prevword=$word
1711 c=$((--c))
1712 done
1714 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1715 while read -r line
1717 case "$line" in
1718 *.*=*)
1719 echo "${line/=*/}"
1721 esac
1722 done
1725 _git_config ()
1727 case "$prev" in
1728 branch.*.remote|branch.*.pushremote)
1729 __gitcomp_nl "$(__git_remotes)"
1730 return
1732 branch.*.merge)
1733 __gitcomp_nl "$(__git_refs)"
1734 return
1736 branch.*.rebase)
1737 __gitcomp "false true"
1738 return
1740 remote.pushdefault)
1741 __gitcomp_nl "$(__git_remotes)"
1742 return
1744 remote.*.fetch)
1745 local remote="${prev#remote.}"
1746 remote="${remote%.fetch}"
1747 if [ -z "$cur" ]; then
1748 __gitcomp_nl "refs/heads/" "" "" ""
1749 return
1751 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1752 return
1754 remote.*.push)
1755 local remote="${prev#remote.}"
1756 remote="${remote%.push}"
1757 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1758 for-each-ref --format='%(refname):%(refname)' \
1759 refs/heads)"
1760 return
1762 pull.twohead|pull.octopus)
1763 __git_compute_merge_strategies
1764 __gitcomp "$__git_merge_strategies"
1765 return
1767 color.branch|color.diff|color.interactive|\
1768 color.showbranch|color.status|color.ui)
1769 __gitcomp "always never auto"
1770 return
1772 color.pager)
1773 __gitcomp "false true"
1774 return
1776 color.*.*)
1777 __gitcomp "
1778 normal black red green yellow blue magenta cyan white
1779 bold dim ul blink reverse
1781 return
1783 diff.submodule)
1784 __gitcomp "log short"
1785 return
1787 help.format)
1788 __gitcomp "man info web html"
1789 return
1791 log.date)
1792 __gitcomp "$__git_log_date_formats"
1793 return
1795 sendemail.aliasesfiletype)
1796 __gitcomp "mutt mailrc pine elm gnus"
1797 return
1799 sendemail.confirm)
1800 __gitcomp "$__git_send_email_confirm_options"
1801 return
1803 sendemail.suppresscc)
1804 __gitcomp "$__git_send_email_suppresscc_options"
1805 return
1807 --get|--get-all|--unset|--unset-all)
1808 __gitcomp_nl "$(__git_config_get_set_variables)"
1809 return
1811 *.*)
1812 return
1814 esac
1815 case "$cur" in
1816 --*)
1817 __gitcomp "
1818 --system --global --local --file=
1819 --list --replace-all
1820 --get --get-all --get-regexp
1821 --add --unset --unset-all
1822 --remove-section --rename-section
1824 return
1826 branch.*.*)
1827 local pfx="${cur%.*}." cur_="${cur##*.}"
1828 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
1829 return
1831 branch.*)
1832 local pfx="${cur%.*}." cur_="${cur#*.}"
1833 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1834 return
1836 guitool.*.*)
1837 local pfx="${cur%.*}." cur_="${cur##*.}"
1838 __gitcomp "
1839 argprompt cmd confirm needsfile noconsole norescan
1840 prompt revprompt revunmerged title
1841 " "$pfx" "$cur_"
1842 return
1844 difftool.*.*)
1845 local pfx="${cur%.*}." cur_="${cur##*.}"
1846 __gitcomp "cmd path" "$pfx" "$cur_"
1847 return
1849 man.*.*)
1850 local pfx="${cur%.*}." cur_="${cur##*.}"
1851 __gitcomp "cmd path" "$pfx" "$cur_"
1852 return
1854 mergetool.*.*)
1855 local pfx="${cur%.*}." cur_="${cur##*.}"
1856 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1857 return
1859 pager.*)
1860 local pfx="${cur%.*}." cur_="${cur#*.}"
1861 __git_compute_all_commands
1862 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1863 return
1865 remote.*.*)
1866 local pfx="${cur%.*}." cur_="${cur##*.}"
1867 __gitcomp "
1868 url proxy fetch push mirror skipDefaultUpdate
1869 receivepack uploadpack tagopt pushurl
1870 " "$pfx" "$cur_"
1871 return
1873 remote.*)
1874 local pfx="${cur%.*}." cur_="${cur#*.}"
1875 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1876 return
1878 url.*.*)
1879 local pfx="${cur%.*}." cur_="${cur##*.}"
1880 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1881 return
1883 esac
1884 __gitcomp "
1885 add.ignoreErrors
1886 advice.commitBeforeMerge
1887 advice.detachedHead
1888 advice.implicitIdentity
1889 advice.pushNonFastForward
1890 advice.resolveConflict
1891 advice.statusHints
1892 alias.
1893 am.keepcr
1894 apply.ignorewhitespace
1895 apply.whitespace
1896 branch.autosetupmerge
1897 branch.autosetuprebase
1898 browser.
1899 clean.requireForce
1900 color.branch
1901 color.branch.current
1902 color.branch.local
1903 color.branch.plain
1904 color.branch.remote
1905 color.decorate.HEAD
1906 color.decorate.branch
1907 color.decorate.remoteBranch
1908 color.decorate.stash
1909 color.decorate.tag
1910 color.diff
1911 color.diff.commit
1912 color.diff.frag
1913 color.diff.func
1914 color.diff.meta
1915 color.diff.new
1916 color.diff.old
1917 color.diff.plain
1918 color.diff.whitespace
1919 color.grep
1920 color.grep.context
1921 color.grep.filename
1922 color.grep.function
1923 color.grep.linenumber
1924 color.grep.match
1925 color.grep.selected
1926 color.grep.separator
1927 color.interactive
1928 color.interactive.error
1929 color.interactive.header
1930 color.interactive.help
1931 color.interactive.prompt
1932 color.pager
1933 color.showbranch
1934 color.status
1935 color.status.added
1936 color.status.changed
1937 color.status.header
1938 color.status.nobranch
1939 color.status.untracked
1940 color.status.updated
1941 color.ui
1942 commit.status
1943 commit.template
1944 core.abbrev
1945 core.askpass
1946 core.attributesfile
1947 core.autocrlf
1948 core.bare
1949 core.bigFileThreshold
1950 core.compression
1951 core.createObject
1952 core.deltaBaseCacheLimit
1953 core.editor
1954 core.eol
1955 core.excludesfile
1956 core.fileMode
1957 core.fsyncobjectfiles
1958 core.gitProxy
1959 core.ignoreStat
1960 core.ignorecase
1961 core.logAllRefUpdates
1962 core.loosecompression
1963 core.notesRef
1964 core.packedGitLimit
1965 core.packedGitWindowSize
1966 core.pager
1967 core.preferSymlinkRefs
1968 core.preloadindex
1969 core.quotepath
1970 core.repositoryFormatVersion
1971 core.safecrlf
1972 core.sharedRepository
1973 core.sparseCheckout
1974 core.symlinks
1975 core.trustctime
1976 core.warnAmbiguousRefs
1977 core.whitespace
1978 core.worktree
1979 diff.autorefreshindex
1980 diff.external
1981 diff.ignoreSubmodules
1982 diff.mnemonicprefix
1983 diff.noprefix
1984 diff.renameLimit
1985 diff.renames
1986 diff.statGraphWidth
1987 diff.submodule
1988 diff.suppressBlankEmpty
1989 diff.tool
1990 diff.wordRegex
1991 diff.algorithm
1992 difftool.
1993 difftool.prompt
1994 fetch.recurseSubmodules
1995 fetch.unpackLimit
1996 format.attach
1997 format.cc
1998 format.headers
1999 format.numbered
2000 format.pretty
2001 format.signature
2002 format.signoff
2003 format.subjectprefix
2004 format.suffix
2005 format.thread
2006 format.to
2008 gc.aggressiveWindow
2009 gc.auto
2010 gc.autopacklimit
2011 gc.packrefs
2012 gc.pruneexpire
2013 gc.reflogexpire
2014 gc.reflogexpireunreachable
2015 gc.rerereresolved
2016 gc.rerereunresolved
2017 gitcvs.allbinary
2018 gitcvs.commitmsgannotation
2019 gitcvs.dbTableNamePrefix
2020 gitcvs.dbdriver
2021 gitcvs.dbname
2022 gitcvs.dbpass
2023 gitcvs.dbuser
2024 gitcvs.enabled
2025 gitcvs.logfile
2026 gitcvs.usecrlfattr
2027 guitool.
2028 gui.blamehistoryctx
2029 gui.commitmsgwidth
2030 gui.copyblamethreshold
2031 gui.diffcontext
2032 gui.encoding
2033 gui.fastcopyblame
2034 gui.matchtrackingbranch
2035 gui.newbranchtemplate
2036 gui.pruneduringfetch
2037 gui.spellingdictionary
2038 gui.trustmtime
2039 help.autocorrect
2040 help.browser
2041 help.format
2042 http.lowSpeedLimit
2043 http.lowSpeedTime
2044 http.maxRequests
2045 http.minSessions
2046 http.noEPSV
2047 http.postBuffer
2048 http.proxy
2049 http.sslCAInfo
2050 http.sslCAPath
2051 http.sslCert
2052 http.sslCertPasswordProtected
2053 http.sslKey
2054 http.sslVerify
2055 http.useragent
2056 i18n.commitEncoding
2057 i18n.logOutputEncoding
2058 imap.authMethod
2059 imap.folder
2060 imap.host
2061 imap.pass
2062 imap.port
2063 imap.preformattedHTML
2064 imap.sslverify
2065 imap.tunnel
2066 imap.user
2067 init.templatedir
2068 instaweb.browser
2069 instaweb.httpd
2070 instaweb.local
2071 instaweb.modulepath
2072 instaweb.port
2073 interactive.singlekey
2074 log.date
2075 log.decorate
2076 log.showroot
2077 mailmap.file
2078 man.
2079 man.viewer
2080 merge.
2081 merge.conflictstyle
2082 merge.log
2083 merge.renameLimit
2084 merge.renormalize
2085 merge.stat
2086 merge.tool
2087 merge.verbosity
2088 mergetool.
2089 mergetool.keepBackup
2090 mergetool.keepTemporaries
2091 mergetool.prompt
2092 notes.displayRef
2093 notes.rewrite.
2094 notes.rewrite.amend
2095 notes.rewrite.rebase
2096 notes.rewriteMode
2097 notes.rewriteRef
2098 pack.compression
2099 pack.deltaCacheLimit
2100 pack.deltaCacheSize
2101 pack.depth
2102 pack.indexVersion
2103 pack.packSizeLimit
2104 pack.threads
2105 pack.window
2106 pack.windowMemory
2107 pager.
2108 pretty.
2109 pull.octopus
2110 pull.twohead
2111 push.default
2112 rebase.autosquash
2113 rebase.stat
2114 receive.autogc
2115 receive.denyCurrentBranch
2116 receive.denyDeleteCurrent
2117 receive.denyDeletes
2118 receive.denyNonFastForwards
2119 receive.fsckObjects
2120 receive.unpackLimit
2121 receive.updateserverinfo
2122 remote.pushdefault
2123 remotes.
2124 repack.usedeltabaseoffset
2125 rerere.autoupdate
2126 rerere.enabled
2127 sendemail.
2128 sendemail.aliasesfile
2129 sendemail.aliasfiletype
2130 sendemail.bcc
2131 sendemail.cc
2132 sendemail.cccmd
2133 sendemail.chainreplyto
2134 sendemail.confirm
2135 sendemail.envelopesender
2136 sendemail.from
2137 sendemail.identity
2138 sendemail.multiedit
2139 sendemail.signedoffbycc
2140 sendemail.smtpdomain
2141 sendemail.smtpencryption
2142 sendemail.smtppass
2143 sendemail.smtpserver
2144 sendemail.smtpserveroption
2145 sendemail.smtpserverport
2146 sendemail.smtpuser
2147 sendemail.suppresscc
2148 sendemail.suppressfrom
2149 sendemail.thread
2150 sendemail.to
2151 sendemail.validate
2152 showbranch.default
2153 status.relativePaths
2154 status.showUntrackedFiles
2155 status.submodulesummary
2156 submodule.
2157 tar.umask
2158 transfer.unpackLimit
2159 url.
2160 user.email
2161 user.name
2162 user.signingkey
2163 web.browser
2164 branch. remote.
2168 _git_remote ()
2170 local subcommands="add rename remove set-head set-branches set-url show prune update"
2171 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2172 if [ -z "$subcommand" ]; then
2173 __gitcomp "$subcommands"
2174 return
2177 case "$subcommand" in
2178 rename|remove|set-url|show|prune)
2179 __gitcomp_nl "$(__git_remotes)"
2181 set-head|set-branches)
2182 __git_complete_remote_or_refspec
2184 update)
2185 local i c='' IFS=$'\n'
2186 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2187 i="${i#remotes.}"
2188 c="$c ${i/ */}"
2189 done
2190 __gitcomp "$c"
2194 esac
2197 _git_replace ()
2199 __gitcomp_nl "$(__git_refs)"
2202 _git_reset ()
2204 __git_has_doubledash && return
2206 case "$cur" in
2207 --*)
2208 __gitcomp "--merge --mixed --hard --soft --patch"
2209 return
2211 esac
2212 __gitcomp_nl "$(__git_refs)"
2215 _git_revert ()
2217 case "$cur" in
2218 --*)
2219 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2220 return
2222 esac
2223 __gitcomp_nl "$(__git_refs)"
2226 _git_rm ()
2228 case "$cur" in
2229 --*)
2230 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2231 return
2233 esac
2235 __git_complete_index_file "--cached"
2238 _git_shortlog ()
2240 __git_has_doubledash && return
2242 case "$cur" in
2243 --*)
2244 __gitcomp "
2245 $__git_log_common_options
2246 $__git_log_shortlog_options
2247 --numbered --summary
2249 return
2251 esac
2252 __git_complete_revlist
2255 _git_show ()
2257 __git_has_doubledash && return
2259 case "$cur" in
2260 --pretty=*|--format=*)
2261 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2262 " "" "${cur#*=}"
2263 return
2265 --diff-algorithm=*)
2266 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2267 return
2269 --*)
2270 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2271 $__git_diff_common_options
2273 return
2275 esac
2276 __git_complete_revlist_file
2279 _git_show_branch ()
2281 case "$cur" in
2282 --*)
2283 __gitcomp "
2284 --all --remotes --topo-order --current --more=
2285 --list --independent --merge-base --no-name
2286 --color --no-color
2287 --sha1-name --sparse --topics --reflog
2289 return
2291 esac
2292 __git_complete_revlist
2295 _git_stash ()
2297 local save_opts='--keep-index --no-keep-index --quiet --patch'
2298 local subcommands='save list show apply clear drop pop create branch'
2299 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2300 if [ -z "$subcommand" ]; then
2301 case "$cur" in
2302 --*)
2303 __gitcomp "$save_opts"
2306 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2307 __gitcomp "$subcommands"
2310 esac
2311 else
2312 case "$subcommand,$cur" in
2313 save,--*)
2314 __gitcomp "$save_opts"
2316 apply,--*|pop,--*)
2317 __gitcomp "--index --quiet"
2319 show,--*|drop,--*|branch,--*)
2321 show,*|apply,*|drop,*|pop,*|branch,*)
2322 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2323 | sed -n -e 's/:.*//p')"
2327 esac
2331 _git_submodule ()
2333 __git_has_doubledash && return
2335 local subcommands="add status init deinit update summary foreach sync"
2336 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2337 case "$cur" in
2338 --*)
2339 __gitcomp "--quiet --cached"
2342 __gitcomp "$subcommands"
2344 esac
2345 return
2349 _git_svn ()
2351 local subcommands="
2352 init fetch clone rebase dcommit log find-rev
2353 set-tree commit-diff info create-ignore propget
2354 proplist show-ignore show-externals branch tag blame
2355 migrate mkdirs reset gc
2357 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2358 if [ -z "$subcommand" ]; then
2359 __gitcomp "$subcommands"
2360 else
2361 local remote_opts="--username= --config-dir= --no-auth-cache"
2362 local fc_opts="
2363 --follow-parent --authors-file= --repack=
2364 --no-metadata --use-svm-props --use-svnsync-props
2365 --log-window-size= --no-checkout --quiet
2366 --repack-flags --use-log-author --localtime
2367 --ignore-paths= --include-paths= $remote_opts
2369 local init_opts="
2370 --template= --shared= --trunk= --tags=
2371 --branches= --stdlayout --minimize-url
2372 --no-metadata --use-svm-props --use-svnsync-props
2373 --rewrite-root= --prefix= --use-log-author
2374 --add-author-from $remote_opts
2376 local cmt_opts="
2377 --edit --rmdir --find-copies-harder --copy-similarity=
2380 case "$subcommand,$cur" in
2381 fetch,--*)
2382 __gitcomp "--revision= --fetch-all $fc_opts"
2384 clone,--*)
2385 __gitcomp "--revision= $fc_opts $init_opts"
2387 init,--*)
2388 __gitcomp "$init_opts"
2390 dcommit,--*)
2391 __gitcomp "
2392 --merge --strategy= --verbose --dry-run
2393 --fetch-all --no-rebase --commit-url
2394 --revision --interactive $cmt_opts $fc_opts
2397 set-tree,--*)
2398 __gitcomp "--stdin $cmt_opts $fc_opts"
2400 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2401 show-externals,--*|mkdirs,--*)
2402 __gitcomp "--revision="
2404 log,--*)
2405 __gitcomp "
2406 --limit= --revision= --verbose --incremental
2407 --oneline --show-commit --non-recursive
2408 --authors-file= --color
2411 rebase,--*)
2412 __gitcomp "
2413 --merge --verbose --strategy= --local
2414 --fetch-all --dry-run $fc_opts
2417 commit-diff,--*)
2418 __gitcomp "--message= --file= --revision= $cmt_opts"
2420 info,--*)
2421 __gitcomp "--url"
2423 branch,--*)
2424 __gitcomp "--dry-run --message --tag"
2426 tag,--*)
2427 __gitcomp "--dry-run --message"
2429 blame,--*)
2430 __gitcomp "--git-format"
2432 migrate,--*)
2433 __gitcomp "
2434 --config-dir= --ignore-paths= --minimize
2435 --no-auth-cache --username=
2438 reset,--*)
2439 __gitcomp "--revision= --parent"
2443 esac
2447 _git_tag ()
2449 local i c=1 f=0
2450 while [ $c -lt $cword ]; do
2451 i="${words[c]}"
2452 case "$i" in
2453 -d|-v)
2454 __gitcomp_nl "$(__git_tags)"
2455 return
2460 esac
2461 ((c++))
2462 done
2464 case "$prev" in
2465 -m|-F)
2467 -*|tag)
2468 if [ $f = 1 ]; then
2469 __gitcomp_nl "$(__git_tags)"
2473 __gitcomp_nl "$(__git_refs)"
2475 esac
2478 _git_whatchanged ()
2480 _git_log
2483 __git_main ()
2485 local i c=1 command __git_dir
2487 while [ $c -lt $cword ]; do
2488 i="${words[c]}"
2489 case "$i" in
2490 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2491 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2492 --bare) __git_dir="." ;;
2493 --help) command="help"; break ;;
2494 -c|--work-tree|--namespace) ((c++)) ;;
2495 -*) ;;
2496 *) command="$i"; break ;;
2497 esac
2498 ((c++))
2499 done
2501 if [ -z "$command" ]; then
2502 case "$cur" in
2503 --*) __gitcomp "
2504 --paginate
2505 --no-pager
2506 --git-dir=
2507 --bare
2508 --version
2509 --exec-path
2510 --exec-path=
2511 --html-path
2512 --man-path
2513 --info-path
2514 --work-tree=
2515 --namespace=
2516 --no-replace-objects
2517 --help
2520 *) __git_compute_porcelain_commands
2521 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2522 esac
2523 return
2526 local completion_func="_git_${command//-/_}"
2527 declare -f $completion_func >/dev/null && $completion_func && return
2529 local expansion=$(__git_aliased_command "$command")
2530 if [ -n "$expansion" ]; then
2531 completion_func="_git_${expansion//-/_}"
2532 declare -f $completion_func >/dev/null && $completion_func
2536 __gitk_main ()
2538 __git_has_doubledash && return
2540 local g="$(__gitdir)"
2541 local merge=""
2542 if [ -f "$g/MERGE_HEAD" ]; then
2543 merge="--merge"
2545 case "$cur" in
2546 --*)
2547 __gitcomp "
2548 $__git_log_common_options
2549 $__git_log_gitk_options
2550 $merge
2552 return
2554 esac
2555 __git_complete_revlist
2558 if [[ -n ${ZSH_VERSION-} ]]; then
2559 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2561 autoload -U +X compinit && compinit
2563 __gitcomp ()
2565 emulate -L zsh
2567 local cur_="${3-$cur}"
2569 case "$cur_" in
2570 --*=)
2573 local c IFS=$' \t\n'
2574 local -a array
2575 for c in ${=1}; do
2576 c="$c${4-}"
2577 case $c in
2578 --*=*|*.) ;;
2579 *) c="$c " ;;
2580 esac
2581 array[${#array[@]}+1]="$c"
2582 done
2583 compset -P '*[=:]'
2584 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2586 esac
2589 __gitcomp_nl ()
2591 emulate -L zsh
2593 local IFS=$'\n'
2594 compset -P '*[=:]'
2595 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2598 __gitcomp_file ()
2600 emulate -L zsh
2602 local IFS=$'\n'
2603 compset -P '*[=:]'
2604 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2607 _git ()
2609 local _ret=1 cur cword prev
2610 cur=${words[CURRENT]}
2611 prev=${words[CURRENT-1]}
2612 let cword=CURRENT-1
2613 emulate ksh -c __${service}_main
2614 let _ret && _default && _ret=0
2615 return _ret
2618 compdef _git git gitk
2619 return
2622 __git_func_wrap ()
2624 local cur words cword prev
2625 _get_comp_words_by_ref -n =: cur words cword prev
2629 # Setup completion for certain functions defined above by setting common
2630 # variables and workarounds.
2631 # This is NOT a public function; use at your own risk.
2632 __git_complete ()
2634 local wrapper="__git_wrap${2}"
2635 eval "$wrapper () { __git_func_wrap $2 ; }"
2636 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2637 || complete -o default -o nospace -F $wrapper $1
2640 # wrapper for backwards compatibility
2641 _git ()
2643 __git_wrap__git_main
2646 # wrapper for backwards compatibility
2647 _gitk ()
2649 __git_wrap__gitk_main
2652 __git_complete git __git_main
2653 __git_complete gitk __gitk_main
2655 # The following are necessary only for Cygwin, and only are needed
2656 # when the user has tab-completed the executable name and consequently
2657 # included the '.exe' suffix.
2659 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2660 __git_complete git.exe __git_main