Code

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