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