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