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