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