Code

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