80edfcacc969986047a27d83df32cc662c9f12f9
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 ()
777{
778 __git_has_doubledash && return
779
780 local cur="${COMP_WORDS[COMP_CWORD]}"
781 case "$cur" in
782 --*)
783 __gitcomp "--cached --stat --numstat --shortstat --summary
784 --patch-with-stat --name-only --name-status --color
785 --no-color --color-words --no-renames --check
786 --full-index --binary --abbrev --diff-filter=
787 --find-copies-harder --pickaxe-all --pickaxe-regex
788 --text --ignore-space-at-eol --ignore-space-change
789 --ignore-all-space --exit-code --quiet --ext-diff
790 --no-ext-diff
791 --no-prefix --src-prefix= --dst-prefix=
792 --base --ours --theirs
793 --inter-hunk-context=
794 "
795 return
796 ;;
797 esac
798 __git_complete_file
799}
800
801_git_fetch ()
802{
803 local cur="${COMP_WORDS[COMP_CWORD]}"
804
805 if [ "$COMP_CWORD" = 2 ]; then
806 __gitcomp "$(__git_remotes)"
807 else
808 case "$cur" in
809 *:*)
810 local pfx=""
811 case "$COMP_WORDBREAKS" in
812 *:*) : great ;;
813 *) pfx="${cur%%:*}:" ;;
814 esac
815 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
816 ;;
817 *)
818 __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
819 ;;
820 esac
821 fi
822}
823
824_git_format_patch ()
825{
826 local cur="${COMP_WORDS[COMP_CWORD]}"
827 case "$cur" in
828 --*)
829 __gitcomp "
830 --stdout --attach --thread
831 --output-directory
832 --numbered --start-number
833 --numbered-files
834 --keep-subject
835 --signoff
836 --in-reply-to=
837 --full-index --binary
838 --not --all
839 --cover-letter
840 --no-prefix --src-prefix= --dst-prefix=
841 --inline --suffix= --ignore-if-in-upstream
842 --subject-prefix=
843 "
844 return
845 ;;
846 esac
847 __git_complete_revlist
848}
849
850_git_gc ()
851{
852 local cur="${COMP_WORDS[COMP_CWORD]}"
853 case "$cur" in
854 --*)
855 __gitcomp "--prune --aggressive"
856 return
857 ;;
858 esac
859 COMPREPLY=()
860}
861
862_git_grep ()
863{
864 __git_has_doubledash && return
865
866 local cur="${COMP_WORDS[COMP_CWORD]}"
867 case "$cur" in
868 --*)
869 __gitcomp "
870 --cached
871 --text --ignore-case --word-regexp --invert-match
872 --full-name
873 --extended-regexp --basic-regexp --fixed-strings
874 --files-with-matches --name-only
875 --files-without-match
876 --count
877 --and --or --not --all-match
878 "
879 return
880 ;;
881 esac
882 COMPREPLY=()
883}
884
885_git_help ()
886{
887 local cur="${COMP_WORDS[COMP_CWORD]}"
888 case "$cur" in
889 --*)
890 __gitcomp "--all --info --man --web"
891 return
892 ;;
893 esac
894 __gitcomp "$(__git_all_commands)
895 attributes cli core-tutorial cvs-migration
896 diffcore gitk glossary hooks ignore modules
897 repository-layout tutorial tutorial-2
898 workflows
899 "
900}
901
902_git_init ()
903{
904 local cur="${COMP_WORDS[COMP_CWORD]}"
905 case "$cur" in
906 --shared=*)
907 __gitcomp "
908 false true umask group all world everybody
909 " "" "${cur##--shared=}"
910 return
911 ;;
912 --*)
913 __gitcomp "--quiet --bare --template= --shared --shared="
914 return
915 ;;
916 esac
917 COMPREPLY=()
918}
919
920_git_ls_files ()
921{
922 __git_has_doubledash && return
923
924 local cur="${COMP_WORDS[COMP_CWORD]}"
925 case "$cur" in
926 --*)
927 __gitcomp "--cached --deleted --modified --others --ignored
928 --stage --directory --no-empty-directory --unmerged
929 --killed --exclude= --exclude-from=
930 --exclude-per-directory= --exclude-standard
931 --error-unmatch --with-tree= --full-name
932 --abbrev --ignored --exclude-per-directory
933 "
934 return
935 ;;
936 esac
937 COMPREPLY=()
938}
939
940_git_ls_remote ()
941{
942 __gitcomp "$(__git_remotes)"
943}
944
945_git_ls_tree ()
946{
947 __git_complete_file
948}
949
950_git_log ()
951{
952 __git_has_doubledash && return
953
954 local cur="${COMP_WORDS[COMP_CWORD]}"
955 case "$cur" in
956 --pretty=*)
957 __gitcomp "
958 oneline short medium full fuller email raw
959 " "" "${cur##--pretty=}"
960 return
961 ;;
962 --date=*)
963 __gitcomp "
964 relative iso8601 rfc2822 short local default
965 " "" "${cur##--date=}"
966 return
967 ;;
968 --*)
969 __gitcomp "
970 --max-count= --max-age= --since= --after=
971 --min-age= --before= --until=
972 --root --topo-order --date-order --reverse
973 --no-merges --follow
974 --abbrev-commit --abbrev=
975 --relative-date --date=
976 --author= --committer= --grep=
977 --all-match
978 --pretty= --name-status --name-only --raw
979 --not --all
980 --left-right --cherry-pick
981 --graph
982 --stat --numstat --shortstat
983 --decorate --diff-filter=
984 --color-words --walk-reflogs
985 --parents --children --full-history
986 --merge
987 --inter-hunk-context=
988 "
989 return
990 ;;
991 esac
992 __git_complete_revlist
993}
994
995_git_merge ()
996{
997 local cur="${COMP_WORDS[COMP_CWORD]}"
998 case "${COMP_WORDS[COMP_CWORD-1]}" in
999 -s|--strategy)
1000 __gitcomp "$(__git_merge_strategies)"
1001 return
1002 esac
1003 case "$cur" in
1004 --strategy=*)
1005 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1006 return
1007 ;;
1008 --*)
1009 __gitcomp "
1010 --no-commit --no-stat --log --no-log --squash --strategy
1011 "
1012 return
1013 esac
1014 __gitcomp "$(__git_refs)"
1015}
1016
1017_git_mergetool ()
1018{
1019 local cur="${COMP_WORDS[COMP_CWORD]}"
1020 case "$cur" in
1021 --tool=*)
1022 __gitcomp "
1023 kdiff3 tkdiff meld xxdiff emerge
1024 vimdiff gvimdiff ecmerge opendiff
1025 " "" "${cur##--tool=}"
1026 return
1027 ;;
1028 --*)
1029 __gitcomp "--tool="
1030 return
1031 ;;
1032 esac
1033 COMPREPLY=()
1034}
1035
1036_git_merge_base ()
1037{
1038 __gitcomp "$(__git_refs)"
1039}
1040
1041_git_mv ()
1042{
1043 local cur="${COMP_WORDS[COMP_CWORD]}"
1044 case "$cur" in
1045 --*)
1046 __gitcomp "--dry-run"
1047 return
1048 ;;
1049 esac
1050 COMPREPLY=()
1051}
1052
1053_git_name_rev ()
1054{
1055 __gitcomp "--tags --all --stdin"
1056}
1057
1058_git_pull ()
1059{
1060 local cur="${COMP_WORDS[COMP_CWORD]}"
1061
1062 if [ "$COMP_CWORD" = 2 ]; then
1063 __gitcomp "$(__git_remotes)"
1064 else
1065 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1066 fi
1067}
1068
1069_git_push ()
1070{
1071 local cur="${COMP_WORDS[COMP_CWORD]}"
1072
1073 if [ "$COMP_CWORD" = 2 ]; then
1074 __gitcomp "$(__git_remotes)"
1075 else
1076 case "$cur" in
1077 *:*)
1078 local pfx=""
1079 case "$COMP_WORDBREAKS" in
1080 *:*) : great ;;
1081 *) pfx="${cur%%:*}:" ;;
1082 esac
1083
1084 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1085 ;;
1086 +*)
1087 __gitcomp "$(__git_refs)" + "${cur#+}"
1088 ;;
1089 *)
1090 __gitcomp "$(__git_refs)"
1091 ;;
1092 esac
1093 fi
1094}
1095
1096_git_rebase ()
1097{
1098 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1099 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1100 __gitcomp "--continue --skip --abort"
1101 return
1102 fi
1103 case "${COMP_WORDS[COMP_CWORD-1]}" in
1104 -s|--strategy)
1105 __gitcomp "$(__git_merge_strategies)"
1106 return
1107 esac
1108 case "$cur" in
1109 --strategy=*)
1110 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1111 return
1112 ;;
1113 --*)
1114 __gitcomp "--onto --merge --strategy --interactive"
1115 return
1116 esac
1117 __gitcomp "$(__git_refs)"
1118}
1119
1120_git_send_email ()
1121{
1122 local cur="${COMP_WORDS[COMP_CWORD]}"
1123 case "$cur" in
1124 --*)
1125 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1126 --dry-run --envelope-sender --from --identity
1127 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1128 --no-suppress-from --no-thread --quiet
1129 --signed-off-by-cc --smtp-pass --smtp-server
1130 --smtp-server-port --smtp-ssl --smtp-user --subject
1131 --suppress-cc --suppress-from --thread --to
1132 --validate --no-validate"
1133 return
1134 ;;
1135 esac
1136 COMPREPLY=()
1137}
1138
1139_git_config ()
1140{
1141 local cur="${COMP_WORDS[COMP_CWORD]}"
1142 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1143 case "$prv" in
1144 branch.*.remote)
1145 __gitcomp "$(__git_remotes)"
1146 return
1147 ;;
1148 branch.*.merge)
1149 __gitcomp "$(__git_refs)"
1150 return
1151 ;;
1152 remote.*.fetch)
1153 local remote="${prv#remote.}"
1154 remote="${remote%.fetch}"
1155 __gitcomp "$(__git_refs_remotes "$remote")"
1156 return
1157 ;;
1158 remote.*.push)
1159 local remote="${prv#remote.}"
1160 remote="${remote%.push}"
1161 __gitcomp "$(git --git-dir="$(__gitdir)" \
1162 for-each-ref --format='%(refname):%(refname)' \
1163 refs/heads)"
1164 return
1165 ;;
1166 pull.twohead|pull.octopus)
1167 __gitcomp "$(__git_merge_strategies)"
1168 return
1169 ;;
1170 color.branch|color.diff|color.status)
1171 __gitcomp "always never auto"
1172 return
1173 ;;
1174 color.*.*)
1175 __gitcomp "
1176 normal black red green yellow blue magenta cyan white
1177 bold dim ul blink reverse
1178 "
1179 return
1180 ;;
1181 *.*)
1182 COMPREPLY=()
1183 return
1184 ;;
1185 esac
1186 case "$cur" in
1187 --*)
1188 __gitcomp "
1189 --global --system --file=
1190 --list --replace-all
1191 --get --get-all --get-regexp
1192 --add --unset --unset-all
1193 --remove-section --rename-section
1194 "
1195 return
1196 ;;
1197 branch.*.*)
1198 local pfx="${cur%.*}."
1199 cur="${cur##*.}"
1200 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1201 return
1202 ;;
1203 branch.*)
1204 local pfx="${cur%.*}."
1205 cur="${cur#*.}"
1206 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1207 return
1208 ;;
1209 remote.*.*)
1210 local pfx="${cur%.*}."
1211 cur="${cur##*.}"
1212 __gitcomp "
1213 url proxy fetch push mirror skipDefaultUpdate
1214 receivepack uploadpack tagopt
1215 " "$pfx" "$cur"
1216 return
1217 ;;
1218 remote.*)
1219 local pfx="${cur%.*}."
1220 cur="${cur#*.}"
1221 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1222 return
1223 ;;
1224 esac
1225 __gitcomp "
1226 apply.whitespace
1227 branch.autosetupmerge
1228 branch.autosetuprebase
1229 clean.requireForce
1230 color.branch
1231 color.branch.current
1232 color.branch.local
1233 color.branch.plain
1234 color.branch.remote
1235 color.diff
1236 color.diff.commit
1237 color.diff.frag
1238 color.diff.meta
1239 color.diff.new
1240 color.diff.old
1241 color.diff.plain
1242 color.diff.whitespace
1243 color.interactive
1244 color.interactive.header
1245 color.interactive.help
1246 color.interactive.prompt
1247 color.pager
1248 color.status
1249 color.status.added
1250 color.status.changed
1251 color.status.header
1252 color.status.nobranch
1253 color.status.untracked
1254 color.status.updated
1255 color.ui
1256 commit.template
1257 core.autocrlf
1258 core.bare
1259 core.compression
1260 core.deltaBaseCacheLimit
1261 core.editor
1262 core.excludesfile
1263 core.fileMode
1264 core.fsyncobjectfiles
1265 core.gitProxy
1266 core.ignoreCygwinFSTricks
1267 core.ignoreStat
1268 core.logAllRefUpdates
1269 core.loosecompression
1270 core.packedGitLimit
1271 core.packedGitWindowSize
1272 core.pager
1273 core.preferSymlinkRefs
1274 core.preloadindex
1275 core.quotepath
1276 core.repositoryFormatVersion
1277 core.safecrlf
1278 core.sharedRepository
1279 core.symlinks
1280 core.trustctime
1281 core.warnAmbiguousRefs
1282 core.whitespace
1283 core.worktree
1284 diff.autorefreshindex
1285 diff.external
1286 diff.mnemonicprefix
1287 diff.renameLimit
1288 diff.renameLimit.
1289 diff.renames
1290 fetch.unpackLimit
1291 format.headers
1292 format.numbered
1293 format.pretty
1294 format.suffix
1295 gc.aggressiveWindow
1296 gc.auto
1297 gc.autopacklimit
1298 gc.packrefs
1299 gc.pruneexpire
1300 gc.reflogexpire
1301 gc.reflogexpireunreachable
1302 gc.rerereresolved
1303 gc.rerereunresolved
1304 gitcvs.allbinary
1305 gitcvs.dbTableNamePrefix
1306 gitcvs.dbdriver
1307 gitcvs.dbname
1308 gitcvs.dbpass
1309 gitcvs.dbuser
1310 gitcvs.enabled
1311 gitcvs.logfile
1312 gitcvs.usecrlfattr
1313 gui.blamehistoryctx
1314 gui.commitmsgwidth
1315 gui.copyblamethreshold
1316 gui.diffcontext
1317 gui.encoding
1318 gui.fastcopyblame
1319 gui.matchtrackingbranch
1320 gui.newbranchtemplate
1321 gui.pruneduringfetch
1322 gui.spellingdictionary
1323 gui.trustmtime
1324 help.autocorrect
1325 help.browser
1326 help.format
1327 http.lowSpeedLimit
1328 http.lowSpeedTime
1329 http.maxRequests
1330 http.noEPSV
1331 http.proxy
1332 http.sslCAInfo
1333 http.sslCAPath
1334 http.sslCert
1335 http.sslKey
1336 http.sslVerify
1337 i18n.commitEncoding
1338 i18n.logOutputEncoding
1339 instaweb.browser
1340 instaweb.httpd
1341 instaweb.local
1342 instaweb.modulepath
1343 instaweb.port
1344 log.date
1345 log.showroot
1346 man.viewer
1347 merge.conflictstyle
1348 merge.log
1349 merge.renameLimit
1350 merge.stat
1351 merge.tool
1352 merge.verbosity
1353 mergetool.keepBackup
1354 pack.compression
1355 pack.deltaCacheLimit
1356 pack.deltaCacheSize
1357 pack.depth
1358 pack.indexVersion
1359 pack.packSizeLimit
1360 pack.threads
1361 pack.window
1362 pack.windowMemory
1363 pull.octopus
1364 pull.twohead
1365 receive.denyCurrentBranch
1366 receive.denyDeletes
1367 receive.denyNonFastForwards
1368 receive.fsckObjects
1369 receive.unpackLimit
1370 repack.usedeltabaseoffset
1371 rerere.autoupdate
1372 rerere.enabled
1373 showbranch.default
1374 status.relativePaths
1375 status.showUntrackedFiles
1376 tar.umask
1377 transfer.unpackLimit
1378 user.email
1379 user.name
1380 user.signingkey
1381 web.browser
1382 branch. remote.
1383 "
1384}
1385
1386_git_remote ()
1387{
1388 local subcommands="add rm show prune update"
1389 local subcommand="$(__git_find_subcommand "$subcommands")"
1390 if [ -z "$subcommand" ]; then
1391 __gitcomp "$subcommands"
1392 return
1393 fi
1394
1395 case "$subcommand" in
1396 rm|show|prune)
1397 __gitcomp "$(__git_remotes)"
1398 ;;
1399 update)
1400 local i c='' IFS=$'\n'
1401 for i in $(git --git-dir="$(__gitdir)" config --list); do
1402 case "$i" in
1403 remotes.*)
1404 i="${i#remotes.}"
1405 c="$c ${i/=*/}"
1406 ;;
1407 esac
1408 done
1409 __gitcomp "$c"
1410 ;;
1411 *)
1412 COMPREPLY=()
1413 ;;
1414 esac
1415}
1416
1417_git_reset ()
1418{
1419 __git_has_doubledash && return
1420
1421 local cur="${COMP_WORDS[COMP_CWORD]}"
1422 case "$cur" in
1423 --*)
1424 __gitcomp "--merge --mixed --hard --soft"
1425 return
1426 ;;
1427 esac
1428 __gitcomp "$(__git_refs)"
1429}
1430
1431_git_revert ()
1432{
1433 local cur="${COMP_WORDS[COMP_CWORD]}"
1434 case "$cur" in
1435 --*)
1436 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1437 return
1438 ;;
1439 esac
1440 __gitcomp "$(__git_refs)"
1441}
1442
1443_git_rm ()
1444{
1445 __git_has_doubledash && return
1446
1447 local cur="${COMP_WORDS[COMP_CWORD]}"
1448 case "$cur" in
1449 --*)
1450 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1451 return
1452 ;;
1453 esac
1454 COMPREPLY=()
1455}
1456
1457_git_shortlog ()
1458{
1459 __git_has_doubledash && return
1460
1461 local cur="${COMP_WORDS[COMP_CWORD]}"
1462 case "$cur" in
1463 --*)
1464 __gitcomp "
1465 --max-count= --max-age= --since= --after=
1466 --min-age= --before= --until=
1467 --no-merges
1468 --author= --committer= --grep=
1469 --all-match
1470 --not --all
1471 --numbered --summary
1472 "
1473 return
1474 ;;
1475 esac
1476 __git_complete_revlist
1477}
1478
1479_git_show ()
1480{
1481 __git_has_doubledash && return
1482
1483 local cur="${COMP_WORDS[COMP_CWORD]}"
1484 case "$cur" in
1485 --pretty=*)
1486 __gitcomp "
1487 oneline short medium full fuller email raw
1488 " "" "${cur##--pretty=}"
1489 return
1490 ;;
1491 --*)
1492 __gitcomp "--pretty="
1493 return
1494 ;;
1495 esac
1496 __git_complete_file
1497}
1498
1499_git_show_branch ()
1500{
1501 local cur="${COMP_WORDS[COMP_CWORD]}"
1502 case "$cur" in
1503 --*)
1504 __gitcomp "
1505 --all --remotes --topo-order --current --more=
1506 --list --independent --merge-base --no-name
1507 --sha1-name --topics --reflog
1508 "
1509 return
1510 ;;
1511 esac
1512 __git_complete_revlist
1513}
1514
1515_git_stash ()
1516{
1517 local subcommands='save list show apply clear drop pop create branch'
1518 local subcommand="$(__git_find_subcommand "$subcommands")"
1519 if [ -z "$subcommand" ]; then
1520 __gitcomp "$subcommands"
1521 else
1522 local cur="${COMP_WORDS[COMP_CWORD]}"
1523 case "$subcommand,$cur" in
1524 save,--*)
1525 __gitcomp "--keep-index"
1526 ;;
1527 apply,--*)
1528 __gitcomp "--index"
1529 ;;
1530 show,--*|drop,--*|pop,--*|branch,--*)
1531 COMPREPLY=()
1532 ;;
1533 show,*|apply,*|drop,*|pop,*|branch,*)
1534 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1535 | sed -n -e 's/:.*//p')"
1536 ;;
1537 *)
1538 COMPREPLY=()
1539 ;;
1540 esac
1541 fi
1542}
1543
1544_git_submodule ()
1545{
1546 __git_has_doubledash && return
1547
1548 local subcommands="add status init update summary foreach sync"
1549 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1550 local cur="${COMP_WORDS[COMP_CWORD]}"
1551 case "$cur" in
1552 --*)
1553 __gitcomp "--quiet --cached"
1554 ;;
1555 *)
1556 __gitcomp "$subcommands"
1557 ;;
1558 esac
1559 return
1560 fi
1561}
1562
1563_git_svn ()
1564{
1565 local subcommands="
1566 init fetch clone rebase dcommit log find-rev
1567 set-tree commit-diff info create-ignore propget
1568 proplist show-ignore show-externals
1569 "
1570 local subcommand="$(__git_find_subcommand "$subcommands")"
1571 if [ -z "$subcommand" ]; then
1572 __gitcomp "$subcommands"
1573 else
1574 local remote_opts="--username= --config-dir= --no-auth-cache"
1575 local fc_opts="
1576 --follow-parent --authors-file= --repack=
1577 --no-metadata --use-svm-props --use-svnsync-props
1578 --log-window-size= --no-checkout --quiet
1579 --repack-flags --user-log-author $remote_opts
1580 "
1581 local init_opts="
1582 --template= --shared= --trunk= --tags=
1583 --branches= --stdlayout --minimize-url
1584 --no-metadata --use-svm-props --use-svnsync-props
1585 --rewrite-root= $remote_opts
1586 "
1587 local cmt_opts="
1588 --edit --rmdir --find-copies-harder --copy-similarity=
1589 "
1590
1591 local cur="${COMP_WORDS[COMP_CWORD]}"
1592 case "$subcommand,$cur" in
1593 fetch,--*)
1594 __gitcomp "--revision= --fetch-all $fc_opts"
1595 ;;
1596 clone,--*)
1597 __gitcomp "--revision= $fc_opts $init_opts"
1598 ;;
1599 init,--*)
1600 __gitcomp "$init_opts"
1601 ;;
1602 dcommit,--*)
1603 __gitcomp "
1604 --merge --strategy= --verbose --dry-run
1605 --fetch-all --no-rebase $cmt_opts $fc_opts
1606 "
1607 ;;
1608 set-tree,--*)
1609 __gitcomp "--stdin $cmt_opts $fc_opts"
1610 ;;
1611 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1612 show-externals,--*)
1613 __gitcomp "--revision="
1614 ;;
1615 log,--*)
1616 __gitcomp "
1617 --limit= --revision= --verbose --incremental
1618 --oneline --show-commit --non-recursive
1619 --authors-file=
1620 "
1621 ;;
1622 rebase,--*)
1623 __gitcomp "
1624 --merge --verbose --strategy= --local
1625 --fetch-all $fc_opts
1626 "
1627 ;;
1628 commit-diff,--*)
1629 __gitcomp "--message= --file= --revision= $cmt_opts"
1630 ;;
1631 info,--*)
1632 __gitcomp "--url"
1633 ;;
1634 *)
1635 COMPREPLY=()
1636 ;;
1637 esac
1638 fi
1639}
1640
1641_git_tag ()
1642{
1643 local i c=1 f=0
1644 while [ $c -lt $COMP_CWORD ]; do
1645 i="${COMP_WORDS[c]}"
1646 case "$i" in
1647 -d|-v)
1648 __gitcomp "$(__git_tags)"
1649 return
1650 ;;
1651 -f)
1652 f=1
1653 ;;
1654 esac
1655 c=$((++c))
1656 done
1657
1658 case "${COMP_WORDS[COMP_CWORD-1]}" in
1659 -m|-F)
1660 COMPREPLY=()
1661 ;;
1662 -*|tag)
1663 if [ $f = 1 ]; then
1664 __gitcomp "$(__git_tags)"
1665 else
1666 COMPREPLY=()
1667 fi
1668 ;;
1669 *)
1670 __gitcomp "$(__git_refs)"
1671 ;;
1672 esac
1673}
1674
1675_git ()
1676{
1677 local i c=1 command __git_dir
1678
1679 while [ $c -lt $COMP_CWORD ]; do
1680 i="${COMP_WORDS[c]}"
1681 case "$i" in
1682 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1683 --bare) __git_dir="." ;;
1684 --version|-p|--paginate) ;;
1685 --help) command="help"; break ;;
1686 *) command="$i"; break ;;
1687 esac
1688 c=$((++c))
1689 done
1690
1691 if [ -z "$command" ]; then
1692 case "${COMP_WORDS[COMP_CWORD]}" in
1693 --*) __gitcomp "
1694 --paginate
1695 --no-pager
1696 --git-dir=
1697 --bare
1698 --version
1699 --exec-path
1700 --work-tree=
1701 --help
1702 "
1703 ;;
1704 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1705 esac
1706 return
1707 fi
1708
1709 local expansion=$(__git_aliased_command "$command")
1710 [ "$expansion" ] && command="$expansion"
1711
1712 case "$command" in
1713 am) _git_am ;;
1714 add) _git_add ;;
1715 apply) _git_apply ;;
1716 archive) _git_archive ;;
1717 bisect) _git_bisect ;;
1718 bundle) _git_bundle ;;
1719 branch) _git_branch ;;
1720 checkout) _git_checkout ;;
1721 cherry) _git_cherry ;;
1722 cherry-pick) _git_cherry_pick ;;
1723 clean) _git_clean ;;
1724 clone) _git_clone ;;
1725 commit) _git_commit ;;
1726 config) _git_config ;;
1727 describe) _git_describe ;;
1728 diff) _git_diff ;;
1729 fetch) _git_fetch ;;
1730 format-patch) _git_format_patch ;;
1731 gc) _git_gc ;;
1732 grep) _git_grep ;;
1733 help) _git_help ;;
1734 init) _git_init ;;
1735 log) _git_log ;;
1736 ls-files) _git_ls_files ;;
1737 ls-remote) _git_ls_remote ;;
1738 ls-tree) _git_ls_tree ;;
1739 merge) _git_merge;;
1740 mergetool) _git_mergetool;;
1741 merge-base) _git_merge_base ;;
1742 mv) _git_mv ;;
1743 name-rev) _git_name_rev ;;
1744 pull) _git_pull ;;
1745 push) _git_push ;;
1746 rebase) _git_rebase ;;
1747 remote) _git_remote ;;
1748 reset) _git_reset ;;
1749 revert) _git_revert ;;
1750 rm) _git_rm ;;
1751 send-email) _git_send_email ;;
1752 shortlog) _git_shortlog ;;
1753 show) _git_show ;;
1754 show-branch) _git_show_branch ;;
1755 stash) _git_stash ;;
1756 stage) _git_add ;;
1757 submodule) _git_submodule ;;
1758 svn) _git_svn ;;
1759 tag) _git_tag ;;
1760 whatchanged) _git_log ;;
1761 *) COMPREPLY=() ;;
1762 esac
1763}
1764
1765_gitk ()
1766{
1767 __git_has_doubledash && return
1768
1769 local cur="${COMP_WORDS[COMP_CWORD]}"
1770 local g="$(git rev-parse --git-dir 2>/dev/null)"
1771 local merge=""
1772 if [ -f $g/MERGE_HEAD ]; then
1773 merge="--merge"
1774 fi
1775 case "$cur" in
1776 --*)
1777 __gitcomp "--not --all $merge"
1778 return
1779 ;;
1780 esac
1781 __git_complete_revlist
1782}
1783
1784complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
1785 || complete -o default -o nospace -F _git git
1786complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
1787 || complete -o default -o nospace -F _gitk gitk
1788
1789# The following are necessary only for Cygwin, and only are needed
1790# when the user has tab-completed the executable name and consequently
1791# included the '.exe' suffix.
1792#
1793if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1794complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
1795 || complete -o default -o nospace -F _git git.exe
1796fi