Merge branch 'maint'
[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
873537fa
SP
48__gitdir ()
49{
67ffa114
SP
50 if [ -z "$1" ]; then
51 if [ -n "$__git_dir" ]; then
52 echo "$__git_dir"
53 elif [ -d .git ]; then
54 echo .git
55 else
56 git rev-parse --git-dir 2>/dev/null
57 fi
58 elif [ -d "$1/.git" ]; then
59 echo "$1/.git"
60 else
61 echo "$1"
62 fi
873537fa
SP
63}
64
d3d717a4
SP
65__git_ps1 ()
66{
67 local b="$(git symbolic-ref HEAD 2>/dev/null)"
68 if [ -n "$b" ]; then
69 if [ -n "$1" ]; then
70 printf "$1" "${b##refs/heads/}"
71 else
72 printf " (%s)" "${b##refs/heads/}"
73 fi
74 fi
75}
76
72e5e989
SP
77__gitcomp ()
78{
79 local all c s=$'\n' IFS=' '$'\t'$'\n'
78d4d6a2 80 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775 81 if [ $# -gt 2 ]; then
78d4d6a2
SP
82 cur="$3"
83 fi
72e5e989 84 for c in $1; do
78d4d6a2
SP
85 case "$c$4" in
86 --*=*) all="$all$c$4$s" ;;
87 *.) all="$all$c$4$s" ;;
88 *) all="$all$c$4 $s" ;;
72e5e989
SP
89 esac
90 done
91 IFS=$s
78d4d6a2 92 COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
72e5e989
SP
93 return
94}
95
5de40f59
SP
96__git_heads ()
97{
67ffa114 98 local cmd i is_hash=y dir="$(__gitdir "$1")"
5de40f59
SP
99 if [ -d "$dir" ]; then
100 for i in $(git --git-dir="$dir" \
101 for-each-ref --format='%(refname)' \
102 refs/heads ); do
103 echo "${i#refs/heads/}"
104 done
105 return
106 fi
67ffa114 107 for i in $(git-ls-remote "$1" 2>/dev/null); do
5de40f59
SP
108 case "$is_hash,$i" in
109 y,*) is_hash=n ;;
110 n,*^{}) is_hash=y ;;
111 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
112 n,*) is_hash=y; echo "$i" ;;
113 esac
114 done
115}
116
88e21dc7
SP
117__git_tags ()
118{
119 local cmd i is_hash=y dir="$(__gitdir "$1")"
120 if [ -d "$dir" ]; then
121 for i in $(git --git-dir="$dir" \
122 for-each-ref --format='%(refname)' \
123 refs/tags ); do
124 echo "${i#refs/tags/}"
125 done
126 return
127 fi
128 for i in $(git-ls-remote "$1" 2>/dev/null); do
129 case "$is_hash,$i" in
130 y,*) is_hash=n ;;
131 n,*^{}) is_hash=y ;;
132 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
133 n,*) is_hash=y; echo "$i" ;;
134 esac
135 done
136}
137
690d8824
JH
138__git_refs ()
139{
67ffa114 140 local cmd i is_hash=y dir="$(__gitdir "$1")"
873537fa 141 if [ -d "$dir" ]; then
35e65ecc
SP
142 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
143 for i in $(git --git-dir="$dir" \
144 for-each-ref --format='%(refname)' \
145 refs/tags refs/heads refs/remotes); do
146 case "$i" in
147 refs/tags/*) echo "${i#refs/tags/}" ;;
148 refs/heads/*) echo "${i#refs/heads/}" ;;
149 refs/remotes/*) echo "${i#refs/remotes/}" ;;
150 *) echo "$i" ;;
151 esac
152 done
153 return
690d8824 154 fi
35e65ecc 155 for i in $(git-ls-remote "$dir" 2>/dev/null); do
690d8824
JH
156 case "$is_hash,$i" in
157 y,*) is_hash=n ;;
158 n,*^{}) is_hash=y ;;
159 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
160 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
35e65ecc 161 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
162 n,*) is_hash=y; echo "$i" ;;
163 esac
164 done
165}
166
167__git_refs2 ()
168{
67ffa114
SP
169 local i
170 for i in $(__git_refs "$1"); do
171 echo "$i:$i"
690d8824
JH
172 done
173}
174
5de40f59
SP
175__git_refs_remotes ()
176{
177 local cmd i is_hash=y
178 for i in $(git-ls-remote "$1" 2>/dev/null); do
179 case "$is_hash,$i" in
180 n,refs/heads/*)
181 is_hash=y
182 echo "$i:refs/remotes/$1/${i#refs/heads/}"
183 ;;
184 y,*) is_hash=n ;;
185 n,*^{}) is_hash=y ;;
186 n,refs/tags/*) is_hash=y;;
187 n,*) is_hash=y; ;;
188 esac
189 done
190}
191
690d8824
JH
192__git_remotes ()
193{
873537fa 194 local i ngoff IFS=$'\n' d="$(__gitdir)"
56fc25f2 195 shopt -q nullglob || ngoff=1
690d8824 196 shopt -s nullglob
873537fa
SP
197 for i in "$d/remotes"/*; do
198 echo ${i#$d/remotes/}
690d8824 199 done
56fc25f2 200 [ "$ngoff" ] && shopt -u nullglob
e0d10e1c 201 for i in $(git --git-dir="$d" config --list); do
56fc25f2
SP
202 case "$i" in
203 remote.*.url=*)
204 i="${i#remote.}"
205 echo "${i/.url=*/}"
206 ;;
207 esac
208 done
690d8824
JH
209}
210
4ad91321
SP
211__git_merge_strategies ()
212{
b51ec6bd
SP
213 if [ -n "$__git_merge_strategylist" ]; then
214 echo "$__git_merge_strategylist"
215 return
216 fi
4ad91321
SP
217 sed -n "/^all_strategies='/{
218 s/^all_strategies='//
219 s/'//
220 p
221 q
222 }" "$(git --exec-path)/git-merge"
223}
b51ec6bd
SP
224__git_merge_strategylist=
225__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
4ad91321 226
690d8824
JH
227__git_complete_file ()
228{
a79c6551 229 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
690d8824
JH
230 case "$cur" in
231 ?*:*)
a79c6551
SP
232 ref="${cur%%:*}"
233 cur="${cur#*:}"
690d8824
JH
234 case "$cur" in
235 ?*/*)
a79c6551
SP
236 pfx="${cur%/*}"
237 cur="${cur##*/}"
690d8824
JH
238 ls="$ref:$pfx"
239 pfx="$pfx/"
240 ;;
241 *)
242 ls="$ref"
243 ;;
244 esac
245 COMPREPLY=($(compgen -P "$pfx" \
873537fa 246 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
690d8824
JH
247 | sed '/^100... blob /s,^.* ,,
248 /^040000 tree /{
249 s,^.* ,,
250 s,$,/,
251 }
252 s/^.* //')" \
253 -- "$cur"))
254 ;;
255 *)
b3391775 256 __gitcomp "$(__git_refs)"
690d8824
JH
257 ;;
258 esac
259}
260
f53352fb
SP
261__git_complete_revlist ()
262{
263 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
264 case "$cur" in
265 *...*)
266 pfx="${cur%...*}..."
267 cur="${cur#*...}"
b3391775 268 __gitcomp "$(__git_refs)" "$pfx" "$cur"
f53352fb
SP
269 ;;
270 *..*)
271 pfx="${cur%..*}.."
272 cur="${cur#*..}"
b3391775
SP
273 __gitcomp "$(__git_refs)" "$pfx" "$cur"
274 ;;
275 *.)
276 __gitcomp "$cur."
f53352fb
SP
277 ;;
278 *)
b3391775 279 __gitcomp "$(__git_refs)"
f53352fb
SP
280 ;;
281 esac
282}
283
f2bb9f88
SP
284__git_commands ()
285{
b51ec6bd
SP
286 if [ -n "$__git_commandlist" ]; then
287 echo "$__git_commandlist"
288 return
289 fi
f2bb9f88
SP
290 local i IFS=" "$'\n'
291 for i in $(git help -a|egrep '^ ')
292 do
293 case $i in
718a087a 294 *--*) : helper pattern;;
a925c6f1
SP
295 applymbox) : ask gittus;;
296 applypatch) : ask gittus;;
297 archimport) : import;;
2e3a430a 298 cat-file) : plumbing;;
56d99c67 299 check-attr) : plumbing;;
f2bb9f88
SP
300 check-ref-format) : plumbing;;
301 commit-tree) : plumbing;;
a925c6f1
SP
302 cvsexportcommit) : export;;
303 cvsimport) : import;;
f2bb9f88
SP
304 cvsserver) : daemon;;
305 daemon) : daemon;;
5cfb4fe5
SP
306 diff-files) : plumbing;;
307 diff-index) : plumbing;;
308 diff-tree) : plumbing;;
c6ec3b13 309 fast-import) : import;;
a925c6f1 310 fsck-objects) : plumbing;;
f2bb9f88 311 fetch-pack) : plumbing;;
a925c6f1 312 fmt-merge-msg) : plumbing;;
56d99c67 313 for-each-ref) : plumbing;;
f2bb9f88
SP
314 hash-object) : plumbing;;
315 http-*) : transport;;
316 index-pack) : plumbing;;
a925c6f1 317 init-db) : deprecated;;
f2bb9f88
SP
318 local-fetch) : plumbing;;
319 mailinfo) : plumbing;;
320 mailsplit) : plumbing;;
321 merge-*) : plumbing;;
322 mktree) : plumbing;;
323 mktag) : plumbing;;
324 pack-objects) : plumbing;;
325 pack-redundant) : plumbing;;
326 pack-refs) : plumbing;;
327 parse-remote) : plumbing;;
328 patch-id) : plumbing;;
329 peek-remote) : plumbing;;
a925c6f1
SP
330 prune) : plumbing;;
331 prune-packed) : plumbing;;
332 quiltimport) : import;;
f2bb9f88
SP
333 read-tree) : plumbing;;
334 receive-pack) : plumbing;;
2e3a430a 335 reflog) : plumbing;;
5c66d0d4 336 repo-config) : deprecated;;
f2bb9f88
SP
337 rerere) : plumbing;;
338 rev-list) : plumbing;;
339 rev-parse) : plumbing;;
340 runstatus) : plumbing;;
341 sh-setup) : internal;;
342 shell) : daemon;;
343 send-pack) : plumbing;;
344 show-index) : plumbing;;
345 ssh-*) : transport;;
346 stripspace) : plumbing;;
a925c6f1 347 svn) : import export;;
f2bb9f88 348 symbolic-ref) : plumbing;;
a925c6f1 349 tar-tree) : deprecated;;
f2bb9f88
SP
350 unpack-file) : plumbing;;
351 unpack-objects) : plumbing;;
a925c6f1 352 update-index) : plumbing;;
f2bb9f88
SP
353 update-ref) : plumbing;;
354 update-server-info) : daemon;;
355 upload-archive) : plumbing;;
356 upload-pack) : plumbing;;
357 write-tree) : plumbing;;
a925c6f1 358 verify-tag) : plumbing;;
f2bb9f88
SP
359 *) echo $i;;
360 esac
361 done
362}
b51ec6bd
SP
363__git_commandlist=
364__git_commandlist="$(__git_commands 2>/dev/null)"
f2bb9f88 365
367dce2a
DS
366__git_aliases ()
367{
56fc25f2 368 local i IFS=$'\n'
e0d10e1c 369 for i in $(git --git-dir="$(__gitdir)" config --list); do
56fc25f2
SP
370 case "$i" in
371 alias.*)
372 i="${i#alias.}"
373 echo "${i/=*/}"
374 ;;
375 esac
376 done
367dce2a
DS
377}
378
379__git_aliased_command ()
380{
873537fa 381 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 382 config --get "alias.$1")
367dce2a
DS
383 for word in $cmdline; do
384 if [ "${word##-*}" ]; then
385 echo $word
386 return
387 fi
388 done
389}
390
88329195
SP
391__git_whitespacelist="nowarn warn error error-all strip"
392
393_git_am ()
394{
395 local cur="${COMP_WORDS[COMP_CWORD]}"
396 if [ -d .dotest ]; then
b3391775 397 __gitcomp "--skip --resolved"
88329195
SP
398 return
399 fi
400 case "$cur" in
401 --whitespace=*)
b3391775 402 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
403 return
404 ;;
405 --*)
b3391775 406 __gitcomp "
88329195
SP
407 --signoff --utf8 --binary --3way --interactive
408 --whitespace=
b3391775 409 "
88329195
SP
410 return
411 esac
412 COMPREPLY=()
413}
414
415_git_apply ()
416{
417 local cur="${COMP_WORDS[COMP_CWORD]}"
418 case "$cur" in
419 --whitespace=*)
b3391775 420 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
421 return
422 ;;
423 --*)
b3391775 424 __gitcomp "
88329195
SP
425 --stat --numstat --summary --check --index
426 --cached --index-info --reverse --reject --unidiff-zero
427 --apply --no-add --exclude=
428 --whitespace= --inaccurate-eof --verbose
b3391775 429 "
88329195
SP
430 return
431 esac
432 COMPREPLY=()
433}
434
8435b548
SP
435_git_add ()
436{
437 local cur="${COMP_WORDS[COMP_CWORD]}"
438 case "$cur" in
439 --*)
47e98eec 440 __gitcomp "--interactive --refresh"
8435b548
SP
441 return
442 esac
443 COMPREPLY=()
444}
445
b2e69f62
SP
446_git_bisect ()
447{
448 local i c=1 command
449 while [ $c -lt $COMP_CWORD ]; do
450 i="${COMP_WORDS[c]}"
451 case "$i" in
452 start|bad|good|reset|visualize|replay|log)
453 command="$i"
454 break
455 ;;
456 esac
457 c=$((++c))
458 done
459
460 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
461 __gitcomp "start bad good reset visualize replay log"
462 return
463 fi
464
465 case "$command" in
466 bad|good|reset)
467 __gitcomp "$(__git_refs)"
468 ;;
469 *)
470 COMPREPLY=()
471 ;;
472 esac
473}
474
690d8824
JH
475_git_branch ()
476{
b3391775 477 __gitcomp "$(__git_refs)"
690d8824
JH
478}
479
374a58c9
ML
480_git_bundle ()
481{
482 local mycword="$COMP_CWORD"
483 case "${COMP_WORDS[0]}" in
484 git)
485 local cmd="${COMP_WORDS[2]}"
486 mycword="$((mycword-1))"
487 ;;
488 git-bundle*)
489 local cmd="${COMP_WORDS[1]}"
490 ;;
491 esac
492 case "$mycword" in
493 1)
494 __gitcomp "create list-heads verify unbundle"
495 ;;
496 2)
497 # looking for a file
498 ;;
499 *)
500 case "$cmd" in
501 create)
502 __git_complete_revlist
503 ;;
504 esac
505 ;;
506 esac
507}
508
690d8824
JH
509_git_checkout ()
510{
b3391775 511 __gitcomp "$(__git_refs)"
690d8824
JH
512}
513
d8a9fea5
SP
514_git_cherry ()
515{
516 __gitcomp "$(__git_refs)"
517}
518
1273231e
SP
519_git_cherry_pick ()
520{
521 local cur="${COMP_WORDS[COMP_CWORD]}"
522 case "$cur" in
523 --*)
b3391775 524 __gitcomp "--edit --no-commit"
1273231e
SP
525 ;;
526 *)
b3391775 527 __gitcomp "$(__git_refs)"
1273231e
SP
528 ;;
529 esac
530}
531
4548e855
SP
532_git_commit ()
533{
534 local cur="${COMP_WORDS[COMP_CWORD]}"
535 case "$cur" in
536 --*)
b3391775 537 __gitcomp "
4548e855
SP
538 --all --author= --signoff --verify --no-verify
539 --edit --amend --include --only
b3391775 540 "
4548e855
SP
541 return
542 esac
543 COMPREPLY=()
544}
545
217926c0
SP
546_git_describe ()
547{
548 __gitcomp "$(__git_refs)"
549}
550
690d8824
JH
551_git_diff ()
552{
b3a4f858
JS
553 local cur="${COMP_WORDS[COMP_CWORD]}"
554 case "$cur" in
555 --*)
556 __gitcomp "--cached --stat --numstat --shortstat --summary
557 --patch-with-stat --name-only --name-status --color
558 --no-color --color-words --no-renames --check
559 --full-index --binary --abbrev --diff-filter
560 --find-copies-harder --pickaxe-all --pickaxe-regex
561 --text --ignore-space-at-eol --ignore-space-change
562 --ignore-all-space --exit-code --quiet --ext-diff
563 --no-ext-diff"
564 return
565 ;;
566 esac
690d8824
JH
567 __git_complete_file
568}
569
570_git_diff_tree ()
571{
b3391775 572 __gitcomp "$(__git_refs)"
690d8824
JH
573}
574
575_git_fetch ()
576{
577 local cur="${COMP_WORDS[COMP_CWORD]}"
578
579 case "${COMP_WORDS[0]},$COMP_CWORD" in
580 git-fetch*,1)
b3391775 581 __gitcomp "$(__git_remotes)"
690d8824
JH
582 ;;
583 git,2)
b3391775 584 __gitcomp "$(__git_remotes)"
690d8824
JH
585 ;;
586 *)
587 case "$cur" in
588 *:*)
b3391775 589 __gitcomp "$(__git_refs)" "" "${cur#*:}"
690d8824
JH
590 ;;
591 *)
592 local remote
593 case "${COMP_WORDS[0]}" in
594 git-fetch) remote="${COMP_WORDS[1]}" ;;
595 git) remote="${COMP_WORDS[2]}" ;;
596 esac
b3391775 597 __gitcomp "$(__git_refs2 "$remote")"
690d8824
JH
598 ;;
599 esac
600 ;;
601 esac
602}
603
f53352fb
SP
604_git_format_patch ()
605{
606 local cur="${COMP_WORDS[COMP_CWORD]}"
607 case "$cur" in
608 --*)
b3391775 609 __gitcomp "
f53352fb
SP
610 --stdout --attach --thread
611 --output-directory
612 --numbered --start-number
47e98eec 613 --numbered-files
f53352fb
SP
614 --keep-subject
615 --signoff
616 --in-reply-to=
617 --full-index --binary
ec804891 618 --not --all
b3391775 619 "
f53352fb
SP
620 return
621 ;;
622 esac
623 __git_complete_revlist
624}
625
b26c8748
SP
626_git_gc ()
627{
628 local cur="${COMP_WORDS[COMP_CWORD]}"
629 case "$cur" in
630 --*)
47e98eec 631 __gitcomp "--prune --aggressive"
b26c8748
SP
632 return
633 ;;
634 esac
635 COMPREPLY=()
636}
637
690d8824
JH
638_git_ls_remote ()
639{
b3391775 640 __gitcomp "$(__git_remotes)"
690d8824
JH
641}
642
643_git_ls_tree ()
644{
645 __git_complete_file
646}
647
648_git_log ()
649{
6e31b866
SP
650 local cur="${COMP_WORDS[COMP_CWORD]}"
651 case "$cur" in
652 --pretty=*)
b3391775 653 __gitcomp "
6e31b866 654 oneline short medium full fuller email raw
b3391775 655 " "" "${cur##--pretty=}"
6e31b866
SP
656 return
657 ;;
47e98eec
SP
658 --date=*)
659 __gitcomp "
660 relative iso8601 rfc2822 short local default
661 " "" "${cur##--date=}"
662 return
663 ;;
6e31b866 664 --*)
b3391775 665 __gitcomp "
6e31b866
SP
666 --max-count= --max-age= --since= --after=
667 --min-age= --before= --until=
8f87fae6 668 --root --topo-order --date-order --reverse
47e98eec 669 --no-merges --follow
6e31b866 670 --abbrev-commit --abbrev=
47e98eec 671 --relative-date --date=
6e31b866
SP
672 --author= --committer= --grep=
673 --all-match
8f87fae6 674 --pretty= --name-status --name-only --raw
ec804891 675 --not --all
7d37b5bf 676 --left-right --cherry-pick
b3391775 677 "
6e31b866
SP
678 return
679 ;;
680 esac
f53352fb 681 __git_complete_revlist
690d8824
JH
682}
683
4ad91321
SP
684_git_merge ()
685{
686 local cur="${COMP_WORDS[COMP_CWORD]}"
ce1e39d2
SP
687 case "${COMP_WORDS[COMP_CWORD-1]}" in
688 -s|--strategy)
b3391775 689 __gitcomp "$(__git_merge_strategies)"
ce1e39d2
SP
690 return
691 esac
4ad91321 692 case "$cur" in
ce1e39d2 693 --strategy=*)
b3391775 694 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
695 return
696 ;;
4ad91321 697 --*)
b3391775 698 __gitcomp "
61d926a3 699 --no-commit --no-summary --squash --strategy
b3391775 700 "
4ad91321
SP
701 return
702 esac
b3391775 703 __gitcomp "$(__git_refs)"
4ad91321
SP
704}
705
690d8824
JH
706_git_merge_base ()
707{
b3391775 708 __gitcomp "$(__git_refs)"
690d8824
JH
709}
710
d33909bf
SP
711_git_name_rev ()
712{
b3391775 713 __gitcomp "--tags --all --stdin"
d33909bf
SP
714}
715
690d8824
JH
716_git_pull ()
717{
718 local cur="${COMP_WORDS[COMP_CWORD]}"
719
720 case "${COMP_WORDS[0]},$COMP_CWORD" in
721 git-pull*,1)
b3391775 722 __gitcomp "$(__git_remotes)"
690d8824
JH
723 ;;
724 git,2)
b3391775 725 __gitcomp "$(__git_remotes)"
690d8824
JH
726 ;;
727 *)
728 local remote
729 case "${COMP_WORDS[0]}" in
730 git-pull) remote="${COMP_WORDS[1]}" ;;
731 git) remote="${COMP_WORDS[2]}" ;;
732 esac
b3391775 733 __gitcomp "$(__git_refs "$remote")"
690d8824
JH
734 ;;
735 esac
736}
737
738_git_push ()
739{
740 local cur="${COMP_WORDS[COMP_CWORD]}"
741
742 case "${COMP_WORDS[0]},$COMP_CWORD" in
743 git-push*,1)
b3391775 744 __gitcomp "$(__git_remotes)"
690d8824
JH
745 ;;
746 git,2)
b3391775 747 __gitcomp "$(__git_remotes)"
690d8824
JH
748 ;;
749 *)
750 case "$cur" in
751 *:*)
752 local remote
753 case "${COMP_WORDS[0]}" in
754 git-push) remote="${COMP_WORDS[1]}" ;;
755 git) remote="${COMP_WORDS[2]}" ;;
756 esac
b3391775 757 __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
690d8824 758 ;;
161fea83
SP
759 +*)
760 __gitcomp "$(__git_refs)" + "${cur#+}"
761 ;;
690d8824 762 *)
92d7c8e3 763 __gitcomp "$(__git_refs)"
690d8824
JH
764 ;;
765 esac
766 ;;
767 esac
768}
769
61d926a3
SP
770_git_rebase ()
771{
772 local cur="${COMP_WORDS[COMP_CWORD]}"
c5650b08 773 if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
b3391775 774 __gitcomp "--continue --skip --abort"
61d926a3
SP
775 return
776 fi
ce1e39d2
SP
777 case "${COMP_WORDS[COMP_CWORD-1]}" in
778 -s|--strategy)
b3391775 779 __gitcomp "$(__git_merge_strategies)"
ce1e39d2
SP
780 return
781 esac
61d926a3 782 case "$cur" in
ce1e39d2 783 --strategy=*)
b3391775 784 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
785 return
786 ;;
61d926a3 787 --*)
b3391775 788 __gitcomp "--onto --merge --strategy"
61d926a3
SP
789 return
790 esac
b3391775 791 __gitcomp "$(__git_refs)"
61d926a3
SP
792}
793
e0d10e1c 794_git_config ()
5de40f59
SP
795{
796 local cur="${COMP_WORDS[COMP_CWORD]}"
797 local prv="${COMP_WORDS[COMP_CWORD-1]}"
798 case "$prv" in
799 branch.*.remote)
78d4d6a2 800 __gitcomp "$(__git_remotes)"
5de40f59
SP
801 return
802 ;;
803 branch.*.merge)
78d4d6a2 804 __gitcomp "$(__git_refs)"
5de40f59
SP
805 return
806 ;;
807 remote.*.fetch)
808 local remote="${prv#remote.}"
809 remote="${remote%.fetch}"
78d4d6a2 810 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
811 return
812 ;;
813 remote.*.push)
814 local remote="${prv#remote.}"
815 remote="${remote%.push}"
78d4d6a2 816 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 817 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
818 refs/heads)"
819 return
820 ;;
821 pull.twohead|pull.octopus)
822 __gitcomp "$(__git_merge_strategies)"
823 return
824 ;;
825 color.branch|color.diff|color.status)
826 __gitcomp "always never auto"
827 return
828 ;;
829 color.*.*)
830 __gitcomp "
831 black red green yellow blue magenta cyan white
832 bold dim ul blink reverse
833 "
5de40f59
SP
834 return
835 ;;
836 *.*)
837 COMPREPLY=()
838 return
839 ;;
840 esac
841 case "$cur" in
842 --*)
78d4d6a2 843 __gitcomp "
47e98eec 844 --global --system --file=
12977705 845 --list --replace-all
5de40f59 846 --get --get-all --get-regexp
1b71eb35 847 --add --unset --unset-all
12977705 848 --remove-section --rename-section
78d4d6a2 849 "
5de40f59
SP
850 return
851 ;;
852 branch.*.*)
853 local pfx="${cur%.*}."
854 cur="${cur##*.}"
78d4d6a2 855 __gitcomp "remote merge" "$pfx" "$cur"
5de40f59
SP
856 return
857 ;;
858 branch.*)
859 local pfx="${cur%.*}."
860 cur="${cur#*.}"
78d4d6a2 861 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
5de40f59
SP
862 return
863 ;;
864 remote.*.*)
865 local pfx="${cur%.*}."
866 cur="${cur##*.}"
12977705
SP
867 __gitcomp "
868 url fetch push skipDefaultUpdate
869 receivepack uploadpack tagopt
870 " "$pfx" "$cur"
5de40f59
SP
871 return
872 ;;
873 remote.*)
874 local pfx="${cur%.*}."
875 cur="${cur#*.}"
78d4d6a2 876 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
5de40f59
SP
877 return
878 ;;
879 esac
78d4d6a2 880 __gitcomp "
5de40f59
SP
881 apply.whitespace
882 core.fileMode
883 core.gitProxy
884 core.ignoreStat
885 core.preferSymlinkRefs
886 core.logAllRefUpdates
47e98eec 887 core.loosecompression
5de40f59
SP
888 core.repositoryFormatVersion
889 core.sharedRepository
890 core.warnAmbiguousRefs
891 core.compression
892 core.legacyHeaders
78d4d6a2
SP
893 core.packedGitWindowSize
894 core.packedGitLimit
2122591b 895 clean.requireForce
78d4d6a2
SP
896 color.branch
897 color.branch.current
898 color.branch.local
899 color.branch.remote
900 color.branch.plain
a159ca0c 901 color.diff
78d4d6a2
SP
902 color.diff.plain
903 color.diff.meta
904 color.diff.frag
905 color.diff.old
906 color.diff.new
907 color.diff.commit
908 color.diff.whitespace
a159ca0c 909 color.pager
a159ca0c 910 color.status
78d4d6a2
SP
911 color.status.header
912 color.status.added
913 color.status.changed
914 color.status.untracked
915 diff.renameLimit
916 diff.renames
917 fetch.unpackLimit
918 format.headers
47e98eec 919 format.subjectprefix
78d4d6a2
SP
920 gitcvs.enabled
921 gitcvs.logfile
12977705
SP
922 gitcvs.allbinary
923 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dvpass
924 gc.packrefs
78d4d6a2
SP
925 gc.reflogexpire
926 gc.reflogexpireunreachable
927 gc.rerereresolved
928 gc.rerereunresolved
5de40f59
SP
929 http.sslVerify
930 http.sslCert
931 http.sslKey
932 http.sslCAInfo
933 http.sslCAPath
934 http.maxRequests
78d4d6a2
SP
935 http.lowSpeedLimit
936 http.lowSpeedTime
5de40f59 937 http.noEPSV
78d4d6a2
SP
938 i18n.commitEncoding
939 i18n.logOutputEncoding
940 log.showroot
12977705 941 merge.tool
78d4d6a2
SP
942 merge.summary
943 merge.verbosity
5de40f59 944 pack.window
12977705 945 pack.depth
47e98eec
SP
946 pack.windowMemory
947 pack.compression
948 pack.deltaCacheSize
949 pack.deltaCacheLimit
78d4d6a2
SP
950 pull.octopus
951 pull.twohead
5de40f59 952 repack.useDeltaBaseOffset
78d4d6a2
SP
953 show.difftree
954 showbranch.default
955 tar.umask
956 transfer.unpackLimit
5de40f59
SP
957 receive.unpackLimit
958 receive.denyNonFastForwards
78d4d6a2
SP
959 user.name
960 user.email
961 user.signingkey
962 whatchanged.difftree
5de40f59 963 branch. remote.
78d4d6a2 964 "
5de40f59
SP
965}
966
88293c67
SP
967_git_remote ()
968{
969 local i c=1 command
970 while [ $c -lt $COMP_CWORD ]; do
971 i="${COMP_WORDS[c]}"
972 case "$i" in
a3b811a4 973 add|rm|show|prune|update) command="$i"; break ;;
88293c67
SP
974 esac
975 c=$((++c))
976 done
977
978 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
a3b811a4 979 __gitcomp "add rm show prune update"
88293c67
SP
980 return
981 fi
982
983 case "$command" in
a3b811a4 984 rm|show|prune)
88293c67
SP
985 __gitcomp "$(__git_remotes)"
986 ;;
fb72759b
SP
987 update)
988 local i c='' IFS=$'\n'
989 for i in $(git --git-dir="$(__gitdir)" config --list); do
990 case "$i" in
991 remotes.*)
992 i="${i#remotes.}"
993 c="$c ${i/=*/}"
994 ;;
995 esac
996 done
997 __gitcomp "$c"
998 ;;
88293c67
SP
999 *)
1000 COMPREPLY=()
1001 ;;
1002 esac
1003}
1004
67e78c3b
SP
1005_git_reset ()
1006{
1007 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
1008 case "$cur" in
1009 --*)
1010 __gitcomp "--mixed --hard --soft"
1011 return
1012 ;;
1013 esac
1014 __gitcomp "$(__git_refs)"
67e78c3b
SP
1015}
1016
1fd6bec9
SP
1017_git_shortlog ()
1018{
1019 local cur="${COMP_WORDS[COMP_CWORD]}"
1020 case "$cur" in
1021 --*)
1022 __gitcomp "
1023 --max-count= --max-age= --since= --after=
1024 --min-age= --before= --until=
1025 --no-merges
1026 --author= --committer= --grep=
1027 --all-match
1028 --not --all
1029 --numbered --summary
1030 "
1031 return
1032 ;;
1033 esac
1034 __git_complete_revlist
1035}
1036
90131924
SP
1037_git_show ()
1038{
1039 local cur="${COMP_WORDS[COMP_CWORD]}"
1040 case "$cur" in
1041 --pretty=*)
b3391775 1042 __gitcomp "
90131924 1043 oneline short medium full fuller email raw
b3391775 1044 " "" "${cur##--pretty=}"
90131924
SP
1045 return
1046 ;;
1047 --*)
b3391775 1048 __gitcomp "--pretty="
90131924
SP
1049 return
1050 ;;
1051 esac
1052 __git_complete_file
1053}
1054
7fd53fce
JH
1055_git_stash ()
1056{
1057 __gitcomp 'list show apply clear'
1058}
1059
be86f7a0
SP
1060_git_submodule ()
1061{
1062 local i c=1 command
1063 while [ $c -lt $COMP_CWORD ]; do
1064 i="${COMP_WORDS[c]}"
1065 case "$i" in
1066 add|status|init|update) command="$i"; break ;;
1067 esac
1068 c=$((++c))
1069 done
1070
1071 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
1072 local cur="${COMP_WORDS[COMP_CWORD]}"
1073 case "$cur" in
1074 --*)
1075 __gitcomp "--quiet --cached"
1076 ;;
1077 *)
1078 __gitcomp "add status init update"
1079 ;;
1080 esac
1081 return
1082 fi
1083}
1084
88e21dc7
SP
1085_git_tag ()
1086{
1087 local i c=1 f=0
1088 while [ $c -lt $COMP_CWORD ]; do
1089 i="${COMP_WORDS[c]}"
1090 case "$i" in
1091 -d|-v)
1092 __gitcomp "$(__git_tags)"
1093 return
1094 ;;
1095 -f)
1096 f=1
1097 ;;
1098 esac
1099 c=$((++c))
1100 done
1101
1102 case "${COMP_WORDS[COMP_CWORD-1]}" in
1103 -m|-F)
1104 COMPREPLY=()
1105 ;;
1106 -*|tag|git-tag)
1107 if [ $f = 1 ]; then
1108 __gitcomp "$(__git_tags)"
1109 else
1110 COMPREPLY=()
1111 fi
1112 ;;
1113 *)
1114 __gitcomp "$(__git_refs)"
1115 ;;
1116 esac
1117}
1118
690d8824
JH
1119_git ()
1120{
873537fa
SP
1121 local i c=1 command __git_dir
1122
1123 while [ $c -lt $COMP_CWORD ]; do
1124 i="${COMP_WORDS[c]}"
1125 case "$i" in
1126 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1127 --bare) __git_dir="." ;;
1128 --version|--help|-p|--paginate) ;;
1129 *) command="$i"; break ;;
1130 esac
1131 c=$((++c))
1132 done
1133
1134 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
72e5e989
SP
1135 case "${COMP_WORDS[COMP_CWORD]}" in
1136 --*=*) COMPREPLY=() ;;
47e98eec
SP
1137 --*) __gitcomp "
1138 --no-pager
1139 --git-dir=
1140 --bare
1141 --version
1142 --exec-path
1143 "
1144 ;;
72e5e989
SP
1145 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1146 esac
1147 return
873537fa 1148 fi
367dce2a 1149
873537fa
SP
1150 local expansion=$(__git_aliased_command "$command")
1151 [ "$expansion" ] && command="$expansion"
367dce2a 1152
873537fa 1153 case "$command" in
88329195 1154 am) _git_am ;;
8435b548 1155 add) _git_add ;;
88329195 1156 apply) _git_apply ;;
b2e69f62 1157 bisect) _git_bisect ;;
374a58c9 1158 bundle) _git_bundle ;;
873537fa 1159 branch) _git_branch ;;
873537fa 1160 checkout) _git_checkout ;;
d8a9fea5 1161 cherry) _git_cherry ;;
1273231e 1162 cherry-pick) _git_cherry_pick ;;
4548e855 1163 commit) _git_commit ;;
e0d10e1c 1164 config) _git_config ;;
217926c0 1165 describe) _git_describe ;;
873537fa 1166 diff) _git_diff ;;
873537fa 1167 fetch) _git_fetch ;;
f53352fb 1168 format-patch) _git_format_patch ;;
b26c8748 1169 gc) _git_gc ;;
873537fa
SP
1170 log) _git_log ;;
1171 ls-remote) _git_ls_remote ;;
1172 ls-tree) _git_ls_tree ;;
4ad91321 1173 merge) _git_merge;;
873537fa 1174 merge-base) _git_merge_base ;;
d33909bf 1175 name-rev) _git_name_rev ;;
873537fa
SP
1176 pull) _git_pull ;;
1177 push) _git_push ;;
61d926a3 1178 rebase) _git_rebase ;;
88293c67 1179 remote) _git_remote ;;
873537fa 1180 reset) _git_reset ;;
1fd6bec9 1181 shortlog) _git_shortlog ;;
90131924 1182 show) _git_show ;;
873537fa 1183 show-branch) _git_log ;;
7fd53fce 1184 stash) _git_stash ;;
be86f7a0 1185 submodule) _git_submodule ;;
88e21dc7 1186 tag) _git_tag ;;
873537fa
SP
1187 whatchanged) _git_log ;;
1188 *) COMPREPLY=() ;;
1189 esac
690d8824
JH
1190}
1191
1192_gitk ()
1193{
1194 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
1195 case "$cur" in
1196 --*)
1197 __gitcomp "--not --all"
1198 return
1199 ;;
1200 esac
ec804891 1201 __git_complete_revlist
690d8824
JH
1202}
1203
1204complete -o default -o nospace -F _git git
b3391775
SP
1205complete -o default -o nospace -F _gitk gitk
1206complete -o default -o nospace -F _git_am git-am
1207complete -o default -o nospace -F _git_apply git-apply
b2e69f62 1208complete -o default -o nospace -F _git_bisect git-bisect
b3391775 1209complete -o default -o nospace -F _git_branch git-branch
374a58c9 1210complete -o default -o nospace -F _git_bundle git-bundle
b3391775 1211complete -o default -o nospace -F _git_checkout git-checkout
d8a9fea5 1212complete -o default -o nospace -F _git_cherry git-cherry
b3391775
SP
1213complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1214complete -o default -o nospace -F _git_commit git-commit
217926c0 1215complete -o default -o nospace -F _git_describe git-describe
690d8824 1216complete -o default -o nospace -F _git_diff git-diff
690d8824 1217complete -o default -o nospace -F _git_fetch git-fetch
f53352fb 1218complete -o default -o nospace -F _git_format_patch git-format-patch
b26c8748 1219complete -o default -o nospace -F _git_gc git-gc
690d8824 1220complete -o default -o nospace -F _git_log git-log
b3391775 1221complete -o default -o nospace -F _git_ls_remote git-ls-remote
690d8824 1222complete -o default -o nospace -F _git_ls_tree git-ls-tree
b3391775
SP
1223complete -o default -o nospace -F _git_merge git-merge
1224complete -o default -o nospace -F _git_merge_base git-merge-base
1225complete -o default -o nospace -F _git_name_rev git-name-rev
690d8824
JH
1226complete -o default -o nospace -F _git_pull git-pull
1227complete -o default -o nospace -F _git_push git-push
b3391775
SP
1228complete -o default -o nospace -F _git_rebase git-rebase
1229complete -o default -o nospace -F _git_config git-config
88293c67 1230complete -o default -o nospace -F _git_remote git-remote
b3391775 1231complete -o default -o nospace -F _git_reset git-reset
1fd6bec9 1232complete -o default -o nospace -F _git_shortlog git-shortlog
90131924 1233complete -o default -o nospace -F _git_show git-show
7fd53fce 1234complete -o default -o nospace -F _git_stash git-stash
be86f7a0 1235complete -o default -o nospace -F _git_submodule git-submodule
144d33de 1236complete -o default -o nospace -F _git_log git-show-branch
88e21dc7 1237complete -o default -o nospace -F _git_tag git-tag
690d8824
JH
1238complete -o default -o nospace -F _git_log git-whatchanged
1239
1240# The following are necessary only for Cygwin, and only are needed
1241# when the user has tab-completed the executable name and consequently
1242# included the '.exe' suffix.
1243#
76c3eb51 1244if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
b3391775
SP
1245complete -o default -o nospace -F _git_add git-add.exe
1246complete -o default -o nospace -F _git_apply git-apply.exe
144d33de 1247complete -o default -o nospace -F _git git.exe
b3391775 1248complete -o default -o nospace -F _git_branch git-branch.exe
374a58c9 1249complete -o default -o nospace -F _git_bundle git-bundle.exe
d8a9fea5 1250complete -o default -o nospace -F _git_cherry git-cherry.exe
217926c0 1251complete -o default -o nospace -F _git_describe git-describe.exe
690d8824 1252complete -o default -o nospace -F _git_diff git-diff.exe
f53352fb 1253complete -o default -o nospace -F _git_format_patch git-format-patch.exe
690d8824
JH
1254complete -o default -o nospace -F _git_log git-log.exe
1255complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
b3391775
SP
1256complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1257complete -o default -o nospace -F _git_name_rev git-name-rev.exe
690d8824 1258complete -o default -o nospace -F _git_push git-push.exe
b3391775 1259complete -o default -o nospace -F _git_config git-config
1fd6bec9 1260complete -o default -o nospace -F _git_shortlog git-shortlog.exe
90131924 1261complete -o default -o nospace -F _git_show git-show.exe
144d33de 1262complete -o default -o nospace -F _git_log git-show-branch.exe
88e21dc7 1263complete -o default -o nospace -F _git_tag git-tag.exe
690d8824 1264complete -o default -o nospace -F _git_log git-whatchanged.exe
76c3eb51 1265fi