Code

Merge branch 'maint-1.6.5' into maint
[git.git] / contrib / completion / git-completion.bash
1 #!bash
2 #
3 # bash completion support for core Git.
4 #
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
8 #
9 # The contained completion routines provide support for completing:
10 #
11 #    *) local and remote branch names
12 #    *) local and remote tag names
13 #    *) .git/remotes file names
14 #    *) git 'subcommands'
15 #    *) tree paths within 'ref:path/to/file' expressions
16 #    *) common --long-options
17 #
18 # To use these routines:
19 #
20 #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 #    2) Added the following line to your .bashrc:
22 #        source ~/.git-completion.sh
23 #
24 #    3) Consider changing your PS1 to also show the current branch:
25 #        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
26 #
27 #       The argument to __git_ps1 will be displayed only if you
28 #       are currently in a git repository.  The %s token will be
29 #       the name of the current branch.
30 #
31 #       In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
32 #       value, unstaged (*) and staged (+) changes will be shown next
33 #       to the branch name.  You can configure this per-repository
34 #       with the bash.showDirtyState variable, which defaults to true
35 #       once GIT_PS1_SHOWDIRTYSTATE is enabled.
36 #
37 #       You can also see if currently something is stashed, by setting
38 #       GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
39 #       then a '$' will be shown next to the branch name.
40 #
41 #       If you would like to see if there're untracked files, then you can
42 #       set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
43 #       untracked files, then a '%' will be shown next to the branch name.
44 #
45 # To submit patches:
46 #
47 #    *) Read Documentation/SubmittingPatches
48 #    *) Send all patches to the current maintainer:
49 #
50 #       "Shawn O. Pearce" <spearce@spearce.org>
51 #
52 #    *) Always CC the Git mailing list:
53 #
54 #       git@vger.kernel.org
55 #
57 case "$COMP_WORDBREAKS" in
58 *:*) : great ;;
59 *)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
60 esac
62 # __gitdir accepts 0 or 1 arguments (i.e., location)
63 # returns location of .git repo
64 __gitdir ()
65 {
66         if [ -z "${1-}" ]; then
67                 if [ -n "${__git_dir-}" ]; then
68                         echo "$__git_dir"
69                 elif [ -d .git ]; then
70                         echo .git
71                 else
72                         git rev-parse --git-dir 2>/dev/null
73                 fi
74         elif [ -d "$1/.git" ]; then
75                 echo "$1/.git"
76         else
77                 echo "$1"
78         fi
79 }
81 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
82 # returns text to add to bash PS1 prompt (includes branch name)
83 __git_ps1 ()
84 {
85         local g="$(__gitdir)"
86         if [ -n "$g" ]; then
87                 local r
88                 local b
89                 if [ -f "$g/rebase-merge/interactive" ]; then
90                         r="|REBASE-i"
91                         b="$(cat "$g/rebase-merge/head-name")"
92                 elif [ -d "$g/rebase-merge" ]; then
93                         r="|REBASE-m"
94                         b="$(cat "$g/rebase-merge/head-name")"
95                 else
96                         if [ -d "$g/rebase-apply" ]; then
97                                 if [ -f "$g/rebase-apply/rebasing" ]; then
98                                         r="|REBASE"
99                                 elif [ -f "$g/rebase-apply/applying" ]; then
100                                         r="|AM"
101                                 else
102                                         r="|AM/REBASE"
103                                 fi
104                         elif [ -f "$g/MERGE_HEAD" ]; then
105                                 r="|MERGING"
106                         elif [ -f "$g/BISECT_LOG" ]; then
107                                 r="|BISECTING"
108                         fi
110                         b="$(git symbolic-ref HEAD 2>/dev/null)" || {
112                                 b="$(
113                                 case "${GIT_PS1_DESCRIBE_STYLE-}" in
114                                 (contains)
115                                         git describe --contains HEAD ;;
116                                 (branch)
117                                         git describe --contains --all HEAD ;;
118                                 (describe)
119                                         git describe HEAD ;;
120                                 (* | default)
121                                         git describe --exact-match HEAD ;;
122                                 esac 2>/dev/null)" ||
124                                 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
125                                 b="unknown"
126                                 b="($b)"
127                         }
128                 fi
130                 local w
131                 local i
132                 local s
133                 local u
134                 local c
136                 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
137                         if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
138                                 c="BARE:"
139                         else
140                                 b="GIT_DIR!"
141                         fi
142                 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
143                         if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
144                                 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
145                                         git diff --no-ext-diff --quiet --exit-code || w="*"
146                                         if git rev-parse --quiet --verify HEAD >/dev/null; then
147                                                 git diff-index --cached --quiet HEAD -- || i="+"
148                                         else
149                                                 i="#"
150                                         fi
151                                 fi
152                         fi
153                         if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
154                                 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
155                         fi
157                         if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
158                            if [ -n "$(git ls-files --others --exclude-standard)" ]; then
159                               u="%"
160                            fi
161                         fi
162                 fi
164                 if [ -n "${1-}" ]; then
165                         printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
166                 else
167                         printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
168                 fi
169         fi
172 # __gitcomp_1 requires 2 arguments
173 __gitcomp_1 ()
175         local c IFS=' '$'\t'$'\n'
176         for c in $1; do
177                 case "$c$2" in
178                 --*=*) printf %s$'\n' "$c$2" ;;
179                 *.)    printf %s$'\n' "$c$2" ;;
180                 *)     printf %s$'\n' "$c$2 " ;;
181                 esac
182         done
185 # __gitcomp accepts 1, 2, 3, or 4 arguments
186 # generates completion reply with compgen
187 __gitcomp ()
189         local cur="${COMP_WORDS[COMP_CWORD]}"
190         if [ $# -gt 2 ]; then
191                 cur="$3"
192         fi
193         case "$cur" in
194         --*=)
195                 COMPREPLY=()
196                 ;;
197         *)
198                 local IFS=$'\n'
199                 COMPREPLY=($(compgen -P "${2-}" \
200                         -W "$(__gitcomp_1 "${1-}" "${4-}")" \
201                         -- "$cur"))
202                 ;;
203         esac
206 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
207 __git_heads ()
209         local cmd i is_hash=y dir="$(__gitdir "${1-}")"
210         if [ -d "$dir" ]; then
211                 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
212                         refs/heads
213                 return
214         fi
215         for i in $(git ls-remote "${1-}" 2>/dev/null); do
216                 case "$is_hash,$i" in
217                 y,*) is_hash=n ;;
218                 n,*^{}) is_hash=y ;;
219                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
220                 n,*) is_hash=y; echo "$i" ;;
221                 esac
222         done
225 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
226 __git_tags ()
228         local cmd i is_hash=y dir="$(__gitdir "${1-}")"
229         if [ -d "$dir" ]; then
230                 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
231                         refs/tags
232                 return
233         fi
234         for i in $(git ls-remote "${1-}" 2>/dev/null); do
235                 case "$is_hash,$i" in
236                 y,*) is_hash=n ;;
237                 n,*^{}) is_hash=y ;;
238                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
239                 n,*) is_hash=y; echo "$i" ;;
240                 esac
241         done
244 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
245 __git_refs ()
247         local i is_hash=y dir="$(__gitdir "${1-}")"
248         local cur="${COMP_WORDS[COMP_CWORD]}" format refs
249         if [ -d "$dir" ]; then
250                 case "$cur" in
251                 refs|refs/*)
252                         format="refname"
253                         refs="${cur%/*}"
254                         ;;
255                 *)
256                         if [ -e "$dir/HEAD" ]; then echo HEAD; fi
257                         format="refname:short"
258                         refs="refs/tags refs/heads refs/remotes"
259                         ;;
260                 esac
261                 git --git-dir="$dir" for-each-ref --format="%($format)" \
262                         $refs
263                 return
264         fi
265         for i in $(git ls-remote "$dir" 2>/dev/null); do
266                 case "$is_hash,$i" in
267                 y,*) is_hash=n ;;
268                 n,*^{}) is_hash=y ;;
269                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
270                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
271                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
272                 n,*) is_hash=y; echo "$i" ;;
273                 esac
274         done
277 # __git_refs2 requires 1 argument (to pass to __git_refs)
278 __git_refs2 ()
280         local i
281         for i in $(__git_refs "$1"); do
282                 echo "$i:$i"
283         done
286 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
287 __git_refs_remotes ()
289         local cmd i is_hash=y
290         for i in $(git ls-remote "$1" 2>/dev/null); do
291                 case "$is_hash,$i" in
292                 n,refs/heads/*)
293                         is_hash=y
294                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
295                         ;;
296                 y,*) is_hash=n ;;
297                 n,*^{}) is_hash=y ;;
298                 n,refs/tags/*) is_hash=y;;
299                 n,*) is_hash=y; ;;
300                 esac
301         done
304 __git_remotes ()
306         local i ngoff IFS=$'\n' d="$(__gitdir)"
307         shopt -q nullglob || ngoff=1
308         shopt -s nullglob
309         for i in "$d/remotes"/*; do
310                 echo ${i#$d/remotes/}
311         done
312         [ "$ngoff" ] && shopt -u nullglob
313         for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
314                 i="${i#remote.}"
315                 echo "${i/.url*/}"
316         done
319 __git_list_merge_strategies ()
321         git merge -s help 2>&1 |
322         sed -n -e '/[Aa]vailable strategies are: /,/^$/{
323                 s/\.$//
324                 s/.*://
325                 s/^[    ]*//
326                 s/[     ]*$//
327                 p
328         }'
331 __git_merge_strategies=
332 # 'git merge -s help' (and thus detection of the merge strategy
333 # list) fails, unfortunately, if run outside of any git working
334 # tree.  __git_merge_strategies is set to the empty string in
335 # that case, and the detection will be repeated the next time it
336 # is needed.
337 __git_compute_merge_strategies ()
339         : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
342 __git_complete_file ()
344         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
345         case "$cur" in
346         ?*:*)
347                 ref="${cur%%:*}"
348                 cur="${cur#*:}"
349                 case "$cur" in
350                 ?*/*)
351                         pfx="${cur%/*}"
352                         cur="${cur##*/}"
353                         ls="$ref:$pfx"
354                         pfx="$pfx/"
355                         ;;
356                 *)
357                         ls="$ref"
358                         ;;
359             esac
361                 case "$COMP_WORDBREAKS" in
362                 *:*) : great ;;
363                 *)   pfx="$ref:$pfx" ;;
364                 esac
366                 local IFS=$'\n'
367                 COMPREPLY=($(compgen -P "$pfx" \
368                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
369                                 | sed '/^100... blob /{
370                                            s,^.*        ,,
371                                            s,$, ,
372                                        }
373                                        /^120000 blob /{
374                                            s,^.*        ,,
375                                            s,$, ,
376                                        }
377                                        /^040000 tree /{
378                                            s,^.*        ,,
379                                            s,$,/,
380                                        }
381                                        s/^.*    //')" \
382                         -- "$cur"))
383                 ;;
384         *)
385                 __gitcomp "$(__git_refs)"
386                 ;;
387         esac
390 __git_complete_revlist ()
392         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
393         case "$cur" in
394         *...*)
395                 pfx="${cur%...*}..."
396                 cur="${cur#*...}"
397                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
398                 ;;
399         *..*)
400                 pfx="${cur%..*}.."
401                 cur="${cur#*..}"
402                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
403                 ;;
404         *)
405                 __gitcomp "$(__git_refs)"
406                 ;;
407         esac
410 __git_complete_remote_or_refspec ()
412         local cmd="${COMP_WORDS[1]}"
413         local cur="${COMP_WORDS[COMP_CWORD]}"
414         local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
415         while [ $c -lt $COMP_CWORD ]; do
416                 i="${COMP_WORDS[c]}"
417                 case "$i" in
418                 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
419                 --all)
420                         case "$cmd" in
421                         push) no_complete_refspec=1 ;;
422                         fetch)
423                                 COMPREPLY=()
424                                 return
425                                 ;;
426                         *) ;;
427                         esac
428                         ;;
429                 -*) ;;
430                 *) remote="$i"; break ;;
431                 esac
432                 c=$((++c))
433         done
434         if [ -z "$remote" ]; then
435                 __gitcomp "$(__git_remotes)"
436                 return
437         fi
438         if [ $no_complete_refspec = 1 ]; then
439                 COMPREPLY=()
440                 return
441         fi
442         [ "$remote" = "." ] && remote=
443         case "$cur" in
444         *:*)
445                 case "$COMP_WORDBREAKS" in
446                 *:*) : great ;;
447                 *)   pfx="${cur%%:*}:" ;;
448                 esac
449                 cur="${cur#*:}"
450                 lhs=0
451                 ;;
452         +*)
453                 pfx="+"
454                 cur="${cur#+}"
455                 ;;
456         esac
457         case "$cmd" in
458         fetch)
459                 if [ $lhs = 1 ]; then
460                         __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
461                 else
462                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
463                 fi
464                 ;;
465         pull)
466                 if [ $lhs = 1 ]; then
467                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
468                 else
469                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
470                 fi
471                 ;;
472         push)
473                 if [ $lhs = 1 ]; then
474                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
475                 else
476                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
477                 fi
478                 ;;
479         esac
482 __git_complete_strategy ()
484         __git_compute_merge_strategies
485         case "${COMP_WORDS[COMP_CWORD-1]}" in
486         -s|--strategy)
487                 __gitcomp "$__git_merge_strategies"
488                 return 0
489         esac
490         local cur="${COMP_WORDS[COMP_CWORD]}"
491         case "$cur" in
492         --strategy=*)
493                 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
494                 return 0
495                 ;;
496         esac
497         return 1
500 __git_list_all_commands ()
502         local i IFS=" "$'\n'
503         for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
504         do
505                 case $i in
506                 *--*)             : helper pattern;;
507                 *) echo $i;;
508                 esac
509         done
512 __git_all_commands=
513 __git_compute_all_commands ()
515         : ${__git_all_commands:=$(__git_list_all_commands)}
518 __git_list_porcelain_commands ()
520         local i IFS=" "$'\n'
521         __git_compute_all_commands
522         for i in "help" $__git_all_commands
523         do
524                 case $i in
525                 *--*)             : helper pattern;;
526                 applymbox)        : ask gittus;;
527                 applypatch)       : ask gittus;;
528                 archimport)       : import;;
529                 cat-file)         : plumbing;;
530                 check-attr)       : plumbing;;
531                 check-ref-format) : plumbing;;
532                 checkout-index)   : plumbing;;
533                 commit-tree)      : plumbing;;
534                 count-objects)    : infrequent;;
535                 cvsexportcommit)  : export;;
536                 cvsimport)        : import;;
537                 cvsserver)        : daemon;;
538                 daemon)           : daemon;;
539                 diff-files)       : plumbing;;
540                 diff-index)       : plumbing;;
541                 diff-tree)        : plumbing;;
542                 fast-import)      : import;;
543                 fast-export)      : export;;
544                 fsck-objects)     : plumbing;;
545                 fetch-pack)       : plumbing;;
546                 fmt-merge-msg)    : plumbing;;
547                 for-each-ref)     : plumbing;;
548                 hash-object)      : plumbing;;
549                 http-*)           : transport;;
550                 index-pack)       : plumbing;;
551                 init-db)          : deprecated;;
552                 local-fetch)      : plumbing;;
553                 lost-found)       : infrequent;;
554                 ls-files)         : plumbing;;
555                 ls-remote)        : plumbing;;
556                 ls-tree)          : plumbing;;
557                 mailinfo)         : plumbing;;
558                 mailsplit)        : plumbing;;
559                 merge-*)          : plumbing;;
560                 mktree)           : plumbing;;
561                 mktag)            : plumbing;;
562                 pack-objects)     : plumbing;;
563                 pack-redundant)   : plumbing;;
564                 pack-refs)        : plumbing;;
565                 parse-remote)     : plumbing;;
566                 patch-id)         : plumbing;;
567                 peek-remote)      : plumbing;;
568                 prune)            : plumbing;;
569                 prune-packed)     : plumbing;;
570                 quiltimport)      : import;;
571                 read-tree)        : plumbing;;
572                 receive-pack)     : plumbing;;
573                 reflog)           : plumbing;;
574                 remote-*)         : transport;;
575                 repo-config)      : deprecated;;
576                 rerere)           : plumbing;;
577                 rev-list)         : plumbing;;
578                 rev-parse)        : plumbing;;
579                 runstatus)        : plumbing;;
580                 sh-setup)         : internal;;
581                 shell)            : daemon;;
582                 show-ref)         : plumbing;;
583                 send-pack)        : plumbing;;
584                 show-index)       : plumbing;;
585                 ssh-*)            : transport;;
586                 stripspace)       : plumbing;;
587                 symbolic-ref)     : plumbing;;
588                 tar-tree)         : deprecated;;
589                 unpack-file)      : plumbing;;
590                 unpack-objects)   : plumbing;;
591                 update-index)     : plumbing;;
592                 update-ref)       : plumbing;;
593                 update-server-info) : daemon;;
594                 upload-archive)   : plumbing;;
595                 upload-pack)      : plumbing;;
596                 write-tree)       : plumbing;;
597                 var)              : infrequent;;
598                 verify-pack)      : infrequent;;
599                 verify-tag)       : plumbing;;
600                 *) echo $i;;
601                 esac
602         done
605 __git_porcelain_commands=
606 __git_compute_porcelain_commands ()
608         __git_compute_all_commands
609         : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
612 __git_aliases ()
614         local i IFS=$'\n'
615         for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
616                 case "$i" in
617                 alias.*)
618                         i="${i#alias.}"
619                         echo "${i/ */}"
620                         ;;
621                 esac
622         done
625 # __git_aliased_command requires 1 argument
626 __git_aliased_command ()
628         local word cmdline=$(git --git-dir="$(__gitdir)" \
629                 config --get "alias.$1")
630         for word in $cmdline; do
631                 if [ "${word##-*}" ]; then
632                         echo $word
633                         return
634                 fi
635         done
638 # __git_find_on_cmdline requires 1 argument
639 __git_find_on_cmdline ()
641         local word subcommand c=1
643         while [ $c -lt $COMP_CWORD ]; do
644                 word="${COMP_WORDS[c]}"
645                 for subcommand in $1; do
646                         if [ "$subcommand" = "$word" ]; then
647                                 echo "$subcommand"
648                                 return
649                         fi
650                 done
651                 c=$((++c))
652         done
655 __git_has_doubledash ()
657         local c=1
658         while [ $c -lt $COMP_CWORD ]; do
659                 if [ "--" = "${COMP_WORDS[c]}" ]; then
660                         return 0
661                 fi
662                 c=$((++c))
663         done
664         return 1
667 __git_whitespacelist="nowarn warn error error-all fix"
669 _git_am ()
671         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
672         if [ -d "$dir"/rebase-apply ]; then
673                 __gitcomp "--skip --resolved --abort"
674                 return
675         fi
676         case "$cur" in
677         --whitespace=*)
678                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
679                 return
680                 ;;
681         --*)
682                 __gitcomp "
683                         --3way --committer-date-is-author-date --ignore-date
684                         --ignore-whitespace --ignore-space-change
685                         --interactive --keep --no-utf8 --signoff --utf8
686                         --whitespace= --scissors
687                         "
688                 return
689         esac
690         COMPREPLY=()
693 _git_apply ()
695         local cur="${COMP_WORDS[COMP_CWORD]}"
696         case "$cur" in
697         --whitespace=*)
698                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
699                 return
700                 ;;
701         --*)
702                 __gitcomp "
703                         --stat --numstat --summary --check --index
704                         --cached --index-info --reverse --reject --unidiff-zero
705                         --apply --no-add --exclude=
706                         --ignore-whitespace --ignore-space-change
707                         --whitespace= --inaccurate-eof --verbose
708                         "
709                 return
710         esac
711         COMPREPLY=()
714 _git_add ()
716         __git_has_doubledash && return
718         local cur="${COMP_WORDS[COMP_CWORD]}"
719         case "$cur" in
720         --*)
721                 __gitcomp "
722                         --interactive --refresh --patch --update --dry-run
723                         --ignore-errors --intent-to-add
724                         "
725                 return
726         esac
727         COMPREPLY=()
730 _git_archive ()
732         local cur="${COMP_WORDS[COMP_CWORD]}"
733         case "$cur" in
734         --format=*)
735                 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
736                 return
737                 ;;
738         --remote=*)
739                 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
740                 return
741                 ;;
742         --*)
743                 __gitcomp "
744                         --format= --list --verbose
745                         --prefix= --remote= --exec=
746                         "
747                 return
748                 ;;
749         esac
750         __git_complete_file
753 _git_bisect ()
755         __git_has_doubledash && return
757         local subcommands="start bad good skip reset visualize replay log run"
758         local subcommand="$(__git_find_on_cmdline "$subcommands")"
759         if [ -z "$subcommand" ]; then
760                 __gitcomp "$subcommands"
761                 return
762         fi
764         case "$subcommand" in
765         bad|good|reset|skip)
766                 __gitcomp "$(__git_refs)"
767                 ;;
768         *)
769                 COMPREPLY=()
770                 ;;
771         esac
774 _git_branch ()
776         local i c=1 only_local_ref="n" has_r="n"
778         while [ $c -lt $COMP_CWORD ]; do
779                 i="${COMP_WORDS[c]}"
780                 case "$i" in
781                 -d|-m)  only_local_ref="y" ;;
782                 -r)     has_r="y" ;;
783                 esac
784                 c=$((++c))
785         done
787         case "${COMP_WORDS[COMP_CWORD]}" in
788         --*)
789                 __gitcomp "
790                         --color --no-color --verbose --abbrev= --no-abbrev
791                         --track --no-track --contains --merged --no-merged
792                         "
793                 ;;
794         *)
795                 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
796                         __gitcomp "$(__git_heads)"
797                 else
798                         __gitcomp "$(__git_refs)"
799                 fi
800                 ;;
801         esac
804 _git_bundle ()
806         local cmd="${COMP_WORDS[2]}"
807         case "$COMP_CWORD" in
808         2)
809                 __gitcomp "create list-heads verify unbundle"
810                 ;;
811         3)
812                 # looking for a file
813                 ;;
814         *)
815                 case "$cmd" in
816                         create)
817                                 __git_complete_revlist
818                         ;;
819                 esac
820                 ;;
821         esac
824 _git_checkout ()
826         __git_has_doubledash && return
828         local cur="${COMP_WORDS[COMP_CWORD]}"
829         case "$cur" in
830         --conflict=*)
831                 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
832                 ;;
833         --*)
834                 __gitcomp "
835                         --quiet --ours --theirs --track --no-track --merge
836                         --conflict= --patch
837                         "
838                 ;;
839         *)
840                 __gitcomp "$(__git_refs)"
841                 ;;
842         esac
845 _git_cherry ()
847         __gitcomp "$(__git_refs)"
850 _git_cherry_pick ()
852         local cur="${COMP_WORDS[COMP_CWORD]}"
853         case "$cur" in
854         --*)
855                 __gitcomp "--edit --no-commit"
856                 ;;
857         *)
858                 __gitcomp "$(__git_refs)"
859                 ;;
860         esac
863 _git_clean ()
865         __git_has_doubledash && return
867         local cur="${COMP_WORDS[COMP_CWORD]}"
868         case "$cur" in
869         --*)
870                 __gitcomp "--dry-run --quiet"
871                 return
872                 ;;
873         esac
874         COMPREPLY=()
877 _git_clone ()
879         local cur="${COMP_WORDS[COMP_CWORD]}"
880         case "$cur" in
881         --*)
882                 __gitcomp "
883                         --local
884                         --no-hardlinks
885                         --shared
886                         --reference
887                         --quiet
888                         --no-checkout
889                         --bare
890                         --mirror
891                         --origin
892                         --upload-pack
893                         --template=
894                         --depth
895                         "
896                 return
897                 ;;
898         esac
899         COMPREPLY=()
902 _git_commit ()
904         __git_has_doubledash && return
906         local cur="${COMP_WORDS[COMP_CWORD]}"
907         case "$cur" in
908         --cleanup=*)
909                 __gitcomp "default strip verbatim whitespace
910                         " "" "${cur##--cleanup=}"
911                 return
912                 ;;
913         --reuse-message=*)
914                 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
915                 return
916                 ;;
917         --reedit-message=*)
918                 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
919                 return
920                 ;;
921         --untracked-files=*)
922                 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
923                 return
924                 ;;
925         --*)
926                 __gitcomp "
927                         --all --author= --signoff --verify --no-verify
928                         --edit --amend --include --only --interactive
929                         --dry-run --reuse-message= --reedit-message=
930                         --reset-author --file= --message= --template=
931                         --cleanup= --untracked-files --untracked-files=
932                         --verbose --quiet
933                         "
934                 return
935         esac
936         COMPREPLY=()
939 _git_describe ()
941         local cur="${COMP_WORDS[COMP_CWORD]}"
942         case "$cur" in
943         --*)
944                 __gitcomp "
945                         --all --tags --contains --abbrev= --candidates=
946                         --exact-match --debug --long --match --always
947                         "
948                 return
949         esac
950         __gitcomp "$(__git_refs)"
953 __git_diff_common_options="--stat --numstat --shortstat --summary
954                         --patch-with-stat --name-only --name-status --color
955                         --no-color --color-words --no-renames --check
956                         --full-index --binary --abbrev --diff-filter=
957                         --find-copies-harder
958                         --text --ignore-space-at-eol --ignore-space-change
959                         --ignore-all-space --exit-code --quiet --ext-diff
960                         --no-ext-diff
961                         --no-prefix --src-prefix= --dst-prefix=
962                         --inter-hunk-context=
963                         --patience
964                         --raw
965                         --dirstat --dirstat= --dirstat-by-file
966                         --dirstat-by-file= --cumulative
969 _git_diff ()
971         __git_has_doubledash && return
973         local cur="${COMP_WORDS[COMP_CWORD]}"
974         case "$cur" in
975         --*)
976                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
977                         --base --ours --theirs
978                         $__git_diff_common_options
979                         "
980                 return
981                 ;;
982         esac
983         __git_complete_file
986 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
987                         tkdiff vimdiff gvimdiff xxdiff araxis p4merge
990 _git_difftool ()
992         __git_has_doubledash && return
994         local cur="${COMP_WORDS[COMP_CWORD]}"
995         case "$cur" in
996         --tool=*)
997                 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
998                 return
999                 ;;
1000         --*)
1001                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1002                         --base --ours --theirs
1003                         --no-renames --diff-filter= --find-copies-harder
1004                         --relative --ignore-submodules
1005                         --tool="
1006                 return
1007                 ;;
1008         esac
1009         __git_complete_file
1012 __git_fetch_options="
1013         --quiet --verbose --append --upload-pack --force --keep --depth=
1014         --tags --no-tags --all --prune --dry-run
1017 _git_fetch ()
1019         local cur="${COMP_WORDS[COMP_CWORD]}"
1020         case "$cur" in
1021         --*)
1022                 __gitcomp "$__git_fetch_options"
1023                 return
1024                 ;;
1025         esac
1026         __git_complete_remote_or_refspec
1029 _git_format_patch ()
1031         local cur="${COMP_WORDS[COMP_CWORD]}"
1032         case "$cur" in
1033         --thread=*)
1034                 __gitcomp "
1035                         deep shallow
1036                         " "" "${cur##--thread=}"
1037                 return
1038                 ;;
1039         --*)
1040                 __gitcomp "
1041                         --stdout --attach --no-attach --thread --thread=
1042                         --output-directory
1043                         --numbered --start-number
1044                         --numbered-files
1045                         --keep-subject
1046                         --signoff
1047                         --in-reply-to= --cc=
1048                         --full-index --binary
1049                         --not --all
1050                         --cover-letter
1051                         --no-prefix --src-prefix= --dst-prefix=
1052                         --inline --suffix= --ignore-if-in-upstream
1053                         --subject-prefix=
1054                         "
1055                 return
1056                 ;;
1057         esac
1058         __git_complete_revlist
1061 _git_fsck ()
1063         local cur="${COMP_WORDS[COMP_CWORD]}"
1064         case "$cur" in
1065         --*)
1066                 __gitcomp "
1067                         --tags --root --unreachable --cache --no-reflogs --full
1068                         --strict --verbose --lost-found
1069                         "
1070                 return
1071                 ;;
1072         esac
1073         COMPREPLY=()
1076 _git_gc ()
1078         local cur="${COMP_WORDS[COMP_CWORD]}"
1079         case "$cur" in
1080         --*)
1081                 __gitcomp "--prune --aggressive"
1082                 return
1083                 ;;
1084         esac
1085         COMPREPLY=()
1088 _git_grep ()
1090         __git_has_doubledash && return
1092         local cur="${COMP_WORDS[COMP_CWORD]}"
1093         case "$cur" in
1094         --*)
1095                 __gitcomp "
1096                         --cached
1097                         --text --ignore-case --word-regexp --invert-match
1098                         --full-name
1099                         --extended-regexp --basic-regexp --fixed-strings
1100                         --files-with-matches --name-only
1101                         --files-without-match
1102                         --max-depth
1103                         --count
1104                         --and --or --not --all-match
1105                         "
1106                 return
1107                 ;;
1108         esac
1110         __gitcomp "$(__git_refs)"
1113 _git_help ()
1115         local cur="${COMP_WORDS[COMP_CWORD]}"
1116         case "$cur" in
1117         --*)
1118                 __gitcomp "--all --info --man --web"
1119                 return
1120                 ;;
1121         esac
1122         __git_compute_all_commands
1123         __gitcomp "$__git_all_commands
1124                 attributes cli core-tutorial cvs-migration
1125                 diffcore gitk glossary hooks ignore modules
1126                 repository-layout tutorial tutorial-2
1127                 workflows
1128                 "
1131 _git_init ()
1133         local cur="${COMP_WORDS[COMP_CWORD]}"
1134         case "$cur" in
1135         --shared=*)
1136                 __gitcomp "
1137                         false true umask group all world everybody
1138                         " "" "${cur##--shared=}"
1139                 return
1140                 ;;
1141         --*)
1142                 __gitcomp "--quiet --bare --template= --shared --shared="
1143                 return
1144                 ;;
1145         esac
1146         COMPREPLY=()
1149 _git_ls_files ()
1151         __git_has_doubledash && return
1153         local cur="${COMP_WORDS[COMP_CWORD]}"
1154         case "$cur" in
1155         --*)
1156                 __gitcomp "--cached --deleted --modified --others --ignored
1157                         --stage --directory --no-empty-directory --unmerged
1158                         --killed --exclude= --exclude-from=
1159                         --exclude-per-directory= --exclude-standard
1160                         --error-unmatch --with-tree= --full-name
1161                         --abbrev --ignored --exclude-per-directory
1162                         "
1163                 return
1164                 ;;
1165         esac
1166         COMPREPLY=()
1169 _git_ls_remote ()
1171         __gitcomp "$(__git_remotes)"
1174 _git_ls_tree ()
1176         __git_complete_file
1179 # Options that go well for log, shortlog and gitk
1180 __git_log_common_options="
1181         --not --all
1182         --branches --tags --remotes
1183         --first-parent --merges --no-merges
1184         --max-count=
1185         --max-age= --since= --after=
1186         --min-age= --until= --before=
1188 # Options that go well for log and gitk (not shortlog)
1189 __git_log_gitk_options="
1190         --dense --sparse --full-history
1191         --simplify-merges --simplify-by-decoration
1192         --left-right
1194 # Options that go well for log and shortlog (not gitk)
1195 __git_log_shortlog_options="
1196         --author= --committer= --grep=
1197         --all-match
1200 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1201 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1203 _git_log ()
1205         __git_has_doubledash && return
1207         local cur="${COMP_WORDS[COMP_CWORD]}"
1208         local g="$(git rev-parse --git-dir 2>/dev/null)"
1209         local merge=""
1210         if [ -f "$g/MERGE_HEAD" ]; then
1211                 merge="--merge"
1212         fi
1213         case "$cur" in
1214         --pretty=*)
1215                 __gitcomp "$__git_log_pretty_formats
1216                         " "" "${cur##--pretty=}"
1217                 return
1218                 ;;
1219         --format=*)
1220                 __gitcomp "$__git_log_pretty_formats
1221                         " "" "${cur##--format=}"
1222                 return
1223                 ;;
1224         --date=*)
1225                 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1226                 return
1227                 ;;
1228         --decorate=*)
1229                 __gitcomp "long short" "" "${cur##--decorate=}"
1230                 return
1231                 ;;
1232         --*)
1233                 __gitcomp "
1234                         $__git_log_common_options
1235                         $__git_log_shortlog_options
1236                         $__git_log_gitk_options
1237                         --root --topo-order --date-order --reverse
1238                         --follow --full-diff
1239                         --abbrev-commit --abbrev=
1240                         --relative-date --date=
1241                         --pretty= --format= --oneline
1242                         --cherry-pick
1243                         --graph
1244                         --decorate --decorate=
1245                         --walk-reflogs
1246                         --parents --children
1247                         $merge
1248                         $__git_diff_common_options
1249                         --pickaxe-all --pickaxe-regex
1250                         "
1251                 return
1252                 ;;
1253         esac
1254         __git_complete_revlist
1257 __git_merge_options="
1258         --no-commit --no-stat --log --no-log --squash --strategy
1259         --commit --stat --no-squash --ff --no-ff --ff-only
1262 _git_merge ()
1264         __git_complete_strategy && return
1266         local cur="${COMP_WORDS[COMP_CWORD]}"
1267         case "$cur" in
1268         --*)
1269                 __gitcomp "$__git_merge_options"
1270                 return
1271         esac
1272         __gitcomp "$(__git_refs)"
1275 _git_mergetool ()
1277         local cur="${COMP_WORDS[COMP_CWORD]}"
1278         case "$cur" in
1279         --tool=*)
1280                 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1281                 return
1282                 ;;
1283         --*)
1284                 __gitcomp "--tool="
1285                 return
1286                 ;;
1287         esac
1288         COMPREPLY=()
1291 _git_merge_base ()
1293         __gitcomp "$(__git_refs)"
1296 _git_mv ()
1298         local cur="${COMP_WORDS[COMP_CWORD]}"
1299         case "$cur" in
1300         --*)
1301                 __gitcomp "--dry-run"
1302                 return
1303                 ;;
1304         esac
1305         COMPREPLY=()
1308 _git_name_rev ()
1310         __gitcomp "--tags --all --stdin"
1313 _git_pull ()
1315         __git_complete_strategy && return
1317         local cur="${COMP_WORDS[COMP_CWORD]}"
1318         case "$cur" in
1319         --*)
1320                 __gitcomp "
1321                         --rebase --no-rebase
1322                         $__git_merge_options
1323                         $__git_fetch_options
1324                 "
1325                 return
1326                 ;;
1327         esac
1328         __git_complete_remote_or_refspec
1331 _git_push ()
1333         local cur="${COMP_WORDS[COMP_CWORD]}"
1334         case "${COMP_WORDS[COMP_CWORD-1]}" in
1335         --repo)
1336                 __gitcomp "$(__git_remotes)"
1337                 return
1338         esac
1339         case "$cur" in
1340         --repo=*)
1341                 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1342                 return
1343                 ;;
1344         --*)
1345                 __gitcomp "
1346                         --all --mirror --tags --dry-run --force --verbose
1347                         --receive-pack= --repo=
1348                 "
1349                 return
1350                 ;;
1351         esac
1352         __git_complete_remote_or_refspec
1355 _git_rebase ()
1357         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1358         if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1359                 __gitcomp "--continue --skip --abort"
1360                 return
1361         fi
1362         __git_complete_strategy && return
1363         case "$cur" in
1364         --whitespace=*)
1365                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1366                 return
1367                 ;;
1368         --*)
1369                 __gitcomp "
1370                         --onto --merge --strategy --interactive
1371                         --preserve-merges --stat --no-stat
1372                         --committer-date-is-author-date --ignore-date
1373                         --ignore-whitespace --whitespace=
1374                         "
1376                 return
1377         esac
1378         __gitcomp "$(__git_refs)"
1381 __git_send_email_confirm_options="always never auto cc compose"
1382 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1384 _git_send_email ()
1386         local cur="${COMP_WORDS[COMP_CWORD]}"
1387         case "$cur" in
1388         --confirm=*)
1389                 __gitcomp "
1390                         $__git_send_email_confirm_options
1391                         " "" "${cur##--confirm=}"
1392                 return
1393                 ;;
1394         --suppress-cc=*)
1395                 __gitcomp "
1396                         $__git_send_email_suppresscc_options
1397                         " "" "${cur##--suppress-cc=}"
1399                 return
1400                 ;;
1401         --smtp-encryption=*)
1402                 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1403                 return
1404                 ;;
1405         --*)
1406                 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1407                         --compose --confirm= --dry-run --envelope-sender
1408                         --from --identity
1409                         --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1410                         --no-suppress-from --no-thread --quiet
1411                         --signed-off-by-cc --smtp-pass --smtp-server
1412                         --smtp-server-port --smtp-encryption= --smtp-user
1413                         --subject --suppress-cc= --suppress-from --thread --to
1414                         --validate --no-validate"
1415                 return
1416                 ;;
1417         esac
1418         COMPREPLY=()
1421 __git_config_get_set_variables ()
1423         local prevword word config_file= c=$COMP_CWORD
1424         while [ $c -gt 1 ]; do
1425                 word="${COMP_WORDS[c]}"
1426                 case "$word" in
1427                 --global|--system|--file=*)
1428                         config_file="$word"
1429                         break
1430                         ;;
1431                 -f|--file)
1432                         config_file="$word $prevword"
1433                         break
1434                         ;;
1435                 esac
1436                 prevword=$word
1437                 c=$((--c))
1438         done
1440         git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1441         while read line
1442         do
1443                 case "$line" in
1444                 *.*=*)
1445                         echo "${line/=*/}"
1446                         ;;
1447                 esac
1448         done
1451 _git_config ()
1453         local cur="${COMP_WORDS[COMP_CWORD]}"
1454         local prv="${COMP_WORDS[COMP_CWORD-1]}"
1455         case "$prv" in
1456         branch.*.remote)
1457                 __gitcomp "$(__git_remotes)"
1458                 return
1459                 ;;
1460         branch.*.merge)
1461                 __gitcomp "$(__git_refs)"
1462                 return
1463                 ;;
1464         remote.*.fetch)
1465                 local remote="${prv#remote.}"
1466                 remote="${remote%.fetch}"
1467                 __gitcomp "$(__git_refs_remotes "$remote")"
1468                 return
1469                 ;;
1470         remote.*.push)
1471                 local remote="${prv#remote.}"
1472                 remote="${remote%.push}"
1473                 __gitcomp "$(git --git-dir="$(__gitdir)" \
1474                         for-each-ref --format='%(refname):%(refname)' \
1475                         refs/heads)"
1476                 return
1477                 ;;
1478         pull.twohead|pull.octopus)
1479                 __git_compute_merge_strategies
1480                 __gitcomp "$__git_merge_strategies"
1481                 return
1482                 ;;
1483         color.branch|color.diff|color.interactive|\
1484         color.showbranch|color.status|color.ui)
1485                 __gitcomp "always never auto"
1486                 return
1487                 ;;
1488         color.pager)
1489                 __gitcomp "false true"
1490                 return
1491                 ;;
1492         color.*.*)
1493                 __gitcomp "
1494                         normal black red green yellow blue magenta cyan white
1495                         bold dim ul blink reverse
1496                         "
1497                 return
1498                 ;;
1499         help.format)
1500                 __gitcomp "man info web html"
1501                 return
1502                 ;;
1503         log.date)
1504                 __gitcomp "$__git_log_date_formats"
1505                 return
1506                 ;;
1507         sendemail.aliasesfiletype)
1508                 __gitcomp "mutt mailrc pine elm gnus"
1509                 return
1510                 ;;
1511         sendemail.confirm)
1512                 __gitcomp "$__git_send_email_confirm_options"
1513                 return
1514                 ;;
1515         sendemail.suppresscc)
1516                 __gitcomp "$__git_send_email_suppresscc_options"
1517                 return
1518                 ;;
1519         --get|--get-all|--unset|--unset-all)
1520                 __gitcomp "$(__git_config_get_set_variables)"
1521                 return
1522                 ;;
1523         *.*)
1524                 COMPREPLY=()
1525                 return
1526                 ;;
1527         esac
1528         case "$cur" in
1529         --*)
1530                 __gitcomp "
1531                         --global --system --file=
1532                         --list --replace-all
1533                         --get --get-all --get-regexp
1534                         --add --unset --unset-all
1535                         --remove-section --rename-section
1536                         "
1537                 return
1538                 ;;
1539         branch.*.*)
1540                 local pfx="${cur%.*}."
1541                 cur="${cur##*.}"
1542                 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1543                 return
1544                 ;;
1545         branch.*)
1546                 local pfx="${cur%.*}."
1547                 cur="${cur#*.}"
1548                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1549                 return
1550                 ;;
1551         guitool.*.*)
1552                 local pfx="${cur%.*}."
1553                 cur="${cur##*.}"
1554                 __gitcomp "
1555                         argprompt cmd confirm needsfile noconsole norescan
1556                         prompt revprompt revunmerged title
1557                         " "$pfx" "$cur"
1558                 return
1559                 ;;
1560         difftool.*.*)
1561                 local pfx="${cur%.*}."
1562                 cur="${cur##*.}"
1563                 __gitcomp "cmd path" "$pfx" "$cur"
1564                 return
1565                 ;;
1566         man.*.*)
1567                 local pfx="${cur%.*}."
1568                 cur="${cur##*.}"
1569                 __gitcomp "cmd path" "$pfx" "$cur"
1570                 return
1571                 ;;
1572         mergetool.*.*)
1573                 local pfx="${cur%.*}."
1574                 cur="${cur##*.}"
1575                 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1576                 return
1577                 ;;
1578         pager.*)
1579                 local pfx="${cur%.*}."
1580                 cur="${cur#*.}"
1581                 __git_compute_all_commands
1582                 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1583                 return
1584                 ;;
1585         remote.*.*)
1586                 local pfx="${cur%.*}."
1587                 cur="${cur##*.}"
1588                 __gitcomp "
1589                         url proxy fetch push mirror skipDefaultUpdate
1590                         receivepack uploadpack tagopt pushurl
1591                         " "$pfx" "$cur"
1592                 return
1593                 ;;
1594         remote.*)
1595                 local pfx="${cur%.*}."
1596                 cur="${cur#*.}"
1597                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1598                 return
1599                 ;;
1600         url.*.*)
1601                 local pfx="${cur%.*}."
1602                 cur="${cur##*.}"
1603                 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1604                 return
1605                 ;;
1606         esac
1607         __gitcomp "
1608                 add.ignore-errors
1609                 alias.
1610                 apply.ignorewhitespace
1611                 apply.whitespace
1612                 branch.autosetupmerge
1613                 branch.autosetuprebase
1614                 clean.requireForce
1615                 color.branch
1616                 color.branch.current
1617                 color.branch.local
1618                 color.branch.plain
1619                 color.branch.remote
1620                 color.diff
1621                 color.diff.commit
1622                 color.diff.frag
1623                 color.diff.meta
1624                 color.diff.new
1625                 color.diff.old
1626                 color.diff.plain
1627                 color.diff.whitespace
1628                 color.grep
1629                 color.grep.external
1630                 color.grep.match
1631                 color.interactive
1632                 color.interactive.header
1633                 color.interactive.help
1634                 color.interactive.prompt
1635                 color.pager
1636                 color.showbranch
1637                 color.status
1638                 color.status.added
1639                 color.status.changed
1640                 color.status.header
1641                 color.status.nobranch
1642                 color.status.untracked
1643                 color.status.updated
1644                 color.ui
1645                 commit.template
1646                 core.autocrlf
1647                 core.bare
1648                 core.compression
1649                 core.createObject
1650                 core.deltaBaseCacheLimit
1651                 core.editor
1652                 core.excludesfile
1653                 core.fileMode
1654                 core.fsyncobjectfiles
1655                 core.gitProxy
1656                 core.ignoreCygwinFSTricks
1657                 core.ignoreStat
1658                 core.logAllRefUpdates
1659                 core.loosecompression
1660                 core.packedGitLimit
1661                 core.packedGitWindowSize
1662                 core.pager
1663                 core.preferSymlinkRefs
1664                 core.preloadindex
1665                 core.quotepath
1666                 core.repositoryFormatVersion
1667                 core.safecrlf
1668                 core.sharedRepository
1669                 core.symlinks
1670                 core.trustctime
1671                 core.warnAmbiguousRefs
1672                 core.whitespace
1673                 core.worktree
1674                 diff.autorefreshindex
1675                 diff.external
1676                 diff.mnemonicprefix
1677                 diff.renameLimit
1678                 diff.renameLimit.
1679                 diff.renames
1680                 diff.suppressBlankEmpty
1681                 diff.tool
1682                 diff.wordRegex
1683                 difftool.
1684                 difftool.prompt
1685                 fetch.unpackLimit
1686                 format.attach
1687                 format.cc
1688                 format.headers
1689                 format.numbered
1690                 format.pretty
1691                 format.signoff
1692                 format.subjectprefix
1693                 format.suffix
1694                 format.thread
1695                 gc.aggressiveWindow
1696                 gc.auto
1697                 gc.autopacklimit
1698                 gc.packrefs
1699                 gc.pruneexpire
1700                 gc.reflogexpire
1701                 gc.reflogexpireunreachable
1702                 gc.rerereresolved
1703                 gc.rerereunresolved
1704                 gitcvs.allbinary
1705                 gitcvs.commitmsgannotation
1706                 gitcvs.dbTableNamePrefix
1707                 gitcvs.dbdriver
1708                 gitcvs.dbname
1709                 gitcvs.dbpass
1710                 gitcvs.dbuser
1711                 gitcvs.enabled
1712                 gitcvs.logfile
1713                 gitcvs.usecrlfattr
1714                 guitool.
1715                 gui.blamehistoryctx
1716                 gui.commitmsgwidth
1717                 gui.copyblamethreshold
1718                 gui.diffcontext
1719                 gui.encoding
1720                 gui.fastcopyblame
1721                 gui.matchtrackingbranch
1722                 gui.newbranchtemplate
1723                 gui.pruneduringfetch
1724                 gui.spellingdictionary
1725                 gui.trustmtime
1726                 help.autocorrect
1727                 help.browser
1728                 help.format
1729                 http.lowSpeedLimit
1730                 http.lowSpeedTime
1731                 http.maxRequests
1732                 http.noEPSV
1733                 http.proxy
1734                 http.sslCAInfo
1735                 http.sslCAPath
1736                 http.sslCert
1737                 http.sslKey
1738                 http.sslVerify
1739                 i18n.commitEncoding
1740                 i18n.logOutputEncoding
1741                 imap.folder
1742                 imap.host
1743                 imap.pass
1744                 imap.port
1745                 imap.preformattedHTML
1746                 imap.sslverify
1747                 imap.tunnel
1748                 imap.user
1749                 instaweb.browser
1750                 instaweb.httpd
1751                 instaweb.local
1752                 instaweb.modulepath
1753                 instaweb.port
1754                 interactive.singlekey
1755                 log.date
1756                 log.showroot
1757                 mailmap.file
1758                 man.
1759                 man.viewer
1760                 merge.conflictstyle
1761                 merge.log
1762                 merge.renameLimit
1763                 merge.stat
1764                 merge.tool
1765                 merge.verbosity
1766                 mergetool.
1767                 mergetool.keepBackup
1768                 mergetool.prompt
1769                 pack.compression
1770                 pack.deltaCacheLimit
1771                 pack.deltaCacheSize
1772                 pack.depth
1773                 pack.indexVersion
1774                 pack.packSizeLimit
1775                 pack.threads
1776                 pack.window
1777                 pack.windowMemory
1778                 pager.
1779                 pull.octopus
1780                 pull.twohead
1781                 push.default
1782                 rebase.stat
1783                 receive.denyCurrentBranch
1784                 receive.denyDeletes
1785                 receive.denyNonFastForwards
1786                 receive.fsckObjects
1787                 receive.unpackLimit
1788                 repack.usedeltabaseoffset
1789                 rerere.autoupdate
1790                 rerere.enabled
1791                 sendemail.aliasesfile
1792                 sendemail.aliasesfiletype
1793                 sendemail.bcc
1794                 sendemail.cc
1795                 sendemail.cccmd
1796                 sendemail.chainreplyto
1797                 sendemail.confirm
1798                 sendemail.envelopesender
1799                 sendemail.multiedit
1800                 sendemail.signedoffbycc
1801                 sendemail.smtpencryption
1802                 sendemail.smtppass
1803                 sendemail.smtpserver
1804                 sendemail.smtpserverport
1805                 sendemail.smtpuser
1806                 sendemail.suppresscc
1807                 sendemail.suppressfrom
1808                 sendemail.thread
1809                 sendemail.to
1810                 sendemail.validate
1811                 showbranch.default
1812                 status.relativePaths
1813                 status.showUntrackedFiles
1814                 tar.umask
1815                 transfer.unpackLimit
1816                 url.
1817                 user.email
1818                 user.name
1819                 user.signingkey
1820                 web.browser
1821                 branch. remote.
1822         "
1825 _git_remote ()
1827         local subcommands="add rename rm show prune update set-head"
1828         local subcommand="$(__git_find_on_cmdline "$subcommands")"
1829         if [ -z "$subcommand" ]; then
1830                 __gitcomp "$subcommands"
1831                 return
1832         fi
1834         case "$subcommand" in
1835         rename|rm|show|prune)
1836                 __gitcomp "$(__git_remotes)"
1837                 ;;
1838         update)
1839                 local i c='' IFS=$'\n'
1840                 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1841                         i="${i#remotes.}"
1842                         c="$c ${i/ */}"
1843                 done
1844                 __gitcomp "$c"
1845                 ;;
1846         *)
1847                 COMPREPLY=()
1848                 ;;
1849         esac
1852 _git_replace ()
1854         __gitcomp "$(__git_refs)"
1857 _git_reset ()
1859         __git_has_doubledash && return
1861         local cur="${COMP_WORDS[COMP_CWORD]}"
1862         case "$cur" in
1863         --*)
1864                 __gitcomp "--merge --mixed --hard --soft --patch"
1865                 return
1866                 ;;
1867         esac
1868         __gitcomp "$(__git_refs)"
1871 _git_revert ()
1873         local cur="${COMP_WORDS[COMP_CWORD]}"
1874         case "$cur" in
1875         --*)
1876                 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1877                 return
1878                 ;;
1879         esac
1880         __gitcomp "$(__git_refs)"
1883 _git_rm ()
1885         __git_has_doubledash && return
1887         local cur="${COMP_WORDS[COMP_CWORD]}"
1888         case "$cur" in
1889         --*)
1890                 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1891                 return
1892                 ;;
1893         esac
1894         COMPREPLY=()
1897 _git_shortlog ()
1899         __git_has_doubledash && return
1901         local cur="${COMP_WORDS[COMP_CWORD]}"
1902         case "$cur" in
1903         --*)
1904                 __gitcomp "
1905                         $__git_log_common_options
1906                         $__git_log_shortlog_options
1907                         --numbered --summary
1908                         "
1909                 return
1910                 ;;
1911         esac
1912         __git_complete_revlist
1915 _git_show ()
1917         __git_has_doubledash && return
1919         local cur="${COMP_WORDS[COMP_CWORD]}"
1920         case "$cur" in
1921         --pretty=*)
1922                 __gitcomp "$__git_log_pretty_formats
1923                         " "" "${cur##--pretty=}"
1924                 return
1925                 ;;
1926         --format=*)
1927                 __gitcomp "$__git_log_pretty_formats
1928                         " "" "${cur##--format=}"
1929                 return
1930                 ;;
1931         --*)
1932                 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1933                         $__git_diff_common_options
1934                         "
1935                 return
1936                 ;;
1937         esac
1938         __git_complete_file
1941 _git_show_branch ()
1943         local cur="${COMP_WORDS[COMP_CWORD]}"
1944         case "$cur" in
1945         --*)
1946                 __gitcomp "
1947                         --all --remotes --topo-order --current --more=
1948                         --list --independent --merge-base --no-name
1949                         --color --no-color
1950                         --sha1-name --sparse --topics --reflog
1951                         "
1952                 return
1953                 ;;
1954         esac
1955         __git_complete_revlist
1958 _git_stash ()
1960         local cur="${COMP_WORDS[COMP_CWORD]}"
1961         local save_opts='--keep-index --no-keep-index --quiet --patch'
1962         local subcommands='save list show apply clear drop pop create branch'
1963         local subcommand="$(__git_find_on_cmdline "$subcommands")"
1964         if [ -z "$subcommand" ]; then
1965                 case "$cur" in
1966                 --*)
1967                         __gitcomp "$save_opts"
1968                         ;;
1969                 *)
1970                         if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1971                                 __gitcomp "$subcommands"
1972                         else
1973                                 COMPREPLY=()
1974                         fi
1975                         ;;
1976                 esac
1977         else
1978                 case "$subcommand,$cur" in
1979                 save,--*)
1980                         __gitcomp "$save_opts"
1981                         ;;
1982                 apply,--*|pop,--*)
1983                         __gitcomp "--index --quiet"
1984                         ;;
1985                 show,--*|drop,--*|branch,--*)
1986                         COMPREPLY=()
1987                         ;;
1988                 show,*|apply,*|drop,*|pop,*|branch,*)
1989                         __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1990                                         | sed -n -e 's/:.*//p')"
1991                         ;;
1992                 *)
1993                         COMPREPLY=()
1994                         ;;
1995                 esac
1996         fi
1999 _git_submodule ()
2001         __git_has_doubledash && return
2003         local subcommands="add status init update summary foreach sync"
2004         if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2005                 local cur="${COMP_WORDS[COMP_CWORD]}"
2006                 case "$cur" in
2007                 --*)
2008                         __gitcomp "--quiet --cached"
2009                         ;;
2010                 *)
2011                         __gitcomp "$subcommands"
2012                         ;;
2013                 esac
2014                 return
2015         fi
2018 _git_svn ()
2020         local subcommands="
2021                 init fetch clone rebase dcommit log find-rev
2022                 set-tree commit-diff info create-ignore propget
2023                 proplist show-ignore show-externals branch tag blame
2024                 migrate
2025                 "
2026         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2027         if [ -z "$subcommand" ]; then
2028                 __gitcomp "$subcommands"
2029         else
2030                 local remote_opts="--username= --config-dir= --no-auth-cache"
2031                 local fc_opts="
2032                         --follow-parent --authors-file= --repack=
2033                         --no-metadata --use-svm-props --use-svnsync-props
2034                         --log-window-size= --no-checkout --quiet
2035                         --repack-flags --use-log-author --localtime
2036                         --ignore-paths= $remote_opts
2037                         "
2038                 local init_opts="
2039                         --template= --shared= --trunk= --tags=
2040                         --branches= --stdlayout --minimize-url
2041                         --no-metadata --use-svm-props --use-svnsync-props
2042                         --rewrite-root= --prefix= --use-log-author
2043                         --add-author-from $remote_opts
2044                         "
2045                 local cmt_opts="
2046                         --edit --rmdir --find-copies-harder --copy-similarity=
2047                         "
2049                 local cur="${COMP_WORDS[COMP_CWORD]}"
2050                 case "$subcommand,$cur" in
2051                 fetch,--*)
2052                         __gitcomp "--revision= --fetch-all $fc_opts"
2053                         ;;
2054                 clone,--*)
2055                         __gitcomp "--revision= $fc_opts $init_opts"
2056                         ;;
2057                 init,--*)
2058                         __gitcomp "$init_opts"
2059                         ;;
2060                 dcommit,--*)
2061                         __gitcomp "
2062                                 --merge --strategy= --verbose --dry-run
2063                                 --fetch-all --no-rebase --commit-url
2064                                 --revision $cmt_opts $fc_opts
2065                                 "
2066                         ;;
2067                 set-tree,--*)
2068                         __gitcomp "--stdin $cmt_opts $fc_opts"
2069                         ;;
2070                 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2071                 show-externals,--*)
2072                         __gitcomp "--revision="
2073                         ;;
2074                 log,--*)
2075                         __gitcomp "
2076                                 --limit= --revision= --verbose --incremental
2077                                 --oneline --show-commit --non-recursive
2078                                 --authors-file= --color
2079                                 "
2080                         ;;
2081                 rebase,--*)
2082                         __gitcomp "
2083                                 --merge --verbose --strategy= --local
2084                                 --fetch-all --dry-run $fc_opts
2085                                 "
2086                         ;;
2087                 commit-diff,--*)
2088                         __gitcomp "--message= --file= --revision= $cmt_opts"
2089                         ;;
2090                 info,--*)
2091                         __gitcomp "--url"
2092                         ;;
2093                 branch,--*)
2094                         __gitcomp "--dry-run --message --tag"
2095                         ;;
2096                 tag,--*)
2097                         __gitcomp "--dry-run --message"
2098                         ;;
2099                 blame,--*)
2100                         __gitcomp "--git-format"
2101                         ;;
2102                 migrate,--*)
2103                         __gitcomp "
2104                                 --config-dir= --ignore-paths= --minimize
2105                                 --no-auth-cache --username=
2106                                 "
2107                         ;;
2108                 *)
2109                         COMPREPLY=()
2110                         ;;
2111                 esac
2112         fi
2115 _git_tag ()
2117         local i c=1 f=0
2118         while [ $c -lt $COMP_CWORD ]; do
2119                 i="${COMP_WORDS[c]}"
2120                 case "$i" in
2121                 -d|-v)
2122                         __gitcomp "$(__git_tags)"
2123                         return
2124                         ;;
2125                 -f)
2126                         f=1
2127                         ;;
2128                 esac
2129                 c=$((++c))
2130         done
2132         case "${COMP_WORDS[COMP_CWORD-1]}" in
2133         -m|-F)
2134                 COMPREPLY=()
2135                 ;;
2136         -*|tag)
2137                 if [ $f = 1 ]; then
2138                         __gitcomp "$(__git_tags)"
2139                 else
2140                         COMPREPLY=()
2141                 fi
2142                 ;;
2143         *)
2144                 __gitcomp "$(__git_refs)"
2145                 ;;
2146         esac
2149 _git ()
2151         local i c=1 command __git_dir
2153         while [ $c -lt $COMP_CWORD ]; do
2154                 i="${COMP_WORDS[c]}"
2155                 case "$i" in
2156                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2157                 --bare)      __git_dir="." ;;
2158                 --version|-p|--paginate) ;;
2159                 --help) command="help"; break ;;
2160                 *) command="$i"; break ;;
2161                 esac
2162                 c=$((++c))
2163         done
2165         if [ -z "$command" ]; then
2166                 case "${COMP_WORDS[COMP_CWORD]}" in
2167                 --*)   __gitcomp "
2168                         --paginate
2169                         --no-pager
2170                         --git-dir=
2171                         --bare
2172                         --version
2173                         --exec-path
2174                         --html-path
2175                         --work-tree=
2176                         --help
2177                         "
2178                         ;;
2179                 *)     __git_compute_porcelain_commands
2180                        __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2181                 esac
2182                 return
2183         fi
2185         local expansion=$(__git_aliased_command "$command")
2186         [ "$expansion" ] && command="$expansion"
2188         case "$command" in
2189         am)          _git_am ;;
2190         add)         _git_add ;;
2191         apply)       _git_apply ;;
2192         archive)     _git_archive ;;
2193         bisect)      _git_bisect ;;
2194         bundle)      _git_bundle ;;
2195         branch)      _git_branch ;;
2196         checkout)    _git_checkout ;;
2197         cherry)      _git_cherry ;;
2198         cherry-pick) _git_cherry_pick ;;
2199         clean)       _git_clean ;;
2200         clone)       _git_clone ;;
2201         commit)      _git_commit ;;
2202         config)      _git_config ;;
2203         describe)    _git_describe ;;
2204         diff)        _git_diff ;;
2205         difftool)    _git_difftool ;;
2206         fetch)       _git_fetch ;;
2207         format-patch) _git_format_patch ;;
2208         fsck)        _git_fsck ;;
2209         gc)          _git_gc ;;
2210         grep)        _git_grep ;;
2211         help)        _git_help ;;
2212         init)        _git_init ;;
2213         log)         _git_log ;;
2214         ls-files)    _git_ls_files ;;
2215         ls-remote)   _git_ls_remote ;;
2216         ls-tree)     _git_ls_tree ;;
2217         merge)       _git_merge;;
2218         mergetool)   _git_mergetool;;
2219         merge-base)  _git_merge_base ;;
2220         mv)          _git_mv ;;
2221         name-rev)    _git_name_rev ;;
2222         pull)        _git_pull ;;
2223         push)        _git_push ;;
2224         rebase)      _git_rebase ;;
2225         remote)      _git_remote ;;
2226         replace)     _git_replace ;;
2227         reset)       _git_reset ;;
2228         revert)      _git_revert ;;
2229         rm)          _git_rm ;;
2230         send-email)  _git_send_email ;;
2231         shortlog)    _git_shortlog ;;
2232         show)        _git_show ;;
2233         show-branch) _git_show_branch ;;
2234         stash)       _git_stash ;;
2235         stage)       _git_add ;;
2236         submodule)   _git_submodule ;;
2237         svn)         _git_svn ;;
2238         tag)         _git_tag ;;
2239         whatchanged) _git_log ;;
2240         *)           COMPREPLY=() ;;
2241         esac
2244 _gitk ()
2246         __git_has_doubledash && return
2248         local cur="${COMP_WORDS[COMP_CWORD]}"
2249         local g="$(__gitdir)"
2250         local merge=""
2251         if [ -f "$g/MERGE_HEAD" ]; then
2252                 merge="--merge"
2253         fi
2254         case "$cur" in
2255         --*)
2256                 __gitcomp "
2257                         $__git_log_common_options
2258                         $__git_log_gitk_options
2259                         $merge
2260                         "
2261                 return
2262                 ;;
2263         esac
2264         __git_complete_revlist
2267 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2268         || complete -o default -o nospace -F _git git
2269 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2270         || complete -o default -o nospace -F _gitk gitk
2272 # The following are necessary only for Cygwin, and only are needed
2273 # when the user has tab-completed the executable name and consequently
2274 # included the '.exe' suffix.
2276 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2277 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2278         || complete -o default -o nospace -F _git git.exe
2279 fi