]> git.ipfire.org Git - thirdparty/git.git/blame - contrib/completion/git-completion.bash
completion: document __gitcomp()
[thirdparty/git.git] / contrib / completion / git-completion.bash
CommitLineData
a42577d4 1#!bash
690d8824 2#
b5a49471 3# bash/zsh completion support for core Git.
690d8824 4#
c70680ce 5# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
690d8824 6# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
c70680ce 7# Distributed under the GNU General Public License, version 2.0.
690d8824
JH
8#
9# The contained completion routines provide support for completing:
10#
11# *) local and remote branch names
12# *) local and remote tag names
13# *) .git/remotes file names
14# *) git 'subcommands'
15# *) tree paths within 'ref:path/to/file' expressions
c70680ce 16# *) common --long-options
690d8824
JH
17#
18# To use these routines:
19#
20# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
b5a49471 21# 2) Add the following line to your .bashrc/.zshrc:
06f44c3c
ML
22# source ~/.git-completion.sh
23#
eaa4e6ee 24# 3) Consider changing your PS1 to also show the current branch:
b5a49471
MSO
25# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
26# ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
d3d717a4
SP
27#
28# The argument to __git_ps1 will be displayed only if you
29# are currently in a git repository. The %s token will be
30# the name of the current branch.
31#
a9ee90d7
TP
32# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
33# value, unstaged (*) and staged (+) changes will be shown next
34# to the branch name. You can configure this per-repository
35# with the bash.showDirtyState variable, which defaults to true
36# once GIT_PS1_SHOWDIRTYSTATE is enabled.
738a94a9 37#
2414b45c
DT
38# You can also see if currently something is stashed, by setting
39# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
40# then a '$' will be shown next to the branch name.
41#
397f7c63
DT
42# If you would like to see if there're untracked files, then you can
43# set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
44# untracked files, then a '%' will be shown next to the branch name.
45#
6d158cba
AS
46# If you would like to see the difference between HEAD and its
47# upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates
48# you are behind, ">" indicates you are ahead, and "<>"
49# indicates you have diverged. You can further control
50# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
51# list of values:
52# verbose show number of commits ahead/behind (+/-) upstream
53# legacy don't use the '--count' option available in recent
54# versions of git-rev-list
55# git always compare HEAD to @{upstream}
56# svn always compare HEAD to your SVN upstream
57# By default, __git_ps1 will compare HEAD to your SVN upstream
58# if it can find one, or @{upstream} otherwise. Once you have
59# set GIT_PS1_SHOWUPSTREAM, you can override it on a
60# per-repository basis by setting the bash.showUpstream config
61# variable.
62#
63#
c70680ce
SP
64# To submit patches:
65#
66# *) Read Documentation/SubmittingPatches
67# *) Send all patches to the current maintainer:
68#
69# "Shawn O. Pearce" <spearce@spearce.org>
70#
71# *) Always CC the Git mailing list:
72#
73# git@vger.kernel.org
74#
690d8824 75
b5a49471
MSO
76if [[ -n ${ZSH_VERSION-} ]]; then
77 autoload -U +X bashcompinit && bashcompinit
78fi
79
db8a9ff0
SP
80case "$COMP_WORDBREAKS" in
81*:*) : great ;;
82*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
83esac
84
a42577d4
TP
85# __gitdir accepts 0 or 1 arguments (i.e., location)
86# returns location of .git repo
873537fa
SP
87__gitdir ()
88{
25a31f81 89 if [ -z "${1-}" ]; then
5c9cc64a 90 if [ -n "${__git_dir-}" ]; then
67ffa114
SP
91 echo "$__git_dir"
92 elif [ -d .git ]; then
93 echo .git
94 else
95 git rev-parse --git-dir 2>/dev/null
96 fi
97 elif [ -d "$1/.git" ]; then
98 echo "$1/.git"
99 else
100 echo "$1"
101 fi
873537fa
SP
102}
103
6d158cba
AS
104# stores the divergence from upstream in $p
105# used by GIT_PS1_SHOWUPSTREAM
106__git_ps1_show_upstream ()
107{
108 local key value
109 local svn_remote=() svn_url_pattern count n
110 local upstream=git legacy="" verbose=""
111
112 # get some config options from git-config
113 while read key value; do
114 case "$key" in
115 bash.showupstream)
116 GIT_PS1_SHOWUPSTREAM="$value"
117 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
118 p=""
119 return
120 fi
121 ;;
122 svn-remote.*.url)
123 svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
124 svn_url_pattern+="\\|$value"
125 upstream=svn+git # default upstream is SVN if available, else git
126 ;;
127 esac
128 done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
129
130 # parse configuration values
131 for option in ${GIT_PS1_SHOWUPSTREAM}; do
132 case "$option" in
133 git|svn) upstream="$option" ;;
134 verbose) verbose=1 ;;
135 legacy) legacy=1 ;;
136 esac
137 done
138
139 # Find our upstream
140 case "$upstream" in
141 git) upstream="@{upstream}" ;;
142 svn*)
143 # get the upstream from the "git-svn-id: ..." in a commit message
144 # (git-svn uses essentially the same procedure internally)
145 local svn_upstream=($(git log --first-parent -1 \
06f44c3c 146 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
6d158cba
AS
147 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
148 svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
149 svn_upstream=${svn_upstream%@*}
06f44c3c
ML
150 local n_stop="${#svn_remote[@]}"
151 for ((n=1; n <= n_stop; ++n)); do
6d158cba
AS
152 svn_upstream=${svn_upstream#${svn_remote[$n]}}
153 done
154
155 if [[ -z "$svn_upstream" ]]; then
156 # default branch name for checkouts with no layout:
157 upstream=${GIT_SVN_ID:-git-svn}
158 else
159 upstream=${svn_upstream#/}
160 fi
161 elif [[ "svn+git" = "$upstream" ]]; then
162 upstream="@{upstream}"
163 fi
164 ;;
165 esac
166
167 # Find how many commits we are ahead/behind our upstream
168 if [[ -z "$legacy" ]]; then
169 count="$(git rev-list --count --left-right \
170 "$upstream"...HEAD 2>/dev/null)"
171 else
172 # produce equivalent output to --count for older versions of git
173 local commits
174 if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
175 then
176 local commit behind=0 ahead=0
177 for commit in $commits
178 do
179 case "$commit" in
180 "<"*) let ++behind
181 ;;
182 *) let ++ahead
183 ;;
184 esac
185 done
186 count="$behind $ahead"
187 else
188 count=""
189 fi
190 fi
191
192 # calculate the result
193 if [[ -z "$verbose" ]]; then
194 case "$count" in
195 "") # no upstream
196 p="" ;;
197 "0 0") # equal to upstream
198 p="=" ;;
199 "0 "*) # ahead of upstream
200 p=">" ;;
201 *" 0") # behind upstream
202 p="<" ;;
203 *) # diverged from upstream
204 p="<>" ;;
205 esac
206 else
207 case "$count" in
208 "") # no upstream
209 p="" ;;
210 "0 0") # equal to upstream
211 p=" u=" ;;
212 "0 "*) # ahead of upstream
213 p=" u+${count#0 }" ;;
214 *" 0") # behind upstream
215 p=" u-${count% 0}" ;;
216 *) # diverged from upstream
217 p=" u+${count#* }-${count% *}" ;;
218 esac
219 fi
220
221}
222
223
a42577d4
TP
224# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
225# returns text to add to bash PS1 prompt (includes branch name)
d3d717a4
SP
226__git_ps1 ()
227{
fa26a401 228 local g="$(__gitdir)"
e7520196 229 if [ -n "$g" ]; then
6c44b640
AS
230 local r=""
231 local b=""
d7107ca6 232 if [ -f "$g/rebase-merge/interactive" ]; then
e7520196 233 r="|REBASE-i"
28ed6e7b 234 b="$(cat "$g/rebase-merge/head-name")"
ad244d25 235 elif [ -d "$g/rebase-merge" ]; then
e7520196 236 r="|REBASE-m"
28ed6e7b 237 b="$(cat "$g/rebase-merge/head-name")"
e7520196 238 else
d7107ca6
JH
239 if [ -d "$g/rebase-apply" ]; then
240 if [ -f "$g/rebase-apply/rebasing" ]; then
241 r="|REBASE"
242 elif [ -f "$g/rebase-apply/applying" ]; then
243 r="|AM"
244 else
245 r="|AM/REBASE"
246 fi
247 elif [ -f "$g/MERGE_HEAD" ]; then
8763dbb1 248 r="|MERGING"
5b2af8ca
JS
249 elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
250 r="|CHERRY-PICKING"
d7107ca6 251 elif [ -f "$g/BISECT_LOG" ]; then
e7520196
RR
252 r="|BISECTING"
253 fi
ff790b6a
JH
254
255 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
dd42c2f0
JH
256
257 b="$(
258 case "${GIT_PS1_DESCRIBE_STYLE-}" in
259 (contains)
260 git describe --contains HEAD ;;
261 (branch)
262 git describe --contains --all HEAD ;;
263 (describe)
264 git describe HEAD ;;
265 (* | default)
bd40d252 266 git describe --tags --exact-match HEAD ;;
dd42c2f0
JH
267 esac 2>/dev/null)" ||
268
ff790b6a
JH
269 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
270 b="unknown"
ff790b6a
JH
271 b="($b)"
272 }
e7520196
RR
273 fi
274
6c44b640
AS
275 local w=""
276 local i=""
277 local s=""
278 local u=""
279 local c=""
6d158cba 280 local p=""
738a94a9 281
e5dd864a 282 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
8dfb17e1 283 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
ddb6d010
MSO
284 c="BARE:"
285 else
286 b="GIT_DIR!"
287 fi
e5dd864a
TP
288 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
289 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
290 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
cf6e7ba1 291 git diff --no-ext-diff --quiet --exit-code || w="*"
e5dd864a 292 if git rev-parse --quiet --verify HEAD >/dev/null; then
cf6e7ba1 293 git diff-index --cached --quiet HEAD -- || i="+"
e5dd864a
TP
294 else
295 i="#"
296 fi
738a94a9
TR
297 fi
298 fi
2414b45c
DT
299 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
300 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
301 fi
397f7c63
DT
302
303 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
304 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
305 u="%"
306 fi
307 fi
6d158cba
AS
308
309 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
310 __git_ps1_show_upstream
311 fi
738a94a9
TR
312 fi
313
4cc47382 314 local f="$w$i$s$u"
6d158cba 315 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
d3d717a4
SP
316 fi
317}
318
a42577d4 319# __gitcomp_1 requires 2 arguments
ab02dfe5
SP
320__gitcomp_1 ()
321{
322 local c IFS=' '$'\t'$'\n'
323 for c in $1; do
324 case "$c$2" in
325 --*=*) printf %s$'\n' "$c$2" ;;
326 *.) printf %s$'\n' "$c$2" ;;
327 *) printf %s$'\n' "$c$2 " ;;
328 esac
329 done
330}
331
dbda3b10
JN
332# The following function is based on code from:
333#
334# bash_completion - programmable completion functions for bash 3.2+
335#
336# Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
337# © 2009-2010, Bash Completion Maintainers
338# <bash-completion-devel@lists.alioth.debian.org>
339#
340# This program is free software; you can redistribute it and/or modify
341# it under the terms of the GNU General Public License as published by
342# the Free Software Foundation; either version 2, or (at your option)
343# any later version.
344#
345# This program is distributed in the hope that it will be useful,
346# but WITHOUT ANY WARRANTY; without even the implied warranty of
347# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
348# GNU General Public License for more details.
349#
350# You should have received a copy of the GNU General Public License
351# along with this program; if not, write to the Free Software Foundation,
352# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
353#
354# The latest version of this software can be obtained here:
355#
356# http://bash-completion.alioth.debian.org/
357#
358# RELEASE: 2.x
359
360# This function can be used to access a tokenized list of words
361# on the command line:
362#
363# __git_reassemble_comp_words_by_ref '=:'
364# if test "${words_[cword_-1]}" = -w
365# then
366# ...
367# fi
368#
369# The argument should be a collection of characters from the list of
370# word completion separators (COMP_WORDBREAKS) to treat as ordinary
371# characters.
372#
373# This is roughly equivalent to going back in time and setting
374# COMP_WORDBREAKS to exclude those characters. The intent is to
375# make option types like --date=<type> and <rev>:<path> easy to
376# recognize by treating each shell word as a single token.
377#
378# It is best not to set COMP_WORDBREAKS directly because the value is
379# shared with other completion scripts. By the time the completion
380# function gets called, COMP_WORDS has already been populated so local
381# changes to COMP_WORDBREAKS have no effect.
382#
383# Output: words_, cword_, cur_.
384
385__git_reassemble_comp_words_by_ref()
386{
387 local exclude i j first
388 # Which word separators to exclude?
389 exclude="${1//[^$COMP_WORDBREAKS]}"
390 cword_=$COMP_CWORD
391 if [ -z "$exclude" ]; then
392 words_=("${COMP_WORDS[@]}")
393 return
394 fi
395 # List of word completion separators has shrunk;
396 # re-assemble words to complete.
397 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
398 # Append each nonempty word consisting of just
399 # word separator characters to the current word.
400 first=t
401 while
402 [ $i -gt 0 ] &&
403 [ -n "${COMP_WORDS[$i]}" ] &&
404 # word consists of excluded word separators
405 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
406 do
407 # Attach to the previous token,
408 # unless the previous token is the command name.
409 if [ $j -ge 2 ] && [ -n "$first" ]; then
410 ((j--))
411 fi
412 first=
413 words_[$j]=${words_[j]}${COMP_WORDS[i]}
414 if [ $i = $COMP_CWORD ]; then
415 cword_=$j
416 fi
417 if (($i < ${#COMP_WORDS[@]} - 1)); then
418 ((i++))
419 else
420 # Done.
421 return
422 fi
423 done
424 words_[$j]=${words_[j]}${COMP_WORDS[i]}
425 if [ $i = $COMP_CWORD ]; then
426 cword_=$j
427 fi
428 done
429}
430
da48616f 431if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
52c9d8e2 432if [[ -z ${ZSH_VERSION:+set} ]]; then
da48616f
PD
433_get_comp_words_by_ref ()
434{
dbda3b10
JN
435 local exclude cur_ words_ cword_
436 if [ "$1" = "-n" ]; then
437 exclude=$2
438 shift 2
439 fi
440 __git_reassemble_comp_words_by_ref "$exclude"
441 cur_=${words_[cword_]}
da48616f
PD
442 while [ $# -gt 0 ]; do
443 case "$1" in
444 cur)
dbda3b10 445 cur=$cur_
da48616f
PD
446 ;;
447 prev)
dbda3b10 448 prev=${words_[$cword_-1]}
da48616f
PD
449 ;;
450 words)
dbda3b10 451 words=("${words_[@]}")
da48616f
PD
452 ;;
453 cword)
dbda3b10 454 cword=$cword_
da48616f
PD
455 ;;
456 esac
457 shift
458 done
459}
52c9d8e2
JN
460else
461_get_comp_words_by_ref ()
462{
463 while [ $# -gt 0 ]; do
464 case "$1" in
465 cur)
466 cur=${COMP_WORDS[COMP_CWORD]}
467 ;;
468 prev)
469 prev=${COMP_WORDS[COMP_CWORD-1]}
470 ;;
471 words)
472 words=("${COMP_WORDS[@]}")
473 ;;
474 cword)
475 cword=$COMP_CWORD
476 ;;
477 -n)
478 # assume COMP_WORDBREAKS is already set sanely
479 shift
480 ;;
481 esac
482 shift
483 done
484}
485fi
da48616f
PD
486fi
487
f674bb80
SG
488# Generates completion reply with compgen, appending a space to possible
489# completion words, if necessary.
490# It accepts 1 to 4 arguments:
491# 1: List of possible completion words.
492# 2: A prefix to be added to each possible completion word (optional).
493# 3: Generate possible completion matches for this word (optional).
494# 4: A suffix to be appended to each possible completion word (optional).
72e5e989
SP
495__gitcomp ()
496{
9244d69b
SG
497 local cur_="$cur"
498
b3391775 499 if [ $# -gt 2 ]; then
9244d69b 500 cur_="$3"
78d4d6a2 501 fi
9244d69b 502 case "$cur_" in
5447aac7
SG
503 --*=)
504 COMPREPLY=()
5447aac7
SG
505 ;;
506 *)
ab02dfe5 507 local IFS=$'\n'
25a31f81
TP
508 COMPREPLY=($(compgen -P "${2-}" \
509 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
9244d69b 510 -- "$cur_"))
5447aac7
SG
511 ;;
512 esac
72e5e989
SP
513}
514
a42577d4 515# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
5de40f59
SP
516__git_heads ()
517{
25a31f81 518 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
5de40f59 519 if [ -d "$dir" ]; then
05e8b3d6
SG
520 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
521 refs/heads
5de40f59
SP
522 return
523 fi
25a31f81 524 for i in $(git ls-remote "${1-}" 2>/dev/null); do
5de40f59
SP
525 case "$is_hash,$i" in
526 y,*) is_hash=n ;;
527 n,*^{}) is_hash=y ;;
528 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
529 n,*) is_hash=y; echo "$i" ;;
530 esac
531 done
532}
533
a42577d4 534# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
88e21dc7
SP
535__git_tags ()
536{
25a31f81 537 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
88e21dc7 538 if [ -d "$dir" ]; then
05e8b3d6
SG
539 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
540 refs/tags
88e21dc7
SP
541 return
542 fi
25a31f81 543 for i in $(git ls-remote "${1-}" 2>/dev/null); do
88e21dc7
SP
544 case "$is_hash,$i" in
545 y,*) is_hash=n ;;
546 n,*^{}) is_hash=y ;;
547 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
548 n,*) is_hash=y; echo "$i" ;;
549 esac
550 done
551}
552
34a6bbb5
KB
553# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
554# presence of 2nd argument means use the guess heuristic employed
555# by checkout for tracking branches
690d8824
JH
556__git_refs ()
557{
34a6bbb5 558 local i is_hash=y dir="$(__gitdir "${1-}")" track="${2-}"
da4902a7 559 local format refs
873537fa 560 if [ -d "$dir" ]; then
608efb87
SG
561 case "$cur" in
562 refs|refs/*)
563 format="refname"
564 refs="${cur%/*}"
34a6bbb5 565 track=""
608efb87
SG
566 ;;
567 *)
d23e7570
IWC
568 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
569 if [ -e "$dir/$i" ]; then echo $i; fi
570 done
608efb87
SG
571 format="refname:short"
572 refs="refs/tags refs/heads refs/remotes"
573 ;;
574 esac
575 git --git-dir="$dir" for-each-ref --format="%($format)" \
576 $refs
34a6bbb5
KB
577 if [ -n "$track" ]; then
578 # employ the heuristic used by git checkout
579 # Try to find a remote branch that matches the completion word
580 # but only output if the branch name is unique
581 local ref entry
582 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
583 "refs/remotes/" | \
584 while read entry; do
585 eval "$entry"
586 ref="${ref#*/}"
587 if [[ "$ref" == "$cur"* ]]; then
588 echo "$ref"
589 fi
590 done | uniq -u
591 fi
35e65ecc 592 return
690d8824 593 fi
799596a5 594 for i in $(git ls-remote "$dir" 2>/dev/null); do
690d8824
JH
595 case "$is_hash,$i" in
596 y,*) is_hash=n ;;
597 n,*^{}) is_hash=y ;;
598 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
599 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
35e65ecc 600 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
601 n,*) is_hash=y; echo "$i" ;;
602 esac
603 done
604}
605
a42577d4 606# __git_refs2 requires 1 argument (to pass to __git_refs)
690d8824
JH
607__git_refs2 ()
608{
67ffa114
SP
609 local i
610 for i in $(__git_refs "$1"); do
611 echo "$i:$i"
690d8824
JH
612 done
613}
614
a42577d4 615# __git_refs_remotes requires 1 argument (to pass to ls-remote)
5de40f59
SP
616__git_refs_remotes ()
617{
618 local cmd i is_hash=y
799596a5 619 for i in $(git ls-remote "$1" 2>/dev/null); do
5de40f59
SP
620 case "$is_hash,$i" in
621 n,refs/heads/*)
622 is_hash=y
623 echo "$i:refs/remotes/$1/${i#refs/heads/}"
624 ;;
625 y,*) is_hash=n ;;
626 n,*^{}) is_hash=y ;;
627 n,refs/tags/*) is_hash=y;;
628 n,*) is_hash=y; ;;
629 esac
630 done
631}
632
690d8824
JH
633__git_remotes ()
634{
873537fa 635 local i ngoff IFS=$'\n' d="$(__gitdir)"
dad42775
JN
636 __git_shopt -q nullglob || ngoff=1
637 __git_shopt -s nullglob
873537fa
SP
638 for i in "$d/remotes"/*; do
639 echo ${i#$d/remotes/}
690d8824 640 done
dad42775 641 [ "$ngoff" ] && __git_shopt -u nullglob
518ef8f0
TZ
642 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
643 i="${i#remote.}"
644 echo "${i/.url*/}"
56fc25f2 645 done
690d8824
JH
646}
647
eaa4e6ee 648__git_list_merge_strategies ()
4ad91321 649{
25b3d4d6
JH
650 git merge -s help 2>&1 |
651 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
652 s/\.$//
653 s/.*://
654 s/^[ ]*//
655 s/[ ]*$//
4ad91321 656 p
25b3d4d6 657 }'
4ad91321 658}
eaa4e6ee
JN
659
660__git_merge_strategies=
661# 'git merge -s help' (and thus detection of the merge strategy
662# list) fails, unfortunately, if run outside of any git working
663# tree. __git_merge_strategies is set to the empty string in
664# that case, and the detection will be repeated the next time it
665# is needed.
666__git_compute_merge_strategies ()
667{
668 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
669}
4ad91321 670
1d66ec58 671__git_complete_revlist_file ()
690d8824 672{
da4902a7 673 local pfx ls ref cur_="$cur"
9244d69b 674 case "$cur_" in
1d66ec58
SG
675 *..?*:*)
676 return
677 ;;
690d8824 678 ?*:*)
9244d69b
SG
679 ref="${cur_%%:*}"
680 cur_="${cur_#*:}"
681 case "$cur_" in
690d8824 682 ?*/*)
9244d69b
SG
683 pfx="${cur_%/*}"
684 cur_="${cur_##*/}"
690d8824
JH
685 ls="$ref:$pfx"
686 pfx="$pfx/"
687 ;;
688 *)
689 ls="$ref"
690 ;;
80152b09 691 esac
db8a9ff0
SP
692
693 case "$COMP_WORDBREAKS" in
694 *:*) : great ;;
695 *) pfx="$ref:$pfx" ;;
696 esac
697
778306e4 698 local IFS=$'\n'
690d8824 699 COMPREPLY=($(compgen -P "$pfx" \
873537fa 700 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
778306e4
SP
701 | sed '/^100... blob /{
702 s,^.* ,,
703 s,$, ,
704 }
705 /^120000 blob /{
706 s,^.* ,,
707 s,$, ,
708 }
690d8824
JH
709 /^040000 tree /{
710 s,^.* ,,
711 s,$,/,
712 }
713 s/^.* //')" \
9244d69b 714 -- "$cur_"))
690d8824 715 ;;
f53352fb 716 *...*)
9244d69b
SG
717 pfx="${cur_%...*}..."
718 cur_="${cur_#*...}"
719 __gitcomp "$(__git_refs)" "$pfx" "$cur_"
f53352fb
SP
720 ;;
721 *..*)
9244d69b
SG
722 pfx="${cur_%..*}.."
723 cur_="${cur_#*..}"
724 __gitcomp "$(__git_refs)" "$pfx" "$cur_"
b3391775 725 ;;
f53352fb 726 *)
b3391775 727 __gitcomp "$(__git_refs)"
f53352fb
SP
728 ;;
729 esac
730}
731
1d66ec58
SG
732
733__git_complete_file ()
734{
735 __git_complete_revlist_file
736}
737
738__git_complete_revlist ()
739{
740 __git_complete_revlist_file
741}
742
52d5c3b5
JS
743__git_complete_remote_or_refspec ()
744{
9244d69b 745 local cur_="$cur" cmd="${words[1]}"
0a4e1472 746 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
da48616f
PD
747 while [ $c -lt $cword ]; do
748 i="${words[c]}"
52d5c3b5 749 case "$i" in
e25e2b42
BG
750 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
751 --all)
752 case "$cmd" in
753 push) no_complete_refspec=1 ;;
754 fetch)
755 COMPREPLY=()
756 return
757 ;;
758 *) ;;
759 esac
760 ;;
52d5c3b5
JS
761 -*) ;;
762 *) remote="$i"; break ;;
763 esac
764 c=$((++c))
765 done
766 if [ -z "$remote" ]; then
767 __gitcomp "$(__git_remotes)"
768 return
769 fi
0a4e1472
JS
770 if [ $no_complete_refspec = 1 ]; then
771 COMPREPLY=()
772 return
773 fi
52d5c3b5 774 [ "$remote" = "." ] && remote=
9244d69b 775 case "$cur_" in
52d5c3b5
JS
776 *:*)
777 case "$COMP_WORDBREAKS" in
778 *:*) : great ;;
9244d69b 779 *) pfx="${cur_%%:*}:" ;;
52d5c3b5 780 esac
9244d69b 781 cur_="${cur_#*:}"
52d5c3b5
JS
782 lhs=0
783 ;;
784 +*)
785 pfx="+"
9244d69b 786 cur_="${cur_#+}"
52d5c3b5
JS
787 ;;
788 esac
789 case "$cmd" in
790 fetch)
791 if [ $lhs = 1 ]; then
9244d69b 792 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur_"
52d5c3b5 793 else
9244d69b 794 __gitcomp "$(__git_refs)" "$pfx" "$cur_"
52d5c3b5
JS
795 fi
796 ;;
797 pull)
798 if [ $lhs = 1 ]; then
9244d69b 799 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur_"
52d5c3b5 800 else
9244d69b 801 __gitcomp "$(__git_refs)" "$pfx" "$cur_"
52d5c3b5
JS
802 fi
803 ;;
804 push)
805 if [ $lhs = 1 ]; then
9244d69b 806 __gitcomp "$(__git_refs)" "$pfx" "$cur_"
52d5c3b5 807 else
9244d69b 808 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur_"
52d5c3b5
JS
809 fi
810 ;;
811 esac
812}
813
3c7b480a
JS
814__git_complete_strategy ()
815{
eaa4e6ee 816 __git_compute_merge_strategies
da48616f 817 case "$prev" in
3c7b480a 818 -s|--strategy)
eaa4e6ee 819 __gitcomp "$__git_merge_strategies"
3c7b480a
JS
820 return 0
821 esac
3c7b480a
JS
822 case "$cur" in
823 --strategy=*)
eaa4e6ee 824 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
3c7b480a
JS
825 return 0
826 ;;
827 esac
828 return 1
829}
830
eaa4e6ee 831__git_list_all_commands ()
f2bb9f88
SP
832{
833 local i IFS=" "$'\n'
427e586b 834 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
1eb7e2f8
LM
835 do
836 case $i in
837 *--*) : helper pattern;;
838 *) echo $i;;
839 esac
840 done
841}
1eb7e2f8 842
eaa4e6ee
JN
843__git_all_commands=
844__git_compute_all_commands ()
845{
846 : ${__git_all_commands:=$(__git_list_all_commands)}
847}
848
849__git_list_porcelain_commands ()
1eb7e2f8 850{
1eb7e2f8 851 local i IFS=" "$'\n'
eaa4e6ee
JN
852 __git_compute_all_commands
853 for i in "help" $__git_all_commands
f2bb9f88
SP
854 do
855 case $i in
718a087a 856 *--*) : helper pattern;;
a925c6f1
SP
857 applymbox) : ask gittus;;
858 applypatch) : ask gittus;;
859 archimport) : import;;
2e3a430a 860 cat-file) : plumbing;;
56d99c67 861 check-attr) : plumbing;;
f2bb9f88 862 check-ref-format) : plumbing;;
ff2549dc 863 checkout-index) : plumbing;;
f2bb9f88 864 commit-tree) : plumbing;;
ff2549dc 865 count-objects) : infrequent;;
a925c6f1
SP
866 cvsexportcommit) : export;;
867 cvsimport) : import;;
f2bb9f88
SP
868 cvsserver) : daemon;;
869 daemon) : daemon;;
5cfb4fe5
SP
870 diff-files) : plumbing;;
871 diff-index) : plumbing;;
872 diff-tree) : plumbing;;
c6ec3b13 873 fast-import) : import;;
ff2549dc 874 fast-export) : export;;
a925c6f1 875 fsck-objects) : plumbing;;
f2bb9f88 876 fetch-pack) : plumbing;;
a925c6f1 877 fmt-merge-msg) : plumbing;;
56d99c67 878 for-each-ref) : plumbing;;
f2bb9f88
SP
879 hash-object) : plumbing;;
880 http-*) : transport;;
881 index-pack) : plumbing;;
a925c6f1 882 init-db) : deprecated;;
f2bb9f88 883 local-fetch) : plumbing;;
ff2549dc
PB
884 lost-found) : infrequent;;
885 ls-files) : plumbing;;
886 ls-remote) : plumbing;;
887 ls-tree) : plumbing;;
f2bb9f88
SP
888 mailinfo) : plumbing;;
889 mailsplit) : plumbing;;
890 merge-*) : plumbing;;
891 mktree) : plumbing;;
892 mktag) : plumbing;;
893 pack-objects) : plumbing;;
894 pack-redundant) : plumbing;;
895 pack-refs) : plumbing;;
896 parse-remote) : plumbing;;
897 patch-id) : plumbing;;
898 peek-remote) : plumbing;;
a925c6f1
SP
899 prune) : plumbing;;
900 prune-packed) : plumbing;;
901 quiltimport) : import;;
f2bb9f88
SP
902 read-tree) : plumbing;;
903 receive-pack) : plumbing;;
63d04a78 904 remote-*) : transport;;
5c66d0d4 905 repo-config) : deprecated;;
f2bb9f88
SP
906 rerere) : plumbing;;
907 rev-list) : plumbing;;
908 rev-parse) : plumbing;;
909 runstatus) : plumbing;;
910 sh-setup) : internal;;
911 shell) : daemon;;
ff2549dc 912 show-ref) : plumbing;;
f2bb9f88
SP
913 send-pack) : plumbing;;
914 show-index) : plumbing;;
915 ssh-*) : transport;;
916 stripspace) : plumbing;;
917 symbolic-ref) : plumbing;;
a925c6f1 918 tar-tree) : deprecated;;
f2bb9f88
SP
919 unpack-file) : plumbing;;
920 unpack-objects) : plumbing;;
a925c6f1 921 update-index) : plumbing;;
f2bb9f88
SP
922 update-ref) : plumbing;;
923 update-server-info) : daemon;;
924 upload-archive) : plumbing;;
925 upload-pack) : plumbing;;
926 write-tree) : plumbing;;
ff2549dc
PB
927 var) : infrequent;;
928 verify-pack) : infrequent;;
a925c6f1 929 verify-tag) : plumbing;;
f2bb9f88
SP
930 *) echo $i;;
931 esac
932 done
933}
eaa4e6ee
JN
934
935__git_porcelain_commands=
936__git_compute_porcelain_commands ()
937{
938 __git_compute_all_commands
939 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
940}
f2bb9f88 941
c3898111
SG
942__git_pretty_aliases ()
943{
944 local i IFS=$'\n'
945 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
946 case "$i" in
947 pretty.*)
948 i="${i#pretty.}"
949 echo "${i/ */}"
950 ;;
951 esac
952 done
953}
954
367dce2a
DS
955__git_aliases ()
956{
56fc25f2 957 local i IFS=$'\n'
518ef8f0 958 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
e0d78059
SB
959 case "$i" in
960 alias.*)
961 i="${i#alias.}"
962 echo "${i/ */}"
963 ;;
964 esac
56fc25f2 965 done
367dce2a
DS
966}
967
a42577d4 968# __git_aliased_command requires 1 argument
367dce2a
DS
969__git_aliased_command ()
970{
873537fa 971 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 972 config --get "alias.$1")
367dce2a 973 for word in $cmdline; do
c63437cb 974 case "$word" in
66729509
SG
975 \!gitk|gitk)
976 echo "gitk"
367dce2a 977 return
66729509 978 ;;
c63437cb
SG
979 \!*) : shell command alias ;;
980 -*) : option ;;
981 *=*) : setting env ;;
982 git) : git itself ;;
983 *)
984 echo "$word"
367dce2a 985 return
c63437cb 986 esac
367dce2a
DS
987 done
988}
989
918c03c2
SG
990# __git_find_on_cmdline requires 1 argument
991__git_find_on_cmdline ()
3ff1320d 992{
da4902a7 993 local word subcommand c=1
da48616f
PD
994 while [ $c -lt $cword ]; do
995 word="${words[c]}"
3ff1320d
SG
996 for subcommand in $1; do
997 if [ "$subcommand" = "$word" ]; then
998 echo "$subcommand"
999 return
1000 fi
1001 done
1002 c=$((++c))
1003 done
1004}
1005
d773c631
SG
1006__git_has_doubledash ()
1007{
da4902a7 1008 local c=1
da48616f
PD
1009 while [ $c -lt $cword ]; do
1010 if [ "--" = "${words[c]}" ]; then
d773c631
SG
1011 return 0
1012 fi
1013 c=$((++c))
1014 done
1015 return 1
1016}
1017
7950659d 1018__git_whitespacelist="nowarn warn error error-all fix"
88329195
SP
1019
1020_git_am ()
1021{
da4902a7 1022 local dir="$(__gitdir)"
51ef1daa 1023 if [ -d "$dir"/rebase-apply ]; then
85f6b439 1024 __gitcomp "--skip --continue --resolved --abort"
88329195
SP
1025 return
1026 fi
1027 case "$cur" in
1028 --whitespace=*)
b3391775 1029 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
1030 return
1031 ;;
1032 --*)
b3391775 1033 __gitcomp "
43acdf24 1034 --3way --committer-date-is-author-date --ignore-date
86c91f91 1035 --ignore-whitespace --ignore-space-change
43acdf24 1036 --interactive --keep --no-utf8 --signoff --utf8
af4e9e8c 1037 --whitespace= --scissors
b3391775 1038 "
88329195
SP
1039 return
1040 esac
1041 COMPREPLY=()
1042}
1043
1044_git_apply ()
1045{
88329195
SP
1046 case "$cur" in
1047 --whitespace=*)
b3391775 1048 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
1049 return
1050 ;;
1051 --*)
b3391775 1052 __gitcomp "
88329195
SP
1053 --stat --numstat --summary --check --index
1054 --cached --index-info --reverse --reject --unidiff-zero
1055 --apply --no-add --exclude=
86c91f91 1056 --ignore-whitespace --ignore-space-change
88329195 1057 --whitespace= --inaccurate-eof --verbose
b3391775 1058 "
88329195
SP
1059 return
1060 esac
1061 COMPREPLY=()
1062}
1063
8435b548
SP
1064_git_add ()
1065{
d773c631
SG
1066 __git_has_doubledash && return
1067
8435b548
SP
1068 case "$cur" in
1069 --*)
1d284cba
SG
1070 __gitcomp "
1071 --interactive --refresh --patch --update --dry-run
c9a114b5 1072 --ignore-errors --intent-to-add
1d284cba 1073 "
8435b548
SP
1074 return
1075 esac
1076 COMPREPLY=()
1077}
1078
b3191ce2
LM
1079_git_archive ()
1080{
b3191ce2
LM
1081 case "$cur" in
1082 --format=*)
1083 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1084 return
1085 ;;
1086 --remote=*)
1087 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
1088 return
1089 ;;
1090 --*)
1091 __gitcomp "
1092 --format= --list --verbose
1093 --prefix= --remote= --exec=
1094 "
1095 return
1096 ;;
1097 esac
1098 __git_complete_file
1099}
1100
b2e69f62
SP
1101_git_bisect ()
1102{
d773c631
SG
1103 __git_has_doubledash && return
1104
bf11d461 1105 local subcommands="start bad good skip reset visualize replay log run"
918c03c2 1106 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3ff1320d 1107 if [ -z "$subcommand" ]; then
128191f5
SG
1108 if [ -f "$(__gitdir)"/BISECT_START ]; then
1109 __gitcomp "$subcommands"
1110 else
1111 __gitcomp "replay start"
1112 fi
b2e69f62
SP
1113 return
1114 fi
1115
3ff1320d 1116 case "$subcommand" in
8205ff8e 1117 bad|good|reset|skip|start)
b2e69f62
SP
1118 __gitcomp "$(__git_refs)"
1119 ;;
1120 *)
1121 COMPREPLY=()
1122 ;;
1123 esac
1124}
1125
690d8824
JH
1126_git_branch ()
1127{
da4902a7 1128 local i c=1 only_local_ref="n" has_r="n"
b9217642 1129
da48616f
PD
1130 while [ $c -lt $cword ]; do
1131 i="${words[c]}"
b9217642
SG
1132 case "$i" in
1133 -d|-m) only_local_ref="y" ;;
1134 -r) has_r="y" ;;
1135 esac
1136 c=$((++c))
1137 done
1138
da48616f 1139 case "$cur" in
3b376b0c
SG
1140 --*)
1141 __gitcomp "
1142 --color --no-color --verbose --abbrev= --no-abbrev
50e61025 1143 --track --no-track --contains --merged --no-merged
ff9c0825 1144 --set-upstream
3b376b0c
SG
1145 "
1146 ;;
b9217642
SG
1147 *)
1148 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1149 __gitcomp "$(__git_heads)"
1150 else
1151 __gitcomp "$(__git_refs)"
1152 fi
1153 ;;
3b376b0c 1154 esac
690d8824
JH
1155}
1156
374a58c9
ML
1157_git_bundle ()
1158{
da48616f
PD
1159 local cmd="${words[2]}"
1160 case "$cword" in
8d8163f3 1161 2)
374a58c9
ML
1162 __gitcomp "create list-heads verify unbundle"
1163 ;;
8d8163f3 1164 3)
374a58c9
ML
1165 # looking for a file
1166 ;;
1167 *)
1168 case "$cmd" in
1169 create)
1170 __git_complete_revlist
1171 ;;
1172 esac
1173 ;;
1174 esac
1175}
1176
690d8824
JH
1177_git_checkout ()
1178{
c84bb14c
SG
1179 __git_has_doubledash && return
1180
e648f8b6
SG
1181 case "$cur" in
1182 --conflict=*)
1183 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1184 ;;
1185 --*)
1186 __gitcomp "
1187 --quiet --ours --theirs --track --no-track --merge
86e8e7a5 1188 --conflict= --orphan --patch
e648f8b6
SG
1189 "
1190 ;;
1191 *)
34a6bbb5
KB
1192 # check if --track, --no-track, or --no-guess was specified
1193 # if so, disable DWIM mode
1194 local flags="--track --no-track --no-guess" track=1
1195 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1196 track=''
1197 fi
1198 __gitcomp "$(__git_refs '' $track)"
e648f8b6
SG
1199 ;;
1200 esac
690d8824
JH
1201}
1202
d8a9fea5
SP
1203_git_cherry ()
1204{
1205 __gitcomp "$(__git_refs)"
1206}
1207
1273231e
SP
1208_git_cherry_pick ()
1209{
1273231e
SP
1210 case "$cur" in
1211 --*)
b3391775 1212 __gitcomp "--edit --no-commit"
1273231e
SP
1213 ;;
1214 *)
b3391775 1215 __gitcomp "$(__git_refs)"
1273231e
SP
1216 ;;
1217 esac
1218}
1219
4181c7e8
LM
1220_git_clean ()
1221{
1222 __git_has_doubledash && return
1223
4181c7e8
LM
1224 case "$cur" in
1225 --*)
1226 __gitcomp "--dry-run --quiet"
1227 return
1228 ;;
1229 esac
1230 COMPREPLY=()
1231}
1232
3eb11012
LM
1233_git_clone ()
1234{
3eb11012
LM
1235 case "$cur" in
1236 --*)
1237 __gitcomp "
1238 --local
1239 --no-hardlinks
1240 --shared
1241 --reference
1242 --quiet
1243 --no-checkout
1244 --bare
1245 --mirror
1246 --origin
1247 --upload-pack
1248 --template=
1249 --depth
1250 "
1251 return
1252 ;;
1253 esac
1254 COMPREPLY=()
1255}
1256
4548e855
SP
1257_git_commit ()
1258{
d773c631
SG
1259 __git_has_doubledash && return
1260
4548e855 1261 case "$cur" in
9a424b27
SG
1262 --cleanup=*)
1263 __gitcomp "default strip verbatim whitespace
1264 " "" "${cur##--cleanup=}"
1265 return
1266 ;;
77653abd
TM
1267 --reuse-message=*|--reedit-message=*|\
1268 --fixup=*|--squash=*)
f8e49e13 1269 __gitcomp "$(__git_refs)" "" "${cur#*=}"
9a424b27
SG
1270 return
1271 ;;
1272 --untracked-files=*)
1273 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1274 return
1275 ;;
4548e855 1276 --*)
b3391775 1277 __gitcomp "
4548e855 1278 --all --author= --signoff --verify --no-verify
aa5735be 1279 --edit --amend --include --only --interactive
9a424b27
SG
1280 --dry-run --reuse-message= --reedit-message=
1281 --reset-author --file= --message= --template=
1282 --cleanup= --untracked-files --untracked-files=
77653abd 1283 --verbose --quiet --fixup= --squash=
b3391775 1284 "
4548e855
SP
1285 return
1286 esac
1287 COMPREPLY=()
1288}
1289
217926c0
SP
1290_git_describe ()
1291{
cbb504c9
TR
1292 case "$cur" in
1293 --*)
1294 __gitcomp "
1295 --all --tags --contains --abbrev= --candidates=
1296 --exact-match --debug --long --match --always
1297 "
1298 return
1299 esac
217926c0
SP
1300 __gitcomp "$(__git_refs)"
1301}
1302
20bf7292 1303__git_diff_common_options="--stat --numstat --shortstat --summary
b3a4f858
JS
1304 --patch-with-stat --name-only --name-status --color
1305 --no-color --color-words --no-renames --check
f135aacb 1306 --full-index --binary --abbrev --diff-filter=
47d5a8fa 1307 --find-copies-harder
b3a4f858
JS
1308 --text --ignore-space-at-eol --ignore-space-change
1309 --ignore-all-space --exit-code --quiet --ext-diff
aba201c6
PO
1310 --no-ext-diff
1311 --no-prefix --src-prefix= --dst-prefix=
6d0e674a 1312 --inter-hunk-context=
cc545709 1313 --patience
20bf7292 1314 --raw
8fd2cfa7
SB
1315 --dirstat --dirstat= --dirstat-by-file
1316 --dirstat-by-file= --cumulative
20bf7292
TR
1317"
1318
1319_git_diff ()
1320{
1321 __git_has_doubledash && return
1322
20bf7292
TR
1323 case "$cur" in
1324 --*)
ebd15bf0 1325 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
861514d3 1326 --base --ours --theirs --no-index
20bf7292 1327 $__git_diff_common_options
aba201c6 1328 "
b3a4f858
JS
1329 return
1330 ;;
1331 esac
1d66ec58 1332 __git_complete_revlist_file
690d8824
JH
1333}
1334
e2dc2de9 1335__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
ffe6dc08 1336 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
e2dc2de9
DA
1337"
1338
1339_git_difftool ()
1340{
f7ad96cf
MH
1341 __git_has_doubledash && return
1342
e2dc2de9
DA
1343 case "$cur" in
1344 --tool=*)
1345 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1346 return
1347 ;;
1348 --*)
f7ad96cf
MH
1349 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1350 --base --ours --theirs
1351 --no-renames --diff-filter= --find-copies-harder
1352 --relative --ignore-submodules
1353 --tool="
e2dc2de9
DA
1354 return
1355 ;;
1356 esac
f7ad96cf 1357 __git_complete_file
e2dc2de9
DA
1358}
1359
0a4e1472
JS
1360__git_fetch_options="
1361 --quiet --verbose --append --upload-pack --force --keep --depth=
e25e2b42 1362 --tags --no-tags --all --prune --dry-run
0a4e1472
JS
1363"
1364
690d8824
JH
1365_git_fetch ()
1366{
0a4e1472
JS
1367 case "$cur" in
1368 --*)
1369 __gitcomp "$__git_fetch_options"
1370 return
1371 ;;
1372 esac
52d5c3b5 1373 __git_complete_remote_or_refspec
690d8824
JH
1374}
1375
f53352fb
SP
1376_git_format_patch ()
1377{
f53352fb 1378 case "$cur" in
e1d37937
SB
1379 --thread=*)
1380 __gitcomp "
1381 deep shallow
1382 " "" "${cur##--thread=}"
1383 return
1384 ;;
f53352fb 1385 --*)
b3391775 1386 __gitcomp "
e1d37937 1387 --stdout --attach --no-attach --thread --thread=
f53352fb
SP
1388 --output-directory
1389 --numbered --start-number
47e98eec 1390 --numbered-files
f53352fb 1391 --keep-subject
d8e1e5df 1392 --signoff --signature --no-signature
3f7df3a7 1393 --in-reply-to= --cc=
f53352fb 1394 --full-index --binary
ec804891 1395 --not --all
be5f5bf0 1396 --cover-letter
aba201c6 1397 --no-prefix --src-prefix= --dst-prefix=
81085134
SG
1398 --inline --suffix= --ignore-if-in-upstream
1399 --subject-prefix=
b3391775 1400 "
f53352fb
SP
1401 return
1402 ;;
1403 esac
1404 __git_complete_revlist
1405}
1406
4bca8636
AJ
1407_git_fsck ()
1408{
4bca8636
AJ
1409 case "$cur" in
1410 --*)
1411 __gitcomp "
1412 --tags --root --unreachable --cache --no-reflogs --full
1413 --strict --verbose --lost-found
1414 "
1415 return
1416 ;;
1417 esac
1418 COMPREPLY=()
1419}
1420
b26c8748
SP
1421_git_gc ()
1422{
b26c8748
SP
1423 case "$cur" in
1424 --*)
47e98eec 1425 __gitcomp "--prune --aggressive"
b26c8748
SP
1426 return
1427 ;;
1428 esac
1429 COMPREPLY=()
1430}
1431
66729509
SG
1432_git_gitk ()
1433{
1434 _gitk
1435}
1436
c72e0db1
LM
1437_git_grep ()
1438{
1439 __git_has_doubledash && return
1440
c72e0db1
LM
1441 case "$cur" in
1442 --*)
1443 __gitcomp "
1444 --cached
1445 --text --ignore-case --word-regexp --invert-match
5a69eaf5 1446 --full-name --line-number
c72e0db1 1447 --extended-regexp --basic-regexp --fixed-strings
63e7e9d8 1448 --perl-regexp
c72e0db1
LM
1449 --files-with-matches --name-only
1450 --files-without-match
a91f453f 1451 --max-depth
c72e0db1
LM
1452 --count
1453 --and --or --not --all-match
1454 "
1455 return
1456 ;;
1457 esac
17225c49
TR
1458
1459 __gitcomp "$(__git_refs)"
c72e0db1
LM
1460}
1461
1eb7e2f8
LM
1462_git_help ()
1463{
1eb7e2f8
LM
1464 case "$cur" in
1465 --*)
1466 __gitcomp "--all --info --man --web"
1467 return
1468 ;;
1469 esac
eaa4e6ee 1470 __git_compute_all_commands
f85a6f0b 1471 __gitcomp "$__git_all_commands $(__git_aliases)
2946cccf
MG
1472 attributes cli core-tutorial cvs-migration
1473 diffcore gitk glossary hooks ignore modules
d49483f0 1474 namespaces repository-layout tutorial tutorial-2
99f0b599 1475 workflows
2946cccf 1476 "
1eb7e2f8
LM
1477}
1478
5dad868b
LM
1479_git_init ()
1480{
5dad868b
LM
1481 case "$cur" in
1482 --shared=*)
1483 __gitcomp "
1484 false true umask group all world everybody
1485 " "" "${cur##--shared=}"
1486 return
1487 ;;
1488 --*)
1489 __gitcomp "--quiet --bare --template= --shared --shared="
1490 return
1491 ;;
1492 esac
1493 COMPREPLY=()
1494}
1495
b1bc1494
LM
1496_git_ls_files ()
1497{
1498 __git_has_doubledash && return
1499
b1bc1494
LM
1500 case "$cur" in
1501 --*)
1502 __gitcomp "--cached --deleted --modified --others --ignored
1503 --stage --directory --no-empty-directory --unmerged
1504 --killed --exclude= --exclude-from=
1505 --exclude-per-directory= --exclude-standard
1506 --error-unmatch --with-tree= --full-name
1507 --abbrev --ignored --exclude-per-directory
1508 "
1509 return
1510 ;;
1511 esac
1512 COMPREPLY=()
1513}
1514
690d8824
JH
1515_git_ls_remote ()
1516{
b3391775 1517 __gitcomp "$(__git_remotes)"
690d8824
JH
1518}
1519
1520_git_ls_tree ()
1521{
1522 __git_complete_file
1523}
1524
a393777e
TR
1525# Options that go well for log, shortlog and gitk
1526__git_log_common_options="
1527 --not --all
1528 --branches --tags --remotes
4fe1a619 1529 --first-parent --merges --no-merges
a393777e
TR
1530 --max-count=
1531 --max-age= --since= --after=
1532 --min-age= --until= --before=
6a6ebded
MG
1533 --min-parents= --max-parents=
1534 --no-min-parents --no-max-parents
a393777e
TR
1535"
1536# Options that go well for log and gitk (not shortlog)
1537__git_log_gitk_options="
1538 --dense --sparse --full-history
1539 --simplify-merges --simplify-by-decoration
3925b575 1540 --left-right --notes --no-notes
a393777e
TR
1541"
1542# Options that go well for log and shortlog (not gitk)
1543__git_log_shortlog_options="
1544 --author= --committer= --grep=
1545 --all-match
1546"
1547
3d279863 1548__git_log_pretty_formats="oneline short medium full fuller email raw format:"
672c68cb 1549__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
3d279863 1550
690d8824
JH
1551_git_log ()
1552{
d773c631
SG
1553 __git_has_doubledash && return
1554
bf3c20f6
TR
1555 local g="$(git rev-parse --git-dir 2>/dev/null)"
1556 local merge=""
ba7906f2 1557 if [ -f "$g/MERGE_HEAD" ]; then
bf3c20f6
TR
1558 merge="--merge"
1559 fi
6e31b866 1560 case "$cur" in
e67d71e5 1561 --pretty=*|--format=*)
c3898111 1562 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
e67d71e5 1563 " "" "${cur#*=}"
72de29c2
TL
1564 return
1565 ;;
47e98eec 1566 --date=*)
672c68cb 1567 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
47e98eec
SP
1568 return
1569 ;;
af4e9e8c
SB
1570 --decorate=*)
1571 __gitcomp "long short" "" "${cur##--decorate=}"
1572 return
1573 ;;
6e31b866 1574 --*)
b3391775 1575 __gitcomp "
a393777e
TR
1576 $__git_log_common_options
1577 $__git_log_shortlog_options
1578 $__git_log_gitk_options
8f87fae6 1579 --root --topo-order --date-order --reverse
5d0e6343 1580 --follow --full-diff
6e31b866 1581 --abbrev-commit --abbrev=
47e98eec 1582 --relative-date --date=
72de29c2 1583 --pretty= --format= --oneline
a393777e 1584 --cherry-pick
20827d99 1585 --graph
af4e9e8c 1586 --decorate --decorate=
20bf7292 1587 --walk-reflogs
a393777e 1588 --parents --children
bf3c20f6 1589 $merge
20bf7292 1590 $__git_diff_common_options
47d5a8fa 1591 --pickaxe-all --pickaxe-regex
b3391775 1592 "
6e31b866
SP
1593 return
1594 ;;
1595 esac
f53352fb 1596 __git_complete_revlist
690d8824
JH
1597}
1598
0a4e1472
JS
1599__git_merge_options="
1600 --no-commit --no-stat --log --no-log --squash --strategy
9858b87f 1601 --commit --stat --no-squash --ff --no-ff --ff-only
0a4e1472
JS
1602"
1603
4ad91321
SP
1604_git_merge ()
1605{
3c7b480a
JS
1606 __git_complete_strategy && return
1607
4ad91321
SP
1608 case "$cur" in
1609 --*)
0a4e1472 1610 __gitcomp "$__git_merge_options"
4ad91321
SP
1611 return
1612 esac
b3391775 1613 __gitcomp "$(__git_refs)"
4ad91321
SP
1614}
1615
b4c72162
LM
1616_git_mergetool ()
1617{
b4c72162
LM
1618 case "$cur" in
1619 --tool=*)
e2dc2de9 1620 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
b4c72162
LM
1621 return
1622 ;;
1623 --*)
1624 __gitcomp "--tool="
1625 return
1626 ;;
1627 esac
1628 COMPREPLY=()
1629}
1630
690d8824
JH
1631_git_merge_base ()
1632{
b3391775 1633 __gitcomp "$(__git_refs)"
690d8824
JH
1634}
1635
1127c51c
LM
1636_git_mv ()
1637{
1127c51c
LM
1638 case "$cur" in
1639 --*)
1640 __gitcomp "--dry-run"
1641 return
1642 ;;
1643 esac
1644 COMPREPLY=()
1645}
1646
d33909bf
SP
1647_git_name_rev ()
1648{
b3391775 1649 __gitcomp "--tags --all --stdin"
d33909bf
SP
1650}
1651
00f09d0e
SG
1652_git_notes ()
1653{
2a5da755
SG
1654 local subcommands='add append copy edit list prune remove show'
1655 local subcommand="$(__git_find_on_cmdline "$subcommands")"
00f09d0e 1656
2a5da755
SG
1657 case "$subcommand,$cur" in
1658 ,--*)
1659 __gitcomp '--ref'
1660 ;;
1661 ,*)
02fedc0f 1662 case "${words[cword-1]}" in
2a5da755
SG
1663 --ref)
1664 __gitcomp "$(__git_refs)"
1665 ;;
1666 *)
1667 __gitcomp "$subcommands --ref"
1668 ;;
1669 esac
1670 ;;
a8f89bfa 1671 add,--reuse-message=*|append,--reuse-message=*|\
2a5da755 1672 add,--reedit-message=*|append,--reedit-message=*)
a8f89bfa 1673 __gitcomp "$(__git_refs)" "" "${cur#*=}"
2a5da755
SG
1674 ;;
1675 add,--*|append,--*)
1676 __gitcomp '--file= --message= --reedit-message=
1677 --reuse-message='
1678 ;;
1679 copy,--*)
1680 __gitcomp '--stdin'
1681 ;;
1682 prune,--*)
1683 __gitcomp '--dry-run --verbose'
1684 ;;
1685 prune,*)
00f09d0e
SG
1686 ;;
1687 *)
02fedc0f 1688 case "${words[cword-1]}" in
2a5da755
SG
1689 -m|-F)
1690 ;;
1691 *)
1692 __gitcomp "$(__git_refs)"
1693 ;;
1694 esac
00f09d0e
SG
1695 ;;
1696 esac
1697}
1698
690d8824
JH
1699_git_pull ()
1700{
0a4e1472
JS
1701 __git_complete_strategy && return
1702
0a4e1472
JS
1703 case "$cur" in
1704 --*)
1705 __gitcomp "
1706 --rebase --no-rebase
1707 $__git_merge_options
1708 $__git_fetch_options
1709 "
1710 return
1711 ;;
1712 esac
52d5c3b5 1713 __git_complete_remote_or_refspec
690d8824
JH
1714}
1715
1716_git_push ()
1717{
da48616f 1718 case "$prev" in
0a4e1472
JS
1719 --repo)
1720 __gitcomp "$(__git_remotes)"
1721 return
1722 esac
1723 case "$cur" in
1724 --repo=*)
1725 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1726 return
1727 ;;
1728 --*)
1729 __gitcomp "
1730 --all --mirror --tags --dry-run --force --verbose
3623dc03 1731 --receive-pack= --repo= --set-upstream
0a4e1472
JS
1732 "
1733 return
1734 ;;
1735 esac
52d5c3b5 1736 __git_complete_remote_or_refspec
690d8824
JH
1737}
1738
61d926a3
SP
1739_git_rebase ()
1740{
da48616f 1741 local dir="$(__gitdir)"
51ef1daa 1742 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
b3391775 1743 __gitcomp "--continue --skip --abort"
61d926a3
SP
1744 return
1745 fi
3c7b480a 1746 __git_complete_strategy && return
61d926a3 1747 case "$cur" in
93cf50a4
BG
1748 --whitespace=*)
1749 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1750 return
1751 ;;
61d926a3 1752 --*)
93cf50a4
BG
1753 __gitcomp "
1754 --onto --merge --strategy --interactive
1755 --preserve-merges --stat --no-stat
1756 --committer-date-is-author-date --ignore-date
1757 --ignore-whitespace --whitespace=
6d0d465e 1758 --autosquash
93cf50a4
BG
1759 "
1760
61d926a3
SP
1761 return
1762 esac
b3391775 1763 __gitcomp "$(__git_refs)"
61d926a3
SP
1764}
1765
057f3279
TRC
1766_git_reflog ()
1767{
1768 local subcommands="show delete expire"
1769 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1770
1771 if [ -z "$subcommand" ]; then
1772 __gitcomp "$subcommands"
1773 else
1774 __gitcomp "$(__git_refs)"
1775 fi
1776}
1777
ae616de6 1778__git_send_email_confirm_options="always never auto cc compose"
cb8a9bd5 1779__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
ae616de6 1780
25a1f374
TL
1781_git_send_email ()
1782{
25a1f374 1783 case "$cur" in
ae616de6
SB
1784 --confirm=*)
1785 __gitcomp "
1786 $__git_send_email_confirm_options
1787 " "" "${cur##--confirm=}"
1788 return
1789 ;;
1790 --suppress-cc=*)
1791 __gitcomp "
1792 $__git_send_email_suppresscc_options
1793 " "" "${cur##--suppress-cc=}"
1794
1795 return
1796 ;;
1797 --smtp-encryption=*)
1798 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1799 return
1800 ;;
25a1f374 1801 --*)
77813151 1802 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
ae616de6
SB
1803 --compose --confirm= --dry-run --envelope-sender
1804 --from --identity
25a1f374
TL
1805 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1806 --no-suppress-from --no-thread --quiet
1807 --signed-off-by-cc --smtp-pass --smtp-server
ae616de6
SB
1808 --smtp-server-port --smtp-encryption= --smtp-user
1809 --subject --suppress-cc= --suppress-from --thread --to
fd3a8dcb 1810 --validate --no-validate"
25a1f374
TL
1811 return
1812 ;;
1813 esac
1814 COMPREPLY=()
1815}
1816
424cce83
SG
1817_git_stage ()
1818{
1819 _git_add
1820}
1821
00652369
SB
1822__git_config_get_set_variables ()
1823{
da48616f 1824 local prevword word config_file= c=$cword
00652369 1825 while [ $c -gt 1 ]; do
da48616f 1826 word="${words[c]}"
00652369
SB
1827 case "$word" in
1828 --global|--system|--file=*)
1829 config_file="$word"
1830 break
1831 ;;
1832 -f|--file)
1833 config_file="$word $prevword"
1834 break
1835 ;;
1836 esac
1837 prevword=$word
1838 c=$((--c))
1839 done
1840
f581de1b
SB
1841 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1842 while read line
1843 do
1844 case "$line" in
1845 *.*=*)
1846 echo "${line/=*/}"
00652369
SB
1847 ;;
1848 esac
1849 done
1850}
1851
e0d10e1c 1852_git_config ()
5de40f59 1853{
da48616f 1854 case "$prev" in
5de40f59 1855 branch.*.remote)
78d4d6a2 1856 __gitcomp "$(__git_remotes)"
5de40f59
SP
1857 return
1858 ;;
1859 branch.*.merge)
78d4d6a2 1860 __gitcomp "$(__git_refs)"
5de40f59
SP
1861 return
1862 ;;
1863 remote.*.fetch)
da48616f 1864 local remote="${prev#remote.}"
5de40f59 1865 remote="${remote%.fetch}"
78d4d6a2 1866 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
1867 return
1868 ;;
1869 remote.*.push)
da48616f 1870 local remote="${prev#remote.}"
5de40f59 1871 remote="${remote%.push}"
78d4d6a2 1872 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 1873 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
1874 refs/heads)"
1875 return
1876 ;;
1877 pull.twohead|pull.octopus)
eaa4e6ee
JN
1878 __git_compute_merge_strategies
1879 __gitcomp "$__git_merge_strategies"
78d4d6a2
SP
1880 return
1881 ;;
6123d719
MH
1882 color.branch|color.diff|color.interactive|\
1883 color.showbranch|color.status|color.ui)
78d4d6a2
SP
1884 __gitcomp "always never auto"
1885 return
1886 ;;
901d615c
MK
1887 color.pager)
1888 __gitcomp "false true"
1889 return
1890 ;;
78d4d6a2
SP
1891 color.*.*)
1892 __gitcomp "
98171a07 1893 normal black red green yellow blue magenta cyan white
78d4d6a2
SP
1894 bold dim ul blink reverse
1895 "
5de40f59
SP
1896 return
1897 ;;
9b82d63b
SB
1898 help.format)
1899 __gitcomp "man info web html"
1900 return
1901 ;;
672c68cb
SB
1902 log.date)
1903 __gitcomp "$__git_log_date_formats"
1904 return
1905 ;;
ae616de6
SB
1906 sendemail.aliasesfiletype)
1907 __gitcomp "mutt mailrc pine elm gnus"
1908 return
1909 ;;
1910 sendemail.confirm)
1911 __gitcomp "$__git_send_email_confirm_options"
1912 return
1913 ;;
1914 sendemail.suppresscc)
1915 __gitcomp "$__git_send_email_suppresscc_options"
1916 return
1917 ;;
00652369
SB
1918 --get|--get-all|--unset|--unset-all)
1919 __gitcomp "$(__git_config_get_set_variables)"
1920 return
1921 ;;
5de40f59
SP
1922 *.*)
1923 COMPREPLY=()
1924 return
1925 ;;
1926 esac
1927 case "$cur" in
1928 --*)
78d4d6a2 1929 __gitcomp "
47e98eec 1930 --global --system --file=
12977705 1931 --list --replace-all
5de40f59 1932 --get --get-all --get-regexp
1b71eb35 1933 --add --unset --unset-all
12977705 1934 --remove-section --rename-section
78d4d6a2 1935 "
5de40f59
SP
1936 return
1937 ;;
1938 branch.*.*)
9244d69b
SG
1939 local pfx="${cur%.*}." cur_="${cur##*.}"
1940 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
5de40f59
SP
1941 return
1942 ;;
1943 branch.*)
9244d69b
SG
1944 local pfx="${cur%.*}." cur_="${cur#*.}"
1945 __gitcomp "$(__git_heads)" "$pfx" "$cur_" "."
5de40f59
SP
1946 return
1947 ;;
0aa62fd0 1948 guitool.*.*)
9244d69b 1949 local pfx="${cur%.*}." cur_="${cur##*.}"
0aa62fd0
SB
1950 __gitcomp "
1951 argprompt cmd confirm needsfile noconsole norescan
1952 prompt revprompt revunmerged title
9244d69b 1953 " "$pfx" "$cur_"
0aa62fd0
SB
1954 return
1955 ;;
1956 difftool.*.*)
9244d69b
SG
1957 local pfx="${cur%.*}." cur_="${cur##*.}"
1958 __gitcomp "cmd path" "$pfx" "$cur_"
0aa62fd0
SB
1959 return
1960 ;;
1961 man.*.*)
9244d69b
SG
1962 local pfx="${cur%.*}." cur_="${cur##*.}"
1963 __gitcomp "cmd path" "$pfx" "$cur_"
0aa62fd0
SB
1964 return
1965 ;;
1966 mergetool.*.*)
9244d69b
SG
1967 local pfx="${cur%.*}." cur_="${cur##*.}"
1968 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
0aa62fd0
SB
1969 return
1970 ;;
1971 pager.*)
9244d69b 1972 local pfx="${cur%.*}." cur_="${cur#*.}"
eaa4e6ee 1973 __git_compute_all_commands
9244d69b 1974 __gitcomp "$__git_all_commands" "$pfx" "$cur_"
0aa62fd0
SB
1975 return
1976 ;;
5de40f59 1977 remote.*.*)
9244d69b 1978 local pfx="${cur%.*}." cur_="${cur##*.}"
12977705 1979 __gitcomp "
98171a07 1980 url proxy fetch push mirror skipDefaultUpdate
6fac1b83 1981 receivepack uploadpack tagopt pushurl
9244d69b 1982 " "$pfx" "$cur_"
5de40f59
SP
1983 return
1984 ;;
1985 remote.*)
9244d69b
SG
1986 local pfx="${cur%.*}." cur_="${cur#*.}"
1987 __gitcomp "$(__git_remotes)" "$pfx" "$cur_" "."
5de40f59
SP
1988 return
1989 ;;
0aa62fd0 1990 url.*.*)
9244d69b
SG
1991 local pfx="${cur%.*}." cur_="${cur##*.}"
1992 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
0aa62fd0
SB
1993 return
1994 ;;
5de40f59 1995 esac
78d4d6a2 1996 __gitcomp "
6068ac88
MZ
1997 add.ignoreErrors
1998 advice.commitBeforeMerge
1999 advice.detachedHead
2000 advice.implicitIdentity
2001 advice.pushNonFastForward
2002 advice.resolveConflict
2003 advice.statusHints
226b343c 2004 alias.
6068ac88 2005 am.keepcr
86c91f91 2006 apply.ignorewhitespace
5de40f59 2007 apply.whitespace
98171a07
LM
2008 branch.autosetupmerge
2009 branch.autosetuprebase
6068ac88 2010 browser.
2122591b 2011 clean.requireForce
78d4d6a2
SP
2012 color.branch
2013 color.branch.current
2014 color.branch.local
78d4d6a2 2015 color.branch.plain
025a1929 2016 color.branch.remote
6068ac88
MZ
2017 color.decorate.HEAD
2018 color.decorate.branch
2019 color.decorate.remoteBranch
2020 color.decorate.stash
2021 color.decorate.tag
a159ca0c 2022 color.diff
025a1929 2023 color.diff.commit
78d4d6a2 2024 color.diff.frag
6068ac88 2025 color.diff.func
025a1929 2026 color.diff.meta
78d4d6a2 2027 color.diff.new
025a1929
LM
2028 color.diff.old
2029 color.diff.plain
78d4d6a2 2030 color.diff.whitespace
226b343c 2031 color.grep
6068ac88
MZ
2032 color.grep.context
2033 color.grep.filename
2034 color.grep.function
2035 color.grep.linenumber
226b343c 2036 color.grep.match
6068ac88
MZ
2037 color.grep.selected
2038 color.grep.separator
98171a07 2039 color.interactive
6068ac88 2040 color.interactive.error
98171a07
LM
2041 color.interactive.header
2042 color.interactive.help
2043 color.interactive.prompt
a159ca0c 2044 color.pager
6123d719 2045 color.showbranch
a159ca0c 2046 color.status
78d4d6a2
SP
2047 color.status.added
2048 color.status.changed
025a1929 2049 color.status.header
98171a07 2050 color.status.nobranch
78d4d6a2 2051 color.status.untracked
98171a07
LM
2052 color.status.updated
2053 color.ui
6068ac88 2054 commit.status
98171a07 2055 commit.template
cdb791f6 2056 core.abbrev
6068ac88
MZ
2057 core.askpass
2058 core.attributesfile
98171a07
LM
2059 core.autocrlf
2060 core.bare
6068ac88 2061 core.bigFileThreshold
025a1929 2062 core.compression
226b343c 2063 core.createObject
98171a07
LM
2064 core.deltaBaseCacheLimit
2065 core.editor
6068ac88 2066 core.eol
98171a07 2067 core.excludesfile
025a1929 2068 core.fileMode
98171a07 2069 core.fsyncobjectfiles
025a1929 2070 core.gitProxy
98171a07 2071 core.ignoreCygwinFSTricks
025a1929 2072 core.ignoreStat
6068ac88 2073 core.ignorecase
025a1929
LM
2074 core.logAllRefUpdates
2075 core.loosecompression
6068ac88 2076 core.notesRef
025a1929
LM
2077 core.packedGitLimit
2078 core.packedGitWindowSize
98171a07 2079 core.pager
025a1929 2080 core.preferSymlinkRefs
98171a07
LM
2081 core.preloadindex
2082 core.quotepath
025a1929 2083 core.repositoryFormatVersion
98171a07 2084 core.safecrlf
025a1929 2085 core.sharedRepository
6068ac88 2086 core.sparseCheckout
98171a07
LM
2087 core.symlinks
2088 core.trustctime
025a1929 2089 core.warnAmbiguousRefs
98171a07
LM
2090 core.whitespace
2091 core.worktree
2092 diff.autorefreshindex
2093 diff.external
6068ac88 2094 diff.ignoreSubmodules
98171a07 2095 diff.mnemonicprefix
6068ac88 2096 diff.noprefix
78d4d6a2
SP
2097 diff.renameLimit
2098 diff.renames
226b343c
SB
2099 diff.suppressBlankEmpty
2100 diff.tool
2101 diff.wordRegex
0aa62fd0 2102 difftool.
226b343c 2103 difftool.prompt
6068ac88 2104 fetch.recurseSubmodules
78d4d6a2 2105 fetch.unpackLimit
226b343c
SB
2106 format.attach
2107 format.cc
78d4d6a2 2108 format.headers
98171a07
LM
2109 format.numbered
2110 format.pretty
d8e1e5df 2111 format.signature
226b343c
SB
2112 format.signoff
2113 format.subjectprefix
98171a07 2114 format.suffix
226b343c 2115 format.thread
6068ac88
MZ
2116 format.to
2117 gc.
98171a07
LM
2118 gc.aggressiveWindow
2119 gc.auto
2120 gc.autopacklimit
12977705 2121 gc.packrefs
98171a07 2122 gc.pruneexpire
78d4d6a2
SP
2123 gc.reflogexpire
2124 gc.reflogexpireunreachable
2125 gc.rerereresolved
2126 gc.rerereunresolved
025a1929 2127 gitcvs.allbinary
226b343c 2128 gitcvs.commitmsgannotation
98171a07 2129 gitcvs.dbTableNamePrefix
025a1929
LM
2130 gitcvs.dbdriver
2131 gitcvs.dbname
2132 gitcvs.dbpass
025a1929
LM
2133 gitcvs.dbuser
2134 gitcvs.enabled
2135 gitcvs.logfile
98171a07 2136 gitcvs.usecrlfattr
0aa62fd0 2137 guitool.
98171a07
LM
2138 gui.blamehistoryctx
2139 gui.commitmsgwidth
2140 gui.copyblamethreshold
2141 gui.diffcontext
2142 gui.encoding
2143 gui.fastcopyblame
2144 gui.matchtrackingbranch
2145 gui.newbranchtemplate
2146 gui.pruneduringfetch
2147 gui.spellingdictionary
2148 gui.trustmtime
2149 help.autocorrect
2150 help.browser
2151 help.format
78d4d6a2
SP
2152 http.lowSpeedLimit
2153 http.lowSpeedTime
025a1929 2154 http.maxRequests
6068ac88 2155 http.minSessions
5de40f59 2156 http.noEPSV
6068ac88 2157 http.postBuffer
98171a07 2158 http.proxy
025a1929
LM
2159 http.sslCAInfo
2160 http.sslCAPath
2161 http.sslCert
6068ac88 2162 http.sslCertPasswordProtected
025a1929
LM
2163 http.sslKey
2164 http.sslVerify
6068ac88 2165 http.useragent
78d4d6a2
SP
2166 i18n.commitEncoding
2167 i18n.logOutputEncoding
6068ac88 2168 imap.authMethod
226b343c
SB
2169 imap.folder
2170 imap.host
2171 imap.pass
2172 imap.port
2173 imap.preformattedHTML
2174 imap.sslverify
2175 imap.tunnel
2176 imap.user
6068ac88 2177 init.templatedir
98171a07
LM
2178 instaweb.browser
2179 instaweb.httpd
2180 instaweb.local
2181 instaweb.modulepath
2182 instaweb.port
226b343c 2183 interactive.singlekey
98171a07 2184 log.date
6068ac88 2185 log.decorate
78d4d6a2 2186 log.showroot
226b343c 2187 mailmap.file
0aa62fd0 2188 man.
98171a07 2189 man.viewer
6068ac88 2190 merge.
98171a07
LM
2191 merge.conflictstyle
2192 merge.log
2193 merge.renameLimit
6068ac88 2194 merge.renormalize
98171a07 2195 merge.stat
025a1929 2196 merge.tool
78d4d6a2 2197 merge.verbosity
0aa62fd0 2198 mergetool.
98171a07 2199 mergetool.keepBackup
6068ac88 2200 mergetool.keepTemporaries
226b343c 2201 mergetool.prompt
6068ac88
MZ
2202 notes.displayRef
2203 notes.rewrite.
2204 notes.rewrite.amend
2205 notes.rewrite.rebase
2206 notes.rewriteMode
2207 notes.rewriteRef
47e98eec 2208 pack.compression
47e98eec 2209 pack.deltaCacheLimit
025a1929
LM
2210 pack.deltaCacheSize
2211 pack.depth
98171a07
LM
2212 pack.indexVersion
2213 pack.packSizeLimit
2214 pack.threads
025a1929
LM
2215 pack.window
2216 pack.windowMemory
0aa62fd0 2217 pager.
6068ac88 2218 pretty.
78d4d6a2
SP
2219 pull.octopus
2220 pull.twohead
226b343c 2221 push.default
6068ac88 2222 rebase.autosquash
226b343c 2223 rebase.stat
6068ac88 2224 receive.autogc
98171a07 2225 receive.denyCurrentBranch
6068ac88 2226 receive.denyDeleteCurrent
98171a07 2227 receive.denyDeletes
025a1929 2228 receive.denyNonFastForwards
98171a07 2229 receive.fsckObjects
025a1929 2230 receive.unpackLimit
6068ac88
MZ
2231 receive.updateserverinfo
2232 remotes.
98171a07
LM
2233 repack.usedeltabaseoffset
2234 rerere.autoupdate
2235 rerere.enabled
6068ac88 2236 sendemail.
226b343c 2237 sendemail.aliasesfile
6068ac88 2238 sendemail.aliasfiletype
226b343c
SB
2239 sendemail.bcc
2240 sendemail.cc
2241 sendemail.cccmd
2242 sendemail.chainreplyto
2243 sendemail.confirm
2244 sendemail.envelopesender
6068ac88
MZ
2245 sendemail.from
2246 sendemail.identity
226b343c
SB
2247 sendemail.multiedit
2248 sendemail.signedoffbycc
6068ac88 2249 sendemail.smtpdomain
226b343c
SB
2250 sendemail.smtpencryption
2251 sendemail.smtppass
2252 sendemail.smtpserver
6068ac88 2253 sendemail.smtpserveroption
226b343c
SB
2254 sendemail.smtpserverport
2255 sendemail.smtpuser
2256 sendemail.suppresscc
2257 sendemail.suppressfrom
2258 sendemail.thread
2259 sendemail.to
2260 sendemail.validate
78d4d6a2 2261 showbranch.default
98171a07
LM
2262 status.relativePaths
2263 status.showUntrackedFiles
6068ac88
MZ
2264 status.submodulesummary
2265 submodule.
78d4d6a2
SP
2266 tar.umask
2267 transfer.unpackLimit
0aa62fd0 2268 url.
78d4d6a2 2269 user.email
025a1929 2270 user.name
78d4d6a2 2271 user.signingkey
98171a07 2272 web.browser
5de40f59 2273 branch. remote.
78d4d6a2 2274 "
5de40f59
SP
2275}
2276
88293c67
SP
2277_git_remote ()
2278{
bc14fac8 2279 local subcommands="add rename rm show prune update set-head"
918c03c2 2280 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3ff1320d 2281 if [ -z "$subcommand" ]; then
3903c618 2282 __gitcomp "$subcommands"
88293c67
SP
2283 return
2284 fi
2285
3ff1320d 2286 case "$subcommand" in
f135e72d 2287 rename|rm|show|prune)
88293c67
SP
2288 __gitcomp "$(__git_remotes)"
2289 ;;
fb72759b
SP
2290 update)
2291 local i c='' IFS=$'\n'
518ef8f0
TZ
2292 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2293 i="${i#remotes.}"
2294 c="$c ${i/ */}"
fb72759b
SP
2295 done
2296 __gitcomp "$c"
2297 ;;
88293c67
SP
2298 *)
2299 COMPREPLY=()
2300 ;;
2301 esac
2302}
2303
e1c1a067
BG
2304_git_replace ()
2305{
2306 __gitcomp "$(__git_refs)"
2307}
2308
67e78c3b
SP
2309_git_reset ()
2310{
d773c631
SG
2311 __git_has_doubledash && return
2312
b3391775
SP
2313 case "$cur" in
2314 --*)
9f040e95 2315 __gitcomp "--merge --mixed --hard --soft --patch"
b3391775
SP
2316 return
2317 ;;
2318 esac
2319 __gitcomp "$(__git_refs)"
67e78c3b
SP
2320}
2321
a6c2be24
LM
2322_git_revert ()
2323{
a6c2be24
LM
2324 case "$cur" in
2325 --*)
2326 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2327 return
2328 ;;
2329 esac
c0783837 2330 __gitcomp "$(__git_refs)"
a6c2be24
LM
2331}
2332
08c701d4
LM
2333_git_rm ()
2334{
2335 __git_has_doubledash && return
2336
08c701d4
LM
2337 case "$cur" in
2338 --*)
2339 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2340 return
2341 ;;
2342 esac
2343 COMPREPLY=()
2344}
2345
1fd6bec9
SP
2346_git_shortlog ()
2347{
d773c631
SG
2348 __git_has_doubledash && return
2349
1fd6bec9
SP
2350 case "$cur" in
2351 --*)
2352 __gitcomp "
a393777e
TR
2353 $__git_log_common_options
2354 $__git_log_shortlog_options
1fd6bec9
SP
2355 --numbered --summary
2356 "
2357 return
2358 ;;
2359 esac
2360 __git_complete_revlist
2361}
2362
90131924
SP
2363_git_show ()
2364{
41d8cf7d
MH
2365 __git_has_doubledash && return
2366
90131924 2367 case "$cur" in
e67d71e5 2368 --pretty=*|--format=*)
c3898111 2369 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
e67d71e5 2370 " "" "${cur#*=}"
72de29c2
TL
2371 return
2372 ;;
90131924 2373 --*)
076c3237 2374 __gitcomp "--pretty= --format= --abbrev-commit --oneline
20bf7292
TR
2375 $__git_diff_common_options
2376 "
90131924
SP
2377 return
2378 ;;
2379 esac
2380 __git_complete_file
2381}
2382
2ca880fe
TR
2383_git_show_branch ()
2384{
2ca880fe
TR
2385 case "$cur" in
2386 --*)
2387 __gitcomp "
2388 --all --remotes --topo-order --current --more=
2389 --list --independent --merge-base --no-name
6123d719 2390 --color --no-color
076c3237 2391 --sha1-name --sparse --topics --reflog
2ca880fe
TR
2392 "
2393 return
2394 ;;
2395 esac
2396 __git_complete_revlist
2397}
2398
7fd53fce
JH
2399_git_stash ()
2400{
59d5eeee 2401 local save_opts='--keep-index --no-keep-index --quiet --patch'
95d43780 2402 local subcommands='save list show apply clear drop pop create branch'
918c03c2 2403 local subcommand="$(__git_find_on_cmdline "$subcommands")"
7bedebca 2404 if [ -z "$subcommand" ]; then
59d5eeee
SG
2405 case "$cur" in
2406 --*)
2407 __gitcomp "$save_opts"
2408 ;;
2409 *)
2410 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2411 __gitcomp "$subcommands"
2412 else
2413 COMPREPLY=()
2414 fi
2415 ;;
2416 esac
7bedebca 2417 else
7bedebca
SG
2418 case "$subcommand,$cur" in
2419 save,--*)
59d5eeee 2420 __gitcomp "$save_opts"
7bedebca 2421 ;;
8513c54b 2422 apply,--*|pop,--*)
59d5eeee 2423 __gitcomp "--index --quiet"
95d43780 2424 ;;
8513c54b 2425 show,--*|drop,--*|branch,--*)
95d43780
LM
2426 COMPREPLY=()
2427 ;;
2428 show,*|apply,*|drop,*|pop,*|branch,*)
2429 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2430 | sed -n -e 's/:.*//p')"
2431 ;;
7bedebca
SG
2432 *)
2433 COMPREPLY=()
2434 ;;
2435 esac
3ff1320d 2436 fi
7fd53fce
JH
2437}
2438
be86f7a0
SP
2439_git_submodule ()
2440{
d773c631
SG
2441 __git_has_doubledash && return
2442
1b0f7978 2443 local subcommands="add status init update summary foreach sync"
918c03c2 2444 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
be86f7a0
SP
2445 case "$cur" in
2446 --*)
2447 __gitcomp "--quiet --cached"
2448 ;;
2449 *)
3ff1320d 2450 __gitcomp "$subcommands"
be86f7a0
SP
2451 ;;
2452 esac
2453 return
2454 fi
2455}
2456
47f6ee28
SG
2457_git_svn ()
2458{
2459 local subcommands="
2460 init fetch clone rebase dcommit log find-rev
2461 set-tree commit-diff info create-ignore propget
4a5856cb 2462 proplist show-ignore show-externals branch tag blame
c18d5d82 2463 migrate mkdirs reset gc
47f6ee28 2464 "
918c03c2 2465 local subcommand="$(__git_find_on_cmdline "$subcommands")"
47f6ee28
SG
2466 if [ -z "$subcommand" ]; then
2467 __gitcomp "$subcommands"
2468 else
2469 local remote_opts="--username= --config-dir= --no-auth-cache"
2470 local fc_opts="
2471 --follow-parent --authors-file= --repack=
2472 --no-metadata --use-svm-props --use-svnsync-props
2473 --log-window-size= --no-checkout --quiet
4a5856cb
SG
2474 --repack-flags --use-log-author --localtime
2475 --ignore-paths= $remote_opts
47f6ee28
SG
2476 "
2477 local init_opts="
2478 --template= --shared= --trunk= --tags=
2479 --branches= --stdlayout --minimize-url
2480 --no-metadata --use-svm-props --use-svnsync-props
4a5856cb
SG
2481 --rewrite-root= --prefix= --use-log-author
2482 --add-author-from $remote_opts
47f6ee28
SG
2483 "
2484 local cmt_opts="
2485 --edit --rmdir --find-copies-harder --copy-similarity=
2486 "
2487
47f6ee28
SG
2488 case "$subcommand,$cur" in
2489 fetch,--*)
2490 __gitcomp "--revision= --fetch-all $fc_opts"
2491 ;;
2492 clone,--*)
2493 __gitcomp "--revision= $fc_opts $init_opts"
2494 ;;
2495 init,--*)
2496 __gitcomp "$init_opts"
2497 ;;
2498 dcommit,--*)
2499 __gitcomp "
2500 --merge --strategy= --verbose --dry-run
4a5856cb
SG
2501 --fetch-all --no-rebase --commit-url
2502 --revision $cmt_opts $fc_opts
47f6ee28
SG
2503 "
2504 ;;
2505 set-tree,--*)
2506 __gitcomp "--stdin $cmt_opts $fc_opts"
2507 ;;
2508 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
c18d5d82 2509 show-externals,--*|mkdirs,--*)
47f6ee28
SG
2510 __gitcomp "--revision="
2511 ;;
2512 log,--*)
2513 __gitcomp "
2514 --limit= --revision= --verbose --incremental
2515 --oneline --show-commit --non-recursive
4a5856cb 2516 --authors-file= --color
47f6ee28
SG
2517 "
2518 ;;
2519 rebase,--*)
2520 __gitcomp "
2521 --merge --verbose --strategy= --local
4a5856cb 2522 --fetch-all --dry-run $fc_opts
47f6ee28
SG
2523 "
2524 ;;
2525 commit-diff,--*)
2526 __gitcomp "--message= --file= --revision= $cmt_opts"
2527 ;;
2528 info,--*)
2529 __gitcomp "--url"
2530 ;;
4a5856cb
SG
2531 branch,--*)
2532 __gitcomp "--dry-run --message --tag"
2533 ;;
2534 tag,--*)
2535 __gitcomp "--dry-run --message"
2536 ;;
2537 blame,--*)
2538 __gitcomp "--git-format"
2539 ;;
2540 migrate,--*)
2541 __gitcomp "
2542 --config-dir= --ignore-paths= --minimize
2543 --no-auth-cache --username=
2544 "
2545 ;;
c18d5d82
RZ
2546 reset,--*)
2547 __gitcomp "--revision= --parent"
2548 ;;
47f6ee28
SG
2549 *)
2550 COMPREPLY=()
2551 ;;
2552 esac
2553 fi
2554}
2555
88e21dc7
SP
2556_git_tag ()
2557{
2558 local i c=1 f=0
da48616f
PD
2559 while [ $c -lt $cword ]; do
2560 i="${words[c]}"
88e21dc7
SP
2561 case "$i" in
2562 -d|-v)
2563 __gitcomp "$(__git_tags)"
2564 return
2565 ;;
2566 -f)
2567 f=1
2568 ;;
2569 esac
2570 c=$((++c))
2571 done
2572
da48616f 2573 case "$prev" in
88e21dc7
SP
2574 -m|-F)
2575 COMPREPLY=()
2576 ;;
8d8163f3 2577 -*|tag)
88e21dc7
SP
2578 if [ $f = 1 ]; then
2579 __gitcomp "$(__git_tags)"
2580 else
2581 COMPREPLY=()
2582 fi
2583 ;;
2584 *)
2585 __gitcomp "$(__git_refs)"
2586 ;;
2587 esac
2588}
2589
424cce83
SG
2590_git_whatchanged ()
2591{
2592 _git_log
2593}
2594
690d8824
JH
2595_git ()
2596{
873537fa
SP
2597 local i c=1 command __git_dir
2598
ca209065 2599 if [[ -n ${ZSH_VERSION-} ]]; then
06f44c3c
ML
2600 emulate -L bash
2601 setopt KSH_TYPESET
52fd972d
FC
2602
2603 # workaround zsh's bug that leaves 'words' as a special
2604 # variable in versions < 4.3.12
2605 typeset -h words
06f44c3c
ML
2606 fi
2607
da4902a7
SG
2608 local cur words cword prev
2609 _get_comp_words_by_ref -n =: cur words cword prev
da48616f
PD
2610 while [ $c -lt $cword ]; do
2611 i="${words[c]}"
873537fa
SP
2612 case "$i" in
2613 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2614 --bare) __git_dir="." ;;
1eb7e2f8
LM
2615 --version|-p|--paginate) ;;
2616 --help) command="help"; break ;;
873537fa
SP
2617 *) command="$i"; break ;;
2618 esac
2619 c=$((++c))
2620 done
2621
1d17b22e 2622 if [ -z "$command" ]; then
da48616f 2623 case "$cur" in
47e98eec 2624 --*) __gitcomp "
ce5a2c95 2625 --paginate
47e98eec
SP
2626 --no-pager
2627 --git-dir=
2628 --bare
2629 --version
2630 --exec-path
89a56bfb 2631 --html-path
ce5a2c95 2632 --work-tree=
a1bea2c1 2633 --namespace=
ce5a2c95 2634 --help
47e98eec
SP
2635 "
2636 ;;
eaa4e6ee
JN
2637 *) __git_compute_porcelain_commands
2638 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
72e5e989
SP
2639 esac
2640 return
873537fa 2641 fi
367dce2a 2642
424cce83 2643 local completion_func="_git_${command//-/_}"
06f44c3c 2644 declare -f $completion_func >/dev/null && $completion_func && return
8024ea60 2645
873537fa 2646 local expansion=$(__git_aliased_command "$command")
8024ea60
SG
2647 if [ -n "$expansion" ]; then
2648 completion_func="_git_${expansion//-/_}"
06f44c3c 2649 declare -f $completion_func >/dev/null && $completion_func
8024ea60 2650 fi
690d8824
JH
2651}
2652
2653_gitk ()
2654{
ca209065 2655 if [[ -n ${ZSH_VERSION-} ]]; then
06f44c3c
ML
2656 emulate -L bash
2657 setopt KSH_TYPESET
52fd972d
FC
2658
2659 # workaround zsh's bug that leaves 'words' as a special
2660 # variable in versions < 4.3.12
2661 typeset -h words
06f44c3c
ML
2662 fi
2663
da4902a7
SG
2664 local cur words cword prev
2665 _get_comp_words_by_ref -n =: cur words cword prev
2666
d773c631
SG
2667 __git_has_doubledash && return
2668
fa26a401 2669 local g="$(__gitdir)"
07ba53f7 2670 local merge=""
ba7906f2 2671 if [ -f "$g/MERGE_HEAD" ]; then
07ba53f7
RQ
2672 merge="--merge"
2673 fi
b3391775
SP
2674 case "$cur" in
2675 --*)
a393777e
TR
2676 __gitcomp "
2677 $__git_log_common_options
2678 $__git_log_gitk_options
2679 $merge
2680 "
b3391775
SP
2681 return
2682 ;;
2683 esac
ec804891 2684 __git_complete_revlist
690d8824
JH
2685}
2686
50e126e1
TP
2687complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2688 || complete -o default -o nospace -F _git git
2689complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2690 || complete -o default -o nospace -F _gitk gitk
690d8824
JH
2691
2692# The following are necessary only for Cygwin, and only are needed
2693# when the user has tab-completed the executable name and consequently
2694# included the '.exe' suffix.
2695#
76c3eb51 2696if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
50e126e1
TP
2697complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2698 || complete -o default -o nospace -F _git git.exe
76c3eb51 2699fi
06f44c3c 2700
ca209065 2701if [[ -n ${ZSH_VERSION-} ]]; then
dad42775 2702 __git_shopt () {
06f44c3c
ML
2703 local option
2704 if [ $# -ne 2 ]; then
2705 echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2706 return 1
2707 fi
2708 case "$2" in
2709 nullglob)
2710 option="$2"
2711 ;;
2712 *)
2713 echo "$0: invalid option: $2" >&2
2714 return 1
2715 esac
2716 case "$1" in
2717 -q) setopt | grep -q "$option" ;;
2718 -u) unsetopt "$option" ;;
2719 -s) setopt "$option" ;;
2720 *)
2721 echo "$0: invalid flag: $1" >&2
2722 return 1
2723 esac
2724 }
dad42775
JN
2725else
2726 __git_shopt () {
2727 shopt "$@"
2728 }
06f44c3c 2729fi