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