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