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