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