]> git.ipfire.org Git - thirdparty/git.git/blame - contrib/completion/git-completion.bash
bash: Classify more commends out of completion.
[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'
67 for c in $1; do
68 case "$c" in
69 --*=*) all="$all$c$s" ;;
70 *) all="$all$c $s" ;;
71 esac
72 done
73 IFS=$s
74 COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}"))
75 return
76}
77
5de40f59
SP
78__git_heads ()
79{
67ffa114 80 local cmd i is_hash=y dir="$(__gitdir "$1")"
5de40f59
SP
81 if [ -d "$dir" ]; then
82 for i in $(git --git-dir="$dir" \
83 for-each-ref --format='%(refname)' \
84 refs/heads ); do
85 echo "${i#refs/heads/}"
86 done
87 return
88 fi
67ffa114 89 for i in $(git-ls-remote "$1" 2>/dev/null); do
5de40f59
SP
90 case "$is_hash,$i" in
91 y,*) is_hash=n ;;
92 n,*^{}) is_hash=y ;;
93 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
94 n,*) is_hash=y; echo "$i" ;;
95 esac
96 done
97}
98
690d8824
JH
99__git_refs ()
100{
67ffa114 101 local cmd i is_hash=y dir="$(__gitdir "$1")"
873537fa 102 if [ -d "$dir" ]; then
35e65ecc
SP
103 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
104 for i in $(git --git-dir="$dir" \
105 for-each-ref --format='%(refname)' \
106 refs/tags refs/heads refs/remotes); do
107 case "$i" in
108 refs/tags/*) echo "${i#refs/tags/}" ;;
109 refs/heads/*) echo "${i#refs/heads/}" ;;
110 refs/remotes/*) echo "${i#refs/remotes/}" ;;
111 *) echo "$i" ;;
112 esac
113 done
114 return
690d8824 115 fi
35e65ecc 116 for i in $(git-ls-remote "$dir" 2>/dev/null); do
690d8824
JH
117 case "$is_hash,$i" in
118 y,*) is_hash=n ;;
119 n,*^{}) is_hash=y ;;
120 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
121 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
35e65ecc 122 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
123 n,*) is_hash=y; echo "$i" ;;
124 esac
125 done
126}
127
128__git_refs2 ()
129{
67ffa114
SP
130 local i
131 for i in $(__git_refs "$1"); do
132 echo "$i:$i"
690d8824
JH
133 done
134}
135
5de40f59
SP
136__git_refs_remotes ()
137{
138 local cmd i is_hash=y
139 for i in $(git-ls-remote "$1" 2>/dev/null); do
140 case "$is_hash,$i" in
141 n,refs/heads/*)
142 is_hash=y
143 echo "$i:refs/remotes/$1/${i#refs/heads/}"
144 ;;
145 y,*) is_hash=n ;;
146 n,*^{}) is_hash=y ;;
147 n,refs/tags/*) is_hash=y;;
148 n,*) is_hash=y; ;;
149 esac
150 done
151}
152
690d8824
JH
153__git_remotes ()
154{
873537fa 155 local i ngoff IFS=$'\n' d="$(__gitdir)"
56fc25f2 156 shopt -q nullglob || ngoff=1
690d8824 157 shopt -s nullglob
873537fa
SP
158 for i in "$d/remotes"/*; do
159 echo ${i#$d/remotes/}
690d8824 160 done
56fc25f2 161 [ "$ngoff" ] && shopt -u nullglob
e0d10e1c 162 for i in $(git --git-dir="$d" config --list); do
56fc25f2
SP
163 case "$i" in
164 remote.*.url=*)
165 i="${i#remote.}"
166 echo "${i/.url=*/}"
167 ;;
168 esac
169 done
690d8824
JH
170}
171
4ad91321
SP
172__git_merge_strategies ()
173{
b51ec6bd
SP
174 if [ -n "$__git_merge_strategylist" ]; then
175 echo "$__git_merge_strategylist"
176 return
177 fi
4ad91321
SP
178 sed -n "/^all_strategies='/{
179 s/^all_strategies='//
180 s/'//
181 p
182 q
183 }" "$(git --exec-path)/git-merge"
184}
b51ec6bd
SP
185__git_merge_strategylist=
186__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
4ad91321 187
690d8824
JH
188__git_complete_file ()
189{
a79c6551 190 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
690d8824
JH
191 case "$cur" in
192 ?*:*)
a79c6551
SP
193 ref="${cur%%:*}"
194 cur="${cur#*:}"
690d8824
JH
195 case "$cur" in
196 ?*/*)
a79c6551
SP
197 pfx="${cur%/*}"
198 cur="${cur##*/}"
690d8824
JH
199 ls="$ref:$pfx"
200 pfx="$pfx/"
201 ;;
202 *)
203 ls="$ref"
204 ;;
205 esac
206 COMPREPLY=($(compgen -P "$pfx" \
873537fa 207 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
690d8824
JH
208 | sed '/^100... blob /s,^.* ,,
209 /^040000 tree /{
210 s,^.* ,,
211 s,$,/,
212 }
213 s/^.* //')" \
214 -- "$cur"))
215 ;;
216 *)
873537fa 217 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
218 ;;
219 esac
220}
221
f53352fb
SP
222__git_complete_revlist ()
223{
224 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
225 case "$cur" in
226 *...*)
227 pfx="${cur%...*}..."
228 cur="${cur#*...}"
229 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
230 ;;
231 *..*)
232 pfx="${cur%..*}.."
233 cur="${cur#*..}"
234 COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
235 ;;
236 *)
237 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
238 ;;
239 esac
240}
241
f2bb9f88
SP
242__git_commands ()
243{
b51ec6bd
SP
244 if [ -n "$__git_commandlist" ]; then
245 echo "$__git_commandlist"
246 return
247 fi
f2bb9f88
SP
248 local i IFS=" "$'\n'
249 for i in $(git help -a|egrep '^ ')
250 do
251 case $i in
8435b548 252 add--interactive) : plumbing;;
a925c6f1
SP
253 applymbox) : ask gittus;;
254 applypatch) : ask gittus;;
255 archimport) : import;;
2e3a430a 256 cat-file) : plumbing;;
f2bb9f88
SP
257 check-ref-format) : plumbing;;
258 commit-tree) : plumbing;;
259 convert-objects) : plumbing;;
a925c6f1
SP
260 cvsexportcommit) : export;;
261 cvsimport) : import;;
f2bb9f88
SP
262 cvsserver) : daemon;;
263 daemon) : daemon;;
a925c6f1 264 fsck-objects) : plumbing;;
f2bb9f88 265 fetch-pack) : plumbing;;
a925c6f1 266 fmt-merge-msg) : plumbing;;
f2bb9f88
SP
267 hash-object) : plumbing;;
268 http-*) : transport;;
269 index-pack) : plumbing;;
a925c6f1 270 init-db) : deprecated;;
f2bb9f88
SP
271 local-fetch) : plumbing;;
272 mailinfo) : plumbing;;
273 mailsplit) : plumbing;;
274 merge-*) : plumbing;;
275 mktree) : plumbing;;
276 mktag) : plumbing;;
277 pack-objects) : plumbing;;
278 pack-redundant) : plumbing;;
279 pack-refs) : plumbing;;
280 parse-remote) : plumbing;;
281 patch-id) : plumbing;;
282 peek-remote) : plumbing;;
a925c6f1
SP
283 prune) : plumbing;;
284 prune-packed) : plumbing;;
285 quiltimport) : import;;
f2bb9f88
SP
286 read-tree) : plumbing;;
287 receive-pack) : plumbing;;
2e3a430a 288 reflog) : plumbing;;
a925c6f1 289 repo-config) : plumbing;;
f2bb9f88
SP
290 rerere) : plumbing;;
291 rev-list) : plumbing;;
292 rev-parse) : plumbing;;
293 runstatus) : plumbing;;
294 sh-setup) : internal;;
295 shell) : daemon;;
296 send-pack) : plumbing;;
297 show-index) : plumbing;;
298 ssh-*) : transport;;
299 stripspace) : plumbing;;
a925c6f1
SP
300 svn) : import export;;
301 svnimport) : import;;
f2bb9f88 302 symbolic-ref) : plumbing;;
a925c6f1 303 tar-tree) : deprecated;;
f2bb9f88
SP
304 unpack-file) : plumbing;;
305 unpack-objects) : plumbing;;
a925c6f1 306 update-index) : plumbing;;
f2bb9f88
SP
307 update-ref) : plumbing;;
308 update-server-info) : daemon;;
309 upload-archive) : plumbing;;
310 upload-pack) : plumbing;;
311 write-tree) : plumbing;;
a925c6f1 312 verify-tag) : plumbing;;
f2bb9f88
SP
313 *) echo $i;;
314 esac
315 done
316}
b51ec6bd
SP
317__git_commandlist=
318__git_commandlist="$(__git_commands 2>/dev/null)"
f2bb9f88 319
367dce2a
DS
320__git_aliases ()
321{
56fc25f2 322 local i IFS=$'\n'
e0d10e1c 323 for i in $(git --git-dir="$(__gitdir)" config --list); do
56fc25f2
SP
324 case "$i" in
325 alias.*)
326 i="${i#alias.}"
327 echo "${i/=*/}"
328 ;;
329 esac
330 done
367dce2a
DS
331}
332
333__git_aliased_command ()
334{
873537fa 335 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 336 config --get "alias.$1")
367dce2a
DS
337 for word in $cmdline; do
338 if [ "${word##-*}" ]; then
339 echo $word
340 return
341 fi
342 done
343}
344
88329195
SP
345__git_whitespacelist="nowarn warn error error-all strip"
346
347_git_am ()
348{
349 local cur="${COMP_WORDS[COMP_CWORD]}"
350 if [ -d .dotest ]; then
351 COMPREPLY=($(compgen -W "
352 --skip --resolved
353 " -- "$cur"))
354 return
355 fi
356 case "$cur" in
357 --whitespace=*)
358 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
359 -- "${cur##--whitespace=}"))
360 return
361 ;;
362 --*)
363 COMPREPLY=($(compgen -W "
364 --signoff --utf8 --binary --3way --interactive
365 --whitespace=
366 " -- "$cur"))
367 return
368 esac
369 COMPREPLY=()
370}
371
372_git_apply ()
373{
374 local cur="${COMP_WORDS[COMP_CWORD]}"
375 case "$cur" in
376 --whitespace=*)
377 COMPREPLY=($(compgen -W "$__git_whitespacelist" \
378 -- "${cur##--whitespace=}"))
379 return
380 ;;
381 --*)
382 COMPREPLY=($(compgen -W "
383 --stat --numstat --summary --check --index
384 --cached --index-info --reverse --reject --unidiff-zero
385 --apply --no-add --exclude=
386 --whitespace= --inaccurate-eof --verbose
387 " -- "$cur"))
388 return
389 esac
390 COMPREPLY=()
391}
392
8435b548
SP
393_git_add ()
394{
395 local cur="${COMP_WORDS[COMP_CWORD]}"
396 case "$cur" in
397 --*)
398 COMPREPLY=($(compgen -W "
399 --interactive
400 " -- "$cur"))
401 return
402 esac
403 COMPREPLY=()
404}
405
690d8824
JH
406_git_branch ()
407{
408 local cur="${COMP_WORDS[COMP_CWORD]}"
9f4cc6f7 409 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
410}
411
690d8824
JH
412_git_checkout ()
413{
414 local cur="${COMP_WORDS[COMP_CWORD]}"
9f4cc6f7 415 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
416}
417
1273231e
SP
418_git_cherry_pick ()
419{
420 local cur="${COMP_WORDS[COMP_CWORD]}"
421 case "$cur" in
422 --*)
423 COMPREPLY=($(compgen -W "
424 --edit --no-commit
425 " -- "$cur"))
426 ;;
427 *)
428 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
429 ;;
430 esac
431}
432
4548e855
SP
433_git_commit ()
434{
435 local cur="${COMP_WORDS[COMP_CWORD]}"
436 case "$cur" in
437 --*)
438 COMPREPLY=($(compgen -W "
439 --all --author= --signoff --verify --no-verify
440 --edit --amend --include --only
441 " -- "$cur"))
442 return
443 esac
444 COMPREPLY=()
445}
446
690d8824
JH
447_git_diff ()
448{
449 __git_complete_file
450}
451
452_git_diff_tree ()
453{
454 local cur="${COMP_WORDS[COMP_CWORD]}"
9f4cc6f7 455 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
456}
457
458_git_fetch ()
459{
460 local cur="${COMP_WORDS[COMP_CWORD]}"
461
462 case "${COMP_WORDS[0]},$COMP_CWORD" in
463 git-fetch*,1)
464 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
465 ;;
466 git,2)
467 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
468 ;;
469 *)
470 case "$cur" in
471 *:*)
a79c6551 472 cur="${cur#*:}"
873537fa 473 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
474 ;;
475 *)
476 local remote
477 case "${COMP_WORDS[0]}" in
478 git-fetch) remote="${COMP_WORDS[1]}" ;;
479 git) remote="${COMP_WORDS[2]}" ;;
480 esac
481 COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur"))
482 ;;
483 esac
484 ;;
485 esac
486}
487
f53352fb
SP
488_git_format_patch ()
489{
490 local cur="${COMP_WORDS[COMP_CWORD]}"
491 case "$cur" in
492 --*)
493 COMPREPLY=($(compgen -W "
494 --stdout --attach --thread
495 --output-directory
496 --numbered --start-number
497 --keep-subject
498 --signoff
499 --in-reply-to=
500 --full-index --binary
501 " -- "$cur"))
502 return
503 ;;
504 esac
505 __git_complete_revlist
506}
507
690d8824
JH
508_git_ls_remote ()
509{
510 local cur="${COMP_WORDS[COMP_CWORD]}"
511 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
512}
513
514_git_ls_tree ()
515{
516 __git_complete_file
517}
518
519_git_log ()
520{
6e31b866
SP
521 local cur="${COMP_WORDS[COMP_CWORD]}"
522 case "$cur" in
523 --pretty=*)
524 COMPREPLY=($(compgen -W "
525 oneline short medium full fuller email raw
526 " -- "${cur##--pretty=}"))
527 return
528 ;;
529 --*)
530 COMPREPLY=($(compgen -W "
531 --max-count= --max-age= --since= --after=
532 --min-age= --before= --until=
533 --root --not --topo-order --date-order
534 --no-merges
535 --abbrev-commit --abbrev=
536 --relative-date
537 --author= --committer= --grep=
538 --all-match
539 --pretty= --name-status --name-only
540 " -- "$cur"))
541 return
542 ;;
543 esac
f53352fb 544 __git_complete_revlist
690d8824
JH
545}
546
4ad91321
SP
547_git_merge ()
548{
549 local cur="${COMP_WORDS[COMP_CWORD]}"
ce1e39d2
SP
550 case "${COMP_WORDS[COMP_CWORD-1]}" in
551 -s|--strategy)
552 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
553 return
554 esac
4ad91321 555 case "$cur" in
ce1e39d2
SP
556 --strategy=*)
557 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
558 -- "${cur##--strategy=}"))
559 return
560 ;;
4ad91321
SP
561 --*)
562 COMPREPLY=($(compgen -W "
61d926a3 563 --no-commit --no-summary --squash --strategy
4ad91321
SP
564 " -- "$cur"))
565 return
566 esac
61d926a3 567 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
4ad91321
SP
568}
569
690d8824
JH
570_git_merge_base ()
571{
572 local cur="${COMP_WORDS[COMP_CWORD]}"
873537fa 573 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
690d8824
JH
574}
575
d33909bf
SP
576_git_name_rev ()
577{
578 local cur="${COMP_WORDS[COMP_CWORD]}"
579 COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
580}
581
690d8824
JH
582_git_pull ()
583{
584 local cur="${COMP_WORDS[COMP_CWORD]}"
585
586 case "${COMP_WORDS[0]},$COMP_CWORD" in
587 git-pull*,1)
588 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
589 ;;
590 git,2)
591 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
592 ;;
593 *)
594 local remote
595 case "${COMP_WORDS[0]}" in
596 git-pull) remote="${COMP_WORDS[1]}" ;;
597 git) remote="${COMP_WORDS[2]}" ;;
598 esac
599 COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
600 ;;
601 esac
602}
603
604_git_push ()
605{
606 local cur="${COMP_WORDS[COMP_CWORD]}"
607
608 case "${COMP_WORDS[0]},$COMP_CWORD" in
609 git-push*,1)
610 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
611 ;;
612 git,2)
613 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
614 ;;
615 *)
616 case "$cur" in
617 *:*)
618 local remote
619 case "${COMP_WORDS[0]}" in
620 git-push) remote="${COMP_WORDS[1]}" ;;
621 git) remote="${COMP_WORDS[2]}" ;;
622 esac
a79c6551 623 cur="${cur#*:}"
690d8824
JH
624 COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
625 ;;
626 *)
873537fa 627 COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur"))
690d8824
JH
628 ;;
629 esac
630 ;;
631 esac
632}
633
61d926a3
SP
634_git_rebase ()
635{
636 local cur="${COMP_WORDS[COMP_CWORD]}"
637 if [ -d .dotest ]; then
638 COMPREPLY=($(compgen -W "
639 --continue --skip --abort
640 " -- "$cur"))
641 return
642 fi
ce1e39d2
SP
643 case "${COMP_WORDS[COMP_CWORD-1]}" in
644 -s|--strategy)
645 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
646 return
647 esac
61d926a3 648 case "$cur" in
ce1e39d2
SP
649 --strategy=*)
650 COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
651 -- "${cur##--strategy=}"))
652 return
653 ;;
61d926a3
SP
654 --*)
655 COMPREPLY=($(compgen -W "
656 --onto --merge --strategy
657 " -- "$cur"))
658 return
659 esac
61d926a3
SP
660 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
661}
662
e0d10e1c 663_git_config ()
5de40f59
SP
664{
665 local cur="${COMP_WORDS[COMP_CWORD]}"
666 local prv="${COMP_WORDS[COMP_CWORD-1]}"
667 case "$prv" in
668 branch.*.remote)
669 COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
670 return
671 ;;
672 branch.*.merge)
673 COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
674 return
675 ;;
676 remote.*.fetch)
677 local remote="${prv#remote.}"
678 remote="${remote%.fetch}"
679 COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \
680 -- "$cur"))
681 return
682 ;;
683 remote.*.push)
684 local remote="${prv#remote.}"
685 remote="${remote%.push}"
686 COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \
687 for-each-ref --format='%(refname):%(refname)' \
688 refs/heads)" -- "$cur"))
689 return
690 ;;
691 *.*)
692 COMPREPLY=()
693 return
694 ;;
695 esac
696 case "$cur" in
697 --*)
698 COMPREPLY=($(compgen -W "
699 --global --list --replace-all
700 --get --get-all --get-regexp
701 --unset --unset-all
702 " -- "$cur"))
703 return
704 ;;
705 branch.*.*)
706 local pfx="${cur%.*}."
707 cur="${cur##*.}"
708 COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur"))
709 return
710 ;;
711 branch.*)
712 local pfx="${cur%.*}."
713 cur="${cur#*.}"
714 COMPREPLY=($(compgen -P "$pfx" -S . \
715 -W "$(__git_heads)" -- "$cur"))
716 return
717 ;;
718 remote.*.*)
719 local pfx="${cur%.*}."
720 cur="${cur##*.}"
721 COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur"))
722 return
723 ;;
724 remote.*)
725 local pfx="${cur%.*}."
726 cur="${cur#*.}"
727 COMPREPLY=($(compgen -P "$pfx" -S . \
728 -W "$(__git_remotes)" -- "$cur"))
729 return
730 ;;
731 esac
732 COMPREPLY=($(compgen -W "
733 apply.whitespace
734 core.fileMode
735 core.gitProxy
736 core.ignoreStat
737 core.preferSymlinkRefs
738 core.logAllRefUpdates
739 core.repositoryFormatVersion
740 core.sharedRepository
741 core.warnAmbiguousRefs
742 core.compression
743 core.legacyHeaders
744 i18n.commitEncoding
d2c11a38 745 i18n.logOutputEncoding
5de40f59 746 diff.color
a159ca0c 747 color.diff
5de40f59
SP
748 diff.renameLimit
749 diff.renames
750 pager.color
a159ca0c 751 color.pager
5de40f59 752 status.color
a159ca0c 753 color.status
5de40f59
SP
754 log.showroot
755 show.difftree
756 showbranch.default
757 whatchanged.difftree
758 http.sslVerify
759 http.sslCert
760 http.sslKey
761 http.sslCAInfo
762 http.sslCAPath
763 http.maxRequests
764 http.lowSpeedLimit http.lowSpeedTime
765 http.noEPSV
766 pack.window
767 repack.useDeltaBaseOffset
768 pull.octopus pull.twohead
769 merge.summary
770 receive.unpackLimit
771 receive.denyNonFastForwards
772 user.name user.email
773 tar.umask
774 gitcvs.enabled
775 gitcvs.logfile
776 branch. remote.
777 " -- "$cur"))
778}
779
67e78c3b
SP
780_git_reset ()
781{
782 local cur="${COMP_WORDS[COMP_CWORD]}"
783 local opt="--mixed --hard --soft"
873537fa 784 COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
67e78c3b
SP
785}
786
90131924
SP
787_git_show ()
788{
789 local cur="${COMP_WORDS[COMP_CWORD]}"
790 case "$cur" in
791 --pretty=*)
792 COMPREPLY=($(compgen -W "
793 oneline short medium full fuller email raw
794 " -- "${cur##--pretty=}"))
795 return
796 ;;
797 --*)
798 COMPREPLY=($(compgen -W "--pretty=" -- "$cur"))
799 return
800 ;;
801 esac
802 __git_complete_file
803}
804
690d8824
JH
805_git ()
806{
873537fa
SP
807 local i c=1 command __git_dir
808
809 while [ $c -lt $COMP_CWORD ]; do
810 i="${COMP_WORDS[c]}"
811 case "$i" in
812 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
813 --bare) __git_dir="." ;;
814 --version|--help|-p|--paginate) ;;
815 *) command="$i"; break ;;
816 esac
817 c=$((++c))
818 done
819
820 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
72e5e989
SP
821 case "${COMP_WORDS[COMP_CWORD]}" in
822 --*=*) COMPREPLY=() ;;
823 --*) __gitcomp "--git-dir= --bare --version --exec-path" ;;
824 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
825 esac
826 return
873537fa 827 fi
367dce2a 828
873537fa
SP
829 local expansion=$(__git_aliased_command "$command")
830 [ "$expansion" ] && command="$expansion"
367dce2a 831
873537fa 832 case "$command" in
88329195 833 am) _git_am ;;
8435b548 834 add) _git_add ;;
88329195 835 apply) _git_apply ;;
873537fa 836 branch) _git_branch ;;
873537fa 837 checkout) _git_checkout ;;
1273231e 838 cherry-pick) _git_cherry_pick ;;
4548e855 839 commit) _git_commit ;;
e0d10e1c 840 config) _git_config ;;
873537fa
SP
841 diff) _git_diff ;;
842 diff-tree) _git_diff_tree ;;
843 fetch) _git_fetch ;;
f53352fb 844 format-patch) _git_format_patch ;;
873537fa
SP
845 log) _git_log ;;
846 ls-remote) _git_ls_remote ;;
847 ls-tree) _git_ls_tree ;;
4ad91321 848 merge) _git_merge;;
873537fa 849 merge-base) _git_merge_base ;;
d33909bf 850 name-rev) _git_name_rev ;;
873537fa
SP
851 pull) _git_pull ;;
852 push) _git_push ;;
61d926a3 853 rebase) _git_rebase ;;
873537fa 854 reset) _git_reset ;;
90131924 855 show) _git_show ;;
873537fa
SP
856 show-branch) _git_log ;;
857 whatchanged) _git_log ;;
858 *) COMPREPLY=() ;;
859 esac
690d8824
JH
860}
861
862_gitk ()
863{
864 local cur="${COMP_WORDS[COMP_CWORD]}"
873537fa 865 COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur"))
690d8824
JH
866}
867
868complete -o default -o nospace -F _git git
869complete -o default -F _gitk gitk
88329195
SP
870complete -o default -F _git_am git-am
871complete -o default -F _git_apply git-apply
690d8824 872complete -o default -F _git_branch git-branch
690d8824 873complete -o default -F _git_checkout git-checkout
1273231e 874complete -o default -F _git_cherry_pick git-cherry-pick
4548e855 875complete -o default -F _git_commit git-commit
690d8824
JH
876complete -o default -o nospace -F _git_diff git-diff
877complete -o default -F _git_diff_tree git-diff-tree
878complete -o default -o nospace -F _git_fetch git-fetch
f53352fb 879complete -o default -o nospace -F _git_format_patch git-format-patch
690d8824
JH
880complete -o default -o nospace -F _git_log git-log
881complete -o default -F _git_ls_remote git-ls-remote
882complete -o default -o nospace -F _git_ls_tree git-ls-tree
4ad91321 883complete -o default -F _git_merge git-merge
690d8824 884complete -o default -F _git_merge_base git-merge-base
d33909bf 885complete -o default -F _git_name_rev git-name-rev
690d8824
JH
886complete -o default -o nospace -F _git_pull git-pull
887complete -o default -o nospace -F _git_push git-push
61d926a3 888complete -o default -F _git_rebase git-rebase
e0d10e1c 889complete -o default -F _git_config git-config
67e78c3b 890complete -o default -F _git_reset git-reset
90131924 891complete -o default -o nospace -F _git_show git-show
144d33de 892complete -o default -o nospace -F _git_log git-show-branch
690d8824
JH
893complete -o default -o nospace -F _git_log git-whatchanged
894
895# The following are necessary only for Cygwin, and only are needed
896# when the user has tab-completed the executable name and consequently
897# included the '.exe' suffix.
898#
76c3eb51 899if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
8435b548 900complete -o default -F _git_add git-add.exe
88329195 901complete -o default -F _git_apply git-apply.exe
144d33de 902complete -o default -o nospace -F _git git.exe
dfb96092 903complete -o default -F _git_branch git-branch.exe
690d8824
JH
904complete -o default -o nospace -F _git_diff git-diff.exe
905complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
f53352fb 906complete -o default -o nospace -F _git_format_patch git-format-patch.exe
690d8824
JH
907complete -o default -o nospace -F _git_log git-log.exe
908complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
909complete -o default -F _git_merge_base git-merge-base.exe
d33909bf 910complete -o default -F _git_name_rev git-name-rev.exe
690d8824 911complete -o default -o nospace -F _git_push git-push.exe
e0d10e1c 912complete -o default -F _git_config git-config
90131924 913complete -o default -o nospace -F _git_show git-show.exe
144d33de 914complete -o default -o nospace -F _git_log git-show-branch.exe
690d8824 915complete -o default -o nospace -F _git_log git-whatchanged.exe
76c3eb51 916fi