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