Code

Merge branch 'jn/maint-gitweb-pathinfo-fix'
[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 #       Or, add the following lines to your .zshrc:
25 #        autoload bashcompinit
26 #        bashcompinit
27 #        source ~/.git-completion.sh
28 #
29 #    3) Consider changing your PS1 to also show the current branch:
30 #        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
31 #
32 #       The argument to __git_ps1 will be displayed only if you
33 #       are currently in a git repository.  The %s token will be
34 #       the name of the current branch.
35 #
36 #       In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
37 #       value, unstaged (*) and staged (+) changes will be shown next
38 #       to the branch name.  You can configure this per-repository
39 #       with the bash.showDirtyState variable, which defaults to true
40 #       once GIT_PS1_SHOWDIRTYSTATE is enabled.
41 #
42 #       You can also see if currently something is stashed, by setting
43 #       GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
44 #       then a '$' will be shown next to the branch name.
45 #
46 #       If you would like to see if there're untracked files, then you can
47 #       set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
48 #       untracked files, then a '%' will be shown next to the branch name.
49 #
50 #       If you would like to see the difference between HEAD and its
51 #       upstream, set GIT_PS1_SHOWUPSTREAM="auto".  A "<" indicates
52 #       you are behind, ">" indicates you are ahead, and "<>"
53 #       indicates you have diverged.  You can further control
54 #       behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
55 #       list of values:
56 #           verbose       show number of commits ahead/behind (+/-) upstream
57 #           legacy        don't use the '--count' option available in recent
58 #                         versions of git-rev-list
59 #           git           always compare HEAD to @{upstream}
60 #           svn           always compare HEAD to your SVN upstream
61 #       By default, __git_ps1 will compare HEAD to your SVN upstream
62 #       if it can find one, or @{upstream} otherwise.  Once you have
63 #       set GIT_PS1_SHOWUPSTREAM, you can override it on a
64 #       per-repository basis by setting the bash.showUpstream config
65 #       variable.
66 #
67 #
68 # To submit patches:
69 #
70 #    *) Read Documentation/SubmittingPatches
71 #    *) Send all patches to the current maintainer:
72 #
73 #       "Shawn O. Pearce" <spearce@spearce.org>
74 #
75 #    *) Always CC the Git mailing list:
76 #
77 #       git@vger.kernel.org
78 #
80 case "$COMP_WORDBREAKS" in
81 *:*) : great ;;
82 *)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
83 esac
85 # __gitdir accepts 0 or 1 arguments (i.e., location)
86 # returns location of .git repo
87 __gitdir ()
88 {
89         if [ -z "${1-}" ]; then
90                 if [ -n "${__git_dir-}" ]; then
91                         echo "$__git_dir"
92                 elif [ -d .git ]; then
93                         echo .git
94                 else
95                         git rev-parse --git-dir 2>/dev/null
96                 fi
97         elif [ -d "$1/.git" ]; then
98                 echo "$1/.git"
99         else
100                 echo "$1"
101         fi
104 # stores the divergence from upstream in $p
105 # used by GIT_PS1_SHOWUPSTREAM
106 __git_ps1_show_upstream ()
108         local key value
109         local svn_remote=() svn_url_pattern count n
110         local upstream=git legacy="" verbose=""
112         # get some config options from git-config
113         while read key value; do
114                 case "$key" in
115                 bash.showupstream)
116                         GIT_PS1_SHOWUPSTREAM="$value"
117                         if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
118                                 p=""
119                                 return
120                         fi
121                         ;;
122                 svn-remote.*.url)
123                         svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
124                         svn_url_pattern+="\\|$value"
125                         upstream=svn+git # default upstream is SVN if available, else git
126                         ;;
127                 esac
128         done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
130         # parse configuration values
131         for option in ${GIT_PS1_SHOWUPSTREAM}; do
132                 case "$option" in
133                 git|svn) upstream="$option" ;;
134                 verbose) verbose=1 ;;
135                 legacy)  legacy=1  ;;
136                 esac
137         done
139         # Find our upstream
140         case "$upstream" in
141         git)    upstream="@{upstream}" ;;
142         svn*)
143                 # get the upstream from the "git-svn-id: ..." in a commit message
144                 # (git-svn uses essentially the same procedure internally)
145                 local svn_upstream=($(git log --first-parent -1 \
146                                         --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
147                 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
148                         svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
149                         svn_upstream=${svn_upstream%@*}
150                         local n_stop="${#svn_remote[@]}"
151                         for ((n=1; n <= n_stop; ++n)); do
152                                 svn_upstream=${svn_upstream#${svn_remote[$n]}}
153                         done
155                         if [[ -z "$svn_upstream" ]]; then
156                                 # default branch name for checkouts with no layout:
157                                 upstream=${GIT_SVN_ID:-git-svn}
158                         else
159                                 upstream=${svn_upstream#/}
160                         fi
161                 elif [[ "svn+git" = "$upstream" ]]; then
162                         upstream="@{upstream}"
163                 fi
164                 ;;
165         esac
167         # Find how many commits we are ahead/behind our upstream
168         if [[ -z "$legacy" ]]; then
169                 count="$(git rev-list --count --left-right \
170                                 "$upstream"...HEAD 2>/dev/null)"
171         else
172                 # produce equivalent output to --count for older versions of git
173                 local commits
174                 if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
175                 then
176                         local commit behind=0 ahead=0
177                         for commit in $commits
178                         do
179                                 case "$commit" in
180                                 "<"*) let ++behind
181                                         ;;
182                                 *)    let ++ahead
183                                         ;;
184                                 esac
185                         done
186                         count="$behind  $ahead"
187                 else
188                         count=""
189                 fi
190         fi
192         # calculate the result
193         if [[ -z "$verbose" ]]; then
194                 case "$count" in
195                 "") # no upstream
196                         p="" ;;
197                 "0      0") # equal to upstream
198                         p="=" ;;
199                 "0      "*) # ahead of upstream
200                         p=">" ;;
201                 *"      0") # behind upstream
202                         p="<" ;;
203                 *)          # diverged from upstream
204                         p="<>" ;;
205                 esac
206         else
207                 case "$count" in
208                 "") # no upstream
209                         p="" ;;
210                 "0      0") # equal to upstream
211                         p=" u=" ;;
212                 "0      "*) # ahead of upstream
213                         p=" u+${count#0 }" ;;
214                 *"      0") # behind upstream
215                         p=" u-${count%  0}" ;;
216                 *)          # diverged from upstream
217                         p=" u+${count#* }-${count%      *}" ;;
218                 esac
219         fi
224 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
225 # returns text to add to bash PS1 prompt (includes branch name)
226 __git_ps1 ()
228         local g="$(__gitdir)"
229         if [ -n "$g" ]; then
230                 local r=""
231                 local b=""
232                 if [ -f "$g/rebase-merge/interactive" ]; then
233                         r="|REBASE-i"
234                         b="$(cat "$g/rebase-merge/head-name")"
235                 elif [ -d "$g/rebase-merge" ]; then
236                         r="|REBASE-m"
237                         b="$(cat "$g/rebase-merge/head-name")"
238                 else
239                         if [ -d "$g/rebase-apply" ]; then
240                                 if [ -f "$g/rebase-apply/rebasing" ]; then
241                                         r="|REBASE"
242                                 elif [ -f "$g/rebase-apply/applying" ]; then
243                                         r="|AM"
244                                 else
245                                         r="|AM/REBASE"
246                                 fi
247                         elif [ -f "$g/MERGE_HEAD" ]; then
248                                 r="|MERGING"
249                         elif [ -f "$g/BISECT_LOG" ]; then
250                                 r="|BISECTING"
251                         fi
253                         b="$(git symbolic-ref HEAD 2>/dev/null)" || {
255                                 b="$(
256                                 case "${GIT_PS1_DESCRIBE_STYLE-}" in
257                                 (contains)
258                                         git describe --contains HEAD ;;
259                                 (branch)
260                                         git describe --contains --all HEAD ;;
261                                 (describe)
262                                         git describe HEAD ;;
263                                 (* | default)
264                                         git describe --tags --exact-match HEAD ;;
265                                 esac 2>/dev/null)" ||
267                                 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
268                                 b="unknown"
269                                 b="($b)"
270                         }
271                 fi
273                 local w=""
274                 local i=""
275                 local s=""
276                 local u=""
277                 local c=""
278                 local p=""
280                 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
281                         if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
282                                 c="BARE:"
283                         else
284                                 b="GIT_DIR!"
285                         fi
286                 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
287                         if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
288                                 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
289                                         git diff --no-ext-diff --quiet --exit-code || w="*"
290                                         if git rev-parse --quiet --verify HEAD >/dev/null; then
291                                                 git diff-index --cached --quiet HEAD -- || i="+"
292                                         else
293                                                 i="#"
294                                         fi
295                                 fi
296                         fi
297                         if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
298                                 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
299                         fi
301                         if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
302                            if [ -n "$(git ls-files --others --exclude-standard)" ]; then
303                               u="%"
304                            fi
305                         fi
307                         if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
308                                 __git_ps1_show_upstream
309                         fi
310                 fi
312                 local f="$w$i$s$u"
313                 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
314         fi
317 # __gitcomp_1 requires 2 arguments
318 __gitcomp_1 ()
320         local c IFS=' '$'\t'$'\n'
321         for c in $1; do
322                 case "$c$2" in
323                 --*=*) printf %s$'\n' "$c$2" ;;
324                 *.)    printf %s$'\n' "$c$2" ;;
325                 *)     printf %s$'\n' "$c$2 " ;;
326                 esac
327         done
330 # __gitcomp accepts 1, 2, 3, or 4 arguments
331 # generates completion reply with compgen
332 __gitcomp ()
334         local cur="${COMP_WORDS[COMP_CWORD]}"
335         if [ $# -gt 2 ]; then
336                 cur="$3"
337         fi
338         case "$cur" in
339         --*=)
340                 COMPREPLY=()
341                 ;;
342         *)
343                 local IFS=$'\n'
344                 COMPREPLY=($(compgen -P "${2-}" \
345                         -W "$(__gitcomp_1 "${1-}" "${4-}")" \
346                         -- "$cur"))
347                 ;;
348         esac
351 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
352 __git_heads ()
354         local cmd i is_hash=y dir="$(__gitdir "${1-}")"
355         if [ -d "$dir" ]; then
356                 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
357                         refs/heads
358                 return
359         fi
360         for i in $(git ls-remote "${1-}" 2>/dev/null); do
361                 case "$is_hash,$i" in
362                 y,*) is_hash=n ;;
363                 n,*^{}) is_hash=y ;;
364                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
365                 n,*) is_hash=y; echo "$i" ;;
366                 esac
367         done
370 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
371 __git_tags ()
373         local cmd i is_hash=y dir="$(__gitdir "${1-}")"
374         if [ -d "$dir" ]; then
375                 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
376                         refs/tags
377                 return
378         fi
379         for i in $(git ls-remote "${1-}" 2>/dev/null); do
380                 case "$is_hash,$i" in
381                 y,*) is_hash=n ;;
382                 n,*^{}) is_hash=y ;;
383                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
384                 n,*) is_hash=y; echo "$i" ;;
385                 esac
386         done
389 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
390 # presence of 2nd argument means use the guess heuristic employed
391 # by checkout for tracking branches
392 __git_refs ()
394         local i is_hash=y dir="$(__gitdir "${1-}")" track="${2-}"
395         local cur="${COMP_WORDS[COMP_CWORD]}" format refs
396         if [ -d "$dir" ]; then
397                 case "$cur" in
398                 refs|refs/*)
399                         format="refname"
400                         refs="${cur%/*}"
401                         track=""
402                         ;;
403                 *)
404                         for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
405                                 if [ -e "$dir/$i" ]; then echo $i; fi
406                         done
407                         format="refname:short"
408                         refs="refs/tags refs/heads refs/remotes"
409                         ;;
410                 esac
411                 git --git-dir="$dir" for-each-ref --format="%($format)" \
412                         $refs
413                 if [ -n "$track" ]; then
414                         # employ the heuristic used by git checkout
415                         # Try to find a remote branch that matches the completion word
416                         # but only output if the branch name is unique
417                         local ref entry
418                         git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
419                                 "refs/remotes/" | \
420                         while read entry; do
421                                 eval "$entry"
422                                 ref="${ref#*/}"
423                                 if [[ "$ref" == "$cur"* ]]; then
424                                         echo "$ref"
425                                 fi
426                         done | uniq -u
427                 fi
428                 return
429         fi
430         for i in $(git ls-remote "$dir" 2>/dev/null); do
431                 case "$is_hash,$i" in
432                 y,*) is_hash=n ;;
433                 n,*^{}) is_hash=y ;;
434                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
435                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
436                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
437                 n,*) is_hash=y; echo "$i" ;;
438                 esac
439         done
442 # __git_refs2 requires 1 argument (to pass to __git_refs)
443 __git_refs2 ()
445         local i
446         for i in $(__git_refs "$1"); do
447                 echo "$i:$i"
448         done
451 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
452 __git_refs_remotes ()
454         local cmd i is_hash=y
455         for i in $(git ls-remote "$1" 2>/dev/null); do
456                 case "$is_hash,$i" in
457                 n,refs/heads/*)
458                         is_hash=y
459                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
460                         ;;
461                 y,*) is_hash=n ;;
462                 n,*^{}) is_hash=y ;;
463                 n,refs/tags/*) is_hash=y;;
464                 n,*) is_hash=y; ;;
465                 esac
466         done
469 __git_remotes ()
471         local i ngoff IFS=$'\n' d="$(__gitdir)"
472         shopt -q nullglob || ngoff=1
473         shopt -s nullglob
474         for i in "$d/remotes"/*; do
475                 echo ${i#$d/remotes/}
476         done
477         [ "$ngoff" ] && shopt -u nullglob
478         for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
479                 i="${i#remote.}"
480                 echo "${i/.url*/}"
481         done
484 __git_list_merge_strategies ()
486         git merge -s help 2>&1 |
487         sed -n -e '/[Aa]vailable strategies are: /,/^$/{
488                 s/\.$//
489                 s/.*://
490                 s/^[    ]*//
491                 s/[     ]*$//
492                 p
493         }'
496 __git_merge_strategies=
497 # 'git merge -s help' (and thus detection of the merge strategy
498 # list) fails, unfortunately, if run outside of any git working
499 # tree.  __git_merge_strategies is set to the empty string in
500 # that case, and the detection will be repeated the next time it
501 # is needed.
502 __git_compute_merge_strategies ()
504         : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
507 __git_complete_file ()
509         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
510         case "$cur" in
511         ?*:*)
512                 ref="${cur%%:*}"
513                 cur="${cur#*:}"
514                 case "$cur" in
515                 ?*/*)
516                         pfx="${cur%/*}"
517                         cur="${cur##*/}"
518                         ls="$ref:$pfx"
519                         pfx="$pfx/"
520                         ;;
521                 *)
522                         ls="$ref"
523                         ;;
524             esac
526                 case "$COMP_WORDBREAKS" in
527                 *:*) : great ;;
528                 *)   pfx="$ref:$pfx" ;;
529                 esac
531                 local IFS=$'\n'
532                 COMPREPLY=($(compgen -P "$pfx" \
533                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
534                                 | sed '/^100... blob /{
535                                            s,^.*        ,,
536                                            s,$, ,
537                                        }
538                                        /^120000 blob /{
539                                            s,^.*        ,,
540                                            s,$, ,
541                                        }
542                                        /^040000 tree /{
543                                            s,^.*        ,,
544                                            s,$,/,
545                                        }
546                                        s/^.*    //')" \
547                         -- "$cur"))
548                 ;;
549         *)
550                 __gitcomp "$(__git_refs)"
551                 ;;
552         esac
555 __git_complete_revlist ()
557         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
558         case "$cur" in
559         *...*)
560                 pfx="${cur%...*}..."
561                 cur="${cur#*...}"
562                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
563                 ;;
564         *..*)
565                 pfx="${cur%..*}.."
566                 cur="${cur#*..}"
567                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
568                 ;;
569         *)
570                 __gitcomp "$(__git_refs)"
571                 ;;
572         esac
575 __git_complete_remote_or_refspec ()
577         local cmd="${COMP_WORDS[1]}"
578         local cur="${COMP_WORDS[COMP_CWORD]}"
579         local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
580         while [ $c -lt $COMP_CWORD ]; do
581                 i="${COMP_WORDS[c]}"
582                 case "$i" in
583                 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
584                 --all)
585                         case "$cmd" in
586                         push) no_complete_refspec=1 ;;
587                         fetch)
588                                 COMPREPLY=()
589                                 return
590                                 ;;
591                         *) ;;
592                         esac
593                         ;;
594                 -*) ;;
595                 *) remote="$i"; break ;;
596                 esac
597                 c=$((++c))
598         done
599         if [ -z "$remote" ]; then
600                 __gitcomp "$(__git_remotes)"
601                 return
602         fi
603         if [ $no_complete_refspec = 1 ]; then
604                 COMPREPLY=()
605                 return
606         fi
607         [ "$remote" = "." ] && remote=
608         case "$cur" in
609         *:*)
610                 case "$COMP_WORDBREAKS" in
611                 *:*) : great ;;
612                 *)   pfx="${cur%%:*}:" ;;
613                 esac
614                 cur="${cur#*:}"
615                 lhs=0
616                 ;;
617         +*)
618                 pfx="+"
619                 cur="${cur#+}"
620                 ;;
621         esac
622         case "$cmd" in
623         fetch)
624                 if [ $lhs = 1 ]; then
625                         __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
626                 else
627                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
628                 fi
629                 ;;
630         pull)
631                 if [ $lhs = 1 ]; then
632                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
633                 else
634                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
635                 fi
636                 ;;
637         push)
638                 if [ $lhs = 1 ]; then
639                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
640                 else
641                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
642                 fi
643                 ;;
644         esac
647 __git_complete_strategy ()
649         __git_compute_merge_strategies
650         case "${COMP_WORDS[COMP_CWORD-1]}" in
651         -s|--strategy)
652                 __gitcomp "$__git_merge_strategies"
653                 return 0
654         esac
655         local cur="${COMP_WORDS[COMP_CWORD]}"
656         case "$cur" in
657         --strategy=*)
658                 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
659                 return 0
660                 ;;
661         esac
662         return 1
665 __git_list_all_commands ()
667         local i IFS=" "$'\n'
668         for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
669         do
670                 case $i in
671                 *--*)             : helper pattern;;
672                 *) echo $i;;
673                 esac
674         done
677 __git_all_commands=
678 __git_compute_all_commands ()
680         : ${__git_all_commands:=$(__git_list_all_commands)}
683 __git_list_porcelain_commands ()
685         local i IFS=" "$'\n'
686         __git_compute_all_commands
687         for i in "help" $__git_all_commands
688         do
689                 case $i in
690                 *--*)             : helper pattern;;
691                 applymbox)        : ask gittus;;
692                 applypatch)       : ask gittus;;
693                 archimport)       : import;;
694                 cat-file)         : plumbing;;
695                 check-attr)       : plumbing;;
696                 check-ref-format) : plumbing;;
697                 checkout-index)   : plumbing;;
698                 commit-tree)      : plumbing;;
699                 count-objects)    : infrequent;;
700                 cvsexportcommit)  : export;;
701                 cvsimport)        : import;;
702                 cvsserver)        : daemon;;
703                 daemon)           : daemon;;
704                 diff-files)       : plumbing;;
705                 diff-index)       : plumbing;;
706                 diff-tree)        : plumbing;;
707                 fast-import)      : import;;
708                 fast-export)      : export;;
709                 fsck-objects)     : plumbing;;
710                 fetch-pack)       : plumbing;;
711                 fmt-merge-msg)    : plumbing;;
712                 for-each-ref)     : plumbing;;
713                 hash-object)      : plumbing;;
714                 http-*)           : transport;;
715                 index-pack)       : plumbing;;
716                 init-db)          : deprecated;;
717                 local-fetch)      : plumbing;;
718                 lost-found)       : infrequent;;
719                 ls-files)         : plumbing;;
720                 ls-remote)        : plumbing;;
721                 ls-tree)          : plumbing;;
722                 mailinfo)         : plumbing;;
723                 mailsplit)        : plumbing;;
724                 merge-*)          : plumbing;;
725                 mktree)           : plumbing;;
726                 mktag)            : plumbing;;
727                 pack-objects)     : plumbing;;
728                 pack-redundant)   : plumbing;;
729                 pack-refs)        : plumbing;;
730                 parse-remote)     : plumbing;;
731                 patch-id)         : plumbing;;
732                 peek-remote)      : plumbing;;
733                 prune)            : plumbing;;
734                 prune-packed)     : plumbing;;
735                 quiltimport)      : import;;
736                 read-tree)        : plumbing;;
737                 receive-pack)     : plumbing;;
738                 reflog)           : plumbing;;
739                 remote-*)         : transport;;
740                 repo-config)      : deprecated;;
741                 rerere)           : plumbing;;
742                 rev-list)         : plumbing;;
743                 rev-parse)        : plumbing;;
744                 runstatus)        : plumbing;;
745                 sh-setup)         : internal;;
746                 shell)            : daemon;;
747                 show-ref)         : plumbing;;
748                 send-pack)        : plumbing;;
749                 show-index)       : plumbing;;
750                 ssh-*)            : transport;;
751                 stripspace)       : plumbing;;
752                 symbolic-ref)     : plumbing;;
753                 tar-tree)         : deprecated;;
754                 unpack-file)      : plumbing;;
755                 unpack-objects)   : plumbing;;
756                 update-index)     : plumbing;;
757                 update-ref)       : plumbing;;
758                 update-server-info) : daemon;;
759                 upload-archive)   : plumbing;;
760                 upload-pack)      : plumbing;;
761                 write-tree)       : plumbing;;
762                 var)              : infrequent;;
763                 verify-pack)      : infrequent;;
764                 verify-tag)       : plumbing;;
765                 *) echo $i;;
766                 esac
767         done
770 __git_porcelain_commands=
771 __git_compute_porcelain_commands ()
773         __git_compute_all_commands
774         : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
777 __git_pretty_aliases ()
779         local i IFS=$'\n'
780         for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
781                 case "$i" in
782                 pretty.*)
783                         i="${i#pretty.}"
784                         echo "${i/ */}"
785                         ;;
786                 esac
787         done
790 __git_aliases ()
792         local i IFS=$'\n'
793         for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
794                 case "$i" in
795                 alias.*)
796                         i="${i#alias.}"
797                         echo "${i/ */}"
798                         ;;
799                 esac
800         done
803 # __git_aliased_command requires 1 argument
804 __git_aliased_command ()
806         local word cmdline=$(git --git-dir="$(__gitdir)" \
807                 config --get "alias.$1")
808         for word in $cmdline; do
809                 case "$word" in
810                 \!gitk|gitk)
811                         echo "gitk"
812                         return
813                         ;;
814                 \!*)    : shell command alias ;;
815                 -*)     : option ;;
816                 *=*)    : setting env ;;
817                 git)    : git itself ;;
818                 *)
819                         echo "$word"
820                         return
821                 esac
822         done
825 # __git_find_on_cmdline requires 1 argument
826 __git_find_on_cmdline ()
828         local word subcommand c=1
830         while [ $c -lt $COMP_CWORD ]; do
831                 word="${COMP_WORDS[c]}"
832                 for subcommand in $1; do
833                         if [ "$subcommand" = "$word" ]; then
834                                 echo "$subcommand"
835                                 return
836                         fi
837                 done
838                 c=$((++c))
839         done
842 __git_has_doubledash ()
844         local c=1
845         while [ $c -lt $COMP_CWORD ]; do
846                 if [ "--" = "${COMP_WORDS[c]}" ]; then
847                         return 0
848                 fi
849                 c=$((++c))
850         done
851         return 1
854 __git_whitespacelist="nowarn warn error error-all fix"
856 _git_am ()
858         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
859         if [ -d "$dir"/rebase-apply ]; then
860                 __gitcomp "--skip --continue --resolved --abort"
861                 return
862         fi
863         case "$cur" in
864         --whitespace=*)
865                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
866                 return
867                 ;;
868         --*)
869                 __gitcomp "
870                         --3way --committer-date-is-author-date --ignore-date
871                         --ignore-whitespace --ignore-space-change
872                         --interactive --keep --no-utf8 --signoff --utf8
873                         --whitespace= --scissors
874                         "
875                 return
876         esac
877         COMPREPLY=()
880 _git_apply ()
882         local cur="${COMP_WORDS[COMP_CWORD]}"
883         case "$cur" in
884         --whitespace=*)
885                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
886                 return
887                 ;;
888         --*)
889                 __gitcomp "
890                         --stat --numstat --summary --check --index
891                         --cached --index-info --reverse --reject --unidiff-zero
892                         --apply --no-add --exclude=
893                         --ignore-whitespace --ignore-space-change
894                         --whitespace= --inaccurate-eof --verbose
895                         "
896                 return
897         esac
898         COMPREPLY=()
901 _git_add ()
903         __git_has_doubledash && return
905         local cur="${COMP_WORDS[COMP_CWORD]}"
906         case "$cur" in
907         --*)
908                 __gitcomp "
909                         --interactive --refresh --patch --update --dry-run
910                         --ignore-errors --intent-to-add
911                         "
912                 return
913         esac
914         COMPREPLY=()
917 _git_archive ()
919         local cur="${COMP_WORDS[COMP_CWORD]}"
920         case "$cur" in
921         --format=*)
922                 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
923                 return
924                 ;;
925         --remote=*)
926                 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
927                 return
928                 ;;
929         --*)
930                 __gitcomp "
931                         --format= --list --verbose
932                         --prefix= --remote= --exec=
933                         "
934                 return
935                 ;;
936         esac
937         __git_complete_file
940 _git_bisect ()
942         __git_has_doubledash && return
944         local subcommands="start bad good skip reset visualize replay log run"
945         local subcommand="$(__git_find_on_cmdline "$subcommands")"
946         if [ -z "$subcommand" ]; then
947                 if [ -f "$(__gitdir)"/BISECT_START ]; then
948                         __gitcomp "$subcommands"
949                 else
950                         __gitcomp "replay start"
951                 fi
952                 return
953         fi
955         case "$subcommand" in
956         bad|good|reset|skip|start)
957                 __gitcomp "$(__git_refs)"
958                 ;;
959         *)
960                 COMPREPLY=()
961                 ;;
962         esac
965 _git_branch ()
967         local i c=1 only_local_ref="n" has_r="n"
969         while [ $c -lt $COMP_CWORD ]; do
970                 i="${COMP_WORDS[c]}"
971                 case "$i" in
972                 -d|-m)  only_local_ref="y" ;;
973                 -r)     has_r="y" ;;
974                 esac
975                 c=$((++c))
976         done
978         case "${COMP_WORDS[COMP_CWORD]}" in
979         --*)
980                 __gitcomp "
981                         --color --no-color --verbose --abbrev= --no-abbrev
982                         --track --no-track --contains --merged --no-merged
983                         --set-upstream
984                         "
985                 ;;
986         *)
987                 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
988                         __gitcomp "$(__git_heads)"
989                 else
990                         __gitcomp "$(__git_refs)"
991                 fi
992                 ;;
993         esac
996 _git_bundle ()
998         local cmd="${COMP_WORDS[2]}"
999         case "$COMP_CWORD" in
1000         2)
1001                 __gitcomp "create list-heads verify unbundle"
1002                 ;;
1003         3)
1004                 # looking for a file
1005                 ;;
1006         *)
1007                 case "$cmd" in
1008                         create)
1009                                 __git_complete_revlist
1010                         ;;
1011                 esac
1012                 ;;
1013         esac
1016 _git_checkout ()
1018         __git_has_doubledash && return
1020         local cur="${COMP_WORDS[COMP_CWORD]}"
1021         case "$cur" in
1022         --conflict=*)
1023                 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1024                 ;;
1025         --*)
1026                 __gitcomp "
1027                         --quiet --ours --theirs --track --no-track --merge
1028                         --conflict= --orphan --patch
1029                         "
1030                 ;;
1031         *)
1032                 # check if --track, --no-track, or --no-guess was specified
1033                 # if so, disable DWIM mode
1034                 local flags="--track --no-track --no-guess" track=1
1035                 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1036                         track=''
1037                 fi
1038                 __gitcomp "$(__git_refs '' $track)"
1039                 ;;
1040         esac
1043 _git_cherry ()
1045         __gitcomp "$(__git_refs)"
1048 _git_cherry_pick ()
1050         local cur="${COMP_WORDS[COMP_CWORD]}"
1051         case "$cur" in
1052         --*)
1053                 __gitcomp "--edit --no-commit"
1054                 ;;
1055         *)
1056                 __gitcomp "$(__git_refs)"
1057                 ;;
1058         esac
1061 _git_clean ()
1063         __git_has_doubledash && return
1065         local cur="${COMP_WORDS[COMP_CWORD]}"
1066         case "$cur" in
1067         --*)
1068                 __gitcomp "--dry-run --quiet"
1069                 return
1070                 ;;
1071         esac
1072         COMPREPLY=()
1075 _git_clone ()
1077         local cur="${COMP_WORDS[COMP_CWORD]}"
1078         case "$cur" in
1079         --*)
1080                 __gitcomp "
1081                         --local
1082                         --no-hardlinks
1083                         --shared
1084                         --reference
1085                         --quiet
1086                         --no-checkout
1087                         --bare
1088                         --mirror
1089                         --origin
1090                         --upload-pack
1091                         --template=
1092                         --depth
1093                         "
1094                 return
1095                 ;;
1096         esac
1097         COMPREPLY=()
1100 _git_commit ()
1102         __git_has_doubledash && return
1104         local cur="${COMP_WORDS[COMP_CWORD]}"
1105         case "$cur" in
1106         --cleanup=*)
1107                 __gitcomp "default strip verbatim whitespace
1108                         " "" "${cur##--cleanup=}"
1109                 return
1110                 ;;
1111         --reuse-message=*)
1112                 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1113                 return
1114                 ;;
1115         --reedit-message=*)
1116                 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1117                 return
1118                 ;;
1119         --untracked-files=*)
1120                 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1121                 return
1122                 ;;
1123         --*)
1124                 __gitcomp "
1125                         --all --author= --signoff --verify --no-verify
1126                         --edit --amend --include --only --interactive
1127                         --dry-run --reuse-message= --reedit-message=
1128                         --reset-author --file= --message= --template=
1129                         --cleanup= --untracked-files --untracked-files=
1130                         --verbose --quiet
1131                         "
1132                 return
1133         esac
1134         COMPREPLY=()
1137 _git_describe ()
1139         local cur="${COMP_WORDS[COMP_CWORD]}"
1140         case "$cur" in
1141         --*)
1142                 __gitcomp "
1143                         --all --tags --contains --abbrev= --candidates=
1144                         --exact-match --debug --long --match --always
1145                         "
1146                 return
1147         esac
1148         __gitcomp "$(__git_refs)"
1151 __git_diff_common_options="--stat --numstat --shortstat --summary
1152                         --patch-with-stat --name-only --name-status --color
1153                         --no-color --color-words --no-renames --check
1154                         --full-index --binary --abbrev --diff-filter=
1155                         --find-copies-harder
1156                         --text --ignore-space-at-eol --ignore-space-change
1157                         --ignore-all-space --exit-code --quiet --ext-diff
1158                         --no-ext-diff
1159                         --no-prefix --src-prefix= --dst-prefix=
1160                         --inter-hunk-context=
1161                         --patience
1162                         --raw
1163                         --dirstat --dirstat= --dirstat-by-file
1164                         --dirstat-by-file= --cumulative
1167 _git_diff ()
1169         __git_has_doubledash && return
1171         local cur="${COMP_WORDS[COMP_CWORD]}"
1172         case "$cur" in
1173         --*)
1174                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1175                         --base --ours --theirs --no-index
1176                         $__git_diff_common_options
1177                         "
1178                 return
1179                 ;;
1180         esac
1181         __git_complete_file
1184 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1185                         tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1188 _git_difftool ()
1190         __git_has_doubledash && return
1192         local cur="${COMP_WORDS[COMP_CWORD]}"
1193         case "$cur" in
1194         --tool=*)
1195                 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1196                 return
1197                 ;;
1198         --*)
1199                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1200                         --base --ours --theirs
1201                         --no-renames --diff-filter= --find-copies-harder
1202                         --relative --ignore-submodules
1203                         --tool="
1204                 return
1205                 ;;
1206         esac
1207         __git_complete_file
1210 __git_fetch_options="
1211         --quiet --verbose --append --upload-pack --force --keep --depth=
1212         --tags --no-tags --all --prune --dry-run
1215 _git_fetch ()
1217         local cur="${COMP_WORDS[COMP_CWORD]}"
1218         case "$cur" in
1219         --*)
1220                 __gitcomp "$__git_fetch_options"
1221                 return
1222                 ;;
1223         esac
1224         __git_complete_remote_or_refspec
1227 _git_format_patch ()
1229         local cur="${COMP_WORDS[COMP_CWORD]}"
1230         case "$cur" in
1231         --thread=*)
1232                 __gitcomp "
1233                         deep shallow
1234                         " "" "${cur##--thread=}"
1235                 return
1236                 ;;
1237         --*)
1238                 __gitcomp "
1239                         --stdout --attach --no-attach --thread --thread=
1240                         --output-directory
1241                         --numbered --start-number
1242                         --numbered-files
1243                         --keep-subject
1244                         --signoff --signature --no-signature
1245                         --in-reply-to= --cc=
1246                         --full-index --binary
1247                         --not --all
1248                         --cover-letter
1249                         --no-prefix --src-prefix= --dst-prefix=
1250                         --inline --suffix= --ignore-if-in-upstream
1251                         --subject-prefix=
1252                         "
1253                 return
1254                 ;;
1255         esac
1256         __git_complete_revlist
1259 _git_fsck ()
1261         local cur="${COMP_WORDS[COMP_CWORD]}"
1262         case "$cur" in
1263         --*)
1264                 __gitcomp "
1265                         --tags --root --unreachable --cache --no-reflogs --full
1266                         --strict --verbose --lost-found
1267                         "
1268                 return
1269                 ;;
1270         esac
1271         COMPREPLY=()
1274 _git_gc ()
1276         local cur="${COMP_WORDS[COMP_CWORD]}"
1277         case "$cur" in
1278         --*)
1279                 __gitcomp "--prune --aggressive"
1280                 return
1281                 ;;
1282         esac
1283         COMPREPLY=()
1286 _git_gitk ()
1288         _gitk
1291 _git_grep ()
1293         __git_has_doubledash && return
1295         local cur="${COMP_WORDS[COMP_CWORD]}"
1296         case "$cur" in
1297         --*)
1298                 __gitcomp "
1299                         --cached
1300                         --text --ignore-case --word-regexp --invert-match
1301                         --full-name
1302                         --extended-regexp --basic-regexp --fixed-strings
1303                         --files-with-matches --name-only
1304                         --files-without-match
1305                         --max-depth
1306                         --count
1307                         --and --or --not --all-match
1308                         "
1309                 return
1310                 ;;
1311         esac
1313         __gitcomp "$(__git_refs)"
1316 _git_help ()
1318         local cur="${COMP_WORDS[COMP_CWORD]}"
1319         case "$cur" in
1320         --*)
1321                 __gitcomp "--all --info --man --web"
1322                 return
1323                 ;;
1324         esac
1325         __git_compute_all_commands
1326         __gitcomp "$__git_all_commands
1327                 attributes cli core-tutorial cvs-migration
1328                 diffcore gitk glossary hooks ignore modules
1329                 repository-layout tutorial tutorial-2
1330                 workflows
1331                 "
1334 _git_init ()
1336         local cur="${COMP_WORDS[COMP_CWORD]}"
1337         case "$cur" in
1338         --shared=*)
1339                 __gitcomp "
1340                         false true umask group all world everybody
1341                         " "" "${cur##--shared=}"
1342                 return
1343                 ;;
1344         --*)
1345                 __gitcomp "--quiet --bare --template= --shared --shared="
1346                 return
1347                 ;;
1348         esac
1349         COMPREPLY=()
1352 _git_ls_files ()
1354         __git_has_doubledash && return
1356         local cur="${COMP_WORDS[COMP_CWORD]}"
1357         case "$cur" in
1358         --*)
1359                 __gitcomp "--cached --deleted --modified --others --ignored
1360                         --stage --directory --no-empty-directory --unmerged
1361                         --killed --exclude= --exclude-from=
1362                         --exclude-per-directory= --exclude-standard
1363                         --error-unmatch --with-tree= --full-name
1364                         --abbrev --ignored --exclude-per-directory
1365                         "
1366                 return
1367                 ;;
1368         esac
1369         COMPREPLY=()
1372 _git_ls_remote ()
1374         __gitcomp "$(__git_remotes)"
1377 _git_ls_tree ()
1379         __git_complete_file
1382 # Options that go well for log, shortlog and gitk
1383 __git_log_common_options="
1384         --not --all
1385         --branches --tags --remotes
1386         --first-parent --merges --no-merges
1387         --max-count=
1388         --max-age= --since= --after=
1389         --min-age= --until= --before=
1391 # Options that go well for log and gitk (not shortlog)
1392 __git_log_gitk_options="
1393         --dense --sparse --full-history
1394         --simplify-merges --simplify-by-decoration
1395         --left-right
1397 # Options that go well for log and shortlog (not gitk)
1398 __git_log_shortlog_options="
1399         --author= --committer= --grep=
1400         --all-match
1403 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1404 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1406 _git_log ()
1408         __git_has_doubledash && return
1410         local cur="${COMP_WORDS[COMP_CWORD]}"
1411         local g="$(git rev-parse --git-dir 2>/dev/null)"
1412         local merge=""
1413         if [ -f "$g/MERGE_HEAD" ]; then
1414                 merge="--merge"
1415         fi
1416         case "$cur" in
1417         --pretty=*)
1418                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1419                         " "" "${cur##--pretty=}"
1420                 return
1421                 ;;
1422         --format=*)
1423                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1424                         " "" "${cur##--format=}"
1425                 return
1426                 ;;
1427         --date=*)
1428                 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1429                 return
1430                 ;;
1431         --decorate=*)
1432                 __gitcomp "long short" "" "${cur##--decorate=}"
1433                 return
1434                 ;;
1435         --*)
1436                 __gitcomp "
1437                         $__git_log_common_options
1438                         $__git_log_shortlog_options
1439                         $__git_log_gitk_options
1440                         --root --topo-order --date-order --reverse
1441                         --follow --full-diff
1442                         --abbrev-commit --abbrev=
1443                         --relative-date --date=
1444                         --pretty= --format= --oneline
1445                         --cherry-pick
1446                         --graph
1447                         --decorate --decorate=
1448                         --walk-reflogs
1449                         --parents --children
1450                         $merge
1451                         $__git_diff_common_options
1452                         --pickaxe-all --pickaxe-regex
1453                         "
1454                 return
1455                 ;;
1456         esac
1457         __git_complete_revlist
1460 __git_merge_options="
1461         --no-commit --no-stat --log --no-log --squash --strategy
1462         --commit --stat --no-squash --ff --no-ff --ff-only
1465 _git_merge ()
1467         __git_complete_strategy && return
1469         local cur="${COMP_WORDS[COMP_CWORD]}"
1470         case "$cur" in
1471         --*)
1472                 __gitcomp "$__git_merge_options"
1473                 return
1474         esac
1475         __gitcomp "$(__git_refs)"
1478 _git_mergetool ()
1480         local cur="${COMP_WORDS[COMP_CWORD]}"
1481         case "$cur" in
1482         --tool=*)
1483                 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1484                 return
1485                 ;;
1486         --*)
1487                 __gitcomp "--tool="
1488                 return
1489                 ;;
1490         esac
1491         COMPREPLY=()
1494 _git_merge_base ()
1496         __gitcomp "$(__git_refs)"
1499 _git_mv ()
1501         local cur="${COMP_WORDS[COMP_CWORD]}"
1502         case "$cur" in
1503         --*)
1504                 __gitcomp "--dry-run"
1505                 return
1506                 ;;
1507         esac
1508         COMPREPLY=()
1511 _git_name_rev ()
1513         __gitcomp "--tags --all --stdin"
1516 _git_notes ()
1518         local subcommands='add append copy edit list prune remove show'
1519         local subcommand="$(__git_find_on_cmdline "$subcommands")"
1520         local cur="${COMP_WORDS[COMP_CWORD]}"
1522         case "$subcommand,$cur" in
1523         ,--*)
1524                 __gitcomp '--ref'
1525                 ;;
1526         ,*)
1527                 case "${COMP_WORDS[COMP_CWORD-1]}" in
1528                 --ref)
1529                         __gitcomp "$(__git_refs)"
1530                         ;;
1531                 *)
1532                         __gitcomp "$subcommands --ref"
1533                         ;;
1534                 esac
1535                 ;;
1536         add,--reuse-message=*|append,--reuse-message=*)
1537                 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1538                 ;;
1539         add,--reedit-message=*|append,--reedit-message=*)
1540                 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1541                 ;;
1542         add,--*|append,--*)
1543                 __gitcomp '--file= --message= --reedit-message=
1544                                 --reuse-message='
1545                 ;;
1546         copy,--*)
1547                 __gitcomp '--stdin'
1548                 ;;
1549         prune,--*)
1550                 __gitcomp '--dry-run --verbose'
1551                 ;;
1552         prune,*)
1553                 ;;
1554         *)
1555                 case "${COMP_WORDS[COMP_CWORD-1]}" in
1556                 -m|-F)
1557                         ;;
1558                 *)
1559                         __gitcomp "$(__git_refs)"
1560                         ;;
1561                 esac
1562                 ;;
1563         esac
1566 _git_pull ()
1568         __git_complete_strategy && return
1570         local cur="${COMP_WORDS[COMP_CWORD]}"
1571         case "$cur" in
1572         --*)
1573                 __gitcomp "
1574                         --rebase --no-rebase
1575                         $__git_merge_options
1576                         $__git_fetch_options
1577                 "
1578                 return
1579                 ;;
1580         esac
1581         __git_complete_remote_or_refspec
1584 _git_push ()
1586         local cur="${COMP_WORDS[COMP_CWORD]}"
1587         case "${COMP_WORDS[COMP_CWORD-1]}" in
1588         --repo)
1589                 __gitcomp "$(__git_remotes)"
1590                 return
1591         esac
1592         case "$cur" in
1593         --repo=*)
1594                 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1595                 return
1596                 ;;
1597         --*)
1598                 __gitcomp "
1599                         --all --mirror --tags --dry-run --force --verbose
1600                         --receive-pack= --repo=
1601                 "
1602                 return
1603                 ;;
1604         esac
1605         __git_complete_remote_or_refspec
1608 _git_rebase ()
1610         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1611         if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1612                 __gitcomp "--continue --skip --abort"
1613                 return
1614         fi
1615         __git_complete_strategy && return
1616         case "$cur" in
1617         --whitespace=*)
1618                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1619                 return
1620                 ;;
1621         --*)
1622                 __gitcomp "
1623                         --onto --merge --strategy --interactive
1624                         --preserve-merges --stat --no-stat
1625                         --committer-date-is-author-date --ignore-date
1626                         --ignore-whitespace --whitespace=
1627                         --autosquash
1628                         "
1630                 return
1631         esac
1632         __gitcomp "$(__git_refs)"
1635 __git_send_email_confirm_options="always never auto cc compose"
1636 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1638 _git_send_email ()
1640         local cur="${COMP_WORDS[COMP_CWORD]}"
1641         case "$cur" in
1642         --confirm=*)
1643                 __gitcomp "
1644                         $__git_send_email_confirm_options
1645                         " "" "${cur##--confirm=}"
1646                 return
1647                 ;;
1648         --suppress-cc=*)
1649                 __gitcomp "
1650                         $__git_send_email_suppresscc_options
1651                         " "" "${cur##--suppress-cc=}"
1653                 return
1654                 ;;
1655         --smtp-encryption=*)
1656                 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1657                 return
1658                 ;;
1659         --*)
1660                 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1661                         --compose --confirm= --dry-run --envelope-sender
1662                         --from --identity
1663                         --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1664                         --no-suppress-from --no-thread --quiet
1665                         --signed-off-by-cc --smtp-pass --smtp-server
1666                         --smtp-server-port --smtp-encryption= --smtp-user
1667                         --subject --suppress-cc= --suppress-from --thread --to
1668                         --validate --no-validate"
1669                 return
1670                 ;;
1671         esac
1672         COMPREPLY=()
1675 _git_stage ()
1677         _git_add
1680 __git_config_get_set_variables ()
1682         local prevword word config_file= c=$COMP_CWORD
1683         while [ $c -gt 1 ]; do
1684                 word="${COMP_WORDS[c]}"
1685                 case "$word" in
1686                 --global|--system|--file=*)
1687                         config_file="$word"
1688                         break
1689                         ;;
1690                 -f|--file)
1691                         config_file="$word $prevword"
1692                         break
1693                         ;;
1694                 esac
1695                 prevword=$word
1696                 c=$((--c))
1697         done
1699         git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1700         while read line
1701         do
1702                 case "$line" in
1703                 *.*=*)
1704                         echo "${line/=*/}"
1705                         ;;
1706                 esac
1707         done
1710 _git_config ()
1712         local cur="${COMP_WORDS[COMP_CWORD]}"
1713         local prv="${COMP_WORDS[COMP_CWORD-1]}"
1714         case "$prv" in
1715         branch.*.remote)
1716                 __gitcomp "$(__git_remotes)"
1717                 return
1718                 ;;
1719         branch.*.merge)
1720                 __gitcomp "$(__git_refs)"
1721                 return
1722                 ;;
1723         remote.*.fetch)
1724                 local remote="${prv#remote.}"
1725                 remote="${remote%.fetch}"
1726                 __gitcomp "$(__git_refs_remotes "$remote")"
1727                 return
1728                 ;;
1729         remote.*.push)
1730                 local remote="${prv#remote.}"
1731                 remote="${remote%.push}"
1732                 __gitcomp "$(git --git-dir="$(__gitdir)" \
1733                         for-each-ref --format='%(refname):%(refname)' \
1734                         refs/heads)"
1735                 return
1736                 ;;
1737         pull.twohead|pull.octopus)
1738                 __git_compute_merge_strategies
1739                 __gitcomp "$__git_merge_strategies"
1740                 return
1741                 ;;
1742         color.branch|color.diff|color.interactive|\
1743         color.showbranch|color.status|color.ui)
1744                 __gitcomp "always never auto"
1745                 return
1746                 ;;
1747         color.pager)
1748                 __gitcomp "false true"
1749                 return
1750                 ;;
1751         color.*.*)
1752                 __gitcomp "
1753                         normal black red green yellow blue magenta cyan white
1754                         bold dim ul blink reverse
1755                         "
1756                 return
1757                 ;;
1758         help.format)
1759                 __gitcomp "man info web html"
1760                 return
1761                 ;;
1762         log.date)
1763                 __gitcomp "$__git_log_date_formats"
1764                 return
1765                 ;;
1766         sendemail.aliasesfiletype)
1767                 __gitcomp "mutt mailrc pine elm gnus"
1768                 return
1769                 ;;
1770         sendemail.confirm)
1771                 __gitcomp "$__git_send_email_confirm_options"
1772                 return
1773                 ;;
1774         sendemail.suppresscc)
1775                 __gitcomp "$__git_send_email_suppresscc_options"
1776                 return
1777                 ;;
1778         --get|--get-all|--unset|--unset-all)
1779                 __gitcomp "$(__git_config_get_set_variables)"
1780                 return
1781                 ;;
1782         *.*)
1783                 COMPREPLY=()
1784                 return
1785                 ;;
1786         esac
1787         case "$cur" in
1788         --*)
1789                 __gitcomp "
1790                         --global --system --file=
1791                         --list --replace-all
1792                         --get --get-all --get-regexp
1793                         --add --unset --unset-all
1794                         --remove-section --rename-section
1795                         "
1796                 return
1797                 ;;
1798         branch.*.*)
1799                 local pfx="${cur%.*}."
1800                 cur="${cur##*.}"
1801                 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1802                 return
1803                 ;;
1804         branch.*)
1805                 local pfx="${cur%.*}."
1806                 cur="${cur#*.}"
1807                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1808                 return
1809                 ;;
1810         guitool.*.*)
1811                 local pfx="${cur%.*}."
1812                 cur="${cur##*.}"
1813                 __gitcomp "
1814                         argprompt cmd confirm needsfile noconsole norescan
1815                         prompt revprompt revunmerged title
1816                         " "$pfx" "$cur"
1817                 return
1818                 ;;
1819         difftool.*.*)
1820                 local pfx="${cur%.*}."
1821                 cur="${cur##*.}"
1822                 __gitcomp "cmd path" "$pfx" "$cur"
1823                 return
1824                 ;;
1825         man.*.*)
1826                 local pfx="${cur%.*}."
1827                 cur="${cur##*.}"
1828                 __gitcomp "cmd path" "$pfx" "$cur"
1829                 return
1830                 ;;
1831         mergetool.*.*)
1832                 local pfx="${cur%.*}."
1833                 cur="${cur##*.}"
1834                 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1835                 return
1836                 ;;
1837         pager.*)
1838                 local pfx="${cur%.*}."
1839                 cur="${cur#*.}"
1840                 __git_compute_all_commands
1841                 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1842                 return
1843                 ;;
1844         remote.*.*)
1845                 local pfx="${cur%.*}."
1846                 cur="${cur##*.}"
1847                 __gitcomp "
1848                         url proxy fetch push mirror skipDefaultUpdate
1849                         receivepack uploadpack tagopt pushurl
1850                         " "$pfx" "$cur"
1851                 return
1852                 ;;
1853         remote.*)
1854                 local pfx="${cur%.*}."
1855                 cur="${cur#*.}"
1856                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1857                 return
1858                 ;;
1859         url.*.*)
1860                 local pfx="${cur%.*}."
1861                 cur="${cur##*.}"
1862                 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1863                 return
1864                 ;;
1865         esac
1866         __gitcomp "
1867                 add.ignoreErrors
1868                 advice.commitBeforeMerge
1869                 advice.detachedHead
1870                 advice.implicitIdentity
1871                 advice.pushNonFastForward
1872                 advice.resolveConflict
1873                 advice.statusHints
1874                 alias.
1875                 am.keepcr
1876                 apply.ignorewhitespace
1877                 apply.whitespace
1878                 branch.autosetupmerge
1879                 branch.autosetuprebase
1880                 browser.
1881                 clean.requireForce
1882                 color.branch
1883                 color.branch.current
1884                 color.branch.local
1885                 color.branch.plain
1886                 color.branch.remote
1887                 color.decorate.HEAD
1888                 color.decorate.branch
1889                 color.decorate.remoteBranch
1890                 color.decorate.stash
1891                 color.decorate.tag
1892                 color.diff
1893                 color.diff.commit
1894                 color.diff.frag
1895                 color.diff.func
1896                 color.diff.meta
1897                 color.diff.new
1898                 color.diff.old
1899                 color.diff.plain
1900                 color.diff.whitespace
1901                 color.grep
1902                 color.grep.context
1903                 color.grep.filename
1904                 color.grep.function
1905                 color.grep.linenumber
1906                 color.grep.match
1907                 color.grep.selected
1908                 color.grep.separator
1909                 color.interactive
1910                 color.interactive.error
1911                 color.interactive.header
1912                 color.interactive.help
1913                 color.interactive.prompt
1914                 color.pager
1915                 color.showbranch
1916                 color.status
1917                 color.status.added
1918                 color.status.changed
1919                 color.status.header
1920                 color.status.nobranch
1921                 color.status.untracked
1922                 color.status.updated
1923                 color.ui
1924                 commit.status
1925                 commit.template
1926                 core.abbrevguard
1927                 core.askpass
1928                 core.attributesfile
1929                 core.autocrlf
1930                 core.bare
1931                 core.bigFileThreshold
1932                 core.compression
1933                 core.createObject
1934                 core.deltaBaseCacheLimit
1935                 core.editor
1936                 core.eol
1937                 core.excludesfile
1938                 core.fileMode
1939                 core.fsyncobjectfiles
1940                 core.gitProxy
1941                 core.ignoreCygwinFSTricks
1942                 core.ignoreStat
1943                 core.ignorecase
1944                 core.logAllRefUpdates
1945                 core.loosecompression
1946                 core.notesRef
1947                 core.packedGitLimit
1948                 core.packedGitWindowSize
1949                 core.pager
1950                 core.preferSymlinkRefs
1951                 core.preloadindex
1952                 core.quotepath
1953                 core.repositoryFormatVersion
1954                 core.safecrlf
1955                 core.sharedRepository
1956                 core.sparseCheckout
1957                 core.symlinks
1958                 core.trustctime
1959                 core.warnAmbiguousRefs
1960                 core.whitespace
1961                 core.worktree
1962                 diff.autorefreshindex
1963                 diff.external
1964                 diff.ignoreSubmodules
1965                 diff.mnemonicprefix
1966                 diff.noprefix
1967                 diff.renameLimit
1968                 diff.renames
1969                 diff.suppressBlankEmpty
1970                 diff.tool
1971                 diff.wordRegex
1972                 difftool.
1973                 difftool.prompt
1974                 fetch.recurseSubmodules
1975                 fetch.unpackLimit
1976                 format.attach
1977                 format.cc
1978                 format.headers
1979                 format.numbered
1980                 format.pretty
1981                 format.signature
1982                 format.signoff
1983                 format.subjectprefix
1984                 format.suffix
1985                 format.thread
1986                 format.to
1987                 gc.
1988                 gc.aggressiveWindow
1989                 gc.auto
1990                 gc.autopacklimit
1991                 gc.packrefs
1992                 gc.pruneexpire
1993                 gc.reflogexpire
1994                 gc.reflogexpireunreachable
1995                 gc.rerereresolved
1996                 gc.rerereunresolved
1997                 gitcvs.allbinary
1998                 gitcvs.commitmsgannotation
1999                 gitcvs.dbTableNamePrefix
2000                 gitcvs.dbdriver
2001                 gitcvs.dbname
2002                 gitcvs.dbpass
2003                 gitcvs.dbuser
2004                 gitcvs.enabled
2005                 gitcvs.logfile
2006                 gitcvs.usecrlfattr
2007                 guitool.
2008                 gui.blamehistoryctx
2009                 gui.commitmsgwidth
2010                 gui.copyblamethreshold
2011                 gui.diffcontext
2012                 gui.encoding
2013                 gui.fastcopyblame
2014                 gui.matchtrackingbranch
2015                 gui.newbranchtemplate
2016                 gui.pruneduringfetch
2017                 gui.spellingdictionary
2018                 gui.trustmtime
2019                 help.autocorrect
2020                 help.browser
2021                 help.format
2022                 http.lowSpeedLimit
2023                 http.lowSpeedTime
2024                 http.maxRequests
2025                 http.minSessions
2026                 http.noEPSV
2027                 http.postBuffer
2028                 http.proxy
2029                 http.sslCAInfo
2030                 http.sslCAPath
2031                 http.sslCert
2032                 http.sslCertPasswordProtected
2033                 http.sslKey
2034                 http.sslVerify
2035                 http.useragent
2036                 i18n.commitEncoding
2037                 i18n.logOutputEncoding
2038                 imap.authMethod
2039                 imap.folder
2040                 imap.host
2041                 imap.pass
2042                 imap.port
2043                 imap.preformattedHTML
2044                 imap.sslverify
2045                 imap.tunnel
2046                 imap.user
2047                 init.templatedir
2048                 instaweb.browser
2049                 instaweb.httpd
2050                 instaweb.local
2051                 instaweb.modulepath
2052                 instaweb.port
2053                 interactive.singlekey
2054                 log.date
2055                 log.decorate
2056                 log.showroot
2057                 mailmap.file
2058                 man.
2059                 man.viewer
2060                 merge.
2061                 merge.conflictstyle
2062                 merge.log
2063                 merge.renameLimit
2064                 merge.renormalize
2065                 merge.stat
2066                 merge.tool
2067                 merge.verbosity
2068                 mergetool.
2069                 mergetool.keepBackup
2070                 mergetool.keepTemporaries
2071                 mergetool.prompt
2072                 notes.displayRef
2073                 notes.rewrite.
2074                 notes.rewrite.amend
2075                 notes.rewrite.rebase
2076                 notes.rewriteMode
2077                 notes.rewriteRef
2078                 pack.compression
2079                 pack.deltaCacheLimit
2080                 pack.deltaCacheSize
2081                 pack.depth
2082                 pack.indexVersion
2083                 pack.packSizeLimit
2084                 pack.threads
2085                 pack.window
2086                 pack.windowMemory
2087                 pager.
2088                 pretty.
2089                 pull.octopus
2090                 pull.twohead
2091                 push.default
2092                 rebase.autosquash
2093                 rebase.stat
2094                 receive.autogc
2095                 receive.denyCurrentBranch
2096                 receive.denyDeleteCurrent
2097                 receive.denyDeletes
2098                 receive.denyNonFastForwards
2099                 receive.fsckObjects
2100                 receive.unpackLimit
2101                 receive.updateserverinfo
2102                 remotes.
2103                 repack.usedeltabaseoffset
2104                 rerere.autoupdate
2105                 rerere.enabled
2106                 sendemail.
2107                 sendemail.aliasesfile
2108                 sendemail.aliasfiletype
2109                 sendemail.bcc
2110                 sendemail.cc
2111                 sendemail.cccmd
2112                 sendemail.chainreplyto
2113                 sendemail.confirm
2114                 sendemail.envelopesender
2115                 sendemail.from
2116                 sendemail.identity
2117                 sendemail.multiedit
2118                 sendemail.signedoffbycc
2119                 sendemail.smtpdomain
2120                 sendemail.smtpencryption
2121                 sendemail.smtppass
2122                 sendemail.smtpserver
2123                 sendemail.smtpserveroption
2124                 sendemail.smtpserverport
2125                 sendemail.smtpuser
2126                 sendemail.suppresscc
2127                 sendemail.suppressfrom
2128                 sendemail.thread
2129                 sendemail.to
2130                 sendemail.validate
2131                 showbranch.default
2132                 status.relativePaths
2133                 status.showUntrackedFiles
2134                 status.submodulesummary
2135                 submodule.
2136                 tar.umask
2137                 transfer.unpackLimit
2138                 url.
2139                 user.email
2140                 user.name
2141                 user.signingkey
2142                 web.browser
2143                 branch. remote.
2144         "
2147 _git_remote ()
2149         local subcommands="add rename rm show prune update set-head"
2150         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2151         if [ -z "$subcommand" ]; then
2152                 __gitcomp "$subcommands"
2153                 return
2154         fi
2156         case "$subcommand" in
2157         rename|rm|show|prune)
2158                 __gitcomp "$(__git_remotes)"
2159                 ;;
2160         update)
2161                 local i c='' IFS=$'\n'
2162                 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2163                         i="${i#remotes.}"
2164                         c="$c ${i/ */}"
2165                 done
2166                 __gitcomp "$c"
2167                 ;;
2168         *)
2169                 COMPREPLY=()
2170                 ;;
2171         esac
2174 _git_replace ()
2176         __gitcomp "$(__git_refs)"
2179 _git_reset ()
2181         __git_has_doubledash && return
2183         local cur="${COMP_WORDS[COMP_CWORD]}"
2184         case "$cur" in
2185         --*)
2186                 __gitcomp "--merge --mixed --hard --soft --patch"
2187                 return
2188                 ;;
2189         esac
2190         __gitcomp "$(__git_refs)"
2193 _git_revert ()
2195         local cur="${COMP_WORDS[COMP_CWORD]}"
2196         case "$cur" in
2197         --*)
2198                 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2199                 return
2200                 ;;
2201         esac
2202         __gitcomp "$(__git_refs)"
2205 _git_rm ()
2207         __git_has_doubledash && return
2209         local cur="${COMP_WORDS[COMP_CWORD]}"
2210         case "$cur" in
2211         --*)
2212                 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2213                 return
2214                 ;;
2215         esac
2216         COMPREPLY=()
2219 _git_shortlog ()
2221         __git_has_doubledash && return
2223         local cur="${COMP_WORDS[COMP_CWORD]}"
2224         case "$cur" in
2225         --*)
2226                 __gitcomp "
2227                         $__git_log_common_options
2228                         $__git_log_shortlog_options
2229                         --numbered --summary
2230                         "
2231                 return
2232                 ;;
2233         esac
2234         __git_complete_revlist
2237 _git_show ()
2239         __git_has_doubledash && return
2241         local cur="${COMP_WORDS[COMP_CWORD]}"
2242         case "$cur" in
2243         --pretty=*)
2244                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2245                         " "" "${cur##--pretty=}"
2246                 return
2247                 ;;
2248         --format=*)
2249                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2250                         " "" "${cur##--format=}"
2251                 return
2252                 ;;
2253         --*)
2254                 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2255                         $__git_diff_common_options
2256                         "
2257                 return
2258                 ;;
2259         esac
2260         __git_complete_file
2263 _git_show_branch ()
2265         local cur="${COMP_WORDS[COMP_CWORD]}"
2266         case "$cur" in
2267         --*)
2268                 __gitcomp "
2269                         --all --remotes --topo-order --current --more=
2270                         --list --independent --merge-base --no-name
2271                         --color --no-color
2272                         --sha1-name --sparse --topics --reflog
2273                         "
2274                 return
2275                 ;;
2276         esac
2277         __git_complete_revlist
2280 _git_stash ()
2282         local cur="${COMP_WORDS[COMP_CWORD]}"
2283         local save_opts='--keep-index --no-keep-index --quiet --patch'
2284         local subcommands='save list show apply clear drop pop create branch'
2285         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2286         if [ -z "$subcommand" ]; then
2287                 case "$cur" in
2288                 --*)
2289                         __gitcomp "$save_opts"
2290                         ;;
2291                 *)
2292                         if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2293                                 __gitcomp "$subcommands"
2294                         else
2295                                 COMPREPLY=()
2296                         fi
2297                         ;;
2298                 esac
2299         else
2300                 case "$subcommand,$cur" in
2301                 save,--*)
2302                         __gitcomp "$save_opts"
2303                         ;;
2304                 apply,--*|pop,--*)
2305                         __gitcomp "--index --quiet"
2306                         ;;
2307                 show,--*|drop,--*|branch,--*)
2308                         COMPREPLY=()
2309                         ;;
2310                 show,*|apply,*|drop,*|pop,*|branch,*)
2311                         __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2312                                         | sed -n -e 's/:.*//p')"
2313                         ;;
2314                 *)
2315                         COMPREPLY=()
2316                         ;;
2317                 esac
2318         fi
2321 _git_submodule ()
2323         __git_has_doubledash && return
2325         local subcommands="add status init update summary foreach sync"
2326         if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2327                 local cur="${COMP_WORDS[COMP_CWORD]}"
2328                 case "$cur" in
2329                 --*)
2330                         __gitcomp "--quiet --cached"
2331                         ;;
2332                 *)
2333                         __gitcomp "$subcommands"
2334                         ;;
2335                 esac
2336                 return
2337         fi
2340 _git_svn ()
2342         local subcommands="
2343                 init fetch clone rebase dcommit log find-rev
2344                 set-tree commit-diff info create-ignore propget
2345                 proplist show-ignore show-externals branch tag blame
2346                 migrate mkdirs reset gc
2347                 "
2348         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2349         if [ -z "$subcommand" ]; then
2350                 __gitcomp "$subcommands"
2351         else
2352                 local remote_opts="--username= --config-dir= --no-auth-cache"
2353                 local fc_opts="
2354                         --follow-parent --authors-file= --repack=
2355                         --no-metadata --use-svm-props --use-svnsync-props
2356                         --log-window-size= --no-checkout --quiet
2357                         --repack-flags --use-log-author --localtime
2358                         --ignore-paths= $remote_opts
2359                         "
2360                 local init_opts="
2361                         --template= --shared= --trunk= --tags=
2362                         --branches= --stdlayout --minimize-url
2363                         --no-metadata --use-svm-props --use-svnsync-props
2364                         --rewrite-root= --prefix= --use-log-author
2365                         --add-author-from $remote_opts
2366                         "
2367                 local cmt_opts="
2368                         --edit --rmdir --find-copies-harder --copy-similarity=
2369                         "
2371                 local cur="${COMP_WORDS[COMP_CWORD]}"
2372                 case "$subcommand,$cur" in
2373                 fetch,--*)
2374                         __gitcomp "--revision= --fetch-all $fc_opts"
2375                         ;;
2376                 clone,--*)
2377                         __gitcomp "--revision= $fc_opts $init_opts"
2378                         ;;
2379                 init,--*)
2380                         __gitcomp "$init_opts"
2381                         ;;
2382                 dcommit,--*)
2383                         __gitcomp "
2384                                 --merge --strategy= --verbose --dry-run
2385                                 --fetch-all --no-rebase --commit-url
2386                                 --revision $cmt_opts $fc_opts
2387                                 "
2388                         ;;
2389                 set-tree,--*)
2390                         __gitcomp "--stdin $cmt_opts $fc_opts"
2391                         ;;
2392                 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2393                 show-externals,--*|mkdirs,--*)
2394                         __gitcomp "--revision="
2395                         ;;
2396                 log,--*)
2397                         __gitcomp "
2398                                 --limit= --revision= --verbose --incremental
2399                                 --oneline --show-commit --non-recursive
2400                                 --authors-file= --color
2401                                 "
2402                         ;;
2403                 rebase,--*)
2404                         __gitcomp "
2405                                 --merge --verbose --strategy= --local
2406                                 --fetch-all --dry-run $fc_opts
2407                                 "
2408                         ;;
2409                 commit-diff,--*)
2410                         __gitcomp "--message= --file= --revision= $cmt_opts"
2411                         ;;
2412                 info,--*)
2413                         __gitcomp "--url"
2414                         ;;
2415                 branch,--*)
2416                         __gitcomp "--dry-run --message --tag"
2417                         ;;
2418                 tag,--*)
2419                         __gitcomp "--dry-run --message"
2420                         ;;
2421                 blame,--*)
2422                         __gitcomp "--git-format"
2423                         ;;
2424                 migrate,--*)
2425                         __gitcomp "
2426                                 --config-dir= --ignore-paths= --minimize
2427                                 --no-auth-cache --username=
2428                                 "
2429                         ;;
2430                 reset,--*)
2431                         __gitcomp "--revision= --parent"
2432                         ;;
2433                 *)
2434                         COMPREPLY=()
2435                         ;;
2436                 esac
2437         fi
2440 _git_tag ()
2442         local i c=1 f=0
2443         while [ $c -lt $COMP_CWORD ]; do
2444                 i="${COMP_WORDS[c]}"
2445                 case "$i" in
2446                 -d|-v)
2447                         __gitcomp "$(__git_tags)"
2448                         return
2449                         ;;
2450                 -f)
2451                         f=1
2452                         ;;
2453                 esac
2454                 c=$((++c))
2455         done
2457         case "${COMP_WORDS[COMP_CWORD-1]}" in
2458         -m|-F)
2459                 COMPREPLY=()
2460                 ;;
2461         -*|tag)
2462                 if [ $f = 1 ]; then
2463                         __gitcomp "$(__git_tags)"
2464                 else
2465                         COMPREPLY=()
2466                 fi
2467                 ;;
2468         *)
2469                 __gitcomp "$(__git_refs)"
2470                 ;;
2471         esac
2474 _git_whatchanged ()
2476         _git_log
2479 _git ()
2481         local i c=1 command __git_dir
2483         if [[ -n ${ZSH_VERSION-} ]]; then
2484                 emulate -L bash
2485                 setopt KSH_TYPESET
2486         fi
2488         while [ $c -lt $COMP_CWORD ]; do
2489                 i="${COMP_WORDS[c]}"
2490                 case "$i" in
2491                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2492                 --bare)      __git_dir="." ;;
2493                 --version|-p|--paginate) ;;
2494                 --help) command="help"; break ;;
2495                 *) command="$i"; break ;;
2496                 esac
2497                 c=$((++c))
2498         done
2500         if [ -z "$command" ]; then
2501                 case "${COMP_WORDS[COMP_CWORD]}" in
2502                 --*)   __gitcomp "
2503                         --paginate
2504                         --no-pager
2505                         --git-dir=
2506                         --bare
2507                         --version
2508                         --exec-path
2509                         --html-path
2510                         --work-tree=
2511                         --help
2512                         "
2513                         ;;
2514                 *)     __git_compute_porcelain_commands
2515                        __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2516                 esac
2517                 return
2518         fi
2520         local completion_func="_git_${command//-/_}"
2521         declare -f $completion_func >/dev/null && $completion_func && return
2523         local expansion=$(__git_aliased_command "$command")
2524         if [ -n "$expansion" ]; then
2525                 completion_func="_git_${expansion//-/_}"
2526                 declare -f $completion_func >/dev/null && $completion_func
2527         fi
2530 _gitk ()
2532         if [[ -n ${ZSH_VERSION-} ]]; then
2533                 emulate -L bash
2534                 setopt KSH_TYPESET
2535         fi
2537         __git_has_doubledash && return
2539         local cur="${COMP_WORDS[COMP_CWORD]}"
2540         local g="$(__gitdir)"
2541         local merge=""
2542         if [ -f "$g/MERGE_HEAD" ]; then
2543                 merge="--merge"
2544         fi
2545         case "$cur" in
2546         --*)
2547                 __gitcomp "
2548                         $__git_log_common_options
2549                         $__git_log_gitk_options
2550                         $merge
2551                         "
2552                 return
2553                 ;;
2554         esac
2555         __git_complete_revlist
2558 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2559         || complete -o default -o nospace -F _git git
2560 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2561         || complete -o default -o nospace -F _gitk gitk
2563 # The following are necessary only for Cygwin, and only are needed
2564 # when the user has tab-completed the executable name and consequently
2565 # included the '.exe' suffix.
2567 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2568 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2569         || complete -o default -o nospace -F _git git.exe
2570 fi
2572 if [[ -n ${ZSH_VERSION-} ]]; then
2573         shopt () {
2574                 local option
2575                 if [ $# -ne 2 ]; then
2576                         echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2577                         return 1
2578                 fi
2579                 case "$2" in
2580                 nullglob)
2581                         option="$2"
2582                         ;;
2583                 *)
2584                         echo "$0: invalid option: $2" >&2
2585                         return 1
2586                 esac
2587                 case "$1" in
2588                 -q)     setopt | grep -q "$option" ;;
2589                 -u)     unsetopt "$option" ;;
2590                 -s)     setopt "$option" ;;
2591                 *)
2592                         echo "$0: invalid flag: $1" >&2
2593                         return 1
2594                 esac
2595         }
2596 fi