]> asedeno.scripts.mit.edu Git - git.git/blob - contrib/completion/git-completion.bash
bash: Support unique completion on git-config.
[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 #
34
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 }
51
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 }
63
64 __gitcomp ()
65 {
66         local all c s=$'\n' IFS=' '$'\t'$'\n'
67         local cur="${COMP_WORDS[COMP_CWORD]}"
68         if [ -n "$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 }
82
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
102 }
103
104 __git_refs ()
105 {
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
131 }
132
133 __git_refs2 ()
134 {
135         local i
136         for i in $(__git_refs "$1"); do
137                 echo "$i:$i"
138         done
139 }
140
141 __git_refs_remotes ()
142 {
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
156 }
157
158 __git_remotes ()
159 {
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
175 }
176
177 __git_merge_strategies ()
178 {
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"
189 }
190 __git_merge_strategylist=
191 __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
192
193 __git_complete_file ()
194 {
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                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
223                 ;;
224         esac
225 }
226
227 __git_complete_revlist ()
228 {
229         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
230         case "$cur" in
231         *...*)
232                 pfx="${cur%...*}..."
233                 cur="${cur#*...}"
234                 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
235                 ;;
236         *..*)
237                 pfx="${cur%..*}.."
238                 cur="${cur#*..}"
239                 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
240                 ;;
241         *)
242                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
243                 ;;
244         esac
245 }
246
247 __git_commands ()
248 {
249         if [ -n "$__git_commandlist" ]; then
250                 echo "$__git_commandlist"
251                 return
252         fi
253         local i IFS=" "$'\n'
254         for i in $(git help -a|egrep '^ ')
255         do
256                 case $i in
257                 add--interactive) : plumbing;;
258                 applymbox)        : ask gittus;;
259                 applypatch)       : ask gittus;;
260                 archimport)       : import;;
261                 cat-file)         : plumbing;;
262                 check-ref-format) : plumbing;;
263                 commit-tree)      : plumbing;;
264                 convert-objects)  : plumbing;;
265                 cvsexportcommit)  : export;;
266                 cvsimport)        : import;;
267                 cvsserver)        : daemon;;
268                 daemon)           : daemon;;
269                 fsck-objects)     : plumbing;;
270                 fetch-pack)       : plumbing;;
271                 fmt-merge-msg)    : plumbing;;
272                 hash-object)      : plumbing;;
273                 http-*)           : transport;;
274                 index-pack)       : plumbing;;
275                 init-db)          : deprecated;;
276                 local-fetch)      : plumbing;;
277                 mailinfo)         : plumbing;;
278                 mailsplit)        : plumbing;;
279                 merge-*)          : plumbing;;
280                 mktree)           : plumbing;;
281                 mktag)            : plumbing;;
282                 pack-objects)     : plumbing;;
283                 pack-redundant)   : plumbing;;
284                 pack-refs)        : plumbing;;
285                 parse-remote)     : plumbing;;
286                 patch-id)         : plumbing;;
287                 peek-remote)      : plumbing;;
288                 prune)            : plumbing;;
289                 prune-packed)     : plumbing;;
290                 quiltimport)      : import;;
291                 read-tree)        : plumbing;;
292                 receive-pack)     : plumbing;;
293                 reflog)           : plumbing;;
294                 repo-config)      : plumbing;;
295                 rerere)           : plumbing;;
296                 rev-list)         : plumbing;;
297                 rev-parse)        : plumbing;;
298                 runstatus)        : plumbing;;
299                 sh-setup)         : internal;;
300                 shell)            : daemon;;
301                 send-pack)        : plumbing;;
302                 show-index)       : plumbing;;
303                 ssh-*)            : transport;;
304                 stripspace)       : plumbing;;
305                 svn)              : import export;;
306                 svnimport)        : import;;
307                 symbolic-ref)     : plumbing;;
308                 tar-tree)         : deprecated;;
309                 unpack-file)      : plumbing;;
310                 unpack-objects)   : plumbing;;
311                 update-index)     : plumbing;;
312                 update-ref)       : plumbing;;
313                 update-server-info) : daemon;;
314                 upload-archive)   : plumbing;;
315                 upload-pack)      : plumbing;;
316                 write-tree)       : plumbing;;
317                 verify-tag)       : plumbing;;
318                 *) echo $i;;
319                 esac
320         done
321 }
322 __git_commandlist=
323 __git_commandlist="$(__git_commands 2>/dev/null)"
324
325 __git_aliases ()
326 {
327         local i IFS=$'\n'
328         for i in $(git --git-dir="$(__gitdir)" config --list); do
329                 case "$i" in
330                 alias.*)
331                         i="${i#alias.}"
332                         echo "${i/=*/}"
333                         ;;
334                 esac
335         done
336 }
337
338 __git_aliased_command ()
339 {
340         local word cmdline=$(git --git-dir="$(__gitdir)" \
341                 config --get "alias.$1")
342         for word in $cmdline; do
343                 if [ "${word##-*}" ]; then
344                         echo $word
345                         return
346                 fi
347         done
348 }
349
350 __git_whitespacelist="nowarn warn error error-all strip"
351
352 _git_am ()
353 {
354         local cur="${COMP_WORDS[COMP_CWORD]}"
355         if [ -d .dotest ]; then
356                 COMPREPLY=($(compgen -W "
357                         --skip --resolved
358                         " -- "$cur"))
359                 return
360         fi
361         case "$cur" in
362         --whitespace=*)
363                 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
364                         -- "${cur##--whitespace=}"))
365                 return
366                 ;;
367         --*)
368                 COMPREPLY=($(compgen -W "
369                         --signoff --utf8 --binary --3way --interactive
370                         --whitespace=
371                         " -- "$cur"))
372                 return
373         esac
374         COMPREPLY=()
375 }
376
377 _git_apply ()
378 {
379         local cur="${COMP_WORDS[COMP_CWORD]}"
380         case "$cur" in
381         --whitespace=*)
382                 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
383                         -- "${cur##--whitespace=}"))
384                 return
385                 ;;
386         --*)
387                 COMPREPLY=($(compgen -W "
388                         --stat --numstat --summary --check --index
389                         --cached --index-info --reverse --reject --unidiff-zero
390                         --apply --no-add --exclude=
391                         --whitespace= --inaccurate-eof --verbose
392                         " -- "$cur"))
393                 return
394         esac
395         COMPREPLY=()
396 }
397
398 _git_add ()
399 {
400         local cur="${COMP_WORDS[COMP_CWORD]}"
401         case "$cur" in
402         --*)
403                 COMPREPLY=($(compgen -W "
404                         --interactive
405                         " -- "$cur"))
406                 return
407         esac
408         COMPREPLY=()
409 }
410
411 _git_branch ()
412 {
413         local cur="${COMP_WORDS[COMP_CWORD]}"
414         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
415 }
416
417 _git_checkout ()
418 {
419         local cur="${COMP_WORDS[COMP_CWORD]}"
420         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
421 }
422
423 _git_cherry_pick ()
424 {
425         local cur="${COMP_WORDS[COMP_CWORD]}"
426         case "$cur" in
427         --*)
428                 COMPREPLY=($(compgen -W "
429                         --edit --no-commit
430                         " -- "$cur"))
431                 ;;
432         *)
433                 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
434                 ;;
435         esac
436 }
437
438 _git_commit ()
439 {
440         local cur="${COMP_WORDS[COMP_CWORD]}"
441         case "$cur" in
442         --*)
443                 COMPREPLY=($(compgen -W "
444                         --all --author= --signoff --verify --no-verify
445                         --edit --amend --include --only
446                         " -- "$cur"))
447                 return
448         esac
449         COMPREPLY=()
450 }
451
452 _git_diff ()
453 {
454         __git_complete_file
455 }
456
457 _git_diff_tree ()
458 {
459         local cur="${COMP_WORDS[COMP_CWORD]}"
460         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
461 }
462
463 _git_fetch ()
464 {
465         local cur="${COMP_WORDS[COMP_CWORD]}"
466
467         case "${COMP_WORDS[0]},$COMP_CWORD" in
468         git-fetch*,1)
469                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
470                 ;;
471         git,2)
472                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
473                 ;;
474         *)
475                 case "$cur" in
476                 *:*)
477                         cur="${cur#*:}"
478                         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
479                         ;;
480                 *)
481                         local remote
482                         case "${COMP_WORDS[0]}" in
483                         git-fetch) remote="${COMP_WORDS[1]}" ;;
484                         git)       remote="${COMP_WORDS[2]}" ;;
485                         esac
486                         COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur"))
487                         ;;
488                 esac
489                 ;;
490         esac
491 }
492
493 _git_format_patch ()
494 {
495         local cur="${COMP_WORDS[COMP_CWORD]}"
496         case "$cur" in
497         --*)
498                 COMPREPLY=($(compgen -W "
499                         --stdout --attach --thread
500                         --output-directory
501                         --numbered --start-number
502                         --keep-subject
503                         --signoff
504                         --in-reply-to=
505                         --full-index --binary
506                         " -- "$cur"))
507                 return
508                 ;;
509         esac
510         __git_complete_revlist
511 }
512
513 _git_ls_remote ()
514 {
515         local cur="${COMP_WORDS[COMP_CWORD]}"
516         COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
517 }
518
519 _git_ls_tree ()
520 {
521         __git_complete_file
522 }
523
524 _git_log ()
525 {
526         local cur="${COMP_WORDS[COMP_CWORD]}"
527         case "$cur" in
528         --pretty=*)
529                 COMPREPLY=($(compgen -W "
530                         oneline short medium full fuller email raw
531                         " -- "${cur##--pretty=}"))
532                 return
533                 ;;
534         --*)
535                 COMPREPLY=($(compgen -W "
536                         --max-count= --max-age= --since= --after=
537                         --min-age= --before= --until=
538                         --root --not --topo-order --date-order
539                         --no-merges
540                         --abbrev-commit --abbrev=
541                         --relative-date
542                         --author= --committer= --grep=
543                         --all-match
544                         --pretty= --name-status --name-only
545                         " -- "$cur"))
546                 return
547                 ;;
548         esac
549         __git_complete_revlist
550 }
551
552 _git_merge ()
553 {
554         local cur="${COMP_WORDS[COMP_CWORD]}"
555         case "${COMP_WORDS[COMP_CWORD-1]}" in
556         -s|--strategy)
557                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
558                 return
559         esac
560         case "$cur" in
561         --strategy=*)
562                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
563                         -- "${cur##--strategy=}"))
564                 return
565                 ;;
566         --*)
567                 COMPREPLY=($(compgen -W "
568                         --no-commit --no-summary --squash --strategy
569                         " -- "$cur"))
570                 return
571         esac
572         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
573 }
574
575 _git_merge_base ()
576 {
577         local cur="${COMP_WORDS[COMP_CWORD]}"
578         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
579 }
580
581 _git_name_rev ()
582 {
583         local cur="${COMP_WORDS[COMP_CWORD]}"
584         COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
585 }
586
587 _git_pull ()
588 {
589         local cur="${COMP_WORDS[COMP_CWORD]}"
590
591         case "${COMP_WORDS[0]},$COMP_CWORD" in
592         git-pull*,1)
593                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
594                 ;;
595         git,2)
596                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
597                 ;;
598         *)
599                 local remote
600                 case "${COMP_WORDS[0]}" in
601                 git-pull)  remote="${COMP_WORDS[1]}" ;;
602                 git)       remote="${COMP_WORDS[2]}" ;;
603                 esac
604                 COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
605                 ;;
606         esac
607 }
608
609 _git_push ()
610 {
611         local cur="${COMP_WORDS[COMP_CWORD]}"
612
613         case "${COMP_WORDS[0]},$COMP_CWORD" in
614         git-push*,1)
615                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
616                 ;;
617         git,2)
618                 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
619                 ;;
620         *)
621                 case "$cur" in
622                 *:*)
623                         local remote
624                         case "${COMP_WORDS[0]}" in
625                         git-push)  remote="${COMP_WORDS[1]}" ;;
626                         git)       remote="${COMP_WORDS[2]}" ;;
627                         esac
628                         cur="${cur#*:}"
629                         COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
630                         ;;
631                 *)
632                         COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur"))
633                         ;;
634                 esac
635                 ;;
636         esac
637 }
638
639 _git_rebase ()
640 {
641         local cur="${COMP_WORDS[COMP_CWORD]}"
642         if [ -d .dotest ]; then
643                 COMPREPLY=($(compgen -W "
644                         --continue --skip --abort
645                         " -- "$cur"))
646                 return
647         fi
648         case "${COMP_WORDS[COMP_CWORD-1]}" in
649         -s|--strategy)
650                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
651                 return
652         esac
653         case "$cur" in
654         --strategy=*)
655                 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
656                         -- "${cur##--strategy=}"))
657                 return
658                 ;;
659         --*)
660                 COMPREPLY=($(compgen -W "
661                         --onto --merge --strategy
662                         " -- "$cur"))
663                 return
664         esac
665         COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
666 }
667
668 _git_config ()
669 {
670         local cur="${COMP_WORDS[COMP_CWORD]}"
671         local prv="${COMP_WORDS[COMP_CWORD-1]}"
672         case "$prv" in
673         branch.*.remote)
674                 __gitcomp "$(__git_remotes)"
675                 return
676                 ;;
677         branch.*.merge)
678                 __gitcomp "$(__git_refs)"
679                 return
680                 ;;
681         remote.*.fetch)
682                 local remote="${prv#remote.}"
683                 remote="${remote%.fetch}"
684                 __gitcomp "$(__git_refs_remotes "$remote")"
685                 return
686                 ;;
687         remote.*.push)
688                 local remote="${prv#remote.}"
689                 remote="${remote%.push}"
690                 __gitcomp "$(git --git-dir="$(__gitdir)" \
691                         for-each-ref --format='%(refname):%(refname)' \
692                         refs/heads)"
693                 return
694                 ;;
695         pull.twohead|pull.octopus)
696                 __gitcomp "$(__git_merge_strategies)"
697                 return
698                 ;;
699         color.branch|color.diff|color.status)
700                 __gitcomp "always never auto"
701                 return
702                 ;;
703         color.*.*)
704                 __gitcomp "
705                         black red green yellow blue magenta cyan white
706                         bold dim ul blink reverse
707                         "
708                 return
709                 ;;
710         *.*)
711                 COMPREPLY=()
712                 return
713                 ;;
714         esac
715         case "$cur" in
716         --*)
717                 __gitcomp "
718                         --global --list --replace-all
719                         --get --get-all --get-regexp
720                         --unset --unset-all
721                         "
722                 return
723                 ;;
724         branch.*.*)
725                 local pfx="${cur%.*}."
726                 cur="${cur##*.}"
727                 __gitcomp "remote merge" "$pfx" "$cur"
728                 return
729                 ;;
730         branch.*)
731                 local pfx="${cur%.*}."
732                 cur="${cur#*.}"
733                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
734                 return
735                 ;;
736         remote.*.*)
737                 local pfx="${cur%.*}."
738                 cur="${cur##*.}"
739                 __gitcomp "url fetch push" "$pfx" "$cur"
740                 return
741                 ;;
742         remote.*)
743                 local pfx="${cur%.*}."
744                 cur="${cur#*.}"
745                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
746                 return
747                 ;;
748         esac
749         __gitcomp "
750                 apply.whitespace
751                 core.fileMode
752                 core.gitProxy
753                 core.ignoreStat
754                 core.preferSymlinkRefs
755                 core.logAllRefUpdates
756                 core.repositoryFormatVersion
757                 core.sharedRepository
758                 core.warnAmbiguousRefs
759                 core.compression
760                 core.legacyHeaders
761                 core.packedGitWindowSize
762                 core.packedGitLimit
763                 color.branch
764                 color.branch.current
765                 color.branch.local
766                 color.branch.remote
767                 color.branch.plain
768                 color.diff
769                 color.diff.plain
770                 color.diff.meta
771                 color.diff.frag
772                 color.diff.old
773                 color.diff.new
774                 color.diff.commit
775                 color.diff.whitespace
776                 color.pager
777                 color.status
778                 color.status.header
779                 color.status.added
780                 color.status.changed
781                 color.status.untracked
782                 diff.renameLimit
783                 diff.renames
784                 fetch.unpackLimit
785                 format.headers
786                 gitcvs.enabled
787                 gitcvs.logfile
788                 gc.reflogexpire
789                 gc.reflogexpireunreachable
790                 gc.rerereresolved
791                 gc.rerereunresolved
792                 http.sslVerify
793                 http.sslCert
794                 http.sslKey
795                 http.sslCAInfo
796                 http.sslCAPath
797                 http.maxRequests
798                 http.lowSpeedLimit
799                 http.lowSpeedTime
800                 http.noEPSV
801                 i18n.commitEncoding
802                 i18n.logOutputEncoding
803                 log.showroot
804                 merge.summary
805                 merge.verbosity
806                 pack.window
807                 pull.octopus
808                 pull.twohead
809                 repack.useDeltaBaseOffset
810                 show.difftree
811                 showbranch.default
812                 tar.umask
813                 transfer.unpackLimit
814                 receive.unpackLimit
815                 receive.denyNonFastForwards
816                 user.name
817                 user.email
818                 user.signingkey
819                 whatchanged.difftree
820                 branch. remote.
821         "
822 }
823
824 _git_reset ()
825 {
826         local cur="${COMP_WORDS[COMP_CWORD]}"
827         local opt="--mixed --hard --soft"
828         COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
829 }
830
831 _git_show ()
832 {
833         local cur="${COMP_WORDS[COMP_CWORD]}"
834         case "$cur" in
835         --pretty=*)
836                 COMPREPLY=($(compgen -W "
837                         oneline short medium full fuller email raw
838                         " -- "${cur##--pretty=}"))
839                 return
840                 ;;
841         --*)
842                 COMPREPLY=($(compgen -W "--pretty=" -- "$cur"))
843                 return
844                 ;;
845         esac
846         __git_complete_file
847 }
848
849 _git ()
850 {
851         local i c=1 command __git_dir
852
853         while [ $c -lt $COMP_CWORD ]; do
854                 i="${COMP_WORDS[c]}"
855                 case "$i" in
856                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
857                 --bare)      __git_dir="." ;;
858                 --version|--help|-p|--paginate) ;;
859                 *) command="$i"; break ;;
860                 esac
861                 c=$((++c))
862         done
863
864         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
865                 case "${COMP_WORDS[COMP_CWORD]}" in
866                 --*=*) COMPREPLY=() ;;
867                 --*)   __gitcomp "--git-dir= --bare --version --exec-path" ;;
868                 *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
869                 esac
870                 return
871         fi
872
873         local expansion=$(__git_aliased_command "$command")
874         [ "$expansion" ] && command="$expansion"
875
876         case "$command" in
877         am)          _git_am ;;
878         add)         _git_add ;;
879         apply)       _git_apply ;;
880         branch)      _git_branch ;;
881         checkout)    _git_checkout ;;
882         cherry-pick) _git_cherry_pick ;;
883         commit)      _git_commit ;;
884         config)      _git_config ;;
885         diff)        _git_diff ;;
886         diff-tree)   _git_diff_tree ;;
887         fetch)       _git_fetch ;;
888         format-patch) _git_format_patch ;;
889         log)         _git_log ;;
890         ls-remote)   _git_ls_remote ;;
891         ls-tree)     _git_ls_tree ;;
892         merge)       _git_merge;;
893         merge-base)  _git_merge_base ;;
894         name-rev)    _git_name_rev ;;
895         pull)        _git_pull ;;
896         push)        _git_push ;;
897         rebase)      _git_rebase ;;
898         reset)       _git_reset ;;
899         show)        _git_show ;;
900         show-branch) _git_log ;;
901         whatchanged) _git_log ;;
902         *)           COMPREPLY=() ;;
903         esac
904 }
905
906 _gitk ()
907 {
908         local cur="${COMP_WORDS[COMP_CWORD]}"
909         COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur"))
910 }
911
912 complete -o default -o nospace -F _git git
913 complete -o default            -F _gitk gitk
914 complete -o default            -F _git_am git-am
915 complete -o default            -F _git_apply git-apply
916 complete -o default            -F _git_branch git-branch
917 complete -o default            -F _git_checkout git-checkout
918 complete -o default            -F _git_cherry_pick git-cherry-pick
919 complete -o default            -F _git_commit git-commit
920 complete -o default -o nospace -F _git_diff git-diff
921 complete -o default            -F _git_diff_tree git-diff-tree
922 complete -o default -o nospace -F _git_fetch git-fetch
923 complete -o default -o nospace -F _git_format_patch git-format-patch
924 complete -o default -o nospace -F _git_log git-log
925 complete -o default            -F _git_ls_remote git-ls-remote
926 complete -o default -o nospace -F _git_ls_tree git-ls-tree
927 complete -o default            -F _git_merge git-merge
928 complete -o default            -F _git_merge_base git-merge-base
929 complete -o default            -F _git_name_rev git-name-rev
930 complete -o default -o nospace -F _git_pull git-pull
931 complete -o default -o nospace -F _git_push git-push
932 complete -o default            -F _git_rebase git-rebase
933 complete -o default            -F _git_config git-config
934 complete -o default            -F _git_reset git-reset
935 complete -o default -o nospace -F _git_show git-show
936 complete -o default -o nospace -F _git_log git-show-branch
937 complete -o default -o nospace -F _git_log git-whatchanged
938
939 # The following are necessary only for Cygwin, and only are needed
940 # when the user has tab-completed the executable name and consequently
941 # included the '.exe' suffix.
942 #
943 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
944 complete -o default            -F _git_add git-add.exe
945 complete -o default            -F _git_apply git-apply.exe
946 complete -o default -o nospace -F _git git.exe
947 complete -o default            -F _git_branch git-branch.exe
948 complete -o default -o nospace -F _git_diff git-diff.exe
949 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
950 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
951 complete -o default -o nospace -F _git_log git-log.exe
952 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
953 complete -o default            -F _git_merge_base git-merge-base.exe
954 complete -o default            -F _git_name_rev git-name-rev.exe
955 complete -o default -o nospace -F _git_push git-push.exe
956 complete -o default            -F _git_config git-config
957 complete -o default -o nospace -F _git_show git-show.exe
958 complete -o default -o nospace -F _git_log git-show-branch.exe
959 complete -o default -o nospace -F _git_log git-whatchanged.exe
960 fi