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