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