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