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