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