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