Code

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