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