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