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 #
55 case "$COMP_WORDBREAKS" in
56 *:*) : great ;;
57 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
58 esac
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 }
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
118 local w
119 local i
120 local c
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
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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)
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
341 case "$COMP_WORDBREAKS" in
342 *:*) : great ;;
343 *) pfx="$ref:$pfx" ;;
344 esac
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 }
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 }
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)"
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)"
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 }
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 }
525 # __git_find_subcommand requires 1 argument
526 __git_find_subcommand ()
527 {
528 local word subcommand c=1
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 }
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 }
554 __git_whitespacelist="nowarn warn error error-all fix"
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 }
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 }
598 _git_add ()
599 {
600 __git_has_doubledash && return
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 }
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 }
637 _git_bisect ()
638 {
639 __git_has_doubledash && return
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
648 case "$subcommand" in
649 bad|good|reset|skip)
650 __gitcomp "$(__git_refs)"
651 ;;
652 *)
653 COMPREPLY=()
654 ;;
655 esac
656 }
658 _git_branch ()
659 {
660 local i c=1 only_local_ref="n" has_r="n"
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
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 }
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 }
708 _git_checkout ()
709 {
710 __git_has_doubledash && return
712 __gitcomp "$(__git_refs)"
713 }
715 _git_cherry ()
716 {
717 __gitcomp "$(__git_refs)"
718 }
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 }
733 _git_clean ()
734 {
735 __git_has_doubledash && return
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 }
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 }
772 _git_commit ()
773 {
774 __git_has_doubledash && return
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 }
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 }
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 "
816 _git_diff ()
817 {
818 __git_has_doubledash && return
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 }
833 _git_fetch ()
834 {
835 local cur="${COMP_WORDS[COMP_CWORD]}"
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 }
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 }
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 }
894 _git_grep ()
895 {
896 __git_has_doubledash && return
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 }
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 }
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 }
952 _git_ls_files ()
953 {
954 __git_has_doubledash && return
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 }
972 _git_ls_remote ()
973 {
974 __gitcomp "$(__git_remotes)"
975 }
977 _git_ls_tree ()
978 {
979 __git_complete_file
980 }
982 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
984 _git_log ()
985 {
986 __git_has_doubledash && return
988 local cur="${COMP_WORDS[COMP_CWORD]}"
989 case "$cur" in
990 --pretty=*)
991 __gitcomp "$__git_log_pretty_formats
992 " "" "${cur##--pretty=}"
993 return
994 ;;
995 --date=*)
996 __gitcomp "
997 relative iso8601 rfc2822 short local default
998 " "" "${cur##--date=}"
999 return
1000 ;;
1001 --*)
1002 __gitcomp "
1003 --max-count= --max-age= --since= --after=
1004 --min-age= --before= --until=
1005 --root --topo-order --date-order --reverse
1006 --no-merges --follow
1007 --abbrev-commit --abbrev=
1008 --relative-date --date=
1009 --author= --committer= --grep=
1010 --all-match
1011 --pretty=
1012 --not --all
1013 --left-right --cherry-pick
1014 --graph
1015 --decorate
1016 --walk-reflogs
1017 --parents --children --full-history
1018 --merge
1019 $__git_diff_common_options
1020 --pickaxe-all --pickaxe-regex
1021 "
1022 return
1023 ;;
1024 esac
1025 __git_complete_revlist
1026 }
1028 _git_merge ()
1029 {
1030 local cur="${COMP_WORDS[COMP_CWORD]}"
1031 case "${COMP_WORDS[COMP_CWORD-1]}" in
1032 -s|--strategy)
1033 __gitcomp "$(__git_merge_strategies)"
1034 return
1035 esac
1036 case "$cur" in
1037 --strategy=*)
1038 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1039 return
1040 ;;
1041 --*)
1042 __gitcomp "
1043 --no-commit --no-stat --log --no-log --squash --strategy
1044 "
1045 return
1046 esac
1047 __gitcomp "$(__git_refs)"
1048 }
1050 _git_mergetool ()
1051 {
1052 local cur="${COMP_WORDS[COMP_CWORD]}"
1053 case "$cur" in
1054 --tool=*)
1055 __gitcomp "
1056 kdiff3 tkdiff meld xxdiff emerge
1057 vimdiff gvimdiff ecmerge opendiff
1058 " "" "${cur##--tool=}"
1059 return
1060 ;;
1061 --*)
1062 __gitcomp "--tool="
1063 return
1064 ;;
1065 esac
1066 COMPREPLY=()
1067 }
1069 _git_merge_base ()
1070 {
1071 __gitcomp "$(__git_refs)"
1072 }
1074 _git_mv ()
1075 {
1076 local cur="${COMP_WORDS[COMP_CWORD]}"
1077 case "$cur" in
1078 --*)
1079 __gitcomp "--dry-run"
1080 return
1081 ;;
1082 esac
1083 COMPREPLY=()
1084 }
1086 _git_name_rev ()
1087 {
1088 __gitcomp "--tags --all --stdin"
1089 }
1091 _git_pull ()
1092 {
1093 local cur="${COMP_WORDS[COMP_CWORD]}"
1095 if [ "$COMP_CWORD" = 2 ]; then
1096 __gitcomp "$(__git_remotes)"
1097 else
1098 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1099 fi
1100 }
1102 _git_push ()
1103 {
1104 local cur="${COMP_WORDS[COMP_CWORD]}"
1106 if [ "$COMP_CWORD" = 2 ]; then
1107 __gitcomp "$(__git_remotes)"
1108 else
1109 case "$cur" in
1110 *:*)
1111 local pfx=""
1112 case "$COMP_WORDBREAKS" in
1113 *:*) : great ;;
1114 *) pfx="${cur%%:*}:" ;;
1115 esac
1117 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1118 ;;
1119 +*)
1120 __gitcomp "$(__git_refs)" + "${cur#+}"
1121 ;;
1122 *)
1123 __gitcomp "$(__git_refs)"
1124 ;;
1125 esac
1126 fi
1127 }
1129 _git_rebase ()
1130 {
1131 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1132 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1133 __gitcomp "--continue --skip --abort"
1134 return
1135 fi
1136 case "${COMP_WORDS[COMP_CWORD-1]}" in
1137 -s|--strategy)
1138 __gitcomp "$(__git_merge_strategies)"
1139 return
1140 esac
1141 case "$cur" in
1142 --strategy=*)
1143 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1144 return
1145 ;;
1146 --*)
1147 __gitcomp "--onto --merge --strategy --interactive"
1148 return
1149 esac
1150 __gitcomp "$(__git_refs)"
1151 }
1153 _git_send_email ()
1154 {
1155 local cur="${COMP_WORDS[COMP_CWORD]}"
1156 case "$cur" in
1157 --*)
1158 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1159 --dry-run --envelope-sender --from --identity
1160 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1161 --no-suppress-from --no-thread --quiet
1162 --signed-off-by-cc --smtp-pass --smtp-server
1163 --smtp-server-port --smtp-ssl --smtp-user --subject
1164 --suppress-cc --suppress-from --thread --to
1165 --validate --no-validate"
1166 return
1167 ;;
1168 esac
1169 COMPREPLY=()
1170 }
1172 _git_config ()
1173 {
1174 local cur="${COMP_WORDS[COMP_CWORD]}"
1175 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1176 case "$prv" in
1177 branch.*.remote)
1178 __gitcomp "$(__git_remotes)"
1179 return
1180 ;;
1181 branch.*.merge)
1182 __gitcomp "$(__git_refs)"
1183 return
1184 ;;
1185 remote.*.fetch)
1186 local remote="${prv#remote.}"
1187 remote="${remote%.fetch}"
1188 __gitcomp "$(__git_refs_remotes "$remote")"
1189 return
1190 ;;
1191 remote.*.push)
1192 local remote="${prv#remote.}"
1193 remote="${remote%.push}"
1194 __gitcomp "$(git --git-dir="$(__gitdir)" \
1195 for-each-ref --format='%(refname):%(refname)' \
1196 refs/heads)"
1197 return
1198 ;;
1199 pull.twohead|pull.octopus)
1200 __gitcomp "$(__git_merge_strategies)"
1201 return
1202 ;;
1203 color.branch|color.diff|color.status)
1204 __gitcomp "always never auto"
1205 return
1206 ;;
1207 color.*.*)
1208 __gitcomp "
1209 normal black red green yellow blue magenta cyan white
1210 bold dim ul blink reverse
1211 "
1212 return
1213 ;;
1214 *.*)
1215 COMPREPLY=()
1216 return
1217 ;;
1218 esac
1219 case "$cur" in
1220 --*)
1221 __gitcomp "
1222 --global --system --file=
1223 --list --replace-all
1224 --get --get-all --get-regexp
1225 --add --unset --unset-all
1226 --remove-section --rename-section
1227 "
1228 return
1229 ;;
1230 branch.*.*)
1231 local pfx="${cur%.*}."
1232 cur="${cur##*.}"
1233 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1234 return
1235 ;;
1236 branch.*)
1237 local pfx="${cur%.*}."
1238 cur="${cur#*.}"
1239 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1240 return
1241 ;;
1242 remote.*.*)
1243 local pfx="${cur%.*}."
1244 cur="${cur##*.}"
1245 __gitcomp "
1246 url proxy fetch push mirror skipDefaultUpdate
1247 receivepack uploadpack tagopt
1248 " "$pfx" "$cur"
1249 return
1250 ;;
1251 remote.*)
1252 local pfx="${cur%.*}."
1253 cur="${cur#*.}"
1254 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1255 return
1256 ;;
1257 esac
1258 __gitcomp "
1259 apply.whitespace
1260 branch.autosetupmerge
1261 branch.autosetuprebase
1262 clean.requireForce
1263 color.branch
1264 color.branch.current
1265 color.branch.local
1266 color.branch.plain
1267 color.branch.remote
1268 color.diff
1269 color.diff.commit
1270 color.diff.frag
1271 color.diff.meta
1272 color.diff.new
1273 color.diff.old
1274 color.diff.plain
1275 color.diff.whitespace
1276 color.interactive
1277 color.interactive.header
1278 color.interactive.help
1279 color.interactive.prompt
1280 color.pager
1281 color.status
1282 color.status.added
1283 color.status.changed
1284 color.status.header
1285 color.status.nobranch
1286 color.status.untracked
1287 color.status.updated
1288 color.ui
1289 commit.template
1290 core.autocrlf
1291 core.bare
1292 core.compression
1293 core.deltaBaseCacheLimit
1294 core.editor
1295 core.excludesfile
1296 core.fileMode
1297 core.fsyncobjectfiles
1298 core.gitProxy
1299 core.ignoreCygwinFSTricks
1300 core.ignoreStat
1301 core.logAllRefUpdates
1302 core.loosecompression
1303 core.packedGitLimit
1304 core.packedGitWindowSize
1305 core.pager
1306 core.preferSymlinkRefs
1307 core.preloadindex
1308 core.quotepath
1309 core.repositoryFormatVersion
1310 core.safecrlf
1311 core.sharedRepository
1312 core.symlinks
1313 core.trustctime
1314 core.warnAmbiguousRefs
1315 core.whitespace
1316 core.worktree
1317 diff.autorefreshindex
1318 diff.external
1319 diff.mnemonicprefix
1320 diff.renameLimit
1321 diff.renameLimit.
1322 diff.renames
1323 fetch.unpackLimit
1324 format.headers
1325 format.numbered
1326 format.pretty
1327 format.suffix
1328 gc.aggressiveWindow
1329 gc.auto
1330 gc.autopacklimit
1331 gc.packrefs
1332 gc.pruneexpire
1333 gc.reflogexpire
1334 gc.reflogexpireunreachable
1335 gc.rerereresolved
1336 gc.rerereunresolved
1337 gitcvs.allbinary
1338 gitcvs.dbTableNamePrefix
1339 gitcvs.dbdriver
1340 gitcvs.dbname
1341 gitcvs.dbpass
1342 gitcvs.dbuser
1343 gitcvs.enabled
1344 gitcvs.logfile
1345 gitcvs.usecrlfattr
1346 gui.blamehistoryctx
1347 gui.commitmsgwidth
1348 gui.copyblamethreshold
1349 gui.diffcontext
1350 gui.encoding
1351 gui.fastcopyblame
1352 gui.matchtrackingbranch
1353 gui.newbranchtemplate
1354 gui.pruneduringfetch
1355 gui.spellingdictionary
1356 gui.trustmtime
1357 help.autocorrect
1358 help.browser
1359 help.format
1360 http.lowSpeedLimit
1361 http.lowSpeedTime
1362 http.maxRequests
1363 http.noEPSV
1364 http.proxy
1365 http.sslCAInfo
1366 http.sslCAPath
1367 http.sslCert
1368 http.sslKey
1369 http.sslVerify
1370 i18n.commitEncoding
1371 i18n.logOutputEncoding
1372 instaweb.browser
1373 instaweb.httpd
1374 instaweb.local
1375 instaweb.modulepath
1376 instaweb.port
1377 log.date
1378 log.showroot
1379 man.viewer
1380 merge.conflictstyle
1381 merge.log
1382 merge.renameLimit
1383 merge.stat
1384 merge.tool
1385 merge.verbosity
1386 mergetool.keepBackup
1387 pack.compression
1388 pack.deltaCacheLimit
1389 pack.deltaCacheSize
1390 pack.depth
1391 pack.indexVersion
1392 pack.packSizeLimit
1393 pack.threads
1394 pack.window
1395 pack.windowMemory
1396 pull.octopus
1397 pull.twohead
1398 receive.denyCurrentBranch
1399 receive.denyDeletes
1400 receive.denyNonFastForwards
1401 receive.fsckObjects
1402 receive.unpackLimit
1403 repack.usedeltabaseoffset
1404 rerere.autoupdate
1405 rerere.enabled
1406 showbranch.default
1407 status.relativePaths
1408 status.showUntrackedFiles
1409 tar.umask
1410 transfer.unpackLimit
1411 user.email
1412 user.name
1413 user.signingkey
1414 web.browser
1415 branch. remote.
1416 "
1417 }
1419 _git_remote ()
1420 {
1421 local subcommands="add rename rm show prune update"
1422 local subcommand="$(__git_find_subcommand "$subcommands")"
1423 if [ -z "$subcommand" ]; then
1424 __gitcomp "$subcommands"
1425 return
1426 fi
1428 case "$subcommand" in
1429 rename|rm|show|prune)
1430 __gitcomp "$(__git_remotes)"
1431 ;;
1432 update)
1433 local i c='' IFS=$'\n'
1434 for i in $(git --git-dir="$(__gitdir)" config --list); do
1435 case "$i" in
1436 remotes.*)
1437 i="${i#remotes.}"
1438 c="$c ${i/=*/}"
1439 ;;
1440 esac
1441 done
1442 __gitcomp "$c"
1443 ;;
1444 *)
1445 COMPREPLY=()
1446 ;;
1447 esac
1448 }
1450 _git_reset ()
1451 {
1452 __git_has_doubledash && return
1454 local cur="${COMP_WORDS[COMP_CWORD]}"
1455 case "$cur" in
1456 --*)
1457 __gitcomp "--merge --mixed --hard --soft"
1458 return
1459 ;;
1460 esac
1461 __gitcomp "$(__git_refs)"
1462 }
1464 _git_revert ()
1465 {
1466 local cur="${COMP_WORDS[COMP_CWORD]}"
1467 case "$cur" in
1468 --*)
1469 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1470 return
1471 ;;
1472 esac
1473 __gitcomp "$(__git_refs)"
1474 }
1476 _git_rm ()
1477 {
1478 __git_has_doubledash && return
1480 local cur="${COMP_WORDS[COMP_CWORD]}"
1481 case "$cur" in
1482 --*)
1483 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1484 return
1485 ;;
1486 esac
1487 COMPREPLY=()
1488 }
1490 _git_shortlog ()
1491 {
1492 __git_has_doubledash && return
1494 local cur="${COMP_WORDS[COMP_CWORD]}"
1495 case "$cur" in
1496 --*)
1497 __gitcomp "
1498 --max-count= --max-age= --since= --after=
1499 --min-age= --before= --until=
1500 --no-merges
1501 --author= --committer= --grep=
1502 --all-match
1503 --not --all
1504 --numbered --summary
1505 "
1506 return
1507 ;;
1508 esac
1509 __git_complete_revlist
1510 }
1512 _git_show ()
1513 {
1514 __git_has_doubledash && return
1516 local cur="${COMP_WORDS[COMP_CWORD]}"
1517 case "$cur" in
1518 --pretty=*)
1519 __gitcomp "$__git_log_pretty_formats
1520 " "" "${cur##--pretty=}"
1521 return
1522 ;;
1523 --*)
1524 __gitcomp "--pretty=
1525 $__git_diff_common_options
1526 "
1527 return
1528 ;;
1529 esac
1530 __git_complete_file
1531 }
1533 _git_show_branch ()
1534 {
1535 local cur="${COMP_WORDS[COMP_CWORD]}"
1536 case "$cur" in
1537 --*)
1538 __gitcomp "
1539 --all --remotes --topo-order --current --more=
1540 --list --independent --merge-base --no-name
1541 --sha1-name --topics --reflog
1542 "
1543 return
1544 ;;
1545 esac
1546 __git_complete_revlist
1547 }
1549 _git_stash ()
1550 {
1551 local subcommands='save list show apply clear drop pop create branch'
1552 local subcommand="$(__git_find_subcommand "$subcommands")"
1553 if [ -z "$subcommand" ]; then
1554 __gitcomp "$subcommands"
1555 else
1556 local cur="${COMP_WORDS[COMP_CWORD]}"
1557 case "$subcommand,$cur" in
1558 save,--*)
1559 __gitcomp "--keep-index"
1560 ;;
1561 apply,--*)
1562 __gitcomp "--index"
1563 ;;
1564 show,--*|drop,--*|pop,--*|branch,--*)
1565 COMPREPLY=()
1566 ;;
1567 show,*|apply,*|drop,*|pop,*|branch,*)
1568 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1569 | sed -n -e 's/:.*//p')"
1570 ;;
1571 *)
1572 COMPREPLY=()
1573 ;;
1574 esac
1575 fi
1576 }
1578 _git_submodule ()
1579 {
1580 __git_has_doubledash && return
1582 local subcommands="add status init update summary foreach sync"
1583 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1584 local cur="${COMP_WORDS[COMP_CWORD]}"
1585 case "$cur" in
1586 --*)
1587 __gitcomp "--quiet --cached"
1588 ;;
1589 *)
1590 __gitcomp "$subcommands"
1591 ;;
1592 esac
1593 return
1594 fi
1595 }
1597 _git_svn ()
1598 {
1599 local subcommands="
1600 init fetch clone rebase dcommit log find-rev
1601 set-tree commit-diff info create-ignore propget
1602 proplist show-ignore show-externals
1603 "
1604 local subcommand="$(__git_find_subcommand "$subcommands")"
1605 if [ -z "$subcommand" ]; then
1606 __gitcomp "$subcommands"
1607 else
1608 local remote_opts="--username= --config-dir= --no-auth-cache"
1609 local fc_opts="
1610 --follow-parent --authors-file= --repack=
1611 --no-metadata --use-svm-props --use-svnsync-props
1612 --log-window-size= --no-checkout --quiet
1613 --repack-flags --user-log-author --localtime $remote_opts
1614 "
1615 local init_opts="
1616 --template= --shared= --trunk= --tags=
1617 --branches= --stdlayout --minimize-url
1618 --no-metadata --use-svm-props --use-svnsync-props
1619 --rewrite-root= $remote_opts
1620 "
1621 local cmt_opts="
1622 --edit --rmdir --find-copies-harder --copy-similarity=
1623 "
1625 local cur="${COMP_WORDS[COMP_CWORD]}"
1626 case "$subcommand,$cur" in
1627 fetch,--*)
1628 __gitcomp "--revision= --fetch-all $fc_opts"
1629 ;;
1630 clone,--*)
1631 __gitcomp "--revision= $fc_opts $init_opts"
1632 ;;
1633 init,--*)
1634 __gitcomp "$init_opts"
1635 ;;
1636 dcommit,--*)
1637 __gitcomp "
1638 --merge --strategy= --verbose --dry-run
1639 --fetch-all --no-rebase $cmt_opts $fc_opts
1640 "
1641 ;;
1642 set-tree,--*)
1643 __gitcomp "--stdin $cmt_opts $fc_opts"
1644 ;;
1645 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1646 show-externals,--*)
1647 __gitcomp "--revision="
1648 ;;
1649 log,--*)
1650 __gitcomp "
1651 --limit= --revision= --verbose --incremental
1652 --oneline --show-commit --non-recursive
1653 --authors-file=
1654 "
1655 ;;
1656 rebase,--*)
1657 __gitcomp "
1658 --merge --verbose --strategy= --local
1659 --fetch-all $fc_opts
1660 "
1661 ;;
1662 commit-diff,--*)
1663 __gitcomp "--message= --file= --revision= $cmt_opts"
1664 ;;
1665 info,--*)
1666 __gitcomp "--url"
1667 ;;
1668 *)
1669 COMPREPLY=()
1670 ;;
1671 esac
1672 fi
1673 }
1675 _git_tag ()
1676 {
1677 local i c=1 f=0
1678 while [ $c -lt $COMP_CWORD ]; do
1679 i="${COMP_WORDS[c]}"
1680 case "$i" in
1681 -d|-v)
1682 __gitcomp "$(__git_tags)"
1683 return
1684 ;;
1685 -f)
1686 f=1
1687 ;;
1688 esac
1689 c=$((++c))
1690 done
1692 case "${COMP_WORDS[COMP_CWORD-1]}" in
1693 -m|-F)
1694 COMPREPLY=()
1695 ;;
1696 -*|tag)
1697 if [ $f = 1 ]; then
1698 __gitcomp "$(__git_tags)"
1699 else
1700 COMPREPLY=()
1701 fi
1702 ;;
1703 *)
1704 __gitcomp "$(__git_refs)"
1705 ;;
1706 esac
1707 }
1709 _git ()
1710 {
1711 local i c=1 command __git_dir
1713 while [ $c -lt $COMP_CWORD ]; do
1714 i="${COMP_WORDS[c]}"
1715 case "$i" in
1716 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1717 --bare) __git_dir="." ;;
1718 --version|-p|--paginate) ;;
1719 --help) command="help"; break ;;
1720 *) command="$i"; break ;;
1721 esac
1722 c=$((++c))
1723 done
1725 if [ -z "$command" ]; then
1726 case "${COMP_WORDS[COMP_CWORD]}" in
1727 --*) __gitcomp "
1728 --paginate
1729 --no-pager
1730 --git-dir=
1731 --bare
1732 --version
1733 --exec-path
1734 --work-tree=
1735 --help
1736 "
1737 ;;
1738 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1739 esac
1740 return
1741 fi
1743 local expansion=$(__git_aliased_command "$command")
1744 [ "$expansion" ] && command="$expansion"
1746 case "$command" in
1747 am) _git_am ;;
1748 add) _git_add ;;
1749 apply) _git_apply ;;
1750 archive) _git_archive ;;
1751 bisect) _git_bisect ;;
1752 bundle) _git_bundle ;;
1753 branch) _git_branch ;;
1754 checkout) _git_checkout ;;
1755 cherry) _git_cherry ;;
1756 cherry-pick) _git_cherry_pick ;;
1757 clean) _git_clean ;;
1758 clone) _git_clone ;;
1759 commit) _git_commit ;;
1760 config) _git_config ;;
1761 describe) _git_describe ;;
1762 diff) _git_diff ;;
1763 fetch) _git_fetch ;;
1764 format-patch) _git_format_patch ;;
1765 gc) _git_gc ;;
1766 grep) _git_grep ;;
1767 help) _git_help ;;
1768 init) _git_init ;;
1769 log) _git_log ;;
1770 ls-files) _git_ls_files ;;
1771 ls-remote) _git_ls_remote ;;
1772 ls-tree) _git_ls_tree ;;
1773 merge) _git_merge;;
1774 mergetool) _git_mergetool;;
1775 merge-base) _git_merge_base ;;
1776 mv) _git_mv ;;
1777 name-rev) _git_name_rev ;;
1778 pull) _git_pull ;;
1779 push) _git_push ;;
1780 rebase) _git_rebase ;;
1781 remote) _git_remote ;;
1782 reset) _git_reset ;;
1783 revert) _git_revert ;;
1784 rm) _git_rm ;;
1785 send-email) _git_send_email ;;
1786 shortlog) _git_shortlog ;;
1787 show) _git_show ;;
1788 show-branch) _git_show_branch ;;
1789 stash) _git_stash ;;
1790 stage) _git_add ;;
1791 submodule) _git_submodule ;;
1792 svn) _git_svn ;;
1793 tag) _git_tag ;;
1794 whatchanged) _git_log ;;
1795 *) COMPREPLY=() ;;
1796 esac
1797 }
1799 _gitk ()
1800 {
1801 __git_has_doubledash && return
1803 local cur="${COMP_WORDS[COMP_CWORD]}"
1804 local g="$(__gitdir)"
1805 local merge=""
1806 if [ -f $g/MERGE_HEAD ]; then
1807 merge="--merge"
1808 fi
1809 case "$cur" in
1810 --*)
1811 __gitcomp "--not --all $merge"
1812 return
1813 ;;
1814 esac
1815 __git_complete_revlist
1816 }
1818 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
1819 || complete -o default -o nospace -F _git git
1820 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
1821 || complete -o default -o nospace -F _gitk gitk
1823 # The following are necessary only for Cygwin, and only are needed
1824 # when the user has tab-completed the executable name and consequently
1825 # included the '.exe' suffix.
1826 #
1827 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1828 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
1829 || complete -o default -o nospace -F _git git.exe
1830 fi