bash completion: factor submodules into dirty state
[git/dscho.git] / contrib / completion / git-completion.bash
blob4cb89a1256a7fc7df0fce443f61eb209b82ac8e6
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 --quiet --exit-code || w="*"
152 if git rev-parse --quiet --verify HEAD >/dev/null; then
153 git diff-index --cached --quiet HEAD -- || i="+"
154 else
155 i="#"
159 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
160 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
163 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
164 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
165 u="%"
170 if [ -n "${1-}" ]; then
171 printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
172 else
173 printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
178 # __gitcomp_1 requires 2 arguments
179 __gitcomp_1 ()
181 local c IFS=' '$'\t'$'\n'
182 for c in $1; do
183 case "$c$2" in
184 --*=*) printf %s$'\n' "$c$2" ;;
185 *.) printf %s$'\n' "$c$2" ;;
186 *) printf %s$'\n' "$c$2 " ;;
187 esac
188 done
191 # __gitcomp accepts 1, 2, 3, or 4 arguments
192 # generates completion reply with compgen
193 __gitcomp ()
195 local cur="${COMP_WORDS[COMP_CWORD]}"
196 if [ $# -gt 2 ]; then
197 cur="$3"
199 case "$cur" in
200 --*=)
201 COMPREPLY=()
204 local IFS=$'\n'
205 COMPREPLY=($(compgen -P "${2-}" \
206 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
207 -- "$cur"))
209 esac
212 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
213 __git_heads ()
215 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
216 if [ -d "$dir" ]; then
217 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
218 refs/heads
219 return
221 for i in $(git ls-remote "${1-}" 2>/dev/null); do
222 case "$is_hash,$i" in
223 y,*) is_hash=n ;;
224 n,*^{}) is_hash=y ;;
225 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
226 n,*) is_hash=y; echo "$i" ;;
227 esac
228 done
231 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
232 __git_tags ()
234 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
235 if [ -d "$dir" ]; then
236 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
237 refs/tags
238 return
240 for i in $(git ls-remote "${1-}" 2>/dev/null); do
241 case "$is_hash,$i" in
242 y,*) is_hash=n ;;
243 n,*^{}) is_hash=y ;;
244 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
245 n,*) is_hash=y; echo "$i" ;;
246 esac
247 done
250 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
251 __git_refs ()
253 local i is_hash=y dir="$(__gitdir "${1-}")"
254 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
255 if [ -d "$dir" ]; then
256 case "$cur" in
257 refs|refs/*)
258 format="refname"
259 refs="${cur%/*}"
262 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
263 format="refname:short"
264 refs="refs/tags refs/heads refs/remotes"
266 esac
267 git --git-dir="$dir" for-each-ref --format="%($format)" \
268 $refs
269 return
271 for i in $(git ls-remote "$dir" 2>/dev/null); do
272 case "$is_hash,$i" in
273 y,*) is_hash=n ;;
274 n,*^{}) is_hash=y ;;
275 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
276 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
277 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
278 n,*) is_hash=y; echo "$i" ;;
279 esac
280 done
283 # __git_refs2 requires 1 argument (to pass to __git_refs)
284 __git_refs2 ()
286 local i
287 for i in $(__git_refs "$1"); do
288 echo "$i:$i"
289 done
292 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
293 __git_refs_remotes ()
295 local cmd i is_hash=y
296 for i in $(git ls-remote "$1" 2>/dev/null); do
297 case "$is_hash,$i" in
298 n,refs/heads/*)
299 is_hash=y
300 echo "$i:refs/remotes/$1/${i#refs/heads/}"
302 y,*) is_hash=n ;;
303 n,*^{}) is_hash=y ;;
304 n,refs/tags/*) is_hash=y;;
305 n,*) is_hash=y; ;;
306 esac
307 done
310 __git_remotes ()
312 local i ngoff IFS=$'\n' d="$(__gitdir)"
313 shopt -q nullglob || ngoff=1
314 shopt -s nullglob
315 for i in "$d/remotes"/*; do
316 echo ${i#$d/remotes/}
317 done
318 [ "$ngoff" ] && shopt -u nullglob
319 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
320 i="${i#remote.}"
321 echo "${i/.url*/}"
322 done
325 __git_merge_strategies ()
327 if [ -n "${__git_merge_strategylist-}" ]; then
328 echo "$__git_merge_strategylist"
329 return
331 git merge -s help 2>&1 |
332 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
333 s/\.$//
334 s/.*://
335 s/^[ ]*//
336 s/[ ]*$//
340 __git_merge_strategylist=
341 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
343 __git_complete_file ()
345 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
346 case "$cur" in
347 ?*:*)
348 ref="${cur%%:*}"
349 cur="${cur#*:}"
350 case "$cur" in
351 ?*/*)
352 pfx="${cur%/*}"
353 cur="${cur##*/}"
354 ls="$ref:$pfx"
355 pfx="$pfx/"
358 ls="$ref"
360 esac
362 case "$COMP_WORDBREAKS" in
363 *:*) : great ;;
364 *) pfx="$ref:$pfx" ;;
365 esac
367 local IFS=$'\n'
368 COMPREPLY=($(compgen -P "$pfx" \
369 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
370 | sed '/^100... blob /{
371 s,^.* ,,
372 s,$, ,
374 /^120000 blob /{
375 s,^.* ,,
376 s,$, ,
378 /^040000 tree /{
379 s,^.* ,,
380 s,$,/,
382 s/^.* //')" \
383 -- "$cur"))
386 __gitcomp "$(__git_refs)"
388 esac
391 __git_complete_revlist ()
393 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
394 case "$cur" in
395 *...*)
396 pfx="${cur%...*}..."
397 cur="${cur#*...}"
398 __gitcomp "$(__git_refs)" "$pfx" "$cur"
400 *..*)
401 pfx="${cur%..*}.."
402 cur="${cur#*..}"
403 __gitcomp "$(__git_refs)" "$pfx" "$cur"
406 __gitcomp "$(__git_refs)"
408 esac
411 __git_complete_remote_or_refspec ()
413 local cmd="${COMP_WORDS[1]}"
414 local cur="${COMP_WORDS[COMP_CWORD]}"
415 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
416 while [ $c -lt $COMP_CWORD ]; do
417 i="${COMP_WORDS[c]}"
418 case "$i" in
419 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
420 -*) ;;
421 *) remote="$i"; break ;;
422 esac
423 c=$((++c))
424 done
425 if [ -z "$remote" ]; then
426 __gitcomp "$(__git_remotes)"
427 return
429 if [ $no_complete_refspec = 1 ]; then
430 COMPREPLY=()
431 return
433 [ "$remote" = "." ] && remote=
434 case "$cur" in
435 *:*)
436 case "$COMP_WORDBREAKS" in
437 *:*) : great ;;
438 *) pfx="${cur%%:*}:" ;;
439 esac
440 cur="${cur#*:}"
441 lhs=0
444 pfx="+"
445 cur="${cur#+}"
447 esac
448 case "$cmd" in
449 fetch)
450 if [ $lhs = 1 ]; then
451 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
452 else
453 __gitcomp "$(__git_refs)" "$pfx" "$cur"
456 pull)
457 if [ $lhs = 1 ]; then
458 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
459 else
460 __gitcomp "$(__git_refs)" "$pfx" "$cur"
463 push)
464 if [ $lhs = 1 ]; then
465 __gitcomp "$(__git_refs)" "$pfx" "$cur"
466 else
467 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
470 esac
473 __git_complete_strategy ()
475 case "${COMP_WORDS[COMP_CWORD-1]}" in
476 -s|--strategy)
477 __gitcomp "$(__git_merge_strategies)"
478 return 0
479 esac
480 local cur="${COMP_WORDS[COMP_CWORD]}"
481 case "$cur" in
482 --strategy=*)
483 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
484 return 0
486 esac
487 return 1
490 __git_all_commands ()
492 if [ -n "${__git_all_commandlist-}" ]; then
493 echo "$__git_all_commandlist"
494 return
496 local i IFS=" "$'\n'
497 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
499 case $i in
500 *--*) : helper pattern;;
501 *) echo $i;;
502 esac
503 done
505 __git_all_commandlist=
506 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
508 __git_porcelain_commands ()
510 if [ -n "${__git_porcelain_commandlist-}" ]; then
511 echo "$__git_porcelain_commandlist"
512 return
514 local i IFS=" "$'\n'
515 for i in "help" $(__git_all_commands)
517 case $i in
518 *--*) : helper pattern;;
519 applymbox) : ask gittus;;
520 applypatch) : ask gittus;;
521 archimport) : import;;
522 cat-file) : plumbing;;
523 check-attr) : plumbing;;
524 check-ref-format) : plumbing;;
525 checkout-index) : plumbing;;
526 commit-tree) : plumbing;;
527 count-objects) : infrequent;;
528 cvsexportcommit) : export;;
529 cvsimport) : import;;
530 cvsserver) : daemon;;
531 daemon) : daemon;;
532 diff-files) : plumbing;;
533 diff-index) : plumbing;;
534 diff-tree) : plumbing;;
535 fast-import) : import;;
536 fast-export) : export;;
537 fsck-objects) : plumbing;;
538 fetch-pack) : plumbing;;
539 fmt-merge-msg) : plumbing;;
540 for-each-ref) : plumbing;;
541 hash-object) : plumbing;;
542 http-*) : transport;;
543 index-pack) : plumbing;;
544 init-db) : deprecated;;
545 local-fetch) : plumbing;;
546 lost-found) : infrequent;;
547 ls-files) : plumbing;;
548 ls-remote) : plumbing;;
549 ls-tree) : plumbing;;
550 mailinfo) : plumbing;;
551 mailsplit) : plumbing;;
552 merge-*) : plumbing;;
553 mktree) : plumbing;;
554 mktag) : plumbing;;
555 pack-objects) : plumbing;;
556 pack-redundant) : plumbing;;
557 pack-refs) : plumbing;;
558 parse-remote) : plumbing;;
559 patch-id) : plumbing;;
560 peek-remote) : plumbing;;
561 prune) : plumbing;;
562 prune-packed) : plumbing;;
563 quiltimport) : import;;
564 read-tree) : plumbing;;
565 receive-pack) : plumbing;;
566 reflog) : plumbing;;
567 repo-config) : deprecated;;
568 rerere) : plumbing;;
569 rev-list) : plumbing;;
570 rev-parse) : plumbing;;
571 runstatus) : plumbing;;
572 sh-setup) : internal;;
573 shell) : daemon;;
574 show-ref) : plumbing;;
575 send-pack) : plumbing;;
576 show-index) : plumbing;;
577 ssh-*) : transport;;
578 stripspace) : plumbing;;
579 symbolic-ref) : plumbing;;
580 tar-tree) : deprecated;;
581 unpack-file) : plumbing;;
582 unpack-objects) : plumbing;;
583 update-index) : plumbing;;
584 update-ref) : plumbing;;
585 update-server-info) : daemon;;
586 upload-archive) : plumbing;;
587 upload-pack) : plumbing;;
588 write-tree) : plumbing;;
589 var) : infrequent;;
590 verify-pack) : infrequent;;
591 verify-tag) : plumbing;;
592 *) echo $i;;
593 esac
594 done
596 __git_porcelain_commandlist=
597 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
599 __git_aliases ()
601 local i IFS=$'\n'
602 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
603 case "$i" in
604 alias.*)
605 i="${i#alias.}"
606 echo "${i/ */}"
608 esac
609 done
612 # __git_aliased_command requires 1 argument
613 __git_aliased_command ()
615 local word cmdline=$(git --git-dir="$(__gitdir)" \
616 config --get "alias.$1")
617 for word in $cmdline; do
618 if [ "${word##-*}" ]; then
619 echo $word
620 return
622 done
625 # __git_find_on_cmdline requires 1 argument
626 __git_find_on_cmdline ()
628 local word subcommand c=1
630 while [ $c -lt $COMP_CWORD ]; do
631 word="${COMP_WORDS[c]}"
632 for subcommand in $1; do
633 if [ "$subcommand" = "$word" ]; then
634 echo "$subcommand"
635 return
637 done
638 c=$((++c))
639 done
642 __git_has_doubledash ()
644 local c=1
645 while [ $c -lt $COMP_CWORD ]; do
646 if [ "--" = "${COMP_WORDS[c]}" ]; then
647 return 0
649 c=$((++c))
650 done
651 return 1
654 __git_whitespacelist="nowarn warn error error-all fix"
656 _git_am ()
658 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
659 if [ -d "$dir"/rebase-apply ]; then
660 __gitcomp "--skip --resolved --abort"
661 return
663 case "$cur" in
664 --whitespace=*)
665 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
666 return
668 --*)
669 __gitcomp "
670 --3way --committer-date-is-author-date --ignore-date
671 --ignore-whitespace --ignore-space-change
672 --interactive --keep --no-utf8 --signoff --utf8
673 --whitespace= --scissors
675 return
676 esac
677 COMPREPLY=()
680 _git_apply ()
682 local cur="${COMP_WORDS[COMP_CWORD]}"
683 case "$cur" in
684 --whitespace=*)
685 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
686 return
688 --*)
689 __gitcomp "
690 --stat --numstat --summary --check --index
691 --cached --index-info --reverse --reject --unidiff-zero
692 --apply --no-add --exclude=
693 --ignore-whitespace --ignore-space-change
694 --whitespace= --inaccurate-eof --verbose
696 return
697 esac
698 COMPREPLY=()
701 _git_add ()
703 __git_has_doubledash && return
705 local cur="${COMP_WORDS[COMP_CWORD]}"
706 case "$cur" in
707 --*)
708 __gitcomp "
709 --interactive --refresh --patch --update --dry-run
710 --ignore-errors --intent-to-add
712 return
713 esac
714 COMPREPLY=()
717 _git_archive ()
719 local cur="${COMP_WORDS[COMP_CWORD]}"
720 case "$cur" in
721 --format=*)
722 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
723 return
725 --remote=*)
726 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
727 return
729 --*)
730 __gitcomp "
731 --format= --list --verbose
732 --prefix= --remote= --exec=
734 return
736 esac
737 __git_complete_file
740 _git_bisect ()
742 __git_has_doubledash && return
744 local subcommands="start bad good skip reset visualize replay log run"
745 local subcommand="$(__git_find_on_cmdline "$subcommands")"
746 if [ -z "$subcommand" ]; then
747 __gitcomp "$subcommands"
748 return
751 case "$subcommand" in
752 bad|good|reset|skip)
753 __gitcomp "$(__git_refs)"
756 COMPREPLY=()
758 esac
761 _git_branch ()
763 local i c=1 only_local_ref="n" has_r="n"
765 while [ $c -lt $COMP_CWORD ]; do
766 i="${COMP_WORDS[c]}"
767 case "$i" in
768 -d|-m) only_local_ref="y" ;;
769 -r) has_r="y" ;;
770 esac
771 c=$((++c))
772 done
774 case "${COMP_WORDS[COMP_CWORD]}" in
775 --*)
776 __gitcomp "
777 --color --no-color --verbose --abbrev= --no-abbrev
778 --track --no-track --contains --merged --no-merged
782 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
783 __gitcomp "$(__git_heads)"
784 else
785 __gitcomp "$(__git_refs)"
788 esac
791 _git_bundle ()
793 local cmd="${COMP_WORDS[2]}"
794 case "$COMP_CWORD" in
796 __gitcomp "create list-heads verify unbundle"
799 # looking for a file
802 case "$cmd" in
803 create)
804 __git_complete_revlist
806 esac
808 esac
811 _git_checkout ()
813 __git_has_doubledash && return
815 local cur="${COMP_WORDS[COMP_CWORD]}"
816 case "$cur" in
817 --conflict=*)
818 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
820 --*)
821 __gitcomp "
822 --quiet --ours --theirs --track --no-track --merge
823 --conflict= --patch
827 __gitcomp "$(__git_refs)"
829 esac
832 _git_cherry ()
834 __gitcomp "$(__git_refs)"
837 _git_cherry_pick ()
839 local cur="${COMP_WORDS[COMP_CWORD]}"
840 case "$cur" in
841 --*)
842 __gitcomp "--edit --no-commit"
845 __gitcomp "$(__git_refs)"
847 esac
850 _git_clean ()
852 __git_has_doubledash && return
854 local cur="${COMP_WORDS[COMP_CWORD]}"
855 case "$cur" in
856 --*)
857 __gitcomp "--dry-run --quiet"
858 return
860 esac
861 COMPREPLY=()
864 _git_clone ()
866 local cur="${COMP_WORDS[COMP_CWORD]}"
867 case "$cur" in
868 --*)
869 __gitcomp "
870 --local
871 --no-hardlinks
872 --shared
873 --reference
874 --quiet
875 --no-checkout
876 --bare
877 --mirror
878 --origin
879 --upload-pack
880 --template=
881 --depth
883 return
885 esac
886 COMPREPLY=()
889 _git_commit ()
891 __git_has_doubledash && return
893 local cur="${COMP_WORDS[COMP_CWORD]}"
894 case "$cur" in
895 --*)
896 __gitcomp "
897 --all --author= --signoff --verify --no-verify
898 --edit --amend --include --only --interactive
899 --dry-run
901 return
902 esac
903 COMPREPLY=()
906 _git_describe ()
908 local cur="${COMP_WORDS[COMP_CWORD]}"
909 case "$cur" in
910 --*)
911 __gitcomp "
912 --all --tags --contains --abbrev= --candidates=
913 --exact-match --debug --long --match --always
915 return
916 esac
917 __gitcomp "$(__git_refs)"
920 __git_diff_common_options="--stat --numstat --shortstat --summary
921 --patch-with-stat --name-only --name-status --color
922 --no-color --color-words --no-renames --check
923 --full-index --binary --abbrev --diff-filter=
924 --find-copies-harder
925 --text --ignore-space-at-eol --ignore-space-change
926 --ignore-all-space --exit-code --quiet --ext-diff
927 --no-ext-diff
928 --no-prefix --src-prefix= --dst-prefix=
929 --inter-hunk-context=
930 --patience
931 --raw
932 --dirstat --dirstat= --dirstat-by-file
933 --dirstat-by-file= --cumulative
936 _git_diff ()
938 __git_has_doubledash && return
940 local cur="${COMP_WORDS[COMP_CWORD]}"
941 case "$cur" in
942 --*)
943 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
944 --base --ours --theirs
945 $__git_diff_common_options
947 return
949 esac
950 __git_complete_file
953 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
954 tkdiff vimdiff gvimdiff xxdiff araxis
957 _git_difftool ()
959 local cur="${COMP_WORDS[COMP_CWORD]}"
960 case "$cur" in
961 --tool=*)
962 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
963 return
965 --*)
966 __gitcomp "--tool="
967 return
969 esac
970 COMPREPLY=()
973 __git_fetch_options="
974 --quiet --verbose --append --upload-pack --force --keep --depth=
975 --tags --no-tags
978 _git_fetch ()
980 local cur="${COMP_WORDS[COMP_CWORD]}"
981 case "$cur" in
982 --*)
983 __gitcomp "$__git_fetch_options"
984 return
986 esac
987 __git_complete_remote_or_refspec
990 _git_format_patch ()
992 local cur="${COMP_WORDS[COMP_CWORD]}"
993 case "$cur" in
994 --thread=*)
995 __gitcomp "
996 deep shallow
997 " "" "${cur##--thread=}"
998 return
1000 --*)
1001 __gitcomp "
1002 --stdout --attach --no-attach --thread --thread=
1003 --output-directory
1004 --numbered --start-number
1005 --numbered-files
1006 --keep-subject
1007 --signoff
1008 --in-reply-to= --cc=
1009 --full-index --binary
1010 --not --all
1011 --cover-letter
1012 --no-prefix --src-prefix= --dst-prefix=
1013 --inline --suffix= --ignore-if-in-upstream
1014 --subject-prefix=
1016 return
1018 esac
1019 __git_complete_revlist
1022 _git_fsck ()
1024 local cur="${COMP_WORDS[COMP_CWORD]}"
1025 case "$cur" in
1026 --*)
1027 __gitcomp "
1028 --tags --root --unreachable --cache --no-reflogs --full
1029 --strict --verbose --lost-found
1031 return
1033 esac
1034 COMPREPLY=()
1037 _git_gc ()
1039 local cur="${COMP_WORDS[COMP_CWORD]}"
1040 case "$cur" in
1041 --*)
1042 __gitcomp "--prune --aggressive"
1043 return
1045 esac
1046 COMPREPLY=()
1049 _git_grep ()
1051 __git_has_doubledash && return
1053 local cur="${COMP_WORDS[COMP_CWORD]}"
1054 case "$cur" in
1055 --*)
1056 __gitcomp "
1057 --cached
1058 --text --ignore-case --word-regexp --invert-match
1059 --full-name
1060 --extended-regexp --basic-regexp --fixed-strings
1061 --files-with-matches --name-only
1062 --files-without-match
1063 --max-depth
1064 --count
1065 --and --or --not --all-match
1067 return
1069 esac
1070 COMPREPLY=()
1073 _git_help ()
1075 local cur="${COMP_WORDS[COMP_CWORD]}"
1076 case "$cur" in
1077 --*)
1078 __gitcomp "--all --info --man --web"
1079 return
1081 esac
1082 __gitcomp "$(__git_all_commands)
1083 attributes cli core-tutorial cvs-migration
1084 diffcore gitk glossary hooks ignore modules
1085 repository-layout tutorial tutorial-2
1086 workflows
1090 _git_init ()
1092 local cur="${COMP_WORDS[COMP_CWORD]}"
1093 case "$cur" in
1094 --shared=*)
1095 __gitcomp "
1096 false true umask group all world everybody
1097 " "" "${cur##--shared=}"
1098 return
1100 --*)
1101 __gitcomp "--quiet --bare --template= --shared --shared="
1102 return
1104 esac
1105 COMPREPLY=()
1108 _git_ls_files ()
1110 __git_has_doubledash && return
1112 local cur="${COMP_WORDS[COMP_CWORD]}"
1113 case "$cur" in
1114 --*)
1115 __gitcomp "--cached --deleted --modified --others --ignored
1116 --stage --directory --no-empty-directory --unmerged
1117 --killed --exclude= --exclude-from=
1118 --exclude-per-directory= --exclude-standard
1119 --error-unmatch --with-tree= --full-name
1120 --abbrev --ignored --exclude-per-directory
1122 return
1124 esac
1125 COMPREPLY=()
1128 _git_ls_remote ()
1130 __gitcomp "$(__git_remotes)"
1133 _git_ls_tree ()
1135 __git_complete_file
1138 # Options that go well for log, shortlog and gitk
1139 __git_log_common_options="
1140 --not --all
1141 --branches --tags --remotes
1142 --first-parent --merges --no-merges
1143 --max-count=
1144 --max-age= --since= --after=
1145 --min-age= --until= --before=
1147 # Options that go well for log and gitk (not shortlog)
1148 __git_log_gitk_options="
1149 --dense --sparse --full-history
1150 --simplify-merges --simplify-by-decoration
1151 --left-right
1153 # Options that go well for log and shortlog (not gitk)
1154 __git_log_shortlog_options="
1155 --author= --committer= --grep=
1156 --all-match
1159 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1160 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1162 _git_log ()
1164 __git_has_doubledash && return
1166 local cur="${COMP_WORDS[COMP_CWORD]}"
1167 local g="$(git rev-parse --git-dir 2>/dev/null)"
1168 local merge=""
1169 if [ -f "$g/MERGE_HEAD" ]; then
1170 merge="--merge"
1172 case "$cur" in
1173 --pretty=*)
1174 __gitcomp "$__git_log_pretty_formats
1175 " "" "${cur##--pretty=}"
1176 return
1178 --format=*)
1179 __gitcomp "$__git_log_pretty_formats
1180 " "" "${cur##--format=}"
1181 return
1183 --date=*)
1184 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1185 return
1187 --decorate=*)
1188 __gitcomp "long short" "" "${cur##--decorate=}"
1189 return
1191 --*)
1192 __gitcomp "
1193 $__git_log_common_options
1194 $__git_log_shortlog_options
1195 $__git_log_gitk_options
1196 --root --topo-order --date-order --reverse
1197 --follow --full-diff
1198 --abbrev-commit --abbrev=
1199 --relative-date --date=
1200 --pretty= --format= --oneline
1201 --cherry-pick
1202 --graph
1203 --decorate --decorate=
1204 --walk-reflogs
1205 --parents --children
1206 $merge
1207 $__git_diff_common_options
1208 --pickaxe-all --pickaxe-regex
1210 return
1212 esac
1213 __git_complete_revlist
1216 __git_merge_options="
1217 --no-commit --no-stat --log --no-log --squash --strategy
1218 --commit --stat --no-squash --ff --no-ff
1221 _git_merge ()
1223 __git_complete_strategy && return
1225 local cur="${COMP_WORDS[COMP_CWORD]}"
1226 case "$cur" in
1227 --*)
1228 __gitcomp "$__git_merge_options"
1229 return
1230 esac
1231 __gitcomp "$(__git_refs)"
1234 _git_mergetool ()
1236 local cur="${COMP_WORDS[COMP_CWORD]}"
1237 case "$cur" in
1238 --tool=*)
1239 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1240 return
1242 --*)
1243 __gitcomp "--tool="
1244 return
1246 esac
1247 COMPREPLY=()
1250 _git_merge_base ()
1252 __gitcomp "$(__git_refs)"
1255 _git_mv ()
1257 local cur="${COMP_WORDS[COMP_CWORD]}"
1258 case "$cur" in
1259 --*)
1260 __gitcomp "--dry-run"
1261 return
1263 esac
1264 COMPREPLY=()
1267 _git_name_rev ()
1269 __gitcomp "--tags --all --stdin"
1272 _git_pull ()
1274 __git_complete_strategy && return
1276 local cur="${COMP_WORDS[COMP_CWORD]}"
1277 case "$cur" in
1278 --*)
1279 __gitcomp "
1280 --rebase --no-rebase
1281 $__git_merge_options
1282 $__git_fetch_options
1284 return
1286 esac
1287 __git_complete_remote_or_refspec
1290 _git_push ()
1292 local cur="${COMP_WORDS[COMP_CWORD]}"
1293 case "${COMP_WORDS[COMP_CWORD-1]}" in
1294 --repo)
1295 __gitcomp "$(__git_remotes)"
1296 return
1297 esac
1298 case "$cur" in
1299 --repo=*)
1300 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1301 return
1303 --*)
1304 __gitcomp "
1305 --all --mirror --tags --dry-run --force --verbose
1306 --receive-pack= --repo=
1308 return
1310 esac
1311 __git_complete_remote_or_refspec
1314 _git_rebase ()
1316 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1317 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1318 __gitcomp "--continue --skip --abort"
1319 return
1321 __git_complete_strategy && return
1322 case "$cur" in
1323 --*)
1324 __gitcomp "--onto --merge --strategy --interactive"
1325 return
1326 esac
1327 __gitcomp "$(__git_refs)"
1330 __git_send_email_confirm_options="always never auto cc compose"
1331 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1333 _git_send_email ()
1335 local cur="${COMP_WORDS[COMP_CWORD]}"
1336 case "$cur" in
1337 --confirm=*)
1338 __gitcomp "
1339 $__git_send_email_confirm_options
1340 " "" "${cur##--confirm=}"
1341 return
1343 --suppress-cc=*)
1344 __gitcomp "
1345 $__git_send_email_suppresscc_options
1346 " "" "${cur##--suppress-cc=}"
1348 return
1350 --smtp-encryption=*)
1351 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1352 return
1354 --*)
1355 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1356 --compose --confirm= --dry-run --envelope-sender
1357 --from --identity
1358 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1359 --no-suppress-from --no-thread --quiet
1360 --signed-off-by-cc --smtp-pass --smtp-server
1361 --smtp-server-port --smtp-encryption= --smtp-user
1362 --subject --suppress-cc= --suppress-from --thread --to
1363 --validate --no-validate"
1364 return
1366 esac
1367 COMPREPLY=()
1370 __git_config_get_set_variables ()
1372 local prevword word config_file= c=$COMP_CWORD
1373 while [ $c -gt 1 ]; do
1374 word="${COMP_WORDS[c]}"
1375 case "$word" in
1376 --global|--system|--file=*)
1377 config_file="$word"
1378 break
1380 -f|--file)
1381 config_file="$word $prevword"
1382 break
1384 esac
1385 prevword=$word
1386 c=$((--c))
1387 done
1389 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1390 while read line
1392 case "$line" in
1393 *.*=*)
1394 echo "${line/=*/}"
1396 esac
1397 done
1400 _git_config ()
1402 local cur="${COMP_WORDS[COMP_CWORD]}"
1403 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1404 case "$prv" in
1405 branch.*.remote)
1406 __gitcomp "$(__git_remotes)"
1407 return
1409 branch.*.merge)
1410 __gitcomp "$(__git_refs)"
1411 return
1413 remote.*.fetch)
1414 local remote="${prv#remote.}"
1415 remote="${remote%.fetch}"
1416 __gitcomp "$(__git_refs_remotes "$remote")"
1417 return
1419 remote.*.push)
1420 local remote="${prv#remote.}"
1421 remote="${remote%.push}"
1422 __gitcomp "$(git --git-dir="$(__gitdir)" \
1423 for-each-ref --format='%(refname):%(refname)' \
1424 refs/heads)"
1425 return
1427 pull.twohead|pull.octopus)
1428 __gitcomp "$(__git_merge_strategies)"
1429 return
1431 color.branch|color.diff|color.interactive|\
1432 color.showbranch|color.status|color.ui)
1433 __gitcomp "always never auto"
1434 return
1436 color.pager)
1437 __gitcomp "false true"
1438 return
1440 color.*.*)
1441 __gitcomp "
1442 normal black red green yellow blue magenta cyan white
1443 bold dim ul blink reverse
1445 return
1447 help.format)
1448 __gitcomp "man info web html"
1449 return
1451 log.date)
1452 __gitcomp "$__git_log_date_formats"
1453 return
1455 sendemail.aliasesfiletype)
1456 __gitcomp "mutt mailrc pine elm gnus"
1457 return
1459 sendemail.confirm)
1460 __gitcomp "$__git_send_email_confirm_options"
1461 return
1463 sendemail.suppresscc)
1464 __gitcomp "$__git_send_email_suppresscc_options"
1465 return
1467 --get|--get-all|--unset|--unset-all)
1468 __gitcomp "$(__git_config_get_set_variables)"
1469 return
1471 *.*)
1472 COMPREPLY=()
1473 return
1475 esac
1476 case "$cur" in
1477 --*)
1478 __gitcomp "
1479 --global --system --file=
1480 --list --replace-all
1481 --get --get-all --get-regexp
1482 --add --unset --unset-all
1483 --remove-section --rename-section
1485 return
1487 branch.*.*)
1488 local pfx="${cur%.*}."
1489 cur="${cur##*.}"
1490 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1491 return
1493 branch.*)
1494 local pfx="${cur%.*}."
1495 cur="${cur#*.}"
1496 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1497 return
1499 guitool.*.*)
1500 local pfx="${cur%.*}."
1501 cur="${cur##*.}"
1502 __gitcomp "
1503 argprompt cmd confirm needsfile noconsole norescan
1504 prompt revprompt revunmerged title
1505 " "$pfx" "$cur"
1506 return
1508 difftool.*.*)
1509 local pfx="${cur%.*}."
1510 cur="${cur##*.}"
1511 __gitcomp "cmd path" "$pfx" "$cur"
1512 return
1514 man.*.*)
1515 local pfx="${cur%.*}."
1516 cur="${cur##*.}"
1517 __gitcomp "cmd path" "$pfx" "$cur"
1518 return
1520 mergetool.*.*)
1521 local pfx="${cur%.*}."
1522 cur="${cur##*.}"
1523 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1524 return
1526 pager.*)
1527 local pfx="${cur%.*}."
1528 cur="${cur#*.}"
1529 __gitcomp "$(__git_all_commands)" "$pfx" "$cur"
1530 return
1532 remote.*.*)
1533 local pfx="${cur%.*}."
1534 cur="${cur##*.}"
1535 __gitcomp "
1536 url proxy fetch push mirror skipDefaultUpdate
1537 receivepack uploadpack tagopt pushurl
1538 " "$pfx" "$cur"
1539 return
1541 remote.*)
1542 local pfx="${cur%.*}."
1543 cur="${cur#*.}"
1544 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1545 return
1547 url.*.*)
1548 local pfx="${cur%.*}."
1549 cur="${cur##*.}"
1550 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1551 return
1553 esac
1554 __gitcomp "
1555 add.ignore-errors
1556 alias.
1557 apply.ignorewhitespace
1558 apply.whitespace
1559 branch.autosetupmerge
1560 branch.autosetuprebase
1561 clean.requireForce
1562 color.branch
1563 color.branch.current
1564 color.branch.local
1565 color.branch.plain
1566 color.branch.remote
1567 color.diff
1568 color.diff.commit
1569 color.diff.frag
1570 color.diff.meta
1571 color.diff.new
1572 color.diff.old
1573 color.diff.plain
1574 color.diff.whitespace
1575 color.grep
1576 color.grep.external
1577 color.grep.match
1578 color.interactive
1579 color.interactive.header
1580 color.interactive.help
1581 color.interactive.prompt
1582 color.pager
1583 color.showbranch
1584 color.status
1585 color.status.added
1586 color.status.changed
1587 color.status.header
1588 color.status.nobranch
1589 color.status.untracked
1590 color.status.updated
1591 color.ui
1592 commit.template
1593 core.autocrlf
1594 core.bare
1595 core.compression
1596 core.createObject
1597 core.deltaBaseCacheLimit
1598 core.editor
1599 core.excludesfile
1600 core.fileMode
1601 core.fsyncobjectfiles
1602 core.gitProxy
1603 core.ignoreCygwinFSTricks
1604 core.ignoreStat
1605 core.logAllRefUpdates
1606 core.loosecompression
1607 core.packedGitLimit
1608 core.packedGitWindowSize
1609 core.pager
1610 core.preferSymlinkRefs
1611 core.preloadindex
1612 core.quotepath
1613 core.repositoryFormatVersion
1614 core.safecrlf
1615 core.sharedRepository
1616 core.symlinks
1617 core.trustctime
1618 core.warnAmbiguousRefs
1619 core.whitespace
1620 core.worktree
1621 diff.autorefreshindex
1622 diff.external
1623 diff.mnemonicprefix
1624 diff.renameLimit
1625 diff.renameLimit.
1626 diff.renames
1627 diff.suppressBlankEmpty
1628 diff.tool
1629 diff.wordRegex
1630 difftool.
1631 difftool.prompt
1632 fetch.unpackLimit
1633 format.attach
1634 format.cc
1635 format.headers
1636 format.numbered
1637 format.pretty
1638 format.signoff
1639 format.subjectprefix
1640 format.suffix
1641 format.thread
1642 gc.aggressiveWindow
1643 gc.auto
1644 gc.autopacklimit
1645 gc.packrefs
1646 gc.pruneexpire
1647 gc.reflogexpire
1648 gc.reflogexpireunreachable
1649 gc.rerereresolved
1650 gc.rerereunresolved
1651 gitcvs.allbinary
1652 gitcvs.commitmsgannotation
1653 gitcvs.dbTableNamePrefix
1654 gitcvs.dbdriver
1655 gitcvs.dbname
1656 gitcvs.dbpass
1657 gitcvs.dbuser
1658 gitcvs.enabled
1659 gitcvs.logfile
1660 gitcvs.usecrlfattr
1661 guitool.
1662 gui.blamehistoryctx
1663 gui.commitmsgwidth
1664 gui.copyblamethreshold
1665 gui.diffcontext
1666 gui.encoding
1667 gui.fastcopyblame
1668 gui.matchtrackingbranch
1669 gui.newbranchtemplate
1670 gui.pruneduringfetch
1671 gui.spellingdictionary
1672 gui.trustmtime
1673 help.autocorrect
1674 help.browser
1675 help.format
1676 http.lowSpeedLimit
1677 http.lowSpeedTime
1678 http.maxRequests
1679 http.noEPSV
1680 http.proxy
1681 http.sslCAInfo
1682 http.sslCAPath
1683 http.sslCert
1684 http.sslKey
1685 http.sslVerify
1686 i18n.commitEncoding
1687 i18n.logOutputEncoding
1688 imap.folder
1689 imap.host
1690 imap.pass
1691 imap.port
1692 imap.preformattedHTML
1693 imap.sslverify
1694 imap.tunnel
1695 imap.user
1696 instaweb.browser
1697 instaweb.httpd
1698 instaweb.local
1699 instaweb.modulepath
1700 instaweb.port
1701 interactive.singlekey
1702 log.date
1703 log.showroot
1704 mailmap.file
1705 man.
1706 man.viewer
1707 merge.conflictstyle
1708 merge.log
1709 merge.renameLimit
1710 merge.stat
1711 merge.tool
1712 merge.verbosity
1713 mergetool.
1714 mergetool.keepBackup
1715 mergetool.prompt
1716 pack.compression
1717 pack.deltaCacheLimit
1718 pack.deltaCacheSize
1719 pack.depth
1720 pack.indexVersion
1721 pack.packSizeLimit
1722 pack.threads
1723 pack.window
1724 pack.windowMemory
1725 pager.
1726 pull.octopus
1727 pull.twohead
1728 push.default
1729 rebase.stat
1730 receive.denyCurrentBranch
1731 receive.denyDeletes
1732 receive.denyNonFastForwards
1733 receive.fsckObjects
1734 receive.unpackLimit
1735 repack.usedeltabaseoffset
1736 rerere.autoupdate
1737 rerere.enabled
1738 sendemail.aliasesfile
1739 sendemail.aliasesfiletype
1740 sendemail.bcc
1741 sendemail.cc
1742 sendemail.cccmd
1743 sendemail.chainreplyto
1744 sendemail.confirm
1745 sendemail.envelopesender
1746 sendemail.multiedit
1747 sendemail.signedoffbycc
1748 sendemail.smtpencryption
1749 sendemail.smtppass
1750 sendemail.smtpserver
1751 sendemail.smtpserverport
1752 sendemail.smtpuser
1753 sendemail.suppresscc
1754 sendemail.suppressfrom
1755 sendemail.thread
1756 sendemail.to
1757 sendemail.validate
1758 showbranch.default
1759 status.relativePaths
1760 status.showUntrackedFiles
1761 tar.umask
1762 transfer.unpackLimit
1763 url.
1764 user.email
1765 user.name
1766 user.signingkey
1767 web.browser
1768 branch. remote.
1772 _git_remote ()
1774 local subcommands="add rename rm show prune update set-head"
1775 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1776 if [ -z "$subcommand" ]; then
1777 __gitcomp "$subcommands"
1778 return
1781 case "$subcommand" in
1782 rename|rm|show|prune)
1783 __gitcomp "$(__git_remotes)"
1785 update)
1786 local i c='' IFS=$'\n'
1787 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1788 i="${i#remotes.}"
1789 c="$c ${i/ */}"
1790 done
1791 __gitcomp "$c"
1794 COMPREPLY=()
1796 esac
1799 _git_replace ()
1801 __gitcomp "$(__git_refs)"
1804 _git_reset ()
1806 __git_has_doubledash && return
1808 local cur="${COMP_WORDS[COMP_CWORD]}"
1809 case "$cur" in
1810 --*)
1811 __gitcomp "--merge --mixed --hard --soft --patch"
1812 return
1814 esac
1815 __gitcomp "$(__git_refs)"
1818 _git_revert ()
1820 local cur="${COMP_WORDS[COMP_CWORD]}"
1821 case "$cur" in
1822 --*)
1823 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1824 return
1826 esac
1827 __gitcomp "$(__git_refs)"
1830 _git_rm ()
1832 __git_has_doubledash && return
1834 local cur="${COMP_WORDS[COMP_CWORD]}"
1835 case "$cur" in
1836 --*)
1837 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1838 return
1840 esac
1841 COMPREPLY=()
1844 _git_shortlog ()
1846 __git_has_doubledash && return
1848 local cur="${COMP_WORDS[COMP_CWORD]}"
1849 case "$cur" in
1850 --*)
1851 __gitcomp "
1852 $__git_log_common_options
1853 $__git_log_shortlog_options
1854 --numbered --summary
1856 return
1858 esac
1859 __git_complete_revlist
1862 _git_show ()
1864 __git_has_doubledash && return
1866 local cur="${COMP_WORDS[COMP_CWORD]}"
1867 case "$cur" in
1868 --pretty=*)
1869 __gitcomp "$__git_log_pretty_formats
1870 " "" "${cur##--pretty=}"
1871 return
1873 --format=*)
1874 __gitcomp "$__git_log_pretty_formats
1875 " "" "${cur##--format=}"
1876 return
1878 --*)
1879 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1880 $__git_diff_common_options
1882 return
1884 esac
1885 __git_complete_file
1888 _git_show_branch ()
1890 local cur="${COMP_WORDS[COMP_CWORD]}"
1891 case "$cur" in
1892 --*)
1893 __gitcomp "
1894 --all --remotes --topo-order --current --more=
1895 --list --independent --merge-base --no-name
1896 --color --no-color
1897 --sha1-name --sparse --topics --reflog
1899 return
1901 esac
1902 __git_complete_revlist
1905 _git_stash ()
1907 local cur="${COMP_WORDS[COMP_CWORD]}"
1908 local save_opts='--keep-index --no-keep-index --quiet --patch'
1909 local subcommands='save list show apply clear drop pop create branch'
1910 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1911 if [ -z "$subcommand" ]; then
1912 case "$cur" in
1913 --*)
1914 __gitcomp "$save_opts"
1917 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1918 __gitcomp "$subcommands"
1919 else
1920 COMPREPLY=()
1923 esac
1924 else
1925 case "$subcommand,$cur" in
1926 save,--*)
1927 __gitcomp "$save_opts"
1929 apply,--*|pop,--*)
1930 __gitcomp "--index --quiet"
1932 show,--*|drop,--*|branch,--*)
1933 COMPREPLY=()
1935 show,*|apply,*|drop,*|pop,*|branch,*)
1936 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1937 | sed -n -e 's/:.*//p')"
1940 COMPREPLY=()
1942 esac
1946 _git_submodule ()
1948 __git_has_doubledash && return
1950 local subcommands="add status init update summary foreach sync"
1951 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1952 local cur="${COMP_WORDS[COMP_CWORD]}"
1953 case "$cur" in
1954 --*)
1955 __gitcomp "--quiet --cached"
1958 __gitcomp "$subcommands"
1960 esac
1961 return
1965 _git_svn ()
1967 local subcommands="
1968 init fetch clone rebase dcommit log find-rev
1969 set-tree commit-diff info create-ignore propget
1970 proplist show-ignore show-externals branch tag blame
1971 migrate
1973 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1974 if [ -z "$subcommand" ]; then
1975 __gitcomp "$subcommands"
1976 else
1977 local remote_opts="--username= --config-dir= --no-auth-cache"
1978 local fc_opts="
1979 --follow-parent --authors-file= --repack=
1980 --no-metadata --use-svm-props --use-svnsync-props
1981 --log-window-size= --no-checkout --quiet
1982 --repack-flags --use-log-author --localtime
1983 --ignore-paths= $remote_opts
1985 local init_opts="
1986 --template= --shared= --trunk= --tags=
1987 --branches= --stdlayout --minimize-url
1988 --no-metadata --use-svm-props --use-svnsync-props
1989 --rewrite-root= --prefix= --use-log-author
1990 --add-author-from $remote_opts
1992 local cmt_opts="
1993 --edit --rmdir --find-copies-harder --copy-similarity=
1996 local cur="${COMP_WORDS[COMP_CWORD]}"
1997 case "$subcommand,$cur" in
1998 fetch,--*)
1999 __gitcomp "--revision= --fetch-all $fc_opts"
2001 clone,--*)
2002 __gitcomp "--revision= $fc_opts $init_opts"
2004 init,--*)
2005 __gitcomp "$init_opts"
2007 dcommit,--*)
2008 __gitcomp "
2009 --merge --strategy= --verbose --dry-run
2010 --fetch-all --no-rebase --commit-url
2011 --revision $cmt_opts $fc_opts
2014 set-tree,--*)
2015 __gitcomp "--stdin $cmt_opts $fc_opts"
2017 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2018 show-externals,--*)
2019 __gitcomp "--revision="
2021 log,--*)
2022 __gitcomp "
2023 --limit= --revision= --verbose --incremental
2024 --oneline --show-commit --non-recursive
2025 --authors-file= --color
2028 rebase,--*)
2029 __gitcomp "
2030 --merge --verbose --strategy= --local
2031 --fetch-all --dry-run $fc_opts
2034 commit-diff,--*)
2035 __gitcomp "--message= --file= --revision= $cmt_opts"
2037 info,--*)
2038 __gitcomp "--url"
2040 branch,--*)
2041 __gitcomp "--dry-run --message --tag"
2043 tag,--*)
2044 __gitcomp "--dry-run --message"
2046 blame,--*)
2047 __gitcomp "--git-format"
2049 migrate,--*)
2050 __gitcomp "
2051 --config-dir= --ignore-paths= --minimize
2052 --no-auth-cache --username=
2056 COMPREPLY=()
2058 esac
2062 _git_tag ()
2064 local i c=1 f=0
2065 while [ $c -lt $COMP_CWORD ]; do
2066 i="${COMP_WORDS[c]}"
2067 case "$i" in
2068 -d|-v)
2069 __gitcomp "$(__git_tags)"
2070 return
2075 esac
2076 c=$((++c))
2077 done
2079 case "${COMP_WORDS[COMP_CWORD-1]}" in
2080 -m|-F)
2081 COMPREPLY=()
2083 -*|tag)
2084 if [ $f = 1 ]; then
2085 __gitcomp "$(__git_tags)"
2086 else
2087 COMPREPLY=()
2091 __gitcomp "$(__git_refs)"
2093 esac
2096 _git ()
2098 local i c=1 command __git_dir
2100 while [ $c -lt $COMP_CWORD ]; do
2101 i="${COMP_WORDS[c]}"
2102 case "$i" in
2103 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2104 --bare) __git_dir="." ;;
2105 --version|-p|--paginate) ;;
2106 --help) command="help"; break ;;
2107 *) command="$i"; break ;;
2108 esac
2109 c=$((++c))
2110 done
2112 if [ -z "$command" ]; then
2113 case "${COMP_WORDS[COMP_CWORD]}" in
2114 --*) __gitcomp "
2115 --paginate
2116 --no-pager
2117 --git-dir=
2118 --bare
2119 --version
2120 --exec-path
2121 --html-path
2122 --work-tree=
2123 --help
2126 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
2127 esac
2128 return
2131 local expansion=$(__git_aliased_command "$command")
2132 [ "$expansion" ] && command="$expansion"
2134 case "$command" in
2135 am) _git_am ;;
2136 add) _git_add ;;
2137 apply) _git_apply ;;
2138 archive) _git_archive ;;
2139 bisect) _git_bisect ;;
2140 bundle) _git_bundle ;;
2141 branch) _git_branch ;;
2142 checkout) _git_checkout ;;
2143 cherry) _git_cherry ;;
2144 cherry-pick) _git_cherry_pick ;;
2145 clean) _git_clean ;;
2146 clone) _git_clone ;;
2147 commit) _git_commit ;;
2148 config) _git_config ;;
2149 describe) _git_describe ;;
2150 diff) _git_diff ;;
2151 difftool) _git_difftool ;;
2152 fetch) _git_fetch ;;
2153 format-patch) _git_format_patch ;;
2154 fsck) _git_fsck ;;
2155 gc) _git_gc ;;
2156 grep) _git_grep ;;
2157 help) _git_help ;;
2158 init) _git_init ;;
2159 log) _git_log ;;
2160 ls-files) _git_ls_files ;;
2161 ls-remote) _git_ls_remote ;;
2162 ls-tree) _git_ls_tree ;;
2163 merge) _git_merge;;
2164 mergetool) _git_mergetool;;
2165 merge-base) _git_merge_base ;;
2166 mv) _git_mv ;;
2167 name-rev) _git_name_rev ;;
2168 pull) _git_pull ;;
2169 push) _git_push ;;
2170 rebase) _git_rebase ;;
2171 remote) _git_remote ;;
2172 replace) _git_replace ;;
2173 reset) _git_reset ;;
2174 revert) _git_revert ;;
2175 rm) _git_rm ;;
2176 send-email) _git_send_email ;;
2177 shortlog) _git_shortlog ;;
2178 show) _git_show ;;
2179 show-branch) _git_show_branch ;;
2180 stash) _git_stash ;;
2181 stage) _git_add ;;
2182 submodule) _git_submodule ;;
2183 svn) _git_svn ;;
2184 tag) _git_tag ;;
2185 whatchanged) _git_log ;;
2186 *) COMPREPLY=() ;;
2187 esac
2190 _gitk ()
2192 __git_has_doubledash && return
2194 local cur="${COMP_WORDS[COMP_CWORD]}"
2195 local g="$(__gitdir)"
2196 local merge=""
2197 if [ -f "$g/MERGE_HEAD" ]; then
2198 merge="--merge"
2200 case "$cur" in
2201 --*)
2202 __gitcomp "
2203 $__git_log_common_options
2204 $__git_log_gitk_options
2205 $merge
2207 return
2209 esac
2210 __git_complete_revlist
2213 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2214 || complete -o default -o nospace -F _git git
2215 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2216 || complete -o default -o nospace -F _gitk gitk
2218 # The following are necessary only for Cygwin, and only are needed
2219 # when the user has tab-completed the executable name and consequently
2220 # included the '.exe' suffix.
2222 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2223 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2224 || complete -o default -o nospace -F _git git.exe