Code

Merge branch 'maint'
[git.git] / contrib / completion / git-completion.bash
1 #
2 # bash completion support for core Git.
3 #
4 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
5 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
6 # Distributed under the GNU General Public License, version 2.0.
7 #
8 # The contained completion routines provide support for completing:
9 #
10 #    *) local and remote branch names
11 #    *) local and remote tag names
12 #    *) .git/remotes file names
13 #    *) git 'subcommands'
14 #    *) tree paths within 'ref:path/to/file' expressions
15 #    *) common --long-options
16 #
17 # To use these routines:
18 #
19 #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
20 #    2) Added the following line to your .bashrc:
21 #        source ~/.git-completion.sh
22 #
23 #    3) You may want to make sure the git executable is available
24 #       in your PATH before this script is sourced, as some caching
25 #       is performed while the script loads.  If git isn't found
26 #       at source time then all lookups will be done on demand,
27 #       which may be slightly slower.
28 #
29 #    4) Consider changing your PS1 to also show the current branch:
30 #        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
31 #
32 #       The argument to __git_ps1 will be displayed only if you
33 #       are currently in a git repository.  The %s token will be
34 #       the name of the current branch.
35 #
36 # To submit patches:
37 #
38 #    *) Read Documentation/SubmittingPatches
39 #    *) Send all patches to the current maintainer:
40 #
41 #       "Shawn O. Pearce" <spearce@spearce.org>
42 #
43 #    *) Always CC the Git mailing list:
44 #
45 #       git@vger.kernel.org
46 #
48 __gitdir ()
49 {
50         if [ -z "$1" ]; then
51                 if [ -n "$__git_dir" ]; then
52                         echo "$__git_dir"
53                 elif [ -d .git ]; then
54                         echo .git
55                 else
56                         git rev-parse --git-dir 2>/dev/null
57                 fi
58         elif [ -d "$1/.git" ]; then
59                 echo "$1/.git"
60         else
61                 echo "$1"
62         fi
63 }
65 __git_ps1 ()
66 {
67         local b="$(git symbolic-ref HEAD 2>/dev/null)"
68         if [ -n "$b" ]; then
69                 if [ -n "$1" ]; then
70                         printf "$1" "${b##refs/heads/}"
71                 else
72                         printf " (%s)" "${b##refs/heads/}"
73                 fi
74         fi
75 }
77 __gitcomp ()
78 {
79         local all c s=$'\n' IFS=' '$'\t'$'\n'
80         local cur="${COMP_WORDS[COMP_CWORD]}"
81         if [ $# -gt 2 ]; then
82                 cur="$3"
83         fi
84         for c in $1; do
85                 case "$c$4" in
86                 --*=*) all="$all$c$4$s" ;;
87                 *.)    all="$all$c$4$s" ;;
88                 *)     all="$all$c$4 $s" ;;
89                 esac
90         done
91         IFS=$s
92         COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
93         return
94 }
96 __git_heads ()
97 {
98         local cmd i is_hash=y dir="$(__gitdir "$1")"
99         if [ -d "$dir" ]; then
100                 for i in $(git --git-dir="$dir" \
101                         for-each-ref --format='%(refname)' \
102                         refs/heads ); do
103                         echo "${i#refs/heads/}"
104                 done
105                 return
106         fi
107         for i in $(git-ls-remote "$1" 2>/dev/null); do
108                 case "$is_hash,$i" in
109                 y,*) is_hash=n ;;
110                 n,*^{}) is_hash=y ;;
111                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
112                 n,*) is_hash=y; echo "$i" ;;
113                 esac
114         done
117 __git_tags ()
119         local cmd i is_hash=y dir="$(__gitdir "$1")"
120         if [ -d "$dir" ]; then
121                 for i in $(git --git-dir="$dir" \
122                         for-each-ref --format='%(refname)' \
123                         refs/tags ); do
124                         echo "${i#refs/tags/}"
125                 done
126                 return
127         fi
128         for i in $(git-ls-remote "$1" 2>/dev/null); do
129                 case "$is_hash,$i" in
130                 y,*) is_hash=n ;;
131                 n,*^{}) is_hash=y ;;
132                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
133                 n,*) is_hash=y; echo "$i" ;;
134                 esac
135         done
138 __git_refs ()
140         local cmd i is_hash=y dir="$(__gitdir "$1")"
141         if [ -d "$dir" ]; then
142                 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
143                 for i in $(git --git-dir="$dir" \
144                         for-each-ref --format='%(refname)' \
145                         refs/tags refs/heads refs/remotes); do
146                         case "$i" in
147                                 refs/tags/*)    echo "${i#refs/tags/}" ;;
148                                 refs/heads/*)   echo "${i#refs/heads/}" ;;
149                                 refs/remotes/*) echo "${i#refs/remotes/}" ;;
150                                 *)              echo "$i" ;;
151                         esac
152                 done
153                 return
154         fi
155         for i in $(git-ls-remote "$dir" 2>/dev/null); do
156                 case "$is_hash,$i" in
157                 y,*) is_hash=n ;;
158                 n,*^{}) is_hash=y ;;
159                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
160                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
161                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
162                 n,*) is_hash=y; echo "$i" ;;
163                 esac
164         done
167 __git_refs2 ()
169         local i
170         for i in $(__git_refs "$1"); do
171                 echo "$i:$i"
172         done
175 __git_refs_remotes ()
177         local cmd i is_hash=y
178         for i in $(git-ls-remote "$1" 2>/dev/null); do
179                 case "$is_hash,$i" in
180                 n,refs/heads/*)
181                         is_hash=y
182                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
183                         ;;
184                 y,*) is_hash=n ;;
185                 n,*^{}) is_hash=y ;;
186                 n,refs/tags/*) is_hash=y;;
187                 n,*) is_hash=y; ;;
188                 esac
189         done
192 __git_remotes ()
194         local i ngoff IFS=$'\n' d="$(__gitdir)"
195         shopt -q nullglob || ngoff=1
196         shopt -s nullglob
197         for i in "$d/remotes"/*; do
198                 echo ${i#$d/remotes/}
199         done
200         [ "$ngoff" ] && shopt -u nullglob
201         for i in $(git --git-dir="$d" config --list); do
202                 case "$i" in
203                 remote.*.url=*)
204                         i="${i#remote.}"
205                         echo "${i/.url=*/}"
206                         ;;
207                 esac
208         done
211 __git_merge_strategies ()
213         if [ -n "$__git_merge_strategylist" ]; then
214                 echo "$__git_merge_strategylist"
215                 return
216         fi
217         sed -n "/^all_strategies='/{
218                 s/^all_strategies='//
219                 s/'//
220                 p
221                 q
222                 }" "$(git --exec-path)/git-merge"
224 __git_merge_strategylist=
225 __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
227 __git_complete_file ()
229         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
230         case "$cur" in
231         ?*:*)
232                 ref="${cur%%:*}"
233                 cur="${cur#*:}"
234                 case "$cur" in
235                 ?*/*)
236                         pfx="${cur%/*}"
237                         cur="${cur##*/}"
238                         ls="$ref:$pfx"
239                         pfx="$pfx/"
240                         ;;
241                 *)
242                         ls="$ref"
243                         ;;
244             esac
245                 COMPREPLY=($(compgen -P "$pfx" \
246                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
247                                 | sed '/^100... blob /s,^.*     ,,
248                                        /^040000 tree /{
249                                            s,^.*        ,,
250                                            s,$,/,
251                                        }
252                                        s/^.*    //')" \
253                         -- "$cur"))
254                 ;;
255         *)
256                 __gitcomp "$(__git_refs)"
257                 ;;
258         esac
261 __git_complete_revlist ()
263         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
264         case "$cur" in
265         *...*)
266                 pfx="${cur%...*}..."
267                 cur="${cur#*...}"
268                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
269                 ;;
270         *..*)
271                 pfx="${cur%..*}.."
272                 cur="${cur#*..}"
273                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
274                 ;;
275         *.)
276                 __gitcomp "$cur."
277                 ;;
278         *)
279                 __gitcomp "$(__git_refs)"
280                 ;;
281         esac
284 __git_commands ()
286         if [ -n "$__git_commandlist" ]; then
287                 echo "$__git_commandlist"
288                 return
289         fi
290         local i IFS=" "$'\n'
291         for i in $(git help -a|egrep '^ ')
292         do
293                 case $i in
294                 add--interactive) : plumbing;;
295                 applymbox)        : ask gittus;;
296                 applypatch)       : ask gittus;;
297                 archimport)       : import;;
298                 cat-file)         : plumbing;;
299                 check-attr)       : plumbing;;
300                 check-ref-format) : plumbing;;
301                 commit-tree)      : plumbing;;
302                 cvsexportcommit)  : export;;
303                 cvsimport)        : import;;
304                 cvsserver)        : daemon;;
305                 daemon)           : daemon;;
306                 diff-files)       : plumbing;;
307                 diff-index)       : plumbing;;
308                 diff-tree)        : plumbing;;
309                 fast-import)      : import;;
310                 fsck-objects)     : plumbing;;
311                 fetch--tool)      : plumbing;;
312                 fetch-pack)       : plumbing;;
313                 fmt-merge-msg)    : plumbing;;
314                 for-each-ref)     : plumbing;;
315                 hash-object)      : plumbing;;
316                 http-*)           : transport;;
317                 index-pack)       : plumbing;;
318                 init-db)          : deprecated;;
319                 local-fetch)      : plumbing;;
320                 mailinfo)         : plumbing;;
321                 mailsplit)        : plumbing;;
322                 merge-*)          : plumbing;;
323                 mktree)           : plumbing;;
324                 mktag)            : plumbing;;
325                 pack-objects)     : plumbing;;
326                 pack-redundant)   : plumbing;;
327                 pack-refs)        : plumbing;;
328                 parse-remote)     : plumbing;;
329                 patch-id)         : plumbing;;
330                 peek-remote)      : plumbing;;
331                 prune)            : plumbing;;
332                 prune-packed)     : plumbing;;
333                 quiltimport)      : import;;
334                 read-tree)        : plumbing;;
335                 receive-pack)     : plumbing;;
336                 reflog)           : plumbing;;
337                 repo-config)      : plumbing;;
338                 rerere)           : plumbing;;
339                 rev-list)         : plumbing;;
340                 rev-parse)        : plumbing;;
341                 runstatus)        : plumbing;;
342                 sh-setup)         : internal;;
343                 shell)            : daemon;;
344                 send-pack)        : plumbing;;
345                 show-index)       : plumbing;;
346                 ssh-*)            : transport;;
347                 stripspace)       : plumbing;;
348                 svn)              : import export;;
349                 symbolic-ref)     : plumbing;;
350                 tar-tree)         : deprecated;;
351                 unpack-file)      : plumbing;;
352                 unpack-objects)   : plumbing;;
353                 update-index)     : plumbing;;
354                 update-ref)       : plumbing;;
355                 update-server-info) : daemon;;
356                 upload-archive)   : plumbing;;
357                 upload-pack)      : plumbing;;
358                 write-tree)       : plumbing;;
359                 verify-tag)       : plumbing;;
360                 *) echo $i;;
361                 esac
362         done
364 __git_commandlist=
365 __git_commandlist="$(__git_commands 2>/dev/null)"
367 __git_aliases ()
369         local i IFS=$'\n'
370         for i in $(git --git-dir="$(__gitdir)" config --list); do
371                 case "$i" in
372                 alias.*)
373                         i="${i#alias.}"
374                         echo "${i/=*/}"
375                         ;;
376                 esac
377         done
380 __git_aliased_command ()
382         local word cmdline=$(git --git-dir="$(__gitdir)" \
383                 config --get "alias.$1")
384         for word in $cmdline; do
385                 if [ "${word##-*}" ]; then
386                         echo $word
387                         return
388                 fi
389         done
392 __git_whitespacelist="nowarn warn error error-all strip"
394 _git_am ()
396         local cur="${COMP_WORDS[COMP_CWORD]}"
397         if [ -d .dotest ]; then
398                 __gitcomp "--skip --resolved"
399                 return
400         fi
401         case "$cur" in
402         --whitespace=*)
403                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
404                 return
405                 ;;
406         --*)
407                 __gitcomp "
408                         --signoff --utf8 --binary --3way --interactive
409                         --whitespace=
410                         "
411                 return
412         esac
413         COMPREPLY=()
416 _git_apply ()
418         local cur="${COMP_WORDS[COMP_CWORD]}"
419         case "$cur" in
420         --whitespace=*)
421                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
422                 return
423                 ;;
424         --*)
425                 __gitcomp "
426                         --stat --numstat --summary --check --index
427                         --cached --index-info --reverse --reject --unidiff-zero
428                         --apply --no-add --exclude=
429                         --whitespace= --inaccurate-eof --verbose
430                         "
431                 return
432         esac
433         COMPREPLY=()
436 _git_add ()
438         local cur="${COMP_WORDS[COMP_CWORD]}"
439         case "$cur" in
440         --*)
441                 __gitcomp "--interactive --refresh"
442                 return
443         esac
444         COMPREPLY=()
447 _git_bisect ()
449         local i c=1 command
450         while [ $c -lt $COMP_CWORD ]; do
451                 i="${COMP_WORDS[c]}"
452                 case "$i" in
453                 start|bad|good|reset|visualize|replay|log)
454                         command="$i"
455                         break
456                         ;;
457                 esac
458                 c=$((++c))
459         done
461         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
462                 __gitcomp "start bad good reset visualize replay log"
463                 return
464         fi
466         case "$command" in
467         bad|good|reset)
468                 __gitcomp "$(__git_refs)"
469                 ;;
470         *)
471                 COMPREPLY=()
472                 ;;
473         esac
476 _git_branch ()
478         __gitcomp "$(__git_refs)"
481 _git_bundle ()
483         local mycword="$COMP_CWORD"
484         case "${COMP_WORDS[0]}" in
485         git)
486                 local cmd="${COMP_WORDS[2]}"
487                 mycword="$((mycword-1))"
488                 ;;
489         git-bundle*)
490                 local cmd="${COMP_WORDS[1]}"
491                 ;;
492         esac
493         case "$mycword" in
494         1)
495                 __gitcomp "create list-heads verify unbundle"
496                 ;;
497         2)
498                 # looking for a file
499                 ;;
500         *)
501                 case "$cmd" in
502                         create)
503                                 __git_complete_revlist
504                         ;;
505                 esac
506                 ;;
507         esac
510 _git_checkout ()
512         __gitcomp "$(__git_refs)"
515 _git_cherry ()
517         __gitcomp "$(__git_refs)"
520 _git_cherry_pick ()
522         local cur="${COMP_WORDS[COMP_CWORD]}"
523         case "$cur" in
524         --*)
525                 __gitcomp "--edit --no-commit"
526                 ;;
527         *)
528                 __gitcomp "$(__git_refs)"
529                 ;;
530         esac
533 _git_commit ()
535         local cur="${COMP_WORDS[COMP_CWORD]}"
536         case "$cur" in
537         --*)
538                 __gitcomp "
539                         --all --author= --signoff --verify --no-verify
540                         --edit --amend --include --only
541                         "
542                 return
543         esac
544         COMPREPLY=()
547 _git_describe ()
549         __gitcomp "$(__git_refs)"
552 _git_diff ()
554         local cur="${COMP_WORDS[COMP_CWORD]}"
555         case "$cur" in
556         --*)
557                 __gitcomp "--cached --stat --numstat --shortstat --summary
558                         --patch-with-stat --name-only --name-status --color
559                         --no-color --color-words --no-renames --check
560                         --full-index --binary --abbrev --diff-filter
561                         --find-copies-harder --pickaxe-all --pickaxe-regex
562                         --text --ignore-space-at-eol --ignore-space-change
563                         --ignore-all-space --exit-code --quiet --ext-diff
564                         --no-ext-diff"
565                 return
566                 ;;
567         esac
568         __git_complete_file
571 _git_diff_tree ()
573         __gitcomp "$(__git_refs)"
576 _git_fetch ()
578         local cur="${COMP_WORDS[COMP_CWORD]}"
580         case "${COMP_WORDS[0]},$COMP_CWORD" in
581         git-fetch*,1)
582                 __gitcomp "$(__git_remotes)"
583                 ;;
584         git,2)
585                 __gitcomp "$(__git_remotes)"
586                 ;;
587         *)
588                 case "$cur" in
589                 *:*)
590                         __gitcomp "$(__git_refs)" "" "${cur#*:}"
591                         ;;
592                 *)
593                         local remote
594                         case "${COMP_WORDS[0]}" in
595                         git-fetch) remote="${COMP_WORDS[1]}" ;;
596                         git)       remote="${COMP_WORDS[2]}" ;;
597                         esac
598                         __gitcomp "$(__git_refs2 "$remote")"
599                         ;;
600                 esac
601                 ;;
602         esac
605 _git_format_patch ()
607         local cur="${COMP_WORDS[COMP_CWORD]}"
608         case "$cur" in
609         --*)
610                 __gitcomp "
611                         --stdout --attach --thread
612                         --output-directory
613                         --numbered --start-number
614                         --numbered-files
615                         --keep-subject
616                         --signoff
617                         --in-reply-to=
618                         --full-index --binary
619                         --not --all
620                         "
621                 return
622                 ;;
623         esac
624         __git_complete_revlist
627 _git_gc ()
629         local cur="${COMP_WORDS[COMP_CWORD]}"
630         case "$cur" in
631         --*)
632                 __gitcomp "--prune --aggressive"
633                 return
634                 ;;
635         esac
636         COMPREPLY=()
639 _git_ls_remote ()
641         __gitcomp "$(__git_remotes)"
644 _git_ls_tree ()
646         __git_complete_file
649 _git_log ()
651         local cur="${COMP_WORDS[COMP_CWORD]}"
652         case "$cur" in
653         --pretty=*)
654                 __gitcomp "
655                         oneline short medium full fuller email raw
656                         " "" "${cur##--pretty=}"
657                 return
658                 ;;
659         --date=*)
660                 __gitcomp "
661                         relative iso8601 rfc2822 short local default
662                 " "" "${cur##--date=}"
663                 return
664                 ;;
665         --*)
666                 __gitcomp "
667                         --max-count= --max-age= --since= --after=
668                         --min-age= --before= --until=
669                         --root --topo-order --date-order --reverse
670                         --no-merges --follow
671                         --abbrev-commit --abbrev=
672                         --relative-date --date=
673                         --author= --committer= --grep=
674                         --all-match
675                         --pretty= --name-status --name-only --raw
676                         --not --all
677                         --left-right --cherry-pick
678                         "
679                 return
680                 ;;
681         esac
682         __git_complete_revlist
685 _git_merge ()
687         local cur="${COMP_WORDS[COMP_CWORD]}"
688         case "${COMP_WORDS[COMP_CWORD-1]}" in
689         -s|--strategy)
690                 __gitcomp "$(__git_merge_strategies)"
691                 return
692         esac
693         case "$cur" in
694         --strategy=*)
695                 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
696                 return
697                 ;;
698         --*)
699                 __gitcomp "
700                         --no-commit --no-summary --squash --strategy
701                         "
702                 return
703         esac
704         __gitcomp "$(__git_refs)"
707 _git_merge_base ()
709         __gitcomp "$(__git_refs)"
712 _git_name_rev ()
714         __gitcomp "--tags --all --stdin"
717 _git_pull ()
719         local cur="${COMP_WORDS[COMP_CWORD]}"
721         case "${COMP_WORDS[0]},$COMP_CWORD" in
722         git-pull*,1)
723                 __gitcomp "$(__git_remotes)"
724                 ;;
725         git,2)
726                 __gitcomp "$(__git_remotes)"
727                 ;;
728         *)
729                 local remote
730                 case "${COMP_WORDS[0]}" in
731                 git-pull)  remote="${COMP_WORDS[1]}" ;;
732                 git)       remote="${COMP_WORDS[2]}" ;;
733                 esac
734                 __gitcomp "$(__git_refs "$remote")"
735                 ;;
736         esac
739 _git_push ()
741         local cur="${COMP_WORDS[COMP_CWORD]}"
743         case "${COMP_WORDS[0]},$COMP_CWORD" in
744         git-push*,1)
745                 __gitcomp "$(__git_remotes)"
746                 ;;
747         git,2)
748                 __gitcomp "$(__git_remotes)"
749                 ;;
750         *)
751                 case "$cur" in
752                 *:*)
753                         local remote
754                         case "${COMP_WORDS[0]}" in
755                         git-push)  remote="${COMP_WORDS[1]}" ;;
756                         git)       remote="${COMP_WORDS[2]}" ;;
757                         esac
758                         __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
759                         ;;
760                 +*)
761                         __gitcomp "$(__git_refs)" + "${cur#+}"
762                         ;;
763                 *)
764                         __gitcomp "$(__git_refs)"
765                         ;;
766                 esac
767                 ;;
768         esac
771 _git_rebase ()
773         local cur="${COMP_WORDS[COMP_CWORD]}"
774         if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
775                 __gitcomp "--continue --skip --abort"
776                 return
777         fi
778         case "${COMP_WORDS[COMP_CWORD-1]}" in
779         -s|--strategy)
780                 __gitcomp "$(__git_merge_strategies)"
781                 return
782         esac
783         case "$cur" in
784         --strategy=*)
785                 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
786                 return
787                 ;;
788         --*)
789                 __gitcomp "--onto --merge --strategy"
790                 return
791         esac
792         __gitcomp "$(__git_refs)"
795 _git_config ()
797         local cur="${COMP_WORDS[COMP_CWORD]}"
798         local prv="${COMP_WORDS[COMP_CWORD-1]}"
799         case "$prv" in
800         branch.*.remote)
801                 __gitcomp "$(__git_remotes)"
802                 return
803                 ;;
804         branch.*.merge)
805                 __gitcomp "$(__git_refs)"
806                 return
807                 ;;
808         remote.*.fetch)
809                 local remote="${prv#remote.}"
810                 remote="${remote%.fetch}"
811                 __gitcomp "$(__git_refs_remotes "$remote")"
812                 return
813                 ;;
814         remote.*.push)
815                 local remote="${prv#remote.}"
816                 remote="${remote%.push}"
817                 __gitcomp "$(git --git-dir="$(__gitdir)" \
818                         for-each-ref --format='%(refname):%(refname)' \
819                         refs/heads)"
820                 return
821                 ;;
822         pull.twohead|pull.octopus)
823                 __gitcomp "$(__git_merge_strategies)"
824                 return
825                 ;;
826         color.branch|color.diff|color.status)
827                 __gitcomp "always never auto"
828                 return
829                 ;;
830         color.*.*)
831                 __gitcomp "
832                         black red green yellow blue magenta cyan white
833                         bold dim ul blink reverse
834                         "
835                 return
836                 ;;
837         *.*)
838                 COMPREPLY=()
839                 return
840                 ;;
841         esac
842         case "$cur" in
843         --*)
844                 __gitcomp "
845                         --global --system --file=
846                         --list --replace-all
847                         --get --get-all --get-regexp
848                         --add --unset --unset-all
849                         --remove-section --rename-section
850                         "
851                 return
852                 ;;
853         branch.*.*)
854                 local pfx="${cur%.*}."
855                 cur="${cur##*.}"
856                 __gitcomp "remote merge" "$pfx" "$cur"
857                 return
858                 ;;
859         branch.*)
860                 local pfx="${cur%.*}."
861                 cur="${cur#*.}"
862                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
863                 return
864                 ;;
865         remote.*.*)
866                 local pfx="${cur%.*}."
867                 cur="${cur##*.}"
868                 __gitcomp "
869                         url fetch push skipDefaultUpdate
870                         receivepack uploadpack tagopt
871                         " "$pfx" "$cur"
872                 return
873                 ;;
874         remote.*)
875                 local pfx="${cur%.*}."
876                 cur="${cur#*.}"
877                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
878                 return
879                 ;;
880         esac
881         __gitcomp "
882                 apply.whitespace
883                 core.fileMode
884                 core.gitProxy
885                 core.ignoreStat
886                 core.preferSymlinkRefs
887                 core.logAllRefUpdates
888                 core.loosecompression
889                 core.repositoryFormatVersion
890                 core.sharedRepository
891                 core.warnAmbiguousRefs
892                 core.compression
893                 core.legacyHeaders
894                 core.packedGitWindowSize
895                 core.packedGitLimit
896                 clean.requireForce
897                 color.branch
898                 color.branch.current
899                 color.branch.local
900                 color.branch.remote
901                 color.branch.plain
902                 color.diff
903                 color.diff.plain
904                 color.diff.meta
905                 color.diff.frag
906                 color.diff.old
907                 color.diff.new
908                 color.diff.commit
909                 color.diff.whitespace
910                 color.pager
911                 color.status
912                 color.status.header
913                 color.status.added
914                 color.status.changed
915                 color.status.untracked
916                 diff.renameLimit
917                 diff.renames
918                 fetch.unpackLimit
919                 format.headers
920                 format.subjectprefix
921                 gitcvs.enabled
922                 gitcvs.logfile
923                 gitcvs.allbinary
924                 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dvpass
925                 gc.packrefs
926                 gc.reflogexpire
927                 gc.reflogexpireunreachable
928                 gc.rerereresolved
929                 gc.rerereunresolved
930                 http.sslVerify
931                 http.sslCert
932                 http.sslKey
933                 http.sslCAInfo
934                 http.sslCAPath
935                 http.maxRequests
936                 http.lowSpeedLimit
937                 http.lowSpeedTime
938                 http.noEPSV
939                 i18n.commitEncoding
940                 i18n.logOutputEncoding
941                 log.showroot
942                 merge.tool
943                 merge.summary
944                 merge.verbosity
945                 pack.window
946                 pack.depth
947                 pack.windowMemory
948                 pack.compression
949                 pack.deltaCacheSize
950                 pack.deltaCacheLimit
951                 pull.octopus
952                 pull.twohead
953                 repack.useDeltaBaseOffset
954                 show.difftree
955                 showbranch.default
956                 tar.umask
957                 transfer.unpackLimit
958                 receive.unpackLimit
959                 receive.denyNonFastForwards
960                 user.name
961                 user.email
962                 user.signingkey
963                 whatchanged.difftree
964                 branch. remote.
965         "
968 _git_remote ()
970         local i c=1 command
971         while [ $c -lt $COMP_CWORD ]; do
972                 i="${COMP_WORDS[c]}"
973                 case "$i" in
974                 add|show|prune|update) command="$i"; break ;;
975                 esac
976                 c=$((++c))
977         done
979         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
980                 __gitcomp "add show prune update"
981                 return
982         fi
984         case "$command" in
985         show|prune)
986                 __gitcomp "$(__git_remotes)"
987                 ;;
988         update)
989                 local i c='' IFS=$'\n'
990                 for i in $(git --git-dir="$(__gitdir)" config --list); do
991                         case "$i" in
992                         remotes.*)
993                                 i="${i#remotes.}"
994                                 c="$c ${i/=*/}"
995                                 ;;
996                         esac
997                 done
998                 __gitcomp "$c"
999                 ;;
1000         *)
1001                 COMPREPLY=()
1002                 ;;
1003         esac
1006 _git_reset ()
1008         local cur="${COMP_WORDS[COMP_CWORD]}"
1009         case "$cur" in
1010         --*)
1011                 __gitcomp "--mixed --hard --soft"
1012                 return
1013                 ;;
1014         esac
1015         __gitcomp "$(__git_refs)"
1018 _git_shortlog ()
1020         local cur="${COMP_WORDS[COMP_CWORD]}"
1021         case "$cur" in
1022         --*)
1023                 __gitcomp "
1024                         --max-count= --max-age= --since= --after=
1025                         --min-age= --before= --until=
1026                         --no-merges
1027                         --author= --committer= --grep=
1028                         --all-match
1029                         --not --all
1030                         --numbered --summary
1031                         "
1032                 return
1033                 ;;
1034         esac
1035         __git_complete_revlist
1038 _git_show ()
1040         local cur="${COMP_WORDS[COMP_CWORD]}"
1041         case "$cur" in
1042         --pretty=*)
1043                 __gitcomp "
1044                         oneline short medium full fuller email raw
1045                         " "" "${cur##--pretty=}"
1046                 return
1047                 ;;
1048         --*)
1049                 __gitcomp "--pretty="
1050                 return
1051                 ;;
1052         esac
1053         __git_complete_file
1056 _git_stash ()
1058         __gitcomp 'list show apply clear'
1061 _git_submodule ()
1063         local i c=1 command
1064         while [ $c -lt $COMP_CWORD ]; do
1065                 i="${COMP_WORDS[c]}"
1066                 case "$i" in
1067                 add|status|init|update) command="$i"; break ;;
1068                 esac
1069                 c=$((++c))
1070         done
1072         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
1073                 local cur="${COMP_WORDS[COMP_CWORD]}"
1074                 case "$cur" in
1075                 --*)
1076                         __gitcomp "--quiet --cached"
1077                         ;;
1078                 *)
1079                         __gitcomp "add status init update"
1080                         ;;
1081                 esac
1082                 return
1083         fi
1086 _git_tag ()
1088         local i c=1 f=0
1089         while [ $c -lt $COMP_CWORD ]; do
1090                 i="${COMP_WORDS[c]}"
1091                 case "$i" in
1092                 -d|-v)
1093                         __gitcomp "$(__git_tags)"
1094                         return
1095                         ;;
1096                 -f)
1097                         f=1
1098                         ;;
1099                 esac
1100                 c=$((++c))
1101         done
1103         case "${COMP_WORDS[COMP_CWORD-1]}" in
1104         -m|-F)
1105                 COMPREPLY=()
1106                 ;;
1107         -*|tag|git-tag)
1108                 if [ $f = 1 ]; then
1109                         __gitcomp "$(__git_tags)"
1110                 else
1111                         COMPREPLY=()
1112                 fi
1113                 ;;
1114         *)
1115                 __gitcomp "$(__git_refs)"
1116                 ;;
1117         esac
1120 _git ()
1122         local i c=1 command __git_dir
1124         while [ $c -lt $COMP_CWORD ]; do
1125                 i="${COMP_WORDS[c]}"
1126                 case "$i" in
1127                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1128                 --bare)      __git_dir="." ;;
1129                 --version|--help|-p|--paginate) ;;
1130                 *) command="$i"; break ;;
1131                 esac
1132                 c=$((++c))
1133         done
1135         if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
1136                 case "${COMP_WORDS[COMP_CWORD]}" in
1137                 --*=*) COMPREPLY=() ;;
1138                 --*)   __gitcomp "
1139                         --no-pager
1140                         --git-dir=
1141                         --bare
1142                         --version
1143                         --exec-path
1144                         "
1145                         ;;
1146                 *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1147                 esac
1148                 return
1149         fi
1151         local expansion=$(__git_aliased_command "$command")
1152         [ "$expansion" ] && command="$expansion"
1154         case "$command" in
1155         am)          _git_am ;;
1156         add)         _git_add ;;
1157         apply)       _git_apply ;;
1158         bisect)      _git_bisect ;;
1159         bundle)      _git_bundle ;;
1160         branch)      _git_branch ;;
1161         checkout)    _git_checkout ;;
1162         cherry)      _git_cherry ;;
1163         cherry-pick) _git_cherry_pick ;;
1164         commit)      _git_commit ;;
1165         config)      _git_config ;;
1166         describe)    _git_describe ;;
1167         diff)        _git_diff ;;
1168         fetch)       _git_fetch ;;
1169         format-patch) _git_format_patch ;;
1170         gc)          _git_gc ;;
1171         log)         _git_log ;;
1172         ls-remote)   _git_ls_remote ;;
1173         ls-tree)     _git_ls_tree ;;
1174         merge)       _git_merge;;
1175         merge-base)  _git_merge_base ;;
1176         name-rev)    _git_name_rev ;;
1177         pull)        _git_pull ;;
1178         push)        _git_push ;;
1179         rebase)      _git_rebase ;;
1180         remote)      _git_remote ;;
1181         reset)       _git_reset ;;
1182         shortlog)    _git_shortlog ;;
1183         show)        _git_show ;;
1184         show-branch) _git_log ;;
1185         stash)       _git_stash ;;
1186         submodule)   _git_submodule ;;
1187         tag)         _git_tag ;;
1188         whatchanged) _git_log ;;
1189         *)           COMPREPLY=() ;;
1190         esac
1193 _gitk ()
1195         local cur="${COMP_WORDS[COMP_CWORD]}"
1196         case "$cur" in
1197         --*)
1198                 __gitcomp "--not --all"
1199                 return
1200                 ;;
1201         esac
1202         __git_complete_revlist
1205 complete -o default -o nospace -F _git git
1206 complete -o default -o nospace -F _gitk gitk
1207 complete -o default -o nospace -F _git_am git-am
1208 complete -o default -o nospace -F _git_apply git-apply
1209 complete -o default -o nospace -F _git_bisect git-bisect
1210 complete -o default -o nospace -F _git_branch git-branch
1211 complete -o default -o nospace -F _git_bundle git-bundle
1212 complete -o default -o nospace -F _git_checkout git-checkout
1213 complete -o default -o nospace -F _git_cherry git-cherry
1214 complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1215 complete -o default -o nospace -F _git_commit git-commit
1216 complete -o default -o nospace -F _git_describe git-describe
1217 complete -o default -o nospace -F _git_diff git-diff
1218 complete -o default -o nospace -F _git_fetch git-fetch
1219 complete -o default -o nospace -F _git_format_patch git-format-patch
1220 complete -o default -o nospace -F _git_gc git-gc
1221 complete -o default -o nospace -F _git_log git-log
1222 complete -o default -o nospace -F _git_ls_remote git-ls-remote
1223 complete -o default -o nospace -F _git_ls_tree git-ls-tree
1224 complete -o default -o nospace -F _git_merge git-merge
1225 complete -o default -o nospace -F _git_merge_base git-merge-base
1226 complete -o default -o nospace -F _git_name_rev git-name-rev
1227 complete -o default -o nospace -F _git_pull git-pull
1228 complete -o default -o nospace -F _git_push git-push
1229 complete -o default -o nospace -F _git_rebase git-rebase
1230 complete -o default -o nospace -F _git_config git-config
1231 complete -o default -o nospace -F _git_remote git-remote
1232 complete -o default -o nospace -F _git_reset git-reset
1233 complete -o default -o nospace -F _git_shortlog git-shortlog
1234 complete -o default -o nospace -F _git_show git-show
1235 complete -o default -o nospace -F _git_stash git-stash
1236 complete -o default -o nospace -F _git_submodule git-submodule
1237 complete -o default -o nospace -F _git_log git-show-branch
1238 complete -o default -o nospace -F _git_tag git-tag
1239 complete -o default -o nospace -F _git_log git-whatchanged
1241 # The following are necessary only for Cygwin, and only are needed
1242 # when the user has tab-completed the executable name and consequently
1243 # included the '.exe' suffix.
1245 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1246 complete -o default -o nospace -F _git_add git-add.exe
1247 complete -o default -o nospace -F _git_apply git-apply.exe
1248 complete -o default -o nospace -F _git git.exe
1249 complete -o default -o nospace -F _git_branch git-branch.exe
1250 complete -o default -o nospace -F _git_bundle git-bundle.exe
1251 complete -o default -o nospace -F _git_cherry git-cherry.exe
1252 complete -o default -o nospace -F _git_describe git-describe.exe
1253 complete -o default -o nospace -F _git_diff git-diff.exe
1254 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
1255 complete -o default -o nospace -F _git_log git-log.exe
1256 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
1257 complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1258 complete -o default -o nospace -F _git_name_rev git-name-rev.exe
1259 complete -o default -o nospace -F _git_push git-push.exe
1260 complete -o default -o nospace -F _git_config git-config
1261 complete -o default -o nospace -F _git_shortlog git-shortlog.exe
1262 complete -o default -o nospace -F _git_show git-show.exe
1263 complete -o default -o nospace -F _git_log git-show-branch.exe
1264 complete -o default -o nospace -F _git_tag git-tag.exe
1265 complete -o default -o nospace -F _git_log git-whatchanged.exe
1266 fi