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