completion: offer ctags symbol names for 'git log -S', '-G' and '-L:'
[alt-git.git] / contrib / completion / git-completion.bash
blobd6f25a7e0b3f50b6f6f6d5b645fe794c1cbe4788
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 # Fills the COMPREPLY array with prefiltered words without any additional
217 # processing.
218 # Callers must take care of providing only words that match the current word
219 # to be completed and adding any prefix and/or suffix (trailing space!), if
220 # necessary.
221 # 1: List of newline-separated matching completion words, complete with
222 # prefix and suffix.
223 __gitcomp_direct ()
225 local IFS=$'\n'
227 COMPREPLY=($1)
230 __gitcompappend ()
232 local x i=${#COMPREPLY[@]}
233 for x in $1; do
234 if [[ "$x" == "$3"* ]]; then
235 COMPREPLY[i++]="$2$x$4"
237 done
240 __gitcompadd ()
242 COMPREPLY=()
243 __gitcompappend "$@"
246 # Generates completion reply, appending a space to possible completion words,
247 # if necessary.
248 # It accepts 1 to 4 arguments:
249 # 1: List of possible completion words.
250 # 2: A prefix to be added to each possible completion word (optional).
251 # 3: Generate possible completion matches for this word (optional).
252 # 4: A suffix to be appended to each possible completion word (optional).
253 __gitcomp ()
255 local cur_="${3-$cur}"
257 case "$cur_" in
258 --*=)
261 local c i=0 IFS=$' \t\n'
262 for c in $1; do
263 c="$c${4-}"
264 if [[ $c == "$cur_"* ]]; then
265 case $c in
266 --*=*|*.) ;;
267 *) c="$c " ;;
268 esac
269 COMPREPLY[i++]="${2-}$c"
271 done
273 esac
276 # Variation of __gitcomp_nl () that appends to the existing list of
277 # completion candidates, COMPREPLY.
278 __gitcomp_nl_append ()
280 local IFS=$'\n'
281 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
284 # Generates completion reply from newline-separated possible completion words
285 # by appending a space to all of them.
286 # It accepts 1 to 4 arguments:
287 # 1: List of possible completion words, separated by a single newline.
288 # 2: A prefix to be added to each possible completion word (optional).
289 # 3: Generate possible completion matches for this word (optional).
290 # 4: A suffix to be appended to each possible completion word instead of
291 # the default space (optional). If specified but empty, nothing is
292 # appended.
293 __gitcomp_nl ()
295 COMPREPLY=()
296 __gitcomp_nl_append "$@"
299 # Generates completion reply with compgen from newline-separated possible
300 # completion filenames.
301 # It accepts 1 to 3 arguments:
302 # 1: List of possible completion filenames, separated by a single newline.
303 # 2: A directory prefix to be added to each possible completion filename
304 # (optional).
305 # 3: Generate possible completion matches for this word (optional).
306 __gitcomp_file ()
308 local IFS=$'\n'
310 # XXX does not work when the directory prefix contains a tilde,
311 # since tilde expansion is not applied.
312 # This means that COMPREPLY will be empty and Bash default
313 # completion will be used.
314 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
316 # use a hack to enable file mode in bash < 4
317 compopt -o filenames +o nospace 2>/dev/null ||
318 compgen -f /non-existing-dir/ > /dev/null
321 # Execute 'git ls-files', unless the --committable option is specified, in
322 # which case it runs 'git diff-index' to find out the files that can be
323 # committed. It return paths relative to the directory specified in the first
324 # argument, and using the options specified in the second argument.
325 __git_ls_files_helper ()
327 if [ "$2" == "--committable" ]; then
328 __git -C "$1" diff-index --name-only --relative HEAD
329 else
330 # NOTE: $2 is not quoted in order to support multiple options
331 __git -C "$1" ls-files --exclude-standard $2
336 # __git_index_files accepts 1 or 2 arguments:
337 # 1: Options to pass to ls-files (required).
338 # 2: A directory path (optional).
339 # If provided, only files within the specified directory are listed.
340 # Sub directories are never recursed. Path must have a trailing
341 # slash.
342 __git_index_files ()
344 local root="${2-.}" file
346 __git_ls_files_helper "$root" "$1" |
347 while read -r file; do
348 case "$file" in
349 ?*/*) echo "${file%%/*}" ;;
350 *) echo "$file" ;;
351 esac
352 done | sort | uniq
355 # Lists branches from the local repository.
356 # 1: A prefix to be added to each listed branch (optional).
357 # 2: List only branches matching this word (optional; list all branches if
358 # unset or empty).
359 # 3: A suffix to be appended to each listed branch (optional).
360 __git_heads ()
362 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
364 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
365 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
368 # Lists tags from the local repository.
369 # Accepts the same positional parameters as __git_heads() above.
370 __git_tags ()
372 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
374 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
375 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
378 # Lists refs from the local (by default) or from a remote repository.
379 # It accepts 0, 1 or 2 arguments:
380 # 1: The remote to list refs from (optional; ignored, if set but empty).
381 # Can be the name of a configured remote, a path, or a URL.
382 # 2: In addition to local refs, list unique branches from refs/remotes/ for
383 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
384 # 3: A prefix to be added to each listed ref (optional).
385 # 4: List only refs matching this word (optional; list all refs if unset or
386 # empty).
387 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
388 # but empty).
390 # Use __git_complete_refs() instead.
391 __git_refs ()
393 local i hash dir track="${2-}"
394 local list_refs_from=path remote="${1-}"
395 local format refs
396 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
397 local match="${4-}"
398 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
400 __git_find_repo_path
401 dir="$__git_repo_path"
403 if [ -z "$remote" ]; then
404 if [ -z "$dir" ]; then
405 return
407 else
408 if __git_is_configured_remote "$remote"; then
409 # configured remote takes precedence over a
410 # local directory with the same name
411 list_refs_from=remote
412 elif [ -d "$remote/.git" ]; then
413 dir="$remote/.git"
414 elif [ -d "$remote" ]; then
415 dir="$remote"
416 else
417 list_refs_from=url
421 if [ "$list_refs_from" = path ]; then
422 if [[ "$cur_" == ^* ]]; then
423 pfx="$pfx^"
424 fer_pfx="$fer_pfx^"
425 cur_=${cur_#^}
426 match=${match#^}
428 case "$cur_" in
429 refs|refs/*)
430 format="refname"
431 refs=("$match*" "$match*/**")
432 track=""
435 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
436 case "$i" in
437 $match*)
438 if [ -e "$dir/$i" ]; then
439 echo "$pfx$i$sfx"
442 esac
443 done
444 format="refname:strip=2"
445 refs=("refs/tags/$match*" "refs/tags/$match*/**"
446 "refs/heads/$match*" "refs/heads/$match*/**"
447 "refs/remotes/$match*" "refs/remotes/$match*/**")
449 esac
450 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
451 "${refs[@]}"
452 if [ -n "$track" ]; then
453 # employ the heuristic used by git checkout
454 # Try to find a remote branch that matches the completion word
455 # but only output if the branch name is unique
456 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
457 --sort="refname:strip=3" \
458 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
459 uniq -u
461 return
463 case "$cur_" in
464 refs|refs/*)
465 __git ls-remote "$remote" "$match*" | \
466 while read -r hash i; do
467 case "$i" in
468 *^{}) ;;
469 *) echo "$pfx$i$sfx" ;;
470 esac
471 done
474 if [ "$list_refs_from" = remote ]; then
475 case "HEAD" in
476 $match*) echo "${pfx}HEAD$sfx" ;;
477 esac
478 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
479 "refs/remotes/$remote/$match*" \
480 "refs/remotes/$remote/$match*/**"
481 else
482 local query_symref
483 case "HEAD" in
484 $match*) query_symref="HEAD" ;;
485 esac
486 __git ls-remote "$remote" $query_symref \
487 "refs/tags/$match*" "refs/heads/$match*" \
488 "refs/remotes/$match*" |
489 while read -r hash i; do
490 case "$i" in
491 *^{}) ;;
492 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
493 *) echo "$pfx$i$sfx" ;; # symbolic refs
494 esac
495 done
498 esac
501 # Completes refs, short and long, local and remote, symbolic and pseudo.
503 # Usage: __git_complete_refs [<option>]...
504 # --remote=<remote>: The remote to list refs from, can be the name of a
505 # configured remote, a path, or a URL.
506 # --track: List unique remote branches for 'git checkout's tracking DWIMery.
507 # --pfx=<prefix>: A prefix to be added to each ref.
508 # --cur=<word>: The current ref to be completed. Defaults to the current
509 # word to be completed.
510 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
511 # space.
512 __git_complete_refs ()
514 local remote track pfx cur_="$cur" sfx=" "
516 while test $# != 0; do
517 case "$1" in
518 --remote=*) remote="${1##--remote=}" ;;
519 --track) track="yes" ;;
520 --pfx=*) pfx="${1##--pfx=}" ;;
521 --cur=*) cur_="${1##--cur=}" ;;
522 --sfx=*) sfx="${1##--sfx=}" ;;
523 *) return 1 ;;
524 esac
525 shift
526 done
528 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
531 # __git_refs2 requires 1 argument (to pass to __git_refs)
532 # Deprecated: use __git_complete_fetch_refspecs() instead.
533 __git_refs2 ()
535 local i
536 for i in $(__git_refs "$1"); do
537 echo "$i:$i"
538 done
541 # Completes refspecs for fetching from a remote repository.
542 # 1: The remote repository.
543 # 2: A prefix to be added to each listed refspec (optional).
544 # 3: The ref to be completed as a refspec instead of the current word to be
545 # completed (optional)
546 # 4: A suffix to be appended to each listed refspec instead of the default
547 # space (optional).
548 __git_complete_fetch_refspecs ()
550 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
552 __gitcomp_direct "$(
553 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
554 echo "$pfx$i:$i$sfx"
555 done
559 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
560 __git_refs_remotes ()
562 local i hash
563 __git ls-remote "$1" 'refs/heads/*' | \
564 while read -r hash i; do
565 echo "$i:refs/remotes/$1/${i#refs/heads/}"
566 done
569 __git_remotes ()
571 __git_find_repo_path
572 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
573 __git remote
576 # Returns true if $1 matches the name of a configured remote, false otherwise.
577 __git_is_configured_remote ()
579 local remote
580 for remote in $(__git_remotes); do
581 if [ "$remote" = "$1" ]; then
582 return 0
584 done
585 return 1
588 __git_list_merge_strategies ()
590 git merge -s help 2>&1 |
591 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
592 s/\.$//
593 s/.*://
594 s/^[ ]*//
595 s/[ ]*$//
600 __git_merge_strategies=
601 # 'git merge -s help' (and thus detection of the merge strategy
602 # list) fails, unfortunately, if run outside of any git working
603 # tree. __git_merge_strategies is set to the empty string in
604 # that case, and the detection will be repeated the next time it
605 # is needed.
606 __git_compute_merge_strategies ()
608 test -n "$__git_merge_strategies" ||
609 __git_merge_strategies=$(__git_list_merge_strategies)
612 __git_complete_revlist_file ()
614 local pfx ls ref cur_="$cur"
615 case "$cur_" in
616 *..?*:*)
617 return
619 ?*:*)
620 ref="${cur_%%:*}"
621 cur_="${cur_#*:}"
622 case "$cur_" in
623 ?*/*)
624 pfx="${cur_%/*}"
625 cur_="${cur_##*/}"
626 ls="$ref:$pfx"
627 pfx="$pfx/"
630 ls="$ref"
632 esac
634 case "$COMP_WORDBREAKS" in
635 *:*) : great ;;
636 *) pfx="$ref:$pfx" ;;
637 esac
639 __gitcomp_nl "$(__git ls-tree "$ls" \
640 | sed '/^100... blob /{
641 s,^.* ,,
642 s,$, ,
644 /^120000 blob /{
645 s,^.* ,,
646 s,$, ,
648 /^040000 tree /{
649 s,^.* ,,
650 s,$,/,
652 s/^.* //')" \
653 "$pfx" "$cur_" ""
655 *...*)
656 pfx="${cur_%...*}..."
657 cur_="${cur_#*...}"
658 __git_complete_refs --pfx="$pfx" --cur="$cur_"
660 *..*)
661 pfx="${cur_%..*}.."
662 cur_="${cur_#*..}"
663 __git_complete_refs --pfx="$pfx" --cur="$cur_"
666 __git_complete_refs
668 esac
672 # __git_complete_index_file requires 1 argument:
673 # 1: the options to pass to ls-file
675 # The exception is --committable, which finds the files appropriate commit.
676 __git_complete_index_file ()
678 local pfx="" cur_="$cur"
680 case "$cur_" in
681 ?*/*)
682 pfx="${cur_%/*}"
683 cur_="${cur_##*/}"
684 pfx="${pfx}/"
686 esac
688 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
691 __git_complete_file ()
693 __git_complete_revlist_file
696 __git_complete_revlist ()
698 __git_complete_revlist_file
701 __git_complete_remote_or_refspec ()
703 local cur_="$cur" cmd="${words[1]}"
704 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
705 if [ "$cmd" = "remote" ]; then
706 ((c++))
708 while [ $c -lt $cword ]; do
709 i="${words[c]}"
710 case "$i" in
711 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
712 --all)
713 case "$cmd" in
714 push) no_complete_refspec=1 ;;
715 fetch)
716 return
718 *) ;;
719 esac
721 -*) ;;
722 *) remote="$i"; break ;;
723 esac
724 ((c++))
725 done
726 if [ -z "$remote" ]; then
727 __gitcomp_nl "$(__git_remotes)"
728 return
730 if [ $no_complete_refspec = 1 ]; then
731 return
733 [ "$remote" = "." ] && remote=
734 case "$cur_" in
735 *:*)
736 case "$COMP_WORDBREAKS" in
737 *:*) : great ;;
738 *) pfx="${cur_%%:*}:" ;;
739 esac
740 cur_="${cur_#*:}"
741 lhs=0
744 pfx="+"
745 cur_="${cur_#+}"
747 esac
748 case "$cmd" in
749 fetch)
750 if [ $lhs = 1 ]; then
751 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
752 else
753 __git_complete_refs --pfx="$pfx" --cur="$cur_"
756 pull|remote)
757 if [ $lhs = 1 ]; then
758 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
759 else
760 __git_complete_refs --pfx="$pfx" --cur="$cur_"
763 push)
764 if [ $lhs = 1 ]; then
765 __git_complete_refs --pfx="$pfx" --cur="$cur_"
766 else
767 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
770 esac
773 __git_complete_strategy ()
775 __git_compute_merge_strategies
776 case "$prev" in
777 -s|--strategy)
778 __gitcomp "$__git_merge_strategies"
779 return 0
780 esac
781 case "$cur" in
782 --strategy=*)
783 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
784 return 0
786 esac
787 return 1
790 __git_commands () {
791 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
792 then
793 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
794 else
795 git help -a|egrep '^ [a-zA-Z0-9]'
799 __git_list_all_commands ()
801 local i IFS=" "$'\n'
802 for i in $(__git_commands)
804 case $i in
805 *--*) : helper pattern;;
806 *) echo $i;;
807 esac
808 done
811 __git_all_commands=
812 __git_compute_all_commands ()
814 test -n "$__git_all_commands" ||
815 __git_all_commands=$(__git_list_all_commands)
818 __git_list_porcelain_commands ()
820 local i IFS=" "$'\n'
821 __git_compute_all_commands
822 for i in $__git_all_commands
824 case $i in
825 *--*) : helper pattern;;
826 applymbox) : ask gittus;;
827 applypatch) : ask gittus;;
828 archimport) : import;;
829 cat-file) : plumbing;;
830 check-attr) : plumbing;;
831 check-ignore) : plumbing;;
832 check-mailmap) : plumbing;;
833 check-ref-format) : plumbing;;
834 checkout-index) : plumbing;;
835 column) : internal helper;;
836 commit-tree) : plumbing;;
837 count-objects) : infrequent;;
838 credential) : credentials;;
839 credential-*) : credentials helper;;
840 cvsexportcommit) : export;;
841 cvsimport) : import;;
842 cvsserver) : daemon;;
843 daemon) : daemon;;
844 diff-files) : plumbing;;
845 diff-index) : plumbing;;
846 diff-tree) : plumbing;;
847 fast-import) : import;;
848 fast-export) : export;;
849 fsck-objects) : plumbing;;
850 fetch-pack) : plumbing;;
851 fmt-merge-msg) : plumbing;;
852 for-each-ref) : plumbing;;
853 hash-object) : plumbing;;
854 http-*) : transport;;
855 index-pack) : plumbing;;
856 init-db) : deprecated;;
857 local-fetch) : plumbing;;
858 ls-files) : plumbing;;
859 ls-remote) : plumbing;;
860 ls-tree) : plumbing;;
861 mailinfo) : plumbing;;
862 mailsplit) : plumbing;;
863 merge-*) : plumbing;;
864 mktree) : plumbing;;
865 mktag) : plumbing;;
866 pack-objects) : plumbing;;
867 pack-redundant) : plumbing;;
868 pack-refs) : plumbing;;
869 parse-remote) : plumbing;;
870 patch-id) : plumbing;;
871 prune) : plumbing;;
872 prune-packed) : plumbing;;
873 quiltimport) : import;;
874 read-tree) : plumbing;;
875 receive-pack) : plumbing;;
876 remote-*) : transport;;
877 rerere) : plumbing;;
878 rev-list) : plumbing;;
879 rev-parse) : plumbing;;
880 runstatus) : plumbing;;
881 sh-setup) : internal;;
882 shell) : daemon;;
883 show-ref) : plumbing;;
884 send-pack) : plumbing;;
885 show-index) : plumbing;;
886 ssh-*) : transport;;
887 stripspace) : plumbing;;
888 symbolic-ref) : plumbing;;
889 unpack-file) : plumbing;;
890 unpack-objects) : plumbing;;
891 update-index) : plumbing;;
892 update-ref) : plumbing;;
893 update-server-info) : daemon;;
894 upload-archive) : plumbing;;
895 upload-pack) : plumbing;;
896 write-tree) : plumbing;;
897 var) : infrequent;;
898 verify-pack) : infrequent;;
899 verify-tag) : plumbing;;
900 *) echo $i;;
901 esac
902 done
905 __git_porcelain_commands=
906 __git_compute_porcelain_commands ()
908 test -n "$__git_porcelain_commands" ||
909 __git_porcelain_commands=$(__git_list_porcelain_commands)
912 # Lists all set config variables starting with the given section prefix,
913 # with the prefix removed.
914 __git_get_config_variables ()
916 local section="$1" i IFS=$'\n'
917 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
918 echo "${i#$section.}"
919 done
922 __git_pretty_aliases ()
924 __git_get_config_variables "pretty"
927 __git_aliases ()
929 __git_get_config_variables "alias"
932 # __git_aliased_command requires 1 argument
933 __git_aliased_command ()
935 local word cmdline=$(__git config --get "alias.$1")
936 for word in $cmdline; do
937 case "$word" in
938 \!gitk|gitk)
939 echo "gitk"
940 return
942 \!*) : shell command alias ;;
943 -*) : option ;;
944 *=*) : setting env ;;
945 git) : git itself ;;
946 \(\)) : skip parens of shell function definition ;;
947 {) : skip start of shell helper function ;;
948 :) : skip null command ;;
949 \'*) : skip opening quote after sh -c ;;
951 echo "$word"
952 return
953 esac
954 done
957 # __git_find_on_cmdline requires 1 argument
958 __git_find_on_cmdline ()
960 local word subcommand c=1
961 while [ $c -lt $cword ]; do
962 word="${words[c]}"
963 for subcommand in $1; do
964 if [ "$subcommand" = "$word" ]; then
965 echo "$subcommand"
966 return
968 done
969 ((c++))
970 done
973 # Echo the value of an option set on the command line or config
975 # $1: short option name
976 # $2: long option name including =
977 # $3: list of possible values
978 # $4: config string (optional)
980 # example:
981 # result="$(__git_get_option_value "-d" "--do-something=" \
982 # "yes no" "core.doSomething")"
984 # result is then either empty (no option set) or "yes" or "no"
986 # __git_get_option_value requires 3 arguments
987 __git_get_option_value ()
989 local c short_opt long_opt val
990 local result= values config_key word
992 short_opt="$1"
993 long_opt="$2"
994 values="$3"
995 config_key="$4"
997 ((c = $cword - 1))
998 while [ $c -ge 0 ]; do
999 word="${words[c]}"
1000 for val in $values; do
1001 if [ "$short_opt$val" = "$word" ] ||
1002 [ "$long_opt$val" = "$word" ]; then
1003 result="$val"
1004 break 2
1006 done
1007 ((c--))
1008 done
1010 if [ -n "$config_key" ] && [ -z "$result" ]; then
1011 result="$(__git config "$config_key")"
1014 echo "$result"
1017 __git_has_doubledash ()
1019 local c=1
1020 while [ $c -lt $cword ]; do
1021 if [ "--" = "${words[c]}" ]; then
1022 return 0
1024 ((c++))
1025 done
1026 return 1
1029 # Try to count non option arguments passed on the command line for the
1030 # specified git command.
1031 # When options are used, it is necessary to use the special -- option to
1032 # tell the implementation were non option arguments begin.
1033 # XXX this can not be improved, since options can appear everywhere, as
1034 # an example:
1035 # git mv x -n y
1037 # __git_count_arguments requires 1 argument: the git command executed.
1038 __git_count_arguments ()
1040 local word i c=0
1042 # Skip "git" (first argument)
1043 for ((i=1; i < ${#words[@]}; i++)); do
1044 word="${words[i]}"
1046 case "$word" in
1048 # Good; we can assume that the following are only non
1049 # option arguments.
1050 ((c = 0))
1052 "$1")
1053 # Skip the specified git command and discard git
1054 # main options
1055 ((c = 0))
1058 ((c++))
1060 esac
1061 done
1063 printf "%d" $c
1066 __git_whitespacelist="nowarn warn error error-all fix"
1068 _git_am ()
1070 __git_find_repo_path
1071 if [ -d "$__git_repo_path"/rebase-apply ]; then
1072 __gitcomp "--skip --continue --resolved --abort"
1073 return
1075 case "$cur" in
1076 --whitespace=*)
1077 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1078 return
1080 --*)
1081 __gitcomp "
1082 --3way --committer-date-is-author-date --ignore-date
1083 --ignore-whitespace --ignore-space-change
1084 --interactive --keep --no-utf8 --signoff --utf8
1085 --whitespace= --scissors
1087 return
1088 esac
1091 _git_apply ()
1093 case "$cur" in
1094 --whitespace=*)
1095 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1096 return
1098 --*)
1099 __gitcomp "
1100 --stat --numstat --summary --check --index
1101 --cached --index-info --reverse --reject --unidiff-zero
1102 --apply --no-add --exclude=
1103 --ignore-whitespace --ignore-space-change
1104 --whitespace= --inaccurate-eof --verbose
1106 return
1107 esac
1110 _git_add ()
1112 case "$cur" in
1113 --*)
1114 __gitcomp "
1115 --interactive --refresh --patch --update --dry-run
1116 --ignore-errors --intent-to-add
1118 return
1119 esac
1121 # XXX should we check for --update and --all options ?
1122 __git_complete_index_file "--others --modified --directory --no-empty-directory"
1125 _git_archive ()
1127 case "$cur" in
1128 --format=*)
1129 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1130 return
1132 --remote=*)
1133 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1134 return
1136 --*)
1137 __gitcomp "
1138 --format= --list --verbose
1139 --prefix= --remote= --exec=
1141 return
1143 esac
1144 __git_complete_file
1147 _git_bisect ()
1149 __git_has_doubledash && return
1151 local subcommands="start bad good skip reset visualize replay log run"
1152 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1153 if [ -z "$subcommand" ]; then
1154 __git_find_repo_path
1155 if [ -f "$__git_repo_path"/BISECT_START ]; then
1156 __gitcomp "$subcommands"
1157 else
1158 __gitcomp "replay start"
1160 return
1163 case "$subcommand" in
1164 bad|good|reset|skip|start)
1165 __git_complete_refs
1169 esac
1172 _git_branch ()
1174 local i c=1 only_local_ref="n" has_r="n"
1176 while [ $c -lt $cword ]; do
1177 i="${words[c]}"
1178 case "$i" in
1179 -d|--delete|-m|--move) only_local_ref="y" ;;
1180 -r|--remotes) has_r="y" ;;
1181 esac
1182 ((c++))
1183 done
1185 case "$cur" in
1186 --set-upstream-to=*)
1187 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1189 --*)
1190 __gitcomp "
1191 --color --no-color --verbose --abbrev= --no-abbrev
1192 --track --no-track --contains --merged --no-merged
1193 --set-upstream-to= --edit-description --list
1194 --unset-upstream --delete --move --remotes
1198 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1199 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1200 else
1201 __git_complete_refs
1204 esac
1207 _git_bundle ()
1209 local cmd="${words[2]}"
1210 case "$cword" in
1212 __gitcomp "create list-heads verify unbundle"
1215 # looking for a file
1218 case "$cmd" in
1219 create)
1220 __git_complete_revlist
1222 esac
1224 esac
1227 _git_checkout ()
1229 __git_has_doubledash && return
1231 case "$cur" in
1232 --conflict=*)
1233 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1235 --*)
1236 __gitcomp "
1237 --quiet --ours --theirs --track --no-track --merge
1238 --conflict= --orphan --patch
1242 # check if --track, --no-track, or --no-guess was specified
1243 # if so, disable DWIM mode
1244 local flags="--track --no-track --no-guess" track_opt="--track"
1245 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1246 track_opt=''
1248 __git_complete_refs $track_opt
1250 esac
1253 _git_cherry ()
1255 __git_complete_refs
1258 _git_cherry_pick ()
1260 __git_find_repo_path
1261 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1262 __gitcomp "--continue --quit --abort"
1263 return
1265 case "$cur" in
1266 --*)
1267 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1270 __git_complete_refs
1272 esac
1275 _git_clean ()
1277 case "$cur" in
1278 --*)
1279 __gitcomp "--dry-run --quiet"
1280 return
1282 esac
1284 # XXX should we check for -x option ?
1285 __git_complete_index_file "--others --directory"
1288 _git_clone ()
1290 case "$cur" in
1291 --*)
1292 __gitcomp "
1293 --local
1294 --no-hardlinks
1295 --shared
1296 --reference
1297 --quiet
1298 --no-checkout
1299 --bare
1300 --mirror
1301 --origin
1302 --upload-pack
1303 --template=
1304 --depth
1305 --single-branch
1306 --branch
1307 --recurse-submodules
1309 return
1311 esac
1314 __git_untracked_file_modes="all no normal"
1316 _git_commit ()
1318 case "$prev" in
1319 -c|-C)
1320 __git_complete_refs
1321 return
1323 esac
1325 case "$cur" in
1326 --cleanup=*)
1327 __gitcomp "default scissors strip verbatim whitespace
1328 " "" "${cur##--cleanup=}"
1329 return
1331 --reuse-message=*|--reedit-message=*|\
1332 --fixup=*|--squash=*)
1333 __git_complete_refs --cur="${cur#*=}"
1334 return
1336 --untracked-files=*)
1337 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1338 return
1340 --*)
1341 __gitcomp "
1342 --all --author= --signoff --verify --no-verify
1343 --edit --no-edit
1344 --amend --include --only --interactive
1345 --dry-run --reuse-message= --reedit-message=
1346 --reset-author --file= --message= --template=
1347 --cleanup= --untracked-files --untracked-files=
1348 --verbose --quiet --fixup= --squash=
1350 return
1351 esac
1353 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1354 __git_complete_index_file "--committable"
1355 else
1356 # This is the first commit
1357 __git_complete_index_file "--cached"
1361 _git_describe ()
1363 case "$cur" in
1364 --*)
1365 __gitcomp "
1366 --all --tags --contains --abbrev= --candidates=
1367 --exact-match --debug --long --match --always
1369 return
1370 esac
1371 __git_complete_refs
1374 __git_diff_algorithms="myers minimal patience histogram"
1376 __git_diff_submodule_formats="diff log short"
1378 __git_diff_common_options="--stat --numstat --shortstat --summary
1379 --patch-with-stat --name-only --name-status --color
1380 --no-color --color-words --no-renames --check
1381 --full-index --binary --abbrev --diff-filter=
1382 --find-copies-harder
1383 --text --ignore-space-at-eol --ignore-space-change
1384 --ignore-all-space --ignore-blank-lines --exit-code
1385 --quiet --ext-diff --no-ext-diff
1386 --no-prefix --src-prefix= --dst-prefix=
1387 --inter-hunk-context=
1388 --patience --histogram --minimal
1389 --raw --word-diff --word-diff-regex=
1390 --dirstat --dirstat= --dirstat-by-file
1391 --dirstat-by-file= --cumulative
1392 --diff-algorithm=
1393 --submodule --submodule=
1396 _git_diff ()
1398 __git_has_doubledash && return
1400 case "$cur" in
1401 --diff-algorithm=*)
1402 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1403 return
1405 --submodule=*)
1406 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1407 return
1409 --*)
1410 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1411 --base --ours --theirs --no-index
1412 $__git_diff_common_options
1414 return
1416 esac
1417 __git_complete_revlist_file
1420 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1421 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1424 _git_difftool ()
1426 __git_has_doubledash && return
1428 case "$cur" in
1429 --tool=*)
1430 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1431 return
1433 --*)
1434 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1435 --base --ours --theirs
1436 --no-renames --diff-filter= --find-copies-harder
1437 --relative --ignore-submodules
1438 --tool="
1439 return
1441 esac
1442 __git_complete_revlist_file
1445 __git_fetch_recurse_submodules="yes on-demand no"
1447 __git_fetch_options="
1448 --quiet --verbose --append --upload-pack --force --keep --depth=
1449 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1452 _git_fetch ()
1454 case "$cur" in
1455 --recurse-submodules=*)
1456 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1457 return
1459 --*)
1460 __gitcomp "$__git_fetch_options"
1461 return
1463 esac
1464 __git_complete_remote_or_refspec
1467 __git_format_patch_options="
1468 --stdout --attach --no-attach --thread --thread= --no-thread
1469 --numbered --start-number --numbered-files --keep-subject --signoff
1470 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1471 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1472 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1473 --output-directory --reroll-count --to= --quiet --notes
1476 _git_format_patch ()
1478 case "$cur" in
1479 --thread=*)
1480 __gitcomp "
1481 deep shallow
1482 " "" "${cur##--thread=}"
1483 return
1485 --*)
1486 __gitcomp "$__git_format_patch_options"
1487 return
1489 esac
1490 __git_complete_revlist
1493 _git_fsck ()
1495 case "$cur" in
1496 --*)
1497 __gitcomp "
1498 --tags --root --unreachable --cache --no-reflogs --full
1499 --strict --verbose --lost-found
1501 return
1503 esac
1506 _git_gc ()
1508 case "$cur" in
1509 --*)
1510 __gitcomp "--prune --aggressive"
1511 return
1513 esac
1516 _git_gitk ()
1518 _gitk
1521 # Lists matching symbol names from a tag (as in ctags) file.
1522 # 1: List symbol names matching this word.
1523 # 2: The tag file to list symbol names from.
1524 # 3: A prefix to be added to each listed symbol name (optional).
1525 # 4: A suffix to be appended to each listed symbol name (optional).
1526 __git_match_ctag () {
1527 awk -v pfx="${3-}" -v sfx="${4-}" "
1528 /^${1//\//\\/}/ { print pfx \$1 sfx }
1529 " "$2"
1532 # Complete symbol names from a tag file.
1533 # Usage: __git_complete_symbol [<option>]...
1534 # --tags=<file>: The tag file to list symbol names from instead of the
1535 # default "tags".
1536 # --pfx=<prefix>: A prefix to be added to each symbol name.
1537 # --cur=<word>: The current symbol name to be completed. Defaults to
1538 # the current word to be completed.
1539 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1540 # of the default space.
1541 __git_complete_symbol () {
1542 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1544 while test $# != 0; do
1545 case "$1" in
1546 --tags=*) tags="${1##--tags=}" ;;
1547 --pfx=*) pfx="${1##--pfx=}" ;;
1548 --cur=*) cur_="${1##--cur=}" ;;
1549 --sfx=*) sfx="${1##--sfx=}" ;;
1550 *) return 1 ;;
1551 esac
1552 shift
1553 done
1555 if test -r "$tags"; then
1556 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1560 _git_grep ()
1562 __git_has_doubledash && return
1564 case "$cur" in
1565 --*)
1566 __gitcomp "
1567 --cached
1568 --text --ignore-case --word-regexp --invert-match
1569 --full-name --line-number
1570 --extended-regexp --basic-regexp --fixed-strings
1571 --perl-regexp
1572 --threads
1573 --files-with-matches --name-only
1574 --files-without-match
1575 --max-depth
1576 --count
1577 --and --or --not --all-match
1579 return
1581 esac
1583 case "$cword,$prev" in
1584 2,*|*,-*)
1585 __git_complete_symbol && return
1587 esac
1589 __git_complete_refs
1592 _git_help ()
1594 case "$cur" in
1595 --*)
1596 __gitcomp "--all --guides --info --man --web"
1597 return
1599 esac
1600 __git_compute_all_commands
1601 __gitcomp "$__git_all_commands $(__git_aliases)
1602 attributes cli core-tutorial cvs-migration
1603 diffcore everyday gitk glossary hooks ignore modules
1604 namespaces repository-layout revisions tutorial tutorial-2
1605 workflows
1609 _git_init ()
1611 case "$cur" in
1612 --shared=*)
1613 __gitcomp "
1614 false true umask group all world everybody
1615 " "" "${cur##--shared=}"
1616 return
1618 --*)
1619 __gitcomp "--quiet --bare --template= --shared --shared="
1620 return
1622 esac
1625 _git_ls_files ()
1627 case "$cur" in
1628 --*)
1629 __gitcomp "--cached --deleted --modified --others --ignored
1630 --stage --directory --no-empty-directory --unmerged
1631 --killed --exclude= --exclude-from=
1632 --exclude-per-directory= --exclude-standard
1633 --error-unmatch --with-tree= --full-name
1634 --abbrev --ignored --exclude-per-directory
1636 return
1638 esac
1640 # XXX ignore options like --modified and always suggest all cached
1641 # files.
1642 __git_complete_index_file "--cached"
1645 _git_ls_remote ()
1647 __gitcomp_nl "$(__git_remotes)"
1650 _git_ls_tree ()
1652 __git_complete_file
1655 # Options that go well for log, shortlog and gitk
1656 __git_log_common_options="
1657 --not --all
1658 --branches --tags --remotes
1659 --first-parent --merges --no-merges
1660 --max-count=
1661 --max-age= --since= --after=
1662 --min-age= --until= --before=
1663 --min-parents= --max-parents=
1664 --no-min-parents --no-max-parents
1666 # Options that go well for log and gitk (not shortlog)
1667 __git_log_gitk_options="
1668 --dense --sparse --full-history
1669 --simplify-merges --simplify-by-decoration
1670 --left-right --notes --no-notes
1672 # Options that go well for log and shortlog (not gitk)
1673 __git_log_shortlog_options="
1674 --author= --committer= --grep=
1675 --all-match --invert-grep
1678 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1679 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1681 _git_log ()
1683 __git_has_doubledash && return
1684 __git_find_repo_path
1686 local merge=""
1687 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1688 merge="--merge"
1690 case "$prev,$cur" in
1691 -L,:*:*)
1692 return # fall back to Bash filename completion
1694 -L,:*)
1695 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1696 return
1698 -G,*|-S,*)
1699 __git_complete_symbol
1700 return
1702 esac
1703 case "$cur" in
1704 --pretty=*|--format=*)
1705 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1706 " "" "${cur#*=}"
1707 return
1709 --date=*)
1710 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1711 return
1713 --decorate=*)
1714 __gitcomp "full short no" "" "${cur##--decorate=}"
1715 return
1717 --diff-algorithm=*)
1718 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1719 return
1721 --submodule=*)
1722 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1723 return
1725 --*)
1726 __gitcomp "
1727 $__git_log_common_options
1728 $__git_log_shortlog_options
1729 $__git_log_gitk_options
1730 --root --topo-order --date-order --reverse
1731 --follow --full-diff
1732 --abbrev-commit --abbrev=
1733 --relative-date --date=
1734 --pretty= --format= --oneline
1735 --show-signature
1736 --cherry-mark
1737 --cherry-pick
1738 --graph
1739 --decorate --decorate=
1740 --walk-reflogs
1741 --parents --children
1742 $merge
1743 $__git_diff_common_options
1744 --pickaxe-all --pickaxe-regex
1746 return
1748 -L:*:*)
1749 return # fall back to Bash filename completion
1751 -L:*)
1752 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1753 return
1755 -G*)
1756 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1757 return
1759 -S*)
1760 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1761 return
1763 esac
1764 __git_complete_revlist
1767 # Common merge options shared by git-merge(1) and git-pull(1).
1768 __git_merge_options="
1769 --no-commit --no-stat --log --no-log --squash --strategy
1770 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1771 --verify-signatures --no-verify-signatures --gpg-sign
1772 --quiet --verbose --progress --no-progress
1775 _git_merge ()
1777 __git_complete_strategy && return
1779 case "$cur" in
1780 --*)
1781 __gitcomp "$__git_merge_options
1782 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1783 return
1784 esac
1785 __git_complete_refs
1788 _git_mergetool ()
1790 case "$cur" in
1791 --tool=*)
1792 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1793 return
1795 --*)
1796 __gitcomp "--tool="
1797 return
1799 esac
1802 _git_merge_base ()
1804 case "$cur" in
1805 --*)
1806 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1807 return
1809 esac
1810 __git_complete_refs
1813 _git_mv ()
1815 case "$cur" in
1816 --*)
1817 __gitcomp "--dry-run"
1818 return
1820 esac
1822 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1823 # We need to show both cached and untracked files (including
1824 # empty directories) since this may not be the last argument.
1825 __git_complete_index_file "--cached --others --directory"
1826 else
1827 __git_complete_index_file "--cached"
1831 _git_name_rev ()
1833 __gitcomp "--tags --all --stdin"
1836 _git_notes ()
1838 local subcommands='add append copy edit list prune remove show'
1839 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1841 case "$subcommand,$cur" in
1842 ,--*)
1843 __gitcomp '--ref'
1846 case "$prev" in
1847 --ref)
1848 __git_complete_refs
1851 __gitcomp "$subcommands --ref"
1853 esac
1855 add,--reuse-message=*|append,--reuse-message=*|\
1856 add,--reedit-message=*|append,--reedit-message=*)
1857 __git_complete_refs --cur="${cur#*=}"
1859 add,--*|append,--*)
1860 __gitcomp '--file= --message= --reedit-message=
1861 --reuse-message='
1863 copy,--*)
1864 __gitcomp '--stdin'
1866 prune,--*)
1867 __gitcomp '--dry-run --verbose'
1869 prune,*)
1872 case "$prev" in
1873 -m|-F)
1876 __git_complete_refs
1878 esac
1880 esac
1883 _git_pull ()
1885 __git_complete_strategy && return
1887 case "$cur" in
1888 --recurse-submodules=*)
1889 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1890 return
1892 --*)
1893 __gitcomp "
1894 --rebase --no-rebase
1895 $__git_merge_options
1896 $__git_fetch_options
1898 return
1900 esac
1901 __git_complete_remote_or_refspec
1904 __git_push_recurse_submodules="check on-demand"
1906 __git_complete_force_with_lease ()
1908 local cur_=$1
1910 case "$cur_" in
1911 --*=)
1913 *:*)
1914 __git_complete_refs --cur="${cur_#*:}"
1917 __git_complete_refs --cur="$cur_"
1919 esac
1922 _git_push ()
1924 case "$prev" in
1925 --repo)
1926 __gitcomp_nl "$(__git_remotes)"
1927 return
1929 --recurse-submodules)
1930 __gitcomp "$__git_push_recurse_submodules"
1931 return
1933 esac
1934 case "$cur" in
1935 --repo=*)
1936 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1937 return
1939 --recurse-submodules=*)
1940 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1941 return
1943 --force-with-lease=*)
1944 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1945 return
1947 --*)
1948 __gitcomp "
1949 --all --mirror --tags --dry-run --force --verbose
1950 --quiet --prune --delete --follow-tags
1951 --receive-pack= --repo= --set-upstream
1952 --force-with-lease --force-with-lease= --recurse-submodules=
1954 return
1956 esac
1957 __git_complete_remote_or_refspec
1960 _git_rebase ()
1962 __git_find_repo_path
1963 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1964 __gitcomp "--continue --skip --abort --quit --edit-todo"
1965 return
1966 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1967 [ -d "$__git_repo_path"/rebase-merge ]; then
1968 __gitcomp "--continue --skip --abort --quit"
1969 return
1971 __git_complete_strategy && return
1972 case "$cur" in
1973 --whitespace=*)
1974 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1975 return
1977 --*)
1978 __gitcomp "
1979 --onto --merge --strategy --interactive
1980 --preserve-merges --stat --no-stat
1981 --committer-date-is-author-date --ignore-date
1982 --ignore-whitespace --whitespace=
1983 --autosquash --no-autosquash
1984 --fork-point --no-fork-point
1985 --autostash --no-autostash
1986 --verify --no-verify
1987 --keep-empty --root --force-rebase --no-ff
1988 --exec
1991 return
1992 esac
1993 __git_complete_refs
1996 _git_reflog ()
1998 local subcommands="show delete expire"
1999 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2001 if [ -z "$subcommand" ]; then
2002 __gitcomp "$subcommands"
2003 else
2004 __git_complete_refs
2008 __git_send_email_confirm_options="always never auto cc compose"
2009 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2011 _git_send_email ()
2013 case "$prev" in
2014 --to|--cc|--bcc|--from)
2015 __gitcomp "$(__git send-email --dump-aliases)"
2016 return
2018 esac
2020 case "$cur" in
2021 --confirm=*)
2022 __gitcomp "
2023 $__git_send_email_confirm_options
2024 " "" "${cur##--confirm=}"
2025 return
2027 --suppress-cc=*)
2028 __gitcomp "
2029 $__git_send_email_suppresscc_options
2030 " "" "${cur##--suppress-cc=}"
2032 return
2034 --smtp-encryption=*)
2035 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2036 return
2038 --thread=*)
2039 __gitcomp "
2040 deep shallow
2041 " "" "${cur##--thread=}"
2042 return
2044 --to=*|--cc=*|--bcc=*|--from=*)
2045 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2046 return
2048 --*)
2049 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2050 --compose --confirm= --dry-run --envelope-sender
2051 --from --identity
2052 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2053 --no-suppress-from --no-thread --quiet
2054 --signed-off-by-cc --smtp-pass --smtp-server
2055 --smtp-server-port --smtp-encryption= --smtp-user
2056 --subject --suppress-cc= --suppress-from --thread --to
2057 --validate --no-validate
2058 $__git_format_patch_options"
2059 return
2061 esac
2062 __git_complete_revlist
2065 _git_stage ()
2067 _git_add
2070 _git_status ()
2072 local complete_opt
2073 local untracked_state
2075 case "$cur" in
2076 --ignore-submodules=*)
2077 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2078 return
2080 --untracked-files=*)
2081 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2082 return
2084 --column=*)
2085 __gitcomp "
2086 always never auto column row plain dense nodense
2087 " "" "${cur##--column=}"
2088 return
2090 --*)
2091 __gitcomp "
2092 --short --branch --porcelain --long --verbose
2093 --untracked-files= --ignore-submodules= --ignored
2094 --column= --no-column
2096 return
2098 esac
2100 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2101 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2103 case "$untracked_state" in
2105 # --ignored option does not matter
2106 complete_opt=
2108 all|normal|*)
2109 complete_opt="--cached --directory --no-empty-directory --others"
2111 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2112 complete_opt="$complete_opt --ignored --exclude=*"
2115 esac
2117 __git_complete_index_file "$complete_opt"
2120 __git_config_get_set_variables ()
2122 local prevword word config_file= c=$cword
2123 while [ $c -gt 1 ]; do
2124 word="${words[c]}"
2125 case "$word" in
2126 --system|--global|--local|--file=*)
2127 config_file="$word"
2128 break
2130 -f|--file)
2131 config_file="$word $prevword"
2132 break
2134 esac
2135 prevword=$word
2136 c=$((--c))
2137 done
2139 __git config $config_file --name-only --list
2142 _git_config ()
2144 case "$prev" in
2145 branch.*.remote|branch.*.pushremote)
2146 __gitcomp_nl "$(__git_remotes)"
2147 return
2149 branch.*.merge)
2150 __git_complete_refs
2151 return
2153 branch.*.rebase)
2154 __gitcomp "false true preserve interactive"
2155 return
2157 remote.pushdefault)
2158 __gitcomp_nl "$(__git_remotes)"
2159 return
2161 remote.*.fetch)
2162 local remote="${prev#remote.}"
2163 remote="${remote%.fetch}"
2164 if [ -z "$cur" ]; then
2165 __gitcomp_nl "refs/heads/" "" "" ""
2166 return
2168 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2169 return
2171 remote.*.push)
2172 local remote="${prev#remote.}"
2173 remote="${remote%.push}"
2174 __gitcomp_nl "$(__git for-each-ref \
2175 --format='%(refname):%(refname)' refs/heads)"
2176 return
2178 pull.twohead|pull.octopus)
2179 __git_compute_merge_strategies
2180 __gitcomp "$__git_merge_strategies"
2181 return
2183 color.branch|color.diff|color.interactive|\
2184 color.showbranch|color.status|color.ui)
2185 __gitcomp "always never auto"
2186 return
2188 color.pager)
2189 __gitcomp "false true"
2190 return
2192 color.*.*)
2193 __gitcomp "
2194 normal black red green yellow blue magenta cyan white
2195 bold dim ul blink reverse
2197 return
2199 diff.submodule)
2200 __gitcomp "log short"
2201 return
2203 help.format)
2204 __gitcomp "man info web html"
2205 return
2207 log.date)
2208 __gitcomp "$__git_log_date_formats"
2209 return
2211 sendemail.aliasesfiletype)
2212 __gitcomp "mutt mailrc pine elm gnus"
2213 return
2215 sendemail.confirm)
2216 __gitcomp "$__git_send_email_confirm_options"
2217 return
2219 sendemail.suppresscc)
2220 __gitcomp "$__git_send_email_suppresscc_options"
2221 return
2223 sendemail.transferencoding)
2224 __gitcomp "7bit 8bit quoted-printable base64"
2225 return
2227 --get|--get-all|--unset|--unset-all)
2228 __gitcomp_nl "$(__git_config_get_set_variables)"
2229 return
2231 *.*)
2232 return
2234 esac
2235 case "$cur" in
2236 --*)
2237 __gitcomp "
2238 --system --global --local --file=
2239 --list --replace-all
2240 --get --get-all --get-regexp
2241 --add --unset --unset-all
2242 --remove-section --rename-section
2243 --name-only
2245 return
2247 branch.*.*)
2248 local pfx="${cur%.*}." cur_="${cur##*.}"
2249 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2250 return
2252 branch.*)
2253 local pfx="${cur%.*}." cur_="${cur#*.}"
2254 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2255 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2256 return
2258 guitool.*.*)
2259 local pfx="${cur%.*}." cur_="${cur##*.}"
2260 __gitcomp "
2261 argprompt cmd confirm needsfile noconsole norescan
2262 prompt revprompt revunmerged title
2263 " "$pfx" "$cur_"
2264 return
2266 difftool.*.*)
2267 local pfx="${cur%.*}." cur_="${cur##*.}"
2268 __gitcomp "cmd path" "$pfx" "$cur_"
2269 return
2271 man.*.*)
2272 local pfx="${cur%.*}." cur_="${cur##*.}"
2273 __gitcomp "cmd path" "$pfx" "$cur_"
2274 return
2276 mergetool.*.*)
2277 local pfx="${cur%.*}." cur_="${cur##*.}"
2278 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2279 return
2281 pager.*)
2282 local pfx="${cur%.*}." cur_="${cur#*.}"
2283 __git_compute_all_commands
2284 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2285 return
2287 remote.*.*)
2288 local pfx="${cur%.*}." cur_="${cur##*.}"
2289 __gitcomp "
2290 url proxy fetch push mirror skipDefaultUpdate
2291 receivepack uploadpack tagopt pushurl
2292 " "$pfx" "$cur_"
2293 return
2295 remote.*)
2296 local pfx="${cur%.*}." cur_="${cur#*.}"
2297 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2298 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2299 return
2301 url.*.*)
2302 local pfx="${cur%.*}." cur_="${cur##*.}"
2303 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2304 return
2306 esac
2307 __gitcomp "
2308 add.ignoreErrors
2309 advice.commitBeforeMerge
2310 advice.detachedHead
2311 advice.implicitIdentity
2312 advice.pushNonFastForward
2313 advice.resolveConflict
2314 advice.statusHints
2315 alias.
2316 am.keepcr
2317 apply.ignorewhitespace
2318 apply.whitespace
2319 branch.autosetupmerge
2320 branch.autosetuprebase
2321 browser.
2322 clean.requireForce
2323 color.branch
2324 color.branch.current
2325 color.branch.local
2326 color.branch.plain
2327 color.branch.remote
2328 color.decorate.HEAD
2329 color.decorate.branch
2330 color.decorate.remoteBranch
2331 color.decorate.stash
2332 color.decorate.tag
2333 color.diff
2334 color.diff.commit
2335 color.diff.frag
2336 color.diff.func
2337 color.diff.meta
2338 color.diff.new
2339 color.diff.old
2340 color.diff.plain
2341 color.diff.whitespace
2342 color.grep
2343 color.grep.context
2344 color.grep.filename
2345 color.grep.function
2346 color.grep.linenumber
2347 color.grep.match
2348 color.grep.selected
2349 color.grep.separator
2350 color.interactive
2351 color.interactive.error
2352 color.interactive.header
2353 color.interactive.help
2354 color.interactive.prompt
2355 color.pager
2356 color.showbranch
2357 color.status
2358 color.status.added
2359 color.status.changed
2360 color.status.header
2361 color.status.nobranch
2362 color.status.unmerged
2363 color.status.untracked
2364 color.status.updated
2365 color.ui
2366 commit.status
2367 commit.template
2368 core.abbrev
2369 core.askpass
2370 core.attributesfile
2371 core.autocrlf
2372 core.bare
2373 core.bigFileThreshold
2374 core.compression
2375 core.createObject
2376 core.deltaBaseCacheLimit
2377 core.editor
2378 core.eol
2379 core.excludesfile
2380 core.fileMode
2381 core.fsyncobjectfiles
2382 core.gitProxy
2383 core.ignoreStat
2384 core.ignorecase
2385 core.logAllRefUpdates
2386 core.loosecompression
2387 core.notesRef
2388 core.packedGitLimit
2389 core.packedGitWindowSize
2390 core.pager
2391 core.preferSymlinkRefs
2392 core.preloadindex
2393 core.quotepath
2394 core.repositoryFormatVersion
2395 core.safecrlf
2396 core.sharedRepository
2397 core.sparseCheckout
2398 core.symlinks
2399 core.trustctime
2400 core.untrackedCache
2401 core.warnAmbiguousRefs
2402 core.whitespace
2403 core.worktree
2404 diff.autorefreshindex
2405 diff.external
2406 diff.ignoreSubmodules
2407 diff.mnemonicprefix
2408 diff.noprefix
2409 diff.renameLimit
2410 diff.renames
2411 diff.statGraphWidth
2412 diff.submodule
2413 diff.suppressBlankEmpty
2414 diff.tool
2415 diff.wordRegex
2416 diff.algorithm
2417 difftool.
2418 difftool.prompt
2419 fetch.recurseSubmodules
2420 fetch.unpackLimit
2421 format.attach
2422 format.cc
2423 format.coverLetter
2424 format.from
2425 format.headers
2426 format.numbered
2427 format.pretty
2428 format.signature
2429 format.signoff
2430 format.subjectprefix
2431 format.suffix
2432 format.thread
2433 format.to
2435 gc.aggressiveWindow
2436 gc.auto
2437 gc.autopacklimit
2438 gc.packrefs
2439 gc.pruneexpire
2440 gc.reflogexpire
2441 gc.reflogexpireunreachable
2442 gc.rerereresolved
2443 gc.rerereunresolved
2444 gitcvs.allbinary
2445 gitcvs.commitmsgannotation
2446 gitcvs.dbTableNamePrefix
2447 gitcvs.dbdriver
2448 gitcvs.dbname
2449 gitcvs.dbpass
2450 gitcvs.dbuser
2451 gitcvs.enabled
2452 gitcvs.logfile
2453 gitcvs.usecrlfattr
2454 guitool.
2455 gui.blamehistoryctx
2456 gui.commitmsgwidth
2457 gui.copyblamethreshold
2458 gui.diffcontext
2459 gui.encoding
2460 gui.fastcopyblame
2461 gui.matchtrackingbranch
2462 gui.newbranchtemplate
2463 gui.pruneduringfetch
2464 gui.spellingdictionary
2465 gui.trustmtime
2466 help.autocorrect
2467 help.browser
2468 help.format
2469 http.lowSpeedLimit
2470 http.lowSpeedTime
2471 http.maxRequests
2472 http.minSessions
2473 http.noEPSV
2474 http.postBuffer
2475 http.proxy
2476 http.sslCipherList
2477 http.sslVersion
2478 http.sslCAInfo
2479 http.sslCAPath
2480 http.sslCert
2481 http.sslCertPasswordProtected
2482 http.sslKey
2483 http.sslVerify
2484 http.useragent
2485 i18n.commitEncoding
2486 i18n.logOutputEncoding
2487 imap.authMethod
2488 imap.folder
2489 imap.host
2490 imap.pass
2491 imap.port
2492 imap.preformattedHTML
2493 imap.sslverify
2494 imap.tunnel
2495 imap.user
2496 init.templatedir
2497 instaweb.browser
2498 instaweb.httpd
2499 instaweb.local
2500 instaweb.modulepath
2501 instaweb.port
2502 interactive.singlekey
2503 log.date
2504 log.decorate
2505 log.showroot
2506 mailmap.file
2507 man.
2508 man.viewer
2509 merge.
2510 merge.conflictstyle
2511 merge.log
2512 merge.renameLimit
2513 merge.renormalize
2514 merge.stat
2515 merge.tool
2516 merge.verbosity
2517 mergetool.
2518 mergetool.keepBackup
2519 mergetool.keepTemporaries
2520 mergetool.prompt
2521 notes.displayRef
2522 notes.rewrite.
2523 notes.rewrite.amend
2524 notes.rewrite.rebase
2525 notes.rewriteMode
2526 notes.rewriteRef
2527 pack.compression
2528 pack.deltaCacheLimit
2529 pack.deltaCacheSize
2530 pack.depth
2531 pack.indexVersion
2532 pack.packSizeLimit
2533 pack.threads
2534 pack.window
2535 pack.windowMemory
2536 pager.
2537 pretty.
2538 pull.octopus
2539 pull.twohead
2540 push.default
2541 push.followTags
2542 rebase.autosquash
2543 rebase.stat
2544 receive.autogc
2545 receive.denyCurrentBranch
2546 receive.denyDeleteCurrent
2547 receive.denyDeletes
2548 receive.denyNonFastForwards
2549 receive.fsckObjects
2550 receive.unpackLimit
2551 receive.updateserverinfo
2552 remote.pushdefault
2553 remotes.
2554 repack.usedeltabaseoffset
2555 rerere.autoupdate
2556 rerere.enabled
2557 sendemail.
2558 sendemail.aliasesfile
2559 sendemail.aliasfiletype
2560 sendemail.bcc
2561 sendemail.cc
2562 sendemail.cccmd
2563 sendemail.chainreplyto
2564 sendemail.confirm
2565 sendemail.envelopesender
2566 sendemail.from
2567 sendemail.identity
2568 sendemail.multiedit
2569 sendemail.signedoffbycc
2570 sendemail.smtpdomain
2571 sendemail.smtpencryption
2572 sendemail.smtppass
2573 sendemail.smtpserver
2574 sendemail.smtpserveroption
2575 sendemail.smtpserverport
2576 sendemail.smtpuser
2577 sendemail.suppresscc
2578 sendemail.suppressfrom
2579 sendemail.thread
2580 sendemail.to
2581 sendemail.validate
2582 showbranch.default
2583 status.relativePaths
2584 status.showUntrackedFiles
2585 status.submodulesummary
2586 submodule.
2587 tar.umask
2588 transfer.unpackLimit
2589 url.
2590 user.email
2591 user.name
2592 user.signingkey
2593 web.browser
2594 branch. remote.
2598 _git_remote ()
2600 local subcommands="add rename remove set-head set-branches set-url show prune update"
2601 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2602 if [ -z "$subcommand" ]; then
2603 __gitcomp "$subcommands"
2604 return
2607 case "$subcommand" in
2608 rename|remove|set-url|show|prune)
2609 __gitcomp_nl "$(__git_remotes)"
2611 set-head|set-branches)
2612 __git_complete_remote_or_refspec
2614 update)
2615 __gitcomp "$(__git_get_config_variables "remotes")"
2619 esac
2622 _git_replace ()
2624 __git_complete_refs
2627 _git_reset ()
2629 __git_has_doubledash && return
2631 case "$cur" in
2632 --*)
2633 __gitcomp "--merge --mixed --hard --soft --patch"
2634 return
2636 esac
2637 __git_complete_refs
2640 _git_revert ()
2642 __git_find_repo_path
2643 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2644 __gitcomp "--continue --quit --abort"
2645 return
2647 case "$cur" in
2648 --*)
2649 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2650 return
2652 esac
2653 __git_complete_refs
2656 _git_rm ()
2658 case "$cur" in
2659 --*)
2660 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2661 return
2663 esac
2665 __git_complete_index_file "--cached"
2668 _git_shortlog ()
2670 __git_has_doubledash && return
2672 case "$cur" in
2673 --*)
2674 __gitcomp "
2675 $__git_log_common_options
2676 $__git_log_shortlog_options
2677 --numbered --summary
2679 return
2681 esac
2682 __git_complete_revlist
2685 _git_show ()
2687 __git_has_doubledash && return
2689 case "$cur" in
2690 --pretty=*|--format=*)
2691 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2692 " "" "${cur#*=}"
2693 return
2695 --diff-algorithm=*)
2696 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2697 return
2699 --submodule=*)
2700 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2701 return
2703 --*)
2704 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2705 --show-signature
2706 $__git_diff_common_options
2708 return
2710 esac
2711 __git_complete_revlist_file
2714 _git_show_branch ()
2716 case "$cur" in
2717 --*)
2718 __gitcomp "
2719 --all --remotes --topo-order --date-order --current --more=
2720 --list --independent --merge-base --no-name
2721 --color --no-color
2722 --sha1-name --sparse --topics --reflog
2724 return
2726 esac
2727 __git_complete_revlist
2730 _git_stash ()
2732 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2733 local subcommands='save list show apply clear drop pop create branch'
2734 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2735 if [ -z "$subcommand" ]; then
2736 case "$cur" in
2737 --*)
2738 __gitcomp "$save_opts"
2741 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2742 __gitcomp "$subcommands"
2745 esac
2746 else
2747 case "$subcommand,$cur" in
2748 save,--*)
2749 __gitcomp "$save_opts"
2751 apply,--*|pop,--*)
2752 __gitcomp "--index --quiet"
2754 drop,--*)
2755 __gitcomp "--quiet"
2757 show,--*|branch,--*)
2759 branch,*)
2760 if [ $cword -eq 3 ]; then
2761 __git_complete_refs
2762 else
2763 __gitcomp_nl "$(__git stash list \
2764 | sed -n -e 's/:.*//p')"
2767 show,*|apply,*|drop,*|pop,*)
2768 __gitcomp_nl "$(__git stash list \
2769 | sed -n -e 's/:.*//p')"
2773 esac
2777 _git_submodule ()
2779 __git_has_doubledash && return
2781 local subcommands="add status init deinit update summary foreach sync"
2782 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2783 case "$cur" in
2784 --*)
2785 __gitcomp "--quiet --cached"
2788 __gitcomp "$subcommands"
2790 esac
2791 return
2795 _git_svn ()
2797 local subcommands="
2798 init fetch clone rebase dcommit log find-rev
2799 set-tree commit-diff info create-ignore propget
2800 proplist show-ignore show-externals branch tag blame
2801 migrate mkdirs reset gc
2803 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2804 if [ -z "$subcommand" ]; then
2805 __gitcomp "$subcommands"
2806 else
2807 local remote_opts="--username= --config-dir= --no-auth-cache"
2808 local fc_opts="
2809 --follow-parent --authors-file= --repack=
2810 --no-metadata --use-svm-props --use-svnsync-props
2811 --log-window-size= --no-checkout --quiet
2812 --repack-flags --use-log-author --localtime
2813 --ignore-paths= --include-paths= $remote_opts
2815 local init_opts="
2816 --template= --shared= --trunk= --tags=
2817 --branches= --stdlayout --minimize-url
2818 --no-metadata --use-svm-props --use-svnsync-props
2819 --rewrite-root= --prefix= --use-log-author
2820 --add-author-from $remote_opts
2822 local cmt_opts="
2823 --edit --rmdir --find-copies-harder --copy-similarity=
2826 case "$subcommand,$cur" in
2827 fetch,--*)
2828 __gitcomp "--revision= --fetch-all $fc_opts"
2830 clone,--*)
2831 __gitcomp "--revision= $fc_opts $init_opts"
2833 init,--*)
2834 __gitcomp "$init_opts"
2836 dcommit,--*)
2837 __gitcomp "
2838 --merge --strategy= --verbose --dry-run
2839 --fetch-all --no-rebase --commit-url
2840 --revision --interactive $cmt_opts $fc_opts
2843 set-tree,--*)
2844 __gitcomp "--stdin $cmt_opts $fc_opts"
2846 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2847 show-externals,--*|mkdirs,--*)
2848 __gitcomp "--revision="
2850 log,--*)
2851 __gitcomp "
2852 --limit= --revision= --verbose --incremental
2853 --oneline --show-commit --non-recursive
2854 --authors-file= --color
2857 rebase,--*)
2858 __gitcomp "
2859 --merge --verbose --strategy= --local
2860 --fetch-all --dry-run $fc_opts
2863 commit-diff,--*)
2864 __gitcomp "--message= --file= --revision= $cmt_opts"
2866 info,--*)
2867 __gitcomp "--url"
2869 branch,--*)
2870 __gitcomp "--dry-run --message --tag"
2872 tag,--*)
2873 __gitcomp "--dry-run --message"
2875 blame,--*)
2876 __gitcomp "--git-format"
2878 migrate,--*)
2879 __gitcomp "
2880 --config-dir= --ignore-paths= --minimize
2881 --no-auth-cache --username=
2884 reset,--*)
2885 __gitcomp "--revision= --parent"
2889 esac
2893 _git_tag ()
2895 local i c=1 f=0
2896 while [ $c -lt $cword ]; do
2897 i="${words[c]}"
2898 case "$i" in
2899 -d|-v)
2900 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2901 return
2906 esac
2907 ((c++))
2908 done
2910 case "$prev" in
2911 -m|-F)
2913 -*|tag)
2914 if [ $f = 1 ]; then
2915 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2919 __git_complete_refs
2921 esac
2923 case "$cur" in
2924 --*)
2925 __gitcomp "
2926 --list --delete --verify --annotate --message --file
2927 --sign --cleanup --local-user --force --column --sort
2928 --contains --points-at
2931 esac
2934 _git_whatchanged ()
2936 _git_log
2939 _git_worktree ()
2941 local subcommands="add list lock prune unlock"
2942 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2943 if [ -z "$subcommand" ]; then
2944 __gitcomp "$subcommands"
2945 else
2946 case "$subcommand,$cur" in
2947 add,--*)
2948 __gitcomp "--detach"
2950 list,--*)
2951 __gitcomp "--porcelain"
2953 lock,--*)
2954 __gitcomp "--reason"
2956 prune,--*)
2957 __gitcomp "--dry-run --expire --verbose"
2961 esac
2965 __git_main ()
2967 local i c=1 command __git_dir __git_repo_path
2968 local __git_C_args C_args_count=0
2970 while [ $c -lt $cword ]; do
2971 i="${words[c]}"
2972 case "$i" in
2973 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2974 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2975 --bare) __git_dir="." ;;
2976 --help) command="help"; break ;;
2977 -c|--work-tree|--namespace) ((c++)) ;;
2978 -C) __git_C_args[C_args_count++]=-C
2979 ((c++))
2980 __git_C_args[C_args_count++]="${words[c]}"
2982 -*) ;;
2983 *) command="$i"; break ;;
2984 esac
2985 ((c++))
2986 done
2988 if [ -z "$command" ]; then
2989 case "$prev" in
2990 --git-dir|-C|--work-tree)
2991 # these need a path argument, let's fall back to
2992 # Bash filename completion
2993 return
2995 -c|--namespace)
2996 # we don't support completing these options' arguments
2997 return
2999 esac
3000 case "$cur" in
3001 --*) __gitcomp "
3002 --paginate
3003 --no-pager
3004 --git-dir=
3005 --bare
3006 --version
3007 --exec-path
3008 --exec-path=
3009 --html-path
3010 --man-path
3011 --info-path
3012 --work-tree=
3013 --namespace=
3014 --no-replace-objects
3015 --help
3018 *) __git_compute_porcelain_commands
3019 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
3020 esac
3021 return
3024 local completion_func="_git_${command//-/_}"
3025 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
3027 local expansion=$(__git_aliased_command "$command")
3028 if [ -n "$expansion" ]; then
3029 words[1]=$expansion
3030 completion_func="_git_${expansion//-/_}"
3031 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
3035 __gitk_main ()
3037 __git_has_doubledash && return
3039 local __git_repo_path
3040 __git_find_repo_path
3042 local merge=""
3043 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3044 merge="--merge"
3046 case "$cur" in
3047 --*)
3048 __gitcomp "
3049 $__git_log_common_options
3050 $__git_log_gitk_options
3051 $merge
3053 return
3055 esac
3056 __git_complete_revlist
3059 if [[ -n ${ZSH_VERSION-} ]]; then
3060 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3062 autoload -U +X compinit && compinit
3064 __gitcomp ()
3066 emulate -L zsh
3068 local cur_="${3-$cur}"
3070 case "$cur_" in
3071 --*=)
3074 local c IFS=$' \t\n'
3075 local -a array
3076 for c in ${=1}; do
3077 c="$c${4-}"
3078 case $c in
3079 --*=*|*.) ;;
3080 *) c="$c " ;;
3081 esac
3082 array[${#array[@]}+1]="$c"
3083 done
3084 compset -P '*[=:]'
3085 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3087 esac
3090 __gitcomp_direct ()
3092 emulate -L zsh
3094 local IFS=$'\n'
3095 compset -P '*[=:]'
3096 compadd -Q -- ${=1} && _ret=0
3099 __gitcomp_nl ()
3101 emulate -L zsh
3103 local IFS=$'\n'
3104 compset -P '*[=:]'
3105 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3108 __gitcomp_file ()
3110 emulate -L zsh
3112 local IFS=$'\n'
3113 compset -P '*[=:]'
3114 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3117 _git ()
3119 local _ret=1 cur cword prev
3120 cur=${words[CURRENT]}
3121 prev=${words[CURRENT-1]}
3122 let cword=CURRENT-1
3123 emulate ksh -c __${service}_main
3124 let _ret && _default && _ret=0
3125 return _ret
3128 compdef _git git gitk
3129 return
3132 __git_func_wrap ()
3134 local cur words cword prev
3135 _get_comp_words_by_ref -n =: cur words cword prev
3139 # Setup completion for certain functions defined above by setting common
3140 # variables and workarounds.
3141 # This is NOT a public function; use at your own risk.
3142 __git_complete ()
3144 local wrapper="__git_wrap${2}"
3145 eval "$wrapper () { __git_func_wrap $2 ; }"
3146 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3147 || complete -o default -o nospace -F $wrapper $1
3150 # wrapper for backwards compatibility
3151 _git ()
3153 __git_wrap__git_main
3156 # wrapper for backwards compatibility
3157 _gitk ()
3159 __git_wrap__gitk_main
3162 __git_complete git __git_main
3163 __git_complete gitk __gitk_main
3165 # The following are necessary only for Cygwin, and only are needed
3166 # when the user has tab-completed the executable name and consequently
3167 # included the '.exe' suffix.
3169 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3170 __git_complete git.exe __git_main