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