Code

Teach bash about git-am/git-apply and their whitespace options.
[git.git] / contrib / completion / git-completion.bash
1 #
2 # bash completion support for core Git.
3 #
4 # Copyright (C) 2006 Shawn Pearce
5 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
6 #
7 # The contained completion routines provide support for completing:
8 #
9 #    *) local and remote branch names
10 #    *) local and remote tag names
11 #    *) .git/remotes file names
12 #    *) git 'subcommands'
13 #    *) tree paths within 'ref:path/to/file' expressions
14 #
15 # To use these routines:
16 #
17 #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
18 #    2) Added the following line to your .bashrc:
19 #        source ~/.git-completion.sh
20 #
21 #    3) You may want to make sure the git executable is available
22 #       in your PATH before this script is sourced, as some caching
23 #       is performed while the script loads.  If git isn't found
24 #       at source time then all lookups will be done on demand,
25 #       which may be slightly slower.
26 #
27 #    4) Consider changing your PS1 to also show the current branch:
28 #        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
29 #
30 #       The argument to __git_ps1 will be displayed only if you
31 #       are currently in a git repository.  The %s token will be
32 #       the name of the current branch.
33 #
35 __gitdir ()
36 {
37         echo "${__git_dir:-$(git rev-parse --git-dir 2>/dev/null)}"
38 }
40 __git_ps1 ()
41 {
42         local b="$(git symbolic-ref HEAD 2>/dev/null)"
43         if [ -n "$b" ]; then
44                 if [ -n "$1" ]; then
45                         printf "$1" "${b##refs/heads/}"
46                 else
47                         printf " (%s)" "${b##refs/heads/}"
48                 fi
49         fi
50 }
52 __git_heads ()
53 {
54         local cmd i is_hash=y dir="${1:-$(__gitdir)}"
55         if [ -d "$dir" ]; then
56                 for i in $(git --git-dir="$dir" \
57                         for-each-ref --format='%(refname)' \
58                         refs/heads ); do
59                         echo "${i#refs/heads/}"
60                 done
61                 return
62         fi
63         for i in $(git-ls-remote "$dir" 2>/dev/null); do
64                 case "$is_hash,$i" in
65                 y,*) is_hash=n ;;
66                 n,*^{}) is_hash=y ;;
67                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
68                 n,*) is_hash=y; echo "$i" ;;
69                 esac
70         done
71 }
73 __git_refs ()
74 {
75         local cmd i is_hash=y dir="${1:-$(__gitdir)}"
76         if [ -d "$dir" ]; then
77                 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
78                 for i in $(git --git-dir="$dir" \
79                         for-each-ref --format='%(refname)' \
80                         refs/tags refs/heads refs/remotes); do
81                         case "$i" in
82                                 refs/tags/*)    echo "${i#refs/tags/}" ;;
83                                 refs/heads/*)   echo "${i#refs/heads/}" ;;
84                                 refs/remotes/*) echo "${i#refs/remotes/}" ;;
85                                 *)              echo "$i" ;;
86                         esac
87                 done
88                 return
89         fi
90         for i in $(git-ls-remote "$dir" 2>/dev/null); do
91                 case "$is_hash,$i" in
92                 y,*) is_hash=n ;;
93                 n,*^{}) is_hash=y ;;
94                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
95                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
96                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
97                 n,*) is_hash=y; echo "$i" ;;
98                 esac
99         done
102 __git_refs2 ()
104         local cmd i is_hash=y dir="${1:-$(__gitdir)}"
105         if [ -d "$dir" ]; then
106                 cmd=git-peek-remote
107         else
108                 cmd=git-ls-remote
109         fi
110         for i in $($cmd "$dir" 2>/dev/null); do
111                 case "$is_hash,$i" in
112                 y,*) is_hash=n ;;
113                 n,*^{}) is_hash=y ;;
114                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}:${i#refs/tags/}" ;;
115                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}:${i#refs/heads/}" ;;
116                 n,*) is_hash=y; echo "$i:$i" ;;
117                 esac
118         done
121 __git_refs_remotes ()
123         local cmd i is_hash=y
124         for i in $(git-ls-remote "$1" 2>/dev/null); do
125                 case "$is_hash,$i" in
126                 n,refs/heads/*)
127                         is_hash=y
128                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
129                         ;;
130                 y,*) is_hash=n ;;
131                 n,*^{}) is_hash=y ;;
132                 n,refs/tags/*) is_hash=y;;
133                 n,*) is_hash=y; ;;
134                 esac
135         done
138 __git_remotes ()
140         local i ngoff IFS=$'\n' d="$(__gitdir)"
141         shopt -q nullglob || ngoff=1
142         shopt -s nullglob
143         for i in "$d/remotes"/*; do
144                 echo ${i#$d/remotes/}
145         done
146         [ "$ngoff" ] && shopt -u nullglob
147         for i in $(git --git-dir="$d" repo-config --list); do
148                 case "$i" in
149                 remote.*.url=*)
150                         i="${i#remote.}"
151                         echo "${i/.url=*/}"
152                         ;;
153                 esac
154         done
157 __git_merge_strategies ()
159         if [ -n "$__git_merge_strategylist" ]; then
160                 echo "$__git_merge_strategylist"
161                 return
162         fi
163         sed -n "/^all_strategies='/{
164                 s/^all_strategies='//
165                 s/'//
166                 p
167                 q
168                 }" "$(git --exec-path)/git-merge"
170 __git_merge_strategylist=
171 __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
173 __git_complete_file ()
175         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
176         case "$cur" in
177         ?*:*)
178                 ref="${cur%%:*}"
179                 cur="${cur#*:}"
180                 case "$cur" in
181                 ?*/*)
182                         pfx="${cur%/*}"
183                         cur="${cur##*/}"
184                         ls="$ref:$pfx"
185                         pfx="$pfx/"
186                         ;;
187                 *)
188                         ls="$ref"
189                         ;;
190             esac
191                 COMPREPLY=($(compgen -P "$pfx" \
192                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
193                                 | sed '/^100... blob /s,^.*     ,,
194                                        /^040000 tree /{
195                                            s,^.*        ,,
196                                            s,$,/,
197                                        }
198                                        s/^.*    //')" \
199                         -- "$cur"))
200                 ;;
201         *)
202                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
203                 ;;
204         esac
207 __git_complete_revlist ()
209         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
210         case "$cur" in
211         *...*)
212                 pfx="${cur%...*}..."
213                 cur="${cur#*...}"
214                 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
215                 ;;
216         *..*)
217                 pfx="${cur%..*}.."
218                 cur="${cur#*..}"
219                 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
220                 ;;
221         *)
222                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
223                 ;;
224         esac
227 __git_commands ()
229         if [ -n "$__git_commandlist" ]; then
230                 echo "$__git_commandlist"
231                 return
232         fi
233         local i IFS=" "$'\n'
234         for i in $(git help -a|egrep '^ ')
235         do
236                 case $i in
237                 check-ref-format) : plumbing;;
238                 commit-tree)      : plumbing;;
239                 convert-objects)  : plumbing;;
240                 cvsserver)        : daemon;;
241                 daemon)           : daemon;;
242                 fetch-pack)       : plumbing;;
243                 hash-object)      : plumbing;;
244                 http-*)           : transport;;
245                 index-pack)       : plumbing;;
246                 local-fetch)      : plumbing;;
247                 mailinfo)         : plumbing;;
248                 mailsplit)        : plumbing;;
249                 merge-*)          : plumbing;;
250                 mktree)           : plumbing;;
251                 mktag)            : plumbing;;
252                 pack-objects)     : plumbing;;
253                 pack-redundant)   : plumbing;;
254                 pack-refs)        : plumbing;;
255                 parse-remote)     : plumbing;;
256                 patch-id)         : plumbing;;
257                 peek-remote)      : plumbing;;
258                 read-tree)        : plumbing;;
259                 receive-pack)     : plumbing;;
260                 rerere)           : plumbing;;
261                 rev-list)         : plumbing;;
262                 rev-parse)        : plumbing;;
263                 runstatus)        : plumbing;;
264                 sh-setup)         : internal;;
265                 shell)            : daemon;;
266                 send-pack)        : plumbing;;
267                 show-index)       : plumbing;;
268                 ssh-*)            : transport;;
269                 stripspace)       : plumbing;;
270                 symbolic-ref)     : plumbing;;
271                 unpack-file)      : plumbing;;
272                 unpack-objects)   : plumbing;;
273                 update-ref)       : plumbing;;
274                 update-server-info) : daemon;;
275                 upload-archive)   : plumbing;;
276                 upload-pack)      : plumbing;;
277                 write-tree)       : plumbing;;
278                 *) echo $i;;
279                 esac
280         done
282 __git_commandlist=
283 __git_commandlist="$(__git_commands 2>/dev/null)"
285 __git_aliases ()
287         local i IFS=$'\n'
288         for i in $(git --git-dir="$(__gitdir)" repo-config --list); do
289                 case "$i" in
290                 alias.*)
291                         i="${i#alias.}"
292                         echo "${i/=*/}"
293                         ;;
294                 esac
295         done
298 __git_aliased_command ()
300         local word cmdline=$(git --git-dir="$(__gitdir)" \
301                 repo-config --get "alias.$1")
302         for word in $cmdline; do
303                 if [ "${word##-*}" ]; then
304                         echo $word
305                         return
306                 fi
307         done
310 __git_whitespacelist="nowarn warn error error-all strip"
312 _git_am ()
314         local cur="${COMP_WORDS[COMP_CWORD]}"
315         if [ -d .dotest ]; then
316                 COMPREPLY=($(compgen -W "
317                         --skip --resolved
318                         " -- "$cur"))
319                 return
320         fi
321         case "$cur" in
322         --whitespace=*)
323                 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
324                         -- "${cur##--whitespace=}"))
325                 return
326                 ;;
327         --*)
328                 COMPREPLY=($(compgen -W "
329                         --signoff --utf8 --binary --3way --interactive
330                         --whitespace=
331                         " -- "$cur"))
332                 return
333         esac
334         COMPREPLY=()
337 _git_apply ()
339         local cur="${COMP_WORDS[COMP_CWORD]}"
340         case "$cur" in
341         --whitespace=*)
342                 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
343                         -- "${cur##--whitespace=}"))
344                 return
345                 ;;
346         --*)
347                 COMPREPLY=($(compgen -W "
348                         --stat --numstat --summary --check --index
349                         --cached --index-info --reverse --reject --unidiff-zero
350                         --apply --no-add --exclude=
351                         --whitespace= --inaccurate-eof --verbose
352                         " -- "$cur"))
353                 return
354         esac
355         COMPREPLY=()
358 _git_branch ()
360         local cur="${COMP_WORDS[COMP_CWORD]}"
361         COMPREPLY=($(compgen -W "-l -f -d -D $(__git_refs)" -- "$cur"))
364 _git_cat_file ()
366         local cur="${COMP_WORDS[COMP_CWORD]}"
367         case "${COMP_WORDS[0]},$COMP_CWORD" in
368         git-cat-file*,1)
369                 COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
370                 ;;
371         git,2)
372                 COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
373                 ;;
374         *)
375                 __git_complete_file
376                 ;;
377         esac
380 _git_checkout ()
382         local cur="${COMP_WORDS[COMP_CWORD]}"
383         COMPREPLY=($(compgen -W "-l -b $(__git_refs)" -- "$cur"))
386 _git_cherry_pick ()
388         local cur="${COMP_WORDS[COMP_CWORD]}"
389         case "$cur" in
390         --*)
391                 COMPREPLY=($(compgen -W "
392                         --edit --no-commit
393                         " -- "$cur"))
394                 ;;
395         *)
396                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
397                 ;;
398         esac
401 _git_diff ()
403         __git_complete_file
406 _git_diff_tree ()
408         local cur="${COMP_WORDS[COMP_CWORD]}"
409         COMPREPLY=($(compgen -W "-r -p -M $(__git_refs)" -- "$cur"))
412 _git_fetch ()
414         local cur="${COMP_WORDS[COMP_CWORD]}"
416         case "${COMP_WORDS[0]},$COMP_CWORD" in
417         git-fetch*,1)
418                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
419                 ;;
420         git,2)
421                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
422                 ;;
423         *)
424                 case "$cur" in
425                 *:*)
426                         cur="${cur#*:}"
427                         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
428                         ;;
429                 *)
430                         local remote
431                         case "${COMP_WORDS[0]}" in
432                         git-fetch) remote="${COMP_WORDS[1]}" ;;
433                         git)       remote="${COMP_WORDS[2]}" ;;
434                         esac
435                         COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur"))
436                         ;;
437                 esac
438                 ;;
439         esac
442 _git_format_patch ()
444         local cur="${COMP_WORDS[COMP_CWORD]}"
445         case "$cur" in
446         --*)
447                 COMPREPLY=($(compgen -W "
448                         --stdout --attach --thread
449                         --output-directory
450                         --numbered --start-number
451                         --keep-subject
452                         --signoff
453                         --in-reply-to=
454                         --full-index --binary
455                         " -- "$cur"))
456                 return
457                 ;;
458         esac
459         __git_complete_revlist
462 _git_ls_remote ()
464         local cur="${COMP_WORDS[COMP_CWORD]}"
465         COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
468 _git_ls_tree ()
470         __git_complete_file
473 _git_log ()
475         local cur="${COMP_WORDS[COMP_CWORD]}"
476         case "$cur" in
477         --pretty=*)
478                 COMPREPLY=($(compgen -W "
479                         oneline short medium full fuller email raw
480                         " -- "${cur##--pretty=}"))
481                 return
482                 ;;
483         --*)
484                 COMPREPLY=($(compgen -W "
485                         --max-count= --max-age= --since= --after=
486                         --min-age= --before= --until=
487                         --root --not --topo-order --date-order
488                         --no-merges
489                         --abbrev-commit --abbrev=
490                         --relative-date
491                         --author= --committer= --grep=
492                         --all-match
493                         --pretty= --name-status --name-only
494                         " -- "$cur"))
495                 return
496                 ;;
497         esac
498         __git_complete_revlist
501 _git_merge ()
503         local cur="${COMP_WORDS[COMP_CWORD]}"
504         case "${COMP_WORDS[COMP_CWORD-1]}" in
505         -s|--strategy)
506                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
507                 return
508         esac
509         case "$cur" in
510         --strategy=*)
511                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
512                         -- "${cur##--strategy=}"))
513                 return
514                 ;;
515         --*)
516                 COMPREPLY=($(compgen -W "
517                         --no-commit --no-summary --squash --strategy
518                         " -- "$cur"))
519                 return
520         esac
521         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
524 _git_merge_base ()
526         local cur="${COMP_WORDS[COMP_CWORD]}"
527         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
530 _git_name_rev ()
532         local cur="${COMP_WORDS[COMP_CWORD]}"
533         COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
536 _git_pull ()
538         local cur="${COMP_WORDS[COMP_CWORD]}"
540         case "${COMP_WORDS[0]},$COMP_CWORD" in
541         git-pull*,1)
542                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
543                 ;;
544         git,2)
545                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
546                 ;;
547         *)
548                 local remote
549                 case "${COMP_WORDS[0]}" in
550                 git-pull)  remote="${COMP_WORDS[1]}" ;;
551                 git)       remote="${COMP_WORDS[2]}" ;;
552                 esac
553                 COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
554                 ;;
555         esac
558 _git_push ()
560         local cur="${COMP_WORDS[COMP_CWORD]}"
562         case "${COMP_WORDS[0]},$COMP_CWORD" in
563         git-push*,1)
564                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
565                 ;;
566         git,2)
567                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
568                 ;;
569         *)
570                 case "$cur" in
571                 *:*)
572                         local remote
573                         case "${COMP_WORDS[0]}" in
574                         git-push)  remote="${COMP_WORDS[1]}" ;;
575                         git)       remote="${COMP_WORDS[2]}" ;;
576                         esac
577                         cur="${cur#*:}"
578                         COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
579                         ;;
580                 *)
581                         COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur"))
582                         ;;
583                 esac
584                 ;;
585         esac
588 _git_rebase ()
590         local cur="${COMP_WORDS[COMP_CWORD]}"
591         if [ -d .dotest ]; then
592                 COMPREPLY=($(compgen -W "
593                         --continue --skip --abort
594                         " -- "$cur"))
595                 return
596         fi
597         case "${COMP_WORDS[COMP_CWORD-1]}" in
598         -s|--strategy)
599                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
600                 return
601         esac
602         case "$cur" in
603         --strategy=*)
604                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
605                         -- "${cur##--strategy=}"))
606                 return
607                 ;;
608         --*)
609                 COMPREPLY=($(compgen -W "
610                         --onto --merge --strategy
611                         " -- "$cur"))
612                 return
613         esac
614         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
617 _git_repo_config ()
619         local cur="${COMP_WORDS[COMP_CWORD]}"
620         local prv="${COMP_WORDS[COMP_CWORD-1]}"
621         case "$prv" in
622         branch.*.remote)
623                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
624                 return
625                 ;;
626         branch.*.merge)
627                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
628                 return
629                 ;;
630         remote.*.fetch)
631                 local remote="${prv#remote.}"
632                 remote="${remote%.fetch}"
633                 COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \
634                         -- "$cur"))
635                 return
636                 ;;
637         remote.*.push)
638                 local remote="${prv#remote.}"
639                 remote="${remote%.push}"
640                 COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \
641                         for-each-ref --format='%(refname):%(refname)' \
642                         refs/heads)" -- "$cur"))
643                 return
644                 ;;
645         *.*)
646                 COMPREPLY=()
647                 return
648                 ;;
649         esac
650         case "$cur" in
651         --*)
652                 COMPREPLY=($(compgen -W "
653                         --global --list --replace-all
654                         --get --get-all --get-regexp
655                         --unset --unset-all
656                         " -- "$cur"))
657                 return
658                 ;;
659         branch.*.*)
660                 local pfx="${cur%.*}."
661                 cur="${cur##*.}"
662                 COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur"))
663                 return
664                 ;;
665         branch.*)
666                 local pfx="${cur%.*}."
667                 cur="${cur#*.}"
668                 COMPREPLY=($(compgen -P "$pfx" -S . \
669                         -W "$(__git_heads)" -- "$cur"))
670                 return
671                 ;;
672         remote.*.*)
673                 local pfx="${cur%.*}."
674                 cur="${cur##*.}"
675                 COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur"))
676                 return
677                 ;;
678         remote.*)
679                 local pfx="${cur%.*}."
680                 cur="${cur#*.}"
681                 COMPREPLY=($(compgen -P "$pfx" -S . \
682                         -W "$(__git_remotes)" -- "$cur"))
683                 return
684                 ;;
685         esac
686         COMPREPLY=($(compgen -W "
687                 apply.whitespace
688                 core.fileMode
689                 core.gitProxy
690                 core.ignoreStat
691                 core.preferSymlinkRefs
692                 core.logAllRefUpdates
693                 core.repositoryFormatVersion
694                 core.sharedRepository
695                 core.warnAmbiguousRefs
696                 core.compression
697                 core.legacyHeaders
698                 i18n.commitEncoding
699                 diff.color
700                 diff.renameLimit
701                 diff.renames
702                 pager.color
703                 status.color
704                 log.showroot
705                 show.difftree
706                 showbranch.default
707                 whatchanged.difftree
708                 http.sslVerify
709                 http.sslCert
710                 http.sslKey
711                 http.sslCAInfo
712                 http.sslCAPath
713                 http.maxRequests
714                 http.lowSpeedLimit http.lowSpeedTime
715                 http.noEPSV
716                 pack.window
717                 repack.useDeltaBaseOffset
718                 pull.octopus pull.twohead
719                 merge.summary
720                 receive.unpackLimit
721                 receive.denyNonFastForwards
722                 user.name user.email
723                 tar.umask
724                 gitcvs.enabled
725                 gitcvs.logfile
726                 branch. remote.
727         " -- "$cur"))
730 _git_reset ()
732         local cur="${COMP_WORDS[COMP_CWORD]}"
733         local opt="--mixed --hard --soft"
734         COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
737 _git ()
739         local i c=1 command __git_dir
741         while [ $c -lt $COMP_CWORD ]; do
742                 i="${COMP_WORDS[c]}"
743                 case "$i" in
744                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
745                 --bare)      __git_dir="." ;;
746                 --version|--help|-p|--paginate) ;;
747                 *) command="$i"; break ;;
748                 esac
749                 c=$((++c))
750         done
752         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
753                 COMPREPLY=($(compgen -W "
754                         --git-dir= --version --exec-path
755                         $(__git_commands)
756                         $(__git_aliases)
757                         " -- "${COMP_WORDS[COMP_CWORD]}"))
758                 return;
759         fi
761         local expansion=$(__git_aliased_command "$command")
762         [ "$expansion" ] && command="$expansion"
764         case "$command" in
765         am)          _git_am ;;
766         apply)       _git_apply ;;
767         branch)      _git_branch ;;
768         cat-file)    _git_cat_file ;;
769         checkout)    _git_checkout ;;
770         cherry-pick) _git_cherry_pick ;;
771         diff)        _git_diff ;;
772         diff-tree)   _git_diff_tree ;;
773         fetch)       _git_fetch ;;
774         format-patch) _git_format_patch ;;
775         log)         _git_log ;;
776         ls-remote)   _git_ls_remote ;;
777         ls-tree)     _git_ls_tree ;;
778         merge)       _git_merge;;
779         merge-base)  _git_merge_base ;;
780         name-rev)    _git_name_rev ;;
781         pull)        _git_pull ;;
782         push)        _git_push ;;
783         rebase)      _git_rebase ;;
784         repo-config) _git_repo_config ;;
785         reset)       _git_reset ;;
786         show)        _git_log ;;
787         show-branch) _git_log ;;
788         whatchanged) _git_log ;;
789         *)           COMPREPLY=() ;;
790         esac
793 _gitk ()
795         local cur="${COMP_WORDS[COMP_CWORD]}"
796         COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur"))
799 complete -o default -o nospace -F _git git
800 complete -o default            -F _gitk gitk
801 complete -o default            -F _git_am git-am
802 complete -o default            -F _git_apply git-apply
803 complete -o default            -F _git_branch git-branch
804 complete -o default -o nospace -F _git_cat_file git-cat-file
805 complete -o default            -F _git_checkout git-checkout
806 complete -o default            -F _git_cherry_pick git-cherry-pick
807 complete -o default -o nospace -F _git_diff git-diff
808 complete -o default            -F _git_diff_tree git-diff-tree
809 complete -o default -o nospace -F _git_fetch git-fetch
810 complete -o default -o nospace -F _git_format_patch git-format-patch
811 complete -o default -o nospace -F _git_log git-log
812 complete -o default            -F _git_ls_remote git-ls-remote
813 complete -o default -o nospace -F _git_ls_tree git-ls-tree
814 complete -o default            -F _git_merge git-merge
815 complete -o default            -F _git_merge_base git-merge-base
816 complete -o default            -F _git_name_rev git-name-rev
817 complete -o default -o nospace -F _git_pull git-pull
818 complete -o default -o nospace -F _git_push git-push
819 complete -o default            -F _git_rebase git-rebase
820 complete -o default            -F _git_repo_config git-repo-config
821 complete -o default            -F _git_reset git-reset
822 complete -o default            -F _git_log git-show
823 complete -o default -o nospace -F _git_log git-show-branch
824 complete -o default -o nospace -F _git_log git-whatchanged
826 # The following are necessary only for Cygwin, and only are needed
827 # when the user has tab-completed the executable name and consequently
828 # included the '.exe' suffix.
830 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
831 complete -o default            -F _git_apply git-apply.exe
832 complete -o default -o nospace -F _git git.exe
833 complete -o default            -F _git_branch git-branch.exe
834 complete -o default -o nospace -F _git_cat_file git-cat-file.exe
835 complete -o default -o nospace -F _git_diff git-diff.exe
836 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
837 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
838 complete -o default -o nospace -F _git_log git-log.exe
839 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
840 complete -o default            -F _git_merge_base git-merge-base.exe
841 complete -o default            -F _git_name_rev git-name-rev.exe
842 complete -o default -o nospace -F _git_push git-push.exe
843 complete -o default            -F _git_repo_config git-repo-config
844 complete -o default -o nospace -F _git_log git-show.exe
845 complete -o default -o nospace -F _git_log git-show-branch.exe
846 complete -o default -o nospace -F _git_log git-whatchanged.exe
847 fi