Start 1.6.0.2 maintenance cycle
[git/git.git] / contrib / completion / git-completion.bash
CommitLineData
690d8824
JH
1#
2# bash completion support for core Git.
3#
c70680ce 4# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
690d8824 5# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
c70680ce 6# Distributed under the GNU General Public License, version 2.0.
690d8824
JH
7#
8# The contained completion routines provide support for completing:
9#
10# *) local and remote branch names
11# *) local and remote tag names
12# *) .git/remotes file names
13# *) git 'subcommands'
14# *) tree paths within 'ref:path/to/file' expressions
c70680ce 15# *) common --long-options
690d8824
JH
16#
17# To use these routines:
18#
19# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
20# 2) Added the following line to your .bashrc:
21# source ~/.git-completion.sh
22#
b51ec6bd
SP
23# 3) You may want to make sure the git executable is available
24# in your PATH before this script is sourced, as some caching
25# is performed while the script loads. If git isn't found
26# at source time then all lookups will be done on demand,
27# which may be slightly slower.
28#
29# 4) Consider changing your PS1 to also show the current branch:
d3d717a4
SP
30# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
31#
32# The argument to __git_ps1 will be displayed only if you
33# are currently in a git repository. The %s token will be
34# the name of the current branch.
35#
c70680ce
SP
36# To submit patches:
37#
38# *) Read Documentation/SubmittingPatches
39# *) Send all patches to the current maintainer:
40#
41# "Shawn O. Pearce" <spearce@spearce.org>
42#
43# *) Always CC the Git mailing list:
44#
45# git@vger.kernel.org
46#
690d8824 47
db8a9ff0
SP
48case "$COMP_WORDBREAKS" in
49*:*) : great ;;
50*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
51esac
52
873537fa
SP
53__gitdir ()
54{
67ffa114
SP
55 if [ -z "$1" ]; then
56 if [ -n "$__git_dir" ]; then
57 echo "$__git_dir"
58 elif [ -d .git ]; then
59 echo .git
60 else
61 git rev-parse --git-dir 2>/dev/null
62 fi
63 elif [ -d "$1/.git" ]; then
64 echo "$1/.git"
65 else
66 echo "$1"
67 fi
873537fa
SP
68}
69
d3d717a4
SP
70__git_ps1 ()
71{
e7520196
RR
72 local g="$(git rev-parse --git-dir 2>/dev/null)"
73 if [ -n "$g" ]; then
74 local r
75 local b
51ef1daa 76 if [ -d "$g/rebase-apply" ]
e7520196 77 then
51ef1daa 78 if test -f "$g/rebase-apply/rebasing"
3041c324
JH
79 then
80 r="|REBASE"
51ef1daa 81 elif test -f "$g/rebase-apply/applying"
3041c324
JH
82 then
83 r="|AM"
84 else
85 r="|AM/REBASE"
86 fi
e7520196 87 b="$(git symbolic-ref HEAD 2>/dev/null)"
28ed6e7b 88 elif [ -f "$g/rebase-merge/interactive" ]
e7520196
RR
89 then
90 r="|REBASE-i"
28ed6e7b
JS
91 b="$(cat "$g/rebase-merge/head-name")"
92 elif [ -d "$g/rebase-merge" ]
e7520196
RR
93 then
94 r="|REBASE-m"
28ed6e7b 95 b="$(cat "$g/rebase-merge/head-name")"
e7520196
RR
96 elif [ -f "$g/MERGE_HEAD" ]
97 then
98 r="|MERGING"
99 b="$(git symbolic-ref HEAD 2>/dev/null)"
100 else
a5c4f85b 101 if [ -f "$g/BISECT_LOG" ]
e7520196
RR
102 then
103 r="|BISECTING"
104 fi
105 if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
106 then
27c57888
SP
107 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
108 then
a5c4f85b 109 b="$(cut -c1-7 "$g/HEAD")..."
27c57888 110 fi
e7520196
RR
111 fi
112 fi
113
d3d717a4 114 if [ -n "$1" ]; then
e7520196 115 printf "$1" "${b##refs/heads/}$r"
d3d717a4 116 else
e7520196 117 printf " (%s)" "${b##refs/heads/}$r"
d3d717a4
SP
118 fi
119 fi
120}
121
ab02dfe5
SP
122__gitcomp_1 ()
123{
124 local c IFS=' '$'\t'$'\n'
125 for c in $1; do
126 case "$c$2" in
127 --*=*) printf %s$'\n' "$c$2" ;;
128 *.) printf %s$'\n' "$c$2" ;;
129 *) printf %s$'\n' "$c$2 " ;;
130 esac
131 done
132}
133
72e5e989
SP
134__gitcomp ()
135{
78d4d6a2 136 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775 137 if [ $# -gt 2 ]; then
78d4d6a2
SP
138 cur="$3"
139 fi
5447aac7
SG
140 case "$cur" in
141 --*=)
142 COMPREPLY=()
5447aac7
SG
143 ;;
144 *)
ab02dfe5
SP
145 local IFS=$'\n'
146 COMPREPLY=($(compgen -P "$2" \
147 -W "$(__gitcomp_1 "$1" "$4")" \
148 -- "$cur"))
5447aac7
SG
149 ;;
150 esac
72e5e989
SP
151}
152
5de40f59
SP
153__git_heads ()
154{
67ffa114 155 local cmd i is_hash=y dir="$(__gitdir "$1")"
5de40f59
SP
156 if [ -d "$dir" ]; then
157 for i in $(git --git-dir="$dir" \
158 for-each-ref --format='%(refname)' \
159 refs/heads ); do
160 echo "${i#refs/heads/}"
161 done
162 return
163 fi
799596a5 164 for i in $(git ls-remote "$1" 2>/dev/null); do
5de40f59
SP
165 case "$is_hash,$i" in
166 y,*) is_hash=n ;;
167 n,*^{}) is_hash=y ;;
168 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
169 n,*) is_hash=y; echo "$i" ;;
170 esac
171 done
172}
173
88e21dc7
SP
174__git_tags ()
175{
176 local cmd i is_hash=y dir="$(__gitdir "$1")"
177 if [ -d "$dir" ]; then
178 for i in $(git --git-dir="$dir" \
179 for-each-ref --format='%(refname)' \
180 refs/tags ); do
181 echo "${i#refs/tags/}"
182 done
183 return
184 fi
799596a5 185 for i in $(git ls-remote "$1" 2>/dev/null); do
88e21dc7
SP
186 case "$is_hash,$i" in
187 y,*) is_hash=n ;;
188 n,*^{}) is_hash=y ;;
189 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
190 n,*) is_hash=y; echo "$i" ;;
191 esac
192 done
193}
194
690d8824
JH
195__git_refs ()
196{
67ffa114 197 local cmd i is_hash=y dir="$(__gitdir "$1")"
873537fa 198 if [ -d "$dir" ]; then
35e65ecc
SP
199 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
200 for i in $(git --git-dir="$dir" \
201 for-each-ref --format='%(refname)' \
202 refs/tags refs/heads refs/remotes); do
203 case "$i" in
204 refs/tags/*) echo "${i#refs/tags/}" ;;
205 refs/heads/*) echo "${i#refs/heads/}" ;;
206 refs/remotes/*) echo "${i#refs/remotes/}" ;;
207 *) echo "$i" ;;
208 esac
209 done
210 return
690d8824 211 fi
799596a5 212 for i in $(git ls-remote "$dir" 2>/dev/null); do
690d8824
JH
213 case "$is_hash,$i" in
214 y,*) is_hash=n ;;
215 n,*^{}) is_hash=y ;;
216 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
217 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
35e65ecc 218 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
219 n,*) is_hash=y; echo "$i" ;;
220 esac
221 done
222}
223
224__git_refs2 ()
225{
67ffa114
SP
226 local i
227 for i in $(__git_refs "$1"); do
228 echo "$i:$i"
690d8824
JH
229 done
230}
231
5de40f59
SP
232__git_refs_remotes ()
233{
234 local cmd i is_hash=y
799596a5 235 for i in $(git ls-remote "$1" 2>/dev/null); do
5de40f59
SP
236 case "$is_hash,$i" in
237 n,refs/heads/*)
238 is_hash=y
239 echo "$i:refs/remotes/$1/${i#refs/heads/}"
240 ;;
241 y,*) is_hash=n ;;
242 n,*^{}) is_hash=y ;;
243 n,refs/tags/*) is_hash=y;;
244 n,*) is_hash=y; ;;
245 esac
246 done
247}
248
690d8824
JH
249__git_remotes ()
250{
873537fa 251 local i ngoff IFS=$'\n' d="$(__gitdir)"
56fc25f2 252 shopt -q nullglob || ngoff=1
690d8824 253 shopt -s nullglob
873537fa
SP
254 for i in "$d/remotes"/*; do
255 echo ${i#$d/remotes/}
690d8824 256 done
56fc25f2 257 [ "$ngoff" ] && shopt -u nullglob
e0d10e1c 258 for i in $(git --git-dir="$d" config --list); do
56fc25f2
SP
259 case "$i" in
260 remote.*.url=*)
261 i="${i#remote.}"
262 echo "${i/.url=*/}"
263 ;;
264 esac
265 done
690d8824
JH
266}
267
4ad91321
SP
268__git_merge_strategies ()
269{
b51ec6bd
SP
270 if [ -n "$__git_merge_strategylist" ]; then
271 echo "$__git_merge_strategylist"
272 return
273 fi
25b3d4d6
JH
274 git merge -s help 2>&1 |
275 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
276 s/\.$//
277 s/.*://
278 s/^[ ]*//
279 s/[ ]*$//
4ad91321 280 p
25b3d4d6 281 }'
4ad91321 282}
b51ec6bd 283__git_merge_strategylist=
25b3d4d6 284__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
4ad91321 285
690d8824
JH
286__git_complete_file ()
287{
a79c6551 288 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
690d8824
JH
289 case "$cur" in
290 ?*:*)
a79c6551
SP
291 ref="${cur%%:*}"
292 cur="${cur#*:}"
690d8824
JH
293 case "$cur" in
294 ?*/*)
a79c6551
SP
295 pfx="${cur%/*}"
296 cur="${cur##*/}"
690d8824
JH
297 ls="$ref:$pfx"
298 pfx="$pfx/"
299 ;;
300 *)
301 ls="$ref"
302 ;;
303 esac
db8a9ff0
SP
304
305 case "$COMP_WORDBREAKS" in
306 *:*) : great ;;
307 *) pfx="$ref:$pfx" ;;
308 esac
309
778306e4 310 local IFS=$'\n'
690d8824 311 COMPREPLY=($(compgen -P "$pfx" \
873537fa 312 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
778306e4
SP
313 | sed '/^100... blob /{
314 s,^.* ,,
315 s,$, ,
316 }
317 /^120000 blob /{
318 s,^.* ,,
319 s,$, ,
320 }
690d8824
JH
321 /^040000 tree /{
322 s,^.* ,,
323 s,$,/,
324 }
325 s/^.* //')" \
326 -- "$cur"))
327 ;;
328 *)
b3391775 329 __gitcomp "$(__git_refs)"
690d8824
JH
330 ;;
331 esac
332}
333
f53352fb
SP
334__git_complete_revlist ()
335{
336 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
337 case "$cur" in
338 *...*)
339 pfx="${cur%...*}..."
340 cur="${cur#*...}"
b3391775 341 __gitcomp "$(__git_refs)" "$pfx" "$cur"
f53352fb
SP
342 ;;
343 *..*)
344 pfx="${cur%..*}.."
345 cur="${cur#*..}"
b3391775
SP
346 __gitcomp "$(__git_refs)" "$pfx" "$cur"
347 ;;
f53352fb 348 *)
b3391775 349 __gitcomp "$(__git_refs)"
f53352fb
SP
350 ;;
351 esac
352}
353
1eb7e2f8 354__git_all_commands ()
f2bb9f88 355{
1eb7e2f8
LM
356 if [ -n "$__git_all_commandlist" ]; then
357 echo "$__git_all_commandlist"
b51ec6bd
SP
358 return
359 fi
f2bb9f88
SP
360 local i IFS=" "$'\n'
361 for i in $(git help -a|egrep '^ ')
1eb7e2f8
LM
362 do
363 case $i in
364 *--*) : helper pattern;;
365 *) echo $i;;
366 esac
367 done
368}
369__git_all_commandlist=
370__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
371
372__git_porcelain_commands ()
373{
374 if [ -n "$__git_porcelain_commandlist" ]; then
375 echo "$__git_porcelain_commandlist"
376 return
377 fi
378 local i IFS=" "$'\n'
379 for i in "help" $(__git_all_commands)
f2bb9f88
SP
380 do
381 case $i in
718a087a 382 *--*) : helper pattern;;
a925c6f1
SP
383 applymbox) : ask gittus;;
384 applypatch) : ask gittus;;
385 archimport) : import;;
2e3a430a 386 cat-file) : plumbing;;
56d99c67 387 check-attr) : plumbing;;
f2bb9f88
SP
388 check-ref-format) : plumbing;;
389 commit-tree) : plumbing;;
a925c6f1
SP
390 cvsexportcommit) : export;;
391 cvsimport) : import;;
f2bb9f88
SP
392 cvsserver) : daemon;;
393 daemon) : daemon;;
5cfb4fe5
SP
394 diff-files) : plumbing;;
395 diff-index) : plumbing;;
396 diff-tree) : plumbing;;
c6ec3b13 397 fast-import) : import;;
a925c6f1 398 fsck-objects) : plumbing;;
f2bb9f88 399 fetch-pack) : plumbing;;
a925c6f1 400 fmt-merge-msg) : plumbing;;
56d99c67 401 for-each-ref) : plumbing;;
f2bb9f88
SP
402 hash-object) : plumbing;;
403 http-*) : transport;;
404 index-pack) : plumbing;;
a925c6f1 405 init-db) : deprecated;;
f2bb9f88
SP
406 local-fetch) : plumbing;;
407 mailinfo) : plumbing;;
408 mailsplit) : plumbing;;
409 merge-*) : plumbing;;
410 mktree) : plumbing;;
411 mktag) : plumbing;;
412 pack-objects) : plumbing;;
413 pack-redundant) : plumbing;;
414 pack-refs) : plumbing;;
415 parse-remote) : plumbing;;
416 patch-id) : plumbing;;
417 peek-remote) : plumbing;;
a925c6f1
SP
418 prune) : plumbing;;
419 prune-packed) : plumbing;;
420 quiltimport) : import;;
f2bb9f88
SP
421 read-tree) : plumbing;;
422 receive-pack) : plumbing;;
2e3a430a 423 reflog) : plumbing;;
5c66d0d4 424 repo-config) : deprecated;;
f2bb9f88
SP
425 rerere) : plumbing;;
426 rev-list) : plumbing;;
427 rev-parse) : plumbing;;
428 runstatus) : plumbing;;
429 sh-setup) : internal;;
430 shell) : daemon;;
431 send-pack) : plumbing;;
432 show-index) : plumbing;;
433 ssh-*) : transport;;
434 stripspace) : plumbing;;
435 symbolic-ref) : plumbing;;
a925c6f1 436 tar-tree) : deprecated;;
f2bb9f88
SP
437 unpack-file) : plumbing;;
438 unpack-objects) : plumbing;;
a925c6f1 439 update-index) : plumbing;;
f2bb9f88
SP
440 update-ref) : plumbing;;
441 update-server-info) : daemon;;
442 upload-archive) : plumbing;;
443 upload-pack) : plumbing;;
444 write-tree) : plumbing;;
a925c6f1 445 verify-tag) : plumbing;;
f2bb9f88
SP
446 *) echo $i;;
447 esac
448 done
449}
1eb7e2f8
LM
450__git_porcelain_commandlist=
451__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
f2bb9f88 452
367dce2a
DS
453__git_aliases ()
454{
56fc25f2 455 local i IFS=$'\n'
e0d10e1c 456 for i in $(git --git-dir="$(__gitdir)" config --list); do
56fc25f2
SP
457 case "$i" in
458 alias.*)
459 i="${i#alias.}"
460 echo "${i/=*/}"
461 ;;
462 esac
463 done
367dce2a
DS
464}
465
466__git_aliased_command ()
467{
873537fa 468 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 469 config --get "alias.$1")
367dce2a
DS
470 for word in $cmdline; do
471 if [ "${word##-*}" ]; then
472 echo $word
473 return
474 fi
475 done
476}
477
3ff1320d
SG
478__git_find_subcommand ()
479{
480 local word subcommand c=1
481
482 while [ $c -lt $COMP_CWORD ]; do
483 word="${COMP_WORDS[c]}"
484 for subcommand in $1; do
485 if [ "$subcommand" = "$word" ]; then
486 echo "$subcommand"
487 return
488 fi
489 done
490 c=$((++c))
491 done
492}
493
d773c631
SG
494__git_has_doubledash ()
495{
496 local c=1
497 while [ $c -lt $COMP_CWORD ]; do
498 if [ "--" = "${COMP_WORDS[c]}" ]; then
499 return 0
500 fi
501 c=$((++c))
502 done
503 return 1
504}
505
7950659d 506__git_whitespacelist="nowarn warn error error-all fix"
88329195
SP
507
508_git_am ()
509{
28ed6e7b 510 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
51ef1daa 511 if [ -d "$dir"/rebase-apply ]; then
a31c00b0 512 __gitcomp "--skip --resolved --abort"
88329195
SP
513 return
514 fi
515 case "$cur" in
516 --whitespace=*)
b3391775 517 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
518 return
519 ;;
520 --*)
b3391775 521 __gitcomp "
88329195
SP
522 --signoff --utf8 --binary --3way --interactive
523 --whitespace=
b3391775 524 "
88329195
SP
525 return
526 esac
527 COMPREPLY=()
528}
529
530_git_apply ()
531{
532 local cur="${COMP_WORDS[COMP_CWORD]}"
533 case "$cur" in
534 --whitespace=*)
b3391775 535 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
536 return
537 ;;
538 --*)
b3391775 539 __gitcomp "
88329195
SP
540 --stat --numstat --summary --check --index
541 --cached --index-info --reverse --reject --unidiff-zero
542 --apply --no-add --exclude=
543 --whitespace= --inaccurate-eof --verbose
b3391775 544 "
88329195
SP
545 return
546 esac
547 COMPREPLY=()
548}
549
8435b548
SP
550_git_add ()
551{
d773c631
SG
552 __git_has_doubledash && return
553
8435b548
SP
554 local cur="${COMP_WORDS[COMP_CWORD]}"
555 case "$cur" in
556 --*)
1d284cba
SG
557 __gitcomp "
558 --interactive --refresh --patch --update --dry-run
559 --ignore-errors
560 "
8435b548
SP
561 return
562 esac
563 COMPREPLY=()
564}
565
b3191ce2
LM
566_git_archive ()
567{
568 local cur="${COMP_WORDS[COMP_CWORD]}"
569 case "$cur" in
570 --format=*)
571 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
572 return
573 ;;
574 --remote=*)
575 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
576 return
577 ;;
578 --*)
579 __gitcomp "
580 --format= --list --verbose
581 --prefix= --remote= --exec=
582 "
583 return
584 ;;
585 esac
586 __git_complete_file
587}
588
b2e69f62
SP
589_git_bisect ()
590{
d773c631
SG
591 __git_has_doubledash && return
592
bf11d461 593 local subcommands="start bad good skip reset visualize replay log run"
3ff1320d
SG
594 local subcommand="$(__git_find_subcommand "$subcommands")"
595 if [ -z "$subcommand" ]; then
596 __gitcomp "$subcommands"
b2e69f62
SP
597 return
598 fi
599
3ff1320d 600 case "$subcommand" in
bf11d461 601 bad|good|reset|skip)
b2e69f62
SP
602 __gitcomp "$(__git_refs)"
603 ;;
604 *)
605 COMPREPLY=()
606 ;;
607 esac
608}
609
690d8824
JH
610_git_branch ()
611{
b9217642
SG
612 local i c=1 only_local_ref="n" has_r="n"
613
614 while [ $c -lt $COMP_CWORD ]; do
615 i="${COMP_WORDS[c]}"
616 case "$i" in
617 -d|-m) only_local_ref="y" ;;
618 -r) has_r="y" ;;
619 esac
620 c=$((++c))
621 done
622
3b376b0c
SG
623 case "${COMP_WORDS[COMP_CWORD]}" in
624 --*=*) COMPREPLY=() ;;
625 --*)
626 __gitcomp "
627 --color --no-color --verbose --abbrev= --no-abbrev
50e61025 628 --track --no-track --contains --merged --no-merged
3b376b0c
SG
629 "
630 ;;
b9217642
SG
631 *)
632 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
633 __gitcomp "$(__git_heads)"
634 else
635 __gitcomp "$(__git_refs)"
636 fi
637 ;;
3b376b0c 638 esac
690d8824
JH
639}
640
374a58c9
ML
641_git_bundle ()
642{
643 local mycword="$COMP_CWORD"
644 case "${COMP_WORDS[0]}" in
645 git)
646 local cmd="${COMP_WORDS[2]}"
647 mycword="$((mycword-1))"
648 ;;
649 git-bundle*)
650 local cmd="${COMP_WORDS[1]}"
651 ;;
652 esac
653 case "$mycword" in
654 1)
655 __gitcomp "create list-heads verify unbundle"
656 ;;
657 2)
658 # looking for a file
659 ;;
660 *)
661 case "$cmd" in
662 create)
663 __git_complete_revlist
664 ;;
665 esac
666 ;;
667 esac
668}
669
690d8824
JH
670_git_checkout ()
671{
c84bb14c
SG
672 __git_has_doubledash && return
673
b3391775 674 __gitcomp "$(__git_refs)"
690d8824
JH
675}
676
d8a9fea5
SP
677_git_cherry ()
678{
679 __gitcomp "$(__git_refs)"
680}
681
1273231e
SP
682_git_cherry_pick ()
683{
684 local cur="${COMP_WORDS[COMP_CWORD]}"
685 case "$cur" in
686 --*)
b3391775 687 __gitcomp "--edit --no-commit"
1273231e
SP
688 ;;
689 *)
b3391775 690 __gitcomp "$(__git_refs)"
1273231e
SP
691 ;;
692 esac
693}
694
4181c7e8
LM
695_git_clean ()
696{
697 __git_has_doubledash && return
698
699 local cur="${COMP_WORDS[COMP_CWORD]}"
700 case "$cur" in
701 --*)
702 __gitcomp "--dry-run --quiet"
703 return
704 ;;
705 esac
706 COMPREPLY=()
707}
708
3eb11012
LM
709_git_clone ()
710{
711 local cur="${COMP_WORDS[COMP_CWORD]}"
712 case "$cur" in
713 --*)
714 __gitcomp "
715 --local
716 --no-hardlinks
717 --shared
718 --reference
719 --quiet
720 --no-checkout
721 --bare
722 --mirror
723 --origin
724 --upload-pack
725 --template=
726 --depth
727 "
728 return
729 ;;
730 esac
731 COMPREPLY=()
732}
733
4548e855
SP
734_git_commit ()
735{
d773c631
SG
736 __git_has_doubledash && return
737
4548e855
SP
738 local cur="${COMP_WORDS[COMP_CWORD]}"
739 case "$cur" in
740 --*)
b3391775 741 __gitcomp "
4548e855
SP
742 --all --author= --signoff --verify --no-verify
743 --edit --amend --include --only
b3391775 744 "
4548e855
SP
745 return
746 esac
747 COMPREPLY=()
748}
749
217926c0
SP
750_git_describe ()
751{
cbb504c9
TR
752 local cur="${COMP_WORDS[COMP_CWORD]}"
753 case "$cur" in
754 --*)
755 __gitcomp "
756 --all --tags --contains --abbrev= --candidates=
757 --exact-match --debug --long --match --always
758 "
759 return
760 esac
217926c0
SP
761 __gitcomp "$(__git_refs)"
762}
763
690d8824
JH
764_git_diff ()
765{
d773c631
SG
766 __git_has_doubledash && return
767
b3a4f858
JS
768 local cur="${COMP_WORDS[COMP_CWORD]}"
769 case "$cur" in
770 --*)
771 __gitcomp "--cached --stat --numstat --shortstat --summary
772 --patch-with-stat --name-only --name-status --color
773 --no-color --color-words --no-renames --check
f135aacb 774 --full-index --binary --abbrev --diff-filter=
b3a4f858
JS
775 --find-copies-harder --pickaxe-all --pickaxe-regex
776 --text --ignore-space-at-eol --ignore-space-change
777 --ignore-all-space --exit-code --quiet --ext-diff
aba201c6
PO
778 --no-ext-diff
779 --no-prefix --src-prefix= --dst-prefix=
f4574139 780 --base --ours --theirs
aba201c6 781 "
b3a4f858
JS
782 return
783 ;;
784 esac
690d8824
JH
785 __git_complete_file
786}
787
690d8824
JH
788_git_fetch ()
789{
790 local cur="${COMP_WORDS[COMP_CWORD]}"
791
792 case "${COMP_WORDS[0]},$COMP_CWORD" in
793 git-fetch*,1)
b3391775 794 __gitcomp "$(__git_remotes)"
690d8824
JH
795 ;;
796 git,2)
b3391775 797 __gitcomp "$(__git_remotes)"
690d8824
JH
798 ;;
799 *)
800 case "$cur" in
801 *:*)
db8a9ff0
SP
802 local pfx=""
803 case "$COMP_WORDBREAKS" in
804 *:*) : great ;;
805 *) pfx="${cur%%:*}:" ;;
806 esac
807 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
690d8824
JH
808 ;;
809 *)
810 local remote
811 case "${COMP_WORDS[0]}" in
812 git-fetch) remote="${COMP_WORDS[1]}" ;;
813 git) remote="${COMP_WORDS[2]}" ;;
814 esac
b3391775 815 __gitcomp "$(__git_refs2 "$remote")"
690d8824
JH
816 ;;
817 esac
818 ;;
819 esac
820}
821
f53352fb
SP
822_git_format_patch ()
823{
824 local cur="${COMP_WORDS[COMP_CWORD]}"
825 case "$cur" in
826 --*)
b3391775 827 __gitcomp "
f53352fb
SP
828 --stdout --attach --thread
829 --output-directory
830 --numbered --start-number
47e98eec 831 --numbered-files
f53352fb
SP
832 --keep-subject
833 --signoff
834 --in-reply-to=
835 --full-index --binary
ec804891 836 --not --all
be5f5bf0 837 --cover-letter
aba201c6 838 --no-prefix --src-prefix= --dst-prefix=
b3391775 839 "
f53352fb
SP
840 return
841 ;;
842 esac
843 __git_complete_revlist
844}
845
b26c8748
SP
846_git_gc ()
847{
848 local cur="${COMP_WORDS[COMP_CWORD]}"
849 case "$cur" in
850 --*)
47e98eec 851 __gitcomp "--prune --aggressive"
b26c8748
SP
852 return
853 ;;
854 esac
855 COMPREPLY=()
856}
857
c72e0db1
LM
858_git_grep ()
859{
860 __git_has_doubledash && return
861
862 local cur="${COMP_WORDS[COMP_CWORD]}"
863 case "$cur" in
864 --*)
865 __gitcomp "
866 --cached
867 --text --ignore-case --word-regexp --invert-match
868 --full-name
869 --extended-regexp --basic-regexp --fixed-strings
870 --files-with-matches --name-only
871 --files-without-match
872 --count
873 --and --or --not --all-match
874 "
875 return
876 ;;
877 esac
878 COMPREPLY=()
879}
880
1eb7e2f8
LM
881_git_help ()
882{
883 local cur="${COMP_WORDS[COMP_CWORD]}"
884 case "$cur" in
885 --*)
886 __gitcomp "--all --info --man --web"
887 return
888 ;;
889 esac
2946cccf
MG
890 __gitcomp "$(__git_all_commands)
891 attributes cli core-tutorial cvs-migration
892 diffcore gitk glossary hooks ignore modules
893 repository-layout tutorial tutorial-2
894 "
1eb7e2f8
LM
895}
896
5dad868b
LM
897_git_init ()
898{
899 local cur="${COMP_WORDS[COMP_CWORD]}"
900 case "$cur" in
901 --shared=*)
902 __gitcomp "
903 false true umask group all world everybody
904 " "" "${cur##--shared=}"
905 return
906 ;;
907 --*)
908 __gitcomp "--quiet --bare --template= --shared --shared="
909 return
910 ;;
911 esac
912 COMPREPLY=()
913}
914
b1bc1494
LM
915_git_ls_files ()
916{
917 __git_has_doubledash && return
918
919 local cur="${COMP_WORDS[COMP_CWORD]}"
920 case "$cur" in
921 --*)
922 __gitcomp "--cached --deleted --modified --others --ignored
923 --stage --directory --no-empty-directory --unmerged
924 --killed --exclude= --exclude-from=
925 --exclude-per-directory= --exclude-standard
926 --error-unmatch --with-tree= --full-name
927 --abbrev --ignored --exclude-per-directory
928 "
929 return
930 ;;
931 esac
932 COMPREPLY=()
933}
934
690d8824
JH
935_git_ls_remote ()
936{
b3391775 937 __gitcomp "$(__git_remotes)"
690d8824
JH
938}
939
940_git_ls_tree ()
941{
942 __git_complete_file
943}
944
945_git_log ()
946{
d773c631
SG
947 __git_has_doubledash && return
948
6e31b866
SP
949 local cur="${COMP_WORDS[COMP_CWORD]}"
950 case "$cur" in
951 --pretty=*)
b3391775 952 __gitcomp "
6e31b866 953 oneline short medium full fuller email raw
b3391775 954 " "" "${cur##--pretty=}"
6e31b866
SP
955 return
956 ;;
47e98eec
SP
957 --date=*)
958 __gitcomp "
959 relative iso8601 rfc2822 short local default
960 " "" "${cur##--date=}"
961 return
962 ;;
6e31b866 963 --*)
b3391775 964 __gitcomp "
6e31b866
SP
965 --max-count= --max-age= --since= --after=
966 --min-age= --before= --until=
8f87fae6 967 --root --topo-order --date-order --reverse
47e98eec 968 --no-merges --follow
6e31b866 969 --abbrev-commit --abbrev=
47e98eec 970 --relative-date --date=
6e31b866
SP
971 --author= --committer= --grep=
972 --all-match
8f87fae6 973 --pretty= --name-status --name-only --raw
ec804891 974 --not --all
7d37b5bf 975 --left-right --cherry-pick
20827d99 976 --graph
66aafad5
TL
977 --stat --numstat --shortstat
978 --decorate --diff-filter=
979 --color-words --walk-reflogs
e49b99a6 980 --parents --children --full-history
5a13c8f6 981 --merge
b3391775 982 "
6e31b866
SP
983 return
984 ;;
985 esac
f53352fb 986 __git_complete_revlist
690d8824
JH
987}
988
4ad91321
SP
989_git_merge ()
990{
991 local cur="${COMP_WORDS[COMP_CWORD]}"
ce1e39d2
SP
992 case "${COMP_WORDS[COMP_CWORD-1]}" in
993 -s|--strategy)
b3391775 994 __gitcomp "$(__git_merge_strategies)"
ce1e39d2
SP
995 return
996 esac
4ad91321 997 case "$cur" in
ce1e39d2 998 --strategy=*)
b3391775 999 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
1000 return
1001 ;;
4ad91321 1002 --*)
b3391775 1003 __gitcomp "
efb779f8 1004 --no-commit --no-stat --log --no-log --squash --strategy
b3391775 1005 "
4ad91321
SP
1006 return
1007 esac
b3391775 1008 __gitcomp "$(__git_refs)"
4ad91321
SP
1009}
1010
b4c72162
LM
1011_git_mergetool ()
1012{
1013 local cur="${COMP_WORDS[COMP_CWORD]}"
1014 case "$cur" in
1015 --tool=*)
1016 __gitcomp "
1017 kdiff3 tkdiff meld xxdiff emerge
1018 vimdiff gvimdiff ecmerge opendiff
1019 " "" "${cur##--tool=}"
1020 return
1021 ;;
1022 --*)
1023 __gitcomp "--tool="
1024 return
1025 ;;
1026 esac
1027 COMPREPLY=()
1028}
1029
690d8824
JH
1030_git_merge_base ()
1031{
b3391775 1032 __gitcomp "$(__git_refs)"
690d8824
JH
1033}
1034
1127c51c
LM
1035_git_mv ()
1036{
1037 local cur="${COMP_WORDS[COMP_CWORD]}"
1038 case "$cur" in
1039 --*)
1040 __gitcomp "--dry-run"
1041 return
1042 ;;
1043 esac
1044 COMPREPLY=()
1045}
1046
d33909bf
SP
1047_git_name_rev ()
1048{
b3391775 1049 __gitcomp "--tags --all --stdin"
d33909bf
SP
1050}
1051
690d8824
JH
1052_git_pull ()
1053{
1054 local cur="${COMP_WORDS[COMP_CWORD]}"
1055
1056 case "${COMP_WORDS[0]},$COMP_CWORD" in
1057 git-pull*,1)
b3391775 1058 __gitcomp "$(__git_remotes)"
690d8824
JH
1059 ;;
1060 git,2)
b3391775 1061 __gitcomp "$(__git_remotes)"
690d8824
JH
1062 ;;
1063 *)
1064 local remote
1065 case "${COMP_WORDS[0]}" in
1066 git-pull) remote="${COMP_WORDS[1]}" ;;
1067 git) remote="${COMP_WORDS[2]}" ;;
1068 esac
b3391775 1069 __gitcomp "$(__git_refs "$remote")"
690d8824
JH
1070 ;;
1071 esac
1072}
1073
1074_git_push ()
1075{
1076 local cur="${COMP_WORDS[COMP_CWORD]}"
1077
1078 case "${COMP_WORDS[0]},$COMP_CWORD" in
1079 git-push*,1)
b3391775 1080 __gitcomp "$(__git_remotes)"
690d8824
JH
1081 ;;
1082 git,2)
b3391775 1083 __gitcomp "$(__git_remotes)"
690d8824
JH
1084 ;;
1085 *)
1086 case "$cur" in
1087 *:*)
1088 local remote
1089 case "${COMP_WORDS[0]}" in
1090 git-push) remote="${COMP_WORDS[1]}" ;;
1091 git) remote="${COMP_WORDS[2]}" ;;
1092 esac
db8a9ff0
SP
1093
1094 local pfx=""
1095 case "$COMP_WORDBREAKS" in
1096 *:*) : great ;;
1097 *) pfx="${cur%%:*}:" ;;
1098 esac
1099
1100 __gitcomp "$(__git_refs "$remote")" "$pfx" "${cur#*:}"
690d8824 1101 ;;
161fea83
SP
1102 +*)
1103 __gitcomp "$(__git_refs)" + "${cur#+}"
1104 ;;
690d8824 1105 *)
92d7c8e3 1106 __gitcomp "$(__git_refs)"
690d8824
JH
1107 ;;
1108 esac
1109 ;;
1110 esac
1111}
1112
61d926a3
SP
1113_git_rebase ()
1114{
51fe1209 1115 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
51ef1daa 1116 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
b3391775 1117 __gitcomp "--continue --skip --abort"
61d926a3
SP
1118 return
1119 fi
ce1e39d2
SP
1120 case "${COMP_WORDS[COMP_CWORD-1]}" in
1121 -s|--strategy)
b3391775 1122 __gitcomp "$(__git_merge_strategies)"
ce1e39d2
SP
1123 return
1124 esac
61d926a3 1125 case "$cur" in
ce1e39d2 1126 --strategy=*)
b3391775 1127 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
1128 return
1129 ;;
61d926a3 1130 --*)
d9e3b702 1131 __gitcomp "--onto --merge --strategy --interactive"
61d926a3
SP
1132 return
1133 esac
b3391775 1134 __gitcomp "$(__git_refs)"
61d926a3
SP
1135}
1136
25a1f374
TL
1137_git_send_email ()
1138{
1139 local cur="${COMP_WORDS[COMP_CWORD]}"
1140 case "$cur" in
1141 --*)
1142 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1143 --dry-run --envelope-sender --from --identity
1144 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1145 --no-suppress-from --no-thread --quiet
1146 --signed-off-by-cc --smtp-pass --smtp-server
1147 --smtp-server-port --smtp-ssl --smtp-user --subject
1148 --suppress-cc --suppress-from --thread --to"
1149 return
1150 ;;
1151 esac
1152 COMPREPLY=()
1153}
1154
e0d10e1c 1155_git_config ()
5de40f59
SP
1156{
1157 local cur="${COMP_WORDS[COMP_CWORD]}"
1158 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1159 case "$prv" in
1160 branch.*.remote)
78d4d6a2 1161 __gitcomp "$(__git_remotes)"
5de40f59
SP
1162 return
1163 ;;
1164 branch.*.merge)
78d4d6a2 1165 __gitcomp "$(__git_refs)"
5de40f59
SP
1166 return
1167 ;;
1168 remote.*.fetch)
1169 local remote="${prv#remote.}"
1170 remote="${remote%.fetch}"
78d4d6a2 1171 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
1172 return
1173 ;;
1174 remote.*.push)
1175 local remote="${prv#remote.}"
1176 remote="${remote%.push}"
78d4d6a2 1177 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 1178 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
1179 refs/heads)"
1180 return
1181 ;;
1182 pull.twohead|pull.octopus)
1183 __gitcomp "$(__git_merge_strategies)"
1184 return
1185 ;;
1186 color.branch|color.diff|color.status)
1187 __gitcomp "always never auto"
1188 return
1189 ;;
1190 color.*.*)
1191 __gitcomp "
1192 black red green yellow blue magenta cyan white
1193 bold dim ul blink reverse
1194 "
5de40f59
SP
1195 return
1196 ;;
1197 *.*)
1198 COMPREPLY=()
1199 return
1200 ;;
1201 esac
1202 case "$cur" in
1203 --*)
78d4d6a2 1204 __gitcomp "
47e98eec 1205 --global --system --file=
12977705 1206 --list --replace-all
5de40f59 1207 --get --get-all --get-regexp
1b71eb35 1208 --add --unset --unset-all
12977705 1209 --remove-section --rename-section
78d4d6a2 1210 "
5de40f59
SP
1211 return
1212 ;;
1213 branch.*.*)
1214 local pfx="${cur%.*}."
1215 cur="${cur##*.}"
78d4d6a2 1216 __gitcomp "remote merge" "$pfx" "$cur"
5de40f59
SP
1217 return
1218 ;;
1219 branch.*)
1220 local pfx="${cur%.*}."
1221 cur="${cur#*.}"
78d4d6a2 1222 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
5de40f59
SP
1223 return
1224 ;;
1225 remote.*.*)
1226 local pfx="${cur%.*}."
1227 cur="${cur##*.}"
12977705
SP
1228 __gitcomp "
1229 url fetch push skipDefaultUpdate
1230 receivepack uploadpack tagopt
1231 " "$pfx" "$cur"
5de40f59
SP
1232 return
1233 ;;
1234 remote.*)
1235 local pfx="${cur%.*}."
1236 cur="${cur#*.}"
78d4d6a2 1237 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
5de40f59
SP
1238 return
1239 ;;
1240 esac
78d4d6a2 1241 __gitcomp "
5de40f59
SP
1242 apply.whitespace
1243 core.fileMode
1244 core.gitProxy
1245 core.ignoreStat
1246 core.preferSymlinkRefs
1247 core.logAllRefUpdates
47e98eec 1248 core.loosecompression
5de40f59
SP
1249 core.repositoryFormatVersion
1250 core.sharedRepository
1251 core.warnAmbiguousRefs
1252 core.compression
78d4d6a2
SP
1253 core.packedGitWindowSize
1254 core.packedGitLimit
2122591b 1255 clean.requireForce
78d4d6a2
SP
1256 color.branch
1257 color.branch.current
1258 color.branch.local
1259 color.branch.remote
1260 color.branch.plain
a159ca0c 1261 color.diff
78d4d6a2
SP
1262 color.diff.plain
1263 color.diff.meta
1264 color.diff.frag
1265 color.diff.old
1266 color.diff.new
1267 color.diff.commit
1268 color.diff.whitespace
a159ca0c 1269 color.pager
a159ca0c 1270 color.status
78d4d6a2
SP
1271 color.status.header
1272 color.status.added
1273 color.status.changed
1274 color.status.untracked
1275 diff.renameLimit
1276 diff.renames
1277 fetch.unpackLimit
1278 format.headers
47e98eec 1279 format.subjectprefix
78d4d6a2
SP
1280 gitcvs.enabled
1281 gitcvs.logfile
12977705 1282 gitcvs.allbinary
6aeeffd1
JE
1283 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
1284 gitcvs.dbtablenameprefix
12977705 1285 gc.packrefs
78d4d6a2
SP
1286 gc.reflogexpire
1287 gc.reflogexpireunreachable
1288 gc.rerereresolved
1289 gc.rerereunresolved
5de40f59
SP
1290 http.sslVerify
1291 http.sslCert
1292 http.sslKey
1293 http.sslCAInfo
1294 http.sslCAPath
1295 http.maxRequests
78d4d6a2
SP
1296 http.lowSpeedLimit
1297 http.lowSpeedTime
5de40f59 1298 http.noEPSV
78d4d6a2
SP
1299 i18n.commitEncoding
1300 i18n.logOutputEncoding
1301 log.showroot
12977705 1302 merge.tool
78d4d6a2
SP
1303 merge.summary
1304 merge.verbosity
5de40f59 1305 pack.window
12977705 1306 pack.depth
47e98eec
SP
1307 pack.windowMemory
1308 pack.compression
1309 pack.deltaCacheSize
1310 pack.deltaCacheLimit
78d4d6a2
SP
1311 pull.octopus
1312 pull.twohead
5de40f59 1313 repack.useDeltaBaseOffset
78d4d6a2
SP
1314 showbranch.default
1315 tar.umask
1316 transfer.unpackLimit
5de40f59
SP
1317 receive.unpackLimit
1318 receive.denyNonFastForwards
78d4d6a2
SP
1319 user.name
1320 user.email
1321 user.signingkey
5de40f59 1322 branch. remote.
78d4d6a2 1323 "
5de40f59
SP
1324}
1325
88293c67
SP
1326_git_remote ()
1327{
3ff1320d
SG
1328 local subcommands="add rm show prune update"
1329 local subcommand="$(__git_find_subcommand "$subcommands")"
1330 if [ -z "$subcommand" ]; then
3903c618 1331 __gitcomp "$subcommands"
88293c67
SP
1332 return
1333 fi
1334
3ff1320d 1335 case "$subcommand" in
a3b811a4 1336 rm|show|prune)
88293c67
SP
1337 __gitcomp "$(__git_remotes)"
1338 ;;
fb72759b
SP
1339 update)
1340 local i c='' IFS=$'\n'
1341 for i in $(git --git-dir="$(__gitdir)" config --list); do
1342 case "$i" in
1343 remotes.*)
1344 i="${i#remotes.}"
1345 c="$c ${i/=*/}"
1346 ;;
1347 esac
1348 done
1349 __gitcomp "$c"
1350 ;;
88293c67
SP
1351 *)
1352 COMPREPLY=()
1353 ;;
1354 esac
1355}
1356
67e78c3b
SP
1357_git_reset ()
1358{
d773c631
SG
1359 __git_has_doubledash && return
1360
67e78c3b 1361 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
1362 case "$cur" in
1363 --*)
1364 __gitcomp "--mixed --hard --soft"
1365 return
1366 ;;
1367 esac
1368 __gitcomp "$(__git_refs)"
67e78c3b
SP
1369}
1370
a6c2be24
LM
1371_git_revert ()
1372{
1373 local cur="${COMP_WORDS[COMP_CWORD]}"
1374 case "$cur" in
1375 --*)
1376 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1377 return
1378 ;;
1379 esac
1380 COMPREPLY=()
1381}
1382
08c701d4
LM
1383_git_rm ()
1384{
1385 __git_has_doubledash && return
1386
1387 local cur="${COMP_WORDS[COMP_CWORD]}"
1388 case "$cur" in
1389 --*)
1390 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1391 return
1392 ;;
1393 esac
1394 COMPREPLY=()
1395}
1396
1fd6bec9
SP
1397_git_shortlog ()
1398{
d773c631
SG
1399 __git_has_doubledash && return
1400
1fd6bec9
SP
1401 local cur="${COMP_WORDS[COMP_CWORD]}"
1402 case "$cur" in
1403 --*)
1404 __gitcomp "
1405 --max-count= --max-age= --since= --after=
1406 --min-age= --before= --until=
1407 --no-merges
1408 --author= --committer= --grep=
1409 --all-match
1410 --not --all
1411 --numbered --summary
1412 "
1413 return
1414 ;;
1415 esac
1416 __git_complete_revlist
1417}
1418
90131924
SP
1419_git_show ()
1420{
1421 local cur="${COMP_WORDS[COMP_CWORD]}"
1422 case "$cur" in
1423 --pretty=*)
b3391775 1424 __gitcomp "
90131924 1425 oneline short medium full fuller email raw
b3391775 1426 " "" "${cur##--pretty=}"
90131924
SP
1427 return
1428 ;;
1429 --*)
b3391775 1430 __gitcomp "--pretty="
90131924
SP
1431 return
1432 ;;
1433 esac
1434 __git_complete_file
1435}
1436
2ca880fe
TR
1437_git_show_branch ()
1438{
1439 local cur="${COMP_WORDS[COMP_CWORD]}"
1440 case "$cur" in
1441 --*)
1442 __gitcomp "
1443 --all --remotes --topo-order --current --more=
1444 --list --independent --merge-base --no-name
1445 --sha1-name --topics --reflog
1446 "
1447 return
1448 ;;
1449 esac
1450 __git_complete_revlist
1451}
1452
7fd53fce
JH
1453_git_stash ()
1454{
95d43780 1455 local subcommands='save list show apply clear drop pop create branch'
7bedebca
SG
1456 local subcommand="$(__git_find_subcommand "$subcommands")"
1457 if [ -z "$subcommand" ]; then
3ff1320d 1458 __gitcomp "$subcommands"
7bedebca
SG
1459 else
1460 local cur="${COMP_WORDS[COMP_CWORD]}"
1461 case "$subcommand,$cur" in
1462 save,--*)
1463 __gitcomp "--keep-index"
1464 ;;
95d43780
LM
1465 apply,--*)
1466 __gitcomp "--index"
1467 ;;
5a7ebd4f 1468 show,--*|drop,--*|pop,--*|branch,--*)
95d43780
LM
1469 COMPREPLY=()
1470 ;;
1471 show,*|apply,*|drop,*|pop,*|branch,*)
1472 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1473 | sed -n -e 's/:.*//p')"
1474 ;;
7bedebca
SG
1475 *)
1476 COMPREPLY=()
1477 ;;
1478 esac
3ff1320d 1479 fi
7fd53fce
JH
1480}
1481
be86f7a0
SP
1482_git_submodule ()
1483{
d773c631
SG
1484 __git_has_doubledash && return
1485
3ff1320d
SG
1486 local subcommands="add status init update"
1487 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
be86f7a0
SP
1488 local cur="${COMP_WORDS[COMP_CWORD]}"
1489 case "$cur" in
1490 --*)
1491 __gitcomp "--quiet --cached"
1492 ;;
1493 *)
3ff1320d 1494 __gitcomp "$subcommands"
be86f7a0
SP
1495 ;;
1496 esac
1497 return
1498 fi
1499}
1500
47f6ee28
SG
1501_git_svn ()
1502{
1503 local subcommands="
1504 init fetch clone rebase dcommit log find-rev
1505 set-tree commit-diff info create-ignore propget
1506 proplist show-ignore show-externals
1507 "
1508 local subcommand="$(__git_find_subcommand "$subcommands")"
1509 if [ -z "$subcommand" ]; then
1510 __gitcomp "$subcommands"
1511 else
1512 local remote_opts="--username= --config-dir= --no-auth-cache"
1513 local fc_opts="
1514 --follow-parent --authors-file= --repack=
1515 --no-metadata --use-svm-props --use-svnsync-props
1516 --log-window-size= --no-checkout --quiet
1517 --repack-flags --user-log-author $remote_opts
1518 "
1519 local init_opts="
1520 --template= --shared= --trunk= --tags=
1521 --branches= --stdlayout --minimize-url
1522 --no-metadata --use-svm-props --use-svnsync-props
1523 --rewrite-root= $remote_opts
1524 "
1525 local cmt_opts="
1526 --edit --rmdir --find-copies-harder --copy-similarity=
1527 "
1528
1529 local cur="${COMP_WORDS[COMP_CWORD]}"
1530 case "$subcommand,$cur" in
1531 fetch,--*)
1532 __gitcomp "--revision= --fetch-all $fc_opts"
1533 ;;
1534 clone,--*)
1535 __gitcomp "--revision= $fc_opts $init_opts"
1536 ;;
1537 init,--*)
1538 __gitcomp "$init_opts"
1539 ;;
1540 dcommit,--*)
1541 __gitcomp "
1542 --merge --strategy= --verbose --dry-run
1543 --fetch-all --no-rebase $cmt_opts $fc_opts
1544 "
1545 ;;
1546 set-tree,--*)
1547 __gitcomp "--stdin $cmt_opts $fc_opts"
1548 ;;
1549 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1550 show-externals,--*)
1551 __gitcomp "--revision="
1552 ;;
1553 log,--*)
1554 __gitcomp "
1555 --limit= --revision= --verbose --incremental
1556 --oneline --show-commit --non-recursive
1557 --authors-file=
1558 "
1559 ;;
1560 rebase,--*)
1561 __gitcomp "
1562 --merge --verbose --strategy= --local
1563 --fetch-all $fc_opts
1564 "
1565 ;;
1566 commit-diff,--*)
1567 __gitcomp "--message= --file= --revision= $cmt_opts"
1568 ;;
1569 info,--*)
1570 __gitcomp "--url"
1571 ;;
1572 *)
1573 COMPREPLY=()
1574 ;;
1575 esac
1576 fi
1577}
1578
88e21dc7
SP
1579_git_tag ()
1580{
1581 local i c=1 f=0
1582 while [ $c -lt $COMP_CWORD ]; do
1583 i="${COMP_WORDS[c]}"
1584 case "$i" in
1585 -d|-v)
1586 __gitcomp "$(__git_tags)"
1587 return
1588 ;;
1589 -f)
1590 f=1
1591 ;;
1592 esac
1593 c=$((++c))
1594 done
1595
1596 case "${COMP_WORDS[COMP_CWORD-1]}" in
1597 -m|-F)
1598 COMPREPLY=()
1599 ;;
1600 -*|tag|git-tag)
1601 if [ $f = 1 ]; then
1602 __gitcomp "$(__git_tags)"
1603 else
1604 COMPREPLY=()
1605 fi
1606 ;;
1607 *)
1608 __gitcomp "$(__git_refs)"
1609 ;;
1610 esac
1611}
1612
690d8824
JH
1613_git ()
1614{
873537fa
SP
1615 local i c=1 command __git_dir
1616
1617 while [ $c -lt $COMP_CWORD ]; do
1618 i="${COMP_WORDS[c]}"
1619 case "$i" in
1620 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1621 --bare) __git_dir="." ;;
1eb7e2f8
LM
1622 --version|-p|--paginate) ;;
1623 --help) command="help"; break ;;
873537fa
SP
1624 *) command="$i"; break ;;
1625 esac
1626 c=$((++c))
1627 done
1628
1d17b22e 1629 if [ -z "$command" ]; then
72e5e989
SP
1630 case "${COMP_WORDS[COMP_CWORD]}" in
1631 --*=*) COMPREPLY=() ;;
47e98eec 1632 --*) __gitcomp "
ce5a2c95 1633 --paginate
47e98eec
SP
1634 --no-pager
1635 --git-dir=
1636 --bare
1637 --version
1638 --exec-path
ce5a2c95
TL
1639 --work-tree=
1640 --help
47e98eec
SP
1641 "
1642 ;;
1eb7e2f8 1643 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
72e5e989
SP
1644 esac
1645 return
873537fa 1646 fi
367dce2a 1647
873537fa
SP
1648 local expansion=$(__git_aliased_command "$command")
1649 [ "$expansion" ] && command="$expansion"
367dce2a 1650
873537fa 1651 case "$command" in
88329195 1652 am) _git_am ;;
8435b548 1653 add) _git_add ;;
88329195 1654 apply) _git_apply ;;
b3191ce2 1655 archive) _git_archive ;;
b2e69f62 1656 bisect) _git_bisect ;;
374a58c9 1657 bundle) _git_bundle ;;
873537fa 1658 branch) _git_branch ;;
873537fa 1659 checkout) _git_checkout ;;
d8a9fea5 1660 cherry) _git_cherry ;;
1273231e 1661 cherry-pick) _git_cherry_pick ;;
4181c7e8 1662 clean) _git_clean ;;
3eb11012 1663 clone) _git_clone ;;
4548e855 1664 commit) _git_commit ;;
e0d10e1c 1665 config) _git_config ;;
217926c0 1666 describe) _git_describe ;;
873537fa 1667 diff) _git_diff ;;
873537fa 1668 fetch) _git_fetch ;;
f53352fb 1669 format-patch) _git_format_patch ;;
b26c8748 1670 gc) _git_gc ;;
c72e0db1 1671 grep) _git_grep ;;
1eb7e2f8 1672 help) _git_help ;;
5dad868b 1673 init) _git_init ;;
873537fa 1674 log) _git_log ;;
b1bc1494 1675 ls-files) _git_ls_files ;;
873537fa
SP
1676 ls-remote) _git_ls_remote ;;
1677 ls-tree) _git_ls_tree ;;
4ad91321 1678 merge) _git_merge;;
b4c72162 1679 mergetool) _git_mergetool;;
873537fa 1680 merge-base) _git_merge_base ;;
1127c51c 1681 mv) _git_mv ;;
d33909bf 1682 name-rev) _git_name_rev ;;
873537fa
SP
1683 pull) _git_pull ;;
1684 push) _git_push ;;
61d926a3 1685 rebase) _git_rebase ;;
88293c67 1686 remote) _git_remote ;;
873537fa 1687 reset) _git_reset ;;
a6c2be24 1688 revert) _git_revert ;;
08c701d4 1689 rm) _git_rm ;;
25a1f374 1690 send-email) _git_send_email ;;
1fd6bec9 1691 shortlog) _git_shortlog ;;
90131924 1692 show) _git_show ;;
2ca880fe 1693 show-branch) _git_show_branch ;;
7fd53fce 1694 stash) _git_stash ;;
be86f7a0 1695 submodule) _git_submodule ;;
47f6ee28 1696 svn) _git_svn ;;
88e21dc7 1697 tag) _git_tag ;;
873537fa
SP
1698 whatchanged) _git_log ;;
1699 *) COMPREPLY=() ;;
1700 esac
690d8824
JH
1701}
1702
1703_gitk ()
1704{
d773c631
SG
1705 __git_has_doubledash && return
1706
690d8824 1707 local cur="${COMP_WORDS[COMP_CWORD]}"
07ba53f7
RQ
1708 local g="$(git rev-parse --git-dir 2>/dev/null)"
1709 local merge=""
1710 if [ -f $g/MERGE_HEAD ]; then
1711 merge="--merge"
1712 fi
b3391775
SP
1713 case "$cur" in
1714 --*)
07ba53f7 1715 __gitcomp "--not --all $merge"
b3391775
SP
1716 return
1717 ;;
1718 esac
ec804891 1719 __git_complete_revlist
690d8824
JH
1720}
1721
1722complete -o default -o nospace -F _git git
b3391775 1723complete -o default -o nospace -F _gitk gitk
690d8824
JH
1724
1725# The following are necessary only for Cygwin, and only are needed
1726# when the user has tab-completed the executable name and consequently
1727# included the '.exe' suffix.
1728#
76c3eb51 1729if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
144d33de 1730complete -o default -o nospace -F _git git.exe
76c3eb51 1731fi