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