MSVC: require pton and ntop emulation
[git/dscho.git] / contrib / completion / git-completion.bash
blobf1f67b5fc467d428eaddf42b2013d6cd92c984ab
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 # get some config options from git-config
101 local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
102 while read -r key value; do
103 case "$key" in
104 bash.showupstream)
105 GIT_PS1_SHOWUPSTREAM="$value"
106 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
107 p=""
108 return
111 svn-remote.*.url)
112 svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
113 svn_url_pattern+="\\|$value"
114 upstream=svn+git # default upstream is SVN if available, else git
116 esac
117 done <<< "$output"
119 # parse configuration values
120 for option in ${GIT_PS1_SHOWUPSTREAM}; do
121 case "$option" in
122 git|svn) upstream="$option" ;;
123 verbose) verbose=1 ;;
124 legacy) legacy=1 ;;
125 esac
126 done
128 # Find our upstream
129 case "$upstream" in
130 git) upstream="@{upstream}" ;;
131 svn*)
132 # get the upstream from the "git-svn-id: ..." in a commit message
133 # (git-svn uses essentially the same procedure internally)
134 local svn_upstream=($(git log --first-parent -1 \
135 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
136 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
137 svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
138 svn_upstream=${svn_upstream%@*}
139 local n_stop="${#svn_remote[@]}"
140 for ((n=1; n <= n_stop; n++)); do
141 svn_upstream=${svn_upstream#${svn_remote[$n]}}
142 done
144 if [[ -z "$svn_upstream" ]]; then
145 # default branch name for checkouts with no layout:
146 upstream=${GIT_SVN_ID:-git-svn}
147 else
148 upstream=${svn_upstream#/}
150 elif [[ "svn+git" = "$upstream" ]]; then
151 upstream="@{upstream}"
154 esac
156 # Find how many commits we are ahead/behind our upstream
157 if [[ -z "$legacy" ]]; then
158 count="$(git rev-list --count --left-right \
159 "$upstream"...HEAD 2>/dev/null)"
160 else
161 # produce equivalent output to --count for older versions of git
162 local commits
163 if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
164 then
165 local commit behind=0 ahead=0
166 for commit in $commits
168 case "$commit" in
169 "<"*) ((behind++)) ;;
170 *) ((ahead++)) ;;
171 esac
172 done
173 count="$behind $ahead"
174 else
175 count=""
179 # calculate the result
180 if [[ -z "$verbose" ]]; then
181 case "$count" in
182 "") # no upstream
183 p="" ;;
184 "0 0") # equal to upstream
185 p="=" ;;
186 "0 "*) # ahead of upstream
187 p=">" ;;
188 *" 0") # behind upstream
189 p="<" ;;
190 *) # diverged from upstream
191 p="<>" ;;
192 esac
193 else
194 case "$count" in
195 "") # no upstream
196 p="" ;;
197 "0 0") # equal to upstream
198 p=" u=" ;;
199 "0 "*) # ahead of upstream
200 p=" u+${count#0 }" ;;
201 *" 0") # behind upstream
202 p=" u-${count% 0}" ;;
203 *) # diverged from upstream
204 p=" u+${count#* }-${count% *}" ;;
205 esac
211 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
212 # returns text to add to bash PS1 prompt (includes branch name)
213 __git_ps1 ()
215 local g="$(__gitdir)"
216 if [ -n "$g" ]; then
217 local r=""
218 local b=""
219 if [ -f "$g/rebase-merge/interactive" ]; then
220 r="|REBASE-i"
221 b="$(cat "$g/rebase-merge/head-name")"
222 elif [ -d "$g/rebase-merge" ]; then
223 r="|REBASE-m"
224 b="$(cat "$g/rebase-merge/head-name")"
225 else
226 if [ -d "$g/rebase-apply" ]; then
227 if [ -f "$g/rebase-apply/rebasing" ]; then
228 r="|REBASE"
229 elif [ -f "$g/rebase-apply/applying" ]; then
230 r="|AM"
231 else
232 r="|AM/REBASE"
234 elif [ -f "$g/MERGE_HEAD" ]; then
235 r="|MERGING"
236 elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
237 r="|CHERRY-PICKING"
238 elif [ -f "$g/BISECT_LOG" ]; then
239 r="|BISECTING"
242 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
244 b="$(
245 case "${GIT_PS1_DESCRIBE_STYLE-}" in
246 (contains)
247 git describe --contains HEAD ;;
248 (branch)
249 git describe --contains --all HEAD ;;
250 (describe)
251 git describe HEAD ;;
252 (* | default)
253 git describe --tags --exact-match HEAD ;;
254 esac 2>/dev/null)" ||
256 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
257 b="unknown"
258 b="($b)"
262 local w=""
263 local i=""
264 local s=""
265 local u=""
266 local c=""
267 local p=""
269 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
270 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
271 c="BARE:"
272 else
273 b="GIT_DIR!"
275 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
276 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
277 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
278 git diff --no-ext-diff --quiet --exit-code || w="*"
279 if git rev-parse --quiet --verify HEAD >/dev/null; then
280 git diff-index --cached --quiet HEAD -- || i="+"
281 else
282 i="#"
286 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
287 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
290 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
291 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
292 u="%"
296 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
297 __git_ps1_show_upstream
301 local f="$w$i$s$u"
302 printf -- "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
306 # __gitcomp_1 requires 2 arguments
307 __gitcomp_1 ()
309 local c IFS=' '$'\t'$'\n'
310 for c in $1; do
311 case "$c$2" in
312 --*=*) printf %s$'\n' "$c$2" ;;
313 *.) printf %s$'\n' "$c$2" ;;
314 *) printf %s$'\n' "$c$2 " ;;
315 esac
316 done
319 # The following function is based on code from:
321 # bash_completion - programmable completion functions for bash 3.2+
323 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
324 # © 2009-2010, Bash Completion Maintainers
325 # <bash-completion-devel@lists.alioth.debian.org>
327 # This program is free software; you can redistribute it and/or modify
328 # it under the terms of the GNU General Public License as published by
329 # the Free Software Foundation; either version 2, or (at your option)
330 # any later version.
332 # This program is distributed in the hope that it will be useful,
333 # but WITHOUT ANY WARRANTY; without even the implied warranty of
334 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
335 # GNU General Public License for more details.
337 # You should have received a copy of the GNU General Public License
338 # along with this program; if not, write to the Free Software Foundation,
339 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
341 # The latest version of this software can be obtained here:
343 # http://bash-completion.alioth.debian.org/
345 # RELEASE: 2.x
347 # This function can be used to access a tokenized list of words
348 # on the command line:
350 # __git_reassemble_comp_words_by_ref '=:'
351 # if test "${words_[cword_-1]}" = -w
352 # then
353 # ...
354 # fi
356 # The argument should be a collection of characters from the list of
357 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
358 # characters.
360 # This is roughly equivalent to going back in time and setting
361 # COMP_WORDBREAKS to exclude those characters. The intent is to
362 # make option types like --date=<type> and <rev>:<path> easy to
363 # recognize by treating each shell word as a single token.
365 # It is best not to set COMP_WORDBREAKS directly because the value is
366 # shared with other completion scripts. By the time the completion
367 # function gets called, COMP_WORDS has already been populated so local
368 # changes to COMP_WORDBREAKS have no effect.
370 # Output: words_, cword_, cur_.
372 __git_reassemble_comp_words_by_ref()
374 local exclude i j first
375 # Which word separators to exclude?
376 exclude="${1//[^$COMP_WORDBREAKS]}"
377 cword_=$COMP_CWORD
378 if [ -z "$exclude" ]; then
379 words_=("${COMP_WORDS[@]}")
380 return
382 # List of word completion separators has shrunk;
383 # re-assemble words to complete.
384 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
385 # Append each nonempty word consisting of just
386 # word separator characters to the current word.
387 first=t
388 while
389 [ $i -gt 0 ] &&
390 [ -n "${COMP_WORDS[$i]}" ] &&
391 # word consists of excluded word separators
392 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
394 # Attach to the previous token,
395 # unless the previous token is the command name.
396 if [ $j -ge 2 ] && [ -n "$first" ]; then
397 ((j--))
399 first=
400 words_[$j]=${words_[j]}${COMP_WORDS[i]}
401 if [ $i = $COMP_CWORD ]; then
402 cword_=$j
404 if (($i < ${#COMP_WORDS[@]} - 1)); then
405 ((i++))
406 else
407 # Done.
408 return
410 done
411 words_[$j]=${words_[j]}${COMP_WORDS[i]}
412 if [ $i = $COMP_CWORD ]; then
413 cword_=$j
415 done
418 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
419 if [[ -z ${ZSH_VERSION:+set} ]]; then
420 _get_comp_words_by_ref ()
422 local exclude cur_ words_ cword_
423 if [ "$1" = "-n" ]; then
424 exclude=$2
425 shift 2
427 __git_reassemble_comp_words_by_ref "$exclude"
428 cur_=${words_[cword_]}
429 while [ $# -gt 0 ]; do
430 case "$1" in
431 cur)
432 cur=$cur_
434 prev)
435 prev=${words_[$cword_-1]}
437 words)
438 words=("${words_[@]}")
440 cword)
441 cword=$cword_
443 esac
444 shift
445 done
447 else
448 _get_comp_words_by_ref ()
450 while [ $# -gt 0 ]; do
451 case "$1" in
452 cur)
453 cur=${COMP_WORDS[COMP_CWORD]}
455 prev)
456 prev=${COMP_WORDS[COMP_CWORD-1]}
458 words)
459 words=("${COMP_WORDS[@]}")
461 cword)
462 cword=$COMP_CWORD
465 # assume COMP_WORDBREAKS is already set sanely
466 shift
468 esac
469 shift
470 done
475 # Generates completion reply with compgen, appending a space to possible
476 # completion words, if necessary.
477 # It accepts 1 to 4 arguments:
478 # 1: List of possible completion words.
479 # 2: A prefix to be added to each possible completion word (optional).
480 # 3: Generate possible completion matches for this word (optional).
481 # 4: A suffix to be appended to each possible completion word (optional).
482 __gitcomp ()
484 local cur_="${3-$cur}"
486 case "$cur_" in
487 --*=)
488 COMPREPLY=()
491 local IFS=$'\n'
492 COMPREPLY=($(compgen -P "${2-}" \
493 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
494 -- "$cur_"))
496 esac
499 # Generates completion reply with compgen from newline-separated possible
500 # completion words by appending a space to all of them.
501 # It accepts 1 to 4 arguments:
502 # 1: List of possible completion words, separated by a single newline.
503 # 2: A prefix to be added to each possible completion word (optional).
504 # 3: Generate possible completion matches for this word (optional).
505 # 4: A suffix to be appended to each possible completion word instead of
506 # the default space (optional). If specified but empty, nothing is
507 # appended.
508 __gitcomp_nl ()
510 local IFS=$'\n'
512 # ZSH would quote the trailing space added with -S. bash users
513 # will appreciate the extra space to compensate the use of -o nospace.
514 if [ -n "${ZSH_VERSION-}" ] && [ "$suffix" = " " ]; then
515 suffix=""
518 COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
521 __git_heads ()
523 local dir="$(__gitdir)"
524 if [ -d "$dir" ]; then
525 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
526 refs/heads
527 return
531 __git_tags ()
533 local dir="$(__gitdir)"
534 if [ -d "$dir" ]; then
535 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
536 refs/tags
537 return
541 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
542 # presence of 2nd argument means use the guess heuristic employed
543 # by checkout for tracking branches
544 __git_refs ()
546 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
547 local format refs
548 if [ -d "$dir" ]; then
549 case "$cur" in
550 refs|refs/*)
551 format="refname"
552 refs="${cur%/*}"
553 track=""
556 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
557 if [ -e "$dir/$i" ]; then echo $i; fi
558 done
559 format="refname:short"
560 refs="refs/tags refs/heads refs/remotes"
562 esac
563 git --git-dir="$dir" for-each-ref --format="%($format)" \
564 $refs
565 if [ -n "$track" ]; then
566 # employ the heuristic used by git checkout
567 # Try to find a remote branch that matches the completion word
568 # but only output if the branch name is unique
569 local ref entry
570 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
571 "refs/remotes/" | \
572 while read -r entry; do
573 eval "$entry"
574 ref="${ref#*/}"
575 if [[ "$ref" == "$cur"* ]]; then
576 echo "$ref"
578 done | uniq -u
580 return
582 case "$cur" in
583 refs|refs/*)
584 git ls-remote "$dir" "$cur*" 2>/dev/null | \
585 while read -r hash i; do
586 case "$i" in
587 *^{}) ;;
588 *) echo "$i" ;;
589 esac
590 done
593 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
594 while read -r hash i; do
595 case "$i" in
596 *^{}) ;;
597 refs/*) echo "${i#refs/*/}" ;;
598 *) echo "$i" ;;
599 esac
600 done
602 esac
605 # __git_refs2 requires 1 argument (to pass to __git_refs)
606 __git_refs2 ()
608 local i
609 for i in $(__git_refs "$1"); do
610 echo "$i:$i"
611 done
614 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
615 __git_refs_remotes ()
617 local i hash
618 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
619 while read -r hash i; do
620 echo "$i:refs/remotes/$1/${i#refs/heads/}"
621 done
624 __git_remotes ()
626 local i IFS=$'\n' d="$(__gitdir)"
627 test -d "$d/remotes" && ls -1 "$d/remotes"
628 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
629 i="${i#remote.}"
630 echo "${i/.url*/}"
631 done
634 __git_list_merge_strategies ()
636 git merge -s help 2>&1 |
637 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
638 s/\.$//
639 s/.*://
640 s/^[ ]*//
641 s/[ ]*$//
646 __git_merge_strategies=
647 # 'git merge -s help' (and thus detection of the merge strategy
648 # list) fails, unfortunately, if run outside of any git working
649 # tree. __git_merge_strategies is set to the empty string in
650 # that case, and the detection will be repeated the next time it
651 # is needed.
652 __git_compute_merge_strategies ()
654 test -n "$__git_merge_strategies" ||
655 __git_merge_strategies=$(__git_list_merge_strategies)
658 __git_complete_revlist_file ()
660 local pfx ls ref cur_="$cur"
661 case "$cur_" in
662 *..?*:*)
663 return
665 ?*:*)
666 ref="${cur_%%:*}"
667 cur_="${cur_#*:}"
668 case "$cur_" in
669 ?*/*)
670 pfx="${cur_%/*}"
671 cur_="${cur_##*/}"
672 ls="$ref:$pfx"
673 pfx="$pfx/"
676 ls="$ref"
678 esac
680 case "$COMP_WORDBREAKS" in
681 *:*) : great ;;
682 *) pfx="$ref:$pfx" ;;
683 esac
685 local IFS=$'\n'
686 COMPREPLY=($(compgen -P "$pfx" \
687 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
688 | sed '/^100... blob /{
689 s,^.* ,,
690 s,$, ,
692 /^120000 blob /{
693 s,^.* ,,
694 s,$, ,
696 /^040000 tree /{
697 s,^.* ,,
698 s,$,/,
700 s/^.* //')" \
701 -- "$cur_"))
703 *...*)
704 pfx="${cur_%...*}..."
705 cur_="${cur_#*...}"
706 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
708 *..*)
709 pfx="${cur_%..*}.."
710 cur_="${cur_#*..}"
711 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
714 __gitcomp_nl "$(__git_refs)"
716 esac
720 __git_complete_file ()
722 __git_complete_revlist_file
725 __git_complete_revlist ()
727 __git_complete_revlist_file
730 __git_complete_remote_or_refspec ()
732 local cur_="$cur" cmd="${words[1]}"
733 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
734 if [ "$cmd" = "remote" ]; then
735 ((c++))
737 while [ $c -lt $cword ]; do
738 i="${words[c]}"
739 case "$i" in
740 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
741 --all)
742 case "$cmd" in
743 push) no_complete_refspec=1 ;;
744 fetch)
745 COMPREPLY=()
746 return
748 *) ;;
749 esac
751 -*) ;;
752 *) remote="$i"; break ;;
753 esac
754 ((c++))
755 done
756 if [ -z "$remote" ]; then
757 __gitcomp_nl "$(__git_remotes)"
758 return
760 if [ $no_complete_refspec = 1 ]; then
761 COMPREPLY=()
762 return
764 [ "$remote" = "." ] && remote=
765 case "$cur_" in
766 *:*)
767 case "$COMP_WORDBREAKS" in
768 *:*) : great ;;
769 *) pfx="${cur_%%:*}:" ;;
770 esac
771 cur_="${cur_#*:}"
772 lhs=0
775 pfx="+"
776 cur_="${cur_#+}"
778 esac
779 case "$cmd" in
780 fetch)
781 if [ $lhs = 1 ]; then
782 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
783 else
784 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
787 pull|remote)
788 if [ $lhs = 1 ]; then
789 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
790 else
791 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
794 push)
795 if [ $lhs = 1 ]; then
796 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
797 else
798 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
801 esac
804 __git_complete_strategy ()
806 __git_compute_merge_strategies
807 case "$prev" in
808 -s|--strategy)
809 __gitcomp "$__git_merge_strategies"
810 return 0
811 esac
812 case "$cur" in
813 --strategy=*)
814 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
815 return 0
817 esac
818 return 1
821 __git_list_all_commands ()
823 local i IFS=" "$'\n'
824 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
826 case $i in
827 *--*) : helper pattern;;
828 *) echo $i;;
829 esac
830 done
833 __git_all_commands=
834 __git_compute_all_commands ()
836 test -n "$__git_all_commands" ||
837 __git_all_commands=$(__git_list_all_commands)
840 __git_list_porcelain_commands ()
842 local i IFS=" "$'\n'
843 __git_compute_all_commands
844 for i in "help" $__git_all_commands
846 case $i in
847 *--*) : helper pattern;;
848 applymbox) : ask gittus;;
849 applypatch) : ask gittus;;
850 archimport) : import;;
851 cat-file) : plumbing;;
852 check-attr) : plumbing;;
853 check-ref-format) : plumbing;;
854 checkout-index) : plumbing;;
855 commit-tree) : plumbing;;
856 count-objects) : infrequent;;
857 cvsexportcommit) : export;;
858 cvsimport) : import;;
859 cvsserver) : daemon;;
860 daemon) : daemon;;
861 diff-files) : plumbing;;
862 diff-index) : plumbing;;
863 diff-tree) : plumbing;;
864 fast-import) : import;;
865 fast-export) : export;;
866 fsck-objects) : plumbing;;
867 fetch-pack) : plumbing;;
868 fmt-merge-msg) : plumbing;;
869 for-each-ref) : plumbing;;
870 hash-object) : plumbing;;
871 http-*) : transport;;
872 index-pack) : plumbing;;
873 init-db) : deprecated;;
874 local-fetch) : plumbing;;
875 lost-found) : infrequent;;
876 ls-files) : plumbing;;
877 ls-remote) : plumbing;;
878 ls-tree) : plumbing;;
879 mailinfo) : plumbing;;
880 mailsplit) : plumbing;;
881 merge-*) : plumbing;;
882 mktree) : plumbing;;
883 mktag) : plumbing;;
884 pack-objects) : plumbing;;
885 pack-redundant) : plumbing;;
886 pack-refs) : plumbing;;
887 parse-remote) : plumbing;;
888 patch-id) : plumbing;;
889 peek-remote) : plumbing;;
890 prune) : plumbing;;
891 prune-packed) : plumbing;;
892 quiltimport) : import;;
893 read-tree) : plumbing;;
894 receive-pack) : plumbing;;
895 remote-*) : transport;;
896 repo-config) : deprecated;;
897 rerere) : plumbing;;
898 rev-list) : plumbing;;
899 rev-parse) : plumbing;;
900 runstatus) : plumbing;;
901 sh-setup) : internal;;
902 shell) : daemon;;
903 show-ref) : plumbing;;
904 send-pack) : plumbing;;
905 show-index) : plumbing;;
906 ssh-*) : transport;;
907 stripspace) : plumbing;;
908 symbolic-ref) : plumbing;;
909 tar-tree) : deprecated;;
910 unpack-file) : plumbing;;
911 unpack-objects) : plumbing;;
912 update-index) : plumbing;;
913 update-ref) : plumbing;;
914 update-server-info) : daemon;;
915 upload-archive) : plumbing;;
916 upload-pack) : plumbing;;
917 write-tree) : plumbing;;
918 var) : infrequent;;
919 verify-pack) : infrequent;;
920 verify-tag) : plumbing;;
921 *) echo $i;;
922 esac
923 done
926 __git_porcelain_commands=
927 __git_compute_porcelain_commands ()
929 __git_compute_all_commands
930 test -n "$__git_porcelain_commands" ||
931 __git_porcelain_commands=$(__git_list_porcelain_commands)
934 __git_pretty_aliases ()
936 local i IFS=$'\n'
937 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
938 case "$i" in
939 pretty.*)
940 i="${i#pretty.}"
941 echo "${i/ */}"
943 esac
944 done
947 __git_aliases ()
949 local i IFS=$'\n'
950 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
951 case "$i" in
952 alias.*)
953 i="${i#alias.}"
954 echo "${i/ */}"
956 esac
957 done
960 # __git_aliased_command requires 1 argument
961 __git_aliased_command ()
963 local word cmdline=$(git --git-dir="$(__gitdir)" \
964 config --get "alias.$1")
965 for word in $cmdline; do
966 case "$word" in
967 \!gitk|gitk)
968 echo "gitk"
969 return
971 \!*) : shell command alias ;;
972 -*) : option ;;
973 *=*) : setting env ;;
974 git) : git itself ;;
976 echo "$word"
977 return
978 esac
979 done
982 # __git_find_on_cmdline requires 1 argument
983 __git_find_on_cmdline ()
985 local word subcommand c=1
986 while [ $c -lt $cword ]; do
987 word="${words[c]}"
988 for subcommand in $1; do
989 if [ "$subcommand" = "$word" ]; then
990 echo "$subcommand"
991 return
993 done
994 ((c++))
995 done
998 __git_has_doubledash ()
1000 local c=1
1001 while [ $c -lt $cword ]; do
1002 if [ "--" = "${words[c]}" ]; then
1003 return 0
1005 ((c++))
1006 done
1007 return 1
1010 __git_whitespacelist="nowarn warn error error-all fix"
1012 _git_am ()
1014 local dir="$(__gitdir)"
1015 if [ -d "$dir"/rebase-apply ]; then
1016 __gitcomp "--skip --continue --resolved --abort"
1017 return
1019 case "$cur" in
1020 --whitespace=*)
1021 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1022 return
1024 --*)
1025 __gitcomp "
1026 --3way --committer-date-is-author-date --ignore-date
1027 --ignore-whitespace --ignore-space-change
1028 --interactive --keep --no-utf8 --signoff --utf8
1029 --whitespace= --scissors
1031 return
1032 esac
1033 COMPREPLY=()
1036 _git_apply ()
1038 case "$cur" in
1039 --whitespace=*)
1040 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1041 return
1043 --*)
1044 __gitcomp "
1045 --stat --numstat --summary --check --index
1046 --cached --index-info --reverse --reject --unidiff-zero
1047 --apply --no-add --exclude=
1048 --ignore-whitespace --ignore-space-change
1049 --whitespace= --inaccurate-eof --verbose
1051 return
1052 esac
1053 COMPREPLY=()
1056 _git_add ()
1058 __git_has_doubledash && return
1060 case "$cur" in
1061 --*)
1062 __gitcomp "
1063 --interactive --refresh --patch --update --dry-run
1064 --ignore-errors --intent-to-add
1066 return
1067 esac
1068 COMPREPLY=()
1071 _git_archive ()
1073 case "$cur" in
1074 --format=*)
1075 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1076 return
1078 --remote=*)
1079 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1080 return
1082 --*)
1083 __gitcomp "
1084 --format= --list --verbose
1085 --prefix= --remote= --exec=
1087 return
1089 esac
1090 __git_complete_file
1093 _git_bisect ()
1095 __git_has_doubledash && return
1097 local subcommands="start bad good skip reset visualize replay log run"
1098 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1099 if [ -z "$subcommand" ]; then
1100 if [ -f "$(__gitdir)"/BISECT_START ]; then
1101 __gitcomp "$subcommands"
1102 else
1103 __gitcomp "replay start"
1105 return
1108 case "$subcommand" in
1109 bad|good|reset|skip|start)
1110 __gitcomp_nl "$(__git_refs)"
1113 COMPREPLY=()
1115 esac
1118 _git_branch ()
1120 local i c=1 only_local_ref="n" has_r="n"
1122 while [ $c -lt $cword ]; do
1123 i="${words[c]}"
1124 case "$i" in
1125 -d|-m) only_local_ref="y" ;;
1126 -r) has_r="y" ;;
1127 esac
1128 ((c++))
1129 done
1131 case "$cur" in
1132 --*)
1133 __gitcomp "
1134 --color --no-color --verbose --abbrev= --no-abbrev
1135 --track --no-track --contains --merged --no-merged
1136 --set-upstream --edit-description --list
1140 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1141 __gitcomp_nl "$(__git_heads)"
1142 else
1143 __gitcomp_nl "$(__git_refs)"
1146 esac
1149 _git_bundle ()
1151 local cmd="${words[2]}"
1152 case "$cword" in
1154 __gitcomp "create list-heads verify unbundle"
1157 # looking for a file
1160 case "$cmd" in
1161 create)
1162 __git_complete_revlist
1164 esac
1166 esac
1169 _git_checkout ()
1171 __git_has_doubledash && return
1173 case "$cur" in
1174 --conflict=*)
1175 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1177 --*)
1178 __gitcomp "
1179 --quiet --ours --theirs --track --no-track --merge
1180 --conflict= --orphan --patch
1184 # check if --track, --no-track, or --no-guess was specified
1185 # if so, disable DWIM mode
1186 local flags="--track --no-track --no-guess" track=1
1187 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1188 track=''
1190 __gitcomp_nl "$(__git_refs '' $track)"
1192 esac
1195 _git_cherry ()
1197 __gitcomp "$(__git_refs)"
1200 _git_cherry_pick ()
1202 case "$cur" in
1203 --*)
1204 __gitcomp "--edit --no-commit"
1207 __gitcomp_nl "$(__git_refs)"
1209 esac
1212 _git_clean ()
1214 __git_has_doubledash && return
1216 case "$cur" in
1217 --*)
1218 __gitcomp "--dry-run --quiet"
1219 return
1221 esac
1222 COMPREPLY=()
1225 _git_clone ()
1227 case "$cur" in
1228 --*)
1229 __gitcomp "
1230 --local
1231 --no-hardlinks
1232 --shared
1233 --reference
1234 --quiet
1235 --no-checkout
1236 --bare
1237 --mirror
1238 --origin
1239 --upload-pack
1240 --template=
1241 --depth
1243 return
1245 esac
1246 COMPREPLY=()
1249 _git_commit ()
1251 __git_has_doubledash && return
1253 case "$cur" in
1254 --cleanup=*)
1255 __gitcomp "default strip verbatim whitespace
1256 " "" "${cur##--cleanup=}"
1257 return
1259 --reuse-message=*|--reedit-message=*|\
1260 --fixup=*|--squash=*)
1261 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1262 return
1264 --untracked-files=*)
1265 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1266 return
1268 --*)
1269 __gitcomp "
1270 --all --author= --signoff --verify --no-verify
1271 --edit --amend --include --only --interactive
1272 --dry-run --reuse-message= --reedit-message=
1273 --reset-author --file= --message= --template=
1274 --cleanup= --untracked-files --untracked-files=
1275 --verbose --quiet --fixup= --squash=
1277 return
1278 esac
1279 COMPREPLY=()
1282 _git_describe ()
1284 case "$cur" in
1285 --*)
1286 __gitcomp "
1287 --all --tags --contains --abbrev= --candidates=
1288 --exact-match --debug --long --match --always
1290 return
1291 esac
1292 __gitcomp_nl "$(__git_refs)"
1295 __git_diff_common_options="--stat --numstat --shortstat --summary
1296 --patch-with-stat --name-only --name-status --color
1297 --no-color --color-words --no-renames --check
1298 --full-index --binary --abbrev --diff-filter=
1299 --find-copies-harder
1300 --text --ignore-space-at-eol --ignore-space-change
1301 --ignore-all-space --exit-code --quiet --ext-diff
1302 --no-ext-diff
1303 --no-prefix --src-prefix= --dst-prefix=
1304 --inter-hunk-context=
1305 --patience
1306 --raw
1307 --dirstat --dirstat= --dirstat-by-file
1308 --dirstat-by-file= --cumulative
1311 _git_diff ()
1313 __git_has_doubledash && return
1315 case "$cur" in
1316 --*)
1317 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1318 --base --ours --theirs --no-index
1319 $__git_diff_common_options
1321 return
1323 esac
1324 __git_complete_revlist_file
1327 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1328 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
1331 _git_difftool ()
1333 __git_has_doubledash && return
1335 case "$cur" in
1336 --tool=*)
1337 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1338 return
1340 --*)
1341 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1342 --base --ours --theirs
1343 --no-renames --diff-filter= --find-copies-harder
1344 --relative --ignore-submodules
1345 --tool="
1346 return
1348 esac
1349 __git_complete_file
1352 __git_fetch_options="
1353 --quiet --verbose --append --upload-pack --force --keep --depth=
1354 --tags --no-tags --all --prune --dry-run
1357 _git_fetch ()
1359 case "$cur" in
1360 --*)
1361 __gitcomp "$__git_fetch_options"
1362 return
1364 esac
1365 __git_complete_remote_or_refspec
1368 _git_format_patch ()
1370 case "$cur" in
1371 --thread=*)
1372 __gitcomp "
1373 deep shallow
1374 " "" "${cur##--thread=}"
1375 return
1377 --*)
1378 __gitcomp "
1379 --stdout --attach --no-attach --thread --thread=
1380 --output-directory
1381 --numbered --start-number
1382 --numbered-files
1383 --keep-subject
1384 --signoff --signature --no-signature
1385 --in-reply-to= --cc=
1386 --full-index --binary
1387 --not --all
1388 --cover-letter
1389 --no-prefix --src-prefix= --dst-prefix=
1390 --inline --suffix= --ignore-if-in-upstream
1391 --subject-prefix=
1393 return
1395 esac
1396 __git_complete_revlist
1399 _git_fsck ()
1401 case "$cur" in
1402 --*)
1403 __gitcomp "
1404 --tags --root --unreachable --cache --no-reflogs --full
1405 --strict --verbose --lost-found
1407 return
1409 esac
1410 COMPREPLY=()
1413 _git_gc ()
1415 case "$cur" in
1416 --*)
1417 __gitcomp "--prune --aggressive"
1418 return
1420 esac
1421 COMPREPLY=()
1424 _git_gitk ()
1426 _gitk
1429 __git_match_ctag() {
1430 awk "/^${1////\\/}/ { print \$1 }" "$2"
1433 _git_grep ()
1435 __git_has_doubledash && return
1437 case "$cur" in
1438 --*)
1439 __gitcomp "
1440 --cached
1441 --text --ignore-case --word-regexp --invert-match
1442 --full-name --line-number
1443 --extended-regexp --basic-regexp --fixed-strings
1444 --perl-regexp
1445 --files-with-matches --name-only
1446 --files-without-match
1447 --max-depth
1448 --count
1449 --and --or --not --all-match
1451 return
1453 esac
1455 case "$cword,$prev" in
1456 2,*|*,-*)
1457 if test -r tags; then
1458 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1459 return
1462 esac
1464 __gitcomp_nl "$(__git_refs)"
1467 _git_help ()
1469 case "$cur" in
1470 --*)
1471 __gitcomp "--all --info --man --web"
1472 return
1474 esac
1475 __git_compute_all_commands
1476 __gitcomp "$__git_all_commands $(__git_aliases)
1477 attributes cli core-tutorial cvs-migration
1478 diffcore gitk glossary hooks ignore modules
1479 namespaces repository-layout tutorial tutorial-2
1480 workflows
1484 _git_init ()
1486 case "$cur" in
1487 --shared=*)
1488 __gitcomp "
1489 false true umask group all world everybody
1490 " "" "${cur##--shared=}"
1491 return
1493 --*)
1494 __gitcomp "--quiet --bare --template= --shared --shared="
1495 return
1497 esac
1498 COMPREPLY=()
1501 _git_ls_files ()
1503 __git_has_doubledash && return
1505 case "$cur" in
1506 --*)
1507 __gitcomp "--cached --deleted --modified --others --ignored
1508 --stage --directory --no-empty-directory --unmerged
1509 --killed --exclude= --exclude-from=
1510 --exclude-per-directory= --exclude-standard
1511 --error-unmatch --with-tree= --full-name
1512 --abbrev --ignored --exclude-per-directory
1514 return
1516 esac
1517 COMPREPLY=()
1520 _git_ls_remote ()
1522 __gitcomp_nl "$(__git_remotes)"
1525 _git_ls_tree ()
1527 __git_complete_file
1530 # Options that go well for log, shortlog and gitk
1531 __git_log_common_options="
1532 --not --all
1533 --branches --tags --remotes
1534 --first-parent --merges --no-merges
1535 --max-count=
1536 --max-age= --since= --after=
1537 --min-age= --until= --before=
1538 --min-parents= --max-parents=
1539 --no-min-parents --no-max-parents
1541 # Options that go well for log and gitk (not shortlog)
1542 __git_log_gitk_options="
1543 --dense --sparse --full-history
1544 --simplify-merges --simplify-by-decoration
1545 --left-right --notes --no-notes
1547 # Options that go well for log and shortlog (not gitk)
1548 __git_log_shortlog_options="
1549 --author= --committer= --grep=
1550 --all-match
1553 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1554 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1556 _git_log ()
1558 __git_has_doubledash && return
1560 local g="$(git rev-parse --git-dir 2>/dev/null)"
1561 local merge=""
1562 if [ -f "$g/MERGE_HEAD" ]; then
1563 merge="--merge"
1565 case "$cur" in
1566 --pretty=*|--format=*)
1567 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1568 " "" "${cur#*=}"
1569 return
1571 --date=*)
1572 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1573 return
1575 --decorate=*)
1576 __gitcomp "long short" "" "${cur##--decorate=}"
1577 return
1579 --*)
1580 __gitcomp "
1581 $__git_log_common_options
1582 $__git_log_shortlog_options
1583 $__git_log_gitk_options
1584 --root --topo-order --date-order --reverse
1585 --follow --full-diff
1586 --abbrev-commit --abbrev=
1587 --relative-date --date=
1588 --pretty= --format= --oneline
1589 --cherry-pick
1590 --graph
1591 --decorate --decorate=
1592 --walk-reflogs
1593 --parents --children
1594 $merge
1595 $__git_diff_common_options
1596 --pickaxe-all --pickaxe-regex
1598 return
1600 esac
1601 __git_complete_revlist
1604 __git_merge_options="
1605 --no-commit --no-stat --log --no-log --squash --strategy
1606 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1609 _git_merge ()
1611 __git_complete_strategy && return
1613 case "$cur" in
1614 --*)
1615 __gitcomp "$__git_merge_options"
1616 return
1617 esac
1618 __gitcomp_nl "$(__git_refs)"
1621 _git_mergetool ()
1623 case "$cur" in
1624 --tool=*)
1625 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1626 return
1628 --*)
1629 __gitcomp "--tool="
1630 return
1632 esac
1633 COMPREPLY=()
1636 _git_merge_base ()
1638 __gitcomp_nl "$(__git_refs)"
1641 _git_mv ()
1643 case "$cur" in
1644 --*)
1645 __gitcomp "--dry-run"
1646 return
1648 esac
1649 COMPREPLY=()
1652 _git_name_rev ()
1654 __gitcomp "--tags --all --stdin"
1657 _git_notes ()
1659 local subcommands='add append copy edit list prune remove show'
1660 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1662 case "$subcommand,$cur" in
1663 ,--*)
1664 __gitcomp '--ref'
1667 case "${words[cword-1]}" in
1668 --ref)
1669 __gitcomp_nl "$(__git_refs)"
1672 __gitcomp "$subcommands --ref"
1674 esac
1676 add,--reuse-message=*|append,--reuse-message=*|\
1677 add,--reedit-message=*|append,--reedit-message=*)
1678 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1680 add,--*|append,--*)
1681 __gitcomp '--file= --message= --reedit-message=
1682 --reuse-message='
1684 copy,--*)
1685 __gitcomp '--stdin'
1687 prune,--*)
1688 __gitcomp '--dry-run --verbose'
1690 prune,*)
1693 case "${words[cword-1]}" in
1694 -m|-F)
1697 __gitcomp_nl "$(__git_refs)"
1699 esac
1701 esac
1704 _git_pull ()
1706 __git_complete_strategy && return
1708 case "$cur" in
1709 --*)
1710 __gitcomp "
1711 --rebase --no-rebase
1712 $__git_merge_options
1713 $__git_fetch_options
1715 return
1717 esac
1718 __git_complete_remote_or_refspec
1721 _git_push ()
1723 case "$prev" in
1724 --repo)
1725 __gitcomp_nl "$(__git_remotes)"
1726 return
1727 esac
1728 case "$cur" in
1729 --repo=*)
1730 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1731 return
1733 --*)
1734 __gitcomp "
1735 --all --mirror --tags --dry-run --force --verbose
1736 --receive-pack= --repo= --set-upstream
1738 return
1740 esac
1741 __git_complete_remote_or_refspec
1744 _git_rebase ()
1746 local dir="$(__gitdir)"
1747 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1748 __gitcomp "--continue --skip --abort"
1749 return
1751 __git_complete_strategy && return
1752 case "$cur" in
1753 --whitespace=*)
1754 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1755 return
1757 --*)
1758 __gitcomp "
1759 --onto --merge --strategy --interactive
1760 --preserve-merges --stat --no-stat
1761 --committer-date-is-author-date --ignore-date
1762 --ignore-whitespace --whitespace=
1763 --autosquash
1766 return
1767 esac
1768 __gitcomp_nl "$(__git_refs)"
1771 _git_reflog ()
1773 local subcommands="show delete expire"
1774 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1776 if [ -z "$subcommand" ]; then
1777 __gitcomp "$subcommands"
1778 else
1779 __gitcomp_nl "$(__git_refs)"
1783 __git_send_email_confirm_options="always never auto cc compose"
1784 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1786 _git_send_email ()
1788 case "$cur" in
1789 --confirm=*)
1790 __gitcomp "
1791 $__git_send_email_confirm_options
1792 " "" "${cur##--confirm=}"
1793 return
1795 --suppress-cc=*)
1796 __gitcomp "
1797 $__git_send_email_suppresscc_options
1798 " "" "${cur##--suppress-cc=}"
1800 return
1802 --smtp-encryption=*)
1803 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1804 return
1806 --*)
1807 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1808 --compose --confirm= --dry-run --envelope-sender
1809 --from --identity
1810 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1811 --no-suppress-from --no-thread --quiet
1812 --signed-off-by-cc --smtp-pass --smtp-server
1813 --smtp-server-port --smtp-encryption= --smtp-user
1814 --subject --suppress-cc= --suppress-from --thread --to
1815 --validate --no-validate"
1816 return
1818 esac
1819 COMPREPLY=()
1822 _git_stage ()
1824 _git_add
1827 __git_config_get_set_variables ()
1829 local prevword word config_file= c=$cword
1830 while [ $c -gt 1 ]; do
1831 word="${words[c]}"
1832 case "$word" in
1833 --global|--system|--file=*)
1834 config_file="$word"
1835 break
1837 -f|--file)
1838 config_file="$word $prevword"
1839 break
1841 esac
1842 prevword=$word
1843 c=$((--c))
1844 done
1846 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1847 while read -r line
1849 case "$line" in
1850 *.*=*)
1851 echo "${line/=*/}"
1853 esac
1854 done
1857 _git_config ()
1859 case "$prev" in
1860 branch.*.remote)
1861 __gitcomp_nl "$(__git_remotes)"
1862 return
1864 branch.*.merge)
1865 __gitcomp_nl "$(__git_refs)"
1866 return
1868 remote.*.fetch)
1869 local remote="${prev#remote.}"
1870 remote="${remote%.fetch}"
1871 if [ -z "$cur" ]; then
1872 COMPREPLY=("refs/heads/")
1873 return
1875 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1876 return
1878 remote.*.push)
1879 local remote="${prev#remote.}"
1880 remote="${remote%.push}"
1881 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1882 for-each-ref --format='%(refname):%(refname)' \
1883 refs/heads)"
1884 return
1886 pull.twohead|pull.octopus)
1887 __git_compute_merge_strategies
1888 __gitcomp "$__git_merge_strategies"
1889 return
1891 color.branch|color.diff|color.interactive|\
1892 color.showbranch|color.status|color.ui)
1893 __gitcomp "always never auto"
1894 return
1896 color.pager)
1897 __gitcomp "false true"
1898 return
1900 color.*.*)
1901 __gitcomp "
1902 normal black red green yellow blue magenta cyan white
1903 bold dim ul blink reverse
1905 return
1907 help.format)
1908 __gitcomp "man info web html"
1909 return
1911 log.date)
1912 __gitcomp "$__git_log_date_formats"
1913 return
1915 sendemail.aliasesfiletype)
1916 __gitcomp "mutt mailrc pine elm gnus"
1917 return
1919 sendemail.confirm)
1920 __gitcomp "$__git_send_email_confirm_options"
1921 return
1923 sendemail.suppresscc)
1924 __gitcomp "$__git_send_email_suppresscc_options"
1925 return
1927 --get|--get-all|--unset|--unset-all)
1928 __gitcomp_nl "$(__git_config_get_set_variables)"
1929 return
1931 *.*)
1932 COMPREPLY=()
1933 return
1935 esac
1936 case "$cur" in
1937 --*)
1938 __gitcomp "
1939 --global --system --file=
1940 --list --replace-all
1941 --get --get-all --get-regexp
1942 --add --unset --unset-all
1943 --remove-section --rename-section
1945 return
1947 branch.*.*)
1948 local pfx="${cur%.*}." cur_="${cur##*.}"
1949 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1950 return
1952 branch.*)
1953 local pfx="${cur%.*}." cur_="${cur#*.}"
1954 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1955 return
1957 guitool.*.*)
1958 local pfx="${cur%.*}." cur_="${cur##*.}"
1959 __gitcomp "
1960 argprompt cmd confirm needsfile noconsole norescan
1961 prompt revprompt revunmerged title
1962 " "$pfx" "$cur_"
1963 return
1965 difftool.*.*)
1966 local pfx="${cur%.*}." cur_="${cur##*.}"
1967 __gitcomp "cmd path" "$pfx" "$cur_"
1968 return
1970 man.*.*)
1971 local pfx="${cur%.*}." cur_="${cur##*.}"
1972 __gitcomp "cmd path" "$pfx" "$cur_"
1973 return
1975 mergetool.*.*)
1976 local pfx="${cur%.*}." cur_="${cur##*.}"
1977 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1978 return
1980 pager.*)
1981 local pfx="${cur%.*}." cur_="${cur#*.}"
1982 __git_compute_all_commands
1983 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1984 return
1986 remote.*.*)
1987 local pfx="${cur%.*}." cur_="${cur##*.}"
1988 __gitcomp "
1989 url proxy fetch push mirror skipDefaultUpdate
1990 receivepack uploadpack tagopt pushurl
1991 " "$pfx" "$cur_"
1992 return
1994 remote.*)
1995 local pfx="${cur%.*}." cur_="${cur#*.}"
1996 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1997 return
1999 url.*.*)
2000 local pfx="${cur%.*}." cur_="${cur##*.}"
2001 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2002 return
2004 esac
2005 __gitcomp "
2006 add.ignoreErrors
2007 advice.commitBeforeMerge
2008 advice.detachedHead
2009 advice.implicitIdentity
2010 advice.pushNonFastForward
2011 advice.resolveConflict
2012 advice.statusHints
2013 alias.
2014 am.keepcr
2015 apply.ignorewhitespace
2016 apply.whitespace
2017 branch.autosetupmerge
2018 branch.autosetuprebase
2019 browser.
2020 clean.requireForce
2021 color.branch
2022 color.branch.current
2023 color.branch.local
2024 color.branch.plain
2025 color.branch.remote
2026 color.decorate.HEAD
2027 color.decorate.branch
2028 color.decorate.remoteBranch
2029 color.decorate.stash
2030 color.decorate.tag
2031 color.diff
2032 color.diff.commit
2033 color.diff.frag
2034 color.diff.func
2035 color.diff.meta
2036 color.diff.new
2037 color.diff.old
2038 color.diff.plain
2039 color.diff.whitespace
2040 color.grep
2041 color.grep.context
2042 color.grep.filename
2043 color.grep.function
2044 color.grep.linenumber
2045 color.grep.match
2046 color.grep.selected
2047 color.grep.separator
2048 color.interactive
2049 color.interactive.error
2050 color.interactive.header
2051 color.interactive.help
2052 color.interactive.prompt
2053 color.pager
2054 color.showbranch
2055 color.status
2056 color.status.added
2057 color.status.changed
2058 color.status.header
2059 color.status.nobranch
2060 color.status.untracked
2061 color.status.updated
2062 color.ui
2063 commit.status
2064 commit.template
2065 core.abbrev
2066 core.askpass
2067 core.attributesfile
2068 core.autocrlf
2069 core.bare
2070 core.bigFileThreshold
2071 core.compression
2072 core.createObject
2073 core.deltaBaseCacheLimit
2074 core.editor
2075 core.eol
2076 core.excludesfile
2077 core.fileMode
2078 core.fsyncobjectfiles
2079 core.gitProxy
2080 core.ignoreCygwinFSTricks
2081 core.ignoreStat
2082 core.ignorecase
2083 core.logAllRefUpdates
2084 core.loosecompression
2085 core.notesRef
2086 core.packedGitLimit
2087 core.packedGitWindowSize
2088 core.pager
2089 core.preferSymlinkRefs
2090 core.preloadindex
2091 core.quotepath
2092 core.repositoryFormatVersion
2093 core.safecrlf
2094 core.sharedRepository
2095 core.sparseCheckout
2096 core.symlinks
2097 core.trustctime
2098 core.warnAmbiguousRefs
2099 core.whitespace
2100 core.worktree
2101 diff.autorefreshindex
2102 diff.statGraphWidth
2103 diff.external
2104 diff.ignoreSubmodules
2105 diff.mnemonicprefix
2106 diff.noprefix
2107 diff.renameLimit
2108 diff.renames
2109 diff.suppressBlankEmpty
2110 diff.tool
2111 diff.wordRegex
2112 difftool.
2113 difftool.prompt
2114 fetch.recurseSubmodules
2115 fetch.unpackLimit
2116 format.attach
2117 format.cc
2118 format.headers
2119 format.numbered
2120 format.pretty
2121 format.signature
2122 format.signoff
2123 format.subjectprefix
2124 format.suffix
2125 format.thread
2126 format.to
2128 gc.aggressiveWindow
2129 gc.auto
2130 gc.autopacklimit
2131 gc.packrefs
2132 gc.pruneexpire
2133 gc.reflogexpire
2134 gc.reflogexpireunreachable
2135 gc.rerereresolved
2136 gc.rerereunresolved
2137 gitcvs.allbinary
2138 gitcvs.commitmsgannotation
2139 gitcvs.dbTableNamePrefix
2140 gitcvs.dbdriver
2141 gitcvs.dbname
2142 gitcvs.dbpass
2143 gitcvs.dbuser
2144 gitcvs.enabled
2145 gitcvs.logfile
2146 gitcvs.usecrlfattr
2147 guitool.
2148 gui.blamehistoryctx
2149 gui.commitmsgwidth
2150 gui.copyblamethreshold
2151 gui.diffcontext
2152 gui.encoding
2153 gui.fastcopyblame
2154 gui.matchtrackingbranch
2155 gui.newbranchtemplate
2156 gui.pruneduringfetch
2157 gui.spellingdictionary
2158 gui.trustmtime
2159 help.autocorrect
2160 help.browser
2161 help.format
2162 http.lowSpeedLimit
2163 http.lowSpeedTime
2164 http.maxRequests
2165 http.minSessions
2166 http.noEPSV
2167 http.postBuffer
2168 http.proxy
2169 http.sslCAInfo
2170 http.sslCAPath
2171 http.sslCert
2172 http.sslCertPasswordProtected
2173 http.sslKey
2174 http.sslVerify
2175 http.useragent
2176 i18n.commitEncoding
2177 i18n.logOutputEncoding
2178 imap.authMethod
2179 imap.folder
2180 imap.host
2181 imap.pass
2182 imap.port
2183 imap.preformattedHTML
2184 imap.sslverify
2185 imap.tunnel
2186 imap.user
2187 init.templatedir
2188 instaweb.browser
2189 instaweb.httpd
2190 instaweb.local
2191 instaweb.modulepath
2192 instaweb.port
2193 interactive.singlekey
2194 log.date
2195 log.decorate
2196 log.showroot
2197 mailmap.file
2198 man.
2199 man.viewer
2200 merge.
2201 merge.conflictstyle
2202 merge.log
2203 merge.renameLimit
2204 merge.renormalize
2205 merge.stat
2206 merge.tool
2207 merge.verbosity
2208 mergetool.
2209 mergetool.keepBackup
2210 mergetool.keepTemporaries
2211 mergetool.prompt
2212 notes.displayRef
2213 notes.rewrite.
2214 notes.rewrite.amend
2215 notes.rewrite.rebase
2216 notes.rewriteMode
2217 notes.rewriteRef
2218 pack.compression
2219 pack.deltaCacheLimit
2220 pack.deltaCacheSize
2221 pack.depth
2222 pack.indexVersion
2223 pack.packSizeLimit
2224 pack.threads
2225 pack.window
2226 pack.windowMemory
2227 pager.
2228 pretty.
2229 pull.octopus
2230 pull.twohead
2231 push.default
2232 rebase.autosquash
2233 rebase.stat
2234 receive.autogc
2235 receive.denyCurrentBranch
2236 receive.denyDeleteCurrent
2237 receive.denyDeletes
2238 receive.denyNonFastForwards
2239 receive.fsckObjects
2240 receive.unpackLimit
2241 receive.updateserverinfo
2242 remotes.
2243 repack.usedeltabaseoffset
2244 rerere.autoupdate
2245 rerere.enabled
2246 sendemail.
2247 sendemail.aliasesfile
2248 sendemail.aliasfiletype
2249 sendemail.bcc
2250 sendemail.cc
2251 sendemail.cccmd
2252 sendemail.chainreplyto
2253 sendemail.confirm
2254 sendemail.envelopesender
2255 sendemail.from
2256 sendemail.identity
2257 sendemail.multiedit
2258 sendemail.signedoffbycc
2259 sendemail.smtpdomain
2260 sendemail.smtpencryption
2261 sendemail.smtppass
2262 sendemail.smtpserver
2263 sendemail.smtpserveroption
2264 sendemail.smtpserverport
2265 sendemail.smtpuser
2266 sendemail.suppresscc
2267 sendemail.suppressfrom
2268 sendemail.thread
2269 sendemail.to
2270 sendemail.validate
2271 showbranch.default
2272 status.relativePaths
2273 status.showUntrackedFiles
2274 status.submodulesummary
2275 submodule.
2276 tar.umask
2277 transfer.unpackLimit
2278 url.
2279 user.email
2280 user.name
2281 user.signingkey
2282 web.browser
2283 branch. remote.
2287 _git_remote ()
2289 local subcommands="add rename rm set-head set-branches set-url show prune update"
2290 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2291 if [ -z "$subcommand" ]; then
2292 __gitcomp "$subcommands"
2293 return
2296 case "$subcommand" in
2297 rename|rm|set-url|show|prune)
2298 __gitcomp_nl "$(__git_remotes)"
2300 set-head|set-branches)
2301 __git_complete_remote_or_refspec
2303 update)
2304 local i c='' IFS=$'\n'
2305 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2306 i="${i#remotes.}"
2307 c="$c ${i/ */}"
2308 done
2309 __gitcomp "$c"
2312 COMPREPLY=()
2314 esac
2317 _git_replace ()
2319 __gitcomp_nl "$(__git_refs)"
2322 _git_reset ()
2324 __git_has_doubledash && return
2326 case "$cur" in
2327 --*)
2328 __gitcomp "--merge --mixed --hard --soft --patch"
2329 return
2331 esac
2332 __gitcomp_nl "$(__git_refs)"
2335 _git_revert ()
2337 case "$cur" in
2338 --*)
2339 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2340 return
2342 esac
2343 __gitcomp_nl "$(__git_refs)"
2346 _git_rm ()
2348 __git_has_doubledash && return
2350 case "$cur" in
2351 --*)
2352 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2353 return
2355 esac
2356 COMPREPLY=()
2359 _git_shortlog ()
2361 __git_has_doubledash && return
2363 case "$cur" in
2364 --*)
2365 __gitcomp "
2366 $__git_log_common_options
2367 $__git_log_shortlog_options
2368 --numbered --summary
2370 return
2372 esac
2373 __git_complete_revlist
2376 _git_show ()
2378 __git_has_doubledash && return
2380 case "$cur" in
2381 --pretty=*|--format=*)
2382 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2383 " "" "${cur#*=}"
2384 return
2386 --*)
2387 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2388 $__git_diff_common_options
2390 return
2392 esac
2393 __git_complete_file
2396 _git_show_branch ()
2398 case "$cur" in
2399 --*)
2400 __gitcomp "
2401 --all --remotes --topo-order --current --more=
2402 --list --independent --merge-base --no-name
2403 --color --no-color
2404 --sha1-name --sparse --topics --reflog
2406 return
2408 esac
2409 __git_complete_revlist
2412 _git_stash ()
2414 local save_opts='--keep-index --no-keep-index --quiet --patch'
2415 local subcommands='save list show apply clear drop pop create branch'
2416 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2417 if [ -z "$subcommand" ]; then
2418 case "$cur" in
2419 --*)
2420 __gitcomp "$save_opts"
2423 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2424 __gitcomp "$subcommands"
2425 else
2426 COMPREPLY=()
2429 esac
2430 else
2431 case "$subcommand,$cur" in
2432 save,--*)
2433 __gitcomp "$save_opts"
2435 apply,--*|pop,--*)
2436 __gitcomp "--index --quiet"
2438 show,--*|drop,--*|branch,--*)
2439 COMPREPLY=()
2441 show,*|apply,*|drop,*|pop,*|branch,*)
2442 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2443 | sed -n -e 's/:.*//p')"
2446 COMPREPLY=()
2448 esac
2452 _git_submodule ()
2454 __git_has_doubledash && return
2456 local subcommands="add status init update summary foreach sync"
2457 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2458 case "$cur" in
2459 --*)
2460 __gitcomp "--quiet --cached"
2463 __gitcomp "$subcommands"
2465 esac
2466 return
2470 _git_svn ()
2472 local subcommands="
2473 init fetch clone rebase dcommit log find-rev
2474 set-tree commit-diff info create-ignore propget
2475 proplist show-ignore show-externals branch tag blame
2476 migrate mkdirs reset gc
2478 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2479 if [ -z "$subcommand" ]; then
2480 __gitcomp "$subcommands"
2481 else
2482 local remote_opts="--username= --config-dir= --no-auth-cache"
2483 local fc_opts="
2484 --follow-parent --authors-file= --repack=
2485 --no-metadata --use-svm-props --use-svnsync-props
2486 --log-window-size= --no-checkout --quiet
2487 --repack-flags --use-log-author --localtime
2488 --ignore-paths= $remote_opts
2490 local init_opts="
2491 --template= --shared= --trunk= --tags=
2492 --branches= --stdlayout --minimize-url
2493 --no-metadata --use-svm-props --use-svnsync-props
2494 --rewrite-root= --prefix= --use-log-author
2495 --add-author-from $remote_opts
2497 local cmt_opts="
2498 --edit --rmdir --find-copies-harder --copy-similarity=
2501 case "$subcommand,$cur" in
2502 fetch,--*)
2503 __gitcomp "--revision= --fetch-all $fc_opts"
2505 clone,--*)
2506 __gitcomp "--revision= $fc_opts $init_opts"
2508 init,--*)
2509 __gitcomp "$init_opts"
2511 dcommit,--*)
2512 __gitcomp "
2513 --merge --strategy= --verbose --dry-run
2514 --fetch-all --no-rebase --commit-url
2515 --revision --interactive $cmt_opts $fc_opts
2518 set-tree,--*)
2519 __gitcomp "--stdin $cmt_opts $fc_opts"
2521 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2522 show-externals,--*|mkdirs,--*)
2523 __gitcomp "--revision="
2525 log,--*)
2526 __gitcomp "
2527 --limit= --revision= --verbose --incremental
2528 --oneline --show-commit --non-recursive
2529 --authors-file= --color
2532 rebase,--*)
2533 __gitcomp "
2534 --merge --verbose --strategy= --local
2535 --fetch-all --dry-run $fc_opts
2538 commit-diff,--*)
2539 __gitcomp "--message= --file= --revision= $cmt_opts"
2541 info,--*)
2542 __gitcomp "--url"
2544 branch,--*)
2545 __gitcomp "--dry-run --message --tag"
2547 tag,--*)
2548 __gitcomp "--dry-run --message"
2550 blame,--*)
2551 __gitcomp "--git-format"
2553 migrate,--*)
2554 __gitcomp "
2555 --config-dir= --ignore-paths= --minimize
2556 --no-auth-cache --username=
2559 reset,--*)
2560 __gitcomp "--revision= --parent"
2563 COMPREPLY=()
2565 esac
2569 _git_tag ()
2571 local i c=1 f=0
2572 while [ $c -lt $cword ]; do
2573 i="${words[c]}"
2574 case "$i" in
2575 -d|-v)
2576 __gitcomp_nl "$(__git_tags)"
2577 return
2582 esac
2583 ((c++))
2584 done
2586 case "$prev" in
2587 -m|-F)
2588 COMPREPLY=()
2590 -*|tag)
2591 if [ $f = 1 ]; then
2592 __gitcomp_nl "$(__git_tags)"
2593 else
2594 COMPREPLY=()
2598 __gitcomp_nl "$(__git_refs)"
2600 esac
2603 _git_whatchanged ()
2605 _git_log
2608 _git ()
2610 local i c=1 command __git_dir
2612 if [[ -n ${ZSH_VERSION-} ]]; then
2613 emulate -L bash
2614 setopt KSH_TYPESET
2616 # workaround zsh's bug that leaves 'words' as a special
2617 # variable in versions < 4.3.12
2618 typeset -h words
2620 # workaround zsh's bug that quotes spaces in the COMPREPLY
2621 # array if IFS doesn't contain spaces.
2622 typeset -h IFS
2625 local cur words cword prev
2626 _get_comp_words_by_ref -n =: cur words cword prev
2627 while [ $c -lt $cword ]; do
2628 i="${words[c]}"
2629 case "$i" in
2630 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2631 --bare) __git_dir="." ;;
2632 --version|-p|--paginate) ;;
2633 --help) command="help"; break ;;
2634 *) command="$i"; break ;;
2635 esac
2636 ((c++))
2637 done
2639 if [ -z "$command" ]; then
2640 case "$cur" in
2641 --*) __gitcomp "
2642 --paginate
2643 --no-pager
2644 --git-dir=
2645 --bare
2646 --version
2647 --exec-path
2648 --html-path
2649 --work-tree=
2650 --namespace=
2651 --help
2654 *) __git_compute_porcelain_commands
2655 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2656 esac
2657 return
2660 local completion_func="_git_${command//-/_}"
2661 declare -f $completion_func >/dev/null && $completion_func && return
2663 local expansion=$(__git_aliased_command "$command")
2664 if [ -n "$expansion" ]; then
2665 completion_func="_git_${expansion//-/_}"
2666 declare -f $completion_func >/dev/null && $completion_func
2670 _gitk ()
2672 if [[ -n ${ZSH_VERSION-} ]]; then
2673 emulate -L bash
2674 setopt KSH_TYPESET
2676 # workaround zsh's bug that leaves 'words' as a special
2677 # variable in versions < 4.3.12
2678 typeset -h words
2680 # workaround zsh's bug that quotes spaces in the COMPREPLY
2681 # array if IFS doesn't contain spaces.
2682 typeset -h IFS
2685 local cur words cword prev
2686 _get_comp_words_by_ref -n =: cur words cword prev
2688 __git_has_doubledash && return
2690 local g="$(__gitdir)"
2691 local merge=""
2692 if [ -f "$g/MERGE_HEAD" ]; then
2693 merge="--merge"
2695 case "$cur" in
2696 --*)
2697 __gitcomp "
2698 $__git_log_common_options
2699 $__git_log_gitk_options
2700 $merge
2702 return
2704 esac
2705 __git_complete_revlist
2708 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2709 || complete -o default -o nospace -F _git git
2710 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2711 || complete -o default -o nospace -F _gitk gitk
2713 # The following are necessary only for Cygwin, and only are needed
2714 # when the user has tab-completed the executable name and consequently
2715 # included the '.exe' suffix.
2717 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2718 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2719 || complete -o default -o nospace -F _git git.exe