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