Code

bash completion: complete variable names for "git config" with options
[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) You may want to make sure the git executable is available
25 #       in your PATH before this script is sourced, as some caching
26 #       is performed while the script loads.  If git isn't found
27 #       at source time then all lookups will be done on demand,
28 #       which may be slightly slower.
29 #
30 #    4) Consider changing your PS1 to also show the current branch:
31 #        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
32 #
33 #       The argument to __git_ps1 will be displayed only if you
34 #       are currently in a git repository.  The %s token will be
35 #       the name of the current branch.
36 #
37 #       In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
38 #       value, unstaged (*) and staged (+) changes will be shown next
39 #       to the branch name.  You can configure this per-repository
40 #       with the bash.showDirtyState variable, which defaults to true
41 #       once GIT_PS1_SHOWDIRTYSTATE is enabled.
42 #
43 # To submit patches:
44 #
45 #    *) Read Documentation/SubmittingPatches
46 #    *) Send all patches to the current maintainer:
47 #
48 #       "Shawn O. Pearce" <spearce@spearce.org>
49 #
50 #    *) Always CC the Git mailing list:
51 #
52 #       git@vger.kernel.org
53 #
55 case "$COMP_WORDBREAKS" in
56 *:*) : great ;;
57 *)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
58 esac
60 # __gitdir accepts 0 or 1 arguments (i.e., location)
61 # returns location of .git repo
62 __gitdir ()
63 {
64         if [ -z "${1-}" ]; then
65                 if [ -n "${__git_dir-}" ]; then
66                         echo "$__git_dir"
67                 elif [ -d .git ]; then
68                         echo .git
69                 else
70                         git rev-parse --git-dir 2>/dev/null
71                 fi
72         elif [ -d "$1/.git" ]; then
73                 echo "$1/.git"
74         else
75                 echo "$1"
76         fi
77 }
79 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
80 # returns text to add to bash PS1 prompt (includes branch name)
81 __git_ps1 ()
82 {
83         local g="$(__gitdir)"
84         if [ -n "$g" ]; then
85                 local r
86                 local b
87                 if [ -d "$g/rebase-apply" ]; then
88                         if [ -f "$g/rebase-apply/rebasing" ]; then
89                                 r="|REBASE"
90                 elif [ -f "$g/rebase-apply/applying" ]; then
91                                 r="|AM"
92                         else
93                                 r="|AM/REBASE"
94                         fi
95                         b="$(git symbolic-ref HEAD 2>/dev/null)"
96                 elif [ -f "$g/rebase-merge/interactive" ]; then
97                         r="|REBASE-i"
98                         b="$(cat "$g/rebase-merge/head-name")"
99                 elif [ -d "$g/rebase-merge" ]; then
100                         r="|REBASE-m"
101                         b="$(cat "$g/rebase-merge/head-name")"
102                 elif [ -f "$g/MERGE_HEAD" ]; then
103                         r="|MERGING"
104                         b="$(git symbolic-ref HEAD 2>/dev/null)"
105                 else
106                         if [ -f "$g/BISECT_LOG" ]; then
107                                 r="|BISECTING"
108                         fi
109                         if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
110                                 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
111                                         if [ -r "$g/HEAD" ]; then
112                                                 b="$(cut -c1-7 "$g/HEAD")..."
113                                         fi
114                                 fi
115                         fi
116                 fi
118                 local w
119                 local i
120                 local c
122                 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
123                         if [ "true" = "$(git config --bool core.bare 2>/dev/null)" ]; then
124                                 c="BARE:"
125                         else
126                                 b="GIT_DIR!"
127                         fi
128                 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
129                         if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
130                                 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
131                                         git diff --no-ext-diff --ignore-submodules \
132                                                 --quiet --exit-code || w="*"
133                                         if git rev-parse --quiet --verify HEAD >/dev/null; then
134                                                 git diff-index --cached --quiet \
135                                                         --ignore-submodules HEAD -- || i="+"
136                                         else
137                                                 i="#"
138                                         fi
139                                 fi
140                         fi
141                 fi
143                 if [ -n "$b" ]; then
144                         if [ -n "${1-}" ]; then
145                                 printf "$1" "$c${b##refs/heads/}$w$i$r"
146                         else
147                                 printf " (%s)" "$c${b##refs/heads/}$w$i$r"
148                         fi
149                 fi
150         fi
153 # __gitcomp_1 requires 2 arguments
154 __gitcomp_1 ()
156         local c IFS=' '$'\t'$'\n'
157         for c in $1; do
158                 case "$c$2" in
159                 --*=*) printf %s$'\n' "$c$2" ;;
160                 *.)    printf %s$'\n' "$c$2" ;;
161                 *)     printf %s$'\n' "$c$2 " ;;
162                 esac
163         done
166 # __gitcomp accepts 1, 2, 3, or 4 arguments
167 # generates completion reply with compgen
168 __gitcomp ()
170         local cur="${COMP_WORDS[COMP_CWORD]}"
171         if [ $# -gt 2 ]; then
172                 cur="$3"
173         fi
174         case "$cur" in
175         --*=)
176                 COMPREPLY=()
177                 ;;
178         *)
179                 local IFS=$'\n'
180                 COMPREPLY=($(compgen -P "${2-}" \
181                         -W "$(__gitcomp_1 "${1-}" "${4-}")" \
182                         -- "$cur"))
183                 ;;
184         esac
187 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
188 __git_heads ()
190         local cmd i is_hash=y dir="$(__gitdir "${1-}")"
191         if [ -d "$dir" ]; then
192                 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
193                         refs/heads
194                 return
195         fi
196         for i in $(git ls-remote "${1-}" 2>/dev/null); do
197                 case "$is_hash,$i" in
198                 y,*) is_hash=n ;;
199                 n,*^{}) is_hash=y ;;
200                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
201                 n,*) is_hash=y; echo "$i" ;;
202                 esac
203         done
206 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
207 __git_tags ()
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/tags
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/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
220                 n,*) is_hash=y; echo "$i" ;;
221                 esac
222         done
225 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
226 __git_refs ()
228         local i is_hash=y dir="$(__gitdir "${1-}")"
229         local cur="${COMP_WORDS[COMP_CWORD]}" format refs
230         if [ -d "$dir" ]; then
231                 case "$cur" in
232                 refs|refs/*)
233                         format="refname"
234                         refs="${cur%/*}"
235                         ;;
236                 *)
237                         if [ -e "$dir/HEAD" ]; then echo HEAD; fi
238                         format="refname:short"
239                         refs="refs/tags refs/heads refs/remotes"
240                         ;;
241                 esac
242                 git --git-dir="$dir" for-each-ref --format="%($format)" \
243                         $refs
244                 return
245         fi
246         for i in $(git ls-remote "$dir" 2>/dev/null); do
247                 case "$is_hash,$i" in
248                 y,*) is_hash=n ;;
249                 n,*^{}) is_hash=y ;;
250                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
251                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
252                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
253                 n,*) is_hash=y; echo "$i" ;;
254                 esac
255         done
258 # __git_refs2 requires 1 argument (to pass to __git_refs)
259 __git_refs2 ()
261         local i
262         for i in $(__git_refs "$1"); do
263                 echo "$i:$i"
264         done
267 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
268 __git_refs_remotes ()
270         local cmd i is_hash=y
271         for i in $(git ls-remote "$1" 2>/dev/null); do
272                 case "$is_hash,$i" in
273                 n,refs/heads/*)
274                         is_hash=y
275                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
276                         ;;
277                 y,*) is_hash=n ;;
278                 n,*^{}) is_hash=y ;;
279                 n,refs/tags/*) is_hash=y;;
280                 n,*) is_hash=y; ;;
281                 esac
282         done
285 __git_remotes ()
287         local i ngoff IFS=$'\n' d="$(__gitdir)"
288         shopt -q nullglob || ngoff=1
289         shopt -s nullglob
290         for i in "$d/remotes"/*; do
291                 echo ${i#$d/remotes/}
292         done
293         [ "$ngoff" ] && shopt -u nullglob
294         for i in $(git --git-dir="$d" config --list); do
295                 case "$i" in
296                 remote.*.url=*)
297                         i="${i#remote.}"
298                         echo "${i/.url=*/}"
299                         ;;
300                 esac
301         done
304 __git_merge_strategies ()
306         if [ -n "${__git_merge_strategylist-}" ]; then
307                 echo "$__git_merge_strategylist"
308                 return
309         fi
310         git merge -s help 2>&1 |
311         sed -n -e '/[Aa]vailable strategies are: /,/^$/{
312                 s/\.$//
313                 s/.*://
314                 s/^[    ]*//
315                 s/[     ]*$//
316                 p
317         }'
319 __git_merge_strategylist=
320 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
322 __git_complete_file ()
324         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
325         case "$cur" in
326         ?*:*)
327                 ref="${cur%%:*}"
328                 cur="${cur#*:}"
329                 case "$cur" in
330                 ?*/*)
331                         pfx="${cur%/*}"
332                         cur="${cur##*/}"
333                         ls="$ref:$pfx"
334                         pfx="$pfx/"
335                         ;;
336                 *)
337                         ls="$ref"
338                         ;;
339             esac
341                 case "$COMP_WORDBREAKS" in
342                 *:*) : great ;;
343                 *)   pfx="$ref:$pfx" ;;
344                 esac
346                 local IFS=$'\n'
347                 COMPREPLY=($(compgen -P "$pfx" \
348                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
349                                 | sed '/^100... blob /{
350                                            s,^.*        ,,
351                                            s,$, ,
352                                        }
353                                        /^120000 blob /{
354                                            s,^.*        ,,
355                                            s,$, ,
356                                        }
357                                        /^040000 tree /{
358                                            s,^.*        ,,
359                                            s,$,/,
360                                        }
361                                        s/^.*    //')" \
362                         -- "$cur"))
363                 ;;
364         *)
365                 __gitcomp "$(__git_refs)"
366                 ;;
367         esac
370 __git_complete_revlist ()
372         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
373         case "$cur" in
374         *...*)
375                 pfx="${cur%...*}..."
376                 cur="${cur#*...}"
377                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
378                 ;;
379         *..*)
380                 pfx="${cur%..*}.."
381                 cur="${cur#*..}"
382                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
383                 ;;
384         *)
385                 __gitcomp "$(__git_refs)"
386                 ;;
387         esac
390 __git_complete_remote_or_refspec ()
392         local cmd="${COMP_WORDS[1]}"
393         local cur="${COMP_WORDS[COMP_CWORD]}"
394         local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
395         while [ $c -lt $COMP_CWORD ]; do
396                 i="${COMP_WORDS[c]}"
397                 case "$i" in
398                 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
399                 -*) ;;
400                 *) remote="$i"; break ;;
401                 esac
402                 c=$((++c))
403         done
404         if [ -z "$remote" ]; then
405                 __gitcomp "$(__git_remotes)"
406                 return
407         fi
408         if [ $no_complete_refspec = 1 ]; then
409                 COMPREPLY=()
410                 return
411         fi
412         [ "$remote" = "." ] && remote=
413         case "$cur" in
414         *:*)
415                 case "$COMP_WORDBREAKS" in
416                 *:*) : great ;;
417                 *)   pfx="${cur%%:*}:" ;;
418                 esac
419                 cur="${cur#*:}"
420                 lhs=0
421                 ;;
422         +*)
423                 pfx="+"
424                 cur="${cur#+}"
425                 ;;
426         esac
427         case "$cmd" in
428         fetch)
429                 if [ $lhs = 1 ]; then
430                         __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
431                 else
432                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
433                 fi
434                 ;;
435         pull)
436                 if [ $lhs = 1 ]; then
437                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
438                 else
439                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
440                 fi
441                 ;;
442         push)
443                 if [ $lhs = 1 ]; then
444                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
445                 else
446                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
447                 fi
448                 ;;
449         esac
452 __git_complete_strategy ()
454         case "${COMP_WORDS[COMP_CWORD-1]}" in
455         -s|--strategy)
456                 __gitcomp "$(__git_merge_strategies)"
457                 return 0
458         esac
459         local cur="${COMP_WORDS[COMP_CWORD]}"
460         case "$cur" in
461         --strategy=*)
462                 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
463                 return 0
464                 ;;
465         esac
466         return 1
469 __git_all_commands ()
471         if [ -n "${__git_all_commandlist-}" ]; then
472                 echo "$__git_all_commandlist"
473                 return
474         fi
475         local i IFS=" "$'\n'
476         for i in $(git help -a|egrep '^ ')
477         do
478                 case $i in
479                 *--*)             : helper pattern;;
480                 *) echo $i;;
481                 esac
482         done
484 __git_all_commandlist=
485 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
487 __git_porcelain_commands ()
489         if [ -n "${__git_porcelain_commandlist-}" ]; then
490                 echo "$__git_porcelain_commandlist"
491                 return
492         fi
493         local i IFS=" "$'\n'
494         for i in "help" $(__git_all_commands)
495         do
496                 case $i in
497                 *--*)             : helper pattern;;
498                 applymbox)        : ask gittus;;
499                 applypatch)       : ask gittus;;
500                 archimport)       : import;;
501                 cat-file)         : plumbing;;
502                 check-attr)       : plumbing;;
503                 check-ref-format) : plumbing;;
504                 checkout-index)   : plumbing;;
505                 commit-tree)      : plumbing;;
506                 count-objects)    : infrequent;;
507                 cvsexportcommit)  : export;;
508                 cvsimport)        : import;;
509                 cvsserver)        : daemon;;
510                 daemon)           : daemon;;
511                 diff-files)       : plumbing;;
512                 diff-index)       : plumbing;;
513                 diff-tree)        : plumbing;;
514                 fast-import)      : import;;
515                 fast-export)      : export;;
516                 fsck-objects)     : plumbing;;
517                 fetch-pack)       : plumbing;;
518                 fmt-merge-msg)    : plumbing;;
519                 for-each-ref)     : plumbing;;
520                 hash-object)      : plumbing;;
521                 http-*)           : transport;;
522                 index-pack)       : plumbing;;
523                 init-db)          : deprecated;;
524                 local-fetch)      : plumbing;;
525                 lost-found)       : infrequent;;
526                 ls-files)         : plumbing;;
527                 ls-remote)        : plumbing;;
528                 ls-tree)          : plumbing;;
529                 mailinfo)         : plumbing;;
530                 mailsplit)        : plumbing;;
531                 merge-*)          : plumbing;;
532                 mktree)           : plumbing;;
533                 mktag)            : plumbing;;
534                 pack-objects)     : plumbing;;
535                 pack-redundant)   : plumbing;;
536                 pack-refs)        : plumbing;;
537                 parse-remote)     : plumbing;;
538                 patch-id)         : plumbing;;
539                 peek-remote)      : plumbing;;
540                 prune)            : plumbing;;
541                 prune-packed)     : plumbing;;
542                 quiltimport)      : import;;
543                 read-tree)        : plumbing;;
544                 receive-pack)     : plumbing;;
545                 reflog)           : plumbing;;
546                 repo-config)      : deprecated;;
547                 rerere)           : plumbing;;
548                 rev-list)         : plumbing;;
549                 rev-parse)        : plumbing;;
550                 runstatus)        : plumbing;;
551                 sh-setup)         : internal;;
552                 shell)            : daemon;;
553                 show-ref)         : plumbing;;
554                 send-pack)        : plumbing;;
555                 show-index)       : plumbing;;
556                 ssh-*)            : transport;;
557                 stripspace)       : plumbing;;
558                 symbolic-ref)     : plumbing;;
559                 tar-tree)         : deprecated;;
560                 unpack-file)      : plumbing;;
561                 unpack-objects)   : plumbing;;
562                 update-index)     : plumbing;;
563                 update-ref)       : plumbing;;
564                 update-server-info) : daemon;;
565                 upload-archive)   : plumbing;;
566                 upload-pack)      : plumbing;;
567                 write-tree)       : plumbing;;
568                 var)              : infrequent;;
569                 verify-pack)      : infrequent;;
570                 verify-tag)       : plumbing;;
571                 *) echo $i;;
572                 esac
573         done
575 __git_porcelain_commandlist=
576 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
578 __git_aliases ()
580         local i IFS=$'\n'
581         for i in $(git --git-dir="$(__gitdir)" config --list); do
582                 case "$i" in
583                 alias.*)
584                         i="${i#alias.}"
585                         echo "${i/=*/}"
586                         ;;
587                 esac
588         done
591 # __git_aliased_command requires 1 argument
592 __git_aliased_command ()
594         local word cmdline=$(git --git-dir="$(__gitdir)" \
595                 config --get "alias.$1")
596         for word in $cmdline; do
597                 if [ "${word##-*}" ]; then
598                         echo $word
599                         return
600                 fi
601         done
604 # __git_find_subcommand requires 1 argument
605 __git_find_subcommand ()
607         local word subcommand c=1
609         while [ $c -lt $COMP_CWORD ]; do
610                 word="${COMP_WORDS[c]}"
611                 for subcommand in $1; do
612                         if [ "$subcommand" = "$word" ]; then
613                                 echo "$subcommand"
614                                 return
615                         fi
616                 done
617                 c=$((++c))
618         done
621 __git_has_doubledash ()
623         local c=1
624         while [ $c -lt $COMP_CWORD ]; do
625                 if [ "--" = "${COMP_WORDS[c]}" ]; then
626                         return 0
627                 fi
628                 c=$((++c))
629         done
630         return 1
633 __git_whitespacelist="nowarn warn error error-all fix"
635 _git_am ()
637         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
638         if [ -d "$dir"/rebase-apply ]; then
639                 __gitcomp "--skip --resolved --abort"
640                 return
641         fi
642         case "$cur" in
643         --whitespace=*)
644                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
645                 return
646                 ;;
647         --*)
648                 __gitcomp "
649                         --3way --committer-date-is-author-date --ignore-date
650                         --interactive --keep --no-utf8 --signoff --utf8
651                         --whitespace=
652                         "
653                 return
654         esac
655         COMPREPLY=()
658 _git_apply ()
660         local cur="${COMP_WORDS[COMP_CWORD]}"
661         case "$cur" in
662         --whitespace=*)
663                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
664                 return
665                 ;;
666         --*)
667                 __gitcomp "
668                         --stat --numstat --summary --check --index
669                         --cached --index-info --reverse --reject --unidiff-zero
670                         --apply --no-add --exclude=
671                         --whitespace= --inaccurate-eof --verbose
672                         "
673                 return
674         esac
675         COMPREPLY=()
678 _git_add ()
680         __git_has_doubledash && return
682         local cur="${COMP_WORDS[COMP_CWORD]}"
683         case "$cur" in
684         --*)
685                 __gitcomp "
686                         --interactive --refresh --patch --update --dry-run
687                         --ignore-errors --intent-to-add
688                         "
689                 return
690         esac
691         COMPREPLY=()
694 _git_archive ()
696         local cur="${COMP_WORDS[COMP_CWORD]}"
697         case "$cur" in
698         --format=*)
699                 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
700                 return
701                 ;;
702         --remote=*)
703                 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
704                 return
705                 ;;
706         --*)
707                 __gitcomp "
708                         --format= --list --verbose
709                         --prefix= --remote= --exec=
710                         "
711                 return
712                 ;;
713         esac
714         __git_complete_file
717 _git_bisect ()
719         __git_has_doubledash && return
721         local subcommands="start bad good skip reset visualize replay log run"
722         local subcommand="$(__git_find_subcommand "$subcommands")"
723         if [ -z "$subcommand" ]; then
724                 __gitcomp "$subcommands"
725                 return
726         fi
728         case "$subcommand" in
729         bad|good|reset|skip)
730                 __gitcomp "$(__git_refs)"
731                 ;;
732         *)
733                 COMPREPLY=()
734                 ;;
735         esac
738 _git_branch ()
740         local i c=1 only_local_ref="n" has_r="n"
742         while [ $c -lt $COMP_CWORD ]; do
743                 i="${COMP_WORDS[c]}"
744                 case "$i" in
745                 -d|-m)  only_local_ref="y" ;;
746                 -r)     has_r="y" ;;
747                 esac
748                 c=$((++c))
749         done
751         case "${COMP_WORDS[COMP_CWORD]}" in
752         --*)
753                 __gitcomp "
754                         --color --no-color --verbose --abbrev= --no-abbrev
755                         --track --no-track --contains --merged --no-merged
756                         "
757                 ;;
758         *)
759                 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
760                         __gitcomp "$(__git_heads)"
761                 else
762                         __gitcomp "$(__git_refs)"
763                 fi
764                 ;;
765         esac
768 _git_bundle ()
770         local cmd="${COMP_WORDS[2]}"
771         case "$COMP_CWORD" in
772         2)
773                 __gitcomp "create list-heads verify unbundle"
774                 ;;
775         3)
776                 # looking for a file
777                 ;;
778         *)
779                 case "$cmd" in
780                         create)
781                                 __git_complete_revlist
782                         ;;
783                 esac
784                 ;;
785         esac
788 _git_checkout ()
790         __git_has_doubledash && return
792         __gitcomp "$(__git_refs)"
795 _git_cherry ()
797         __gitcomp "$(__git_refs)"
800 _git_cherry_pick ()
802         local cur="${COMP_WORDS[COMP_CWORD]}"
803         case "$cur" in
804         --*)
805                 __gitcomp "--edit --no-commit"
806                 ;;
807         *)
808                 __gitcomp "$(__git_refs)"
809                 ;;
810         esac
813 _git_clean ()
815         __git_has_doubledash && return
817         local cur="${COMP_WORDS[COMP_CWORD]}"
818         case "$cur" in
819         --*)
820                 __gitcomp "--dry-run --quiet"
821                 return
822                 ;;
823         esac
824         COMPREPLY=()
827 _git_clone ()
829         local cur="${COMP_WORDS[COMP_CWORD]}"
830         case "$cur" in
831         --*)
832                 __gitcomp "
833                         --local
834                         --no-hardlinks
835                         --shared
836                         --reference
837                         --quiet
838                         --no-checkout
839                         --bare
840                         --mirror
841                         --origin
842                         --upload-pack
843                         --template=
844                         --depth
845                         "
846                 return
847                 ;;
848         esac
849         COMPREPLY=()
852 _git_commit ()
854         __git_has_doubledash && return
856         local cur="${COMP_WORDS[COMP_CWORD]}"
857         case "$cur" in
858         --*)
859                 __gitcomp "
860                         --all --author= --signoff --verify --no-verify
861                         --edit --amend --include --only --interactive
862                         "
863                 return
864         esac
865         COMPREPLY=()
868 _git_describe ()
870         local cur="${COMP_WORDS[COMP_CWORD]}"
871         case "$cur" in
872         --*)
873                 __gitcomp "
874                         --all --tags --contains --abbrev= --candidates=
875                         --exact-match --debug --long --match --always
876                         "
877                 return
878         esac
879         __gitcomp "$(__git_refs)"
882 __git_diff_common_options="--stat --numstat --shortstat --summary
883                         --patch-with-stat --name-only --name-status --color
884                         --no-color --color-words --no-renames --check
885                         --full-index --binary --abbrev --diff-filter=
886                         --find-copies-harder
887                         --text --ignore-space-at-eol --ignore-space-change
888                         --ignore-all-space --exit-code --quiet --ext-diff
889                         --no-ext-diff
890                         --no-prefix --src-prefix= --dst-prefix=
891                         --inter-hunk-context=
892                         --patience
893                         --raw
896 _git_diff ()
898         __git_has_doubledash && return
900         local cur="${COMP_WORDS[COMP_CWORD]}"
901         case "$cur" in
902         --*)
903                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
904                         --base --ours --theirs
905                         $__git_diff_common_options
906                         "
907                 return
908                 ;;
909         esac
910         __git_complete_file
913 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
914                         tkdiff vimdiff gvimdiff xxdiff
917 _git_difftool ()
919         local cur="${COMP_WORDS[COMP_CWORD]}"
920         case "$cur" in
921         --tool=*)
922                 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
923                 return
924                 ;;
925         --*)
926                 __gitcomp "--tool="
927                 return
928                 ;;
929         esac
930         COMPREPLY=()
933 __git_fetch_options="
934         --quiet --verbose --append --upload-pack --force --keep --depth=
935         --tags --no-tags
938 _git_fetch ()
940         local cur="${COMP_WORDS[COMP_CWORD]}"
941         case "$cur" in
942         --*)
943                 __gitcomp "$__git_fetch_options"
944                 return
945                 ;;
946         esac
947         __git_complete_remote_or_refspec
950 _git_format_patch ()
952         local cur="${COMP_WORDS[COMP_CWORD]}"
953         case "$cur" in
954         --thread=*)
955                 __gitcomp "
956                         deep shallow
957                         " "" "${cur##--thread=}"
958                 return
959                 ;;
960         --*)
961                 __gitcomp "
962                         --stdout --attach --no-attach --thread --thread=
963                         --output-directory
964                         --numbered --start-number
965                         --numbered-files
966                         --keep-subject
967                         --signoff
968                         --in-reply-to= --cc=
969                         --full-index --binary
970                         --not --all
971                         --cover-letter
972                         --no-prefix --src-prefix= --dst-prefix=
973                         --inline --suffix= --ignore-if-in-upstream
974                         --subject-prefix=
975                         "
976                 return
977                 ;;
978         esac
979         __git_complete_revlist
982 _git_fsck ()
984         local cur="${COMP_WORDS[COMP_CWORD]}"
985         case "$cur" in
986         --*)
987                 __gitcomp "
988                         --tags --root --unreachable --cache --no-reflogs --full
989                         --strict --verbose --lost-found
990                         "
991                 return
992                 ;;
993         esac
994         COMPREPLY=()
997 _git_gc ()
999         local cur="${COMP_WORDS[COMP_CWORD]}"
1000         case "$cur" in
1001         --*)
1002                 __gitcomp "--prune --aggressive"
1003                 return
1004                 ;;
1005         esac
1006         COMPREPLY=()
1009 _git_grep ()
1011         __git_has_doubledash && return
1013         local cur="${COMP_WORDS[COMP_CWORD]}"
1014         case "$cur" in
1015         --*)
1016                 __gitcomp "
1017                         --cached
1018                         --text --ignore-case --word-regexp --invert-match
1019                         --full-name
1020                         --extended-regexp --basic-regexp --fixed-strings
1021                         --files-with-matches --name-only
1022                         --files-without-match
1023                         --count
1024                         --and --or --not --all-match
1025                         "
1026                 return
1027                 ;;
1028         esac
1029         COMPREPLY=()
1032 _git_help ()
1034         local cur="${COMP_WORDS[COMP_CWORD]}"
1035         case "$cur" in
1036         --*)
1037                 __gitcomp "--all --info --man --web"
1038                 return
1039                 ;;
1040         esac
1041         __gitcomp "$(__git_all_commands)
1042                 attributes cli core-tutorial cvs-migration
1043                 diffcore gitk glossary hooks ignore modules
1044                 repository-layout tutorial tutorial-2
1045                 workflows
1046                 "
1049 _git_init ()
1051         local cur="${COMP_WORDS[COMP_CWORD]}"
1052         case "$cur" in
1053         --shared=*)
1054                 __gitcomp "
1055                         false true umask group all world everybody
1056                         " "" "${cur##--shared=}"
1057                 return
1058                 ;;
1059         --*)
1060                 __gitcomp "--quiet --bare --template= --shared --shared="
1061                 return
1062                 ;;
1063         esac
1064         COMPREPLY=()
1067 _git_ls_files ()
1069         __git_has_doubledash && return
1071         local cur="${COMP_WORDS[COMP_CWORD]}"
1072         case "$cur" in
1073         --*)
1074                 __gitcomp "--cached --deleted --modified --others --ignored
1075                         --stage --directory --no-empty-directory --unmerged
1076                         --killed --exclude= --exclude-from=
1077                         --exclude-per-directory= --exclude-standard
1078                         --error-unmatch --with-tree= --full-name
1079                         --abbrev --ignored --exclude-per-directory
1080                         "
1081                 return
1082                 ;;
1083         esac
1084         COMPREPLY=()
1087 _git_ls_remote ()
1089         __gitcomp "$(__git_remotes)"
1092 _git_ls_tree ()
1094         __git_complete_file
1097 # Options that go well for log, shortlog and gitk
1098 __git_log_common_options="
1099         --not --all
1100         --branches --tags --remotes
1101         --first-parent --no-merges
1102         --max-count=
1103         --max-age= --since= --after=
1104         --min-age= --until= --before=
1106 # Options that go well for log and gitk (not shortlog)
1107 __git_log_gitk_options="
1108         --dense --sparse --full-history
1109         --simplify-merges --simplify-by-decoration
1110         --left-right
1112 # Options that go well for log and shortlog (not gitk)
1113 __git_log_shortlog_options="
1114         --author= --committer= --grep=
1115         --all-match
1118 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1119 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1121 _git_log ()
1123         __git_has_doubledash && return
1125         local cur="${COMP_WORDS[COMP_CWORD]}"
1126         local g="$(git rev-parse --git-dir 2>/dev/null)"
1127         local merge=""
1128         if [ -f "$g/MERGE_HEAD" ]; then
1129                 merge="--merge"
1130         fi
1131         case "$cur" in
1132         --pretty=*)
1133                 __gitcomp "$__git_log_pretty_formats
1134                         " "" "${cur##--pretty=}"
1135                 return
1136                 ;;
1137         --format=*)
1138                 __gitcomp "$__git_log_pretty_formats
1139                         " "" "${cur##--format=}"
1140                 return
1141                 ;;
1142         --date=*)
1143                 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1144                 return
1145                 ;;
1146         --*)
1147                 __gitcomp "
1148                         $__git_log_common_options
1149                         $__git_log_shortlog_options
1150                         $__git_log_gitk_options
1151                         --root --topo-order --date-order --reverse
1152                         --follow
1153                         --abbrev-commit --abbrev=
1154                         --relative-date --date=
1155                         --pretty= --format= --oneline
1156                         --cherry-pick
1157                         --graph
1158                         --decorate
1159                         --walk-reflogs
1160                         --parents --children
1161                         $merge
1162                         $__git_diff_common_options
1163                         --pickaxe-all --pickaxe-regex
1164                         "
1165                 return
1166                 ;;
1167         esac
1168         __git_complete_revlist
1171 __git_merge_options="
1172         --no-commit --no-stat --log --no-log --squash --strategy
1173         --commit --stat --no-squash --ff --no-ff
1176 _git_merge ()
1178         __git_complete_strategy && return
1180         local cur="${COMP_WORDS[COMP_CWORD]}"
1181         case "$cur" in
1182         --*)
1183                 __gitcomp "$__git_merge_options"
1184                 return
1185         esac
1186         __gitcomp "$(__git_refs)"
1189 _git_mergetool ()
1191         local cur="${COMP_WORDS[COMP_CWORD]}"
1192         case "$cur" in
1193         --tool=*)
1194                 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1195                 return
1196                 ;;
1197         --*)
1198                 __gitcomp "--tool="
1199                 return
1200                 ;;
1201         esac
1202         COMPREPLY=()
1205 _git_merge_base ()
1207         __gitcomp "$(__git_refs)"
1210 _git_mv ()
1212         local cur="${COMP_WORDS[COMP_CWORD]}"
1213         case "$cur" in
1214         --*)
1215                 __gitcomp "--dry-run"
1216                 return
1217                 ;;
1218         esac
1219         COMPREPLY=()
1222 _git_name_rev ()
1224         __gitcomp "--tags --all --stdin"
1227 _git_pull ()
1229         __git_complete_strategy && return
1231         local cur="${COMP_WORDS[COMP_CWORD]}"
1232         case "$cur" in
1233         --*)
1234                 __gitcomp "
1235                         --rebase --no-rebase
1236                         $__git_merge_options
1237                         $__git_fetch_options
1238                 "
1239                 return
1240                 ;;
1241         esac
1242         __git_complete_remote_or_refspec
1245 _git_push ()
1247         local cur="${COMP_WORDS[COMP_CWORD]}"
1248         case "${COMP_WORDS[COMP_CWORD-1]}" in
1249         --repo)
1250                 __gitcomp "$(__git_remotes)"
1251                 return
1252         esac
1253         case "$cur" in
1254         --repo=*)
1255                 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1256                 return
1257                 ;;
1258         --*)
1259                 __gitcomp "
1260                         --all --mirror --tags --dry-run --force --verbose
1261                         --receive-pack= --repo=
1262                 "
1263                 return
1264                 ;;
1265         esac
1266         __git_complete_remote_or_refspec
1269 _git_rebase ()
1271         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1272         if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1273                 __gitcomp "--continue --skip --abort"
1274                 return
1275         fi
1276         __git_complete_strategy && return
1277         case "$cur" in
1278         --*)
1279                 __gitcomp "--onto --merge --strategy --interactive"
1280                 return
1281         esac
1282         __gitcomp "$(__git_refs)"
1285 __git_send_email_confirm_options="always never auto cc compose"
1286 __git_send_email_suppresscc_options="author self cc ccbody sob cccmd body all"
1288 _git_send_email ()
1290         local cur="${COMP_WORDS[COMP_CWORD]}"
1291         case "$cur" in
1292         --confirm=*)
1293                 __gitcomp "
1294                         $__git_send_email_confirm_options
1295                         " "" "${cur##--confirm=}"
1296                 return
1297                 ;;
1298         --suppress-cc=*)
1299                 __gitcomp "
1300                         $__git_send_email_suppresscc_options
1301                         " "" "${cur##--suppress-cc=}"
1303                 return
1304                 ;;
1305         --smtp-encryption=*)
1306                 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1307                 return
1308                 ;;
1309         --*)
1310                 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1311                         --compose --confirm= --dry-run --envelope-sender
1312                         --from --identity
1313                         --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1314                         --no-suppress-from --no-thread --quiet
1315                         --signed-off-by-cc --smtp-pass --smtp-server
1316                         --smtp-server-port --smtp-encryption= --smtp-user
1317                         --subject --suppress-cc= --suppress-from --thread --to
1318                         --validate --no-validate"
1319                 return
1320                 ;;
1321         esac
1322         COMPREPLY=()
1325 __git_config_get_set_variables ()
1327         local prevword word config_file= c=$COMP_CWORD
1328         while [ $c -gt 1 ]; do
1329                 word="${COMP_WORDS[c]}"
1330                 case "$word" in
1331                 --global|--system|--file=*)
1332                         config_file="$word"
1333                         break
1334                         ;;
1335                 -f|--file)
1336                         config_file="$word $prevword"
1337                         break
1338                         ;;
1339                 esac
1340                 prevword=$word
1341                 c=$((--c))
1342         done
1344         for i in $(git --git-dir="$(__gitdir)" config $config_file --list \
1345                         2>/dev/null); do
1346                 case "$i" in
1347                 *.*)
1348                         echo "${i/=*/}"
1349                         ;;
1350                 esac
1351         done
1354 _git_config ()
1356         local cur="${COMP_WORDS[COMP_CWORD]}"
1357         local prv="${COMP_WORDS[COMP_CWORD-1]}"
1358         case "$prv" in
1359         branch.*.remote)
1360                 __gitcomp "$(__git_remotes)"
1361                 return
1362                 ;;
1363         branch.*.merge)
1364                 __gitcomp "$(__git_refs)"
1365                 return
1366                 ;;
1367         remote.*.fetch)
1368                 local remote="${prv#remote.}"
1369                 remote="${remote%.fetch}"
1370                 __gitcomp "$(__git_refs_remotes "$remote")"
1371                 return
1372                 ;;
1373         remote.*.push)
1374                 local remote="${prv#remote.}"
1375                 remote="${remote%.push}"
1376                 __gitcomp "$(git --git-dir="$(__gitdir)" \
1377                         for-each-ref --format='%(refname):%(refname)' \
1378                         refs/heads)"
1379                 return
1380                 ;;
1381         pull.twohead|pull.octopus)
1382                 __gitcomp "$(__git_merge_strategies)"
1383                 return
1384                 ;;
1385         color.branch|color.diff|color.interactive|color.status|color.ui)
1386                 __gitcomp "always never auto"
1387                 return
1388                 ;;
1389         color.pager)
1390                 __gitcomp "false true"
1391                 return
1392                 ;;
1393         color.*.*)
1394                 __gitcomp "
1395                         normal black red green yellow blue magenta cyan white
1396                         bold dim ul blink reverse
1397                         "
1398                 return
1399                 ;;
1400         help.format)
1401                 __gitcomp "man info web html"
1402                 return
1403                 ;;
1404         log.date)
1405                 __gitcomp "$__git_log_date_formats"
1406                 return
1407                 ;;
1408         sendemail.aliasesfiletype)
1409                 __gitcomp "mutt mailrc pine elm gnus"
1410                 return
1411                 ;;
1412         sendemail.confirm)
1413                 __gitcomp "$__git_send_email_confirm_options"
1414                 return
1415                 ;;
1416         sendemail.suppresscc)
1417                 __gitcomp "$__git_send_email_suppresscc_options"
1418                 return
1419                 ;;
1420         --get|--get-all|--unset|--unset-all)
1421                 __gitcomp "$(__git_config_get_set_variables)"
1422                 return
1423                 ;;
1424         *.*)
1425                 COMPREPLY=()
1426                 return
1427                 ;;
1428         esac
1429         case "$cur" in
1430         --*)
1431                 __gitcomp "
1432                         --global --system --file=
1433                         --list --replace-all
1434                         --get --get-all --get-regexp
1435                         --add --unset --unset-all
1436                         --remove-section --rename-section
1437                         "
1438                 return
1439                 ;;
1440         branch.*.*)
1441                 local pfx="${cur%.*}."
1442                 cur="${cur##*.}"
1443                 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1444                 return
1445                 ;;
1446         branch.*)
1447                 local pfx="${cur%.*}."
1448                 cur="${cur#*.}"
1449                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1450                 return
1451                 ;;
1452         guitool.*.*)
1453                 local pfx="${cur%.*}."
1454                 cur="${cur##*.}"
1455                 __gitcomp "
1456                         argprompt cmd confirm needsfile noconsole norescan
1457                         prompt revprompt revunmerged title
1458                         " "$pfx" "$cur"
1459                 return
1460                 ;;
1461         difftool.*.*)
1462                 local pfx="${cur%.*}."
1463                 cur="${cur##*.}"
1464                 __gitcomp "cmd path" "$pfx" "$cur"
1465                 return
1466                 ;;
1467         man.*.*)
1468                 local pfx="${cur%.*}."
1469                 cur="${cur##*.}"
1470                 __gitcomp "cmd path" "$pfx" "$cur"
1471                 return
1472                 ;;
1473         mergetool.*.*)
1474                 local pfx="${cur%.*}."
1475                 cur="${cur##*.}"
1476                 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1477                 return
1478                 ;;
1479         pager.*)
1480                 local pfx="${cur%.*}."
1481                 cur="${cur#*.}"
1482                 __gitcomp "$(__git_all_commands)" "$pfx" "$cur"
1483                 return
1484                 ;;
1485         remote.*.*)
1486                 local pfx="${cur%.*}."
1487                 cur="${cur##*.}"
1488                 __gitcomp "
1489                         url proxy fetch push mirror skipDefaultUpdate
1490                         receivepack uploadpack tagopt
1491                         " "$pfx" "$cur"
1492                 return
1493                 ;;
1494         remote.*)
1495                 local pfx="${cur%.*}."
1496                 cur="${cur#*.}"
1497                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1498                 return
1499                 ;;
1500         url.*.*)
1501                 local pfx="${cur%.*}."
1502                 cur="${cur##*.}"
1503                 __gitcomp "insteadof" "$pfx" "$cur"
1504                 return
1505                 ;;
1506         esac
1507         __gitcomp "
1508                 alias.
1509                 apply.whitespace
1510                 branch.autosetupmerge
1511                 branch.autosetuprebase
1512                 clean.requireForce
1513                 color.branch
1514                 color.branch.current
1515                 color.branch.local
1516                 color.branch.plain
1517                 color.branch.remote
1518                 color.diff
1519                 color.diff.commit
1520                 color.diff.frag
1521                 color.diff.meta
1522                 color.diff.new
1523                 color.diff.old
1524                 color.diff.plain
1525                 color.diff.whitespace
1526                 color.grep
1527                 color.grep.external
1528                 color.grep.match
1529                 color.interactive
1530                 color.interactive.header
1531                 color.interactive.help
1532                 color.interactive.prompt
1533                 color.pager
1534                 color.status
1535                 color.status.added
1536                 color.status.changed
1537                 color.status.header
1538                 color.status.nobranch
1539                 color.status.untracked
1540                 color.status.updated
1541                 color.ui
1542                 commit.template
1543                 core.autocrlf
1544                 core.bare
1545                 core.compression
1546                 core.createObject
1547                 core.deltaBaseCacheLimit
1548                 core.editor
1549                 core.excludesfile
1550                 core.fileMode
1551                 core.fsyncobjectfiles
1552                 core.gitProxy
1553                 core.ignoreCygwinFSTricks
1554                 core.ignoreStat
1555                 core.logAllRefUpdates
1556                 core.loosecompression
1557                 core.packedGitLimit
1558                 core.packedGitWindowSize
1559                 core.pager
1560                 core.preferSymlinkRefs
1561                 core.preloadindex
1562                 core.quotepath
1563                 core.repositoryFormatVersion
1564                 core.safecrlf
1565                 core.sharedRepository
1566                 core.symlinks
1567                 core.trustctime
1568                 core.warnAmbiguousRefs
1569                 core.whitespace
1570                 core.worktree
1571                 diff.autorefreshindex
1572                 diff.external
1573                 diff.mnemonicprefix
1574                 diff.renameLimit
1575                 diff.renameLimit.
1576                 diff.renames
1577                 diff.suppressBlankEmpty
1578                 diff.tool
1579                 diff.wordRegex
1580                 difftool.
1581                 difftool.prompt
1582                 fetch.unpackLimit
1583                 format.attach
1584                 format.cc
1585                 format.headers
1586                 format.numbered
1587                 format.pretty
1588                 format.signoff
1589                 format.subjectprefix
1590                 format.suffix
1591                 format.thread
1592                 gc.aggressiveWindow
1593                 gc.auto
1594                 gc.autopacklimit
1595                 gc.packrefs
1596                 gc.pruneexpire
1597                 gc.reflogexpire
1598                 gc.reflogexpireunreachable
1599                 gc.rerereresolved
1600                 gc.rerereunresolved
1601                 gitcvs.allbinary
1602                 gitcvs.commitmsgannotation
1603                 gitcvs.dbTableNamePrefix
1604                 gitcvs.dbdriver
1605                 gitcvs.dbname
1606                 gitcvs.dbpass
1607                 gitcvs.dbuser
1608                 gitcvs.enabled
1609                 gitcvs.logfile
1610                 gitcvs.usecrlfattr
1611                 guitool.
1612                 gui.blamehistoryctx
1613                 gui.commitmsgwidth
1614                 gui.copyblamethreshold
1615                 gui.diffcontext
1616                 gui.encoding
1617                 gui.fastcopyblame
1618                 gui.matchtrackingbranch
1619                 gui.newbranchtemplate
1620                 gui.pruneduringfetch
1621                 gui.spellingdictionary
1622                 gui.trustmtime
1623                 help.autocorrect
1624                 help.browser
1625                 help.format
1626                 http.lowSpeedLimit
1627                 http.lowSpeedTime
1628                 http.maxRequests
1629                 http.noEPSV
1630                 http.proxy
1631                 http.sslCAInfo
1632                 http.sslCAPath
1633                 http.sslCert
1634                 http.sslKey
1635                 http.sslVerify
1636                 i18n.commitEncoding
1637                 i18n.logOutputEncoding
1638                 imap.folder
1639                 imap.host
1640                 imap.pass
1641                 imap.port
1642                 imap.preformattedHTML
1643                 imap.sslverify
1644                 imap.tunnel
1645                 imap.user
1646                 instaweb.browser
1647                 instaweb.httpd
1648                 instaweb.local
1649                 instaweb.modulepath
1650                 instaweb.port
1651                 interactive.singlekey
1652                 log.date
1653                 log.showroot
1654                 mailmap.file
1655                 man.
1656                 man.viewer
1657                 merge.conflictstyle
1658                 merge.log
1659                 merge.renameLimit
1660                 merge.stat
1661                 merge.tool
1662                 merge.verbosity
1663                 mergetool.
1664                 mergetool.keepBackup
1665                 mergetool.prompt
1666                 pack.compression
1667                 pack.deltaCacheLimit
1668                 pack.deltaCacheSize
1669                 pack.depth
1670                 pack.indexVersion
1671                 pack.packSizeLimit
1672                 pack.threads
1673                 pack.window
1674                 pack.windowMemory
1675                 pager.
1676                 pull.octopus
1677                 pull.twohead
1678                 push.default
1679                 rebase.stat
1680                 receive.denyCurrentBranch
1681                 receive.denyDeletes
1682                 receive.denyNonFastForwards
1683                 receive.fsckObjects
1684                 receive.unpackLimit
1685                 repack.usedeltabaseoffset
1686                 rerere.autoupdate
1687                 rerere.enabled
1688                 sendemail.aliasesfile
1689                 sendemail.aliasesfiletype
1690                 sendemail.bcc
1691                 sendemail.cc
1692                 sendemail.cccmd
1693                 sendemail.chainreplyto
1694                 sendemail.confirm
1695                 sendemail.envelopesender
1696                 sendemail.multiedit
1697                 sendemail.signedoffbycc
1698                 sendemail.smtpencryption
1699                 sendemail.smtppass
1700                 sendemail.smtpserver
1701                 sendemail.smtpserverport
1702                 sendemail.smtpuser
1703                 sendemail.suppresscc
1704                 sendemail.suppressfrom
1705                 sendemail.thread
1706                 sendemail.to
1707                 sendemail.validate
1708                 showbranch.default
1709                 status.relativePaths
1710                 status.showUntrackedFiles
1711                 tar.umask
1712                 transfer.unpackLimit
1713                 url.
1714                 user.email
1715                 user.name
1716                 user.signingkey
1717                 web.browser
1718                 branch. remote.
1719         "
1722 _git_remote ()
1724         local subcommands="add rename rm show prune update set-head"
1725         local subcommand="$(__git_find_subcommand "$subcommands")"
1726         if [ -z "$subcommand" ]; then
1727                 __gitcomp "$subcommands"
1728                 return
1729         fi
1731         case "$subcommand" in
1732         rename|rm|show|prune)
1733                 __gitcomp "$(__git_remotes)"
1734                 ;;
1735         update)
1736                 local i c='' IFS=$'\n'
1737                 for i in $(git --git-dir="$(__gitdir)" config --list); do
1738                         case "$i" in
1739                         remotes.*)
1740                                 i="${i#remotes.}"
1741                                 c="$c ${i/=*/}"
1742                                 ;;
1743                         esac
1744                 done
1745                 __gitcomp "$c"
1746                 ;;
1747         *)
1748                 COMPREPLY=()
1749                 ;;
1750         esac
1753 _git_reset ()
1755         __git_has_doubledash && return
1757         local cur="${COMP_WORDS[COMP_CWORD]}"
1758         case "$cur" in
1759         --*)
1760                 __gitcomp "--merge --mixed --hard --soft"
1761                 return
1762                 ;;
1763         esac
1764         __gitcomp "$(__git_refs)"
1767 _git_revert ()
1769         local cur="${COMP_WORDS[COMP_CWORD]}"
1770         case "$cur" in
1771         --*)
1772                 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1773                 return
1774                 ;;
1775         esac
1776         __gitcomp "$(__git_refs)"
1779 _git_rm ()
1781         __git_has_doubledash && return
1783         local cur="${COMP_WORDS[COMP_CWORD]}"
1784         case "$cur" in
1785         --*)
1786                 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1787                 return
1788                 ;;
1789         esac
1790         COMPREPLY=()
1793 _git_shortlog ()
1795         __git_has_doubledash && return
1797         local cur="${COMP_WORDS[COMP_CWORD]}"
1798         case "$cur" in
1799         --*)
1800                 __gitcomp "
1801                         $__git_log_common_options
1802                         $__git_log_shortlog_options
1803                         --numbered --summary
1804                         "
1805                 return
1806                 ;;
1807         esac
1808         __git_complete_revlist
1811 _git_show ()
1813         __git_has_doubledash && return
1815         local cur="${COMP_WORDS[COMP_CWORD]}"
1816         case "$cur" in
1817         --pretty=*)
1818                 __gitcomp "$__git_log_pretty_formats
1819                         " "" "${cur##--pretty=}"
1820                 return
1821                 ;;
1822         --format=*)
1823                 __gitcomp "$__git_log_pretty_formats
1824                         " "" "${cur##--format=}"
1825                 return
1826                 ;;
1827         --*)
1828                 __gitcomp "--pretty= --format=
1829                         $__git_diff_common_options
1830                         "
1831                 return
1832                 ;;
1833         esac
1834         __git_complete_file
1837 _git_show_branch ()
1839         local cur="${COMP_WORDS[COMP_CWORD]}"
1840         case "$cur" in
1841         --*)
1842                 __gitcomp "
1843                         --all --remotes --topo-order --current --more=
1844                         --list --independent --merge-base --no-name
1845                         --sha1-name --topics --reflog
1846                         "
1847                 return
1848                 ;;
1849         esac
1850         __git_complete_revlist
1853 _git_stash ()
1855         local subcommands='save list show apply clear drop pop create branch'
1856         local subcommand="$(__git_find_subcommand "$subcommands")"
1857         if [ -z "$subcommand" ]; then
1858                 __gitcomp "$subcommands"
1859         else
1860                 local cur="${COMP_WORDS[COMP_CWORD]}"
1861                 case "$subcommand,$cur" in
1862                 save,--*)
1863                         __gitcomp "--keep-index"
1864                         ;;
1865                 apply,--*)
1866                         __gitcomp "--index"
1867                         ;;
1868                 show,--*|drop,--*|pop,--*|branch,--*)
1869                         COMPREPLY=()
1870                         ;;
1871                 show,*|apply,*|drop,*|pop,*|branch,*)
1872                         __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1873                                         | sed -n -e 's/:.*//p')"
1874                         ;;
1875                 *)
1876                         COMPREPLY=()
1877                         ;;
1878                 esac
1879         fi
1882 _git_submodule ()
1884         __git_has_doubledash && return
1886         local subcommands="add status init update summary foreach sync"
1887         if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1888                 local cur="${COMP_WORDS[COMP_CWORD]}"
1889                 case "$cur" in
1890                 --*)
1891                         __gitcomp "--quiet --cached"
1892                         ;;
1893                 *)
1894                         __gitcomp "$subcommands"
1895                         ;;
1896                 esac
1897                 return
1898         fi
1901 _git_svn ()
1903         local subcommands="
1904                 init fetch clone rebase dcommit log find-rev
1905                 set-tree commit-diff info create-ignore propget
1906                 proplist show-ignore show-externals branch tag blame
1907                 migrate
1908                 "
1909         local subcommand="$(__git_find_subcommand "$subcommands")"
1910         if [ -z "$subcommand" ]; then
1911                 __gitcomp "$subcommands"
1912         else
1913                 local remote_opts="--username= --config-dir= --no-auth-cache"
1914                 local fc_opts="
1915                         --follow-parent --authors-file= --repack=
1916                         --no-metadata --use-svm-props --use-svnsync-props
1917                         --log-window-size= --no-checkout --quiet
1918                         --repack-flags --use-log-author --localtime
1919                         --ignore-paths= $remote_opts
1920                         "
1921                 local init_opts="
1922                         --template= --shared= --trunk= --tags=
1923                         --branches= --stdlayout --minimize-url
1924                         --no-metadata --use-svm-props --use-svnsync-props
1925                         --rewrite-root= --prefix= --use-log-author
1926                         --add-author-from $remote_opts
1927                         "
1928                 local cmt_opts="
1929                         --edit --rmdir --find-copies-harder --copy-similarity=
1930                         "
1932                 local cur="${COMP_WORDS[COMP_CWORD]}"
1933                 case "$subcommand,$cur" in
1934                 fetch,--*)
1935                         __gitcomp "--revision= --fetch-all $fc_opts"
1936                         ;;
1937                 clone,--*)
1938                         __gitcomp "--revision= $fc_opts $init_opts"
1939                         ;;
1940                 init,--*)
1941                         __gitcomp "$init_opts"
1942                         ;;
1943                 dcommit,--*)
1944                         __gitcomp "
1945                                 --merge --strategy= --verbose --dry-run
1946                                 --fetch-all --no-rebase --commit-url
1947                                 --revision $cmt_opts $fc_opts
1948                                 "
1949                         ;;
1950                 set-tree,--*)
1951                         __gitcomp "--stdin $cmt_opts $fc_opts"
1952                         ;;
1953                 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1954                 show-externals,--*)
1955                         __gitcomp "--revision="
1956                         ;;
1957                 log,--*)
1958                         __gitcomp "
1959                                 --limit= --revision= --verbose --incremental
1960                                 --oneline --show-commit --non-recursive
1961                                 --authors-file= --color
1962                                 "
1963                         ;;
1964                 rebase,--*)
1965                         __gitcomp "
1966                                 --merge --verbose --strategy= --local
1967                                 --fetch-all --dry-run $fc_opts
1968                                 "
1969                         ;;
1970                 commit-diff,--*)
1971                         __gitcomp "--message= --file= --revision= $cmt_opts"
1972                         ;;
1973                 info,--*)
1974                         __gitcomp "--url"
1975                         ;;
1976                 branch,--*)
1977                         __gitcomp "--dry-run --message --tag"
1978                         ;;
1979                 tag,--*)
1980                         __gitcomp "--dry-run --message"
1981                         ;;
1982                 blame,--*)
1983                         __gitcomp "--git-format"
1984                         ;;
1985                 migrate,--*)
1986                         __gitcomp "
1987                                 --config-dir= --ignore-paths= --minimize
1988                                 --no-auth-cache --username=
1989                                 "
1990                         ;;
1991                 *)
1992                         COMPREPLY=()
1993                         ;;
1994                 esac
1995         fi
1998 _git_tag ()
2000         local i c=1 f=0
2001         while [ $c -lt $COMP_CWORD ]; do
2002                 i="${COMP_WORDS[c]}"
2003                 case "$i" in
2004                 -d|-v)
2005                         __gitcomp "$(__git_tags)"
2006                         return
2007                         ;;
2008                 -f)
2009                         f=1
2010                         ;;
2011                 esac
2012                 c=$((++c))
2013         done
2015         case "${COMP_WORDS[COMP_CWORD-1]}" in
2016         -m|-F)
2017                 COMPREPLY=()
2018                 ;;
2019         -*|tag)
2020                 if [ $f = 1 ]; then
2021                         __gitcomp "$(__git_tags)"
2022                 else
2023                         COMPREPLY=()
2024                 fi
2025                 ;;
2026         *)
2027                 __gitcomp "$(__git_refs)"
2028                 ;;
2029         esac
2032 _git ()
2034         local i c=1 command __git_dir
2036         while [ $c -lt $COMP_CWORD ]; do
2037                 i="${COMP_WORDS[c]}"
2038                 case "$i" in
2039                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2040                 --bare)      __git_dir="." ;;
2041                 --version|-p|--paginate) ;;
2042                 --help) command="help"; break ;;
2043                 *) command="$i"; break ;;
2044                 esac
2045                 c=$((++c))
2046         done
2048         if [ -z "$command" ]; then
2049                 case "${COMP_WORDS[COMP_CWORD]}" in
2050                 --*)   __gitcomp "
2051                         --paginate
2052                         --no-pager
2053                         --git-dir=
2054                         --bare
2055                         --version
2056                         --exec-path
2057                         --html-path
2058                         --work-tree=
2059                         --help
2060                         "
2061                         ;;
2062                 *)     __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
2063                 esac
2064                 return
2065         fi
2067         local expansion=$(__git_aliased_command "$command")
2068         [ "$expansion" ] && command="$expansion"
2070         case "$command" in
2071         am)          _git_am ;;
2072         add)         _git_add ;;
2073         apply)       _git_apply ;;
2074         archive)     _git_archive ;;
2075         bisect)      _git_bisect ;;
2076         bundle)      _git_bundle ;;
2077         branch)      _git_branch ;;
2078         checkout)    _git_checkout ;;
2079         cherry)      _git_cherry ;;
2080         cherry-pick) _git_cherry_pick ;;
2081         clean)       _git_clean ;;
2082         clone)       _git_clone ;;
2083         commit)      _git_commit ;;
2084         config)      _git_config ;;
2085         describe)    _git_describe ;;
2086         diff)        _git_diff ;;
2087         difftool)    _git_difftool ;;
2088         fetch)       _git_fetch ;;
2089         format-patch) _git_format_patch ;;
2090         fsck)        _git_fsck ;;
2091         gc)          _git_gc ;;
2092         grep)        _git_grep ;;
2093         help)        _git_help ;;
2094         init)        _git_init ;;
2095         log)         _git_log ;;
2096         ls-files)    _git_ls_files ;;
2097         ls-remote)   _git_ls_remote ;;
2098         ls-tree)     _git_ls_tree ;;
2099         merge)       _git_merge;;
2100         mergetool)   _git_mergetool;;
2101         merge-base)  _git_merge_base ;;
2102         mv)          _git_mv ;;
2103         name-rev)    _git_name_rev ;;
2104         pull)        _git_pull ;;
2105         push)        _git_push ;;
2106         rebase)      _git_rebase ;;
2107         remote)      _git_remote ;;
2108         reset)       _git_reset ;;
2109         revert)      _git_revert ;;
2110         rm)          _git_rm ;;
2111         send-email)  _git_send_email ;;
2112         shortlog)    _git_shortlog ;;
2113         show)        _git_show ;;
2114         show-branch) _git_show_branch ;;
2115         stash)       _git_stash ;;
2116         stage)       _git_add ;;
2117         submodule)   _git_submodule ;;
2118         svn)         _git_svn ;;
2119         tag)         _git_tag ;;
2120         whatchanged) _git_log ;;
2121         *)           COMPREPLY=() ;;
2122         esac
2125 _gitk ()
2127         __git_has_doubledash && return
2129         local cur="${COMP_WORDS[COMP_CWORD]}"
2130         local g="$(__gitdir)"
2131         local merge=""
2132         if [ -f "$g/MERGE_HEAD" ]; then
2133                 merge="--merge"
2134         fi
2135         case "$cur" in
2136         --*)
2137                 __gitcomp "
2138                         $__git_log_common_options
2139                         $__git_log_gitk_options
2140                         $merge
2141                         "
2142                 return
2143                 ;;
2144         esac
2145         __git_complete_revlist
2148 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2149         || complete -o default -o nospace -F _git git
2150 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2151         || complete -o default -o nospace -F _gitk gitk
2153 # The following are necessary only for Cygwin, and only are needed
2154 # when the user has tab-completed the executable name and consequently
2155 # included the '.exe' suffix.
2157 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2158 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2159         || complete -o default -o nospace -F _git git.exe
2160 fi