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