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