completion: __git_config_get_set_variables() handle values with spaces
[git/git.git] / contrib / completion / git-completion.bash
CommitLineData
a42577d4 1#!bash
690d8824
JH
2#
3# bash completion support for core Git.
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).
21# 2) Added the following line to your .bashrc:
22# source ~/.git-completion.sh
23#
b51ec6bd
SP
24# 3) You may want to make sure the git executable is available
25# in your PATH before this script is sourced, as some caching
26# is performed while the script loads. If git isn't found
27# at source time then all lookups will be done on demand,
28# which may be slightly slower.
29#
30# 4) Consider changing your PS1 to also show the current branch:
d3d717a4
SP
31# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
32#
33# The argument to __git_ps1 will be displayed only if you
34# are currently in a git repository. The %s token will be
35# the name of the current branch.
36#
a9ee90d7
TP
37# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
38# value, unstaged (*) and staged (+) changes will be shown next
39# to the branch name. You can configure this per-repository
40# with the bash.showDirtyState variable, which defaults to true
41# once GIT_PS1_SHOWDIRTYSTATE is enabled.
738a94a9 42#
2414b45c
DT
43# You can also see if currently something is stashed, by setting
44# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
45# then a '$' will be shown next to the branch name.
46#
c70680ce
SP
47# To submit patches:
48#
49# *) Read Documentation/SubmittingPatches
50# *) Send all patches to the current maintainer:
51#
52# "Shawn O. Pearce" <spearce@spearce.org>
53#
54# *) Always CC the Git mailing list:
55#
56# git@vger.kernel.org
57#
690d8824 58
db8a9ff0
SP
59case "$COMP_WORDBREAKS" in
60*:*) : great ;;
61*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
62esac
63
a42577d4
TP
64# __gitdir accepts 0 or 1 arguments (i.e., location)
65# returns location of .git repo
873537fa
SP
66__gitdir ()
67{
25a31f81 68 if [ -z "${1-}" ]; then
5c9cc64a 69 if [ -n "${__git_dir-}" ]; then
67ffa114
SP
70 echo "$__git_dir"
71 elif [ -d .git ]; then
72 echo .git
73 else
74 git rev-parse --git-dir 2>/dev/null
75 fi
76 elif [ -d "$1/.git" ]; then
77 echo "$1/.git"
78 else
79 echo "$1"
80 fi
873537fa
SP
81}
82
a42577d4
TP
83# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
84# returns text to add to bash PS1 prompt (includes branch name)
d3d717a4
SP
85__git_ps1 ()
86{
fa26a401 87 local g="$(__gitdir)"
e7520196
RR
88 if [ -n "$g" ]; then
89 local r
90 local b
d7107ca6 91 if [ -f "$g/rebase-merge/interactive" ]; then
e7520196 92 r="|REBASE-i"
28ed6e7b 93 b="$(cat "$g/rebase-merge/head-name")"
ad244d25 94 elif [ -d "$g/rebase-merge" ]; then
e7520196 95 r="|REBASE-m"
28ed6e7b 96 b="$(cat "$g/rebase-merge/head-name")"
e7520196 97 else
d7107ca6
JH
98 if [ -d "$g/rebase-apply" ]; then
99 if [ -f "$g/rebase-apply/rebasing" ]; then
100 r="|REBASE"
101 elif [ -f "$g/rebase-apply/applying" ]; then
102 r="|AM"
103 else
104 r="|AM/REBASE"
105 fi
106 elif [ -f "$g/MERGE_HEAD" ]; then
8763dbb1 107 r="|MERGING"
d7107ca6 108 elif [ -f "$g/BISECT_LOG" ]; then
e7520196
RR
109 r="|BISECTING"
110 fi
ff790b6a
JH
111
112 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
dd42c2f0
JH
113
114 b="$(
115 case "${GIT_PS1_DESCRIBE_STYLE-}" in
116 (contains)
117 git describe --contains HEAD ;;
118 (branch)
119 git describe --contains --all HEAD ;;
120 (describe)
121 git describe HEAD ;;
122 (* | default)
123 git describe --exact-match HEAD ;;
124 esac 2>/dev/null)" ||
125
ff790b6a
JH
126 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
127 b="unknown"
ff790b6a
JH
128 b="($b)"
129 }
e7520196
RR
130 fi
131
738a94a9
TR
132 local w
133 local i
2414b45c 134 local s
ddb6d010 135 local c
738a94a9 136
e5dd864a 137 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
8dfb17e1 138 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
ddb6d010
MSO
139 c="BARE:"
140 else
141 b="GIT_DIR!"
142 fi
e5dd864a
TP
143 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
144 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
145 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
146 git diff --no-ext-diff --ignore-submodules \
147 --quiet --exit-code || w="*"
148 if git rev-parse --quiet --verify HEAD >/dev/null; then
149 git diff-index --cached --quiet \
150 --ignore-submodules HEAD -- || i="+"
151 else
152 i="#"
153 fi
738a94a9
TR
154 fi
155 fi
2414b45c
DT
156 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
157 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
158 fi
738a94a9
TR
159 fi
160
ee6b7114 161 if [ -n "${1-}" ]; then
2414b45c 162 printf "$1" "$c${b##refs/heads/}$w$i$s$r"
ee6b7114 163 else
2414b45c 164 printf " (%s)" "$c${b##refs/heads/}$w$i$s$r"
d3d717a4
SP
165 fi
166 fi
167}
168
a42577d4 169# __gitcomp_1 requires 2 arguments
ab02dfe5
SP
170__gitcomp_1 ()
171{
172 local c IFS=' '$'\t'$'\n'
173 for c in $1; do
174 case "$c$2" in
175 --*=*) printf %s$'\n' "$c$2" ;;
176 *.) printf %s$'\n' "$c$2" ;;
177 *) printf %s$'\n' "$c$2 " ;;
178 esac
179 done
180}
181
a42577d4
TP
182# __gitcomp accepts 1, 2, 3, or 4 arguments
183# generates completion reply with compgen
72e5e989
SP
184__gitcomp ()
185{
78d4d6a2 186 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775 187 if [ $# -gt 2 ]; then
78d4d6a2
SP
188 cur="$3"
189 fi
5447aac7
SG
190 case "$cur" in
191 --*=)
192 COMPREPLY=()
5447aac7
SG
193 ;;
194 *)
ab02dfe5 195 local IFS=$'\n'
25a31f81
TP
196 COMPREPLY=($(compgen -P "${2-}" \
197 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
ab02dfe5 198 -- "$cur"))
5447aac7
SG
199 ;;
200 esac
72e5e989
SP
201}
202
a42577d4 203# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
5de40f59
SP
204__git_heads ()
205{
25a31f81 206 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
5de40f59 207 if [ -d "$dir" ]; then
05e8b3d6
SG
208 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
209 refs/heads
5de40f59
SP
210 return
211 fi
25a31f81 212 for i in $(git ls-remote "${1-}" 2>/dev/null); do
5de40f59
SP
213 case "$is_hash,$i" in
214 y,*) is_hash=n ;;
215 n,*^{}) is_hash=y ;;
216 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
217 n,*) is_hash=y; echo "$i" ;;
218 esac
219 done
220}
221
a42577d4 222# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
88e21dc7
SP
223__git_tags ()
224{
25a31f81 225 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
88e21dc7 226 if [ -d "$dir" ]; then
05e8b3d6
SG
227 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
228 refs/tags
88e21dc7
SP
229 return
230 fi
25a31f81 231 for i in $(git ls-remote "${1-}" 2>/dev/null); do
88e21dc7
SP
232 case "$is_hash,$i" in
233 y,*) is_hash=n ;;
234 n,*^{}) is_hash=y ;;
235 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
236 n,*) is_hash=y; echo "$i" ;;
237 esac
238 done
239}
240
a42577d4 241# __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
690d8824
JH
242__git_refs ()
243{
25a31f81 244 local i is_hash=y dir="$(__gitdir "${1-}")"
608efb87 245 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
873537fa 246 if [ -d "$dir" ]; then
608efb87
SG
247 case "$cur" in
248 refs|refs/*)
249 format="refname"
250 refs="${cur%/*}"
251 ;;
252 *)
253 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
254 format="refname:short"
255 refs="refs/tags refs/heads refs/remotes"
256 ;;
257 esac
258 git --git-dir="$dir" for-each-ref --format="%($format)" \
259 $refs
35e65ecc 260 return
690d8824 261 fi
799596a5 262 for i in $(git ls-remote "$dir" 2>/dev/null); do
690d8824
JH
263 case "$is_hash,$i" in
264 y,*) is_hash=n ;;
265 n,*^{}) is_hash=y ;;
266 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
267 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
35e65ecc 268 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
269 n,*) is_hash=y; echo "$i" ;;
270 esac
271 done
272}
273
a42577d4 274# __git_refs2 requires 1 argument (to pass to __git_refs)
690d8824
JH
275__git_refs2 ()
276{
67ffa114
SP
277 local i
278 for i in $(__git_refs "$1"); do
279 echo "$i:$i"
690d8824
JH
280 done
281}
282
a42577d4 283# __git_refs_remotes requires 1 argument (to pass to ls-remote)
5de40f59
SP
284__git_refs_remotes ()
285{
286 local cmd i is_hash=y
799596a5 287 for i in $(git ls-remote "$1" 2>/dev/null); do
5de40f59
SP
288 case "$is_hash,$i" in
289 n,refs/heads/*)
290 is_hash=y
291 echo "$i:refs/remotes/$1/${i#refs/heads/}"
292 ;;
293 y,*) is_hash=n ;;
294 n,*^{}) is_hash=y ;;
295 n,refs/tags/*) is_hash=y;;
296 n,*) is_hash=y; ;;
297 esac
298 done
299}
300
690d8824
JH
301__git_remotes ()
302{
873537fa 303 local i ngoff IFS=$'\n' d="$(__gitdir)"
56fc25f2 304 shopt -q nullglob || ngoff=1
690d8824 305 shopt -s nullglob
873537fa
SP
306 for i in "$d/remotes"/*; do
307 echo ${i#$d/remotes/}
690d8824 308 done
56fc25f2 309 [ "$ngoff" ] && shopt -u nullglob
e0d10e1c 310 for i in $(git --git-dir="$d" config --list); do
56fc25f2
SP
311 case "$i" in
312 remote.*.url=*)
313 i="${i#remote.}"
314 echo "${i/.url=*/}"
315 ;;
316 esac
317 done
690d8824
JH
318}
319
4ad91321
SP
320__git_merge_strategies ()
321{
5c9cc64a 322 if [ -n "${__git_merge_strategylist-}" ]; then
b51ec6bd
SP
323 echo "$__git_merge_strategylist"
324 return
325 fi
25b3d4d6
JH
326 git merge -s help 2>&1 |
327 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
328 s/\.$//
329 s/.*://
330 s/^[ ]*//
331 s/[ ]*$//
4ad91321 332 p
25b3d4d6 333 }'
4ad91321 334}
b51ec6bd 335__git_merge_strategylist=
25b3d4d6 336__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
4ad91321 337
690d8824
JH
338__git_complete_file ()
339{
a79c6551 340 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
690d8824
JH
341 case "$cur" in
342 ?*:*)
a79c6551
SP
343 ref="${cur%%:*}"
344 cur="${cur#*:}"
690d8824
JH
345 case "$cur" in
346 ?*/*)
a79c6551
SP
347 pfx="${cur%/*}"
348 cur="${cur##*/}"
690d8824
JH
349 ls="$ref:$pfx"
350 pfx="$pfx/"
351 ;;
352 *)
353 ls="$ref"
354 ;;
355 esac
db8a9ff0
SP
356
357 case "$COMP_WORDBREAKS" in
358 *:*) : great ;;
359 *) pfx="$ref:$pfx" ;;
360 esac
361
778306e4 362 local IFS=$'\n'
690d8824 363 COMPREPLY=($(compgen -P "$pfx" \
873537fa 364 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
778306e4
SP
365 | sed '/^100... blob /{
366 s,^.* ,,
367 s,$, ,
368 }
369 /^120000 blob /{
370 s,^.* ,,
371 s,$, ,
372 }
690d8824
JH
373 /^040000 tree /{
374 s,^.* ,,
375 s,$,/,
376 }
377 s/^.* //')" \
378 -- "$cur"))
379 ;;
380 *)
b3391775 381 __gitcomp "$(__git_refs)"
690d8824
JH
382 ;;
383 esac
384}
385
f53352fb
SP
386__git_complete_revlist ()
387{
388 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
389 case "$cur" in
390 *...*)
391 pfx="${cur%...*}..."
392 cur="${cur#*...}"
b3391775 393 __gitcomp "$(__git_refs)" "$pfx" "$cur"
f53352fb
SP
394 ;;
395 *..*)
396 pfx="${cur%..*}.."
397 cur="${cur#*..}"
b3391775
SP
398 __gitcomp "$(__git_refs)" "$pfx" "$cur"
399 ;;
f53352fb 400 *)
b3391775 401 __gitcomp "$(__git_refs)"
f53352fb
SP
402 ;;
403 esac
404}
405
52d5c3b5
JS
406__git_complete_remote_or_refspec ()
407{
408 local cmd="${COMP_WORDS[1]}"
409 local cur="${COMP_WORDS[COMP_CWORD]}"
0a4e1472 410 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
52d5c3b5
JS
411 while [ $c -lt $COMP_CWORD ]; do
412 i="${COMP_WORDS[c]}"
413 case "$i" in
0a4e1472 414 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
52d5c3b5
JS
415 -*) ;;
416 *) remote="$i"; break ;;
417 esac
418 c=$((++c))
419 done
420 if [ -z "$remote" ]; then
421 __gitcomp "$(__git_remotes)"
422 return
423 fi
0a4e1472
JS
424 if [ $no_complete_refspec = 1 ]; then
425 COMPREPLY=()
426 return
427 fi
52d5c3b5
JS
428 [ "$remote" = "." ] && remote=
429 case "$cur" in
430 *:*)
431 case "$COMP_WORDBREAKS" in
432 *:*) : great ;;
433 *) pfx="${cur%%:*}:" ;;
434 esac
435 cur="${cur#*:}"
436 lhs=0
437 ;;
438 +*)
439 pfx="+"
440 cur="${cur#+}"
441 ;;
442 esac
443 case "$cmd" in
444 fetch)
445 if [ $lhs = 1 ]; then
446 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
447 else
448 __gitcomp "$(__git_refs)" "$pfx" "$cur"
449 fi
450 ;;
451 pull)
452 if [ $lhs = 1 ]; then
453 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
454 else
455 __gitcomp "$(__git_refs)" "$pfx" "$cur"
456 fi
457 ;;
458 push)
459 if [ $lhs = 1 ]; then
460 __gitcomp "$(__git_refs)" "$pfx" "$cur"
461 else
462 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
463 fi
464 ;;
465 esac
466}
467
3c7b480a
JS
468__git_complete_strategy ()
469{
470 case "${COMP_WORDS[COMP_CWORD-1]}" in
471 -s|--strategy)
472 __gitcomp "$(__git_merge_strategies)"
473 return 0
474 esac
475 local cur="${COMP_WORDS[COMP_CWORD]}"
476 case "$cur" in
477 --strategy=*)
478 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
479 return 0
480 ;;
481 esac
482 return 1
483}
484
1eb7e2f8 485__git_all_commands ()
f2bb9f88 486{
5c9cc64a 487 if [ -n "${__git_all_commandlist-}" ]; then
1eb7e2f8 488 echo "$__git_all_commandlist"
b51ec6bd
SP
489 return
490 fi
f2bb9f88
SP
491 local i IFS=" "$'\n'
492 for i in $(git help -a|egrep '^ ')
1eb7e2f8
LM
493 do
494 case $i in
495 *--*) : helper pattern;;
496 *) echo $i;;
497 esac
498 done
499}
500__git_all_commandlist=
501__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
502
503__git_porcelain_commands ()
504{
5c9cc64a 505 if [ -n "${__git_porcelain_commandlist-}" ]; then
1eb7e2f8
LM
506 echo "$__git_porcelain_commandlist"
507 return
508 fi
509 local i IFS=" "$'\n'
510 for i in "help" $(__git_all_commands)
f2bb9f88
SP
511 do
512 case $i in
718a087a 513 *--*) : helper pattern;;
a925c6f1
SP
514 applymbox) : ask gittus;;
515 applypatch) : ask gittus;;
516 archimport) : import;;
2e3a430a 517 cat-file) : plumbing;;
56d99c67 518 check-attr) : plumbing;;
f2bb9f88 519 check-ref-format) : plumbing;;
ff2549dc 520 checkout-index) : plumbing;;
f2bb9f88 521 commit-tree) : plumbing;;
ff2549dc 522 count-objects) : infrequent;;
a925c6f1
SP
523 cvsexportcommit) : export;;
524 cvsimport) : import;;
f2bb9f88
SP
525 cvsserver) : daemon;;
526 daemon) : daemon;;
5cfb4fe5
SP
527 diff-files) : plumbing;;
528 diff-index) : plumbing;;
529 diff-tree) : plumbing;;
c6ec3b13 530 fast-import) : import;;
ff2549dc 531 fast-export) : export;;
a925c6f1 532 fsck-objects) : plumbing;;
f2bb9f88 533 fetch-pack) : plumbing;;
a925c6f1 534 fmt-merge-msg) : plumbing;;
56d99c67 535 for-each-ref) : plumbing;;
f2bb9f88
SP
536 hash-object) : plumbing;;
537 http-*) : transport;;
538 index-pack) : plumbing;;
a925c6f1 539 init-db) : deprecated;;
f2bb9f88 540 local-fetch) : plumbing;;
ff2549dc
PB
541 lost-found) : infrequent;;
542 ls-files) : plumbing;;
543 ls-remote) : plumbing;;
544 ls-tree) : plumbing;;
f2bb9f88
SP
545 mailinfo) : plumbing;;
546 mailsplit) : plumbing;;
547 merge-*) : plumbing;;
548 mktree) : plumbing;;
549 mktag) : plumbing;;
550 pack-objects) : plumbing;;
551 pack-redundant) : plumbing;;
552 pack-refs) : plumbing;;
553 parse-remote) : plumbing;;
554 patch-id) : plumbing;;
555 peek-remote) : plumbing;;
a925c6f1
SP
556 prune) : plumbing;;
557 prune-packed) : plumbing;;
558 quiltimport) : import;;
f2bb9f88
SP
559 read-tree) : plumbing;;
560 receive-pack) : plumbing;;
2e3a430a 561 reflog) : plumbing;;
5c66d0d4 562 repo-config) : deprecated;;
f2bb9f88
SP
563 rerere) : plumbing;;
564 rev-list) : plumbing;;
565 rev-parse) : plumbing;;
566 runstatus) : plumbing;;
567 sh-setup) : internal;;
568 shell) : daemon;;
ff2549dc 569 show-ref) : plumbing;;
f2bb9f88
SP
570 send-pack) : plumbing;;
571 show-index) : plumbing;;
572 ssh-*) : transport;;
573 stripspace) : plumbing;;
574 symbolic-ref) : plumbing;;
a925c6f1 575 tar-tree) : deprecated;;
f2bb9f88
SP
576 unpack-file) : plumbing;;
577 unpack-objects) : plumbing;;
a925c6f1 578 update-index) : plumbing;;
f2bb9f88
SP
579 update-ref) : plumbing;;
580 update-server-info) : daemon;;
581 upload-archive) : plumbing;;
582 upload-pack) : plumbing;;
583 write-tree) : plumbing;;
ff2549dc
PB
584 var) : infrequent;;
585 verify-pack) : infrequent;;
a925c6f1 586 verify-tag) : plumbing;;
f2bb9f88
SP
587 *) echo $i;;
588 esac
589 done
590}
1eb7e2f8
LM
591__git_porcelain_commandlist=
592__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
f2bb9f88 593
367dce2a
DS
594__git_aliases ()
595{
56fc25f2 596 local i IFS=$'\n'
e0d10e1c 597 for i in $(git --git-dir="$(__gitdir)" config --list); do
56fc25f2
SP
598 case "$i" in
599 alias.*)
600 i="${i#alias.}"
601 echo "${i/=*/}"
602 ;;
603 esac
604 done
367dce2a
DS
605}
606
a42577d4 607# __git_aliased_command requires 1 argument
367dce2a
DS
608__git_aliased_command ()
609{
873537fa 610 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 611 config --get "alias.$1")
367dce2a
DS
612 for word in $cmdline; do
613 if [ "${word##-*}" ]; then
614 echo $word
615 return
616 fi
617 done
618}
619
a42577d4 620# __git_find_subcommand requires 1 argument
3ff1320d
SG
621__git_find_subcommand ()
622{
623 local word subcommand c=1
624
625 while [ $c -lt $COMP_CWORD ]; do
626 word="${COMP_WORDS[c]}"
627 for subcommand in $1; do
628 if [ "$subcommand" = "$word" ]; then
629 echo "$subcommand"
630 return
631 fi
632 done
633 c=$((++c))
634 done
635}
636
d773c631
SG
637__git_has_doubledash ()
638{
639 local c=1
640 while [ $c -lt $COMP_CWORD ]; do
641 if [ "--" = "${COMP_WORDS[c]}" ]; then
642 return 0
643 fi
644 c=$((++c))
645 done
646 return 1
647}
648
7950659d 649__git_whitespacelist="nowarn warn error error-all fix"
88329195
SP
650
651_git_am ()
652{
28ed6e7b 653 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
51ef1daa 654 if [ -d "$dir"/rebase-apply ]; then
a31c00b0 655 __gitcomp "--skip --resolved --abort"
88329195
SP
656 return
657 fi
658 case "$cur" in
659 --whitespace=*)
b3391775 660 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
661 return
662 ;;
663 --*)
b3391775 664 __gitcomp "
43acdf24
TZ
665 --3way --committer-date-is-author-date --ignore-date
666 --interactive --keep --no-utf8 --signoff --utf8
88329195 667 --whitespace=
b3391775 668 "
88329195
SP
669 return
670 esac
671 COMPREPLY=()
672}
673
674_git_apply ()
675{
676 local cur="${COMP_WORDS[COMP_CWORD]}"
677 case "$cur" in
678 --whitespace=*)
b3391775 679 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
680 return
681 ;;
682 --*)
b3391775 683 __gitcomp "
88329195
SP
684 --stat --numstat --summary --check --index
685 --cached --index-info --reverse --reject --unidiff-zero
686 --apply --no-add --exclude=
687 --whitespace= --inaccurate-eof --verbose
b3391775 688 "
88329195
SP
689 return
690 esac
691 COMPREPLY=()
692}
693
8435b548
SP
694_git_add ()
695{
d773c631
SG
696 __git_has_doubledash && return
697
8435b548
SP
698 local cur="${COMP_WORDS[COMP_CWORD]}"
699 case "$cur" in
700 --*)
1d284cba
SG
701 __gitcomp "
702 --interactive --refresh --patch --update --dry-run
c9a114b5 703 --ignore-errors --intent-to-add
1d284cba 704 "
8435b548
SP
705 return
706 esac
707 COMPREPLY=()
708}
709
b3191ce2
LM
710_git_archive ()
711{
712 local cur="${COMP_WORDS[COMP_CWORD]}"
713 case "$cur" in
714 --format=*)
715 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
716 return
717 ;;
718 --remote=*)
719 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
720 return
721 ;;
722 --*)
723 __gitcomp "
724 --format= --list --verbose
725 --prefix= --remote= --exec=
726 "
727 return
728 ;;
729 esac
730 __git_complete_file
731}
732
b2e69f62
SP
733_git_bisect ()
734{
d773c631
SG
735 __git_has_doubledash && return
736
bf11d461 737 local subcommands="start bad good skip reset visualize replay log run"
3ff1320d
SG
738 local subcommand="$(__git_find_subcommand "$subcommands")"
739 if [ -z "$subcommand" ]; then
740 __gitcomp "$subcommands"
b2e69f62
SP
741 return
742 fi
743
3ff1320d 744 case "$subcommand" in
bf11d461 745 bad|good|reset|skip)
b2e69f62
SP
746 __gitcomp "$(__git_refs)"
747 ;;
748 *)
749 COMPREPLY=()
750 ;;
751 esac
752}
753
690d8824
JH
754_git_branch ()
755{
b9217642
SG
756 local i c=1 only_local_ref="n" has_r="n"
757
758 while [ $c -lt $COMP_CWORD ]; do
759 i="${COMP_WORDS[c]}"
760 case "$i" in
761 -d|-m) only_local_ref="y" ;;
762 -r) has_r="y" ;;
763 esac
764 c=$((++c))
765 done
766
3b376b0c 767 case "${COMP_WORDS[COMP_CWORD]}" in
3b376b0c
SG
768 --*)
769 __gitcomp "
770 --color --no-color --verbose --abbrev= --no-abbrev
50e61025 771 --track --no-track --contains --merged --no-merged
3b376b0c
SG
772 "
773 ;;
b9217642
SG
774 *)
775 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
776 __gitcomp "$(__git_heads)"
777 else
778 __gitcomp "$(__git_refs)"
779 fi
780 ;;
3b376b0c 781 esac
690d8824
JH
782}
783
374a58c9
ML
784_git_bundle ()
785{
8d8163f3
SG
786 local cmd="${COMP_WORDS[2]}"
787 case "$COMP_CWORD" in
788 2)
374a58c9
ML
789 __gitcomp "create list-heads verify unbundle"
790 ;;
8d8163f3 791 3)
374a58c9
ML
792 # looking for a file
793 ;;
794 *)
795 case "$cmd" in
796 create)
797 __git_complete_revlist
798 ;;
799 esac
800 ;;
801 esac
802}
803
690d8824
JH
804_git_checkout ()
805{
c84bb14c
SG
806 __git_has_doubledash && return
807
b3391775 808 __gitcomp "$(__git_refs)"
690d8824
JH
809}
810
d8a9fea5
SP
811_git_cherry ()
812{
813 __gitcomp "$(__git_refs)"
814}
815
1273231e
SP
816_git_cherry_pick ()
817{
818 local cur="${COMP_WORDS[COMP_CWORD]}"
819 case "$cur" in
820 --*)
b3391775 821 __gitcomp "--edit --no-commit"
1273231e
SP
822 ;;
823 *)
b3391775 824 __gitcomp "$(__git_refs)"
1273231e
SP
825 ;;
826 esac
827}
828
4181c7e8
LM
829_git_clean ()
830{
831 __git_has_doubledash && return
832
833 local cur="${COMP_WORDS[COMP_CWORD]}"
834 case "$cur" in
835 --*)
836 __gitcomp "--dry-run --quiet"
837 return
838 ;;
839 esac
840 COMPREPLY=()
841}
842
3eb11012
LM
843_git_clone ()
844{
845 local cur="${COMP_WORDS[COMP_CWORD]}"
846 case "$cur" in
847 --*)
848 __gitcomp "
849 --local
850 --no-hardlinks
851 --shared
852 --reference
853 --quiet
854 --no-checkout
855 --bare
856 --mirror
857 --origin
858 --upload-pack
859 --template=
860 --depth
861 "
862 return
863 ;;
864 esac
865 COMPREPLY=()
866}
867
4548e855
SP
868_git_commit ()
869{
d773c631
SG
870 __git_has_doubledash && return
871
4548e855
SP
872 local cur="${COMP_WORDS[COMP_CWORD]}"
873 case "$cur" in
874 --*)
b3391775 875 __gitcomp "
4548e855 876 --all --author= --signoff --verify --no-verify
aa5735be 877 --edit --amend --include --only --interactive
b3391775 878 "
4548e855
SP
879 return
880 esac
881 COMPREPLY=()
882}
883
217926c0
SP
884_git_describe ()
885{
cbb504c9
TR
886 local cur="${COMP_WORDS[COMP_CWORD]}"
887 case "$cur" in
888 --*)
889 __gitcomp "
890 --all --tags --contains --abbrev= --candidates=
891 --exact-match --debug --long --match --always
892 "
893 return
894 esac
217926c0
SP
895 __gitcomp "$(__git_refs)"
896}
897
20bf7292 898__git_diff_common_options="--stat --numstat --shortstat --summary
b3a4f858
JS
899 --patch-with-stat --name-only --name-status --color
900 --no-color --color-words --no-renames --check
f135aacb 901 --full-index --binary --abbrev --diff-filter=
47d5a8fa 902 --find-copies-harder
b3a4f858
JS
903 --text --ignore-space-at-eol --ignore-space-change
904 --ignore-all-space --exit-code --quiet --ext-diff
aba201c6
PO
905 --no-ext-diff
906 --no-prefix --src-prefix= --dst-prefix=
6d0e674a 907 --inter-hunk-context=
cc545709 908 --patience
20bf7292
TR
909 --raw
910"
911
912_git_diff ()
913{
914 __git_has_doubledash && return
915
916 local cur="${COMP_WORDS[COMP_CWORD]}"
917 case "$cur" in
918 --*)
ebd15bf0 919 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
20bf7292
TR
920 --base --ours --theirs
921 $__git_diff_common_options
aba201c6 922 "
b3a4f858
JS
923 return
924 ;;
925 esac
690d8824
JH
926 __git_complete_file
927}
928
e2dc2de9 929__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
b6f0621a 930 tkdiff vimdiff gvimdiff xxdiff araxis
e2dc2de9
DA
931"
932
933_git_difftool ()
934{
935 local cur="${COMP_WORDS[COMP_CWORD]}"
936 case "$cur" in
937 --tool=*)
938 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
939 return
940 ;;
941 --*)
942 __gitcomp "--tool="
943 return
944 ;;
945 esac
946 COMPREPLY=()
947}
948
0a4e1472
JS
949__git_fetch_options="
950 --quiet --verbose --append --upload-pack --force --keep --depth=
951 --tags --no-tags
952"
953
690d8824
JH
954_git_fetch ()
955{
0a4e1472
JS
956 local cur="${COMP_WORDS[COMP_CWORD]}"
957 case "$cur" in
958 --*)
959 __gitcomp "$__git_fetch_options"
960 return
961 ;;
962 esac
52d5c3b5 963 __git_complete_remote_or_refspec
690d8824
JH
964}
965
f53352fb
SP
966_git_format_patch ()
967{
968 local cur="${COMP_WORDS[COMP_CWORD]}"
969 case "$cur" in
e1d37937
SB
970 --thread=*)
971 __gitcomp "
972 deep shallow
973 " "" "${cur##--thread=}"
974 return
975 ;;
f53352fb 976 --*)
b3391775 977 __gitcomp "
e1d37937 978 --stdout --attach --no-attach --thread --thread=
f53352fb
SP
979 --output-directory
980 --numbered --start-number
47e98eec 981 --numbered-files
f53352fb
SP
982 --keep-subject
983 --signoff
3f7df3a7 984 --in-reply-to= --cc=
f53352fb 985 --full-index --binary
ec804891 986 --not --all
be5f5bf0 987 --cover-letter
aba201c6 988 --no-prefix --src-prefix= --dst-prefix=
81085134
SG
989 --inline --suffix= --ignore-if-in-upstream
990 --subject-prefix=
b3391775 991 "
f53352fb
SP
992 return
993 ;;
994 esac
995 __git_complete_revlist
996}
997
4bca8636
AJ
998_git_fsck ()
999{
1000 local cur="${COMP_WORDS[COMP_CWORD]}"
1001 case "$cur" in
1002 --*)
1003 __gitcomp "
1004 --tags --root --unreachable --cache --no-reflogs --full
1005 --strict --verbose --lost-found
1006 "
1007 return
1008 ;;
1009 esac
1010 COMPREPLY=()
1011}
1012
b26c8748
SP
1013_git_gc ()
1014{
1015 local cur="${COMP_WORDS[COMP_CWORD]}"
1016 case "$cur" in
1017 --*)
47e98eec 1018 __gitcomp "--prune --aggressive"
b26c8748
SP
1019 return
1020 ;;
1021 esac
1022 COMPREPLY=()
1023}
1024
c72e0db1
LM
1025_git_grep ()
1026{
1027 __git_has_doubledash && return
1028
1029 local cur="${COMP_WORDS[COMP_CWORD]}"
1030 case "$cur" in
1031 --*)
1032 __gitcomp "
1033 --cached
1034 --text --ignore-case --word-regexp --invert-match
1035 --full-name
1036 --extended-regexp --basic-regexp --fixed-strings
1037 --files-with-matches --name-only
1038 --files-without-match
1039 --count
1040 --and --or --not --all-match
1041 "
1042 return
1043 ;;
1044 esac
1045 COMPREPLY=()
1046}
1047
1eb7e2f8
LM
1048_git_help ()
1049{
1050 local cur="${COMP_WORDS[COMP_CWORD]}"
1051 case "$cur" in
1052 --*)
1053 __gitcomp "--all --info --man --web"
1054 return
1055 ;;
1056 esac
2946cccf
MG
1057 __gitcomp "$(__git_all_commands)
1058 attributes cli core-tutorial cvs-migration
1059 diffcore gitk glossary hooks ignore modules
1060 repository-layout tutorial tutorial-2
99f0b599 1061 workflows
2946cccf 1062 "
1eb7e2f8
LM
1063}
1064
5dad868b
LM
1065_git_init ()
1066{
1067 local cur="${COMP_WORDS[COMP_CWORD]}"
1068 case "$cur" in
1069 --shared=*)
1070 __gitcomp "
1071 false true umask group all world everybody
1072 " "" "${cur##--shared=}"
1073 return
1074 ;;
1075 --*)
1076 __gitcomp "--quiet --bare --template= --shared --shared="
1077 return
1078 ;;
1079 esac
1080 COMPREPLY=()
1081}
1082
b1bc1494
LM
1083_git_ls_files ()
1084{
1085 __git_has_doubledash && return
1086
1087 local cur="${COMP_WORDS[COMP_CWORD]}"
1088 case "$cur" in
1089 --*)
1090 __gitcomp "--cached --deleted --modified --others --ignored
1091 --stage --directory --no-empty-directory --unmerged
1092 --killed --exclude= --exclude-from=
1093 --exclude-per-directory= --exclude-standard
1094 --error-unmatch --with-tree= --full-name
1095 --abbrev --ignored --exclude-per-directory
1096 "
1097 return
1098 ;;
1099 esac
1100 COMPREPLY=()
1101}
1102
690d8824
JH
1103_git_ls_remote ()
1104{
b3391775 1105 __gitcomp "$(__git_remotes)"
690d8824
JH
1106}
1107
1108_git_ls_tree ()
1109{
1110 __git_complete_file
1111}
1112
a393777e
TR
1113# Options that go well for log, shortlog and gitk
1114__git_log_common_options="
1115 --not --all
1116 --branches --tags --remotes
1117 --first-parent --no-merges
1118 --max-count=
1119 --max-age= --since= --after=
1120 --min-age= --until= --before=
1121"
1122# Options that go well for log and gitk (not shortlog)
1123__git_log_gitk_options="
1124 --dense --sparse --full-history
1125 --simplify-merges --simplify-by-decoration
1126 --left-right
1127"
1128# Options that go well for log and shortlog (not gitk)
1129__git_log_shortlog_options="
1130 --author= --committer= --grep=
1131 --all-match
1132"
1133
3d279863 1134__git_log_pretty_formats="oneline short medium full fuller email raw format:"
672c68cb 1135__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
3d279863 1136
690d8824
JH
1137_git_log ()
1138{
d773c631
SG
1139 __git_has_doubledash && return
1140
6e31b866 1141 local cur="${COMP_WORDS[COMP_CWORD]}"
bf3c20f6
TR
1142 local g="$(git rev-parse --git-dir 2>/dev/null)"
1143 local merge=""
ba7906f2 1144 if [ -f "$g/MERGE_HEAD" ]; then
bf3c20f6
TR
1145 merge="--merge"
1146 fi
6e31b866
SP
1147 case "$cur" in
1148 --pretty=*)
3d279863 1149 __gitcomp "$__git_log_pretty_formats
b3391775 1150 " "" "${cur##--pretty=}"
6e31b866
SP
1151 return
1152 ;;
72de29c2
TL
1153 --format=*)
1154 __gitcomp "$__git_log_pretty_formats
1155 " "" "${cur##--format=}"
1156 return
1157 ;;
47e98eec 1158 --date=*)
672c68cb 1159 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
47e98eec
SP
1160 return
1161 ;;
6e31b866 1162 --*)
b3391775 1163 __gitcomp "
a393777e
TR
1164 $__git_log_common_options
1165 $__git_log_shortlog_options
1166 $__git_log_gitk_options
8f87fae6 1167 --root --topo-order --date-order --reverse
5d0e6343 1168 --follow --full-diff
6e31b866 1169 --abbrev-commit --abbrev=
47e98eec 1170 --relative-date --date=
72de29c2 1171 --pretty= --format= --oneline
a393777e 1172 --cherry-pick
20827d99 1173 --graph
20bf7292
TR
1174 --decorate
1175 --walk-reflogs
a393777e 1176 --parents --children
bf3c20f6 1177 $merge
20bf7292 1178 $__git_diff_common_options
47d5a8fa 1179 --pickaxe-all --pickaxe-regex
b3391775 1180 "
6e31b866
SP
1181 return
1182 ;;
1183 esac
f53352fb 1184 __git_complete_revlist
690d8824
JH
1185}
1186
0a4e1472
JS
1187__git_merge_options="
1188 --no-commit --no-stat --log --no-log --squash --strategy
1189 --commit --stat --no-squash --ff --no-ff
1190"
1191
4ad91321
SP
1192_git_merge ()
1193{
3c7b480a
JS
1194 __git_complete_strategy && return
1195
4ad91321
SP
1196 local cur="${COMP_WORDS[COMP_CWORD]}"
1197 case "$cur" in
1198 --*)
0a4e1472 1199 __gitcomp "$__git_merge_options"
4ad91321
SP
1200 return
1201 esac
b3391775 1202 __gitcomp "$(__git_refs)"
4ad91321
SP
1203}
1204
b4c72162
LM
1205_git_mergetool ()
1206{
1207 local cur="${COMP_WORDS[COMP_CWORD]}"
1208 case "$cur" in
1209 --tool=*)
e2dc2de9 1210 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
b4c72162
LM
1211 return
1212 ;;
1213 --*)
1214 __gitcomp "--tool="
1215 return
1216 ;;
1217 esac
1218 COMPREPLY=()
1219}
1220
690d8824
JH
1221_git_merge_base ()
1222{
b3391775 1223 __gitcomp "$(__git_refs)"
690d8824
JH
1224}
1225
1127c51c
LM
1226_git_mv ()
1227{
1228 local cur="${COMP_WORDS[COMP_CWORD]}"
1229 case "$cur" in
1230 --*)
1231 __gitcomp "--dry-run"
1232 return
1233 ;;
1234 esac
1235 COMPREPLY=()
1236}
1237
d33909bf
SP
1238_git_name_rev ()
1239{
b3391775 1240 __gitcomp "--tags --all --stdin"
d33909bf
SP
1241}
1242
690d8824
JH
1243_git_pull ()
1244{
0a4e1472
JS
1245 __git_complete_strategy && return
1246
1247 local cur="${COMP_WORDS[COMP_CWORD]}"
1248 case "$cur" in
1249 --*)
1250 __gitcomp "
1251 --rebase --no-rebase
1252 $__git_merge_options
1253 $__git_fetch_options
1254 "
1255 return
1256 ;;
1257 esac
52d5c3b5 1258 __git_complete_remote_or_refspec
690d8824
JH
1259}
1260
1261_git_push ()
1262{
0a4e1472
JS
1263 local cur="${COMP_WORDS[COMP_CWORD]}"
1264 case "${COMP_WORDS[COMP_CWORD-1]}" in
1265 --repo)
1266 __gitcomp "$(__git_remotes)"
1267 return
1268 esac
1269 case "$cur" in
1270 --repo=*)
1271 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1272 return
1273 ;;
1274 --*)
1275 __gitcomp "
1276 --all --mirror --tags --dry-run --force --verbose
1277 --receive-pack= --repo=
1278 "
1279 return
1280 ;;
1281 esac
52d5c3b5 1282 __git_complete_remote_or_refspec
690d8824
JH
1283}
1284
61d926a3
SP
1285_git_rebase ()
1286{
51fe1209 1287 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
51ef1daa 1288 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
b3391775 1289 __gitcomp "--continue --skip --abort"
61d926a3
SP
1290 return
1291 fi
3c7b480a 1292 __git_complete_strategy && return
61d926a3
SP
1293 case "$cur" in
1294 --*)
d9e3b702 1295 __gitcomp "--onto --merge --strategy --interactive"
61d926a3
SP
1296 return
1297 esac
b3391775 1298 __gitcomp "$(__git_refs)"
61d926a3
SP
1299}
1300
ae616de6 1301__git_send_email_confirm_options="always never auto cc compose"
cb8a9bd5 1302__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
ae616de6 1303
25a1f374
TL
1304_git_send_email ()
1305{
1306 local cur="${COMP_WORDS[COMP_CWORD]}"
1307 case "$cur" in
ae616de6
SB
1308 --confirm=*)
1309 __gitcomp "
1310 $__git_send_email_confirm_options
1311 " "" "${cur##--confirm=}"
1312 return
1313 ;;
1314 --suppress-cc=*)
1315 __gitcomp "
1316 $__git_send_email_suppresscc_options
1317 " "" "${cur##--suppress-cc=}"
1318
1319 return
1320 ;;
1321 --smtp-encryption=*)
1322 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1323 return
1324 ;;
25a1f374 1325 --*)
77813151 1326 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
ae616de6
SB
1327 --compose --confirm= --dry-run --envelope-sender
1328 --from --identity
25a1f374
TL
1329 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1330 --no-suppress-from --no-thread --quiet
1331 --signed-off-by-cc --smtp-pass --smtp-server
ae616de6
SB
1332 --smtp-server-port --smtp-encryption= --smtp-user
1333 --subject --suppress-cc= --suppress-from --thread --to
fd3a8dcb 1334 --validate --no-validate"
25a1f374
TL
1335 return
1336 ;;
1337 esac
1338 COMPREPLY=()
1339}
1340
00652369
SB
1341__git_config_get_set_variables ()
1342{
1343 local prevword word config_file= c=$COMP_CWORD
1344 while [ $c -gt 1 ]; do
1345 word="${COMP_WORDS[c]}"
1346 case "$word" in
1347 --global|--system|--file=*)
1348 config_file="$word"
1349 break
1350 ;;
1351 -f|--file)
1352 config_file="$word $prevword"
1353 break
1354 ;;
1355 esac
1356 prevword=$word
1357 c=$((--c))
1358 done
1359
f581de1b
SB
1360 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1361 while read line
1362 do
1363 case "$line" in
1364 *.*=*)
1365 echo "${line/=*/}"
00652369
SB
1366 ;;
1367 esac
1368 done
1369}
1370
e0d10e1c 1371_git_config ()
5de40f59
SP
1372{
1373 local cur="${COMP_WORDS[COMP_CWORD]}"
1374 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1375 case "$prv" in
1376 branch.*.remote)
78d4d6a2 1377 __gitcomp "$(__git_remotes)"
5de40f59
SP
1378 return
1379 ;;
1380 branch.*.merge)
78d4d6a2 1381 __gitcomp "$(__git_refs)"
5de40f59
SP
1382 return
1383 ;;
1384 remote.*.fetch)
1385 local remote="${prv#remote.}"
1386 remote="${remote%.fetch}"
78d4d6a2 1387 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
1388 return
1389 ;;
1390 remote.*.push)
1391 local remote="${prv#remote.}"
1392 remote="${remote%.push}"
78d4d6a2 1393 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 1394 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
1395 refs/heads)"
1396 return
1397 ;;
1398 pull.twohead|pull.octopus)
1399 __gitcomp "$(__git_merge_strategies)"
1400 return
1401 ;;
6123d719
MH
1402 color.branch|color.diff|color.interactive|\
1403 color.showbranch|color.status|color.ui)
78d4d6a2
SP
1404 __gitcomp "always never auto"
1405 return
1406 ;;
901d615c
MK
1407 color.pager)
1408 __gitcomp "false true"
1409 return
1410 ;;
78d4d6a2
SP
1411 color.*.*)
1412 __gitcomp "
98171a07 1413 normal black red green yellow blue magenta cyan white
78d4d6a2
SP
1414 bold dim ul blink reverse
1415 "
5de40f59
SP
1416 return
1417 ;;
9b82d63b
SB
1418 help.format)
1419 __gitcomp "man info web html"
1420 return
1421 ;;
672c68cb
SB
1422 log.date)
1423 __gitcomp "$__git_log_date_formats"
1424 return
1425 ;;
ae616de6
SB
1426 sendemail.aliasesfiletype)
1427 __gitcomp "mutt mailrc pine elm gnus"
1428 return
1429 ;;
1430 sendemail.confirm)
1431 __gitcomp "$__git_send_email_confirm_options"
1432 return
1433 ;;
1434 sendemail.suppresscc)
1435 __gitcomp "$__git_send_email_suppresscc_options"
1436 return
1437 ;;
00652369
SB
1438 --get|--get-all|--unset|--unset-all)
1439 __gitcomp "$(__git_config_get_set_variables)"
1440 return
1441 ;;
5de40f59
SP
1442 *.*)
1443 COMPREPLY=()
1444 return
1445 ;;
1446 esac
1447 case "$cur" in
1448 --*)
78d4d6a2 1449 __gitcomp "
47e98eec 1450 --global --system --file=
12977705 1451 --list --replace-all
5de40f59 1452 --get --get-all --get-regexp
1b71eb35 1453 --add --unset --unset-all
12977705 1454 --remove-section --rename-section
78d4d6a2 1455 "
5de40f59
SP
1456 return
1457 ;;
1458 branch.*.*)
1459 local pfx="${cur%.*}."
1460 cur="${cur##*.}"
6fac1b83 1461 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
5de40f59
SP
1462 return
1463 ;;
1464 branch.*)
1465 local pfx="${cur%.*}."
1466 cur="${cur#*.}"
78d4d6a2 1467 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
5de40f59
SP
1468 return
1469 ;;
0aa62fd0
SB
1470 guitool.*.*)
1471 local pfx="${cur%.*}."
1472 cur="${cur##*.}"
1473 __gitcomp "
1474 argprompt cmd confirm needsfile noconsole norescan
1475 prompt revprompt revunmerged title
1476 " "$pfx" "$cur"
1477 return
1478 ;;
1479 difftool.*.*)
1480 local pfx="${cur%.*}."
1481 cur="${cur##*.}"
1482 __gitcomp "cmd path" "$pfx" "$cur"
1483 return
1484 ;;
1485 man.*.*)
1486 local pfx="${cur%.*}."
1487 cur="${cur##*.}"
1488 __gitcomp "cmd path" "$pfx" "$cur"
1489 return
1490 ;;
1491 mergetool.*.*)
1492 local pfx="${cur%.*}."
1493 cur="${cur##*.}"
1494 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1495 return
1496 ;;
1497 pager.*)
1498 local pfx="${cur%.*}."
1499 cur="${cur#*.}"
1500 __gitcomp "$(__git_all_commands)" "$pfx" "$cur"
1501 return
1502 ;;
5de40f59
SP
1503 remote.*.*)
1504 local pfx="${cur%.*}."
1505 cur="${cur##*.}"
12977705 1506 __gitcomp "
98171a07 1507 url proxy fetch push mirror skipDefaultUpdate
6fac1b83 1508 receivepack uploadpack tagopt pushurl
12977705 1509 " "$pfx" "$cur"
5de40f59
SP
1510 return
1511 ;;
1512 remote.*)
1513 local pfx="${cur%.*}."
1514 cur="${cur#*.}"
78d4d6a2 1515 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
5de40f59
SP
1516 return
1517 ;;
0aa62fd0
SB
1518 url.*.*)
1519 local pfx="${cur%.*}."
1520 cur="${cur##*.}"
1521 __gitcomp "insteadof" "$pfx" "$cur"
1522 return
1523 ;;
5de40f59 1524 esac
78d4d6a2 1525 __gitcomp "
6fac1b83 1526 add.ignore-errors
226b343c 1527 alias.
5de40f59 1528 apply.whitespace
98171a07
LM
1529 branch.autosetupmerge
1530 branch.autosetuprebase
2122591b 1531 clean.requireForce
78d4d6a2
SP
1532 color.branch
1533 color.branch.current
1534 color.branch.local
78d4d6a2 1535 color.branch.plain
025a1929 1536 color.branch.remote
a159ca0c 1537 color.diff
025a1929 1538 color.diff.commit
78d4d6a2 1539 color.diff.frag
025a1929 1540 color.diff.meta
78d4d6a2 1541 color.diff.new
025a1929
LM
1542 color.diff.old
1543 color.diff.plain
78d4d6a2 1544 color.diff.whitespace
226b343c
SB
1545 color.grep
1546 color.grep.external
1547 color.grep.match
98171a07
LM
1548 color.interactive
1549 color.interactive.header
1550 color.interactive.help
1551 color.interactive.prompt
a159ca0c 1552 color.pager
6123d719 1553 color.showbranch
a159ca0c 1554 color.status
78d4d6a2
SP
1555 color.status.added
1556 color.status.changed
025a1929 1557 color.status.header
98171a07 1558 color.status.nobranch
78d4d6a2 1559 color.status.untracked
98171a07
LM
1560 color.status.updated
1561 color.ui
1562 commit.template
1563 core.autocrlf
1564 core.bare
025a1929 1565 core.compression
226b343c 1566 core.createObject
98171a07
LM
1567 core.deltaBaseCacheLimit
1568 core.editor
1569 core.excludesfile
025a1929 1570 core.fileMode
98171a07 1571 core.fsyncobjectfiles
025a1929 1572 core.gitProxy
98171a07 1573 core.ignoreCygwinFSTricks
025a1929
LM
1574 core.ignoreStat
1575 core.logAllRefUpdates
1576 core.loosecompression
1577 core.packedGitLimit
1578 core.packedGitWindowSize
98171a07 1579 core.pager
025a1929 1580 core.preferSymlinkRefs
98171a07
LM
1581 core.preloadindex
1582 core.quotepath
025a1929 1583 core.repositoryFormatVersion
98171a07 1584 core.safecrlf
025a1929 1585 core.sharedRepository
98171a07
LM
1586 core.symlinks
1587 core.trustctime
025a1929 1588 core.warnAmbiguousRefs
98171a07
LM
1589 core.whitespace
1590 core.worktree
1591 diff.autorefreshindex
1592 diff.external
1593 diff.mnemonicprefix
78d4d6a2 1594 diff.renameLimit
98171a07 1595 diff.renameLimit.
78d4d6a2 1596 diff.renames
226b343c
SB
1597 diff.suppressBlankEmpty
1598 diff.tool
1599 diff.wordRegex
0aa62fd0 1600 difftool.
226b343c 1601 difftool.prompt
78d4d6a2 1602 fetch.unpackLimit
226b343c
SB
1603 format.attach
1604 format.cc
78d4d6a2 1605 format.headers
98171a07
LM
1606 format.numbered
1607 format.pretty
226b343c
SB
1608 format.signoff
1609 format.subjectprefix
98171a07 1610 format.suffix
226b343c 1611 format.thread
98171a07
LM
1612 gc.aggressiveWindow
1613 gc.auto
1614 gc.autopacklimit
12977705 1615 gc.packrefs
98171a07 1616 gc.pruneexpire
78d4d6a2
SP
1617 gc.reflogexpire
1618 gc.reflogexpireunreachable
1619 gc.rerereresolved
1620 gc.rerereunresolved
025a1929 1621 gitcvs.allbinary
226b343c 1622 gitcvs.commitmsgannotation
98171a07 1623 gitcvs.dbTableNamePrefix
025a1929
LM
1624 gitcvs.dbdriver
1625 gitcvs.dbname
1626 gitcvs.dbpass
025a1929
LM
1627 gitcvs.dbuser
1628 gitcvs.enabled
1629 gitcvs.logfile
98171a07 1630 gitcvs.usecrlfattr
0aa62fd0 1631 guitool.
98171a07
LM
1632 gui.blamehistoryctx
1633 gui.commitmsgwidth
1634 gui.copyblamethreshold
1635 gui.diffcontext
1636 gui.encoding
1637 gui.fastcopyblame
1638 gui.matchtrackingbranch
1639 gui.newbranchtemplate
1640 gui.pruneduringfetch
1641 gui.spellingdictionary
1642 gui.trustmtime
1643 help.autocorrect
1644 help.browser
1645 help.format
78d4d6a2
SP
1646 http.lowSpeedLimit
1647 http.lowSpeedTime
025a1929 1648 http.maxRequests
5de40f59 1649 http.noEPSV
98171a07 1650 http.proxy
025a1929
LM
1651 http.sslCAInfo
1652 http.sslCAPath
1653 http.sslCert
1654 http.sslKey
1655 http.sslVerify
78d4d6a2
SP
1656 i18n.commitEncoding
1657 i18n.logOutputEncoding
226b343c
SB
1658 imap.folder
1659 imap.host
1660 imap.pass
1661 imap.port
1662 imap.preformattedHTML
1663 imap.sslverify
1664 imap.tunnel
1665 imap.user
98171a07
LM
1666 instaweb.browser
1667 instaweb.httpd
1668 instaweb.local
1669 instaweb.modulepath
1670 instaweb.port
226b343c 1671 interactive.singlekey
98171a07 1672 log.date
78d4d6a2 1673 log.showroot
226b343c 1674 mailmap.file
0aa62fd0 1675 man.
98171a07
LM
1676 man.viewer
1677 merge.conflictstyle
1678 merge.log
1679 merge.renameLimit
1680 merge.stat
025a1929 1681 merge.tool
78d4d6a2 1682 merge.verbosity
0aa62fd0 1683 mergetool.
98171a07 1684 mergetool.keepBackup
226b343c 1685 mergetool.prompt
47e98eec 1686 pack.compression
47e98eec 1687 pack.deltaCacheLimit
025a1929
LM
1688 pack.deltaCacheSize
1689 pack.depth
98171a07
LM
1690 pack.indexVersion
1691 pack.packSizeLimit
1692 pack.threads
025a1929
LM
1693 pack.window
1694 pack.windowMemory
0aa62fd0 1695 pager.
78d4d6a2
SP
1696 pull.octopus
1697 pull.twohead
226b343c
SB
1698 push.default
1699 rebase.stat
98171a07
LM
1700 receive.denyCurrentBranch
1701 receive.denyDeletes
025a1929 1702 receive.denyNonFastForwards
98171a07 1703 receive.fsckObjects
025a1929 1704 receive.unpackLimit
98171a07
LM
1705 repack.usedeltabaseoffset
1706 rerere.autoupdate
1707 rerere.enabled
226b343c
SB
1708 sendemail.aliasesfile
1709 sendemail.aliasesfiletype
1710 sendemail.bcc
1711 sendemail.cc
1712 sendemail.cccmd
1713 sendemail.chainreplyto
1714 sendemail.confirm
1715 sendemail.envelopesender
1716 sendemail.multiedit
1717 sendemail.signedoffbycc
1718 sendemail.smtpencryption
1719 sendemail.smtppass
1720 sendemail.smtpserver
1721 sendemail.smtpserverport
1722 sendemail.smtpuser
1723 sendemail.suppresscc
1724 sendemail.suppressfrom
1725 sendemail.thread
1726 sendemail.to
1727 sendemail.validate
78d4d6a2 1728 showbranch.default
98171a07
LM
1729 status.relativePaths
1730 status.showUntrackedFiles
78d4d6a2
SP
1731 tar.umask
1732 transfer.unpackLimit
0aa62fd0 1733 url.
78d4d6a2 1734 user.email
025a1929 1735 user.name
78d4d6a2 1736 user.signingkey
98171a07 1737 web.browser
5de40f59 1738 branch. remote.
78d4d6a2 1739 "
5de40f59
SP
1740}
1741
88293c67
SP
1742_git_remote ()
1743{
bc14fac8 1744 local subcommands="add rename rm show prune update set-head"
3ff1320d
SG
1745 local subcommand="$(__git_find_subcommand "$subcommands")"
1746 if [ -z "$subcommand" ]; then
3903c618 1747 __gitcomp "$subcommands"
88293c67
SP
1748 return
1749 fi
1750
3ff1320d 1751 case "$subcommand" in
f135e72d 1752 rename|rm|show|prune)
88293c67
SP
1753 __gitcomp "$(__git_remotes)"
1754 ;;
fb72759b
SP
1755 update)
1756 local i c='' IFS=$'\n'
1757 for i in $(git --git-dir="$(__gitdir)" config --list); do
1758 case "$i" in
1759 remotes.*)
1760 i="${i#remotes.}"
1761 c="$c ${i/=*/}"
1762 ;;
1763 esac
1764 done
1765 __gitcomp "$c"
1766 ;;
88293c67
SP
1767 *)
1768 COMPREPLY=()
1769 ;;
1770 esac
1771}
1772
67e78c3b
SP
1773_git_reset ()
1774{
d773c631
SG
1775 __git_has_doubledash && return
1776
67e78c3b 1777 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
1778 case "$cur" in
1779 --*)
e89e2ed7 1780 __gitcomp "--merge --mixed --hard --soft"
b3391775
SP
1781 return
1782 ;;
1783 esac
1784 __gitcomp "$(__git_refs)"
67e78c3b
SP
1785}
1786
a6c2be24
LM
1787_git_revert ()
1788{
1789 local cur="${COMP_WORDS[COMP_CWORD]}"
1790 case "$cur" in
1791 --*)
1792 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1793 return
1794 ;;
1795 esac
c0783837 1796 __gitcomp "$(__git_refs)"
a6c2be24
LM
1797}
1798
08c701d4
LM
1799_git_rm ()
1800{
1801 __git_has_doubledash && return
1802
1803 local cur="${COMP_WORDS[COMP_CWORD]}"
1804 case "$cur" in
1805 --*)
1806 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1807 return
1808 ;;
1809 esac
1810 COMPREPLY=()
1811}
1812
1fd6bec9
SP
1813_git_shortlog ()
1814{
d773c631
SG
1815 __git_has_doubledash && return
1816
1fd6bec9
SP
1817 local cur="${COMP_WORDS[COMP_CWORD]}"
1818 case "$cur" in
1819 --*)
1820 __gitcomp "
a393777e
TR
1821 $__git_log_common_options
1822 $__git_log_shortlog_options
1fd6bec9
SP
1823 --numbered --summary
1824 "
1825 return
1826 ;;
1827 esac
1828 __git_complete_revlist
1829}
1830
90131924
SP
1831_git_show ()
1832{
41d8cf7d
MH
1833 __git_has_doubledash && return
1834
90131924
SP
1835 local cur="${COMP_WORDS[COMP_CWORD]}"
1836 case "$cur" in
1837 --pretty=*)
3d279863 1838 __gitcomp "$__git_log_pretty_formats
b3391775 1839 " "" "${cur##--pretty=}"
90131924
SP
1840 return
1841 ;;
72de29c2
TL
1842 --format=*)
1843 __gitcomp "$__git_log_pretty_formats
1844 " "" "${cur##--format=}"
1845 return
1846 ;;
90131924 1847 --*)
076c3237 1848 __gitcomp "--pretty= --format= --abbrev-commit --oneline
20bf7292
TR
1849 $__git_diff_common_options
1850 "
90131924
SP
1851 return
1852 ;;
1853 esac
1854 __git_complete_file
1855}
1856
2ca880fe
TR
1857_git_show_branch ()
1858{
1859 local cur="${COMP_WORDS[COMP_CWORD]}"
1860 case "$cur" in
1861 --*)
1862 __gitcomp "
1863 --all --remotes --topo-order --current --more=
1864 --list --independent --merge-base --no-name
6123d719 1865 --color --no-color
076c3237 1866 --sha1-name --sparse --topics --reflog
2ca880fe
TR
1867 "
1868 return
1869 ;;
1870 esac
1871 __git_complete_revlist
1872}
1873
7fd53fce
JH
1874_git_stash ()
1875{
95d43780 1876 local subcommands='save list show apply clear drop pop create branch'
7bedebca
SG
1877 local subcommand="$(__git_find_subcommand "$subcommands")"
1878 if [ -z "$subcommand" ]; then
3ff1320d 1879 __gitcomp "$subcommands"
7bedebca
SG
1880 else
1881 local cur="${COMP_WORDS[COMP_CWORD]}"
1882 case "$subcommand,$cur" in
1883 save,--*)
1884 __gitcomp "--keep-index"
1885 ;;
8513c54b 1886 apply,--*|pop,--*)
95d43780
LM
1887 __gitcomp "--index"
1888 ;;
8513c54b 1889 show,--*|drop,--*|branch,--*)
95d43780
LM
1890 COMPREPLY=()
1891 ;;
1892 show,*|apply,*|drop,*|pop,*|branch,*)
1893 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1894 | sed -n -e 's/:.*//p')"
1895 ;;
7bedebca
SG
1896 *)
1897 COMPREPLY=()
1898 ;;
1899 esac
3ff1320d 1900 fi
7fd53fce
JH
1901}
1902
be86f7a0
SP
1903_git_submodule ()
1904{
d773c631
SG
1905 __git_has_doubledash && return
1906
1b0f7978 1907 local subcommands="add status init update summary foreach sync"
3ff1320d 1908 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
be86f7a0
SP
1909 local cur="${COMP_WORDS[COMP_CWORD]}"
1910 case "$cur" in
1911 --*)
1912 __gitcomp "--quiet --cached"
1913 ;;
1914 *)
3ff1320d 1915 __gitcomp "$subcommands"
be86f7a0
SP
1916 ;;
1917 esac
1918 return
1919 fi
1920}
1921
47f6ee28
SG
1922_git_svn ()
1923{
1924 local subcommands="
1925 init fetch clone rebase dcommit log find-rev
1926 set-tree commit-diff info create-ignore propget
4a5856cb
SG
1927 proplist show-ignore show-externals branch tag blame
1928 migrate
47f6ee28
SG
1929 "
1930 local subcommand="$(__git_find_subcommand "$subcommands")"
1931 if [ -z "$subcommand" ]; then
1932 __gitcomp "$subcommands"
1933 else
1934 local remote_opts="--username= --config-dir= --no-auth-cache"
1935 local fc_opts="
1936 --follow-parent --authors-file= --repack=
1937 --no-metadata --use-svm-props --use-svnsync-props
1938 --log-window-size= --no-checkout --quiet
4a5856cb
SG
1939 --repack-flags --use-log-author --localtime
1940 --ignore-paths= $remote_opts
47f6ee28
SG
1941 "
1942 local init_opts="
1943 --template= --shared= --trunk= --tags=
1944 --branches= --stdlayout --minimize-url
1945 --no-metadata --use-svm-props --use-svnsync-props
4a5856cb
SG
1946 --rewrite-root= --prefix= --use-log-author
1947 --add-author-from $remote_opts
47f6ee28
SG
1948 "
1949 local cmt_opts="
1950 --edit --rmdir --find-copies-harder --copy-similarity=
1951 "
1952
1953 local cur="${COMP_WORDS[COMP_CWORD]}"
1954 case "$subcommand,$cur" in
1955 fetch,--*)
1956 __gitcomp "--revision= --fetch-all $fc_opts"
1957 ;;
1958 clone,--*)
1959 __gitcomp "--revision= $fc_opts $init_opts"
1960 ;;
1961 init,--*)
1962 __gitcomp "$init_opts"
1963 ;;
1964 dcommit,--*)
1965 __gitcomp "
1966 --merge --strategy= --verbose --dry-run
4a5856cb
SG
1967 --fetch-all --no-rebase --commit-url
1968 --revision $cmt_opts $fc_opts
47f6ee28
SG
1969 "
1970 ;;
1971 set-tree,--*)
1972 __gitcomp "--stdin $cmt_opts $fc_opts"
1973 ;;
1974 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1975 show-externals,--*)
1976 __gitcomp "--revision="
1977 ;;
1978 log,--*)
1979 __gitcomp "
1980 --limit= --revision= --verbose --incremental
1981 --oneline --show-commit --non-recursive
4a5856cb 1982 --authors-file= --color
47f6ee28
SG
1983 "
1984 ;;
1985 rebase,--*)
1986 __gitcomp "
1987 --merge --verbose --strategy= --local
4a5856cb 1988 --fetch-all --dry-run $fc_opts
47f6ee28
SG
1989 "
1990 ;;
1991 commit-diff,--*)
1992 __gitcomp "--message= --file= --revision= $cmt_opts"
1993 ;;
1994 info,--*)
1995 __gitcomp "--url"
1996 ;;
4a5856cb
SG
1997 branch,--*)
1998 __gitcomp "--dry-run --message --tag"
1999 ;;
2000 tag,--*)
2001 __gitcomp "--dry-run --message"
2002 ;;
2003 blame,--*)
2004 __gitcomp "--git-format"
2005 ;;
2006 migrate,--*)
2007 __gitcomp "
2008 --config-dir= --ignore-paths= --minimize
2009 --no-auth-cache --username=
2010 "
2011 ;;
47f6ee28
SG
2012 *)
2013 COMPREPLY=()
2014 ;;
2015 esac
2016 fi
2017}
2018
88e21dc7
SP
2019_git_tag ()
2020{
2021 local i c=1 f=0
2022 while [ $c -lt $COMP_CWORD ]; do
2023 i="${COMP_WORDS[c]}"
2024 case "$i" in
2025 -d|-v)
2026 __gitcomp "$(__git_tags)"
2027 return
2028 ;;
2029 -f)
2030 f=1
2031 ;;
2032 esac
2033 c=$((++c))
2034 done
2035
2036 case "${COMP_WORDS[COMP_CWORD-1]}" in
2037 -m|-F)
2038 COMPREPLY=()
2039 ;;
8d8163f3 2040 -*|tag)
88e21dc7
SP
2041 if [ $f = 1 ]; then
2042 __gitcomp "$(__git_tags)"
2043 else
2044 COMPREPLY=()
2045 fi
2046 ;;
2047 *)
2048 __gitcomp "$(__git_refs)"
2049 ;;
2050 esac
2051}
2052
690d8824
JH
2053_git ()
2054{
873537fa
SP
2055 local i c=1 command __git_dir
2056
2057 while [ $c -lt $COMP_CWORD ]; do
2058 i="${COMP_WORDS[c]}"
2059 case "$i" in
2060 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2061 --bare) __git_dir="." ;;
1eb7e2f8
LM
2062 --version|-p|--paginate) ;;
2063 --help) command="help"; break ;;
873537fa
SP
2064 *) command="$i"; break ;;
2065 esac
2066 c=$((++c))
2067 done
2068
1d17b22e 2069 if [ -z "$command" ]; then
72e5e989 2070 case "${COMP_WORDS[COMP_CWORD]}" in
47e98eec 2071 --*) __gitcomp "
ce5a2c95 2072 --paginate
47e98eec
SP
2073 --no-pager
2074 --git-dir=
2075 --bare
2076 --version
2077 --exec-path
89a56bfb 2078 --html-path
ce5a2c95
TL
2079 --work-tree=
2080 --help
47e98eec
SP
2081 "
2082 ;;
1eb7e2f8 2083 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
72e5e989
SP
2084 esac
2085 return
873537fa 2086 fi
367dce2a 2087
873537fa
SP
2088 local expansion=$(__git_aliased_command "$command")
2089 [ "$expansion" ] && command="$expansion"
367dce2a 2090
873537fa 2091 case "$command" in
88329195 2092 am) _git_am ;;
8435b548 2093 add) _git_add ;;
88329195 2094 apply) _git_apply ;;
b3191ce2 2095 archive) _git_archive ;;
b2e69f62 2096 bisect) _git_bisect ;;
374a58c9 2097 bundle) _git_bundle ;;
873537fa 2098 branch) _git_branch ;;
873537fa 2099 checkout) _git_checkout ;;
d8a9fea5 2100 cherry) _git_cherry ;;
1273231e 2101 cherry-pick) _git_cherry_pick ;;
4181c7e8 2102 clean) _git_clean ;;
3eb11012 2103 clone) _git_clone ;;
4548e855 2104 commit) _git_commit ;;
e0d10e1c 2105 config) _git_config ;;
217926c0 2106 describe) _git_describe ;;
873537fa 2107 diff) _git_diff ;;
e2dc2de9 2108 difftool) _git_difftool ;;
873537fa 2109 fetch) _git_fetch ;;
f53352fb 2110 format-patch) _git_format_patch ;;
4bca8636 2111 fsck) _git_fsck ;;
b26c8748 2112 gc) _git_gc ;;
c72e0db1 2113 grep) _git_grep ;;
1eb7e2f8 2114 help) _git_help ;;
5dad868b 2115 init) _git_init ;;
873537fa 2116 log) _git_log ;;
b1bc1494 2117 ls-files) _git_ls_files ;;
873537fa
SP
2118 ls-remote) _git_ls_remote ;;
2119 ls-tree) _git_ls_tree ;;
4ad91321 2120 merge) _git_merge;;
b4c72162 2121 mergetool) _git_mergetool;;
873537fa 2122 merge-base) _git_merge_base ;;
1127c51c 2123 mv) _git_mv ;;
d33909bf 2124 name-rev) _git_name_rev ;;
873537fa
SP
2125 pull) _git_pull ;;
2126 push) _git_push ;;
61d926a3 2127 rebase) _git_rebase ;;
88293c67 2128 remote) _git_remote ;;
873537fa 2129 reset) _git_reset ;;
a6c2be24 2130 revert) _git_revert ;;
08c701d4 2131 rm) _git_rm ;;
25a1f374 2132 send-email) _git_send_email ;;
1fd6bec9 2133 shortlog) _git_shortlog ;;
90131924 2134 show) _git_show ;;
2ca880fe 2135 show-branch) _git_show_branch ;;
7fd53fce 2136 stash) _git_stash ;;
df398771 2137 stage) _git_add ;;
be86f7a0 2138 submodule) _git_submodule ;;
47f6ee28 2139 svn) _git_svn ;;
88e21dc7 2140 tag) _git_tag ;;
873537fa
SP
2141 whatchanged) _git_log ;;
2142 *) COMPREPLY=() ;;
2143 esac
690d8824
JH
2144}
2145
2146_gitk ()
2147{
d773c631
SG
2148 __git_has_doubledash && return
2149
690d8824 2150 local cur="${COMP_WORDS[COMP_CWORD]}"
fa26a401 2151 local g="$(__gitdir)"
07ba53f7 2152 local merge=""
ba7906f2 2153 if [ -f "$g/MERGE_HEAD" ]; then
07ba53f7
RQ
2154 merge="--merge"
2155 fi
b3391775
SP
2156 case "$cur" in
2157 --*)
a393777e
TR
2158 __gitcomp "
2159 $__git_log_common_options
2160 $__git_log_gitk_options
2161 $merge
2162 "
b3391775
SP
2163 return
2164 ;;
2165 esac
ec804891 2166 __git_complete_revlist
690d8824
JH
2167}
2168
50e126e1
TP
2169complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2170 || complete -o default -o nospace -F _git git
2171complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2172 || complete -o default -o nospace -F _gitk gitk
690d8824
JH
2173
2174# The following are necessary only for Cygwin, and only are needed
2175# when the user has tab-completed the executable name and consequently
2176# included the '.exe' suffix.
2177#
76c3eb51 2178if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
50e126e1
TP
2179complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2180 || complete -o default -o nospace -F _git git.exe
76c3eb51 2181fi