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