lost-found: remove deprecated command
[git] / contrib / completion / git-completion.bash
1 #!bash
2 #
3 # bash/zsh 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 #    *) file paths within current working directory and index
17 #    *) common --long-options
18 #
19 # To use these routines:
20 #
21 #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
22 #    2) Add the following line to your .bashrc/.zshrc:
23 #        source ~/.git-completion.sh
24 #    3) Consider changing your PS1 to also show the current branch,
25 #       see git-prompt.sh for details.
26
27 case "$COMP_WORDBREAKS" in
28 *:*) : great ;;
29 *)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
30 esac
31
32 # __gitdir accepts 0 or 1 arguments (i.e., location)
33 # returns location of .git repo
34 __gitdir ()
35 {
36         if [ -z "${1-}" ]; then
37                 if [ -n "${__git_dir-}" ]; then
38                         echo "$__git_dir"
39                 elif [ -n "${GIT_DIR-}" ]; then
40                         test -d "${GIT_DIR-}" || return 1
41                         echo "$GIT_DIR"
42                 elif [ -d .git ]; then
43                         echo .git
44                 else
45                         git rev-parse --git-dir 2>/dev/null
46                 fi
47         elif [ -d "$1/.git" ]; then
48                 echo "$1/.git"
49         else
50                 echo "$1"
51         fi
52 }
53
54 # The following function is based on code from:
55 #
56 #   bash_completion - programmable completion functions for bash 3.2+
57 #
58 #   Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
59 #             © 2009-2010, Bash Completion Maintainers
60 #                     <bash-completion-devel@lists.alioth.debian.org>
61 #
62 #   This program is free software; you can redistribute it and/or modify
63 #   it under the terms of the GNU General Public License as published by
64 #   the Free Software Foundation; either version 2, or (at your option)
65 #   any later version.
66 #
67 #   This program is distributed in the hope that it will be useful,
68 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
69 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
70 #   GNU General Public License for more details.
71 #
72 #   You should have received a copy of the GNU General Public License
73 #   along with this program; if not, write to the Free Software Foundation,
74 #   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
75 #
76 #   The latest version of this software can be obtained here:
77 #
78 #   http://bash-completion.alioth.debian.org/
79 #
80 #   RELEASE: 2.x
81
82 # This function can be used to access a tokenized list of words
83 # on the command line:
84 #
85 #       __git_reassemble_comp_words_by_ref '=:'
86 #       if test "${words_[cword_-1]}" = -w
87 #       then
88 #               ...
89 #       fi
90 #
91 # The argument should be a collection of characters from the list of
92 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
93 # characters.
94 #
95 # This is roughly equivalent to going back in time and setting
96 # COMP_WORDBREAKS to exclude those characters.  The intent is to
97 # make option types like --date=<type> and <rev>:<path> easy to
98 # recognize by treating each shell word as a single token.
99 #
100 # It is best not to set COMP_WORDBREAKS directly because the value is
101 # shared with other completion scripts.  By the time the completion
102 # function gets called, COMP_WORDS has already been populated so local
103 # changes to COMP_WORDBREAKS have no effect.
104 #
105 # Output: words_, cword_, cur_.
106
107 __git_reassemble_comp_words_by_ref()
108 {
109         local exclude i j first
110         # Which word separators to exclude?
111         exclude="${1//[^$COMP_WORDBREAKS]}"
112         cword_=$COMP_CWORD
113         if [ -z "$exclude" ]; then
114                 words_=("${COMP_WORDS[@]}")
115                 return
116         fi
117         # List of word completion separators has shrunk;
118         # re-assemble words to complete.
119         for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
120                 # Append each nonempty word consisting of just
121                 # word separator characters to the current word.
122                 first=t
123                 while
124                         [ $i -gt 0 ] &&
125                         [ -n "${COMP_WORDS[$i]}" ] &&
126                         # word consists of excluded word separators
127                         [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
128                 do
129                         # Attach to the previous token,
130                         # unless the previous token is the command name.
131                         if [ $j -ge 2 ] && [ -n "$first" ]; then
132                                 ((j--))
133                         fi
134                         first=
135                         words_[$j]=${words_[j]}${COMP_WORDS[i]}
136                         if [ $i = $COMP_CWORD ]; then
137                                 cword_=$j
138                         fi
139                         if (($i < ${#COMP_WORDS[@]} - 1)); then
140                                 ((i++))
141                         else
142                                 # Done.
143                                 return
144                         fi
145                 done
146                 words_[$j]=${words_[j]}${COMP_WORDS[i]}
147                 if [ $i = $COMP_CWORD ]; then
148                         cword_=$j
149                 fi
150         done
151 }
152
153 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
154 _get_comp_words_by_ref ()
155 {
156         local exclude cur_ words_ cword_
157         if [ "$1" = "-n" ]; then
158                 exclude=$2
159                 shift 2
160         fi
161         __git_reassemble_comp_words_by_ref "$exclude"
162         cur_=${words_[cword_]}
163         while [ $# -gt 0 ]; do
164                 case "$1" in
165                 cur)
166                         cur=$cur_
167                         ;;
168                 prev)
169                         prev=${words_[$cword_-1]}
170                         ;;
171                 words)
172                         words=("${words_[@]}")
173                         ;;
174                 cword)
175                         cword=$cword_
176                         ;;
177                 esac
178                 shift
179         done
180 }
181 fi
182
183 __gitcompadd ()
184 {
185         local i=0
186         for x in $1; do
187                 if [[ "$x" == "$3"* ]]; then
188                         COMPREPLY[i++]="$2$x$4"
189                 fi
190         done
191 }
192
193 # Generates completion reply, appending a space to possible completion words,
194 # if necessary.
195 # It accepts 1 to 4 arguments:
196 # 1: List of possible completion words.
197 # 2: A prefix to be added to each possible completion word (optional).
198 # 3: Generate possible completion matches for this word (optional).
199 # 4: A suffix to be appended to each possible completion word (optional).
200 __gitcomp ()
201 {
202         local cur_="${3-$cur}"
203
204         case "$cur_" in
205         --*=)
206                 ;;
207         *)
208                 local c i=0 IFS=$' \t\n'
209                 for c in $1; do
210                         c="$c${4-}"
211                         if [[ $c == "$cur_"* ]]; then
212                                 case $c in
213                                 --*=*|*.) ;;
214                                 *) c="$c " ;;
215                                 esac
216                                 COMPREPLY[i++]="${2-}$c"
217                         fi
218                 done
219                 ;;
220         esac
221 }
222
223 # Generates completion reply from newline-separated possible completion words
224 # by appending a space to all of them.
225 # It accepts 1 to 4 arguments:
226 # 1: List of possible completion words, separated by a single newline.
227 # 2: A prefix to be added to each possible completion word (optional).
228 # 3: Generate possible completion matches for this word (optional).
229 # 4: A suffix to be appended to each possible completion word instead of
230 #    the default space (optional).  If specified but empty, nothing is
231 #    appended.
232 __gitcomp_nl ()
233 {
234         local IFS=$'\n'
235         __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
236 }
237
238 # Generates completion reply with compgen from newline-separated possible
239 # completion filenames.
240 # It accepts 1 to 3 arguments:
241 # 1: List of possible completion filenames, separated by a single newline.
242 # 2: A directory prefix to be added to each possible completion filename
243 #    (optional).
244 # 3: Generate possible completion matches for this word (optional).
245 __gitcomp_file ()
246 {
247         local IFS=$'\n'
248
249         # XXX does not work when the directory prefix contains a tilde,
250         # since tilde expansion is not applied.
251         # This means that COMPREPLY will be empty and Bash default
252         # completion will be used.
253         __gitcompadd "$1" "${2-}" "${3-$cur}" ""
254
255         # use a hack to enable file mode in bash < 4
256         compopt -o filenames +o nospace 2>/dev/null ||
257         compgen -f /non-existing-dir/ > /dev/null
258 }
259
260 # Execute 'git ls-files', unless the --committable option is specified, in
261 # which case it runs 'git diff-index' to find out the files that can be
262 # committed.  It return paths relative to the directory specified in the first
263 # argument, and using the options specified in the second argument.
264 __git_ls_files_helper ()
265 {
266         (
267                 test -n "${CDPATH+set}" && unset CDPATH
268                 cd "$1"
269                 if [ "$2" == "--committable" ]; then
270                         git diff-index --name-only --relative HEAD
271                 else
272                         # NOTE: $2 is not quoted in order to support multiple options
273                         git ls-files --exclude-standard $2
274                 fi
275         ) 2>/dev/null
276 }
277
278
279 # __git_index_files accepts 1 or 2 arguments:
280 # 1: Options to pass to ls-files (required).
281 # 2: A directory path (optional).
282 #    If provided, only files within the specified directory are listed.
283 #    Sub directories are never recursed.  Path must have a trailing
284 #    slash.
285 __git_index_files ()
286 {
287         local dir="$(__gitdir)" root="${2-.}" file
288
289         if [ -d "$dir" ]; then
290                 __git_ls_files_helper "$root" "$1" |
291                 while read -r file; do
292                         case "$file" in
293                         ?*/*) echo "${file%%/*}" ;;
294                         *) echo "$file" ;;
295                         esac
296                 done | sort | uniq
297         fi
298 }
299
300 __git_heads ()
301 {
302         local dir="$(__gitdir)"
303         if [ -d "$dir" ]; then
304                 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
305                         refs/heads
306                 return
307         fi
308 }
309
310 __git_tags ()
311 {
312         local dir="$(__gitdir)"
313         if [ -d "$dir" ]; then
314                 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
315                         refs/tags
316                 return
317         fi
318 }
319
320 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
321 # presence of 2nd argument means use the guess heuristic employed
322 # by checkout for tracking branches
323 __git_refs ()
324 {
325         local i hash dir="$(__gitdir "${1-}")" track="${2-}"
326         local format refs
327         if [ -d "$dir" ]; then
328                 case "$cur" in
329                 refs|refs/*)
330                         format="refname"
331                         refs="${cur%/*}"
332                         track=""
333                         ;;
334                 *)
335                         for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
336                                 if [ -e "$dir/$i" ]; then echo $i; fi
337                         done
338                         format="refname:short"
339                         refs="refs/tags refs/heads refs/remotes"
340                         ;;
341                 esac
342                 git --git-dir="$dir" for-each-ref --format="%($format)" \
343                         $refs
344                 if [ -n "$track" ]; then
345                         # employ the heuristic used by git checkout
346                         # Try to find a remote branch that matches the completion word
347                         # but only output if the branch name is unique
348                         local ref entry
349                         git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
350                                 "refs/remotes/" | \
351                         while read -r entry; do
352                                 eval "$entry"
353                                 ref="${ref#*/}"
354                                 if [[ "$ref" == "$cur"* ]]; then
355                                         echo "$ref"
356                                 fi
357                         done | sort | uniq -u
358                 fi
359                 return
360         fi
361         case "$cur" in
362         refs|refs/*)
363                 git ls-remote "$dir" "$cur*" 2>/dev/null | \
364                 while read -r hash i; do
365                         case "$i" in
366                         *^{}) ;;
367                         *) echo "$i" ;;
368                         esac
369                 done
370                 ;;
371         *)
372                 echo "HEAD"
373                 git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
374                 ;;
375         esac
376 }
377
378 # __git_refs2 requires 1 argument (to pass to __git_refs)
379 __git_refs2 ()
380 {
381         local i
382         for i in $(__git_refs "$1"); do
383                 echo "$i:$i"
384         done
385 }
386
387 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
388 __git_refs_remotes ()
389 {
390         local i hash
391         git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
392         while read -r hash i; do
393                 echo "$i:refs/remotes/$1/${i#refs/heads/}"
394         done
395 }
396
397 __git_remotes ()
398 {
399         local i IFS=$'\n' d="$(__gitdir)"
400         test -d "$d/remotes" && ls -1 "$d/remotes"
401         for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
402                 i="${i#remote.}"
403                 echo "${i/.url*/}"
404         done
405 }
406
407 __git_list_merge_strategies ()
408 {
409         git merge -s help 2>&1 |
410         sed -n -e '/[Aa]vailable strategies are: /,/^$/{
411                 s/\.$//
412                 s/.*://
413                 s/^[    ]*//
414                 s/[     ]*$//
415                 p
416         }'
417 }
418
419 __git_merge_strategies=
420 # 'git merge -s help' (and thus detection of the merge strategy
421 # list) fails, unfortunately, if run outside of any git working
422 # tree.  __git_merge_strategies is set to the empty string in
423 # that case, and the detection will be repeated the next time it
424 # is needed.
425 __git_compute_merge_strategies ()
426 {
427         test -n "$__git_merge_strategies" ||
428         __git_merge_strategies=$(__git_list_merge_strategies)
429 }
430
431 __git_complete_revlist_file ()
432 {
433         local pfx ls ref cur_="$cur"
434         case "$cur_" in
435         *..?*:*)
436                 return
437                 ;;
438         ?*:*)
439                 ref="${cur_%%:*}"
440                 cur_="${cur_#*:}"
441                 case "$cur_" in
442                 ?*/*)
443                         pfx="${cur_%/*}"
444                         cur_="${cur_##*/}"
445                         ls="$ref:$pfx"
446                         pfx="$pfx/"
447                         ;;
448                 *)
449                         ls="$ref"
450                         ;;
451                 esac
452
453                 case "$COMP_WORDBREAKS" in
454                 *:*) : great ;;
455                 *)   pfx="$ref:$pfx" ;;
456                 esac
457
458                 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
459                                 | sed '/^100... blob /{
460                                            s,^.*        ,,
461                                            s,$, ,
462                                        }
463                                        /^120000 blob /{
464                                            s,^.*        ,,
465                                            s,$, ,
466                                        }
467                                        /^040000 tree /{
468                                            s,^.*        ,,
469                                            s,$,/,
470                                        }
471                                        s/^.*    //')" \
472                         "$pfx" "$cur_" ""
473                 ;;
474         *...*)
475                 pfx="${cur_%...*}..."
476                 cur_="${cur_#*...}"
477                 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
478                 ;;
479         *..*)
480                 pfx="${cur_%..*}.."
481                 cur_="${cur_#*..}"
482                 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
483                 ;;
484         *)
485                 __gitcomp_nl "$(__git_refs)"
486                 ;;
487         esac
488 }
489
490
491 # __git_complete_index_file requires 1 argument:
492 # 1: the options to pass to ls-file
493 #
494 # The exception is --committable, which finds the files appropriate commit.
495 __git_complete_index_file ()
496 {
497         local pfx="" cur_="$cur"
498
499         case "$cur_" in
500         ?*/*)
501                 pfx="${cur_%/*}"
502                 cur_="${cur_##*/}"
503                 pfx="${pfx}/"
504                 ;;
505         esac
506
507         __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
508 }
509
510 __git_complete_file ()
511 {
512         __git_complete_revlist_file
513 }
514
515 __git_complete_revlist ()
516 {
517         __git_complete_revlist_file
518 }
519
520 __git_complete_remote_or_refspec ()
521 {
522         local cur_="$cur" cmd="${words[1]}"
523         local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
524         if [ "$cmd" = "remote" ]; then
525                 ((c++))
526         fi
527         while [ $c -lt $cword ]; do
528                 i="${words[c]}"
529                 case "$i" in
530                 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
531                 --all)
532                         case "$cmd" in
533                         push) no_complete_refspec=1 ;;
534                         fetch)
535                                 return
536                                 ;;
537                         *) ;;
538                         esac
539                         ;;
540                 -*) ;;
541                 *) remote="$i"; break ;;
542                 esac
543                 ((c++))
544         done
545         if [ -z "$remote" ]; then
546                 __gitcomp_nl "$(__git_remotes)"
547                 return
548         fi
549         if [ $no_complete_refspec = 1 ]; then
550                 return
551         fi
552         [ "$remote" = "." ] && remote=
553         case "$cur_" in
554         *:*)
555                 case "$COMP_WORDBREAKS" in
556                 *:*) : great ;;
557                 *)   pfx="${cur_%%:*}:" ;;
558                 esac
559                 cur_="${cur_#*:}"
560                 lhs=0
561                 ;;
562         +*)
563                 pfx="+"
564                 cur_="${cur_#+}"
565                 ;;
566         esac
567         case "$cmd" in
568         fetch)
569                 if [ $lhs = 1 ]; then
570                         __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
571                 else
572                         __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
573                 fi
574                 ;;
575         pull|remote)
576                 if [ $lhs = 1 ]; then
577                         __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
578                 else
579                         __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
580                 fi
581                 ;;
582         push)
583                 if [ $lhs = 1 ]; then
584                         __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
585                 else
586                         __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
587                 fi
588                 ;;
589         esac
590 }
591
592 __git_complete_strategy ()
593 {
594         __git_compute_merge_strategies
595         case "$prev" in
596         -s|--strategy)
597                 __gitcomp "$__git_merge_strategies"
598                 return 0
599         esac
600         case "$cur" in
601         --strategy=*)
602                 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
603                 return 0
604                 ;;
605         esac
606         return 1
607 }
608
609 __git_commands () {
610         if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
611         then
612                 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
613         else
614                 git help -a|egrep '^  [a-zA-Z0-9]'
615         fi
616 }
617
618 __git_list_all_commands ()
619 {
620         local i IFS=" "$'\n'
621         for i in $(__git_commands)
622         do
623                 case $i in
624                 *--*)             : helper pattern;;
625                 *) echo $i;;
626                 esac
627         done
628 }
629
630 __git_all_commands=
631 __git_compute_all_commands ()
632 {
633         test -n "$__git_all_commands" ||
634         __git_all_commands=$(__git_list_all_commands)
635 }
636
637 __git_list_porcelain_commands ()
638 {
639         local i IFS=" "$'\n'
640         __git_compute_all_commands
641         for i in $__git_all_commands
642         do
643                 case $i in
644                 *--*)             : helper pattern;;
645                 applymbox)        : ask gittus;;
646                 applypatch)       : ask gittus;;
647                 archimport)       : import;;
648                 cat-file)         : plumbing;;
649                 check-attr)       : plumbing;;
650                 check-ignore)     : plumbing;;
651                 check-mailmap)    : plumbing;;
652                 check-ref-format) : plumbing;;
653                 checkout-index)   : plumbing;;
654                 commit-tree)      : plumbing;;
655                 count-objects)    : infrequent;;
656                 credential-cache) : credentials helper;;
657                 credential-store) : credentials helper;;
658                 cvsexportcommit)  : export;;
659                 cvsimport)        : import;;
660                 cvsserver)        : daemon;;
661                 daemon)           : daemon;;
662                 diff-files)       : plumbing;;
663                 diff-index)       : plumbing;;
664                 diff-tree)        : plumbing;;
665                 fast-import)      : import;;
666                 fast-export)      : export;;
667                 fsck-objects)     : plumbing;;
668                 fetch-pack)       : plumbing;;
669                 fmt-merge-msg)    : plumbing;;
670                 for-each-ref)     : plumbing;;
671                 hash-object)      : plumbing;;
672                 http-*)           : transport;;
673                 index-pack)       : plumbing;;
674                 init-db)          : deprecated;;
675                 local-fetch)      : plumbing;;
676                 ls-files)         : plumbing;;
677                 ls-remote)        : plumbing;;
678                 ls-tree)          : plumbing;;
679                 mailinfo)         : plumbing;;
680                 mailsplit)        : plumbing;;
681                 merge-*)          : plumbing;;
682                 mktree)           : plumbing;;
683                 mktag)            : plumbing;;
684                 pack-objects)     : plumbing;;
685                 pack-redundant)   : plumbing;;
686                 pack-refs)        : plumbing;;
687                 parse-remote)     : plumbing;;
688                 patch-id)         : plumbing;;
689                 peek-remote)      : plumbing;;
690                 prune)            : plumbing;;
691                 prune-packed)     : plumbing;;
692                 quiltimport)      : import;;
693                 read-tree)        : plumbing;;
694                 receive-pack)     : plumbing;;
695                 remote-*)         : transport;;
696                 rerere)           : plumbing;;
697                 rev-list)         : plumbing;;
698                 rev-parse)        : plumbing;;
699                 runstatus)        : plumbing;;
700                 sh-setup)         : internal;;
701                 shell)            : daemon;;
702                 show-ref)         : plumbing;;
703                 send-pack)        : plumbing;;
704                 show-index)       : plumbing;;
705                 ssh-*)            : transport;;
706                 stripspace)       : plumbing;;
707                 symbolic-ref)     : plumbing;;
708                 unpack-file)      : plumbing;;
709                 unpack-objects)   : plumbing;;
710                 update-index)     : plumbing;;
711                 update-ref)       : plumbing;;
712                 update-server-info) : daemon;;
713                 upload-archive)   : plumbing;;
714                 upload-pack)      : plumbing;;
715                 write-tree)       : plumbing;;
716                 var)              : infrequent;;
717                 verify-pack)      : infrequent;;
718                 verify-tag)       : plumbing;;
719                 *) echo $i;;
720                 esac
721         done
722 }
723
724 __git_porcelain_commands=
725 __git_compute_porcelain_commands ()
726 {
727         __git_compute_all_commands
728         test -n "$__git_porcelain_commands" ||
729         __git_porcelain_commands=$(__git_list_porcelain_commands)
730 }
731
732 __git_pretty_aliases ()
733 {
734         local i IFS=$'\n'
735         for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
736                 case "$i" in
737                 pretty.*)
738                         i="${i#pretty.}"
739                         echo "${i/ */}"
740                         ;;
741                 esac
742         done
743 }
744
745 __git_aliases ()
746 {
747         local i IFS=$'\n'
748         for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
749                 case "$i" in
750                 alias.*)
751                         i="${i#alias.}"
752                         echo "${i/ */}"
753                         ;;
754                 esac
755         done
756 }
757
758 # __git_aliased_command requires 1 argument
759 __git_aliased_command ()
760 {
761         local word cmdline=$(git --git-dir="$(__gitdir)" \
762                 config --get "alias.$1")
763         for word in $cmdline; do
764                 case "$word" in
765                 \!gitk|gitk)
766                         echo "gitk"
767                         return
768                         ;;
769                 \!*)    : shell command alias ;;
770                 -*)     : option ;;
771                 *=*)    : setting env ;;
772                 git)    : git itself ;;
773                 *)
774                         echo "$word"
775                         return
776                 esac
777         done
778 }
779
780 # __git_find_on_cmdline requires 1 argument
781 __git_find_on_cmdline ()
782 {
783         local word subcommand c=1
784         while [ $c -lt $cword ]; do
785                 word="${words[c]}"
786                 for subcommand in $1; do
787                         if [ "$subcommand" = "$word" ]; then
788                                 echo "$subcommand"
789                                 return
790                         fi
791                 done
792                 ((c++))
793         done
794 }
795
796 __git_has_doubledash ()
797 {
798         local c=1
799         while [ $c -lt $cword ]; do
800                 if [ "--" = "${words[c]}" ]; then
801                         return 0
802                 fi
803                 ((c++))
804         done
805         return 1
806 }
807
808 # Try to count non option arguments passed on the command line for the
809 # specified git command.
810 # When options are used, it is necessary to use the special -- option to
811 # tell the implementation were non option arguments begin.
812 # XXX this can not be improved, since options can appear everywhere, as
813 # an example:
814 #       git mv x -n y
815 #
816 # __git_count_arguments requires 1 argument: the git command executed.
817 __git_count_arguments ()
818 {
819         local word i c=0
820
821         # Skip "git" (first argument)
822         for ((i=1; i < ${#words[@]}; i++)); do
823                 word="${words[i]}"
824
825                 case "$word" in
826                         --)
827                                 # Good; we can assume that the following are only non
828                                 # option arguments.
829                                 ((c = 0))
830                                 ;;
831                         "$1")
832                                 # Skip the specified git command and discard git
833                                 # main options
834                                 ((c = 0))
835                                 ;;
836                         ?*)
837                                 ((c++))
838                                 ;;
839                 esac
840         done
841
842         printf "%d" $c
843 }
844
845 __git_whitespacelist="nowarn warn error error-all fix"
846
847 _git_am ()
848 {
849         local dir="$(__gitdir)"
850         if [ -d "$dir"/rebase-apply ]; then
851                 __gitcomp "--skip --continue --resolved --abort"
852                 return
853         fi
854         case "$cur" in
855         --whitespace=*)
856                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
857                 return
858                 ;;
859         --*)
860                 __gitcomp "
861                         --3way --committer-date-is-author-date --ignore-date
862                         --ignore-whitespace --ignore-space-change
863                         --interactive --keep --no-utf8 --signoff --utf8
864                         --whitespace= --scissors
865                         "
866                 return
867         esac
868 }
869
870 _git_apply ()
871 {
872         case "$cur" in
873         --whitespace=*)
874                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
875                 return
876                 ;;
877         --*)
878                 __gitcomp "
879                         --stat --numstat --summary --check --index
880                         --cached --index-info --reverse --reject --unidiff-zero
881                         --apply --no-add --exclude=
882                         --ignore-whitespace --ignore-space-change
883                         --whitespace= --inaccurate-eof --verbose
884                         "
885                 return
886         esac
887 }
888
889 _git_add ()
890 {
891         case "$cur" in
892         --*)
893                 __gitcomp "
894                         --interactive --refresh --patch --update --dry-run
895                         --ignore-errors --intent-to-add
896                         "
897                 return
898         esac
899
900         # XXX should we check for --update and --all options ?
901         __git_complete_index_file "--others --modified --directory --no-empty-directory"
902 }
903
904 _git_archive ()
905 {
906         case "$cur" in
907         --format=*)
908                 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
909                 return
910                 ;;
911         --remote=*)
912                 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
913                 return
914                 ;;
915         --*)
916                 __gitcomp "
917                         --format= --list --verbose
918                         --prefix= --remote= --exec=
919                         "
920                 return
921                 ;;
922         esac
923         __git_complete_file
924 }
925
926 _git_bisect ()
927 {
928         __git_has_doubledash && return
929
930         local subcommands="start bad good skip reset visualize replay log run"
931         local subcommand="$(__git_find_on_cmdline "$subcommands")"
932         if [ -z "$subcommand" ]; then
933                 if [ -f "$(__gitdir)"/BISECT_START ]; then
934                         __gitcomp "$subcommands"
935                 else
936                         __gitcomp "replay start"
937                 fi
938                 return
939         fi
940
941         case "$subcommand" in
942         bad|good|reset|skip|start)
943                 __gitcomp_nl "$(__git_refs)"
944                 ;;
945         *)
946                 ;;
947         esac
948 }
949
950 _git_branch ()
951 {
952         local i c=1 only_local_ref="n" has_r="n"
953
954         while [ $c -lt $cword ]; do
955                 i="${words[c]}"
956                 case "$i" in
957                 -d|-m)  only_local_ref="y" ;;
958                 -r)     has_r="y" ;;
959                 esac
960                 ((c++))
961         done
962
963         case "$cur" in
964         --set-upstream-to=*)
965                 __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
966                 ;;
967         --*)
968                 __gitcomp "
969                         --color --no-color --verbose --abbrev= --no-abbrev
970                         --track --no-track --contains --merged --no-merged
971                         --set-upstream-to= --edit-description --list
972                         --unset-upstream
973                         "
974                 ;;
975         *)
976                 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
977                         __gitcomp_nl "$(__git_heads)"
978                 else
979                         __gitcomp_nl "$(__git_refs)"
980                 fi
981                 ;;
982         esac
983 }
984
985 _git_bundle ()
986 {
987         local cmd="${words[2]}"
988         case "$cword" in
989         2)
990                 __gitcomp "create list-heads verify unbundle"
991                 ;;
992         3)
993                 # looking for a file
994                 ;;
995         *)
996                 case "$cmd" in
997                         create)
998                                 __git_complete_revlist
999                         ;;
1000                 esac
1001                 ;;
1002         esac
1003 }
1004
1005 _git_checkout ()
1006 {
1007         __git_has_doubledash && return
1008
1009         case "$cur" in
1010         --conflict=*)
1011                 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1012                 ;;
1013         --*)
1014                 __gitcomp "
1015                         --quiet --ours --theirs --track --no-track --merge
1016                         --conflict= --orphan --patch
1017                         "
1018                 ;;
1019         *)
1020                 # check if --track, --no-track, or --no-guess was specified
1021                 # if so, disable DWIM mode
1022                 local flags="--track --no-track --no-guess" track=1
1023                 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1024                         track=''
1025                 fi
1026                 __gitcomp_nl "$(__git_refs '' $track)"
1027                 ;;
1028         esac
1029 }
1030
1031 _git_cherry ()
1032 {
1033         __gitcomp "$(__git_refs)"
1034 }
1035
1036 _git_cherry_pick ()
1037 {
1038         local dir="$(__gitdir)"
1039         if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1040                 __gitcomp "--continue --quit --abort"
1041                 return
1042         fi
1043         case "$cur" in
1044         --*)
1045                 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1046                 ;;
1047         *)
1048                 __gitcomp_nl "$(__git_refs)"
1049                 ;;
1050         esac
1051 }
1052
1053 _git_clean ()
1054 {
1055         case "$cur" in
1056         --*)
1057                 __gitcomp "--dry-run --quiet"
1058                 return
1059                 ;;
1060         esac
1061
1062         # XXX should we check for -x option ?
1063         __git_complete_index_file "--others --directory"
1064 }
1065
1066 _git_clone ()
1067 {
1068         case "$cur" in
1069         --*)
1070                 __gitcomp "
1071                         --local
1072                         --no-hardlinks
1073                         --shared
1074                         --reference
1075                         --quiet
1076                         --no-checkout
1077                         --bare
1078                         --mirror
1079                         --origin
1080                         --upload-pack
1081                         --template=
1082                         --depth
1083                         --single-branch
1084                         --branch
1085                         "
1086                 return
1087                 ;;
1088         esac
1089 }
1090
1091 _git_commit ()
1092 {
1093         case "$prev" in
1094         -c|-C)
1095                 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1096                 return
1097                 ;;
1098         esac
1099
1100         case "$cur" in
1101         --cleanup=*)
1102                 __gitcomp "default strip verbatim whitespace
1103                         " "" "${cur##--cleanup=}"
1104                 return
1105                 ;;
1106         --reuse-message=*|--reedit-message=*|\
1107         --fixup=*|--squash=*)
1108                 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1109                 return
1110                 ;;
1111         --untracked-files=*)
1112                 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1113                 return
1114                 ;;
1115         --*)
1116                 __gitcomp "
1117                         --all --author= --signoff --verify --no-verify
1118                         --edit --no-edit
1119                         --amend --include --only --interactive
1120                         --dry-run --reuse-message= --reedit-message=
1121                         --reset-author --file= --message= --template=
1122                         --cleanup= --untracked-files --untracked-files=
1123                         --verbose --quiet --fixup= --squash=
1124                         "
1125                 return
1126         esac
1127
1128         if git rev-parse --verify --quiet HEAD >/dev/null; then
1129                 __git_complete_index_file "--committable"
1130         else
1131                 # This is the first commit
1132                 __git_complete_index_file "--cached"
1133         fi
1134 }
1135
1136 _git_describe ()
1137 {
1138         case "$cur" in
1139         --*)
1140                 __gitcomp "
1141                         --all --tags --contains --abbrev= --candidates=
1142                         --exact-match --debug --long --match --always
1143                         "
1144                 return
1145         esac
1146         __gitcomp_nl "$(__git_refs)"
1147 }
1148
1149 __git_diff_algorithms="myers minimal patience histogram"
1150
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 --histogram --minimal
1162                         --raw --word-diff
1163                         --dirstat --dirstat= --dirstat-by-file
1164                         --dirstat-by-file= --cumulative
1165                         --diff-algorithm=
1166 "
1167
1168 _git_diff ()
1169 {
1170         __git_has_doubledash && return
1171
1172         case "$cur" in
1173         --diff-algorithm=*)
1174                 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1175                 return
1176                 ;;
1177         --*)
1178                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1179                         --base --ours --theirs --no-index
1180                         $__git_diff_common_options
1181                         "
1182                 return
1183                 ;;
1184         esac
1185         __git_complete_revlist_file
1186 }
1187
1188 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1189                         tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1190 "
1191
1192 _git_difftool ()
1193 {
1194         __git_has_doubledash && return
1195
1196         case "$cur" in
1197         --tool=*)
1198                 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1199                 return
1200                 ;;
1201         --*)
1202                 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1203                         --base --ours --theirs
1204                         --no-renames --diff-filter= --find-copies-harder
1205                         --relative --ignore-submodules
1206                         --tool="
1207                 return
1208                 ;;
1209         esac
1210         __git_complete_revlist_file
1211 }
1212
1213 __git_fetch_options="
1214         --quiet --verbose --append --upload-pack --force --keep --depth=
1215         --tags --no-tags --all --prune --dry-run
1216 "
1217
1218 _git_fetch ()
1219 {
1220         case "$cur" in
1221         --*)
1222                 __gitcomp "$__git_fetch_options"
1223                 return
1224                 ;;
1225         esac
1226         __git_complete_remote_or_refspec
1227 }
1228
1229 __git_format_patch_options="
1230         --stdout --attach --no-attach --thread --thread= --no-thread
1231         --numbered --start-number --numbered-files --keep-subject --signoff
1232         --signature --no-signature --in-reply-to= --cc= --full-index --binary
1233         --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1234         --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1235         --output-directory --reroll-count --to= --quiet --notes
1236 "
1237
1238 _git_format_patch ()
1239 {
1240         case "$cur" in
1241         --thread=*)
1242                 __gitcomp "
1243                         deep shallow
1244                         " "" "${cur##--thread=}"
1245                 return
1246                 ;;
1247         --*)
1248                 __gitcomp "$__git_format_patch_options"
1249                 return
1250                 ;;
1251         esac
1252         __git_complete_revlist
1253 }
1254
1255 _git_fsck ()
1256 {
1257         case "$cur" in
1258         --*)
1259                 __gitcomp "
1260                         --tags --root --unreachable --cache --no-reflogs --full
1261                         --strict --verbose --lost-found
1262                         "
1263                 return
1264                 ;;
1265         esac
1266 }
1267
1268 _git_gc ()
1269 {
1270         case "$cur" in
1271         --*)
1272                 __gitcomp "--prune --aggressive"
1273                 return
1274                 ;;
1275         esac
1276 }
1277
1278 _git_gitk ()
1279 {
1280         _gitk
1281 }
1282
1283 __git_match_ctag() {
1284         awk "/^${1////\\/}/ { print \$1 }" "$2"
1285 }
1286
1287 _git_grep ()
1288 {
1289         __git_has_doubledash && return
1290
1291         case "$cur" in
1292         --*)
1293                 __gitcomp "
1294                         --cached
1295                         --text --ignore-case --word-regexp --invert-match
1296                         --full-name --line-number
1297                         --extended-regexp --basic-regexp --fixed-strings
1298                         --perl-regexp
1299                         --files-with-matches --name-only
1300                         --files-without-match
1301                         --max-depth
1302                         --count
1303                         --and --or --not --all-match
1304                         "
1305                 return
1306                 ;;
1307         esac
1308
1309         case "$cword,$prev" in
1310         2,*|*,-*)
1311                 if test -r tags; then
1312                         __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1313                         return
1314                 fi
1315                 ;;
1316         esac
1317
1318         __gitcomp_nl "$(__git_refs)"
1319 }
1320
1321 _git_help ()
1322 {
1323         case "$cur" in
1324         --*)
1325                 __gitcomp "--all --info --man --web"
1326                 return
1327                 ;;
1328         esac
1329         __git_compute_all_commands
1330         __gitcomp "$__git_all_commands $(__git_aliases)
1331                 attributes cli core-tutorial cvs-migration
1332                 diffcore gitk glossary hooks ignore modules
1333                 namespaces repository-layout tutorial tutorial-2
1334                 workflows
1335                 "
1336 }
1337
1338 _git_init ()
1339 {
1340         case "$cur" in
1341         --shared=*)
1342                 __gitcomp "
1343                         false true umask group all world everybody
1344                         " "" "${cur##--shared=}"
1345                 return
1346                 ;;
1347         --*)
1348                 __gitcomp "--quiet --bare --template= --shared --shared="
1349                 return
1350                 ;;
1351         esac
1352 }
1353
1354 _git_ls_files ()
1355 {
1356         case "$cur" in
1357         --*)
1358                 __gitcomp "--cached --deleted --modified --others --ignored
1359                         --stage --directory --no-empty-directory --unmerged
1360                         --killed --exclude= --exclude-from=
1361                         --exclude-per-directory= --exclude-standard
1362                         --error-unmatch --with-tree= --full-name
1363                         --abbrev --ignored --exclude-per-directory
1364                         "
1365                 return
1366                 ;;
1367         esac
1368
1369         # XXX ignore options like --modified and always suggest all cached
1370         # files.
1371         __git_complete_index_file "--cached"
1372 }
1373
1374 _git_ls_remote ()
1375 {
1376         __gitcomp_nl "$(__git_remotes)"
1377 }
1378
1379 _git_ls_tree ()
1380 {
1381         __git_complete_file
1382 }
1383
1384 # Options that go well for log, shortlog and gitk
1385 __git_log_common_options="
1386         --not --all
1387         --branches --tags --remotes
1388         --first-parent --merges --no-merges
1389         --max-count=
1390         --max-age= --since= --after=
1391         --min-age= --until= --before=
1392         --min-parents= --max-parents=
1393         --no-min-parents --no-max-parents
1394 "
1395 # Options that go well for log and gitk (not shortlog)
1396 __git_log_gitk_options="
1397         --dense --sparse --full-history
1398         --simplify-merges --simplify-by-decoration
1399         --left-right --notes --no-notes
1400 "
1401 # Options that go well for log and shortlog (not gitk)
1402 __git_log_shortlog_options="
1403         --author= --committer= --grep=
1404         --all-match
1405 "
1406
1407 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1408 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1409
1410 _git_log ()
1411 {
1412         __git_has_doubledash && return
1413
1414         local g="$(git rev-parse --git-dir 2>/dev/null)"
1415         local merge=""
1416         if [ -f "$g/MERGE_HEAD" ]; then
1417                 merge="--merge"
1418         fi
1419         case "$cur" in
1420         --pretty=*|--format=*)
1421                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1422                         " "" "${cur#*=}"
1423                 return
1424                 ;;
1425         --date=*)
1426                 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1427                 return
1428                 ;;
1429         --decorate=*)
1430                 __gitcomp "long short" "" "${cur##--decorate=}"
1431                 return
1432                 ;;
1433         --*)
1434                 __gitcomp "
1435                         $__git_log_common_options
1436                         $__git_log_shortlog_options
1437                         $__git_log_gitk_options
1438                         --root --topo-order --date-order --reverse
1439                         --follow --full-diff
1440                         --abbrev-commit --abbrev=
1441                         --relative-date --date=
1442                         --pretty= --format= --oneline
1443                         --cherry-pick
1444                         --graph
1445                         --decorate --decorate=
1446                         --walk-reflogs
1447                         --parents --children
1448                         $merge
1449                         $__git_diff_common_options
1450                         --pickaxe-all --pickaxe-regex
1451                         "
1452                 return
1453                 ;;
1454         esac
1455         __git_complete_revlist
1456 }
1457
1458 __git_merge_options="
1459         --no-commit --no-stat --log --no-log --squash --strategy
1460         --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1461 "
1462
1463 _git_merge ()
1464 {
1465         __git_complete_strategy && return
1466
1467         case "$cur" in
1468         --*)
1469                 __gitcomp "$__git_merge_options"
1470                 return
1471         esac
1472         __gitcomp_nl "$(__git_refs)"
1473 }
1474
1475 _git_mergetool ()
1476 {
1477         case "$cur" in
1478         --tool=*)
1479                 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1480                 return
1481                 ;;
1482         --*)
1483                 __gitcomp "--tool="
1484                 return
1485                 ;;
1486         esac
1487 }
1488
1489 _git_merge_base ()
1490 {
1491         __gitcomp_nl "$(__git_refs)"
1492 }
1493
1494 _git_mv ()
1495 {
1496         case "$cur" in
1497         --*)
1498                 __gitcomp "--dry-run"
1499                 return
1500                 ;;
1501         esac
1502
1503         if [ $(__git_count_arguments "mv") -gt 0 ]; then
1504                 # We need to show both cached and untracked files (including
1505                 # empty directories) since this may not be the last argument.
1506                 __git_complete_index_file "--cached --others --directory"
1507         else
1508                 __git_complete_index_file "--cached"
1509         fi
1510 }
1511
1512 _git_name_rev ()
1513 {
1514         __gitcomp "--tags --all --stdin"
1515 }
1516
1517 _git_notes ()
1518 {
1519         local subcommands='add append copy edit list prune remove show'
1520         local subcommand="$(__git_find_on_cmdline "$subcommands")"
1521
1522         case "$subcommand,$cur" in
1523         ,--*)
1524                 __gitcomp '--ref'
1525                 ;;
1526         ,*)
1527                 case "$prev" in
1528                 --ref)
1529                         __gitcomp_nl "$(__git_refs)"
1530                         ;;
1531                 *)
1532                         __gitcomp "$subcommands --ref"
1533                         ;;
1534                 esac
1535                 ;;
1536         add,--reuse-message=*|append,--reuse-message=*|\
1537         add,--reedit-message=*|append,--reedit-message=*)
1538                 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1539                 ;;
1540         add,--*|append,--*)
1541                 __gitcomp '--file= --message= --reedit-message=
1542                                 --reuse-message='
1543                 ;;
1544         copy,--*)
1545                 __gitcomp '--stdin'
1546                 ;;
1547         prune,--*)
1548                 __gitcomp '--dry-run --verbose'
1549                 ;;
1550         prune,*)
1551                 ;;
1552         *)
1553                 case "$prev" in
1554                 -m|-F)
1555                         ;;
1556                 *)
1557                         __gitcomp_nl "$(__git_refs)"
1558                         ;;
1559                 esac
1560                 ;;
1561         esac
1562 }
1563
1564 _git_pull ()
1565 {
1566         __git_complete_strategy && return
1567
1568         case "$cur" in
1569         --*)
1570                 __gitcomp "
1571                         --rebase --no-rebase
1572                         $__git_merge_options
1573                         $__git_fetch_options
1574                 "
1575                 return
1576                 ;;
1577         esac
1578         __git_complete_remote_or_refspec
1579 }
1580
1581 _git_push ()
1582 {
1583         case "$prev" in
1584         --repo)
1585                 __gitcomp_nl "$(__git_remotes)"
1586                 return
1587         esac
1588         case "$cur" in
1589         --repo=*)
1590                 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1591                 return
1592                 ;;
1593         --*)
1594                 __gitcomp "
1595                         --all --mirror --tags --dry-run --force --verbose
1596                         --receive-pack= --repo= --set-upstream
1597                 "
1598                 return
1599                 ;;
1600         esac
1601         __git_complete_remote_or_refspec
1602 }
1603
1604 _git_rebase ()
1605 {
1606         local dir="$(__gitdir)"
1607         if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1608                 __gitcomp "--continue --skip --abort"
1609                 return
1610         fi
1611         __git_complete_strategy && return
1612         case "$cur" in
1613         --whitespace=*)
1614                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1615                 return
1616                 ;;
1617         --*)
1618                 __gitcomp "
1619                         --onto --merge --strategy --interactive
1620                         --preserve-merges --stat --no-stat
1621                         --committer-date-is-author-date --ignore-date
1622                         --ignore-whitespace --whitespace=
1623                         --autosquash
1624                         "
1625
1626                 return
1627         esac
1628         __gitcomp_nl "$(__git_refs)"
1629 }
1630
1631 _git_reflog ()
1632 {
1633         local subcommands="show delete expire"
1634         local subcommand="$(__git_find_on_cmdline "$subcommands")"
1635
1636         if [ -z "$subcommand" ]; then
1637                 __gitcomp "$subcommands"
1638         else
1639                 __gitcomp_nl "$(__git_refs)"
1640         fi
1641 }
1642
1643 __git_send_email_confirm_options="always never auto cc compose"
1644 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1645
1646 _git_send_email ()
1647 {
1648         case "$cur" in
1649         --confirm=*)
1650                 __gitcomp "
1651                         $__git_send_email_confirm_options
1652                         " "" "${cur##--confirm=}"
1653                 return
1654                 ;;
1655         --suppress-cc=*)
1656                 __gitcomp "
1657                         $__git_send_email_suppresscc_options
1658                         " "" "${cur##--suppress-cc=}"
1659
1660                 return
1661                 ;;
1662         --smtp-encryption=*)
1663                 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1664                 return
1665                 ;;
1666         --thread=*)
1667                 __gitcomp "
1668                         deep shallow
1669                         " "" "${cur##--thread=}"
1670                 return
1671                 ;;
1672         --*)
1673                 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1674                         --compose --confirm= --dry-run --envelope-sender
1675                         --from --identity
1676                         --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1677                         --no-suppress-from --no-thread --quiet
1678                         --signed-off-by-cc --smtp-pass --smtp-server
1679                         --smtp-server-port --smtp-encryption= --smtp-user
1680                         --subject --suppress-cc= --suppress-from --thread --to
1681                         --validate --no-validate
1682                         $__git_format_patch_options"
1683                 return
1684                 ;;
1685         esac
1686         __git_complete_revlist
1687 }
1688
1689 _git_stage ()
1690 {
1691         _git_add
1692 }
1693
1694 __git_config_get_set_variables ()
1695 {
1696         local prevword word config_file= c=$cword
1697         while [ $c -gt 1 ]; do
1698                 word="${words[c]}"
1699                 case "$word" in
1700                 --system|--global|--local|--file=*)
1701                         config_file="$word"
1702                         break
1703                         ;;
1704                 -f|--file)
1705                         config_file="$word $prevword"
1706                         break
1707                         ;;
1708                 esac
1709                 prevword=$word
1710                 c=$((--c))
1711         done
1712
1713         git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1714         while read -r line
1715         do
1716                 case "$line" in
1717                 *.*=*)
1718                         echo "${line/=*/}"
1719                         ;;
1720                 esac
1721         done
1722 }
1723
1724 _git_config ()
1725 {
1726         case "$prev" in
1727         branch.*.remote|branch.*.pushremote)
1728                 __gitcomp_nl "$(__git_remotes)"
1729                 return
1730                 ;;
1731         branch.*.merge)
1732                 __gitcomp_nl "$(__git_refs)"
1733                 return
1734                 ;;
1735         branch.*.rebase)
1736                 __gitcomp "false true"
1737                 return
1738                 ;;
1739         remote.pushdefault)
1740                 __gitcomp_nl "$(__git_remotes)"
1741                 return
1742                 ;;
1743         remote.*.fetch)
1744                 local remote="${prev#remote.}"
1745                 remote="${remote%.fetch}"
1746                 if [ -z "$cur" ]; then
1747                         __gitcomp_nl "refs/heads/" "" "" ""
1748                         return
1749                 fi
1750                 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1751                 return
1752                 ;;
1753         remote.*.push)
1754                 local remote="${prev#remote.}"
1755                 remote="${remote%.push}"
1756                 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1757                         for-each-ref --format='%(refname):%(refname)' \
1758                         refs/heads)"
1759                 return
1760                 ;;
1761         pull.twohead|pull.octopus)
1762                 __git_compute_merge_strategies
1763                 __gitcomp "$__git_merge_strategies"
1764                 return
1765                 ;;
1766         color.branch|color.diff|color.interactive|\
1767         color.showbranch|color.status|color.ui)
1768                 __gitcomp "always never auto"
1769                 return
1770                 ;;
1771         color.pager)
1772                 __gitcomp "false true"
1773                 return
1774                 ;;
1775         color.*.*)
1776                 __gitcomp "
1777                         normal black red green yellow blue magenta cyan white
1778                         bold dim ul blink reverse
1779                         "
1780                 return
1781                 ;;
1782         diff.submodule)
1783                 __gitcomp "log short"
1784                 return
1785                 ;;
1786         help.format)
1787                 __gitcomp "man info web html"
1788                 return
1789                 ;;
1790         log.date)
1791                 __gitcomp "$__git_log_date_formats"
1792                 return
1793                 ;;
1794         sendemail.aliasesfiletype)
1795                 __gitcomp "mutt mailrc pine elm gnus"
1796                 return
1797                 ;;
1798         sendemail.confirm)
1799                 __gitcomp "$__git_send_email_confirm_options"
1800                 return
1801                 ;;
1802         sendemail.suppresscc)
1803                 __gitcomp "$__git_send_email_suppresscc_options"
1804                 return
1805                 ;;
1806         --get|--get-all|--unset|--unset-all)
1807                 __gitcomp_nl "$(__git_config_get_set_variables)"
1808                 return
1809                 ;;
1810         *.*)
1811                 return
1812                 ;;
1813         esac
1814         case "$cur" in
1815         --*)
1816                 __gitcomp "
1817                         --system --global --local --file=
1818                         --list --replace-all
1819                         --get --get-all --get-regexp
1820                         --add --unset --unset-all
1821                         --remove-section --rename-section
1822                         "
1823                 return
1824                 ;;
1825         branch.*.*)
1826                 local pfx="${cur%.*}." cur_="${cur##*.}"
1827                 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
1828                 return
1829                 ;;
1830         branch.*)
1831                 local pfx="${cur%.*}." cur_="${cur#*.}"
1832                 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1833                 return
1834                 ;;
1835         guitool.*.*)
1836                 local pfx="${cur%.*}." cur_="${cur##*.}"
1837                 __gitcomp "
1838                         argprompt cmd confirm needsfile noconsole norescan
1839                         prompt revprompt revunmerged title
1840                         " "$pfx" "$cur_"
1841                 return
1842                 ;;
1843         difftool.*.*)
1844                 local pfx="${cur%.*}." cur_="${cur##*.}"
1845                 __gitcomp "cmd path" "$pfx" "$cur_"
1846                 return
1847                 ;;
1848         man.*.*)
1849                 local pfx="${cur%.*}." cur_="${cur##*.}"
1850                 __gitcomp "cmd path" "$pfx" "$cur_"
1851                 return
1852                 ;;
1853         mergetool.*.*)
1854                 local pfx="${cur%.*}." cur_="${cur##*.}"
1855                 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1856                 return
1857                 ;;
1858         pager.*)
1859                 local pfx="${cur%.*}." cur_="${cur#*.}"
1860                 __git_compute_all_commands
1861                 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1862                 return
1863                 ;;
1864         remote.*.*)
1865                 local pfx="${cur%.*}." cur_="${cur##*.}"
1866                 __gitcomp "
1867                         url proxy fetch push mirror skipDefaultUpdate
1868                         receivepack uploadpack tagopt pushurl
1869                         " "$pfx" "$cur_"
1870                 return
1871                 ;;
1872         remote.*)
1873                 local pfx="${cur%.*}." cur_="${cur#*.}"
1874                 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1875                 return
1876                 ;;
1877         url.*.*)
1878                 local pfx="${cur%.*}." cur_="${cur##*.}"
1879                 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1880                 return
1881                 ;;
1882         esac
1883         __gitcomp "
1884                 add.ignoreErrors
1885                 advice.commitBeforeMerge
1886                 advice.detachedHead
1887                 advice.implicitIdentity
1888                 advice.pushNonFastForward
1889                 advice.resolveConflict
1890                 advice.statusHints
1891                 alias.
1892                 am.keepcr
1893                 apply.ignorewhitespace
1894                 apply.whitespace
1895                 branch.autosetupmerge
1896                 branch.autosetuprebase
1897                 browser.
1898                 clean.requireForce
1899                 color.branch
1900                 color.branch.current
1901                 color.branch.local
1902                 color.branch.plain
1903                 color.branch.remote
1904                 color.decorate.HEAD
1905                 color.decorate.branch
1906                 color.decorate.remoteBranch
1907                 color.decorate.stash
1908                 color.decorate.tag
1909                 color.diff
1910                 color.diff.commit
1911                 color.diff.frag
1912                 color.diff.func
1913                 color.diff.meta
1914                 color.diff.new
1915                 color.diff.old
1916                 color.diff.plain
1917                 color.diff.whitespace
1918                 color.grep
1919                 color.grep.context
1920                 color.grep.filename
1921                 color.grep.function
1922                 color.grep.linenumber
1923                 color.grep.match
1924                 color.grep.selected
1925                 color.grep.separator
1926                 color.interactive
1927                 color.interactive.error
1928                 color.interactive.header
1929                 color.interactive.help
1930                 color.interactive.prompt
1931                 color.pager
1932                 color.showbranch
1933                 color.status
1934                 color.status.added
1935                 color.status.changed
1936                 color.status.header
1937                 color.status.nobranch
1938                 color.status.untracked
1939                 color.status.updated
1940                 color.ui
1941                 commit.status
1942                 commit.template
1943                 core.abbrev
1944                 core.askpass
1945                 core.attributesfile
1946                 core.autocrlf
1947                 core.bare
1948                 core.bigFileThreshold
1949                 core.compression
1950                 core.createObject
1951                 core.deltaBaseCacheLimit
1952                 core.editor
1953                 core.eol
1954                 core.excludesfile
1955                 core.fileMode
1956                 core.fsyncobjectfiles
1957                 core.gitProxy
1958                 core.ignoreStat
1959                 core.ignorecase
1960                 core.logAllRefUpdates
1961                 core.loosecompression
1962                 core.notesRef
1963                 core.packedGitLimit
1964                 core.packedGitWindowSize
1965                 core.pager
1966                 core.preferSymlinkRefs
1967                 core.preloadindex
1968                 core.quotepath
1969                 core.repositoryFormatVersion
1970                 core.safecrlf
1971                 core.sharedRepository
1972                 core.sparseCheckout
1973                 core.symlinks
1974                 core.trustctime
1975                 core.warnAmbiguousRefs
1976                 core.whitespace
1977                 core.worktree
1978                 diff.autorefreshindex
1979                 diff.external
1980                 diff.ignoreSubmodules
1981                 diff.mnemonicprefix
1982                 diff.noprefix
1983                 diff.renameLimit
1984                 diff.renames
1985                 diff.statGraphWidth
1986                 diff.submodule
1987                 diff.suppressBlankEmpty
1988                 diff.tool
1989                 diff.wordRegex
1990                 diff.algorithm
1991                 difftool.
1992                 difftool.prompt
1993                 fetch.recurseSubmodules
1994                 fetch.unpackLimit
1995                 format.attach
1996                 format.cc
1997                 format.headers
1998                 format.numbered
1999                 format.pretty
2000                 format.signature
2001                 format.signoff
2002                 format.subjectprefix
2003                 format.suffix
2004                 format.thread
2005                 format.to
2006                 gc.
2007                 gc.aggressiveWindow
2008                 gc.auto
2009                 gc.autopacklimit
2010                 gc.packrefs
2011                 gc.pruneexpire
2012                 gc.reflogexpire
2013                 gc.reflogexpireunreachable
2014                 gc.rerereresolved
2015                 gc.rerereunresolved
2016                 gitcvs.allbinary
2017                 gitcvs.commitmsgannotation
2018                 gitcvs.dbTableNamePrefix
2019                 gitcvs.dbdriver
2020                 gitcvs.dbname
2021                 gitcvs.dbpass
2022                 gitcvs.dbuser
2023                 gitcvs.enabled
2024                 gitcvs.logfile
2025                 gitcvs.usecrlfattr
2026                 guitool.
2027                 gui.blamehistoryctx
2028                 gui.commitmsgwidth
2029                 gui.copyblamethreshold
2030                 gui.diffcontext
2031                 gui.encoding
2032                 gui.fastcopyblame
2033                 gui.matchtrackingbranch
2034                 gui.newbranchtemplate
2035                 gui.pruneduringfetch
2036                 gui.spellingdictionary
2037                 gui.trustmtime
2038                 help.autocorrect
2039                 help.browser
2040                 help.format
2041                 http.lowSpeedLimit
2042                 http.lowSpeedTime
2043                 http.maxRequests
2044                 http.minSessions
2045                 http.noEPSV
2046                 http.postBuffer
2047                 http.proxy
2048                 http.sslCAInfo
2049                 http.sslCAPath
2050                 http.sslCert
2051                 http.sslCertPasswordProtected
2052                 http.sslKey
2053                 http.sslVerify
2054                 http.useragent
2055                 i18n.commitEncoding
2056                 i18n.logOutputEncoding
2057                 imap.authMethod
2058                 imap.folder
2059                 imap.host
2060                 imap.pass
2061                 imap.port
2062                 imap.preformattedHTML
2063                 imap.sslverify
2064                 imap.tunnel
2065                 imap.user
2066                 init.templatedir
2067                 instaweb.browser
2068                 instaweb.httpd
2069                 instaweb.local
2070                 instaweb.modulepath
2071                 instaweb.port
2072                 interactive.singlekey
2073                 log.date
2074                 log.decorate
2075                 log.showroot
2076                 mailmap.file
2077                 man.
2078                 man.viewer
2079                 merge.
2080                 merge.conflictstyle
2081                 merge.log
2082                 merge.renameLimit
2083                 merge.renormalize
2084                 merge.stat
2085                 merge.tool
2086                 merge.verbosity
2087                 mergetool.
2088                 mergetool.keepBackup
2089                 mergetool.keepTemporaries
2090                 mergetool.prompt
2091                 notes.displayRef
2092                 notes.rewrite.
2093                 notes.rewrite.amend
2094                 notes.rewrite.rebase
2095                 notes.rewriteMode
2096                 notes.rewriteRef
2097                 pack.compression
2098                 pack.deltaCacheLimit
2099                 pack.deltaCacheSize
2100                 pack.depth
2101                 pack.indexVersion
2102                 pack.packSizeLimit
2103                 pack.threads
2104                 pack.window
2105                 pack.windowMemory
2106                 pager.
2107                 pretty.
2108                 pull.octopus
2109                 pull.twohead
2110                 push.default
2111                 rebase.autosquash
2112                 rebase.stat
2113                 receive.autogc
2114                 receive.denyCurrentBranch
2115                 receive.denyDeleteCurrent
2116                 receive.denyDeletes
2117                 receive.denyNonFastForwards
2118                 receive.fsckObjects
2119                 receive.unpackLimit
2120                 receive.updateserverinfo
2121                 remote.pushdefault
2122                 remotes.
2123                 repack.usedeltabaseoffset
2124                 rerere.autoupdate
2125                 rerere.enabled
2126                 sendemail.
2127                 sendemail.aliasesfile
2128                 sendemail.aliasfiletype
2129                 sendemail.bcc
2130                 sendemail.cc
2131                 sendemail.cccmd
2132                 sendemail.chainreplyto
2133                 sendemail.confirm
2134                 sendemail.envelopesender
2135                 sendemail.from
2136                 sendemail.identity
2137                 sendemail.multiedit
2138                 sendemail.signedoffbycc
2139                 sendemail.smtpdomain
2140                 sendemail.smtpencryption
2141                 sendemail.smtppass
2142                 sendemail.smtpserver
2143                 sendemail.smtpserveroption
2144                 sendemail.smtpserverport
2145                 sendemail.smtpuser
2146                 sendemail.suppresscc
2147                 sendemail.suppressfrom
2148                 sendemail.thread
2149                 sendemail.to
2150                 sendemail.validate
2151                 showbranch.default
2152                 status.relativePaths
2153                 status.showUntrackedFiles
2154                 status.submodulesummary
2155                 submodule.
2156                 tar.umask
2157                 transfer.unpackLimit
2158                 url.
2159                 user.email
2160                 user.name
2161                 user.signingkey
2162                 web.browser
2163                 branch. remote.
2164         "
2165 }
2166
2167 _git_remote ()
2168 {
2169         local subcommands="add rename remove set-head set-branches set-url show prune update"
2170         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2171         if [ -z "$subcommand" ]; then
2172                 __gitcomp "$subcommands"
2173                 return
2174         fi
2175
2176         case "$subcommand" in
2177         rename|remove|set-url|show|prune)
2178                 __gitcomp_nl "$(__git_remotes)"
2179                 ;;
2180         set-head|set-branches)
2181                 __git_complete_remote_or_refspec
2182                 ;;
2183         update)
2184                 local i c='' IFS=$'\n'
2185                 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2186                         i="${i#remotes.}"
2187                         c="$c ${i/ */}"
2188                 done
2189                 __gitcomp "$c"
2190                 ;;
2191         *)
2192                 ;;
2193         esac
2194 }
2195
2196 _git_replace ()
2197 {
2198         __gitcomp_nl "$(__git_refs)"
2199 }
2200
2201 _git_reset ()
2202 {
2203         __git_has_doubledash && return
2204
2205         case "$cur" in
2206         --*)
2207                 __gitcomp "--merge --mixed --hard --soft --patch"
2208                 return
2209                 ;;
2210         esac
2211         __gitcomp_nl "$(__git_refs)"
2212 }
2213
2214 _git_revert ()
2215 {
2216         case "$cur" in
2217         --*)
2218                 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2219                 return
2220                 ;;
2221         esac
2222         __gitcomp_nl "$(__git_refs)"
2223 }
2224
2225 _git_rm ()
2226 {
2227         case "$cur" in
2228         --*)
2229                 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2230                 return
2231                 ;;
2232         esac
2233
2234         __git_complete_index_file "--cached"
2235 }
2236
2237 _git_shortlog ()
2238 {
2239         __git_has_doubledash && return
2240
2241         case "$cur" in
2242         --*)
2243                 __gitcomp "
2244                         $__git_log_common_options
2245                         $__git_log_shortlog_options
2246                         --numbered --summary
2247                         "
2248                 return
2249                 ;;
2250         esac
2251         __git_complete_revlist
2252 }
2253
2254 _git_show ()
2255 {
2256         __git_has_doubledash && return
2257
2258         case "$cur" in
2259         --pretty=*|--format=*)
2260                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2261                         " "" "${cur#*=}"
2262                 return
2263                 ;;
2264         --diff-algorithm=*)
2265                 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2266                 return
2267                 ;;
2268         --*)
2269                 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2270                         $__git_diff_common_options
2271                         "
2272                 return
2273                 ;;
2274         esac
2275         __git_complete_revlist_file
2276 }
2277
2278 _git_show_branch ()
2279 {
2280         case "$cur" in
2281         --*)
2282                 __gitcomp "
2283                         --all --remotes --topo-order --current --more=
2284                         --list --independent --merge-base --no-name
2285                         --color --no-color
2286                         --sha1-name --sparse --topics --reflog
2287                         "
2288                 return
2289                 ;;
2290         esac
2291         __git_complete_revlist
2292 }
2293
2294 _git_stash ()
2295 {
2296         local save_opts='--keep-index --no-keep-index --quiet --patch'
2297         local subcommands='save list show apply clear drop pop create branch'
2298         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2299         if [ -z "$subcommand" ]; then
2300                 case "$cur" in
2301                 --*)
2302                         __gitcomp "$save_opts"
2303                         ;;
2304                 *)
2305                         if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2306                                 __gitcomp "$subcommands"
2307                         fi
2308                         ;;
2309                 esac
2310         else
2311                 case "$subcommand,$cur" in
2312                 save,--*)
2313                         __gitcomp "$save_opts"
2314                         ;;
2315                 apply,--*|pop,--*)
2316                         __gitcomp "--index --quiet"
2317                         ;;
2318                 show,--*|drop,--*|branch,--*)
2319                         ;;
2320                 show,*|apply,*|drop,*|pop,*|branch,*)
2321                         __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2322                                         | sed -n -e 's/:.*//p')"
2323                         ;;
2324                 *)
2325                         ;;
2326                 esac
2327         fi
2328 }
2329
2330 _git_submodule ()
2331 {
2332         __git_has_doubledash && return
2333
2334         local subcommands="add status init deinit update summary foreach sync"
2335         if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2336                 case "$cur" in
2337                 --*)
2338                         __gitcomp "--quiet --cached"
2339                         ;;
2340                 *)
2341                         __gitcomp "$subcommands"
2342                         ;;
2343                 esac
2344                 return
2345         fi
2346 }
2347
2348 _git_svn ()
2349 {
2350         local subcommands="
2351                 init fetch clone rebase dcommit log find-rev
2352                 set-tree commit-diff info create-ignore propget
2353                 proplist show-ignore show-externals branch tag blame
2354                 migrate mkdirs reset gc
2355                 "
2356         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2357         if [ -z "$subcommand" ]; then
2358                 __gitcomp "$subcommands"
2359         else
2360                 local remote_opts="--username= --config-dir= --no-auth-cache"
2361                 local fc_opts="
2362                         --follow-parent --authors-file= --repack=
2363                         --no-metadata --use-svm-props --use-svnsync-props
2364                         --log-window-size= --no-checkout --quiet
2365                         --repack-flags --use-log-author --localtime
2366                         --ignore-paths= --include-paths= $remote_opts
2367                         "
2368                 local init_opts="
2369                         --template= --shared= --trunk= --tags=
2370                         --branches= --stdlayout --minimize-url
2371                         --no-metadata --use-svm-props --use-svnsync-props
2372                         --rewrite-root= --prefix= --use-log-author
2373                         --add-author-from $remote_opts
2374                         "
2375                 local cmt_opts="
2376                         --edit --rmdir --find-copies-harder --copy-similarity=
2377                         "
2378
2379                 case "$subcommand,$cur" in
2380                 fetch,--*)
2381                         __gitcomp "--revision= --fetch-all $fc_opts"
2382                         ;;
2383                 clone,--*)
2384                         __gitcomp "--revision= $fc_opts $init_opts"
2385                         ;;
2386                 init,--*)
2387                         __gitcomp "$init_opts"
2388                         ;;
2389                 dcommit,--*)
2390                         __gitcomp "
2391                                 --merge --strategy= --verbose --dry-run
2392                                 --fetch-all --no-rebase --commit-url
2393                                 --revision --interactive $cmt_opts $fc_opts
2394                                 "
2395                         ;;
2396                 set-tree,--*)
2397                         __gitcomp "--stdin $cmt_opts $fc_opts"
2398                         ;;
2399                 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2400                 show-externals,--*|mkdirs,--*)
2401                         __gitcomp "--revision="
2402                         ;;
2403                 log,--*)
2404                         __gitcomp "
2405                                 --limit= --revision= --verbose --incremental
2406                                 --oneline --show-commit --non-recursive
2407                                 --authors-file= --color
2408                                 "
2409                         ;;
2410                 rebase,--*)
2411                         __gitcomp "
2412                                 --merge --verbose --strategy= --local
2413                                 --fetch-all --dry-run $fc_opts
2414                                 "
2415                         ;;
2416                 commit-diff,--*)
2417                         __gitcomp "--message= --file= --revision= $cmt_opts"
2418                         ;;
2419                 info,--*)
2420                         __gitcomp "--url"
2421                         ;;
2422                 branch,--*)
2423                         __gitcomp "--dry-run --message --tag"
2424                         ;;
2425                 tag,--*)
2426                         __gitcomp "--dry-run --message"
2427                         ;;
2428                 blame,--*)
2429                         __gitcomp "--git-format"
2430                         ;;
2431                 migrate,--*)
2432                         __gitcomp "
2433                                 --config-dir= --ignore-paths= --minimize
2434                                 --no-auth-cache --username=
2435                                 "
2436                         ;;
2437                 reset,--*)
2438                         __gitcomp "--revision= --parent"
2439                         ;;
2440                 *)
2441                         ;;
2442                 esac
2443         fi
2444 }
2445
2446 _git_tag ()
2447 {
2448         local i c=1 f=0
2449         while [ $c -lt $cword ]; do
2450                 i="${words[c]}"
2451                 case "$i" in
2452                 -d|-v)
2453                         __gitcomp_nl "$(__git_tags)"
2454                         return
2455                         ;;
2456                 -f)
2457                         f=1
2458                         ;;
2459                 esac
2460                 ((c++))
2461         done
2462
2463         case "$prev" in
2464         -m|-F)
2465                 ;;
2466         -*|tag)
2467                 if [ $f = 1 ]; then
2468                         __gitcomp_nl "$(__git_tags)"
2469                 fi
2470                 ;;
2471         *)
2472                 __gitcomp_nl "$(__git_refs)"
2473                 ;;
2474         esac
2475 }
2476
2477 _git_whatchanged ()
2478 {
2479         _git_log
2480 }
2481
2482 __git_main ()
2483 {
2484         local i c=1 command __git_dir
2485
2486         while [ $c -lt $cword ]; do
2487                 i="${words[c]}"
2488                 case "$i" in
2489                 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2490                 --git-dir)   ((c++)) ; __git_dir="${words[c]}" ;;
2491                 --bare)      __git_dir="." ;;
2492                 --help) command="help"; break ;;
2493                 -c|--work-tree|--namespace) ((c++)) ;;
2494                 -*) ;;
2495                 *) command="$i"; break ;;
2496                 esac
2497                 ((c++))
2498         done
2499
2500         if [ -z "$command" ]; then
2501                 case "$cur" in
2502                 --*)   __gitcomp "
2503                         --paginate
2504                         --no-pager
2505                         --git-dir=
2506                         --bare
2507                         --version
2508                         --exec-path
2509                         --exec-path=
2510                         --html-path
2511                         --man-path
2512                         --info-path
2513                         --work-tree=
2514                         --namespace=
2515                         --no-replace-objects
2516                         --help
2517                         "
2518                         ;;
2519                 *)     __git_compute_porcelain_commands
2520                        __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2521                 esac
2522                 return
2523         fi
2524
2525         local completion_func="_git_${command//-/_}"
2526         declare -f $completion_func >/dev/null && $completion_func && return
2527
2528         local expansion=$(__git_aliased_command "$command")
2529         if [ -n "$expansion" ]; then
2530                 completion_func="_git_${expansion//-/_}"
2531                 declare -f $completion_func >/dev/null && $completion_func
2532         fi
2533 }
2534
2535 __gitk_main ()
2536 {
2537         __git_has_doubledash && return
2538
2539         local g="$(__gitdir)"
2540         local merge=""
2541         if [ -f "$g/MERGE_HEAD" ]; then
2542                 merge="--merge"
2543         fi
2544         case "$cur" in
2545         --*)
2546                 __gitcomp "
2547                         $__git_log_common_options
2548                         $__git_log_gitk_options
2549                         $merge
2550                         "
2551                 return
2552                 ;;
2553         esac
2554         __git_complete_revlist
2555 }
2556
2557 if [[ -n ${ZSH_VERSION-} ]]; then
2558         echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2559
2560         autoload -U +X compinit && compinit
2561
2562         __gitcomp ()
2563         {
2564                 emulate -L zsh
2565
2566                 local cur_="${3-$cur}"
2567
2568                 case "$cur_" in
2569                 --*=)
2570                         ;;
2571                 *)
2572                         local c IFS=$' \t\n'
2573                         local -a array
2574                         for c in ${=1}; do
2575                                 c="$c${4-}"
2576                                 case $c in
2577                                 --*=*|*.) ;;
2578                                 *) c="$c " ;;
2579                                 esac
2580                                 array[${#array[@]}+1]="$c"
2581                         done
2582                         compset -P '*[=:]'
2583                         compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2584                         ;;
2585                 esac
2586         }
2587
2588         __gitcomp_nl ()
2589         {
2590                 emulate -L zsh
2591
2592                 local IFS=$'\n'
2593                 compset -P '*[=:]'
2594                 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2595         }
2596
2597         __gitcomp_file ()
2598         {
2599                 emulate -L zsh
2600
2601                 local IFS=$'\n'
2602                 compset -P '*[=:]'
2603                 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2604         }
2605
2606         _git ()
2607         {
2608                 local _ret=1 cur cword prev
2609                 cur=${words[CURRENT]}
2610                 prev=${words[CURRENT-1]}
2611                 let cword=CURRENT-1
2612                 emulate ksh -c __${service}_main
2613                 let _ret && _default && _ret=0
2614                 return _ret
2615         }
2616
2617         compdef _git git gitk
2618         return
2619 fi
2620
2621 __git_func_wrap ()
2622 {
2623         local cur words cword prev
2624         _get_comp_words_by_ref -n =: cur words cword prev
2625         $1
2626 }
2627
2628 # Setup completion for certain functions defined above by setting common
2629 # variables and workarounds.
2630 # This is NOT a public function; use at your own risk.
2631 __git_complete ()
2632 {
2633         local wrapper="__git_wrap${2}"
2634         eval "$wrapper () { __git_func_wrap $2 ; }"
2635         complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2636                 || complete -o default -o nospace -F $wrapper $1
2637 }
2638
2639 # wrapper for backwards compatibility
2640 _git ()
2641 {
2642         __git_wrap__git_main
2643 }
2644
2645 # wrapper for backwards compatibility
2646 _gitk ()
2647 {
2648         __git_wrap__gitk_main
2649 }
2650
2651 __git_complete git __git_main
2652 __git_complete gitk __gitk_main
2653
2654 # The following are necessary only for Cygwin, and only are needed
2655 # when the user has tab-completed the executable name and consequently
2656 # included the '.exe' suffix.
2657 #
2658 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2659 __git_complete git.exe __git_main
2660 fi