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