Code

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