bash-completion: don't add quoted space for ZSH (fix regression)
[git/dscho.git] / contrib / completion / git-completion.bash
blobd9a93ea418c021325242d1030fb456cadc56b792
1 #!bash
3 # bash/zsh completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.sh
24 # 3) Consider changing your PS1 to also show the current branch:
25 # Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
26 # ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
28 # The argument to __git_ps1 will be displayed only if you
29 # are currently in a git repository. The %s token will be
30 # the name of the current branch.
32 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
33 # value, unstaged (*) and staged (+) changes will be shown next
34 # to the branch name. You can configure this per-repository
35 # with the bash.showDirtyState variable, which defaults to true
36 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
38 # You can also see if currently something is stashed, by setting
39 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
40 # then a '$' will be shown next to the branch name.
42 # If you would like to see if there're untracked files, then you can
43 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
44 # untracked files, then a '%' will be shown next to the branch name.
46 # If you would like to see the difference between HEAD and its
47 # upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates
48 # you are behind, ">" indicates you are ahead, and "<>"
49 # indicates you have diverged. You can further control
50 # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
51 # list of values:
52 # verbose show number of commits ahead/behind (+/-) upstream
53 # legacy don't use the '--count' option available in recent
54 # versions of git-rev-list
55 # git always compare HEAD to @{upstream}
56 # svn always compare HEAD to your SVN upstream
57 # By default, __git_ps1 will compare HEAD to your SVN upstream
58 # if it can find one, or @{upstream} otherwise. Once you have
59 # set GIT_PS1_SHOWUPSTREAM, you can override it on a
60 # per-repository basis by setting the bash.showUpstream config
61 # variable.
64 if [[ -n ${ZSH_VERSION-} ]]; then
65 autoload -U +X bashcompinit && bashcompinit
68 case "$COMP_WORDBREAKS" in
69 *:*) : great ;;
70 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
71 esac
73 # __gitdir accepts 0 or 1 arguments (i.e., location)
74 # returns location of .git repo
75 __gitdir ()
77 if [ -z "${1-}" ]; then
78 if [ -n "${__git_dir-}" ]; then
79 echo "$__git_dir"
80 elif [ -d .git ]; then
81 echo .git
82 else
83 git rev-parse --git-dir 2>/dev/null
85 elif [ -d "$1/.git" ]; then
86 echo "$1/.git"
87 else
88 echo "$1"
92 # stores the divergence from upstream in $p
93 # used by GIT_PS1_SHOWUPSTREAM
94 __git_ps1_show_upstream ()
96 local key value
97 local svn_remote svn_url_pattern count n
98 local upstream=git legacy="" verbose=""
100 svn_remote=()
101 # get some config options from git-config
102 local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
103 while read -r key value; do
104 case "$key" in
105 bash.showupstream)
106 GIT_PS1_SHOWUPSTREAM="$value"
107 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
108 p=""
109 return
112 svn-remote.*.url)
113 svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
114 svn_url_pattern+="\\|$value"
115 upstream=svn+git # default upstream is SVN if available, else git
117 esac
118 done <<< "$output"
120 # parse configuration values
121 for option in ${GIT_PS1_SHOWUPSTREAM}; do
122 case "$option" in
123 git|svn) upstream="$option" ;;
124 verbose) verbose=1 ;;
125 legacy) legacy=1 ;;
126 esac
127 done
129 # Find our upstream
130 case "$upstream" in
131 git) upstream="@{upstream}" ;;
132 svn*)
133 # get the upstream from the "git-svn-id: ..." in a commit message
134 # (git-svn uses essentially the same procedure internally)
135 local svn_upstream=($(git log --first-parent -1 \
136 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
137 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
138 svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
139 svn_upstream=${svn_upstream%@*}
140 local n_stop="${#svn_remote[@]}"
141 for ((n=1; n <= n_stop; n++)); do
142 svn_upstream=${svn_upstream#${svn_remote[$n]}}
143 done
145 if [[ -z "$svn_upstream" ]]; then
146 # default branch name for checkouts with no layout:
147 upstream=${GIT_SVN_ID:-git-svn}
148 else
149 upstream=${svn_upstream#/}
151 elif [[ "svn+git" = "$upstream" ]]; then
152 upstream="@{upstream}"
155 esac
157 # Find how many commits we are ahead/behind our upstream
158 if [[ -z "$legacy" ]]; then
159 count="$(git rev-list --count --left-right \
160 "$upstream"...HEAD 2>/dev/null)"
161 else
162 # produce equivalent output to --count for older versions of git
163 local commits
164 if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
165 then
166 local commit behind=0 ahead=0
167 for commit in $commits
169 case "$commit" in
170 "<"*) ((behind++)) ;;
171 *) ((ahead++)) ;;
172 esac
173 done
174 count="$behind $ahead"
175 else
176 count=""
180 # calculate the result
181 if [[ -z "$verbose" ]]; then
182 case "$count" in
183 "") # no upstream
184 p="" ;;
185 "0 0") # equal to upstream
186 p="=" ;;
187 "0 "*) # ahead of upstream
188 p=">" ;;
189 *" 0") # behind upstream
190 p="<" ;;
191 *) # diverged from upstream
192 p="<>" ;;
193 esac
194 else
195 case "$count" in
196 "") # no upstream
197 p="" ;;
198 "0 0") # equal to upstream
199 p=" u=" ;;
200 "0 "*) # ahead of upstream
201 p=" u+${count#0 }" ;;
202 *" 0") # behind upstream
203 p=" u-${count% 0}" ;;
204 *) # diverged from upstream
205 p=" u+${count#* }-${count% *}" ;;
206 esac
212 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
213 # returns text to add to bash PS1 prompt (includes branch name)
214 __git_ps1 ()
216 local g="$(__gitdir)"
217 if [ -n "$g" ]; then
218 local r=""
219 local b=""
220 if [ -f "$g/rebase-merge/interactive" ]; then
221 r="|REBASE-i"
222 b="$(cat "$g/rebase-merge/head-name")"
223 elif [ -d "$g/rebase-merge" ]; then
224 r="|REBASE-m"
225 b="$(cat "$g/rebase-merge/head-name")"
226 else
227 if [ -d "$g/rebase-apply" ]; then
228 if [ -f "$g/rebase-apply/rebasing" ]; then
229 r="|REBASE"
230 elif [ -f "$g/rebase-apply/applying" ]; then
231 r="|AM"
232 else
233 r="|AM/REBASE"
235 elif [ -f "$g/MERGE_HEAD" ]; then
236 r="|MERGING"
237 elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
238 r="|CHERRY-PICKING"
239 elif [ -f "$g/BISECT_LOG" ]; then
240 r="|BISECTING"
243 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
245 b="$(
246 case "${GIT_PS1_DESCRIBE_STYLE-}" in
247 (contains)
248 git describe --contains HEAD ;;
249 (branch)
250 git describe --contains --all HEAD ;;
251 (describe)
252 git describe HEAD ;;
253 (* | default)
254 git describe --tags --exact-match HEAD ;;
255 esac 2>/dev/null)" ||
257 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
258 b="unknown"
259 b="($b)"
263 local w=""
264 local i=""
265 local s=""
266 local u=""
267 local c=""
268 local p=""
270 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
271 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
272 c="BARE:"
273 else
274 b="GIT_DIR!"
276 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
277 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
278 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
279 git diff --no-ext-diff --quiet --exit-code || w="*"
280 if git rev-parse --quiet --verify HEAD >/dev/null; then
281 git diff-index --cached --quiet HEAD -- || i="+"
282 else
283 i="#"
287 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
288 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
291 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
292 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
293 u="%"
297 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
298 __git_ps1_show_upstream
302 local f="$w$i$s$u"
303 printf -- "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
307 __gitcomp_1 ()
309 local c IFS=$' \t\n'
310 for c in $1; do
311 c="$c$2"
312 case $c in
313 --*=*|*.) ;;
314 *) c="$c " ;;
315 esac
316 printf '%s\n' "$c"
317 done
320 # The following function is based on code from:
322 # bash_completion - programmable completion functions for bash 3.2+
324 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
325 # © 2009-2010, Bash Completion Maintainers
326 # <bash-completion-devel@lists.alioth.debian.org>
328 # This program is free software; you can redistribute it and/or modify
329 # it under the terms of the GNU General Public License as published by
330 # the Free Software Foundation; either version 2, or (at your option)
331 # any later version.
333 # This program is distributed in the hope that it will be useful,
334 # but WITHOUT ANY WARRANTY; without even the implied warranty of
335 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
336 # GNU General Public License for more details.
338 # You should have received a copy of the GNU General Public License
339 # along with this program; if not, write to the Free Software Foundation,
340 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
342 # The latest version of this software can be obtained here:
344 # http://bash-completion.alioth.debian.org/
346 # RELEASE: 2.x
348 # This function can be used to access a tokenized list of words
349 # on the command line:
351 # __git_reassemble_comp_words_by_ref '=:'
352 # if test "${words_[cword_-1]}" = -w
353 # then
354 # ...
355 # fi
357 # The argument should be a collection of characters from the list of
358 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
359 # characters.
361 # This is roughly equivalent to going back in time and setting
362 # COMP_WORDBREAKS to exclude those characters. The intent is to
363 # make option types like --date=<type> and <rev>:<path> easy to
364 # recognize by treating each shell word as a single token.
366 # It is best not to set COMP_WORDBREAKS directly because the value is
367 # shared with other completion scripts. By the time the completion
368 # function gets called, COMP_WORDS has already been populated so local
369 # changes to COMP_WORDBREAKS have no effect.
371 # Output: words_, cword_, cur_.
373 __git_reassemble_comp_words_by_ref()
375 local exclude i j first
376 # Which word separators to exclude?
377 exclude="${1//[^$COMP_WORDBREAKS]}"
378 cword_=$COMP_CWORD
379 if [ -z "$exclude" ]; then
380 words_=("${COMP_WORDS[@]}")
381 return
383 # List of word completion separators has shrunk;
384 # re-assemble words to complete.
385 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
386 # Append each nonempty word consisting of just
387 # word separator characters to the current word.
388 first=t
389 while
390 [ $i -gt 0 ] &&
391 [ -n "${COMP_WORDS[$i]}" ] &&
392 # word consists of excluded word separators
393 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
395 # Attach to the previous token,
396 # unless the previous token is the command name.
397 if [ $j -ge 2 ] && [ -n "$first" ]; then
398 ((j--))
400 first=
401 words_[$j]=${words_[j]}${COMP_WORDS[i]}
402 if [ $i = $COMP_CWORD ]; then
403 cword_=$j
405 if (($i < ${#COMP_WORDS[@]} - 1)); then
406 ((i++))
407 else
408 # Done.
409 return
411 done
412 words_[$j]=${words_[j]}${COMP_WORDS[i]}
413 if [ $i = $COMP_CWORD ]; then
414 cword_=$j
416 done
419 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
420 if [[ -z ${ZSH_VERSION:+set} ]]; then
421 _get_comp_words_by_ref ()
423 local exclude cur_ words_ cword_
424 if [ "$1" = "-n" ]; then
425 exclude=$2
426 shift 2
428 __git_reassemble_comp_words_by_ref "$exclude"
429 cur_=${words_[cword_]}
430 while [ $# -gt 0 ]; do
431 case "$1" in
432 cur)
433 cur=$cur_
435 prev)
436 prev=${words_[$cword_-1]}
438 words)
439 words=("${words_[@]}")
441 cword)
442 cword=$cword_
444 esac
445 shift
446 done
448 else
449 _get_comp_words_by_ref ()
451 while [ $# -gt 0 ]; do
452 case "$1" in
453 cur)
454 cur=${COMP_WORDS[COMP_CWORD]}
456 prev)
457 prev=${COMP_WORDS[COMP_CWORD-1]}
459 words)
460 words=("${COMP_WORDS[@]}")
462 cword)
463 cword=$COMP_CWORD
466 # assume COMP_WORDBREAKS is already set sanely
467 shift
469 esac
470 shift
471 done
476 # Generates completion reply with compgen, appending a space to possible
477 # completion words, if necessary.
478 # It accepts 1 to 4 arguments:
479 # 1: List of possible completion words.
480 # 2: A prefix to be added to each possible completion word (optional).
481 # 3: Generate possible completion matches for this word (optional).
482 # 4: A suffix to be appended to each possible completion word (optional).
483 __gitcomp ()
485 local cur_="${3-$cur}"
487 case "$cur_" in
488 --*=)
489 COMPREPLY=()
492 local IFS=$'\n'
493 COMPREPLY=($(compgen -P "${2-}" \
494 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
495 -- "$cur_"))
497 esac
500 # Generates completion reply with compgen from newline-separated possible
501 # completion words by appending a space to all of them.
502 # It accepts 1 to 4 arguments:
503 # 1: List of possible completion words, separated by a single newline.
504 # 2: A prefix to be added to each possible completion word (optional).
505 # 3: Generate possible completion matches for this word (optional).
506 # 4: A suffix to be appended to each possible completion word instead of
507 # the default space (optional). If specified but empty, nothing is
508 # appended.
509 __gitcomp_nl ()
511 local IFS=$'\n'
513 # ZSH would quote the trailing space added with -S. bash users
514 # will appreciate the extra space to compensate the use of -o nospace.
515 if [ -n "${ZSH_VERSION-}" ] && [ "$suffix" = " " ]; then
516 suffix=""
519 COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
522 __git_heads ()
524 local dir="$(__gitdir)"
525 if [ -d "$dir" ]; then
526 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
527 refs/heads
528 return
532 __git_tags ()
534 local dir="$(__gitdir)"
535 if [ -d "$dir" ]; then
536 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
537 refs/tags
538 return
542 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
543 # presence of 2nd argument means use the guess heuristic employed
544 # by checkout for tracking branches
545 __git_refs ()
547 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
548 local format refs
549 if [ -d "$dir" ]; then
550 case "$cur" in
551 refs|refs/*)
552 format="refname"
553 refs="${cur%/*}"
554 track=""
557 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
558 if [ -e "$dir/$i" ]; then echo $i; fi
559 done
560 format="refname:short"
561 refs="refs/tags refs/heads refs/remotes"
563 esac
564 git --git-dir="$dir" for-each-ref --format="%($format)" \
565 $refs
566 if [ -n "$track" ]; then
567 # employ the heuristic used by git checkout
568 # Try to find a remote branch that matches the completion word
569 # but only output if the branch name is unique
570 local ref entry
571 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
572 "refs/remotes/" | \
573 while read -r entry; do
574 eval "$entry"
575 ref="${ref#*/}"
576 if [[ "$ref" == "$cur"* ]]; then
577 echo "$ref"
579 done | uniq -u
581 return
583 case "$cur" in
584 refs|refs/*)
585 git ls-remote "$dir" "$cur*" 2>/dev/null | \
586 while read -r hash i; do
587 case "$i" in
588 *^{}) ;;
589 *) echo "$i" ;;
590 esac
591 done
594 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
595 while read -r hash i; do
596 case "$i" in
597 *^{}) ;;
598 refs/*) echo "${i#refs/*/}" ;;
599 *) echo "$i" ;;
600 esac
601 done
603 esac
606 # __git_refs2 requires 1 argument (to pass to __git_refs)
607 __git_refs2 ()
609 local i
610 for i in $(__git_refs "$1"); do
611 echo "$i:$i"
612 done
615 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
616 __git_refs_remotes ()
618 local i hash
619 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
620 while read -r hash i; do
621 echo "$i:refs/remotes/$1/${i#refs/heads/}"
622 done
625 __git_remotes ()
627 local i IFS=$'\n' d="$(__gitdir)"
628 test -d "$d/remotes" && ls -1 "$d/remotes"
629 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
630 i="${i#remote.}"
631 echo "${i/.url*/}"
632 done
635 __git_list_merge_strategies ()
637 git merge -s help 2>&1 |
638 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
639 s/\.$//
640 s/.*://
641 s/^[ ]*//
642 s/[ ]*$//
647 __git_merge_strategies=
648 # 'git merge -s help' (and thus detection of the merge strategy
649 # list) fails, unfortunately, if run outside of any git working
650 # tree. __git_merge_strategies is set to the empty string in
651 # that case, and the detection will be repeated the next time it
652 # is needed.
653 __git_compute_merge_strategies ()
655 test -n "$__git_merge_strategies" ||
656 __git_merge_strategies=$(__git_list_merge_strategies)
659 __git_complete_revlist_file ()
661 local pfx ls ref cur_="$cur"
662 case "$cur_" in
663 *..?*:*)
664 return
666 ?*:*)
667 ref="${cur_%%:*}"
668 cur_="${cur_#*:}"
669 case "$cur_" in
670 ?*/*)
671 pfx="${cur_%/*}"
672 cur_="${cur_##*/}"
673 ls="$ref:$pfx"
674 pfx="$pfx/"
677 ls="$ref"
679 esac
681 case "$COMP_WORDBREAKS" in
682 *:*) : great ;;
683 *) pfx="$ref:$pfx" ;;
684 esac
686 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
687 | sed '/^100... blob /{
688 s,^.* ,,
689 s,$, ,
691 /^120000 blob /{
692 s,^.* ,,
693 s,$, ,
695 /^040000 tree /{
696 s,^.* ,,
697 s,$,/,
699 s/^.* //')" \
700 "$pfx" "$cur_" ""
702 *...*)
703 pfx="${cur_%...*}..."
704 cur_="${cur_#*...}"
705 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
707 *..*)
708 pfx="${cur_%..*}.."
709 cur_="${cur_#*..}"
710 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
713 __gitcomp_nl "$(__git_refs)"
715 esac
719 __git_complete_file ()
721 __git_complete_revlist_file
724 __git_complete_revlist ()
726 __git_complete_revlist_file
729 __git_complete_remote_or_refspec ()
731 local cur_="$cur" cmd="${words[1]}"
732 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
733 if [ "$cmd" = "remote" ]; then
734 ((c++))
736 while [ $c -lt $cword ]; do
737 i="${words[c]}"
738 case "$i" in
739 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
740 --all)
741 case "$cmd" in
742 push) no_complete_refspec=1 ;;
743 fetch)
744 COMPREPLY=()
745 return
747 *) ;;
748 esac
750 -*) ;;
751 *) remote="$i"; break ;;
752 esac
753 ((c++))
754 done
755 if [ -z "$remote" ]; then
756 __gitcomp_nl "$(__git_remotes)"
757 return
759 if [ $no_complete_refspec = 1 ]; then
760 COMPREPLY=()
761 return
763 [ "$remote" = "." ] && remote=
764 case "$cur_" in
765 *:*)
766 case "$COMP_WORDBREAKS" in
767 *:*) : great ;;
768 *) pfx="${cur_%%:*}:" ;;
769 esac
770 cur_="${cur_#*:}"
771 lhs=0
774 pfx="+"
775 cur_="${cur_#+}"
777 esac
778 case "$cmd" in
779 fetch)
780 if [ $lhs = 1 ]; then
781 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
782 else
783 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
786 pull|remote)
787 if [ $lhs = 1 ]; then
788 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
789 else
790 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
793 push)
794 if [ $lhs = 1 ]; then
795 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
796 else
797 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
800 esac
803 __git_complete_strategy ()
805 __git_compute_merge_strategies
806 case "$prev" in
807 -s|--strategy)
808 __gitcomp "$__git_merge_strategies"
809 return 0
810 esac
811 case "$cur" in
812 --strategy=*)
813 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
814 return 0
816 esac
817 return 1
820 __git_list_all_commands ()
822 local i IFS=" "$'\n'
823 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
825 case $i in
826 *--*) : helper pattern;;
827 *) echo $i;;
828 esac
829 done
832 __git_all_commands=
833 __git_compute_all_commands ()
835 test -n "$__git_all_commands" ||
836 __git_all_commands=$(__git_list_all_commands)
839 __git_list_porcelain_commands ()
841 local i IFS=" "$'\n'
842 __git_compute_all_commands
843 for i in "help" $__git_all_commands
845 case $i in
846 *--*) : helper pattern;;
847 applymbox) : ask gittus;;
848 applypatch) : ask gittus;;
849 archimport) : import;;
850 cat-file) : plumbing;;
851 check-attr) : plumbing;;
852 check-ref-format) : plumbing;;
853 checkout-index) : plumbing;;
854 commit-tree) : plumbing;;
855 count-objects) : infrequent;;
856 cvsexportcommit) : export;;
857 cvsimport) : import;;
858 cvsserver) : daemon;;
859 daemon) : daemon;;
860 diff-files) : plumbing;;
861 diff-index) : plumbing;;
862 diff-tree) : plumbing;;
863 fast-import) : import;;
864 fast-export) : export;;
865 fsck-objects) : plumbing;;
866 fetch-pack) : plumbing;;
867 fmt-merge-msg) : plumbing;;
868 for-each-ref) : plumbing;;
869 hash-object) : plumbing;;
870 http-*) : transport;;
871 index-pack) : plumbing;;
872 init-db) : deprecated;;
873 local-fetch) : plumbing;;
874 lost-found) : infrequent;;
875 ls-files) : plumbing;;
876 ls-remote) : plumbing;;
877 ls-tree) : plumbing;;
878 mailinfo) : plumbing;;
879 mailsplit) : plumbing;;
880 merge-*) : plumbing;;
881 mktree) : plumbing;;
882 mktag) : plumbing;;
883 pack-objects) : plumbing;;
884 pack-redundant) : plumbing;;
885 pack-refs) : plumbing;;
886 parse-remote) : plumbing;;
887 patch-id) : plumbing;;
888 peek-remote) : plumbing;;
889 prune) : plumbing;;
890 prune-packed) : plumbing;;
891 quiltimport) : import;;
892 read-tree) : plumbing;;
893 receive-pack) : plumbing;;
894 remote-*) : transport;;
895 repo-config) : deprecated;;
896 rerere) : plumbing;;
897 rev-list) : plumbing;;
898 rev-parse) : plumbing;;
899 runstatus) : plumbing;;
900 sh-setup) : internal;;
901 shell) : daemon;;
902 show-ref) : plumbing;;
903 send-pack) : plumbing;;
904 show-index) : plumbing;;
905 ssh-*) : transport;;
906 stripspace) : plumbing;;
907 symbolic-ref) : plumbing;;
908 tar-tree) : deprecated;;
909 unpack-file) : plumbing;;
910 unpack-objects) : plumbing;;
911 update-index) : plumbing;;
912 update-ref) : plumbing;;
913 update-server-info) : daemon;;
914 upload-archive) : plumbing;;
915 upload-pack) : plumbing;;
916 write-tree) : plumbing;;
917 var) : infrequent;;
918 verify-pack) : infrequent;;
919 verify-tag) : plumbing;;
920 *) echo $i;;
921 esac
922 done
925 __git_porcelain_commands=
926 __git_compute_porcelain_commands ()
928 __git_compute_all_commands
929 test -n "$__git_porcelain_commands" ||
930 __git_porcelain_commands=$(__git_list_porcelain_commands)
933 __git_pretty_aliases ()
935 local i IFS=$'\n'
936 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
937 case "$i" in
938 pretty.*)
939 i="${i#pretty.}"
940 echo "${i/ */}"
942 esac
943 done
946 __git_aliases ()
948 local i IFS=$'\n'
949 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
950 case "$i" in
951 alias.*)
952 i="${i#alias.}"
953 echo "${i/ */}"
955 esac
956 done
959 # __git_aliased_command requires 1 argument
960 __git_aliased_command ()
962 local word cmdline=$(git --git-dir="$(__gitdir)" \
963 config --get "alias.$1")
964 for word in $cmdline; do
965 case "$word" in
966 \!gitk|gitk)
967 echo "gitk"
968 return
970 \!*) : shell command alias ;;
971 -*) : option ;;
972 *=*) : setting env ;;
973 git) : git itself ;;
975 echo "$word"
976 return
977 esac
978 done
981 # __git_find_on_cmdline requires 1 argument
982 __git_find_on_cmdline ()
984 local word subcommand c=1
985 while [ $c -lt $cword ]; do
986 word="${words[c]}"
987 for subcommand in $1; do
988 if [ "$subcommand" = "$word" ]; then
989 echo "$subcommand"
990 return
992 done
993 ((c++))
994 done
997 __git_has_doubledash ()
999 local c=1
1000 while [ $c -lt $cword ]; do
1001 if [ "--" = "${words[c]}" ]; then
1002 return 0
1004 ((c++))
1005 done
1006 return 1
1009 __git_whitespacelist="nowarn warn error error-all fix"
1011 _git_am ()
1013 local dir="$(__gitdir)"
1014 if [ -d "$dir"/rebase-apply ]; then
1015 __gitcomp "--skip --continue --resolved --abort"
1016 return
1018 case "$cur" in
1019 --whitespace=*)
1020 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1021 return
1023 --*)
1024 __gitcomp "
1025 --3way --committer-date-is-author-date --ignore-date
1026 --ignore-whitespace --ignore-space-change
1027 --interactive --keep --no-utf8 --signoff --utf8
1028 --whitespace= --scissors
1030 return
1031 esac
1032 COMPREPLY=()
1035 _git_apply ()
1037 case "$cur" in
1038 --whitespace=*)
1039 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1040 return
1042 --*)
1043 __gitcomp "
1044 --stat --numstat --summary --check --index
1045 --cached --index-info --reverse --reject --unidiff-zero
1046 --apply --no-add --exclude=
1047 --ignore-whitespace --ignore-space-change
1048 --whitespace= --inaccurate-eof --verbose
1050 return
1051 esac
1052 COMPREPLY=()
1055 _git_add ()
1057 __git_has_doubledash && return
1059 case "$cur" in
1060 --*)
1061 __gitcomp "
1062 --interactive --refresh --patch --update --dry-run
1063 --ignore-errors --intent-to-add
1065 return
1066 esac
1067 COMPREPLY=()
1070 _git_archive ()
1072 case "$cur" in
1073 --format=*)
1074 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1075 return
1077 --remote=*)
1078 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1079 return
1081 --*)
1082 __gitcomp "
1083 --format= --list --verbose
1084 --prefix= --remote= --exec=
1086 return
1088 esac
1089 __git_complete_file
1092 _git_bisect ()
1094 __git_has_doubledash && return
1096 local subcommands="start bad good skip reset visualize replay log run"
1097 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1098 if [ -z "$subcommand" ]; then
1099 if [ -f "$(__gitdir)"/BISECT_START ]; then
1100 __gitcomp "$subcommands"
1101 else
1102 __gitcomp "replay start"
1104 return
1107 case "$subcommand" in
1108 bad|good|reset|skip|start)
1109 __gitcomp_nl "$(__git_refs)"
1112 COMPREPLY=()
1114 esac
1117 _git_branch ()
1119 local i c=1 only_local_ref="n" has_r="n"
1121 while [ $c -lt $cword ]; do
1122 i="${words[c]}"
1123 case "$i" in
1124 -d|-m) only_local_ref="y" ;;
1125 -r) has_r="y" ;;
1126 esac
1127 ((c++))
1128 done
1130 case "$cur" in
1131 --*)
1132 __gitcomp "
1133 --color --no-color --verbose --abbrev= --no-abbrev
1134 --track --no-track --contains --merged --no-merged
1135 --set-upstream --edit-description --list
1139 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1140 __gitcomp_nl "$(__git_heads)"
1141 else
1142 __gitcomp_nl "$(__git_refs)"
1145 esac
1148 _git_bundle ()
1150 local cmd="${words[2]}"
1151 case "$cword" in
1153 __gitcomp "create list-heads verify unbundle"
1156 # looking for a file
1159 case "$cmd" in
1160 create)
1161 __git_complete_revlist
1163 esac
1165 esac
1168 _git_checkout ()
1170 __git_has_doubledash && return
1172 case "$cur" in
1173 --conflict=*)
1174 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1176 --*)
1177 __gitcomp "
1178 --quiet --ours --theirs --track --no-track --merge
1179 --conflict= --orphan --patch
1183 # check if --track, --no-track, or --no-guess was specified
1184 # if so, disable DWIM mode
1185 local flags="--track --no-track --no-guess" track=1
1186 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1187 track=''
1189 __gitcomp_nl "$(__git_refs '' $track)"
1191 esac
1194 _git_cherry ()
1196 __gitcomp "$(__git_refs)"
1199 _git_cherry_pick ()
1201 case "$cur" in
1202 --*)
1203 __gitcomp "--edit --no-commit"
1206 __gitcomp_nl "$(__git_refs)"
1208 esac
1211 _git_clean ()
1213 __git_has_doubledash && return
1215 case "$cur" in
1216 --*)
1217 __gitcomp "--dry-run --quiet"
1218 return
1220 esac
1221 COMPREPLY=()
1224 _git_clone ()
1226 case "$cur" in
1227 --*)
1228 __gitcomp "
1229 --local
1230 --no-hardlinks
1231 --shared
1232 --reference
1233 --quiet
1234 --no-checkout
1235 --bare
1236 --mirror
1237 --origin
1238 --upload-pack
1239 --template=
1240 --depth
1242 return
1244 esac
1245 COMPREPLY=()
1248 _git_commit ()
1250 __git_has_doubledash && return
1252 case "$cur" in
1253 --cleanup=*)
1254 __gitcomp "default strip verbatim whitespace
1255 " "" "${cur##--cleanup=}"
1256 return
1258 --reuse-message=*|--reedit-message=*|\
1259 --fixup=*|--squash=*)
1260 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1261 return
1263 --untracked-files=*)
1264 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1265 return
1267 --*)
1268 __gitcomp "
1269 --all --author= --signoff --verify --no-verify
1270 --edit --amend --include --only --interactive
1271 --dry-run --reuse-message= --reedit-message=
1272 --reset-author --file= --message= --template=
1273 --cleanup= --untracked-files --untracked-files=
1274 --verbose --quiet --fixup= --squash=
1276 return
1277 esac
1278 COMPREPLY=()
1281 _git_describe ()
1283 case "$cur" in
1284 --*)
1285 __gitcomp "
1286 --all --tags --contains --abbrev= --candidates=
1287 --exact-match --debug --long --match --always
1289 return
1290 esac
1291 __gitcomp_nl "$(__git_refs)"
1294 __git_diff_common_options="--stat --numstat --shortstat --summary
1295 --patch-with-stat --name-only --name-status --color
1296 --no-color --color-words --no-renames --check
1297 --full-index --binary --abbrev --diff-filter=
1298 --find-copies-harder
1299 --text --ignore-space-at-eol --ignore-space-change
1300 --ignore-all-space --exit-code --quiet --ext-diff
1301 --no-ext-diff
1302 --no-prefix --src-prefix= --dst-prefix=
1303 --inter-hunk-context=
1304 --patience
1305 --raw
1306 --dirstat --dirstat= --dirstat-by-file
1307 --dirstat-by-file= --cumulative
1310 _git_diff ()
1312 __git_has_doubledash && return
1314 case "$cur" in
1315 --*)
1316 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1317 --base --ours --theirs --no-index
1318 $__git_diff_common_options
1320 return
1322 esac
1323 __git_complete_revlist_file
1326 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1327 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
1330 _git_difftool ()
1332 __git_has_doubledash && return
1334 case "$cur" in
1335 --tool=*)
1336 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1337 return
1339 --*)
1340 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1341 --base --ours --theirs
1342 --no-renames --diff-filter= --find-copies-harder
1343 --relative --ignore-submodules
1344 --tool="
1345 return
1347 esac
1348 __git_complete_file
1351 __git_fetch_options="
1352 --quiet --verbose --append --upload-pack --force --keep --depth=
1353 --tags --no-tags --all --prune --dry-run
1356 _git_fetch ()
1358 case "$cur" in
1359 --*)
1360 __gitcomp "$__git_fetch_options"
1361 return
1363 esac
1364 __git_complete_remote_or_refspec
1367 _git_format_patch ()
1369 case "$cur" in
1370 --thread=*)
1371 __gitcomp "
1372 deep shallow
1373 " "" "${cur##--thread=}"
1374 return
1376 --*)
1377 __gitcomp "
1378 --stdout --attach --no-attach --thread --thread=
1379 --output-directory
1380 --numbered --start-number
1381 --numbered-files
1382 --keep-subject
1383 --signoff --signature --no-signature
1384 --in-reply-to= --cc=
1385 --full-index --binary
1386 --not --all
1387 --cover-letter
1388 --no-prefix --src-prefix= --dst-prefix=
1389 --inline --suffix= --ignore-if-in-upstream
1390 --subject-prefix=
1392 return
1394 esac
1395 __git_complete_revlist
1398 _git_fsck ()
1400 case "$cur" in
1401 --*)
1402 __gitcomp "
1403 --tags --root --unreachable --cache --no-reflogs --full
1404 --strict --verbose --lost-found
1406 return
1408 esac
1409 COMPREPLY=()
1412 _git_gc ()
1414 case "$cur" in
1415 --*)
1416 __gitcomp "--prune --aggressive"
1417 return
1419 esac
1420 COMPREPLY=()
1423 _git_gitk ()
1425 _gitk
1428 __git_match_ctag() {
1429 awk "/^${1////\\/}/ { print \$1 }" "$2"
1432 _git_grep ()
1434 __git_has_doubledash && return
1436 case "$cur" in
1437 --*)
1438 __gitcomp "
1439 --cached
1440 --text --ignore-case --word-regexp --invert-match
1441 --full-name --line-number
1442 --extended-regexp --basic-regexp --fixed-strings
1443 --perl-regexp
1444 --files-with-matches --name-only
1445 --files-without-match
1446 --max-depth
1447 --count
1448 --and --or --not --all-match
1450 return
1452 esac
1454 case "$cword,$prev" in
1455 2,*|*,-*)
1456 if test -r tags; then
1457 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1458 return
1461 esac
1463 __gitcomp_nl "$(__git_refs)"
1466 _git_help ()
1468 case "$cur" in
1469 --*)
1470 __gitcomp "--all --info --man --web"
1471 return
1473 esac
1474 __git_compute_all_commands
1475 __gitcomp "$__git_all_commands $(__git_aliases)
1476 attributes cli core-tutorial cvs-migration
1477 diffcore gitk glossary hooks ignore modules
1478 namespaces repository-layout tutorial tutorial-2
1479 workflows
1483 _git_init ()
1485 case "$cur" in
1486 --shared=*)
1487 __gitcomp "
1488 false true umask group all world everybody
1489 " "" "${cur##--shared=}"
1490 return
1492 --*)
1493 __gitcomp "--quiet --bare --template= --shared --shared="
1494 return
1496 esac
1497 COMPREPLY=()
1500 _git_ls_files ()
1502 __git_has_doubledash && return
1504 case "$cur" in
1505 --*)
1506 __gitcomp "--cached --deleted --modified --others --ignored
1507 --stage --directory --no-empty-directory --unmerged
1508 --killed --exclude= --exclude-from=
1509 --exclude-per-directory= --exclude-standard
1510 --error-unmatch --with-tree= --full-name
1511 --abbrev --ignored --exclude-per-directory
1513 return
1515 esac
1516 COMPREPLY=()
1519 _git_ls_remote ()
1521 __gitcomp_nl "$(__git_remotes)"
1524 _git_ls_tree ()
1526 __git_complete_file
1529 # Options that go well for log, shortlog and gitk
1530 __git_log_common_options="
1531 --not --all
1532 --branches --tags --remotes
1533 --first-parent --merges --no-merges
1534 --max-count=
1535 --max-age= --since= --after=
1536 --min-age= --until= --before=
1537 --min-parents= --max-parents=
1538 --no-min-parents --no-max-parents
1540 # Options that go well for log and gitk (not shortlog)
1541 __git_log_gitk_options="
1542 --dense --sparse --full-history
1543 --simplify-merges --simplify-by-decoration
1544 --left-right --notes --no-notes
1546 # Options that go well for log and shortlog (not gitk)
1547 __git_log_shortlog_options="
1548 --author= --committer= --grep=
1549 --all-match
1552 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1553 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1555 _git_log ()
1557 __git_has_doubledash && return
1559 local g="$(git rev-parse --git-dir 2>/dev/null)"
1560 local merge=""
1561 if [ -f "$g/MERGE_HEAD" ]; then
1562 merge="--merge"
1564 case "$cur" in
1565 --pretty=*|--format=*)
1566 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1567 " "" "${cur#*=}"
1568 return
1570 --date=*)
1571 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1572 return
1574 --decorate=*)
1575 __gitcomp "long short" "" "${cur##--decorate=}"
1576 return
1578 --*)
1579 __gitcomp "
1580 $__git_log_common_options
1581 $__git_log_shortlog_options
1582 $__git_log_gitk_options
1583 --root --topo-order --date-order --reverse
1584 --follow --full-diff
1585 --abbrev-commit --abbrev=
1586 --relative-date --date=
1587 --pretty= --format= --oneline
1588 --cherry-pick
1589 --graph
1590 --decorate --decorate=
1591 --walk-reflogs
1592 --parents --children
1593 $merge
1594 $__git_diff_common_options
1595 --pickaxe-all --pickaxe-regex
1597 return
1599 esac
1600 __git_complete_revlist
1603 __git_merge_options="
1604 --no-commit --no-stat --log --no-log --squash --strategy
1605 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1608 _git_merge ()
1610 __git_complete_strategy && return
1612 case "$cur" in
1613 --*)
1614 __gitcomp "$__git_merge_options"
1615 return
1616 esac
1617 __gitcomp_nl "$(__git_refs)"
1620 _git_mergetool ()
1622 case "$cur" in
1623 --tool=*)
1624 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1625 return
1627 --*)
1628 __gitcomp "--tool="
1629 return
1631 esac
1632 COMPREPLY=()
1635 _git_merge_base ()
1637 __gitcomp_nl "$(__git_refs)"
1640 _git_mv ()
1642 case "$cur" in
1643 --*)
1644 __gitcomp "--dry-run"
1645 return
1647 esac
1648 COMPREPLY=()
1651 _git_name_rev ()
1653 __gitcomp "--tags --all --stdin"
1656 _git_notes ()
1658 local subcommands='add append copy edit list prune remove show'
1659 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1661 case "$subcommand,$cur" in
1662 ,--*)
1663 __gitcomp '--ref'
1666 case "$prev" in
1667 --ref)
1668 __gitcomp_nl "$(__git_refs)"
1671 __gitcomp "$subcommands --ref"
1673 esac
1675 add,--reuse-message=*|append,--reuse-message=*|\
1676 add,--reedit-message=*|append,--reedit-message=*)
1677 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1679 add,--*|append,--*)
1680 __gitcomp '--file= --message= --reedit-message=
1681 --reuse-message='
1683 copy,--*)
1684 __gitcomp '--stdin'
1686 prune,--*)
1687 __gitcomp '--dry-run --verbose'
1689 prune,*)
1692 case "$prev" in
1693 -m|-F)
1696 __gitcomp_nl "$(__git_refs)"
1698 esac
1700 esac
1703 _git_pull ()
1705 __git_complete_strategy && return
1707 case "$cur" in
1708 --*)
1709 __gitcomp "
1710 --rebase --no-rebase
1711 $__git_merge_options
1712 $__git_fetch_options
1714 return
1716 esac
1717 __git_complete_remote_or_refspec
1720 _git_push ()
1722 case "$prev" in
1723 --repo)
1724 __gitcomp_nl "$(__git_remotes)"
1725 return
1726 esac
1727 case "$cur" in
1728 --repo=*)
1729 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1730 return
1732 --*)
1733 __gitcomp "
1734 --all --mirror --tags --dry-run --force --verbose
1735 --receive-pack= --repo= --set-upstream
1737 return
1739 esac
1740 __git_complete_remote_or_refspec
1743 _git_rebase ()
1745 local dir="$(__gitdir)"
1746 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1747 __gitcomp "--continue --skip --abort"
1748 return
1750 __git_complete_strategy && return
1751 case "$cur" in
1752 --whitespace=*)
1753 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1754 return
1756 --*)
1757 __gitcomp "
1758 --onto --merge --strategy --interactive
1759 --preserve-merges --stat --no-stat
1760 --committer-date-is-author-date --ignore-date
1761 --ignore-whitespace --whitespace=
1762 --autosquash
1765 return
1766 esac
1767 __gitcomp_nl "$(__git_refs)"
1770 _git_reflog ()
1772 local subcommands="show delete expire"
1773 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1775 if [ -z "$subcommand" ]; then
1776 __gitcomp "$subcommands"
1777 else
1778 __gitcomp_nl "$(__git_refs)"
1782 __git_send_email_confirm_options="always never auto cc compose"
1783 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1785 _git_send_email ()
1787 case "$cur" in
1788 --confirm=*)
1789 __gitcomp "
1790 $__git_send_email_confirm_options
1791 " "" "${cur##--confirm=}"
1792 return
1794 --suppress-cc=*)
1795 __gitcomp "
1796 $__git_send_email_suppresscc_options
1797 " "" "${cur##--suppress-cc=}"
1799 return
1801 --smtp-encryption=*)
1802 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1803 return
1805 --*)
1806 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1807 --compose --confirm= --dry-run --envelope-sender
1808 --from --identity
1809 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1810 --no-suppress-from --no-thread --quiet
1811 --signed-off-by-cc --smtp-pass --smtp-server
1812 --smtp-server-port --smtp-encryption= --smtp-user
1813 --subject --suppress-cc= --suppress-from --thread --to
1814 --validate --no-validate"
1815 return
1817 esac
1818 COMPREPLY=()
1821 _git_stage ()
1823 _git_add
1826 __git_config_get_set_variables ()
1828 local prevword word config_file= c=$cword
1829 while [ $c -gt 1 ]; do
1830 word="${words[c]}"
1831 case "$word" in
1832 --global|--system|--file=*)
1833 config_file="$word"
1834 break
1836 -f|--file)
1837 config_file="$word $prevword"
1838 break
1840 esac
1841 prevword=$word
1842 c=$((--c))
1843 done
1845 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1846 while read -r line
1848 case "$line" in
1849 *.*=*)
1850 echo "${line/=*/}"
1852 esac
1853 done
1856 _git_config ()
1858 case "$prev" in
1859 branch.*.remote)
1860 __gitcomp_nl "$(__git_remotes)"
1861 return
1863 branch.*.merge)
1864 __gitcomp_nl "$(__git_refs)"
1865 return
1867 remote.*.fetch)
1868 local remote="${prev#remote.}"
1869 remote="${remote%.fetch}"
1870 if [ -z "$cur" ]; then
1871 COMPREPLY=("refs/heads/")
1872 return
1874 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1875 return
1877 remote.*.push)
1878 local remote="${prev#remote.}"
1879 remote="${remote%.push}"
1880 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1881 for-each-ref --format='%(refname):%(refname)' \
1882 refs/heads)"
1883 return
1885 pull.twohead|pull.octopus)
1886 __git_compute_merge_strategies
1887 __gitcomp "$__git_merge_strategies"
1888 return
1890 color.branch|color.diff|color.interactive|\
1891 color.showbranch|color.status|color.ui)
1892 __gitcomp "always never auto"
1893 return
1895 color.pager)
1896 __gitcomp "false true"
1897 return
1899 color.*.*)
1900 __gitcomp "
1901 normal black red green yellow blue magenta cyan white
1902 bold dim ul blink reverse
1904 return
1906 help.format)
1907 __gitcomp "man info web html"
1908 return
1910 log.date)
1911 __gitcomp "$__git_log_date_formats"
1912 return
1914 sendemail.aliasesfiletype)
1915 __gitcomp "mutt mailrc pine elm gnus"
1916 return
1918 sendemail.confirm)
1919 __gitcomp "$__git_send_email_confirm_options"
1920 return
1922 sendemail.suppresscc)
1923 __gitcomp "$__git_send_email_suppresscc_options"
1924 return
1926 --get|--get-all|--unset|--unset-all)
1927 __gitcomp_nl "$(__git_config_get_set_variables)"
1928 return
1930 *.*)
1931 COMPREPLY=()
1932 return
1934 esac
1935 case "$cur" in
1936 --*)
1937 __gitcomp "
1938 --global --system --file=
1939 --list --replace-all
1940 --get --get-all --get-regexp
1941 --add --unset --unset-all
1942 --remove-section --rename-section
1944 return
1946 branch.*.*)
1947 local pfx="${cur%.*}." cur_="${cur##*.}"
1948 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1949 return
1951 branch.*)
1952 local pfx="${cur%.*}." cur_="${cur#*.}"
1953 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1954 return
1956 guitool.*.*)
1957 local pfx="${cur%.*}." cur_="${cur##*.}"
1958 __gitcomp "
1959 argprompt cmd confirm needsfile noconsole norescan
1960 prompt revprompt revunmerged title
1961 " "$pfx" "$cur_"
1962 return
1964 difftool.*.*)
1965 local pfx="${cur%.*}." cur_="${cur##*.}"
1966 __gitcomp "cmd path" "$pfx" "$cur_"
1967 return
1969 man.*.*)
1970 local pfx="${cur%.*}." cur_="${cur##*.}"
1971 __gitcomp "cmd path" "$pfx" "$cur_"
1972 return
1974 mergetool.*.*)
1975 local pfx="${cur%.*}." cur_="${cur##*.}"
1976 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1977 return
1979 pager.*)
1980 local pfx="${cur%.*}." cur_="${cur#*.}"
1981 __git_compute_all_commands
1982 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1983 return
1985 remote.*.*)
1986 local pfx="${cur%.*}." cur_="${cur##*.}"
1987 __gitcomp "
1988 url proxy fetch push mirror skipDefaultUpdate
1989 receivepack uploadpack tagopt pushurl
1990 " "$pfx" "$cur_"
1991 return
1993 remote.*)
1994 local pfx="${cur%.*}." cur_="${cur#*.}"
1995 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1996 return
1998 url.*.*)
1999 local pfx="${cur%.*}." cur_="${cur##*.}"
2000 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2001 return
2003 esac
2004 __gitcomp "
2005 add.ignoreErrors
2006 advice.commitBeforeMerge
2007 advice.detachedHead
2008 advice.implicitIdentity
2009 advice.pushNonFastForward
2010 advice.resolveConflict
2011 advice.statusHints
2012 alias.
2013 am.keepcr
2014 apply.ignorewhitespace
2015 apply.whitespace
2016 branch.autosetupmerge
2017 branch.autosetuprebase
2018 browser.
2019 clean.requireForce
2020 color.branch
2021 color.branch.current
2022 color.branch.local
2023 color.branch.plain
2024 color.branch.remote
2025 color.decorate.HEAD
2026 color.decorate.branch
2027 color.decorate.remoteBranch
2028 color.decorate.stash
2029 color.decorate.tag
2030 color.diff
2031 color.diff.commit
2032 color.diff.frag
2033 color.diff.func
2034 color.diff.meta
2035 color.diff.new
2036 color.diff.old
2037 color.diff.plain
2038 color.diff.whitespace
2039 color.grep
2040 color.grep.context
2041 color.grep.filename
2042 color.grep.function
2043 color.grep.linenumber
2044 color.grep.match
2045 color.grep.selected
2046 color.grep.separator
2047 color.interactive
2048 color.interactive.error
2049 color.interactive.header
2050 color.interactive.help
2051 color.interactive.prompt
2052 color.pager
2053 color.showbranch
2054 color.status
2055 color.status.added
2056 color.status.changed
2057 color.status.header
2058 color.status.nobranch
2059 color.status.untracked
2060 color.status.updated
2061 color.ui
2062 commit.status
2063 commit.template
2064 core.abbrev
2065 core.askpass
2066 core.attributesfile
2067 core.autocrlf
2068 core.bare
2069 core.bigFileThreshold
2070 core.compression
2071 core.createObject
2072 core.deltaBaseCacheLimit
2073 core.editor
2074 core.eol
2075 core.excludesfile
2076 core.fileMode
2077 core.fsyncobjectfiles
2078 core.gitProxy
2079 core.ignoreCygwinFSTricks
2080 core.ignoreStat
2081 core.ignorecase
2082 core.logAllRefUpdates
2083 core.loosecompression
2084 core.notesRef
2085 core.packedGitLimit
2086 core.packedGitWindowSize
2087 core.pager
2088 core.preferSymlinkRefs
2089 core.preloadindex
2090 core.quotepath
2091 core.repositoryFormatVersion
2092 core.safecrlf
2093 core.sharedRepository
2094 core.sparseCheckout
2095 core.symlinks
2096 core.trustctime
2097 core.warnAmbiguousRefs
2098 core.whitespace
2099 core.worktree
2100 diff.autorefreshindex
2101 diff.statGraphWidth
2102 diff.external
2103 diff.ignoreSubmodules
2104 diff.mnemonicprefix
2105 diff.noprefix
2106 diff.renameLimit
2107 diff.renames
2108 diff.suppressBlankEmpty
2109 diff.tool
2110 diff.wordRegex
2111 difftool.
2112 difftool.prompt
2113 fetch.recurseSubmodules
2114 fetch.unpackLimit
2115 format.attach
2116 format.cc
2117 format.headers
2118 format.numbered
2119 format.pretty
2120 format.signature
2121 format.signoff
2122 format.subjectprefix
2123 format.suffix
2124 format.thread
2125 format.to
2127 gc.aggressiveWindow
2128 gc.auto
2129 gc.autopacklimit
2130 gc.packrefs
2131 gc.pruneexpire
2132 gc.reflogexpire
2133 gc.reflogexpireunreachable
2134 gc.rerereresolved
2135 gc.rerereunresolved
2136 gitcvs.allbinary
2137 gitcvs.commitmsgannotation
2138 gitcvs.dbTableNamePrefix
2139 gitcvs.dbdriver
2140 gitcvs.dbname
2141 gitcvs.dbpass
2142 gitcvs.dbuser
2143 gitcvs.enabled
2144 gitcvs.logfile
2145 gitcvs.usecrlfattr
2146 guitool.
2147 gui.blamehistoryctx
2148 gui.commitmsgwidth
2149 gui.copyblamethreshold
2150 gui.diffcontext
2151 gui.encoding
2152 gui.fastcopyblame
2153 gui.matchtrackingbranch
2154 gui.newbranchtemplate
2155 gui.pruneduringfetch
2156 gui.spellingdictionary
2157 gui.trustmtime
2158 help.autocorrect
2159 help.browser
2160 help.format
2161 http.lowSpeedLimit
2162 http.lowSpeedTime
2163 http.maxRequests
2164 http.minSessions
2165 http.noEPSV
2166 http.postBuffer
2167 http.proxy
2168 http.sslCAInfo
2169 http.sslCAPath
2170 http.sslCert
2171 http.sslCertPasswordProtected
2172 http.sslKey
2173 http.sslVerify
2174 http.useragent
2175 i18n.commitEncoding
2176 i18n.logOutputEncoding
2177 imap.authMethod
2178 imap.folder
2179 imap.host
2180 imap.pass
2181 imap.port
2182 imap.preformattedHTML
2183 imap.sslverify
2184 imap.tunnel
2185 imap.user
2186 init.templatedir
2187 instaweb.browser
2188 instaweb.httpd
2189 instaweb.local
2190 instaweb.modulepath
2191 instaweb.port
2192 interactive.singlekey
2193 log.date
2194 log.decorate
2195 log.showroot
2196 mailmap.file
2197 man.
2198 man.viewer
2199 merge.
2200 merge.conflictstyle
2201 merge.log
2202 merge.renameLimit
2203 merge.renormalize
2204 merge.stat
2205 merge.tool
2206 merge.verbosity
2207 mergetool.
2208 mergetool.keepBackup
2209 mergetool.keepTemporaries
2210 mergetool.prompt
2211 notes.displayRef
2212 notes.rewrite.
2213 notes.rewrite.amend
2214 notes.rewrite.rebase
2215 notes.rewriteMode
2216 notes.rewriteRef
2217 pack.compression
2218 pack.deltaCacheLimit
2219 pack.deltaCacheSize
2220 pack.depth
2221 pack.indexVersion
2222 pack.packSizeLimit
2223 pack.threads
2224 pack.window
2225 pack.windowMemory
2226 pager.
2227 pretty.
2228 pull.octopus
2229 pull.twohead
2230 push.default
2231 rebase.autosquash
2232 rebase.stat
2233 receive.autogc
2234 receive.denyCurrentBranch
2235 receive.denyDeleteCurrent
2236 receive.denyDeletes
2237 receive.denyNonFastForwards
2238 receive.fsckObjects
2239 receive.unpackLimit
2240 receive.updateserverinfo
2241 remotes.
2242 repack.usedeltabaseoffset
2243 rerere.autoupdate
2244 rerere.enabled
2245 sendemail.
2246 sendemail.aliasesfile
2247 sendemail.aliasfiletype
2248 sendemail.bcc
2249 sendemail.cc
2250 sendemail.cccmd
2251 sendemail.chainreplyto
2252 sendemail.confirm
2253 sendemail.envelopesender
2254 sendemail.from
2255 sendemail.identity
2256 sendemail.multiedit
2257 sendemail.signedoffbycc
2258 sendemail.smtpdomain
2259 sendemail.smtpencryption
2260 sendemail.smtppass
2261 sendemail.smtpserver
2262 sendemail.smtpserveroption
2263 sendemail.smtpserverport
2264 sendemail.smtpuser
2265 sendemail.suppresscc
2266 sendemail.suppressfrom
2267 sendemail.thread
2268 sendemail.to
2269 sendemail.validate
2270 showbranch.default
2271 status.relativePaths
2272 status.showUntrackedFiles
2273 status.submodulesummary
2274 submodule.
2275 tar.umask
2276 transfer.unpackLimit
2277 url.
2278 user.email
2279 user.name
2280 user.signingkey
2281 web.browser
2282 branch. remote.
2286 _git_remote ()
2288 local subcommands="add rename rm set-head set-branches set-url show prune update"
2289 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2290 if [ -z "$subcommand" ]; then
2291 __gitcomp "$subcommands"
2292 return
2295 case "$subcommand" in
2296 rename|rm|set-url|show|prune)
2297 __gitcomp_nl "$(__git_remotes)"
2299 set-head|set-branches)
2300 __git_complete_remote_or_refspec
2302 update)
2303 local i c='' IFS=$'\n'
2304 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2305 i="${i#remotes.}"
2306 c="$c ${i/ */}"
2307 done
2308 __gitcomp "$c"
2311 COMPREPLY=()
2313 esac
2316 _git_replace ()
2318 __gitcomp_nl "$(__git_refs)"
2321 _git_reset ()
2323 __git_has_doubledash && return
2325 case "$cur" in
2326 --*)
2327 __gitcomp "--merge --mixed --hard --soft --patch"
2328 return
2330 esac
2331 __gitcomp_nl "$(__git_refs)"
2334 _git_revert ()
2336 case "$cur" in
2337 --*)
2338 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2339 return
2341 esac
2342 __gitcomp_nl "$(__git_refs)"
2345 _git_rm ()
2347 __git_has_doubledash && return
2349 case "$cur" in
2350 --*)
2351 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2352 return
2354 esac
2355 COMPREPLY=()
2358 _git_shortlog ()
2360 __git_has_doubledash && return
2362 case "$cur" in
2363 --*)
2364 __gitcomp "
2365 $__git_log_common_options
2366 $__git_log_shortlog_options
2367 --numbered --summary
2369 return
2371 esac
2372 __git_complete_revlist
2375 _git_show ()
2377 __git_has_doubledash && return
2379 case "$cur" in
2380 --pretty=*|--format=*)
2381 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2382 " "" "${cur#*=}"
2383 return
2385 --*)
2386 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2387 $__git_diff_common_options
2389 return
2391 esac
2392 __git_complete_file
2395 _git_show_branch ()
2397 case "$cur" in
2398 --*)
2399 __gitcomp "
2400 --all --remotes --topo-order --current --more=
2401 --list --independent --merge-base --no-name
2402 --color --no-color
2403 --sha1-name --sparse --topics --reflog
2405 return
2407 esac
2408 __git_complete_revlist
2411 _git_stash ()
2413 local save_opts='--keep-index --no-keep-index --quiet --patch'
2414 local subcommands='save list show apply clear drop pop create branch'
2415 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2416 if [ -z "$subcommand" ]; then
2417 case "$cur" in
2418 --*)
2419 __gitcomp "$save_opts"
2422 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2423 __gitcomp "$subcommands"
2424 else
2425 COMPREPLY=()
2428 esac
2429 else
2430 case "$subcommand,$cur" in
2431 save,--*)
2432 __gitcomp "$save_opts"
2434 apply,--*|pop,--*)
2435 __gitcomp "--index --quiet"
2437 show,--*|drop,--*|branch,--*)
2438 COMPREPLY=()
2440 show,*|apply,*|drop,*|pop,*|branch,*)
2441 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2442 | sed -n -e 's/:.*//p')"
2445 COMPREPLY=()
2447 esac
2451 _git_submodule ()
2453 __git_has_doubledash && return
2455 local subcommands="add status init update summary foreach sync"
2456 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2457 case "$cur" in
2458 --*)
2459 __gitcomp "--quiet --cached"
2462 __gitcomp "$subcommands"
2464 esac
2465 return
2469 _git_svn ()
2471 local subcommands="
2472 init fetch clone rebase dcommit log find-rev
2473 set-tree commit-diff info create-ignore propget
2474 proplist show-ignore show-externals branch tag blame
2475 migrate mkdirs reset gc
2477 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2478 if [ -z "$subcommand" ]; then
2479 __gitcomp "$subcommands"
2480 else
2481 local remote_opts="--username= --config-dir= --no-auth-cache"
2482 local fc_opts="
2483 --follow-parent --authors-file= --repack=
2484 --no-metadata --use-svm-props --use-svnsync-props
2485 --log-window-size= --no-checkout --quiet
2486 --repack-flags --use-log-author --localtime
2487 --ignore-paths= $remote_opts
2489 local init_opts="
2490 --template= --shared= --trunk= --tags=
2491 --branches= --stdlayout --minimize-url
2492 --no-metadata --use-svm-props --use-svnsync-props
2493 --rewrite-root= --prefix= --use-log-author
2494 --add-author-from $remote_opts
2496 local cmt_opts="
2497 --edit --rmdir --find-copies-harder --copy-similarity=
2500 case "$subcommand,$cur" in
2501 fetch,--*)
2502 __gitcomp "--revision= --fetch-all $fc_opts"
2504 clone,--*)
2505 __gitcomp "--revision= $fc_opts $init_opts"
2507 init,--*)
2508 __gitcomp "$init_opts"
2510 dcommit,--*)
2511 __gitcomp "
2512 --merge --strategy= --verbose --dry-run
2513 --fetch-all --no-rebase --commit-url
2514 --revision --interactive $cmt_opts $fc_opts
2517 set-tree,--*)
2518 __gitcomp "--stdin $cmt_opts $fc_opts"
2520 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2521 show-externals,--*|mkdirs,--*)
2522 __gitcomp "--revision="
2524 log,--*)
2525 __gitcomp "
2526 --limit= --revision= --verbose --incremental
2527 --oneline --show-commit --non-recursive
2528 --authors-file= --color
2531 rebase,--*)
2532 __gitcomp "
2533 --merge --verbose --strategy= --local
2534 --fetch-all --dry-run $fc_opts
2537 commit-diff,--*)
2538 __gitcomp "--message= --file= --revision= $cmt_opts"
2540 info,--*)
2541 __gitcomp "--url"
2543 branch,--*)
2544 __gitcomp "--dry-run --message --tag"
2546 tag,--*)
2547 __gitcomp "--dry-run --message"
2549 blame,--*)
2550 __gitcomp "--git-format"
2552 migrate,--*)
2553 __gitcomp "
2554 --config-dir= --ignore-paths= --minimize
2555 --no-auth-cache --username=
2558 reset,--*)
2559 __gitcomp "--revision= --parent"
2562 COMPREPLY=()
2564 esac
2568 _git_tag ()
2570 local i c=1 f=0
2571 while [ $c -lt $cword ]; do
2572 i="${words[c]}"
2573 case "$i" in
2574 -d|-v)
2575 __gitcomp_nl "$(__git_tags)"
2576 return
2581 esac
2582 ((c++))
2583 done
2585 case "$prev" in
2586 -m|-F)
2587 COMPREPLY=()
2589 -*|tag)
2590 if [ $f = 1 ]; then
2591 __gitcomp_nl "$(__git_tags)"
2592 else
2593 COMPREPLY=()
2597 __gitcomp_nl "$(__git_refs)"
2599 esac
2602 _git_whatchanged ()
2604 _git_log
2607 _main_git ()
2609 local i c=1 command __git_dir
2611 while [ $c -lt $cword ]; do
2612 i="${words[c]}"
2613 case "$i" in
2614 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2615 --bare) __git_dir="." ;;
2616 --help) command="help"; break ;;
2617 -c) c=$((++c)) ;;
2618 -*) ;;
2619 *) command="$i"; break ;;
2620 esac
2621 ((c++))
2622 done
2624 if [ -z "$command" ]; then
2625 case "$cur" in
2626 --*) __gitcomp "
2627 --paginate
2628 --no-pager
2629 --git-dir=
2630 --bare
2631 --version
2632 --exec-path
2633 --exec-path=
2634 --html-path
2635 --info-path
2636 --work-tree=
2637 --namespace=
2638 --no-replace-objects
2639 --help
2642 *) __git_compute_porcelain_commands
2643 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2644 esac
2645 return
2648 local completion_func="_git_${command//-/_}"
2649 declare -f $completion_func >/dev/null && $completion_func && return
2651 local expansion=$(__git_aliased_command "$command")
2652 if [ -n "$expansion" ]; then
2653 completion_func="_git_${expansion//-/_}"
2654 declare -f $completion_func >/dev/null && $completion_func
2658 _main_gitk ()
2660 __git_has_doubledash && return
2662 local g="$(__gitdir)"
2663 local merge=""
2664 if [ -f "$g/MERGE_HEAD" ]; then
2665 merge="--merge"
2667 case "$cur" in
2668 --*)
2669 __gitcomp "
2670 $__git_log_common_options
2671 $__git_log_gitk_options
2672 $merge
2674 return
2676 esac
2677 __git_complete_revlist
2680 __git_func_wrap ()
2682 if [[ -n ${ZSH_VERSION-} ]]; then
2683 emulate -L bash
2684 setopt KSH_TYPESET
2686 # workaround zsh's bug that leaves 'words' as a special
2687 # variable in versions < 4.3.12
2688 typeset -h words
2690 # workaround zsh's bug that quotes spaces in the COMPREPLY
2691 # array if IFS doesn't contain spaces.
2692 typeset -h IFS
2694 local cur words cword prev
2695 _get_comp_words_by_ref -n =: cur words cword prev
2699 # Setup completion for certain functions defined above by setting common
2700 # variables and workarounds.
2701 # This is NOT a public function; use at your own risk.
2702 __git_complete ()
2704 local wrapper="__git_wrap${2}"
2705 eval "$wrapper () { __git_func_wrap $2 ; }"
2706 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2707 || complete -o default -o nospace -F $wrapper $1
2710 # wrapper for backwards compatibility
2711 _git ()
2713 __git_wrap_main_git
2716 # wrapper for backwards compatibility
2717 _gitk ()
2719 __git_wrap_main_gitk
2722 __git_complete git _main_git
2723 __git_complete gitk _main_gitk
2725 # The following are necessary only for Cygwin, and only are needed
2726 # when the user has tab-completed the executable name and consequently
2727 # included the '.exe' suffix.
2729 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2730 __git_complete git.exe _main_git