Git 2.13-rc0
[git/git.git] / contrib / completion / git-completion.bash
CommitLineData
b5a49471 1# bash/zsh completion support for core Git.
690d8824 2#
c70680ce 3# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
690d8824 4# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
c70680ce 5# Distributed under the GNU General Public License, version 2.0.
690d8824
JH
6#
7# The contained completion routines provide support for completing:
8#
9# *) local and remote branch names
10# *) local and remote tag names
11# *) .git/remotes file names
12# *) git 'subcommands'
dfbe5eeb 13# *) git email aliases for git-send-email
690d8824 14# *) tree paths within 'ref:path/to/file' expressions
fea16b47 15# *) file paths within current working directory and index
c70680ce 16# *) common --long-options
690d8824
JH
17#
18# To use these routines:
19#
0e5ed7cc 20# 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
b5a49471 21# 2) Add the following line to your .bashrc/.zshrc:
0e5ed7cc 22# source ~/.git-completion.bash
af31a456
FC
23# 3) Consider changing your PS1 to also show the current branch,
24# see git-prompt.sh for details.
56f24e80
SP
25#
26# If you use complex aliases of form '!f() { ... }; f', you can use the null
27# command ':' as the first command in the function body to declare the desired
28# completion style. For example '!f() { : git commit ; ... }; f' will
29# tell the completion to use commit completion. This also works with aliases
30# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
690d8824 31
db8a9ff0
SP
32case "$COMP_WORDBREAKS" in
33*:*) : great ;;
34*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
35esac
36
beb6ee71
SG
37# Discovers the path to the git repository taking any '--git-dir=<path>' and
38# '-C <path>' options into account and stores it in the $__git_repo_path
39# variable.
40__git_find_repo_path ()
41{
fad9484f
SG
42 if [ -n "$__git_repo_path" ]; then
43 # we already know where it is
44 return
45 fi
46
beb6ee71
SG
47 if [ -n "${__git_C_args-}" ]; then
48 __git_repo_path="$(git "${__git_C_args[@]}" \
49 ${__git_dir:+--git-dir="$__git_dir"} \
50 rev-parse --absolute-git-dir 2>/dev/null)"
51 elif [ -n "${__git_dir-}" ]; then
52 test -d "$__git_dir" &&
53 __git_repo_path="$__git_dir"
54 elif [ -n "${GIT_DIR-}" ]; then
55 test -d "${GIT_DIR-}" &&
56 __git_repo_path="$GIT_DIR"
57 elif [ -d .git ]; then
58 __git_repo_path=.git
59 else
60 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
61 fi
62}
63
fad9484f 64# Deprecated: use __git_find_repo_path() and $__git_repo_path instead
a42577d4
TP
65# __gitdir accepts 0 or 1 arguments (i.e., location)
66# returns location of .git repo
873537fa
SP
67__gitdir ()
68{
25a31f81 69 if [ -z "${1-}" ]; then
beb6ee71
SG
70 __git_find_repo_path || return 1
71 echo "$__git_repo_path"
67ffa114
SP
72 elif [ -d "$1/.git" ]; then
73 echo "$1/.git"
74 else
75 echo "$1"
76 fi
873537fa
SP
77}
78
1cd23e9e
SG
79# Runs git with all the options given as argument, respecting any
80# '--git-dir=<path>' and '-C <path>' options present on the command line
81__git ()
82{
83 git ${__git_C_args:+"${__git_C_args[@]}"} \
e15098a3 84 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
1cd23e9e
SG
85}
86
dbda3b10
JN
87# The following function is based on code from:
88#
89# bash_completion - programmable completion functions for bash 3.2+
90#
91# Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
92# © 2009-2010, Bash Completion Maintainers
93# <bash-completion-devel@lists.alioth.debian.org>
94#
95# This program is free software; you can redistribute it and/or modify
96# it under the terms of the GNU General Public License as published by
97# the Free Software Foundation; either version 2, or (at your option)
98# any later version.
99#
100# This program is distributed in the hope that it will be useful,
101# but WITHOUT ANY WARRANTY; without even the implied warranty of
102# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103# GNU General Public License for more details.
104#
105# You should have received a copy of the GNU General Public License
106# along with this program; if not, write to the Free Software Foundation,
107# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
108#
109# The latest version of this software can be obtained here:
110#
111# http://bash-completion.alioth.debian.org/
112#
113# RELEASE: 2.x
114
115# This function can be used to access a tokenized list of words
116# on the command line:
117#
118# __git_reassemble_comp_words_by_ref '=:'
119# if test "${words_[cword_-1]}" = -w
120# then
121# ...
122# fi
123#
124# The argument should be a collection of characters from the list of
125# word completion separators (COMP_WORDBREAKS) to treat as ordinary
126# characters.
127#
128# This is roughly equivalent to going back in time and setting
129# COMP_WORDBREAKS to exclude those characters. The intent is to
130# make option types like --date=<type> and <rev>:<path> easy to
131# recognize by treating each shell word as a single token.
132#
133# It is best not to set COMP_WORDBREAKS directly because the value is
134# shared with other completion scripts. By the time the completion
135# function gets called, COMP_WORDS has already been populated so local
136# changes to COMP_WORDBREAKS have no effect.
137#
138# Output: words_, cword_, cur_.
139
140__git_reassemble_comp_words_by_ref()
141{
142 local exclude i j first
143 # Which word separators to exclude?
144 exclude="${1//[^$COMP_WORDBREAKS]}"
145 cword_=$COMP_CWORD
146 if [ -z "$exclude" ]; then
147 words_=("${COMP_WORDS[@]}")
148 return
149 fi
150 # List of word completion separators has shrunk;
151 # re-assemble words to complete.
152 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
153 # Append each nonempty word consisting of just
154 # word separator characters to the current word.
155 first=t
156 while
157 [ $i -gt 0 ] &&
158 [ -n "${COMP_WORDS[$i]}" ] &&
159 # word consists of excluded word separators
160 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
161 do
162 # Attach to the previous token,
163 # unless the previous token is the command name.
164 if [ $j -ge 2 ] && [ -n "$first" ]; then
165 ((j--))
166 fi
167 first=
168 words_[$j]=${words_[j]}${COMP_WORDS[i]}
169 if [ $i = $COMP_CWORD ]; then
170 cword_=$j
171 fi
172 if (($i < ${#COMP_WORDS[@]} - 1)); then
173 ((i++))
174 else
175 # Done.
176 return
177 fi
178 done
179 words_[$j]=${words_[j]}${COMP_WORDS[i]}
180 if [ $i = $COMP_CWORD ]; then
181 cword_=$j
182 fi
183 done
184}
185
da48616f
PD
186if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
187_get_comp_words_by_ref ()
188{
dbda3b10
JN
189 local exclude cur_ words_ cword_
190 if [ "$1" = "-n" ]; then
191 exclude=$2
192 shift 2
193 fi
194 __git_reassemble_comp_words_by_ref "$exclude"
195 cur_=${words_[cword_]}
da48616f
PD
196 while [ $# -gt 0 ]; do
197 case "$1" in
198 cur)
dbda3b10 199 cur=$cur_
da48616f
PD
200 ;;
201 prev)
dbda3b10 202 prev=${words_[$cword_-1]}
da48616f
PD
203 ;;
204 words)
dbda3b10 205 words=("${words_[@]}")
da48616f
PD
206 ;;
207 cword)
dbda3b10 208 cword=$cword_
da48616f
PD
209 ;;
210 esac
211 shift
212 done
213}
214fi
215
fef56eb0
SG
216# Fills the COMPREPLY array with prefiltered words without any additional
217# processing.
218# Callers must take care of providing only words that match the current word
219# to be completed and adding any prefix and/or suffix (trailing space!), if
220# necessary.
221# 1: List of newline-separated matching completion words, complete with
222# prefix and suffix.
223__gitcomp_direct ()
224{
225 local IFS=$'\n'
226
227 COMPREPLY=($1)
228}
229
f33c2c0f 230__gitcompappend ()
1ce23aad 231{
852ff1c3 232 local x i=${#COMPREPLY[@]}
7d13e0a3
FC
233 for x in $1; do
234 if [[ "$x" == "$3"* ]]; then
235 COMPREPLY[i++]="$2$x$4"
236 fi
237 done
1ce23aad
FC
238}
239
f33c2c0f
RR
240__gitcompadd ()
241{
242 COMPREPLY=()
243 __gitcompappend "$@"
244}
245
7d13e0a3
FC
246# Generates completion reply, appending a space to possible completion words,
247# if necessary.
f674bb80
SG
248# It accepts 1 to 4 arguments:
249# 1: List of possible completion words.
250# 2: A prefix to be added to each possible completion word (optional).
251# 3: Generate possible completion matches for this word (optional).
252# 4: A suffix to be appended to each possible completion word (optional).
72e5e989
SP
253__gitcomp ()
254{
583e4d57 255 local cur_="${3-$cur}"
9244d69b 256
9244d69b 257 case "$cur_" in
5447aac7 258 --*=)
5447aac7
SG
259 ;;
260 *)
b4cfbc96
FC
261 local c i=0 IFS=$' \t\n'
262 for c in $1; do
263 c="$c${4-}"
b4cfbc96 264 if [[ $c == "$cur_"* ]]; then
ddc996d7
FC
265 case $c in
266 --*=*|*.) ;;
267 *) c="$c " ;;
268 esac
b4cfbc96
FC
269 COMPREPLY[i++]="${2-}$c"
270 fi
271 done
5447aac7
SG
272 ;;
273 esac
72e5e989
SP
274}
275
f33c2c0f
RR
276# Variation of __gitcomp_nl () that appends to the existing list of
277# completion candidates, COMPREPLY.
278__gitcomp_nl_append ()
279{
280 local IFS=$'\n'
281 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
282}
283
7d13e0a3
FC
284# Generates completion reply from newline-separated possible completion words
285# by appending a space to all of them.
a31e6262
SG
286# It accepts 1 to 4 arguments:
287# 1: List of possible completion words, separated by a single newline.
288# 2: A prefix to be added to each possible completion word (optional).
289# 3: Generate possible completion matches for this word (optional).
290# 4: A suffix to be appended to each possible completion word instead of
291# the default space (optional). If specified but empty, nothing is
292# appended.
293__gitcomp_nl ()
294{
f33c2c0f
RR
295 COMPREPLY=()
296 __gitcomp_nl_append "$@"
a31e6262
SG
297}
298
fea16b47
MP
299# Generates completion reply with compgen from newline-separated possible
300# completion filenames.
301# It accepts 1 to 3 arguments:
302# 1: List of possible completion filenames, separated by a single newline.
303# 2: A directory prefix to be added to each possible completion filename
304# (optional).
305# 3: Generate possible completion matches for this word (optional).
306__gitcomp_file ()
307{
308 local IFS=$'\n'
309
310 # XXX does not work when the directory prefix contains a tilde,
311 # since tilde expansion is not applied.
312 # This means that COMPREPLY will be empty and Bash default
313 # completion will be used.
0afe8e9e 314 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
fea16b47 315
3ffa4df4 316 # use a hack to enable file mode in bash < 4
fbe45118 317 compopt -o filenames +o nospace 2>/dev/null ||
3ffa4df4 318 compgen -f /non-existing-dir/ > /dev/null
fea16b47
MP
319}
320
f825972c
FC
321# Execute 'git ls-files', unless the --committable option is specified, in
322# which case it runs 'git diff-index' to find out the files that can be
323# committed. It return paths relative to the directory specified in the first
324# argument, and using the options specified in the second argument.
fea16b47
MP
325__git_ls_files_helper ()
326{
fca416a4 327 if [ "$2" == "--committable" ]; then
1cd23e9e 328 __git -C "$1" diff-index --name-only --relative HEAD
fca416a4
JH
329 else
330 # NOTE: $2 is not quoted in order to support multiple options
1cd23e9e 331 __git -C "$1" ls-files --exclude-standard $2
e15098a3 332 fi
35ba83cc 333}
fea16b47
MP
334
335
fea16b47
MP
336# __git_index_files accepts 1 or 2 arguments:
337# 1: Options to pass to ls-files (required).
fea16b47
MP
338# 2: A directory path (optional).
339# If provided, only files within the specified directory are listed.
340# Sub directories are never recursed. Path must have a trailing
341# slash.
342__git_index_files ()
343{
a958d40f 344 local root="${2-.}" file
fea16b47 345
a958d40f
SG
346 __git_ls_files_helper "$root" "$1" |
347 while read -r file; do
348 case "$file" in
349 ?*/*) echo "${file%%/*}" ;;
350 *) echo "$file" ;;
351 esac
352 done | sort | uniq
fea16b47
MP
353}
354
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
690d8824
JH
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
f483a0aa 1105 --recount --directory=
b3391775 1106 "
88329195
SP
1107 return
1108 esac
88329195
SP
1109}
1110
8435b548
SP
1111_git_add ()
1112{
8435b548
SP
1113 case "$cur" in
1114 --*)
1d284cba
SG
1115 __gitcomp "
1116 --interactive --refresh --patch --update --dry-run
bd9ab9df 1117 --ignore-errors --intent-to-add --force --edit --chmod=
1d284cba 1118 "
8435b548
SP
1119 return
1120 esac
fea16b47 1121
bd9ab9df
CW
1122 local complete_opt="--others --modified --directory --no-empty-directory"
1123 if test -n "$(__git_find_on_cmdline "-u --update")"
1124 then
1125 complete_opt="--modified"
1126 fi
1127 __git_complete_index_file "$complete_opt"
8435b548
SP
1128}
1129
b3191ce2
LM
1130_git_archive ()
1131{
b3191ce2
LM
1132 case "$cur" in
1133 --format=*)
1134 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1135 return
1136 ;;
1137 --remote=*)
a31e6262 1138 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
b3191ce2
LM
1139 return
1140 ;;
1141 --*)
1142 __gitcomp "
1143 --format= --list --verbose
f483a0aa 1144 --prefix= --remote= --exec= --output
b3191ce2
LM
1145 "
1146 return
1147 ;;
1148 esac
1149 __git_complete_file
1150}
1151
b2e69f62
SP
1152_git_bisect ()
1153{
d773c631
SG
1154 __git_has_doubledash && return
1155
bf11d461 1156 local subcommands="start bad good skip reset visualize replay log run"
918c03c2 1157 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3ff1320d 1158 if [ -z "$subcommand" ]; then
fad9484f
SG
1159 __git_find_repo_path
1160 if [ -f "$__git_repo_path"/BISECT_START ]; then
128191f5
SG
1161 __gitcomp "$subcommands"
1162 else
1163 __gitcomp "replay start"
1164 fi
b2e69f62
SP
1165 return
1166 fi
1167
3ff1320d 1168 case "$subcommand" in
8205ff8e 1169 bad|good|reset|skip|start)
15b4a163 1170 __git_complete_refs
b2e69f62
SP
1171 ;;
1172 *)
b2e69f62
SP
1173 ;;
1174 esac
1175}
1176
690d8824
JH
1177_git_branch ()
1178{
da4902a7 1179 local i c=1 only_local_ref="n" has_r="n"
b9217642 1180
da48616f
PD
1181 while [ $c -lt $cword ]; do
1182 i="${words[c]}"
b9217642 1183 case "$i" in
2703c22f
VS
1184 -d|--delete|-m|--move) only_local_ref="y" ;;
1185 -r|--remotes) has_r="y" ;;
b9217642 1186 esac
6e8c755f 1187 ((c++))
b9217642
SG
1188 done
1189
da48616f 1190 case "$cur" in
ca45d0fa 1191 --set-upstream-to=*)
15b4a163 1192 __git_complete_refs --cur="${cur##--set-upstream-to=}"
ca45d0fa 1193 ;;
3b376b0c
SG
1194 --*)
1195 __gitcomp "
1196 --color --no-color --verbose --abbrev= --no-abbrev
ac3f5a34 1197 --track --no-track --contains --no-contains --merged --no-merged
04308e9d 1198 --set-upstream-to= --edit-description --list
2703c22f 1199 --unset-upstream --delete --move --remotes
f483a0aa 1200 --column --no-column --sort= --points-at
3b376b0c
SG
1201 "
1202 ;;
b9217642
SG
1203 *)
1204 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
227307a6 1205 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
b9217642 1206 else
15b4a163 1207 __git_complete_refs
b9217642
SG
1208 fi
1209 ;;
3b376b0c 1210 esac
690d8824
JH
1211}
1212
374a58c9
ML
1213_git_bundle ()
1214{
da48616f
PD
1215 local cmd="${words[2]}"
1216 case "$cword" in
8d8163f3 1217 2)
374a58c9
ML
1218 __gitcomp "create list-heads verify unbundle"
1219 ;;
8d8163f3 1220 3)
374a58c9
ML
1221 # looking for a file
1222 ;;
1223 *)
1224 case "$cmd" in
1225 create)
1226 __git_complete_revlist
1227 ;;
1228 esac
1229 ;;
1230 esac
1231}
1232
690d8824
JH
1233_git_checkout ()
1234{
c84bb14c
SG
1235 __git_has_doubledash && return
1236
e648f8b6
SG
1237 case "$cur" in
1238 --conflict=*)
1239 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1240 ;;
1241 --*)
1242 __gitcomp "
1243 --quiet --ours --theirs --track --no-track --merge
86e8e7a5 1244 --conflict= --orphan --patch
e648f8b6
SG
1245 "
1246 ;;
1247 *)
34a6bbb5
KB
1248 # check if --track, --no-track, or --no-guess was specified
1249 # if so, disable DWIM mode
15b4a163 1250 local flags="--track --no-track --no-guess" track_opt="--track"
34a6bbb5 1251 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
15b4a163 1252 track_opt=''
34a6bbb5 1253 fi
15b4a163 1254 __git_complete_refs $track_opt
e648f8b6
SG
1255 ;;
1256 esac
690d8824
JH
1257}
1258
d8a9fea5
SP
1259_git_cherry ()
1260{
15b4a163 1261 __git_complete_refs
d8a9fea5
SP
1262}
1263
1273231e
SP
1264_git_cherry_pick ()
1265{
fad9484f
SG
1266 __git_find_repo_path
1267 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
7655fa7f
FC
1268 __gitcomp "--continue --quit --abort"
1269 return
1270 fi
1273231e
SP
1271 case "$cur" in
1272 --*)
7655fa7f 1273 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1273231e
SP
1274 ;;
1275 *)
15b4a163 1276 __git_complete_refs
1273231e
SP
1277 ;;
1278 esac
1279}
1280
4181c7e8
LM
1281_git_clean ()
1282{
4181c7e8
LM
1283 case "$cur" in
1284 --*)
1285 __gitcomp "--dry-run --quiet"
1286 return
1287 ;;
1288 esac
fea16b47
MP
1289
1290 # XXX should we check for -x option ?
ea95c7b8 1291 __git_complete_index_file "--others --directory"
4181c7e8
LM
1292}
1293
3eb11012
LM
1294_git_clone ()
1295{
3eb11012
LM
1296 case "$cur" in
1297 --*)
1298 __gitcomp "
1299 --local
1300 --no-hardlinks
1301 --shared
1302 --reference
1303 --quiet
1304 --no-checkout
1305 --bare
1306 --mirror
1307 --origin
1308 --upload-pack
1309 --template=
1310 --depth
4047fecf
RT
1311 --single-branch
1312 --branch
5f072e00 1313 --recurse-submodules
f483a0aa
CW
1314 --no-single-branch
1315 --shallow-submodules
3eb11012
LM
1316 "
1317 return
1318 ;;
1319 esac
3eb11012
LM
1320}
1321
21d2a9e3
TB
1322__git_untracked_file_modes="all no normal"
1323
4548e855
SP
1324_git_commit ()
1325{
fea16b47
MP
1326 case "$prev" in
1327 -c|-C)
15b4a163 1328 __git_complete_refs
fea16b47
MP
1329 return
1330 ;;
1331 esac
d773c631 1332
4548e855 1333 case "$cur" in
9a424b27 1334 --cleanup=*)
72dbb365 1335 __gitcomp "default scissors strip verbatim whitespace
9a424b27
SG
1336 " "" "${cur##--cleanup=}"
1337 return
1338 ;;
77653abd
TM
1339 --reuse-message=*|--reedit-message=*|\
1340 --fixup=*|--squash=*)
15b4a163 1341 __git_complete_refs --cur="${cur#*=}"
9a424b27
SG
1342 return
1343 ;;
1344 --untracked-files=*)
21d2a9e3 1345 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
9a424b27
SG
1346 return
1347 ;;
4548e855 1348 --*)
b3391775 1349 __gitcomp "
4548e855 1350 --all --author= --signoff --verify --no-verify
7dd9ab0c
YB
1351 --edit --no-edit
1352 --amend --include --only --interactive
9a424b27
SG
1353 --dry-run --reuse-message= --reedit-message=
1354 --reset-author --file= --message= --template=
1355 --cleanup= --untracked-files --untracked-files=
77653abd 1356 --verbose --quiet --fixup= --squash=
f483a0aa 1357 --patch --short --date --allow-empty
b3391775 1358 "
4548e855
SP
1359 return
1360 esac
fea16b47 1361
1cd23e9e 1362 if __git rev-parse --verify --quiet HEAD >/dev/null; then
f825972c 1363 __git_complete_index_file "--committable"
fea16b47
MP
1364 else
1365 # This is the first commit
1366 __git_complete_index_file "--cached"
1367 fi
4548e855
SP
1368}
1369
217926c0
SP
1370_git_describe ()
1371{
cbb504c9
TR
1372 case "$cur" in
1373 --*)
1374 __gitcomp "
1375 --all --tags --contains --abbrev= --candidates=
f483a0aa 1376 --exact-match --debug --long --match --always --first-parent
77d21f29 1377 --exclude
cbb504c9
TR
1378 "
1379 return
1380 esac
15b4a163 1381 __git_complete_refs
217926c0
SP
1382}
1383
07924d4d
MP
1384__git_diff_algorithms="myers minimal patience histogram"
1385
462f2134 1386__git_diff_submodule_formats="diff log short"
ac76fd54 1387
20bf7292 1388__git_diff_common_options="--stat --numstat --shortstat --summary
b3a4f858
JS
1389 --patch-with-stat --name-only --name-status --color
1390 --no-color --color-words --no-renames --check
f135aacb 1391 --full-index --binary --abbrev --diff-filter=
47d5a8fa 1392 --find-copies-harder
b3a4f858 1393 --text --ignore-space-at-eol --ignore-space-change
c2545167
TB
1394 --ignore-all-space --ignore-blank-lines --exit-code
1395 --quiet --ext-diff --no-ext-diff
aba201c6 1396 --no-prefix --src-prefix= --dst-prefix=
6d0e674a 1397 --inter-hunk-context=
216120ab 1398 --patience --histogram --minimal
e6414b46 1399 --raw --word-diff --word-diff-regex=
8fd2cfa7
SB
1400 --dirstat --dirstat= --dirstat-by-file
1401 --dirstat-by-file= --cumulative
07924d4d 1402 --diff-algorithm=
ac76fd54 1403 --submodule --submodule=
20bf7292
TR
1404"
1405
1406_git_diff ()
1407{
1408 __git_has_doubledash && return
1409
20bf7292 1410 case "$cur" in
07924d4d
MP
1411 --diff-algorithm=*)
1412 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1413 return
1414 ;;
ac76fd54
JK
1415 --submodule=*)
1416 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1417 return
1418 ;;
20bf7292 1419 --*)
ebd15bf0 1420 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
861514d3 1421 --base --ours --theirs --no-index
20bf7292 1422 $__git_diff_common_options
aba201c6 1423 "
b3a4f858
JS
1424 return
1425 ;;
1426 esac
1d66ec58 1427 __git_complete_revlist_file
690d8824
JH
1428}
1429
c5f424fd 1430__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
f13f9b0e 1431 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
e2dc2de9
DA
1432"
1433
1434_git_difftool ()
1435{
f7ad96cf
MH
1436 __git_has_doubledash && return
1437
e2dc2de9
DA
1438 case "$cur" in
1439 --tool=*)
1440 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1441 return
1442 ;;
1443 --*)
f7ad96cf
MH
1444 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1445 --base --ours --theirs
1446 --no-renames --diff-filter= --find-copies-harder
1447 --relative --ignore-submodules
1448 --tool="
e2dc2de9
DA
1449 return
1450 ;;
1451 esac
d8517cc6 1452 __git_complete_revlist_file
e2dc2de9
DA
1453}
1454
4dd5c470
SYS
1455__git_fetch_recurse_submodules="yes on-demand no"
1456
0a4e1472
JS
1457__git_fetch_options="
1458 --quiet --verbose --append --upload-pack --force --keep --depth=
4dd5c470 1459 --tags --no-tags --all --prune --dry-run --recurse-submodules=
f483a0aa 1460 --unshallow --update-shallow
0a4e1472
JS
1461"
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
JS
1470 --*)
1471 __gitcomp "$__git_fetch_options"
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 --*)
1508 __gitcomp "
1509 --tags --root --unreachable --cache --no-reflogs --full
f483a0aa 1510 --strict --verbose --lost-found --name-objects
4bca8636
AJ
1511 "
1512 return
1513 ;;
1514 esac
4bca8636
AJ
1515}
1516
b26c8748
SP
1517_git_gc ()
1518{
b26c8748
SP
1519 case "$cur" in
1520 --*)
47e98eec 1521 __gitcomp "--prune --aggressive"
b26c8748
SP
1522 return
1523 ;;
1524 esac
b26c8748
SP
1525}
1526
66729509
SG
1527_git_gitk ()
1528{
1529 _gitk
1530}
1531
7826a786
SG
1532# Lists matching symbol names from a tag (as in ctags) file.
1533# 1: List symbol names matching this word.
1534# 2: The tag file to list symbol names from.
1535# 3: A prefix to be added to each listed symbol name (optional).
1536# 4: A suffix to be appended to each listed symbol name (optional).
1537__git_match_ctag () {
1538 awk -v pfx="${3-}" -v sfx="${4-}" "
1539 /^${1//\//\\/}/ { print pfx \$1 sfx }
1540 " "$2"
29eec71f
JK
1541}
1542
2f779f91
SG
1543# Complete symbol names from a tag file.
1544# Usage: __git_complete_symbol [<option>]...
1545# --tags=<file>: The tag file to list symbol names from instead of the
1546# default "tags".
1547# --pfx=<prefix>: A prefix to be added to each symbol name.
1548# --cur=<word>: The current symbol name to be completed. Defaults to
1549# the current word to be completed.
1550# --sfx=<suffix>: A suffix to be appended to each symbol name instead
1551# of the default space.
1552__git_complete_symbol () {
1553 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1554
1555 while test $# != 0; do
1556 case "$1" in
1557 --tags=*) tags="${1##--tags=}" ;;
1558 --pfx=*) pfx="${1##--pfx=}" ;;
1559 --cur=*) cur_="${1##--cur=}" ;;
1560 --sfx=*) sfx="${1##--sfx=}" ;;
1561 *) return 1 ;;
1562 esac
1563 shift
1564 done
1565
1566 if test -r "$tags"; then
1567 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1568 fi
29eec71f
JK
1569}
1570
c72e0db1
LM
1571_git_grep ()
1572{
1573 __git_has_doubledash && return
1574
c72e0db1
LM
1575 case "$cur" in
1576 --*)
1577 __gitcomp "
1578 --cached
1579 --text --ignore-case --word-regexp --invert-match
5a69eaf5 1580 --full-name --line-number
c72e0db1 1581 --extended-regexp --basic-regexp --fixed-strings
63e7e9d8 1582 --perl-regexp
89f09dd3 1583 --threads
c72e0db1
LM
1584 --files-with-matches --name-only
1585 --files-without-match
a91f453f 1586 --max-depth
c72e0db1
LM
1587 --count
1588 --and --or --not --all-match
f483a0aa
CW
1589 --break --heading --show-function --function-context
1590 --untracked --no-index
c72e0db1
LM
1591 "
1592 return
1593 ;;
1594 esac
17225c49 1595
29eec71f
JK
1596 case "$cword,$prev" in
1597 2,*|*,-*)
2f779f91 1598 __git_complete_symbol && return
29eec71f
JK
1599 ;;
1600 esac
1601
15b4a163 1602 __git_complete_refs
c72e0db1
LM
1603}
1604
1eb7e2f8
LM
1605_git_help ()
1606{
1eb7e2f8
LM
1607 case "$cur" in
1608 --*)
716b29db 1609 __gitcomp "--all --guides --info --man --web"
1eb7e2f8
LM
1610 return
1611 ;;
1612 esac
eaa4e6ee 1613 __git_compute_all_commands
f85a6f0b 1614 __gitcomp "$__git_all_commands $(__git_aliases)
2946cccf 1615 attributes cli core-tutorial cvs-migration
4d10b7e1
RT
1616 diffcore everyday gitk glossary hooks ignore modules
1617 namespaces repository-layout revisions tutorial tutorial-2
99f0b599 1618 workflows
2946cccf 1619 "
1eb7e2f8
LM
1620}
1621
5dad868b
LM
1622_git_init ()
1623{
5dad868b
LM
1624 case "$cur" in
1625 --shared=*)
1626 __gitcomp "
1627 false true umask group all world everybody
1628 " "" "${cur##--shared=}"
1629 return
1630 ;;
1631 --*)
1632 __gitcomp "--quiet --bare --template= --shared --shared="
1633 return
1634 ;;
1635 esac
5dad868b
LM
1636}
1637
b1bc1494
LM
1638_git_ls_files ()
1639{
b1bc1494
LM
1640 case "$cur" in
1641 --*)
1642 __gitcomp "--cached --deleted --modified --others --ignored
1643 --stage --directory --no-empty-directory --unmerged
1644 --killed --exclude= --exclude-from=
1645 --exclude-per-directory= --exclude-standard
1646 --error-unmatch --with-tree= --full-name
1647 --abbrev --ignored --exclude-per-directory
1648 "
1649 return
1650 ;;
1651 esac
fea16b47
MP
1652
1653 # XXX ignore options like --modified and always suggest all cached
1654 # files.
1655 __git_complete_index_file "--cached"
b1bc1494
LM
1656}
1657
690d8824
JH
1658_git_ls_remote ()
1659{
2c0f3a53
CW
1660 case "$cur" in
1661 --*)
1662 __gitcomp "--heads --tags --refs --get-url --symref"
1663 return
1664 ;;
1665 esac
a31e6262 1666 __gitcomp_nl "$(__git_remotes)"
690d8824
JH
1667}
1668
1669_git_ls_tree ()
1670{
1671 __git_complete_file
1672}
1673
a393777e
TR
1674# Options that go well for log, shortlog and gitk
1675__git_log_common_options="
1676 --not --all
1677 --branches --tags --remotes
4fe1a619 1678 --first-parent --merges --no-merges
a393777e
TR
1679 --max-count=
1680 --max-age= --since= --after=
1681 --min-age= --until= --before=
6a6ebded
MG
1682 --min-parents= --max-parents=
1683 --no-min-parents --no-max-parents
a393777e
TR
1684"
1685# Options that go well for log and gitk (not shortlog)
1686__git_log_gitk_options="
1687 --dense --sparse --full-history
1688 --simplify-merges --simplify-by-decoration
3925b575 1689 --left-right --notes --no-notes
a393777e
TR
1690"
1691# Options that go well for log and shortlog (not gitk)
1692__git_log_shortlog_options="
1693 --author= --committer= --grep=
22dfa8a2 1694 --all-match --invert-grep
a393777e
TR
1695"
1696
3d279863 1697__git_log_pretty_formats="oneline short medium full fuller email raw format:"
672c68cb 1698__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
3d279863 1699
690d8824
JH
1700_git_log ()
1701{
d773c631 1702 __git_has_doubledash && return
fad9484f 1703 __git_find_repo_path
d773c631 1704
bf3c20f6 1705 local merge=""
fad9484f 1706 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
bf3c20f6
TR
1707 merge="--merge"
1708 fi
41d2716c
SG
1709 case "$prev,$cur" in
1710 -L,:*:*)
1711 return # fall back to Bash filename completion
1712 ;;
1713 -L,:*)
1714 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1715 return
1716 ;;
1717 -G,*|-S,*)
1718 __git_complete_symbol
1719 return
1720 ;;
1721 esac
6e31b866 1722 case "$cur" in
e67d71e5 1723 --pretty=*|--format=*)
c3898111 1724 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
e67d71e5 1725 " "" "${cur#*=}"
72de29c2
TL
1726 return
1727 ;;
47e98eec 1728 --date=*)
672c68cb 1729 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
47e98eec
SP
1730 return
1731 ;;
af4e9e8c 1732 --decorate=*)
af16bdaa 1733 __gitcomp "full short no" "" "${cur##--decorate=}"
af4e9e8c
SB
1734 return
1735 ;;
ac76fd54
JK
1736 --diff-algorithm=*)
1737 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1738 return
1739 ;;
1740 --submodule=*)
1741 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1742 return
1743 ;;
6e31b866 1744 --*)
b3391775 1745 __gitcomp "
a393777e
TR
1746 $__git_log_common_options
1747 $__git_log_shortlog_options
1748 $__git_log_gitk_options
8f87fae6 1749 --root --topo-order --date-order --reverse
5d0e6343 1750 --follow --full-diff
6e31b866 1751 --abbrev-commit --abbrev=
47e98eec 1752 --relative-date --date=
72de29c2 1753 --pretty= --format= --oneline
2ca0b197 1754 --show-signature
d3bfbf91 1755 --cherry-mark
a393777e 1756 --cherry-pick
20827d99 1757 --graph
af4e9e8c 1758 --decorate --decorate=
20bf7292 1759 --walk-reflogs
a393777e 1760 --parents --children
bf3c20f6 1761 $merge
20bf7292 1762 $__git_diff_common_options
47d5a8fa 1763 --pickaxe-all --pickaxe-regex
b3391775 1764 "
6e31b866
SP
1765 return
1766 ;;
41d2716c
SG
1767 -L:*:*)
1768 return # fall back to Bash filename completion
1769 ;;
1770 -L:*)
1771 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1772 return
1773 ;;
1774 -G*)
1775 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1776 return
1777 ;;
1778 -S*)
1779 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1780 return
1781 ;;
6e31b866 1782 esac
f53352fb 1783 __git_complete_revlist
690d8824
JH
1784}
1785
6d2b06f0 1786# Common merge options shared by git-merge(1) and git-pull(1).
0a4e1472
JS
1787__git_merge_options="
1788 --no-commit --no-stat --log --no-log --squash --strategy
2ff14e31 1789 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
8fee8726
JK
1790 --verify-signatures --no-verify-signatures --gpg-sign
1791 --quiet --verbose --progress --no-progress
0a4e1472
JS
1792"
1793
4ad91321
SP
1794_git_merge ()
1795{
3c7b480a
JS
1796 __git_complete_strategy && return
1797
4ad91321
SP
1798 case "$cur" in
1799 --*)
8fee8726 1800 __gitcomp "$__git_merge_options
c261a87e 1801 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
4ad91321
SP
1802 return
1803 esac
15b4a163 1804 __git_complete_refs
4ad91321
SP
1805}
1806
b4c72162
LM
1807_git_mergetool ()
1808{
b4c72162
LM
1809 case "$cur" in
1810 --tool=*)
e2dc2de9 1811 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
b4c72162
LM
1812 return
1813 ;;
1814 --*)
f483a0aa 1815 __gitcomp "--tool= --prompt --no-prompt"
b4c72162
LM
1816 return
1817 ;;
1818 esac
b4c72162
LM
1819}
1820
690d8824
JH
1821_git_merge_base ()
1822{
85453fd1
JK
1823 case "$cur" in
1824 --*)
1825 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1826 return
1827 ;;
1828 esac
15b4a163 1829 __git_complete_refs
690d8824
JH
1830}
1831
1127c51c
LM
1832_git_mv ()
1833{
1127c51c
LM
1834 case "$cur" in
1835 --*)
1836 __gitcomp "--dry-run"
1837 return
1838 ;;
1839 esac
fea16b47
MP
1840
1841 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1842 # We need to show both cached and untracked files (including
1843 # empty directories) since this may not be the last argument.
1844 __git_complete_index_file "--cached --others --directory"
1845 else
1846 __git_complete_index_file "--cached"
1847 fi
1127c51c
LM
1848}
1849
d33909bf
SP
1850_git_name_rev ()
1851{
b3391775 1852 __gitcomp "--tags --all --stdin"
d33909bf
SP
1853}
1854
00f09d0e
SG
1855_git_notes ()
1856{
2a5da755
SG
1857 local subcommands='add append copy edit list prune remove show'
1858 local subcommand="$(__git_find_on_cmdline "$subcommands")"
00f09d0e 1859
2a5da755
SG
1860 case "$subcommand,$cur" in
1861 ,--*)
1862 __gitcomp '--ref'
1863 ;;
1864 ,*)
39540681 1865 case "$prev" in
2a5da755 1866 --ref)
15b4a163 1867 __git_complete_refs
2a5da755
SG
1868 ;;
1869 *)
1870 __gitcomp "$subcommands --ref"
1871 ;;
1872 esac
1873 ;;
a8f89bfa 1874 add,--reuse-message=*|append,--reuse-message=*|\
2a5da755 1875 add,--reedit-message=*|append,--reedit-message=*)
15b4a163 1876 __git_complete_refs --cur="${cur#*=}"
2a5da755
SG
1877 ;;
1878 add,--*|append,--*)
1879 __gitcomp '--file= --message= --reedit-message=
1880 --reuse-message='
1881 ;;
1882 copy,--*)
1883 __gitcomp '--stdin'
1884 ;;
1885 prune,--*)
1886 __gitcomp '--dry-run --verbose'
1887 ;;
1888 prune,*)
00f09d0e
SG
1889 ;;
1890 *)
39540681 1891 case "$prev" in
2a5da755
SG
1892 -m|-F)
1893 ;;
1894 *)
15b4a163 1895 __git_complete_refs
2a5da755
SG
1896 ;;
1897 esac
00f09d0e
SG
1898 ;;
1899 esac
1900}
1901
690d8824
JH
1902_git_pull ()
1903{
0a4e1472
JS
1904 __git_complete_strategy && return
1905
0a4e1472 1906 case "$cur" in
4dd5c470
SYS
1907 --recurse-submodules=*)
1908 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1909 return
1910 ;;
0a4e1472
JS
1911 --*)
1912 __gitcomp "
1913 --rebase --no-rebase
1914 $__git_merge_options
1915 $__git_fetch_options
1916 "
1917 return
1918 ;;
1919 esac
52d5c3b5 1920 __git_complete_remote_or_refspec
690d8824
JH
1921}
1922
446624ce 1923__git_push_recurse_submodules="check on-demand only"
4dd5c470 1924
aaf7253f
JK
1925__git_complete_force_with_lease ()
1926{
1927 local cur_=$1
1928
1929 case "$cur_" in
1930 --*=)
1931 ;;
1932 *:*)
15b4a163 1933 __git_complete_refs --cur="${cur_#*:}"
aaf7253f
JK
1934 ;;
1935 *)
15b4a163 1936 __git_complete_refs --cur="$cur_"
aaf7253f
JK
1937 ;;
1938 esac
1939}
1940
690d8824
JH
1941_git_push ()
1942{
da48616f 1943 case "$prev" in
0a4e1472 1944 --repo)
a31e6262 1945 __gitcomp_nl "$(__git_remotes)"
0a4e1472 1946 return
3a224ff2
JK
1947 ;;
1948 --recurse-submodules)
1949 __gitcomp "$__git_push_recurse_submodules"
1950 return
1951 ;;
0a4e1472
JS
1952 esac
1953 case "$cur" in
1954 --repo=*)
a31e6262 1955 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
0a4e1472
JS
1956 return
1957 ;;
4dd5c470
SYS
1958 --recurse-submodules=*)
1959 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1960 return
1961 ;;
aaf7253f
JK
1962 --force-with-lease=*)
1963 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1964 return
1965 ;;
0a4e1472
JS
1966 --*)
1967 __gitcomp "
1968 --all --mirror --tags --dry-run --force --verbose
9e8a6a94 1969 --quiet --prune --delete --follow-tags
3623dc03 1970 --receive-pack= --repo= --set-upstream
aaf7253f 1971 --force-with-lease --force-with-lease= --recurse-submodules=
0a4e1472
JS
1972 "
1973 return
1974 ;;
1975 esac
52d5c3b5 1976 __git_complete_remote_or_refspec
690d8824
JH
1977}
1978
61d926a3
SP
1979_git_rebase ()
1980{
fad9484f
SG
1981 __git_find_repo_path
1982 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
9512177b 1983 __gitcomp "--continue --skip --abort --quit --edit-todo"
09bb6520 1984 return
fad9484f
SG
1985 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1986 [ -d "$__git_repo_path"/rebase-merge ]; then
9512177b 1987 __gitcomp "--continue --skip --abort --quit"
61d926a3
SP
1988 return
1989 fi
3c7b480a 1990 __git_complete_strategy && return
61d926a3 1991 case "$cur" in
93cf50a4
BG
1992 --whitespace=*)
1993 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1994 return
1995 ;;
61d926a3 1996 --*)
93cf50a4
BG
1997 __gitcomp "
1998 --onto --merge --strategy --interactive
1999 --preserve-merges --stat --no-stat
2000 --committer-date-is-author-date --ignore-date
2001 --ignore-whitespace --whitespace=
fa4b5e3a
JK
2002 --autosquash --no-autosquash
2003 --fork-point --no-fork-point
2004 --autostash --no-autostash
2005 --verify --no-verify
2006 --keep-empty --root --force-rebase --no-ff
2007 --exec
93cf50a4
BG
2008 "
2009
61d926a3
SP
2010 return
2011 esac
15b4a163 2012 __git_complete_refs
61d926a3
SP
2013}
2014
057f3279
TRC
2015_git_reflog ()
2016{
2017 local subcommands="show delete expire"
2018 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2019
2020 if [ -z "$subcommand" ]; then
2021 __gitcomp "$subcommands"
2022 else
15b4a163 2023 __git_complete_refs
057f3279
TRC
2024 fi
2025}
2026
ae616de6 2027__git_send_email_confirm_options="always never auto cc compose"
cb8a9bd5 2028__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
ae616de6 2029
25a1f374
TL
2030_git_send_email ()
2031{
dfbe5eeb
JK
2032 case "$prev" in
2033 --to|--cc|--bcc|--from)
e15098a3 2034 __gitcomp "$(__git send-email --dump-aliases)"
dfbe5eeb
JK
2035 return
2036 ;;
2037 esac
2038
25a1f374 2039 case "$cur" in
ae616de6
SB
2040 --confirm=*)
2041 __gitcomp "
2042 $__git_send_email_confirm_options
2043 " "" "${cur##--confirm=}"
2044 return
2045 ;;
2046 --suppress-cc=*)
2047 __gitcomp "
2048 $__git_send_email_suppresscc_options
2049 " "" "${cur##--suppress-cc=}"
2050
2051 return
2052 ;;
2053 --smtp-encryption=*)
2054 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2055 return
2056 ;;
2f65494d
FC
2057 --thread=*)
2058 __gitcomp "
2059 deep shallow
2060 " "" "${cur##--thread=}"
2061 return
2062 ;;
dfbe5eeb 2063 --to=*|--cc=*|--bcc=*|--from=*)
e15098a3 2064 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
dfbe5eeb
JK
2065 return
2066 ;;
25a1f374 2067 --*)
77813151 2068 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
ae616de6
SB
2069 --compose --confirm= --dry-run --envelope-sender
2070 --from --identity
25a1f374
TL
2071 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2072 --no-suppress-from --no-thread --quiet
2073 --signed-off-by-cc --smtp-pass --smtp-server
ae616de6
SB
2074 --smtp-server-port --smtp-encryption= --smtp-user
2075 --subject --suppress-cc= --suppress-from --thread --to
2f65494d
FC
2076 --validate --no-validate
2077 $__git_format_patch_options"
25a1f374
TL
2078 return
2079 ;;
2080 esac
2f65494d 2081 __git_complete_revlist
25a1f374
TL
2082}
2083
424cce83
SG
2084_git_stage ()
2085{
2086 _git_add
2087}
2088
634d2344
TB
2089_git_status ()
2090{
2091 local complete_opt
2092 local untracked_state
2093
2094 case "$cur" in
2095 --ignore-submodules=*)
2096 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2097 return
2098 ;;
2099 --untracked-files=*)
2100 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2101 return
2102 ;;
2103 --column=*)
2104 __gitcomp "
2105 always never auto column row plain dense nodense
2106 " "" "${cur##--column=}"
2107 return
2108 ;;
2109 --*)
2110 __gitcomp "
2111 --short --branch --porcelain --long --verbose
2112 --untracked-files= --ignore-submodules= --ignored
2113 --column= --no-column
2114 "
2115 return
2116 ;;
2117 esac
2118
2119 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2120 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2121
2122 case "$untracked_state" in
2123 no)
2124 # --ignored option does not matter
2125 complete_opt=
2126 ;;
2127 all|normal|*)
2128 complete_opt="--cached --directory --no-empty-directory --others"
2129
2130 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2131 complete_opt="$complete_opt --ignored --exclude=*"
2132 fi
2133 ;;
2134 esac
2135
2136 __git_complete_index_file "$complete_opt"
2137}
2138
00652369
SB
2139__git_config_get_set_variables ()
2140{
da48616f 2141 local prevword word config_file= c=$cword
00652369 2142 while [ $c -gt 1 ]; do
da48616f 2143 word="${words[c]}"
00652369 2144 case "$word" in
66c0786c 2145 --system|--global|--local|--file=*)
00652369
SB
2146 config_file="$word"
2147 break
2148 ;;
2149 -f|--file)
2150 config_file="$word $prevword"
2151 break
2152 ;;
2153 esac
2154 prevword=$word
2155 c=$((--c))
2156 done
2157
e15098a3 2158 __git config $config_file --name-only --list
00652369
SB
2159}
2160
e0d10e1c 2161_git_config ()
5de40f59 2162{
da48616f 2163 case "$prev" in
72f75077 2164 branch.*.remote|branch.*.pushremote)
a31e6262 2165 __gitcomp_nl "$(__git_remotes)"
5de40f59
SP
2166 return
2167 ;;
2168 branch.*.merge)
15b4a163 2169 __git_complete_refs
5de40f59
SP
2170 return
2171 ;;
a05490ed 2172 branch.*.rebase)
17c4ddbb 2173 __gitcomp "false true preserve interactive"
a05490ed
RR
2174 return
2175 ;;
7e6a0cc4
RR
2176 remote.pushdefault)
2177 __gitcomp_nl "$(__git_remotes)"
2178 return
2179 ;;
5de40f59 2180 remote.*.fetch)
da48616f 2181 local remote="${prev#remote.}"
5de40f59 2182 remote="${remote%.fetch}"
d51a8ecd 2183 if [ -z "$cur" ]; then
73704451 2184 __gitcomp_nl "refs/heads/" "" "" ""
d51a8ecd
SG
2185 return
2186 fi
a31e6262 2187 __gitcomp_nl "$(__git_refs_remotes "$remote")"
5de40f59
SP
2188 return
2189 ;;
2190 remote.*.push)
da48616f 2191 local remote="${prev#remote.}"
5de40f59 2192 remote="${remote%.push}"
3ba04201 2193 __gitcomp_nl "$(__git for-each-ref \
1cd23e9e 2194 --format='%(refname):%(refname)' refs/heads)"
78d4d6a2
SP
2195 return
2196 ;;
2197 pull.twohead|pull.octopus)
eaa4e6ee
JN
2198 __git_compute_merge_strategies
2199 __gitcomp "$__git_merge_strategies"
78d4d6a2
SP
2200 return
2201 ;;
6123d719
MH
2202 color.branch|color.diff|color.interactive|\
2203 color.showbranch|color.status|color.ui)
78d4d6a2
SP
2204 __gitcomp "always never auto"
2205 return
2206 ;;
901d615c
MK
2207 color.pager)
2208 __gitcomp "false true"
2209 return
2210 ;;
78d4d6a2
SP
2211 color.*.*)
2212 __gitcomp "
98171a07 2213 normal black red green yellow blue magenta cyan white
78d4d6a2
SP
2214 bold dim ul blink reverse
2215 "
5de40f59
SP
2216 return
2217 ;;
2651baae
RR
2218 diff.submodule)
2219 __gitcomp "log short"
2220 return
2221 ;;
9b82d63b
SB
2222 help.format)
2223 __gitcomp "man info web html"
2224 return
2225 ;;
672c68cb
SB
2226 log.date)
2227 __gitcomp "$__git_log_date_formats"
2228 return
2229 ;;
ae616de6
SB
2230 sendemail.aliasesfiletype)
2231 __gitcomp "mutt mailrc pine elm gnus"
2232 return
2233 ;;
2234 sendemail.confirm)
2235 __gitcomp "$__git_send_email_confirm_options"
2236 return
2237 ;;
2238 sendemail.suppresscc)
2239 __gitcomp "$__git_send_email_suppresscc_options"
2240 return
2241 ;;
8d814084
PB
2242 sendemail.transferencoding)
2243 __gitcomp "7bit 8bit quoted-printable base64"
2244 return
2245 ;;
00652369 2246 --get|--get-all|--unset|--unset-all)
a31e6262 2247 __gitcomp_nl "$(__git_config_get_set_variables)"
00652369
SB
2248 return
2249 ;;
5de40f59 2250 *.*)
5de40f59
SP
2251 return
2252 ;;
2253 esac
2254 case "$cur" in
2255 --*)
78d4d6a2 2256 __gitcomp "
66c0786c 2257 --system --global --local --file=
12977705 2258 --list --replace-all
5de40f59 2259 --get --get-all --get-regexp
1b71eb35 2260 --add --unset --unset-all
12977705 2261 --remove-section --rename-section
578625fa 2262 --name-only
78d4d6a2 2263 "
5de40f59
SP
2264 return
2265 ;;
2266 branch.*.*)
9244d69b 2267 local pfx="${cur%.*}." cur_="${cur##*.}"
72f75077 2268 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
5de40f59
SP
2269 return
2270 ;;
2271 branch.*)
9244d69b 2272 local pfx="${cur%.*}." cur_="${cur#*.}"
227307a6 2273 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
422553df 2274 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
5de40f59
SP
2275 return
2276 ;;
0aa62fd0 2277 guitool.*.*)
9244d69b 2278 local pfx="${cur%.*}." cur_="${cur##*.}"
0aa62fd0
SB
2279 __gitcomp "
2280 argprompt cmd confirm needsfile noconsole norescan
2281 prompt revprompt revunmerged title
9244d69b 2282 " "$pfx" "$cur_"
0aa62fd0
SB
2283 return
2284 ;;
2285 difftool.*.*)
9244d69b
SG
2286 local pfx="${cur%.*}." cur_="${cur##*.}"
2287 __gitcomp "cmd path" "$pfx" "$cur_"
0aa62fd0
SB
2288 return
2289 ;;
2290 man.*.*)
9244d69b
SG
2291 local pfx="${cur%.*}." cur_="${cur##*.}"
2292 __gitcomp "cmd path" "$pfx" "$cur_"
0aa62fd0
SB
2293 return
2294 ;;
2295 mergetool.*.*)
9244d69b
SG
2296 local pfx="${cur%.*}." cur_="${cur##*.}"
2297 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
0aa62fd0
SB
2298 return
2299 ;;
2300 pager.*)
9244d69b 2301 local pfx="${cur%.*}." cur_="${cur#*.}"
eaa4e6ee 2302 __git_compute_all_commands
a31e6262 2303 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
0aa62fd0
SB
2304 return
2305 ;;
5de40f59 2306 remote.*.*)
9244d69b 2307 local pfx="${cur%.*}." cur_="${cur##*.}"
12977705 2308 __gitcomp "
98171a07 2309 url proxy fetch push mirror skipDefaultUpdate
6fac1b83 2310 receivepack uploadpack tagopt pushurl
9244d69b 2311 " "$pfx" "$cur_"
5de40f59
SP
2312 return
2313 ;;
2314 remote.*)
9244d69b 2315 local pfx="${cur%.*}." cur_="${cur#*.}"
a31e6262 2316 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
c39a2f11 2317 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
5de40f59
SP
2318 return
2319 ;;
0aa62fd0 2320 url.*.*)
9244d69b
SG
2321 local pfx="${cur%.*}." cur_="${cur##*.}"
2322 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
0aa62fd0
SB
2323 return
2324 ;;
5de40f59 2325 esac
78d4d6a2 2326 __gitcomp "
6068ac88
MZ
2327 add.ignoreErrors
2328 advice.commitBeforeMerge
2329 advice.detachedHead
2330 advice.implicitIdentity
2331 advice.pushNonFastForward
2332 advice.resolveConflict
2333 advice.statusHints
226b343c 2334 alias.
6068ac88 2335 am.keepcr
86c91f91 2336 apply.ignorewhitespace
5de40f59 2337 apply.whitespace
98171a07
LM
2338 branch.autosetupmerge
2339 branch.autosetuprebase
6068ac88 2340 browser.
2122591b 2341 clean.requireForce
78d4d6a2
SP
2342 color.branch
2343 color.branch.current
2344 color.branch.local
78d4d6a2 2345 color.branch.plain
025a1929 2346 color.branch.remote
6068ac88
MZ
2347 color.decorate.HEAD
2348 color.decorate.branch
2349 color.decorate.remoteBranch
2350 color.decorate.stash
2351 color.decorate.tag
a159ca0c 2352 color.diff
025a1929 2353 color.diff.commit
78d4d6a2 2354 color.diff.frag
6068ac88 2355 color.diff.func
025a1929 2356 color.diff.meta
78d4d6a2 2357 color.diff.new
025a1929
LM
2358 color.diff.old
2359 color.diff.plain
78d4d6a2 2360 color.diff.whitespace
226b343c 2361 color.grep
6068ac88
MZ
2362 color.grep.context
2363 color.grep.filename
2364 color.grep.function
2365 color.grep.linenumber
226b343c 2366 color.grep.match
6068ac88
MZ
2367 color.grep.selected
2368 color.grep.separator
98171a07 2369 color.interactive
6068ac88 2370 color.interactive.error
98171a07
LM
2371 color.interactive.header
2372 color.interactive.help
2373 color.interactive.prompt
a159ca0c 2374 color.pager
6123d719 2375 color.showbranch
a159ca0c 2376 color.status
78d4d6a2
SP
2377 color.status.added
2378 color.status.changed
025a1929 2379 color.status.header
98171a07 2380 color.status.nobranch
0d6accc0 2381 color.status.unmerged
78d4d6a2 2382 color.status.untracked
98171a07
LM
2383 color.status.updated
2384 color.ui
6068ac88 2385 commit.status
98171a07 2386 commit.template
cdb791f6 2387 core.abbrev
6068ac88
MZ
2388 core.askpass
2389 core.attributesfile
98171a07
LM
2390 core.autocrlf
2391 core.bare
6068ac88 2392 core.bigFileThreshold
025a1929 2393 core.compression
226b343c 2394 core.createObject
98171a07
LM
2395 core.deltaBaseCacheLimit
2396 core.editor
6068ac88 2397 core.eol
98171a07 2398 core.excludesfile
025a1929 2399 core.fileMode
98171a07 2400 core.fsyncobjectfiles
025a1929
LM
2401 core.gitProxy
2402 core.ignoreStat
6068ac88 2403 core.ignorecase
025a1929
LM
2404 core.logAllRefUpdates
2405 core.loosecompression
6068ac88 2406 core.notesRef
025a1929
LM
2407 core.packedGitLimit
2408 core.packedGitWindowSize
98171a07 2409 core.pager
025a1929 2410 core.preferSymlinkRefs
98171a07
LM
2411 core.preloadindex
2412 core.quotepath
025a1929 2413 core.repositoryFormatVersion
98171a07 2414 core.safecrlf
025a1929 2415 core.sharedRepository
6068ac88 2416 core.sparseCheckout
98171a07
LM
2417 core.symlinks
2418 core.trustctime
435ec090 2419 core.untrackedCache
025a1929 2420 core.warnAmbiguousRefs
98171a07
LM
2421 core.whitespace
2422 core.worktree
2423 diff.autorefreshindex
2424 diff.external
6068ac88 2425 diff.ignoreSubmodules
98171a07 2426 diff.mnemonicprefix
6068ac88 2427 diff.noprefix
78d4d6a2
SP
2428 diff.renameLimit
2429 diff.renames
de7c201a 2430 diff.statGraphWidth
2651baae 2431 diff.submodule
226b343c
SB
2432 diff.suppressBlankEmpty
2433 diff.tool
2434 diff.wordRegex
07ab4dec 2435 diff.algorithm
0aa62fd0 2436 difftool.
226b343c 2437 difftool.prompt
6068ac88 2438 fetch.recurseSubmodules
78d4d6a2 2439 fetch.unpackLimit
226b343c
SB
2440 format.attach
2441 format.cc
de06c13a 2442 format.coverLetter
6bc6b6c0 2443 format.from
78d4d6a2 2444 format.headers
98171a07
LM
2445 format.numbered
2446 format.pretty
d8e1e5df 2447 format.signature
226b343c
SB
2448 format.signoff
2449 format.subjectprefix
98171a07 2450 format.suffix
226b343c 2451 format.thread
6068ac88
MZ
2452 format.to
2453 gc.
98171a07
LM
2454 gc.aggressiveWindow
2455 gc.auto
2456 gc.autopacklimit
12977705 2457 gc.packrefs
98171a07 2458 gc.pruneexpire
78d4d6a2
SP
2459 gc.reflogexpire
2460 gc.reflogexpireunreachable
2461 gc.rerereresolved
2462 gc.rerereunresolved
025a1929 2463 gitcvs.allbinary
226b343c 2464 gitcvs.commitmsgannotation
98171a07 2465 gitcvs.dbTableNamePrefix
025a1929
LM
2466 gitcvs.dbdriver
2467 gitcvs.dbname
2468 gitcvs.dbpass
025a1929
LM
2469 gitcvs.dbuser
2470 gitcvs.enabled
2471 gitcvs.logfile
98171a07 2472 gitcvs.usecrlfattr
0aa62fd0 2473 guitool.
98171a07
LM
2474 gui.blamehistoryctx
2475 gui.commitmsgwidth
2476 gui.copyblamethreshold
2477 gui.diffcontext
2478 gui.encoding
2479 gui.fastcopyblame
2480 gui.matchtrackingbranch
2481 gui.newbranchtemplate
2482 gui.pruneduringfetch
2483 gui.spellingdictionary
2484 gui.trustmtime
2485 help.autocorrect
2486 help.browser
2487 help.format
78d4d6a2
SP
2488 http.lowSpeedLimit
2489 http.lowSpeedTime
025a1929 2490 http.maxRequests
6068ac88 2491 http.minSessions
5de40f59 2492 http.noEPSV
6068ac88 2493 http.postBuffer
98171a07 2494 http.proxy
f6f2a9e4 2495 http.sslCipherList
01861cb7 2496 http.sslVersion
025a1929
LM
2497 http.sslCAInfo
2498 http.sslCAPath
2499 http.sslCert
6068ac88 2500 http.sslCertPasswordProtected
025a1929
LM
2501 http.sslKey
2502 http.sslVerify
6068ac88 2503 http.useragent
78d4d6a2
SP
2504 i18n.commitEncoding
2505 i18n.logOutputEncoding
6068ac88 2506 imap.authMethod
226b343c
SB
2507 imap.folder
2508 imap.host
2509 imap.pass
2510 imap.port
2511 imap.preformattedHTML
2512 imap.sslverify
2513 imap.tunnel
2514 imap.user
6068ac88 2515 init.templatedir
98171a07
LM
2516 instaweb.browser
2517 instaweb.httpd
2518 instaweb.local
2519 instaweb.modulepath
2520 instaweb.port
226b343c 2521 interactive.singlekey
98171a07 2522 log.date
6068ac88 2523 log.decorate
78d4d6a2 2524 log.showroot
226b343c 2525 mailmap.file
0aa62fd0 2526 man.
98171a07 2527 man.viewer
6068ac88 2528 merge.
98171a07
LM
2529 merge.conflictstyle
2530 merge.log
2531 merge.renameLimit
6068ac88 2532 merge.renormalize
98171a07 2533 merge.stat
025a1929 2534 merge.tool
78d4d6a2 2535 merge.verbosity
0aa62fd0 2536 mergetool.
98171a07 2537 mergetool.keepBackup
6068ac88 2538 mergetool.keepTemporaries
226b343c 2539 mergetool.prompt
6068ac88
MZ
2540 notes.displayRef
2541 notes.rewrite.
2542 notes.rewrite.amend
2543 notes.rewrite.rebase
2544 notes.rewriteMode
2545 notes.rewriteRef
47e98eec 2546 pack.compression
47e98eec 2547 pack.deltaCacheLimit
025a1929
LM
2548 pack.deltaCacheSize
2549 pack.depth
98171a07
LM
2550 pack.indexVersion
2551 pack.packSizeLimit
2552 pack.threads
025a1929
LM
2553 pack.window
2554 pack.windowMemory
0aa62fd0 2555 pager.
6068ac88 2556 pretty.
78d4d6a2
SP
2557 pull.octopus
2558 pull.twohead
226b343c 2559 push.default
a8bc269f 2560 push.followTags
6068ac88 2561 rebase.autosquash
226b343c 2562 rebase.stat
6068ac88 2563 receive.autogc
98171a07 2564 receive.denyCurrentBranch
6068ac88 2565 receive.denyDeleteCurrent
98171a07 2566 receive.denyDeletes
025a1929 2567 receive.denyNonFastForwards
98171a07 2568 receive.fsckObjects
025a1929 2569 receive.unpackLimit
6068ac88 2570 receive.updateserverinfo
7e6a0cc4 2571 remote.pushdefault
6068ac88 2572 remotes.
98171a07
LM
2573 repack.usedeltabaseoffset
2574 rerere.autoupdate
2575 rerere.enabled
6068ac88 2576 sendemail.
226b343c 2577 sendemail.aliasesfile
6068ac88 2578 sendemail.aliasfiletype
226b343c
SB
2579 sendemail.bcc
2580 sendemail.cc
2581 sendemail.cccmd
2582 sendemail.chainreplyto
2583 sendemail.confirm
2584 sendemail.envelopesender
6068ac88
MZ
2585 sendemail.from
2586 sendemail.identity
226b343c
SB
2587 sendemail.multiedit
2588 sendemail.signedoffbycc
6068ac88 2589 sendemail.smtpdomain
226b343c
SB
2590 sendemail.smtpencryption
2591 sendemail.smtppass
2592 sendemail.smtpserver
6068ac88 2593 sendemail.smtpserveroption
226b343c
SB
2594 sendemail.smtpserverport
2595 sendemail.smtpuser
2596 sendemail.suppresscc
2597 sendemail.suppressfrom
2598 sendemail.thread
2599 sendemail.to
2600 sendemail.validate
78d4d6a2 2601 showbranch.default
98171a07
LM
2602 status.relativePaths
2603 status.showUntrackedFiles
6068ac88
MZ
2604 status.submodulesummary
2605 submodule.
78d4d6a2
SP
2606 tar.umask
2607 transfer.unpackLimit
0aa62fd0 2608 url.
78d4d6a2 2609 user.email
025a1929 2610 user.name
78d4d6a2 2611 user.signingkey
98171a07 2612 web.browser
5de40f59 2613 branch. remote.
78d4d6a2 2614 "
5de40f59
SP
2615}
2616
88293c67
SP
2617_git_remote ()
2618{
cac84960
CW
2619 local subcommands="
2620 add rename remove set-head set-branches
2621 get-url set-url show prune update
2622 "
918c03c2 2623 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3ff1320d 2624 if [ -z "$subcommand" ]; then
cac84960
CW
2625 case "$cur" in
2626 --*)
2627 __gitcomp "--verbose"
2628 ;;
2629 *)
2630 __gitcomp "$subcommands"
2631 ;;
2632 esac
88293c67
SP
2633 return
2634 fi
2635
cac84960
CW
2636 case "$subcommand,$cur" in
2637 add,--*)
2638 __gitcomp "--track --master --fetch --tags --no-tags --mirror="
88293c67 2639 ;;
cac84960
CW
2640 add,*)
2641 ;;
2642 set-head,--*)
2643 __gitcomp "--auto --delete"
2644 ;;
2645 set-branches,--*)
2646 __gitcomp "--add"
88293c67 2647 ;;
cac84960 2648 set-head,*|set-branches,*)
f1c6ffe6
PJ
2649 __git_complete_remote_or_refspec
2650 ;;
cac84960
CW
2651 update,--*)
2652 __gitcomp "--prune"
2653 ;;
2654 update,*)
e8f9e428 2655 __gitcomp "$(__git_get_config_variables "remotes")"
fb72759b 2656 ;;
cac84960
CW
2657 set-url,--*)
2658 __gitcomp "--push --add --delete"
2659 ;;
2660 get-url,--*)
2661 __gitcomp "--push --all"
2662 ;;
2663 prune,--*)
2664 __gitcomp "--dry-run"
2665 ;;
88293c67 2666 *)
cac84960 2667 __gitcomp_nl "$(__git_remotes)"
88293c67
SP
2668 ;;
2669 esac
2670}
2671
e1c1a067
BG
2672_git_replace ()
2673{
188fba11
CW
2674 case "$cur" in
2675 --*)
2676 __gitcomp "--edit --graft --format= --list --delete"
2677 return
2678 ;;
2679 esac
15b4a163 2680 __git_complete_refs
e1c1a067
BG
2681}
2682
e24a256b
CW
2683_git_rerere ()
2684{
2685 local subcommands="clear forget diff remaining status gc"
2686 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2687 if test -z "$subcommand"
2688 then
2689 __gitcomp "$subcommands"
2690 return
2691 fi
2692}
2693
67e78c3b
SP
2694_git_reset ()
2695{
d773c631
SG
2696 __git_has_doubledash && return
2697
b3391775
SP
2698 case "$cur" in
2699 --*)
f483a0aa 2700 __gitcomp "--merge --mixed --hard --soft --patch --keep"
b3391775
SP
2701 return
2702 ;;
2703 esac
15b4a163 2704 __git_complete_refs
67e78c3b
SP
2705}
2706
a6c2be24
LM
2707_git_revert ()
2708{
fad9484f
SG
2709 __git_find_repo_path
2710 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
956352b6
TB
2711 __gitcomp "--continue --quit --abort"
2712 return
2713 fi
a6c2be24
LM
2714 case "$cur" in
2715 --*)
f483a0aa
CW
2716 __gitcomp "
2717 --edit --mainline --no-edit --no-commit --signoff
2718 --strategy= --strategy-option=
2719 "
a6c2be24
LM
2720 return
2721 ;;
2722 esac
15b4a163 2723 __git_complete_refs
a6c2be24
LM
2724}
2725
08c701d4
LM
2726_git_rm ()
2727{
08c701d4
LM
2728 case "$cur" in
2729 --*)
2730 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2731 return
2732 ;;
2733 esac
fea16b47
MP
2734
2735 __git_complete_index_file "--cached"
08c701d4
LM
2736}
2737
1fd6bec9
SP
2738_git_shortlog ()
2739{
d773c631
SG
2740 __git_has_doubledash && return
2741
1fd6bec9
SP
2742 case "$cur" in
2743 --*)
2744 __gitcomp "
a393777e
TR
2745 $__git_log_common_options
2746 $__git_log_shortlog_options
f483a0aa 2747 --numbered --summary --email
1fd6bec9
SP
2748 "
2749 return
2750 ;;
2751 esac
2752 __git_complete_revlist
2753}
2754
90131924
SP
2755_git_show ()
2756{
41d8cf7d
MH
2757 __git_has_doubledash && return
2758
90131924 2759 case "$cur" in
e67d71e5 2760 --pretty=*|--format=*)
c3898111 2761 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
e67d71e5 2762 " "" "${cur#*=}"
72de29c2
TL
2763 return
2764 ;;
07924d4d
MP
2765 --diff-algorithm=*)
2766 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2767 return
2768 ;;
ac76fd54
JK
2769 --submodule=*)
2770 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2771 return
2772 ;;
90131924 2773 --*)
076c3237 2774 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2ca0b197 2775 --show-signature
20bf7292
TR
2776 $__git_diff_common_options
2777 "
90131924
SP
2778 return
2779 ;;
2780 esac
5269f7f8 2781 __git_complete_revlist_file
90131924
SP
2782}
2783
2ca880fe
TR
2784_git_show_branch ()
2785{
2ca880fe
TR
2786 case "$cur" in
2787 --*)
2788 __gitcomp "
f7c2e1a0 2789 --all --remotes --topo-order --date-order --current --more=
2ca880fe 2790 --list --independent --merge-base --no-name
6123d719 2791 --color --no-color
076c3237 2792 --sha1-name --sparse --topics --reflog
2ca880fe
TR
2793 "
2794 return
2795 ;;
2796 esac
2797 __git_complete_revlist
2798}
2799
7fd53fce
JH
2800_git_stash ()
2801{
d7d4ca87 2802 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
95d43780 2803 local subcommands='save list show apply clear drop pop create branch'
918c03c2 2804 local subcommand="$(__git_find_on_cmdline "$subcommands")"
7bedebca 2805 if [ -z "$subcommand" ]; then
59d5eeee
SG
2806 case "$cur" in
2807 --*)
2808 __gitcomp "$save_opts"
2809 ;;
2810 *)
2811 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2812 __gitcomp "$subcommands"
59d5eeee
SG
2813 fi
2814 ;;
2815 esac
7bedebca 2816 else
7bedebca
SG
2817 case "$subcommand,$cur" in
2818 save,--*)
59d5eeee 2819 __gitcomp "$save_opts"
7bedebca 2820 ;;
8513c54b 2821 apply,--*|pop,--*)
59d5eeee 2822 __gitcomp "--index --quiet"
95d43780 2823 ;;
d7d4ca87
PW
2824 drop,--*)
2825 __gitcomp "--quiet"
95d43780 2826 ;;
d7d4ca87
PW
2827 show,--*|branch,--*)
2828 ;;
2829 branch,*)
59305aee 2830 if [ $cword -eq 3 ]; then
15b4a163 2831 __git_complete_refs
d7d4ca87 2832 else
1cd23e9e 2833 __gitcomp_nl "$(__git stash list \
d7d4ca87
PW
2834 | sed -n -e 's/:.*//p')"
2835 fi
2836 ;;
2837 show,*|apply,*|drop,*|pop,*)
1cd23e9e 2838 __gitcomp_nl "$(__git stash list \
95d43780
LM
2839 | sed -n -e 's/:.*//p')"
2840 ;;
7bedebca 2841 *)
7bedebca
SG
2842 ;;
2843 esac
3ff1320d 2844 fi
7fd53fce
JH
2845}
2846
be86f7a0
SP
2847_git_submodule ()
2848{
d773c631
SG
2849 __git_has_doubledash && return
2850
cf419828 2851 local subcommands="add status init deinit update summary foreach sync"
65d5a1e0
CW
2852 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2853 if [ -z "$subcommand" ]; then
be86f7a0
SP
2854 case "$cur" in
2855 --*)
65d5a1e0 2856 __gitcomp "--quiet"
be86f7a0
SP
2857 ;;
2858 *)
3ff1320d 2859 __gitcomp "$subcommands"
be86f7a0
SP
2860 ;;
2861 esac
2862 return
2863 fi
65d5a1e0
CW
2864
2865 case "$subcommand,$cur" in
2866 add,--*)
2867 __gitcomp "--branch --force --name --reference --depth"
2868 ;;
2869 status,--*)
2870 __gitcomp "--cached --recursive"
2871 ;;
2872 deinit,--*)
2873 __gitcomp "--force --all"
2874 ;;
2875 update,--*)
2876 __gitcomp "
2877 --init --remote --no-fetch
2878 --recommend-shallow --no-recommend-shallow
2879 --force --rebase --merge --reference --depth --recursive --jobs
2880 "
2881 ;;
2882 summary,--*)
2883 __gitcomp "--cached --files --summary-limit"
2884 ;;
2885 foreach,--*|sync,--*)
2886 __gitcomp "--recursive"
2887 ;;
2888 *)
2889 ;;
2890 esac
be86f7a0
SP
2891}
2892
47f6ee28
SG
2893_git_svn ()
2894{
2895 local subcommands="
2896 init fetch clone rebase dcommit log find-rev
2897 set-tree commit-diff info create-ignore propget
4a5856cb 2898 proplist show-ignore show-externals branch tag blame
c18d5d82 2899 migrate mkdirs reset gc
47f6ee28 2900 "
918c03c2 2901 local subcommand="$(__git_find_on_cmdline "$subcommands")"
47f6ee28
SG
2902 if [ -z "$subcommand" ]; then
2903 __gitcomp "$subcommands"
2904 else
2905 local remote_opts="--username= --config-dir= --no-auth-cache"
2906 local fc_opts="
2907 --follow-parent --authors-file= --repack=
2908 --no-metadata --use-svm-props --use-svnsync-props
2909 --log-window-size= --no-checkout --quiet
4a5856cb 2910 --repack-flags --use-log-author --localtime
2cbad176 2911 --add-author-from
a7b10230 2912 --ignore-paths= --include-paths= $remote_opts
47f6ee28
SG
2913 "
2914 local init_opts="
2915 --template= --shared= --trunk= --tags=
2916 --branches= --stdlayout --minimize-url
2917 --no-metadata --use-svm-props --use-svnsync-props
2cbad176 2918 --rewrite-root= --prefix= $remote_opts
47f6ee28
SG
2919 "
2920 local cmt_opts="
2921 --edit --rmdir --find-copies-harder --copy-similarity=
2922 "
2923
47f6ee28
SG
2924 case "$subcommand,$cur" in
2925 fetch,--*)
2926 __gitcomp "--revision= --fetch-all $fc_opts"
2927 ;;
2928 clone,--*)
2929 __gitcomp "--revision= $fc_opts $init_opts"
2930 ;;
2931 init,--*)
2932 __gitcomp "$init_opts"
2933 ;;
2934 dcommit,--*)
2935 __gitcomp "
2936 --merge --strategy= --verbose --dry-run
4a5856cb 2937 --fetch-all --no-rebase --commit-url
7b151f49 2938 --revision --interactive $cmt_opts $fc_opts
47f6ee28
SG
2939 "
2940 ;;
2941 set-tree,--*)
2942 __gitcomp "--stdin $cmt_opts $fc_opts"
2943 ;;
2944 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
c18d5d82 2945 show-externals,--*|mkdirs,--*)
47f6ee28
SG
2946 __gitcomp "--revision="
2947 ;;
2948 log,--*)
2949 __gitcomp "
2950 --limit= --revision= --verbose --incremental
2951 --oneline --show-commit --non-recursive
4a5856cb 2952 --authors-file= --color
47f6ee28
SG
2953 "
2954 ;;
2955 rebase,--*)
2956 __gitcomp "
2957 --merge --verbose --strategy= --local
4a5856cb 2958 --fetch-all --dry-run $fc_opts
47f6ee28
SG
2959 "
2960 ;;
2961 commit-diff,--*)
2962 __gitcomp "--message= --file= --revision= $cmt_opts"
2963 ;;
2964 info,--*)
2965 __gitcomp "--url"
2966 ;;
4a5856cb
SG
2967 branch,--*)
2968 __gitcomp "--dry-run --message --tag"
2969 ;;
2970 tag,--*)
2971 __gitcomp "--dry-run --message"
2972 ;;
2973 blame,--*)
2974 __gitcomp "--git-format"
2975 ;;
2976 migrate,--*)
2977 __gitcomp "
2978 --config-dir= --ignore-paths= --minimize
2979 --no-auth-cache --username=
2980 "
2981 ;;
c18d5d82
RZ
2982 reset,--*)
2983 __gitcomp "--revision= --parent"
2984 ;;
47f6ee28 2985 *)
47f6ee28
SG
2986 ;;
2987 esac
2988 fi
2989}
2990
88e21dc7
SP
2991_git_tag ()
2992{
2993 local i c=1 f=0
da48616f
PD
2994 while [ $c -lt $cword ]; do
2995 i="${words[c]}"
88e21dc7
SP
2996 case "$i" in
2997 -d|-v)
227307a6 2998 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
88e21dc7
SP
2999 return
3000 ;;
3001 -f)
3002 f=1
3003 ;;
3004 esac
6e8c755f 3005 ((c++))
88e21dc7
SP
3006 done
3007
da48616f 3008 case "$prev" in
88e21dc7 3009 -m|-F)
88e21dc7 3010 ;;
8d8163f3 3011 -*|tag)
88e21dc7 3012 if [ $f = 1 ]; then
227307a6 3013 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
88e21dc7
SP
3014 fi
3015 ;;
3016 *)
15b4a163 3017 __git_complete_refs
88e21dc7
SP
3018 ;;
3019 esac
85ed2f32
RT
3020
3021 case "$cur" in
3022 --*)
3023 __gitcomp "
3024 --list --delete --verify --annotate --message --file
f483a0aa 3025 --sign --cleanup --local-user --force --column --sort=
ac3f5a34 3026 --contains --no-contains --points-at --merged --no-merged --create-reflog
85ed2f32
RT
3027 "
3028 ;;
3029 esac
88e21dc7
SP
3030}
3031
424cce83
SG
3032_git_whatchanged ()
3033{
3034 _git_log
3035}
3036
b462c024
NTND
3037_git_worktree ()
3038{
6d308627 3039 local subcommands="add list lock prune unlock"
b462c024
NTND
3040 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3041 if [ -z "$subcommand" ]; then
3042 __gitcomp "$subcommands"
3043 else
3044 case "$subcommand,$cur" in
3045 add,--*)
3046 __gitcomp "--detach"
3047 ;;
3048 list,--*)
3049 __gitcomp "--porcelain"
3050 ;;
58142c09
NTND
3051 lock,--*)
3052 __gitcomp "--reason"
3053 ;;
b462c024
NTND
3054 prune,--*)
3055 __gitcomp "--dry-run --expire --verbose"
3056 ;;
3057 *)
3058 ;;
3059 esac
3060 fi
3061}
3062
93b291e0 3063__git_main ()
690d8824 3064{
beb6ee71 3065 local i c=1 command __git_dir __git_repo_path
80ac0744 3066 local __git_C_args C_args_count=0
873537fa 3067
da48616f
PD
3068 while [ $c -lt $cword ]; do
3069 i="${words[c]}"
873537fa
SP
3070 case "$i" in
3071 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
776009d1 3072 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
873537fa 3073 --bare) __git_dir="." ;;
1eb7e2f8 3074 --help) command="help"; break ;;
776009d1 3075 -c|--work-tree|--namespace) ((c++)) ;;
80ac0744
SG
3076 -C) __git_C_args[C_args_count++]=-C
3077 ((c++))
3078 __git_C_args[C_args_count++]="${words[c]}"
3079 ;;
911d5da6 3080 -*) ;;
873537fa
SP
3081 *) command="$i"; break ;;
3082 esac
6e8c755f 3083 ((c++))