Code

Merge branch 'sg/completion'
[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 --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 or 1 arguments (to pass to __gitdir)
390 __git_refs ()
392         local i is_hash=y dir="$(__gitdir "${1-}")"
393         local cur="${COMP_WORDS[COMP_CWORD]}" format refs
394         if [ -d "$dir" ]; then
395                 case "$cur" in
396                 refs|refs/*)
397                         format="refname"
398                         refs="${cur%/*}"
399                         ;;
400                 *)
401                         for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
402                                 if [ -e "$dir/$i" ]; then echo $i; fi
403                         done
404                         format="refname:short"
405                         refs="refs/tags refs/heads refs/remotes"
406                         ;;
407                 esac
408                 git --git-dir="$dir" for-each-ref --format="%($format)" \
409                         $refs
410                 return
411         fi
412         for i in $(git ls-remote "$dir" 2>/dev/null); do
413                 case "$is_hash,$i" in
414                 y,*) is_hash=n ;;
415                 n,*^{}) is_hash=y ;;
416                 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
417                 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
418                 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
419                 n,*) is_hash=y; echo "$i" ;;
420                 esac
421         done
424 # __git_refs2 requires 1 argument (to pass to __git_refs)
425 __git_refs2 ()
427         local i
428         for i in $(__git_refs "$1"); do
429                 echo "$i:$i"
430         done
433 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
434 __git_refs_remotes ()
436         local cmd i is_hash=y
437         for i in $(git ls-remote "$1" 2>/dev/null); do
438                 case "$is_hash,$i" in
439                 n,refs/heads/*)
440                         is_hash=y
441                         echo "$i:refs/remotes/$1/${i#refs/heads/}"
442                         ;;
443                 y,*) is_hash=n ;;
444                 n,*^{}) is_hash=y ;;
445                 n,refs/tags/*) is_hash=y;;
446                 n,*) is_hash=y; ;;
447                 esac
448         done
451 __git_remotes ()
453         local i ngoff IFS=$'\n' d="$(__gitdir)"
454         shopt -q nullglob || ngoff=1
455         shopt -s nullglob
456         for i in "$d/remotes"/*; do
457                 echo ${i#$d/remotes/}
458         done
459         [ "$ngoff" ] && shopt -u nullglob
460         for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
461                 i="${i#remote.}"
462                 echo "${i/.url*/}"
463         done
466 __git_list_merge_strategies ()
468         git merge -s help 2>&1 |
469         sed -n -e '/[Aa]vailable strategies are: /,/^$/{
470                 s/\.$//
471                 s/.*://
472                 s/^[    ]*//
473                 s/[     ]*$//
474                 p
475         }'
478 __git_merge_strategies=
479 # 'git merge -s help' (and thus detection of the merge strategy
480 # list) fails, unfortunately, if run outside of any git working
481 # tree.  __git_merge_strategies is set to the empty string in
482 # that case, and the detection will be repeated the next time it
483 # is needed.
484 __git_compute_merge_strategies ()
486         : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
489 __git_complete_file ()
491         local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
492         case "$cur" in
493         ?*:*)
494                 ref="${cur%%:*}"
495                 cur="${cur#*:}"
496                 case "$cur" in
497                 ?*/*)
498                         pfx="${cur%/*}"
499                         cur="${cur##*/}"
500                         ls="$ref:$pfx"
501                         pfx="$pfx/"
502                         ;;
503                 *)
504                         ls="$ref"
505                         ;;
506             esac
508                 case "$COMP_WORDBREAKS" in
509                 *:*) : great ;;
510                 *)   pfx="$ref:$pfx" ;;
511                 esac
513                 local IFS=$'\n'
514                 COMPREPLY=($(compgen -P "$pfx" \
515                         -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
516                                 | sed '/^100... blob /{
517                                            s,^.*        ,,
518                                            s,$, ,
519                                        }
520                                        /^120000 blob /{
521                                            s,^.*        ,,
522                                            s,$, ,
523                                        }
524                                        /^040000 tree /{
525                                            s,^.*        ,,
526                                            s,$,/,
527                                        }
528                                        s/^.*    //')" \
529                         -- "$cur"))
530                 ;;
531         *)
532                 __gitcomp "$(__git_refs)"
533                 ;;
534         esac
537 __git_complete_revlist ()
539         local pfx cur="${COMP_WORDS[COMP_CWORD]}"
540         case "$cur" in
541         *...*)
542                 pfx="${cur%...*}..."
543                 cur="${cur#*...}"
544                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
545                 ;;
546         *..*)
547                 pfx="${cur%..*}.."
548                 cur="${cur#*..}"
549                 __gitcomp "$(__git_refs)" "$pfx" "$cur"
550                 ;;
551         *)
552                 __gitcomp "$(__git_refs)"
553                 ;;
554         esac
557 __git_complete_remote_or_refspec ()
559         local cmd="${COMP_WORDS[1]}"
560         local cur="${COMP_WORDS[COMP_CWORD]}"
561         local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
562         while [ $c -lt $COMP_CWORD ]; do
563                 i="${COMP_WORDS[c]}"
564                 case "$i" in
565                 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
566                 --all)
567                         case "$cmd" in
568                         push) no_complete_refspec=1 ;;
569                         fetch)
570                                 COMPREPLY=()
571                                 return
572                                 ;;
573                         *) ;;
574                         esac
575                         ;;
576                 -*) ;;
577                 *) remote="$i"; break ;;
578                 esac
579                 c=$((++c))
580         done
581         if [ -z "$remote" ]; then
582                 __gitcomp "$(__git_remotes)"
583                 return
584         fi
585         if [ $no_complete_refspec = 1 ]; then
586                 COMPREPLY=()
587                 return
588         fi
589         [ "$remote" = "." ] && remote=
590         case "$cur" in
591         *:*)
592                 case "$COMP_WORDBREAKS" in
593                 *:*) : great ;;
594                 *)   pfx="${cur%%:*}:" ;;
595                 esac
596                 cur="${cur#*:}"
597                 lhs=0
598                 ;;
599         +*)
600                 pfx="+"
601                 cur="${cur#+}"
602                 ;;
603         esac
604         case "$cmd" in
605         fetch)
606                 if [ $lhs = 1 ]; then
607                         __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
608                 else
609                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
610                 fi
611                 ;;
612         pull)
613                 if [ $lhs = 1 ]; then
614                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
615                 else
616                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
617                 fi
618                 ;;
619         push)
620                 if [ $lhs = 1 ]; then
621                         __gitcomp "$(__git_refs)" "$pfx" "$cur"
622                 else
623                         __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
624                 fi
625                 ;;
626         esac
629 __git_complete_strategy ()
631         __git_compute_merge_strategies
632         case "${COMP_WORDS[COMP_CWORD-1]}" in
633         -s|--strategy)
634                 __gitcomp "$__git_merge_strategies"
635                 return 0
636         esac
637         local cur="${COMP_WORDS[COMP_CWORD]}"
638         case "$cur" in
639         --strategy=*)
640                 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
641                 return 0
642                 ;;
643         esac
644         return 1
647 __git_list_all_commands ()
649         local i IFS=" "$'\n'
650         for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
651         do
652                 case $i in
653                 *--*)             : helper pattern;;
654                 *) echo $i;;
655                 esac
656         done
659 __git_all_commands=
660 __git_compute_all_commands ()
662         : ${__git_all_commands:=$(__git_list_all_commands)}
665 __git_list_porcelain_commands ()
667         local i IFS=" "$'\n'
668         __git_compute_all_commands
669         for i in "help" $__git_all_commands
670         do
671                 case $i in
672                 *--*)             : helper pattern;;
673                 applymbox)        : ask gittus;;
674                 applypatch)       : ask gittus;;
675                 archimport)       : import;;
676                 cat-file)         : plumbing;;
677                 check-attr)       : plumbing;;
678                 check-ref-format) : plumbing;;
679                 checkout-index)   : plumbing;;
680                 commit-tree)      : plumbing;;
681                 count-objects)    : infrequent;;
682                 cvsexportcommit)  : export;;
683                 cvsimport)        : import;;
684                 cvsserver)        : daemon;;
685                 daemon)           : daemon;;
686                 diff-files)       : plumbing;;
687                 diff-index)       : plumbing;;
688                 diff-tree)        : plumbing;;
689                 fast-import)      : import;;
690                 fast-export)      : export;;
691                 fsck-objects)     : plumbing;;
692                 fetch-pack)       : plumbing;;
693                 fmt-merge-msg)    : plumbing;;
694                 for-each-ref)     : plumbing;;
695                 hash-object)      : plumbing;;
696                 http-*)           : transport;;
697                 index-pack)       : plumbing;;
698                 init-db)          : deprecated;;
699                 local-fetch)      : plumbing;;
700                 lost-found)       : infrequent;;
701                 ls-files)         : plumbing;;
702                 ls-remote)        : plumbing;;
703                 ls-tree)          : plumbing;;
704                 mailinfo)         : plumbing;;
705                 mailsplit)        : plumbing;;
706                 merge-*)          : plumbing;;
707                 mktree)           : plumbing;;
708                 mktag)            : plumbing;;
709                 pack-objects)     : plumbing;;
710                 pack-redundant)   : plumbing;;
711                 pack-refs)        : plumbing;;
712                 parse-remote)     : plumbing;;
713                 patch-id)         : plumbing;;
714                 peek-remote)      : plumbing;;
715                 prune)            : plumbing;;
716                 prune-packed)     : plumbing;;
717                 quiltimport)      : import;;
718                 read-tree)        : plumbing;;
719                 receive-pack)     : plumbing;;
720                 reflog)           : plumbing;;
721                 remote-*)         : transport;;
722                 repo-config)      : deprecated;;
723                 rerere)           : plumbing;;
724                 rev-list)         : plumbing;;
725                 rev-parse)        : plumbing;;
726                 runstatus)        : plumbing;;
727                 sh-setup)         : internal;;
728                 shell)            : daemon;;
729                 show-ref)         : plumbing;;
730                 send-pack)        : plumbing;;
731                 show-index)       : plumbing;;
732                 ssh-*)            : transport;;
733                 stripspace)       : plumbing;;
734                 symbolic-ref)     : plumbing;;
735                 tar-tree)         : deprecated;;
736                 unpack-file)      : plumbing;;
737                 unpack-objects)   : plumbing;;
738                 update-index)     : plumbing;;
739                 update-ref)       : plumbing;;
740                 update-server-info) : daemon;;
741                 upload-archive)   : plumbing;;
742                 upload-pack)      : plumbing;;
743                 write-tree)       : plumbing;;
744                 var)              : infrequent;;
745                 verify-pack)      : infrequent;;
746                 verify-tag)       : plumbing;;
747                 *) echo $i;;
748                 esac
749         done
752 __git_porcelain_commands=
753 __git_compute_porcelain_commands ()
755         __git_compute_all_commands
756         : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
759 __git_pretty_aliases ()
761         local i IFS=$'\n'
762         for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
763                 case "$i" in
764                 pretty.*)
765                         i="${i#pretty.}"
766                         echo "${i/ */}"
767                         ;;
768                 esac
769         done
772 __git_aliases ()
774         local i IFS=$'\n'
775         for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
776                 case "$i" in
777                 alias.*)
778                         i="${i#alias.}"
779                         echo "${i/ */}"
780                         ;;
781                 esac
782         done
785 # __git_aliased_command requires 1 argument
786 __git_aliased_command ()
788         local word cmdline=$(git --git-dir="$(__gitdir)" \
789                 config --get "alias.$1")
790         for word in $cmdline; do
791                 case "$word" in
792                 \!gitk|gitk)
793                         echo "gitk"
794                         return
795                         ;;
796                 \!*)    : shell command alias ;;
797                 -*)     : option ;;
798                 *=*)    : setting env ;;
799                 git)    : git itself ;;
800                 *)
801                         echo "$word"
802                         return
803                 esac
804         done
807 # __git_find_on_cmdline requires 1 argument
808 __git_find_on_cmdline ()
810         local word subcommand c=1
812         while [ $c -lt $COMP_CWORD ]; do
813                 word="${COMP_WORDS[c]}"
814                 for subcommand in $1; do
815                         if [ "$subcommand" = "$word" ]; then
816                                 echo "$subcommand"
817                                 return
818                         fi
819                 done
820                 c=$((++c))
821         done
824 __git_has_doubledash ()
826         local c=1
827         while [ $c -lt $COMP_CWORD ]; do
828                 if [ "--" = "${COMP_WORDS[c]}" ]; then
829                         return 0
830                 fi
831                 c=$((++c))
832         done
833         return 1
836 __git_whitespacelist="nowarn warn error error-all fix"
838 _git_am ()
840         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
841         if [ -d "$dir"/rebase-apply ]; then
842                 __gitcomp "--skip --continue --resolved --abort"
843                 return
844         fi
845         case "$cur" in
846         --whitespace=*)
847                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
848                 return
849                 ;;
850         --*)
851                 __gitcomp "
852                         --3way --committer-date-is-author-date --ignore-date
853                         --ignore-whitespace --ignore-space-change
854                         --interactive --keep --no-utf8 --signoff --utf8
855                         --whitespace= --scissors
856                         "
857                 return
858         esac
859         COMPREPLY=()
862 _git_apply ()
864         local cur="${COMP_WORDS[COMP_CWORD]}"
865         case "$cur" in
866         --whitespace=*)
867                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
868                 return
869                 ;;
870         --*)
871                 __gitcomp "
872                         --stat --numstat --summary --check --index
873                         --cached --index-info --reverse --reject --unidiff-zero
874                         --apply --no-add --exclude=
875                         --ignore-whitespace --ignore-space-change
876                         --whitespace= --inaccurate-eof --verbose
877                         "
878                 return
879         esac
880         COMPREPLY=()
883 _git_add ()
885         __git_has_doubledash && return
887         local cur="${COMP_WORDS[COMP_CWORD]}"
888         case "$cur" in
889         --*)
890                 __gitcomp "
891                         --interactive --refresh --patch --update --dry-run
892                         --ignore-errors --intent-to-add
893                         "
894                 return
895         esac
896         COMPREPLY=()
899 _git_archive ()
901         local cur="${COMP_WORDS[COMP_CWORD]}"
902         case "$cur" in
903         --format=*)
904                 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
905                 return
906                 ;;
907         --remote=*)
908                 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
909                 return
910                 ;;
911         --*)
912                 __gitcomp "
913                         --format= --list --verbose
914                         --prefix= --remote= --exec=
915                         "
916                 return
917                 ;;
918         esac
919         __git_complete_file
922 _git_bisect ()
924         __git_has_doubledash && return
926         local subcommands="start bad good skip reset visualize replay log run"
927         local subcommand="$(__git_find_on_cmdline "$subcommands")"
928         if [ -z "$subcommand" ]; then
929                 if [ -f "$(__gitdir)"/BISECT_START ]; then
930                         __gitcomp "$subcommands"
931                 else
932                         __gitcomp "replay start"
933                 fi
934                 return
935         fi
937         case "$subcommand" in
938         bad|good|reset|skip|start)
939                 __gitcomp "$(__git_refs)"
940                 ;;
941         *)
942                 COMPREPLY=()
943                 ;;
944         esac
947 _git_branch ()
949         local i c=1 only_local_ref="n" has_r="n"
951         while [ $c -lt $COMP_CWORD ]; do
952                 i="${COMP_WORDS[c]}"
953                 case "$i" in
954                 -d|-m)  only_local_ref="y" ;;
955                 -r)     has_r="y" ;;
956                 esac
957                 c=$((++c))
958         done
960         case "${COMP_WORDS[COMP_CWORD]}" in
961         --*)
962                 __gitcomp "
963                         --color --no-color --verbose --abbrev= --no-abbrev
964                         --track --no-track --contains --merged --no-merged
965                         --set-upstream
966                         "
967                 ;;
968         *)
969                 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
970                         __gitcomp "$(__git_heads)"
971                 else
972                         __gitcomp "$(__git_refs)"
973                 fi
974                 ;;
975         esac
978 _git_bundle ()
980         local cmd="${COMP_WORDS[2]}"
981         case "$COMP_CWORD" in
982         2)
983                 __gitcomp "create list-heads verify unbundle"
984                 ;;
985         3)
986                 # looking for a file
987                 ;;
988         *)
989                 case "$cmd" in
990                         create)
991                                 __git_complete_revlist
992                         ;;
993                 esac
994                 ;;
995         esac
998 _git_checkout ()
1000         __git_has_doubledash && return
1002         local cur="${COMP_WORDS[COMP_CWORD]}"
1003         case "$cur" in
1004         --conflict=*)
1005                 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1006                 ;;
1007         --*)
1008                 __gitcomp "
1009                         --quiet --ours --theirs --track --no-track --merge
1010                         --conflict= --orphan --patch
1011                         "
1012                 ;;
1013         *)
1014                 __gitcomp "$(__git_refs)"
1015                 ;;
1016         esac
1019 _git_cherry ()
1021         __gitcomp "$(__git_refs)"
1024 _git_cherry_pick ()
1026         local cur="${COMP_WORDS[COMP_CWORD]}"
1027         case "$cur" in
1028         --*)
1029                 __gitcomp "--edit --no-commit"
1030                 ;;
1031         *)
1032                 __gitcomp "$(__git_refs)"
1033                 ;;
1034         esac
1037 _git_clean ()
1039         __git_has_doubledash && return
1041         local cur="${COMP_WORDS[COMP_CWORD]}"
1042         case "$cur" in
1043         --*)
1044                 __gitcomp "--dry-run --quiet"
1045                 return
1046                 ;;
1047         esac
1048         COMPREPLY=()
1051 _git_clone ()
1053         local cur="${COMP_WORDS[COMP_CWORD]}"
1054         case "$cur" in
1055         --*)
1056                 __gitcomp "
1057                         --local
1058                         --no-hardlinks
1059                         --shared
1060                         --reference
1061                         --quiet
1062                         --no-checkout
1063                         --bare
1064                         --mirror
1065                         --origin
1066                         --upload-pack
1067                         --template=
1068                         --depth
1069                         "
1070                 return
1071                 ;;
1072         esac
1073         COMPREPLY=()
1076 _git_commit ()
1078         __git_has_doubledash && return
1080         local cur="${COMP_WORDS[COMP_CWORD]}"
1081         case "$cur" in
1082         --cleanup=*)
1083                 __gitcomp "default strip verbatim whitespace
1084                         " "" "${cur##--cleanup=}"
1085                 return
1086                 ;;
1087         --reuse-message=*)
1088                 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1089                 return
1090                 ;;
1091         --reedit-message=*)
1092                 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1093                 return
1094                 ;;
1095         --untracked-files=*)
1096                 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1097                 return
1098                 ;;
1099         --*)
1100                 __gitcomp "
1101                         --all --author= --signoff --verify --no-verify
1102                         --edit --amend --include --only --interactive
1103                         --dry-run --reuse-message= --reedit-message=
1104                         --reset-author --file= --message= --template=
1105                         --cleanup= --untracked-files --untracked-files=
1106                         --verbose --quiet
1107                         "
1108                 return
1109         esac
1110         COMPREPLY=()
1113 _git_describe ()
1115         local cur="${COMP_WORDS[COMP_CWORD]}"
1116         case "$cur" in
1117         --*)
1118                 __gitcomp "
1119                         --all --tags --contains --abbrev= --candidates=
1120                         --exact-match --debug --long --match --always
1121                         "
1122                 return
1123         esac
1124         __gitcomp "$(__git_refs)"
1127 __git_diff_common_options="--stat --numstat --shortstat --summary
1128                         --patch-with-stat --name-only --name-status --color
1129                         --no-color --color-words --no-renames --check
1130                         --full-index --binary --abbrev --diff-filter=
1131                         --find-copies-harder
1132                         --text --ignore-space-at-eol --ignore-space-change
1133                         --ignore-all-space --exit-code --quiet --ext-diff
1134                         --no-ext-diff
1135                         --no-prefix --src-prefix= --dst-prefix=
1136                         --inter-hunk-context=
1137                         --patience
1138                         --raw
1139                         --dirstat --dirstat= --dirstat-by-file
1140                         --dirstat-by-file= --cumulative
1143 _git_diff ()
1145         __git_has_doubledash && return
1147         local cur="${COMP_WORDS[COMP_CWORD]}"
1148         case "$cur" in
1149         --*)
1150                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1151                         --base --ours --theirs --no-index
1152                         $__git_diff_common_options
1153                         "
1154                 return
1155                 ;;
1156         esac
1157         __git_complete_file
1160 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1161                         tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1164 _git_difftool ()
1166         __git_has_doubledash && return
1168         local cur="${COMP_WORDS[COMP_CWORD]}"
1169         case "$cur" in
1170         --tool=*)
1171                 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1172                 return
1173                 ;;
1174         --*)
1175                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1176                         --base --ours --theirs
1177                         --no-renames --diff-filter= --find-copies-harder
1178                         --relative --ignore-submodules
1179                         --tool="
1180                 return
1181                 ;;
1182         esac
1183         __git_complete_file
1186 __git_fetch_options="
1187         --quiet --verbose --append --upload-pack --force --keep --depth=
1188         --tags --no-tags --all --prune --dry-run
1191 _git_fetch ()
1193         local cur="${COMP_WORDS[COMP_CWORD]}"
1194         case "$cur" in
1195         --*)
1196                 __gitcomp "$__git_fetch_options"
1197                 return
1198                 ;;
1199         esac
1200         __git_complete_remote_or_refspec
1203 _git_format_patch ()
1205         local cur="${COMP_WORDS[COMP_CWORD]}"
1206         case "$cur" in
1207         --thread=*)
1208                 __gitcomp "
1209                         deep shallow
1210                         " "" "${cur##--thread=}"
1211                 return
1212                 ;;
1213         --*)
1214                 __gitcomp "
1215                         --stdout --attach --no-attach --thread --thread=
1216                         --output-directory
1217                         --numbered --start-number
1218                         --numbered-files
1219                         --keep-subject
1220                         --signoff --signature --no-signature
1221                         --in-reply-to= --cc=
1222                         --full-index --binary
1223                         --not --all
1224                         --cover-letter
1225                         --no-prefix --src-prefix= --dst-prefix=
1226                         --inline --suffix= --ignore-if-in-upstream
1227                         --subject-prefix=
1228                         "
1229                 return
1230                 ;;
1231         esac
1232         __git_complete_revlist
1235 _git_fsck ()
1237         local cur="${COMP_WORDS[COMP_CWORD]}"
1238         case "$cur" in
1239         --*)
1240                 __gitcomp "
1241                         --tags --root --unreachable --cache --no-reflogs --full
1242                         --strict --verbose --lost-found
1243                         "
1244                 return
1245                 ;;
1246         esac
1247         COMPREPLY=()
1250 _git_gc ()
1252         local cur="${COMP_WORDS[COMP_CWORD]}"
1253         case "$cur" in
1254         --*)
1255                 __gitcomp "--prune --aggressive"
1256                 return
1257                 ;;
1258         esac
1259         COMPREPLY=()
1262 _git_gitk ()
1264         _gitk
1267 _git_grep ()
1269         __git_has_doubledash && return
1271         local cur="${COMP_WORDS[COMP_CWORD]}"
1272         case "$cur" in
1273         --*)
1274                 __gitcomp "
1275                         --cached
1276                         --text --ignore-case --word-regexp --invert-match
1277                         --full-name
1278                         --extended-regexp --basic-regexp --fixed-strings
1279                         --files-with-matches --name-only
1280                         --files-without-match
1281                         --max-depth
1282                         --count
1283                         --and --or --not --all-match
1284                         "
1285                 return
1286                 ;;
1287         esac
1289         __gitcomp "$(__git_refs)"
1292 _git_help ()
1294         local cur="${COMP_WORDS[COMP_CWORD]}"
1295         case "$cur" in
1296         --*)
1297                 __gitcomp "--all --info --man --web"
1298                 return
1299                 ;;
1300         esac
1301         __git_compute_all_commands
1302         __gitcomp "$__git_all_commands
1303                 attributes cli core-tutorial cvs-migration
1304                 diffcore gitk glossary hooks ignore modules
1305                 repository-layout tutorial tutorial-2
1306                 workflows
1307                 "
1310 _git_init ()
1312         local cur="${COMP_WORDS[COMP_CWORD]}"
1313         case "$cur" in
1314         --shared=*)
1315                 __gitcomp "
1316                         false true umask group all world everybody
1317                         " "" "${cur##--shared=}"
1318                 return
1319                 ;;
1320         --*)
1321                 __gitcomp "--quiet --bare --template= --shared --shared="
1322                 return
1323                 ;;
1324         esac
1325         COMPREPLY=()
1328 _git_ls_files ()
1330         __git_has_doubledash && return
1332         local cur="${COMP_WORDS[COMP_CWORD]}"
1333         case "$cur" in
1334         --*)
1335                 __gitcomp "--cached --deleted --modified --others --ignored
1336                         --stage --directory --no-empty-directory --unmerged
1337                         --killed --exclude= --exclude-from=
1338                         --exclude-per-directory= --exclude-standard
1339                         --error-unmatch --with-tree= --full-name
1340                         --abbrev --ignored --exclude-per-directory
1341                         "
1342                 return
1343                 ;;
1344         esac
1345         COMPREPLY=()
1348 _git_ls_remote ()
1350         __gitcomp "$(__git_remotes)"
1353 _git_ls_tree ()
1355         __git_complete_file
1358 # Options that go well for log, shortlog and gitk
1359 __git_log_common_options="
1360         --not --all
1361         --branches --tags --remotes
1362         --first-parent --merges --no-merges
1363         --max-count=
1364         --max-age= --since= --after=
1365         --min-age= --until= --before=
1367 # Options that go well for log and gitk (not shortlog)
1368 __git_log_gitk_options="
1369         --dense --sparse --full-history
1370         --simplify-merges --simplify-by-decoration
1371         --left-right
1373 # Options that go well for log and shortlog (not gitk)
1374 __git_log_shortlog_options="
1375         --author= --committer= --grep=
1376         --all-match
1379 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1380 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1382 _git_log ()
1384         __git_has_doubledash && return
1386         local cur="${COMP_WORDS[COMP_CWORD]}"
1387         local g="$(git rev-parse --git-dir 2>/dev/null)"
1388         local merge=""
1389         if [ -f "$g/MERGE_HEAD" ]; then
1390                 merge="--merge"
1391         fi
1392         case "$cur" in
1393         --pretty=*)
1394                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1395                         " "" "${cur##--pretty=}"
1396                 return
1397                 ;;
1398         --format=*)
1399                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1400                         " "" "${cur##--format=}"
1401                 return
1402                 ;;
1403         --date=*)
1404                 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1405                 return
1406                 ;;
1407         --decorate=*)
1408                 __gitcomp "long short" "" "${cur##--decorate=}"
1409                 return
1410                 ;;
1411         --*)
1412                 __gitcomp "
1413                         $__git_log_common_options
1414                         $__git_log_shortlog_options
1415                         $__git_log_gitk_options
1416                         --root --topo-order --date-order --reverse
1417                         --follow --full-diff
1418                         --abbrev-commit --abbrev=
1419                         --relative-date --date=
1420                         --pretty= --format= --oneline
1421                         --cherry-pick
1422                         --graph
1423                         --decorate --decorate=
1424                         --walk-reflogs
1425                         --parents --children
1426                         $merge
1427                         $__git_diff_common_options
1428                         --pickaxe-all --pickaxe-regex
1429                         "
1430                 return
1431                 ;;
1432         esac
1433         __git_complete_revlist
1436 __git_merge_options="
1437         --no-commit --no-stat --log --no-log --squash --strategy
1438         --commit --stat --no-squash --ff --no-ff --ff-only
1441 _git_merge ()
1443         __git_complete_strategy && return
1445         local cur="${COMP_WORDS[COMP_CWORD]}"
1446         case "$cur" in
1447         --*)
1448                 __gitcomp "$__git_merge_options"
1449                 return
1450         esac
1451         __gitcomp "$(__git_refs)"
1454 _git_mergetool ()
1456         local cur="${COMP_WORDS[COMP_CWORD]}"
1457         case "$cur" in
1458         --tool=*)
1459                 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1460                 return
1461                 ;;
1462         --*)
1463                 __gitcomp "--tool="
1464                 return
1465                 ;;
1466         esac
1467         COMPREPLY=()
1470 _git_merge_base ()
1472         __gitcomp "$(__git_refs)"
1475 _git_mv ()
1477         local cur="${COMP_WORDS[COMP_CWORD]}"
1478         case "$cur" in
1479         --*)
1480                 __gitcomp "--dry-run"
1481                 return
1482                 ;;
1483         esac
1484         COMPREPLY=()
1487 _git_name_rev ()
1489         __gitcomp "--tags --all --stdin"
1492 _git_notes ()
1494         local subcommands='add append copy edit list prune remove show'
1495         local subcommand="$(__git_find_on_cmdline "$subcommands")"
1496         local cur="${COMP_WORDS[COMP_CWORD]}"
1498         case "$subcommand,$cur" in
1499         ,--*)
1500                 __gitcomp '--ref'
1501                 ;;
1502         ,*)
1503                 case "${COMP_WORDS[COMP_CWORD-1]}" in
1504                 --ref)
1505                         __gitcomp "$(__git_refs)"
1506                         ;;
1507                 *)
1508                         __gitcomp "$subcommands --ref"
1509                         ;;
1510                 esac
1511                 ;;
1512         add,--reuse-message=*|append,--reuse-message=*)
1513                 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1514                 ;;
1515         add,--reedit-message=*|append,--reedit-message=*)
1516                 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1517                 ;;
1518         add,--*|append,--*)
1519                 __gitcomp '--file= --message= --reedit-message=
1520                                 --reuse-message='
1521                 ;;
1522         copy,--*)
1523                 __gitcomp '--stdin'
1524                 ;;
1525         prune,--*)
1526                 __gitcomp '--dry-run --verbose'
1527                 ;;
1528         prune,*)
1529                 ;;
1530         *)
1531                 case "${COMP_WORDS[COMP_CWORD-1]}" in
1532                 -m|-F)
1533                         ;;
1534                 *)
1535                         __gitcomp "$(__git_refs)"
1536                         ;;
1537                 esac
1538                 ;;
1539         esac
1542 _git_pull ()
1544         __git_complete_strategy && return
1546         local cur="${COMP_WORDS[COMP_CWORD]}"
1547         case "$cur" in
1548         --*)
1549                 __gitcomp "
1550                         --rebase --no-rebase
1551                         $__git_merge_options
1552                         $__git_fetch_options
1553                 "
1554                 return
1555                 ;;
1556         esac
1557         __git_complete_remote_or_refspec
1560 _git_push ()
1562         local cur="${COMP_WORDS[COMP_CWORD]}"
1563         case "${COMP_WORDS[COMP_CWORD-1]}" in
1564         --repo)
1565                 __gitcomp "$(__git_remotes)"
1566                 return
1567         esac
1568         case "$cur" in
1569         --repo=*)
1570                 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1571                 return
1572                 ;;
1573         --*)
1574                 __gitcomp "
1575                         --all --mirror --tags --dry-run --force --verbose
1576                         --receive-pack= --repo=
1577                 "
1578                 return
1579                 ;;
1580         esac
1581         __git_complete_remote_or_refspec
1584 _git_rebase ()
1586         local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1587         if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1588                 __gitcomp "--continue --skip --abort"
1589                 return
1590         fi
1591         __git_complete_strategy && return
1592         case "$cur" in
1593         --whitespace=*)
1594                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1595                 return
1596                 ;;
1597         --*)
1598                 __gitcomp "
1599                         --onto --merge --strategy --interactive
1600                         --preserve-merges --stat --no-stat
1601                         --committer-date-is-author-date --ignore-date
1602                         --ignore-whitespace --whitespace=
1603                         --autosquash
1604                         "
1606                 return
1607         esac
1608         __gitcomp "$(__git_refs)"
1611 __git_send_email_confirm_options="always never auto cc compose"
1612 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1614 _git_send_email ()
1616         local cur="${COMP_WORDS[COMP_CWORD]}"
1617         case "$cur" in
1618         --confirm=*)
1619                 __gitcomp "
1620                         $__git_send_email_confirm_options
1621                         " "" "${cur##--confirm=}"
1622                 return
1623                 ;;
1624         --suppress-cc=*)
1625                 __gitcomp "
1626                         $__git_send_email_suppresscc_options
1627                         " "" "${cur##--suppress-cc=}"
1629                 return
1630                 ;;
1631         --smtp-encryption=*)
1632                 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1633                 return
1634                 ;;
1635         --*)
1636                 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1637                         --compose --confirm= --dry-run --envelope-sender
1638                         --from --identity
1639                         --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1640                         --no-suppress-from --no-thread --quiet
1641                         --signed-off-by-cc --smtp-pass --smtp-server
1642                         --smtp-server-port --smtp-encryption= --smtp-user
1643                         --subject --suppress-cc= --suppress-from --thread --to
1644                         --validate --no-validate"
1645                 return
1646                 ;;
1647         esac
1648         COMPREPLY=()
1651 _git_stage ()
1653         _git_add
1656 __git_config_get_set_variables ()
1658         local prevword word config_file= c=$COMP_CWORD
1659         while [ $c -gt 1 ]; do
1660                 word="${COMP_WORDS[c]}"
1661                 case "$word" in
1662                 --global|--system|--file=*)
1663                         config_file="$word"
1664                         break
1665                         ;;
1666                 -f|--file)
1667                         config_file="$word $prevword"
1668                         break
1669                         ;;
1670                 esac
1671                 prevword=$word
1672                 c=$((--c))
1673         done
1675         git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1676         while read line
1677         do
1678                 case "$line" in
1679                 *.*=*)
1680                         echo "${line/=*/}"
1681                         ;;
1682                 esac
1683         done
1686 _git_config ()
1688         local cur="${COMP_WORDS[COMP_CWORD]}"
1689         local prv="${COMP_WORDS[COMP_CWORD-1]}"
1690         case "$prv" in
1691         branch.*.remote)
1692                 __gitcomp "$(__git_remotes)"
1693                 return
1694                 ;;
1695         branch.*.merge)
1696                 __gitcomp "$(__git_refs)"
1697                 return
1698                 ;;
1699         remote.*.fetch)
1700                 local remote="${prv#remote.}"
1701                 remote="${remote%.fetch}"
1702                 __gitcomp "$(__git_refs_remotes "$remote")"
1703                 return
1704                 ;;
1705         remote.*.push)
1706                 local remote="${prv#remote.}"
1707                 remote="${remote%.push}"
1708                 __gitcomp "$(git --git-dir="$(__gitdir)" \
1709                         for-each-ref --format='%(refname):%(refname)' \
1710                         refs/heads)"
1711                 return
1712                 ;;
1713         pull.twohead|pull.octopus)
1714                 __git_compute_merge_strategies
1715                 __gitcomp "$__git_merge_strategies"
1716                 return
1717                 ;;
1718         color.branch|color.diff|color.interactive|\
1719         color.showbranch|color.status|color.ui)
1720                 __gitcomp "always never auto"
1721                 return
1722                 ;;
1723         color.pager)
1724                 __gitcomp "false true"
1725                 return
1726                 ;;
1727         color.*.*)
1728                 __gitcomp "
1729                         normal black red green yellow blue magenta cyan white
1730                         bold dim ul blink reverse
1731                         "
1732                 return
1733                 ;;
1734         help.format)
1735                 __gitcomp "man info web html"
1736                 return
1737                 ;;
1738         log.date)
1739                 __gitcomp "$__git_log_date_formats"
1740                 return
1741                 ;;
1742         sendemail.aliasesfiletype)
1743                 __gitcomp "mutt mailrc pine elm gnus"
1744                 return
1745                 ;;
1746         sendemail.confirm)
1747                 __gitcomp "$__git_send_email_confirm_options"
1748                 return
1749                 ;;
1750         sendemail.suppresscc)
1751                 __gitcomp "$__git_send_email_suppresscc_options"
1752                 return
1753                 ;;
1754         --get|--get-all|--unset|--unset-all)
1755                 __gitcomp "$(__git_config_get_set_variables)"
1756                 return
1757                 ;;
1758         *.*)
1759                 COMPREPLY=()
1760                 return
1761                 ;;
1762         esac
1763         case "$cur" in
1764         --*)
1765                 __gitcomp "
1766                         --global --system --file=
1767                         --list --replace-all
1768                         --get --get-all --get-regexp
1769                         --add --unset --unset-all
1770                         --remove-section --rename-section
1771                         "
1772                 return
1773                 ;;
1774         branch.*.*)
1775                 local pfx="${cur%.*}."
1776                 cur="${cur##*.}"
1777                 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1778                 return
1779                 ;;
1780         branch.*)
1781                 local pfx="${cur%.*}."
1782                 cur="${cur#*.}"
1783                 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1784                 return
1785                 ;;
1786         guitool.*.*)
1787                 local pfx="${cur%.*}."
1788                 cur="${cur##*.}"
1789                 __gitcomp "
1790                         argprompt cmd confirm needsfile noconsole norescan
1791                         prompt revprompt revunmerged title
1792                         " "$pfx" "$cur"
1793                 return
1794                 ;;
1795         difftool.*.*)
1796                 local pfx="${cur%.*}."
1797                 cur="${cur##*.}"
1798                 __gitcomp "cmd path" "$pfx" "$cur"
1799                 return
1800                 ;;
1801         man.*.*)
1802                 local pfx="${cur%.*}."
1803                 cur="${cur##*.}"
1804                 __gitcomp "cmd path" "$pfx" "$cur"
1805                 return
1806                 ;;
1807         mergetool.*.*)
1808                 local pfx="${cur%.*}."
1809                 cur="${cur##*.}"
1810                 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1811                 return
1812                 ;;
1813         pager.*)
1814                 local pfx="${cur%.*}."
1815                 cur="${cur#*.}"
1816                 __git_compute_all_commands
1817                 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1818                 return
1819                 ;;
1820         remote.*.*)
1821                 local pfx="${cur%.*}."
1822                 cur="${cur##*.}"
1823                 __gitcomp "
1824                         url proxy fetch push mirror skipDefaultUpdate
1825                         receivepack uploadpack tagopt pushurl
1826                         " "$pfx" "$cur"
1827                 return
1828                 ;;
1829         remote.*)
1830                 local pfx="${cur%.*}."
1831                 cur="${cur#*.}"
1832                 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1833                 return
1834                 ;;
1835         url.*.*)
1836                 local pfx="${cur%.*}."
1837                 cur="${cur##*.}"
1838                 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1839                 return
1840                 ;;
1841         esac
1842         __gitcomp "
1843                 add.ignore-errors
1844                 alias.
1845                 apply.ignorewhitespace
1846                 apply.whitespace
1847                 branch.autosetupmerge
1848                 branch.autosetuprebase
1849                 clean.requireForce
1850                 color.branch
1851                 color.branch.current
1852                 color.branch.local
1853                 color.branch.plain
1854                 color.branch.remote
1855                 color.diff
1856                 color.diff.commit
1857                 color.diff.frag
1858                 color.diff.meta
1859                 color.diff.new
1860                 color.diff.old
1861                 color.diff.plain
1862                 color.diff.whitespace
1863                 color.grep
1864                 color.grep.external
1865                 color.grep.match
1866                 color.interactive
1867                 color.interactive.header
1868                 color.interactive.help
1869                 color.interactive.prompt
1870                 color.pager
1871                 color.showbranch
1872                 color.status
1873                 color.status.added
1874                 color.status.changed
1875                 color.status.header
1876                 color.status.nobranch
1877                 color.status.untracked
1878                 color.status.updated
1879                 color.ui
1880                 commit.template
1881                 core.autocrlf
1882                 core.bare
1883                 core.compression
1884                 core.createObject
1885                 core.deltaBaseCacheLimit
1886                 core.editor
1887                 core.excludesfile
1888                 core.fileMode
1889                 core.fsyncobjectfiles
1890                 core.gitProxy
1891                 core.ignoreCygwinFSTricks
1892                 core.ignoreStat
1893                 core.logAllRefUpdates
1894                 core.loosecompression
1895                 core.packedGitLimit
1896                 core.packedGitWindowSize
1897                 core.pager
1898                 core.preferSymlinkRefs
1899                 core.preloadindex
1900                 core.quotepath
1901                 core.repositoryFormatVersion
1902                 core.safecrlf
1903                 core.sharedRepository
1904                 core.symlinks
1905                 core.trustctime
1906                 core.warnAmbiguousRefs
1907                 core.whitespace
1908                 core.worktree
1909                 diff.autorefreshindex
1910                 diff.external
1911                 diff.mnemonicprefix
1912                 diff.renameLimit
1913                 diff.renameLimit.
1914                 diff.renames
1915                 diff.suppressBlankEmpty
1916                 diff.tool
1917                 diff.wordRegex
1918                 difftool.
1919                 difftool.prompt
1920                 fetch.unpackLimit
1921                 format.attach
1922                 format.cc
1923                 format.headers
1924                 format.numbered
1925                 format.pretty
1926                 format.signature
1927                 format.signoff
1928                 format.subjectprefix
1929                 format.suffix
1930                 format.thread
1931                 gc.aggressiveWindow
1932                 gc.auto
1933                 gc.autopacklimit
1934                 gc.packrefs
1935                 gc.pruneexpire
1936                 gc.reflogexpire
1937                 gc.reflogexpireunreachable
1938                 gc.rerereresolved
1939                 gc.rerereunresolved
1940                 gitcvs.allbinary
1941                 gitcvs.commitmsgannotation
1942                 gitcvs.dbTableNamePrefix
1943                 gitcvs.dbdriver
1944                 gitcvs.dbname
1945                 gitcvs.dbpass
1946                 gitcvs.dbuser
1947                 gitcvs.enabled
1948                 gitcvs.logfile
1949                 gitcvs.usecrlfattr
1950                 guitool.
1951                 gui.blamehistoryctx
1952                 gui.commitmsgwidth
1953                 gui.copyblamethreshold
1954                 gui.diffcontext
1955                 gui.encoding
1956                 gui.fastcopyblame
1957                 gui.matchtrackingbranch
1958                 gui.newbranchtemplate
1959                 gui.pruneduringfetch
1960                 gui.spellingdictionary
1961                 gui.trustmtime
1962                 help.autocorrect
1963                 help.browser
1964                 help.format
1965                 http.lowSpeedLimit
1966                 http.lowSpeedTime
1967                 http.maxRequests
1968                 http.noEPSV
1969                 http.proxy
1970                 http.sslCAInfo
1971                 http.sslCAPath
1972                 http.sslCert
1973                 http.sslKey
1974                 http.sslVerify
1975                 i18n.commitEncoding
1976                 i18n.logOutputEncoding
1977                 imap.folder
1978                 imap.host
1979                 imap.pass
1980                 imap.port
1981                 imap.preformattedHTML
1982                 imap.sslverify
1983                 imap.tunnel
1984                 imap.user
1985                 instaweb.browser
1986                 instaweb.httpd
1987                 instaweb.local
1988                 instaweb.modulepath
1989                 instaweb.port
1990                 interactive.singlekey
1991                 log.date
1992                 log.showroot
1993                 mailmap.file
1994                 man.
1995                 man.viewer
1996                 merge.conflictstyle
1997                 merge.log
1998                 merge.renameLimit
1999                 merge.stat
2000                 merge.tool
2001                 merge.verbosity
2002                 mergetool.
2003                 mergetool.keepBackup
2004                 mergetool.prompt
2005                 pack.compression
2006                 pack.deltaCacheLimit
2007                 pack.deltaCacheSize
2008                 pack.depth
2009                 pack.indexVersion
2010                 pack.packSizeLimit
2011                 pack.threads
2012                 pack.window
2013                 pack.windowMemory
2014                 pager.
2015                 pull.octopus
2016                 pull.twohead
2017                 push.default
2018                 rebase.stat
2019                 receive.denyCurrentBranch
2020                 receive.denyDeletes
2021                 receive.denyNonFastForwards
2022                 receive.fsckObjects
2023                 receive.unpackLimit
2024                 repack.usedeltabaseoffset
2025                 rerere.autoupdate
2026                 rerere.enabled
2027                 sendemail.aliasesfile
2028                 sendemail.aliasesfiletype
2029                 sendemail.bcc
2030                 sendemail.cc
2031                 sendemail.cccmd
2032                 sendemail.chainreplyto
2033                 sendemail.confirm
2034                 sendemail.envelopesender
2035                 sendemail.multiedit
2036                 sendemail.signedoffbycc
2037                 sendemail.smtpencryption
2038                 sendemail.smtppass
2039                 sendemail.smtpserver
2040                 sendemail.smtpserverport
2041                 sendemail.smtpuser
2042                 sendemail.suppresscc
2043                 sendemail.suppressfrom
2044                 sendemail.thread
2045                 sendemail.to
2046                 sendemail.validate
2047                 showbranch.default
2048                 status.relativePaths
2049                 status.showUntrackedFiles
2050                 tar.umask
2051                 transfer.unpackLimit
2052                 url.
2053                 user.email
2054                 user.name
2055                 user.signingkey
2056                 web.browser
2057                 branch. remote.
2058         "
2061 _git_remote ()
2063         local subcommands="add rename rm show prune update set-head"
2064         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2065         if [ -z "$subcommand" ]; then
2066                 __gitcomp "$subcommands"
2067                 return
2068         fi
2070         case "$subcommand" in
2071         rename|rm|show|prune)
2072                 __gitcomp "$(__git_remotes)"
2073                 ;;
2074         update)
2075                 local i c='' IFS=$'\n'
2076                 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2077                         i="${i#remotes.}"
2078                         c="$c ${i/ */}"
2079                 done
2080                 __gitcomp "$c"
2081                 ;;
2082         *)
2083                 COMPREPLY=()
2084                 ;;
2085         esac
2088 _git_replace ()
2090         __gitcomp "$(__git_refs)"
2093 _git_reset ()
2095         __git_has_doubledash && return
2097         local cur="${COMP_WORDS[COMP_CWORD]}"
2098         case "$cur" in
2099         --*)
2100                 __gitcomp "--merge --mixed --hard --soft --patch"
2101                 return
2102                 ;;
2103         esac
2104         __gitcomp "$(__git_refs)"
2107 _git_revert ()
2109         local cur="${COMP_WORDS[COMP_CWORD]}"
2110         case "$cur" in
2111         --*)
2112                 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2113                 return
2114                 ;;
2115         esac
2116         __gitcomp "$(__git_refs)"
2119 _git_rm ()
2121         __git_has_doubledash && return
2123         local cur="${COMP_WORDS[COMP_CWORD]}"
2124         case "$cur" in
2125         --*)
2126                 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2127                 return
2128                 ;;
2129         esac
2130         COMPREPLY=()
2133 _git_shortlog ()
2135         __git_has_doubledash && return
2137         local cur="${COMP_WORDS[COMP_CWORD]}"
2138         case "$cur" in
2139         --*)
2140                 __gitcomp "
2141                         $__git_log_common_options
2142                         $__git_log_shortlog_options
2143                         --numbered --summary
2144                         "
2145                 return
2146                 ;;
2147         esac
2148         __git_complete_revlist
2151 _git_show ()
2153         __git_has_doubledash && return
2155         local cur="${COMP_WORDS[COMP_CWORD]}"
2156         case "$cur" in
2157         --pretty=*)
2158                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2159                         " "" "${cur##--pretty=}"
2160                 return
2161                 ;;
2162         --format=*)
2163                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2164                         " "" "${cur##--format=}"
2165                 return
2166                 ;;
2167         --*)
2168                 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2169                         $__git_diff_common_options
2170                         "
2171                 return
2172                 ;;
2173         esac
2174         __git_complete_file
2177 _git_show_branch ()
2179         local cur="${COMP_WORDS[COMP_CWORD]}"
2180         case "$cur" in
2181         --*)
2182                 __gitcomp "
2183                         --all --remotes --topo-order --current --more=
2184                         --list --independent --merge-base --no-name
2185                         --color --no-color
2186                         --sha1-name --sparse --topics --reflog
2187                         "
2188                 return
2189                 ;;
2190         esac
2191         __git_complete_revlist
2194 _git_stash ()
2196         local cur="${COMP_WORDS[COMP_CWORD]}"
2197         local save_opts='--keep-index --no-keep-index --quiet --patch'
2198         local subcommands='save list show apply clear drop pop create branch'
2199         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2200         if [ -z "$subcommand" ]; then
2201                 case "$cur" in
2202                 --*)
2203                         __gitcomp "$save_opts"
2204                         ;;
2205                 *)
2206                         if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2207                                 __gitcomp "$subcommands"
2208                         else
2209                                 COMPREPLY=()
2210                         fi
2211                         ;;
2212                 esac
2213         else
2214                 case "$subcommand,$cur" in
2215                 save,--*)
2216                         __gitcomp "$save_opts"
2217                         ;;
2218                 apply,--*|pop,--*)
2219                         __gitcomp "--index --quiet"
2220                         ;;
2221                 show,--*|drop,--*|branch,--*)
2222                         COMPREPLY=()
2223                         ;;
2224                 show,*|apply,*|drop,*|pop,*|branch,*)
2225                         __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2226                                         | sed -n -e 's/:.*//p')"
2227                         ;;
2228                 *)
2229                         COMPREPLY=()
2230                         ;;
2231                 esac
2232         fi
2235 _git_submodule ()
2237         __git_has_doubledash && return
2239         local subcommands="add status init update summary foreach sync"
2240         if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2241                 local cur="${COMP_WORDS[COMP_CWORD]}"
2242                 case "$cur" in
2243                 --*)
2244                         __gitcomp "--quiet --cached"
2245                         ;;
2246                 *)
2247                         __gitcomp "$subcommands"
2248                         ;;
2249                 esac
2250                 return
2251         fi
2254 _git_svn ()
2256         local subcommands="
2257                 init fetch clone rebase dcommit log find-rev
2258                 set-tree commit-diff info create-ignore propget
2259                 proplist show-ignore show-externals branch tag blame
2260                 migrate mkdirs reset gc
2261                 "
2262         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2263         if [ -z "$subcommand" ]; then
2264                 __gitcomp "$subcommands"
2265         else
2266                 local remote_opts="--username= --config-dir= --no-auth-cache"
2267                 local fc_opts="
2268                         --follow-parent --authors-file= --repack=
2269                         --no-metadata --use-svm-props --use-svnsync-props
2270                         --log-window-size= --no-checkout --quiet
2271                         --repack-flags --use-log-author --localtime
2272                         --ignore-paths= $remote_opts
2273                         "
2274                 local init_opts="
2275                         --template= --shared= --trunk= --tags=
2276                         --branches= --stdlayout --minimize-url
2277                         --no-metadata --use-svm-props --use-svnsync-props
2278                         --rewrite-root= --prefix= --use-log-author
2279                         --add-author-from $remote_opts
2280                         "
2281                 local cmt_opts="
2282                         --edit --rmdir --find-copies-harder --copy-similarity=
2283                         "
2285                 local cur="${COMP_WORDS[COMP_CWORD]}"
2286                 case "$subcommand,$cur" in
2287                 fetch,--*)
2288                         __gitcomp "--revision= --fetch-all $fc_opts"
2289                         ;;
2290                 clone,--*)
2291                         __gitcomp "--revision= $fc_opts $init_opts"
2292                         ;;
2293                 init,--*)
2294                         __gitcomp "$init_opts"
2295                         ;;
2296                 dcommit,--*)
2297                         __gitcomp "
2298                                 --merge --strategy= --verbose --dry-run
2299                                 --fetch-all --no-rebase --commit-url
2300                                 --revision $cmt_opts $fc_opts
2301                                 "
2302                         ;;
2303                 set-tree,--*)
2304                         __gitcomp "--stdin $cmt_opts $fc_opts"
2305                         ;;
2306                 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2307                 show-externals,--*|mkdirs,--*)
2308                         __gitcomp "--revision="
2309                         ;;
2310                 log,--*)
2311                         __gitcomp "
2312                                 --limit= --revision= --verbose --incremental
2313                                 --oneline --show-commit --non-recursive
2314                                 --authors-file= --color
2315                                 "
2316                         ;;
2317                 rebase,--*)
2318                         __gitcomp "
2319                                 --merge --verbose --strategy= --local
2320                                 --fetch-all --dry-run $fc_opts
2321                                 "
2322                         ;;
2323                 commit-diff,--*)
2324                         __gitcomp "--message= --file= --revision= $cmt_opts"
2325                         ;;
2326                 info,--*)
2327                         __gitcomp "--url"
2328                         ;;
2329                 branch,--*)
2330                         __gitcomp "--dry-run --message --tag"
2331                         ;;
2332                 tag,--*)
2333                         __gitcomp "--dry-run --message"
2334                         ;;
2335                 blame,--*)
2336                         __gitcomp "--git-format"
2337                         ;;
2338                 migrate,--*)
2339                         __gitcomp "
2340                                 --config-dir= --ignore-paths= --minimize
2341                                 --no-auth-cache --username=
2342                                 "
2343                         ;;
2344                 reset,--*)
2345                         __gitcomp "--revision= --parent"
2346                         ;;
2347                 *)
2348                         COMPREPLY=()
2349                         ;;
2350                 esac
2351         fi
2354 _git_tag ()
2356         local i c=1 f=0
2357         while [ $c -lt $COMP_CWORD ]; do
2358                 i="${COMP_WORDS[c]}"
2359                 case "$i" in
2360                 -d|-v)
2361                         __gitcomp "$(__git_tags)"
2362                         return
2363                         ;;
2364                 -f)
2365                         f=1
2366                         ;;
2367                 esac
2368                 c=$((++c))
2369         done
2371         case "${COMP_WORDS[COMP_CWORD-1]}" in
2372         -m|-F)
2373                 COMPREPLY=()
2374                 ;;
2375         -*|tag)
2376                 if [ $f = 1 ]; then
2377                         __gitcomp "$(__git_tags)"
2378                 else
2379                         COMPREPLY=()
2380                 fi
2381                 ;;
2382         *)
2383                 __gitcomp "$(__git_refs)"
2384                 ;;
2385         esac
2388 _git_whatchanged ()
2390         _git_log
2393 _git ()
2395         local i c=1 command __git_dir
2397         if [[ -n ${ZSH_VERSION-} ]]; then
2398                 emulate -L bash
2399                 setopt KSH_TYPESET
2400         fi
2402         while [ $c -lt $COMP_CWORD ]; do
2403                 i="${COMP_WORDS[c]}"
2404                 case "$i" in
2405                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2406                 --bare)      __git_dir="." ;;
2407                 --version|-p|--paginate) ;;
2408                 --help) command="help"; break ;;
2409                 *) command="$i"; break ;;
2410                 esac
2411                 c=$((++c))
2412         done
2414         if [ -z "$command" ]; then
2415                 case "${COMP_WORDS[COMP_CWORD]}" in
2416                 --*)   __gitcomp "
2417                         --paginate
2418                         --no-pager
2419                         --git-dir=
2420                         --bare
2421                         --version
2422                         --exec-path
2423                         --html-path
2424                         --work-tree=
2425                         --help
2426                         "
2427                         ;;
2428                 *)     __git_compute_porcelain_commands
2429                        __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2430                 esac
2431                 return
2432         fi
2434         local completion_func="_git_${command//-/_}"
2435         declare -f $completion_func >/dev/null && $completion_func && return
2437         local expansion=$(__git_aliased_command "$command")
2438         if [ -n "$expansion" ]; then
2439                 completion_func="_git_${expansion//-/_}"
2440                 declare -f $completion_func >/dev/null && $completion_func
2441         fi
2444 _gitk ()
2446         if [[ -n ${ZSH_VERSION-} ]]; then
2447                 emulate -L bash
2448                 setopt KSH_TYPESET
2449         fi
2451         __git_has_doubledash && return
2453         local cur="${COMP_WORDS[COMP_CWORD]}"
2454         local g="$(__gitdir)"
2455         local merge=""
2456         if [ -f "$g/MERGE_HEAD" ]; then
2457                 merge="--merge"
2458         fi
2459         case "$cur" in
2460         --*)
2461                 __gitcomp "
2462                         $__git_log_common_options
2463                         $__git_log_gitk_options
2464                         $merge
2465                         "
2466                 return
2467                 ;;
2468         esac
2469         __git_complete_revlist
2472 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2473         || complete -o default -o nospace -F _git git
2474 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2475         || complete -o default -o nospace -F _gitk gitk
2477 # The following are necessary only for Cygwin, and only are needed
2478 # when the user has tab-completed the executable name and consequently
2479 # included the '.exe' suffix.
2481 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2482 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2483         || complete -o default -o nospace -F _git git.exe
2484 fi
2486 if [[ -n ${ZSH_VERSION-} ]]; then
2487         shopt () {
2488                 local option
2489                 if [ $# -ne 2 ]; then
2490                         echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2491                         return 1
2492                 fi
2493                 case "$2" in
2494                 nullglob)
2495                         option="$2"
2496                         ;;
2497                 *)
2498                         echo "$0: invalid option: $2" >&2
2499                         return 1
2500                 esac
2501                 case "$1" in
2502                 -q)     setopt | grep -q "$option" ;;
2503                 -u)     unsetopt "$option" ;;
2504                 -s)     setopt "$option" ;;
2505                 *)
2506                         echo "$0: invalid flag: $1" >&2
2507                         return 1
2508                 esac
2509         }
2510 fi