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