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