]> git.ipfire.org Git - thirdparty/git.git/blame - contrib/completion/git-completion.bash
completion: don't modify the $cur variable in completion functions
[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
a42577d4
TP
488# __gitcomp accepts 1, 2, 3, or 4 arguments
489# generates completion reply with compgen
72e5e989
SP
490__gitcomp ()
491{
da48616f
PD
492 local cur
493 _get_comp_words_by_ref -n =: cur
9244d69b
SG
494 local cur_="$cur"
495
b3391775 496 if [ $# -gt 2 ]; then
9244d69b 497 cur_="$3"
78d4d6a2 498 fi
9244d69b 499 case "$cur_" in
5447aac7
SG
500 --*=)
501 COMPREPLY=()
5447aac7
SG
502 ;;
503 *)
ab02dfe5 504 local IFS=$'\n'
25a31f81
TP
505 COMPREPLY=($(compgen -P "${2-}" \
506 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
9244d69b 507 -- "$cur_"))
5447aac7
SG
508 ;;
509 esac
72e5e989
SP
510}
511
a42577d4 512# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
5de40f59
SP
513__git_heads ()
514{
25a31f81 515 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
5de40f59 516 if [ -d "$dir" ]; then
05e8b3d6
SG
517 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
518 refs/heads
5de40f59
SP
519 return
520 fi
25a31f81 521 for i in $(git ls-remote "${1-}" 2>/dev/null); do
5de40f59
SP
522 case "$is_hash,$i" in
523 y,*) is_hash=n ;;
524 n,*^{}) is_hash=y ;;
525 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
526 n,*) is_hash=y; echo "$i" ;;
527 esac
528 done
529}
530
a42577d4 531# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
88e21dc7
SP
532__git_tags ()
533{
25a31f81 534 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
88e21dc7 535 if [ -d "$dir" ]; then
05e8b3d6
SG
536 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
537 refs/tags
88e21dc7
SP
538 return
539 fi
25a31f81 540 for i in $(git ls-remote "${1-}" 2>/dev/null); do
88e21dc7
SP
541 case "$is_hash,$i" in
542 y,*) is_hash=n ;;
543 n,*^{}) is_hash=y ;;
544 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
545 n,*) is_hash=y; echo "$i" ;;
546 esac
547 done
548}
549
34a6bbb5
KB
550# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
551# presence of 2nd argument means use the guess heuristic employed
552# by checkout for tracking branches
690d8824
JH
553__git_refs ()
554{
34a6bbb5 555 local i is_hash=y dir="$(__gitdir "${1-}")" track="${2-}"
da48616f
PD
556 local cur format refs
557 _get_comp_words_by_ref -n =: cur
873537fa 558 if [ -d "$dir" ]; then
608efb87
SG
559 case "$cur" in
560 refs|refs/*)
561 format="refname"
562 refs="${cur%/*}"
34a6bbb5 563 track=""
608efb87
SG
564 ;;
565 *)
d23e7570
IWC
566 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
567 if [ -e "$dir/$i" ]; then echo $i; fi
568 done
608efb87
SG
569 format="refname:short"
570 refs="refs/tags refs/heads refs/remotes"
571 ;;
572 esac
573 git --git-dir="$dir" for-each-ref --format="%($format)" \
574 $refs
34a6bbb5
KB
575 if [ -n "$track" ]; then
576 # employ the heuristic used by git checkout
577 # Try to find a remote branch that matches the completion word
578 # but only output if the branch name is unique
579 local ref entry
580 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
581 "refs/remotes/" | \
582 while read entry; do
583 eval "$entry"
584 ref="${ref#*/}"
585 if [[ "$ref" == "$cur"* ]]; then
586 echo "$ref"
587 fi
588 done | uniq -u
589 fi
35e65ecc 590 return
690d8824 591 fi
799596a5 592 for i in $(git ls-remote "$dir" 2>/dev/null); do
690d8824
JH
593 case "$is_hash,$i" in
594 y,*) is_hash=n ;;
595 n,*^{}) is_hash=y ;;
596 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
597 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
35e65ecc 598 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
599 n,*) is_hash=y; echo "$i" ;;
600 esac
601 done
602}
603
a42577d4 604# __git_refs2 requires 1 argument (to pass to __git_refs)
690d8824
JH
605__git_refs2 ()
606{
67ffa114
SP
607 local i
608 for i in $(__git_refs "$1"); do
609 echo "$i:$i"
690d8824
JH
610 done
611}
612
a42577d4 613# __git_refs_remotes requires 1 argument (to pass to ls-remote)
5de40f59
SP
614__git_refs_remotes ()
615{
616 local cmd i is_hash=y
799596a5 617 for i in $(git ls-remote "$1" 2>/dev/null); do
5de40f59
SP
618 case "$is_hash,$i" in
619 n,refs/heads/*)
620 is_hash=y
621 echo "$i:refs/remotes/$1/${i#refs/heads/}"
622 ;;
623 y,*) is_hash=n ;;
624 n,*^{}) is_hash=y ;;
625 n,refs/tags/*) is_hash=y;;
626 n,*) is_hash=y; ;;
627 esac
628 done
629}
630
690d8824
JH
631__git_remotes ()
632{
873537fa 633 local i ngoff IFS=$'\n' d="$(__gitdir)"
56fc25f2 634 shopt -q nullglob || ngoff=1
690d8824 635 shopt -s nullglob
873537fa
SP
636 for i in "$d/remotes"/*; do
637 echo ${i#$d/remotes/}
690d8824 638 done
56fc25f2 639 [ "$ngoff" ] && shopt -u nullglob
518ef8f0
TZ
640 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
641 i="${i#remote.}"
642 echo "${i/.url*/}"
56fc25f2 643 done
690d8824
JH
644}
645
eaa4e6ee 646__git_list_merge_strategies ()
4ad91321 647{
25b3d4d6
JH
648 git merge -s help 2>&1 |
649 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
650 s/\.$//
651 s/.*://
652 s/^[ ]*//
653 s/[ ]*$//
4ad91321 654 p
25b3d4d6 655 }'
4ad91321 656}
eaa4e6ee
JN
657
658__git_merge_strategies=
659# 'git merge -s help' (and thus detection of the merge strategy
660# list) fails, unfortunately, if run outside of any git working
661# tree. __git_merge_strategies is set to the empty string in
662# that case, and the detection will be repeated the next time it
663# is needed.
664__git_compute_merge_strategies ()
665{
666 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
667}
4ad91321 668
1d66ec58 669__git_complete_revlist_file ()
690d8824 670{
da48616f
PD
671 local pfx ls ref cur
672 _get_comp_words_by_ref -n =: cur
9244d69b
SG
673 local cur_="$cur"
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{
da48616f
PD
745 local cur words cword
746 _get_comp_words_by_ref -n =: cur words cword
9244d69b 747 local cur_="$cur" cmd="${words[1]}"
0a4e1472 748 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
da48616f
PD
749 while [ $c -lt $cword ]; do
750 i="${words[c]}"
52d5c3b5 751 case "$i" in
e25e2b42
BG
752 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
753 --all)
754 case "$cmd" in
755 push) no_complete_refspec=1 ;;
756 fetch)
757 COMPREPLY=()
758 return
759 ;;
760 *) ;;
761 esac
762 ;;
52d5c3b5
JS
763 -*) ;;
764 *) remote="$i"; break ;;
765 esac
766 c=$((++c))
767 done
768 if [ -z "$remote" ]; then
769 __gitcomp "$(__git_remotes)"
770 return
771 fi
0a4e1472
JS
772 if [ $no_complete_refspec = 1 ]; then
773 COMPREPLY=()
774 return
775 fi
52d5c3b5 776 [ "$remote" = "." ] && remote=
9244d69b 777 case "$cur_" in
52d5c3b5
JS
778 *:*)
779 case "$COMP_WORDBREAKS" in
780 *:*) : great ;;
9244d69b 781 *) pfx="${cur_%%:*}:" ;;
52d5c3b5 782 esac
9244d69b 783 cur_="${cur_#*:}"
52d5c3b5
JS
784 lhs=0
785 ;;
786 +*)
787 pfx="+"
9244d69b 788 cur_="${cur_#+}"
52d5c3b5
JS
789 ;;
790 esac
791 case "$cmd" in
792 fetch)
793 if [ $lhs = 1 ]; then
9244d69b 794 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur_"
52d5c3b5 795 else
9244d69b 796 __gitcomp "$(__git_refs)" "$pfx" "$cur_"
52d5c3b5
JS
797 fi
798 ;;
799 pull)
800 if [ $lhs = 1 ]; then
9244d69b 801 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur_"
52d5c3b5 802 else
9244d69b 803 __gitcomp "$(__git_refs)" "$pfx" "$cur_"
52d5c3b5
JS
804 fi
805 ;;
806 push)
807 if [ $lhs = 1 ]; then
9244d69b 808 __gitcomp "$(__git_refs)" "$pfx" "$cur_"
52d5c3b5 809 else
9244d69b 810 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur_"
52d5c3b5
JS
811 fi
812 ;;
813 esac
814}
815
3c7b480a
JS
816__git_complete_strategy ()
817{
da48616f
PD
818 local cur prev
819 _get_comp_words_by_ref -n =: cur prev
eaa4e6ee 820 __git_compute_merge_strategies
da48616f 821 case "$prev" in
3c7b480a 822 -s|--strategy)
eaa4e6ee 823 __gitcomp "$__git_merge_strategies"
3c7b480a
JS
824 return 0
825 esac
3c7b480a
JS
826 case "$cur" in
827 --strategy=*)
eaa4e6ee 828 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
3c7b480a
JS
829 return 0
830 ;;
831 esac
832 return 1
833}
834
eaa4e6ee 835__git_list_all_commands ()
f2bb9f88
SP
836{
837 local i IFS=" "$'\n'
427e586b 838 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
1eb7e2f8
LM
839 do
840 case $i in
841 *--*) : helper pattern;;
842 *) echo $i;;
843 esac
844 done
845}
1eb7e2f8 846
eaa4e6ee
JN
847__git_all_commands=
848__git_compute_all_commands ()
849{
850 : ${__git_all_commands:=$(__git_list_all_commands)}
851}
852
853__git_list_porcelain_commands ()
1eb7e2f8 854{
1eb7e2f8 855 local i IFS=" "$'\n'
eaa4e6ee
JN
856 __git_compute_all_commands
857 for i in "help" $__git_all_commands
f2bb9f88
SP
858 do
859 case $i in
718a087a 860 *--*) : helper pattern;;
a925c6f1
SP
861 applymbox) : ask gittus;;
862 applypatch) : ask gittus;;
863 archimport) : import;;
2e3a430a 864 cat-file) : plumbing;;
56d99c67 865 check-attr) : plumbing;;
f2bb9f88 866 check-ref-format) : plumbing;;
ff2549dc 867 checkout-index) : plumbing;;
f2bb9f88 868 commit-tree) : plumbing;;
ff2549dc 869 count-objects) : infrequent;;
a925c6f1
SP
870 cvsexportcommit) : export;;
871 cvsimport) : import;;
f2bb9f88
SP
872 cvsserver) : daemon;;
873 daemon) : daemon;;
5cfb4fe5
SP
874 diff-files) : plumbing;;
875 diff-index) : plumbing;;
876 diff-tree) : plumbing;;
c6ec3b13 877 fast-import) : import;;
ff2549dc 878 fast-export) : export;;
a925c6f1 879 fsck-objects) : plumbing;;
f2bb9f88 880 fetch-pack) : plumbing;;
a925c6f1 881 fmt-merge-msg) : plumbing;;
56d99c67 882 for-each-ref) : plumbing;;
f2bb9f88
SP
883 hash-object) : plumbing;;
884 http-*) : transport;;
885 index-pack) : plumbing;;
a925c6f1 886 init-db) : deprecated;;
f2bb9f88 887 local-fetch) : plumbing;;
ff2549dc
PB
888 lost-found) : infrequent;;
889 ls-files) : plumbing;;
890 ls-remote) : plumbing;;
891 ls-tree) : plumbing;;
f2bb9f88
SP
892 mailinfo) : plumbing;;
893 mailsplit) : plumbing;;
894 merge-*) : plumbing;;
895 mktree) : plumbing;;
896 mktag) : plumbing;;
897 pack-objects) : plumbing;;
898 pack-redundant) : plumbing;;
899 pack-refs) : plumbing;;
900 parse-remote) : plumbing;;
901 patch-id) : plumbing;;
902 peek-remote) : plumbing;;
a925c6f1
SP
903 prune) : plumbing;;
904 prune-packed) : plumbing;;
905 quiltimport) : import;;
f2bb9f88
SP
906 read-tree) : plumbing;;
907 receive-pack) : plumbing;;
63d04a78 908 remote-*) : transport;;
5c66d0d4 909 repo-config) : deprecated;;
f2bb9f88
SP
910 rerere) : plumbing;;
911 rev-list) : plumbing;;
912 rev-parse) : plumbing;;
913 runstatus) : plumbing;;
914 sh-setup) : internal;;
915 shell) : daemon;;
ff2549dc 916 show-ref) : plumbing;;
f2bb9f88
SP
917 send-pack) : plumbing;;
918 show-index) : plumbing;;
919 ssh-*) : transport;;
920 stripspace) : plumbing;;
921 symbolic-ref) : plumbing;;
a925c6f1 922 tar-tree) : deprecated;;
f2bb9f88
SP
923 unpack-file) : plumbing;;
924 unpack-objects) : plumbing;;
a925c6f1 925 update-index) : plumbing;;
f2bb9f88
SP
926 update-ref) : plumbing;;
927 update-server-info) : daemon;;
928 upload-archive) : plumbing;;
929 upload-pack) : plumbing;;
930 write-tree) : plumbing;;
ff2549dc
PB
931 var) : infrequent;;
932 verify-pack) : infrequent;;
a925c6f1 933 verify-tag) : plumbing;;
f2bb9f88
SP
934 *) echo $i;;
935 esac
936 done
937}
eaa4e6ee
JN
938
939__git_porcelain_commands=
940__git_compute_porcelain_commands ()
941{
942 __git_compute_all_commands
943 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
944}
f2bb9f88 945
c3898111
SG
946__git_pretty_aliases ()
947{
948 local i IFS=$'\n'
949 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
950 case "$i" in
951 pretty.*)
952 i="${i#pretty.}"
953 echo "${i/ */}"
954 ;;
955 esac
956 done
957}
958
367dce2a
DS
959__git_aliases ()
960{
56fc25f2 961 local i IFS=$'\n'
518ef8f0 962 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
e0d78059
SB
963 case "$i" in
964 alias.*)
965 i="${i#alias.}"
966 echo "${i/ */}"
967 ;;
968 esac
56fc25f2 969 done
367dce2a
DS
970}
971
a42577d4 972# __git_aliased_command requires 1 argument
367dce2a
DS
973__git_aliased_command ()
974{
873537fa 975 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 976 config --get "alias.$1")
367dce2a 977 for word in $cmdline; do
c63437cb 978 case "$word" in
66729509
SG
979 \!gitk|gitk)
980 echo "gitk"
367dce2a 981 return
66729509 982 ;;
c63437cb
SG
983 \!*) : shell command alias ;;
984 -*) : option ;;
985 *=*) : setting env ;;
986 git) : git itself ;;
987 *)
988 echo "$word"
367dce2a 989 return
c63437cb 990 esac
367dce2a
DS
991 done
992}
993
918c03c2
SG
994# __git_find_on_cmdline requires 1 argument
995__git_find_on_cmdline ()
3ff1320d 996{
da48616f
PD
997 local word subcommand c=1 words cword
998 _get_comp_words_by_ref -n =: words cword
999 while [ $c -lt $cword ]; do
1000 word="${words[c]}"
3ff1320d
SG
1001 for subcommand in $1; do
1002 if [ "$subcommand" = "$word" ]; then
1003 echo "$subcommand"
1004 return
1005 fi
1006 done
1007 c=$((++c))
1008 done
1009}
1010
d773c631
SG
1011__git_has_doubledash ()
1012{
da48616f
PD
1013 local c=1 words cword
1014 _get_comp_words_by_ref -n =: words cword
1015 while [ $c -lt $cword ]; do
1016 if [ "--" = "${words[c]}" ]; then
d773c631
SG
1017 return 0
1018 fi
1019 c=$((++c))
1020 done
1021 return 1
1022}
1023
7950659d 1024__git_whitespacelist="nowarn warn error error-all fix"
88329195
SP
1025
1026_git_am ()
1027{
da48616f
PD
1028 local cur dir="$(__gitdir)"
1029 _get_comp_words_by_ref -n =: cur
51ef1daa 1030 if [ -d "$dir"/rebase-apply ]; then
85f6b439 1031 __gitcomp "--skip --continue --resolved --abort"
88329195
SP
1032 return
1033 fi
1034 case "$cur" in
1035 --whitespace=*)
b3391775 1036 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
1037 return
1038 ;;
1039 --*)
b3391775 1040 __gitcomp "
43acdf24 1041 --3way --committer-date-is-author-date --ignore-date
86c91f91 1042 --ignore-whitespace --ignore-space-change
43acdf24 1043 --interactive --keep --no-utf8 --signoff --utf8
af4e9e8c 1044 --whitespace= --scissors
b3391775 1045 "
88329195
SP
1046 return
1047 esac
1048 COMPREPLY=()
1049}
1050
1051_git_apply ()
1052{
da48616f
PD
1053 local cur
1054 _get_comp_words_by_ref -n =: cur
88329195
SP
1055 case "$cur" in
1056 --whitespace=*)
b3391775 1057 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
1058 return
1059 ;;
1060 --*)
b3391775 1061 __gitcomp "
88329195
SP
1062 --stat --numstat --summary --check --index
1063 --cached --index-info --reverse --reject --unidiff-zero
1064 --apply --no-add --exclude=
86c91f91 1065 --ignore-whitespace --ignore-space-change
88329195 1066 --whitespace= --inaccurate-eof --verbose
b3391775 1067 "
88329195
SP
1068 return
1069 esac
1070 COMPREPLY=()
1071}
1072
8435b548
SP
1073_git_add ()
1074{
d773c631
SG
1075 __git_has_doubledash && return
1076
da48616f
PD
1077 local cur
1078 _get_comp_words_by_ref -n =: cur
8435b548
SP
1079 case "$cur" in
1080 --*)
1d284cba
SG
1081 __gitcomp "
1082 --interactive --refresh --patch --update --dry-run
c9a114b5 1083 --ignore-errors --intent-to-add
1d284cba 1084 "
8435b548
SP
1085 return
1086 esac
1087 COMPREPLY=()
1088}
1089
b3191ce2
LM
1090_git_archive ()
1091{
da48616f
PD
1092 local cur
1093 _get_comp_words_by_ref -n =: cur
b3191ce2
LM
1094 case "$cur" in
1095 --format=*)
1096 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1097 return
1098 ;;
1099 --remote=*)
1100 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
1101 return
1102 ;;
1103 --*)
1104 __gitcomp "
1105 --format= --list --verbose
1106 --prefix= --remote= --exec=
1107 "
1108 return
1109 ;;
1110 esac
1111 __git_complete_file
1112}
1113
b2e69f62
SP
1114_git_bisect ()
1115{
d773c631
SG
1116 __git_has_doubledash && return
1117
bf11d461 1118 local subcommands="start bad good skip reset visualize replay log run"
918c03c2 1119 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3ff1320d 1120 if [ -z "$subcommand" ]; then
128191f5
SG
1121 if [ -f "$(__gitdir)"/BISECT_START ]; then
1122 __gitcomp "$subcommands"
1123 else
1124 __gitcomp "replay start"
1125 fi
b2e69f62
SP
1126 return
1127 fi
1128
3ff1320d 1129 case "$subcommand" in
8205ff8e 1130 bad|good|reset|skip|start)
b2e69f62
SP
1131 __gitcomp "$(__git_refs)"
1132 ;;
1133 *)
1134 COMPREPLY=()
1135 ;;
1136 esac
1137}
1138
690d8824
JH
1139_git_branch ()
1140{
da48616f 1141 local i c=1 only_local_ref="n" has_r="n" cur words cword
b9217642 1142
da48616f
PD
1143 _get_comp_words_by_ref -n =: cur words cword
1144 while [ $c -lt $cword ]; do
1145 i="${words[c]}"
b9217642
SG
1146 case "$i" in
1147 -d|-m) only_local_ref="y" ;;
1148 -r) has_r="y" ;;
1149 esac
1150 c=$((++c))
1151 done
1152
da48616f 1153 case "$cur" in
3b376b0c
SG
1154 --*)
1155 __gitcomp "
1156 --color --no-color --verbose --abbrev= --no-abbrev
50e61025 1157 --track --no-track --contains --merged --no-merged
ff9c0825 1158 --set-upstream
3b376b0c
SG
1159 "
1160 ;;
b9217642
SG
1161 *)
1162 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1163 __gitcomp "$(__git_heads)"
1164 else
1165 __gitcomp "$(__git_refs)"
1166 fi
1167 ;;
3b376b0c 1168 esac
690d8824
JH
1169}
1170
374a58c9
ML
1171_git_bundle ()
1172{
da48616f
PD
1173 local words cword
1174 _get_comp_words_by_ref -n =: words cword
1175 local cmd="${words[2]}"
1176 case "$cword" in
8d8163f3 1177 2)
374a58c9
ML
1178 __gitcomp "create list-heads verify unbundle"
1179 ;;
8d8163f3 1180 3)
374a58c9
ML
1181 # looking for a file
1182 ;;
1183 *)
1184 case "$cmd" in
1185 create)
1186 __git_complete_revlist
1187 ;;
1188 esac
1189 ;;
1190 esac
1191}
1192
690d8824
JH
1193_git_checkout ()
1194{
c84bb14c
SG
1195 __git_has_doubledash && return
1196
da48616f
PD
1197 local cur
1198 _get_comp_words_by_ref -n =: cur
e648f8b6
SG
1199 case "$cur" in
1200 --conflict=*)
1201 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1202 ;;
1203 --*)
1204 __gitcomp "
1205 --quiet --ours --theirs --track --no-track --merge
86e8e7a5 1206 --conflict= --orphan --patch
e648f8b6
SG
1207 "
1208 ;;
1209 *)
34a6bbb5
KB
1210 # check if --track, --no-track, or --no-guess was specified
1211 # if so, disable DWIM mode
1212 local flags="--track --no-track --no-guess" track=1
1213 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1214 track=''
1215 fi
1216 __gitcomp "$(__git_refs '' $track)"
e648f8b6
SG
1217 ;;
1218 esac
690d8824
JH
1219}
1220
d8a9fea5
SP
1221_git_cherry ()
1222{
1223 __gitcomp "$(__git_refs)"
1224}
1225
1273231e
SP
1226_git_cherry_pick ()
1227{
da48616f
PD
1228 local cur
1229 _get_comp_words_by_ref -n =: cur
1273231e
SP
1230 case "$cur" in
1231 --*)
b3391775 1232 __gitcomp "--edit --no-commit"
1273231e
SP
1233 ;;
1234 *)
b3391775 1235 __gitcomp "$(__git_refs)"
1273231e
SP
1236 ;;
1237 esac
1238}
1239
4181c7e8
LM
1240_git_clean ()
1241{
1242 __git_has_doubledash && return
1243
da48616f
PD
1244 local cur
1245 _get_comp_words_by_ref -n =: cur
4181c7e8
LM
1246 case "$cur" in
1247 --*)
1248 __gitcomp "--dry-run --quiet"
1249 return
1250 ;;
1251 esac
1252 COMPREPLY=()
1253}
1254
3eb11012
LM
1255_git_clone ()
1256{
da48616f
PD
1257 local cur
1258 _get_comp_words_by_ref -n =: cur
3eb11012
LM
1259 case "$cur" in
1260 --*)
1261 __gitcomp "
1262 --local
1263 --no-hardlinks
1264 --shared
1265 --reference
1266 --quiet
1267 --no-checkout
1268 --bare
1269 --mirror
1270 --origin
1271 --upload-pack
1272 --template=
1273 --depth
1274 "
1275 return
1276 ;;
1277 esac
1278 COMPREPLY=()
1279}
1280
4548e855
SP
1281_git_commit ()
1282{
d773c631
SG
1283 __git_has_doubledash && return
1284
da48616f
PD
1285 local cur
1286 _get_comp_words_by_ref -n =: cur
4548e855 1287 case "$cur" in
9a424b27
SG
1288 --cleanup=*)
1289 __gitcomp "default strip verbatim whitespace
1290 " "" "${cur##--cleanup=}"
1291 return
1292 ;;
1293 --reuse-message=*)
1294 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1295 return
1296 ;;
1297 --reedit-message=*)
1298 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1299 return
1300 ;;
1301 --untracked-files=*)
1302 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1303 return
1304 ;;
4548e855 1305 --*)
b3391775 1306 __gitcomp "
4548e855 1307 --all --author= --signoff --verify --no-verify
aa5735be 1308 --edit --amend --include --only --interactive
9a424b27
SG
1309 --dry-run --reuse-message= --reedit-message=
1310 --reset-author --file= --message= --template=
1311 --cleanup= --untracked-files --untracked-files=
1312 --verbose --quiet
b3391775 1313 "
4548e855
SP
1314 return
1315 esac
1316 COMPREPLY=()
1317}
1318
217926c0
SP
1319_git_describe ()
1320{
da48616f
PD
1321 local cur
1322 _get_comp_words_by_ref -n =: cur
cbb504c9
TR
1323 case "$cur" in
1324 --*)
1325 __gitcomp "
1326 --all --tags --contains --abbrev= --candidates=
1327 --exact-match --debug --long --match --always
1328 "
1329 return
1330 esac
217926c0
SP
1331 __gitcomp "$(__git_refs)"
1332}
1333
20bf7292 1334__git_diff_common_options="--stat --numstat --shortstat --summary
b3a4f858
JS
1335 --patch-with-stat --name-only --name-status --color
1336 --no-color --color-words --no-renames --check
f135aacb 1337 --full-index --binary --abbrev --diff-filter=
47d5a8fa 1338 --find-copies-harder
b3a4f858
JS
1339 --text --ignore-space-at-eol --ignore-space-change
1340 --ignore-all-space --exit-code --quiet --ext-diff
aba201c6
PO
1341 --no-ext-diff
1342 --no-prefix --src-prefix= --dst-prefix=
6d0e674a 1343 --inter-hunk-context=
cc545709 1344 --patience
20bf7292 1345 --raw
8fd2cfa7
SB
1346 --dirstat --dirstat= --dirstat-by-file
1347 --dirstat-by-file= --cumulative
20bf7292
TR
1348"
1349
1350_git_diff ()
1351{
1352 __git_has_doubledash && return
1353
da48616f
PD
1354 local cur
1355 _get_comp_words_by_ref -n =: cur
20bf7292
TR
1356 case "$cur" in
1357 --*)
ebd15bf0 1358 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
861514d3 1359 --base --ours --theirs --no-index
20bf7292 1360 $__git_diff_common_options
aba201c6 1361 "
b3a4f858
JS
1362 return
1363 ;;
1364 esac
1d66ec58 1365 __git_complete_revlist_file
690d8824
JH
1366}
1367
e2dc2de9 1368__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
ffe6dc08 1369 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
e2dc2de9
DA
1370"
1371
1372_git_difftool ()
1373{
f7ad96cf
MH
1374 __git_has_doubledash && return
1375
da48616f
PD
1376 local cur
1377 _get_comp_words_by_ref -n =: cur
e2dc2de9
DA
1378 case "$cur" in
1379 --tool=*)
1380 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1381 return
1382 ;;
1383 --*)
f7ad96cf
MH
1384 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1385 --base --ours --theirs
1386 --no-renames --diff-filter= --find-copies-harder
1387 --relative --ignore-submodules
1388 --tool="
e2dc2de9
DA
1389 return
1390 ;;
1391 esac
f7ad96cf 1392 __git_complete_file
e2dc2de9
DA
1393}
1394
0a4e1472
JS
1395__git_fetch_options="
1396 --quiet --verbose --append --upload-pack --force --keep --depth=
e25e2b42 1397 --tags --no-tags --all --prune --dry-run
0a4e1472
JS
1398"
1399
690d8824
JH
1400_git_fetch ()
1401{
da48616f
PD
1402 local cur
1403 _get_comp_words_by_ref -n =: cur
0a4e1472
JS
1404 case "$cur" in
1405 --*)
1406 __gitcomp "$__git_fetch_options"
1407 return
1408 ;;
1409 esac
52d5c3b5 1410 __git_complete_remote_or_refspec
690d8824
JH
1411}
1412
f53352fb
SP
1413_git_format_patch ()
1414{
da48616f
PD
1415 local cur
1416 _get_comp_words_by_ref -n =: cur
f53352fb 1417 case "$cur" in
e1d37937
SB
1418 --thread=*)
1419 __gitcomp "
1420 deep shallow
1421 " "" "${cur##--thread=}"
1422 return
1423 ;;
f53352fb 1424 --*)
b3391775 1425 __gitcomp "
e1d37937 1426 --stdout --attach --no-attach --thread --thread=
f53352fb
SP
1427 --output-directory
1428 --numbered --start-number
47e98eec 1429 --numbered-files
f53352fb 1430 --keep-subject
d8e1e5df 1431 --signoff --signature --no-signature
3f7df3a7 1432 --in-reply-to= --cc=
f53352fb 1433 --full-index --binary
ec804891 1434 --not --all
be5f5bf0 1435 --cover-letter
aba201c6 1436 --no-prefix --src-prefix= --dst-prefix=
81085134
SG
1437 --inline --suffix= --ignore-if-in-upstream
1438 --subject-prefix=
b3391775 1439 "
f53352fb
SP
1440 return
1441 ;;
1442 esac
1443 __git_complete_revlist
1444}
1445
4bca8636
AJ
1446_git_fsck ()
1447{
da48616f
PD
1448 local cur
1449 _get_comp_words_by_ref -n =: cur
4bca8636
AJ
1450 case "$cur" in
1451 --*)
1452 __gitcomp "
1453 --tags --root --unreachable --cache --no-reflogs --full
1454 --strict --verbose --lost-found
1455 "
1456 return
1457 ;;
1458 esac
1459 COMPREPLY=()
1460}
1461
b26c8748
SP
1462_git_gc ()
1463{
da48616f
PD
1464 local cur
1465 _get_comp_words_by_ref -n =: cur
b26c8748
SP
1466 case "$cur" in
1467 --*)
47e98eec 1468 __gitcomp "--prune --aggressive"
b26c8748
SP
1469 return
1470 ;;
1471 esac
1472 COMPREPLY=()
1473}
1474
66729509
SG
1475_git_gitk ()
1476{
1477 _gitk
1478}
1479
c72e0db1
LM
1480_git_grep ()
1481{
1482 __git_has_doubledash && return
1483
da48616f
PD
1484 local cur
1485 _get_comp_words_by_ref -n =: cur
c72e0db1
LM
1486 case "$cur" in
1487 --*)
1488 __gitcomp "
1489 --cached
1490 --text --ignore-case --word-regexp --invert-match
1491 --full-name
1492 --extended-regexp --basic-regexp --fixed-strings
1493 --files-with-matches --name-only
1494 --files-without-match
a91f453f 1495 --max-depth
c72e0db1
LM
1496 --count
1497 --and --or --not --all-match
1498 "
1499 return
1500 ;;
1501 esac
17225c49
TR
1502
1503 __gitcomp "$(__git_refs)"
c72e0db1
LM
1504}
1505
1eb7e2f8
LM
1506_git_help ()
1507{
da48616f
PD
1508 local cur
1509 _get_comp_words_by_ref -n =: cur
1eb7e2f8
LM
1510 case "$cur" in
1511 --*)
1512 __gitcomp "--all --info --man --web"
1513 return
1514 ;;
1515 esac
eaa4e6ee 1516 __git_compute_all_commands
f85a6f0b 1517 __gitcomp "$__git_all_commands $(__git_aliases)
2946cccf
MG
1518 attributes cli core-tutorial cvs-migration
1519 diffcore gitk glossary hooks ignore modules
1520 repository-layout tutorial tutorial-2
99f0b599 1521 workflows
2946cccf 1522 "
1eb7e2f8
LM
1523}
1524
5dad868b
LM
1525_git_init ()
1526{
da48616f
PD
1527 local cur
1528 _get_comp_words_by_ref -n =: cur
5dad868b
LM
1529 case "$cur" in
1530 --shared=*)
1531 __gitcomp "
1532 false true umask group all world everybody
1533 " "" "${cur##--shared=}"
1534 return
1535 ;;
1536 --*)
1537 __gitcomp "--quiet --bare --template= --shared --shared="
1538 return
1539 ;;
1540 esac
1541 COMPREPLY=()
1542}
1543
b1bc1494
LM
1544_git_ls_files ()
1545{
1546 __git_has_doubledash && return
1547
da48616f
PD
1548 local cur
1549 _get_comp_words_by_ref -n =: cur
b1bc1494
LM
1550 case "$cur" in
1551 --*)
1552 __gitcomp "--cached --deleted --modified --others --ignored
1553 --stage --directory --no-empty-directory --unmerged
1554 --killed --exclude= --exclude-from=
1555 --exclude-per-directory= --exclude-standard
1556 --error-unmatch --with-tree= --full-name
1557 --abbrev --ignored --exclude-per-directory
1558 "
1559 return
1560 ;;
1561 esac
1562 COMPREPLY=()
1563}
1564
690d8824
JH
1565_git_ls_remote ()
1566{
b3391775 1567 __gitcomp "$(__git_remotes)"
690d8824
JH
1568}
1569
1570_git_ls_tree ()
1571{
1572 __git_complete_file
1573}
1574
a393777e
TR
1575# Options that go well for log, shortlog and gitk
1576__git_log_common_options="
1577 --not --all
1578 --branches --tags --remotes
4fe1a619 1579 --first-parent --merges --no-merges
a393777e
TR
1580 --max-count=
1581 --max-age= --since= --after=
1582 --min-age= --until= --before=
6a6ebded
MG
1583 --min-parents= --max-parents=
1584 --no-min-parents --no-max-parents
a393777e
TR
1585"
1586# Options that go well for log and gitk (not shortlog)
1587__git_log_gitk_options="
1588 --dense --sparse --full-history
1589 --simplify-merges --simplify-by-decoration
1590 --left-right
1591"
1592# Options that go well for log and shortlog (not gitk)
1593__git_log_shortlog_options="
1594 --author= --committer= --grep=
1595 --all-match
1596"
1597
3d279863 1598__git_log_pretty_formats="oneline short medium full fuller email raw format:"
672c68cb 1599__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
3d279863 1600
690d8824
JH
1601_git_log ()
1602{
d773c631
SG
1603 __git_has_doubledash && return
1604
bf3c20f6
TR
1605 local g="$(git rev-parse --git-dir 2>/dev/null)"
1606 local merge=""
ba7906f2 1607 if [ -f "$g/MERGE_HEAD" ]; then
bf3c20f6
TR
1608 merge="--merge"
1609 fi
da48616f
PD
1610 local cur
1611 _get_comp_words_by_ref -n =: cur
6e31b866
SP
1612 case "$cur" in
1613 --pretty=*)
c3898111 1614 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
b3391775 1615 " "" "${cur##--pretty=}"
6e31b866
SP
1616 return
1617 ;;
72de29c2 1618 --format=*)
c3898111 1619 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
72de29c2
TL
1620 " "" "${cur##--format=}"
1621 return
1622 ;;
47e98eec 1623 --date=*)
672c68cb 1624 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
47e98eec
SP
1625 return
1626 ;;
af4e9e8c
SB
1627 --decorate=*)
1628 __gitcomp "long short" "" "${cur##--decorate=}"
1629 return
1630 ;;
6e31b866 1631 --*)
b3391775 1632 __gitcomp "
a393777e
TR
1633 $__git_log_common_options
1634 $__git_log_shortlog_options
1635 $__git_log_gitk_options
8f87fae6 1636 --root --topo-order --date-order --reverse
5d0e6343 1637 --follow --full-diff
6e31b866 1638 --abbrev-commit --abbrev=
47e98eec 1639 --relative-date --date=
72de29c2 1640 --pretty= --format= --oneline
a393777e 1641 --cherry-pick
20827d99 1642 --graph
af4e9e8c 1643 --decorate --decorate=
20bf7292 1644 --walk-reflogs
a393777e 1645 --parents --children
bf3c20f6 1646 $merge
20bf7292 1647 $__git_diff_common_options
47d5a8fa 1648 --pickaxe-all --pickaxe-regex
b3391775 1649 "
6e31b866
SP
1650 return
1651 ;;
1652 esac
f53352fb 1653 __git_complete_revlist
690d8824
JH
1654}
1655
0a4e1472
JS
1656__git_merge_options="
1657 --no-commit --no-stat --log --no-log --squash --strategy
9858b87f 1658 --commit --stat --no-squash --ff --no-ff --ff-only
0a4e1472
JS
1659"
1660
4ad91321
SP
1661_git_merge ()
1662{
3c7b480a
JS
1663 __git_complete_strategy && return
1664
da48616f
PD
1665 local cur
1666 _get_comp_words_by_ref -n =: cur
4ad91321
SP
1667 case "$cur" in
1668 --*)
0a4e1472 1669 __gitcomp "$__git_merge_options"
4ad91321
SP
1670 return
1671 esac
b3391775 1672 __gitcomp "$(__git_refs)"
4ad91321
SP
1673}
1674
b4c72162
LM
1675_git_mergetool ()
1676{
da48616f
PD
1677 local cur
1678 _get_comp_words_by_ref -n =: cur
b4c72162
LM
1679 case "$cur" in
1680 --tool=*)
e2dc2de9 1681 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
b4c72162
LM
1682 return
1683 ;;
1684 --*)
1685 __gitcomp "--tool="
1686 return
1687 ;;
1688 esac
1689 COMPREPLY=()
1690}
1691
690d8824
JH
1692_git_merge_base ()
1693{
b3391775 1694 __gitcomp "$(__git_refs)"
690d8824
JH
1695}
1696
1127c51c
LM
1697_git_mv ()
1698{
da48616f
PD
1699 local cur
1700 _get_comp_words_by_ref -n =: cur
1127c51c
LM
1701 case "$cur" in
1702 --*)
1703 __gitcomp "--dry-run"
1704 return
1705 ;;
1706 esac
1707 COMPREPLY=()
1708}
1709
d33909bf
SP
1710_git_name_rev ()
1711{
b3391775 1712 __gitcomp "--tags --all --stdin"
d33909bf
SP
1713}
1714
00f09d0e
SG
1715_git_notes ()
1716{
2a5da755
SG
1717 local subcommands='add append copy edit list prune remove show'
1718 local subcommand="$(__git_find_on_cmdline "$subcommands")"
02fedc0f
JH
1719 local cur words cword
1720 _get_comp_words_by_ref -n =: cur words cword
00f09d0e 1721
2a5da755
SG
1722 case "$subcommand,$cur" in
1723 ,--*)
1724 __gitcomp '--ref'
1725 ;;
1726 ,*)
02fedc0f 1727 case "${words[cword-1]}" in
2a5da755
SG
1728 --ref)
1729 __gitcomp "$(__git_refs)"
1730 ;;
1731 *)
1732 __gitcomp "$subcommands --ref"
1733 ;;
1734 esac
1735 ;;
1736 add,--reuse-message=*|append,--reuse-message=*)
1737 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1738 ;;
1739 add,--reedit-message=*|append,--reedit-message=*)
1740 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1741 ;;
1742 add,--*|append,--*)
1743 __gitcomp '--file= --message= --reedit-message=
1744 --reuse-message='
1745 ;;
1746 copy,--*)
1747 __gitcomp '--stdin'
1748 ;;
1749 prune,--*)
1750 __gitcomp '--dry-run --verbose'
1751 ;;
1752 prune,*)
00f09d0e
SG
1753 ;;
1754 *)
02fedc0f 1755 case "${words[cword-1]}" in
2a5da755
SG
1756 -m|-F)
1757 ;;
1758 *)
1759 __gitcomp "$(__git_refs)"
1760 ;;
1761 esac
00f09d0e
SG
1762 ;;
1763 esac
1764}
1765
690d8824
JH
1766_git_pull ()
1767{
0a4e1472
JS
1768 __git_complete_strategy && return
1769
da48616f
PD
1770 local cur
1771 _get_comp_words_by_ref -n =: cur
0a4e1472
JS
1772 case "$cur" in
1773 --*)
1774 __gitcomp "
1775 --rebase --no-rebase
1776 $__git_merge_options
1777 $__git_fetch_options
1778 "
1779 return
1780 ;;
1781 esac
52d5c3b5 1782 __git_complete_remote_or_refspec
690d8824
JH
1783}
1784
1785_git_push ()
1786{
da48616f
PD
1787 local cur prev
1788 _get_comp_words_by_ref -n =: cur prev
1789 case "$prev" in
0a4e1472
JS
1790 --repo)
1791 __gitcomp "$(__git_remotes)"
1792 return
1793 esac
1794 case "$cur" in
1795 --repo=*)
1796 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1797 return
1798 ;;
1799 --*)
1800 __gitcomp "
1801 --all --mirror --tags --dry-run --force --verbose
1802 --receive-pack= --repo=
1803 "
1804 return
1805 ;;
1806 esac
52d5c3b5 1807 __git_complete_remote_or_refspec
690d8824
JH
1808}
1809
61d926a3
SP
1810_git_rebase ()
1811{
da48616f
PD
1812 local dir="$(__gitdir)"
1813 local cur
1814 _get_comp_words_by_ref -n =: cur
51ef1daa 1815 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
b3391775 1816 __gitcomp "--continue --skip --abort"
61d926a3
SP
1817 return
1818 fi
3c7b480a 1819 __git_complete_strategy && return
61d926a3 1820 case "$cur" in
93cf50a4
BG
1821 --whitespace=*)
1822 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1823 return
1824 ;;
61d926a3 1825 --*)
93cf50a4
BG
1826 __gitcomp "
1827 --onto --merge --strategy --interactive
1828 --preserve-merges --stat --no-stat
1829 --committer-date-is-author-date --ignore-date
1830 --ignore-whitespace --whitespace=
6d0d465e 1831 --autosquash
93cf50a4
BG
1832 "
1833
61d926a3
SP
1834 return
1835 esac
b3391775 1836 __gitcomp "$(__git_refs)"
61d926a3
SP
1837}
1838
057f3279
TRC
1839_git_reflog ()
1840{
1841 local subcommands="show delete expire"
1842 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1843
1844 if [ -z "$subcommand" ]; then
1845 __gitcomp "$subcommands"
1846 else
1847 __gitcomp "$(__git_refs)"
1848 fi
1849}
1850
ae616de6 1851__git_send_email_confirm_options="always never auto cc compose"
cb8a9bd5 1852__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
ae616de6 1853
25a1f374
TL
1854_git_send_email ()
1855{
da48616f
PD
1856 local cur
1857 _get_comp_words_by_ref -n =: cur
25a1f374 1858 case "$cur" in
ae616de6
SB
1859 --confirm=*)
1860 __gitcomp "
1861 $__git_send_email_confirm_options
1862 " "" "${cur##--confirm=}"
1863 return
1864 ;;
1865 --suppress-cc=*)
1866 __gitcomp "
1867 $__git_send_email_suppresscc_options
1868 " "" "${cur##--suppress-cc=}"
1869
1870 return
1871 ;;
1872 --smtp-encryption=*)
1873 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1874 return
1875 ;;
25a1f374 1876 --*)
77813151 1877 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
ae616de6
SB
1878 --compose --confirm= --dry-run --envelope-sender
1879 --from --identity
25a1f374
TL
1880 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1881 --no-suppress-from --no-thread --quiet
1882 --signed-off-by-cc --smtp-pass --smtp-server
ae616de6
SB
1883 --smtp-server-port --smtp-encryption= --smtp-user
1884 --subject --suppress-cc= --suppress-from --thread --to
fd3a8dcb 1885 --validate --no-validate"
25a1f374
TL
1886 return
1887 ;;
1888 esac
1889 COMPREPLY=()
1890}
1891
424cce83
SG
1892_git_stage ()
1893{
1894 _git_add
1895}
1896
00652369
SB
1897__git_config_get_set_variables ()
1898{
da48616f
PD
1899 local words cword
1900 _get_comp_words_by_ref -n =: words cword
1901 local prevword word config_file= c=$cword
00652369 1902 while [ $c -gt 1 ]; do
da48616f 1903 word="${words[c]}"
00652369
SB
1904 case "$word" in
1905 --global|--system|--file=*)
1906 config_file="$word"
1907 break
1908 ;;
1909 -f|--file)
1910 config_file="$word $prevword"
1911 break
1912 ;;
1913 esac
1914 prevword=$word
1915 c=$((--c))
1916 done
1917
f581de1b
SB
1918 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1919 while read line
1920 do
1921 case "$line" in
1922 *.*=*)
1923 echo "${line/=*/}"
00652369
SB
1924 ;;
1925 esac
1926 done
1927}
1928
e0d10e1c 1929_git_config ()
5de40f59 1930{
da48616f
PD
1931 local cur prev
1932 _get_comp_words_by_ref -n =: cur prev
1933 case "$prev" in
5de40f59 1934 branch.*.remote)
78d4d6a2 1935 __gitcomp "$(__git_remotes)"
5de40f59
SP
1936 return
1937 ;;
1938 branch.*.merge)
78d4d6a2 1939 __gitcomp "$(__git_refs)"
5de40f59
SP
1940 return
1941 ;;
1942 remote.*.fetch)
da48616f 1943 local remote="${prev#remote.}"
5de40f59 1944 remote="${remote%.fetch}"
78d4d6a2 1945 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
1946 return
1947 ;;
1948 remote.*.push)
da48616f 1949 local remote="${prev#remote.}"
5de40f59 1950 remote="${remote%.push}"
78d4d6a2 1951 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 1952 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
1953 refs/heads)"
1954 return
1955 ;;
1956 pull.twohead|pull.octopus)
eaa4e6ee
JN
1957 __git_compute_merge_strategies
1958 __gitcomp "$__git_merge_strategies"
78d4d6a2
SP
1959 return
1960 ;;
6123d719
MH
1961 color.branch|color.diff|color.interactive|\
1962 color.showbranch|color.status|color.ui)
78d4d6a2
SP
1963 __gitcomp "always never auto"
1964 return
1965 ;;
901d615c
MK
1966 color.pager)
1967 __gitcomp "false true"
1968 return
1969 ;;
78d4d6a2
SP
1970 color.*.*)
1971 __gitcomp "
98171a07 1972 normal black red green yellow blue magenta cyan white
78d4d6a2
SP
1973 bold dim ul blink reverse
1974 "
5de40f59
SP
1975 return
1976 ;;
9b82d63b
SB
1977 help.format)
1978 __gitcomp "man info web html"
1979 return
1980 ;;
672c68cb
SB
1981 log.date)
1982 __gitcomp "$__git_log_date_formats"
1983 return
1984 ;;
ae616de6
SB
1985 sendemail.aliasesfiletype)
1986 __gitcomp "mutt mailrc pine elm gnus"
1987 return
1988 ;;
1989 sendemail.confirm)
1990 __gitcomp "$__git_send_email_confirm_options"
1991 return
1992 ;;
1993 sendemail.suppresscc)
1994 __gitcomp "$__git_send_email_suppresscc_options"
1995 return
1996 ;;
00652369
SB
1997 --get|--get-all|--unset|--unset-all)
1998 __gitcomp "$(__git_config_get_set_variables)"
1999 return
2000 ;;
5de40f59
SP
2001 *.*)
2002 COMPREPLY=()
2003 return
2004 ;;
2005 esac
2006 case "$cur" in
2007 --*)
78d4d6a2 2008 __gitcomp "
47e98eec 2009 --global --system --file=
12977705 2010 --list --replace-all
5de40f59 2011 --get --get-all --get-regexp
1b71eb35 2012 --add --unset --unset-all
12977705 2013 --remove-section --rename-section
78d4d6a2 2014 "
5de40f59
SP
2015 return
2016 ;;
2017 branch.*.*)
9244d69b
SG
2018 local pfx="${cur%.*}." cur_="${cur##*.}"
2019 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
5de40f59
SP
2020 return
2021 ;;
2022 branch.*)
9244d69b
SG
2023 local pfx="${cur%.*}." cur_="${cur#*.}"
2024 __gitcomp "$(__git_heads)" "$pfx" "$cur_" "."
5de40f59
SP
2025 return
2026 ;;
0aa62fd0 2027 guitool.*.*)
9244d69b 2028 local pfx="${cur%.*}." cur_="${cur##*.}"
0aa62fd0
SB
2029 __gitcomp "
2030 argprompt cmd confirm needsfile noconsole norescan
2031 prompt revprompt revunmerged title
9244d69b 2032 " "$pfx" "$cur_"
0aa62fd0
SB
2033 return
2034 ;;
2035 difftool.*.*)
9244d69b
SG
2036 local pfx="${cur%.*}." cur_="${cur##*.}"
2037 __gitcomp "cmd path" "$pfx" "$cur_"
0aa62fd0
SB
2038 return
2039 ;;
2040 man.*.*)
9244d69b
SG
2041 local pfx="${cur%.*}." cur_="${cur##*.}"
2042 __gitcomp "cmd path" "$pfx" "$cur_"
0aa62fd0
SB
2043 return
2044 ;;
2045 mergetool.*.*)
9244d69b
SG
2046 local pfx="${cur%.*}." cur_="${cur##*.}"
2047 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
0aa62fd0
SB
2048 return
2049 ;;
2050 pager.*)
9244d69b 2051 local pfx="${cur%.*}." cur_="${cur#*.}"
eaa4e6ee 2052 __git_compute_all_commands
9244d69b 2053 __gitcomp "$__git_all_commands" "$pfx" "$cur_"
0aa62fd0
SB
2054 return
2055 ;;
5de40f59 2056 remote.*.*)
9244d69b 2057 local pfx="${cur%.*}." cur_="${cur##*.}"
12977705 2058 __gitcomp "
98171a07 2059 url proxy fetch push mirror skipDefaultUpdate
6fac1b83 2060 receivepack uploadpack tagopt pushurl
9244d69b 2061 " "$pfx" "$cur_"
5de40f59
SP
2062 return
2063 ;;
2064 remote.*)
9244d69b
SG
2065 local pfx="${cur%.*}." cur_="${cur#*.}"
2066 __gitcomp "$(__git_remotes)" "$pfx" "$cur_" "."
5de40f59
SP
2067 return
2068 ;;
0aa62fd0 2069 url.*.*)
9244d69b
SG
2070 local pfx="${cur%.*}." cur_="${cur##*.}"
2071 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
0aa62fd0
SB
2072 return
2073 ;;
5de40f59 2074 esac
78d4d6a2 2075 __gitcomp "
6068ac88
MZ
2076 add.ignoreErrors
2077 advice.commitBeforeMerge
2078 advice.detachedHead
2079 advice.implicitIdentity
2080 advice.pushNonFastForward
2081 advice.resolveConflict
2082 advice.statusHints
226b343c 2083 alias.
6068ac88 2084 am.keepcr
86c91f91 2085 apply.ignorewhitespace
5de40f59 2086 apply.whitespace
98171a07
LM
2087 branch.autosetupmerge
2088 branch.autosetuprebase
6068ac88 2089 browser.
2122591b 2090 clean.requireForce
78d4d6a2
SP
2091 color.branch
2092 color.branch.current
2093 color.branch.local
78d4d6a2 2094 color.branch.plain
025a1929 2095 color.branch.remote
6068ac88
MZ
2096 color.decorate.HEAD
2097 color.decorate.branch
2098 color.decorate.remoteBranch
2099 color.decorate.stash
2100 color.decorate.tag
a159ca0c 2101 color.diff
025a1929 2102 color.diff.commit
78d4d6a2 2103 color.diff.frag
6068ac88 2104 color.diff.func
025a1929 2105 color.diff.meta
78d4d6a2 2106 color.diff.new
025a1929
LM
2107 color.diff.old
2108 color.diff.plain
78d4d6a2 2109 color.diff.whitespace
226b343c 2110 color.grep
6068ac88
MZ
2111 color.grep.context
2112 color.grep.filename
2113 color.grep.function
2114 color.grep.linenumber
226b343c 2115 color.grep.match
6068ac88
MZ
2116 color.grep.selected
2117 color.grep.separator
98171a07 2118 color.interactive
6068ac88 2119 color.interactive.error
98171a07
LM
2120 color.interactive.header
2121 color.interactive.help
2122 color.interactive.prompt
a159ca0c 2123 color.pager
6123d719 2124 color.showbranch
a159ca0c 2125 color.status
78d4d6a2
SP
2126 color.status.added
2127 color.status.changed
025a1929 2128 color.status.header
98171a07 2129 color.status.nobranch
78d4d6a2 2130 color.status.untracked
98171a07
LM
2131 color.status.updated
2132 color.ui
6068ac88 2133 commit.status
98171a07 2134 commit.template
6068ac88
MZ
2135 core.abbrevguard
2136 core.askpass
2137 core.attributesfile
98171a07
LM
2138 core.autocrlf
2139 core.bare
6068ac88 2140 core.bigFileThreshold
025a1929 2141 core.compression
226b343c 2142 core.createObject
98171a07
LM
2143 core.deltaBaseCacheLimit
2144 core.editor
6068ac88 2145 core.eol
98171a07 2146 core.excludesfile
025a1929 2147 core.fileMode
98171a07 2148 core.fsyncobjectfiles
025a1929 2149 core.gitProxy
98171a07 2150 core.ignoreCygwinFSTricks
025a1929 2151 core.ignoreStat
6068ac88 2152 core.ignorecase
025a1929
LM
2153 core.logAllRefUpdates
2154 core.loosecompression
6068ac88 2155 core.notesRef
025a1929
LM
2156 core.packedGitLimit
2157 core.packedGitWindowSize
98171a07 2158 core.pager
025a1929 2159 core.preferSymlinkRefs
98171a07
LM
2160 core.preloadindex
2161 core.quotepath
025a1929 2162 core.repositoryFormatVersion
98171a07 2163 core.safecrlf
025a1929 2164 core.sharedRepository
6068ac88 2165 core.sparseCheckout
98171a07
LM
2166 core.symlinks
2167 core.trustctime
025a1929 2168 core.warnAmbiguousRefs
98171a07
LM
2169 core.whitespace
2170 core.worktree
2171 diff.autorefreshindex
2172 diff.external
6068ac88 2173 diff.ignoreSubmodules
98171a07 2174 diff.mnemonicprefix
6068ac88 2175 diff.noprefix
78d4d6a2
SP
2176 diff.renameLimit
2177 diff.renames
226b343c
SB
2178 diff.suppressBlankEmpty
2179 diff.tool
2180 diff.wordRegex
0aa62fd0 2181 difftool.
226b343c 2182 difftool.prompt
6068ac88 2183 fetch.recurseSubmodules
78d4d6a2 2184 fetch.unpackLimit
226b343c
SB
2185 format.attach
2186 format.cc
78d4d6a2 2187 format.headers
98171a07
LM
2188 format.numbered
2189 format.pretty
d8e1e5df 2190 format.signature
226b343c
SB
2191 format.signoff
2192 format.subjectprefix
98171a07 2193 format.suffix
226b343c 2194 format.thread
6068ac88
MZ
2195 format.to
2196 gc.
98171a07
LM
2197 gc.aggressiveWindow
2198 gc.auto
2199 gc.autopacklimit
12977705 2200 gc.packrefs
98171a07 2201 gc.pruneexpire
78d4d6a2
SP
2202 gc.reflogexpire
2203 gc.reflogexpireunreachable
2204 gc.rerereresolved
2205 gc.rerereunresolved
025a1929 2206 gitcvs.allbinary
226b343c 2207 gitcvs.commitmsgannotation
98171a07 2208 gitcvs.dbTableNamePrefix
025a1929
LM
2209 gitcvs.dbdriver
2210 gitcvs.dbname
2211 gitcvs.dbpass
025a1929
LM
2212 gitcvs.dbuser
2213 gitcvs.enabled
2214 gitcvs.logfile
98171a07 2215 gitcvs.usecrlfattr
0aa62fd0 2216 guitool.
98171a07
LM
2217 gui.blamehistoryctx
2218 gui.commitmsgwidth
2219 gui.copyblamethreshold
2220 gui.diffcontext
2221 gui.encoding
2222 gui.fastcopyblame
2223 gui.matchtrackingbranch
2224 gui.newbranchtemplate
2225 gui.pruneduringfetch
2226 gui.spellingdictionary
2227 gui.trustmtime
2228 help.autocorrect
2229 help.browser
2230 help.format
78d4d6a2
SP
2231 http.lowSpeedLimit
2232 http.lowSpeedTime
025a1929 2233 http.maxRequests
6068ac88 2234 http.minSessions
5de40f59 2235 http.noEPSV
6068ac88 2236 http.postBuffer
98171a07 2237 http.proxy
025a1929
LM
2238 http.sslCAInfo
2239 http.sslCAPath
2240 http.sslCert
6068ac88 2241 http.sslCertPasswordProtected
025a1929
LM
2242 http.sslKey
2243 http.sslVerify
6068ac88 2244 http.useragent
78d4d6a2
SP
2245 i18n.commitEncoding
2246 i18n.logOutputEncoding
6068ac88 2247 imap.authMethod
226b343c
SB
2248 imap.folder
2249 imap.host
2250 imap.pass
2251 imap.port
2252 imap.preformattedHTML
2253 imap.sslverify
2254 imap.tunnel
2255 imap.user
6068ac88 2256 init.templatedir
98171a07
LM
2257 instaweb.browser
2258 instaweb.httpd
2259 instaweb.local
2260 instaweb.modulepath
2261 instaweb.port
226b343c 2262 interactive.singlekey
98171a07 2263 log.date
6068ac88 2264 log.decorate
78d4d6a2 2265 log.showroot
226b343c 2266 mailmap.file
0aa62fd0 2267 man.
98171a07 2268 man.viewer
6068ac88 2269 merge.
98171a07
LM
2270 merge.conflictstyle
2271 merge.log
2272 merge.renameLimit
6068ac88 2273 merge.renormalize
98171a07 2274 merge.stat
025a1929 2275 merge.tool
78d4d6a2 2276 merge.verbosity
0aa62fd0 2277 mergetool.
98171a07 2278 mergetool.keepBackup
6068ac88 2279 mergetool.keepTemporaries
226b343c 2280 mergetool.prompt
6068ac88
MZ
2281 notes.displayRef
2282 notes.rewrite.
2283 notes.rewrite.amend
2284 notes.rewrite.rebase
2285 notes.rewriteMode
2286 notes.rewriteRef
47e98eec 2287 pack.compression
47e98eec 2288 pack.deltaCacheLimit
025a1929
LM
2289 pack.deltaCacheSize
2290 pack.depth
98171a07
LM
2291 pack.indexVersion
2292 pack.packSizeLimit
2293 pack.threads
025a1929
LM
2294 pack.window
2295 pack.windowMemory
0aa62fd0 2296 pager.
6068ac88 2297 pretty.
78d4d6a2
SP
2298 pull.octopus
2299 pull.twohead
226b343c 2300 push.default
6068ac88 2301 rebase.autosquash
226b343c 2302 rebase.stat
6068ac88 2303 receive.autogc
98171a07 2304 receive.denyCurrentBranch
6068ac88 2305 receive.denyDeleteCurrent
98171a07 2306 receive.denyDeletes
025a1929 2307 receive.denyNonFastForwards
98171a07 2308 receive.fsckObjects
025a1929 2309 receive.unpackLimit
6068ac88
MZ
2310 receive.updateserverinfo
2311 remotes.
98171a07
LM
2312 repack.usedeltabaseoffset
2313 rerere.autoupdate
2314 rerere.enabled
6068ac88 2315 sendemail.
226b343c 2316 sendemail.aliasesfile
6068ac88 2317 sendemail.aliasfiletype
226b343c
SB
2318 sendemail.bcc
2319 sendemail.cc
2320 sendemail.cccmd
2321 sendemail.chainreplyto
2322 sendemail.confirm
2323 sendemail.envelopesender
6068ac88
MZ
2324 sendemail.from
2325 sendemail.identity
226b343c
SB
2326 sendemail.multiedit
2327 sendemail.signedoffbycc
6068ac88 2328 sendemail.smtpdomain
226b343c
SB
2329 sendemail.smtpencryption
2330 sendemail.smtppass
2331 sendemail.smtpserver
6068ac88 2332 sendemail.smtpserveroption
226b343c
SB
2333 sendemail.smtpserverport
2334 sendemail.smtpuser
2335 sendemail.suppresscc
2336 sendemail.suppressfrom
2337 sendemail.thread
2338 sendemail.to
2339 sendemail.validate
78d4d6a2 2340 showbranch.default
98171a07
LM
2341 status.relativePaths
2342 status.showUntrackedFiles
6068ac88
MZ
2343 status.submodulesummary
2344 submodule.
78d4d6a2
SP
2345 tar.umask
2346 transfer.unpackLimit
0aa62fd0 2347 url.
78d4d6a2 2348 user.email
025a1929 2349 user.name
78d4d6a2 2350 user.signingkey
98171a07 2351 web.browser
5de40f59 2352 branch. remote.
78d4d6a2 2353 "
5de40f59
SP
2354}
2355
88293c67
SP
2356_git_remote ()
2357{
bc14fac8 2358 local subcommands="add rename rm show prune update set-head"
918c03c2 2359 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3ff1320d 2360 if [ -z "$subcommand" ]; then
3903c618 2361 __gitcomp "$subcommands"
88293c67
SP
2362 return
2363 fi
2364
3ff1320d 2365 case "$subcommand" in
f135e72d 2366 rename|rm|show|prune)
88293c67
SP
2367 __gitcomp "$(__git_remotes)"
2368 ;;
fb72759b
SP
2369 update)
2370 local i c='' IFS=$'\n'
518ef8f0
TZ
2371 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2372 i="${i#remotes.}"
2373 c="$c ${i/ */}"
fb72759b
SP
2374 done
2375 __gitcomp "$c"
2376 ;;
88293c67
SP
2377 *)
2378 COMPREPLY=()
2379 ;;
2380 esac
2381}
2382
e1c1a067
BG
2383_git_replace ()
2384{
2385 __gitcomp "$(__git_refs)"
2386}
2387
67e78c3b
SP
2388_git_reset ()
2389{
d773c631
SG
2390 __git_has_doubledash && return
2391
da48616f
PD
2392 local cur
2393 _get_comp_words_by_ref -n =: cur
b3391775
SP
2394 case "$cur" in
2395 --*)
9f040e95 2396 __gitcomp "--merge --mixed --hard --soft --patch"
b3391775
SP
2397 return
2398 ;;
2399 esac
2400 __gitcomp "$(__git_refs)"
67e78c3b
SP
2401}
2402
a6c2be24
LM
2403_git_revert ()
2404{
da48616f
PD
2405 local cur
2406 _get_comp_words_by_ref -n =: cur
a6c2be24
LM
2407 case "$cur" in
2408 --*)
2409 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2410 return
2411 ;;
2412 esac
c0783837 2413 __gitcomp "$(__git_refs)"
a6c2be24
LM
2414}
2415
08c701d4
LM
2416_git_rm ()
2417{
2418 __git_has_doubledash && return
2419
da48616f
PD
2420 local cur
2421 _get_comp_words_by_ref -n =: cur
08c701d4
LM
2422 case "$cur" in
2423 --*)
2424 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2425 return
2426 ;;
2427 esac
2428 COMPREPLY=()
2429}
2430
1fd6bec9
SP
2431_git_shortlog ()
2432{
d773c631
SG
2433 __git_has_doubledash && return
2434
da48616f
PD
2435 local cur
2436 _get_comp_words_by_ref -n =: cur
1fd6bec9
SP
2437 case "$cur" in
2438 --*)
2439 __gitcomp "
a393777e
TR
2440 $__git_log_common_options
2441 $__git_log_shortlog_options
1fd6bec9
SP
2442 --numbered --summary
2443 "
2444 return
2445 ;;
2446 esac
2447 __git_complete_revlist
2448}
2449
90131924
SP
2450_git_show ()
2451{
41d8cf7d
MH
2452 __git_has_doubledash && return
2453
da48616f
PD
2454 local cur
2455 _get_comp_words_by_ref -n =: cur
90131924
SP
2456 case "$cur" in
2457 --pretty=*)
c3898111 2458 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
b3391775 2459 " "" "${cur##--pretty=}"
90131924
SP
2460 return
2461 ;;
72de29c2 2462 --format=*)
c3898111 2463 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
72de29c2
TL
2464 " "" "${cur##--format=}"
2465 return
2466 ;;
90131924 2467 --*)
076c3237 2468 __gitcomp "--pretty= --format= --abbrev-commit --oneline
20bf7292
TR
2469 $__git_diff_common_options
2470 "
90131924
SP
2471 return
2472 ;;
2473 esac
2474 __git_complete_file
2475}
2476
2ca880fe
TR
2477_git_show_branch ()
2478{
da48616f
PD
2479 local cur
2480 _get_comp_words_by_ref -n =: cur
2ca880fe
TR
2481 case "$cur" in
2482 --*)
2483 __gitcomp "
2484 --all --remotes --topo-order --current --more=
2485 --list --independent --merge-base --no-name
6123d719 2486 --color --no-color
076c3237 2487 --sha1-name --sparse --topics --reflog
2ca880fe
TR
2488 "
2489 return
2490 ;;
2491 esac
2492 __git_complete_revlist
2493}
2494
7fd53fce
JH
2495_git_stash ()
2496{
da48616f
PD
2497 local cur
2498 _get_comp_words_by_ref -n =: cur
59d5eeee 2499 local save_opts='--keep-index --no-keep-index --quiet --patch'
95d43780 2500 local subcommands='save list show apply clear drop pop create branch'
918c03c2 2501 local subcommand="$(__git_find_on_cmdline "$subcommands")"
7bedebca 2502 if [ -z "$subcommand" ]; then
59d5eeee
SG
2503 case "$cur" in
2504 --*)
2505 __gitcomp "$save_opts"
2506 ;;
2507 *)
2508 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2509 __gitcomp "$subcommands"
2510 else
2511 COMPREPLY=()
2512 fi
2513 ;;
2514 esac
7bedebca 2515 else
7bedebca
SG
2516 case "$subcommand,$cur" in
2517 save,--*)
59d5eeee 2518 __gitcomp "$save_opts"
7bedebca 2519 ;;
8513c54b 2520 apply,--*|pop,--*)
59d5eeee 2521 __gitcomp "--index --quiet"
95d43780 2522 ;;
8513c54b 2523 show,--*|drop,--*|branch,--*)
95d43780
LM
2524 COMPREPLY=()
2525 ;;
2526 show,*|apply,*|drop,*|pop,*|branch,*)
2527 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2528 | sed -n -e 's/:.*//p')"
2529 ;;
7bedebca
SG
2530 *)
2531 COMPREPLY=()
2532 ;;
2533 esac
3ff1320d 2534 fi
7fd53fce
JH
2535}
2536
be86f7a0
SP
2537_git_submodule ()
2538{
d773c631
SG
2539 __git_has_doubledash && return
2540
1b0f7978 2541 local subcommands="add status init update summary foreach sync"
918c03c2 2542 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
da48616f
PD
2543 local cur
2544 _get_comp_words_by_ref -n =: cur
be86f7a0
SP
2545 case "$cur" in
2546 --*)
2547 __gitcomp "--quiet --cached"
2548 ;;
2549 *)
3ff1320d 2550 __gitcomp "$subcommands"
be86f7a0
SP
2551 ;;
2552 esac
2553 return
2554 fi
2555}
2556
47f6ee28
SG
2557_git_svn ()
2558{
2559 local subcommands="
2560 init fetch clone rebase dcommit log find-rev
2561 set-tree commit-diff info create-ignore propget
4a5856cb 2562 proplist show-ignore show-externals branch tag blame
c18d5d82 2563 migrate mkdirs reset gc
47f6ee28 2564 "
918c03c2 2565 local subcommand="$(__git_find_on_cmdline "$subcommands")"
47f6ee28
SG
2566 if [ -z "$subcommand" ]; then
2567 __gitcomp "$subcommands"
2568 else
2569 local remote_opts="--username= --config-dir= --no-auth-cache"
2570 local fc_opts="
2571 --follow-parent --authors-file= --repack=
2572 --no-metadata --use-svm-props --use-svnsync-props
2573 --log-window-size= --no-checkout --quiet
4a5856cb
SG
2574 --repack-flags --use-log-author --localtime
2575 --ignore-paths= $remote_opts
47f6ee28
SG
2576 "
2577 local init_opts="
2578 --template= --shared= --trunk= --tags=
2579 --branches= --stdlayout --minimize-url
2580 --no-metadata --use-svm-props --use-svnsync-props
4a5856cb
SG
2581 --rewrite-root= --prefix= --use-log-author
2582 --add-author-from $remote_opts
47f6ee28
SG
2583 "
2584 local cmt_opts="
2585 --edit --rmdir --find-copies-harder --copy-similarity=
2586 "
2587
da48616f
PD
2588 local cur
2589 _get_comp_words_by_ref -n =: cur
47f6ee28
SG
2590 case "$subcommand,$cur" in
2591 fetch,--*)
2592 __gitcomp "--revision= --fetch-all $fc_opts"
2593 ;;
2594 clone,--*)
2595 __gitcomp "--revision= $fc_opts $init_opts"
2596 ;;
2597 init,--*)
2598 __gitcomp "$init_opts"
2599 ;;
2600 dcommit,--*)
2601 __gitcomp "
2602 --merge --strategy= --verbose --dry-run
4a5856cb
SG
2603 --fetch-all --no-rebase --commit-url
2604 --revision $cmt_opts $fc_opts
47f6ee28
SG
2605 "
2606 ;;
2607 set-tree,--*)
2608 __gitcomp "--stdin $cmt_opts $fc_opts"
2609 ;;
2610 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
c18d5d82 2611 show-externals,--*|mkdirs,--*)
47f6ee28
SG
2612 __gitcomp "--revision="
2613 ;;
2614 log,--*)
2615 __gitcomp "
2616 --limit= --revision= --verbose --incremental
2617 --oneline --show-commit --non-recursive
4a5856cb 2618 --authors-file= --color
47f6ee28
SG
2619 "
2620 ;;
2621 rebase,--*)
2622 __gitcomp "
2623 --merge --verbose --strategy= --local
4a5856cb 2624 --fetch-all --dry-run $fc_opts
47f6ee28
SG
2625 "
2626 ;;
2627 commit-diff,--*)
2628 __gitcomp "--message= --file= --revision= $cmt_opts"
2629 ;;
2630 info,--*)
2631 __gitcomp "--url"
2632 ;;
4a5856cb
SG
2633 branch,--*)
2634 __gitcomp "--dry-run --message --tag"
2635 ;;
2636 tag,--*)
2637 __gitcomp "--dry-run --message"
2638 ;;
2639 blame,--*)
2640 __gitcomp "--git-format"
2641 ;;
2642 migrate,--*)
2643 __gitcomp "
2644 --config-dir= --ignore-paths= --minimize
2645 --no-auth-cache --username=
2646 "
2647 ;;
c18d5d82
RZ
2648 reset,--*)
2649 __gitcomp "--revision= --parent"
2650 ;;
47f6ee28
SG
2651 *)
2652 COMPREPLY=()
2653 ;;
2654 esac
2655 fi
2656}
2657
88e21dc7
SP
2658_git_tag ()
2659{
2660 local i c=1 f=0
da48616f
PD
2661 local words cword prev
2662 _get_comp_words_by_ref -n =: words cword prev
2663 while [ $c -lt $cword ]; do
2664 i="${words[c]}"
88e21dc7
SP
2665 case "$i" in
2666 -d|-v)
2667 __gitcomp "$(__git_tags)"
2668 return
2669 ;;
2670 -f)
2671 f=1
2672 ;;
2673 esac
2674 c=$((++c))
2675 done
2676
da48616f 2677 case "$prev" in
88e21dc7
SP
2678 -m|-F)
2679 COMPREPLY=()
2680 ;;
8d8163f3 2681 -*|tag)
88e21dc7
SP
2682 if [ $f = 1 ]; then
2683 __gitcomp "$(__git_tags)"
2684 else
2685 COMPREPLY=()
2686 fi
2687 ;;
2688 *)
2689 __gitcomp "$(__git_refs)"
2690 ;;
2691 esac
2692}
2693
424cce83
SG
2694_git_whatchanged ()
2695{
2696 _git_log
2697}
2698
690d8824
JH
2699_git ()
2700{
873537fa
SP
2701 local i c=1 command __git_dir
2702
ca209065 2703 if [[ -n ${ZSH_VERSION-} ]]; then
06f44c3c
ML
2704 emulate -L bash
2705 setopt KSH_TYPESET
2706 fi
2707
da48616f
PD
2708 local cur words cword
2709 _get_comp_words_by_ref -n =: cur words cword
2710 while [ $c -lt $cword ]; do
2711 i="${words[c]}"
873537fa
SP
2712 case "$i" in
2713 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2714 --bare) __git_dir="." ;;
1eb7e2f8
LM
2715 --version|-p|--paginate) ;;
2716 --help) command="help"; break ;;
873537fa
SP
2717 *) command="$i"; break ;;
2718 esac
2719 c=$((++c))
2720 done
2721
1d17b22e 2722 if [ -z "$command" ]; then
da48616f 2723 case "$cur" in
47e98eec 2724 --*) __gitcomp "
ce5a2c95 2725 --paginate
47e98eec
SP
2726 --no-pager
2727 --git-dir=
2728 --bare
2729 --version
2730 --exec-path
89a56bfb 2731 --html-path
ce5a2c95
TL
2732 --work-tree=
2733 --help
47e98eec
SP
2734 "
2735 ;;
eaa4e6ee
JN
2736 *) __git_compute_porcelain_commands
2737 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
72e5e989
SP
2738 esac
2739 return
873537fa 2740 fi
367dce2a 2741
424cce83 2742 local completion_func="_git_${command//-/_}"
06f44c3c 2743 declare -f $completion_func >/dev/null && $completion_func && return
8024ea60 2744
873537fa 2745 local expansion=$(__git_aliased_command "$command")
8024ea60
SG
2746 if [ -n "$expansion" ]; then
2747 completion_func="_git_${expansion//-/_}"
06f44c3c 2748 declare -f $completion_func >/dev/null && $completion_func
8024ea60 2749 fi
690d8824
JH
2750}
2751
2752_gitk ()
2753{
ca209065 2754 if [[ -n ${ZSH_VERSION-} ]]; then
06f44c3c
ML
2755 emulate -L bash
2756 setopt KSH_TYPESET
2757 fi
2758
d773c631
SG
2759 __git_has_doubledash && return
2760
da48616f 2761 local cur
fa26a401 2762 local g="$(__gitdir)"
07ba53f7 2763 local merge=""
ba7906f2 2764 if [ -f "$g/MERGE_HEAD" ]; then
07ba53f7
RQ
2765 merge="--merge"
2766 fi
da48616f 2767 _get_comp_words_by_ref -n =: cur
b3391775
SP
2768 case "$cur" in
2769 --*)
a393777e
TR
2770 __gitcomp "
2771 $__git_log_common_options
2772 $__git_log_gitk_options
2773 $merge
2774 "
b3391775
SP
2775 return
2776 ;;
2777 esac
ec804891 2778 __git_complete_revlist
690d8824
JH
2779}
2780
50e126e1
TP
2781complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2782 || complete -o default -o nospace -F _git git
2783complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2784 || complete -o default -o nospace -F _gitk gitk
690d8824
JH
2785
2786# The following are necessary only for Cygwin, and only are needed
2787# when the user has tab-completed the executable name and consequently
2788# included the '.exe' suffix.
2789#
76c3eb51 2790if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
50e126e1
TP
2791complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2792 || complete -o default -o nospace -F _git git.exe
76c3eb51 2793fi
06f44c3c 2794
ca209065 2795if [[ -n ${ZSH_VERSION-} ]]; then
06f44c3c
ML
2796 shopt () {
2797 local option
2798 if [ $# -ne 2 ]; then
2799 echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2800 return 1
2801 fi
2802 case "$2" in
2803 nullglob)
2804 option="$2"
2805 ;;
2806 *)
2807 echo "$0: invalid option: $2" >&2
2808 return 1
2809 esac
2810 case "$1" in
2811 -q) setopt | grep -q "$option" ;;
2812 -u) unsetopt "$option" ;;
2813 -s) setopt "$option" ;;
2814 *)
2815 echo "$0: invalid flag: $1" >&2
2816 return 1
2817 esac
2818 }
2819fi