am: Use cat instead of echo to avoid DOS line-endings (fixes t4150)
[git/dscho.git] / contrib / completion / git-completion.bash
blob8d92094e42558914f53033cbda10e93eeddccd92
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 requires 2 arguments
308 __gitcomp_1 ()
310 local c IFS=' '$'\t'$'\n'
311 for c in $1; do
312 case "$c$2" in
313 --*=*) printf %s$'\n' "$c$2" ;;
314 *.) printf %s$'\n' "$c$2" ;;
315 *) printf %s$'\n' "$c$2 " ;;
316 esac
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 local IFS=$'\n'
687 COMPREPLY=($(compgen -P "$pfx" \
688 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
689 | sed '/^100... blob /{
690 s,^.* ,,
691 s,$, ,
693 /^120000 blob /{
694 s,^.* ,,
695 s,$, ,
697 /^040000 tree /{
698 s,^.* ,,
699 s,$,/,
701 s/^.* //')" \
702 -- "$cur_"))
704 *...*)
705 pfx="${cur_%...*}..."
706 cur_="${cur_#*...}"
707 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
709 *..*)
710 pfx="${cur_%..*}.."
711 cur_="${cur_#*..}"
712 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
715 __gitcomp_nl "$(__git_refs)"
717 esac
721 __git_complete_file ()
723 __git_complete_revlist_file
726 __git_complete_revlist ()
728 __git_complete_revlist_file
731 __git_complete_remote_or_refspec ()
733 local cur_="$cur" cmd="${words[1]}"
734 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
735 if [ "$cmd" = "remote" ]; then
736 ((c++))
738 while [ $c -lt $cword ]; do
739 i="${words[c]}"
740 case "$i" in
741 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
742 --all)
743 case "$cmd" in
744 push) no_complete_refspec=1 ;;
745 fetch)
746 COMPREPLY=()
747 return
749 *) ;;
750 esac
752 -*) ;;
753 *) remote="$i"; break ;;
754 esac
755 ((c++))
756 done
757 if [ -z "$remote" ]; then
758 __gitcomp_nl "$(__git_remotes)"
759 return
761 if [ $no_complete_refspec = 1 ]; then
762 COMPREPLY=()
763 return
765 [ "$remote" = "." ] && remote=
766 case "$cur_" in
767 *:*)
768 case "$COMP_WORDBREAKS" in
769 *:*) : great ;;
770 *) pfx="${cur_%%:*}:" ;;
771 esac
772 cur_="${cur_#*:}"
773 lhs=0
776 pfx="+"
777 cur_="${cur_#+}"
779 esac
780 case "$cmd" in
781 fetch)
782 if [ $lhs = 1 ]; then
783 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
784 else
785 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
788 pull|remote)
789 if [ $lhs = 1 ]; then
790 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
791 else
792 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
795 push)
796 if [ $lhs = 1 ]; then
797 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
798 else
799 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
802 esac
805 __git_complete_strategy ()
807 __git_compute_merge_strategies
808 case "$prev" in
809 -s|--strategy)
810 __gitcomp "$__git_merge_strategies"
811 return 0
812 esac
813 case "$cur" in
814 --strategy=*)
815 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
816 return 0
818 esac
819 return 1
822 __git_list_all_commands ()
824 local i IFS=" "$'\n'
825 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
827 case $i in
828 *--*) : helper pattern;;
829 *) echo $i;;
830 esac
831 done
834 __git_all_commands=
835 __git_compute_all_commands ()
837 test -n "$__git_all_commands" ||
838 __git_all_commands=$(__git_list_all_commands)
841 __git_list_porcelain_commands ()
843 local i IFS=" "$'\n'
844 __git_compute_all_commands
845 for i in "help" $__git_all_commands
847 case $i in
848 *--*) : helper pattern;;
849 applymbox) : ask gittus;;
850 applypatch) : ask gittus;;
851 archimport) : import;;
852 cat-file) : plumbing;;
853 check-attr) : plumbing;;
854 check-ref-format) : plumbing;;
855 checkout-index) : plumbing;;
856 commit-tree) : plumbing;;
857 count-objects) : infrequent;;
858 cvsexportcommit) : export;;
859 cvsimport) : import;;
860 cvsserver) : daemon;;
861 daemon) : daemon;;
862 diff-files) : plumbing;;
863 diff-index) : plumbing;;
864 diff-tree) : plumbing;;
865 fast-import) : import;;
866 fast-export) : export;;
867 fsck-objects) : plumbing;;
868 fetch-pack) : plumbing;;
869 fmt-merge-msg) : plumbing;;
870 for-each-ref) : plumbing;;
871 hash-object) : plumbing;;
872 http-*) : transport;;
873 index-pack) : plumbing;;
874 init-db) : deprecated;;
875 local-fetch) : plumbing;;
876 lost-found) : infrequent;;
877 ls-files) : plumbing;;
878 ls-remote) : plumbing;;
879 ls-tree) : plumbing;;
880 mailinfo) : plumbing;;
881 mailsplit) : plumbing;;
882 merge-*) : plumbing;;
883 mktree) : plumbing;;
884 mktag) : plumbing;;
885 pack-objects) : plumbing;;
886 pack-redundant) : plumbing;;
887 pack-refs) : plumbing;;
888 parse-remote) : plumbing;;
889 patch-id) : plumbing;;
890 peek-remote) : plumbing;;
891 prune) : plumbing;;
892 prune-packed) : plumbing;;
893 quiltimport) : import;;
894 read-tree) : plumbing;;
895 receive-pack) : plumbing;;
896 remote-*) : transport;;
897 repo-config) : deprecated;;
898 rerere) : plumbing;;
899 rev-list) : plumbing;;
900 rev-parse) : plumbing;;
901 runstatus) : plumbing;;
902 sh-setup) : internal;;
903 shell) : daemon;;
904 show-ref) : plumbing;;
905 send-pack) : plumbing;;
906 show-index) : plumbing;;
907 ssh-*) : transport;;
908 stripspace) : plumbing;;
909 symbolic-ref) : plumbing;;
910 tar-tree) : deprecated;;
911 unpack-file) : plumbing;;
912 unpack-objects) : plumbing;;
913 update-index) : plumbing;;
914 update-ref) : plumbing;;
915 update-server-info) : daemon;;
916 upload-archive) : plumbing;;
917 upload-pack) : plumbing;;
918 write-tree) : plumbing;;
919 var) : infrequent;;
920 verify-pack) : infrequent;;
921 verify-tag) : plumbing;;
922 *) echo $i;;
923 esac
924 done
927 __git_porcelain_commands=
928 __git_compute_porcelain_commands ()
930 __git_compute_all_commands
931 test -n "$__git_porcelain_commands" ||
932 __git_porcelain_commands=$(__git_list_porcelain_commands)
935 __git_pretty_aliases ()
937 local i IFS=$'\n'
938 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
939 case "$i" in
940 pretty.*)
941 i="${i#pretty.}"
942 echo "${i/ */}"
944 esac
945 done
948 __git_aliases ()
950 local i IFS=$'\n'
951 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
952 case "$i" in
953 alias.*)
954 i="${i#alias.}"
955 echo "${i/ */}"
957 esac
958 done
961 # __git_aliased_command requires 1 argument
962 __git_aliased_command ()
964 local word cmdline=$(git --git-dir="$(__gitdir)" \
965 config --get "alias.$1")
966 for word in $cmdline; do
967 case "$word" in
968 \!gitk|gitk)
969 echo "gitk"
970 return
972 \!*) : shell command alias ;;
973 -*) : option ;;
974 *=*) : setting env ;;
975 git) : git itself ;;
977 echo "$word"
978 return
979 esac
980 done
983 # __git_find_on_cmdline requires 1 argument
984 __git_find_on_cmdline ()
986 local word subcommand c=1
987 while [ $c -lt $cword ]; do
988 word="${words[c]}"
989 for subcommand in $1; do
990 if [ "$subcommand" = "$word" ]; then
991 echo "$subcommand"
992 return
994 done
995 ((c++))
996 done
999 __git_has_doubledash ()
1001 local c=1
1002 while [ $c -lt $cword ]; do
1003 if [ "--" = "${words[c]}" ]; then
1004 return 0
1006 ((c++))
1007 done
1008 return 1
1011 __git_whitespacelist="nowarn warn error error-all fix"
1013 _git_am ()
1015 local dir="$(__gitdir)"
1016 if [ -d "$dir"/rebase-apply ]; then
1017 __gitcomp "--skip --continue --resolved --abort"
1018 return
1020 case "$cur" in
1021 --whitespace=*)
1022 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1023 return
1025 --*)
1026 __gitcomp "
1027 --3way --committer-date-is-author-date --ignore-date
1028 --ignore-whitespace --ignore-space-change
1029 --interactive --keep --no-utf8 --signoff --utf8
1030 --whitespace= --scissors
1032 return
1033 esac
1034 COMPREPLY=()
1037 _git_apply ()
1039 case "$cur" in
1040 --whitespace=*)
1041 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1042 return
1044 --*)
1045 __gitcomp "
1046 --stat --numstat --summary --check --index
1047 --cached --index-info --reverse --reject --unidiff-zero
1048 --apply --no-add --exclude=
1049 --ignore-whitespace --ignore-space-change
1050 --whitespace= --inaccurate-eof --verbose
1052 return
1053 esac
1054 COMPREPLY=()
1057 _git_add ()
1059 __git_has_doubledash && return
1061 case "$cur" in
1062 --*)
1063 __gitcomp "
1064 --interactive --refresh --patch --update --dry-run
1065 --ignore-errors --intent-to-add
1067 return
1068 esac
1069 COMPREPLY=()
1072 _git_archive ()
1074 case "$cur" in
1075 --format=*)
1076 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1077 return
1079 --remote=*)
1080 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1081 return
1083 --*)
1084 __gitcomp "
1085 --format= --list --verbose
1086 --prefix= --remote= --exec=
1088 return
1090 esac
1091 __git_complete_file
1094 _git_bisect ()
1096 __git_has_doubledash && return
1098 local subcommands="start bad good skip reset visualize replay log run"
1099 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1100 if [ -z "$subcommand" ]; then
1101 if [ -f "$(__gitdir)"/BISECT_START ]; then
1102 __gitcomp "$subcommands"
1103 else
1104 __gitcomp "replay start"
1106 return
1109 case "$subcommand" in
1110 bad|good|reset|skip|start)
1111 __gitcomp_nl "$(__git_refs)"
1114 COMPREPLY=()
1116 esac
1119 _git_branch ()
1121 local i c=1 only_local_ref="n" has_r="n"
1123 while [ $c -lt $cword ]; do
1124 i="${words[c]}"
1125 case "$i" in
1126 -d|-m) only_local_ref="y" ;;
1127 -r) has_r="y" ;;
1128 esac
1129 ((c++))
1130 done
1132 case "$cur" in
1133 --*)
1134 __gitcomp "
1135 --color --no-color --verbose --abbrev= --no-abbrev
1136 --track --no-track --contains --merged --no-merged
1137 --set-upstream --edit-description --list
1141 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1142 __gitcomp_nl "$(__git_heads)"
1143 else
1144 __gitcomp_nl "$(__git_refs)"
1147 esac
1150 _git_bundle ()
1152 local cmd="${words[2]}"
1153 case "$cword" in
1155 __gitcomp "create list-heads verify unbundle"
1158 # looking for a file
1161 case "$cmd" in
1162 create)
1163 __git_complete_revlist
1165 esac
1167 esac
1170 _git_checkout ()
1172 __git_has_doubledash && return
1174 case "$cur" in
1175 --conflict=*)
1176 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1178 --*)
1179 __gitcomp "
1180 --quiet --ours --theirs --track --no-track --merge
1181 --conflict= --orphan --patch
1185 # check if --track, --no-track, or --no-guess was specified
1186 # if so, disable DWIM mode
1187 local flags="--track --no-track --no-guess" track=1
1188 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1189 track=''
1191 __gitcomp_nl "$(__git_refs '' $track)"
1193 esac
1196 _git_cherry ()
1198 __gitcomp "$(__git_refs)"
1201 _git_cherry_pick ()
1203 case "$cur" in
1204 --*)
1205 __gitcomp "--edit --no-commit"
1208 __gitcomp_nl "$(__git_refs)"
1210 esac
1213 _git_clean ()
1215 __git_has_doubledash && return
1217 case "$cur" in
1218 --*)
1219 __gitcomp "--dry-run --quiet"
1220 return
1222 esac
1223 COMPREPLY=()
1226 _git_clone ()
1228 case "$cur" in
1229 --*)
1230 __gitcomp "
1231 --local
1232 --no-hardlinks
1233 --shared
1234 --reference
1235 --quiet
1236 --no-checkout
1237 --bare
1238 --mirror
1239 --origin
1240 --upload-pack
1241 --template=
1242 --depth
1244 return
1246 esac
1247 COMPREPLY=()
1250 _git_commit ()
1252 __git_has_doubledash && return
1254 case "$cur" in
1255 --cleanup=*)
1256 __gitcomp "default strip verbatim whitespace
1257 " "" "${cur##--cleanup=}"
1258 return
1260 --reuse-message=*|--reedit-message=*|\
1261 --fixup=*|--squash=*)
1262 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1263 return
1265 --untracked-files=*)
1266 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1267 return
1269 --*)
1270 __gitcomp "
1271 --all --author= --signoff --verify --no-verify
1272 --edit --amend --include --only --interactive
1273 --dry-run --reuse-message= --reedit-message=
1274 --reset-author --file= --message= --template=
1275 --cleanup= --untracked-files --untracked-files=
1276 --verbose --quiet --fixup= --squash=
1278 return
1279 esac
1280 COMPREPLY=()
1283 _git_describe ()
1285 case "$cur" in
1286 --*)
1287 __gitcomp "
1288 --all --tags --contains --abbrev= --candidates=
1289 --exact-match --debug --long --match --always
1291 return
1292 esac
1293 __gitcomp_nl "$(__git_refs)"
1296 __git_diff_common_options="--stat --numstat --shortstat --summary
1297 --patch-with-stat --name-only --name-status --color
1298 --no-color --color-words --no-renames --check
1299 --full-index --binary --abbrev --diff-filter=
1300 --find-copies-harder
1301 --text --ignore-space-at-eol --ignore-space-change
1302 --ignore-all-space --exit-code --quiet --ext-diff
1303 --no-ext-diff
1304 --no-prefix --src-prefix= --dst-prefix=
1305 --inter-hunk-context=
1306 --patience
1307 --raw
1308 --dirstat --dirstat= --dirstat-by-file
1309 --dirstat-by-file= --cumulative
1312 _git_diff ()
1314 __git_has_doubledash && return
1316 case "$cur" in
1317 --*)
1318 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1319 --base --ours --theirs --no-index
1320 $__git_diff_common_options
1322 return
1324 esac
1325 __git_complete_revlist_file
1328 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1329 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
1332 _git_difftool ()
1334 __git_has_doubledash && return
1336 case "$cur" in
1337 --tool=*)
1338 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1339 return
1341 --*)
1342 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1343 --base --ours --theirs
1344 --no-renames --diff-filter= --find-copies-harder
1345 --relative --ignore-submodules
1346 --tool="
1347 return
1349 esac
1350 __git_complete_file
1353 __git_fetch_options="
1354 --quiet --verbose --append --upload-pack --force --keep --depth=
1355 --tags --no-tags --all --prune --dry-run
1358 _git_fetch ()
1360 case "$cur" in
1361 --*)
1362 __gitcomp "$__git_fetch_options"
1363 return
1365 esac
1366 __git_complete_remote_or_refspec
1369 _git_format_patch ()
1371 case "$cur" in
1372 --thread=*)
1373 __gitcomp "
1374 deep shallow
1375 " "" "${cur##--thread=}"
1376 return
1378 --*)
1379 __gitcomp "
1380 --stdout --attach --no-attach --thread --thread=
1381 --output-directory
1382 --numbered --start-number
1383 --numbered-files
1384 --keep-subject
1385 --signoff --signature --no-signature
1386 --in-reply-to= --cc=
1387 --full-index --binary
1388 --not --all
1389 --cover-letter
1390 --no-prefix --src-prefix= --dst-prefix=
1391 --inline --suffix= --ignore-if-in-upstream
1392 --subject-prefix=
1394 return
1396 esac
1397 __git_complete_revlist
1400 _git_fsck ()
1402 case "$cur" in
1403 --*)
1404 __gitcomp "
1405 --tags --root --unreachable --cache --no-reflogs --full
1406 --strict --verbose --lost-found
1408 return
1410 esac
1411 COMPREPLY=()
1414 _git_gc ()
1416 case "$cur" in
1417 --*)
1418 __gitcomp "--prune --aggressive"
1419 return
1421 esac
1422 COMPREPLY=()
1425 _git_gitk ()
1427 _gitk
1430 __git_match_ctag() {
1431 awk "/^${1////\\/}/ { print \$1 }" "$2"
1434 _git_grep ()
1436 __git_has_doubledash && return
1438 case "$cur" in
1439 --*)
1440 __gitcomp "
1441 --cached
1442 --text --ignore-case --word-regexp --invert-match
1443 --full-name --line-number
1444 --extended-regexp --basic-regexp --fixed-strings
1445 --perl-regexp
1446 --files-with-matches --name-only
1447 --files-without-match
1448 --max-depth
1449 --count
1450 --and --or --not --all-match
1452 return
1454 esac
1456 case "$cword,$prev" in
1457 2,*|*,-*)
1458 if test -r tags; then
1459 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1460 return
1463 esac
1465 __gitcomp_nl "$(__git_refs)"
1468 _git_help ()
1470 case "$cur" in
1471 --*)
1472 __gitcomp "--all --info --man --web"
1473 return
1475 esac
1476 __git_compute_all_commands
1477 __gitcomp "$__git_all_commands $(__git_aliases)
1478 attributes cli core-tutorial cvs-migration
1479 diffcore gitk glossary hooks ignore modules
1480 namespaces repository-layout tutorial tutorial-2
1481 workflows
1485 _git_init ()
1487 case "$cur" in
1488 --shared=*)
1489 __gitcomp "
1490 false true umask group all world everybody
1491 " "" "${cur##--shared=}"
1492 return
1494 --*)
1495 __gitcomp "--quiet --bare --template= --shared --shared="
1496 return
1498 esac
1499 COMPREPLY=()
1502 _git_ls_files ()
1504 __git_has_doubledash && return
1506 case "$cur" in
1507 --*)
1508 __gitcomp "--cached --deleted --modified --others --ignored
1509 --stage --directory --no-empty-directory --unmerged
1510 --killed --exclude= --exclude-from=
1511 --exclude-per-directory= --exclude-standard
1512 --error-unmatch --with-tree= --full-name
1513 --abbrev --ignored --exclude-per-directory
1515 return
1517 esac
1518 COMPREPLY=()
1521 _git_ls_remote ()
1523 __gitcomp_nl "$(__git_remotes)"
1526 _git_ls_tree ()
1528 __git_complete_file
1531 # Options that go well for log, shortlog and gitk
1532 __git_log_common_options="
1533 --not --all
1534 --branches --tags --remotes
1535 --first-parent --merges --no-merges
1536 --max-count=
1537 --max-age= --since= --after=
1538 --min-age= --until= --before=
1539 --min-parents= --max-parents=
1540 --no-min-parents --no-max-parents
1542 # Options that go well for log and gitk (not shortlog)
1543 __git_log_gitk_options="
1544 --dense --sparse --full-history
1545 --simplify-merges --simplify-by-decoration
1546 --left-right --notes --no-notes
1548 # Options that go well for log and shortlog (not gitk)
1549 __git_log_shortlog_options="
1550 --author= --committer= --grep=
1551 --all-match
1554 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1555 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1557 _git_log ()
1559 __git_has_doubledash && return
1561 local g="$(git rev-parse --git-dir 2>/dev/null)"
1562 local merge=""
1563 if [ -f "$g/MERGE_HEAD" ]; then
1564 merge="--merge"
1566 case "$cur" in
1567 --pretty=*|--format=*)
1568 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1569 " "" "${cur#*=}"
1570 return
1572 --date=*)
1573 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1574 return
1576 --decorate=*)
1577 __gitcomp "long short" "" "${cur##--decorate=}"
1578 return
1580 --*)
1581 __gitcomp "
1582 $__git_log_common_options
1583 $__git_log_shortlog_options
1584 $__git_log_gitk_options
1585 --root --topo-order --date-order --reverse
1586 --follow --full-diff
1587 --abbrev-commit --abbrev=
1588 --relative-date --date=
1589 --pretty= --format= --oneline
1590 --cherry-pick
1591 --graph
1592 --decorate --decorate=
1593 --walk-reflogs
1594 --parents --children
1595 $merge
1596 $__git_diff_common_options
1597 --pickaxe-all --pickaxe-regex
1599 return
1601 esac
1602 __git_complete_revlist
1605 __git_merge_options="
1606 --no-commit --no-stat --log --no-log --squash --strategy
1607 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1610 _git_merge ()
1612 __git_complete_strategy && return
1614 case "$cur" in
1615 --*)
1616 __gitcomp "$__git_merge_options"
1617 return
1618 esac
1619 __gitcomp_nl "$(__git_refs)"
1622 _git_mergetool ()
1624 case "$cur" in
1625 --tool=*)
1626 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1627 return
1629 --*)
1630 __gitcomp "--tool="
1631 return
1633 esac
1634 COMPREPLY=()
1637 _git_merge_base ()
1639 __gitcomp_nl "$(__git_refs)"
1642 _git_mv ()
1644 case "$cur" in
1645 --*)
1646 __gitcomp "--dry-run"
1647 return
1649 esac
1650 COMPREPLY=()
1653 _git_name_rev ()
1655 __gitcomp "--tags --all --stdin"
1658 _git_notes ()
1660 local subcommands='add append copy edit list prune remove show'
1661 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1663 case "$subcommand,$cur" in
1664 ,--*)
1665 __gitcomp '--ref'
1668 case "${words[cword-1]}" in
1669 --ref)
1670 __gitcomp_nl "$(__git_refs)"
1673 __gitcomp "$subcommands --ref"
1675 esac
1677 add,--reuse-message=*|append,--reuse-message=*|\
1678 add,--reedit-message=*|append,--reedit-message=*)
1679 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1681 add,--*|append,--*)
1682 __gitcomp '--file= --message= --reedit-message=
1683 --reuse-message='
1685 copy,--*)
1686 __gitcomp '--stdin'
1688 prune,--*)
1689 __gitcomp '--dry-run --verbose'
1691 prune,*)
1694 case "${words[cword-1]}" in
1695 -m|-F)
1698 __gitcomp_nl "$(__git_refs)"
1700 esac
1702 esac
1705 _git_pull ()
1707 __git_complete_strategy && return
1709 case "$cur" in
1710 --*)
1711 __gitcomp "
1712 --rebase --no-rebase
1713 $__git_merge_options
1714 $__git_fetch_options
1716 return
1718 esac
1719 __git_complete_remote_or_refspec
1722 _git_push ()
1724 case "$prev" in
1725 --repo)
1726 __gitcomp_nl "$(__git_remotes)"
1727 return
1728 esac
1729 case "$cur" in
1730 --repo=*)
1731 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1732 return
1734 --*)
1735 __gitcomp "
1736 --all --mirror --tags --dry-run --force --verbose
1737 --receive-pack= --repo= --set-upstream
1739 return
1741 esac
1742 __git_complete_remote_or_refspec
1745 _git_rebase ()
1747 local dir="$(__gitdir)"
1748 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1749 __gitcomp "--continue --skip --abort"
1750 return
1752 __git_complete_strategy && return
1753 case "$cur" in
1754 --whitespace=*)
1755 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1756 return
1758 --*)
1759 __gitcomp "
1760 --onto --merge --strategy --interactive
1761 --preserve-merges --stat --no-stat
1762 --committer-date-is-author-date --ignore-date
1763 --ignore-whitespace --whitespace=
1764 --autosquash
1767 return
1768 esac
1769 __gitcomp_nl "$(__git_refs)"
1772 _git_reflog ()
1774 local subcommands="show delete expire"
1775 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1777 if [ -z "$subcommand" ]; then
1778 __gitcomp "$subcommands"
1779 else
1780 __gitcomp_nl "$(__git_refs)"
1784 __git_send_email_confirm_options="always never auto cc compose"
1785 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1787 _git_send_email ()
1789 case "$cur" in
1790 --confirm=*)
1791 __gitcomp "
1792 $__git_send_email_confirm_options
1793 " "" "${cur##--confirm=}"
1794 return
1796 --suppress-cc=*)
1797 __gitcomp "
1798 $__git_send_email_suppresscc_options
1799 " "" "${cur##--suppress-cc=}"
1801 return
1803 --smtp-encryption=*)
1804 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1805 return
1807 --*)
1808 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1809 --compose --confirm= --dry-run --envelope-sender
1810 --from --identity
1811 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1812 --no-suppress-from --no-thread --quiet
1813 --signed-off-by-cc --smtp-pass --smtp-server
1814 --smtp-server-port --smtp-encryption= --smtp-user
1815 --subject --suppress-cc= --suppress-from --thread --to
1816 --validate --no-validate"
1817 return
1819 esac
1820 COMPREPLY=()
1823 _git_stage ()
1825 _git_add
1828 __git_config_get_set_variables ()
1830 local prevword word config_file= c=$cword
1831 while [ $c -gt 1 ]; do
1832 word="${words[c]}"
1833 case "$word" in
1834 --global|--system|--file=*)
1835 config_file="$word"
1836 break
1838 -f|--file)
1839 config_file="$word $prevword"
1840 break
1842 esac
1843 prevword=$word
1844 c=$((--c))
1845 done
1847 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1848 while read -r line
1850 case "$line" in
1851 *.*=*)
1852 echo "${line/=*/}"
1854 esac
1855 done
1858 _git_config ()
1860 case "$prev" in
1861 branch.*.remote)
1862 __gitcomp_nl "$(__git_remotes)"
1863 return
1865 branch.*.merge)
1866 __gitcomp_nl "$(__git_refs)"
1867 return
1869 remote.*.fetch)
1870 local remote="${prev#remote.}"
1871 remote="${remote%.fetch}"
1872 if [ -z "$cur" ]; then
1873 COMPREPLY=("refs/heads/")
1874 return
1876 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1877 return
1879 remote.*.push)
1880 local remote="${prev#remote.}"
1881 remote="${remote%.push}"
1882 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1883 for-each-ref --format='%(refname):%(refname)' \
1884 refs/heads)"
1885 return
1887 pull.twohead|pull.octopus)
1888 __git_compute_merge_strategies
1889 __gitcomp "$__git_merge_strategies"
1890 return
1892 color.branch|color.diff|color.interactive|\
1893 color.showbranch|color.status|color.ui)
1894 __gitcomp "always never auto"
1895 return
1897 color.pager)
1898 __gitcomp "false true"
1899 return
1901 color.*.*)
1902 __gitcomp "
1903 normal black red green yellow blue magenta cyan white
1904 bold dim ul blink reverse
1906 return
1908 help.format)
1909 __gitcomp "man info web html"
1910 return
1912 log.date)
1913 __gitcomp "$__git_log_date_formats"
1914 return
1916 sendemail.aliasesfiletype)
1917 __gitcomp "mutt mailrc pine elm gnus"
1918 return
1920 sendemail.confirm)
1921 __gitcomp "$__git_send_email_confirm_options"
1922 return
1924 sendemail.suppresscc)
1925 __gitcomp "$__git_send_email_suppresscc_options"
1926 return
1928 --get|--get-all|--unset|--unset-all)
1929 __gitcomp_nl "$(__git_config_get_set_variables)"
1930 return
1932 *.*)
1933 COMPREPLY=()
1934 return
1936 esac
1937 case "$cur" in
1938 --*)
1939 __gitcomp "
1940 --global --system --file=
1941 --list --replace-all
1942 --get --get-all --get-regexp
1943 --add --unset --unset-all
1944 --remove-section --rename-section
1946 return
1948 branch.*.*)
1949 local pfx="${cur%.*}." cur_="${cur##*.}"
1950 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1951 return
1953 branch.*)
1954 local pfx="${cur%.*}." cur_="${cur#*.}"
1955 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1956 return
1958 guitool.*.*)
1959 local pfx="${cur%.*}." cur_="${cur##*.}"
1960 __gitcomp "
1961 argprompt cmd confirm needsfile noconsole norescan
1962 prompt revprompt revunmerged title
1963 " "$pfx" "$cur_"
1964 return
1966 difftool.*.*)
1967 local pfx="${cur%.*}." cur_="${cur##*.}"
1968 __gitcomp "cmd path" "$pfx" "$cur_"
1969 return
1971 man.*.*)
1972 local pfx="${cur%.*}." cur_="${cur##*.}"
1973 __gitcomp "cmd path" "$pfx" "$cur_"
1974 return
1976 mergetool.*.*)
1977 local pfx="${cur%.*}." cur_="${cur##*.}"
1978 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1979 return
1981 pager.*)
1982 local pfx="${cur%.*}." cur_="${cur#*.}"
1983 __git_compute_all_commands
1984 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1985 return
1987 remote.*.*)
1988 local pfx="${cur%.*}." cur_="${cur##*.}"
1989 __gitcomp "
1990 url proxy fetch push mirror skipDefaultUpdate
1991 receivepack uploadpack tagopt pushurl
1992 " "$pfx" "$cur_"
1993 return
1995 remote.*)
1996 local pfx="${cur%.*}." cur_="${cur#*.}"
1997 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1998 return
2000 url.*.*)
2001 local pfx="${cur%.*}." cur_="${cur##*.}"
2002 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2003 return
2005 esac
2006 __gitcomp "
2007 add.ignoreErrors
2008 advice.commitBeforeMerge
2009 advice.detachedHead
2010 advice.implicitIdentity
2011 advice.pushNonFastForward
2012 advice.resolveConflict
2013 advice.statusHints
2014 alias.
2015 am.keepcr
2016 apply.ignorewhitespace
2017 apply.whitespace
2018 branch.autosetupmerge
2019 branch.autosetuprebase
2020 browser.
2021 clean.requireForce
2022 color.branch
2023 color.branch.current
2024 color.branch.local
2025 color.branch.plain
2026 color.branch.remote
2027 color.decorate.HEAD
2028 color.decorate.branch
2029 color.decorate.remoteBranch
2030 color.decorate.stash
2031 color.decorate.tag
2032 color.diff
2033 color.diff.commit
2034 color.diff.frag
2035 color.diff.func
2036 color.diff.meta
2037 color.diff.new
2038 color.diff.old
2039 color.diff.plain
2040 color.diff.whitespace
2041 color.grep
2042 color.grep.context
2043 color.grep.filename
2044 color.grep.function
2045 color.grep.linenumber
2046 color.grep.match
2047 color.grep.selected
2048 color.grep.separator
2049 color.interactive
2050 color.interactive.error
2051 color.interactive.header
2052 color.interactive.help
2053 color.interactive.prompt
2054 color.pager
2055 color.showbranch
2056 color.status
2057 color.status.added
2058 color.status.changed
2059 color.status.header
2060 color.status.nobranch
2061 color.status.untracked
2062 color.status.updated
2063 color.ui
2064 commit.status
2065 commit.template
2066 core.abbrev
2067 core.askpass
2068 core.attributesfile
2069 core.autocrlf
2070 core.bare
2071 core.bigFileThreshold
2072 core.compression
2073 core.createObject
2074 core.deltaBaseCacheLimit
2075 core.editor
2076 core.eol
2077 core.excludesfile
2078 core.fileMode
2079 core.fsyncobjectfiles
2080 core.gitProxy
2081 core.ignoreCygwinFSTricks
2082 core.ignoreStat
2083 core.ignorecase
2084 core.logAllRefUpdates
2085 core.loosecompression
2086 core.notesRef
2087 core.packedGitLimit
2088 core.packedGitWindowSize
2089 core.pager
2090 core.preferSymlinkRefs
2091 core.preloadindex
2092 core.quotepath
2093 core.repositoryFormatVersion
2094 core.safecrlf
2095 core.sharedRepository
2096 core.sparseCheckout
2097 core.symlinks
2098 core.trustctime
2099 core.warnAmbiguousRefs
2100 core.whitespace
2101 core.worktree
2102 diff.autorefreshindex
2103 diff.statGraphWidth
2104 diff.external
2105 diff.ignoreSubmodules
2106 diff.mnemonicprefix
2107 diff.noprefix
2108 diff.renameLimit
2109 diff.renames
2110 diff.suppressBlankEmpty
2111 diff.tool
2112 diff.wordRegex
2113 difftool.
2114 difftool.prompt
2115 fetch.recurseSubmodules
2116 fetch.unpackLimit
2117 format.attach
2118 format.cc
2119 format.headers
2120 format.numbered
2121 format.pretty
2122 format.signature
2123 format.signoff
2124 format.subjectprefix
2125 format.suffix
2126 format.thread
2127 format.to
2129 gc.aggressiveWindow
2130 gc.auto
2131 gc.autopacklimit
2132 gc.packrefs
2133 gc.pruneexpire
2134 gc.reflogexpire
2135 gc.reflogexpireunreachable
2136 gc.rerereresolved
2137 gc.rerereunresolved
2138 gitcvs.allbinary
2139 gitcvs.commitmsgannotation
2140 gitcvs.dbTableNamePrefix
2141 gitcvs.dbdriver
2142 gitcvs.dbname
2143 gitcvs.dbpass
2144 gitcvs.dbuser
2145 gitcvs.enabled
2146 gitcvs.logfile
2147 gitcvs.usecrlfattr
2148 guitool.
2149 gui.blamehistoryctx
2150 gui.commitmsgwidth
2151 gui.copyblamethreshold
2152 gui.diffcontext
2153 gui.encoding
2154 gui.fastcopyblame
2155 gui.matchtrackingbranch
2156 gui.newbranchtemplate
2157 gui.pruneduringfetch
2158 gui.spellingdictionary
2159 gui.trustmtime
2160 help.autocorrect
2161 help.browser
2162 help.format
2163 http.lowSpeedLimit
2164 http.lowSpeedTime
2165 http.maxRequests
2166 http.minSessions
2167 http.noEPSV
2168 http.postBuffer
2169 http.proxy
2170 http.sslCAInfo
2171 http.sslCAPath
2172 http.sslCert
2173 http.sslCertPasswordProtected
2174 http.sslKey
2175 http.sslVerify
2176 http.useragent
2177 i18n.commitEncoding
2178 i18n.logOutputEncoding
2179 imap.authMethod
2180 imap.folder
2181 imap.host
2182 imap.pass
2183 imap.port
2184 imap.preformattedHTML
2185 imap.sslverify
2186 imap.tunnel
2187 imap.user
2188 init.templatedir
2189 instaweb.browser
2190 instaweb.httpd
2191 instaweb.local
2192 instaweb.modulepath
2193 instaweb.port
2194 interactive.singlekey
2195 log.date
2196 log.decorate
2197 log.showroot
2198 mailmap.file
2199 man.
2200 man.viewer
2201 merge.
2202 merge.conflictstyle
2203 merge.log
2204 merge.renameLimit
2205 merge.renormalize
2206 merge.stat
2207 merge.tool
2208 merge.verbosity
2209 mergetool.
2210 mergetool.keepBackup
2211 mergetool.keepTemporaries
2212 mergetool.prompt
2213 notes.displayRef
2214 notes.rewrite.
2215 notes.rewrite.amend
2216 notes.rewrite.rebase
2217 notes.rewriteMode
2218 notes.rewriteRef
2219 pack.compression
2220 pack.deltaCacheLimit
2221 pack.deltaCacheSize
2222 pack.depth
2223 pack.indexVersion
2224 pack.packSizeLimit
2225 pack.threads
2226 pack.window
2227 pack.windowMemory
2228 pager.
2229 pretty.
2230 pull.octopus
2231 pull.twohead
2232 push.default
2233 rebase.autosquash
2234 rebase.stat
2235 receive.autogc
2236 receive.denyCurrentBranch
2237 receive.denyDeleteCurrent
2238 receive.denyDeletes
2239 receive.denyNonFastForwards
2240 receive.fsckObjects
2241 receive.unpackLimit
2242 receive.updateserverinfo
2243 remotes.
2244 repack.usedeltabaseoffset
2245 rerere.autoupdate
2246 rerere.enabled
2247 sendemail.
2248 sendemail.aliasesfile
2249 sendemail.aliasfiletype
2250 sendemail.bcc
2251 sendemail.cc
2252 sendemail.cccmd
2253 sendemail.chainreplyto
2254 sendemail.confirm
2255 sendemail.envelopesender
2256 sendemail.from
2257 sendemail.identity
2258 sendemail.multiedit
2259 sendemail.signedoffbycc
2260 sendemail.smtpdomain
2261 sendemail.smtpencryption
2262 sendemail.smtppass
2263 sendemail.smtpserver
2264 sendemail.smtpserveroption
2265 sendemail.smtpserverport
2266 sendemail.smtpuser
2267 sendemail.suppresscc
2268 sendemail.suppressfrom
2269 sendemail.thread
2270 sendemail.to
2271 sendemail.validate
2272 showbranch.default
2273 status.relativePaths
2274 status.showUntrackedFiles
2275 status.submodulesummary
2276 submodule.
2277 tar.umask
2278 transfer.unpackLimit
2279 url.
2280 user.email
2281 user.name
2282 user.signingkey
2283 web.browser
2284 branch. remote.
2288 _git_remote ()
2290 local subcommands="add rename rm set-head set-branches set-url show prune update"
2291 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2292 if [ -z "$subcommand" ]; then
2293 __gitcomp "$subcommands"
2294 return
2297 case "$subcommand" in
2298 rename|rm|set-url|show|prune)
2299 __gitcomp_nl "$(__git_remotes)"
2301 set-head|set-branches)
2302 __git_complete_remote_or_refspec
2304 update)
2305 local i c='' IFS=$'\n'
2306 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2307 i="${i#remotes.}"
2308 c="$c ${i/ */}"
2309 done
2310 __gitcomp "$c"
2313 COMPREPLY=()
2315 esac
2318 _git_replace ()
2320 __gitcomp_nl "$(__git_refs)"
2323 _git_reset ()
2325 __git_has_doubledash && return
2327 case "$cur" in
2328 --*)
2329 __gitcomp "--merge --mixed --hard --soft --patch"
2330 return
2332 esac
2333 __gitcomp_nl "$(__git_refs)"
2336 _git_revert ()
2338 case "$cur" in
2339 --*)
2340 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2341 return
2343 esac
2344 __gitcomp_nl "$(__git_refs)"
2347 _git_rm ()
2349 __git_has_doubledash && return
2351 case "$cur" in
2352 --*)
2353 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2354 return
2356 esac
2357 COMPREPLY=()
2360 _git_shortlog ()
2362 __git_has_doubledash && return
2364 case "$cur" in
2365 --*)
2366 __gitcomp "
2367 $__git_log_common_options
2368 $__git_log_shortlog_options
2369 --numbered --summary
2371 return
2373 esac
2374 __git_complete_revlist
2377 _git_show ()
2379 __git_has_doubledash && return
2381 case "$cur" in
2382 --pretty=*|--format=*)
2383 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2384 " "" "${cur#*=}"
2385 return
2387 --*)
2388 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2389 $__git_diff_common_options
2391 return
2393 esac
2394 __git_complete_file
2397 _git_show_branch ()
2399 case "$cur" in
2400 --*)
2401 __gitcomp "
2402 --all --remotes --topo-order --current --more=
2403 --list --independent --merge-base --no-name
2404 --color --no-color
2405 --sha1-name --sparse --topics --reflog
2407 return
2409 esac
2410 __git_complete_revlist
2413 _git_stash ()
2415 local save_opts='--keep-index --no-keep-index --quiet --patch'
2416 local subcommands='save list show apply clear drop pop create branch'
2417 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2418 if [ -z "$subcommand" ]; then
2419 case "$cur" in
2420 --*)
2421 __gitcomp "$save_opts"
2424 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2425 __gitcomp "$subcommands"
2426 else
2427 COMPREPLY=()
2430 esac
2431 else
2432 case "$subcommand,$cur" in
2433 save,--*)
2434 __gitcomp "$save_opts"
2436 apply,--*|pop,--*)
2437 __gitcomp "--index --quiet"
2439 show,--*|drop,--*|branch,--*)
2440 COMPREPLY=()
2442 show,*|apply,*|drop,*|pop,*|branch,*)
2443 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2444 | sed -n -e 's/:.*//p')"
2447 COMPREPLY=()
2449 esac
2453 _git_submodule ()
2455 __git_has_doubledash && return
2457 local subcommands="add status init update summary foreach sync"
2458 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2459 case "$cur" in
2460 --*)
2461 __gitcomp "--quiet --cached"
2464 __gitcomp "$subcommands"
2466 esac
2467 return
2471 _git_svn ()
2473 local subcommands="
2474 init fetch clone rebase dcommit log find-rev
2475 set-tree commit-diff info create-ignore propget
2476 proplist show-ignore show-externals branch tag blame
2477 migrate mkdirs reset gc
2479 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2480 if [ -z "$subcommand" ]; then
2481 __gitcomp "$subcommands"
2482 else
2483 local remote_opts="--username= --config-dir= --no-auth-cache"
2484 local fc_opts="
2485 --follow-parent --authors-file= --repack=
2486 --no-metadata --use-svm-props --use-svnsync-props
2487 --log-window-size= --no-checkout --quiet
2488 --repack-flags --use-log-author --localtime
2489 --ignore-paths= $remote_opts
2491 local init_opts="
2492 --template= --shared= --trunk= --tags=
2493 --branches= --stdlayout --minimize-url
2494 --no-metadata --use-svm-props --use-svnsync-props
2495 --rewrite-root= --prefix= --use-log-author
2496 --add-author-from $remote_opts
2498 local cmt_opts="
2499 --edit --rmdir --find-copies-harder --copy-similarity=
2502 case "$subcommand,$cur" in
2503 fetch,--*)
2504 __gitcomp "--revision= --fetch-all $fc_opts"
2506 clone,--*)
2507 __gitcomp "--revision= $fc_opts $init_opts"
2509 init,--*)
2510 __gitcomp "$init_opts"
2512 dcommit,--*)
2513 __gitcomp "
2514 --merge --strategy= --verbose --dry-run
2515 --fetch-all --no-rebase --commit-url
2516 --revision --interactive $cmt_opts $fc_opts
2519 set-tree,--*)
2520 __gitcomp "--stdin $cmt_opts $fc_opts"
2522 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2523 show-externals,--*|mkdirs,--*)
2524 __gitcomp "--revision="
2526 log,--*)
2527 __gitcomp "
2528 --limit= --revision= --verbose --incremental
2529 --oneline --show-commit --non-recursive
2530 --authors-file= --color
2533 rebase,--*)
2534 __gitcomp "
2535 --merge --verbose --strategy= --local
2536 --fetch-all --dry-run $fc_opts
2539 commit-diff,--*)
2540 __gitcomp "--message= --file= --revision= $cmt_opts"
2542 info,--*)
2543 __gitcomp "--url"
2545 branch,--*)
2546 __gitcomp "--dry-run --message --tag"
2548 tag,--*)
2549 __gitcomp "--dry-run --message"
2551 blame,--*)
2552 __gitcomp "--git-format"
2554 migrate,--*)
2555 __gitcomp "
2556 --config-dir= --ignore-paths= --minimize
2557 --no-auth-cache --username=
2560 reset,--*)
2561 __gitcomp "--revision= --parent"
2564 COMPREPLY=()
2566 esac
2570 _git_tag ()
2572 local i c=1 f=0
2573 while [ $c -lt $cword ]; do
2574 i="${words[c]}"
2575 case "$i" in
2576 -d|-v)
2577 __gitcomp_nl "$(__git_tags)"
2578 return
2583 esac
2584 ((c++))
2585 done
2587 case "$prev" in
2588 -m|-F)
2589 COMPREPLY=()
2591 -*|tag)
2592 if [ $f = 1 ]; then
2593 __gitcomp_nl "$(__git_tags)"
2594 else
2595 COMPREPLY=()
2599 __gitcomp_nl "$(__git_refs)"
2601 esac
2604 _git_whatchanged ()
2606 _git_log
2609 _git ()
2611 local i c=1 command __git_dir
2613 if [[ -n ${ZSH_VERSION-} ]]; then
2614 emulate -L bash
2615 setopt KSH_TYPESET
2617 # workaround zsh's bug that leaves 'words' as a special
2618 # variable in versions < 4.3.12
2619 typeset -h words
2621 # workaround zsh's bug that quotes spaces in the COMPREPLY
2622 # array if IFS doesn't contain spaces.
2623 typeset -h IFS
2626 local cur words cword prev
2627 _get_comp_words_by_ref -n =: cur words cword prev
2628 while [ $c -lt $cword ]; do
2629 i="${words[c]}"
2630 case "$i" in
2631 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2632 --bare) __git_dir="." ;;
2633 --version|-p|--paginate) ;;
2634 --help) command="help"; break ;;
2635 *) command="$i"; break ;;
2636 esac
2637 ((c++))
2638 done
2640 if [ -z "$command" ]; then
2641 case "$cur" in
2642 --*) __gitcomp "
2643 --paginate
2644 --no-pager
2645 --git-dir=
2646 --bare
2647 --version
2648 --exec-path
2649 --html-path
2650 --work-tree=
2651 --namespace=
2652 --help
2655 *) __git_compute_porcelain_commands
2656 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2657 esac
2658 return
2661 local completion_func="_git_${command//-/_}"
2662 declare -f $completion_func >/dev/null && $completion_func && return
2664 local expansion=$(__git_aliased_command "$command")
2665 if [ -n "$expansion" ]; then
2666 completion_func="_git_${expansion//-/_}"
2667 declare -f $completion_func >/dev/null && $completion_func
2671 _gitk ()
2673 if [[ -n ${ZSH_VERSION-} ]]; then
2674 emulate -L bash
2675 setopt KSH_TYPESET
2677 # workaround zsh's bug that leaves 'words' as a special
2678 # variable in versions < 4.3.12
2679 typeset -h words
2681 # workaround zsh's bug that quotes spaces in the COMPREPLY
2682 # array if IFS doesn't contain spaces.
2683 typeset -h IFS
2686 local cur words cword prev
2687 _get_comp_words_by_ref -n =: cur words cword prev
2689 __git_has_doubledash && return
2691 local g="$(__gitdir)"
2692 local merge=""
2693 if [ -f "$g/MERGE_HEAD" ]; then
2694 merge="--merge"
2696 case "$cur" in
2697 --*)
2698 __gitcomp "
2699 $__git_log_common_options
2700 $__git_log_gitk_options
2701 $merge
2703 return
2705 esac
2706 __git_complete_revlist
2709 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2710 || complete -o default -o nospace -F _git git
2711 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2712 || complete -o default -o nospace -F _gitk gitk
2714 # The following are necessary only for Cygwin, and only are needed
2715 # when the user has tab-completed the executable name and consequently
2716 # included the '.exe' suffix.
2718 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2719 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2720 || complete -o default -o nospace -F _git git.exe