1#!bash
2#
3# bash completion support for core Git.
4#
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.
8#
9# The contained completion routines provide support for completing:
10#
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
17#
18# To use these routines:
19#
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
23#
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.
29#
30# 4) Consider changing your PS1 to also show the current branch:
31# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
32#
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.
36#
37# To submit patches:
38#
39# *) Read Documentation/SubmittingPatches
40# *) Send all patches to the current maintainer:
41#
42# "Shawn O. Pearce" <spearce@spearce.org>
43#
44# *) Always CC the Git mailing list:
45#
46# git@vger.kernel.org
47#
48
49case "$COMP_WORDBREAKS" in
50*:*) : great ;;
51*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
52esac
53
54# __gitdir accepts 0 or 1 arguments (i.e., location)
55# returns location of .git repo
56__gitdir ()
57{
58 if [ -z "${1-}" ]; then
59 if [ -n "$__git_dir" ]; then
60 echo "$__git_dir"
61 elif [ -d .git ]; then
62 echo .git
63 else
64 git rev-parse --git-dir 2>/dev/null
65 fi
66 elif [ -d "$1/.git" ]; then
67 echo "$1/.git"
68 else
69 echo "$1"
70 fi
71}
72
73# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
74# returns text to add to bash PS1 prompt (includes branch name)
75__git_ps1 ()
76{
77 local g="$(git rev-parse --git-dir 2>/dev/null)"
78 if [ -n "$g" ]; then
79 local r
80 local b
81 if [ -d "$g/rebase-apply" ]
82 then
83 if test -f "$g/rebase-apply/rebasing"
84 then
85 r="|REBASE"
86 elif test -f "$g/rebase-apply/applying"
87 then
88 r="|AM"
89 else
90 r="|AM/REBASE"
91 fi
92 b="$(git symbolic-ref HEAD 2>/dev/null)"
93 elif [ -f "$g/rebase-merge/interactive" ]
94 then
95 r="|REBASE-i"
96 b="$(cat "$g/rebase-merge/head-name")"
97 elif [ -d "$g/rebase-merge" ]
98 then
99 r="|REBASE-m"
100 b="$(cat "$g/rebase-merge/head-name")"
101 elif [ -f "$g/MERGE_HEAD" ]
102 then
103 r="|MERGING"
104 b="$(git symbolic-ref HEAD 2>/dev/null)"
105 else
106 if [ -f "$g/BISECT_LOG" ]
107 then
108 r="|BISECTING"
109 fi
110 if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
111 then
112 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
113 then
114 b="$(cut -c1-7 "$g/HEAD")..."
115 fi
116 fi
117 fi
118
119 if [ -n "${1-}" ]; then
120 printf "$1" "${b##refs/heads/}$r"
121 else
122 printf " (%s)" "${b##refs/heads/}$r"
123 fi
124 fi
125}
126
127# __gitcomp_1 requires 2 arguments
128__gitcomp_1 ()
129{
130 local c IFS=' '$'\t'$'\n'
131 for c in $1; do
132 case "$c$2" in
133 --*=*) printf %s$'\n' "$c$2" ;;
134 *.) printf %s$'\n' "$c$2" ;;
135 *) printf %s$'\n' "$c$2 " ;;
136 esac
137 done
138}
139
140# __gitcomp accepts 1, 2, 3, or 4 arguments
141# generates completion reply with compgen
142__gitcomp ()
143{
144 local cur="${COMP_WORDS[COMP_CWORD]}"
145 if [ $# -gt 2 ]; then
146 cur="$3"
147 fi
148 case "$cur" in
149 --*=)
150 COMPREPLY=()
151 ;;
152 *)
153 local IFS=$'\n'
154 COMPREPLY=($(compgen -P "${2-}" \
155 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
156 -- "$cur"))
157 ;;
158 esac
159}
160
161# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
162__git_heads ()
163{
164 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
165 if [ -d "$dir" ]; then
166 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
167 refs/heads
168 return
169 fi
170 for i in $(git ls-remote "${1-}" 2>/dev/null); do
171 case "$is_hash,$i" in
172 y,*) is_hash=n ;;
173 n,*^{}) is_hash=y ;;
174 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
175 n,*) is_hash=y; echo "$i" ;;
176 esac
177 done
178}
179
180# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
181__git_tags ()
182{
183 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
184 if [ -d "$dir" ]; then
185 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
186 refs/tags
187 return
188 fi
189 for i in $(git ls-remote "${1-}" 2>/dev/null); do
190 case "$is_hash,$i" in
191 y,*) is_hash=n ;;
192 n,*^{}) is_hash=y ;;
193 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
194 n,*) is_hash=y; echo "$i" ;;
195 esac
196 done
197}
198
199# __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
200__git_refs ()
201{
202 local i is_hash=y dir="$(__gitdir "${1-}")"
203 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
204 if [ -d "$dir" ]; then
205 case "$cur" in
206 refs|refs/*)
207 format="refname"
208 refs="${cur%/*}"
209 ;;
210 *)
211 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
212 format="refname:short"
213 refs="refs/tags refs/heads refs/remotes"
214 ;;
215 esac
216 git --git-dir="$dir" for-each-ref --format="%($format)" \
217 $refs
218 return
219 fi
220 for i in $(git ls-remote "$dir" 2>/dev/null); do
221 case "$is_hash,$i" in
222 y,*) is_hash=n ;;
223 n,*^{}) is_hash=y ;;
224 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
225 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
226 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
227 n,*) is_hash=y; echo "$i" ;;
228 esac
229 done
230}
231
232# __git_refs2 requires 1 argument (to pass to __git_refs)
233__git_refs2 ()
234{
235 local i
236 for i in $(__git_refs "$1"); do
237 echo "$i:$i"
238 done
239}
240
241# __git_refs_remotes requires 1 argument (to pass to ls-remote)
242__git_refs_remotes ()
243{
244 local cmd i is_hash=y
245 for i in $(git ls-remote "$1" 2>/dev/null); do
246 case "$is_hash,$i" in
247 n,refs/heads/*)
248 is_hash=y
249 echo "$i:refs/remotes/$1/${i#refs/heads/}"
250 ;;
251 y,*) is_hash=n ;;
252 n,*^{}) is_hash=y ;;
253 n,refs/tags/*) is_hash=y;;
254 n,*) is_hash=y; ;;
255 esac
256 done
257}
258
259__git_remotes ()
260{
261 local i ngoff IFS=$'\n' d="$(__gitdir)"
262 shopt -q nullglob || ngoff=1
263 shopt -s nullglob
264 for i in "$d/remotes"/*; do
265 echo ${i#$d/remotes/}
266 done
267 [ "$ngoff" ] && shopt -u nullglob
268 for i in $(git --git-dir="$d" config --list); do
269 case "$i" in
270 remote.*.url=*)
271 i="${i#remote.}"
272 echo "${i/.url=*/}"
273 ;;
274 esac
275 done
276}
277
278__git_merge_strategies ()
279{
280 if [ -n "$__git_merge_strategylist" ]; then
281 echo "$__git_merge_strategylist"
282 return
283 fi
284 git merge -s help 2>&1 |
285 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
286 s/\.$//
287 s/.*://
288 s/^[ ]*//
289 s/[ ]*$//
290 p
291 }'
292}
293__git_merge_strategylist=
294__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
295
296__git_complete_file ()
297{
298 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
299 case "$cur" in
300 ?*:*)
301 ref="${cur%%:*}"
302 cur="${cur#*:}"
303 case "$cur" in
304 ?*/*)
305 pfx="${cur%/*}"
306 cur="${cur##*/}"
307 ls="$ref:$pfx"
308 pfx="$pfx/"
309 ;;
310 *)
311 ls="$ref"
312 ;;
313 esac
314
315 case "$COMP_WORDBREAKS" in
316 *:*) : great ;;
317 *) pfx="$ref:$pfx" ;;
318 esac
319
320 local IFS=$'\n'
321 COMPREPLY=($(compgen -P "$pfx" \
322 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
323 | sed '/^100... blob /{
324 s,^.* ,,
325 s,$, ,
326 }
327 /^120000 blob /{
328 s,^.* ,,
329 s,$, ,
330 }
331 /^040000 tree /{
332 s,^.* ,,
333 s,$,/,
334 }
335 s/^.* //')" \
336 -- "$cur"))
337 ;;
338 *)
339 __gitcomp "$(__git_refs)"
340 ;;
341 esac
342}
343
344__git_complete_revlist ()
345{
346 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
347 case "$cur" in
348 *...*)
349 pfx="${cur%...*}..."
350 cur="${cur#*...}"
351 __gitcomp "$(__git_refs)" "$pfx" "$cur"
352 ;;
353 *..*)
354 pfx="${cur%..*}.."
355 cur="${cur#*..}"
356 __gitcomp "$(__git_refs)" "$pfx" "$cur"
357 ;;
358 *)
359 __gitcomp "$(__git_refs)"
360 ;;
361 esac
362}
363
364__git_all_commands ()
365{
366 if [ -n "$__git_all_commandlist" ]; then
367 echo "$__git_all_commandlist"
368 return
369 fi
370 local i IFS=" "$'\n'
371 for i in $(git help -a|egrep '^ ')
372 do
373 case $i in
374 *--*) : helper pattern;;
375 *) echo $i;;
376 esac
377 done
378}
379__git_all_commandlist=
380__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
381
382__git_porcelain_commands ()
383{
384 if [ -n "$__git_porcelain_commandlist" ]; then
385 echo "$__git_porcelain_commandlist"
386 return
387 fi
388 local i IFS=" "$'\n'
389 for i in "help" $(__git_all_commands)
390 do
391 case $i in
392 *--*) : helper pattern;;
393 applymbox) : ask gittus;;
394 applypatch) : ask gittus;;
395 archimport) : import;;
396 cat-file) : plumbing;;
397 check-attr) : plumbing;;
398 check-ref-format) : plumbing;;
399 checkout-index) : plumbing;;
400 commit-tree) : plumbing;;
401 count-objects) : infrequent;;
402 cvsexportcommit) : export;;
403 cvsimport) : import;;
404 cvsserver) : daemon;;
405 daemon) : daemon;;
406 diff-files) : plumbing;;
407 diff-index) : plumbing;;
408 diff-tree) : plumbing;;
409 fast-import) : import;;
410 fast-export) : export;;
411 fsck-objects) : plumbing;;
412 fetch-pack) : plumbing;;
413 fmt-merge-msg) : plumbing;;
414 for-each-ref) : plumbing;;
415 hash-object) : plumbing;;
416 http-*) : transport;;
417 index-pack) : plumbing;;
418 init-db) : deprecated;;
419 local-fetch) : plumbing;;
420 lost-found) : infrequent;;
421 ls-files) : plumbing;;
422 ls-remote) : plumbing;;
423 ls-tree) : plumbing;;
424 mailinfo) : plumbing;;
425 mailsplit) : plumbing;;
426 merge-*) : plumbing;;
427 mktree) : plumbing;;
428 mktag) : plumbing;;
429 pack-objects) : plumbing;;
430 pack-redundant) : plumbing;;
431 pack-refs) : plumbing;;
432 parse-remote) : plumbing;;
433 patch-id) : plumbing;;
434 peek-remote) : plumbing;;
435 prune) : plumbing;;
436 prune-packed) : plumbing;;
437 quiltimport) : import;;
438 read-tree) : plumbing;;
439 receive-pack) : plumbing;;
440 reflog) : plumbing;;
441 repo-config) : deprecated;;
442 rerere) : plumbing;;
443 rev-list) : plumbing;;
444 rev-parse) : plumbing;;
445 runstatus) : plumbing;;
446 sh-setup) : internal;;
447 shell) : daemon;;
448 show-ref) : plumbing;;
449 send-pack) : plumbing;;
450 show-index) : plumbing;;
451 ssh-*) : transport;;
452 stripspace) : plumbing;;
453 symbolic-ref) : plumbing;;
454 tar-tree) : deprecated;;
455 unpack-file) : plumbing;;
456 unpack-objects) : plumbing;;
457 update-index) : plumbing;;
458 update-ref) : plumbing;;
459 update-server-info) : daemon;;
460 upload-archive) : plumbing;;
461 upload-pack) : plumbing;;
462 write-tree) : plumbing;;
463 var) : infrequent;;
464 verify-pack) : infrequent;;
465 verify-tag) : plumbing;;
466 *) echo $i;;
467 esac
468 done
469}
470__git_porcelain_commandlist=
471__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
472
473__git_aliases ()
474{
475 local i IFS=$'\n'
476 for i in $(git --git-dir="$(__gitdir)" config --list); do
477 case "$i" in
478 alias.*)
479 i="${i#alias.}"
480 echo "${i/=*/}"
481 ;;
482 esac
483 done
484}
485
486# __git_aliased_command requires 1 argument
487__git_aliased_command ()
488{
489 local word cmdline=$(git --git-dir="$(__gitdir)" \
490 config --get "alias.$1")
491 for word in $cmdline; do
492 if [ "${word##-*}" ]; then
493 echo $word
494 return
495 fi
496 done
497}
498
499# __git_find_subcommand requires 1 argument
500__git_find_subcommand ()
501{
502 local word subcommand c=1
503
504 while [ $c -lt $COMP_CWORD ]; do
505 word="${COMP_WORDS[c]}"
506 for subcommand in $1; do
507 if [ "$subcommand" = "$word" ]; then
508 echo "$subcommand"
509 return
510 fi
511 done
512 c=$((++c))
513 done
514}
515
516__git_has_doubledash ()
517{
518 local c=1
519 while [ $c -lt $COMP_CWORD ]; do
520 if [ "--" = "${COMP_WORDS[c]}" ]; then
521 return 0
522 fi
523 c=$((++c))
524 done
525 return 1
526}
527
528__git_whitespacelist="nowarn warn error error-all fix"
529
530_git_am ()
531{
532 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
533 if [ -d "$dir"/rebase-apply ]; then
534 __gitcomp "--skip --resolved --abort"
535 return
536 fi
537 case "$cur" in
538 --whitespace=*)
539 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
540 return
541 ;;
542 --*)
543 __gitcomp "
544 --signoff --utf8 --binary --3way --interactive
545 --whitespace=
546 "
547 return
548 esac
549 COMPREPLY=()
550}
551
552_git_apply ()
553{
554 local cur="${COMP_WORDS[COMP_CWORD]}"
555 case "$cur" in
556 --whitespace=*)
557 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
558 return
559 ;;
560 --*)
561 __gitcomp "
562 --stat --numstat --summary --check --index
563 --cached --index-info --reverse --reject --unidiff-zero
564 --apply --no-add --exclude=
565 --whitespace= --inaccurate-eof --verbose
566 "
567 return
568 esac
569 COMPREPLY=()
570}
571
572_git_add ()
573{
574 __git_has_doubledash && return
575
576 local cur="${COMP_WORDS[COMP_CWORD]}"
577 case "$cur" in
578 --*)
579 __gitcomp "
580 --interactive --refresh --patch --update --dry-run
581 --ignore-errors --intent-to-add
582 "
583 return
584 esac
585 COMPREPLY=()
586}
587
588_git_archive ()
589{
590 local cur="${COMP_WORDS[COMP_CWORD]}"
591 case "$cur" in
592 --format=*)
593 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
594 return
595 ;;
596 --remote=*)
597 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
598 return
599 ;;
600 --*)
601 __gitcomp "
602 --format= --list --verbose
603 --prefix= --remote= --exec=
604 "
605 return
606 ;;
607 esac
608 __git_complete_file
609}
610
611_git_bisect ()
612{
613 __git_has_doubledash && return
614
615 local subcommands="start bad good skip reset visualize replay log run"
616 local subcommand="$(__git_find_subcommand "$subcommands")"
617 if [ -z "$subcommand" ]; then
618 __gitcomp "$subcommands"
619 return
620 fi
621
622 case "$subcommand" in
623 bad|good|reset|skip)
624 __gitcomp "$(__git_refs)"
625 ;;
626 *)
627 COMPREPLY=()
628 ;;
629 esac
630}
631
632_git_branch ()
633{
634 local i c=1 only_local_ref="n" has_r="n"
635
636 while [ $c -lt $COMP_CWORD ]; do
637 i="${COMP_WORDS[c]}"
638 case "$i" in
639 -d|-m) only_local_ref="y" ;;
640 -r) has_r="y" ;;
641 esac
642 c=$((++c))
643 done
644
645 case "${COMP_WORDS[COMP_CWORD]}" in
646 --*)
647 __gitcomp "
648 --color --no-color --verbose --abbrev= --no-abbrev
649 --track --no-track --contains --merged --no-merged
650 "
651 ;;
652 *)
653 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
654 __gitcomp "$(__git_heads)"
655 else
656 __gitcomp "$(__git_refs)"
657 fi
658 ;;
659 esac
660}
661
662_git_bundle ()
663{
664 local cmd="${COMP_WORDS[2]}"
665 case "$COMP_CWORD" in
666 2)
667 __gitcomp "create list-heads verify unbundle"
668 ;;
669 3)
670 # looking for a file
671 ;;
672 *)
673 case "$cmd" in
674 create)
675 __git_complete_revlist
676 ;;
677 esac
678 ;;
679 esac
680}
681
682_git_checkout ()
683{
684 __git_has_doubledash && return
685
686 __gitcomp "$(__git_refs)"
687}
688
689_git_cherry ()
690{
691 __gitcomp "$(__git_refs)"
692}
693
694_git_cherry_pick ()
695{
696 local cur="${COMP_WORDS[COMP_CWORD]}"
697 case "$cur" in
698 --*)
699 __gitcomp "--edit --no-commit"
700 ;;
701 *)
702 __gitcomp "$(__git_refs)"
703 ;;
704 esac
705}
706
707_git_clean ()
708{
709 __git_has_doubledash && return
710
711 local cur="${COMP_WORDS[COMP_CWORD]}"
712 case "$cur" in
713 --*)
714 __gitcomp "--dry-run --quiet"
715 return
716 ;;
717 esac
718 COMPREPLY=()
719}
720
721_git_clone ()
722{
723 local cur="${COMP_WORDS[COMP_CWORD]}"
724 case "$cur" in
725 --*)
726 __gitcomp "
727 --local
728 --no-hardlinks
729 --shared
730 --reference
731 --quiet
732 --no-checkout
733 --bare
734 --mirror
735 --origin
736 --upload-pack
737 --template=
738 --depth
739 "
740 return
741 ;;
742 esac
743 COMPREPLY=()
744}
745
746_git_commit ()
747{
748 __git_has_doubledash && return
749
750 local cur="${COMP_WORDS[COMP_CWORD]}"
751 case "$cur" in
752 --*)
753 __gitcomp "
754 --all --author= --signoff --verify --no-verify
755 --edit --amend --include --only --interactive
756 "
757 return
758 esac
759 COMPREPLY=()
760}
761
762_git_describe ()
763{
764 local cur="${COMP_WORDS[COMP_CWORD]}"
765 case "$cur" in
766 --*)
767 __gitcomp "
768 --all --tags --contains --abbrev= --candidates=
769 --exact-match --debug --long --match --always
770 "
771 return
772 esac
773 __gitcomp "$(__git_refs)"
774}
775
776__git_diff_common_options="--stat --numstat --shortstat --summary
777 --patch-with-stat --name-only --name-status --color
778 --no-color --color-words --no-renames --check
779 --full-index --binary --abbrev --diff-filter=
780 --find-copies-harder
781 --text --ignore-space-at-eol --ignore-space-change
782 --ignore-all-space --exit-code --quiet --ext-diff
783 --no-ext-diff
784 --no-prefix --src-prefix= --dst-prefix=
785 --inter-hunk-context=
786 --patience
787 --raw
788"
789
790_git_diff ()
791{
792 __git_has_doubledash && return
793
794 local cur="${COMP_WORDS[COMP_CWORD]}"
795 case "$cur" in
796 --*)
797 __gitcomp "--cached --pickaxe-all --pickaxe-regex
798 --base --ours --theirs
799 $__git_diff_common_options
800 "
801 return
802 ;;
803 esac
804 __git_complete_file
805}
806
807_git_fetch ()
808{
809 local cur="${COMP_WORDS[COMP_CWORD]}"
810
811 if [ "$COMP_CWORD" = 2 ]; then
812 __gitcomp "$(__git_remotes)"
813 else
814 case "$cur" in
815 *:*)
816 local pfx=""
817 case "$COMP_WORDBREAKS" in
818 *:*) : great ;;
819 *) pfx="${cur%%:*}:" ;;
820 esac
821 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
822 ;;
823 *)
824 __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
825 ;;
826 esac
827 fi
828}
829
830_git_format_patch ()
831{
832 local cur="${COMP_WORDS[COMP_CWORD]}"
833 case "$cur" in
834 --*)
835 __gitcomp "
836 --stdout --attach --thread
837 --output-directory
838 --numbered --start-number
839 --numbered-files
840 --keep-subject
841 --signoff
842 --in-reply-to=
843 --full-index --binary
844 --not --all
845 --cover-letter
846 --no-prefix --src-prefix= --dst-prefix=
847 --inline --suffix= --ignore-if-in-upstream
848 --subject-prefix=
849 "
850 return
851 ;;
852 esac
853 __git_complete_revlist
854}
855
856_git_gc ()
857{
858 local cur="${COMP_WORDS[COMP_CWORD]}"
859 case "$cur" in
860 --*)
861 __gitcomp "--prune --aggressive"
862 return
863 ;;
864 esac
865 COMPREPLY=()
866}
867
868_git_grep ()
869{
870 __git_has_doubledash && return
871
872 local cur="${COMP_WORDS[COMP_CWORD]}"
873 case "$cur" in
874 --*)
875 __gitcomp "
876 --cached
877 --text --ignore-case --word-regexp --invert-match
878 --full-name
879 --extended-regexp --basic-regexp --fixed-strings
880 --files-with-matches --name-only
881 --files-without-match
882 --count
883 --and --or --not --all-match
884 "
885 return
886 ;;
887 esac
888 COMPREPLY=()
889}
890
891_git_help ()
892{
893 local cur="${COMP_WORDS[COMP_CWORD]}"
894 case "$cur" in
895 --*)
896 __gitcomp "--all --info --man --web"
897 return
898 ;;
899 esac
900 __gitcomp "$(__git_all_commands)
901 attributes cli core-tutorial cvs-migration
902 diffcore gitk glossary hooks ignore modules
903 repository-layout tutorial tutorial-2
904 workflows
905 "
906}
907
908_git_init ()
909{
910 local cur="${COMP_WORDS[COMP_CWORD]}"
911 case "$cur" in
912 --shared=*)
913 __gitcomp "
914 false true umask group all world everybody
915 " "" "${cur##--shared=}"
916 return
917 ;;
918 --*)
919 __gitcomp "--quiet --bare --template= --shared --shared="
920 return
921 ;;
922 esac
923 COMPREPLY=()
924}
925
926_git_ls_files ()
927{
928 __git_has_doubledash && return
929
930 local cur="${COMP_WORDS[COMP_CWORD]}"
931 case "$cur" in
932 --*)
933 __gitcomp "--cached --deleted --modified --others --ignored
934 --stage --directory --no-empty-directory --unmerged
935 --killed --exclude= --exclude-from=
936 --exclude-per-directory= --exclude-standard
937 --error-unmatch --with-tree= --full-name
938 --abbrev --ignored --exclude-per-directory
939 "
940 return
941 ;;
942 esac
943 COMPREPLY=()
944}
945
946_git_ls_remote ()
947{
948 __gitcomp "$(__git_remotes)"
949}
950
951_git_ls_tree ()
952{
953 __git_complete_file
954}
955
956__git_log_pretty_formats="oneline short medium full fuller email raw format:"
957
958_git_log ()
959{
960 __git_has_doubledash && return
961
962 local cur="${COMP_WORDS[COMP_CWORD]}"
963 case "$cur" in
964 --pretty=*)
965 __gitcomp "$__git_log_pretty_formats
966 " "" "${cur##--pretty=}"
967 return
968 ;;
969 --date=*)
970 __gitcomp "
971 relative iso8601 rfc2822 short local default
972 " "" "${cur##--date=}"
973 return
974 ;;
975 --*)
976 __gitcomp "
977 --max-count= --max-age= --since= --after=
978 --min-age= --before= --until=
979 --root --topo-order --date-order --reverse
980 --no-merges --follow
981 --abbrev-commit --abbrev=
982 --relative-date --date=
983 --author= --committer= --grep=
984 --all-match
985 --pretty=
986 --not --all
987 --left-right --cherry-pick
988 --graph
989 --decorate
990 --walk-reflogs
991 --parents --children --full-history
992 --merge
993 $__git_diff_common_options
994 --pickaxe-all --pickaxe-regex
995 "
996 return
997 ;;
998 esac
999 __git_complete_revlist
1000}
1001
1002_git_merge ()
1003{
1004 local cur="${COMP_WORDS[COMP_CWORD]}"
1005 case "${COMP_WORDS[COMP_CWORD-1]}" in
1006 -s|--strategy)
1007 __gitcomp "$(__git_merge_strategies)"
1008 return
1009 esac
1010 case "$cur" in
1011 --strategy=*)
1012 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1013 return
1014 ;;
1015 --*)
1016 __gitcomp "
1017 --no-commit --no-stat --log --no-log --squash --strategy
1018 "
1019 return
1020 esac
1021 __gitcomp "$(__git_refs)"
1022}
1023
1024_git_mergetool ()
1025{
1026 local cur="${COMP_WORDS[COMP_CWORD]}"
1027 case "$cur" in
1028 --tool=*)
1029 __gitcomp "
1030 kdiff3 tkdiff meld xxdiff emerge
1031 vimdiff gvimdiff ecmerge opendiff
1032 " "" "${cur##--tool=}"
1033 return
1034 ;;
1035 --*)
1036 __gitcomp "--tool="
1037 return
1038 ;;
1039 esac
1040 COMPREPLY=()
1041}
1042
1043_git_merge_base ()
1044{
1045 __gitcomp "$(__git_refs)"
1046}
1047
1048_git_mv ()
1049{
1050 local cur="${COMP_WORDS[COMP_CWORD]}"
1051 case "$cur" in
1052 --*)
1053 __gitcomp "--dry-run"
1054 return
1055 ;;
1056 esac
1057 COMPREPLY=()
1058}
1059
1060_git_name_rev ()
1061{
1062 __gitcomp "--tags --all --stdin"
1063}
1064
1065_git_pull ()
1066{
1067 local cur="${COMP_WORDS[COMP_CWORD]}"
1068
1069 if [ "$COMP_CWORD" = 2 ]; then
1070 __gitcomp "$(__git_remotes)"
1071 else
1072 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1073 fi
1074}
1075
1076_git_push ()
1077{
1078 local cur="${COMP_WORDS[COMP_CWORD]}"
1079
1080 if [ "$COMP_CWORD" = 2 ]; then
1081 __gitcomp "$(__git_remotes)"
1082 else
1083 case "$cur" in
1084 *:*)
1085 local pfx=""
1086 case "$COMP_WORDBREAKS" in
1087 *:*) : great ;;
1088 *) pfx="${cur%%:*}:" ;;
1089 esac
1090
1091 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1092 ;;
1093 +*)
1094 __gitcomp "$(__git_refs)" + "${cur#+}"
1095 ;;
1096 *)
1097 __gitcomp "$(__git_refs)"
1098 ;;
1099 esac
1100 fi
1101}
1102
1103_git_rebase ()
1104{
1105 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1106 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1107 __gitcomp "--continue --skip --abort"
1108 return
1109 fi
1110 case "${COMP_WORDS[COMP_CWORD-1]}" in
1111 -s|--strategy)
1112 __gitcomp "$(__git_merge_strategies)"
1113 return
1114 esac
1115 case "$cur" in
1116 --strategy=*)
1117 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1118 return
1119 ;;
1120 --*)
1121 __gitcomp "--onto --merge --strategy --interactive"
1122 return
1123 esac
1124 __gitcomp "$(__git_refs)"
1125}
1126
1127_git_send_email ()
1128{
1129 local cur="${COMP_WORDS[COMP_CWORD]}"
1130 case "$cur" in
1131 --*)
1132 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1133 --dry-run --envelope-sender --from --identity
1134 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1135 --no-suppress-from --no-thread --quiet
1136 --signed-off-by-cc --smtp-pass --smtp-server
1137 --smtp-server-port --smtp-ssl --smtp-user --subject
1138 --suppress-cc --suppress-from --thread --to
1139 --validate --no-validate"
1140 return
1141 ;;
1142 esac
1143 COMPREPLY=()
1144}
1145
1146_git_config ()
1147{
1148 local cur="${COMP_WORDS[COMP_CWORD]}"
1149 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1150 case "$prv" in
1151 branch.*.remote)
1152 __gitcomp "$(__git_remotes)"
1153 return
1154 ;;
1155 branch.*.merge)
1156 __gitcomp "$(__git_refs)"
1157 return
1158 ;;
1159 remote.*.fetch)
1160 local remote="${prv#remote.}"
1161 remote="${remote%.fetch}"
1162 __gitcomp "$(__git_refs_remotes "$remote")"
1163 return
1164 ;;
1165 remote.*.push)
1166 local remote="${prv#remote.}"
1167 remote="${remote%.push}"
1168 __gitcomp "$(git --git-dir="$(__gitdir)" \
1169 for-each-ref --format='%(refname):%(refname)' \
1170 refs/heads)"
1171 return
1172 ;;
1173 pull.twohead|pull.octopus)
1174 __gitcomp "$(__git_merge_strategies)"
1175 return
1176 ;;
1177 color.branch|color.diff|color.status)
1178 __gitcomp "always never auto"
1179 return
1180 ;;
1181 color.*.*)
1182 __gitcomp "
1183 normal black red green yellow blue magenta cyan white
1184 bold dim ul blink reverse
1185 "
1186 return
1187 ;;
1188 *.*)
1189 COMPREPLY=()
1190 return
1191 ;;
1192 esac
1193 case "$cur" in
1194 --*)
1195 __gitcomp "
1196 --global --system --file=
1197 --list --replace-all
1198 --get --get-all --get-regexp
1199 --add --unset --unset-all
1200 --remove-section --rename-section
1201 "
1202 return
1203 ;;
1204 branch.*.*)
1205 local pfx="${cur%.*}."
1206 cur="${cur##*.}"
1207 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1208 return
1209 ;;
1210 branch.*)
1211 local pfx="${cur%.*}."
1212 cur="${cur#*.}"
1213 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1214 return
1215 ;;
1216 remote.*.*)
1217 local pfx="${cur%.*}."
1218 cur="${cur##*.}"
1219 __gitcomp "
1220 url proxy fetch push mirror skipDefaultUpdate
1221 receivepack uploadpack tagopt
1222 " "$pfx" "$cur"
1223 return
1224 ;;
1225 remote.*)
1226 local pfx="${cur%.*}."
1227 cur="${cur#*.}"
1228 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1229 return
1230 ;;
1231 esac
1232 __gitcomp "
1233 apply.whitespace
1234 branch.autosetupmerge
1235 branch.autosetuprebase
1236 clean.requireForce
1237 color.branch
1238 color.branch.current
1239 color.branch.local
1240 color.branch.plain
1241 color.branch.remote
1242 color.diff
1243 color.diff.commit
1244 color.diff.frag
1245 color.diff.meta
1246 color.diff.new
1247 color.diff.old
1248 color.diff.plain
1249 color.diff.whitespace
1250 color.interactive
1251 color.interactive.header
1252 color.interactive.help
1253 color.interactive.prompt
1254 color.pager
1255 color.status
1256 color.status.added
1257 color.status.changed
1258 color.status.header
1259 color.status.nobranch
1260 color.status.untracked
1261 color.status.updated
1262 color.ui
1263 commit.template
1264 core.autocrlf
1265 core.bare
1266 core.compression
1267 core.deltaBaseCacheLimit
1268 core.editor
1269 core.excludesfile
1270 core.fileMode
1271 core.fsyncobjectfiles
1272 core.gitProxy
1273 core.ignoreCygwinFSTricks
1274 core.ignoreStat
1275 core.logAllRefUpdates
1276 core.loosecompression
1277 core.packedGitLimit
1278 core.packedGitWindowSize
1279 core.pager
1280 core.preferSymlinkRefs
1281 core.preloadindex
1282 core.quotepath
1283 core.repositoryFormatVersion
1284 core.safecrlf
1285 core.sharedRepository
1286 core.symlinks
1287 core.trustctime
1288 core.warnAmbiguousRefs
1289 core.whitespace
1290 core.worktree
1291 diff.autorefreshindex
1292 diff.external
1293 diff.mnemonicprefix
1294 diff.renameLimit
1295 diff.renameLimit.
1296 diff.renames
1297 fetch.unpackLimit
1298 format.headers
1299 format.numbered
1300 format.pretty
1301 format.suffix
1302 gc.aggressiveWindow
1303 gc.auto
1304 gc.autopacklimit
1305 gc.packrefs
1306 gc.pruneexpire
1307 gc.reflogexpire
1308 gc.reflogexpireunreachable
1309 gc.rerereresolved
1310 gc.rerereunresolved
1311 gitcvs.allbinary
1312 gitcvs.dbTableNamePrefix
1313 gitcvs.dbdriver
1314 gitcvs.dbname
1315 gitcvs.dbpass
1316 gitcvs.dbuser
1317 gitcvs.enabled
1318 gitcvs.logfile
1319 gitcvs.usecrlfattr
1320 gui.blamehistoryctx
1321 gui.commitmsgwidth
1322 gui.copyblamethreshold
1323 gui.diffcontext
1324 gui.encoding
1325 gui.fastcopyblame
1326 gui.matchtrackingbranch
1327 gui.newbranchtemplate
1328 gui.pruneduringfetch
1329 gui.spellingdictionary
1330 gui.trustmtime
1331 help.autocorrect
1332 help.browser
1333 help.format
1334 http.lowSpeedLimit
1335 http.lowSpeedTime
1336 http.maxRequests
1337 http.noEPSV
1338 http.proxy
1339 http.sslCAInfo
1340 http.sslCAPath
1341 http.sslCert
1342 http.sslKey
1343 http.sslVerify
1344 i18n.commitEncoding
1345 i18n.logOutputEncoding
1346 instaweb.browser
1347 instaweb.httpd
1348 instaweb.local
1349 instaweb.modulepath
1350 instaweb.port
1351 log.date
1352 log.showroot
1353 man.viewer
1354 merge.conflictstyle
1355 merge.log
1356 merge.renameLimit
1357 merge.stat
1358 merge.tool
1359 merge.verbosity
1360 mergetool.keepBackup
1361 pack.compression
1362 pack.deltaCacheLimit
1363 pack.deltaCacheSize
1364 pack.depth
1365 pack.indexVersion
1366 pack.packSizeLimit
1367 pack.threads
1368 pack.window
1369 pack.windowMemory
1370 pull.octopus
1371 pull.twohead
1372 receive.denyCurrentBranch
1373 receive.denyDeletes
1374 receive.denyNonFastForwards
1375 receive.fsckObjects
1376 receive.unpackLimit
1377 repack.usedeltabaseoffset
1378 rerere.autoupdate
1379 rerere.enabled
1380 showbranch.default
1381 status.relativePaths
1382 status.showUntrackedFiles
1383 tar.umask
1384 transfer.unpackLimit
1385 user.email
1386 user.name
1387 user.signingkey
1388 web.browser
1389 branch. remote.
1390 "
1391}
1392
1393_git_remote ()
1394{
1395 local subcommands="add rename rm show prune update"
1396 local subcommand="$(__git_find_subcommand "$subcommands")"
1397 if [ -z "$subcommand" ]; then
1398 __gitcomp "$subcommands"
1399 return
1400 fi
1401
1402 case "$subcommand" in
1403 rename|rm|show|prune)
1404 __gitcomp "$(__git_remotes)"
1405 ;;
1406 update)
1407 local i c='' IFS=$'\n'
1408 for i in $(git --git-dir="$(__gitdir)" config --list); do
1409 case "$i" in
1410 remotes.*)
1411 i="${i#remotes.}"
1412 c="$c ${i/=*/}"
1413 ;;
1414 esac
1415 done
1416 __gitcomp "$c"
1417 ;;
1418 *)
1419 COMPREPLY=()
1420 ;;
1421 esac
1422}
1423
1424_git_reset ()
1425{
1426 __git_has_doubledash && return
1427
1428 local cur="${COMP_WORDS[COMP_CWORD]}"
1429 case "$cur" in
1430 --*)
1431 __gitcomp "--merge --mixed --hard --soft"
1432 return
1433 ;;
1434 esac
1435 __gitcomp "$(__git_refs)"
1436}
1437
1438_git_revert ()
1439{
1440 local cur="${COMP_WORDS[COMP_CWORD]}"
1441 case "$cur" in
1442 --*)
1443 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1444 return
1445 ;;
1446 esac
1447 __gitcomp "$(__git_refs)"
1448}
1449
1450_git_rm ()
1451{
1452 __git_has_doubledash && return
1453
1454 local cur="${COMP_WORDS[COMP_CWORD]}"
1455 case "$cur" in
1456 --*)
1457 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1458 return
1459 ;;
1460 esac
1461 COMPREPLY=()
1462}
1463
1464_git_shortlog ()
1465{
1466 __git_has_doubledash && return
1467
1468 local cur="${COMP_WORDS[COMP_CWORD]}"
1469 case "$cur" in
1470 --*)
1471 __gitcomp "
1472 --max-count= --max-age= --since= --after=
1473 --min-age= --before= --until=
1474 --no-merges
1475 --author= --committer= --grep=
1476 --all-match
1477 --not --all
1478 --numbered --summary
1479 "
1480 return
1481 ;;
1482 esac
1483 __git_complete_revlist
1484}
1485
1486_git_show ()
1487{
1488 __git_has_doubledash && return
1489
1490 local cur="${COMP_WORDS[COMP_CWORD]}"
1491 case "$cur" in
1492 --pretty=*)
1493 __gitcomp "$__git_log_pretty_formats
1494 " "" "${cur##--pretty=}"
1495 return
1496 ;;
1497 --*)
1498 __gitcomp "--pretty=
1499 $__git_diff_common_options
1500 "
1501 return
1502 ;;
1503 esac
1504 __git_complete_file
1505}
1506
1507_git_show_branch ()
1508{
1509 local cur="${COMP_WORDS[COMP_CWORD]}"
1510 case "$cur" in
1511 --*)
1512 __gitcomp "
1513 --all --remotes --topo-order --current --more=
1514 --list --independent --merge-base --no-name
1515 --sha1-name --topics --reflog
1516 "
1517 return
1518 ;;
1519 esac
1520 __git_complete_revlist
1521}
1522
1523_git_stash ()
1524{
1525 local subcommands='save list show apply clear drop pop create branch'
1526 local subcommand="$(__git_find_subcommand "$subcommands")"
1527 if [ -z "$subcommand" ]; then
1528 __gitcomp "$subcommands"
1529 else
1530 local cur="${COMP_WORDS[COMP_CWORD]}"
1531 case "$subcommand,$cur" in
1532 save,--*)
1533 __gitcomp "--keep-index"
1534 ;;
1535 apply,--*)
1536 __gitcomp "--index"
1537 ;;
1538 show,--*|drop,--*|pop,--*|branch,--*)
1539 COMPREPLY=()
1540 ;;
1541 show,*|apply,*|drop,*|pop,*|branch,*)
1542 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1543 | sed -n -e 's/:.*//p')"
1544 ;;
1545 *)
1546 COMPREPLY=()
1547 ;;
1548 esac
1549 fi
1550}
1551
1552_git_submodule ()
1553{
1554 __git_has_doubledash && return
1555
1556 local subcommands="add status init update summary foreach sync"
1557 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1558 local cur="${COMP_WORDS[COMP_CWORD]}"
1559 case "$cur" in
1560 --*)
1561 __gitcomp "--quiet --cached"
1562 ;;
1563 *)
1564 __gitcomp "$subcommands"
1565 ;;
1566 esac
1567 return
1568 fi
1569}
1570
1571_git_svn ()
1572{
1573 local subcommands="
1574 init fetch clone rebase dcommit log find-rev
1575 set-tree commit-diff info create-ignore propget
1576 proplist show-ignore show-externals
1577 "
1578 local subcommand="$(__git_find_subcommand "$subcommands")"
1579 if [ -z "$subcommand" ]; then
1580 __gitcomp "$subcommands"
1581 else
1582 local remote_opts="--username= --config-dir= --no-auth-cache"
1583 local fc_opts="
1584 --follow-parent --authors-file= --repack=
1585 --no-metadata --use-svm-props --use-svnsync-props
1586 --log-window-size= --no-checkout --quiet
1587 --repack-flags --user-log-author --localtime $remote_opts
1588 "
1589 local init_opts="
1590 --template= --shared= --trunk= --tags=
1591 --branches= --stdlayout --minimize-url
1592 --no-metadata --use-svm-props --use-svnsync-props
1593 --rewrite-root= $remote_opts
1594 "
1595 local cmt_opts="
1596 --edit --rmdir --find-copies-harder --copy-similarity=
1597 "
1598
1599 local cur="${COMP_WORDS[COMP_CWORD]}"
1600 case "$subcommand,$cur" in
1601 fetch,--*)
1602 __gitcomp "--revision= --fetch-all $fc_opts"
1603 ;;
1604 clone,--*)
1605 __gitcomp "--revision= $fc_opts $init_opts"
1606 ;;
1607 init,--*)
1608 __gitcomp "$init_opts"
1609 ;;
1610 dcommit,--*)
1611 __gitcomp "
1612 --merge --strategy= --verbose --dry-run
1613 --fetch-all --no-rebase $cmt_opts $fc_opts
1614 "
1615 ;;
1616 set-tree,--*)
1617 __gitcomp "--stdin $cmt_opts $fc_opts"
1618 ;;
1619 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1620 show-externals,--*)
1621 __gitcomp "--revision="
1622 ;;
1623 log,--*)
1624 __gitcomp "
1625 --limit= --revision= --verbose --incremental
1626 --oneline --show-commit --non-recursive
1627 --authors-file=
1628 "
1629 ;;
1630 rebase,--*)
1631 __gitcomp "
1632 --merge --verbose --strategy= --local
1633 --fetch-all $fc_opts
1634 "
1635 ;;
1636 commit-diff,--*)
1637 __gitcomp "--message= --file= --revision= $cmt_opts"
1638 ;;
1639 info,--*)
1640 __gitcomp "--url"
1641 ;;
1642 *)
1643 COMPREPLY=()
1644 ;;
1645 esac
1646 fi
1647}
1648
1649_git_tag ()
1650{
1651 local i c=1 f=0
1652 while [ $c -lt $COMP_CWORD ]; do
1653 i="${COMP_WORDS[c]}"
1654 case "$i" in
1655 -d|-v)
1656 __gitcomp "$(__git_tags)"
1657 return
1658 ;;
1659 -f)
1660 f=1
1661 ;;
1662 esac
1663 c=$((++c))
1664 done
1665
1666 case "${COMP_WORDS[COMP_CWORD-1]}" in
1667 -m|-F)
1668 COMPREPLY=()
1669 ;;
1670 -*|tag)
1671 if [ $f = 1 ]; then
1672 __gitcomp "$(__git_tags)"
1673 else
1674 COMPREPLY=()
1675 fi
1676 ;;
1677 *)
1678 __gitcomp "$(__git_refs)"
1679 ;;
1680 esac
1681}
1682
1683_git ()
1684{
1685 local i c=1 command __git_dir
1686
1687 while [ $c -lt $COMP_CWORD ]; do
1688 i="${COMP_WORDS[c]}"
1689 case "$i" in
1690 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1691 --bare) __git_dir="." ;;
1692 --version|-p|--paginate) ;;
1693 --help) command="help"; break ;;
1694 *) command="$i"; break ;;
1695 esac
1696 c=$((++c))
1697 done
1698
1699 if [ -z "$command" ]; then
1700 case "${COMP_WORDS[COMP_CWORD]}" in
1701 --*) __gitcomp "
1702 --paginate
1703 --no-pager
1704 --git-dir=
1705 --bare
1706 --version
1707 --exec-path
1708 --work-tree=
1709 --help
1710 "
1711 ;;
1712 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1713 esac
1714 return
1715 fi
1716
1717 local expansion=$(__git_aliased_command "$command")
1718 [ "$expansion" ] && command="$expansion"
1719
1720 case "$command" in
1721 am) _git_am ;;
1722 add) _git_add ;;
1723 apply) _git_apply ;;
1724 archive) _git_archive ;;
1725 bisect) _git_bisect ;;
1726 bundle) _git_bundle ;;
1727 branch) _git_branch ;;
1728 checkout) _git_checkout ;;
1729 cherry) _git_cherry ;;
1730 cherry-pick) _git_cherry_pick ;;
1731 clean) _git_clean ;;
1732 clone) _git_clone ;;
1733 commit) _git_commit ;;
1734 config) _git_config ;;
1735 describe) _git_describe ;;
1736 diff) _git_diff ;;
1737 fetch) _git_fetch ;;
1738 format-patch) _git_format_patch ;;
1739 gc) _git_gc ;;
1740 grep) _git_grep ;;
1741 help) _git_help ;;
1742 init) _git_init ;;
1743 log) _git_log ;;
1744 ls-files) _git_ls_files ;;
1745 ls-remote) _git_ls_remote ;;
1746 ls-tree) _git_ls_tree ;;
1747 merge) _git_merge;;
1748 mergetool) _git_mergetool;;
1749 merge-base) _git_merge_base ;;
1750 mv) _git_mv ;;
1751 name-rev) _git_name_rev ;;
1752 pull) _git_pull ;;
1753 push) _git_push ;;
1754 rebase) _git_rebase ;;
1755 remote) _git_remote ;;
1756 reset) _git_reset ;;
1757 revert) _git_revert ;;
1758 rm) _git_rm ;;
1759 send-email) _git_send_email ;;
1760 shortlog) _git_shortlog ;;
1761 show) _git_show ;;
1762 show-branch) _git_show_branch ;;
1763 stash) _git_stash ;;
1764 stage) _git_add ;;
1765 submodule) _git_submodule ;;
1766 svn) _git_svn ;;
1767 tag) _git_tag ;;
1768 whatchanged) _git_log ;;
1769 *) COMPREPLY=() ;;
1770 esac
1771}
1772
1773_gitk ()
1774{
1775 __git_has_doubledash && return
1776
1777 local cur="${COMP_WORDS[COMP_CWORD]}"
1778 local g="$(git rev-parse --git-dir 2>/dev/null)"
1779 local merge=""
1780 if [ -f $g/MERGE_HEAD ]; then
1781 merge="--merge"
1782 fi
1783 case "$cur" in
1784 --*)
1785 __gitcomp "--not --all $merge"
1786 return
1787 ;;
1788 esac
1789 __git_complete_revlist
1790}
1791
1792complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
1793 || complete -o default -o nospace -F _git git
1794complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
1795 || complete -o default -o nospace -F _gitk gitk
1796
1797# The following are necessary only for Cygwin, and only are needed
1798# when the user has tab-completed the executable name and consequently
1799# included the '.exe' suffix.
1800#
1801if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1802complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
1803 || complete -o default -o nospace -F _git git.exe
1804fi