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