Code

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