Ninth batch for 2.13
[git.git] / contrib / completion / git-completion.bash
blobfc32286a43cdece9ea468c4a07c2a8e3d585f1b5
1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 case "$COMP_WORDBREAKS" in
33 *:*) : great ;;
34 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
35 esac
37 # Discovers the path to the git repository taking any '--git-dir=<path>' and
38 # '-C <path>' options into account and stores it in the $__git_repo_path
39 # variable.
40 __git_find_repo_path ()
42 if [ -n "$__git_repo_path" ]; then
43 # we already know where it is
44 return
47 if [ -n "${__git_C_args-}" ]; then
48 __git_repo_path="$(git "${__git_C_args[@]}" \
49 ${__git_dir:+--git-dir="$__git_dir"} \
50 rev-parse --absolute-git-dir 2>/dev/null)"
51 elif [ -n "${__git_dir-}" ]; then
52 test -d "$__git_dir" &&
53 __git_repo_path="$__git_dir"
54 elif [ -n "${GIT_DIR-}" ]; then
55 test -d "${GIT_DIR-}" &&
56 __git_repo_path="$GIT_DIR"
57 elif [ -d .git ]; then
58 __git_repo_path=.git
59 else
60 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
64 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
65 # __gitdir accepts 0 or 1 arguments (i.e., location)
66 # returns location of .git repo
67 __gitdir ()
69 if [ -z "${1-}" ]; then
70 __git_find_repo_path || return 1
71 echo "$__git_repo_path"
72 elif [ -d "$1/.git" ]; then
73 echo "$1/.git"
74 else
75 echo "$1"
79 # Runs git with all the options given as argument, respecting any
80 # '--git-dir=<path>' and '-C <path>' options present on the command line
81 __git ()
83 git ${__git_C_args:+"${__git_C_args[@]}"} \
84 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
87 # The following function is based on code from:
89 # bash_completion - programmable completion functions for bash 3.2+
91 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
92 # © 2009-2010, Bash Completion Maintainers
93 # <bash-completion-devel@lists.alioth.debian.org>
95 # This program is free software; you can redistribute it and/or modify
96 # it under the terms of the GNU General Public License as published by
97 # the Free Software Foundation; either version 2, or (at your option)
98 # any later version.
100 # This program is distributed in the hope that it will be useful,
101 # but WITHOUT ANY WARRANTY; without even the implied warranty of
102 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103 # GNU General Public License for more details.
105 # You should have received a copy of the GNU General Public License
106 # along with this program; if not, write to the Free Software Foundation,
107 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
109 # The latest version of this software can be obtained here:
111 # http://bash-completion.alioth.debian.org/
113 # RELEASE: 2.x
115 # This function can be used to access a tokenized list of words
116 # on the command line:
118 # __git_reassemble_comp_words_by_ref '=:'
119 # if test "${words_[cword_-1]}" = -w
120 # then
121 # ...
122 # fi
124 # The argument should be a collection of characters from the list of
125 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
126 # characters.
128 # This is roughly equivalent to going back in time and setting
129 # COMP_WORDBREAKS to exclude those characters. The intent is to
130 # make option types like --date=<type> and <rev>:<path> easy to
131 # recognize by treating each shell word as a single token.
133 # It is best not to set COMP_WORDBREAKS directly because the value is
134 # shared with other completion scripts. By the time the completion
135 # function gets called, COMP_WORDS has already been populated so local
136 # changes to COMP_WORDBREAKS have no effect.
138 # Output: words_, cword_, cur_.
140 __git_reassemble_comp_words_by_ref()
142 local exclude i j first
143 # Which word separators to exclude?
144 exclude="${1//[^$COMP_WORDBREAKS]}"
145 cword_=$COMP_CWORD
146 if [ -z "$exclude" ]; then
147 words_=("${COMP_WORDS[@]}")
148 return
150 # List of word completion separators has shrunk;
151 # re-assemble words to complete.
152 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
153 # Append each nonempty word consisting of just
154 # word separator characters to the current word.
155 first=t
156 while
157 [ $i -gt 0 ] &&
158 [ -n "${COMP_WORDS[$i]}" ] &&
159 # word consists of excluded word separators
160 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
162 # Attach to the previous token,
163 # unless the previous token is the command name.
164 if [ $j -ge 2 ] && [ -n "$first" ]; then
165 ((j--))
167 first=
168 words_[$j]=${words_[j]}${COMP_WORDS[i]}
169 if [ $i = $COMP_CWORD ]; then
170 cword_=$j
172 if (($i < ${#COMP_WORDS[@]} - 1)); then
173 ((i++))
174 else
175 # Done.
176 return
178 done
179 words_[$j]=${words_[j]}${COMP_WORDS[i]}
180 if [ $i = $COMP_CWORD ]; then
181 cword_=$j
183 done
186 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
187 _get_comp_words_by_ref ()
189 local exclude cur_ words_ cword_
190 if [ "$1" = "-n" ]; then
191 exclude=$2
192 shift 2
194 __git_reassemble_comp_words_by_ref "$exclude"
195 cur_=${words_[cword_]}
196 while [ $# -gt 0 ]; do
197 case "$1" in
198 cur)
199 cur=$cur_
201 prev)
202 prev=${words_[$cword_-1]}
204 words)
205 words=("${words_[@]}")
207 cword)
208 cword=$cword_
210 esac
211 shift
212 done
216 __gitcompappend ()
218 local x i=${#COMPREPLY[@]}
219 for x in $1; do
220 if [[ "$x" == "$3"* ]]; then
221 COMPREPLY[i++]="$2$x$4"
223 done
226 __gitcompadd ()
228 COMPREPLY=()
229 __gitcompappend "$@"
232 # Generates completion reply, appending a space to possible completion words,
233 # if necessary.
234 # It accepts 1 to 4 arguments:
235 # 1: List of possible completion words.
236 # 2: A prefix to be added to each possible completion word (optional).
237 # 3: Generate possible completion matches for this word (optional).
238 # 4: A suffix to be appended to each possible completion word (optional).
239 __gitcomp ()
241 local cur_="${3-$cur}"
243 case "$cur_" in
244 --*=)
247 local c i=0 IFS=$' \t\n'
248 for c in $1; do
249 c="$c${4-}"
250 if [[ $c == "$cur_"* ]]; then
251 case $c in
252 --*=*|*.) ;;
253 *) c="$c " ;;
254 esac
255 COMPREPLY[i++]="${2-}$c"
257 done
259 esac
262 # Variation of __gitcomp_nl () that appends to the existing list of
263 # completion candidates, COMPREPLY.
264 __gitcomp_nl_append ()
266 local IFS=$'\n'
267 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
270 # Generates completion reply from newline-separated possible completion words
271 # by appending a space to all of them.
272 # It accepts 1 to 4 arguments:
273 # 1: List of possible completion words, separated by a single newline.
274 # 2: A prefix to be added to each possible completion word (optional).
275 # 3: Generate possible completion matches for this word (optional).
276 # 4: A suffix to be appended to each possible completion word instead of
277 # the default space (optional). If specified but empty, nothing is
278 # appended.
279 __gitcomp_nl ()
281 COMPREPLY=()
282 __gitcomp_nl_append "$@"
285 # Generates completion reply with compgen from newline-separated possible
286 # completion filenames.
287 # It accepts 1 to 3 arguments:
288 # 1: List of possible completion filenames, separated by a single newline.
289 # 2: A directory prefix to be added to each possible completion filename
290 # (optional).
291 # 3: Generate possible completion matches for this word (optional).
292 __gitcomp_file ()
294 local IFS=$'\n'
296 # XXX does not work when the directory prefix contains a tilde,
297 # since tilde expansion is not applied.
298 # This means that COMPREPLY will be empty and Bash default
299 # completion will be used.
300 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
302 # use a hack to enable file mode in bash < 4
303 compopt -o filenames +o nospace 2>/dev/null ||
304 compgen -f /non-existing-dir/ > /dev/null
307 # Execute 'git ls-files', unless the --committable option is specified, in
308 # which case it runs 'git diff-index' to find out the files that can be
309 # committed. It return paths relative to the directory specified in the first
310 # argument, and using the options specified in the second argument.
311 __git_ls_files_helper ()
313 if [ "$2" == "--committable" ]; then
314 __git -C "$1" diff-index --name-only --relative HEAD
315 else
316 # NOTE: $2 is not quoted in order to support multiple options
317 __git -C "$1" ls-files --exclude-standard $2
322 # __git_index_files accepts 1 or 2 arguments:
323 # 1: Options to pass to ls-files (required).
324 # 2: A directory path (optional).
325 # If provided, only files within the specified directory are listed.
326 # Sub directories are never recursed. Path must have a trailing
327 # slash.
328 __git_index_files ()
330 local root="${2-.}" file
332 __git_ls_files_helper "$root" "$1" |
333 while read -r file; do
334 case "$file" in
335 ?*/*) echo "${file%%/*}" ;;
336 *) echo "$file" ;;
337 esac
338 done | sort | uniq
341 __git_heads ()
343 __git for-each-ref --format='%(refname:short)' refs/heads
346 __git_tags ()
348 __git for-each-ref --format='%(refname:short)' refs/tags
351 # Lists refs from the local (by default) or from a remote repository.
352 # It accepts 0, 1 or 2 arguments:
353 # 1: The remote to list refs from (optional; ignored, if set but empty).
354 # Can be the name of a configured remote, a path, or a URL.
355 # 2: In addition to local refs, list unique branches from refs/remotes/ for
356 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
357 __git_refs ()
359 local i hash dir track="${2-}"
360 local list_refs_from=path remote="${1-}"
361 local format refs pfx
363 __git_find_repo_path
364 dir="$__git_repo_path"
366 if [ -z "$remote" ]; then
367 if [ -z "$dir" ]; then
368 return
370 else
371 if __git_is_configured_remote "$remote"; then
372 # configured remote takes precedence over a
373 # local directory with the same name
374 list_refs_from=remote
375 elif [ -d "$remote/.git" ]; then
376 dir="$remote/.git"
377 elif [ -d "$remote" ]; then
378 dir="$remote"
379 else
380 list_refs_from=url
384 if [ "$list_refs_from" = path ]; then
385 case "$cur" in
386 refs|refs/*)
387 format="refname"
388 refs="${cur%/*}"
389 track=""
392 [[ "$cur" == ^* ]] && pfx="^"
393 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
394 if [ -e "$dir/$i" ]; then echo $pfx$i; fi
395 done
396 format="refname:short"
397 refs="refs/tags refs/heads refs/remotes"
399 esac
400 __git_dir="$dir" __git for-each-ref --format="$pfx%($format)" \
401 $refs
402 if [ -n "$track" ]; then
403 # employ the heuristic used by git checkout
404 # Try to find a remote branch that matches the completion word
405 # but only output if the branch name is unique
406 local ref entry
407 __git for-each-ref --shell --format="ref=%(refname:short)" \
408 "refs/remotes/" | \
409 while read -r entry; do
410 eval "$entry"
411 ref="${ref#*/}"
412 if [[ "$ref" == "$cur"* ]]; then
413 echo "$ref"
415 done | sort | uniq -u
417 return
419 case "$cur" in
420 refs|refs/*)
421 __git ls-remote "$remote" "$cur*" | \
422 while read -r hash i; do
423 case "$i" in
424 *^{}) ;;
425 *) echo "$i" ;;
426 esac
427 done
430 if [ "$list_refs_from" = remote ]; then
431 echo "HEAD"
432 __git for-each-ref --format="%(refname:short)" \
433 "refs/remotes/$remote/" | sed -e "s#^$remote/##"
434 else
435 __git ls-remote "$remote" HEAD \
436 "refs/tags/*" "refs/heads/*" "refs/remotes/*" |
437 while read -r hash i; do
438 case "$i" in
439 *^{}) ;;
440 refs/*) echo "${i#refs/*/}" ;;
441 *) echo "$i" ;; # symbolic refs
442 esac
443 done
446 esac
449 # __git_refs2 requires 1 argument (to pass to __git_refs)
450 __git_refs2 ()
452 local i
453 for i in $(__git_refs "$1"); do
454 echo "$i:$i"
455 done
458 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
459 __git_refs_remotes ()
461 local i hash
462 __git ls-remote "$1" 'refs/heads/*' | \
463 while read -r hash i; do
464 echo "$i:refs/remotes/$1/${i#refs/heads/}"
465 done
468 __git_remotes ()
470 __git_find_repo_path
471 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
472 __git remote
475 # Returns true if $1 matches the name of a configured remote, false otherwise.
476 __git_is_configured_remote ()
478 local remote
479 for remote in $(__git_remotes); do
480 if [ "$remote" = "$1" ]; then
481 return 0
483 done
484 return 1
487 __git_list_merge_strategies ()
489 git merge -s help 2>&1 |
490 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
491 s/\.$//
492 s/.*://
493 s/^[ ]*//
494 s/[ ]*$//
499 __git_merge_strategies=
500 # 'git merge -s help' (and thus detection of the merge strategy
501 # list) fails, unfortunately, if run outside of any git working
502 # tree. __git_merge_strategies is set to the empty string in
503 # that case, and the detection will be repeated the next time it
504 # is needed.
505 __git_compute_merge_strategies ()
507 test -n "$__git_merge_strategies" ||
508 __git_merge_strategies=$(__git_list_merge_strategies)
511 __git_complete_revlist_file ()
513 local pfx ls ref cur_="$cur"
514 case "$cur_" in
515 *..?*:*)
516 return
518 ?*:*)
519 ref="${cur_%%:*}"
520 cur_="${cur_#*:}"
521 case "$cur_" in
522 ?*/*)
523 pfx="${cur_%/*}"
524 cur_="${cur_##*/}"
525 ls="$ref:$pfx"
526 pfx="$pfx/"
529 ls="$ref"
531 esac
533 case "$COMP_WORDBREAKS" in
534 *:*) : great ;;
535 *) pfx="$ref:$pfx" ;;
536 esac
538 __gitcomp_nl "$(__git ls-tree "$ls" \
539 | sed '/^100... blob /{
540 s,^.* ,,
541 s,$, ,
543 /^120000 blob /{
544 s,^.* ,,
545 s,$, ,
547 /^040000 tree /{
548 s,^.* ,,
549 s,$,/,
551 s/^.* //')" \
552 "$pfx" "$cur_" ""
554 *...*)
555 pfx="${cur_%...*}..."
556 cur_="${cur_#*...}"
557 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
559 *..*)
560 pfx="${cur_%..*}.."
561 cur_="${cur_#*..}"
562 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
565 __gitcomp_nl "$(__git_refs)"
567 esac
571 # __git_complete_index_file requires 1 argument:
572 # 1: the options to pass to ls-file
574 # The exception is --committable, which finds the files appropriate commit.
575 __git_complete_index_file ()
577 local pfx="" cur_="$cur"
579 case "$cur_" in
580 ?*/*)
581 pfx="${cur_%/*}"
582 cur_="${cur_##*/}"
583 pfx="${pfx}/"
585 esac
587 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
590 __git_complete_file ()
592 __git_complete_revlist_file
595 __git_complete_revlist ()
597 __git_complete_revlist_file
600 __git_complete_remote_or_refspec ()
602 local cur_="$cur" cmd="${words[1]}"
603 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
604 if [ "$cmd" = "remote" ]; then
605 ((c++))
607 while [ $c -lt $cword ]; do
608 i="${words[c]}"
609 case "$i" in
610 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
611 --all)
612 case "$cmd" in
613 push) no_complete_refspec=1 ;;
614 fetch)
615 return
617 *) ;;
618 esac
620 -*) ;;
621 *) remote="$i"; break ;;
622 esac
623 ((c++))
624 done
625 if [ -z "$remote" ]; then
626 __gitcomp_nl "$(__git_remotes)"
627 return
629 if [ $no_complete_refspec = 1 ]; then
630 return
632 [ "$remote" = "." ] && remote=
633 case "$cur_" in
634 *:*)
635 case "$COMP_WORDBREAKS" in
636 *:*) : great ;;
637 *) pfx="${cur_%%:*}:" ;;
638 esac
639 cur_="${cur_#*:}"
640 lhs=0
643 pfx="+"
644 cur_="${cur_#+}"
646 esac
647 case "$cmd" in
648 fetch)
649 if [ $lhs = 1 ]; then
650 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
651 else
652 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
655 pull|remote)
656 if [ $lhs = 1 ]; then
657 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
658 else
659 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
662 push)
663 if [ $lhs = 1 ]; then
664 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
665 else
666 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
669 esac
672 __git_complete_strategy ()
674 __git_compute_merge_strategies
675 case "$prev" in
676 -s|--strategy)
677 __gitcomp "$__git_merge_strategies"
678 return 0
679 esac
680 case "$cur" in
681 --strategy=*)
682 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
683 return 0
685 esac
686 return 1
689 __git_commands () {
690 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
691 then
692 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
693 else
694 git help -a|egrep '^ [a-zA-Z0-9]'
698 __git_list_all_commands ()
700 local i IFS=" "$'\n'
701 for i in $(__git_commands)
703 case $i in
704 *--*) : helper pattern;;
705 *) echo $i;;
706 esac
707 done
710 __git_all_commands=
711 __git_compute_all_commands ()
713 test -n "$__git_all_commands" ||
714 __git_all_commands=$(__git_list_all_commands)
717 __git_list_porcelain_commands ()
719 local i IFS=" "$'\n'
720 __git_compute_all_commands
721 for i in $__git_all_commands
723 case $i in
724 *--*) : helper pattern;;
725 applymbox) : ask gittus;;
726 applypatch) : ask gittus;;
727 archimport) : import;;
728 cat-file) : plumbing;;
729 check-attr) : plumbing;;
730 check-ignore) : plumbing;;
731 check-mailmap) : plumbing;;
732 check-ref-format) : plumbing;;
733 checkout-index) : plumbing;;
734 column) : internal helper;;
735 commit-tree) : plumbing;;
736 count-objects) : infrequent;;
737 credential) : credentials;;
738 credential-*) : credentials helper;;
739 cvsexportcommit) : export;;
740 cvsimport) : import;;
741 cvsserver) : daemon;;
742 daemon) : daemon;;
743 diff-files) : plumbing;;
744 diff-index) : plumbing;;
745 diff-tree) : plumbing;;
746 fast-import) : import;;
747 fast-export) : export;;
748 fsck-objects) : plumbing;;
749 fetch-pack) : plumbing;;
750 fmt-merge-msg) : plumbing;;
751 for-each-ref) : plumbing;;
752 hash-object) : plumbing;;
753 http-*) : transport;;
754 index-pack) : plumbing;;
755 init-db) : deprecated;;
756 local-fetch) : plumbing;;
757 ls-files) : plumbing;;
758 ls-remote) : plumbing;;
759 ls-tree) : plumbing;;
760 mailinfo) : plumbing;;
761 mailsplit) : plumbing;;
762 merge-*) : plumbing;;
763 mktree) : plumbing;;
764 mktag) : plumbing;;
765 pack-objects) : plumbing;;
766 pack-redundant) : plumbing;;
767 pack-refs) : plumbing;;
768 parse-remote) : plumbing;;
769 patch-id) : plumbing;;
770 prune) : plumbing;;
771 prune-packed) : plumbing;;
772 quiltimport) : import;;
773 read-tree) : plumbing;;
774 receive-pack) : plumbing;;
775 remote-*) : transport;;
776 rerere) : plumbing;;
777 rev-list) : plumbing;;
778 rev-parse) : plumbing;;
779 runstatus) : plumbing;;
780 sh-setup) : internal;;
781 shell) : daemon;;
782 show-ref) : plumbing;;
783 send-pack) : plumbing;;
784 show-index) : plumbing;;
785 ssh-*) : transport;;
786 stripspace) : plumbing;;
787 symbolic-ref) : plumbing;;
788 unpack-file) : plumbing;;
789 unpack-objects) : plumbing;;
790 update-index) : plumbing;;
791 update-ref) : plumbing;;
792 update-server-info) : daemon;;
793 upload-archive) : plumbing;;
794 upload-pack) : plumbing;;
795 write-tree) : plumbing;;
796 var) : infrequent;;
797 verify-pack) : infrequent;;
798 verify-tag) : plumbing;;
799 *) echo $i;;
800 esac
801 done
804 __git_porcelain_commands=
805 __git_compute_porcelain_commands ()
807 test -n "$__git_porcelain_commands" ||
808 __git_porcelain_commands=$(__git_list_porcelain_commands)
811 # Lists all set config variables starting with the given section prefix,
812 # with the prefix removed.
813 __git_get_config_variables ()
815 local section="$1" i IFS=$'\n'
816 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
817 echo "${i#$section.}"
818 done
821 __git_pretty_aliases ()
823 __git_get_config_variables "pretty"
826 __git_aliases ()
828 __git_get_config_variables "alias"
831 # __git_aliased_command requires 1 argument
832 __git_aliased_command ()
834 local word cmdline=$(__git config --get "alias.$1")
835 for word in $cmdline; do
836 case "$word" in
837 \!gitk|gitk)
838 echo "gitk"
839 return
841 \!*) : shell command alias ;;
842 -*) : option ;;
843 *=*) : setting env ;;
844 git) : git itself ;;
845 \(\)) : skip parens of shell function definition ;;
846 {) : skip start of shell helper function ;;
847 :) : skip null command ;;
848 \'*) : skip opening quote after sh -c ;;
850 echo "$word"
851 return
852 esac
853 done
856 # __git_find_on_cmdline requires 1 argument
857 __git_find_on_cmdline ()
859 local word subcommand c=1
860 while [ $c -lt $cword ]; do
861 word="${words[c]}"
862 for subcommand in $1; do
863 if [ "$subcommand" = "$word" ]; then
864 echo "$subcommand"
865 return
867 done
868 ((c++))
869 done
872 # Echo the value of an option set on the command line or config
874 # $1: short option name
875 # $2: long option name including =
876 # $3: list of possible values
877 # $4: config string (optional)
879 # example:
880 # result="$(__git_get_option_value "-d" "--do-something=" \
881 # "yes no" "core.doSomething")"
883 # result is then either empty (no option set) or "yes" or "no"
885 # __git_get_option_value requires 3 arguments
886 __git_get_option_value ()
888 local c short_opt long_opt val
889 local result= values config_key word
891 short_opt="$1"
892 long_opt="$2"
893 values="$3"
894 config_key="$4"
896 ((c = $cword - 1))
897 while [ $c -ge 0 ]; do
898 word="${words[c]}"
899 for val in $values; do
900 if [ "$short_opt$val" = "$word" ] ||
901 [ "$long_opt$val" = "$word" ]; then
902 result="$val"
903 break 2
905 done
906 ((c--))
907 done
909 if [ -n "$config_key" ] && [ -z "$result" ]; then
910 result="$(__git config "$config_key")"
913 echo "$result"
916 __git_has_doubledash ()
918 local c=1
919 while [ $c -lt $cword ]; do
920 if [ "--" = "${words[c]}" ]; then
921 return 0
923 ((c++))
924 done
925 return 1
928 # Try to count non option arguments passed on the command line for the
929 # specified git command.
930 # When options are used, it is necessary to use the special -- option to
931 # tell the implementation were non option arguments begin.
932 # XXX this can not be improved, since options can appear everywhere, as
933 # an example:
934 # git mv x -n y
936 # __git_count_arguments requires 1 argument: the git command executed.
937 __git_count_arguments ()
939 local word i c=0
941 # Skip "git" (first argument)
942 for ((i=1; i < ${#words[@]}; i++)); do
943 word="${words[i]}"
945 case "$word" in
947 # Good; we can assume that the following are only non
948 # option arguments.
949 ((c = 0))
951 "$1")
952 # Skip the specified git command and discard git
953 # main options
954 ((c = 0))
957 ((c++))
959 esac
960 done
962 printf "%d" $c
965 __git_whitespacelist="nowarn warn error error-all fix"
967 _git_am ()
969 __git_find_repo_path
970 if [ -d "$__git_repo_path"/rebase-apply ]; then
971 __gitcomp "--skip --continue --resolved --abort"
972 return
974 case "$cur" in
975 --whitespace=*)
976 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
977 return
979 --*)
980 __gitcomp "
981 --3way --committer-date-is-author-date --ignore-date
982 --ignore-whitespace --ignore-space-change
983 --interactive --keep --no-utf8 --signoff --utf8
984 --whitespace= --scissors
986 return
987 esac
990 _git_apply ()
992 case "$cur" in
993 --whitespace=*)
994 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
995 return
997 --*)
998 __gitcomp "
999 --stat --numstat --summary --check --index
1000 --cached --index-info --reverse --reject --unidiff-zero
1001 --apply --no-add --exclude=
1002 --ignore-whitespace --ignore-space-change
1003 --whitespace= --inaccurate-eof --verbose
1004 --recount --directory=
1006 return
1007 esac
1010 _git_add ()
1012 case "$cur" in
1013 --*)
1014 __gitcomp "
1015 --interactive --refresh --patch --update --dry-run
1016 --ignore-errors --intent-to-add --force --edit --chmod=
1018 return
1019 esac
1021 local complete_opt="--others --modified --directory --no-empty-directory"
1022 if test -n "$(__git_find_on_cmdline "-u --update")"
1023 then
1024 complete_opt="--modified"
1026 __git_complete_index_file "$complete_opt"
1029 _git_archive ()
1031 case "$cur" in
1032 --format=*)
1033 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1034 return
1036 --remote=*)
1037 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1038 return
1040 --*)
1041 __gitcomp "
1042 --format= --list --verbose
1043 --prefix= --remote= --exec= --output
1045 return
1047 esac
1048 __git_complete_file
1051 _git_bisect ()
1053 __git_has_doubledash && return
1055 local subcommands="start bad good skip reset visualize replay log run"
1056 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1057 if [ -z "$subcommand" ]; then
1058 __git_find_repo_path
1059 if [ -f "$__git_repo_path"/BISECT_START ]; then
1060 __gitcomp "$subcommands"
1061 else
1062 __gitcomp "replay start"
1064 return
1067 case "$subcommand" in
1068 bad|good|reset|skip|start)
1069 __gitcomp_nl "$(__git_refs)"
1073 esac
1076 _git_branch ()
1078 local i c=1 only_local_ref="n" has_r="n"
1080 while [ $c -lt $cword ]; do
1081 i="${words[c]}"
1082 case "$i" in
1083 -d|--delete|-m|--move) only_local_ref="y" ;;
1084 -r|--remotes) has_r="y" ;;
1085 esac
1086 ((c++))
1087 done
1089 case "$cur" in
1090 --set-upstream-to=*)
1091 __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1093 --*)
1094 __gitcomp "
1095 --color --no-color --verbose --abbrev= --no-abbrev
1096 --track --no-track --contains --merged --no-merged
1097 --set-upstream-to= --edit-description --list
1098 --unset-upstream --delete --move --remotes
1099 --column --no-column --sort= --points-at
1103 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1104 __gitcomp_nl "$(__git_heads)"
1105 else
1106 __gitcomp_nl "$(__git_refs)"
1109 esac
1112 _git_bundle ()
1114 local cmd="${words[2]}"
1115 case "$cword" in
1117 __gitcomp "create list-heads verify unbundle"
1120 # looking for a file
1123 case "$cmd" in
1124 create)
1125 __git_complete_revlist
1127 esac
1129 esac
1132 _git_checkout ()
1134 __git_has_doubledash && return
1136 case "$cur" in
1137 --conflict=*)
1138 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1140 --*)
1141 __gitcomp "
1142 --quiet --ours --theirs --track --no-track --merge
1143 --conflict= --orphan --patch
1147 # check if --track, --no-track, or --no-guess was specified
1148 # if so, disable DWIM mode
1149 local flags="--track --no-track --no-guess" track=1
1150 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1151 track=''
1153 __gitcomp_nl "$(__git_refs '' $track)"
1155 esac
1158 _git_cherry ()
1160 __gitcomp_nl "$(__git_refs)"
1163 _git_cherry_pick ()
1165 __git_find_repo_path
1166 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1167 __gitcomp "--continue --quit --abort"
1168 return
1170 case "$cur" in
1171 --*)
1172 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1175 __gitcomp_nl "$(__git_refs)"
1177 esac
1180 _git_clean ()
1182 case "$cur" in
1183 --*)
1184 __gitcomp "--dry-run --quiet"
1185 return
1187 esac
1189 # XXX should we check for -x option ?
1190 __git_complete_index_file "--others --directory"
1193 _git_clone ()
1195 case "$cur" in
1196 --*)
1197 __gitcomp "
1198 --local
1199 --no-hardlinks
1200 --shared
1201 --reference
1202 --quiet
1203 --no-checkout
1204 --bare
1205 --mirror
1206 --origin
1207 --upload-pack
1208 --template=
1209 --depth
1210 --single-branch
1211 --branch
1212 --recurse-submodules
1213 --no-single-branch
1214 --shallow-submodules
1216 return
1218 esac
1221 __git_untracked_file_modes="all no normal"
1223 _git_commit ()
1225 case "$prev" in
1226 -c|-C)
1227 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1228 return
1230 esac
1232 case "$cur" in
1233 --cleanup=*)
1234 __gitcomp "default scissors strip verbatim whitespace
1235 " "" "${cur##--cleanup=}"
1236 return
1238 --reuse-message=*|--reedit-message=*|\
1239 --fixup=*|--squash=*)
1240 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1241 return
1243 --untracked-files=*)
1244 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1245 return
1247 --*)
1248 __gitcomp "
1249 --all --author= --signoff --verify --no-verify
1250 --edit --no-edit
1251 --amend --include --only --interactive
1252 --dry-run --reuse-message= --reedit-message=
1253 --reset-author --file= --message= --template=
1254 --cleanup= --untracked-files --untracked-files=
1255 --verbose --quiet --fixup= --squash=
1256 --patch --short --date --allow-empty
1258 return
1259 esac
1261 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1262 __git_complete_index_file "--committable"
1263 else
1264 # This is the first commit
1265 __git_complete_index_file "--cached"
1269 _git_describe ()
1271 case "$cur" in
1272 --*)
1273 __gitcomp "
1274 --all --tags --contains --abbrev= --candidates=
1275 --exact-match --debug --long --match --always --first-parent
1276 --exclude
1278 return
1279 esac
1280 __gitcomp_nl "$(__git_refs)"
1283 __git_diff_algorithms="myers minimal patience histogram"
1285 __git_diff_submodule_formats="diff log short"
1287 __git_diff_common_options="--stat --numstat --shortstat --summary
1288 --patch-with-stat --name-only --name-status --color
1289 --no-color --color-words --no-renames --check
1290 --full-index --binary --abbrev --diff-filter=
1291 --find-copies-harder
1292 --text --ignore-space-at-eol --ignore-space-change
1293 --ignore-all-space --ignore-blank-lines --exit-code
1294 --quiet --ext-diff --no-ext-diff
1295 --no-prefix --src-prefix= --dst-prefix=
1296 --inter-hunk-context=
1297 --patience --histogram --minimal
1298 --raw --word-diff --word-diff-regex=
1299 --dirstat --dirstat= --dirstat-by-file
1300 --dirstat-by-file= --cumulative
1301 --diff-algorithm=
1302 --submodule --submodule=
1305 _git_diff ()
1307 __git_has_doubledash && return
1309 case "$cur" in
1310 --diff-algorithm=*)
1311 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1312 return
1314 --submodule=*)
1315 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1316 return
1318 --*)
1319 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1320 --base --ours --theirs --no-index
1321 $__git_diff_common_options
1323 return
1325 esac
1326 __git_complete_revlist_file
1329 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1330 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1333 _git_difftool ()
1335 __git_has_doubledash && return
1337 case "$cur" in
1338 --tool=*)
1339 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1340 return
1342 --*)
1343 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1344 --base --ours --theirs
1345 --no-renames --diff-filter= --find-copies-harder
1346 --relative --ignore-submodules
1347 --tool="
1348 return
1350 esac
1351 __git_complete_revlist_file
1354 __git_fetch_recurse_submodules="yes on-demand no"
1356 __git_fetch_options="
1357 --quiet --verbose --append --upload-pack --force --keep --depth=
1358 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1359 --unshallow --update-shallow
1362 _git_fetch ()
1364 case "$cur" in
1365 --recurse-submodules=*)
1366 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1367 return
1369 --*)
1370 __gitcomp "$__git_fetch_options"
1371 return
1373 esac
1374 __git_complete_remote_or_refspec
1377 __git_format_patch_options="
1378 --stdout --attach --no-attach --thread --thread= --no-thread
1379 --numbered --start-number --numbered-files --keep-subject --signoff
1380 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1381 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1382 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1383 --output-directory --reroll-count --to= --quiet --notes
1386 _git_format_patch ()
1388 case "$cur" in
1389 --thread=*)
1390 __gitcomp "
1391 deep shallow
1392 " "" "${cur##--thread=}"
1393 return
1395 --*)
1396 __gitcomp "$__git_format_patch_options"
1397 return
1399 esac
1400 __git_complete_revlist
1403 _git_fsck ()
1405 case "$cur" in
1406 --*)
1407 __gitcomp "
1408 --tags --root --unreachable --cache --no-reflogs --full
1409 --strict --verbose --lost-found --name-objects
1411 return
1413 esac
1416 _git_gc ()
1418 case "$cur" in
1419 --*)
1420 __gitcomp "--prune --aggressive"
1421 return
1423 esac
1426 _git_gitk ()
1428 _gitk
1431 __git_match_ctag() {
1432 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1435 _git_grep ()
1437 __git_has_doubledash && return
1439 case "$cur" in
1440 --*)
1441 __gitcomp "
1442 --cached
1443 --text --ignore-case --word-regexp --invert-match
1444 --full-name --line-number
1445 --extended-regexp --basic-regexp --fixed-strings
1446 --perl-regexp
1447 --threads
1448 --files-with-matches --name-only
1449 --files-without-match
1450 --max-depth
1451 --count
1452 --and --or --not --all-match
1453 --break --heading --show-function --function-context
1454 --untracked --no-index
1456 return
1458 esac
1460 case "$cword,$prev" in
1461 2,*|*,-*)
1462 if test -r tags; then
1463 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1464 return
1467 esac
1469 __gitcomp_nl "$(__git_refs)"
1472 _git_help ()
1474 case "$cur" in
1475 --*)
1476 __gitcomp "--all --guides --info --man --web"
1477 return
1479 esac
1480 __git_compute_all_commands
1481 __gitcomp "$__git_all_commands $(__git_aliases)
1482 attributes cli core-tutorial cvs-migration
1483 diffcore everyday gitk glossary hooks ignore modules
1484 namespaces repository-layout revisions tutorial tutorial-2
1485 workflows
1489 _git_init ()
1491 case "$cur" in
1492 --shared=*)
1493 __gitcomp "
1494 false true umask group all world everybody
1495 " "" "${cur##--shared=}"
1496 return
1498 --*)
1499 __gitcomp "--quiet --bare --template= --shared --shared="
1500 return
1502 esac
1505 _git_ls_files ()
1507 case "$cur" in
1508 --*)
1509 __gitcomp "--cached --deleted --modified --others --ignored
1510 --stage --directory --no-empty-directory --unmerged
1511 --killed --exclude= --exclude-from=
1512 --exclude-per-directory= --exclude-standard
1513 --error-unmatch --with-tree= --full-name
1514 --abbrev --ignored --exclude-per-directory
1516 return
1518 esac
1520 # XXX ignore options like --modified and always suggest all cached
1521 # files.
1522 __git_complete_index_file "--cached"
1525 _git_ls_remote ()
1527 case "$cur" in
1528 --*)
1529 __gitcomp "--heads --tags --refs --get-url --symref"
1530 return
1532 esac
1533 __gitcomp_nl "$(__git_remotes)"
1536 _git_ls_tree ()
1538 __git_complete_file
1541 # Options that go well for log, shortlog and gitk
1542 __git_log_common_options="
1543 --not --all
1544 --branches --tags --remotes
1545 --first-parent --merges --no-merges
1546 --max-count=
1547 --max-age= --since= --after=
1548 --min-age= --until= --before=
1549 --min-parents= --max-parents=
1550 --no-min-parents --no-max-parents
1552 # Options that go well for log and gitk (not shortlog)
1553 __git_log_gitk_options="
1554 --dense --sparse --full-history
1555 --simplify-merges --simplify-by-decoration
1556 --left-right --notes --no-notes
1558 # Options that go well for log and shortlog (not gitk)
1559 __git_log_shortlog_options="
1560 --author= --committer= --grep=
1561 --all-match --invert-grep
1564 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1565 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1567 _git_log ()
1569 __git_has_doubledash && return
1570 __git_find_repo_path
1572 local merge=""
1573 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1574 merge="--merge"
1576 case "$cur" in
1577 --pretty=*|--format=*)
1578 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1579 " "" "${cur#*=}"
1580 return
1582 --date=*)
1583 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1584 return
1586 --decorate=*)
1587 __gitcomp "full short no" "" "${cur##--decorate=}"
1588 return
1590 --diff-algorithm=*)
1591 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1592 return
1594 --submodule=*)
1595 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1596 return
1598 --*)
1599 __gitcomp "
1600 $__git_log_common_options
1601 $__git_log_shortlog_options
1602 $__git_log_gitk_options
1603 --root --topo-order --date-order --reverse
1604 --follow --full-diff
1605 --abbrev-commit --abbrev=
1606 --relative-date --date=
1607 --pretty= --format= --oneline
1608 --show-signature
1609 --cherry-mark
1610 --cherry-pick
1611 --graph
1612 --decorate --decorate=
1613 --walk-reflogs
1614 --parents --children
1615 $merge
1616 $__git_diff_common_options
1617 --pickaxe-all --pickaxe-regex
1619 return
1621 esac
1622 __git_complete_revlist
1625 # Common merge options shared by git-merge(1) and git-pull(1).
1626 __git_merge_options="
1627 --no-commit --no-stat --log --no-log --squash --strategy
1628 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1629 --verify-signatures --no-verify-signatures --gpg-sign
1630 --quiet --verbose --progress --no-progress
1633 _git_merge ()
1635 __git_complete_strategy && return
1637 case "$cur" in
1638 --*)
1639 __gitcomp "$__git_merge_options
1640 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1641 return
1642 esac
1643 __gitcomp_nl "$(__git_refs)"
1646 _git_mergetool ()
1648 case "$cur" in
1649 --tool=*)
1650 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1651 return
1653 --*)
1654 __gitcomp "--tool= --prompt --no-prompt"
1655 return
1657 esac
1660 _git_merge_base ()
1662 case "$cur" in
1663 --*)
1664 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1665 return
1667 esac
1668 __gitcomp_nl "$(__git_refs)"
1671 _git_mv ()
1673 case "$cur" in
1674 --*)
1675 __gitcomp "--dry-run"
1676 return
1678 esac
1680 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1681 # We need to show both cached and untracked files (including
1682 # empty directories) since this may not be the last argument.
1683 __git_complete_index_file "--cached --others --directory"
1684 else
1685 __git_complete_index_file "--cached"
1689 _git_name_rev ()
1691 __gitcomp "--tags --all --stdin"
1694 _git_notes ()
1696 local subcommands='add append copy edit list prune remove show'
1697 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1699 case "$subcommand,$cur" in
1700 ,--*)
1701 __gitcomp '--ref'
1704 case "$prev" in
1705 --ref)
1706 __gitcomp_nl "$(__git_refs)"
1709 __gitcomp "$subcommands --ref"
1711 esac
1713 add,--reuse-message=*|append,--reuse-message=*|\
1714 add,--reedit-message=*|append,--reedit-message=*)
1715 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1717 add,--*|append,--*)
1718 __gitcomp '--file= --message= --reedit-message=
1719 --reuse-message='
1721 copy,--*)
1722 __gitcomp '--stdin'
1724 prune,--*)
1725 __gitcomp '--dry-run --verbose'
1727 prune,*)
1730 case "$prev" in
1731 -m|-F)
1734 __gitcomp_nl "$(__git_refs)"
1736 esac
1738 esac
1741 _git_pull ()
1743 __git_complete_strategy && return
1745 case "$cur" in
1746 --recurse-submodules=*)
1747 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1748 return
1750 --*)
1751 __gitcomp "
1752 --rebase --no-rebase
1753 $__git_merge_options
1754 $__git_fetch_options
1756 return
1758 esac
1759 __git_complete_remote_or_refspec
1762 __git_push_recurse_submodules="check on-demand only"
1764 __git_complete_force_with_lease ()
1766 local cur_=$1
1768 case "$cur_" in
1769 --*=)
1771 *:*)
1772 __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
1775 __gitcomp_nl "$(__git_refs)" "" "$cur_"
1777 esac
1780 _git_push ()
1782 case "$prev" in
1783 --repo)
1784 __gitcomp_nl "$(__git_remotes)"
1785 return
1787 --recurse-submodules)
1788 __gitcomp "$__git_push_recurse_submodules"
1789 return
1791 esac
1792 case "$cur" in
1793 --repo=*)
1794 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1795 return
1797 --recurse-submodules=*)
1798 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1799 return
1801 --force-with-lease=*)
1802 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1803 return
1805 --*)
1806 __gitcomp "
1807 --all --mirror --tags --dry-run --force --verbose
1808 --quiet --prune --delete --follow-tags
1809 --receive-pack= --repo= --set-upstream
1810 --force-with-lease --force-with-lease= --recurse-submodules=
1812 return
1814 esac
1815 __git_complete_remote_or_refspec
1818 _git_rebase ()
1820 __git_find_repo_path
1821 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1822 __gitcomp "--continue --skip --abort --quit --edit-todo"
1823 return
1824 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1825 [ -d "$__git_repo_path"/rebase-merge ]; then
1826 __gitcomp "--continue --skip --abort --quit"
1827 return
1829 __git_complete_strategy && return
1830 case "$cur" in
1831 --whitespace=*)
1832 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1833 return
1835 --*)
1836 __gitcomp "
1837 --onto --merge --strategy --interactive
1838 --preserve-merges --stat --no-stat
1839 --committer-date-is-author-date --ignore-date
1840 --ignore-whitespace --whitespace=
1841 --autosquash --no-autosquash
1842 --fork-point --no-fork-point
1843 --autostash --no-autostash
1844 --verify --no-verify
1845 --keep-empty --root --force-rebase --no-ff
1846 --exec
1849 return
1850 esac
1851 __gitcomp_nl "$(__git_refs)"
1854 _git_reflog ()
1856 local subcommands="show delete expire"
1857 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1859 if [ -z "$subcommand" ]; then
1860 __gitcomp "$subcommands"
1861 else
1862 __gitcomp_nl "$(__git_refs)"
1866 __git_send_email_confirm_options="always never auto cc compose"
1867 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1869 _git_send_email ()
1871 case "$prev" in
1872 --to|--cc|--bcc|--from)
1873 __gitcomp "$(__git send-email --dump-aliases)"
1874 return
1876 esac
1878 case "$cur" in
1879 --confirm=*)
1880 __gitcomp "
1881 $__git_send_email_confirm_options
1882 " "" "${cur##--confirm=}"
1883 return
1885 --suppress-cc=*)
1886 __gitcomp "
1887 $__git_send_email_suppresscc_options
1888 " "" "${cur##--suppress-cc=}"
1890 return
1892 --smtp-encryption=*)
1893 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1894 return
1896 --thread=*)
1897 __gitcomp "
1898 deep shallow
1899 " "" "${cur##--thread=}"
1900 return
1902 --to=*|--cc=*|--bcc=*|--from=*)
1903 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
1904 return
1906 --*)
1907 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1908 --compose --confirm= --dry-run --envelope-sender
1909 --from --identity
1910 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1911 --no-suppress-from --no-thread --quiet
1912 --signed-off-by-cc --smtp-pass --smtp-server
1913 --smtp-server-port --smtp-encryption= --smtp-user
1914 --subject --suppress-cc= --suppress-from --thread --to
1915 --validate --no-validate
1916 $__git_format_patch_options"
1917 return
1919 esac
1920 __git_complete_revlist
1923 _git_stage ()
1925 _git_add
1928 _git_status ()
1930 local complete_opt
1931 local untracked_state
1933 case "$cur" in
1934 --ignore-submodules=*)
1935 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1936 return
1938 --untracked-files=*)
1939 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1940 return
1942 --column=*)
1943 __gitcomp "
1944 always never auto column row plain dense nodense
1945 " "" "${cur##--column=}"
1946 return
1948 --*)
1949 __gitcomp "
1950 --short --branch --porcelain --long --verbose
1951 --untracked-files= --ignore-submodules= --ignored
1952 --column= --no-column
1954 return
1956 esac
1958 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1959 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
1961 case "$untracked_state" in
1963 # --ignored option does not matter
1964 complete_opt=
1966 all|normal|*)
1967 complete_opt="--cached --directory --no-empty-directory --others"
1969 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1970 complete_opt="$complete_opt --ignored --exclude=*"
1973 esac
1975 __git_complete_index_file "$complete_opt"
1978 __git_config_get_set_variables ()
1980 local prevword word config_file= c=$cword
1981 while [ $c -gt 1 ]; do
1982 word="${words[c]}"
1983 case "$word" in
1984 --system|--global|--local|--file=*)
1985 config_file="$word"
1986 break
1988 -f|--file)
1989 config_file="$word $prevword"
1990 break
1992 esac
1993 prevword=$word
1994 c=$((--c))
1995 done
1997 __git config $config_file --name-only --list
2000 _git_config ()
2002 case "$prev" in
2003 branch.*.remote|branch.*.pushremote)
2004 __gitcomp_nl "$(__git_remotes)"
2005 return
2007 branch.*.merge)
2008 __gitcomp_nl "$(__git_refs)"
2009 return
2011 branch.*.rebase)
2012 __gitcomp "false true preserve interactive"
2013 return
2015 remote.pushdefault)
2016 __gitcomp_nl "$(__git_remotes)"
2017 return
2019 remote.*.fetch)
2020 local remote="${prev#remote.}"
2021 remote="${remote%.fetch}"
2022 if [ -z "$cur" ]; then
2023 __gitcomp_nl "refs/heads/" "" "" ""
2024 return
2026 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2027 return
2029 remote.*.push)
2030 local remote="${prev#remote.}"
2031 remote="${remote%.push}"
2032 __gitcomp_nl "$(__git for-each-ref \
2033 --format='%(refname):%(refname)' refs/heads)"
2034 return
2036 pull.twohead|pull.octopus)
2037 __git_compute_merge_strategies
2038 __gitcomp "$__git_merge_strategies"
2039 return
2041 color.branch|color.diff|color.interactive|\
2042 color.showbranch|color.status|color.ui)
2043 __gitcomp "always never auto"
2044 return
2046 color.pager)
2047 __gitcomp "false true"
2048 return
2050 color.*.*)
2051 __gitcomp "
2052 normal black red green yellow blue magenta cyan white
2053 bold dim ul blink reverse
2055 return
2057 diff.submodule)
2058 __gitcomp "log short"
2059 return
2061 help.format)
2062 __gitcomp "man info web html"
2063 return
2065 log.date)
2066 __gitcomp "$__git_log_date_formats"
2067 return
2069 sendemail.aliasesfiletype)
2070 __gitcomp "mutt mailrc pine elm gnus"
2071 return
2073 sendemail.confirm)
2074 __gitcomp "$__git_send_email_confirm_options"
2075 return
2077 sendemail.suppresscc)
2078 __gitcomp "$__git_send_email_suppresscc_options"
2079 return
2081 sendemail.transferencoding)
2082 __gitcomp "7bit 8bit quoted-printable base64"
2083 return
2085 --get|--get-all|--unset|--unset-all)
2086 __gitcomp_nl "$(__git_config_get_set_variables)"
2087 return
2089 *.*)
2090 return
2092 esac
2093 case "$cur" in
2094 --*)
2095 __gitcomp "
2096 --system --global --local --file=
2097 --list --replace-all
2098 --get --get-all --get-regexp
2099 --add --unset --unset-all
2100 --remove-section --rename-section
2101 --name-only
2103 return
2105 branch.*.*)
2106 local pfx="${cur%.*}." cur_="${cur##*.}"
2107 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2108 return
2110 branch.*)
2111 local pfx="${cur%.*}." cur_="${cur#*.}"
2112 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
2113 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2114 return
2116 guitool.*.*)
2117 local pfx="${cur%.*}." cur_="${cur##*.}"
2118 __gitcomp "
2119 argprompt cmd confirm needsfile noconsole norescan
2120 prompt revprompt revunmerged title
2121 " "$pfx" "$cur_"
2122 return
2124 difftool.*.*)
2125 local pfx="${cur%.*}." cur_="${cur##*.}"
2126 __gitcomp "cmd path" "$pfx" "$cur_"
2127 return
2129 man.*.*)
2130 local pfx="${cur%.*}." cur_="${cur##*.}"
2131 __gitcomp "cmd path" "$pfx" "$cur_"
2132 return
2134 mergetool.*.*)
2135 local pfx="${cur%.*}." cur_="${cur##*.}"
2136 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2137 return
2139 pager.*)
2140 local pfx="${cur%.*}." cur_="${cur#*.}"
2141 __git_compute_all_commands
2142 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2143 return
2145 remote.*.*)
2146 local pfx="${cur%.*}." cur_="${cur##*.}"
2147 __gitcomp "
2148 url proxy fetch push mirror skipDefaultUpdate
2149 receivepack uploadpack tagopt pushurl
2150 " "$pfx" "$cur_"
2151 return
2153 remote.*)
2154 local pfx="${cur%.*}." cur_="${cur#*.}"
2155 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2156 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2157 return
2159 url.*.*)
2160 local pfx="${cur%.*}." cur_="${cur##*.}"
2161 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2162 return
2164 esac
2165 __gitcomp "
2166 add.ignoreErrors
2167 advice.commitBeforeMerge
2168 advice.detachedHead
2169 advice.implicitIdentity
2170 advice.pushNonFastForward
2171 advice.resolveConflict
2172 advice.statusHints
2173 alias.
2174 am.keepcr
2175 apply.ignorewhitespace
2176 apply.whitespace
2177 branch.autosetupmerge
2178 branch.autosetuprebase
2179 browser.
2180 clean.requireForce
2181 color.branch
2182 color.branch.current
2183 color.branch.local
2184 color.branch.plain
2185 color.branch.remote
2186 color.decorate.HEAD
2187 color.decorate.branch
2188 color.decorate.remoteBranch
2189 color.decorate.stash
2190 color.decorate.tag
2191 color.diff
2192 color.diff.commit
2193 color.diff.frag
2194 color.diff.func
2195 color.diff.meta
2196 color.diff.new
2197 color.diff.old
2198 color.diff.plain
2199 color.diff.whitespace
2200 color.grep
2201 color.grep.context
2202 color.grep.filename
2203 color.grep.function
2204 color.grep.linenumber
2205 color.grep.match
2206 color.grep.selected
2207 color.grep.separator
2208 color.interactive
2209 color.interactive.error
2210 color.interactive.header
2211 color.interactive.help
2212 color.interactive.prompt
2213 color.pager
2214 color.showbranch
2215 color.status
2216 color.status.added
2217 color.status.changed
2218 color.status.header
2219 color.status.nobranch
2220 color.status.unmerged
2221 color.status.untracked
2222 color.status.updated
2223 color.ui
2224 commit.status
2225 commit.template
2226 core.abbrev
2227 core.askpass
2228 core.attributesfile
2229 core.autocrlf
2230 core.bare
2231 core.bigFileThreshold
2232 core.compression
2233 core.createObject
2234 core.deltaBaseCacheLimit
2235 core.editor
2236 core.eol
2237 core.excludesfile
2238 core.fileMode
2239 core.fsyncobjectfiles
2240 core.gitProxy
2241 core.ignoreStat
2242 core.ignorecase
2243 core.logAllRefUpdates
2244 core.loosecompression
2245 core.notesRef
2246 core.packedGitLimit
2247 core.packedGitWindowSize
2248 core.pager
2249 core.preferSymlinkRefs
2250 core.preloadindex
2251 core.quotepath
2252 core.repositoryFormatVersion
2253 core.safecrlf
2254 core.sharedRepository
2255 core.sparseCheckout
2256 core.symlinks
2257 core.trustctime
2258 core.untrackedCache
2259 core.warnAmbiguousRefs
2260 core.whitespace
2261 core.worktree
2262 diff.autorefreshindex
2263 diff.external
2264 diff.ignoreSubmodules
2265 diff.mnemonicprefix
2266 diff.noprefix
2267 diff.renameLimit
2268 diff.renames
2269 diff.statGraphWidth
2270 diff.submodule
2271 diff.suppressBlankEmpty
2272 diff.tool
2273 diff.wordRegex
2274 diff.algorithm
2275 difftool.
2276 difftool.prompt
2277 fetch.recurseSubmodules
2278 fetch.unpackLimit
2279 format.attach
2280 format.cc
2281 format.coverLetter
2282 format.from
2283 format.headers
2284 format.numbered
2285 format.pretty
2286 format.signature
2287 format.signoff
2288 format.subjectprefix
2289 format.suffix
2290 format.thread
2291 format.to
2293 gc.aggressiveWindow
2294 gc.auto
2295 gc.autopacklimit
2296 gc.packrefs
2297 gc.pruneexpire
2298 gc.reflogexpire
2299 gc.reflogexpireunreachable
2300 gc.rerereresolved
2301 gc.rerereunresolved
2302 gitcvs.allbinary
2303 gitcvs.commitmsgannotation
2304 gitcvs.dbTableNamePrefix
2305 gitcvs.dbdriver
2306 gitcvs.dbname
2307 gitcvs.dbpass
2308 gitcvs.dbuser
2309 gitcvs.enabled
2310 gitcvs.logfile
2311 gitcvs.usecrlfattr
2312 guitool.
2313 gui.blamehistoryctx
2314 gui.commitmsgwidth
2315 gui.copyblamethreshold
2316 gui.diffcontext
2317 gui.encoding
2318 gui.fastcopyblame
2319 gui.matchtrackingbranch
2320 gui.newbranchtemplate
2321 gui.pruneduringfetch
2322 gui.spellingdictionary
2323 gui.trustmtime
2324 help.autocorrect
2325 help.browser
2326 help.format
2327 http.lowSpeedLimit
2328 http.lowSpeedTime
2329 http.maxRequests
2330 http.minSessions
2331 http.noEPSV
2332 http.postBuffer
2333 http.proxy
2334 http.sslCipherList
2335 http.sslVersion
2336 http.sslCAInfo
2337 http.sslCAPath
2338 http.sslCert
2339 http.sslCertPasswordProtected
2340 http.sslKey
2341 http.sslVerify
2342 http.useragent
2343 i18n.commitEncoding
2344 i18n.logOutputEncoding
2345 imap.authMethod
2346 imap.folder
2347 imap.host
2348 imap.pass
2349 imap.port
2350 imap.preformattedHTML
2351 imap.sslverify
2352 imap.tunnel
2353 imap.user
2354 init.templatedir
2355 instaweb.browser
2356 instaweb.httpd
2357 instaweb.local
2358 instaweb.modulepath
2359 instaweb.port
2360 interactive.singlekey
2361 log.date
2362 log.decorate
2363 log.showroot
2364 mailmap.file
2365 man.
2366 man.viewer
2367 merge.
2368 merge.conflictstyle
2369 merge.log
2370 merge.renameLimit
2371 merge.renormalize
2372 merge.stat
2373 merge.tool
2374 merge.verbosity
2375 mergetool.
2376 mergetool.keepBackup
2377 mergetool.keepTemporaries
2378 mergetool.prompt
2379 notes.displayRef
2380 notes.rewrite.
2381 notes.rewrite.amend
2382 notes.rewrite.rebase
2383 notes.rewriteMode
2384 notes.rewriteRef
2385 pack.compression
2386 pack.deltaCacheLimit
2387 pack.deltaCacheSize
2388 pack.depth
2389 pack.indexVersion
2390 pack.packSizeLimit
2391 pack.threads
2392 pack.window
2393 pack.windowMemory
2394 pager.
2395 pretty.
2396 pull.octopus
2397 pull.twohead
2398 push.default
2399 push.followTags
2400 rebase.autosquash
2401 rebase.stat
2402 receive.autogc
2403 receive.denyCurrentBranch
2404 receive.denyDeleteCurrent
2405 receive.denyDeletes
2406 receive.denyNonFastForwards
2407 receive.fsckObjects
2408 receive.unpackLimit
2409 receive.updateserverinfo
2410 remote.pushdefault
2411 remotes.
2412 repack.usedeltabaseoffset
2413 rerere.autoupdate
2414 rerere.enabled
2415 sendemail.
2416 sendemail.aliasesfile
2417 sendemail.aliasfiletype
2418 sendemail.bcc
2419 sendemail.cc
2420 sendemail.cccmd
2421 sendemail.chainreplyto
2422 sendemail.confirm
2423 sendemail.envelopesender
2424 sendemail.from
2425 sendemail.identity
2426 sendemail.multiedit
2427 sendemail.signedoffbycc
2428 sendemail.smtpdomain
2429 sendemail.smtpencryption
2430 sendemail.smtppass
2431 sendemail.smtpserver
2432 sendemail.smtpserveroption
2433 sendemail.smtpserverport
2434 sendemail.smtpuser
2435 sendemail.suppresscc
2436 sendemail.suppressfrom
2437 sendemail.thread
2438 sendemail.to
2439 sendemail.validate
2440 showbranch.default
2441 status.relativePaths
2442 status.showUntrackedFiles
2443 status.submodulesummary
2444 submodule.
2445 tar.umask
2446 transfer.unpackLimit
2447 url.
2448 user.email
2449 user.name
2450 user.signingkey
2451 web.browser
2452 branch. remote.
2456 _git_remote ()
2458 local subcommands="
2459 add rename remove set-head set-branches
2460 get-url set-url show prune update
2462 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2463 if [ -z "$subcommand" ]; then
2464 case "$cur" in
2465 --*)
2466 __gitcomp "--verbose"
2469 __gitcomp "$subcommands"
2471 esac
2472 return
2475 case "$subcommand,$cur" in
2476 add,--*)
2477 __gitcomp "--track --master --fetch --tags --no-tags --mirror="
2479 add,*)
2481 set-head,--*)
2482 __gitcomp "--auto --delete"
2484 set-branches,--*)
2485 __gitcomp "--add"
2487 set-head,*|set-branches,*)
2488 __git_complete_remote_or_refspec
2490 update,--*)
2491 __gitcomp "--prune"
2493 update,*)
2494 __gitcomp "$(__git_get_config_variables "remotes")"
2496 set-url,--*)
2497 __gitcomp "--push --add --delete"
2499 get-url,--*)
2500 __gitcomp "--push --all"
2502 prune,--*)
2503 __gitcomp "--dry-run"
2506 __gitcomp_nl "$(__git_remotes)"
2508 esac
2511 _git_replace ()
2513 case "$cur" in
2514 --*)
2515 __gitcomp "--edit --graft --format= --list --delete"
2516 return
2518 esac
2519 __gitcomp_nl "$(__git_refs)"
2522 _git_rerere ()
2524 local subcommands="clear forget diff remaining status gc"
2525 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2526 if test -z "$subcommand"
2527 then
2528 __gitcomp "$subcommands"
2529 return
2533 _git_reset ()
2535 __git_has_doubledash && return
2537 case "$cur" in
2538 --*)
2539 __gitcomp "--merge --mixed --hard --soft --patch --keep"
2540 return
2542 esac
2543 __gitcomp_nl "$(__git_refs)"
2546 _git_revert ()
2548 __git_find_repo_path
2549 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2550 __gitcomp "--continue --quit --abort"
2551 return
2553 case "$cur" in
2554 --*)
2555 __gitcomp "
2556 --edit --mainline --no-edit --no-commit --signoff
2557 --strategy= --strategy-option=
2559 return
2561 esac
2562 __gitcomp_nl "$(__git_refs)"
2565 _git_rm ()
2567 case "$cur" in
2568 --*)
2569 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2570 return
2572 esac
2574 __git_complete_index_file "--cached"
2577 _git_shortlog ()
2579 __git_has_doubledash && return
2581 case "$cur" in
2582 --*)
2583 __gitcomp "
2584 $__git_log_common_options
2585 $__git_log_shortlog_options
2586 --numbered --summary --email
2588 return
2590 esac
2591 __git_complete_revlist
2594 _git_show ()
2596 __git_has_doubledash && return
2598 case "$cur" in
2599 --pretty=*|--format=*)
2600 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2601 " "" "${cur#*=}"
2602 return
2604 --diff-algorithm=*)
2605 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2606 return
2608 --submodule=*)
2609 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2610 return
2612 --*)
2613 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2614 --show-signature
2615 $__git_diff_common_options
2617 return
2619 esac
2620 __git_complete_revlist_file
2623 _git_show_branch ()
2625 case "$cur" in
2626 --*)
2627 __gitcomp "
2628 --all --remotes --topo-order --date-order --current --more=
2629 --list --independent --merge-base --no-name
2630 --color --no-color
2631 --sha1-name --sparse --topics --reflog
2633 return
2635 esac
2636 __git_complete_revlist
2639 _git_stash ()
2641 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2642 local subcommands='save list show apply clear drop pop create branch'
2643 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2644 if [ -z "$subcommand" ]; then
2645 case "$cur" in
2646 --*)
2647 __gitcomp "$save_opts"
2650 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2651 __gitcomp "$subcommands"
2654 esac
2655 else
2656 case "$subcommand,$cur" in
2657 save,--*)
2658 __gitcomp "$save_opts"
2660 apply,--*|pop,--*)
2661 __gitcomp "--index --quiet"
2663 drop,--*)
2664 __gitcomp "--quiet"
2666 show,--*|branch,--*)
2668 branch,*)
2669 if [ $cword -eq 3 ]; then
2670 __gitcomp_nl "$(__git_refs)";
2671 else
2672 __gitcomp_nl "$(__git stash list \
2673 | sed -n -e 's/:.*//p')"
2676 show,*|apply,*|drop,*|pop,*)
2677 __gitcomp_nl "$(__git stash list \
2678 | sed -n -e 's/:.*//p')"
2682 esac
2686 _git_submodule ()
2688 __git_has_doubledash && return
2690 local subcommands="add status init deinit update summary foreach sync"
2691 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2692 if [ -z "$subcommand" ]; then
2693 case "$cur" in
2694 --*)
2695 __gitcomp "--quiet"
2698 __gitcomp "$subcommands"
2700 esac
2701 return
2704 case "$subcommand,$cur" in
2705 add,--*)
2706 __gitcomp "--branch --force --name --reference --depth"
2708 status,--*)
2709 __gitcomp "--cached --recursive"
2711 deinit,--*)
2712 __gitcomp "--force --all"
2714 update,--*)
2715 __gitcomp "
2716 --init --remote --no-fetch
2717 --recommend-shallow --no-recommend-shallow
2718 --force --rebase --merge --reference --depth --recursive --jobs
2721 summary,--*)
2722 __gitcomp "--cached --files --summary-limit"
2724 foreach,--*|sync,--*)
2725 __gitcomp "--recursive"
2729 esac
2732 _git_svn ()
2734 local subcommands="
2735 init fetch clone rebase dcommit log find-rev
2736 set-tree commit-diff info create-ignore propget
2737 proplist show-ignore show-externals branch tag blame
2738 migrate mkdirs reset gc
2740 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2741 if [ -z "$subcommand" ]; then
2742 __gitcomp "$subcommands"
2743 else
2744 local remote_opts="--username= --config-dir= --no-auth-cache"
2745 local fc_opts="
2746 --follow-parent --authors-file= --repack=
2747 --no-metadata --use-svm-props --use-svnsync-props
2748 --log-window-size= --no-checkout --quiet
2749 --repack-flags --use-log-author --localtime
2750 --add-author-from
2751 --ignore-paths= --include-paths= $remote_opts
2753 local init_opts="
2754 --template= --shared= --trunk= --tags=
2755 --branches= --stdlayout --minimize-url
2756 --no-metadata --use-svm-props --use-svnsync-props
2757 --rewrite-root= --prefix= $remote_opts
2759 local cmt_opts="
2760 --edit --rmdir --find-copies-harder --copy-similarity=
2763 case "$subcommand,$cur" in
2764 fetch,--*)
2765 __gitcomp "--revision= --fetch-all $fc_opts"
2767 clone,--*)
2768 __gitcomp "--revision= $fc_opts $init_opts"
2770 init,--*)
2771 __gitcomp "$init_opts"
2773 dcommit,--*)
2774 __gitcomp "
2775 --merge --strategy= --verbose --dry-run
2776 --fetch-all --no-rebase --commit-url
2777 --revision --interactive $cmt_opts $fc_opts
2780 set-tree,--*)
2781 __gitcomp "--stdin $cmt_opts $fc_opts"
2783 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2784 show-externals,--*|mkdirs,--*)
2785 __gitcomp "--revision="
2787 log,--*)
2788 __gitcomp "
2789 --limit= --revision= --verbose --incremental
2790 --oneline --show-commit --non-recursive
2791 --authors-file= --color
2794 rebase,--*)
2795 __gitcomp "
2796 --merge --verbose --strategy= --local
2797 --fetch-all --dry-run $fc_opts
2800 commit-diff,--*)
2801 __gitcomp "--message= --file= --revision= $cmt_opts"
2803 info,--*)
2804 __gitcomp "--url"
2806 branch,--*)
2807 __gitcomp "--dry-run --message --tag"
2809 tag,--*)
2810 __gitcomp "--dry-run --message"
2812 blame,--*)
2813 __gitcomp "--git-format"
2815 migrate,--*)
2816 __gitcomp "
2817 --config-dir= --ignore-paths= --minimize
2818 --no-auth-cache --username=
2821 reset,--*)
2822 __gitcomp "--revision= --parent"
2826 esac
2830 _git_tag ()
2832 local i c=1 f=0
2833 while [ $c -lt $cword ]; do
2834 i="${words[c]}"
2835 case "$i" in
2836 -d|-v)
2837 __gitcomp_nl "$(__git_tags)"
2838 return
2843 esac
2844 ((c++))
2845 done
2847 case "$prev" in
2848 -m|-F)
2850 -*|tag)
2851 if [ $f = 1 ]; then
2852 __gitcomp_nl "$(__git_tags)"
2856 __gitcomp_nl "$(__git_refs)"
2858 esac
2860 case "$cur" in
2861 --*)
2862 __gitcomp "
2863 --list --delete --verify --annotate --message --file
2864 --sign --cleanup --local-user --force --column --sort=
2865 --contains --points-at --merged --no-merged --create-reflog
2868 esac
2871 _git_whatchanged ()
2873 _git_log
2876 _git_worktree ()
2878 local subcommands="add list lock prune unlock"
2879 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2880 if [ -z "$subcommand" ]; then
2881 __gitcomp "$subcommands"
2882 else
2883 case "$subcommand,$cur" in
2884 add,--*)
2885 __gitcomp "--detach"
2887 list,--*)
2888 __gitcomp "--porcelain"
2890 lock,--*)
2891 __gitcomp "--reason"
2893 prune,--*)
2894 __gitcomp "--dry-run --expire --verbose"
2898 esac
2902 __git_main ()
2904 local i c=1 command __git_dir __git_repo_path
2905 local __git_C_args C_args_count=0
2907 while [ $c -lt $cword ]; do
2908 i="${words[c]}"
2909 case "$i" in
2910 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2911 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2912 --bare) __git_dir="." ;;
2913 --help) command="help"; break ;;
2914 -c|--work-tree|--namespace) ((c++)) ;;
2915 -C) __git_C_args[C_args_count++]=-C
2916 ((c++))
2917 __git_C_args[C_args_count++]="${words[c]}"
2919 -*) ;;
2920 *) command="$i"; break ;;
2921 esac
2922 ((c++))
2923 done
2925 if [ -z "$command" ]; then
2926 case "$prev" in
2927 --git-dir|-C|--work-tree)
2928 # these need a path argument, let's fall back to
2929 # Bash filename completion
2930 return
2932 -c|--namespace)
2933 # we don't support completing these options' arguments
2934 return
2936 esac
2937 case "$cur" in
2938 --*) __gitcomp "
2939 --paginate
2940 --no-pager
2941 --git-dir=
2942 --bare
2943 --version
2944 --exec-path
2945 --exec-path=
2946 --html-path
2947 --man-path
2948 --info-path
2949 --work-tree=
2950 --namespace=
2951 --no-replace-objects
2952 --help
2955 *) __git_compute_porcelain_commands
2956 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2957 esac
2958 return
2961 local completion_func="_git_${command//-/_}"
2962 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
2964 local expansion=$(__git_aliased_command "$command")
2965 if [ -n "$expansion" ]; then
2966 words[1]=$expansion
2967 completion_func="_git_${expansion//-/_}"
2968 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
2972 __gitk_main ()
2974 __git_has_doubledash && return
2976 local __git_repo_path
2977 __git_find_repo_path
2979 local merge=""
2980 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2981 merge="--merge"
2983 case "$cur" in
2984 --*)
2985 __gitcomp "
2986 $__git_log_common_options
2987 $__git_log_gitk_options
2988 $merge
2990 return
2992 esac
2993 __git_complete_revlist
2996 if [[ -n ${ZSH_VERSION-} ]]; then
2997 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2999 autoload -U +X compinit && compinit
3001 __gitcomp ()
3003 emulate -L zsh
3005 local cur_="${3-$cur}"
3007 case "$cur_" in
3008 --*=)
3011 local c IFS=$' \t\n'
3012 local -a array
3013 for c in ${=1}; do
3014 c="$c${4-}"
3015 case $c in
3016 --*=*|*.) ;;
3017 *) c="$c " ;;
3018 esac
3019 array[${#array[@]}+1]="$c"
3020 done
3021 compset -P '*[=:]'
3022 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3024 esac
3027 __gitcomp_nl ()
3029 emulate -L zsh
3031 local IFS=$'\n'
3032 compset -P '*[=:]'
3033 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3036 __gitcomp_file ()
3038 emulate -L zsh
3040 local IFS=$'\n'
3041 compset -P '*[=:]'
3042 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3045 _git ()
3047 local _ret=1 cur cword prev
3048 cur=${words[CURRENT]}
3049 prev=${words[CURRENT-1]}
3050 let cword=CURRENT-1
3051 emulate ksh -c __${service}_main
3052 let _ret && _default && _ret=0
3053 return _ret
3056 compdef _git git gitk
3057 return
3060 __git_func_wrap ()
3062 local cur words cword prev
3063 _get_comp_words_by_ref -n =: cur words cword prev
3067 # Setup completion for certain functions defined above by setting common
3068 # variables and workarounds.
3069 # This is NOT a public function; use at your own risk.
3070 __git_complete ()
3072 local wrapper="__git_wrap${2}"
3073 eval "$wrapper () { __git_func_wrap $2 ; }"
3074 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3075 || complete -o default -o nospace -F $wrapper $1
3078 # wrapper for backwards compatibility
3079 _git ()
3081 __git_wrap__git_main
3084 # wrapper for backwards compatibility
3085 _gitk ()
3087 __git_wrap__gitk_main
3090 __git_complete git __git_main
3091 __git_complete gitk __gitk_main
3093 # The following are necessary only for Cygwin, and only are needed
3094 # when the user has tab-completed the executable name and consequently
3095 # included the '.exe' suffix.
3097 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3098 __git_complete git.exe __git_main