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