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