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