completion: wrap __git_refs() for better option parsing
[git/debian.git] / contrib / completion / git-completion.bash
blob0b90cfa546813bc5d704586e1697bd4f5c0cf793
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).
358 # Use __git_complete_refs() instead.
359 __git_refs ()
361 local i hash dir track="${2-}"
362 local list_refs_from=path remote="${1-}"
363 local format refs pfx
365 __git_find_repo_path
366 dir="$__git_repo_path"
368 if [ -z "$remote" ]; then
369 if [ -z "$dir" ]; then
370 return
372 else
373 if __git_is_configured_remote "$remote"; then
374 # configured remote takes precedence over a
375 # local directory with the same name
376 list_refs_from=remote
377 elif [ -d "$remote/.git" ]; then
378 dir="$remote/.git"
379 elif [ -d "$remote" ]; then
380 dir="$remote"
381 else
382 list_refs_from=url
386 if [ "$list_refs_from" = path ]; then
387 case "$cur" in
388 refs|refs/*)
389 format="refname"
390 refs="${cur%/*}"
391 track=""
394 [[ "$cur" == ^* ]] && pfx="^"
395 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
396 if [ -e "$dir/$i" ]; then echo $pfx$i; fi
397 done
398 format="refname:short"
399 refs="refs/tags refs/heads refs/remotes"
401 esac
402 __git_dir="$dir" __git for-each-ref --format="$pfx%($format)" \
403 $refs
404 if [ -n "$track" ]; then
405 # employ the heuristic used by git checkout
406 # Try to find a remote branch that matches the completion word
407 # but only output if the branch name is unique
408 local ref entry
409 __git for-each-ref --shell --format="ref=%(refname:short)" \
410 "refs/remotes/" | \
411 while read -r entry; do
412 eval "$entry"
413 ref="${ref#*/}"
414 if [[ "$ref" == "$cur"* ]]; then
415 echo "$ref"
417 done | sort | uniq -u
419 return
421 case "$cur" in
422 refs|refs/*)
423 __git ls-remote "$remote" "$cur*" | \
424 while read -r hash i; do
425 case "$i" in
426 *^{}) ;;
427 *) echo "$i" ;;
428 esac
429 done
432 if [ "$list_refs_from" = remote ]; then
433 echo "HEAD"
434 __git for-each-ref --format="%(refname:short)" \
435 "refs/remotes/$remote/" | sed -e "s#^$remote/##"
436 else
437 __git ls-remote "$remote" HEAD \
438 "refs/tags/*" "refs/heads/*" "refs/remotes/*" |
439 while read -r hash i; do
440 case "$i" in
441 *^{}) ;;
442 refs/*) echo "${i#refs/*/}" ;;
443 *) echo "$i" ;; # symbolic refs
444 esac
445 done
448 esac
451 # Completes refs, short and long, local and remote, symbolic and pseudo.
453 # Usage: __git_complete_refs [<option>]...
454 # --remote=<remote>: The remote to list refs from, can be the name of a
455 # configured remote, a path, or a URL.
456 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
457 # --pfx=<prefix>: A prefix to be added to each ref.
458 # --cur=<word>: The current ref to be completed. Defaults to the current
459 # word to be completed.
460 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
461 # space.
462 __git_complete_refs ()
464 local remote track pfx cur_="$cur" sfx=" "
466 while test $# != 0; do
467 case "$1" in
468 --remote=*) remote="${1##--remote=}" ;;
469 --track) track="yes" ;;
470 --pfx=*) pfx="${1##--pfx=}" ;;
471 --cur=*) cur_="${1##--cur=}" ;;
472 --sfx=*) sfx="${1##--sfx=}" ;;
473 *) return 1 ;;
474 esac
475 shift
476 done
478 __gitcomp_nl "$(__git_refs "$remote" "$track")" "$pfx" "$cur_" "$sfx"
481 # __git_refs2 requires 1 argument (to pass to __git_refs)
482 __git_refs2 ()
484 local i
485 for i in $(__git_refs "$1"); do
486 echo "$i:$i"
487 done
490 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
491 __git_refs_remotes ()
493 local i hash
494 __git ls-remote "$1" 'refs/heads/*' | \
495 while read -r hash i; do
496 echo "$i:refs/remotes/$1/${i#refs/heads/}"
497 done
500 __git_remotes ()
502 __git_find_repo_path
503 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
504 __git remote
507 # Returns true if $1 matches the name of a configured remote, false otherwise.
508 __git_is_configured_remote ()
510 local remote
511 for remote in $(__git_remotes); do
512 if [ "$remote" = "$1" ]; then
513 return 0
515 done
516 return 1
519 __git_list_merge_strategies ()
521 git merge -s help 2>&1 |
522 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
523 s/\.$//
524 s/.*://
525 s/^[ ]*//
526 s/[ ]*$//
531 __git_merge_strategies=
532 # 'git merge -s help' (and thus detection of the merge strategy
533 # list) fails, unfortunately, if run outside of any git working
534 # tree. __git_merge_strategies is set to the empty string in
535 # that case, and the detection will be repeated the next time it
536 # is needed.
537 __git_compute_merge_strategies ()
539 test -n "$__git_merge_strategies" ||
540 __git_merge_strategies=$(__git_list_merge_strategies)
543 __git_complete_revlist_file ()
545 local pfx ls ref cur_="$cur"
546 case "$cur_" in
547 *..?*:*)
548 return
550 ?*:*)
551 ref="${cur_%%:*}"
552 cur_="${cur_#*:}"
553 case "$cur_" in
554 ?*/*)
555 pfx="${cur_%/*}"
556 cur_="${cur_##*/}"
557 ls="$ref:$pfx"
558 pfx="$pfx/"
561 ls="$ref"
563 esac
565 case "$COMP_WORDBREAKS" in
566 *:*) : great ;;
567 *) pfx="$ref:$pfx" ;;
568 esac
570 __gitcomp_nl "$(__git ls-tree "$ls" \
571 | sed '/^100... blob /{
572 s,^.* ,,
573 s,$, ,
575 /^120000 blob /{
576 s,^.* ,,
577 s,$, ,
579 /^040000 tree /{
580 s,^.* ,,
581 s,$,/,
583 s/^.* //')" \
584 "$pfx" "$cur_" ""
586 *...*)
587 pfx="${cur_%...*}..."
588 cur_="${cur_#*...}"
589 __git_complete_refs --pfx="$pfx" --cur="$cur_"
591 *..*)
592 pfx="${cur_%..*}.."
593 cur_="${cur_#*..}"
594 __git_complete_refs --pfx="$pfx" --cur="$cur_"
597 __git_complete_refs
599 esac
603 # __git_complete_index_file requires 1 argument:
604 # 1: the options to pass to ls-file
606 # The exception is --committable, which finds the files appropriate commit.
607 __git_complete_index_file ()
609 local pfx="" cur_="$cur"
611 case "$cur_" in
612 ?*/*)
613 pfx="${cur_%/*}"
614 cur_="${cur_##*/}"
615 pfx="${pfx}/"
617 esac
619 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
622 __git_complete_file ()
624 __git_complete_revlist_file
627 __git_complete_revlist ()
629 __git_complete_revlist_file
632 __git_complete_remote_or_refspec ()
634 local cur_="$cur" cmd="${words[1]}"
635 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
636 if [ "$cmd" = "remote" ]; then
637 ((c++))
639 while [ $c -lt $cword ]; do
640 i="${words[c]}"
641 case "$i" in
642 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
643 --all)
644 case "$cmd" in
645 push) no_complete_refspec=1 ;;
646 fetch)
647 return
649 *) ;;
650 esac
652 -*) ;;
653 *) remote="$i"; break ;;
654 esac
655 ((c++))
656 done
657 if [ -z "$remote" ]; then
658 __gitcomp_nl "$(__git_remotes)"
659 return
661 if [ $no_complete_refspec = 1 ]; then
662 return
664 [ "$remote" = "." ] && remote=
665 case "$cur_" in
666 *:*)
667 case "$COMP_WORDBREAKS" in
668 *:*) : great ;;
669 *) pfx="${cur_%%:*}:" ;;
670 esac
671 cur_="${cur_#*:}"
672 lhs=0
675 pfx="+"
676 cur_="${cur_#+}"
678 esac
679 case "$cmd" in
680 fetch)
681 if [ $lhs = 1 ]; then
682 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
683 else
684 __git_complete_refs --pfx="$pfx" --cur="$cur_"
687 pull|remote)
688 if [ $lhs = 1 ]; then
689 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
690 else
691 __git_complete_refs --pfx="$pfx" --cur="$cur_"
694 push)
695 if [ $lhs = 1 ]; then
696 __git_complete_refs --pfx="$pfx" --cur="$cur_"
697 else
698 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
701 esac
704 __git_complete_strategy ()
706 __git_compute_merge_strategies
707 case "$prev" in
708 -s|--strategy)
709 __gitcomp "$__git_merge_strategies"
710 return 0
711 esac
712 case "$cur" in
713 --strategy=*)
714 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
715 return 0
717 esac
718 return 1
721 __git_commands () {
722 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
723 then
724 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
725 else
726 git help -a|egrep '^ [a-zA-Z0-9]'
730 __git_list_all_commands ()
732 local i IFS=" "$'\n'
733 for i in $(__git_commands)
735 case $i in
736 *--*) : helper pattern;;
737 *) echo $i;;
738 esac
739 done
742 __git_all_commands=
743 __git_compute_all_commands ()
745 test -n "$__git_all_commands" ||
746 __git_all_commands=$(__git_list_all_commands)
749 __git_list_porcelain_commands ()
751 local i IFS=" "$'\n'
752 __git_compute_all_commands
753 for i in $__git_all_commands
755 case $i in
756 *--*) : helper pattern;;
757 applymbox) : ask gittus;;
758 applypatch) : ask gittus;;
759 archimport) : import;;
760 cat-file) : plumbing;;
761 check-attr) : plumbing;;
762 check-ignore) : plumbing;;
763 check-mailmap) : plumbing;;
764 check-ref-format) : plumbing;;
765 checkout-index) : plumbing;;
766 column) : internal helper;;
767 commit-tree) : plumbing;;
768 count-objects) : infrequent;;
769 credential) : credentials;;
770 credential-*) : credentials helper;;
771 cvsexportcommit) : export;;
772 cvsimport) : import;;
773 cvsserver) : daemon;;
774 daemon) : daemon;;
775 diff-files) : plumbing;;
776 diff-index) : plumbing;;
777 diff-tree) : plumbing;;
778 fast-import) : import;;
779 fast-export) : export;;
780 fsck-objects) : plumbing;;
781 fetch-pack) : plumbing;;
782 fmt-merge-msg) : plumbing;;
783 for-each-ref) : plumbing;;
784 hash-object) : plumbing;;
785 http-*) : transport;;
786 index-pack) : plumbing;;
787 init-db) : deprecated;;
788 local-fetch) : plumbing;;
789 ls-files) : plumbing;;
790 ls-remote) : plumbing;;
791 ls-tree) : plumbing;;
792 mailinfo) : plumbing;;
793 mailsplit) : plumbing;;
794 merge-*) : plumbing;;
795 mktree) : plumbing;;
796 mktag) : plumbing;;
797 pack-objects) : plumbing;;
798 pack-redundant) : plumbing;;
799 pack-refs) : plumbing;;
800 parse-remote) : plumbing;;
801 patch-id) : plumbing;;
802 prune) : plumbing;;
803 prune-packed) : plumbing;;
804 quiltimport) : import;;
805 read-tree) : plumbing;;
806 receive-pack) : plumbing;;
807 remote-*) : transport;;
808 rerere) : plumbing;;
809 rev-list) : plumbing;;
810 rev-parse) : plumbing;;
811 runstatus) : plumbing;;
812 sh-setup) : internal;;
813 shell) : daemon;;
814 show-ref) : plumbing;;
815 send-pack) : plumbing;;
816 show-index) : plumbing;;
817 ssh-*) : transport;;
818 stripspace) : plumbing;;
819 symbolic-ref) : plumbing;;
820 unpack-file) : plumbing;;
821 unpack-objects) : plumbing;;
822 update-index) : plumbing;;
823 update-ref) : plumbing;;
824 update-server-info) : daemon;;
825 upload-archive) : plumbing;;
826 upload-pack) : plumbing;;
827 write-tree) : plumbing;;
828 var) : infrequent;;
829 verify-pack) : infrequent;;
830 verify-tag) : plumbing;;
831 *) echo $i;;
832 esac
833 done
836 __git_porcelain_commands=
837 __git_compute_porcelain_commands ()
839 test -n "$__git_porcelain_commands" ||
840 __git_porcelain_commands=$(__git_list_porcelain_commands)
843 # Lists all set config variables starting with the given section prefix,
844 # with the prefix removed.
845 __git_get_config_variables ()
847 local section="$1" i IFS=$'\n'
848 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
849 echo "${i#$section.}"
850 done
853 __git_pretty_aliases ()
855 __git_get_config_variables "pretty"
858 __git_aliases ()
860 __git_get_config_variables "alias"
863 # __git_aliased_command requires 1 argument
864 __git_aliased_command ()
866 local word cmdline=$(__git config --get "alias.$1")
867 for word in $cmdline; do
868 case "$word" in
869 \!gitk|gitk)
870 echo "gitk"
871 return
873 \!*) : shell command alias ;;
874 -*) : option ;;
875 *=*) : setting env ;;
876 git) : git itself ;;
877 \(\)) : skip parens of shell function definition ;;
878 {) : skip start of shell helper function ;;
879 :) : skip null command ;;
880 \'*) : skip opening quote after sh -c ;;
882 echo "$word"
883 return
884 esac
885 done
888 # __git_find_on_cmdline requires 1 argument
889 __git_find_on_cmdline ()
891 local word subcommand c=1
892 while [ $c -lt $cword ]; do
893 word="${words[c]}"
894 for subcommand in $1; do
895 if [ "$subcommand" = "$word" ]; then
896 echo "$subcommand"
897 return
899 done
900 ((c++))
901 done
904 # Echo the value of an option set on the command line or config
906 # $1: short option name
907 # $2: long option name including =
908 # $3: list of possible values
909 # $4: config string (optional)
911 # example:
912 # result="$(__git_get_option_value "-d" "--do-something=" \
913 # "yes no" "core.doSomething")"
915 # result is then either empty (no option set) or "yes" or "no"
917 # __git_get_option_value requires 3 arguments
918 __git_get_option_value ()
920 local c short_opt long_opt val
921 local result= values config_key word
923 short_opt="$1"
924 long_opt="$2"
925 values="$3"
926 config_key="$4"
928 ((c = $cword - 1))
929 while [ $c -ge 0 ]; do
930 word="${words[c]}"
931 for val in $values; do
932 if [ "$short_opt$val" = "$word" ] ||
933 [ "$long_opt$val" = "$word" ]; then
934 result="$val"
935 break 2
937 done
938 ((c--))
939 done
941 if [ -n "$config_key" ] && [ -z "$result" ]; then
942 result="$(__git config "$config_key")"
945 echo "$result"
948 __git_has_doubledash ()
950 local c=1
951 while [ $c -lt $cword ]; do
952 if [ "--" = "${words[c]}" ]; then
953 return 0
955 ((c++))
956 done
957 return 1
960 # Try to count non option arguments passed on the command line for the
961 # specified git command.
962 # When options are used, it is necessary to use the special -- option to
963 # tell the implementation were non option arguments begin.
964 # XXX this can not be improved, since options can appear everywhere, as
965 # an example:
966 # git mv x -n y
968 # __git_count_arguments requires 1 argument: the git command executed.
969 __git_count_arguments ()
971 local word i c=0
973 # Skip "git" (first argument)
974 for ((i=1; i < ${#words[@]}; i++)); do
975 word="${words[i]}"
977 case "$word" in
979 # Good; we can assume that the following are only non
980 # option arguments.
981 ((c = 0))
983 "$1")
984 # Skip the specified git command and discard git
985 # main options
986 ((c = 0))
989 ((c++))
991 esac
992 done
994 printf "%d" $c
997 __git_whitespacelist="nowarn warn error error-all fix"
999 _git_am ()
1001 __git_find_repo_path
1002 if [ -d "$__git_repo_path"/rebase-apply ]; then
1003 __gitcomp "--skip --continue --resolved --abort"
1004 return
1006 case "$cur" in
1007 --whitespace=*)
1008 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1009 return
1011 --*)
1012 __gitcomp "
1013 --3way --committer-date-is-author-date --ignore-date
1014 --ignore-whitespace --ignore-space-change
1015 --interactive --keep --no-utf8 --signoff --utf8
1016 --whitespace= --scissors
1018 return
1019 esac
1022 _git_apply ()
1024 case "$cur" in
1025 --whitespace=*)
1026 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1027 return
1029 --*)
1030 __gitcomp "
1031 --stat --numstat --summary --check --index
1032 --cached --index-info --reverse --reject --unidiff-zero
1033 --apply --no-add --exclude=
1034 --ignore-whitespace --ignore-space-change
1035 --whitespace= --inaccurate-eof --verbose
1037 return
1038 esac
1041 _git_add ()
1043 case "$cur" in
1044 --*)
1045 __gitcomp "
1046 --interactive --refresh --patch --update --dry-run
1047 --ignore-errors --intent-to-add
1049 return
1050 esac
1052 # XXX should we check for --update and --all options ?
1053 __git_complete_index_file "--others --modified --directory --no-empty-directory"
1056 _git_archive ()
1058 case "$cur" in
1059 --format=*)
1060 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1061 return
1063 --remote=*)
1064 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1065 return
1067 --*)
1068 __gitcomp "
1069 --format= --list --verbose
1070 --prefix= --remote= --exec=
1072 return
1074 esac
1075 __git_complete_file
1078 _git_bisect ()
1080 __git_has_doubledash && return
1082 local subcommands="start bad good skip reset visualize replay log run"
1083 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1084 if [ -z "$subcommand" ]; then
1085 __git_find_repo_path
1086 if [ -f "$__git_repo_path"/BISECT_START ]; then
1087 __gitcomp "$subcommands"
1088 else
1089 __gitcomp "replay start"
1091 return
1094 case "$subcommand" in
1095 bad|good|reset|skip|start)
1096 __git_complete_refs
1100 esac
1103 _git_branch ()
1105 local i c=1 only_local_ref="n" has_r="n"
1107 while [ $c -lt $cword ]; do
1108 i="${words[c]}"
1109 case "$i" in
1110 -d|--delete|-m|--move) only_local_ref="y" ;;
1111 -r|--remotes) has_r="y" ;;
1112 esac
1113 ((c++))
1114 done
1116 case "$cur" in
1117 --set-upstream-to=*)
1118 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1120 --*)
1121 __gitcomp "
1122 --color --no-color --verbose --abbrev= --no-abbrev
1123 --track --no-track --contains --merged --no-merged
1124 --set-upstream-to= --edit-description --list
1125 --unset-upstream --delete --move --remotes
1129 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1130 __gitcomp_nl "$(__git_heads)"
1131 else
1132 __git_complete_refs
1135 esac
1138 _git_bundle ()
1140 local cmd="${words[2]}"
1141 case "$cword" in
1143 __gitcomp "create list-heads verify unbundle"
1146 # looking for a file
1149 case "$cmd" in
1150 create)
1151 __git_complete_revlist
1153 esac
1155 esac
1158 _git_checkout ()
1160 __git_has_doubledash && return
1162 case "$cur" in
1163 --conflict=*)
1164 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1166 --*)
1167 __gitcomp "
1168 --quiet --ours --theirs --track --no-track --merge
1169 --conflict= --orphan --patch
1173 # check if --track, --no-track, or --no-guess was specified
1174 # if so, disable DWIM mode
1175 local flags="--track --no-track --no-guess" track_opt="--track"
1176 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1177 track_opt=''
1179 __git_complete_refs $track_opt
1181 esac
1184 _git_cherry ()
1186 __git_complete_refs
1189 _git_cherry_pick ()
1191 __git_find_repo_path
1192 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1193 __gitcomp "--continue --quit --abort"
1194 return
1196 case "$cur" in
1197 --*)
1198 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1201 __git_complete_refs
1203 esac
1206 _git_clean ()
1208 case "$cur" in
1209 --*)
1210 __gitcomp "--dry-run --quiet"
1211 return
1213 esac
1215 # XXX should we check for -x option ?
1216 __git_complete_index_file "--others --directory"
1219 _git_clone ()
1221 case "$cur" in
1222 --*)
1223 __gitcomp "
1224 --local
1225 --no-hardlinks
1226 --shared
1227 --reference
1228 --quiet
1229 --no-checkout
1230 --bare
1231 --mirror
1232 --origin
1233 --upload-pack
1234 --template=
1235 --depth
1236 --single-branch
1237 --branch
1238 --recurse-submodules
1240 return
1242 esac
1245 __git_untracked_file_modes="all no normal"
1247 _git_commit ()
1249 case "$prev" in
1250 -c|-C)
1251 __git_complete_refs
1252 return
1254 esac
1256 case "$cur" in
1257 --cleanup=*)
1258 __gitcomp "default scissors strip verbatim whitespace
1259 " "" "${cur##--cleanup=}"
1260 return
1262 --reuse-message=*|--reedit-message=*|\
1263 --fixup=*|--squash=*)
1264 __git_complete_refs --cur="${cur#*=}"
1265 return
1267 --untracked-files=*)
1268 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1269 return
1271 --*)
1272 __gitcomp "
1273 --all --author= --signoff --verify --no-verify
1274 --edit --no-edit
1275 --amend --include --only --interactive
1276 --dry-run --reuse-message= --reedit-message=
1277 --reset-author --file= --message= --template=
1278 --cleanup= --untracked-files --untracked-files=
1279 --verbose --quiet --fixup= --squash=
1281 return
1282 esac
1284 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1285 __git_complete_index_file "--committable"
1286 else
1287 # This is the first commit
1288 __git_complete_index_file "--cached"
1292 _git_describe ()
1294 case "$cur" in
1295 --*)
1296 __gitcomp "
1297 --all --tags --contains --abbrev= --candidates=
1298 --exact-match --debug --long --match --always
1300 return
1301 esac
1302 __git_complete_refs
1305 __git_diff_algorithms="myers minimal patience histogram"
1307 __git_diff_submodule_formats="diff log short"
1309 __git_diff_common_options="--stat --numstat --shortstat --summary
1310 --patch-with-stat --name-only --name-status --color
1311 --no-color --color-words --no-renames --check
1312 --full-index --binary --abbrev --diff-filter=
1313 --find-copies-harder
1314 --text --ignore-space-at-eol --ignore-space-change
1315 --ignore-all-space --ignore-blank-lines --exit-code
1316 --quiet --ext-diff --no-ext-diff
1317 --no-prefix --src-prefix= --dst-prefix=
1318 --inter-hunk-context=
1319 --patience --histogram --minimal
1320 --raw --word-diff --word-diff-regex=
1321 --dirstat --dirstat= --dirstat-by-file
1322 --dirstat-by-file= --cumulative
1323 --diff-algorithm=
1324 --submodule --submodule=
1327 _git_diff ()
1329 __git_has_doubledash && return
1331 case "$cur" in
1332 --diff-algorithm=*)
1333 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1334 return
1336 --submodule=*)
1337 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1338 return
1340 --*)
1341 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1342 --base --ours --theirs --no-index
1343 $__git_diff_common_options
1345 return
1347 esac
1348 __git_complete_revlist_file
1351 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1352 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1355 _git_difftool ()
1357 __git_has_doubledash && return
1359 case "$cur" in
1360 --tool=*)
1361 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1362 return
1364 --*)
1365 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1366 --base --ours --theirs
1367 --no-renames --diff-filter= --find-copies-harder
1368 --relative --ignore-submodules
1369 --tool="
1370 return
1372 esac
1373 __git_complete_revlist_file
1376 __git_fetch_recurse_submodules="yes on-demand no"
1378 __git_fetch_options="
1379 --quiet --verbose --append --upload-pack --force --keep --depth=
1380 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1383 _git_fetch ()
1385 case "$cur" in
1386 --recurse-submodules=*)
1387 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1388 return
1390 --*)
1391 __gitcomp "$__git_fetch_options"
1392 return
1394 esac
1395 __git_complete_remote_or_refspec
1398 __git_format_patch_options="
1399 --stdout --attach --no-attach --thread --thread= --no-thread
1400 --numbered --start-number --numbered-files --keep-subject --signoff
1401 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1402 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1403 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1404 --output-directory --reroll-count --to= --quiet --notes
1407 _git_format_patch ()
1409 case "$cur" in
1410 --thread=*)
1411 __gitcomp "
1412 deep shallow
1413 " "" "${cur##--thread=}"
1414 return
1416 --*)
1417 __gitcomp "$__git_format_patch_options"
1418 return
1420 esac
1421 __git_complete_revlist
1424 _git_fsck ()
1426 case "$cur" in
1427 --*)
1428 __gitcomp "
1429 --tags --root --unreachable --cache --no-reflogs --full
1430 --strict --verbose --lost-found
1432 return
1434 esac
1437 _git_gc ()
1439 case "$cur" in
1440 --*)
1441 __gitcomp "--prune --aggressive"
1442 return
1444 esac
1447 _git_gitk ()
1449 _gitk
1452 __git_match_ctag() {
1453 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1456 _git_grep ()
1458 __git_has_doubledash && return
1460 case "$cur" in
1461 --*)
1462 __gitcomp "
1463 --cached
1464 --text --ignore-case --word-regexp --invert-match
1465 --full-name --line-number
1466 --extended-regexp --basic-regexp --fixed-strings
1467 --perl-regexp
1468 --threads
1469 --files-with-matches --name-only
1470 --files-without-match
1471 --max-depth
1472 --count
1473 --and --or --not --all-match
1475 return
1477 esac
1479 case "$cword,$prev" in
1480 2,*|*,-*)
1481 if test -r tags; then
1482 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1483 return
1486 esac
1488 __git_complete_refs
1491 _git_help ()
1493 case "$cur" in
1494 --*)
1495 __gitcomp "--all --guides --info --man --web"
1496 return
1498 esac
1499 __git_compute_all_commands
1500 __gitcomp "$__git_all_commands $(__git_aliases)
1501 attributes cli core-tutorial cvs-migration
1502 diffcore everyday gitk glossary hooks ignore modules
1503 namespaces repository-layout revisions tutorial tutorial-2
1504 workflows
1508 _git_init ()
1510 case "$cur" in
1511 --shared=*)
1512 __gitcomp "
1513 false true umask group all world everybody
1514 " "" "${cur##--shared=}"
1515 return
1517 --*)
1518 __gitcomp "--quiet --bare --template= --shared --shared="
1519 return
1521 esac
1524 _git_ls_files ()
1526 case "$cur" in
1527 --*)
1528 __gitcomp "--cached --deleted --modified --others --ignored
1529 --stage --directory --no-empty-directory --unmerged
1530 --killed --exclude= --exclude-from=
1531 --exclude-per-directory= --exclude-standard
1532 --error-unmatch --with-tree= --full-name
1533 --abbrev --ignored --exclude-per-directory
1535 return
1537 esac
1539 # XXX ignore options like --modified and always suggest all cached
1540 # files.
1541 __git_complete_index_file "--cached"
1544 _git_ls_remote ()
1546 __gitcomp_nl "$(__git_remotes)"
1549 _git_ls_tree ()
1551 __git_complete_file
1554 # Options that go well for log, shortlog and gitk
1555 __git_log_common_options="
1556 --not --all
1557 --branches --tags --remotes
1558 --first-parent --merges --no-merges
1559 --max-count=
1560 --max-age= --since= --after=
1561 --min-age= --until= --before=
1562 --min-parents= --max-parents=
1563 --no-min-parents --no-max-parents
1565 # Options that go well for log and gitk (not shortlog)
1566 __git_log_gitk_options="
1567 --dense --sparse --full-history
1568 --simplify-merges --simplify-by-decoration
1569 --left-right --notes --no-notes
1571 # Options that go well for log and shortlog (not gitk)
1572 __git_log_shortlog_options="
1573 --author= --committer= --grep=
1574 --all-match --invert-grep
1577 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1578 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1580 _git_log ()
1582 __git_has_doubledash && return
1583 __git_find_repo_path
1585 local merge=""
1586 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1587 merge="--merge"
1589 case "$cur" in
1590 --pretty=*|--format=*)
1591 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1592 " "" "${cur#*=}"
1593 return
1595 --date=*)
1596 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1597 return
1599 --decorate=*)
1600 __gitcomp "full short no" "" "${cur##--decorate=}"
1601 return
1603 --diff-algorithm=*)
1604 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1605 return
1607 --submodule=*)
1608 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1609 return
1611 --*)
1612 __gitcomp "
1613 $__git_log_common_options
1614 $__git_log_shortlog_options
1615 $__git_log_gitk_options
1616 --root --topo-order --date-order --reverse
1617 --follow --full-diff
1618 --abbrev-commit --abbrev=
1619 --relative-date --date=
1620 --pretty= --format= --oneline
1621 --show-signature
1622 --cherry-mark
1623 --cherry-pick
1624 --graph
1625 --decorate --decorate=
1626 --walk-reflogs
1627 --parents --children
1628 $merge
1629 $__git_diff_common_options
1630 --pickaxe-all --pickaxe-regex
1632 return
1634 esac
1635 __git_complete_revlist
1638 # Common merge options shared by git-merge(1) and git-pull(1).
1639 __git_merge_options="
1640 --no-commit --no-stat --log --no-log --squash --strategy
1641 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1642 --verify-signatures --no-verify-signatures --gpg-sign
1643 --quiet --verbose --progress --no-progress
1646 _git_merge ()
1648 __git_complete_strategy && return
1650 case "$cur" in
1651 --*)
1652 __gitcomp "$__git_merge_options
1653 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1654 return
1655 esac
1656 __git_complete_refs
1659 _git_mergetool ()
1661 case "$cur" in
1662 --tool=*)
1663 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1664 return
1666 --*)
1667 __gitcomp "--tool="
1668 return
1670 esac
1673 _git_merge_base ()
1675 case "$cur" in
1676 --*)
1677 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1678 return
1680 esac
1681 __git_complete_refs
1684 _git_mv ()
1686 case "$cur" in
1687 --*)
1688 __gitcomp "--dry-run"
1689 return
1691 esac
1693 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1694 # We need to show both cached and untracked files (including
1695 # empty directories) since this may not be the last argument.
1696 __git_complete_index_file "--cached --others --directory"
1697 else
1698 __git_complete_index_file "--cached"
1702 _git_name_rev ()
1704 __gitcomp "--tags --all --stdin"
1707 _git_notes ()
1709 local subcommands='add append copy edit list prune remove show'
1710 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1712 case "$subcommand,$cur" in
1713 ,--*)
1714 __gitcomp '--ref'
1717 case "$prev" in
1718 --ref)
1719 __git_complete_refs
1722 __gitcomp "$subcommands --ref"
1724 esac
1726 add,--reuse-message=*|append,--reuse-message=*|\
1727 add,--reedit-message=*|append,--reedit-message=*)
1728 __git_complete_refs --cur="${cur#*=}"
1730 add,--*|append,--*)
1731 __gitcomp '--file= --message= --reedit-message=
1732 --reuse-message='
1734 copy,--*)
1735 __gitcomp '--stdin'
1737 prune,--*)
1738 __gitcomp '--dry-run --verbose'
1740 prune,*)
1743 case "$prev" in
1744 -m|-F)
1747 __git_complete_refs
1749 esac
1751 esac
1754 _git_pull ()
1756 __git_complete_strategy && return
1758 case "$cur" in
1759 --recurse-submodules=*)
1760 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1761 return
1763 --*)
1764 __gitcomp "
1765 --rebase --no-rebase
1766 $__git_merge_options
1767 $__git_fetch_options
1769 return
1771 esac
1772 __git_complete_remote_or_refspec
1775 __git_push_recurse_submodules="check on-demand"
1777 __git_complete_force_with_lease ()
1779 local cur_=$1
1781 case "$cur_" in
1782 --*=)
1784 *:*)
1785 __git_complete_refs --cur="${cur_#*:}"
1788 __git_complete_refs --cur="$cur_"
1790 esac
1793 _git_push ()
1795 case "$prev" in
1796 --repo)
1797 __gitcomp_nl "$(__git_remotes)"
1798 return
1800 --recurse-submodules)
1801 __gitcomp "$__git_push_recurse_submodules"
1802 return
1804 esac
1805 case "$cur" in
1806 --repo=*)
1807 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1808 return
1810 --recurse-submodules=*)
1811 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1812 return
1814 --force-with-lease=*)
1815 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1816 return
1818 --*)
1819 __gitcomp "
1820 --all --mirror --tags --dry-run --force --verbose
1821 --quiet --prune --delete --follow-tags
1822 --receive-pack= --repo= --set-upstream
1823 --force-with-lease --force-with-lease= --recurse-submodules=
1825 return
1827 esac
1828 __git_complete_remote_or_refspec
1831 _git_rebase ()
1833 __git_find_repo_path
1834 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1835 __gitcomp "--continue --skip --abort --quit --edit-todo"
1836 return
1837 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1838 [ -d "$__git_repo_path"/rebase-merge ]; then
1839 __gitcomp "--continue --skip --abort --quit"
1840 return
1842 __git_complete_strategy && return
1843 case "$cur" in
1844 --whitespace=*)
1845 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1846 return
1848 --*)
1849 __gitcomp "
1850 --onto --merge --strategy --interactive
1851 --preserve-merges --stat --no-stat
1852 --committer-date-is-author-date --ignore-date
1853 --ignore-whitespace --whitespace=
1854 --autosquash --no-autosquash
1855 --fork-point --no-fork-point
1856 --autostash --no-autostash
1857 --verify --no-verify
1858 --keep-empty --root --force-rebase --no-ff
1859 --exec
1862 return
1863 esac
1864 __git_complete_refs
1867 _git_reflog ()
1869 local subcommands="show delete expire"
1870 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1872 if [ -z "$subcommand" ]; then
1873 __gitcomp "$subcommands"
1874 else
1875 __git_complete_refs
1879 __git_send_email_confirm_options="always never auto cc compose"
1880 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1882 _git_send_email ()
1884 case "$prev" in
1885 --to|--cc|--bcc|--from)
1886 __gitcomp "$(__git send-email --dump-aliases)"
1887 return
1889 esac
1891 case "$cur" in
1892 --confirm=*)
1893 __gitcomp "
1894 $__git_send_email_confirm_options
1895 " "" "${cur##--confirm=}"
1896 return
1898 --suppress-cc=*)
1899 __gitcomp "
1900 $__git_send_email_suppresscc_options
1901 " "" "${cur##--suppress-cc=}"
1903 return
1905 --smtp-encryption=*)
1906 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1907 return
1909 --thread=*)
1910 __gitcomp "
1911 deep shallow
1912 " "" "${cur##--thread=}"
1913 return
1915 --to=*|--cc=*|--bcc=*|--from=*)
1916 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
1917 return
1919 --*)
1920 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1921 --compose --confirm= --dry-run --envelope-sender
1922 --from --identity
1923 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1924 --no-suppress-from --no-thread --quiet
1925 --signed-off-by-cc --smtp-pass --smtp-server
1926 --smtp-server-port --smtp-encryption= --smtp-user
1927 --subject --suppress-cc= --suppress-from --thread --to
1928 --validate --no-validate
1929 $__git_format_patch_options"
1930 return
1932 esac
1933 __git_complete_revlist
1936 _git_stage ()
1938 _git_add
1941 _git_status ()
1943 local complete_opt
1944 local untracked_state
1946 case "$cur" in
1947 --ignore-submodules=*)
1948 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1949 return
1951 --untracked-files=*)
1952 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1953 return
1955 --column=*)
1956 __gitcomp "
1957 always never auto column row plain dense nodense
1958 " "" "${cur##--column=}"
1959 return
1961 --*)
1962 __gitcomp "
1963 --short --branch --porcelain --long --verbose
1964 --untracked-files= --ignore-submodules= --ignored
1965 --column= --no-column
1967 return
1969 esac
1971 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1972 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
1974 case "$untracked_state" in
1976 # --ignored option does not matter
1977 complete_opt=
1979 all|normal|*)
1980 complete_opt="--cached --directory --no-empty-directory --others"
1982 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1983 complete_opt="$complete_opt --ignored --exclude=*"
1986 esac
1988 __git_complete_index_file "$complete_opt"
1991 __git_config_get_set_variables ()
1993 local prevword word config_file= c=$cword
1994 while [ $c -gt 1 ]; do
1995 word="${words[c]}"
1996 case "$word" in
1997 --system|--global|--local|--file=*)
1998 config_file="$word"
1999 break
2001 -f|--file)
2002 config_file="$word $prevword"
2003 break
2005 esac
2006 prevword=$word
2007 c=$((--c))
2008 done
2010 __git config $config_file --name-only --list
2013 _git_config ()
2015 case "$prev" in
2016 branch.*.remote|branch.*.pushremote)
2017 __gitcomp_nl "$(__git_remotes)"
2018 return
2020 branch.*.merge)
2021 __git_complete_refs
2022 return
2024 branch.*.rebase)
2025 __gitcomp "false true preserve interactive"
2026 return
2028 remote.pushdefault)
2029 __gitcomp_nl "$(__git_remotes)"
2030 return
2032 remote.*.fetch)
2033 local remote="${prev#remote.}"
2034 remote="${remote%.fetch}"
2035 if [ -z "$cur" ]; then
2036 __gitcomp_nl "refs/heads/" "" "" ""
2037 return
2039 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2040 return
2042 remote.*.push)
2043 local remote="${prev#remote.}"
2044 remote="${remote%.push}"
2045 __gitcomp_nl "$(__git for-each-ref \
2046 --format='%(refname):%(refname)' refs/heads)"
2047 return
2049 pull.twohead|pull.octopus)
2050 __git_compute_merge_strategies
2051 __gitcomp "$__git_merge_strategies"
2052 return
2054 color.branch|color.diff|color.interactive|\
2055 color.showbranch|color.status|color.ui)
2056 __gitcomp "always never auto"
2057 return
2059 color.pager)
2060 __gitcomp "false true"
2061 return
2063 color.*.*)
2064 __gitcomp "
2065 normal black red green yellow blue magenta cyan white
2066 bold dim ul blink reverse
2068 return
2070 diff.submodule)
2071 __gitcomp "log short"
2072 return
2074 help.format)
2075 __gitcomp "man info web html"
2076 return
2078 log.date)
2079 __gitcomp "$__git_log_date_formats"
2080 return
2082 sendemail.aliasesfiletype)
2083 __gitcomp "mutt mailrc pine elm gnus"
2084 return
2086 sendemail.confirm)
2087 __gitcomp "$__git_send_email_confirm_options"
2088 return
2090 sendemail.suppresscc)
2091 __gitcomp "$__git_send_email_suppresscc_options"
2092 return
2094 sendemail.transferencoding)
2095 __gitcomp "7bit 8bit quoted-printable base64"
2096 return
2098 --get|--get-all|--unset|--unset-all)
2099 __gitcomp_nl "$(__git_config_get_set_variables)"
2100 return
2102 *.*)
2103 return
2105 esac
2106 case "$cur" in
2107 --*)
2108 __gitcomp "
2109 --system --global --local --file=
2110 --list --replace-all
2111 --get --get-all --get-regexp
2112 --add --unset --unset-all
2113 --remove-section --rename-section
2114 --name-only
2116 return
2118 branch.*.*)
2119 local pfx="${cur%.*}." cur_="${cur##*.}"
2120 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2121 return
2123 branch.*)
2124 local pfx="${cur%.*}." cur_="${cur#*.}"
2125 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
2126 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2127 return
2129 guitool.*.*)
2130 local pfx="${cur%.*}." cur_="${cur##*.}"
2131 __gitcomp "
2132 argprompt cmd confirm needsfile noconsole norescan
2133 prompt revprompt revunmerged title
2134 " "$pfx" "$cur_"
2135 return
2137 difftool.*.*)
2138 local pfx="${cur%.*}." cur_="${cur##*.}"
2139 __gitcomp "cmd path" "$pfx" "$cur_"
2140 return
2142 man.*.*)
2143 local pfx="${cur%.*}." cur_="${cur##*.}"
2144 __gitcomp "cmd path" "$pfx" "$cur_"
2145 return
2147 mergetool.*.*)
2148 local pfx="${cur%.*}." cur_="${cur##*.}"
2149 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2150 return
2152 pager.*)
2153 local pfx="${cur%.*}." cur_="${cur#*.}"
2154 __git_compute_all_commands
2155 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2156 return
2158 remote.*.*)
2159 local pfx="${cur%.*}." cur_="${cur##*.}"
2160 __gitcomp "
2161 url proxy fetch push mirror skipDefaultUpdate
2162 receivepack uploadpack tagopt pushurl
2163 " "$pfx" "$cur_"
2164 return
2166 remote.*)
2167 local pfx="${cur%.*}." cur_="${cur#*.}"
2168 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2169 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2170 return
2172 url.*.*)
2173 local pfx="${cur%.*}." cur_="${cur##*.}"
2174 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2175 return
2177 esac
2178 __gitcomp "
2179 add.ignoreErrors
2180 advice.commitBeforeMerge
2181 advice.detachedHead
2182 advice.implicitIdentity
2183 advice.pushNonFastForward
2184 advice.resolveConflict
2185 advice.statusHints
2186 alias.
2187 am.keepcr
2188 apply.ignorewhitespace
2189 apply.whitespace
2190 branch.autosetupmerge
2191 branch.autosetuprebase
2192 browser.
2193 clean.requireForce
2194 color.branch
2195 color.branch.current
2196 color.branch.local
2197 color.branch.plain
2198 color.branch.remote
2199 color.decorate.HEAD
2200 color.decorate.branch
2201 color.decorate.remoteBranch
2202 color.decorate.stash
2203 color.decorate.tag
2204 color.diff
2205 color.diff.commit
2206 color.diff.frag
2207 color.diff.func
2208 color.diff.meta
2209 color.diff.new
2210 color.diff.old
2211 color.diff.plain
2212 color.diff.whitespace
2213 color.grep
2214 color.grep.context
2215 color.grep.filename
2216 color.grep.function
2217 color.grep.linenumber
2218 color.grep.match
2219 color.grep.selected
2220 color.grep.separator
2221 color.interactive
2222 color.interactive.error
2223 color.interactive.header
2224 color.interactive.help
2225 color.interactive.prompt
2226 color.pager
2227 color.showbranch
2228 color.status
2229 color.status.added
2230 color.status.changed
2231 color.status.header
2232 color.status.nobranch
2233 color.status.unmerged
2234 color.status.untracked
2235 color.status.updated
2236 color.ui
2237 commit.status
2238 commit.template
2239 core.abbrev
2240 core.askpass
2241 core.attributesfile
2242 core.autocrlf
2243 core.bare
2244 core.bigFileThreshold
2245 core.compression
2246 core.createObject
2247 core.deltaBaseCacheLimit
2248 core.editor
2249 core.eol
2250 core.excludesfile
2251 core.fileMode
2252 core.fsyncobjectfiles
2253 core.gitProxy
2254 core.ignoreStat
2255 core.ignorecase
2256 core.logAllRefUpdates
2257 core.loosecompression
2258 core.notesRef
2259 core.packedGitLimit
2260 core.packedGitWindowSize
2261 core.pager
2262 core.preferSymlinkRefs
2263 core.preloadindex
2264 core.quotepath
2265 core.repositoryFormatVersion
2266 core.safecrlf
2267 core.sharedRepository
2268 core.sparseCheckout
2269 core.symlinks
2270 core.trustctime
2271 core.untrackedCache
2272 core.warnAmbiguousRefs
2273 core.whitespace
2274 core.worktree
2275 diff.autorefreshindex
2276 diff.external
2277 diff.ignoreSubmodules
2278 diff.mnemonicprefix
2279 diff.noprefix
2280 diff.renameLimit
2281 diff.renames
2282 diff.statGraphWidth
2283 diff.submodule
2284 diff.suppressBlankEmpty
2285 diff.tool
2286 diff.wordRegex
2287 diff.algorithm
2288 difftool.
2289 difftool.prompt
2290 fetch.recurseSubmodules
2291 fetch.unpackLimit
2292 format.attach
2293 format.cc
2294 format.coverLetter
2295 format.from
2296 format.headers
2297 format.numbered
2298 format.pretty
2299 format.signature
2300 format.signoff
2301 format.subjectprefix
2302 format.suffix
2303 format.thread
2304 format.to
2306 gc.aggressiveWindow
2307 gc.auto
2308 gc.autopacklimit
2309 gc.packrefs
2310 gc.pruneexpire
2311 gc.reflogexpire
2312 gc.reflogexpireunreachable
2313 gc.rerereresolved
2314 gc.rerereunresolved
2315 gitcvs.allbinary
2316 gitcvs.commitmsgannotation
2317 gitcvs.dbTableNamePrefix
2318 gitcvs.dbdriver
2319 gitcvs.dbname
2320 gitcvs.dbpass
2321 gitcvs.dbuser
2322 gitcvs.enabled
2323 gitcvs.logfile
2324 gitcvs.usecrlfattr
2325 guitool.
2326 gui.blamehistoryctx
2327 gui.commitmsgwidth
2328 gui.copyblamethreshold
2329 gui.diffcontext
2330 gui.encoding
2331 gui.fastcopyblame
2332 gui.matchtrackingbranch
2333 gui.newbranchtemplate
2334 gui.pruneduringfetch
2335 gui.spellingdictionary
2336 gui.trustmtime
2337 help.autocorrect
2338 help.browser
2339 help.format
2340 http.lowSpeedLimit
2341 http.lowSpeedTime
2342 http.maxRequests
2343 http.minSessions
2344 http.noEPSV
2345 http.postBuffer
2346 http.proxy
2347 http.sslCipherList
2348 http.sslVersion
2349 http.sslCAInfo
2350 http.sslCAPath
2351 http.sslCert
2352 http.sslCertPasswordProtected
2353 http.sslKey
2354 http.sslVerify
2355 http.useragent
2356 i18n.commitEncoding
2357 i18n.logOutputEncoding
2358 imap.authMethod
2359 imap.folder
2360 imap.host
2361 imap.pass
2362 imap.port
2363 imap.preformattedHTML
2364 imap.sslverify
2365 imap.tunnel
2366 imap.user
2367 init.templatedir
2368 instaweb.browser
2369 instaweb.httpd
2370 instaweb.local
2371 instaweb.modulepath
2372 instaweb.port
2373 interactive.singlekey
2374 log.date
2375 log.decorate
2376 log.showroot
2377 mailmap.file
2378 man.
2379 man.viewer
2380 merge.
2381 merge.conflictstyle
2382 merge.log
2383 merge.renameLimit
2384 merge.renormalize
2385 merge.stat
2386 merge.tool
2387 merge.verbosity
2388 mergetool.
2389 mergetool.keepBackup
2390 mergetool.keepTemporaries
2391 mergetool.prompt
2392 notes.displayRef
2393 notes.rewrite.
2394 notes.rewrite.amend
2395 notes.rewrite.rebase
2396 notes.rewriteMode
2397 notes.rewriteRef
2398 pack.compression
2399 pack.deltaCacheLimit
2400 pack.deltaCacheSize
2401 pack.depth
2402 pack.indexVersion
2403 pack.packSizeLimit
2404 pack.threads
2405 pack.window
2406 pack.windowMemory
2407 pager.
2408 pretty.
2409 pull.octopus
2410 pull.twohead
2411 push.default
2412 push.followTags
2413 rebase.autosquash
2414 rebase.stat
2415 receive.autogc
2416 receive.denyCurrentBranch
2417 receive.denyDeleteCurrent
2418 receive.denyDeletes
2419 receive.denyNonFastForwards
2420 receive.fsckObjects
2421 receive.unpackLimit
2422 receive.updateserverinfo
2423 remote.pushdefault
2424 remotes.
2425 repack.usedeltabaseoffset
2426 rerere.autoupdate
2427 rerere.enabled
2428 sendemail.
2429 sendemail.aliasesfile
2430 sendemail.aliasfiletype
2431 sendemail.bcc
2432 sendemail.cc
2433 sendemail.cccmd
2434 sendemail.chainreplyto
2435 sendemail.confirm
2436 sendemail.envelopesender
2437 sendemail.from
2438 sendemail.identity
2439 sendemail.multiedit
2440 sendemail.signedoffbycc
2441 sendemail.smtpdomain
2442 sendemail.smtpencryption
2443 sendemail.smtppass
2444 sendemail.smtpserver
2445 sendemail.smtpserveroption
2446 sendemail.smtpserverport
2447 sendemail.smtpuser
2448 sendemail.suppresscc
2449 sendemail.suppressfrom
2450 sendemail.thread
2451 sendemail.to
2452 sendemail.validate
2453 showbranch.default
2454 status.relativePaths
2455 status.showUntrackedFiles
2456 status.submodulesummary
2457 submodule.
2458 tar.umask
2459 transfer.unpackLimit
2460 url.
2461 user.email
2462 user.name
2463 user.signingkey
2464 web.browser
2465 branch. remote.
2469 _git_remote ()
2471 local subcommands="add rename remove set-head set-branches set-url show prune update"
2472 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2473 if [ -z "$subcommand" ]; then
2474 __gitcomp "$subcommands"
2475 return
2478 case "$subcommand" in
2479 rename|remove|set-url|show|prune)
2480 __gitcomp_nl "$(__git_remotes)"
2482 set-head|set-branches)
2483 __git_complete_remote_or_refspec
2485 update)
2486 __gitcomp "$(__git_get_config_variables "remotes")"
2490 esac
2493 _git_replace ()
2495 __git_complete_refs
2498 _git_reset ()
2500 __git_has_doubledash && return
2502 case "$cur" in
2503 --*)
2504 __gitcomp "--merge --mixed --hard --soft --patch"
2505 return
2507 esac
2508 __git_complete_refs
2511 _git_revert ()
2513 __git_find_repo_path
2514 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2515 __gitcomp "--continue --quit --abort"
2516 return
2518 case "$cur" in
2519 --*)
2520 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2521 return
2523 esac
2524 __git_complete_refs
2527 _git_rm ()
2529 case "$cur" in
2530 --*)
2531 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2532 return
2534 esac
2536 __git_complete_index_file "--cached"
2539 _git_shortlog ()
2541 __git_has_doubledash && return
2543 case "$cur" in
2544 --*)
2545 __gitcomp "
2546 $__git_log_common_options
2547 $__git_log_shortlog_options
2548 --numbered --summary
2550 return
2552 esac
2553 __git_complete_revlist
2556 _git_show ()
2558 __git_has_doubledash && return
2560 case "$cur" in
2561 --pretty=*|--format=*)
2562 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2563 " "" "${cur#*=}"
2564 return
2566 --diff-algorithm=*)
2567 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2568 return
2570 --submodule=*)
2571 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2572 return
2574 --*)
2575 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2576 --show-signature
2577 $__git_diff_common_options
2579 return
2581 esac
2582 __git_complete_revlist_file
2585 _git_show_branch ()
2587 case "$cur" in
2588 --*)
2589 __gitcomp "
2590 --all --remotes --topo-order --date-order --current --more=
2591 --list --independent --merge-base --no-name
2592 --color --no-color
2593 --sha1-name --sparse --topics --reflog
2595 return
2597 esac
2598 __git_complete_revlist
2601 _git_stash ()
2603 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2604 local subcommands='save list show apply clear drop pop create branch'
2605 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2606 if [ -z "$subcommand" ]; then
2607 case "$cur" in
2608 --*)
2609 __gitcomp "$save_opts"
2612 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2613 __gitcomp "$subcommands"
2616 esac
2617 else
2618 case "$subcommand,$cur" in
2619 save,--*)
2620 __gitcomp "$save_opts"
2622 apply,--*|pop,--*)
2623 __gitcomp "--index --quiet"
2625 drop,--*)
2626 __gitcomp "--quiet"
2628 show,--*|branch,--*)
2630 branch,*)
2631 if [ $cword -eq 3 ]; then
2632 __git_complete_refs
2633 else
2634 __gitcomp_nl "$(__git stash list \
2635 | sed -n -e 's/:.*//p')"
2638 show,*|apply,*|drop,*|pop,*)
2639 __gitcomp_nl "$(__git stash list \
2640 | sed -n -e 's/:.*//p')"
2644 esac
2648 _git_submodule ()
2650 __git_has_doubledash && return
2652 local subcommands="add status init deinit update summary foreach sync"
2653 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2654 case "$cur" in
2655 --*)
2656 __gitcomp "--quiet --cached"
2659 __gitcomp "$subcommands"
2661 esac
2662 return
2666 _git_svn ()
2668 local subcommands="
2669 init fetch clone rebase dcommit log find-rev
2670 set-tree commit-diff info create-ignore propget
2671 proplist show-ignore show-externals branch tag blame
2672 migrate mkdirs reset gc
2674 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2675 if [ -z "$subcommand" ]; then
2676 __gitcomp "$subcommands"
2677 else
2678 local remote_opts="--username= --config-dir= --no-auth-cache"
2679 local fc_opts="
2680 --follow-parent --authors-file= --repack=
2681 --no-metadata --use-svm-props --use-svnsync-props
2682 --log-window-size= --no-checkout --quiet
2683 --repack-flags --use-log-author --localtime
2684 --ignore-paths= --include-paths= $remote_opts
2686 local init_opts="
2687 --template= --shared= --trunk= --tags=
2688 --branches= --stdlayout --minimize-url
2689 --no-metadata --use-svm-props --use-svnsync-props
2690 --rewrite-root= --prefix= --use-log-author
2691 --add-author-from $remote_opts
2693 local cmt_opts="
2694 --edit --rmdir --find-copies-harder --copy-similarity=
2697 case "$subcommand,$cur" in
2698 fetch,--*)
2699 __gitcomp "--revision= --fetch-all $fc_opts"
2701 clone,--*)
2702 __gitcomp "--revision= $fc_opts $init_opts"
2704 init,--*)
2705 __gitcomp "$init_opts"
2707 dcommit,--*)
2708 __gitcomp "
2709 --merge --strategy= --verbose --dry-run
2710 --fetch-all --no-rebase --commit-url
2711 --revision --interactive $cmt_opts $fc_opts
2714 set-tree,--*)
2715 __gitcomp "--stdin $cmt_opts $fc_opts"
2717 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2718 show-externals,--*|mkdirs,--*)
2719 __gitcomp "--revision="
2721 log,--*)
2722 __gitcomp "
2723 --limit= --revision= --verbose --incremental
2724 --oneline --show-commit --non-recursive
2725 --authors-file= --color
2728 rebase,--*)
2729 __gitcomp "
2730 --merge --verbose --strategy= --local
2731 --fetch-all --dry-run $fc_opts
2734 commit-diff,--*)
2735 __gitcomp "--message= --file= --revision= $cmt_opts"
2737 info,--*)
2738 __gitcomp "--url"
2740 branch,--*)
2741 __gitcomp "--dry-run --message --tag"
2743 tag,--*)
2744 __gitcomp "--dry-run --message"
2746 blame,--*)
2747 __gitcomp "--git-format"
2749 migrate,--*)
2750 __gitcomp "
2751 --config-dir= --ignore-paths= --minimize
2752 --no-auth-cache --username=
2755 reset,--*)
2756 __gitcomp "--revision= --parent"
2760 esac
2764 _git_tag ()
2766 local i c=1 f=0
2767 while [ $c -lt $cword ]; do
2768 i="${words[c]}"
2769 case "$i" in
2770 -d|-v)
2771 __gitcomp_nl "$(__git_tags)"
2772 return
2777 esac
2778 ((c++))
2779 done
2781 case "$prev" in
2782 -m|-F)
2784 -*|tag)
2785 if [ $f = 1 ]; then
2786 __gitcomp_nl "$(__git_tags)"
2790 __git_complete_refs
2792 esac
2794 case "$cur" in
2795 --*)
2796 __gitcomp "
2797 --list --delete --verify --annotate --message --file
2798 --sign --cleanup --local-user --force --column --sort
2799 --contains --points-at
2802 esac
2805 _git_whatchanged ()
2807 _git_log
2810 _git_worktree ()
2812 local subcommands="add list lock prune unlock"
2813 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2814 if [ -z "$subcommand" ]; then
2815 __gitcomp "$subcommands"
2816 else
2817 case "$subcommand,$cur" in
2818 add,--*)
2819 __gitcomp "--detach"
2821 list,--*)
2822 __gitcomp "--porcelain"
2824 lock,--*)
2825 __gitcomp "--reason"
2827 prune,--*)
2828 __gitcomp "--dry-run --expire --verbose"
2832 esac
2836 __git_main ()
2838 local i c=1 command __git_dir __git_repo_path
2839 local __git_C_args C_args_count=0
2841 while [ $c -lt $cword ]; do
2842 i="${words[c]}"
2843 case "$i" in
2844 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2845 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2846 --bare) __git_dir="." ;;
2847 --help) command="help"; break ;;
2848 -c|--work-tree|--namespace) ((c++)) ;;
2849 -C) __git_C_args[C_args_count++]=-C
2850 ((c++))
2851 __git_C_args[C_args_count++]="${words[c]}"
2853 -*) ;;
2854 *) command="$i"; break ;;
2855 esac
2856 ((c++))
2857 done
2859 if [ -z "$command" ]; then
2860 case "$prev" in
2861 --git-dir|-C|--work-tree)
2862 # these need a path argument, let's fall back to
2863 # Bash filename completion
2864 return
2866 -c|--namespace)
2867 # we don't support completing these options' arguments
2868 return
2870 esac
2871 case "$cur" in
2872 --*) __gitcomp "
2873 --paginate
2874 --no-pager
2875 --git-dir=
2876 --bare
2877 --version
2878 --exec-path
2879 --exec-path=
2880 --html-path
2881 --man-path
2882 --info-path
2883 --work-tree=
2884 --namespace=
2885 --no-replace-objects
2886 --help
2889 *) __git_compute_porcelain_commands
2890 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2891 esac
2892 return
2895 local completion_func="_git_${command//-/_}"
2896 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
2898 local expansion=$(__git_aliased_command "$command")
2899 if [ -n "$expansion" ]; then
2900 words[1]=$expansion
2901 completion_func="_git_${expansion//-/_}"
2902 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
2906 __gitk_main ()
2908 __git_has_doubledash && return
2910 local __git_repo_path
2911 __git_find_repo_path
2913 local merge=""
2914 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2915 merge="--merge"
2917 case "$cur" in
2918 --*)
2919 __gitcomp "
2920 $__git_log_common_options
2921 $__git_log_gitk_options
2922 $merge
2924 return
2926 esac
2927 __git_complete_revlist
2930 if [[ -n ${ZSH_VERSION-} ]]; then
2931 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2933 autoload -U +X compinit && compinit
2935 __gitcomp ()
2937 emulate -L zsh
2939 local cur_="${3-$cur}"
2941 case "$cur_" in
2942 --*=)
2945 local c IFS=$' \t\n'
2946 local -a array
2947 for c in ${=1}; do
2948 c="$c${4-}"
2949 case $c in
2950 --*=*|*.) ;;
2951 *) c="$c " ;;
2952 esac
2953 array[${#array[@]}+1]="$c"
2954 done
2955 compset -P '*[=:]'
2956 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2958 esac
2961 __gitcomp_nl ()
2963 emulate -L zsh
2965 local IFS=$'\n'
2966 compset -P '*[=:]'
2967 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2970 __gitcomp_file ()
2972 emulate -L zsh
2974 local IFS=$'\n'
2975 compset -P '*[=:]'
2976 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2979 _git ()
2981 local _ret=1 cur cword prev
2982 cur=${words[CURRENT]}
2983 prev=${words[CURRENT-1]}
2984 let cword=CURRENT-1
2985 emulate ksh -c __${service}_main
2986 let _ret && _default && _ret=0
2987 return _ret
2990 compdef _git git gitk
2991 return
2994 __git_func_wrap ()
2996 local cur words cword prev
2997 _get_comp_words_by_ref -n =: cur words cword prev
3001 # Setup completion for certain functions defined above by setting common
3002 # variables and workarounds.
3003 # This is NOT a public function; use at your own risk.
3004 __git_complete ()
3006 local wrapper="__git_wrap${2}"
3007 eval "$wrapper () { __git_func_wrap $2 ; }"
3008 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3009 || complete -o default -o nospace -F $wrapper $1
3012 # wrapper for backwards compatibility
3013 _git ()
3015 __git_wrap__git_main
3018 # wrapper for backwards compatibility
3019 _gitk ()
3021 __git_wrap__gitk_main
3024 __git_complete git __git_main
3025 __git_complete gitk __gitk_main
3027 # The following are necessary only for Cygwin, and only are needed
3028 # when the user has tab-completed the executable name and consequently
3029 # included the '.exe' suffix.
3031 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3032 __git_complete git.exe __git_main