Code

Merge git-gui
[git.git] / contrib / completion / git-completion.bash
1 #
2 # bash completion support for core Git.
3 #
4 # Copyright (C) 2006,2007 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         if [ -z "$1" ]; then
38                 if [ -n "$__git_dir" ]; then
39                         echo "$__git_dir"
40                 elif [ -d .git ]; then
41                         echo .git
42                 else
43                         git rev-parse --git-dir 2>/dev/null
44                 fi
45         elif [ -d "$1/.git" ]; then
46                 echo "$1/.git"
47         else
48                 echo "$1"
49         fi
50 }
52 __git_ps1 ()
53 {
54         local b="$(git symbolic-ref HEAD 2>/dev/null)"
55         if [ -n "$b" ]; then
56                 if [ -n "$1" ]; then
57                         printf "$1" "${b##refs/heads/}"
58                 else
59                         printf " (%s)" "${b##refs/heads/}"
60                 fi
61         fi
62 }
64 __gitcomp ()
65 {
66         local all c s=$'\n' IFS=' '$'\t'$'\n'
67         local cur="${COMP_WORDS[COMP_CWORD]}"
68         if [ $# -gt 2 ]; then
69                 cur="$3"
70         fi
71         for c in $1; do
72                 case "$c$4" in
73                 --*=*) all="$all$c$4$s" ;;
74                 *.)    all="$all$c$4$s" ;;
75                 *)     all="$all$c$4 $s" ;;
76                 esac
77         done
78         IFS=$s
79         COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
80         return
81 }
83 __git_heads ()
84 {
85         local cmd i is_hash=y dir="$(__gitdir "$1")"
86         if [ -d "$dir" ]; then
87                 for i in $(git --git-dir="$dir" \
88                         for-each-ref --format='%(refname)' \
89                         refs/heads ); do
90                         echo "${i#refs/heads/}"
91                 done
92                 return
93         fi
94         for i in $(git-ls-remote "$1" 2>/dev/null); do
95                 case "$is_hash,$i" in
96                 y,*) is_hash=n ;;
97                 n,*^{}) is_hash=y ;;
98                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
99                 n,*) is_hash=y; echo "$i" ;;
100                 esac
101         done
104 __git_refs ()
106         local cmd i is_hash=y dir="$(__gitdir "$1")"
107         if [ -d "$dir" ]; then
108                 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
109                 for i in $(git --git-dir="$dir" \
110                         for-each-ref --format='%(refname)' \
111                         refs/tags refs/heads refs/remotes); do
112                         case "$i" in
113                                 refs/tags/*)    echo "${i#refs/tags/}" ;;
114                                 refs/heads/*)   echo "${i#refs/heads/}" ;;
115                                 refs/remotes/*) echo "${i#refs/remotes/}" ;;
116                                 *)              echo "$i" ;;
117                         esac
118                 done
119                 return
120         fi
121         for i in $(git-ls-remote "$dir" 2>/dev/null); do
122                 case "$is_hash,$i" in
123                 y,*) is_hash=n ;;
124                 n,*^{}) is_hash=y ;;
125                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
126                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
127                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
128                 n,*) is_hash=y; echo "$i" ;;
129                 esac
130         done
133 __git_refs2 ()
135         local i
136         for i in $(__git_refs "$1"); do
137                 echo "$i:$i"
138         done
141 __git_refs_remotes ()
143         local cmd i is_hash=y
144         for i in $(git-ls-remote "$1" 2>/dev/null); do
145                 case "$is_hash,$i" in
146                 n,refs/heads/*)
147                         is_hash=y
148                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
149                         ;;
150                 y,*) is_hash=n ;;
151                 n,*^{}) is_hash=y ;;
152                 n,refs/tags/*) is_hash=y;;
153                 n,*) is_hash=y; ;;
154                 esac
155         done
158 __git_remotes ()
160         local i ngoff IFS=$'\n' d="$(__gitdir)"
161         shopt -q nullglob || ngoff=1
162         shopt -s nullglob
163         for i in "$d/remotes"/*; do
164                 echo ${i#$d/remotes/}
165         done
166         [ "$ngoff" ] && shopt -u nullglob
167         for i in $(git --git-dir="$d" config --list); do
168                 case "$i" in
169                 remote.*.url=*)
170                         i="${i#remote.}"
171                         echo "${i/.url=*/}"
172                         ;;
173                 esac
174         done
177 __git_merge_strategies ()
179         if [ -n "$__git_merge_strategylist" ]; then
180                 echo "$__git_merge_strategylist"
181                 return
182         fi
183         sed -n "/^all_strategies='/{
184                 s/^all_strategies='//
185                 s/'//
186                 p
187                 q
188                 }" "$(git --exec-path)/git-merge"
190 __git_merge_strategylist=
191 __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
193 __git_complete_file ()
195         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
196         case "$cur" in
197         ?*:*)
198                 ref="${cur%%:*}"
199                 cur="${cur#*:}"
200                 case "$cur" in
201                 ?*/*)
202                         pfx="${cur%/*}"
203                         cur="${cur##*/}"
204                         ls="$ref:$pfx"
205                         pfx="$pfx/"
206                         ;;
207                 *)
208                         ls="$ref"
209                         ;;
210             esac
211                 COMPREPLY=($(compgen -P "$pfx" \
212                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
213                                 | sed '/^100... blob /s,^.*     ,,
214                                        /^040000 tree /{
215                                            s,^.*        ,,
216                                            s,$,/,
217                                        }
218                                        s/^.*    //')" \
219                         -- "$cur"))
220                 ;;
221         *)
222                 __gitcomp "$(__git_refs)"
223                 ;;
224         esac
227 __git_complete_revlist ()
229         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
230         case "$cur" in
231         *...*)
232                 pfx="${cur%...*}..."
233                 cur="${cur#*...}"
234                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
235                 ;;
236         *..*)
237                 pfx="${cur%..*}.."
238                 cur="${cur#*..}"
239                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
240                 ;;
241         *.)
242                 __gitcomp "$cur."
243                 ;;
244         *)
245                 __gitcomp "$(__git_refs)"
246                 ;;
247         esac
250 __git_commands ()
252         if [ -n "$__git_commandlist" ]; then
253                 echo "$__git_commandlist"
254                 return
255         fi
256         local i IFS=" "$'\n'
257         for i in $(git help -a|egrep '^ ')
258         do
259                 case $i in
260                 add--interactive) : plumbing;;
261                 applymbox)        : ask gittus;;
262                 applypatch)       : ask gittus;;
263                 archimport)       : import;;
264                 cat-file)         : plumbing;;
265                 check-ref-format) : plumbing;;
266                 commit-tree)      : plumbing;;
267                 convert-objects)  : plumbing;;
268                 cvsexportcommit)  : export;;
269                 cvsimport)        : import;;
270                 cvsserver)        : daemon;;
271                 daemon)           : daemon;;
272                 diff-stages)      : nobody uses it;;
273                 fast-import)      : import;;
274                 fsck-objects)     : plumbing;;
275                 fetch-pack)       : plumbing;;
276                 fmt-merge-msg)    : plumbing;;
277                 hash-object)      : plumbing;;
278                 http-*)           : transport;;
279                 index-pack)       : plumbing;;
280                 init-db)          : deprecated;;
281                 local-fetch)      : plumbing;;
282                 mailinfo)         : plumbing;;
283                 mailsplit)        : plumbing;;
284                 merge-*)          : plumbing;;
285                 mktree)           : plumbing;;
286                 mktag)            : plumbing;;
287                 pack-objects)     : plumbing;;
288                 pack-redundant)   : plumbing;;
289                 pack-refs)        : plumbing;;
290                 parse-remote)     : plumbing;;
291                 patch-id)         : plumbing;;
292                 peek-remote)      : plumbing;;
293                 prune)            : plumbing;;
294                 prune-packed)     : plumbing;;
295                 quiltimport)      : import;;
296                 read-tree)        : plumbing;;
297                 receive-pack)     : plumbing;;
298                 reflog)           : plumbing;;
299                 repo-config)      : plumbing;;
300                 rerere)           : plumbing;;
301                 resolve)          : dead dont use;;
302                 rev-list)         : plumbing;;
303                 rev-parse)        : plumbing;;
304                 runstatus)        : plumbing;;
305                 sh-setup)         : internal;;
306                 shell)            : daemon;;
307                 send-pack)        : plumbing;;
308                 show-index)       : plumbing;;
309                 ssh-*)            : transport;;
310                 stripspace)       : plumbing;;
311                 svn)              : import export;;
312                 svnimport)        : import;;
313                 symbolic-ref)     : plumbing;;
314                 tar-tree)         : deprecated;;
315                 unpack-file)      : plumbing;;
316                 unpack-objects)   : plumbing;;
317                 update-index)     : plumbing;;
318                 update-ref)       : plumbing;;
319                 update-server-info) : daemon;;
320                 upload-archive)   : plumbing;;
321                 upload-pack)      : plumbing;;
322                 write-tree)       : plumbing;;
323                 verify-tag)       : plumbing;;
324                 *) echo $i;;
325                 esac
326         done
328 __git_commandlist=
329 __git_commandlist="$(__git_commands 2>/dev/null)"
331 __git_aliases ()
333         local i IFS=$'\n'
334         for i in $(git --git-dir="$(__gitdir)" config --list); do
335                 case "$i" in
336                 alias.*)
337                         i="${i#alias.}"
338                         echo "${i/=*/}"
339                         ;;
340                 esac
341         done
344 __git_aliased_command ()
346         local word cmdline=$(git --git-dir="$(__gitdir)" \
347                 config --get "alias.$1")
348         for word in $cmdline; do
349                 if [ "${word##-*}" ]; then
350                         echo $word
351                         return
352                 fi
353         done
356 __git_whitespacelist="nowarn warn error error-all strip"
358 _git_am ()
360         local cur="${COMP_WORDS[COMP_CWORD]}"
361         if [ -d .dotest ]; then
362                 __gitcomp "--skip --resolved"
363                 return
364         fi
365         case "$cur" in
366         --whitespace=*)
367                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
368                 return
369                 ;;
370         --*)
371                 __gitcomp "
372                         --signoff --utf8 --binary --3way --interactive
373                         --whitespace=
374                         "
375                 return
376         esac
377         COMPREPLY=()
380 _git_apply ()
382         local cur="${COMP_WORDS[COMP_CWORD]}"
383         case "$cur" in
384         --whitespace=*)
385                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
386                 return
387                 ;;
388         --*)
389                 __gitcomp "
390                         --stat --numstat --summary --check --index
391                         --cached --index-info --reverse --reject --unidiff-zero
392                         --apply --no-add --exclude=
393                         --whitespace= --inaccurate-eof --verbose
394                         "
395                 return
396         esac
397         COMPREPLY=()
400 _git_add ()
402         local cur="${COMP_WORDS[COMP_CWORD]}"
403         case "$cur" in
404         --*)
405                 __gitcomp "--interactive"
406                 return
407         esac
408         COMPREPLY=()
411 _git_bisect ()
413         local i c=1 command
414         while [ $c -lt $COMP_CWORD ]; do
415                 i="${COMP_WORDS[c]}"
416                 case "$i" in
417                 start|bad|good|reset|visualize|replay|log)
418                         command="$i"
419                         break
420                         ;;
421                 esac
422                 c=$((++c))
423         done
425         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
426                 __gitcomp "start bad good reset visualize replay log"
427                 return
428         fi
430         case "$command" in
431         bad|good|reset)
432                 __gitcomp "$(__git_refs)"
433                 ;;
434         *)
435                 COMPREPLY=()
436                 ;;
437         esac
440 _git_branch ()
442         __gitcomp "$(__git_refs)"
445 _git_checkout ()
447         __gitcomp "$(__git_refs)"
450 _git_cherry ()
452         __gitcomp "$(__git_refs)"
455 _git_cherry_pick ()
457         local cur="${COMP_WORDS[COMP_CWORD]}"
458         case "$cur" in
459         --*)
460                 __gitcomp "--edit --no-commit"
461                 ;;
462         *)
463                 __gitcomp "$(__git_refs)"
464                 ;;
465         esac
468 _git_commit ()
470         local cur="${COMP_WORDS[COMP_CWORD]}"
471         case "$cur" in
472         --*)
473                 __gitcomp "
474                         --all --author= --signoff --verify --no-verify
475                         --edit --amend --include --only
476                         "
477                 return
478         esac
479         COMPREPLY=()
482 _git_diff ()
484         __git_complete_file
487 _git_diff_tree ()
489         __gitcomp "$(__git_refs)"
492 _git_fetch ()
494         local cur="${COMP_WORDS[COMP_CWORD]}"
496         case "${COMP_WORDS[0]},$COMP_CWORD" in
497         git-fetch*,1)
498                 __gitcomp "$(__git_remotes)"
499                 ;;
500         git,2)
501                 __gitcomp "$(__git_remotes)"
502                 ;;
503         *)
504                 case "$cur" in
505                 *:*)
506                         __gitcomp "$(__git_refs)" "" "${cur#*:}"
507                         ;;
508                 *)
509                         local remote
510                         case "${COMP_WORDS[0]}" in
511                         git-fetch) remote="${COMP_WORDS[1]}" ;;
512                         git)       remote="${COMP_WORDS[2]}" ;;
513                         esac
514                         __gitcomp "$(__git_refs2 "$remote")"
515                         ;;
516                 esac
517                 ;;
518         esac
521 _git_format_patch ()
523         local cur="${COMP_WORDS[COMP_CWORD]}"
524         case "$cur" in
525         --*)
526                 __gitcomp "
527                         --stdout --attach --thread
528                         --output-directory
529                         --numbered --start-number
530                         --keep-subject
531                         --signoff
532                         --in-reply-to=
533                         --full-index --binary
534                         --not --all
535                         "
536                 return
537                 ;;
538         esac
539         __git_complete_revlist
542 _git_gc ()
544         local cur="${COMP_WORDS[COMP_CWORD]}"
545         case "$cur" in
546         --*)
547                 __gitcomp "--prune"
548                 return
549                 ;;
550         esac
551         COMPREPLY=()
554 _git_ls_remote ()
556         __gitcomp "$(__git_remotes)"
559 _git_ls_tree ()
561         __git_complete_file
564 _git_log ()
566         local cur="${COMP_WORDS[COMP_CWORD]}"
567         case "$cur" in
568         --pretty=*)
569                 __gitcomp "
570                         oneline short medium full fuller email raw
571                         " "" "${cur##--pretty=}"
572                 return
573                 ;;
574         --*)
575                 __gitcomp "
576                         --max-count= --max-age= --since= --after=
577                         --min-age= --before= --until=
578                         --root --not --topo-order --date-order
579                         --no-merges
580                         --abbrev-commit --abbrev=
581                         --relative-date
582                         --author= --committer= --grep=
583                         --all-match
584                         --pretty= --name-status --name-only
585                         --not --all
586                         "
587                 return
588                 ;;
589         esac
590         __git_complete_revlist
593 _git_merge ()
595         local cur="${COMP_WORDS[COMP_CWORD]}"
596         case "${COMP_WORDS[COMP_CWORD-1]}" in
597         -s|--strategy)
598                 __gitcomp "$(__git_merge_strategies)"
599                 return
600         esac
601         case "$cur" in
602         --strategy=*)
603                 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
604                 return
605                 ;;
606         --*)
607                 __gitcomp "
608                         --no-commit --no-summary --squash --strategy
609                         "
610                 return
611         esac
612         __gitcomp "$(__git_refs)"
615 _git_merge_base ()
617         __gitcomp "$(__git_refs)"
620 _git_name_rev ()
622         __gitcomp "--tags --all --stdin"
625 _git_pull ()
627         local cur="${COMP_WORDS[COMP_CWORD]}"
629         case "${COMP_WORDS[0]},$COMP_CWORD" in
630         git-pull*,1)
631                 __gitcomp "$(__git_remotes)"
632                 ;;
633         git,2)
634                 __gitcomp "$(__git_remotes)"
635                 ;;
636         *)
637                 local remote
638                 case "${COMP_WORDS[0]}" in
639                 git-pull)  remote="${COMP_WORDS[1]}" ;;
640                 git)       remote="${COMP_WORDS[2]}" ;;
641                 esac
642                 __gitcomp "$(__git_refs "$remote")"
643                 ;;
644         esac
647 _git_push ()
649         local cur="${COMP_WORDS[COMP_CWORD]}"
651         case "${COMP_WORDS[0]},$COMP_CWORD" in
652         git-push*,1)
653                 __gitcomp "$(__git_remotes)"
654                 ;;
655         git,2)
656                 __gitcomp "$(__git_remotes)"
657                 ;;
658         *)
659                 case "$cur" in
660                 *:*)
661                         local remote
662                         case "${COMP_WORDS[0]}" in
663                         git-push)  remote="${COMP_WORDS[1]}" ;;
664                         git)       remote="${COMP_WORDS[2]}" ;;
665                         esac
666                         __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
667                         ;;
668                 *)
669                         __gitcomp "$(__git_refs2)"
670                         ;;
671                 esac
672                 ;;
673         esac
676 _git_rebase ()
678         local cur="${COMP_WORDS[COMP_CWORD]}"
679         if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
680                 __gitcomp "--continue --skip --abort"
681                 return
682         fi
683         case "${COMP_WORDS[COMP_CWORD-1]}" in
684         -s|--strategy)
685                 __gitcomp "$(__git_merge_strategies)"
686                 return
687         esac
688         case "$cur" in
689         --strategy=*)
690                 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
691                 return
692                 ;;
693         --*)
694                 __gitcomp "--onto --merge --strategy"
695                 return
696         esac
697         __gitcomp "$(__git_refs)"
700 _git_config ()
702         local cur="${COMP_WORDS[COMP_CWORD]}"
703         local prv="${COMP_WORDS[COMP_CWORD-1]}"
704         case "$prv" in
705         branch.*.remote)
706                 __gitcomp "$(__git_remotes)"
707                 return
708                 ;;
709         branch.*.merge)
710                 __gitcomp "$(__git_refs)"
711                 return
712                 ;;
713         remote.*.fetch)
714                 local remote="${prv#remote.}"
715                 remote="${remote%.fetch}"
716                 __gitcomp "$(__git_refs_remotes "$remote")"
717                 return
718                 ;;
719         remote.*.push)
720                 local remote="${prv#remote.}"
721                 remote="${remote%.push}"
722                 __gitcomp "$(git --git-dir="$(__gitdir)" \
723                         for-each-ref --format='%(refname):%(refname)' \
724                         refs/heads)"
725                 return
726                 ;;
727         pull.twohead|pull.octopus)
728                 __gitcomp "$(__git_merge_strategies)"
729                 return
730                 ;;
731         color.branch|color.diff|color.status)
732                 __gitcomp "always never auto"
733                 return
734                 ;;
735         color.*.*)
736                 __gitcomp "
737                         black red green yellow blue magenta cyan white
738                         bold dim ul blink reverse
739                         "
740                 return
741                 ;;
742         *.*)
743                 COMPREPLY=()
744                 return
745                 ;;
746         esac
747         case "$cur" in
748         --*)
749                 __gitcomp "
750                         --global --list --replace-all
751                         --get --get-all --get-regexp
752                         --add --unset --unset-all
753                         "
754                 return
755                 ;;
756         branch.*.*)
757                 local pfx="${cur%.*}."
758                 cur="${cur##*.}"
759                 __gitcomp "remote merge" "$pfx" "$cur"
760                 return
761                 ;;
762         branch.*)
763                 local pfx="${cur%.*}."
764                 cur="${cur#*.}"
765                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
766                 return
767                 ;;
768         remote.*.*)
769                 local pfx="${cur%.*}."
770                 cur="${cur##*.}"
771                 __gitcomp "url fetch push" "$pfx" "$cur"
772                 return
773                 ;;
774         remote.*)
775                 local pfx="${cur%.*}."
776                 cur="${cur#*.}"
777                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
778                 return
779                 ;;
780         esac
781         __gitcomp "
782                 apply.whitespace
783                 core.fileMode
784                 core.gitProxy
785                 core.ignoreStat
786                 core.preferSymlinkRefs
787                 core.logAllRefUpdates
788                 core.repositoryFormatVersion
789                 core.sharedRepository
790                 core.warnAmbiguousRefs
791                 core.compression
792                 core.legacyHeaders
793                 core.packedGitWindowSize
794                 core.packedGitLimit
795                 color.branch
796                 color.branch.current
797                 color.branch.local
798                 color.branch.remote
799                 color.branch.plain
800                 color.diff
801                 color.diff.plain
802                 color.diff.meta
803                 color.diff.frag
804                 color.diff.old
805                 color.diff.new
806                 color.diff.commit
807                 color.diff.whitespace
808                 color.pager
809                 color.status
810                 color.status.header
811                 color.status.added
812                 color.status.changed
813                 color.status.untracked
814                 diff.renameLimit
815                 diff.renames
816                 fetch.unpackLimit
817                 format.headers
818                 gitcvs.enabled
819                 gitcvs.logfile
820                 gc.reflogexpire
821                 gc.reflogexpireunreachable
822                 gc.rerereresolved
823                 gc.rerereunresolved
824                 http.sslVerify
825                 http.sslCert
826                 http.sslKey
827                 http.sslCAInfo
828                 http.sslCAPath
829                 http.maxRequests
830                 http.lowSpeedLimit
831                 http.lowSpeedTime
832                 http.noEPSV
833                 i18n.commitEncoding
834                 i18n.logOutputEncoding
835                 log.showroot
836                 merge.summary
837                 merge.verbosity
838                 pack.window
839                 pull.octopus
840                 pull.twohead
841                 repack.useDeltaBaseOffset
842                 show.difftree
843                 showbranch.default
844                 tar.umask
845                 transfer.unpackLimit
846                 receive.unpackLimit
847                 receive.denyNonFastForwards
848                 user.name
849                 user.email
850                 user.signingkey
851                 whatchanged.difftree
852                 branch. remote.
853         "
856 _git_remote ()
858         local i c=1 command
859         while [ $c -lt $COMP_CWORD ]; do
860                 i="${COMP_WORDS[c]}"
861                 case "$i" in
862                 add|show|prune) command="$i"; break ;;
863                 esac
864                 c=$((++c))
865         done
867         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
868                 __gitcomp "add show prune"
869                 return
870         fi
872         case "$command" in
873         show|prune)
874                 __gitcomp "$(__git_remotes)"
875                 ;;
876         *)
877                 COMPREPLY=()
878                 ;;
879         esac
882 _git_reset ()
884         local cur="${COMP_WORDS[COMP_CWORD]}"
885         case "$cur" in
886         --*)
887                 __gitcomp "--mixed --hard --soft"
888                 return
889                 ;;
890         esac
891         __gitcomp "$(__git_refs)"
894 _git_show ()
896         local cur="${COMP_WORDS[COMP_CWORD]}"
897         case "$cur" in
898         --pretty=*)
899                 __gitcomp "
900                         oneline short medium full fuller email raw
901                         " "" "${cur##--pretty=}"
902                 return
903                 ;;
904         --*)
905                 __gitcomp "--pretty="
906                 return
907                 ;;
908         esac
909         __git_complete_file
912 _git ()
914         local i c=1 command __git_dir
916         while [ $c -lt $COMP_CWORD ]; do
917                 i="${COMP_WORDS[c]}"
918                 case "$i" in
919                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
920                 --bare)      __git_dir="." ;;
921                 --version|--help|-p|--paginate) ;;
922                 *) command="$i"; break ;;
923                 esac
924                 c=$((++c))
925         done
927         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
928                 case "${COMP_WORDS[COMP_CWORD]}" in
929                 --*=*) COMPREPLY=() ;;
930                 --*)   __gitcomp "--git-dir= --bare --version --exec-path" ;;
931                 *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
932                 esac
933                 return
934         fi
936         local expansion=$(__git_aliased_command "$command")
937         [ "$expansion" ] && command="$expansion"
939         case "$command" in
940         am)          _git_am ;;
941         add)         _git_add ;;
942         apply)       _git_apply ;;
943         bisect)      _git_bisect ;;
944         branch)      _git_branch ;;
945         checkout)    _git_checkout ;;
946         cherry)      _git_cherry ;;
947         cherry-pick) _git_cherry_pick ;;
948         commit)      _git_commit ;;
949         config)      _git_config ;;
950         diff)        _git_diff ;;
951         diff-tree)   _git_diff_tree ;;
952         fetch)       _git_fetch ;;
953         format-patch) _git_format_patch ;;
954         gc)          _git_gc ;;
955         log)         _git_log ;;
956         ls-remote)   _git_ls_remote ;;
957         ls-tree)     _git_ls_tree ;;
958         merge)       _git_merge;;
959         merge-base)  _git_merge_base ;;
960         name-rev)    _git_name_rev ;;
961         pull)        _git_pull ;;
962         push)        _git_push ;;
963         rebase)      _git_rebase ;;
964         remote)      _git_remote ;;
965         reset)       _git_reset ;;
966         show)        _git_show ;;
967         show-branch) _git_log ;;
968         whatchanged) _git_log ;;
969         *)           COMPREPLY=() ;;
970         esac
973 _gitk ()
975         local cur="${COMP_WORDS[COMP_CWORD]}"
976         case "$cur" in
977         --*)
978                 __gitcomp "--not --all"
979                 return
980                 ;;
981         esac
982         __git_complete_revlist
985 complete -o default -o nospace -F _git git
986 complete -o default -o nospace -F _gitk gitk
987 complete -o default -o nospace -F _git_am git-am
988 complete -o default -o nospace -F _git_apply git-apply
989 complete -o default -o nospace -F _git_bisect git-bisect
990 complete -o default -o nospace -F _git_branch git-branch
991 complete -o default -o nospace -F _git_checkout git-checkout
992 complete -o default -o nospace -F _git_cherry git-cherry
993 complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
994 complete -o default -o nospace -F _git_commit git-commit
995 complete -o default -o nospace -F _git_diff git-diff
996 complete -o default -o nospace -F _git_diff_tree git-diff-tree
997 complete -o default -o nospace -F _git_fetch git-fetch
998 complete -o default -o nospace -F _git_format_patch git-format-patch
999 complete -o default -o nospace -F _git_gc git-gc
1000 complete -o default -o nospace -F _git_log git-log
1001 complete -o default -o nospace -F _git_ls_remote git-ls-remote
1002 complete -o default -o nospace -F _git_ls_tree git-ls-tree
1003 complete -o default -o nospace -F _git_merge git-merge
1004 complete -o default -o nospace -F _git_merge_base git-merge-base
1005 complete -o default -o nospace -F _git_name_rev git-name-rev
1006 complete -o default -o nospace -F _git_pull git-pull
1007 complete -o default -o nospace -F _git_push git-push
1008 complete -o default -o nospace -F _git_rebase git-rebase
1009 complete -o default -o nospace -F _git_config git-config
1010 complete -o default -o nospace -F _git_remote git-remote
1011 complete -o default -o nospace -F _git_reset git-reset
1012 complete -o default -o nospace -F _git_show git-show
1013 complete -o default -o nospace -F _git_log git-show-branch
1014 complete -o default -o nospace -F _git_log git-whatchanged
1016 # The following are necessary only for Cygwin, and only are needed
1017 # when the user has tab-completed the executable name and consequently
1018 # included the '.exe' suffix.
1020 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1021 complete -o default -o nospace -F _git_add git-add.exe
1022 complete -o default -o nospace -F _git_apply git-apply.exe
1023 complete -o default -o nospace -F _git git.exe
1024 complete -o default -o nospace -F _git_branch git-branch.exe
1025 complete -o default -o nospace -F _git_cherry git-cherry.exe
1026 complete -o default -o nospace -F _git_diff git-diff.exe
1027 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
1028 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
1029 complete -o default -o nospace -F _git_log git-log.exe
1030 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
1031 complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1032 complete -o default -o nospace -F _git_name_rev git-name-rev.exe
1033 complete -o default -o nospace -F _git_push git-push.exe
1034 complete -o default -o nospace -F _git_config git-config
1035 complete -o default -o nospace -F _git_show git-show.exe
1036 complete -o default -o nospace -F _git_log git-show-branch.exe
1037 complete -o default -o nospace -F _git_log git-whatchanged.exe
1038 fi