1#!bash
2#
3# bash completion support for core Git.
4#
5# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7# Distributed under the GNU General Public License, version 2.0.
8#
9# The contained completion routines provide support for completing:
10#
11# *) local and remote branch names
12# *) local and remote tag names
13# *) .git/remotes file names
14# *) git 'subcommands'
15# *) tree paths within 'ref:path/to/file' expressions
16# *) common --long-options
17#
18# To use these routines:
19#
20# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21# 2) Added the following line to your .bashrc:
22# source ~/.git-completion.sh
23#
24# 3) You may want to make sure the git executable is available
25# in your PATH before this script is sourced, as some caching
26# is performed while the script loads. If git isn't found
27# at source time then all lookups will be done on demand,
28# which may be slightly slower.
29#
30# 4) Consider changing your PS1 to also show the current branch:
31# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
32#
33# The argument to __git_ps1 will be displayed only if you
34# are currently in a git repository. The %s token will be
35# the name of the current branch.
36#
37# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
38# value, unstaged (*) and staged (+) changes will be shown next
39# to the branch name. You can configure this per-repository
40# with the bash.showDirtyState variable, which defaults to true
41# once GIT_PS1_SHOWDIRTYSTATE is enabled.
42#
43# To submit patches:
44#
45# *) Read Documentation/SubmittingPatches
46# *) Send all patches to the current maintainer:
47#
48# "Shawn O. Pearce" <spearce@spearce.org>
49#
50# *) Always CC the Git mailing list:
51#
52# git@vger.kernel.org
53#
54
55case "$COMP_WORDBREAKS" in
56*:*) : great ;;
57*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
58esac
59
60# __gitdir accepts 0 or 1 arguments (i.e., location)
61# returns location of .git repo
62__gitdir ()
63{
64 if [ -z "${1-}" ]; then
65 if [ -n "${__git_dir-}" ]; then
66 echo "$__git_dir"
67 elif [ -d .git ]; then
68 echo .git
69 else
70 git rev-parse --git-dir 2>/dev/null
71 fi
72 elif [ -d "$1/.git" ]; then
73 echo "$1/.git"
74 else
75 echo "$1"
76 fi
77}
78
79# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
80# returns text to add to bash PS1 prompt (includes branch name)
81__git_ps1 ()
82{
83 local g="$(__gitdir)"
84 if [ -n "$g" ]; then
85 local r
86 local b
87 if [ -d "$g/rebase-apply" ]; then
88 if [ -f "$g/rebase-apply/rebasing" ]; then
89 r="|REBASE"
90 elif [ -f "$g/rebase-apply/applying" ]; then
91 r="|AM"
92 else
93 r="|AM/REBASE"
94 fi
95 b="$(git symbolic-ref HEAD 2>/dev/null)"
96 elif [ -f "$g/rebase-merge/interactive" ]; then
97 r="|REBASE-i"
98 b="$(cat "$g/rebase-merge/head-name")"
99 elif [ -d "$g/rebase-merge" ]; then
100 r="|REBASE-m"
101 b="$(cat "$g/rebase-merge/head-name")"
102 elif [ -f "$g/MERGE_HEAD" ]; then
103 r="|MERGING"
104 b="$(git symbolic-ref HEAD 2>/dev/null)"
105 else
106 if [ -f "$g/BISECT_LOG" ]; then
107 r="|BISECTING"
108 fi
109 if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
110 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
111 if [ -r "$g/HEAD" ]; then
112 b="$(cut -c1-7 "$g/HEAD")..."
113 fi
114 fi
115 fi
116 fi
117
118 local w
119 local i
120 local c
121
122 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
123 if [ "true" = "$(git config --bool core.bare 2>/dev/null)" ]; then
124 c="BARE:"
125 else
126 b="GIT_DIR!"
127 fi
128 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
129 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
130 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
131 git diff --no-ext-diff --ignore-submodules \
132 --quiet --exit-code || w="*"
133 if git rev-parse --quiet --verify HEAD >/dev/null; then
134 git diff-index --cached --quiet \
135 --ignore-submodules HEAD -- || i="+"
136 else
137 i="#"
138 fi
139 fi
140 fi
141 fi
142
143 if [ -n "$b" ]; then
144 if [ -n "${1-}" ]; then
145 printf "$1" "$c${b##refs/heads/}$w$i$r"
146 else
147 printf " (%s)" "$c${b##refs/heads/}$w$i$r"
148 fi
149 fi
150 fi
151}
152
153# __gitcomp_1 requires 2 arguments
154__gitcomp_1 ()
155{
156 local c IFS=' '$'\t'$'\n'
157 for c in $1; do
158 case "$c$2" in
159 --*=*) printf %s$'\n' "$c$2" ;;
160 *.) printf %s$'\n' "$c$2" ;;
161 *) printf %s$'\n' "$c$2 " ;;
162 esac
163 done
164}
165
166# __gitcomp accepts 1, 2, 3, or 4 arguments
167# generates completion reply with compgen
168__gitcomp ()
169{
170 local cur="${COMP_WORDS[COMP_CWORD]}"
171 if [ $# -gt 2 ]; then
172 cur="$3"
173 fi
174 case "$cur" in
175 --*=)
176 COMPREPLY=()
177 ;;
178 *)
179 local IFS=$'\n'
180 COMPREPLY=($(compgen -P "${2-}" \
181 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
182 -- "$cur"))
183 ;;
184 esac
185}
186
187# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
188__git_heads ()
189{
190 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
191 if [ -d "$dir" ]; then
192 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
193 refs/heads
194 return
195 fi
196 for i in $(git ls-remote "${1-}" 2>/dev/null); do
197 case "$is_hash,$i" in
198 y,*) is_hash=n ;;
199 n,*^{}) is_hash=y ;;
200 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
201 n,*) is_hash=y; echo "$i" ;;
202 esac
203 done
204}
205
206# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
207__git_tags ()
208{
209 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
210 if [ -d "$dir" ]; then
211 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
212 refs/tags
213 return
214 fi
215 for i in $(git ls-remote "${1-}" 2>/dev/null); do
216 case "$is_hash,$i" in
217 y,*) is_hash=n ;;
218 n,*^{}) is_hash=y ;;
219 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
220 n,*) is_hash=y; echo "$i" ;;
221 esac
222 done
223}
224
225# __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
226__git_refs ()
227{
228 local i is_hash=y dir="$(__gitdir "${1-}")"
229 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
230 if [ -d "$dir" ]; then
231 case "$cur" in
232 refs|refs/*)
233 format="refname"
234 refs="${cur%/*}"
235 ;;
236 *)
237 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
238 format="refname:short"
239 refs="refs/tags refs/heads refs/remotes"
240 ;;
241 esac
242 git --git-dir="$dir" for-each-ref --format="%($format)" \
243 $refs
244 return
245 fi
246 for i in $(git ls-remote "$dir" 2>/dev/null); do
247 case "$is_hash,$i" in
248 y,*) is_hash=n ;;
249 n,*^{}) is_hash=y ;;
250 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
251 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
252 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
253 n,*) is_hash=y; echo "$i" ;;
254 esac
255 done
256}
257
258# __git_refs2 requires 1 argument (to pass to __git_refs)
259__git_refs2 ()
260{
261 local i
262 for i in $(__git_refs "$1"); do
263 echo "$i:$i"
264 done
265}
266
267# __git_refs_remotes requires 1 argument (to pass to ls-remote)
268__git_refs_remotes ()
269{
270 local cmd i is_hash=y
271 for i in $(git ls-remote "$1" 2>/dev/null); do
272 case "$is_hash,$i" in
273 n,refs/heads/*)
274 is_hash=y
275 echo "$i:refs/remotes/$1/${i#refs/heads/}"
276 ;;
277 y,*) is_hash=n ;;
278 n,*^{}) is_hash=y ;;
279 n,refs/tags/*) is_hash=y;;
280 n,*) is_hash=y; ;;
281 esac
282 done
283}
284
285__git_remotes ()
286{
287 local i ngoff IFS=$'\n' d="$(__gitdir)"
288 shopt -q nullglob || ngoff=1
289 shopt -s nullglob
290 for i in "$d/remotes"/*; do
291 echo ${i#$d/remotes/}
292 done
293 [ "$ngoff" ] && shopt -u nullglob
294 for i in $(git --git-dir="$d" config --list); do
295 case "$i" in
296 remote.*.url=*)
297 i="${i#remote.}"
298 echo "${i/.url=*/}"
299 ;;
300 esac
301 done
302}
303
304__git_merge_strategies ()
305{
306 if [ -n "${__git_merge_strategylist-}" ]; then
307 echo "$__git_merge_strategylist"
308 return
309 fi
310 git merge -s help 2>&1 |
311 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
312 s/\.$//
313 s/.*://
314 s/^[ ]*//
315 s/[ ]*$//
316 p
317 }'
318}
319__git_merge_strategylist=
320__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
321
322__git_complete_file ()
323{
324 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
325 case "$cur" in
326 ?*:*)
327 ref="${cur%%:*}"
328 cur="${cur#*:}"
329 case "$cur" in
330 ?*/*)
331 pfx="${cur%/*}"
332 cur="${cur##*/}"
333 ls="$ref:$pfx"
334 pfx="$pfx/"
335 ;;
336 *)
337 ls="$ref"
338 ;;
339 esac
340
341 case "$COMP_WORDBREAKS" in
342 *:*) : great ;;
343 *) pfx="$ref:$pfx" ;;
344 esac
345
346 local IFS=$'\n'
347 COMPREPLY=($(compgen -P "$pfx" \
348 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
349 | sed '/^100... blob /{
350 s,^.* ,,
351 s,$, ,
352 }
353 /^120000 blob /{
354 s,^.* ,,
355 s,$, ,
356 }
357 /^040000 tree /{
358 s,^.* ,,
359 s,$,/,
360 }
361 s/^.* //')" \
362 -- "$cur"))
363 ;;
364 *)
365 __gitcomp "$(__git_refs)"
366 ;;
367 esac
368}
369
370__git_complete_revlist ()
371{
372 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
373 case "$cur" in
374 *...*)
375 pfx="${cur%...*}..."
376 cur="${cur#*...}"
377 __gitcomp "$(__git_refs)" "$pfx" "$cur"
378 ;;
379 *..*)
380 pfx="${cur%..*}.."
381 cur="${cur#*..}"
382 __gitcomp "$(__git_refs)" "$pfx" "$cur"
383 ;;
384 *)
385 __gitcomp "$(__git_refs)"
386 ;;
387 esac
388}
389
390__git_all_commands ()
391{
392 if [ -n "${__git_all_commandlist-}" ]; then
393 echo "$__git_all_commandlist"
394 return
395 fi
396 local i IFS=" "$'\n'
397 for i in $(git help -a|egrep '^ ')
398 do
399 case $i in
400 *--*) : helper pattern;;
401 *) echo $i;;
402 esac
403 done
404}
405__git_all_commandlist=
406__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
407
408__git_porcelain_commands ()
409{
410 if [ -n "${__git_porcelain_commandlist-}" ]; then
411 echo "$__git_porcelain_commandlist"
412 return
413 fi
414 local i IFS=" "$'\n'
415 for i in "help" $(__git_all_commands)
416 do
417 case $i in
418 *--*) : helper pattern;;
419 applymbox) : ask gittus;;
420 applypatch) : ask gittus;;
421 archimport) : import;;
422 cat-file) : plumbing;;
423 check-attr) : plumbing;;
424 check-ref-format) : plumbing;;
425 checkout-index) : plumbing;;
426 commit-tree) : plumbing;;
427 count-objects) : infrequent;;
428 cvsexportcommit) : export;;
429 cvsimport) : import;;
430 cvsserver) : daemon;;
431 daemon) : daemon;;
432 diff-files) : plumbing;;
433 diff-index) : plumbing;;
434 diff-tree) : plumbing;;
435 fast-import) : import;;
436 fast-export) : export;;
437 fsck-objects) : plumbing;;
438 fetch-pack) : plumbing;;
439 fmt-merge-msg) : plumbing;;
440 for-each-ref) : plumbing;;
441 hash-object) : plumbing;;
442 http-*) : transport;;
443 index-pack) : plumbing;;
444 init-db) : deprecated;;
445 local-fetch) : plumbing;;
446 lost-found) : infrequent;;
447 ls-files) : plumbing;;
448 ls-remote) : plumbing;;
449 ls-tree) : plumbing;;
450 mailinfo) : plumbing;;
451 mailsplit) : plumbing;;
452 merge-*) : plumbing;;
453 mktree) : plumbing;;
454 mktag) : plumbing;;
455 pack-objects) : plumbing;;
456 pack-redundant) : plumbing;;
457 pack-refs) : plumbing;;
458 parse-remote) : plumbing;;
459 patch-id) : plumbing;;
460 peek-remote) : plumbing;;
461 prune) : plumbing;;
462 prune-packed) : plumbing;;
463 quiltimport) : import;;
464 read-tree) : plumbing;;
465 receive-pack) : plumbing;;
466 reflog) : plumbing;;
467 repo-config) : deprecated;;
468 rerere) : plumbing;;
469 rev-list) : plumbing;;
470 rev-parse) : plumbing;;
471 runstatus) : plumbing;;
472 sh-setup) : internal;;
473 shell) : daemon;;
474 show-ref) : plumbing;;
475 send-pack) : plumbing;;
476 show-index) : plumbing;;
477 ssh-*) : transport;;
478 stripspace) : plumbing;;
479 symbolic-ref) : plumbing;;
480 tar-tree) : deprecated;;
481 unpack-file) : plumbing;;
482 unpack-objects) : plumbing;;
483 update-index) : plumbing;;
484 update-ref) : plumbing;;
485 update-server-info) : daemon;;
486 upload-archive) : plumbing;;
487 upload-pack) : plumbing;;
488 write-tree) : plumbing;;
489 var) : infrequent;;
490 verify-pack) : infrequent;;
491 verify-tag) : plumbing;;
492 *) echo $i;;
493 esac
494 done
495}
496__git_porcelain_commandlist=
497__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
498
499__git_aliases ()
500{
501 local i IFS=$'\n'
502 for i in $(git --git-dir="$(__gitdir)" config --list); do
503 case "$i" in
504 alias.*)
505 i="${i#alias.}"
506 echo "${i/=*/}"
507 ;;
508 esac
509 done
510}
511
512# __git_aliased_command requires 1 argument
513__git_aliased_command ()
514{
515 local word cmdline=$(git --git-dir="$(__gitdir)" \
516 config --get "alias.$1")
517 for word in $cmdline; do
518 if [ "${word##-*}" ]; then
519 echo $word
520 return
521 fi
522 done
523}
524
525# __git_find_subcommand requires 1 argument
526__git_find_subcommand ()
527{
528 local word subcommand c=1
529
530 while [ $c -lt $COMP_CWORD ]; do
531 word="${COMP_WORDS[c]}"
532 for subcommand in $1; do
533 if [ "$subcommand" = "$word" ]; then
534 echo "$subcommand"
535 return
536 fi
537 done
538 c=$((++c))
539 done
540}
541
542__git_has_doubledash ()
543{
544 local c=1
545 while [ $c -lt $COMP_CWORD ]; do
546 if [ "--" = "${COMP_WORDS[c]}" ]; then
547 return 0
548 fi
549 c=$((++c))
550 done
551 return 1
552}
553
554__git_whitespacelist="nowarn warn error error-all fix"
555
556_git_am ()
557{
558 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
559 if [ -d "$dir"/rebase-apply ]; then
560 __gitcomp "--skip --resolved --abort"
561 return
562 fi
563 case "$cur" in
564 --whitespace=*)
565 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
566 return
567 ;;
568 --*)
569 __gitcomp "
570 --signoff --utf8 --binary --3way --interactive
571 --whitespace=
572 "
573 return
574 esac
575 COMPREPLY=()
576}
577
578_git_apply ()
579{
580 local cur="${COMP_WORDS[COMP_CWORD]}"
581 case "$cur" in
582 --whitespace=*)
583 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
584 return
585 ;;
586 --*)
587 __gitcomp "
588 --stat --numstat --summary --check --index
589 --cached --index-info --reverse --reject --unidiff-zero
590 --apply --no-add --exclude=
591 --whitespace= --inaccurate-eof --verbose
592 "
593 return
594 esac
595 COMPREPLY=()
596}
597
598_git_add ()
599{
600 __git_has_doubledash && return
601
602 local cur="${COMP_WORDS[COMP_CWORD]}"
603 case "$cur" in
604 --*)
605 __gitcomp "
606 --interactive --refresh --patch --update --dry-run
607 --ignore-errors --intent-to-add
608 "
609 return
610 esac
611 COMPREPLY=()
612}
613
614_git_archive ()
615{
616 local cur="${COMP_WORDS[COMP_CWORD]}"
617 case "$cur" in
618 --format=*)
619 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
620 return
621 ;;
622 --remote=*)
623 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
624 return
625 ;;
626 --*)
627 __gitcomp "
628 --format= --list --verbose
629 --prefix= --remote= --exec=
630 "
631 return
632 ;;
633 esac
634 __git_complete_file
635}
636
637_git_bisect ()
638{
639 __git_has_doubledash && return
640
641 local subcommands="start bad good skip reset visualize replay log run"
642 local subcommand="$(__git_find_subcommand "$subcommands")"
643 if [ -z "$subcommand" ]; then
644 __gitcomp "$subcommands"
645 return
646 fi
647
648 case "$subcommand" in
649 bad|good|reset|skip)
650 __gitcomp "$(__git_refs)"
651 ;;
652 *)
653 COMPREPLY=()
654 ;;
655 esac
656}
657
658_git_branch ()
659{
660 local i c=1 only_local_ref="n" has_r="n"
661
662 while [ $c -lt $COMP_CWORD ]; do
663 i="${COMP_WORDS[c]}"
664 case "$i" in
665 -d|-m) only_local_ref="y" ;;
666 -r) has_r="y" ;;
667 esac
668 c=$((++c))
669 done
670
671 case "${COMP_WORDS[COMP_CWORD]}" in
672 --*)
673 __gitcomp "
674 --color --no-color --verbose --abbrev= --no-abbrev
675 --track --no-track --contains --merged --no-merged
676 "
677 ;;
678 *)
679 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
680 __gitcomp "$(__git_heads)"
681 else
682 __gitcomp "$(__git_refs)"
683 fi
684 ;;
685 esac
686}
687
688_git_bundle ()
689{
690 local cmd="${COMP_WORDS[2]}"
691 case "$COMP_CWORD" in
692 2)
693 __gitcomp "create list-heads verify unbundle"
694 ;;
695 3)
696 # looking for a file
697 ;;
698 *)
699 case "$cmd" in
700 create)
701 __git_complete_revlist
702 ;;
703 esac
704 ;;
705 esac
706}
707
708_git_checkout ()
709{
710 __git_has_doubledash && return
711
712 __gitcomp "$(__git_refs)"
713}
714
715_git_cherry ()
716{
717 __gitcomp "$(__git_refs)"
718}
719
720_git_cherry_pick ()
721{
722 local cur="${COMP_WORDS[COMP_CWORD]}"
723 case "$cur" in
724 --*)
725 __gitcomp "--edit --no-commit"
726 ;;
727 *)
728 __gitcomp "$(__git_refs)"
729 ;;
730 esac
731}
732
733_git_clean ()
734{
735 __git_has_doubledash && return
736
737 local cur="${COMP_WORDS[COMP_CWORD]}"
738 case "$cur" in
739 --*)
740 __gitcomp "--dry-run --quiet"
741 return
742 ;;
743 esac
744 COMPREPLY=()
745}
746
747_git_clone ()
748{
749 local cur="${COMP_WORDS[COMP_CWORD]}"
750 case "$cur" in
751 --*)
752 __gitcomp "
753 --local
754 --no-hardlinks
755 --shared
756 --reference
757 --quiet
758 --no-checkout
759 --bare
760 --mirror
761 --origin
762 --upload-pack
763 --template=
764 --depth
765 "
766 return
767 ;;
768 esac
769 COMPREPLY=()
770}
771
772_git_commit ()
773{
774 __git_has_doubledash && return
775
776 local cur="${COMP_WORDS[COMP_CWORD]}"
777 case "$cur" in
778 --*)
779 __gitcomp "
780 --all --author= --signoff --verify --no-verify
781 --edit --amend --include --only --interactive
782 "
783 return
784 esac
785 COMPREPLY=()
786}
787
788_git_describe ()
789{
790 local cur="${COMP_WORDS[COMP_CWORD]}"
791 case "$cur" in
792 --*)
793 __gitcomp "
794 --all --tags --contains --abbrev= --candidates=
795 --exact-match --debug --long --match --always
796 "
797 return
798 esac
799 __gitcomp "$(__git_refs)"
800}
801
802__git_diff_common_options="--stat --numstat --shortstat --summary
803 --patch-with-stat --name-only --name-status --color
804 --no-color --color-words --no-renames --check
805 --full-index --binary --abbrev --diff-filter=
806 --find-copies-harder
807 --text --ignore-space-at-eol --ignore-space-change
808 --ignore-all-space --exit-code --quiet --ext-diff
809 --no-ext-diff
810 --no-prefix --src-prefix= --dst-prefix=
811 --inter-hunk-context=
812 --patience
813 --raw
814"
815
816_git_diff ()
817{
818 __git_has_doubledash && return
819
820 local cur="${COMP_WORDS[COMP_CWORD]}"
821 case "$cur" in
822 --*)
823 __gitcomp "--cached --pickaxe-all --pickaxe-regex
824 --base --ours --theirs
825 $__git_diff_common_options
826 "
827 return
828 ;;
829 esac
830 __git_complete_file
831}
832
833_git_fetch ()
834{
835 local cur="${COMP_WORDS[COMP_CWORD]}"
836
837 if [ "$COMP_CWORD" = 2 ]; then
838 __gitcomp "$(__git_remotes)"
839 else
840 case "$cur" in
841 *:*)
842 local pfx=""
843 case "$COMP_WORDBREAKS" in
844 *:*) : great ;;
845 *) pfx="${cur%%:*}:" ;;
846 esac
847 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
848 ;;
849 *)
850 __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
851 ;;
852 esac
853 fi
854}
855
856_git_format_patch ()
857{
858 local cur="${COMP_WORDS[COMP_CWORD]}"
859 case "$cur" in
860 --*)
861 __gitcomp "
862 --stdout --attach --thread
863 --output-directory
864 --numbered --start-number
865 --numbered-files
866 --keep-subject
867 --signoff
868 --in-reply-to=
869 --full-index --binary
870 --not --all
871 --cover-letter
872 --no-prefix --src-prefix= --dst-prefix=
873 --inline --suffix= --ignore-if-in-upstream
874 --subject-prefix=
875 "
876 return
877 ;;
878 esac
879 __git_complete_revlist
880}
881
882_git_gc ()
883{
884 local cur="${COMP_WORDS[COMP_CWORD]}"
885 case "$cur" in
886 --*)
887 __gitcomp "--prune --aggressive"
888 return
889 ;;
890 esac
891 COMPREPLY=()
892}
893
894_git_grep ()
895{
896 __git_has_doubledash && return
897
898 local cur="${COMP_WORDS[COMP_CWORD]}"
899 case "$cur" in
900 --*)
901 __gitcomp "
902 --cached
903 --text --ignore-case --word-regexp --invert-match
904 --full-name
905 --extended-regexp --basic-regexp --fixed-strings
906 --files-with-matches --name-only
907 --files-without-match
908 --count
909 --and --or --not --all-match
910 "
911 return
912 ;;
913 esac
914 COMPREPLY=()
915}
916
917_git_help ()
918{
919 local cur="${COMP_WORDS[COMP_CWORD]}"
920 case "$cur" in
921 --*)
922 __gitcomp "--all --info --man --web"
923 return
924 ;;
925 esac
926 __gitcomp "$(__git_all_commands)
927 attributes cli core-tutorial cvs-migration
928 diffcore gitk glossary hooks ignore modules
929 repository-layout tutorial tutorial-2
930 workflows
931 "
932}
933
934_git_init ()
935{
936 local cur="${COMP_WORDS[COMP_CWORD]}"
937 case "$cur" in
938 --shared=*)
939 __gitcomp "
940 false true umask group all world everybody
941 " "" "${cur##--shared=}"
942 return
943 ;;
944 --*)
945 __gitcomp "--quiet --bare --template= --shared --shared="
946 return
947 ;;
948 esac
949 COMPREPLY=()
950}
951
952_git_ls_files ()
953{
954 __git_has_doubledash && return
955
956 local cur="${COMP_WORDS[COMP_CWORD]}"
957 case "$cur" in
958 --*)
959 __gitcomp "--cached --deleted --modified --others --ignored
960 --stage --directory --no-empty-directory --unmerged
961 --killed --exclude= --exclude-from=
962 --exclude-per-directory= --exclude-standard
963 --error-unmatch --with-tree= --full-name
964 --abbrev --ignored --exclude-per-directory
965 "
966 return
967 ;;
968 esac
969 COMPREPLY=()
970}
971
972_git_ls_remote ()
973{
974 __gitcomp "$(__git_remotes)"
975}
976
977_git_ls_tree ()
978{
979 __git_complete_file
980}
981
982# Options that go well for log, shortlog and gitk
983__git_log_common_options="
984 --not --all
985 --branches --tags --remotes
986 --first-parent --no-merges
987 --max-count=
988 --max-age= --since= --after=
989 --min-age= --until= --before=
990"
991# Options that go well for log and gitk (not shortlog)
992__git_log_gitk_options="
993 --dense --sparse --full-history
994 --simplify-merges --simplify-by-decoration
995 --left-right
996"
997# Options that go well for log and shortlog (not gitk)
998__git_log_shortlog_options="
999 --author= --committer= --grep=
1000 --all-match
1001"
1002
1003__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1004
1005_git_log ()
1006{
1007 __git_has_doubledash && return
1008
1009 local cur="${COMP_WORDS[COMP_CWORD]}"
1010 local g="$(git rev-parse --git-dir 2>/dev/null)"
1011 local merge=""
1012 if [ -f $g/MERGE_HEAD ]; then
1013 merge="--merge"
1014 fi
1015 case "$cur" in
1016 --pretty=*)
1017 __gitcomp "$__git_log_pretty_formats
1018 " "" "${cur##--pretty=}"
1019 return
1020 ;;
1021 --date=*)
1022 __gitcomp "
1023 relative iso8601 rfc2822 short local default
1024 " "" "${cur##--date=}"
1025 return
1026 ;;
1027 --*)
1028 __gitcomp "
1029 $__git_log_common_options
1030 $__git_log_shortlog_options
1031 $__git_log_gitk_options
1032 --root --topo-order --date-order --reverse
1033 --follow
1034 --abbrev-commit --abbrev=
1035 --relative-date --date=
1036 --pretty=
1037 --cherry-pick
1038 --graph
1039 --decorate
1040 --walk-reflogs
1041 --parents --children
1042 $merge
1043 $__git_diff_common_options
1044 --pickaxe-all --pickaxe-regex
1045 "
1046 return
1047 ;;
1048 esac
1049 __git_complete_revlist
1050}
1051
1052_git_merge ()
1053{
1054 local cur="${COMP_WORDS[COMP_CWORD]}"
1055 case "${COMP_WORDS[COMP_CWORD-1]}" in
1056 -s|--strategy)
1057 __gitcomp "$(__git_merge_strategies)"
1058 return
1059 esac
1060 case "$cur" in
1061 --strategy=*)
1062 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1063 return
1064 ;;
1065 --*)
1066 __gitcomp "
1067 --no-commit --no-stat --log --no-log --squash --strategy
1068 --commit --stat --no-squash --ff --no-ff
1069 "
1070 return
1071 esac
1072 __gitcomp "$(__git_refs)"
1073}
1074
1075_git_mergetool ()
1076{
1077 local cur="${COMP_WORDS[COMP_CWORD]}"
1078 case "$cur" in
1079 --tool=*)
1080 __gitcomp "
1081 kdiff3 tkdiff meld xxdiff emerge
1082 vimdiff gvimdiff ecmerge opendiff
1083 " "" "${cur##--tool=}"
1084 return
1085 ;;
1086 --*)
1087 __gitcomp "--tool="
1088 return
1089 ;;
1090 esac
1091 COMPREPLY=()
1092}
1093
1094_git_merge_base ()
1095{
1096 __gitcomp "$(__git_refs)"
1097}
1098
1099_git_mv ()
1100{
1101 local cur="${COMP_WORDS[COMP_CWORD]}"
1102 case "$cur" in
1103 --*)
1104 __gitcomp "--dry-run"
1105 return
1106 ;;
1107 esac
1108 COMPREPLY=()
1109}
1110
1111_git_name_rev ()
1112{
1113 __gitcomp "--tags --all --stdin"
1114}
1115
1116_git_pull ()
1117{
1118 local cur="${COMP_WORDS[COMP_CWORD]}"
1119
1120 if [ "$COMP_CWORD" = 2 ]; then
1121 __gitcomp "$(__git_remotes)"
1122 else
1123 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1124 fi
1125}
1126
1127_git_push ()
1128{
1129 local cur="${COMP_WORDS[COMP_CWORD]}"
1130
1131 if [ "$COMP_CWORD" = 2 ]; then
1132 __gitcomp "$(__git_remotes)"
1133 else
1134 case "$cur" in
1135 *:*)
1136 local pfx=""
1137 case "$COMP_WORDBREAKS" in
1138 *:*) : great ;;
1139 *) pfx="${cur%%:*}:" ;;
1140 esac
1141
1142 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1143 ;;
1144 +*)
1145 __gitcomp "$(__git_refs)" + "${cur#+}"
1146 ;;
1147 *)
1148 __gitcomp "$(__git_refs)"
1149 ;;
1150 esac
1151 fi
1152}
1153
1154_git_rebase ()
1155{
1156 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1157 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1158 __gitcomp "--continue --skip --abort"
1159 return
1160 fi
1161 case "${COMP_WORDS[COMP_CWORD-1]}" in
1162 -s|--strategy)
1163 __gitcomp "$(__git_merge_strategies)"
1164 return
1165 esac
1166 case "$cur" in
1167 --strategy=*)
1168 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1169 return
1170 ;;
1171 --*)
1172 __gitcomp "--onto --merge --strategy --interactive"
1173 return
1174 esac
1175 __gitcomp "$(__git_refs)"
1176}
1177
1178_git_send_email ()
1179{
1180 local cur="${COMP_WORDS[COMP_CWORD]}"
1181 case "$cur" in
1182 --*)
1183 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1184 --dry-run --envelope-sender --from --identity
1185 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1186 --no-suppress-from --no-thread --quiet
1187 --signed-off-by-cc --smtp-pass --smtp-server
1188 --smtp-server-port --smtp-ssl --smtp-user --subject
1189 --suppress-cc --suppress-from --thread --to
1190 --validate --no-validate"
1191 return
1192 ;;
1193 esac
1194 COMPREPLY=()
1195}
1196
1197_git_config ()
1198{
1199 local cur="${COMP_WORDS[COMP_CWORD]}"
1200 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1201 case "$prv" in
1202 branch.*.remote)
1203 __gitcomp "$(__git_remotes)"
1204 return
1205 ;;
1206 branch.*.merge)
1207 __gitcomp "$(__git_refs)"
1208 return
1209 ;;
1210 remote.*.fetch)
1211 local remote="${prv#remote.}"
1212 remote="${remote%.fetch}"
1213 __gitcomp "$(__git_refs_remotes "$remote")"
1214 return
1215 ;;
1216 remote.*.push)
1217 local remote="${prv#remote.}"
1218 remote="${remote%.push}"
1219 __gitcomp "$(git --git-dir="$(__gitdir)" \
1220 for-each-ref --format='%(refname):%(refname)' \
1221 refs/heads)"
1222 return
1223 ;;
1224 pull.twohead|pull.octopus)
1225 __gitcomp "$(__git_merge_strategies)"
1226 return
1227 ;;
1228 color.branch|color.diff|color.interactive|color.status|color.ui)
1229 __gitcomp "always never auto"
1230 return
1231 ;;
1232 color.pager)
1233 __gitcomp "false true"
1234 return
1235 ;;
1236 color.*.*)
1237 __gitcomp "
1238 normal black red green yellow blue magenta cyan white
1239 bold dim ul blink reverse
1240 "
1241 return
1242 ;;
1243 *.*)
1244 COMPREPLY=()
1245 return
1246 ;;
1247 esac
1248 case "$cur" in
1249 --*)
1250 __gitcomp "
1251 --global --system --file=
1252 --list --replace-all
1253 --get --get-all --get-regexp
1254 --add --unset --unset-all
1255 --remove-section --rename-section
1256 "
1257 return
1258 ;;
1259 branch.*.*)
1260 local pfx="${cur%.*}."
1261 cur="${cur##*.}"
1262 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1263 return
1264 ;;
1265 branch.*)
1266 local pfx="${cur%.*}."
1267 cur="${cur#*.}"
1268 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1269 return
1270 ;;
1271 remote.*.*)
1272 local pfx="${cur%.*}."
1273 cur="${cur##*.}"
1274 __gitcomp "
1275 url proxy fetch push mirror skipDefaultUpdate
1276 receivepack uploadpack tagopt
1277 " "$pfx" "$cur"
1278 return
1279 ;;
1280 remote.*)
1281 local pfx="${cur%.*}."
1282 cur="${cur#*.}"
1283 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1284 return
1285 ;;
1286 esac
1287 __gitcomp "
1288 apply.whitespace
1289 branch.autosetupmerge
1290 branch.autosetuprebase
1291 clean.requireForce
1292 color.branch
1293 color.branch.current
1294 color.branch.local
1295 color.branch.plain
1296 color.branch.remote
1297 color.diff
1298 color.diff.commit
1299 color.diff.frag
1300 color.diff.meta
1301 color.diff.new
1302 color.diff.old
1303 color.diff.plain
1304 color.diff.whitespace
1305 color.interactive
1306 color.interactive.header
1307 color.interactive.help
1308 color.interactive.prompt
1309 color.pager
1310 color.status
1311 color.status.added
1312 color.status.changed
1313 color.status.header
1314 color.status.nobranch
1315 color.status.untracked
1316 color.status.updated
1317 color.ui
1318 commit.template
1319 core.autocrlf
1320 core.bare
1321 core.compression
1322 core.deltaBaseCacheLimit
1323 core.editor
1324 core.excludesfile
1325 core.fileMode
1326 core.fsyncobjectfiles
1327 core.gitProxy
1328 core.ignoreCygwinFSTricks
1329 core.ignoreStat
1330 core.logAllRefUpdates
1331 core.loosecompression
1332 core.packedGitLimit
1333 core.packedGitWindowSize
1334 core.pager
1335 core.preferSymlinkRefs
1336 core.preloadindex
1337 core.quotepath
1338 core.repositoryFormatVersion
1339 core.safecrlf
1340 core.sharedRepository
1341 core.symlinks
1342 core.trustctime
1343 core.warnAmbiguousRefs
1344 core.whitespace
1345 core.worktree
1346 diff.autorefreshindex
1347 diff.external
1348 diff.mnemonicprefix
1349 diff.renameLimit
1350 diff.renameLimit.
1351 diff.renames
1352 fetch.unpackLimit
1353 format.headers
1354 format.numbered
1355 format.pretty
1356 format.suffix
1357 gc.aggressiveWindow
1358 gc.auto
1359 gc.autopacklimit
1360 gc.packrefs
1361 gc.pruneexpire
1362 gc.reflogexpire
1363 gc.reflogexpireunreachable
1364 gc.rerereresolved
1365 gc.rerereunresolved
1366 gitcvs.allbinary
1367 gitcvs.dbTableNamePrefix
1368 gitcvs.dbdriver
1369 gitcvs.dbname
1370 gitcvs.dbpass
1371 gitcvs.dbuser
1372 gitcvs.enabled
1373 gitcvs.logfile
1374 gitcvs.usecrlfattr
1375 gui.blamehistoryctx
1376 gui.commitmsgwidth
1377 gui.copyblamethreshold
1378 gui.diffcontext
1379 gui.encoding
1380 gui.fastcopyblame
1381 gui.matchtrackingbranch
1382 gui.newbranchtemplate
1383 gui.pruneduringfetch
1384 gui.spellingdictionary
1385 gui.trustmtime
1386 help.autocorrect
1387 help.browser
1388 help.format
1389 http.lowSpeedLimit
1390 http.lowSpeedTime
1391 http.maxRequests
1392 http.noEPSV
1393 http.proxy
1394 http.sslCAInfo
1395 http.sslCAPath
1396 http.sslCert
1397 http.sslKey
1398 http.sslVerify
1399 i18n.commitEncoding
1400 i18n.logOutputEncoding
1401 instaweb.browser
1402 instaweb.httpd
1403 instaweb.local
1404 instaweb.modulepath
1405 instaweb.port
1406 log.date
1407 log.showroot
1408 man.viewer
1409 merge.conflictstyle
1410 merge.log
1411 merge.renameLimit
1412 merge.stat
1413 merge.tool
1414 merge.verbosity
1415 mergetool.keepBackup
1416 pack.compression
1417 pack.deltaCacheLimit
1418 pack.deltaCacheSize
1419 pack.depth
1420 pack.indexVersion
1421 pack.packSizeLimit
1422 pack.threads
1423 pack.window
1424 pack.windowMemory
1425 pull.octopus
1426 pull.twohead
1427 receive.denyCurrentBranch
1428 receive.denyDeletes
1429 receive.denyNonFastForwards
1430 receive.fsckObjects
1431 receive.unpackLimit
1432 repack.usedeltabaseoffset
1433 rerere.autoupdate
1434 rerere.enabled
1435 showbranch.default
1436 status.relativePaths
1437 status.showUntrackedFiles
1438 tar.umask
1439 transfer.unpackLimit
1440 user.email
1441 user.name
1442 user.signingkey
1443 web.browser
1444 branch. remote.
1445 "
1446}
1447
1448_git_remote ()
1449{
1450 local subcommands="add rename rm show prune update"
1451 local subcommand="$(__git_find_subcommand "$subcommands")"
1452 if [ -z "$subcommand" ]; then
1453 __gitcomp "$subcommands"
1454 return
1455 fi
1456
1457 case "$subcommand" in
1458 rename|rm|show|prune)
1459 __gitcomp "$(__git_remotes)"
1460 ;;
1461 update)
1462 local i c='' IFS=$'\n'
1463 for i in $(git --git-dir="$(__gitdir)" config --list); do
1464 case "$i" in
1465 remotes.*)
1466 i="${i#remotes.}"
1467 c="$c ${i/=*/}"
1468 ;;
1469 esac
1470 done
1471 __gitcomp "$c"
1472 ;;
1473 *)
1474 COMPREPLY=()
1475 ;;
1476 esac
1477}
1478
1479_git_reset ()
1480{
1481 __git_has_doubledash && return
1482
1483 local cur="${COMP_WORDS[COMP_CWORD]}"
1484 case "$cur" in
1485 --*)
1486 __gitcomp "--merge --mixed --hard --soft"
1487 return
1488 ;;
1489 esac
1490 __gitcomp "$(__git_refs)"
1491}
1492
1493_git_revert ()
1494{
1495 local cur="${COMP_WORDS[COMP_CWORD]}"
1496 case "$cur" in
1497 --*)
1498 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1499 return
1500 ;;
1501 esac
1502 __gitcomp "$(__git_refs)"
1503}
1504
1505_git_rm ()
1506{
1507 __git_has_doubledash && return
1508
1509 local cur="${COMP_WORDS[COMP_CWORD]}"
1510 case "$cur" in
1511 --*)
1512 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1513 return
1514 ;;
1515 esac
1516 COMPREPLY=()
1517}
1518
1519_git_shortlog ()
1520{
1521 __git_has_doubledash && return
1522
1523 local cur="${COMP_WORDS[COMP_CWORD]}"
1524 case "$cur" in
1525 --*)
1526 __gitcomp "
1527 $__git_log_common_options
1528 $__git_log_shortlog_options
1529 --numbered --summary
1530 "
1531 return
1532 ;;
1533 esac
1534 __git_complete_revlist
1535}
1536
1537_git_show ()
1538{
1539 __git_has_doubledash && return
1540
1541 local cur="${COMP_WORDS[COMP_CWORD]}"
1542 case "$cur" in
1543 --pretty=*)
1544 __gitcomp "$__git_log_pretty_formats
1545 " "" "${cur##--pretty=}"
1546 return
1547 ;;
1548 --*)
1549 __gitcomp "--pretty=
1550 $__git_diff_common_options
1551 "
1552 return
1553 ;;
1554 esac
1555 __git_complete_file
1556}
1557
1558_git_show_branch ()
1559{
1560 local cur="${COMP_WORDS[COMP_CWORD]}"
1561 case "$cur" in
1562 --*)
1563 __gitcomp "
1564 --all --remotes --topo-order --current --more=
1565 --list --independent --merge-base --no-name
1566 --sha1-name --topics --reflog
1567 "
1568 return
1569 ;;
1570 esac
1571 __git_complete_revlist
1572}
1573
1574_git_stash ()
1575{
1576 local subcommands='save list show apply clear drop pop create branch'
1577 local subcommand="$(__git_find_subcommand "$subcommands")"
1578 if [ -z "$subcommand" ]; then
1579 __gitcomp "$subcommands"
1580 else
1581 local cur="${COMP_WORDS[COMP_CWORD]}"
1582 case "$subcommand,$cur" in
1583 save,--*)
1584 __gitcomp "--keep-index"
1585 ;;
1586 apply,--*)
1587 __gitcomp "--index"
1588 ;;
1589 show,--*|drop,--*|pop,--*|branch,--*)
1590 COMPREPLY=()
1591 ;;
1592 show,*|apply,*|drop,*|pop,*|branch,*)
1593 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1594 | sed -n -e 's/:.*//p')"
1595 ;;
1596 *)
1597 COMPREPLY=()
1598 ;;
1599 esac
1600 fi
1601}
1602
1603_git_submodule ()
1604{
1605 __git_has_doubledash && return
1606
1607 local subcommands="add status init update summary foreach sync"
1608 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1609 local cur="${COMP_WORDS[COMP_CWORD]}"
1610 case "$cur" in
1611 --*)
1612 __gitcomp "--quiet --cached"
1613 ;;
1614 *)
1615 __gitcomp "$subcommands"
1616 ;;
1617 esac
1618 return
1619 fi
1620}
1621
1622_git_svn ()
1623{
1624 local subcommands="
1625 init fetch clone rebase dcommit log find-rev
1626 set-tree commit-diff info create-ignore propget
1627 proplist show-ignore show-externals branch tag blame
1628 migrate
1629 "
1630 local subcommand="$(__git_find_subcommand "$subcommands")"
1631 if [ -z "$subcommand" ]; then
1632 __gitcomp "$subcommands"
1633 else
1634 local remote_opts="--username= --config-dir= --no-auth-cache"
1635 local fc_opts="
1636 --follow-parent --authors-file= --repack=
1637 --no-metadata --use-svm-props --use-svnsync-props
1638 --log-window-size= --no-checkout --quiet
1639 --repack-flags --use-log-author --localtime
1640 --ignore-paths= $remote_opts
1641 "
1642 local init_opts="
1643 --template= --shared= --trunk= --tags=
1644 --branches= --stdlayout --minimize-url
1645 --no-metadata --use-svm-props --use-svnsync-props
1646 --rewrite-root= --prefix= --use-log-author
1647 --add-author-from $remote_opts
1648 "
1649 local cmt_opts="
1650 --edit --rmdir --find-copies-harder --copy-similarity=
1651 "
1652
1653 local cur="${COMP_WORDS[COMP_CWORD]}"
1654 case "$subcommand,$cur" in
1655 fetch,--*)
1656 __gitcomp "--revision= --fetch-all $fc_opts"
1657 ;;
1658 clone,--*)
1659 __gitcomp "--revision= $fc_opts $init_opts"
1660 ;;
1661 init,--*)
1662 __gitcomp "$init_opts"
1663 ;;
1664 dcommit,--*)
1665 __gitcomp "
1666 --merge --strategy= --verbose --dry-run
1667 --fetch-all --no-rebase --commit-url
1668 --revision $cmt_opts $fc_opts
1669 "
1670 ;;
1671 set-tree,--*)
1672 __gitcomp "--stdin $cmt_opts $fc_opts"
1673 ;;
1674 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1675 show-externals,--*)
1676 __gitcomp "--revision="
1677 ;;
1678 log,--*)
1679 __gitcomp "
1680 --limit= --revision= --verbose --incremental
1681 --oneline --show-commit --non-recursive
1682 --authors-file= --color
1683 "
1684 ;;
1685 rebase,--*)
1686 __gitcomp "
1687 --merge --verbose --strategy= --local
1688 --fetch-all --dry-run $fc_opts
1689 "
1690 ;;
1691 commit-diff,--*)
1692 __gitcomp "--message= --file= --revision= $cmt_opts"
1693 ;;
1694 info,--*)
1695 __gitcomp "--url"
1696 ;;
1697 branch,--*)
1698 __gitcomp "--dry-run --message --tag"
1699 ;;
1700 tag,--*)
1701 __gitcomp "--dry-run --message"
1702 ;;
1703 blame,--*)
1704 __gitcomp "--git-format"
1705 ;;
1706 migrate,--*)
1707 __gitcomp "
1708 --config-dir= --ignore-paths= --minimize
1709 --no-auth-cache --username=
1710 "
1711 ;;
1712 *)
1713 COMPREPLY=()
1714 ;;
1715 esac
1716 fi
1717}
1718
1719_git_tag ()
1720{
1721 local i c=1 f=0
1722 while [ $c -lt $COMP_CWORD ]; do
1723 i="${COMP_WORDS[c]}"
1724 case "$i" in
1725 -d|-v)
1726 __gitcomp "$(__git_tags)"
1727 return
1728 ;;
1729 -f)
1730 f=1
1731 ;;
1732 esac
1733 c=$((++c))
1734 done
1735
1736 case "${COMP_WORDS[COMP_CWORD-1]}" in
1737 -m|-F)
1738 COMPREPLY=()
1739 ;;
1740 -*|tag)
1741 if [ $f = 1 ]; then
1742 __gitcomp "$(__git_tags)"
1743 else
1744 COMPREPLY=()
1745 fi
1746 ;;
1747 *)
1748 __gitcomp "$(__git_refs)"
1749 ;;
1750 esac
1751}
1752
1753_git ()
1754{
1755 local i c=1 command __git_dir
1756
1757 while [ $c -lt $COMP_CWORD ]; do
1758 i="${COMP_WORDS[c]}"
1759 case "$i" in
1760 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1761 --bare) __git_dir="." ;;
1762 --version|-p|--paginate) ;;
1763 --help) command="help"; break ;;
1764 *) command="$i"; break ;;
1765 esac
1766 c=$((++c))
1767 done
1768
1769 if [ -z "$command" ]; then
1770 case "${COMP_WORDS[COMP_CWORD]}" in
1771 --*) __gitcomp "
1772 --paginate
1773 --no-pager
1774 --git-dir=
1775 --bare
1776 --version
1777 --exec-path
1778 --work-tree=
1779 --help
1780 "
1781 ;;
1782 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1783 esac
1784 return
1785 fi
1786
1787 local expansion=$(__git_aliased_command "$command")
1788 [ "$expansion" ] && command="$expansion"
1789
1790 case "$command" in
1791 am) _git_am ;;
1792 add) _git_add ;;
1793 apply) _git_apply ;;
1794 archive) _git_archive ;;
1795 bisect) _git_bisect ;;
1796 bundle) _git_bundle ;;
1797 branch) _git_branch ;;
1798 checkout) _git_checkout ;;
1799 cherry) _git_cherry ;;
1800 cherry-pick) _git_cherry_pick ;;
1801 clean) _git_clean ;;
1802 clone) _git_clone ;;
1803 commit) _git_commit ;;
1804 config) _git_config ;;
1805 describe) _git_describe ;;
1806 diff) _git_diff ;;
1807 fetch) _git_fetch ;;
1808 format-patch) _git_format_patch ;;
1809 gc) _git_gc ;;
1810 grep) _git_grep ;;
1811 help) _git_help ;;
1812 init) _git_init ;;
1813 log) _git_log ;;
1814 ls-files) _git_ls_files ;;
1815 ls-remote) _git_ls_remote ;;
1816 ls-tree) _git_ls_tree ;;
1817 merge) _git_merge;;
1818 mergetool) _git_mergetool;;
1819 merge-base) _git_merge_base ;;
1820 mv) _git_mv ;;
1821 name-rev) _git_name_rev ;;
1822 pull) _git_pull ;;
1823 push) _git_push ;;
1824 rebase) _git_rebase ;;
1825 remote) _git_remote ;;
1826 reset) _git_reset ;;
1827 revert) _git_revert ;;
1828 rm) _git_rm ;;
1829 send-email) _git_send_email ;;
1830 shortlog) _git_shortlog ;;
1831 show) _git_show ;;
1832 show-branch) _git_show_branch ;;
1833 stash) _git_stash ;;
1834 stage) _git_add ;;
1835 submodule) _git_submodule ;;
1836 svn) _git_svn ;;
1837 tag) _git_tag ;;
1838 whatchanged) _git_log ;;
1839 *) COMPREPLY=() ;;
1840 esac
1841}
1842
1843_gitk ()
1844{
1845 __git_has_doubledash && return
1846
1847 local cur="${COMP_WORDS[COMP_CWORD]}"
1848 local g="$(__gitdir)"
1849 local merge=""
1850 if [ -f $g/MERGE_HEAD ]; then
1851 merge="--merge"
1852 fi
1853 case "$cur" in
1854 --*)
1855 __gitcomp "
1856 $__git_log_common_options
1857 $__git_log_gitk_options
1858 $merge
1859 "
1860 return
1861 ;;
1862 esac
1863 __git_complete_revlist
1864}
1865
1866complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
1867 || complete -o default -o nospace -F _git git
1868complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
1869 || complete -o default -o nospace -F _gitk gitk
1870
1871# The following are necessary only for Cygwin, and only are needed
1872# when the user has tab-completed the executable name and consequently
1873# included the '.exe' suffix.
1874#
1875if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1876complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
1877 || complete -o default -o nospace -F _git git.exe
1878fi