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