bash completion: add basic support for git-reflog
[git/raj.git] / contrib / completion / git-completion.bash
blob9d6c880e1823ceb0689d8c26c8965878e3015506
1 #!bash
3 # bash 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) Added the following line to your .bashrc:
22 # source ~/.git-completion.sh
24 # Or, add the following lines to your .zshrc:
25 # autoload bashcompinit
26 # bashcompinit
27 # source ~/.git-completion.sh
29 # 3) Consider changing your PS1 to also show the current branch:
30 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
32 # The argument to __git_ps1 will be displayed only if you
33 # are currently in a git repository. The %s token will be
34 # the name of the current branch.
36 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
37 # value, unstaged (*) and staged (+) changes will be shown next
38 # to the branch name. You can configure this per-repository
39 # with the bash.showDirtyState variable, which defaults to true
40 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
42 # You can also see if currently something is stashed, by setting
43 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
44 # then a '$' will be shown next to the branch name.
46 # If you would like to see if there're untracked files, then you can
47 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
48 # untracked files, then a '%' will be shown next to the branch name.
50 # If you would like to see the difference between HEAD and its
51 # upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates
52 # you are behind, ">" indicates you are ahead, and "<>"
53 # indicates you have diverged. You can further control
54 # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
55 # list of values:
56 # verbose show number of commits ahead/behind (+/-) upstream
57 # legacy don't use the '--count' option available in recent
58 # versions of git-rev-list
59 # git always compare HEAD to @{upstream}
60 # svn always compare HEAD to your SVN upstream
61 # By default, __git_ps1 will compare HEAD to your SVN upstream
62 # if it can find one, or @{upstream} otherwise. Once you have
63 # set GIT_PS1_SHOWUPSTREAM, you can override it on a
64 # per-repository basis by setting the bash.showUpstream config
65 # variable.
68 # To submit patches:
70 # *) Read Documentation/SubmittingPatches
71 # *) Send all patches to the current maintainer:
73 # "Shawn O. Pearce" <spearce@spearce.org>
75 # *) Always CC the Git mailing list:
77 # git@vger.kernel.org
80 case "$COMP_WORDBREAKS" in
81 *:*) : great ;;
82 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
83 esac
85 # __gitdir accepts 0 or 1 arguments (i.e., location)
86 # returns location of .git repo
87 __gitdir ()
89 if [ -z "${1-}" ]; then
90 if [ -n "${__git_dir-}" ]; then
91 echo "$__git_dir"
92 elif [ -d .git ]; then
93 echo .git
94 else
95 git rev-parse --git-dir 2>/dev/null
97 elif [ -d "$1/.git" ]; then
98 echo "$1/.git"
99 else
100 echo "$1"
104 # stores the divergence from upstream in $p
105 # used by GIT_PS1_SHOWUPSTREAM
106 __git_ps1_show_upstream ()
108 local key value
109 local svn_remote=() svn_url_pattern count n
110 local upstream=git legacy="" verbose=""
112 # get some config options from git-config
113 while read key value; do
114 case "$key" in
115 bash.showupstream)
116 GIT_PS1_SHOWUPSTREAM="$value"
117 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
118 p=""
119 return
122 svn-remote.*.url)
123 svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
124 svn_url_pattern+="\\|$value"
125 upstream=svn+git # default upstream is SVN if available, else git
127 esac
128 done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
130 # parse configuration values
131 for option in ${GIT_PS1_SHOWUPSTREAM}; do
132 case "$option" in
133 git|svn) upstream="$option" ;;
134 verbose) verbose=1 ;;
135 legacy) legacy=1 ;;
136 esac
137 done
139 # Find our upstream
140 case "$upstream" in
141 git) upstream="@{upstream}" ;;
142 svn*)
143 # get the upstream from the "git-svn-id: ..." in a commit message
144 # (git-svn uses essentially the same procedure internally)
145 local svn_upstream=($(git log --first-parent -1 \
146 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
147 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
148 svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
149 svn_upstream=${svn_upstream%@*}
150 local n_stop="${#svn_remote[@]}"
151 for ((n=1; n <= n_stop; ++n)); do
152 svn_upstream=${svn_upstream#${svn_remote[$n]}}
153 done
155 if [[ -z "$svn_upstream" ]]; then
156 # default branch name for checkouts with no layout:
157 upstream=${GIT_SVN_ID:-git-svn}
158 else
159 upstream=${svn_upstream#/}
161 elif [[ "svn+git" = "$upstream" ]]; then
162 upstream="@{upstream}"
165 esac
167 # Find how many commits we are ahead/behind our upstream
168 if [[ -z "$legacy" ]]; then
169 count="$(git rev-list --count --left-right \
170 "$upstream"...HEAD 2>/dev/null)"
171 else
172 # produce equivalent output to --count for older versions of git
173 local commits
174 if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
175 then
176 local commit behind=0 ahead=0
177 for commit in $commits
179 case "$commit" in
180 "<"*) let ++behind
182 *) let ++ahead
184 esac
185 done
186 count="$behind $ahead"
187 else
188 count=""
192 # calculate the result
193 if [[ -z "$verbose" ]]; then
194 case "$count" in
195 "") # no upstream
196 p="" ;;
197 "0 0") # equal to upstream
198 p="=" ;;
199 "0 "*) # ahead of upstream
200 p=">" ;;
201 *" 0") # behind upstream
202 p="<" ;;
203 *) # diverged from upstream
204 p="<>" ;;
205 esac
206 else
207 case "$count" in
208 "") # no upstream
209 p="" ;;
210 "0 0") # equal to upstream
211 p=" u=" ;;
212 "0 "*) # ahead of upstream
213 p=" u+${count#0 }" ;;
214 *" 0") # behind upstream
215 p=" u-${count% 0}" ;;
216 *) # diverged from upstream
217 p=" u+${count#* }-${count% *}" ;;
218 esac
224 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
225 # returns text to add to bash PS1 prompt (includes branch name)
226 __git_ps1 ()
228 local g="$(__gitdir)"
229 if [ -n "$g" ]; then
230 local r=""
231 local b=""
232 if [ -f "$g/rebase-merge/interactive" ]; then
233 r="|REBASE-i"
234 b="$(cat "$g/rebase-merge/head-name")"
235 elif [ -d "$g/rebase-merge" ]; then
236 r="|REBASE-m"
237 b="$(cat "$g/rebase-merge/head-name")"
238 else
239 if [ -d "$g/rebase-apply" ]; then
240 if [ -f "$g/rebase-apply/rebasing" ]; then
241 r="|REBASE"
242 elif [ -f "$g/rebase-apply/applying" ]; then
243 r="|AM"
244 else
245 r="|AM/REBASE"
247 elif [ -f "$g/MERGE_HEAD" ]; then
248 r="|MERGING"
249 elif [ -f "$g/BISECT_LOG" ]; then
250 r="|BISECTING"
253 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
255 b="$(
256 case "${GIT_PS1_DESCRIBE_STYLE-}" in
257 (contains)
258 git describe --contains HEAD ;;
259 (branch)
260 git describe --contains --all HEAD ;;
261 (describe)
262 git describe HEAD ;;
263 (* | default)
264 git describe --tags --exact-match HEAD ;;
265 esac 2>/dev/null)" ||
267 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
268 b="unknown"
269 b="($b)"
273 local w=""
274 local i=""
275 local s=""
276 local u=""
277 local c=""
278 local p=""
280 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
281 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
282 c="BARE:"
283 else
284 b="GIT_DIR!"
286 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
287 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
288 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
289 git diff --no-ext-diff --quiet --exit-code || w="*"
290 if git rev-parse --quiet --verify HEAD >/dev/null; then
291 git diff-index --cached --quiet HEAD -- || i="+"
292 else
293 i="#"
297 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
298 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
301 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
302 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
303 u="%"
307 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
308 __git_ps1_show_upstream
312 local f="$w$i$s$u"
313 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
317 # __gitcomp_1 requires 2 arguments
318 __gitcomp_1 ()
320 local c IFS=' '$'\t'$'\n'
321 for c in $1; do
322 case "$c$2" in
323 --*=*) printf %s$'\n' "$c$2" ;;
324 *.) printf %s$'\n' "$c$2" ;;
325 *) printf %s$'\n' "$c$2 " ;;
326 esac
327 done
330 # __gitcomp accepts 1, 2, 3, or 4 arguments
331 # generates completion reply with compgen
332 __gitcomp ()
334 local cur="${COMP_WORDS[COMP_CWORD]}"
335 if [ $# -gt 2 ]; then
336 cur="$3"
338 case "$cur" in
339 --*=)
340 COMPREPLY=()
343 local IFS=$'\n'
344 COMPREPLY=($(compgen -P "${2-}" \
345 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
346 -- "$cur"))
348 esac
351 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
352 __git_heads ()
354 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
355 if [ -d "$dir" ]; then
356 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
357 refs/heads
358 return
360 for i in $(git ls-remote "${1-}" 2>/dev/null); do
361 case "$is_hash,$i" in
362 y,*) is_hash=n ;;
363 n,*^{}) is_hash=y ;;
364 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
365 n,*) is_hash=y; echo "$i" ;;
366 esac
367 done
370 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
371 __git_tags ()
373 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
374 if [ -d "$dir" ]; then
375 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
376 refs/tags
377 return
379 for i in $(git ls-remote "${1-}" 2>/dev/null); do
380 case "$is_hash,$i" in
381 y,*) is_hash=n ;;
382 n,*^{}) is_hash=y ;;
383 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
384 n,*) is_hash=y; echo "$i" ;;
385 esac
386 done
389 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
390 # presence of 2nd argument means use the guess heuristic employed
391 # by checkout for tracking branches
392 __git_refs ()
394 local i is_hash=y dir="$(__gitdir "${1-}")" track="${2-}"
395 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
396 if [ -d "$dir" ]; then
397 case "$cur" in
398 refs|refs/*)
399 format="refname"
400 refs="${cur%/*}"
401 track=""
404 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
405 if [ -e "$dir/$i" ]; then echo $i; fi
406 done
407 format="refname:short"
408 refs="refs/tags refs/heads refs/remotes"
410 esac
411 git --git-dir="$dir" for-each-ref --format="%($format)" \
412 $refs
413 if [ -n "$track" ]; then
414 # employ the heuristic used by git checkout
415 # Try to find a remote branch that matches the completion word
416 # but only output if the branch name is unique
417 local ref entry
418 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
419 "refs/remotes/" | \
420 while read entry; do
421 eval "$entry"
422 ref="${ref#*/}"
423 if [[ "$ref" == "$cur"* ]]; then
424 echo "$ref"
426 done | uniq -u
428 return
430 for i in $(git ls-remote "$dir" 2>/dev/null); do
431 case "$is_hash,$i" in
432 y,*) is_hash=n ;;
433 n,*^{}) is_hash=y ;;
434 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
435 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
436 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
437 n,*) is_hash=y; echo "$i" ;;
438 esac
439 done
442 # __git_refs2 requires 1 argument (to pass to __git_refs)
443 __git_refs2 ()
445 local i
446 for i in $(__git_refs "$1"); do
447 echo "$i:$i"
448 done
451 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
452 __git_refs_remotes ()
454 local cmd i is_hash=y
455 for i in $(git ls-remote "$1" 2>/dev/null); do
456 case "$is_hash,$i" in
457 n,refs/heads/*)
458 is_hash=y
459 echo "$i:refs/remotes/$1/${i#refs/heads/}"
461 y,*) is_hash=n ;;
462 n,*^{}) is_hash=y ;;
463 n,refs/tags/*) is_hash=y;;
464 n,*) is_hash=y; ;;
465 esac
466 done
469 __git_remotes ()
471 local i ngoff IFS=$'\n' d="$(__gitdir)"
472 shopt -q nullglob || ngoff=1
473 shopt -s nullglob
474 for i in "$d/remotes"/*; do
475 echo ${i#$d/remotes/}
476 done
477 [ "$ngoff" ] && shopt -u nullglob
478 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
479 i="${i#remote.}"
480 echo "${i/.url*/}"
481 done
484 __git_list_merge_strategies ()
486 git merge -s help 2>&1 |
487 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
488 s/\.$//
489 s/.*://
490 s/^[ ]*//
491 s/[ ]*$//
496 __git_merge_strategies=
497 # 'git merge -s help' (and thus detection of the merge strategy
498 # list) fails, unfortunately, if run outside of any git working
499 # tree. __git_merge_strategies is set to the empty string in
500 # that case, and the detection will be repeated the next time it
501 # is needed.
502 __git_compute_merge_strategies ()
504 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
507 __git_complete_file ()
509 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
510 case "$cur" in
511 ?*:*)
512 ref="${cur%%:*}"
513 cur="${cur#*:}"
514 case "$cur" in
515 ?*/*)
516 pfx="${cur%/*}"
517 cur="${cur##*/}"
518 ls="$ref:$pfx"
519 pfx="$pfx/"
522 ls="$ref"
524 esac
526 case "$COMP_WORDBREAKS" in
527 *:*) : great ;;
528 *) pfx="$ref:$pfx" ;;
529 esac
531 local IFS=$'\n'
532 COMPREPLY=($(compgen -P "$pfx" \
533 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
534 | sed '/^100... blob /{
535 s,^.* ,,
536 s,$, ,
538 /^120000 blob /{
539 s,^.* ,,
540 s,$, ,
542 /^040000 tree /{
543 s,^.* ,,
544 s,$,/,
546 s/^.* //')" \
547 -- "$cur"))
550 __gitcomp "$(__git_refs)"
552 esac
555 __git_complete_revlist ()
557 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
558 case "$cur" in
559 *...*)
560 pfx="${cur%...*}..."
561 cur="${cur#*...}"
562 __gitcomp "$(__git_refs)" "$pfx" "$cur"
564 *..*)
565 pfx="${cur%..*}.."
566 cur="${cur#*..}"
567 __gitcomp "$(__git_refs)" "$pfx" "$cur"
570 __gitcomp "$(__git_refs)"
572 esac
575 __git_complete_remote_or_refspec ()
577 local cmd="${COMP_WORDS[1]}"
578 local cur="${COMP_WORDS[COMP_CWORD]}"
579 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
580 while [ $c -lt $COMP_CWORD ]; do
581 i="${COMP_WORDS[c]}"
582 case "$i" in
583 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
584 --all)
585 case "$cmd" in
586 push) no_complete_refspec=1 ;;
587 fetch)
588 COMPREPLY=()
589 return
591 *) ;;
592 esac
594 -*) ;;
595 *) remote="$i"; break ;;
596 esac
597 c=$((++c))
598 done
599 if [ -z "$remote" ]; then
600 __gitcomp "$(__git_remotes)"
601 return
603 if [ $no_complete_refspec = 1 ]; then
604 COMPREPLY=()
605 return
607 [ "$remote" = "." ] && remote=
608 case "$cur" in
609 *:*)
610 case "$COMP_WORDBREAKS" in
611 *:*) : great ;;
612 *) pfx="${cur%%:*}:" ;;
613 esac
614 cur="${cur#*:}"
615 lhs=0
618 pfx="+"
619 cur="${cur#+}"
621 esac
622 case "$cmd" in
623 fetch)
624 if [ $lhs = 1 ]; then
625 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
626 else
627 __gitcomp "$(__git_refs)" "$pfx" "$cur"
630 pull)
631 if [ $lhs = 1 ]; then
632 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
633 else
634 __gitcomp "$(__git_refs)" "$pfx" "$cur"
637 push)
638 if [ $lhs = 1 ]; then
639 __gitcomp "$(__git_refs)" "$pfx" "$cur"
640 else
641 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
644 esac
647 __git_complete_strategy ()
649 __git_compute_merge_strategies
650 case "${COMP_WORDS[COMP_CWORD-1]}" in
651 -s|--strategy)
652 __gitcomp "$__git_merge_strategies"
653 return 0
654 esac
655 local cur="${COMP_WORDS[COMP_CWORD]}"
656 case "$cur" in
657 --strategy=*)
658 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
659 return 0
661 esac
662 return 1
665 __git_list_all_commands ()
667 local i IFS=" "$'\n'
668 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
670 case $i in
671 *--*) : helper pattern;;
672 *) echo $i;;
673 esac
674 done
677 __git_all_commands=
678 __git_compute_all_commands ()
680 : ${__git_all_commands:=$(__git_list_all_commands)}
683 __git_list_porcelain_commands ()
685 local i IFS=" "$'\n'
686 __git_compute_all_commands
687 for i in "help" $__git_all_commands
689 case $i in
690 *--*) : helper pattern;;
691 applymbox) : ask gittus;;
692 applypatch) : ask gittus;;
693 archimport) : import;;
694 cat-file) : plumbing;;
695 check-attr) : plumbing;;
696 check-ref-format) : plumbing;;
697 checkout-index) : plumbing;;
698 commit-tree) : plumbing;;
699 count-objects) : infrequent;;
700 cvsexportcommit) : export;;
701 cvsimport) : import;;
702 cvsserver) : daemon;;
703 daemon) : daemon;;
704 diff-files) : plumbing;;
705 diff-index) : plumbing;;
706 diff-tree) : plumbing;;
707 fast-import) : import;;
708 fast-export) : export;;
709 fsck-objects) : plumbing;;
710 fetch-pack) : plumbing;;
711 fmt-merge-msg) : plumbing;;
712 for-each-ref) : plumbing;;
713 hash-object) : plumbing;;
714 http-*) : transport;;
715 index-pack) : plumbing;;
716 init-db) : deprecated;;
717 local-fetch) : plumbing;;
718 lost-found) : infrequent;;
719 ls-files) : plumbing;;
720 ls-remote) : plumbing;;
721 ls-tree) : plumbing;;
722 mailinfo) : plumbing;;
723 mailsplit) : plumbing;;
724 merge-*) : plumbing;;
725 mktree) : plumbing;;
726 mktag) : plumbing;;
727 pack-objects) : plumbing;;
728 pack-redundant) : plumbing;;
729 pack-refs) : plumbing;;
730 parse-remote) : plumbing;;
731 patch-id) : plumbing;;
732 peek-remote) : plumbing;;
733 prune) : plumbing;;
734 prune-packed) : plumbing;;
735 quiltimport) : import;;
736 read-tree) : plumbing;;
737 receive-pack) : plumbing;;
738 remote-*) : transport;;
739 repo-config) : deprecated;;
740 rerere) : plumbing;;
741 rev-list) : plumbing;;
742 rev-parse) : plumbing;;
743 runstatus) : plumbing;;
744 sh-setup) : internal;;
745 shell) : daemon;;
746 show-ref) : plumbing;;
747 send-pack) : plumbing;;
748 show-index) : plumbing;;
749 ssh-*) : transport;;
750 stripspace) : plumbing;;
751 symbolic-ref) : plumbing;;
752 tar-tree) : deprecated;;
753 unpack-file) : plumbing;;
754 unpack-objects) : plumbing;;
755 update-index) : plumbing;;
756 update-ref) : plumbing;;
757 update-server-info) : daemon;;
758 upload-archive) : plumbing;;
759 upload-pack) : plumbing;;
760 write-tree) : plumbing;;
761 var) : infrequent;;
762 verify-pack) : infrequent;;
763 verify-tag) : plumbing;;
764 *) echo $i;;
765 esac
766 done
769 __git_porcelain_commands=
770 __git_compute_porcelain_commands ()
772 __git_compute_all_commands
773 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
776 __git_pretty_aliases ()
778 local i IFS=$'\n'
779 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
780 case "$i" in
781 pretty.*)
782 i="${i#pretty.}"
783 echo "${i/ */}"
785 esac
786 done
789 __git_aliases ()
791 local i IFS=$'\n'
792 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
793 case "$i" in
794 alias.*)
795 i="${i#alias.}"
796 echo "${i/ */}"
798 esac
799 done
802 # __git_aliased_command requires 1 argument
803 __git_aliased_command ()
805 local word cmdline=$(git --git-dir="$(__gitdir)" \
806 config --get "alias.$1")
807 for word in $cmdline; do
808 case "$word" in
809 \!gitk|gitk)
810 echo "gitk"
811 return
813 \!*) : shell command alias ;;
814 -*) : option ;;
815 *=*) : setting env ;;
816 git) : git itself ;;
818 echo "$word"
819 return
820 esac
821 done
824 # __git_find_on_cmdline requires 1 argument
825 __git_find_on_cmdline ()
827 local word subcommand c=1
829 while [ $c -lt $COMP_CWORD ]; do
830 word="${COMP_WORDS[c]}"
831 for subcommand in $1; do
832 if [ "$subcommand" = "$word" ]; then
833 echo "$subcommand"
834 return
836 done
837 c=$((++c))
838 done
841 __git_has_doubledash ()
843 local c=1
844 while [ $c -lt $COMP_CWORD ]; do
845 if [ "--" = "${COMP_WORDS[c]}" ]; then
846 return 0
848 c=$((++c))
849 done
850 return 1
853 __git_whitespacelist="nowarn warn error error-all fix"
855 _git_am ()
857 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
858 if [ -d "$dir"/rebase-apply ]; then
859 __gitcomp "--skip --continue --resolved --abort"
860 return
862 case "$cur" in
863 --whitespace=*)
864 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
865 return
867 --*)
868 __gitcomp "
869 --3way --committer-date-is-author-date --ignore-date
870 --ignore-whitespace --ignore-space-change
871 --interactive --keep --no-utf8 --signoff --utf8
872 --whitespace= --scissors
874 return
875 esac
876 COMPREPLY=()
879 _git_apply ()
881 local cur="${COMP_WORDS[COMP_CWORD]}"
882 case "$cur" in
883 --whitespace=*)
884 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
885 return
887 --*)
888 __gitcomp "
889 --stat --numstat --summary --check --index
890 --cached --index-info --reverse --reject --unidiff-zero
891 --apply --no-add --exclude=
892 --ignore-whitespace --ignore-space-change
893 --whitespace= --inaccurate-eof --verbose
895 return
896 esac
897 COMPREPLY=()
900 _git_add ()
902 __git_has_doubledash && return
904 local cur="${COMP_WORDS[COMP_CWORD]}"
905 case "$cur" in
906 --*)
907 __gitcomp "
908 --interactive --refresh --patch --update --dry-run
909 --ignore-errors --intent-to-add
911 return
912 esac
913 COMPREPLY=()
916 _git_archive ()
918 local cur="${COMP_WORDS[COMP_CWORD]}"
919 case "$cur" in
920 --format=*)
921 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
922 return
924 --remote=*)
925 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
926 return
928 --*)
929 __gitcomp "
930 --format= --list --verbose
931 --prefix= --remote= --exec=
933 return
935 esac
936 __git_complete_file
939 _git_bisect ()
941 __git_has_doubledash && return
943 local subcommands="start bad good skip reset visualize replay log run"
944 local subcommand="$(__git_find_on_cmdline "$subcommands")"
945 if [ -z "$subcommand" ]; then
946 if [ -f "$(__gitdir)"/BISECT_START ]; then
947 __gitcomp "$subcommands"
948 else
949 __gitcomp "replay start"
951 return
954 case "$subcommand" in
955 bad|good|reset|skip|start)
956 __gitcomp "$(__git_refs)"
959 COMPREPLY=()
961 esac
964 _git_branch ()
966 local i c=1 only_local_ref="n" has_r="n"
968 while [ $c -lt $COMP_CWORD ]; do
969 i="${COMP_WORDS[c]}"
970 case "$i" in
971 -d|-m) only_local_ref="y" ;;
972 -r) has_r="y" ;;
973 esac
974 c=$((++c))
975 done
977 case "${COMP_WORDS[COMP_CWORD]}" in
978 --*)
979 __gitcomp "
980 --color --no-color --verbose --abbrev= --no-abbrev
981 --track --no-track --contains --merged --no-merged
982 --set-upstream
986 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
987 __gitcomp "$(__git_heads)"
988 else
989 __gitcomp "$(__git_refs)"
992 esac
995 _git_bundle ()
997 local cmd="${COMP_WORDS[2]}"
998 case "$COMP_CWORD" in
1000 __gitcomp "create list-heads verify unbundle"
1003 # looking for a file
1006 case "$cmd" in
1007 create)
1008 __git_complete_revlist
1010 esac
1012 esac
1015 _git_checkout ()
1017 __git_has_doubledash && return
1019 local cur="${COMP_WORDS[COMP_CWORD]}"
1020 case "$cur" in
1021 --conflict=*)
1022 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1024 --*)
1025 __gitcomp "
1026 --quiet --ours --theirs --track --no-track --merge
1027 --conflict= --orphan --patch
1031 # check if --track, --no-track, or --no-guess was specified
1032 # if so, disable DWIM mode
1033 local flags="--track --no-track --no-guess" track=1
1034 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1035 track=''
1037 __gitcomp "$(__git_refs '' $track)"
1039 esac
1042 _git_cherry ()
1044 __gitcomp "$(__git_refs)"
1047 _git_cherry_pick ()
1049 local cur="${COMP_WORDS[COMP_CWORD]}"
1050 case "$cur" in
1051 --*)
1052 __gitcomp "--edit --no-commit"
1055 __gitcomp "$(__git_refs)"
1057 esac
1060 _git_clean ()
1062 __git_has_doubledash && return
1064 local cur="${COMP_WORDS[COMP_CWORD]}"
1065 case "$cur" in
1066 --*)
1067 __gitcomp "--dry-run --quiet"
1068 return
1070 esac
1071 COMPREPLY=()
1074 _git_clone ()
1076 local cur="${COMP_WORDS[COMP_CWORD]}"
1077 case "$cur" in
1078 --*)
1079 __gitcomp "
1080 --local
1081 --no-hardlinks
1082 --shared
1083 --reference
1084 --quiet
1085 --no-checkout
1086 --bare
1087 --mirror
1088 --origin
1089 --upload-pack
1090 --template=
1091 --depth
1093 return
1095 esac
1096 COMPREPLY=()
1099 _git_commit ()
1101 __git_has_doubledash && return
1103 local cur="${COMP_WORDS[COMP_CWORD]}"
1104 case "$cur" in
1105 --cleanup=*)
1106 __gitcomp "default strip verbatim whitespace
1107 " "" "${cur##--cleanup=}"
1108 return
1110 --reuse-message=*)
1111 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1112 return
1114 --reedit-message=*)
1115 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1116 return
1118 --untracked-files=*)
1119 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1120 return
1122 --*)
1123 __gitcomp "
1124 --all --author= --signoff --verify --no-verify
1125 --edit --amend --include --only --interactive
1126 --dry-run --reuse-message= --reedit-message=
1127 --reset-author --file= --message= --template=
1128 --cleanup= --untracked-files --untracked-files=
1129 --verbose --quiet
1131 return
1132 esac
1133 COMPREPLY=()
1136 _git_describe ()
1138 local cur="${COMP_WORDS[COMP_CWORD]}"
1139 case "$cur" in
1140 --*)
1141 __gitcomp "
1142 --all --tags --contains --abbrev= --candidates=
1143 --exact-match --debug --long --match --always
1145 return
1146 esac
1147 __gitcomp "$(__git_refs)"
1150 __git_diff_common_options="--stat --numstat --shortstat --summary
1151 --patch-with-stat --name-only --name-status --color
1152 --no-color --color-words --no-renames --check
1153 --full-index --binary --abbrev --diff-filter=
1154 --find-copies-harder
1155 --text --ignore-space-at-eol --ignore-space-change
1156 --ignore-all-space --exit-code --quiet --ext-diff
1157 --no-ext-diff
1158 --no-prefix --src-prefix= --dst-prefix=
1159 --inter-hunk-context=
1160 --patience
1161 --raw
1162 --dirstat --dirstat= --dirstat-by-file
1163 --dirstat-by-file= --cumulative
1166 _git_diff ()
1168 __git_has_doubledash && return
1170 local cur="${COMP_WORDS[COMP_CWORD]}"
1171 case "$cur" in
1172 --*)
1173 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1174 --base --ours --theirs --no-index
1175 $__git_diff_common_options
1177 return
1179 esac
1180 __git_complete_file
1183 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1184 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1187 _git_difftool ()
1189 __git_has_doubledash && return
1191 local cur="${COMP_WORDS[COMP_CWORD]}"
1192 case "$cur" in
1193 --tool=*)
1194 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1195 return
1197 --*)
1198 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1199 --base --ours --theirs
1200 --no-renames --diff-filter= --find-copies-harder
1201 --relative --ignore-submodules
1202 --tool="
1203 return
1205 esac
1206 __git_complete_file
1209 __git_fetch_options="
1210 --quiet --verbose --append --upload-pack --force --keep --depth=
1211 --tags --no-tags --all --prune --dry-run
1214 _git_fetch ()
1216 local cur="${COMP_WORDS[COMP_CWORD]}"
1217 case "$cur" in
1218 --*)
1219 __gitcomp "$__git_fetch_options"
1220 return
1222 esac
1223 __git_complete_remote_or_refspec
1226 _git_format_patch ()
1228 local cur="${COMP_WORDS[COMP_CWORD]}"
1229 case "$cur" in
1230 --thread=*)
1231 __gitcomp "
1232 deep shallow
1233 " "" "${cur##--thread=}"
1234 return
1236 --*)
1237 __gitcomp "
1238 --stdout --attach --no-attach --thread --thread=
1239 --output-directory
1240 --numbered --start-number
1241 --numbered-files
1242 --keep-subject
1243 --signoff --signature --no-signature
1244 --in-reply-to= --cc=
1245 --full-index --binary
1246 --not --all
1247 --cover-letter
1248 --no-prefix --src-prefix= --dst-prefix=
1249 --inline --suffix= --ignore-if-in-upstream
1250 --subject-prefix=
1252 return
1254 esac
1255 __git_complete_revlist
1258 _git_fsck ()
1260 local cur="${COMP_WORDS[COMP_CWORD]}"
1261 case "$cur" in
1262 --*)
1263 __gitcomp "
1264 --tags --root --unreachable --cache --no-reflogs --full
1265 --strict --verbose --lost-found
1267 return
1269 esac
1270 COMPREPLY=()
1273 _git_gc ()
1275 local cur="${COMP_WORDS[COMP_CWORD]}"
1276 case "$cur" in
1277 --*)
1278 __gitcomp "--prune --aggressive"
1279 return
1281 esac
1282 COMPREPLY=()
1285 _git_gitk ()
1287 _gitk
1290 _git_grep ()
1292 __git_has_doubledash && return
1294 local cur="${COMP_WORDS[COMP_CWORD]}"
1295 case "$cur" in
1296 --*)
1297 __gitcomp "
1298 --cached
1299 --text --ignore-case --word-regexp --invert-match
1300 --full-name
1301 --extended-regexp --basic-regexp --fixed-strings
1302 --files-with-matches --name-only
1303 --files-without-match
1304 --max-depth
1305 --count
1306 --and --or --not --all-match
1308 return
1310 esac
1312 __gitcomp "$(__git_refs)"
1315 _git_help ()
1317 local cur="${COMP_WORDS[COMP_CWORD]}"
1318 case "$cur" in
1319 --*)
1320 __gitcomp "--all --info --man --web"
1321 return
1323 esac
1324 __git_compute_all_commands
1325 __gitcomp "$__git_all_commands
1326 attributes cli core-tutorial cvs-migration
1327 diffcore gitk glossary hooks ignore modules
1328 repository-layout tutorial tutorial-2
1329 workflows
1333 _git_init ()
1335 local cur="${COMP_WORDS[COMP_CWORD]}"
1336 case "$cur" in
1337 --shared=*)
1338 __gitcomp "
1339 false true umask group all world everybody
1340 " "" "${cur##--shared=}"
1341 return
1343 --*)
1344 __gitcomp "--quiet --bare --template= --shared --shared="
1345 return
1347 esac
1348 COMPREPLY=()
1351 _git_ls_files ()
1353 __git_has_doubledash && return
1355 local cur="${COMP_WORDS[COMP_CWORD]}"
1356 case "$cur" in
1357 --*)
1358 __gitcomp "--cached --deleted --modified --others --ignored
1359 --stage --directory --no-empty-directory --unmerged
1360 --killed --exclude= --exclude-from=
1361 --exclude-per-directory= --exclude-standard
1362 --error-unmatch --with-tree= --full-name
1363 --abbrev --ignored --exclude-per-directory
1365 return
1367 esac
1368 COMPREPLY=()
1371 _git_ls_remote ()
1373 __gitcomp "$(__git_remotes)"
1376 _git_ls_tree ()
1378 __git_complete_file
1381 # Options that go well for log, shortlog and gitk
1382 __git_log_common_options="
1383 --not --all
1384 --branches --tags --remotes
1385 --first-parent --merges --no-merges
1386 --max-count=
1387 --max-age= --since= --after=
1388 --min-age= --until= --before=
1390 # Options that go well for log and gitk (not shortlog)
1391 __git_log_gitk_options="
1392 --dense --sparse --full-history
1393 --simplify-merges --simplify-by-decoration
1394 --left-right
1396 # Options that go well for log and shortlog (not gitk)
1397 __git_log_shortlog_options="
1398 --author= --committer= --grep=
1399 --all-match
1402 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1403 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1405 _git_log ()
1407 __git_has_doubledash && return
1409 local cur="${COMP_WORDS[COMP_CWORD]}"
1410 local g="$(git rev-parse --git-dir 2>/dev/null)"
1411 local merge=""
1412 if [ -f "$g/MERGE_HEAD" ]; then
1413 merge="--merge"
1415 case "$cur" in
1416 --pretty=*)
1417 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1418 " "" "${cur##--pretty=}"
1419 return
1421 --format=*)
1422 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1423 " "" "${cur##--format=}"
1424 return
1426 --date=*)
1427 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1428 return
1430 --decorate=*)
1431 __gitcomp "long short" "" "${cur##--decorate=}"
1432 return
1434 --*)
1435 __gitcomp "
1436 $__git_log_common_options
1437 $__git_log_shortlog_options
1438 $__git_log_gitk_options
1439 --root --topo-order --date-order --reverse
1440 --follow --full-diff
1441 --abbrev-commit --abbrev=
1442 --relative-date --date=
1443 --pretty= --format= --oneline
1444 --cherry-pick
1445 --graph
1446 --decorate --decorate=
1447 --walk-reflogs
1448 --parents --children
1449 $merge
1450 $__git_diff_common_options
1451 --pickaxe-all --pickaxe-regex
1453 return
1455 esac
1456 __git_complete_revlist
1459 __git_merge_options="
1460 --no-commit --no-stat --log --no-log --squash --strategy
1461 --commit --stat --no-squash --ff --no-ff --ff-only
1464 _git_merge ()
1466 __git_complete_strategy && return
1468 local cur="${COMP_WORDS[COMP_CWORD]}"
1469 case "$cur" in
1470 --*)
1471 __gitcomp "$__git_merge_options"
1472 return
1473 esac
1474 __gitcomp "$(__git_refs)"
1477 _git_mergetool ()
1479 local cur="${COMP_WORDS[COMP_CWORD]}"
1480 case "$cur" in
1481 --tool=*)
1482 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1483 return
1485 --*)
1486 __gitcomp "--tool="
1487 return
1489 esac
1490 COMPREPLY=()
1493 _git_merge_base ()
1495 __gitcomp "$(__git_refs)"
1498 _git_mv ()
1500 local cur="${COMP_WORDS[COMP_CWORD]}"
1501 case "$cur" in
1502 --*)
1503 __gitcomp "--dry-run"
1504 return
1506 esac
1507 COMPREPLY=()
1510 _git_name_rev ()
1512 __gitcomp "--tags --all --stdin"
1515 _git_notes ()
1517 local subcommands='add append copy edit list prune remove show'
1518 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1519 local cur="${COMP_WORDS[COMP_CWORD]}"
1521 case "$subcommand,$cur" in
1522 ,--*)
1523 __gitcomp '--ref'
1526 case "${COMP_WORDS[COMP_CWORD-1]}" in
1527 --ref)
1528 __gitcomp "$(__git_refs)"
1531 __gitcomp "$subcommands --ref"
1533 esac
1535 add,--reuse-message=*|append,--reuse-message=*)
1536 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1538 add,--reedit-message=*|append,--reedit-message=*)
1539 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1541 add,--*|append,--*)
1542 __gitcomp '--file= --message= --reedit-message=
1543 --reuse-message='
1545 copy,--*)
1546 __gitcomp '--stdin'
1548 prune,--*)
1549 __gitcomp '--dry-run --verbose'
1551 prune,*)
1554 case "${COMP_WORDS[COMP_CWORD-1]}" in
1555 -m|-F)
1558 __gitcomp "$(__git_refs)"
1560 esac
1562 esac
1565 _git_pull ()
1567 __git_complete_strategy && return
1569 local cur="${COMP_WORDS[COMP_CWORD]}"
1570 case "$cur" in
1571 --*)
1572 __gitcomp "
1573 --rebase --no-rebase
1574 $__git_merge_options
1575 $__git_fetch_options
1577 return
1579 esac
1580 __git_complete_remote_or_refspec
1583 _git_push ()
1585 local cur="${COMP_WORDS[COMP_CWORD]}"
1586 case "${COMP_WORDS[COMP_CWORD-1]}" in
1587 --repo)
1588 __gitcomp "$(__git_remotes)"
1589 return
1590 esac
1591 case "$cur" in
1592 --repo=*)
1593 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1594 return
1596 --*)
1597 __gitcomp "
1598 --all --mirror --tags --dry-run --force --verbose
1599 --receive-pack= --repo=
1601 return
1603 esac
1604 __git_complete_remote_or_refspec
1607 _git_rebase ()
1609 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1610 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1611 __gitcomp "--continue --skip --abort"
1612 return
1614 __git_complete_strategy && return
1615 case "$cur" in
1616 --whitespace=*)
1617 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1618 return
1620 --*)
1621 __gitcomp "
1622 --onto --merge --strategy --interactive
1623 --preserve-merges --stat --no-stat
1624 --committer-date-is-author-date --ignore-date
1625 --ignore-whitespace --whitespace=
1626 --autosquash
1629 return
1630 esac
1631 __gitcomp "$(__git_refs)"
1634 _git_reflog ()
1636 local subcommands="show delete expire"
1637 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1639 if [ -z "$subcommand" ]; then
1640 __gitcomp "$subcommands"
1641 else
1642 __gitcomp "$(__git_refs)"
1646 __git_send_email_confirm_options="always never auto cc compose"
1647 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1649 _git_send_email ()
1651 local cur="${COMP_WORDS[COMP_CWORD]}"
1652 case "$cur" in
1653 --confirm=*)
1654 __gitcomp "
1655 $__git_send_email_confirm_options
1656 " "" "${cur##--confirm=}"
1657 return
1659 --suppress-cc=*)
1660 __gitcomp "
1661 $__git_send_email_suppresscc_options
1662 " "" "${cur##--suppress-cc=}"
1664 return
1666 --smtp-encryption=*)
1667 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1668 return
1670 --*)
1671 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1672 --compose --confirm= --dry-run --envelope-sender
1673 --from --identity
1674 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1675 --no-suppress-from --no-thread --quiet
1676 --signed-off-by-cc --smtp-pass --smtp-server
1677 --smtp-server-port --smtp-encryption= --smtp-user
1678 --subject --suppress-cc= --suppress-from --thread --to
1679 --validate --no-validate"
1680 return
1682 esac
1683 COMPREPLY=()
1686 _git_stage ()
1688 _git_add
1691 __git_config_get_set_variables ()
1693 local prevword word config_file= c=$COMP_CWORD
1694 while [ $c -gt 1 ]; do
1695 word="${COMP_WORDS[c]}"
1696 case "$word" in
1697 --global|--system|--file=*)
1698 config_file="$word"
1699 break
1701 -f|--file)
1702 config_file="$word $prevword"
1703 break
1705 esac
1706 prevword=$word
1707 c=$((--c))
1708 done
1710 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1711 while read line
1713 case "$line" in
1714 *.*=*)
1715 echo "${line/=*/}"
1717 esac
1718 done
1721 _git_config ()
1723 local cur="${COMP_WORDS[COMP_CWORD]}"
1724 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1725 case "$prv" in
1726 branch.*.remote)
1727 __gitcomp "$(__git_remotes)"
1728 return
1730 branch.*.merge)
1731 __gitcomp "$(__git_refs)"
1732 return
1734 remote.*.fetch)
1735 local remote="${prv#remote.}"
1736 remote="${remote%.fetch}"
1737 __gitcomp "$(__git_refs_remotes "$remote")"
1738 return
1740 remote.*.push)
1741 local remote="${prv#remote.}"
1742 remote="${remote%.push}"
1743 __gitcomp "$(git --git-dir="$(__gitdir)" \
1744 for-each-ref --format='%(refname):%(refname)' \
1745 refs/heads)"
1746 return
1748 pull.twohead|pull.octopus)
1749 __git_compute_merge_strategies
1750 __gitcomp "$__git_merge_strategies"
1751 return
1753 color.branch|color.diff|color.interactive|\
1754 color.showbranch|color.status|color.ui)
1755 __gitcomp "always never auto"
1756 return
1758 color.pager)
1759 __gitcomp "false true"
1760 return
1762 color.*.*)
1763 __gitcomp "
1764 normal black red green yellow blue magenta cyan white
1765 bold dim ul blink reverse
1767 return
1769 help.format)
1770 __gitcomp "man info web html"
1771 return
1773 log.date)
1774 __gitcomp "$__git_log_date_formats"
1775 return
1777 sendemail.aliasesfiletype)
1778 __gitcomp "mutt mailrc pine elm gnus"
1779 return
1781 sendemail.confirm)
1782 __gitcomp "$__git_send_email_confirm_options"
1783 return
1785 sendemail.suppresscc)
1786 __gitcomp "$__git_send_email_suppresscc_options"
1787 return
1789 --get|--get-all|--unset|--unset-all)
1790 __gitcomp "$(__git_config_get_set_variables)"
1791 return
1793 *.*)
1794 COMPREPLY=()
1795 return
1797 esac
1798 case "$cur" in
1799 --*)
1800 __gitcomp "
1801 --global --system --file=
1802 --list --replace-all
1803 --get --get-all --get-regexp
1804 --add --unset --unset-all
1805 --remove-section --rename-section
1807 return
1809 branch.*.*)
1810 local pfx="${cur%.*}."
1811 cur="${cur##*.}"
1812 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1813 return
1815 branch.*)
1816 local pfx="${cur%.*}."
1817 cur="${cur#*.}"
1818 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1819 return
1821 guitool.*.*)
1822 local pfx="${cur%.*}."
1823 cur="${cur##*.}"
1824 __gitcomp "
1825 argprompt cmd confirm needsfile noconsole norescan
1826 prompt revprompt revunmerged title
1827 " "$pfx" "$cur"
1828 return
1830 difftool.*.*)
1831 local pfx="${cur%.*}."
1832 cur="${cur##*.}"
1833 __gitcomp "cmd path" "$pfx" "$cur"
1834 return
1836 man.*.*)
1837 local pfx="${cur%.*}."
1838 cur="${cur##*.}"
1839 __gitcomp "cmd path" "$pfx" "$cur"
1840 return
1842 mergetool.*.*)
1843 local pfx="${cur%.*}."
1844 cur="${cur##*.}"
1845 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1846 return
1848 pager.*)
1849 local pfx="${cur%.*}."
1850 cur="${cur#*.}"
1851 __git_compute_all_commands
1852 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1853 return
1855 remote.*.*)
1856 local pfx="${cur%.*}."
1857 cur="${cur##*.}"
1858 __gitcomp "
1859 url proxy fetch push mirror skipDefaultUpdate
1860 receivepack uploadpack tagopt pushurl
1861 " "$pfx" "$cur"
1862 return
1864 remote.*)
1865 local pfx="${cur%.*}."
1866 cur="${cur#*.}"
1867 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1868 return
1870 url.*.*)
1871 local pfx="${cur%.*}."
1872 cur="${cur##*.}"
1873 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1874 return
1876 esac
1877 __gitcomp "
1878 add.ignore-errors
1879 alias.
1880 apply.ignorewhitespace
1881 apply.whitespace
1882 branch.autosetupmerge
1883 branch.autosetuprebase
1884 clean.requireForce
1885 color.branch
1886 color.branch.current
1887 color.branch.local
1888 color.branch.plain
1889 color.branch.remote
1890 color.diff
1891 color.diff.commit
1892 color.diff.frag
1893 color.diff.meta
1894 color.diff.new
1895 color.diff.old
1896 color.diff.plain
1897 color.diff.whitespace
1898 color.grep
1899 color.grep.external
1900 color.grep.match
1901 color.interactive
1902 color.interactive.header
1903 color.interactive.help
1904 color.interactive.prompt
1905 color.pager
1906 color.showbranch
1907 color.status
1908 color.status.added
1909 color.status.changed
1910 color.status.header
1911 color.status.nobranch
1912 color.status.untracked
1913 color.status.updated
1914 color.ui
1915 commit.template
1916 core.autocrlf
1917 core.bare
1918 core.compression
1919 core.createObject
1920 core.deltaBaseCacheLimit
1921 core.editor
1922 core.excludesfile
1923 core.fileMode
1924 core.fsyncobjectfiles
1925 core.gitProxy
1926 core.ignoreCygwinFSTricks
1927 core.ignoreStat
1928 core.logAllRefUpdates
1929 core.loosecompression
1930 core.packedGitLimit
1931 core.packedGitWindowSize
1932 core.pager
1933 core.preferSymlinkRefs
1934 core.preloadindex
1935 core.quotepath
1936 core.repositoryFormatVersion
1937 core.safecrlf
1938 core.sharedRepository
1939 core.symlinks
1940 core.trustctime
1941 core.warnAmbiguousRefs
1942 core.whitespace
1943 core.worktree
1944 diff.autorefreshindex
1945 diff.external
1946 diff.mnemonicprefix
1947 diff.renameLimit
1948 diff.renameLimit.
1949 diff.renames
1950 diff.suppressBlankEmpty
1951 diff.tool
1952 diff.wordRegex
1953 difftool.
1954 difftool.prompt
1955 fetch.unpackLimit
1956 format.attach
1957 format.cc
1958 format.headers
1959 format.numbered
1960 format.pretty
1961 format.signature
1962 format.signoff
1963 format.subjectprefix
1964 format.suffix
1965 format.thread
1966 gc.aggressiveWindow
1967 gc.auto
1968 gc.autopacklimit
1969 gc.packrefs
1970 gc.pruneexpire
1971 gc.reflogexpire
1972 gc.reflogexpireunreachable
1973 gc.rerereresolved
1974 gc.rerereunresolved
1975 gitcvs.allbinary
1976 gitcvs.commitmsgannotation
1977 gitcvs.dbTableNamePrefix
1978 gitcvs.dbdriver
1979 gitcvs.dbname
1980 gitcvs.dbpass
1981 gitcvs.dbuser
1982 gitcvs.enabled
1983 gitcvs.logfile
1984 gitcvs.usecrlfattr
1985 guitool.
1986 gui.blamehistoryctx
1987 gui.commitmsgwidth
1988 gui.copyblamethreshold
1989 gui.diffcontext
1990 gui.encoding
1991 gui.fastcopyblame
1992 gui.matchtrackingbranch
1993 gui.newbranchtemplate
1994 gui.pruneduringfetch
1995 gui.spellingdictionary
1996 gui.trustmtime
1997 help.autocorrect
1998 help.browser
1999 help.format
2000 http.lowSpeedLimit
2001 http.lowSpeedTime
2002 http.maxRequests
2003 http.noEPSV
2004 http.proxy
2005 http.sslCAInfo
2006 http.sslCAPath
2007 http.sslCert
2008 http.sslKey
2009 http.sslVerify
2010 i18n.commitEncoding
2011 i18n.logOutputEncoding
2012 imap.folder
2013 imap.host
2014 imap.pass
2015 imap.port
2016 imap.preformattedHTML
2017 imap.sslverify
2018 imap.tunnel
2019 imap.user
2020 instaweb.browser
2021 instaweb.httpd
2022 instaweb.local
2023 instaweb.modulepath
2024 instaweb.port
2025 interactive.singlekey
2026 log.date
2027 log.showroot
2028 mailmap.file
2029 man.
2030 man.viewer
2031 merge.conflictstyle
2032 merge.log
2033 merge.renameLimit
2034 merge.stat
2035 merge.tool
2036 merge.verbosity
2037 mergetool.
2038 mergetool.keepBackup
2039 mergetool.prompt
2040 pack.compression
2041 pack.deltaCacheLimit
2042 pack.deltaCacheSize
2043 pack.depth
2044 pack.indexVersion
2045 pack.packSizeLimit
2046 pack.threads
2047 pack.window
2048 pack.windowMemory
2049 pager.
2050 pull.octopus
2051 pull.twohead
2052 push.default
2053 rebase.stat
2054 receive.denyCurrentBranch
2055 receive.denyDeletes
2056 receive.denyNonFastForwards
2057 receive.fsckObjects
2058 receive.unpackLimit
2059 repack.usedeltabaseoffset
2060 rerere.autoupdate
2061 rerere.enabled
2062 sendemail.aliasesfile
2063 sendemail.aliasesfiletype
2064 sendemail.bcc
2065 sendemail.cc
2066 sendemail.cccmd
2067 sendemail.chainreplyto
2068 sendemail.confirm
2069 sendemail.envelopesender
2070 sendemail.multiedit
2071 sendemail.signedoffbycc
2072 sendemail.smtpencryption
2073 sendemail.smtppass
2074 sendemail.smtpserver
2075 sendemail.smtpserverport
2076 sendemail.smtpuser
2077 sendemail.suppresscc
2078 sendemail.suppressfrom
2079 sendemail.thread
2080 sendemail.to
2081 sendemail.validate
2082 showbranch.default
2083 status.relativePaths
2084 status.showUntrackedFiles
2085 tar.umask
2086 transfer.unpackLimit
2087 url.
2088 user.email
2089 user.name
2090 user.signingkey
2091 web.browser
2092 branch. remote.
2096 _git_remote ()
2098 local subcommands="add rename rm show prune update set-head"
2099 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2100 if [ -z "$subcommand" ]; then
2101 __gitcomp "$subcommands"
2102 return
2105 case "$subcommand" in
2106 rename|rm|show|prune)
2107 __gitcomp "$(__git_remotes)"
2109 update)
2110 local i c='' IFS=$'\n'
2111 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2112 i="${i#remotes.}"
2113 c="$c ${i/ */}"
2114 done
2115 __gitcomp "$c"
2118 COMPREPLY=()
2120 esac
2123 _git_replace ()
2125 __gitcomp "$(__git_refs)"
2128 _git_reset ()
2130 __git_has_doubledash && return
2132 local cur="${COMP_WORDS[COMP_CWORD]}"
2133 case "$cur" in
2134 --*)
2135 __gitcomp "--merge --mixed --hard --soft --patch"
2136 return
2138 esac
2139 __gitcomp "$(__git_refs)"
2142 _git_revert ()
2144 local cur="${COMP_WORDS[COMP_CWORD]}"
2145 case "$cur" in
2146 --*)
2147 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2148 return
2150 esac
2151 __gitcomp "$(__git_refs)"
2154 _git_rm ()
2156 __git_has_doubledash && return
2158 local cur="${COMP_WORDS[COMP_CWORD]}"
2159 case "$cur" in
2160 --*)
2161 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2162 return
2164 esac
2165 COMPREPLY=()
2168 _git_shortlog ()
2170 __git_has_doubledash && return
2172 local cur="${COMP_WORDS[COMP_CWORD]}"
2173 case "$cur" in
2174 --*)
2175 __gitcomp "
2176 $__git_log_common_options
2177 $__git_log_shortlog_options
2178 --numbered --summary
2180 return
2182 esac
2183 __git_complete_revlist
2186 _git_show ()
2188 __git_has_doubledash && return
2190 local cur="${COMP_WORDS[COMP_CWORD]}"
2191 case "$cur" in
2192 --pretty=*)
2193 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2194 " "" "${cur##--pretty=}"
2195 return
2197 --format=*)
2198 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2199 " "" "${cur##--format=}"
2200 return
2202 --*)
2203 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2204 $__git_diff_common_options
2206 return
2208 esac
2209 __git_complete_file
2212 _git_show_branch ()
2214 local cur="${COMP_WORDS[COMP_CWORD]}"
2215 case "$cur" in
2216 --*)
2217 __gitcomp "
2218 --all --remotes --topo-order --current --more=
2219 --list --independent --merge-base --no-name
2220 --color --no-color
2221 --sha1-name --sparse --topics --reflog
2223 return
2225 esac
2226 __git_complete_revlist
2229 _git_stash ()
2231 local cur="${COMP_WORDS[COMP_CWORD]}"
2232 local save_opts='--keep-index --no-keep-index --quiet --patch'
2233 local subcommands='save list show apply clear drop pop create branch'
2234 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2235 if [ -z "$subcommand" ]; then
2236 case "$cur" in
2237 --*)
2238 __gitcomp "$save_opts"
2241 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2242 __gitcomp "$subcommands"
2243 else
2244 COMPREPLY=()
2247 esac
2248 else
2249 case "$subcommand,$cur" in
2250 save,--*)
2251 __gitcomp "$save_opts"
2253 apply,--*|pop,--*)
2254 __gitcomp "--index --quiet"
2256 show,--*|drop,--*|branch,--*)
2257 COMPREPLY=()
2259 show,*|apply,*|drop,*|pop,*|branch,*)
2260 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2261 | sed -n -e 's/:.*//p')"
2264 COMPREPLY=()
2266 esac
2270 _git_submodule ()
2272 __git_has_doubledash && return
2274 local subcommands="add status init update summary foreach sync"
2275 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2276 local cur="${COMP_WORDS[COMP_CWORD]}"
2277 case "$cur" in
2278 --*)
2279 __gitcomp "--quiet --cached"
2282 __gitcomp "$subcommands"
2284 esac
2285 return
2289 _git_svn ()
2291 local subcommands="
2292 init fetch clone rebase dcommit log find-rev
2293 set-tree commit-diff info create-ignore propget
2294 proplist show-ignore show-externals branch tag blame
2295 migrate mkdirs reset gc
2297 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2298 if [ -z "$subcommand" ]; then
2299 __gitcomp "$subcommands"
2300 else
2301 local remote_opts="--username= --config-dir= --no-auth-cache"
2302 local fc_opts="
2303 --follow-parent --authors-file= --repack=
2304 --no-metadata --use-svm-props --use-svnsync-props
2305 --log-window-size= --no-checkout --quiet
2306 --repack-flags --use-log-author --localtime
2307 --ignore-paths= $remote_opts
2309 local init_opts="
2310 --template= --shared= --trunk= --tags=
2311 --branches= --stdlayout --minimize-url
2312 --no-metadata --use-svm-props --use-svnsync-props
2313 --rewrite-root= --prefix= --use-log-author
2314 --add-author-from $remote_opts
2316 local cmt_opts="
2317 --edit --rmdir --find-copies-harder --copy-similarity=
2320 local cur="${COMP_WORDS[COMP_CWORD]}"
2321 case "$subcommand,$cur" in
2322 fetch,--*)
2323 __gitcomp "--revision= --fetch-all $fc_opts"
2325 clone,--*)
2326 __gitcomp "--revision= $fc_opts $init_opts"
2328 init,--*)
2329 __gitcomp "$init_opts"
2331 dcommit,--*)
2332 __gitcomp "
2333 --merge --strategy= --verbose --dry-run
2334 --fetch-all --no-rebase --commit-url
2335 --revision $cmt_opts $fc_opts
2338 set-tree,--*)
2339 __gitcomp "--stdin $cmt_opts $fc_opts"
2341 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2342 show-externals,--*|mkdirs,--*)
2343 __gitcomp "--revision="
2345 log,--*)
2346 __gitcomp "
2347 --limit= --revision= --verbose --incremental
2348 --oneline --show-commit --non-recursive
2349 --authors-file= --color
2352 rebase,--*)
2353 __gitcomp "
2354 --merge --verbose --strategy= --local
2355 --fetch-all --dry-run $fc_opts
2358 commit-diff,--*)
2359 __gitcomp "--message= --file= --revision= $cmt_opts"
2361 info,--*)
2362 __gitcomp "--url"
2364 branch,--*)
2365 __gitcomp "--dry-run --message --tag"
2367 tag,--*)
2368 __gitcomp "--dry-run --message"
2370 blame,--*)
2371 __gitcomp "--git-format"
2373 migrate,--*)
2374 __gitcomp "
2375 --config-dir= --ignore-paths= --minimize
2376 --no-auth-cache --username=
2379 reset,--*)
2380 __gitcomp "--revision= --parent"
2383 COMPREPLY=()
2385 esac
2389 _git_tag ()
2391 local i c=1 f=0
2392 while [ $c -lt $COMP_CWORD ]; do
2393 i="${COMP_WORDS[c]}"
2394 case "$i" in
2395 -d|-v)
2396 __gitcomp "$(__git_tags)"
2397 return
2402 esac
2403 c=$((++c))
2404 done
2406 case "${COMP_WORDS[COMP_CWORD-1]}" in
2407 -m|-F)
2408 COMPREPLY=()
2410 -*|tag)
2411 if [ $f = 1 ]; then
2412 __gitcomp "$(__git_tags)"
2413 else
2414 COMPREPLY=()
2418 __gitcomp "$(__git_refs)"
2420 esac
2423 _git_whatchanged ()
2425 _git_log
2428 _git ()
2430 local i c=1 command __git_dir
2432 if [[ -n ${ZSH_VERSION-} ]]; then
2433 emulate -L bash
2434 setopt KSH_TYPESET
2437 while [ $c -lt $COMP_CWORD ]; do
2438 i="${COMP_WORDS[c]}"
2439 case "$i" in
2440 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2441 --bare) __git_dir="." ;;
2442 --version|-p|--paginate) ;;
2443 --help) command="help"; break ;;
2444 *) command="$i"; break ;;
2445 esac
2446 c=$((++c))
2447 done
2449 if [ -z "$command" ]; then
2450 case "${COMP_WORDS[COMP_CWORD]}" in
2451 --*) __gitcomp "
2452 --paginate
2453 --no-pager
2454 --git-dir=
2455 --bare
2456 --version
2457 --exec-path
2458 --html-path
2459 --work-tree=
2460 --help
2463 *) __git_compute_porcelain_commands
2464 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2465 esac
2466 return
2469 local completion_func="_git_${command//-/_}"
2470 declare -f $completion_func >/dev/null && $completion_func && return
2472 local expansion=$(__git_aliased_command "$command")
2473 if [ -n "$expansion" ]; then
2474 completion_func="_git_${expansion//-/_}"
2475 declare -f $completion_func >/dev/null && $completion_func
2479 _gitk ()
2481 if [[ -n ${ZSH_VERSION-} ]]; then
2482 emulate -L bash
2483 setopt KSH_TYPESET
2486 __git_has_doubledash && return
2488 local cur="${COMP_WORDS[COMP_CWORD]}"
2489 local g="$(__gitdir)"
2490 local merge=""
2491 if [ -f "$g/MERGE_HEAD" ]; then
2492 merge="--merge"
2494 case "$cur" in
2495 --*)
2496 __gitcomp "
2497 $__git_log_common_options
2498 $__git_log_gitk_options
2499 $merge
2501 return
2503 esac
2504 __git_complete_revlist
2507 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2508 || complete -o default -o nospace -F _git git
2509 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2510 || complete -o default -o nospace -F _gitk gitk
2512 # The following are necessary only for Cygwin, and only are needed
2513 # when the user has tab-completed the executable name and consequently
2514 # included the '.exe' suffix.
2516 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2517 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2518 || complete -o default -o nospace -F _git git.exe
2521 if [[ -n ${ZSH_VERSION-} ]]; then
2522 shopt () {
2523 local option
2524 if [ $# -ne 2 ]; then
2525 echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2526 return 1
2528 case "$2" in
2529 nullglob)
2530 option="$2"
2533 echo "$0: invalid option: $2" >&2
2534 return 1
2535 esac
2536 case "$1" in
2537 -q) setopt | grep -q "$option" ;;
2538 -u) unsetopt "$option" ;;
2539 -s) setopt "$option" ;;
2541 echo "$0: invalid flag: $1" >&2
2542 return 1
2543 esac