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