Merge branch 'kb/maint-rebase-autosquash'
[git/kirr.git] / contrib / completion / git-completion.bash
blobf71046947febee2cacfd2a9ed2e0746582a5e54f
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 --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 reflog) : plumbing;;
739 remote-*) : transport;;
740 repo-config) : deprecated;;
741 rerere) : plumbing;;
742 rev-list) : plumbing;;
743 rev-parse) : plumbing;;
744 runstatus) : plumbing;;
745 sh-setup) : internal;;
746 shell) : daemon;;
747 show-ref) : plumbing;;
748 send-pack) : plumbing;;
749 show-index) : plumbing;;
750 ssh-*) : transport;;
751 stripspace) : plumbing;;
752 symbolic-ref) : plumbing;;
753 tar-tree) : deprecated;;
754 unpack-file) : plumbing;;
755 unpack-objects) : plumbing;;
756 update-index) : plumbing;;
757 update-ref) : plumbing;;
758 update-server-info) : daemon;;
759 upload-archive) : plumbing;;
760 upload-pack) : plumbing;;
761 write-tree) : plumbing;;
762 var) : infrequent;;
763 verify-pack) : infrequent;;
764 verify-tag) : plumbing;;
765 *) echo $i;;
766 esac
767 done
770 __git_porcelain_commands=
771 __git_compute_porcelain_commands ()
773 __git_compute_all_commands
774 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
777 __git_pretty_aliases ()
779 local i IFS=$'\n'
780 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
781 case "$i" in
782 pretty.*)
783 i="${i#pretty.}"
784 echo "${i/ */}"
786 esac
787 done
790 __git_aliases ()
792 local i IFS=$'\n'
793 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
794 case "$i" in
795 alias.*)
796 i="${i#alias.}"
797 echo "${i/ */}"
799 esac
800 done
803 # __git_aliased_command requires 1 argument
804 __git_aliased_command ()
806 local word cmdline=$(git --git-dir="$(__gitdir)" \
807 config --get "alias.$1")
808 for word in $cmdline; do
809 case "$word" in
810 \!gitk|gitk)
811 echo "gitk"
812 return
814 \!*) : shell command alias ;;
815 -*) : option ;;
816 *=*) : setting env ;;
817 git) : git itself ;;
819 echo "$word"
820 return
821 esac
822 done
825 # __git_find_on_cmdline requires 1 argument
826 __git_find_on_cmdline ()
828 local word subcommand c=1
830 while [ $c -lt $COMP_CWORD ]; do
831 word="${COMP_WORDS[c]}"
832 for subcommand in $1; do
833 if [ "$subcommand" = "$word" ]; then
834 echo "$subcommand"
835 return
837 done
838 c=$((++c))
839 done
842 __git_has_doubledash ()
844 local c=1
845 while [ $c -lt $COMP_CWORD ]; do
846 if [ "--" = "${COMP_WORDS[c]}" ]; then
847 return 0
849 c=$((++c))
850 done
851 return 1
854 __git_whitespacelist="nowarn warn error error-all fix"
856 _git_am ()
858 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
859 if [ -d "$dir"/rebase-apply ]; then
860 __gitcomp "--skip --continue --resolved --abort"
861 return
863 case "$cur" in
864 --whitespace=*)
865 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
866 return
868 --*)
869 __gitcomp "
870 --3way --committer-date-is-author-date --ignore-date
871 --ignore-whitespace --ignore-space-change
872 --interactive --keep --no-utf8 --signoff --utf8
873 --whitespace= --scissors
875 return
876 esac
877 COMPREPLY=()
880 _git_apply ()
882 local cur="${COMP_WORDS[COMP_CWORD]}"
883 case "$cur" in
884 --whitespace=*)
885 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
886 return
888 --*)
889 __gitcomp "
890 --stat --numstat --summary --check --index
891 --cached --index-info --reverse --reject --unidiff-zero
892 --apply --no-add --exclude=
893 --ignore-whitespace --ignore-space-change
894 --whitespace= --inaccurate-eof --verbose
896 return
897 esac
898 COMPREPLY=()
901 _git_add ()
903 __git_has_doubledash && return
905 local cur="${COMP_WORDS[COMP_CWORD]}"
906 case "$cur" in
907 --*)
908 __gitcomp "
909 --interactive --refresh --patch --update --dry-run
910 --ignore-errors --intent-to-add
912 return
913 esac
914 COMPREPLY=()
917 _git_archive ()
919 local cur="${COMP_WORDS[COMP_CWORD]}"
920 case "$cur" in
921 --format=*)
922 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
923 return
925 --remote=*)
926 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
927 return
929 --*)
930 __gitcomp "
931 --format= --list --verbose
932 --prefix= --remote= --exec=
934 return
936 esac
937 __git_complete_file
940 _git_bisect ()
942 __git_has_doubledash && return
944 local subcommands="start bad good skip reset visualize replay log run"
945 local subcommand="$(__git_find_on_cmdline "$subcommands")"
946 if [ -z "$subcommand" ]; then
947 if [ -f "$(__gitdir)"/BISECT_START ]; then
948 __gitcomp "$subcommands"
949 else
950 __gitcomp "replay start"
952 return
955 case "$subcommand" in
956 bad|good|reset|skip|start)
957 __gitcomp "$(__git_refs)"
960 COMPREPLY=()
962 esac
965 _git_branch ()
967 local i c=1 only_local_ref="n" has_r="n"
969 while [ $c -lt $COMP_CWORD ]; do
970 i="${COMP_WORDS[c]}"
971 case "$i" in
972 -d|-m) only_local_ref="y" ;;
973 -r) has_r="y" ;;
974 esac
975 c=$((++c))
976 done
978 case "${COMP_WORDS[COMP_CWORD]}" in
979 --*)
980 __gitcomp "
981 --color --no-color --verbose --abbrev= --no-abbrev
982 --track --no-track --contains --merged --no-merged
983 --set-upstream
987 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
988 __gitcomp "$(__git_heads)"
989 else
990 __gitcomp "$(__git_refs)"
993 esac
996 _git_bundle ()
998 local cmd="${COMP_WORDS[2]}"
999 case "$COMP_CWORD" in
1001 __gitcomp "create list-heads verify unbundle"
1004 # looking for a file
1007 case "$cmd" in
1008 create)
1009 __git_complete_revlist
1011 esac
1013 esac
1016 _git_checkout ()
1018 __git_has_doubledash && return
1020 local cur="${COMP_WORDS[COMP_CWORD]}"
1021 case "$cur" in
1022 --conflict=*)
1023 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1025 --*)
1026 __gitcomp "
1027 --quiet --ours --theirs --track --no-track --merge
1028 --conflict= --orphan --patch
1032 # check if --track, --no-track, or --no-guess was specified
1033 # if so, disable DWIM mode
1034 local flags="--track --no-track --no-guess" track=1
1035 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1036 track=''
1038 __gitcomp "$(__git_refs '' $track)"
1040 esac
1043 _git_cherry ()
1045 __gitcomp "$(__git_refs)"
1048 _git_cherry_pick ()
1050 local cur="${COMP_WORDS[COMP_CWORD]}"
1051 case "$cur" in
1052 --*)
1053 __gitcomp "--edit --no-commit"
1056 __gitcomp "$(__git_refs)"
1058 esac
1061 _git_clean ()
1063 __git_has_doubledash && return
1065 local cur="${COMP_WORDS[COMP_CWORD]}"
1066 case "$cur" in
1067 --*)
1068 __gitcomp "--dry-run --quiet"
1069 return
1071 esac
1072 COMPREPLY=()
1075 _git_clone ()
1077 local cur="${COMP_WORDS[COMP_CWORD]}"
1078 case "$cur" in
1079 --*)
1080 __gitcomp "
1081 --local
1082 --no-hardlinks
1083 --shared
1084 --reference
1085 --quiet
1086 --no-checkout
1087 --bare
1088 --mirror
1089 --origin
1090 --upload-pack
1091 --template=
1092 --depth
1094 return
1096 esac
1097 COMPREPLY=()
1100 _git_commit ()
1102 __git_has_doubledash && return
1104 local cur="${COMP_WORDS[COMP_CWORD]}"
1105 case "$cur" in
1106 --cleanup=*)
1107 __gitcomp "default strip verbatim whitespace
1108 " "" "${cur##--cleanup=}"
1109 return
1111 --reuse-message=*)
1112 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1113 return
1115 --reedit-message=*)
1116 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1117 return
1119 --untracked-files=*)
1120 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1121 return
1123 --*)
1124 __gitcomp "
1125 --all --author= --signoff --verify --no-verify
1126 --edit --amend --include --only --interactive
1127 --dry-run --reuse-message= --reedit-message=
1128 --reset-author --file= --message= --template=
1129 --cleanup= --untracked-files --untracked-files=
1130 --verbose --quiet
1132 return
1133 esac
1134 COMPREPLY=()
1137 _git_describe ()
1139 local cur="${COMP_WORDS[COMP_CWORD]}"
1140 case "$cur" in
1141 --*)
1142 __gitcomp "
1143 --all --tags --contains --abbrev= --candidates=
1144 --exact-match --debug --long --match --always
1146 return
1147 esac
1148 __gitcomp "$(__git_refs)"
1151 __git_diff_common_options="--stat --numstat --shortstat --summary
1152 --patch-with-stat --name-only --name-status --color
1153 --no-color --color-words --no-renames --check
1154 --full-index --binary --abbrev --diff-filter=
1155 --find-copies-harder
1156 --text --ignore-space-at-eol --ignore-space-change
1157 --ignore-all-space --exit-code --quiet --ext-diff
1158 --no-ext-diff
1159 --no-prefix --src-prefix= --dst-prefix=
1160 --inter-hunk-context=
1161 --patience
1162 --raw
1163 --dirstat --dirstat= --dirstat-by-file
1164 --dirstat-by-file= --cumulative
1167 _git_diff ()
1169 __git_has_doubledash && return
1171 local cur="${COMP_WORDS[COMP_CWORD]}"
1172 case "$cur" in
1173 --*)
1174 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1175 --base --ours --theirs --no-index
1176 $__git_diff_common_options
1178 return
1180 esac
1181 __git_complete_file
1184 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1185 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1188 _git_difftool ()
1190 __git_has_doubledash && return
1192 local cur="${COMP_WORDS[COMP_CWORD]}"
1193 case "$cur" in
1194 --tool=*)
1195 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1196 return
1198 --*)
1199 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1200 --base --ours --theirs
1201 --no-renames --diff-filter= --find-copies-harder
1202 --relative --ignore-submodules
1203 --tool="
1204 return
1206 esac
1207 __git_complete_file
1210 __git_fetch_options="
1211 --quiet --verbose --append --upload-pack --force --keep --depth=
1212 --tags --no-tags --all --prune --dry-run
1215 _git_fetch ()
1217 local cur="${COMP_WORDS[COMP_CWORD]}"
1218 case "$cur" in
1219 --*)
1220 __gitcomp "$__git_fetch_options"
1221 return
1223 esac
1224 __git_complete_remote_or_refspec
1227 _git_format_patch ()
1229 local cur="${COMP_WORDS[COMP_CWORD]}"
1230 case "$cur" in
1231 --thread=*)
1232 __gitcomp "
1233 deep shallow
1234 " "" "${cur##--thread=}"
1235 return
1237 --*)
1238 __gitcomp "
1239 --stdout --attach --no-attach --thread --thread=
1240 --output-directory
1241 --numbered --start-number
1242 --numbered-files
1243 --keep-subject
1244 --signoff --signature --no-signature
1245 --in-reply-to= --cc=
1246 --full-index --binary
1247 --not --all
1248 --cover-letter
1249 --no-prefix --src-prefix= --dst-prefix=
1250 --inline --suffix= --ignore-if-in-upstream
1251 --subject-prefix=
1253 return
1255 esac
1256 __git_complete_revlist
1259 _git_fsck ()
1261 local cur="${COMP_WORDS[COMP_CWORD]}"
1262 case "$cur" in
1263 --*)
1264 __gitcomp "
1265 --tags --root --unreachable --cache --no-reflogs --full
1266 --strict --verbose --lost-found
1268 return
1270 esac
1271 COMPREPLY=()
1274 _git_gc ()
1276 local cur="${COMP_WORDS[COMP_CWORD]}"
1277 case "$cur" in
1278 --*)
1279 __gitcomp "--prune --aggressive"
1280 return
1282 esac
1283 COMPREPLY=()
1286 _git_gitk ()
1288 _gitk
1291 _git_grep ()
1293 __git_has_doubledash && return
1295 local cur="${COMP_WORDS[COMP_CWORD]}"
1296 case "$cur" in
1297 --*)
1298 __gitcomp "
1299 --cached
1300 --text --ignore-case --word-regexp --invert-match
1301 --full-name
1302 --extended-regexp --basic-regexp --fixed-strings
1303 --files-with-matches --name-only
1304 --files-without-match
1305 --max-depth
1306 --count
1307 --and --or --not --all-match
1309 return
1311 esac
1313 __gitcomp "$(__git_refs)"
1316 _git_help ()
1318 local cur="${COMP_WORDS[COMP_CWORD]}"
1319 case "$cur" in
1320 --*)
1321 __gitcomp "--all --info --man --web"
1322 return
1324 esac
1325 __git_compute_all_commands
1326 __gitcomp "$__git_all_commands
1327 attributes cli core-tutorial cvs-migration
1328 diffcore gitk glossary hooks ignore modules
1329 repository-layout tutorial tutorial-2
1330 workflows
1334 _git_init ()
1336 local cur="${COMP_WORDS[COMP_CWORD]}"
1337 case "$cur" in
1338 --shared=*)
1339 __gitcomp "
1340 false true umask group all world everybody
1341 " "" "${cur##--shared=}"
1342 return
1344 --*)
1345 __gitcomp "--quiet --bare --template= --shared --shared="
1346 return
1348 esac
1349 COMPREPLY=()
1352 _git_ls_files ()
1354 __git_has_doubledash && return
1356 local cur="${COMP_WORDS[COMP_CWORD]}"
1357 case "$cur" in
1358 --*)
1359 __gitcomp "--cached --deleted --modified --others --ignored
1360 --stage --directory --no-empty-directory --unmerged
1361 --killed --exclude= --exclude-from=
1362 --exclude-per-directory= --exclude-standard
1363 --error-unmatch --with-tree= --full-name
1364 --abbrev --ignored --exclude-per-directory
1366 return
1368 esac
1369 COMPREPLY=()
1372 _git_ls_remote ()
1374 __gitcomp "$(__git_remotes)"
1377 _git_ls_tree ()
1379 __git_complete_file
1382 # Options that go well for log, shortlog and gitk
1383 __git_log_common_options="
1384 --not --all
1385 --branches --tags --remotes
1386 --first-parent --merges --no-merges
1387 --max-count=
1388 --max-age= --since= --after=
1389 --min-age= --until= --before=
1391 # Options that go well for log and gitk (not shortlog)
1392 __git_log_gitk_options="
1393 --dense --sparse --full-history
1394 --simplify-merges --simplify-by-decoration
1395 --left-right
1397 # Options that go well for log and shortlog (not gitk)
1398 __git_log_shortlog_options="
1399 --author= --committer= --grep=
1400 --all-match
1403 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1404 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1406 _git_log ()
1408 __git_has_doubledash && return
1410 local cur="${COMP_WORDS[COMP_CWORD]}"
1411 local g="$(git rev-parse --git-dir 2>/dev/null)"
1412 local merge=""
1413 if [ -f "$g/MERGE_HEAD" ]; then
1414 merge="--merge"
1416 case "$cur" in
1417 --pretty=*)
1418 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1419 " "" "${cur##--pretty=}"
1420 return
1422 --format=*)
1423 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1424 " "" "${cur##--format=}"
1425 return
1427 --date=*)
1428 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1429 return
1431 --decorate=*)
1432 __gitcomp "long short" "" "${cur##--decorate=}"
1433 return
1435 --*)
1436 __gitcomp "
1437 $__git_log_common_options
1438 $__git_log_shortlog_options
1439 $__git_log_gitk_options
1440 --root --topo-order --date-order --reverse
1441 --follow --full-diff
1442 --abbrev-commit --abbrev=
1443 --relative-date --date=
1444 --pretty= --format= --oneline
1445 --cherry-pick
1446 --graph
1447 --decorate --decorate=
1448 --walk-reflogs
1449 --parents --children
1450 $merge
1451 $__git_diff_common_options
1452 --pickaxe-all --pickaxe-regex
1454 return
1456 esac
1457 __git_complete_revlist
1460 __git_merge_options="
1461 --no-commit --no-stat --log --no-log --squash --strategy
1462 --commit --stat --no-squash --ff --no-ff --ff-only
1465 _git_merge ()
1467 __git_complete_strategy && return
1469 local cur="${COMP_WORDS[COMP_CWORD]}"
1470 case "$cur" in
1471 --*)
1472 __gitcomp "$__git_merge_options"
1473 return
1474 esac
1475 __gitcomp "$(__git_refs)"
1478 _git_mergetool ()
1480 local cur="${COMP_WORDS[COMP_CWORD]}"
1481 case "$cur" in
1482 --tool=*)
1483 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1484 return
1486 --*)
1487 __gitcomp "--tool="
1488 return
1490 esac
1491 COMPREPLY=()
1494 _git_merge_base ()
1496 __gitcomp "$(__git_refs)"
1499 _git_mv ()
1501 local cur="${COMP_WORDS[COMP_CWORD]}"
1502 case "$cur" in
1503 --*)
1504 __gitcomp "--dry-run"
1505 return
1507 esac
1508 COMPREPLY=()
1511 _git_name_rev ()
1513 __gitcomp "--tags --all --stdin"
1516 _git_notes ()
1518 local subcommands='add append copy edit list prune remove show'
1519 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1520 local cur="${COMP_WORDS[COMP_CWORD]}"
1522 case "$subcommand,$cur" in
1523 ,--*)
1524 __gitcomp '--ref'
1527 case "${COMP_WORDS[COMP_CWORD-1]}" in
1528 --ref)
1529 __gitcomp "$(__git_refs)"
1532 __gitcomp "$subcommands --ref"
1534 esac
1536 add,--reuse-message=*|append,--reuse-message=*)
1537 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1539 add,--reedit-message=*|append,--reedit-message=*)
1540 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1542 add,--*|append,--*)
1543 __gitcomp '--file= --message= --reedit-message=
1544 --reuse-message='
1546 copy,--*)
1547 __gitcomp '--stdin'
1549 prune,--*)
1550 __gitcomp '--dry-run --verbose'
1552 prune,*)
1555 case "${COMP_WORDS[COMP_CWORD-1]}" in
1556 -m|-F)
1559 __gitcomp "$(__git_refs)"
1561 esac
1563 esac
1566 _git_pull ()
1568 __git_complete_strategy && return
1570 local cur="${COMP_WORDS[COMP_CWORD]}"
1571 case "$cur" in
1572 --*)
1573 __gitcomp "
1574 --rebase --no-rebase
1575 $__git_merge_options
1576 $__git_fetch_options
1578 return
1580 esac
1581 __git_complete_remote_or_refspec
1584 _git_push ()
1586 local cur="${COMP_WORDS[COMP_CWORD]}"
1587 case "${COMP_WORDS[COMP_CWORD-1]}" in
1588 --repo)
1589 __gitcomp "$(__git_remotes)"
1590 return
1591 esac
1592 case "$cur" in
1593 --repo=*)
1594 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1595 return
1597 --*)
1598 __gitcomp "
1599 --all --mirror --tags --dry-run --force --verbose
1600 --receive-pack= --repo=
1602 return
1604 esac
1605 __git_complete_remote_or_refspec
1608 _git_rebase ()
1610 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1611 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1612 __gitcomp "--continue --skip --abort"
1613 return
1615 __git_complete_strategy && return
1616 case "$cur" in
1617 --whitespace=*)
1618 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1619 return
1621 --*)
1622 __gitcomp "
1623 --onto --merge --strategy --interactive
1624 --preserve-merges --stat --no-stat
1625 --committer-date-is-author-date --ignore-date
1626 --ignore-whitespace --whitespace=
1627 --autosquash
1630 return
1631 esac
1632 __gitcomp "$(__git_refs)"
1635 __git_send_email_confirm_options="always never auto cc compose"
1636 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1638 _git_send_email ()
1640 local cur="${COMP_WORDS[COMP_CWORD]}"
1641 case "$cur" in
1642 --confirm=*)
1643 __gitcomp "
1644 $__git_send_email_confirm_options
1645 " "" "${cur##--confirm=}"
1646 return
1648 --suppress-cc=*)
1649 __gitcomp "
1650 $__git_send_email_suppresscc_options
1651 " "" "${cur##--suppress-cc=}"
1653 return
1655 --smtp-encryption=*)
1656 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1657 return
1659 --*)
1660 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1661 --compose --confirm= --dry-run --envelope-sender
1662 --from --identity
1663 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1664 --no-suppress-from --no-thread --quiet
1665 --signed-off-by-cc --smtp-pass --smtp-server
1666 --smtp-server-port --smtp-encryption= --smtp-user
1667 --subject --suppress-cc= --suppress-from --thread --to
1668 --validate --no-validate"
1669 return
1671 esac
1672 COMPREPLY=()
1675 _git_stage ()
1677 _git_add
1680 __git_config_get_set_variables ()
1682 local prevword word config_file= c=$COMP_CWORD
1683 while [ $c -gt 1 ]; do
1684 word="${COMP_WORDS[c]}"
1685 case "$word" in
1686 --global|--system|--file=*)
1687 config_file="$word"
1688 break
1690 -f|--file)
1691 config_file="$word $prevword"
1692 break
1694 esac
1695 prevword=$word
1696 c=$((--c))
1697 done
1699 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1700 while read line
1702 case "$line" in
1703 *.*=*)
1704 echo "${line/=*/}"
1706 esac
1707 done
1710 _git_config ()
1712 local cur="${COMP_WORDS[COMP_CWORD]}"
1713 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1714 case "$prv" in
1715 branch.*.remote)
1716 __gitcomp "$(__git_remotes)"
1717 return
1719 branch.*.merge)
1720 __gitcomp "$(__git_refs)"
1721 return
1723 remote.*.fetch)
1724 local remote="${prv#remote.}"
1725 remote="${remote%.fetch}"
1726 __gitcomp "$(__git_refs_remotes "$remote")"
1727 return
1729 remote.*.push)
1730 local remote="${prv#remote.}"
1731 remote="${remote%.push}"
1732 __gitcomp "$(git --git-dir="$(__gitdir)" \
1733 for-each-ref --format='%(refname):%(refname)' \
1734 refs/heads)"
1735 return
1737 pull.twohead|pull.octopus)
1738 __git_compute_merge_strategies
1739 __gitcomp "$__git_merge_strategies"
1740 return
1742 color.branch|color.diff|color.interactive|\
1743 color.showbranch|color.status|color.ui)
1744 __gitcomp "always never auto"
1745 return
1747 color.pager)
1748 __gitcomp "false true"
1749 return
1751 color.*.*)
1752 __gitcomp "
1753 normal black red green yellow blue magenta cyan white
1754 bold dim ul blink reverse
1756 return
1758 help.format)
1759 __gitcomp "man info web html"
1760 return
1762 log.date)
1763 __gitcomp "$__git_log_date_formats"
1764 return
1766 sendemail.aliasesfiletype)
1767 __gitcomp "mutt mailrc pine elm gnus"
1768 return
1770 sendemail.confirm)
1771 __gitcomp "$__git_send_email_confirm_options"
1772 return
1774 sendemail.suppresscc)
1775 __gitcomp "$__git_send_email_suppresscc_options"
1776 return
1778 --get|--get-all|--unset|--unset-all)
1779 __gitcomp "$(__git_config_get_set_variables)"
1780 return
1782 *.*)
1783 COMPREPLY=()
1784 return
1786 esac
1787 case "$cur" in
1788 --*)
1789 __gitcomp "
1790 --global --system --file=
1791 --list --replace-all
1792 --get --get-all --get-regexp
1793 --add --unset --unset-all
1794 --remove-section --rename-section
1796 return
1798 branch.*.*)
1799 local pfx="${cur%.*}."
1800 cur="${cur##*.}"
1801 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1802 return
1804 branch.*)
1805 local pfx="${cur%.*}."
1806 cur="${cur#*.}"
1807 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1808 return
1810 guitool.*.*)
1811 local pfx="${cur%.*}."
1812 cur="${cur##*.}"
1813 __gitcomp "
1814 argprompt cmd confirm needsfile noconsole norescan
1815 prompt revprompt revunmerged title
1816 " "$pfx" "$cur"
1817 return
1819 difftool.*.*)
1820 local pfx="${cur%.*}."
1821 cur="${cur##*.}"
1822 __gitcomp "cmd path" "$pfx" "$cur"
1823 return
1825 man.*.*)
1826 local pfx="${cur%.*}."
1827 cur="${cur##*.}"
1828 __gitcomp "cmd path" "$pfx" "$cur"
1829 return
1831 mergetool.*.*)
1832 local pfx="${cur%.*}."
1833 cur="${cur##*.}"
1834 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1835 return
1837 pager.*)
1838 local pfx="${cur%.*}."
1839 cur="${cur#*.}"
1840 __git_compute_all_commands
1841 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1842 return
1844 remote.*.*)
1845 local pfx="${cur%.*}."
1846 cur="${cur##*.}"
1847 __gitcomp "
1848 url proxy fetch push mirror skipDefaultUpdate
1849 receivepack uploadpack tagopt pushurl
1850 " "$pfx" "$cur"
1851 return
1853 remote.*)
1854 local pfx="${cur%.*}."
1855 cur="${cur#*.}"
1856 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1857 return
1859 url.*.*)
1860 local pfx="${cur%.*}."
1861 cur="${cur##*.}"
1862 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1863 return
1865 esac
1866 __gitcomp "
1867 add.ignore-errors
1868 alias.
1869 apply.ignorewhitespace
1870 apply.whitespace
1871 branch.autosetupmerge
1872 branch.autosetuprebase
1873 clean.requireForce
1874 color.branch
1875 color.branch.current
1876 color.branch.local
1877 color.branch.plain
1878 color.branch.remote
1879 color.diff
1880 color.diff.commit
1881 color.diff.frag
1882 color.diff.meta
1883 color.diff.new
1884 color.diff.old
1885 color.diff.plain
1886 color.diff.whitespace
1887 color.grep
1888 color.grep.external
1889 color.grep.match
1890 color.interactive
1891 color.interactive.header
1892 color.interactive.help
1893 color.interactive.prompt
1894 color.pager
1895 color.showbranch
1896 color.status
1897 color.status.added
1898 color.status.changed
1899 color.status.header
1900 color.status.nobranch
1901 color.status.untracked
1902 color.status.updated
1903 color.ui
1904 commit.template
1905 core.autocrlf
1906 core.bare
1907 core.compression
1908 core.createObject
1909 core.deltaBaseCacheLimit
1910 core.editor
1911 core.excludesfile
1912 core.fileMode
1913 core.fsyncobjectfiles
1914 core.gitProxy
1915 core.ignoreCygwinFSTricks
1916 core.ignoreStat
1917 core.logAllRefUpdates
1918 core.loosecompression
1919 core.packedGitLimit
1920 core.packedGitWindowSize
1921 core.pager
1922 core.preferSymlinkRefs
1923 core.preloadindex
1924 core.quotepath
1925 core.repositoryFormatVersion
1926 core.safecrlf
1927 core.sharedRepository
1928 core.symlinks
1929 core.trustctime
1930 core.warnAmbiguousRefs
1931 core.whitespace
1932 core.worktree
1933 diff.autorefreshindex
1934 diff.external
1935 diff.mnemonicprefix
1936 diff.renameLimit
1937 diff.renameLimit.
1938 diff.renames
1939 diff.suppressBlankEmpty
1940 diff.tool
1941 diff.wordRegex
1942 difftool.
1943 difftool.prompt
1944 fetch.unpackLimit
1945 format.attach
1946 format.cc
1947 format.headers
1948 format.numbered
1949 format.pretty
1950 format.signature
1951 format.signoff
1952 format.subjectprefix
1953 format.suffix
1954 format.thread
1955 gc.aggressiveWindow
1956 gc.auto
1957 gc.autopacklimit
1958 gc.packrefs
1959 gc.pruneexpire
1960 gc.reflogexpire
1961 gc.reflogexpireunreachable
1962 gc.rerereresolved
1963 gc.rerereunresolved
1964 gitcvs.allbinary
1965 gitcvs.commitmsgannotation
1966 gitcvs.dbTableNamePrefix
1967 gitcvs.dbdriver
1968 gitcvs.dbname
1969 gitcvs.dbpass
1970 gitcvs.dbuser
1971 gitcvs.enabled
1972 gitcvs.logfile
1973 gitcvs.usecrlfattr
1974 guitool.
1975 gui.blamehistoryctx
1976 gui.commitmsgwidth
1977 gui.copyblamethreshold
1978 gui.diffcontext
1979 gui.encoding
1980 gui.fastcopyblame
1981 gui.matchtrackingbranch
1982 gui.newbranchtemplate
1983 gui.pruneduringfetch
1984 gui.spellingdictionary
1985 gui.trustmtime
1986 help.autocorrect
1987 help.browser
1988 help.format
1989 http.lowSpeedLimit
1990 http.lowSpeedTime
1991 http.maxRequests
1992 http.noEPSV
1993 http.proxy
1994 http.sslCAInfo
1995 http.sslCAPath
1996 http.sslCert
1997 http.sslKey
1998 http.sslVerify
1999 i18n.commitEncoding
2000 i18n.logOutputEncoding
2001 imap.folder
2002 imap.host
2003 imap.pass
2004 imap.port
2005 imap.preformattedHTML
2006 imap.sslverify
2007 imap.tunnel
2008 imap.user
2009 instaweb.browser
2010 instaweb.httpd
2011 instaweb.local
2012 instaweb.modulepath
2013 instaweb.port
2014 interactive.singlekey
2015 log.date
2016 log.showroot
2017 mailmap.file
2018 man.
2019 man.viewer
2020 merge.conflictstyle
2021 merge.log
2022 merge.renameLimit
2023 merge.stat
2024 merge.tool
2025 merge.verbosity
2026 mergetool.
2027 mergetool.keepBackup
2028 mergetool.prompt
2029 pack.compression
2030 pack.deltaCacheLimit
2031 pack.deltaCacheSize
2032 pack.depth
2033 pack.indexVersion
2034 pack.packSizeLimit
2035 pack.threads
2036 pack.window
2037 pack.windowMemory
2038 pager.
2039 pull.octopus
2040 pull.twohead
2041 push.default
2042 rebase.stat
2043 receive.denyCurrentBranch
2044 receive.denyDeletes
2045 receive.denyNonFastForwards
2046 receive.fsckObjects
2047 receive.unpackLimit
2048 repack.usedeltabaseoffset
2049 rerere.autoupdate
2050 rerere.enabled
2051 sendemail.aliasesfile
2052 sendemail.aliasesfiletype
2053 sendemail.bcc
2054 sendemail.cc
2055 sendemail.cccmd
2056 sendemail.chainreplyto
2057 sendemail.confirm
2058 sendemail.envelopesender
2059 sendemail.multiedit
2060 sendemail.signedoffbycc
2061 sendemail.smtpencryption
2062 sendemail.smtppass
2063 sendemail.smtpserver
2064 sendemail.smtpserverport
2065 sendemail.smtpuser
2066 sendemail.suppresscc
2067 sendemail.suppressfrom
2068 sendemail.thread
2069 sendemail.to
2070 sendemail.validate
2071 showbranch.default
2072 status.relativePaths
2073 status.showUntrackedFiles
2074 tar.umask
2075 transfer.unpackLimit
2076 url.
2077 user.email
2078 user.name
2079 user.signingkey
2080 web.browser
2081 branch. remote.
2085 _git_remote ()
2087 local subcommands="add rename rm show prune update set-head"
2088 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2089 if [ -z "$subcommand" ]; then
2090 __gitcomp "$subcommands"
2091 return
2094 case "$subcommand" in
2095 rename|rm|show|prune)
2096 __gitcomp "$(__git_remotes)"
2098 update)
2099 local i c='' IFS=$'\n'
2100 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2101 i="${i#remotes.}"
2102 c="$c ${i/ */}"
2103 done
2104 __gitcomp "$c"
2107 COMPREPLY=()
2109 esac
2112 _git_replace ()
2114 __gitcomp "$(__git_refs)"
2117 _git_reset ()
2119 __git_has_doubledash && return
2121 local cur="${COMP_WORDS[COMP_CWORD]}"
2122 case "$cur" in
2123 --*)
2124 __gitcomp "--merge --mixed --hard --soft --patch"
2125 return
2127 esac
2128 __gitcomp "$(__git_refs)"
2131 _git_revert ()
2133 local cur="${COMP_WORDS[COMP_CWORD]}"
2134 case "$cur" in
2135 --*)
2136 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2137 return
2139 esac
2140 __gitcomp "$(__git_refs)"
2143 _git_rm ()
2145 __git_has_doubledash && return
2147 local cur="${COMP_WORDS[COMP_CWORD]}"
2148 case "$cur" in
2149 --*)
2150 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2151 return
2153 esac
2154 COMPREPLY=()
2157 _git_shortlog ()
2159 __git_has_doubledash && return
2161 local cur="${COMP_WORDS[COMP_CWORD]}"
2162 case "$cur" in
2163 --*)
2164 __gitcomp "
2165 $__git_log_common_options
2166 $__git_log_shortlog_options
2167 --numbered --summary
2169 return
2171 esac
2172 __git_complete_revlist
2175 _git_show ()
2177 __git_has_doubledash && return
2179 local cur="${COMP_WORDS[COMP_CWORD]}"
2180 case "$cur" in
2181 --pretty=*)
2182 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2183 " "" "${cur##--pretty=}"
2184 return
2186 --format=*)
2187 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2188 " "" "${cur##--format=}"
2189 return
2191 --*)
2192 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2193 $__git_diff_common_options
2195 return
2197 esac
2198 __git_complete_file
2201 _git_show_branch ()
2203 local cur="${COMP_WORDS[COMP_CWORD]}"
2204 case "$cur" in
2205 --*)
2206 __gitcomp "
2207 --all --remotes --topo-order --current --more=
2208 --list --independent --merge-base --no-name
2209 --color --no-color
2210 --sha1-name --sparse --topics --reflog
2212 return
2214 esac
2215 __git_complete_revlist
2218 _git_stash ()
2220 local cur="${COMP_WORDS[COMP_CWORD]}"
2221 local save_opts='--keep-index --no-keep-index --quiet --patch'
2222 local subcommands='save list show apply clear drop pop create branch'
2223 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2224 if [ -z "$subcommand" ]; then
2225 case "$cur" in
2226 --*)
2227 __gitcomp "$save_opts"
2230 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2231 __gitcomp "$subcommands"
2232 else
2233 COMPREPLY=()
2236 esac
2237 else
2238 case "$subcommand,$cur" in
2239 save,--*)
2240 __gitcomp "$save_opts"
2242 apply,--*|pop,--*)
2243 __gitcomp "--index --quiet"
2245 show,--*|drop,--*|branch,--*)
2246 COMPREPLY=()
2248 show,*|apply,*|drop,*|pop,*|branch,*)
2249 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2250 | sed -n -e 's/:.*//p')"
2253 COMPREPLY=()
2255 esac
2259 _git_submodule ()
2261 __git_has_doubledash && return
2263 local subcommands="add status init update summary foreach sync"
2264 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2265 local cur="${COMP_WORDS[COMP_CWORD]}"
2266 case "$cur" in
2267 --*)
2268 __gitcomp "--quiet --cached"
2271 __gitcomp "$subcommands"
2273 esac
2274 return
2278 _git_svn ()
2280 local subcommands="
2281 init fetch clone rebase dcommit log find-rev
2282 set-tree commit-diff info create-ignore propget
2283 proplist show-ignore show-externals branch tag blame
2284 migrate mkdirs reset gc
2286 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2287 if [ -z "$subcommand" ]; then
2288 __gitcomp "$subcommands"
2289 else
2290 local remote_opts="--username= --config-dir= --no-auth-cache"
2291 local fc_opts="
2292 --follow-parent --authors-file= --repack=
2293 --no-metadata --use-svm-props --use-svnsync-props
2294 --log-window-size= --no-checkout --quiet
2295 --repack-flags --use-log-author --localtime
2296 --ignore-paths= $remote_opts
2298 local init_opts="
2299 --template= --shared= --trunk= --tags=
2300 --branches= --stdlayout --minimize-url
2301 --no-metadata --use-svm-props --use-svnsync-props
2302 --rewrite-root= --prefix= --use-log-author
2303 --add-author-from $remote_opts
2305 local cmt_opts="
2306 --edit --rmdir --find-copies-harder --copy-similarity=
2309 local cur="${COMP_WORDS[COMP_CWORD]}"
2310 case "$subcommand,$cur" in
2311 fetch,--*)
2312 __gitcomp "--revision= --fetch-all $fc_opts"
2314 clone,--*)
2315 __gitcomp "--revision= $fc_opts $init_opts"
2317 init,--*)
2318 __gitcomp "$init_opts"
2320 dcommit,--*)
2321 __gitcomp "
2322 --merge --strategy= --verbose --dry-run
2323 --fetch-all --no-rebase --commit-url
2324 --revision $cmt_opts $fc_opts
2327 set-tree,--*)
2328 __gitcomp "--stdin $cmt_opts $fc_opts"
2330 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2331 show-externals,--*|mkdirs,--*)
2332 __gitcomp "--revision="
2334 log,--*)
2335 __gitcomp "
2336 --limit= --revision= --verbose --incremental
2337 --oneline --show-commit --non-recursive
2338 --authors-file= --color
2341 rebase,--*)
2342 __gitcomp "
2343 --merge --verbose --strategy= --local
2344 --fetch-all --dry-run $fc_opts
2347 commit-diff,--*)
2348 __gitcomp "--message= --file= --revision= $cmt_opts"
2350 info,--*)
2351 __gitcomp "--url"
2353 branch,--*)
2354 __gitcomp "--dry-run --message --tag"
2356 tag,--*)
2357 __gitcomp "--dry-run --message"
2359 blame,--*)
2360 __gitcomp "--git-format"
2362 migrate,--*)
2363 __gitcomp "
2364 --config-dir= --ignore-paths= --minimize
2365 --no-auth-cache --username=
2368 reset,--*)
2369 __gitcomp "--revision= --parent"
2372 COMPREPLY=()
2374 esac
2378 _git_tag ()
2380 local i c=1 f=0
2381 while [ $c -lt $COMP_CWORD ]; do
2382 i="${COMP_WORDS[c]}"
2383 case "$i" in
2384 -d|-v)
2385 __gitcomp "$(__git_tags)"
2386 return
2391 esac
2392 c=$((++c))
2393 done
2395 case "${COMP_WORDS[COMP_CWORD-1]}" in
2396 -m|-F)
2397 COMPREPLY=()
2399 -*|tag)
2400 if [ $f = 1 ]; then
2401 __gitcomp "$(__git_tags)"
2402 else
2403 COMPREPLY=()
2407 __gitcomp "$(__git_refs)"
2409 esac
2412 _git_whatchanged ()
2414 _git_log
2417 _git ()
2419 local i c=1 command __git_dir
2421 if [[ -n ${ZSH_VERSION-} ]]; then
2422 emulate -L bash
2423 setopt KSH_TYPESET
2426 while [ $c -lt $COMP_CWORD ]; do
2427 i="${COMP_WORDS[c]}"
2428 case "$i" in
2429 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2430 --bare) __git_dir="." ;;
2431 --version|-p|--paginate) ;;
2432 --help) command="help"; break ;;
2433 *) command="$i"; break ;;
2434 esac
2435 c=$((++c))
2436 done
2438 if [ -z "$command" ]; then
2439 case "${COMP_WORDS[COMP_CWORD]}" in
2440 --*) __gitcomp "
2441 --paginate
2442 --no-pager
2443 --git-dir=
2444 --bare
2445 --version
2446 --exec-path
2447 --html-path
2448 --work-tree=
2449 --help
2452 *) __git_compute_porcelain_commands
2453 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2454 esac
2455 return
2458 local completion_func="_git_${command//-/_}"
2459 declare -f $completion_func >/dev/null && $completion_func && return
2461 local expansion=$(__git_aliased_command "$command")
2462 if [ -n "$expansion" ]; then
2463 completion_func="_git_${expansion//-/_}"
2464 declare -f $completion_func >/dev/null && $completion_func
2468 _gitk ()
2470 if [[ -n ${ZSH_VERSION-} ]]; then
2471 emulate -L bash
2472 setopt KSH_TYPESET
2475 __git_has_doubledash && return
2477 local cur="${COMP_WORDS[COMP_CWORD]}"
2478 local g="$(__gitdir)"
2479 local merge=""
2480 if [ -f "$g/MERGE_HEAD" ]; then
2481 merge="--merge"
2483 case "$cur" in
2484 --*)
2485 __gitcomp "
2486 $__git_log_common_options
2487 $__git_log_gitk_options
2488 $merge
2490 return
2492 esac
2493 __git_complete_revlist
2496 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2497 || complete -o default -o nospace -F _git git
2498 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2499 || complete -o default -o nospace -F _gitk gitk
2501 # The following are necessary only for Cygwin, and only are needed
2502 # when the user has tab-completed the executable name and consequently
2503 # included the '.exe' suffix.
2505 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2506 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2507 || complete -o default -o nospace -F _git git.exe
2510 if [[ -n ${ZSH_VERSION-} ]]; then
2511 shopt () {
2512 local option
2513 if [ $# -ne 2 ]; then
2514 echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2515 return 1
2517 case "$2" in
2518 nullglob)
2519 option="$2"
2522 echo "$0: invalid option: $2" >&2
2523 return 1
2524 esac
2525 case "$1" in
2526 -q) setopt | grep -q "$option" ;;
2527 -u) unsetopt "$option" ;;
2528 -s) setopt "$option" ;;
2530 echo "$0: invalid flag: $1" >&2
2531 return 1
2532 esac