completion: add more cherry-pick options
[git.git] / contrib / completion / git-completion.bash
blob8ad842e462d4188581c6c12197d9582811a74752
1 #!bash
3 # bash/zsh completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) file paths within current working directory and index
17 # *) common --long-options
19 # To use these routines:
21 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
22 # 2) Add the following line to your .bashrc/.zshrc:
23 # source ~/.git-completion.sh
24 # 3) Consider changing your PS1 to also show the current branch,
25 # see git-prompt.sh for details.
27 case "$COMP_WORDBREAKS" in
28 *:*) : great ;;
29 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
30 esac
32 # __gitdir accepts 0 or 1 arguments (i.e., location)
33 # returns location of .git repo
34 __gitdir ()
36 # Note: this function is duplicated in git-prompt.sh
37 # When updating it, make sure you update the other one to match.
38 if [ -z "${1-}" ]; then
39 if [ -n "${__git_dir-}" ]; then
40 echo "$__git_dir"
41 elif [ -n "${GIT_DIR-}" ]; then
42 test -d "${GIT_DIR-}" || return 1
43 echo "$GIT_DIR"
44 elif [ -d .git ]; then
45 echo .git
46 else
47 git rev-parse --git-dir 2>/dev/null
49 elif [ -d "$1/.git" ]; then
50 echo "$1/.git"
51 else
52 echo "$1"
56 __gitcomp_1 ()
58 local c IFS=$' \t\n'
59 for c in $1; do
60 c="$c$2"
61 case $c in
62 --*=*|*.) ;;
63 *) c="$c " ;;
64 esac
65 printf '%s\n' "$c"
66 done
69 # The following function is based on code from:
71 # bash_completion - programmable completion functions for bash 3.2+
73 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
74 # © 2009-2010, Bash Completion Maintainers
75 # <bash-completion-devel@lists.alioth.debian.org>
77 # This program is free software; you can redistribute it and/or modify
78 # it under the terms of the GNU General Public License as published by
79 # the Free Software Foundation; either version 2, or (at your option)
80 # any later version.
82 # This program is distributed in the hope that it will be useful,
83 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85 # GNU General Public License for more details.
87 # You should have received a copy of the GNU General Public License
88 # along with this program; if not, write to the Free Software Foundation,
89 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
91 # The latest version of this software can be obtained here:
93 # http://bash-completion.alioth.debian.org/
95 # RELEASE: 2.x
97 # This function can be used to access a tokenized list of words
98 # on the command line:
100 # __git_reassemble_comp_words_by_ref '=:'
101 # if test "${words_[cword_-1]}" = -w
102 # then
103 # ...
104 # fi
106 # The argument should be a collection of characters from the list of
107 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
108 # characters.
110 # This is roughly equivalent to going back in time and setting
111 # COMP_WORDBREAKS to exclude those characters. The intent is to
112 # make option types like --date=<type> and <rev>:<path> easy to
113 # recognize by treating each shell word as a single token.
115 # It is best not to set COMP_WORDBREAKS directly because the value is
116 # shared with other completion scripts. By the time the completion
117 # function gets called, COMP_WORDS has already been populated so local
118 # changes to COMP_WORDBREAKS have no effect.
120 # Output: words_, cword_, cur_.
122 __git_reassemble_comp_words_by_ref()
124 local exclude i j first
125 # Which word separators to exclude?
126 exclude="${1//[^$COMP_WORDBREAKS]}"
127 cword_=$COMP_CWORD
128 if [ -z "$exclude" ]; then
129 words_=("${COMP_WORDS[@]}")
130 return
132 # List of word completion separators has shrunk;
133 # re-assemble words to complete.
134 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
135 # Append each nonempty word consisting of just
136 # word separator characters to the current word.
137 first=t
138 while
139 [ $i -gt 0 ] &&
140 [ -n "${COMP_WORDS[$i]}" ] &&
141 # word consists of excluded word separators
142 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
144 # Attach to the previous token,
145 # unless the previous token is the command name.
146 if [ $j -ge 2 ] && [ -n "$first" ]; then
147 ((j--))
149 first=
150 words_[$j]=${words_[j]}${COMP_WORDS[i]}
151 if [ $i = $COMP_CWORD ]; then
152 cword_=$j
154 if (($i < ${#COMP_WORDS[@]} - 1)); then
155 ((i++))
156 else
157 # Done.
158 return
160 done
161 words_[$j]=${words_[j]}${COMP_WORDS[i]}
162 if [ $i = $COMP_CWORD ]; then
163 cword_=$j
165 done
168 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
169 _get_comp_words_by_ref ()
171 local exclude cur_ words_ cword_
172 if [ "$1" = "-n" ]; then
173 exclude=$2
174 shift 2
176 __git_reassemble_comp_words_by_ref "$exclude"
177 cur_=${words_[cword_]}
178 while [ $# -gt 0 ]; do
179 case "$1" in
180 cur)
181 cur=$cur_
183 prev)
184 prev=${words_[$cword_-1]}
186 words)
187 words=("${words_[@]}")
189 cword)
190 cword=$cword_
192 esac
193 shift
194 done
198 # Generates completion reply with compgen, appending a space to possible
199 # completion words, if necessary.
200 # It accepts 1 to 4 arguments:
201 # 1: List of possible completion words.
202 # 2: A prefix to be added to each possible completion word (optional).
203 # 3: Generate possible completion matches for this word (optional).
204 # 4: A suffix to be appended to each possible completion word (optional).
205 __gitcomp ()
207 local cur_="${3-$cur}"
209 case "$cur_" in
210 --*=)
211 COMPREPLY=()
214 local IFS=$'\n'
215 COMPREPLY=($(compgen -P "${2-}" \
216 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
217 -- "$cur_"))
219 esac
222 # Generates completion reply with compgen from newline-separated possible
223 # completion words by appending a space to all of them.
224 # It accepts 1 to 4 arguments:
225 # 1: List of possible completion words, separated by a single newline.
226 # 2: A prefix to be added to each possible completion word (optional).
227 # 3: Generate possible completion matches for this word (optional).
228 # 4: A suffix to be appended to each possible completion word instead of
229 # the default space (optional). If specified but empty, nothing is
230 # appended.
231 __gitcomp_nl ()
233 local IFS=$'\n'
234 COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
237 # Generates completion reply with compgen from newline-separated possible
238 # completion filenames.
239 # It accepts 1 to 3 arguments:
240 # 1: List of possible completion filenames, separated by a single newline.
241 # 2: A directory prefix to be added to each possible completion filename
242 # (optional).
243 # 3: Generate possible completion matches for this word (optional).
244 __gitcomp_file ()
246 local IFS=$'\n'
248 # XXX does not work when the directory prefix contains a tilde,
249 # since tilde expansion is not applied.
250 # This means that COMPREPLY will be empty and Bash default
251 # completion will be used.
252 COMPREPLY=($(compgen -P "${2-}" -W "$1" -- "${3-$cur}"))
254 # Tell Bash that compspec generates filenames.
255 compopt -o filenames 2>/dev/null
258 __git_index_file_list_filter_compat ()
260 local path
262 while read -r path; do
263 case "$path" in
264 ?*/*) echo "${path%%/*}/" ;;
265 *) echo "$path" ;;
266 esac
267 done
270 __git_index_file_list_filter_bash ()
272 local path
274 while read -r path; do
275 case "$path" in
276 ?*/*)
277 # XXX if we append a slash to directory names when using
278 # `compopt -o filenames`, Bash will append another slash.
279 # This is pretty stupid, and this the reason why we have to
280 # define a compatible version for this function.
281 echo "${path%%/*}" ;;
283 echo "$path" ;;
284 esac
285 done
288 # Process path list returned by "ls-files" and "diff-index --name-only"
289 # commands, in order to list only file names relative to a specified
290 # directory, and append a slash to directory names.
291 __git_index_file_list_filter ()
293 # Default to Bash >= 4.x
294 __git_index_file_list_filter_bash
297 # Execute git ls-files, returning paths relative to the directory
298 # specified in the first argument, and using the options specified in
299 # the second argument.
300 __git_ls_files_helper ()
303 test -n "${CDPATH+set}" && unset CDPATH
304 # NOTE: $2 is not quoted in order to support multiple options
305 cd "$1" && git ls-files --exclude-standard $2
306 ) 2>/dev/null
310 # Execute git diff-index, returning paths relative to the directory
311 # specified in the first argument, and using the tree object id
312 # specified in the second argument.
313 __git_diff_index_helper ()
316 test -n "${CDPATH+set}" && unset CDPATH
317 cd "$1" && git diff-index --name-only --relative "$2"
318 ) 2>/dev/null
321 # __git_index_files accepts 1 or 2 arguments:
322 # 1: Options to pass to ls-files (required).
323 # Supported options are --cached, --modified, --deleted, --others,
324 # and --directory.
325 # 2: A directory path (optional).
326 # If provided, only files within the specified directory are listed.
327 # Sub directories are never recursed. Path must have a trailing
328 # slash.
329 __git_index_files ()
331 local dir="$(__gitdir)" root="${2-.}"
333 if [ -d "$dir" ]; then
334 __git_ls_files_helper "$root" "$1" | __git_index_file_list_filter |
335 sort | uniq
339 # __git_diff_index_files accepts 1 or 2 arguments:
340 # 1) The id of a tree object.
341 # 2) A directory path (optional).
342 # If provided, only files within the specified directory are listed.
343 # Sub directories are never recursed. Path must have a trailing
344 # slash.
345 __git_diff_index_files ()
347 local dir="$(__gitdir)" root="${2-.}"
349 if [ -d "$dir" ]; then
350 __git_diff_index_helper "$root" "$1" | __git_index_file_list_filter |
351 sort | uniq
355 __git_heads ()
357 local dir="$(__gitdir)"
358 if [ -d "$dir" ]; then
359 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
360 refs/heads
361 return
365 __git_tags ()
367 local dir="$(__gitdir)"
368 if [ -d "$dir" ]; then
369 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
370 refs/tags
371 return
375 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
376 # presence of 2nd argument means use the guess heuristic employed
377 # by checkout for tracking branches
378 __git_refs ()
380 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
381 local format refs
382 if [ -d "$dir" ]; then
383 case "$cur" in
384 refs|refs/*)
385 format="refname"
386 refs="${cur%/*}"
387 track=""
390 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
391 if [ -e "$dir/$i" ]; then echo $i; fi
392 done
393 format="refname:short"
394 refs="refs/tags refs/heads refs/remotes"
396 esac
397 git --git-dir="$dir" for-each-ref --format="%($format)" \
398 $refs
399 if [ -n "$track" ]; then
400 # employ the heuristic used by git checkout
401 # Try to find a remote branch that matches the completion word
402 # but only output if the branch name is unique
403 local ref entry
404 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
405 "refs/remotes/" | \
406 while read -r entry; do
407 eval "$entry"
408 ref="${ref#*/}"
409 if [[ "$ref" == "$cur"* ]]; then
410 echo "$ref"
412 done | sort | uniq -u
414 return
416 case "$cur" in
417 refs|refs/*)
418 git ls-remote "$dir" "$cur*" 2>/dev/null | \
419 while read -r hash i; do
420 case "$i" in
421 *^{}) ;;
422 *) echo "$i" ;;
423 esac
424 done
427 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
428 while read -r hash i; do
429 case "$i" in
430 *^{}) ;;
431 refs/*) echo "${i#refs/*/}" ;;
432 *) echo "$i" ;;
433 esac
434 done
436 esac
439 # __git_refs2 requires 1 argument (to pass to __git_refs)
440 __git_refs2 ()
442 local i
443 for i in $(__git_refs "$1"); do
444 echo "$i:$i"
445 done
448 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
449 __git_refs_remotes ()
451 local i hash
452 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
453 while read -r hash i; do
454 echo "$i:refs/remotes/$1/${i#refs/heads/}"
455 done
458 __git_remotes ()
460 local i IFS=$'\n' d="$(__gitdir)"
461 test -d "$d/remotes" && ls -1 "$d/remotes"
462 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
463 i="${i#remote.}"
464 echo "${i/.url*/}"
465 done
468 __git_list_merge_strategies ()
470 git merge -s help 2>&1 |
471 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
472 s/\.$//
473 s/.*://
474 s/^[ ]*//
475 s/[ ]*$//
480 __git_merge_strategies=
481 # 'git merge -s help' (and thus detection of the merge strategy
482 # list) fails, unfortunately, if run outside of any git working
483 # tree. __git_merge_strategies is set to the empty string in
484 # that case, and the detection will be repeated the next time it
485 # is needed.
486 __git_compute_merge_strategies ()
488 test -n "$__git_merge_strategies" ||
489 __git_merge_strategies=$(__git_list_merge_strategies)
492 __git_complete_revlist_file ()
494 local pfx ls ref cur_="$cur"
495 case "$cur_" in
496 *..?*:*)
497 return
499 ?*:*)
500 ref="${cur_%%:*}"
501 cur_="${cur_#*:}"
502 case "$cur_" in
503 ?*/*)
504 pfx="${cur_%/*}"
505 cur_="${cur_##*/}"
506 ls="$ref:$pfx"
507 pfx="$pfx/"
510 ls="$ref"
512 esac
514 case "$COMP_WORDBREAKS" in
515 *:*) : great ;;
516 *) pfx="$ref:$pfx" ;;
517 esac
519 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
520 | sed '/^100... blob /{
521 s,^.* ,,
522 s,$, ,
524 /^120000 blob /{
525 s,^.* ,,
526 s,$, ,
528 /^040000 tree /{
529 s,^.* ,,
530 s,$,/,
532 s/^.* //')" \
533 "$pfx" "$cur_" ""
535 *...*)
536 pfx="${cur_%...*}..."
537 cur_="${cur_#*...}"
538 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
540 *..*)
541 pfx="${cur_%..*}.."
542 cur_="${cur_#*..}"
543 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
546 __gitcomp_nl "$(__git_refs)"
548 esac
552 # __git_complete_index_file requires 1 argument: the options to pass to
553 # ls-file
554 __git_complete_index_file ()
556 local pfx cur_="$cur"
558 case "$cur_" in
559 ?*/*)
560 pfx="${cur_%/*}"
561 cur_="${cur_##*/}"
562 pfx="${pfx}/"
564 __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
567 __gitcomp_file "$(__git_index_files "$1")" "" "$cur_"
569 esac
572 # __git_complete_diff_index_file requires 1 argument: the id of a tree
573 # object
574 __git_complete_diff_index_file ()
576 local pfx cur_="$cur"
578 case "$cur_" in
579 ?*/*)
580 pfx="${cur_%/*}"
581 cur_="${cur_##*/}"
582 pfx="${pfx}/"
584 __gitcomp_file "$(__git_diff_index_files "$1" "$pfx")" "$pfx" "$cur_"
587 __gitcomp_file "$(__git_diff_index_files "$1")" "" "$cur_"
589 esac
592 __git_complete_file ()
594 __git_complete_revlist_file
597 __git_complete_revlist ()
599 __git_complete_revlist_file
602 __git_complete_remote_or_refspec ()
604 local cur_="$cur" cmd="${words[1]}"
605 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
606 if [ "$cmd" = "remote" ]; then
607 ((c++))
609 while [ $c -lt $cword ]; do
610 i="${words[c]}"
611 case "$i" in
612 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
613 --all)
614 case "$cmd" in
615 push) no_complete_refspec=1 ;;
616 fetch)
617 COMPREPLY=()
618 return
620 *) ;;
621 esac
623 -*) ;;
624 *) remote="$i"; break ;;
625 esac
626 ((c++))
627 done
628 if [ -z "$remote" ]; then
629 __gitcomp_nl "$(__git_remotes)"
630 return
632 if [ $no_complete_refspec = 1 ]; then
633 COMPREPLY=()
634 return
636 [ "$remote" = "." ] && remote=
637 case "$cur_" in
638 *:*)
639 case "$COMP_WORDBREAKS" in
640 *:*) : great ;;
641 *) pfx="${cur_%%:*}:" ;;
642 esac
643 cur_="${cur_#*:}"
644 lhs=0
647 pfx="+"
648 cur_="${cur_#+}"
650 esac
651 case "$cmd" in
652 fetch)
653 if [ $lhs = 1 ]; then
654 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
655 else
656 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
659 pull|remote)
660 if [ $lhs = 1 ]; then
661 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
662 else
663 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
666 push)
667 if [ $lhs = 1 ]; then
668 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
669 else
670 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
673 esac
676 __git_complete_strategy ()
678 __git_compute_merge_strategies
679 case "$prev" in
680 -s|--strategy)
681 __gitcomp "$__git_merge_strategies"
682 return 0
683 esac
684 case "$cur" in
685 --strategy=*)
686 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
687 return 0
689 esac
690 return 1
693 __git_commands () {
694 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
695 then
696 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
697 else
698 git help -a|egrep '^ [a-zA-Z0-9]'
702 __git_list_all_commands ()
704 local i IFS=" "$'\n'
705 for i in $(__git_commands)
707 case $i in
708 *--*) : helper pattern;;
709 *) echo $i;;
710 esac
711 done
714 __git_all_commands=
715 __git_compute_all_commands ()
717 test -n "$__git_all_commands" ||
718 __git_all_commands=$(__git_list_all_commands)
721 __git_list_porcelain_commands ()
723 local i IFS=" "$'\n'
724 __git_compute_all_commands
725 for i in $__git_all_commands
727 case $i in
728 *--*) : helper pattern;;
729 applymbox) : ask gittus;;
730 applypatch) : ask gittus;;
731 archimport) : import;;
732 cat-file) : plumbing;;
733 check-attr) : plumbing;;
734 check-ignore) : plumbing;;
735 check-ref-format) : plumbing;;
736 checkout-index) : plumbing;;
737 commit-tree) : plumbing;;
738 count-objects) : infrequent;;
739 credential-cache) : credentials helper;;
740 credential-store) : credentials helper;;
741 cvsexportcommit) : export;;
742 cvsimport) : import;;
743 cvsserver) : daemon;;
744 daemon) : daemon;;
745 diff-files) : plumbing;;
746 diff-index) : plumbing;;
747 diff-tree) : plumbing;;
748 fast-import) : import;;
749 fast-export) : export;;
750 fsck-objects) : plumbing;;
751 fetch-pack) : plumbing;;
752 fmt-merge-msg) : plumbing;;
753 for-each-ref) : plumbing;;
754 hash-object) : plumbing;;
755 http-*) : transport;;
756 index-pack) : plumbing;;
757 init-db) : deprecated;;
758 local-fetch) : plumbing;;
759 lost-found) : infrequent;;
760 ls-files) : plumbing;;
761 ls-remote) : plumbing;;
762 ls-tree) : plumbing;;
763 mailinfo) : plumbing;;
764 mailsplit) : plumbing;;
765 merge-*) : plumbing;;
766 mktree) : plumbing;;
767 mktag) : plumbing;;
768 pack-objects) : plumbing;;
769 pack-redundant) : plumbing;;
770 pack-refs) : plumbing;;
771 parse-remote) : plumbing;;
772 patch-id) : plumbing;;
773 peek-remote) : plumbing;;
774 prune) : plumbing;;
775 prune-packed) : plumbing;;
776 quiltimport) : import;;
777 read-tree) : plumbing;;
778 receive-pack) : plumbing;;
779 remote-*) : transport;;
780 repo-config) : deprecated;;
781 rerere) : plumbing;;
782 rev-list) : plumbing;;
783 rev-parse) : plumbing;;
784 runstatus) : plumbing;;
785 sh-setup) : internal;;
786 shell) : daemon;;
787 show-ref) : plumbing;;
788 send-pack) : plumbing;;
789 show-index) : plumbing;;
790 ssh-*) : transport;;
791 stripspace) : plumbing;;
792 symbolic-ref) : plumbing;;
793 tar-tree) : deprecated;;
794 unpack-file) : plumbing;;
795 unpack-objects) : plumbing;;
796 update-index) : plumbing;;
797 update-ref) : plumbing;;
798 update-server-info) : daemon;;
799 upload-archive) : plumbing;;
800 upload-pack) : plumbing;;
801 write-tree) : plumbing;;
802 var) : infrequent;;
803 verify-pack) : infrequent;;
804 verify-tag) : plumbing;;
805 *) echo $i;;
806 esac
807 done
810 __git_porcelain_commands=
811 __git_compute_porcelain_commands ()
813 __git_compute_all_commands
814 test -n "$__git_porcelain_commands" ||
815 __git_porcelain_commands=$(__git_list_porcelain_commands)
818 __git_pretty_aliases ()
820 local i IFS=$'\n'
821 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
822 case "$i" in
823 pretty.*)
824 i="${i#pretty.}"
825 echo "${i/ */}"
827 esac
828 done
831 __git_aliases ()
833 local i IFS=$'\n'
834 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
835 case "$i" in
836 alias.*)
837 i="${i#alias.}"
838 echo "${i/ */}"
840 esac
841 done
844 # __git_aliased_command requires 1 argument
845 __git_aliased_command ()
847 local word cmdline=$(git --git-dir="$(__gitdir)" \
848 config --get "alias.$1")
849 for word in $cmdline; do
850 case "$word" in
851 \!gitk|gitk)
852 echo "gitk"
853 return
855 \!*) : shell command alias ;;
856 -*) : option ;;
857 *=*) : setting env ;;
858 git) : git itself ;;
860 echo "$word"
861 return
862 esac
863 done
866 # __git_find_on_cmdline requires 1 argument
867 __git_find_on_cmdline ()
869 local word subcommand c=1
870 while [ $c -lt $cword ]; do
871 word="${words[c]}"
872 for subcommand in $1; do
873 if [ "$subcommand" = "$word" ]; then
874 echo "$subcommand"
875 return
877 done
878 ((c++))
879 done
882 __git_has_doubledash ()
884 local c=1
885 while [ $c -lt $cword ]; do
886 if [ "--" = "${words[c]}" ]; then
887 return 0
889 ((c++))
890 done
891 return 1
894 # Try to count non option arguments passed on the command line for the
895 # specified git command.
896 # When options are used, it is necessary to use the special -- option to
897 # tell the implementation were non option arguments begin.
898 # XXX this can not be improved, since options can appear everywhere, as
899 # an example:
900 # git mv x -n y
902 # __git_count_arguments requires 1 argument: the git command executed.
903 __git_count_arguments ()
905 local word i c=0
907 # Skip "git" (first argument)
908 for ((i=1; i < ${#words[@]}; i++)); do
909 word="${words[i]}"
911 case "$word" in
913 # Good; we can assume that the following are only non
914 # option arguments.
915 ((c = 0))
917 "$1")
918 # Skip the specified git command and discard git
919 # main options
920 ((c = 0))
923 ((c++))
925 esac
926 done
928 printf "%d" $c
931 __git_whitespacelist="nowarn warn error error-all fix"
933 _git_am ()
935 local dir="$(__gitdir)"
936 if [ -d "$dir"/rebase-apply ]; then
937 __gitcomp "--skip --continue --resolved --abort"
938 return
940 case "$cur" in
941 --whitespace=*)
942 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
943 return
945 --*)
946 __gitcomp "
947 --3way --committer-date-is-author-date --ignore-date
948 --ignore-whitespace --ignore-space-change
949 --interactive --keep --no-utf8 --signoff --utf8
950 --whitespace= --scissors
952 return
953 esac
954 COMPREPLY=()
957 _git_apply ()
959 case "$cur" in
960 --whitespace=*)
961 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
962 return
964 --*)
965 __gitcomp "
966 --stat --numstat --summary --check --index
967 --cached --index-info --reverse --reject --unidiff-zero
968 --apply --no-add --exclude=
969 --ignore-whitespace --ignore-space-change
970 --whitespace= --inaccurate-eof --verbose
972 return
973 esac
974 COMPREPLY=()
977 _git_add ()
979 case "$cur" in
980 --*)
981 __gitcomp "
982 --interactive --refresh --patch --update --dry-run
983 --ignore-errors --intent-to-add
985 return
986 esac
988 # XXX should we check for --update and --all options ?
989 __git_complete_index_file "--others --modified"
992 _git_archive ()
994 case "$cur" in
995 --format=*)
996 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
997 return
999 --remote=*)
1000 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1001 return
1003 --*)
1004 __gitcomp "
1005 --format= --list --verbose
1006 --prefix= --remote= --exec=
1008 return
1010 esac
1011 __git_complete_file
1014 _git_bisect ()
1016 __git_has_doubledash && return
1018 local subcommands="start bad good skip reset visualize replay log run"
1019 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1020 if [ -z "$subcommand" ]; then
1021 if [ -f "$(__gitdir)"/BISECT_START ]; then
1022 __gitcomp "$subcommands"
1023 else
1024 __gitcomp "replay start"
1026 return
1029 case "$subcommand" in
1030 bad|good|reset|skip|start)
1031 __gitcomp_nl "$(__git_refs)"
1034 COMPREPLY=()
1036 esac
1039 _git_branch ()
1041 local i c=1 only_local_ref="n" has_r="n"
1043 while [ $c -lt $cword ]; do
1044 i="${words[c]}"
1045 case "$i" in
1046 -d|-m) only_local_ref="y" ;;
1047 -r) has_r="y" ;;
1048 esac
1049 ((c++))
1050 done
1052 case "$cur" in
1053 --set-upstream-to=*)
1054 __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1056 --*)
1057 __gitcomp "
1058 --color --no-color --verbose --abbrev= --no-abbrev
1059 --track --no-track --contains --merged --no-merged
1060 --set-upstream-to= --edit-description --list
1061 --unset-upstream
1065 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1066 __gitcomp_nl "$(__git_heads)"
1067 else
1068 __gitcomp_nl "$(__git_refs)"
1071 esac
1074 _git_bundle ()
1076 local cmd="${words[2]}"
1077 case "$cword" in
1079 __gitcomp "create list-heads verify unbundle"
1082 # looking for a file
1085 case "$cmd" in
1086 create)
1087 __git_complete_revlist
1089 esac
1091 esac
1094 _git_checkout ()
1096 __git_has_doubledash && return
1098 case "$cur" in
1099 --conflict=*)
1100 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1102 --*)
1103 __gitcomp "
1104 --quiet --ours --theirs --track --no-track --merge
1105 --conflict= --orphan --patch
1109 # check if --track, --no-track, or --no-guess was specified
1110 # if so, disable DWIM mode
1111 local flags="--track --no-track --no-guess" track=1
1112 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1113 track=''
1115 __gitcomp_nl "$(__git_refs '' $track)"
1117 esac
1120 _git_cherry ()
1122 __gitcomp "$(__git_refs)"
1125 _git_cherry_pick ()
1127 local dir="$(__gitdir)"
1128 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1129 __gitcomp "--continue --quit --abort"
1130 return
1132 case "$cur" in
1133 --*)
1134 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1137 __gitcomp_nl "$(__git_refs)"
1139 esac
1142 _git_clean ()
1144 case "$cur" in
1145 --*)
1146 __gitcomp "--dry-run --quiet"
1147 return
1149 esac
1151 # XXX should we check for -x option ?
1152 __git_complete_index_file "--others"
1155 _git_clone ()
1157 case "$cur" in
1158 --*)
1159 __gitcomp "
1160 --local
1161 --no-hardlinks
1162 --shared
1163 --reference
1164 --quiet
1165 --no-checkout
1166 --bare
1167 --mirror
1168 --origin
1169 --upload-pack
1170 --template=
1171 --depth
1172 --single-branch
1173 --branch
1175 return
1177 esac
1178 COMPREPLY=()
1181 _git_commit ()
1183 case "$prev" in
1184 -c|-C)
1185 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1186 return
1188 esac
1190 case "$prev" in
1191 -c|-C)
1192 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1193 return
1195 esac
1197 case "$cur" in
1198 --cleanup=*)
1199 __gitcomp "default strip verbatim whitespace
1200 " "" "${cur##--cleanup=}"
1201 return
1203 --reuse-message=*|--reedit-message=*|\
1204 --fixup=*|--squash=*)
1205 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1206 return
1208 --untracked-files=*)
1209 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1210 return
1212 --*)
1213 __gitcomp "
1214 --all --author= --signoff --verify --no-verify
1215 --edit --no-edit
1216 --amend --include --only --interactive
1217 --dry-run --reuse-message= --reedit-message=
1218 --reset-author --file= --message= --template=
1219 --cleanup= --untracked-files --untracked-files=
1220 --verbose --quiet --fixup= --squash=
1222 return
1223 esac
1225 if git rev-parse --verify --quiet HEAD >/dev/null; then
1226 __git_complete_diff_index_file "HEAD"
1227 else
1228 # This is the first commit
1229 __git_complete_index_file "--cached"
1233 _git_describe ()
1235 case "$cur" in
1236 --*)
1237 __gitcomp "
1238 --all --tags --contains --abbrev= --candidates=
1239 --exact-match --debug --long --match --always
1241 return
1242 esac
1243 __gitcomp_nl "$(__git_refs)"
1246 __git_diff_algorithms="myers minimal patience histogram"
1248 __git_diff_common_options="--stat --numstat --shortstat --summary
1249 --patch-with-stat --name-only --name-status --color
1250 --no-color --color-words --no-renames --check
1251 --full-index --binary --abbrev --diff-filter=
1252 --find-copies-harder
1253 --text --ignore-space-at-eol --ignore-space-change
1254 --ignore-all-space --exit-code --quiet --ext-diff
1255 --no-ext-diff
1256 --no-prefix --src-prefix= --dst-prefix=
1257 --inter-hunk-context=
1258 --patience --histogram --minimal
1259 --raw
1260 --dirstat --dirstat= --dirstat-by-file
1261 --dirstat-by-file= --cumulative
1262 --diff-algorithm=
1265 _git_diff ()
1267 __git_has_doubledash && return
1269 case "$cur" in
1270 --diff-algorithm=*)
1271 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1272 return
1274 --*)
1275 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1276 --base --ours --theirs --no-index
1277 $__git_diff_common_options
1279 return
1281 esac
1282 __git_complete_revlist_file
1285 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1286 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1289 _git_difftool ()
1291 __git_has_doubledash && return
1293 case "$cur" in
1294 --tool=*)
1295 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1296 return
1298 --*)
1299 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1300 --base --ours --theirs
1301 --no-renames --diff-filter= --find-copies-harder
1302 --relative --ignore-submodules
1303 --tool="
1304 return
1306 esac
1307 __git_complete_file
1310 __git_fetch_options="
1311 --quiet --verbose --append --upload-pack --force --keep --depth=
1312 --tags --no-tags --all --prune --dry-run
1315 _git_fetch ()
1317 case "$cur" in
1318 --*)
1319 __gitcomp "$__git_fetch_options"
1320 return
1322 esac
1323 __git_complete_remote_or_refspec
1326 __git_format_patch_options="
1327 --stdout --attach --no-attach --thread --thread= --output-directory
1328 --numbered --start-number --numbered-files --keep-subject --signoff
1329 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1330 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1331 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1334 _git_format_patch ()
1336 case "$cur" in
1337 --thread=*)
1338 __gitcomp "
1339 deep shallow
1340 " "" "${cur##--thread=}"
1341 return
1343 --*)
1344 __gitcomp "$__git_format_patch_options"
1345 return
1347 esac
1348 __git_complete_revlist
1351 _git_fsck ()
1353 case "$cur" in
1354 --*)
1355 __gitcomp "
1356 --tags --root --unreachable --cache --no-reflogs --full
1357 --strict --verbose --lost-found
1359 return
1361 esac
1362 COMPREPLY=()
1365 _git_gc ()
1367 case "$cur" in
1368 --*)
1369 __gitcomp "--prune --aggressive"
1370 return
1372 esac
1373 COMPREPLY=()
1376 _git_gitk ()
1378 _gitk
1381 __git_match_ctag() {
1382 awk "/^${1////\\/}/ { print \$1 }" "$2"
1385 _git_grep ()
1387 __git_has_doubledash && return
1389 case "$cur" in
1390 --*)
1391 __gitcomp "
1392 --cached
1393 --text --ignore-case --word-regexp --invert-match
1394 --full-name --line-number
1395 --extended-regexp --basic-regexp --fixed-strings
1396 --perl-regexp
1397 --files-with-matches --name-only
1398 --files-without-match
1399 --max-depth
1400 --count
1401 --and --or --not --all-match
1403 return
1405 esac
1407 case "$cword,$prev" in
1408 2,*|*,-*)
1409 if test -r tags; then
1410 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1411 return
1414 esac
1416 __gitcomp_nl "$(__git_refs)"
1419 _git_help ()
1421 case "$cur" in
1422 --*)
1423 __gitcomp "--all --info --man --web"
1424 return
1426 esac
1427 __git_compute_all_commands
1428 __gitcomp "$__git_all_commands $(__git_aliases)
1429 attributes cli core-tutorial cvs-migration
1430 diffcore gitk glossary hooks ignore modules
1431 namespaces repository-layout tutorial tutorial-2
1432 workflows
1436 _git_init ()
1438 case "$cur" in
1439 --shared=*)
1440 __gitcomp "
1441 false true umask group all world everybody
1442 " "" "${cur##--shared=}"
1443 return
1445 --*)
1446 __gitcomp "--quiet --bare --template= --shared --shared="
1447 return
1449 esac
1450 COMPREPLY=()
1453 _git_ls_files ()
1455 case "$cur" in
1456 --*)
1457 __gitcomp "--cached --deleted --modified --others --ignored
1458 --stage --directory --no-empty-directory --unmerged
1459 --killed --exclude= --exclude-from=
1460 --exclude-per-directory= --exclude-standard
1461 --error-unmatch --with-tree= --full-name
1462 --abbrev --ignored --exclude-per-directory
1464 return
1466 esac
1468 # XXX ignore options like --modified and always suggest all cached
1469 # files.
1470 __git_complete_index_file "--cached"
1473 _git_ls_remote ()
1475 __gitcomp_nl "$(__git_remotes)"
1478 _git_ls_tree ()
1480 __git_complete_file
1483 # Options that go well for log, shortlog and gitk
1484 __git_log_common_options="
1485 --not --all
1486 --branches --tags --remotes
1487 --first-parent --merges --no-merges
1488 --max-count=
1489 --max-age= --since= --after=
1490 --min-age= --until= --before=
1491 --min-parents= --max-parents=
1492 --no-min-parents --no-max-parents
1494 # Options that go well for log and gitk (not shortlog)
1495 __git_log_gitk_options="
1496 --dense --sparse --full-history
1497 --simplify-merges --simplify-by-decoration
1498 --left-right --notes --no-notes
1500 # Options that go well for log and shortlog (not gitk)
1501 __git_log_shortlog_options="
1502 --author= --committer= --grep=
1503 --all-match
1506 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1507 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1509 _git_log ()
1511 __git_has_doubledash && return
1513 local g="$(git rev-parse --git-dir 2>/dev/null)"
1514 local merge=""
1515 if [ -f "$g/MERGE_HEAD" ]; then
1516 merge="--merge"
1518 case "$cur" in
1519 --pretty=*|--format=*)
1520 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1521 " "" "${cur#*=}"
1522 return
1524 --date=*)
1525 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1526 return
1528 --decorate=*)
1529 __gitcomp "long short" "" "${cur##--decorate=}"
1530 return
1532 --*)
1533 __gitcomp "
1534 $__git_log_common_options
1535 $__git_log_shortlog_options
1536 $__git_log_gitk_options
1537 --root --topo-order --date-order --reverse
1538 --follow --full-diff
1539 --abbrev-commit --abbrev=
1540 --relative-date --date=
1541 --pretty= --format= --oneline
1542 --cherry-pick
1543 --graph
1544 --decorate --decorate=
1545 --walk-reflogs
1546 --parents --children
1547 $merge
1548 $__git_diff_common_options
1549 --pickaxe-all --pickaxe-regex
1551 return
1553 esac
1554 __git_complete_revlist
1557 __git_merge_options="
1558 --no-commit --no-stat --log --no-log --squash --strategy
1559 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1562 _git_merge ()
1564 __git_complete_strategy && return
1566 case "$cur" in
1567 --*)
1568 __gitcomp "$__git_merge_options"
1569 return
1570 esac
1571 __gitcomp_nl "$(__git_refs)"
1574 _git_mergetool ()
1576 case "$cur" in
1577 --tool=*)
1578 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1579 return
1581 --*)
1582 __gitcomp "--tool="
1583 return
1585 esac
1586 COMPREPLY=()
1589 _git_merge_base ()
1591 __gitcomp_nl "$(__git_refs)"
1594 _git_mv ()
1596 case "$cur" in
1597 --*)
1598 __gitcomp "--dry-run"
1599 return
1601 esac
1603 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1604 # We need to show both cached and untracked files (including
1605 # empty directories) since this may not be the last argument.
1606 __git_complete_index_file "--cached --others --directory"
1607 else
1608 __git_complete_index_file "--cached"
1612 _git_name_rev ()
1614 __gitcomp "--tags --all --stdin"
1617 _git_notes ()
1619 local subcommands='add append copy edit list prune remove show'
1620 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1622 case "$subcommand,$cur" in
1623 ,--*)
1624 __gitcomp '--ref'
1627 case "$prev" in
1628 --ref)
1629 __gitcomp_nl "$(__git_refs)"
1632 __gitcomp "$subcommands --ref"
1634 esac
1636 add,--reuse-message=*|append,--reuse-message=*|\
1637 add,--reedit-message=*|append,--reedit-message=*)
1638 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1640 add,--*|append,--*)
1641 __gitcomp '--file= --message= --reedit-message=
1642 --reuse-message='
1644 copy,--*)
1645 __gitcomp '--stdin'
1647 prune,--*)
1648 __gitcomp '--dry-run --verbose'
1650 prune,*)
1653 case "$prev" in
1654 -m|-F)
1657 __gitcomp_nl "$(__git_refs)"
1659 esac
1661 esac
1664 _git_pull ()
1666 __git_complete_strategy && return
1668 case "$cur" in
1669 --*)
1670 __gitcomp "
1671 --rebase --no-rebase
1672 $__git_merge_options
1673 $__git_fetch_options
1675 return
1677 esac
1678 __git_complete_remote_or_refspec
1681 _git_push ()
1683 case "$prev" in
1684 --repo)
1685 __gitcomp_nl "$(__git_remotes)"
1686 return
1687 esac
1688 case "$cur" in
1689 --repo=*)
1690 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1691 return
1693 --*)
1694 __gitcomp "
1695 --all --mirror --tags --dry-run --force --verbose
1696 --receive-pack= --repo= --set-upstream
1698 return
1700 esac
1701 __git_complete_remote_or_refspec
1704 _git_rebase ()
1706 local dir="$(__gitdir)"
1707 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1708 __gitcomp "--continue --skip --abort"
1709 return
1711 __git_complete_strategy && return
1712 case "$cur" in
1713 --whitespace=*)
1714 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1715 return
1717 --*)
1718 __gitcomp "
1719 --onto --merge --strategy --interactive
1720 --preserve-merges --stat --no-stat
1721 --committer-date-is-author-date --ignore-date
1722 --ignore-whitespace --whitespace=
1723 --autosquash
1726 return
1727 esac
1728 __gitcomp_nl "$(__git_refs)"
1731 _git_reflog ()
1733 local subcommands="show delete expire"
1734 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1736 if [ -z "$subcommand" ]; then
1737 __gitcomp "$subcommands"
1738 else
1739 __gitcomp_nl "$(__git_refs)"
1743 __git_send_email_confirm_options="always never auto cc compose"
1744 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1746 _git_send_email ()
1748 case "$cur" in
1749 --confirm=*)
1750 __gitcomp "
1751 $__git_send_email_confirm_options
1752 " "" "${cur##--confirm=}"
1753 return
1755 --suppress-cc=*)
1756 __gitcomp "
1757 $__git_send_email_suppresscc_options
1758 " "" "${cur##--suppress-cc=}"
1760 return
1762 --smtp-encryption=*)
1763 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1764 return
1766 --thread=*)
1767 __gitcomp "
1768 deep shallow
1769 " "" "${cur##--thread=}"
1770 return
1772 --*)
1773 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1774 --compose --confirm= --dry-run --envelope-sender
1775 --from --identity
1776 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1777 --no-suppress-from --no-thread --quiet
1778 --signed-off-by-cc --smtp-pass --smtp-server
1779 --smtp-server-port --smtp-encryption= --smtp-user
1780 --subject --suppress-cc= --suppress-from --thread --to
1781 --validate --no-validate
1782 $__git_format_patch_options"
1783 return
1785 esac
1786 __git_complete_revlist
1789 _git_stage ()
1791 _git_add
1794 __git_config_get_set_variables ()
1796 local prevword word config_file= c=$cword
1797 while [ $c -gt 1 ]; do
1798 word="${words[c]}"
1799 case "$word" in
1800 --system|--global|--local|--file=*)
1801 config_file="$word"
1802 break
1804 -f|--file)
1805 config_file="$word $prevword"
1806 break
1808 esac
1809 prevword=$word
1810 c=$((--c))
1811 done
1813 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1814 while read -r line
1816 case "$line" in
1817 *.*=*)
1818 echo "${line/=*/}"
1820 esac
1821 done
1824 _git_config ()
1826 case "$prev" in
1827 branch.*.remote)
1828 __gitcomp_nl "$(__git_remotes)"
1829 return
1831 branch.*.merge)
1832 __gitcomp_nl "$(__git_refs)"
1833 return
1835 remote.*.fetch)
1836 local remote="${prev#remote.}"
1837 remote="${remote%.fetch}"
1838 if [ -z "$cur" ]; then
1839 COMPREPLY=("refs/heads/")
1840 return
1842 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1843 return
1845 remote.*.push)
1846 local remote="${prev#remote.}"
1847 remote="${remote%.push}"
1848 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1849 for-each-ref --format='%(refname):%(refname)' \
1850 refs/heads)"
1851 return
1853 pull.twohead|pull.octopus)
1854 __git_compute_merge_strategies
1855 __gitcomp "$__git_merge_strategies"
1856 return
1858 color.branch|color.diff|color.interactive|\
1859 color.showbranch|color.status|color.ui)
1860 __gitcomp "always never auto"
1861 return
1863 color.pager)
1864 __gitcomp "false true"
1865 return
1867 color.*.*)
1868 __gitcomp "
1869 normal black red green yellow blue magenta cyan white
1870 bold dim ul blink reverse
1872 return
1874 help.format)
1875 __gitcomp "man info web html"
1876 return
1878 log.date)
1879 __gitcomp "$__git_log_date_formats"
1880 return
1882 sendemail.aliasesfiletype)
1883 __gitcomp "mutt mailrc pine elm gnus"
1884 return
1886 sendemail.confirm)
1887 __gitcomp "$__git_send_email_confirm_options"
1888 return
1890 sendemail.suppresscc)
1891 __gitcomp "$__git_send_email_suppresscc_options"
1892 return
1894 --get|--get-all|--unset|--unset-all)
1895 __gitcomp_nl "$(__git_config_get_set_variables)"
1896 return
1898 *.*)
1899 COMPREPLY=()
1900 return
1902 esac
1903 case "$cur" in
1904 --*)
1905 __gitcomp "
1906 --system --global --local --file=
1907 --list --replace-all
1908 --get --get-all --get-regexp
1909 --add --unset --unset-all
1910 --remove-section --rename-section
1912 return
1914 branch.*.*)
1915 local pfx="${cur%.*}." cur_="${cur##*.}"
1916 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1917 return
1919 branch.*)
1920 local pfx="${cur%.*}." cur_="${cur#*.}"
1921 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1922 return
1924 guitool.*.*)
1925 local pfx="${cur%.*}." cur_="${cur##*.}"
1926 __gitcomp "
1927 argprompt cmd confirm needsfile noconsole norescan
1928 prompt revprompt revunmerged title
1929 " "$pfx" "$cur_"
1930 return
1932 difftool.*.*)
1933 local pfx="${cur%.*}." cur_="${cur##*.}"
1934 __gitcomp "cmd path" "$pfx" "$cur_"
1935 return
1937 man.*.*)
1938 local pfx="${cur%.*}." cur_="${cur##*.}"
1939 __gitcomp "cmd path" "$pfx" "$cur_"
1940 return
1942 mergetool.*.*)
1943 local pfx="${cur%.*}." cur_="${cur##*.}"
1944 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1945 return
1947 pager.*)
1948 local pfx="${cur%.*}." cur_="${cur#*.}"
1949 __git_compute_all_commands
1950 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1951 return
1953 remote.*.*)
1954 local pfx="${cur%.*}." cur_="${cur##*.}"
1955 __gitcomp "
1956 url proxy fetch push mirror skipDefaultUpdate
1957 receivepack uploadpack tagopt pushurl
1958 " "$pfx" "$cur_"
1959 return
1961 remote.*)
1962 local pfx="${cur%.*}." cur_="${cur#*.}"
1963 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1964 return
1966 url.*.*)
1967 local pfx="${cur%.*}." cur_="${cur##*.}"
1968 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1969 return
1971 esac
1972 __gitcomp "
1973 add.ignoreErrors
1974 advice.commitBeforeMerge
1975 advice.detachedHead
1976 advice.implicitIdentity
1977 advice.pushNonFastForward
1978 advice.resolveConflict
1979 advice.statusHints
1980 alias.
1981 am.keepcr
1982 apply.ignorewhitespace
1983 apply.whitespace
1984 branch.autosetupmerge
1985 branch.autosetuprebase
1986 browser.
1987 clean.requireForce
1988 color.branch
1989 color.branch.current
1990 color.branch.local
1991 color.branch.plain
1992 color.branch.remote
1993 color.decorate.HEAD
1994 color.decorate.branch
1995 color.decorate.remoteBranch
1996 color.decorate.stash
1997 color.decorate.tag
1998 color.diff
1999 color.diff.commit
2000 color.diff.frag
2001 color.diff.func
2002 color.diff.meta
2003 color.diff.new
2004 color.diff.old
2005 color.diff.plain
2006 color.diff.whitespace
2007 color.grep
2008 color.grep.context
2009 color.grep.filename
2010 color.grep.function
2011 color.grep.linenumber
2012 color.grep.match
2013 color.grep.selected
2014 color.grep.separator
2015 color.interactive
2016 color.interactive.error
2017 color.interactive.header
2018 color.interactive.help
2019 color.interactive.prompt
2020 color.pager
2021 color.showbranch
2022 color.status
2023 color.status.added
2024 color.status.changed
2025 color.status.header
2026 color.status.nobranch
2027 color.status.untracked
2028 color.status.updated
2029 color.ui
2030 commit.status
2031 commit.template
2032 core.abbrev
2033 core.askpass
2034 core.attributesfile
2035 core.autocrlf
2036 core.bare
2037 core.bigFileThreshold
2038 core.compression
2039 core.createObject
2040 core.deltaBaseCacheLimit
2041 core.editor
2042 core.eol
2043 core.excludesfile
2044 core.fileMode
2045 core.fsyncobjectfiles
2046 core.gitProxy
2047 core.ignoreCygwinFSTricks
2048 core.ignoreStat
2049 core.ignorecase
2050 core.logAllRefUpdates
2051 core.loosecompression
2052 core.notesRef
2053 core.packedGitLimit
2054 core.packedGitWindowSize
2055 core.pager
2056 core.preferSymlinkRefs
2057 core.preloadindex
2058 core.quotepath
2059 core.repositoryFormatVersion
2060 core.safecrlf
2061 core.sharedRepository
2062 core.sparseCheckout
2063 core.symlinks
2064 core.trustctime
2065 core.warnAmbiguousRefs
2066 core.whitespace
2067 core.worktree
2068 diff.autorefreshindex
2069 diff.statGraphWidth
2070 diff.external
2071 diff.ignoreSubmodules
2072 diff.mnemonicprefix
2073 diff.noprefix
2074 diff.renameLimit
2075 diff.renames
2076 diff.suppressBlankEmpty
2077 diff.tool
2078 diff.wordRegex
2079 diff.algorithm
2080 difftool.
2081 difftool.prompt
2082 fetch.recurseSubmodules
2083 fetch.unpackLimit
2084 format.attach
2085 format.cc
2086 format.headers
2087 format.numbered
2088 format.pretty
2089 format.signature
2090 format.signoff
2091 format.subjectprefix
2092 format.suffix
2093 format.thread
2094 format.to
2096 gc.aggressiveWindow
2097 gc.auto
2098 gc.autopacklimit
2099 gc.packrefs
2100 gc.pruneexpire
2101 gc.reflogexpire
2102 gc.reflogexpireunreachable
2103 gc.rerereresolved
2104 gc.rerereunresolved
2105 gitcvs.allbinary
2106 gitcvs.commitmsgannotation
2107 gitcvs.dbTableNamePrefix
2108 gitcvs.dbdriver
2109 gitcvs.dbname
2110 gitcvs.dbpass
2111 gitcvs.dbuser
2112 gitcvs.enabled
2113 gitcvs.logfile
2114 gitcvs.usecrlfattr
2115 guitool.
2116 gui.blamehistoryctx
2117 gui.commitmsgwidth
2118 gui.copyblamethreshold
2119 gui.diffcontext
2120 gui.encoding
2121 gui.fastcopyblame
2122 gui.matchtrackingbranch
2123 gui.newbranchtemplate
2124 gui.pruneduringfetch
2125 gui.spellingdictionary
2126 gui.trustmtime
2127 help.autocorrect
2128 help.browser
2129 help.format
2130 http.lowSpeedLimit
2131 http.lowSpeedTime
2132 http.maxRequests
2133 http.minSessions
2134 http.noEPSV
2135 http.postBuffer
2136 http.proxy
2137 http.sslCAInfo
2138 http.sslCAPath
2139 http.sslCert
2140 http.sslCertPasswordProtected
2141 http.sslKey
2142 http.sslVerify
2143 http.useragent
2144 i18n.commitEncoding
2145 i18n.logOutputEncoding
2146 imap.authMethod
2147 imap.folder
2148 imap.host
2149 imap.pass
2150 imap.port
2151 imap.preformattedHTML
2152 imap.sslverify
2153 imap.tunnel
2154 imap.user
2155 init.templatedir
2156 instaweb.browser
2157 instaweb.httpd
2158 instaweb.local
2159 instaweb.modulepath
2160 instaweb.port
2161 interactive.singlekey
2162 log.date
2163 log.decorate
2164 log.showroot
2165 mailmap.file
2166 man.
2167 man.viewer
2168 merge.
2169 merge.conflictstyle
2170 merge.log
2171 merge.renameLimit
2172 merge.renormalize
2173 merge.stat
2174 merge.tool
2175 merge.verbosity
2176 mergetool.
2177 mergetool.keepBackup
2178 mergetool.keepTemporaries
2179 mergetool.prompt
2180 notes.displayRef
2181 notes.rewrite.
2182 notes.rewrite.amend
2183 notes.rewrite.rebase
2184 notes.rewriteMode
2185 notes.rewriteRef
2186 pack.compression
2187 pack.deltaCacheLimit
2188 pack.deltaCacheSize
2189 pack.depth
2190 pack.indexVersion
2191 pack.packSizeLimit
2192 pack.threads
2193 pack.window
2194 pack.windowMemory
2195 pager.
2196 pretty.
2197 pull.octopus
2198 pull.twohead
2199 push.default
2200 rebase.autosquash
2201 rebase.stat
2202 receive.autogc
2203 receive.denyCurrentBranch
2204 receive.denyDeleteCurrent
2205 receive.denyDeletes
2206 receive.denyNonFastForwards
2207 receive.fsckObjects
2208 receive.unpackLimit
2209 receive.updateserverinfo
2210 remotes.
2211 repack.usedeltabaseoffset
2212 rerere.autoupdate
2213 rerere.enabled
2214 sendemail.
2215 sendemail.aliasesfile
2216 sendemail.aliasfiletype
2217 sendemail.bcc
2218 sendemail.cc
2219 sendemail.cccmd
2220 sendemail.chainreplyto
2221 sendemail.confirm
2222 sendemail.envelopesender
2223 sendemail.from
2224 sendemail.identity
2225 sendemail.multiedit
2226 sendemail.signedoffbycc
2227 sendemail.smtpdomain
2228 sendemail.smtpencryption
2229 sendemail.smtppass
2230 sendemail.smtpserver
2231 sendemail.smtpserveroption
2232 sendemail.smtpserverport
2233 sendemail.smtpuser
2234 sendemail.suppresscc
2235 sendemail.suppressfrom
2236 sendemail.thread
2237 sendemail.to
2238 sendemail.validate
2239 showbranch.default
2240 status.relativePaths
2241 status.showUntrackedFiles
2242 status.submodulesummary
2243 submodule.
2244 tar.umask
2245 transfer.unpackLimit
2246 url.
2247 user.email
2248 user.name
2249 user.signingkey
2250 web.browser
2251 branch. remote.
2255 _git_remote ()
2257 local subcommands="add rename remove set-head set-branches set-url show prune update"
2258 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2259 if [ -z "$subcommand" ]; then
2260 __gitcomp "$subcommands"
2261 return
2264 case "$subcommand" in
2265 rename|remove|set-url|show|prune)
2266 __gitcomp_nl "$(__git_remotes)"
2268 set-head|set-branches)
2269 __git_complete_remote_or_refspec
2271 update)
2272 local i c='' IFS=$'\n'
2273 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2274 i="${i#remotes.}"
2275 c="$c ${i/ */}"
2276 done
2277 __gitcomp "$c"
2280 COMPREPLY=()
2282 esac
2285 _git_replace ()
2287 __gitcomp_nl "$(__git_refs)"
2290 _git_reset ()
2292 __git_has_doubledash && return
2294 case "$cur" in
2295 --*)
2296 __gitcomp "--merge --mixed --hard --soft --patch"
2297 return
2299 esac
2300 __gitcomp_nl "$(__git_refs)"
2303 _git_revert ()
2305 case "$cur" in
2306 --*)
2307 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2308 return
2310 esac
2311 __gitcomp_nl "$(__git_refs)"
2314 _git_rm ()
2316 case "$cur" in
2317 --*)
2318 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2319 return
2321 esac
2323 __git_complete_index_file "--cached"
2326 _git_shortlog ()
2328 __git_has_doubledash && return
2330 case "$cur" in
2331 --*)
2332 __gitcomp "
2333 $__git_log_common_options
2334 $__git_log_shortlog_options
2335 --numbered --summary
2337 return
2339 esac
2340 __git_complete_revlist
2343 _git_show ()
2345 __git_has_doubledash && return
2347 case "$cur" in
2348 --pretty=*|--format=*)
2349 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2350 " "" "${cur#*=}"
2351 return
2353 --diff-algorithm=*)
2354 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2355 return
2357 --*)
2358 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2359 $__git_diff_common_options
2361 return
2363 esac
2364 __git_complete_file
2367 _git_show_branch ()
2369 case "$cur" in
2370 --*)
2371 __gitcomp "
2372 --all --remotes --topo-order --current --more=
2373 --list --independent --merge-base --no-name
2374 --color --no-color
2375 --sha1-name --sparse --topics --reflog
2377 return
2379 esac
2380 __git_complete_revlist
2383 _git_stash ()
2385 local save_opts='--keep-index --no-keep-index --quiet --patch'
2386 local subcommands='save list show apply clear drop pop create branch'
2387 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2388 if [ -z "$subcommand" ]; then
2389 case "$cur" in
2390 --*)
2391 __gitcomp "$save_opts"
2394 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2395 __gitcomp "$subcommands"
2396 else
2397 COMPREPLY=()
2400 esac
2401 else
2402 case "$subcommand,$cur" in
2403 save,--*)
2404 __gitcomp "$save_opts"
2406 apply,--*|pop,--*)
2407 __gitcomp "--index --quiet"
2409 show,--*|drop,--*|branch,--*)
2410 COMPREPLY=()
2412 show,*|apply,*|drop,*|pop,*|branch,*)
2413 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2414 | sed -n -e 's/:.*//p')"
2417 COMPREPLY=()
2419 esac
2423 _git_submodule ()
2425 __git_has_doubledash && return
2427 local subcommands="add status init deinit update summary foreach sync"
2428 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2429 case "$cur" in
2430 --*)
2431 __gitcomp "--quiet --cached"
2434 __gitcomp "$subcommands"
2436 esac
2437 return
2441 _git_svn ()
2443 local subcommands="
2444 init fetch clone rebase dcommit log find-rev
2445 set-tree commit-diff info create-ignore propget
2446 proplist show-ignore show-externals branch tag blame
2447 migrate mkdirs reset gc
2449 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2450 if [ -z "$subcommand" ]; then
2451 __gitcomp "$subcommands"
2452 else
2453 local remote_opts="--username= --config-dir= --no-auth-cache"
2454 local fc_opts="
2455 --follow-parent --authors-file= --repack=
2456 --no-metadata --use-svm-props --use-svnsync-props
2457 --log-window-size= --no-checkout --quiet
2458 --repack-flags --use-log-author --localtime
2459 --ignore-paths= $remote_opts
2461 local init_opts="
2462 --template= --shared= --trunk= --tags=
2463 --branches= --stdlayout --minimize-url
2464 --no-metadata --use-svm-props --use-svnsync-props
2465 --rewrite-root= --prefix= --use-log-author
2466 --add-author-from $remote_opts
2468 local cmt_opts="
2469 --edit --rmdir --find-copies-harder --copy-similarity=
2472 case "$subcommand,$cur" in
2473 fetch,--*)
2474 __gitcomp "--revision= --fetch-all $fc_opts"
2476 clone,--*)
2477 __gitcomp "--revision= $fc_opts $init_opts"
2479 init,--*)
2480 __gitcomp "$init_opts"
2482 dcommit,--*)
2483 __gitcomp "
2484 --merge --strategy= --verbose --dry-run
2485 --fetch-all --no-rebase --commit-url
2486 --revision --interactive $cmt_opts $fc_opts
2489 set-tree,--*)
2490 __gitcomp "--stdin $cmt_opts $fc_opts"
2492 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2493 show-externals,--*|mkdirs,--*)
2494 __gitcomp "--revision="
2496 log,--*)
2497 __gitcomp "
2498 --limit= --revision= --verbose --incremental
2499 --oneline --show-commit --non-recursive
2500 --authors-file= --color
2503 rebase,--*)
2504 __gitcomp "
2505 --merge --verbose --strategy= --local
2506 --fetch-all --dry-run $fc_opts
2509 commit-diff,--*)
2510 __gitcomp "--message= --file= --revision= $cmt_opts"
2512 info,--*)
2513 __gitcomp "--url"
2515 branch,--*)
2516 __gitcomp "--dry-run --message --tag"
2518 tag,--*)
2519 __gitcomp "--dry-run --message"
2521 blame,--*)
2522 __gitcomp "--git-format"
2524 migrate,--*)
2525 __gitcomp "
2526 --config-dir= --ignore-paths= --minimize
2527 --no-auth-cache --username=
2530 reset,--*)
2531 __gitcomp "--revision= --parent"
2534 COMPREPLY=()
2536 esac
2540 _git_tag ()
2542 local i c=1 f=0
2543 while [ $c -lt $cword ]; do
2544 i="${words[c]}"
2545 case "$i" in
2546 -d|-v)
2547 __gitcomp_nl "$(__git_tags)"
2548 return
2553 esac
2554 ((c++))
2555 done
2557 case "$prev" in
2558 -m|-F)
2559 COMPREPLY=()
2561 -*|tag)
2562 if [ $f = 1 ]; then
2563 __gitcomp_nl "$(__git_tags)"
2564 else
2565 COMPREPLY=()
2569 __gitcomp_nl "$(__git_refs)"
2571 esac
2574 _git_whatchanged ()
2576 _git_log
2579 __git_main ()
2581 local i c=1 command __git_dir
2583 while [ $c -lt $cword ]; do
2584 i="${words[c]}"
2585 case "$i" in
2586 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2587 --bare) __git_dir="." ;;
2588 --help) command="help"; break ;;
2589 -c) c=$((++c)) ;;
2590 -*) ;;
2591 *) command="$i"; break ;;
2592 esac
2593 ((c++))
2594 done
2596 if [ -z "$command" ]; then
2597 case "$cur" in
2598 --*) __gitcomp "
2599 --paginate
2600 --no-pager
2601 --git-dir=
2602 --bare
2603 --version
2604 --exec-path
2605 --exec-path=
2606 --html-path
2607 --info-path
2608 --work-tree=
2609 --namespace=
2610 --no-replace-objects
2611 --help
2614 *) __git_compute_porcelain_commands
2615 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2616 esac
2617 return
2620 local completion_func="_git_${command//-/_}"
2621 declare -f $completion_func >/dev/null && $completion_func && return
2623 local expansion=$(__git_aliased_command "$command")
2624 if [ -n "$expansion" ]; then
2625 completion_func="_git_${expansion//-/_}"
2626 declare -f $completion_func >/dev/null && $completion_func
2630 __gitk_main ()
2632 __git_has_doubledash && return
2634 local g="$(__gitdir)"
2635 local merge=""
2636 if [ -f "$g/MERGE_HEAD" ]; then
2637 merge="--merge"
2639 case "$cur" in
2640 --*)
2641 __gitcomp "
2642 $__git_log_common_options
2643 $__git_log_gitk_options
2644 $merge
2646 return
2648 esac
2649 __git_complete_revlist
2652 if [[ -n ${ZSH_VERSION-} ]]; then
2653 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2655 autoload -U +X compinit && compinit
2657 __gitcomp ()
2659 emulate -L zsh
2661 local cur_="${3-$cur}"
2663 case "$cur_" in
2664 --*=)
2667 local c IFS=$' \t\n'
2668 local -a array
2669 for c in ${=1}; do
2670 c="$c${4-}"
2671 case $c in
2672 --*=*|*.) ;;
2673 *) c="$c " ;;
2674 esac
2675 array[$#array+1]="$c"
2676 done
2677 compset -P '*[=:]'
2678 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2680 esac
2683 __gitcomp_nl ()
2685 emulate -L zsh
2687 local IFS=$'\n'
2688 compset -P '*[=:]'
2689 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2692 __gitcomp_file ()
2694 emulate -L zsh
2696 local IFS=$'\n'
2697 compset -P '*[=:]'
2698 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2701 __git_zsh_helper ()
2703 emulate -L ksh
2704 local cur cword prev
2705 cur=${words[CURRENT-1]}
2706 prev=${words[CURRENT-2]}
2707 let cword=CURRENT-1
2708 __${service}_main
2711 _git ()
2713 emulate -L zsh
2714 local _ret=1
2715 __git_zsh_helper
2716 let _ret && _default -S '' && _ret=0
2717 return _ret
2720 compdef _git git gitk
2721 return
2722 elif [[ -n ${BASH_VERSION-} ]]; then
2723 if ((${BASH_VERSINFO[0]} < 4)); then
2724 # compopt is not supported
2725 __git_index_file_list_filter ()
2727 __git_index_file_list_filter_compat
2732 __git_func_wrap ()
2734 local cur words cword prev
2735 _get_comp_words_by_ref -n =: cur words cword prev
2739 # Setup completion for certain functions defined above by setting common
2740 # variables and workarounds.
2741 # This is NOT a public function; use at your own risk.
2742 __git_complete ()
2744 local wrapper="__git_wrap${2}"
2745 eval "$wrapper () { __git_func_wrap $2 ; }"
2746 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2747 || complete -o default -o nospace -F $wrapper $1
2750 # wrapper for backwards compatibility
2751 _git ()
2753 __git_wrap__git_main
2756 # wrapper for backwards compatibility
2757 _gitk ()
2759 __git_wrap__gitk_main
2762 __git_complete git __git_main
2763 __git_complete gitk __gitk_main
2765 # The following are necessary only for Cygwin, and only are needed
2766 # when the user has tab-completed the executable name and consequently
2767 # included the '.exe' suffix.
2769 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2770 __git_complete git.exe __git_main