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