]> git.ipfire.org Git - thirdparty/git.git/blame - contrib/completion/git-completion.bash
Teach bash completion about git-shortlog
[thirdparty/git.git] / contrib / completion / git-completion.bash
CommitLineData
690d8824
JH
1#
2# bash completion support for core Git.
3#
2e3a430a 4# Copyright (C) 2006,2007 Shawn Pearce
690d8824
JH
5# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
6#
7# The contained completion routines provide support for completing:
8#
9# *) local and remote branch names
10# *) local and remote tag names
11# *) .git/remotes file names
12# *) git 'subcommands'
13# *) tree paths within 'ref:path/to/file' expressions
14#
15# To use these routines:
16#
17# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
18# 2) Added the following line to your .bashrc:
19# source ~/.git-completion.sh
20#
b51ec6bd
SP
21# 3) You may want to make sure the git executable is available
22# in your PATH before this script is sourced, as some caching
23# is performed while the script loads. If git isn't found
24# at source time then all lookups will be done on demand,
25# which may be slightly slower.
26#
27# 4) Consider changing your PS1 to also show the current branch:
d3d717a4
SP
28# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
29#
30# The argument to __git_ps1 will be displayed only if you
31# are currently in a git repository. The %s token will be
32# the name of the current branch.
33#
690d8824 34
873537fa
SP
35__gitdir ()
36{
67ffa114
SP
37 if [ -z "$1" ]; then
38 if [ -n "$__git_dir" ]; then
39 echo "$__git_dir"
40 elif [ -d .git ]; then
41 echo .git
42 else
43 git rev-parse --git-dir 2>/dev/null
44 fi
45 elif [ -d "$1/.git" ]; then
46 echo "$1/.git"
47 else
48 echo "$1"
49 fi
873537fa
SP
50}
51
d3d717a4
SP
52__git_ps1 ()
53{
54 local b="$(git symbolic-ref HEAD 2>/dev/null)"
55 if [ -n "$b" ]; then
56 if [ -n "$1" ]; then
57 printf "$1" "${b##refs/heads/}"
58 else
59 printf " (%s)" "${b##refs/heads/}"
60 fi
61 fi
62}
63
72e5e989
SP
64__gitcomp ()
65{
66 local all c s=$'\n' IFS=' '$'\t'$'\n'
78d4d6a2 67 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775 68 if [ $# -gt 2 ]; then
78d4d6a2
SP
69 cur="$3"
70 fi
72e5e989 71 for c in $1; do
78d4d6a2
SP
72 case "$c$4" in
73 --*=*) all="$all$c$4$s" ;;
74 *.) all="$all$c$4$s" ;;
75 *) all="$all$c$4 $s" ;;
72e5e989
SP
76 esac
77 done
78 IFS=$s
78d4d6a2 79 COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
72e5e989
SP
80 return
81}
82
5de40f59
SP
83__git_heads ()
84{
67ffa114 85 local cmd i is_hash=y dir="$(__gitdir "$1")"
5de40f59
SP
86 if [ -d "$dir" ]; then
87 for i in $(git --git-dir="$dir" \
88 for-each-ref --format='%(refname)' \
89 refs/heads ); do
90 echo "${i#refs/heads/}"
91 done
92 return
93 fi
67ffa114 94 for i in $(git-ls-remote "$1" 2>/dev/null); do
5de40f59
SP
95 case "$is_hash,$i" in
96 y,*) is_hash=n ;;
97 n,*^{}) is_hash=y ;;
98 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
99 n,*) is_hash=y; echo "$i" ;;
100 esac
101 done
102}
103
690d8824
JH
104__git_refs ()
105{
67ffa114 106 local cmd i is_hash=y dir="$(__gitdir "$1")"
873537fa 107 if [ -d "$dir" ]; then
35e65ecc
SP
108 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
109 for i in $(git --git-dir="$dir" \
110 for-each-ref --format='%(refname)' \
111 refs/tags refs/heads refs/remotes); do
112 case "$i" in
113 refs/tags/*) echo "${i#refs/tags/}" ;;
114 refs/heads/*) echo "${i#refs/heads/}" ;;
115 refs/remotes/*) echo "${i#refs/remotes/}" ;;
116 *) echo "$i" ;;
117 esac
118 done
119 return
690d8824 120 fi
35e65ecc 121 for i in $(git-ls-remote "$dir" 2>/dev/null); do
690d8824
JH
122 case "$is_hash,$i" in
123 y,*) is_hash=n ;;
124 n,*^{}) is_hash=y ;;
125 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
126 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
35e65ecc 127 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
128 n,*) is_hash=y; echo "$i" ;;
129 esac
130 done
131}
132
133__git_refs2 ()
134{
67ffa114
SP
135 local i
136 for i in $(__git_refs "$1"); do
137 echo "$i:$i"
690d8824
JH
138 done
139}
140
5de40f59
SP
141__git_refs_remotes ()
142{
143 local cmd i is_hash=y
144 for i in $(git-ls-remote "$1" 2>/dev/null); do
145 case "$is_hash,$i" in
146 n,refs/heads/*)
147 is_hash=y
148 echo "$i:refs/remotes/$1/${i#refs/heads/}"
149 ;;
150 y,*) is_hash=n ;;
151 n,*^{}) is_hash=y ;;
152 n,refs/tags/*) is_hash=y;;
153 n,*) is_hash=y; ;;
154 esac
155 done
156}
157
690d8824
JH
158__git_remotes ()
159{
873537fa 160 local i ngoff IFS=$'\n' d="$(__gitdir)"
56fc25f2 161 shopt -q nullglob || ngoff=1
690d8824 162 shopt -s nullglob
873537fa
SP
163 for i in "$d/remotes"/*; do
164 echo ${i#$d/remotes/}
690d8824 165 done
56fc25f2 166 [ "$ngoff" ] && shopt -u nullglob
e0d10e1c 167 for i in $(git --git-dir="$d" config --list); do
56fc25f2
SP
168 case "$i" in
169 remote.*.url=*)
170 i="${i#remote.}"
171 echo "${i/.url=*/}"
172 ;;
173 esac
174 done
690d8824
JH
175}
176
4ad91321
SP
177__git_merge_strategies ()
178{
b51ec6bd
SP
179 if [ -n "$__git_merge_strategylist" ]; then
180 echo "$__git_merge_strategylist"
181 return
182 fi
4ad91321
SP
183 sed -n "/^all_strategies='/{
184 s/^all_strategies='//
185 s/'//
186 p
187 q
188 }" "$(git --exec-path)/git-merge"
189}
b51ec6bd
SP
190__git_merge_strategylist=
191__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
4ad91321 192
690d8824
JH
193__git_complete_file ()
194{
a79c6551 195 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
690d8824
JH
196 case "$cur" in
197 ?*:*)
a79c6551
SP
198 ref="${cur%%:*}"
199 cur="${cur#*:}"
690d8824
JH
200 case "$cur" in
201 ?*/*)
a79c6551
SP
202 pfx="${cur%/*}"
203 cur="${cur##*/}"
690d8824
JH
204 ls="$ref:$pfx"
205 pfx="$pfx/"
206 ;;
207 *)
208 ls="$ref"
209 ;;
210 esac
211 COMPREPLY=($(compgen -P "$pfx" \
873537fa 212 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
690d8824
JH
213 | sed '/^100... blob /s,^.* ,,
214 /^040000 tree /{
215 s,^.* ,,
216 s,$,/,
217 }
218 s/^.* //')" \
219 -- "$cur"))
220 ;;
221 *)
b3391775 222 __gitcomp "$(__git_refs)"
690d8824
JH
223 ;;
224 esac
225}
226
f53352fb
SP
227__git_complete_revlist ()
228{
229 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
230 case "$cur" in
231 *...*)
232 pfx="${cur%...*}..."
233 cur="${cur#*...}"
b3391775 234 __gitcomp "$(__git_refs)" "$pfx" "$cur"
f53352fb
SP
235 ;;
236 *..*)
237 pfx="${cur%..*}.."
238 cur="${cur#*..}"
b3391775
SP
239 __gitcomp "$(__git_refs)" "$pfx" "$cur"
240 ;;
241 *.)
242 __gitcomp "$cur."
f53352fb
SP
243 ;;
244 *)
b3391775 245 __gitcomp "$(__git_refs)"
f53352fb
SP
246 ;;
247 esac
248}
249
f2bb9f88
SP
250__git_commands ()
251{
b51ec6bd
SP
252 if [ -n "$__git_commandlist" ]; then
253 echo "$__git_commandlist"
254 return
255 fi
f2bb9f88
SP
256 local i IFS=" "$'\n'
257 for i in $(git help -a|egrep '^ ')
258 do
259 case $i in
8435b548 260 add--interactive) : plumbing;;
a925c6f1
SP
261 applymbox) : ask gittus;;
262 applypatch) : ask gittus;;
263 archimport) : import;;
2e3a430a 264 cat-file) : plumbing;;
56d99c67 265 check-attr) : plumbing;;
f2bb9f88
SP
266 check-ref-format) : plumbing;;
267 commit-tree) : plumbing;;
268 convert-objects) : plumbing;;
a925c6f1
SP
269 cvsexportcommit) : export;;
270 cvsimport) : import;;
f2bb9f88
SP
271 cvsserver) : daemon;;
272 daemon) : daemon;;
5cfb4fe5
SP
273 diff-files) : plumbing;;
274 diff-index) : plumbing;;
275 diff-tree) : plumbing;;
c6ec3b13 276 fast-import) : import;;
a925c6f1 277 fsck-objects) : plumbing;;
56d99c67 278 fetch--tool) : plumbing;;
f2bb9f88 279 fetch-pack) : plumbing;;
a925c6f1 280 fmt-merge-msg) : plumbing;;
56d99c67 281 for-each-ref) : plumbing;;
f2bb9f88
SP
282 hash-object) : plumbing;;
283 http-*) : transport;;
284 index-pack) : plumbing;;
a925c6f1 285 init-db) : deprecated;;
f2bb9f88
SP
286 local-fetch) : plumbing;;
287 mailinfo) : plumbing;;
288 mailsplit) : plumbing;;
289 merge-*) : plumbing;;
290 mktree) : plumbing;;
291 mktag) : plumbing;;
292 pack-objects) : plumbing;;
293 pack-redundant) : plumbing;;
294 pack-refs) : plumbing;;
295 parse-remote) : plumbing;;
296 patch-id) : plumbing;;
297 peek-remote) : plumbing;;
a925c6f1
SP
298 prune) : plumbing;;
299 prune-packed) : plumbing;;
300 quiltimport) : import;;
f2bb9f88
SP
301 read-tree) : plumbing;;
302 receive-pack) : plumbing;;
2e3a430a 303 reflog) : plumbing;;
a925c6f1 304 repo-config) : plumbing;;
f2bb9f88
SP
305 rerere) : plumbing;;
306 rev-list) : plumbing;;
307 rev-parse) : plumbing;;
308 runstatus) : plumbing;;
309 sh-setup) : internal;;
310 shell) : daemon;;
311 send-pack) : plumbing;;
312 show-index) : plumbing;;
313 ssh-*) : transport;;
314 stripspace) : plumbing;;
a925c6f1
SP
315 svn) : import export;;
316 svnimport) : import;;
f2bb9f88 317 symbolic-ref) : plumbing;;
a925c6f1 318 tar-tree) : deprecated;;
f2bb9f88
SP
319 unpack-file) : plumbing;;
320 unpack-objects) : plumbing;;
a925c6f1 321 update-index) : plumbing;;
f2bb9f88
SP
322 update-ref) : plumbing;;
323 update-server-info) : daemon;;
324 upload-archive) : plumbing;;
325 upload-pack) : plumbing;;
326 write-tree) : plumbing;;
a925c6f1 327 verify-tag) : plumbing;;
f2bb9f88
SP
328 *) echo $i;;
329 esac
330 done
331}
b51ec6bd
SP
332__git_commandlist=
333__git_commandlist="$(__git_commands 2>/dev/null)"
f2bb9f88 334
367dce2a
DS
335__git_aliases ()
336{
56fc25f2 337 local i IFS=$'\n'
e0d10e1c 338 for i in $(git --git-dir="$(__gitdir)" config --list); do
56fc25f2
SP
339 case "$i" in
340 alias.*)
341 i="${i#alias.}"
342 echo "${i/=*/}"
343 ;;
344 esac
345 done
367dce2a
DS
346}
347
348__git_aliased_command ()
349{
873537fa 350 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 351 config --get "alias.$1")
367dce2a
DS
352 for word in $cmdline; do
353 if [ "${word##-*}" ]; then
354 echo $word
355 return
356 fi
357 done
358}
359
88329195
SP
360__git_whitespacelist="nowarn warn error error-all strip"
361
362_git_am ()
363{
364 local cur="${COMP_WORDS[COMP_CWORD]}"
365 if [ -d .dotest ]; then
b3391775 366 __gitcomp "--skip --resolved"
88329195
SP
367 return
368 fi
369 case "$cur" in
370 --whitespace=*)
b3391775 371 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
372 return
373 ;;
374 --*)
b3391775 375 __gitcomp "
88329195
SP
376 --signoff --utf8 --binary --3way --interactive
377 --whitespace=
b3391775 378 "
88329195
SP
379 return
380 esac
381 COMPREPLY=()
382}
383
384_git_apply ()
385{
386 local cur="${COMP_WORDS[COMP_CWORD]}"
387 case "$cur" in
388 --whitespace=*)
b3391775 389 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
390 return
391 ;;
392 --*)
b3391775 393 __gitcomp "
88329195
SP
394 --stat --numstat --summary --check --index
395 --cached --index-info --reverse --reject --unidiff-zero
396 --apply --no-add --exclude=
397 --whitespace= --inaccurate-eof --verbose
b3391775 398 "
88329195
SP
399 return
400 esac
401 COMPREPLY=()
402}
403
8435b548
SP
404_git_add ()
405{
406 local cur="${COMP_WORDS[COMP_CWORD]}"
407 case "$cur" in
408 --*)
b3391775 409 __gitcomp "--interactive"
8435b548
SP
410 return
411 esac
412 COMPREPLY=()
413}
414
b2e69f62
SP
415_git_bisect ()
416{
417 local i c=1 command
418 while [ $c -lt $COMP_CWORD ]; do
419 i="${COMP_WORDS[c]}"
420 case "$i" in
421 start|bad|good|reset|visualize|replay|log)
422 command="$i"
423 break
424 ;;
425 esac
426 c=$((++c))
427 done
428
429 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
430 __gitcomp "start bad good reset visualize replay log"
431 return
432 fi
433
434 case "$command" in
435 bad|good|reset)
436 __gitcomp "$(__git_refs)"
437 ;;
438 *)
439 COMPREPLY=()
440 ;;
441 esac
442}
443
690d8824
JH
444_git_branch ()
445{
b3391775 446 __gitcomp "$(__git_refs)"
690d8824
JH
447}
448
690d8824
JH
449_git_checkout ()
450{
b3391775 451 __gitcomp "$(__git_refs)"
690d8824
JH
452}
453
d8a9fea5
SP
454_git_cherry ()
455{
456 __gitcomp "$(__git_refs)"
457}
458
1273231e
SP
459_git_cherry_pick ()
460{
461 local cur="${COMP_WORDS[COMP_CWORD]}"
462 case "$cur" in
463 --*)
b3391775 464 __gitcomp "--edit --no-commit"
1273231e
SP
465 ;;
466 *)
b3391775 467 __gitcomp "$(__git_refs)"
1273231e
SP
468 ;;
469 esac
470}
471
4548e855
SP
472_git_commit ()
473{
474 local cur="${COMP_WORDS[COMP_CWORD]}"
475 case "$cur" in
476 --*)
b3391775 477 __gitcomp "
4548e855
SP
478 --all --author= --signoff --verify --no-verify
479 --edit --amend --include --only
b3391775 480 "
4548e855
SP
481 return
482 esac
483 COMPREPLY=()
484}
485
690d8824
JH
486_git_diff ()
487{
488 __git_complete_file
489}
490
491_git_diff_tree ()
492{
b3391775 493 __gitcomp "$(__git_refs)"
690d8824
JH
494}
495
496_git_fetch ()
497{
498 local cur="${COMP_WORDS[COMP_CWORD]}"
499
500 case "${COMP_WORDS[0]},$COMP_CWORD" in
501 git-fetch*,1)
b3391775 502 __gitcomp "$(__git_remotes)"
690d8824
JH
503 ;;
504 git,2)
b3391775 505 __gitcomp "$(__git_remotes)"
690d8824
JH
506 ;;
507 *)
508 case "$cur" in
509 *:*)
b3391775 510 __gitcomp "$(__git_refs)" "" "${cur#*:}"
690d8824
JH
511 ;;
512 *)
513 local remote
514 case "${COMP_WORDS[0]}" in
515 git-fetch) remote="${COMP_WORDS[1]}" ;;
516 git) remote="${COMP_WORDS[2]}" ;;
517 esac
b3391775 518 __gitcomp "$(__git_refs2 "$remote")"
690d8824
JH
519 ;;
520 esac
521 ;;
522 esac
523}
524
f53352fb
SP
525_git_format_patch ()
526{
527 local cur="${COMP_WORDS[COMP_CWORD]}"
528 case "$cur" in
529 --*)
b3391775 530 __gitcomp "
f53352fb
SP
531 --stdout --attach --thread
532 --output-directory
533 --numbered --start-number
534 --keep-subject
535 --signoff
536 --in-reply-to=
537 --full-index --binary
ec804891 538 --not --all
b3391775 539 "
f53352fb
SP
540 return
541 ;;
542 esac
543 __git_complete_revlist
544}
545
b26c8748
SP
546_git_gc ()
547{
548 local cur="${COMP_WORDS[COMP_CWORD]}"
549 case "$cur" in
550 --*)
551 __gitcomp "--prune"
552 return
553 ;;
554 esac
555 COMPREPLY=()
556}
557
690d8824
JH
558_git_ls_remote ()
559{
b3391775 560 __gitcomp "$(__git_remotes)"
690d8824
JH
561}
562
563_git_ls_tree ()
564{
565 __git_complete_file
566}
567
568_git_log ()
569{
6e31b866
SP
570 local cur="${COMP_WORDS[COMP_CWORD]}"
571 case "$cur" in
572 --pretty=*)
b3391775 573 __gitcomp "
6e31b866 574 oneline short medium full fuller email raw
b3391775 575 " "" "${cur##--pretty=}"
6e31b866
SP
576 return
577 ;;
578 --*)
b3391775 579 __gitcomp "
6e31b866
SP
580 --max-count= --max-age= --since= --after=
581 --min-age= --before= --until=
582 --root --not --topo-order --date-order
583 --no-merges
584 --abbrev-commit --abbrev=
585 --relative-date
586 --author= --committer= --grep=
587 --all-match
588 --pretty= --name-status --name-only
ec804891 589 --not --all
b3391775 590 "
6e31b866
SP
591 return
592 ;;
593 esac
f53352fb 594 __git_complete_revlist
690d8824
JH
595}
596
4ad91321
SP
597_git_merge ()
598{
599 local cur="${COMP_WORDS[COMP_CWORD]}"
ce1e39d2
SP
600 case "${COMP_WORDS[COMP_CWORD-1]}" in
601 -s|--strategy)
b3391775 602 __gitcomp "$(__git_merge_strategies)"
ce1e39d2
SP
603 return
604 esac
4ad91321 605 case "$cur" in
ce1e39d2 606 --strategy=*)
b3391775 607 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
608 return
609 ;;
4ad91321 610 --*)
b3391775 611 __gitcomp "
61d926a3 612 --no-commit --no-summary --squash --strategy
b3391775 613 "
4ad91321
SP
614 return
615 esac
b3391775 616 __gitcomp "$(__git_refs)"
4ad91321
SP
617}
618
690d8824
JH
619_git_merge_base ()
620{
b3391775 621 __gitcomp "$(__git_refs)"
690d8824
JH
622}
623
d33909bf
SP
624_git_name_rev ()
625{
b3391775 626 __gitcomp "--tags --all --stdin"
d33909bf
SP
627}
628
690d8824
JH
629_git_pull ()
630{
631 local cur="${COMP_WORDS[COMP_CWORD]}"
632
633 case "${COMP_WORDS[0]},$COMP_CWORD" in
634 git-pull*,1)
b3391775 635 __gitcomp "$(__git_remotes)"
690d8824
JH
636 ;;
637 git,2)
b3391775 638 __gitcomp "$(__git_remotes)"
690d8824
JH
639 ;;
640 *)
641 local remote
642 case "${COMP_WORDS[0]}" in
643 git-pull) remote="${COMP_WORDS[1]}" ;;
644 git) remote="${COMP_WORDS[2]}" ;;
645 esac
b3391775 646 __gitcomp "$(__git_refs "$remote")"
690d8824
JH
647 ;;
648 esac
649}
650
651_git_push ()
652{
653 local cur="${COMP_WORDS[COMP_CWORD]}"
654
655 case "${COMP_WORDS[0]},$COMP_CWORD" in
656 git-push*,1)
b3391775 657 __gitcomp "$(__git_remotes)"
690d8824
JH
658 ;;
659 git,2)
b3391775 660 __gitcomp "$(__git_remotes)"
690d8824
JH
661 ;;
662 *)
663 case "$cur" in
664 *:*)
665 local remote
666 case "${COMP_WORDS[0]}" in
667 git-push) remote="${COMP_WORDS[1]}" ;;
668 git) remote="${COMP_WORDS[2]}" ;;
669 esac
b3391775 670 __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
690d8824
JH
671 ;;
672 *)
b3391775 673 __gitcomp "$(__git_refs2)"
690d8824
JH
674 ;;
675 esac
676 ;;
677 esac
678}
679
61d926a3
SP
680_git_rebase ()
681{
682 local cur="${COMP_WORDS[COMP_CWORD]}"
c5650b08 683 if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
b3391775 684 __gitcomp "--continue --skip --abort"
61d926a3
SP
685 return
686 fi
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
61d926a3 692 case "$cur" in
ce1e39d2 693 --strategy=*)
b3391775 694 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
695 return
696 ;;
61d926a3 697 --*)
b3391775 698 __gitcomp "--onto --merge --strategy"
61d926a3
SP
699 return
700 esac
b3391775 701 __gitcomp "$(__git_refs)"
61d926a3
SP
702}
703
e0d10e1c 704_git_config ()
5de40f59
SP
705{
706 local cur="${COMP_WORDS[COMP_CWORD]}"
707 local prv="${COMP_WORDS[COMP_CWORD-1]}"
708 case "$prv" in
709 branch.*.remote)
78d4d6a2 710 __gitcomp "$(__git_remotes)"
5de40f59
SP
711 return
712 ;;
713 branch.*.merge)
78d4d6a2 714 __gitcomp "$(__git_refs)"
5de40f59
SP
715 return
716 ;;
717 remote.*.fetch)
718 local remote="${prv#remote.}"
719 remote="${remote%.fetch}"
78d4d6a2 720 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
721 return
722 ;;
723 remote.*.push)
724 local remote="${prv#remote.}"
725 remote="${remote%.push}"
78d4d6a2 726 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 727 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
728 refs/heads)"
729 return
730 ;;
731 pull.twohead|pull.octopus)
732 __gitcomp "$(__git_merge_strategies)"
733 return
734 ;;
735 color.branch|color.diff|color.status)
736 __gitcomp "always never auto"
737 return
738 ;;
739 color.*.*)
740 __gitcomp "
741 black red green yellow blue magenta cyan white
742 bold dim ul blink reverse
743 "
5de40f59
SP
744 return
745 ;;
746 *.*)
747 COMPREPLY=()
748 return
749 ;;
750 esac
751 case "$cur" in
752 --*)
78d4d6a2 753 __gitcomp "
5de40f59
SP
754 --global --list --replace-all
755 --get --get-all --get-regexp
1b71eb35 756 --add --unset --unset-all
78d4d6a2 757 "
5de40f59
SP
758 return
759 ;;
760 branch.*.*)
761 local pfx="${cur%.*}."
762 cur="${cur##*.}"
78d4d6a2 763 __gitcomp "remote merge" "$pfx" "$cur"
5de40f59
SP
764 return
765 ;;
766 branch.*)
767 local pfx="${cur%.*}."
768 cur="${cur#*.}"
78d4d6a2 769 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
5de40f59
SP
770 return
771 ;;
772 remote.*.*)
773 local pfx="${cur%.*}."
774 cur="${cur##*.}"
78d4d6a2 775 __gitcomp "url fetch push" "$pfx" "$cur"
5de40f59
SP
776 return
777 ;;
778 remote.*)
779 local pfx="${cur%.*}."
780 cur="${cur#*.}"
78d4d6a2 781 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
5de40f59
SP
782 return
783 ;;
784 esac
78d4d6a2 785 __gitcomp "
5de40f59
SP
786 apply.whitespace
787 core.fileMode
788 core.gitProxy
789 core.ignoreStat
790 core.preferSymlinkRefs
791 core.logAllRefUpdates
792 core.repositoryFormatVersion
793 core.sharedRepository
794 core.warnAmbiguousRefs
795 core.compression
796 core.legacyHeaders
78d4d6a2
SP
797 core.packedGitWindowSize
798 core.packedGitLimit
2122591b 799 clean.requireForce
78d4d6a2
SP
800 color.branch
801 color.branch.current
802 color.branch.local
803 color.branch.remote
804 color.branch.plain
a159ca0c 805 color.diff
78d4d6a2
SP
806 color.diff.plain
807 color.diff.meta
808 color.diff.frag
809 color.diff.old
810 color.diff.new
811 color.diff.commit
812 color.diff.whitespace
a159ca0c 813 color.pager
a159ca0c 814 color.status
78d4d6a2
SP
815 color.status.header
816 color.status.added
817 color.status.changed
818 color.status.untracked
819 diff.renameLimit
820 diff.renames
821 fetch.unpackLimit
822 format.headers
823 gitcvs.enabled
824 gitcvs.logfile
825 gc.reflogexpire
826 gc.reflogexpireunreachable
827 gc.rerereresolved
828 gc.rerereunresolved
5de40f59
SP
829 http.sslVerify
830 http.sslCert
831 http.sslKey
832 http.sslCAInfo
833 http.sslCAPath
834 http.maxRequests
78d4d6a2
SP
835 http.lowSpeedLimit
836 http.lowSpeedTime
5de40f59 837 http.noEPSV
78d4d6a2
SP
838 i18n.commitEncoding
839 i18n.logOutputEncoding
840 log.showroot
841 merge.summary
842 merge.verbosity
5de40f59 843 pack.window
78d4d6a2
SP
844 pull.octopus
845 pull.twohead
5de40f59 846 repack.useDeltaBaseOffset
78d4d6a2
SP
847 show.difftree
848 showbranch.default
849 tar.umask
850 transfer.unpackLimit
5de40f59
SP
851 receive.unpackLimit
852 receive.denyNonFastForwards
78d4d6a2
SP
853 user.name
854 user.email
855 user.signingkey
856 whatchanged.difftree
5de40f59 857 branch. remote.
78d4d6a2 858 "
5de40f59
SP
859}
860
88293c67
SP
861_git_remote ()
862{
863 local i c=1 command
864 while [ $c -lt $COMP_CWORD ]; do
865 i="${COMP_WORDS[c]}"
866 case "$i" in
867 add|show|prune) command="$i"; break ;;
868 esac
869 c=$((++c))
870 done
871
872 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
873 __gitcomp "add show prune"
874 return
875 fi
876
877 case "$command" in
878 show|prune)
879 __gitcomp "$(__git_remotes)"
880 ;;
881 *)
882 COMPREPLY=()
883 ;;
884 esac
885}
886
67e78c3b
SP
887_git_reset ()
888{
889 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
890 case "$cur" in
891 --*)
892 __gitcomp "--mixed --hard --soft"
893 return
894 ;;
895 esac
896 __gitcomp "$(__git_refs)"
67e78c3b
SP
897}
898
1fd6bec9
SP
899_git_shortlog ()
900{
901 local cur="${COMP_WORDS[COMP_CWORD]}"
902 case "$cur" in
903 --*)
904 __gitcomp "
905 --max-count= --max-age= --since= --after=
906 --min-age= --before= --until=
907 --no-merges
908 --author= --committer= --grep=
909 --all-match
910 --not --all
911 --numbered --summary
912 "
913 return
914 ;;
915 esac
916 __git_complete_revlist
917}
918
90131924
SP
919_git_show ()
920{
921 local cur="${COMP_WORDS[COMP_CWORD]}"
922 case "$cur" in
923 --pretty=*)
b3391775 924 __gitcomp "
90131924 925 oneline short medium full fuller email raw
b3391775 926 " "" "${cur##--pretty=}"
90131924
SP
927 return
928 ;;
929 --*)
b3391775 930 __gitcomp "--pretty="
90131924
SP
931 return
932 ;;
933 esac
934 __git_complete_file
935}
936
690d8824
JH
937_git ()
938{
873537fa
SP
939 local i c=1 command __git_dir
940
941 while [ $c -lt $COMP_CWORD ]; do
942 i="${COMP_WORDS[c]}"
943 case "$i" in
944 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
945 --bare) __git_dir="." ;;
946 --version|--help|-p|--paginate) ;;
947 *) command="$i"; break ;;
948 esac
949 c=$((++c))
950 done
951
952 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
72e5e989
SP
953 case "${COMP_WORDS[COMP_CWORD]}" in
954 --*=*) COMPREPLY=() ;;
955 --*) __gitcomp "--git-dir= --bare --version --exec-path" ;;
956 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
957 esac
958 return
873537fa 959 fi
367dce2a 960
873537fa
SP
961 local expansion=$(__git_aliased_command "$command")
962 [ "$expansion" ] && command="$expansion"
367dce2a 963
873537fa 964 case "$command" in
88329195 965 am) _git_am ;;
8435b548 966 add) _git_add ;;
88329195 967 apply) _git_apply ;;
b2e69f62 968 bisect) _git_bisect ;;
873537fa 969 branch) _git_branch ;;
873537fa 970 checkout) _git_checkout ;;
d8a9fea5 971 cherry) _git_cherry ;;
1273231e 972 cherry-pick) _git_cherry_pick ;;
4548e855 973 commit) _git_commit ;;
e0d10e1c 974 config) _git_config ;;
873537fa 975 diff) _git_diff ;;
873537fa 976 fetch) _git_fetch ;;
f53352fb 977 format-patch) _git_format_patch ;;
b26c8748 978 gc) _git_gc ;;
873537fa
SP
979 log) _git_log ;;
980 ls-remote) _git_ls_remote ;;
981 ls-tree) _git_ls_tree ;;
4ad91321 982 merge) _git_merge;;
873537fa 983 merge-base) _git_merge_base ;;
d33909bf 984 name-rev) _git_name_rev ;;
873537fa
SP
985 pull) _git_pull ;;
986 push) _git_push ;;
61d926a3 987 rebase) _git_rebase ;;
88293c67 988 remote) _git_remote ;;
873537fa 989 reset) _git_reset ;;
1fd6bec9 990 shortlog) _git_shortlog ;;
90131924 991 show) _git_show ;;
873537fa
SP
992 show-branch) _git_log ;;
993 whatchanged) _git_log ;;
994 *) COMPREPLY=() ;;
995 esac
690d8824
JH
996}
997
998_gitk ()
999{
1000 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
1001 case "$cur" in
1002 --*)
1003 __gitcomp "--not --all"
1004 return
1005 ;;
1006 esac
ec804891 1007 __git_complete_revlist
690d8824
JH
1008}
1009
1010complete -o default -o nospace -F _git git
b3391775
SP
1011complete -o default -o nospace -F _gitk gitk
1012complete -o default -o nospace -F _git_am git-am
1013complete -o default -o nospace -F _git_apply git-apply
b2e69f62 1014complete -o default -o nospace -F _git_bisect git-bisect
b3391775
SP
1015complete -o default -o nospace -F _git_branch git-branch
1016complete -o default -o nospace -F _git_checkout git-checkout
d8a9fea5 1017complete -o default -o nospace -F _git_cherry git-cherry
b3391775
SP
1018complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1019complete -o default -o nospace -F _git_commit git-commit
690d8824 1020complete -o default -o nospace -F _git_diff git-diff
690d8824 1021complete -o default -o nospace -F _git_fetch git-fetch
f53352fb 1022complete -o default -o nospace -F _git_format_patch git-format-patch
b26c8748 1023complete -o default -o nospace -F _git_gc git-gc
690d8824 1024complete -o default -o nospace -F _git_log git-log
b3391775 1025complete -o default -o nospace -F _git_ls_remote git-ls-remote
690d8824 1026complete -o default -o nospace -F _git_ls_tree git-ls-tree
b3391775
SP
1027complete -o default -o nospace -F _git_merge git-merge
1028complete -o default -o nospace -F _git_merge_base git-merge-base
1029complete -o default -o nospace -F _git_name_rev git-name-rev
690d8824
JH
1030complete -o default -o nospace -F _git_pull git-pull
1031complete -o default -o nospace -F _git_push git-push
b3391775
SP
1032complete -o default -o nospace -F _git_rebase git-rebase
1033complete -o default -o nospace -F _git_config git-config
88293c67 1034complete -o default -o nospace -F _git_remote git-remote
b3391775 1035complete -o default -o nospace -F _git_reset git-reset
1fd6bec9 1036complete -o default -o nospace -F _git_shortlog git-shortlog
90131924 1037complete -o default -o nospace -F _git_show git-show
144d33de 1038complete -o default -o nospace -F _git_log git-show-branch
690d8824
JH
1039complete -o default -o nospace -F _git_log git-whatchanged
1040
1041# The following are necessary only for Cygwin, and only are needed
1042# when the user has tab-completed the executable name and consequently
1043# included the '.exe' suffix.
1044#
76c3eb51 1045if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
b3391775
SP
1046complete -o default -o nospace -F _git_add git-add.exe
1047complete -o default -o nospace -F _git_apply git-apply.exe
144d33de 1048complete -o default -o nospace -F _git git.exe
b3391775 1049complete -o default -o nospace -F _git_branch git-branch.exe
d8a9fea5 1050complete -o default -o nospace -F _git_cherry git-cherry.exe
690d8824 1051complete -o default -o nospace -F _git_diff git-diff.exe
f53352fb 1052complete -o default -o nospace -F _git_format_patch git-format-patch.exe
690d8824
JH
1053complete -o default -o nospace -F _git_log git-log.exe
1054complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
b3391775
SP
1055complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1056complete -o default -o nospace -F _git_name_rev git-name-rev.exe
690d8824 1057complete -o default -o nospace -F _git_push git-push.exe
b3391775 1058complete -o default -o nospace -F _git_config git-config
1fd6bec9 1059complete -o default -o nospace -F _git_shortlog git-shortlog.exe
90131924 1060complete -o default -o nospace -F _git_show git-show.exe
144d33de 1061complete -o default -o nospace -F _git_log git-show-branch.exe
690d8824 1062complete -o default -o nospace -F _git_log git-whatchanged.exe
76c3eb51 1063fi