Merge branch 'maint'
[git/gitweb.git] / contrib / completion / git-completion.bash
blobe3ddecc995eb30391639983d9f6f0db7567d7b9a
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 # 3) You may want to make sure the git executable is available
25 # in your PATH before this script is sourced, as some caching
26 # is performed while the script loads. If git isn't found
27 # at source time then all lookups will be done on demand,
28 # which may be slightly slower.
30 # 4) Consider changing your PS1 to also show the current branch:
31 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
33 # The argument to __git_ps1 will be displayed only if you
34 # are currently in a git repository. The %s token will be
35 # the name of the current branch.
37 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
38 # value, unstaged (*) and staged (+) changes will be shown next
39 # to the branch name. You can configure this per-repository
40 # with the bash.showDirtyState variable, which defaults to true
41 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
43 # You can also see if currently something is stashed, by setting
44 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
45 # then a '$' will be shown next to the branch name.
47 # If you would like to see if there're untracked files, then you can
48 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
49 # untracked files, then a '%' will be shown next to the branch name.
51 # To submit patches:
53 # *) Read Documentation/SubmittingPatches
54 # *) Send all patches to the current maintainer:
56 # "Shawn O. Pearce" <spearce@spearce.org>
58 # *) Always CC the Git mailing list:
60 # git@vger.kernel.org
63 case "$COMP_WORDBREAKS" in
64 *:*) : great ;;
65 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
66 esac
68 # __gitdir accepts 0 or 1 arguments (i.e., location)
69 # returns location of .git repo
70 __gitdir ()
72 if [ -z "${1-}" ]; then
73 if [ -n "${__git_dir-}" ]; then
74 echo "$__git_dir"
75 elif [ -d .git ]; then
76 echo .git
77 else
78 git rev-parse --git-dir 2>/dev/null
80 elif [ -d "$1/.git" ]; then
81 echo "$1/.git"
82 else
83 echo "$1"
87 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
88 # returns text to add to bash PS1 prompt (includes branch name)
89 __git_ps1 ()
91 local g="$(__gitdir)"
92 if [ -n "$g" ]; then
93 local r
94 local b
95 if [ -f "$g/rebase-merge/interactive" ]; then
96 r="|REBASE-i"
97 b="$(cat "$g/rebase-merge/head-name")"
98 elif [ -d "$g/rebase-merge" ]; then
99 r="|REBASE-m"
100 b="$(cat "$g/rebase-merge/head-name")"
101 else
102 if [ -d "$g/rebase-apply" ]; then
103 if [ -f "$g/rebase-apply/rebasing" ]; then
104 r="|REBASE"
105 elif [ -f "$g/rebase-apply/applying" ]; then
106 r="|AM"
107 else
108 r="|AM/REBASE"
110 elif [ -f "$g/MERGE_HEAD" ]; then
111 r="|MERGING"
112 elif [ -f "$g/BISECT_LOG" ]; then
113 r="|BISECTING"
116 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
118 b="$(
119 case "${GIT_PS1_DESCRIBE_STYLE-}" in
120 (contains)
121 git describe --contains HEAD ;;
122 (branch)
123 git describe --contains --all HEAD ;;
124 (describe)
125 git describe HEAD ;;
126 (* | default)
127 git describe --exact-match HEAD ;;
128 esac 2>/dev/null)" ||
130 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
131 b="unknown"
132 b="($b)"
136 local w
137 local i
138 local s
139 local u
140 local c
142 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
143 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
144 c="BARE:"
145 else
146 b="GIT_DIR!"
148 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
149 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
150 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
151 git diff --no-ext-diff --ignore-submodules \
152 --quiet --exit-code || w="*"
153 if git rev-parse --quiet --verify HEAD >/dev/null; then
154 git diff-index --cached --quiet \
155 --ignore-submodules HEAD -- || i="+"
156 else
157 i="#"
161 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
162 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
165 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
166 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
167 u="%"
172 if [ -n "${1-}" ]; then
173 printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
174 else
175 printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
180 # __gitcomp_1 requires 2 arguments
181 __gitcomp_1 ()
183 local c IFS=' '$'\t'$'\n'
184 for c in $1; do
185 case "$c$2" in
186 --*=*) printf %s$'\n' "$c$2" ;;
187 *.) printf %s$'\n' "$c$2" ;;
188 *) printf %s$'\n' "$c$2 " ;;
189 esac
190 done
193 # __gitcomp accepts 1, 2, 3, or 4 arguments
194 # generates completion reply with compgen
195 __gitcomp ()
197 local cur="${COMP_WORDS[COMP_CWORD]}"
198 if [ $# -gt 2 ]; then
199 cur="$3"
201 case "$cur" in
202 --*=)
203 COMPREPLY=()
206 local IFS=$'\n'
207 COMPREPLY=($(compgen -P "${2-}" \
208 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
209 -- "$cur"))
211 esac
214 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
215 __git_heads ()
217 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
218 if [ -d "$dir" ]; then
219 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
220 refs/heads
221 return
223 for i in $(git ls-remote "${1-}" 2>/dev/null); do
224 case "$is_hash,$i" in
225 y,*) is_hash=n ;;
226 n,*^{}) is_hash=y ;;
227 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
228 n,*) is_hash=y; echo "$i" ;;
229 esac
230 done
233 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
234 __git_tags ()
236 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
237 if [ -d "$dir" ]; then
238 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
239 refs/tags
240 return
242 for i in $(git ls-remote "${1-}" 2>/dev/null); do
243 case "$is_hash,$i" in
244 y,*) is_hash=n ;;
245 n,*^{}) is_hash=y ;;
246 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
247 n,*) is_hash=y; echo "$i" ;;
248 esac
249 done
252 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
253 __git_refs ()
255 local i is_hash=y dir="$(__gitdir "${1-}")"
256 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
257 if [ -d "$dir" ]; then
258 case "$cur" in
259 refs|refs/*)
260 format="refname"
261 refs="${cur%/*}"
264 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
265 format="refname:short"
266 refs="refs/tags refs/heads refs/remotes"
268 esac
269 git --git-dir="$dir" for-each-ref --format="%($format)" \
270 $refs
271 return
273 for i in $(git ls-remote "$dir" 2>/dev/null); do
274 case "$is_hash,$i" in
275 y,*) is_hash=n ;;
276 n,*^{}) is_hash=y ;;
277 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
278 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
279 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
280 n,*) is_hash=y; echo "$i" ;;
281 esac
282 done
285 # __git_refs2 requires 1 argument (to pass to __git_refs)
286 __git_refs2 ()
288 local i
289 for i in $(__git_refs "$1"); do
290 echo "$i:$i"
291 done
294 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
295 __git_refs_remotes ()
297 local cmd i is_hash=y
298 for i in $(git ls-remote "$1" 2>/dev/null); do
299 case "$is_hash,$i" in
300 n,refs/heads/*)
301 is_hash=y
302 echo "$i:refs/remotes/$1/${i#refs/heads/}"
304 y,*) is_hash=n ;;
305 n,*^{}) is_hash=y ;;
306 n,refs/tags/*) is_hash=y;;
307 n,*) is_hash=y; ;;
308 esac
309 done
312 __git_remotes ()
314 local i ngoff IFS=$'\n' d="$(__gitdir)"
315 shopt -q nullglob || ngoff=1
316 shopt -s nullglob
317 for i in "$d/remotes"/*; do
318 echo ${i#$d/remotes/}
319 done
320 [ "$ngoff" ] && shopt -u nullglob
321 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
322 i="${i#remote.}"
323 echo "${i/.url*/}"
324 done
327 __git_merge_strategies ()
329 if [ -n "${__git_merge_strategylist-}" ]; then
330 echo "$__git_merge_strategylist"
331 return
333 git merge -s help 2>&1 |
334 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
335 s/\.$//
336 s/.*://
337 s/^[ ]*//
338 s/[ ]*$//
342 __git_merge_strategylist=
343 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
345 __git_complete_file ()
347 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
348 case "$cur" in
349 ?*:*)
350 ref="${cur%%:*}"
351 cur="${cur#*:}"
352 case "$cur" in
353 ?*/*)
354 pfx="${cur%/*}"
355 cur="${cur##*/}"
356 ls="$ref:$pfx"
357 pfx="$pfx/"
360 ls="$ref"
362 esac
364 case "$COMP_WORDBREAKS" in
365 *:*) : great ;;
366 *) pfx="$ref:$pfx" ;;
367 esac
369 local IFS=$'\n'
370 COMPREPLY=($(compgen -P "$pfx" \
371 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
372 | sed '/^100... blob /{
373 s,^.* ,,
374 s,$, ,
376 /^120000 blob /{
377 s,^.* ,,
378 s,$, ,
380 /^040000 tree /{
381 s,^.* ,,
382 s,$,/,
384 s/^.* //')" \
385 -- "$cur"))
388 __gitcomp "$(__git_refs)"
390 esac
393 __git_complete_revlist ()
395 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
396 case "$cur" in
397 *...*)
398 pfx="${cur%...*}..."
399 cur="${cur#*...}"
400 __gitcomp "$(__git_refs)" "$pfx" "$cur"
402 *..*)
403 pfx="${cur%..*}.."
404 cur="${cur#*..}"
405 __gitcomp "$(__git_refs)" "$pfx" "$cur"
408 __gitcomp "$(__git_refs)"
410 esac
413 __git_complete_remote_or_refspec ()
415 local cmd="${COMP_WORDS[1]}"
416 local cur="${COMP_WORDS[COMP_CWORD]}"
417 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
418 while [ $c -lt $COMP_CWORD ]; do
419 i="${COMP_WORDS[c]}"
420 case "$i" in
421 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
422 -*) ;;
423 *) remote="$i"; break ;;
424 esac
425 c=$((++c))
426 done
427 if [ -z "$remote" ]; then
428 __gitcomp "$(__git_remotes)"
429 return
431 if [ $no_complete_refspec = 1 ]; then
432 COMPREPLY=()
433 return
435 [ "$remote" = "." ] && remote=
436 case "$cur" in
437 *:*)
438 case "$COMP_WORDBREAKS" in
439 *:*) : great ;;
440 *) pfx="${cur%%:*}:" ;;
441 esac
442 cur="${cur#*:}"
443 lhs=0
446 pfx="+"
447 cur="${cur#+}"
449 esac
450 case "$cmd" in
451 fetch)
452 if [ $lhs = 1 ]; then
453 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
454 else
455 __gitcomp "$(__git_refs)" "$pfx" "$cur"
458 pull)
459 if [ $lhs = 1 ]; then
460 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
461 else
462 __gitcomp "$(__git_refs)" "$pfx" "$cur"
465 push)
466 if [ $lhs = 1 ]; then
467 __gitcomp "$(__git_refs)" "$pfx" "$cur"
468 else
469 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
472 esac
475 __git_complete_strategy ()
477 case "${COMP_WORDS[COMP_CWORD-1]}" in
478 -s|--strategy)
479 __gitcomp "$(__git_merge_strategies)"
480 return 0
481 esac
482 local cur="${COMP_WORDS[COMP_CWORD]}"
483 case "$cur" in
484 --strategy=*)
485 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
486 return 0
488 esac
489 return 1
492 __git_all_commands ()
494 if [ -n "${__git_all_commandlist-}" ]; then
495 echo "$__git_all_commandlist"
496 return
498 local i IFS=" "$'\n'
499 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
501 case $i in
502 *--*) : helper pattern;;
503 *) echo $i;;
504 esac
505 done
507 __git_all_commandlist=
508 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
510 __git_porcelain_commands ()
512 if [ -n "${__git_porcelain_commandlist-}" ]; then
513 echo "$__git_porcelain_commandlist"
514 return
516 local i IFS=" "$'\n'
517 for i in "help" $(__git_all_commands)
519 case $i in
520 *--*) : helper pattern;;
521 applymbox) : ask gittus;;
522 applypatch) : ask gittus;;
523 archimport) : import;;
524 cat-file) : plumbing;;
525 check-attr) : plumbing;;
526 check-ref-format) : plumbing;;
527 checkout-index) : plumbing;;
528 commit-tree) : plumbing;;
529 count-objects) : infrequent;;
530 cvsexportcommit) : export;;
531 cvsimport) : import;;
532 cvsserver) : daemon;;
533 daemon) : daemon;;
534 diff-files) : plumbing;;
535 diff-index) : plumbing;;
536 diff-tree) : plumbing;;
537 fast-import) : import;;
538 fast-export) : export;;
539 fsck-objects) : plumbing;;
540 fetch-pack) : plumbing;;
541 fmt-merge-msg) : plumbing;;
542 for-each-ref) : plumbing;;
543 hash-object) : plumbing;;
544 http-*) : transport;;
545 index-pack) : plumbing;;
546 init-db) : deprecated;;
547 local-fetch) : plumbing;;
548 lost-found) : infrequent;;
549 ls-files) : plumbing;;
550 ls-remote) : plumbing;;
551 ls-tree) : plumbing;;
552 mailinfo) : plumbing;;
553 mailsplit) : plumbing;;
554 merge-*) : plumbing;;
555 mktree) : plumbing;;
556 mktag) : plumbing;;
557 pack-objects) : plumbing;;
558 pack-redundant) : plumbing;;
559 pack-refs) : plumbing;;
560 parse-remote) : plumbing;;
561 patch-id) : plumbing;;
562 peek-remote) : plumbing;;
563 prune) : plumbing;;
564 prune-packed) : plumbing;;
565 quiltimport) : import;;
566 read-tree) : plumbing;;
567 receive-pack) : plumbing;;
568 reflog) : plumbing;;
569 repo-config) : deprecated;;
570 rerere) : plumbing;;
571 rev-list) : plumbing;;
572 rev-parse) : plumbing;;
573 runstatus) : plumbing;;
574 sh-setup) : internal;;
575 shell) : daemon;;
576 show-ref) : plumbing;;
577 send-pack) : plumbing;;
578 show-index) : plumbing;;
579 ssh-*) : transport;;
580 stripspace) : plumbing;;
581 symbolic-ref) : plumbing;;
582 tar-tree) : deprecated;;
583 unpack-file) : plumbing;;
584 unpack-objects) : plumbing;;
585 update-index) : plumbing;;
586 update-ref) : plumbing;;
587 update-server-info) : daemon;;
588 upload-archive) : plumbing;;
589 upload-pack) : plumbing;;
590 write-tree) : plumbing;;
591 var) : infrequent;;
592 verify-pack) : infrequent;;
593 verify-tag) : plumbing;;
594 *) echo $i;;
595 esac
596 done
598 __git_porcelain_commandlist=
599 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
601 __git_aliases ()
603 local i IFS=$'\n'
604 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
605 case "$i" in
606 alias.*)
607 i="${i#alias.}"
608 echo "${i/ */}"
610 esac
611 done
614 # __git_aliased_command requires 1 argument
615 __git_aliased_command ()
617 local word cmdline=$(git --git-dir="$(__gitdir)" \
618 config --get "alias.$1")
619 for word in $cmdline; do
620 if [ "${word##-*}" ]; then
621 echo $word
622 return
624 done
627 # __git_find_on_cmdline requires 1 argument
628 __git_find_on_cmdline ()
630 local word subcommand c=1
632 while [ $c -lt $COMP_CWORD ]; do
633 word="${COMP_WORDS[c]}"
634 for subcommand in $1; do
635 if [ "$subcommand" = "$word" ]; then
636 echo "$subcommand"
637 return
639 done
640 c=$((++c))
641 done
644 __git_has_doubledash ()
646 local c=1
647 while [ $c -lt $COMP_CWORD ]; do
648 if [ "--" = "${COMP_WORDS[c]}" ]; then
649 return 0
651 c=$((++c))
652 done
653 return 1
656 __git_whitespacelist="nowarn warn error error-all fix"
658 _git_am ()
660 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
661 if [ -d "$dir"/rebase-apply ]; then
662 __gitcomp "--skip --resolved --abort"
663 return
665 case "$cur" in
666 --whitespace=*)
667 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
668 return
670 --*)
671 __gitcomp "
672 --3way --committer-date-is-author-date --ignore-date
673 --ignore-whitespace --ignore-space-change
674 --interactive --keep --no-utf8 --signoff --utf8
675 --whitespace= --scissors
677 return
678 esac
679 COMPREPLY=()
682 _git_apply ()
684 local cur="${COMP_WORDS[COMP_CWORD]}"
685 case "$cur" in
686 --whitespace=*)
687 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
688 return
690 --*)
691 __gitcomp "
692 --stat --numstat --summary --check --index
693 --cached --index-info --reverse --reject --unidiff-zero
694 --apply --no-add --exclude=
695 --ignore-whitespace --ignore-space-change
696 --whitespace= --inaccurate-eof --verbose
698 return
699 esac
700 COMPREPLY=()
703 _git_add ()
705 __git_has_doubledash && return
707 local cur="${COMP_WORDS[COMP_CWORD]}"
708 case "$cur" in
709 --*)
710 __gitcomp "
711 --interactive --refresh --patch --update --dry-run
712 --ignore-errors --intent-to-add
714 return
715 esac
716 COMPREPLY=()
719 _git_archive ()
721 local cur="${COMP_WORDS[COMP_CWORD]}"
722 case "$cur" in
723 --format=*)
724 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
725 return
727 --remote=*)
728 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
729 return
731 --*)
732 __gitcomp "
733 --format= --list --verbose
734 --prefix= --remote= --exec=
736 return
738 esac
739 __git_complete_file
742 _git_bisect ()
744 __git_has_doubledash && return
746 local subcommands="start bad good skip reset visualize replay log run"
747 local subcommand="$(__git_find_on_cmdline "$subcommands")"
748 if [ -z "$subcommand" ]; then
749 __gitcomp "$subcommands"
750 return
753 case "$subcommand" in
754 bad|good|reset|skip)
755 __gitcomp "$(__git_refs)"
758 COMPREPLY=()
760 esac
763 _git_branch ()
765 local i c=1 only_local_ref="n" has_r="n"
767 while [ $c -lt $COMP_CWORD ]; do
768 i="${COMP_WORDS[c]}"
769 case "$i" in
770 -d|-m) only_local_ref="y" ;;
771 -r) has_r="y" ;;
772 esac
773 c=$((++c))
774 done
776 case "${COMP_WORDS[COMP_CWORD]}" in
777 --*)
778 __gitcomp "
779 --color --no-color --verbose --abbrev= --no-abbrev
780 --track --no-track --contains --merged --no-merged
784 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
785 __gitcomp "$(__git_heads)"
786 else
787 __gitcomp "$(__git_refs)"
790 esac
793 _git_bundle ()
795 local cmd="${COMP_WORDS[2]}"
796 case "$COMP_CWORD" in
798 __gitcomp "create list-heads verify unbundle"
801 # looking for a file
804 case "$cmd" in
805 create)
806 __git_complete_revlist
808 esac
810 esac
813 _git_checkout ()
815 __git_has_doubledash && return
817 local cur="${COMP_WORDS[COMP_CWORD]}"
818 case "$cur" in
819 --conflict=*)
820 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
822 --*)
823 __gitcomp "
824 --quiet --ours --theirs --track --no-track --merge
825 --conflict= --patch
829 __gitcomp "$(__git_refs)"
831 esac
834 _git_cherry ()
836 __gitcomp "$(__git_refs)"
839 _git_cherry_pick ()
841 local cur="${COMP_WORDS[COMP_CWORD]}"
842 case "$cur" in
843 --*)
844 __gitcomp "--edit --no-commit"
847 __gitcomp "$(__git_refs)"
849 esac
852 _git_clean ()
854 __git_has_doubledash && return
856 local cur="${COMP_WORDS[COMP_CWORD]}"
857 case "$cur" in
858 --*)
859 __gitcomp "--dry-run --quiet"
860 return
862 esac
863 COMPREPLY=()
866 _git_clone ()
868 local cur="${COMP_WORDS[COMP_CWORD]}"
869 case "$cur" in
870 --*)
871 __gitcomp "
872 --local
873 --no-hardlinks
874 --shared
875 --reference
876 --quiet
877 --no-checkout
878 --bare
879 --mirror
880 --origin
881 --upload-pack
882 --template=
883 --depth
885 return
887 esac
888 COMPREPLY=()
891 _git_commit ()
893 __git_has_doubledash && return
895 local cur="${COMP_WORDS[COMP_CWORD]}"
896 case "$cur" in
897 --*)
898 __gitcomp "
899 --all --author= --signoff --verify --no-verify
900 --edit --amend --include --only --interactive
901 --dry-run
903 return
904 esac
905 COMPREPLY=()
908 _git_describe ()
910 local cur="${COMP_WORDS[COMP_CWORD]}"
911 case "$cur" in
912 --*)
913 __gitcomp "
914 --all --tags --contains --abbrev= --candidates=
915 --exact-match --debug --long --match --always
917 return
918 esac
919 __gitcomp "$(__git_refs)"
922 __git_diff_common_options="--stat --numstat --shortstat --summary
923 --patch-with-stat --name-only --name-status --color
924 --no-color --color-words --no-renames --check
925 --full-index --binary --abbrev --diff-filter=
926 --find-copies-harder
927 --text --ignore-space-at-eol --ignore-space-change
928 --ignore-all-space --exit-code --quiet --ext-diff
929 --no-ext-diff
930 --no-prefix --src-prefix= --dst-prefix=
931 --inter-hunk-context=
932 --patience
933 --raw
934 --dirstat --dirstat= --dirstat-by-file
935 --dirstat-by-file= --cumulative
938 _git_diff ()
940 __git_has_doubledash && return
942 local cur="${COMP_WORDS[COMP_CWORD]}"
943 case "$cur" in
944 --*)
945 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
946 --base --ours --theirs
947 $__git_diff_common_options
949 return
951 esac
952 __git_complete_file
955 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
956 tkdiff vimdiff gvimdiff xxdiff araxis
959 _git_difftool ()
961 __git_has_doubledash && return
963 local cur="${COMP_WORDS[COMP_CWORD]}"
964 case "$cur" in
965 --tool=*)
966 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
967 return
969 --*)
970 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
971 --base --ours --theirs
972 --no-renames --diff-filter= --find-copies-harder
973 --relative --ignore-submodules
974 --tool="
975 return
977 esac
978 __git_complete_file
981 __git_fetch_options="
982 --quiet --verbose --append --upload-pack --force --keep --depth=
983 --tags --no-tags
986 _git_fetch ()
988 local cur="${COMP_WORDS[COMP_CWORD]}"
989 case "$cur" in
990 --*)
991 __gitcomp "$__git_fetch_options"
992 return
994 esac
995 __git_complete_remote_or_refspec
998 _git_format_patch ()
1000 local cur="${COMP_WORDS[COMP_CWORD]}"
1001 case "$cur" in
1002 --thread=*)
1003 __gitcomp "
1004 deep shallow
1005 " "" "${cur##--thread=}"
1006 return
1008 --*)
1009 __gitcomp "
1010 --stdout --attach --no-attach --thread --thread=
1011 --output-directory
1012 --numbered --start-number
1013 --numbered-files
1014 --keep-subject
1015 --signoff
1016 --in-reply-to= --cc=
1017 --full-index --binary
1018 --not --all
1019 --cover-letter
1020 --no-prefix --src-prefix= --dst-prefix=
1021 --inline --suffix= --ignore-if-in-upstream
1022 --subject-prefix=
1024 return
1026 esac
1027 __git_complete_revlist
1030 _git_fsck ()
1032 local cur="${COMP_WORDS[COMP_CWORD]}"
1033 case "$cur" in
1034 --*)
1035 __gitcomp "
1036 --tags --root --unreachable --cache --no-reflogs --full
1037 --strict --verbose --lost-found
1039 return
1041 esac
1042 COMPREPLY=()
1045 _git_gc ()
1047 local cur="${COMP_WORDS[COMP_CWORD]}"
1048 case "$cur" in
1049 --*)
1050 __gitcomp "--prune --aggressive"
1051 return
1053 esac
1054 COMPREPLY=()
1057 _git_grep ()
1059 __git_has_doubledash && return
1061 local cur="${COMP_WORDS[COMP_CWORD]}"
1062 case "$cur" in
1063 --*)
1064 __gitcomp "
1065 --cached
1066 --text --ignore-case --word-regexp --invert-match
1067 --full-name
1068 --extended-regexp --basic-regexp --fixed-strings
1069 --files-with-matches --name-only
1070 --files-without-match
1071 --max-depth
1072 --count
1073 --and --or --not --all-match
1075 return
1077 esac
1079 __gitcomp "$(__git_refs)"
1082 _git_help ()
1084 local cur="${COMP_WORDS[COMP_CWORD]}"
1085 case "$cur" in
1086 --*)
1087 __gitcomp "--all --info --man --web"
1088 return
1090 esac
1091 __gitcomp "$(__git_all_commands)
1092 attributes cli core-tutorial cvs-migration
1093 diffcore gitk glossary hooks ignore modules
1094 repository-layout tutorial tutorial-2
1095 workflows
1099 _git_init ()
1101 local cur="${COMP_WORDS[COMP_CWORD]}"
1102 case "$cur" in
1103 --shared=*)
1104 __gitcomp "
1105 false true umask group all world everybody
1106 " "" "${cur##--shared=}"
1107 return
1109 --*)
1110 __gitcomp "--quiet --bare --template= --shared --shared="
1111 return
1113 esac
1114 COMPREPLY=()
1117 _git_ls_files ()
1119 __git_has_doubledash && return
1121 local cur="${COMP_WORDS[COMP_CWORD]}"
1122 case "$cur" in
1123 --*)
1124 __gitcomp "--cached --deleted --modified --others --ignored
1125 --stage --directory --no-empty-directory --unmerged
1126 --killed --exclude= --exclude-from=
1127 --exclude-per-directory= --exclude-standard
1128 --error-unmatch --with-tree= --full-name
1129 --abbrev --ignored --exclude-per-directory
1131 return
1133 esac
1134 COMPREPLY=()
1137 _git_ls_remote ()
1139 __gitcomp "$(__git_remotes)"
1142 _git_ls_tree ()
1144 __git_complete_file
1147 # Options that go well for log, shortlog and gitk
1148 __git_log_common_options="
1149 --not --all
1150 --branches --tags --remotes
1151 --first-parent --merges --no-merges
1152 --max-count=
1153 --max-age= --since= --after=
1154 --min-age= --until= --before=
1156 # Options that go well for log and gitk (not shortlog)
1157 __git_log_gitk_options="
1158 --dense --sparse --full-history
1159 --simplify-merges --simplify-by-decoration
1160 --left-right
1162 # Options that go well for log and shortlog (not gitk)
1163 __git_log_shortlog_options="
1164 --author= --committer= --grep=
1165 --all-match
1168 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1169 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1171 _git_log ()
1173 __git_has_doubledash && return
1175 local cur="${COMP_WORDS[COMP_CWORD]}"
1176 local g="$(git rev-parse --git-dir 2>/dev/null)"
1177 local merge=""
1178 if [ -f "$g/MERGE_HEAD" ]; then
1179 merge="--merge"
1181 case "$cur" in
1182 --pretty=*)
1183 __gitcomp "$__git_log_pretty_formats
1184 " "" "${cur##--pretty=}"
1185 return
1187 --format=*)
1188 __gitcomp "$__git_log_pretty_formats
1189 " "" "${cur##--format=}"
1190 return
1192 --date=*)
1193 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1194 return
1196 --decorate=*)
1197 __gitcomp "long short" "" "${cur##--decorate=}"
1198 return
1200 --*)
1201 __gitcomp "
1202 $__git_log_common_options
1203 $__git_log_shortlog_options
1204 $__git_log_gitk_options
1205 --root --topo-order --date-order --reverse
1206 --follow --full-diff
1207 --abbrev-commit --abbrev=
1208 --relative-date --date=
1209 --pretty= --format= --oneline
1210 --cherry-pick
1211 --graph
1212 --decorate --decorate=
1213 --walk-reflogs
1214 --parents --children
1215 $merge
1216 $__git_diff_common_options
1217 --pickaxe-all --pickaxe-regex
1219 return
1221 esac
1222 __git_complete_revlist
1225 __git_merge_options="
1226 --no-commit --no-stat --log --no-log --squash --strategy
1227 --commit --stat --no-squash --ff --no-ff
1230 _git_merge ()
1232 __git_complete_strategy && return
1234 local cur="${COMP_WORDS[COMP_CWORD]}"
1235 case "$cur" in
1236 --*)
1237 __gitcomp "$__git_merge_options"
1238 return
1239 esac
1240 __gitcomp "$(__git_refs)"
1243 _git_mergetool ()
1245 local cur="${COMP_WORDS[COMP_CWORD]}"
1246 case "$cur" in
1247 --tool=*)
1248 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1249 return
1251 --*)
1252 __gitcomp "--tool="
1253 return
1255 esac
1256 COMPREPLY=()
1259 _git_merge_base ()
1261 __gitcomp "$(__git_refs)"
1264 _git_mv ()
1266 local cur="${COMP_WORDS[COMP_CWORD]}"
1267 case "$cur" in
1268 --*)
1269 __gitcomp "--dry-run"
1270 return
1272 esac
1273 COMPREPLY=()
1276 _git_name_rev ()
1278 __gitcomp "--tags --all --stdin"
1281 _git_pull ()
1283 __git_complete_strategy && return
1285 local cur="${COMP_WORDS[COMP_CWORD]}"
1286 case "$cur" in
1287 --*)
1288 __gitcomp "
1289 --rebase --no-rebase
1290 $__git_merge_options
1291 $__git_fetch_options
1293 return
1295 esac
1296 __git_complete_remote_or_refspec
1299 _git_push ()
1301 local cur="${COMP_WORDS[COMP_CWORD]}"
1302 case "${COMP_WORDS[COMP_CWORD-1]}" in
1303 --repo)
1304 __gitcomp "$(__git_remotes)"
1305 return
1306 esac
1307 case "$cur" in
1308 --repo=*)
1309 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1310 return
1312 --*)
1313 __gitcomp "
1314 --all --mirror --tags --dry-run --force --verbose
1315 --receive-pack= --repo=
1317 return
1319 esac
1320 __git_complete_remote_or_refspec
1323 _git_rebase ()
1325 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1326 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1327 __gitcomp "--continue --skip --abort"
1328 return
1330 __git_complete_strategy && return
1331 case "$cur" in
1332 --whitespace=*)
1333 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1334 return
1336 --*)
1337 __gitcomp "
1338 --onto --merge --strategy --interactive
1339 --preserve-merges --stat --no-stat
1340 --committer-date-is-author-date --ignore-date
1341 --ignore-whitespace --whitespace=
1344 return
1345 esac
1346 __gitcomp "$(__git_refs)"
1349 __git_send_email_confirm_options="always never auto cc compose"
1350 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1352 _git_send_email ()
1354 local cur="${COMP_WORDS[COMP_CWORD]}"
1355 case "$cur" in
1356 --confirm=*)
1357 __gitcomp "
1358 $__git_send_email_confirm_options
1359 " "" "${cur##--confirm=}"
1360 return
1362 --suppress-cc=*)
1363 __gitcomp "
1364 $__git_send_email_suppresscc_options
1365 " "" "${cur##--suppress-cc=}"
1367 return
1369 --smtp-encryption=*)
1370 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1371 return
1373 --*)
1374 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1375 --compose --confirm= --dry-run --envelope-sender
1376 --from --identity
1377 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1378 --no-suppress-from --no-thread --quiet
1379 --signed-off-by-cc --smtp-pass --smtp-server
1380 --smtp-server-port --smtp-encryption= --smtp-user
1381 --subject --suppress-cc= --suppress-from --thread --to
1382 --validate --no-validate"
1383 return
1385 esac
1386 COMPREPLY=()
1389 __git_config_get_set_variables ()
1391 local prevword word config_file= c=$COMP_CWORD
1392 while [ $c -gt 1 ]; do
1393 word="${COMP_WORDS[c]}"
1394 case "$word" in
1395 --global|--system|--file=*)
1396 config_file="$word"
1397 break
1399 -f|--file)
1400 config_file="$word $prevword"
1401 break
1403 esac
1404 prevword=$word
1405 c=$((--c))
1406 done
1408 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1409 while read line
1411 case "$line" in
1412 *.*=*)
1413 echo "${line/=*/}"
1415 esac
1416 done
1419 _git_config ()
1421 local cur="${COMP_WORDS[COMP_CWORD]}"
1422 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1423 case "$prv" in
1424 branch.*.remote)
1425 __gitcomp "$(__git_remotes)"
1426 return
1428 branch.*.merge)
1429 __gitcomp "$(__git_refs)"
1430 return
1432 remote.*.fetch)
1433 local remote="${prv#remote.}"
1434 remote="${remote%.fetch}"
1435 __gitcomp "$(__git_refs_remotes "$remote")"
1436 return
1438 remote.*.push)
1439 local remote="${prv#remote.}"
1440 remote="${remote%.push}"
1441 __gitcomp "$(git --git-dir="$(__gitdir)" \
1442 for-each-ref --format='%(refname):%(refname)' \
1443 refs/heads)"
1444 return
1446 pull.twohead|pull.octopus)
1447 __gitcomp "$(__git_merge_strategies)"
1448 return
1450 color.branch|color.diff|color.interactive|\
1451 color.showbranch|color.status|color.ui)
1452 __gitcomp "always never auto"
1453 return
1455 color.pager)
1456 __gitcomp "false true"
1457 return
1459 color.*.*)
1460 __gitcomp "
1461 normal black red green yellow blue magenta cyan white
1462 bold dim ul blink reverse
1464 return
1466 help.format)
1467 __gitcomp "man info web html"
1468 return
1470 log.date)
1471 __gitcomp "$__git_log_date_formats"
1472 return
1474 sendemail.aliasesfiletype)
1475 __gitcomp "mutt mailrc pine elm gnus"
1476 return
1478 sendemail.confirm)
1479 __gitcomp "$__git_send_email_confirm_options"
1480 return
1482 sendemail.suppresscc)
1483 __gitcomp "$__git_send_email_suppresscc_options"
1484 return
1486 --get|--get-all|--unset|--unset-all)
1487 __gitcomp "$(__git_config_get_set_variables)"
1488 return
1490 *.*)
1491 COMPREPLY=()
1492 return
1494 esac
1495 case "$cur" in
1496 --*)
1497 __gitcomp "
1498 --global --system --file=
1499 --list --replace-all
1500 --get --get-all --get-regexp
1501 --add --unset --unset-all
1502 --remove-section --rename-section
1504 return
1506 branch.*.*)
1507 local pfx="${cur%.*}."
1508 cur="${cur##*.}"
1509 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1510 return
1512 branch.*)
1513 local pfx="${cur%.*}."
1514 cur="${cur#*.}"
1515 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1516 return
1518 guitool.*.*)
1519 local pfx="${cur%.*}."
1520 cur="${cur##*.}"
1521 __gitcomp "
1522 argprompt cmd confirm needsfile noconsole norescan
1523 prompt revprompt revunmerged title
1524 " "$pfx" "$cur"
1525 return
1527 difftool.*.*)
1528 local pfx="${cur%.*}."
1529 cur="${cur##*.}"
1530 __gitcomp "cmd path" "$pfx" "$cur"
1531 return
1533 man.*.*)
1534 local pfx="${cur%.*}."
1535 cur="${cur##*.}"
1536 __gitcomp "cmd path" "$pfx" "$cur"
1537 return
1539 mergetool.*.*)
1540 local pfx="${cur%.*}."
1541 cur="${cur##*.}"
1542 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1543 return
1545 pager.*)
1546 local pfx="${cur%.*}."
1547 cur="${cur#*.}"
1548 __gitcomp "$(__git_all_commands)" "$pfx" "$cur"
1549 return
1551 remote.*.*)
1552 local pfx="${cur%.*}."
1553 cur="${cur##*.}"
1554 __gitcomp "
1555 url proxy fetch push mirror skipDefaultUpdate
1556 receivepack uploadpack tagopt pushurl
1557 " "$pfx" "$cur"
1558 return
1560 remote.*)
1561 local pfx="${cur%.*}."
1562 cur="${cur#*.}"
1563 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1564 return
1566 url.*.*)
1567 local pfx="${cur%.*}."
1568 cur="${cur##*.}"
1569 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1570 return
1572 esac
1573 __gitcomp "
1574 add.ignore-errors
1575 alias.
1576 apply.ignorewhitespace
1577 apply.whitespace
1578 branch.autosetupmerge
1579 branch.autosetuprebase
1580 clean.requireForce
1581 color.branch
1582 color.branch.current
1583 color.branch.local
1584 color.branch.plain
1585 color.branch.remote
1586 color.diff
1587 color.diff.commit
1588 color.diff.frag
1589 color.diff.meta
1590 color.diff.new
1591 color.diff.old
1592 color.diff.plain
1593 color.diff.whitespace
1594 color.grep
1595 color.grep.external
1596 color.grep.match
1597 color.interactive
1598 color.interactive.header
1599 color.interactive.help
1600 color.interactive.prompt
1601 color.pager
1602 color.showbranch
1603 color.status
1604 color.status.added
1605 color.status.changed
1606 color.status.header
1607 color.status.nobranch
1608 color.status.untracked
1609 color.status.updated
1610 color.ui
1611 commit.template
1612 core.autocrlf
1613 core.bare
1614 core.compression
1615 core.createObject
1616 core.deltaBaseCacheLimit
1617 core.editor
1618 core.excludesfile
1619 core.fileMode
1620 core.fsyncobjectfiles
1621 core.gitProxy
1622 core.ignoreCygwinFSTricks
1623 core.ignoreStat
1624 core.logAllRefUpdates
1625 core.loosecompression
1626 core.packedGitLimit
1627 core.packedGitWindowSize
1628 core.pager
1629 core.preferSymlinkRefs
1630 core.preloadindex
1631 core.quotepath
1632 core.repositoryFormatVersion
1633 core.safecrlf
1634 core.sharedRepository
1635 core.symlinks
1636 core.trustctime
1637 core.warnAmbiguousRefs
1638 core.whitespace
1639 core.worktree
1640 diff.autorefreshindex
1641 diff.external
1642 diff.mnemonicprefix
1643 diff.renameLimit
1644 diff.renameLimit.
1645 diff.renames
1646 diff.suppressBlankEmpty
1647 diff.tool
1648 diff.wordRegex
1649 difftool.
1650 difftool.prompt
1651 fetch.unpackLimit
1652 format.attach
1653 format.cc
1654 format.headers
1655 format.numbered
1656 format.pretty
1657 format.signoff
1658 format.subjectprefix
1659 format.suffix
1660 format.thread
1661 gc.aggressiveWindow
1662 gc.auto
1663 gc.autopacklimit
1664 gc.packrefs
1665 gc.pruneexpire
1666 gc.reflogexpire
1667 gc.reflogexpireunreachable
1668 gc.rerereresolved
1669 gc.rerereunresolved
1670 gitcvs.allbinary
1671 gitcvs.commitmsgannotation
1672 gitcvs.dbTableNamePrefix
1673 gitcvs.dbdriver
1674 gitcvs.dbname
1675 gitcvs.dbpass
1676 gitcvs.dbuser
1677 gitcvs.enabled
1678 gitcvs.logfile
1679 gitcvs.usecrlfattr
1680 guitool.
1681 gui.blamehistoryctx
1682 gui.commitmsgwidth
1683 gui.copyblamethreshold
1684 gui.diffcontext
1685 gui.encoding
1686 gui.fastcopyblame
1687 gui.matchtrackingbranch
1688 gui.newbranchtemplate
1689 gui.pruneduringfetch
1690 gui.spellingdictionary
1691 gui.trustmtime
1692 help.autocorrect
1693 help.browser
1694 help.format
1695 http.lowSpeedLimit
1696 http.lowSpeedTime
1697 http.maxRequests
1698 http.noEPSV
1699 http.proxy
1700 http.sslCAInfo
1701 http.sslCAPath
1702 http.sslCert
1703 http.sslKey
1704 http.sslVerify
1705 i18n.commitEncoding
1706 i18n.logOutputEncoding
1707 imap.folder
1708 imap.host
1709 imap.pass
1710 imap.port
1711 imap.preformattedHTML
1712 imap.sslverify
1713 imap.tunnel
1714 imap.user
1715 instaweb.browser
1716 instaweb.httpd
1717 instaweb.local
1718 instaweb.modulepath
1719 instaweb.port
1720 interactive.singlekey
1721 log.date
1722 log.showroot
1723 mailmap.file
1724 man.
1725 man.viewer
1726 merge.conflictstyle
1727 merge.log
1728 merge.renameLimit
1729 merge.stat
1730 merge.tool
1731 merge.verbosity
1732 mergetool.
1733 mergetool.keepBackup
1734 mergetool.prompt
1735 pack.compression
1736 pack.deltaCacheLimit
1737 pack.deltaCacheSize
1738 pack.depth
1739 pack.indexVersion
1740 pack.packSizeLimit
1741 pack.threads
1742 pack.window
1743 pack.windowMemory
1744 pager.
1745 pull.octopus
1746 pull.twohead
1747 push.default
1748 rebase.stat
1749 receive.denyCurrentBranch
1750 receive.denyDeletes
1751 receive.denyNonFastForwards
1752 receive.fsckObjects
1753 receive.unpackLimit
1754 repack.usedeltabaseoffset
1755 rerere.autoupdate
1756 rerere.enabled
1757 sendemail.aliasesfile
1758 sendemail.aliasesfiletype
1759 sendemail.bcc
1760 sendemail.cc
1761 sendemail.cccmd
1762 sendemail.chainreplyto
1763 sendemail.confirm
1764 sendemail.envelopesender
1765 sendemail.multiedit
1766 sendemail.signedoffbycc
1767 sendemail.smtpencryption
1768 sendemail.smtppass
1769 sendemail.smtpserver
1770 sendemail.smtpserverport
1771 sendemail.smtpuser
1772 sendemail.suppresscc
1773 sendemail.suppressfrom
1774 sendemail.thread
1775 sendemail.to
1776 sendemail.validate
1777 showbranch.default
1778 status.relativePaths
1779 status.showUntrackedFiles
1780 tar.umask
1781 transfer.unpackLimit
1782 url.
1783 user.email
1784 user.name
1785 user.signingkey
1786 web.browser
1787 branch. remote.
1791 _git_remote ()
1793 local subcommands="add rename rm show prune update set-head"
1794 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1795 if [ -z "$subcommand" ]; then
1796 __gitcomp "$subcommands"
1797 return
1800 case "$subcommand" in
1801 rename|rm|show|prune)
1802 __gitcomp "$(__git_remotes)"
1804 update)
1805 local i c='' IFS=$'\n'
1806 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1807 i="${i#remotes.}"
1808 c="$c ${i/ */}"
1809 done
1810 __gitcomp "$c"
1813 COMPREPLY=()
1815 esac
1818 _git_replace ()
1820 __gitcomp "$(__git_refs)"
1823 _git_reset ()
1825 __git_has_doubledash && return
1827 local cur="${COMP_WORDS[COMP_CWORD]}"
1828 case "$cur" in
1829 --*)
1830 __gitcomp "--merge --mixed --hard --soft --patch"
1831 return
1833 esac
1834 __gitcomp "$(__git_refs)"
1837 _git_revert ()
1839 local cur="${COMP_WORDS[COMP_CWORD]}"
1840 case "$cur" in
1841 --*)
1842 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1843 return
1845 esac
1846 __gitcomp "$(__git_refs)"
1849 _git_rm ()
1851 __git_has_doubledash && return
1853 local cur="${COMP_WORDS[COMP_CWORD]}"
1854 case "$cur" in
1855 --*)
1856 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1857 return
1859 esac
1860 COMPREPLY=()
1863 _git_shortlog ()
1865 __git_has_doubledash && return
1867 local cur="${COMP_WORDS[COMP_CWORD]}"
1868 case "$cur" in
1869 --*)
1870 __gitcomp "
1871 $__git_log_common_options
1872 $__git_log_shortlog_options
1873 --numbered --summary
1875 return
1877 esac
1878 __git_complete_revlist
1881 _git_show ()
1883 __git_has_doubledash && return
1885 local cur="${COMP_WORDS[COMP_CWORD]}"
1886 case "$cur" in
1887 --pretty=*)
1888 __gitcomp "$__git_log_pretty_formats
1889 " "" "${cur##--pretty=}"
1890 return
1892 --format=*)
1893 __gitcomp "$__git_log_pretty_formats
1894 " "" "${cur##--format=}"
1895 return
1897 --*)
1898 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1899 $__git_diff_common_options
1901 return
1903 esac
1904 __git_complete_file
1907 _git_show_branch ()
1909 local cur="${COMP_WORDS[COMP_CWORD]}"
1910 case "$cur" in
1911 --*)
1912 __gitcomp "
1913 --all --remotes --topo-order --current --more=
1914 --list --independent --merge-base --no-name
1915 --color --no-color
1916 --sha1-name --sparse --topics --reflog
1918 return
1920 esac
1921 __git_complete_revlist
1924 _git_stash ()
1926 local cur="${COMP_WORDS[COMP_CWORD]}"
1927 local save_opts='--keep-index --no-keep-index --quiet --patch'
1928 local subcommands='save list show apply clear drop pop create branch'
1929 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1930 if [ -z "$subcommand" ]; then
1931 case "$cur" in
1932 --*)
1933 __gitcomp "$save_opts"
1936 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1937 __gitcomp "$subcommands"
1938 else
1939 COMPREPLY=()
1942 esac
1943 else
1944 case "$subcommand,$cur" in
1945 save,--*)
1946 __gitcomp "$save_opts"
1948 apply,--*|pop,--*)
1949 __gitcomp "--index --quiet"
1951 show,--*|drop,--*|branch,--*)
1952 COMPREPLY=()
1954 show,*|apply,*|drop,*|pop,*|branch,*)
1955 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1956 | sed -n -e 's/:.*//p')"
1959 COMPREPLY=()
1961 esac
1965 _git_submodule ()
1967 __git_has_doubledash && return
1969 local subcommands="add status init update summary foreach sync"
1970 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1971 local cur="${COMP_WORDS[COMP_CWORD]}"
1972 case "$cur" in
1973 --*)
1974 __gitcomp "--quiet --cached"
1977 __gitcomp "$subcommands"
1979 esac
1980 return
1984 _git_svn ()
1986 local subcommands="
1987 init fetch clone rebase dcommit log find-rev
1988 set-tree commit-diff info create-ignore propget
1989 proplist show-ignore show-externals branch tag blame
1990 migrate
1992 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1993 if [ -z "$subcommand" ]; then
1994 __gitcomp "$subcommands"
1995 else
1996 local remote_opts="--username= --config-dir= --no-auth-cache"
1997 local fc_opts="
1998 --follow-parent --authors-file= --repack=
1999 --no-metadata --use-svm-props --use-svnsync-props
2000 --log-window-size= --no-checkout --quiet
2001 --repack-flags --use-log-author --localtime
2002 --ignore-paths= $remote_opts
2004 local init_opts="
2005 --template= --shared= --trunk= --tags=
2006 --branches= --stdlayout --minimize-url
2007 --no-metadata --use-svm-props --use-svnsync-props
2008 --rewrite-root= --prefix= --use-log-author
2009 --add-author-from $remote_opts
2011 local cmt_opts="
2012 --edit --rmdir --find-copies-harder --copy-similarity=
2015 local cur="${COMP_WORDS[COMP_CWORD]}"
2016 case "$subcommand,$cur" in
2017 fetch,--*)
2018 __gitcomp "--revision= --fetch-all $fc_opts"
2020 clone,--*)
2021 __gitcomp "--revision= $fc_opts $init_opts"
2023 init,--*)
2024 __gitcomp "$init_opts"
2026 dcommit,--*)
2027 __gitcomp "
2028 --merge --strategy= --verbose --dry-run
2029 --fetch-all --no-rebase --commit-url
2030 --revision $cmt_opts $fc_opts
2033 set-tree,--*)
2034 __gitcomp "--stdin $cmt_opts $fc_opts"
2036 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2037 show-externals,--*)
2038 __gitcomp "--revision="
2040 log,--*)
2041 __gitcomp "
2042 --limit= --revision= --verbose --incremental
2043 --oneline --show-commit --non-recursive
2044 --authors-file= --color
2047 rebase,--*)
2048 __gitcomp "
2049 --merge --verbose --strategy= --local
2050 --fetch-all --dry-run $fc_opts
2053 commit-diff,--*)
2054 __gitcomp "--message= --file= --revision= $cmt_opts"
2056 info,--*)
2057 __gitcomp "--url"
2059 branch,--*)
2060 __gitcomp "--dry-run --message --tag"
2062 tag,--*)
2063 __gitcomp "--dry-run --message"
2065 blame,--*)
2066 __gitcomp "--git-format"
2068 migrate,--*)
2069 __gitcomp "
2070 --config-dir= --ignore-paths= --minimize
2071 --no-auth-cache --username=
2075 COMPREPLY=()
2077 esac
2081 _git_tag ()
2083 local i c=1 f=0
2084 while [ $c -lt $COMP_CWORD ]; do
2085 i="${COMP_WORDS[c]}"
2086 case "$i" in
2087 -d|-v)
2088 __gitcomp "$(__git_tags)"
2089 return
2094 esac
2095 c=$((++c))
2096 done
2098 case "${COMP_WORDS[COMP_CWORD-1]}" in
2099 -m|-F)
2100 COMPREPLY=()
2102 -*|tag)
2103 if [ $f = 1 ]; then
2104 __gitcomp "$(__git_tags)"
2105 else
2106 COMPREPLY=()
2110 __gitcomp "$(__git_refs)"
2112 esac
2115 _git ()
2117 local i c=1 command __git_dir
2119 while [ $c -lt $COMP_CWORD ]; do
2120 i="${COMP_WORDS[c]}"
2121 case "$i" in
2122 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2123 --bare) __git_dir="." ;;
2124 --version|-p|--paginate) ;;
2125 --help) command="help"; break ;;
2126 *) command="$i"; break ;;
2127 esac
2128 c=$((++c))
2129 done
2131 if [ -z "$command" ]; then
2132 case "${COMP_WORDS[COMP_CWORD]}" in
2133 --*) __gitcomp "
2134 --paginate
2135 --no-pager
2136 --git-dir=
2137 --bare
2138 --version
2139 --exec-path
2140 --html-path
2141 --work-tree=
2142 --help
2145 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
2146 esac
2147 return
2150 local expansion=$(__git_aliased_command "$command")
2151 [ "$expansion" ] && command="$expansion"
2153 case "$command" in
2154 am) _git_am ;;
2155 add) _git_add ;;
2156 apply) _git_apply ;;
2157 archive) _git_archive ;;
2158 bisect) _git_bisect ;;
2159 bundle) _git_bundle ;;
2160 branch) _git_branch ;;
2161 checkout) _git_checkout ;;
2162 cherry) _git_cherry ;;
2163 cherry-pick) _git_cherry_pick ;;
2164 clean) _git_clean ;;
2165 clone) _git_clone ;;
2166 commit) _git_commit ;;
2167 config) _git_config ;;
2168 describe) _git_describe ;;
2169 diff) _git_diff ;;
2170 difftool) _git_difftool ;;
2171 fetch) _git_fetch ;;
2172 format-patch) _git_format_patch ;;
2173 fsck) _git_fsck ;;
2174 gc) _git_gc ;;
2175 grep) _git_grep ;;
2176 help) _git_help ;;
2177 init) _git_init ;;
2178 log) _git_log ;;
2179 ls-files) _git_ls_files ;;
2180 ls-remote) _git_ls_remote ;;
2181 ls-tree) _git_ls_tree ;;
2182 merge) _git_merge;;
2183 mergetool) _git_mergetool;;
2184 merge-base) _git_merge_base ;;
2185 mv) _git_mv ;;
2186 name-rev) _git_name_rev ;;
2187 pull) _git_pull ;;
2188 push) _git_push ;;
2189 rebase) _git_rebase ;;
2190 remote) _git_remote ;;
2191 replace) _git_replace ;;
2192 reset) _git_reset ;;
2193 revert) _git_revert ;;
2194 rm) _git_rm ;;
2195 send-email) _git_send_email ;;
2196 shortlog) _git_shortlog ;;
2197 show) _git_show ;;
2198 show-branch) _git_show_branch ;;
2199 stash) _git_stash ;;
2200 stage) _git_add ;;
2201 submodule) _git_submodule ;;
2202 svn) _git_svn ;;
2203 tag) _git_tag ;;
2204 whatchanged) _git_log ;;
2205 *) COMPREPLY=() ;;
2206 esac
2209 _gitk ()
2211 __git_has_doubledash && return
2213 local cur="${COMP_WORDS[COMP_CWORD]}"
2214 local g="$(__gitdir)"
2215 local merge=""
2216 if [ -f "$g/MERGE_HEAD" ]; then
2217 merge="--merge"
2219 case "$cur" in
2220 --*)
2221 __gitcomp "
2222 $__git_log_common_options
2223 $__git_log_gitk_options
2224 $merge
2226 return
2228 esac
2229 __git_complete_revlist
2232 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2233 || complete -o default -o nospace -F _git git
2234 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2235 || complete -o default -o nospace -F _gitk gitk
2237 # The following are necessary only for Cygwin, and only are needed
2238 # when the user has tab-completed the executable name and consequently
2239 # included the '.exe' suffix.
2241 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2242 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2243 || complete -o default -o nospace -F _git git.exe