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_complete_remote_or_refspec ()
391{
392 local cmd="${COMP_WORDS[1]}"
393 local cur="${COMP_WORDS[COMP_CWORD]}"
394 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
395 while [ $c -lt $COMP_CWORD ]; do
396 i="${COMP_WORDS[c]}"
397 case "$i" in
398 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
399 -*) ;;
400 *) remote="$i"; break ;;
401 esac
402 c=$((++c))
403 done
404 if [ -z "$remote" ]; then
405 __gitcomp "$(__git_remotes)"
406 return
407 fi
408 if [ $no_complete_refspec = 1 ]; then
409 COMPREPLY=()
410 return
411 fi
412 [ "$remote" = "." ] && remote=
413 case "$cur" in
414 *:*)
415 case "$COMP_WORDBREAKS" in
416 *:*) : great ;;
417 *) pfx="${cur%%:*}:" ;;
418 esac
419 cur="${cur#*:}"
420 lhs=0
421 ;;
422 +*)
423 pfx="+"
424 cur="${cur#+}"
425 ;;
426 esac
427 case "$cmd" in
428 fetch)
429 if [ $lhs = 1 ]; then
430 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
431 else
432 __gitcomp "$(__git_refs)" "$pfx" "$cur"
433 fi
434 ;;
435 pull)
436 if [ $lhs = 1 ]; then
437 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
438 else
439 __gitcomp "$(__git_refs)" "$pfx" "$cur"
440 fi
441 ;;
442 push)
443 if [ $lhs = 1 ]; then
444 __gitcomp "$(__git_refs)" "$pfx" "$cur"
445 else
446 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
447 fi
448 ;;
449 esac
450}
451
452__git_complete_strategy ()
453{
454 case "${COMP_WORDS[COMP_CWORD-1]}" in
455 -s|--strategy)
456 __gitcomp "$(__git_merge_strategies)"
457 return 0
458 esac
459 local cur="${COMP_WORDS[COMP_CWORD]}"
460 case "$cur" in
461 --strategy=*)
462 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
463 return 0
464 ;;
465 esac
466 return 1
467}
468
469__git_all_commands ()
470{
471 if [ -n "${__git_all_commandlist-}" ]; then
472 echo "$__git_all_commandlist"
473 return
474 fi
475 local i IFS=" "$'\n'
476 for i in $(git help -a|egrep '^ ')
477 do
478 case $i in
479 *--*) : helper pattern;;
480 *) echo $i;;
481 esac
482 done
483}
484__git_all_commandlist=
485__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
486
487__git_porcelain_commands ()
488{
489 if [ -n "${__git_porcelain_commandlist-}" ]; then
490 echo "$__git_porcelain_commandlist"
491 return
492 fi
493 local i IFS=" "$'\n'
494 for i in "help" $(__git_all_commands)
495 do
496 case $i in
497 *--*) : helper pattern;;
498 applymbox) : ask gittus;;
499 applypatch) : ask gittus;;
500 archimport) : import;;
501 cat-file) : plumbing;;
502 check-attr) : plumbing;;
503 check-ref-format) : plumbing;;
504 checkout-index) : plumbing;;
505 commit-tree) : plumbing;;
506 count-objects) : infrequent;;
507 cvsexportcommit) : export;;
508 cvsimport) : import;;
509 cvsserver) : daemon;;
510 daemon) : daemon;;
511 diff-files) : plumbing;;
512 diff-index) : plumbing;;
513 diff-tree) : plumbing;;
514 fast-import) : import;;
515 fast-export) : export;;
516 fsck-objects) : plumbing;;
517 fetch-pack) : plumbing;;
518 fmt-merge-msg) : plumbing;;
519 for-each-ref) : plumbing;;
520 hash-object) : plumbing;;
521 http-*) : transport;;
522 index-pack) : plumbing;;
523 init-db) : deprecated;;
524 local-fetch) : plumbing;;
525 lost-found) : infrequent;;
526 ls-files) : plumbing;;
527 ls-remote) : plumbing;;
528 ls-tree) : plumbing;;
529 mailinfo) : plumbing;;
530 mailsplit) : plumbing;;
531 merge-*) : plumbing;;
532 mktree) : plumbing;;
533 mktag) : plumbing;;
534 pack-objects) : plumbing;;
535 pack-redundant) : plumbing;;
536 pack-refs) : plumbing;;
537 parse-remote) : plumbing;;
538 patch-id) : plumbing;;
539 peek-remote) : plumbing;;
540 prune) : plumbing;;
541 prune-packed) : plumbing;;
542 quiltimport) : import;;
543 read-tree) : plumbing;;
544 receive-pack) : plumbing;;
545 reflog) : plumbing;;
546 repo-config) : deprecated;;
547 rerere) : plumbing;;
548 rev-list) : plumbing;;
549 rev-parse) : plumbing;;
550 runstatus) : plumbing;;
551 sh-setup) : internal;;
552 shell) : daemon;;
553 show-ref) : plumbing;;
554 send-pack) : plumbing;;
555 show-index) : plumbing;;
556 ssh-*) : transport;;
557 stripspace) : plumbing;;
558 symbolic-ref) : plumbing;;
559 tar-tree) : deprecated;;
560 unpack-file) : plumbing;;
561 unpack-objects) : plumbing;;
562 update-index) : plumbing;;
563 update-ref) : plumbing;;
564 update-server-info) : daemon;;
565 upload-archive) : plumbing;;
566 upload-pack) : plumbing;;
567 write-tree) : plumbing;;
568 var) : infrequent;;
569 verify-pack) : infrequent;;
570 verify-tag) : plumbing;;
571 *) echo $i;;
572 esac
573 done
574}
575__git_porcelain_commandlist=
576__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
577
578__git_aliases ()
579{
580 local i IFS=$'\n'
581 for i in $(git --git-dir="$(__gitdir)" config --list); do
582 case "$i" in
583 alias.*)
584 i="${i#alias.}"
585 echo "${i/=*/}"
586 ;;
587 esac
588 done
589}
590
591# __git_aliased_command requires 1 argument
592__git_aliased_command ()
593{
594 local word cmdline=$(git --git-dir="$(__gitdir)" \
595 config --get "alias.$1")
596 for word in $cmdline; do
597 if [ "${word##-*}" ]; then
598 echo $word
599 return
600 fi
601 done
602}
603
604# __git_find_subcommand requires 1 argument
605__git_find_subcommand ()
606{
607 local word subcommand c=1
608
609 while [ $c -lt $COMP_CWORD ]; do
610 word="${COMP_WORDS[c]}"
611 for subcommand in $1; do
612 if [ "$subcommand" = "$word" ]; then
613 echo "$subcommand"
614 return
615 fi
616 done
617 c=$((++c))
618 done
619}
620
621__git_has_doubledash ()
622{
623 local c=1
624 while [ $c -lt $COMP_CWORD ]; do
625 if [ "--" = "${COMP_WORDS[c]}" ]; then
626 return 0
627 fi
628 c=$((++c))
629 done
630 return 1
631}
632
633__git_whitespacelist="nowarn warn error error-all fix"
634
635_git_am ()
636{
637 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
638 if [ -d "$dir"/rebase-apply ]; then
639 __gitcomp "--skip --resolved --abort"
640 return
641 fi
642 case "$cur" in
643 --whitespace=*)
644 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
645 return
646 ;;
647 --*)
648 __gitcomp "
649 --3way --committer-date-is-author-date --ignore-date
650 --interactive --keep --no-utf8 --signoff --utf8
651 --whitespace=
652 "
653 return
654 esac
655 COMPREPLY=()
656}
657
658_git_apply ()
659{
660 local cur="${COMP_WORDS[COMP_CWORD]}"
661 case "$cur" in
662 --whitespace=*)
663 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
664 return
665 ;;
666 --*)
667 __gitcomp "
668 --stat --numstat --summary --check --index
669 --cached --index-info --reverse --reject --unidiff-zero
670 --apply --no-add --exclude=
671 --whitespace= --inaccurate-eof --verbose
672 "
673 return
674 esac
675 COMPREPLY=()
676}
677
678_git_add ()
679{
680 __git_has_doubledash && return
681
682 local cur="${COMP_WORDS[COMP_CWORD]}"
683 case "$cur" in
684 --*)
685 __gitcomp "
686 --interactive --refresh --patch --update --dry-run
687 --ignore-errors --intent-to-add
688 "
689 return
690 esac
691 COMPREPLY=()
692}
693
694_git_archive ()
695{
696 local cur="${COMP_WORDS[COMP_CWORD]}"
697 case "$cur" in
698 --format=*)
699 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
700 return
701 ;;
702 --remote=*)
703 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
704 return
705 ;;
706 --*)
707 __gitcomp "
708 --format= --list --verbose
709 --prefix= --remote= --exec=
710 "
711 return
712 ;;
713 esac
714 __git_complete_file
715}
716
717_git_bisect ()
718{
719 __git_has_doubledash && return
720
721 local subcommands="start bad good skip reset visualize replay log run"
722 local subcommand="$(__git_find_subcommand "$subcommands")"
723 if [ -z "$subcommand" ]; then
724 __gitcomp "$subcommands"
725 return
726 fi
727
728 case "$subcommand" in
729 bad|good|reset|skip)
730 __gitcomp "$(__git_refs)"
731 ;;
732 *)
733 COMPREPLY=()
734 ;;
735 esac
736}
737
738_git_branch ()
739{
740 local i c=1 only_local_ref="n" has_r="n"
741
742 while [ $c -lt $COMP_CWORD ]; do
743 i="${COMP_WORDS[c]}"
744 case "$i" in
745 -d|-m) only_local_ref="y" ;;
746 -r) has_r="y" ;;
747 esac
748 c=$((++c))
749 done
750
751 case "${COMP_WORDS[COMP_CWORD]}" in
752 --*)
753 __gitcomp "
754 --color --no-color --verbose --abbrev= --no-abbrev
755 --track --no-track --contains --merged --no-merged
756 "
757 ;;
758 *)
759 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
760 __gitcomp "$(__git_heads)"
761 else
762 __gitcomp "$(__git_refs)"
763 fi
764 ;;
765 esac
766}
767
768_git_bundle ()
769{
770 local cmd="${COMP_WORDS[2]}"
771 case "$COMP_CWORD" in
772 2)
773 __gitcomp "create list-heads verify unbundle"
774 ;;
775 3)
776 # looking for a file
777 ;;
778 *)
779 case "$cmd" in
780 create)
781 __git_complete_revlist
782 ;;
783 esac
784 ;;
785 esac
786}
787
788_git_checkout ()
789{
790 __git_has_doubledash && return
791
792 __gitcomp "$(__git_refs)"
793}
794
795_git_cherry ()
796{
797 __gitcomp "$(__git_refs)"
798}
799
800_git_cherry_pick ()
801{
802 local cur="${COMP_WORDS[COMP_CWORD]}"
803 case "$cur" in
804 --*)
805 __gitcomp "--edit --no-commit"
806 ;;
807 *)
808 __gitcomp "$(__git_refs)"
809 ;;
810 esac
811}
812
813_git_clean ()
814{
815 __git_has_doubledash && return
816
817 local cur="${COMP_WORDS[COMP_CWORD]}"
818 case "$cur" in
819 --*)
820 __gitcomp "--dry-run --quiet"
821 return
822 ;;
823 esac
824 COMPREPLY=()
825}
826
827_git_clone ()
828{
829 local cur="${COMP_WORDS[COMP_CWORD]}"
830 case "$cur" in
831 --*)
832 __gitcomp "
833 --local
834 --no-hardlinks
835 --shared
836 --reference
837 --quiet
838 --no-checkout
839 --bare
840 --mirror
841 --origin
842 --upload-pack
843 --template=
844 --depth
845 "
846 return
847 ;;
848 esac
849 COMPREPLY=()
850}
851
852_git_commit ()
853{
854 __git_has_doubledash && return
855
856 local cur="${COMP_WORDS[COMP_CWORD]}"
857 case "$cur" in
858 --*)
859 __gitcomp "
860 --all --author= --signoff --verify --no-verify
861 --edit --amend --include --only --interactive
862 "
863 return
864 esac
865 COMPREPLY=()
866}
867
868_git_describe ()
869{
870 local cur="${COMP_WORDS[COMP_CWORD]}"
871 case "$cur" in
872 --*)
873 __gitcomp "
874 --all --tags --contains --abbrev= --candidates=
875 --exact-match --debug --long --match --always
876 "
877 return
878 esac
879 __gitcomp "$(__git_refs)"
880}
881
882__git_diff_common_options="--stat --numstat --shortstat --summary
883 --patch-with-stat --name-only --name-status --color
884 --no-color --color-words --no-renames --check
885 --full-index --binary --abbrev --diff-filter=
886 --find-copies-harder
887 --text --ignore-space-at-eol --ignore-space-change
888 --ignore-all-space --exit-code --quiet --ext-diff
889 --no-ext-diff
890 --no-prefix --src-prefix= --dst-prefix=
891 --inter-hunk-context=
892 --patience
893 --raw
894"
895
896_git_diff ()
897{
898 __git_has_doubledash && return
899
900 local cur="${COMP_WORDS[COMP_CWORD]}"
901 case "$cur" in
902 --*)
903 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
904 --base --ours --theirs
905 $__git_diff_common_options
906 "
907 return
908 ;;
909 esac
910 __git_complete_file
911}
912
913__git_fetch_options="
914 --quiet --verbose --append --upload-pack --force --keep --depth=
915 --tags --no-tags
916"
917
918_git_fetch ()
919{
920 local cur="${COMP_WORDS[COMP_CWORD]}"
921 case "$cur" in
922 --*)
923 __gitcomp "$__git_fetch_options"
924 return
925 ;;
926 esac
927 __git_complete_remote_or_refspec
928}
929
930_git_format_patch ()
931{
932 local cur="${COMP_WORDS[COMP_CWORD]}"
933 case "$cur" in
934 --thread=*)
935 __gitcomp "
936 deep shallow
937 " "" "${cur##--thread=}"
938 return
939 ;;
940 --*)
941 __gitcomp "
942 --stdout --attach --no-attach --thread --thread=
943 --output-directory
944 --numbered --start-number
945 --numbered-files
946 --keep-subject
947 --signoff
948 --in-reply-to= --cc=
949 --full-index --binary
950 --not --all
951 --cover-letter
952 --no-prefix --src-prefix= --dst-prefix=
953 --inline --suffix= --ignore-if-in-upstream
954 --subject-prefix=
955 "
956 return
957 ;;
958 esac
959 __git_complete_revlist
960}
961
962_git_fsck ()
963{
964 local cur="${COMP_WORDS[COMP_CWORD]}"
965 case "$cur" in
966 --*)
967 __gitcomp "
968 --tags --root --unreachable --cache --no-reflogs --full
969 --strict --verbose --lost-found
970 "
971 return
972 ;;
973 esac
974 COMPREPLY=()
975}
976
977_git_gc ()
978{
979 local cur="${COMP_WORDS[COMP_CWORD]}"
980 case "$cur" in
981 --*)
982 __gitcomp "--prune --aggressive"
983 return
984 ;;
985 esac
986 COMPREPLY=()
987}
988
989_git_grep ()
990{
991 __git_has_doubledash && return
992
993 local cur="${COMP_WORDS[COMP_CWORD]}"
994 case "$cur" in
995 --*)
996 __gitcomp "
997 --cached
998 --text --ignore-case --word-regexp --invert-match
999 --full-name
1000 --extended-regexp --basic-regexp --fixed-strings
1001 --files-with-matches --name-only
1002 --files-without-match
1003 --count
1004 --and --or --not --all-match
1005 "
1006 return
1007 ;;
1008 esac
1009 COMPREPLY=()
1010}
1011
1012_git_help ()
1013{
1014 local cur="${COMP_WORDS[COMP_CWORD]}"
1015 case "$cur" in
1016 --*)
1017 __gitcomp "--all --info --man --web"
1018 return
1019 ;;
1020 esac
1021 __gitcomp "$(__git_all_commands)
1022 attributes cli core-tutorial cvs-migration
1023 diffcore gitk glossary hooks ignore modules
1024 repository-layout tutorial tutorial-2
1025 workflows
1026 "
1027}
1028
1029_git_init ()
1030{
1031 local cur="${COMP_WORDS[COMP_CWORD]}"
1032 case "$cur" in
1033 --shared=*)
1034 __gitcomp "
1035 false true umask group all world everybody
1036 " "" "${cur##--shared=}"
1037 return
1038 ;;
1039 --*)
1040 __gitcomp "--quiet --bare --template= --shared --shared="
1041 return
1042 ;;
1043 esac
1044 COMPREPLY=()
1045}
1046
1047_git_ls_files ()
1048{
1049 __git_has_doubledash && return
1050
1051 local cur="${COMP_WORDS[COMP_CWORD]}"
1052 case "$cur" in
1053 --*)
1054 __gitcomp "--cached --deleted --modified --others --ignored
1055 --stage --directory --no-empty-directory --unmerged
1056 --killed --exclude= --exclude-from=
1057 --exclude-per-directory= --exclude-standard
1058 --error-unmatch --with-tree= --full-name
1059 --abbrev --ignored --exclude-per-directory
1060 "
1061 return
1062 ;;
1063 esac
1064 COMPREPLY=()
1065}
1066
1067_git_ls_remote ()
1068{
1069 __gitcomp "$(__git_remotes)"
1070}
1071
1072_git_ls_tree ()
1073{
1074 __git_complete_file
1075}
1076
1077# Options that go well for log, shortlog and gitk
1078__git_log_common_options="
1079 --not --all
1080 --branches --tags --remotes
1081 --first-parent --no-merges
1082 --max-count=
1083 --max-age= --since= --after=
1084 --min-age= --until= --before=
1085"
1086# Options that go well for log and gitk (not shortlog)
1087__git_log_gitk_options="
1088 --dense --sparse --full-history
1089 --simplify-merges --simplify-by-decoration
1090 --left-right
1091"
1092# Options that go well for log and shortlog (not gitk)
1093__git_log_shortlog_options="
1094 --author= --committer= --grep=
1095 --all-match
1096"
1097
1098__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1099
1100_git_log ()
1101{
1102 __git_has_doubledash && return
1103
1104 local cur="${COMP_WORDS[COMP_CWORD]}"
1105 local g="$(git rev-parse --git-dir 2>/dev/null)"
1106 local merge=""
1107 if [ -f "$g/MERGE_HEAD" ]; then
1108 merge="--merge"
1109 fi
1110 case "$cur" in
1111 --pretty=*)
1112 __gitcomp "$__git_log_pretty_formats
1113 " "" "${cur##--pretty=}"
1114 return
1115 ;;
1116 --format=*)
1117 __gitcomp "$__git_log_pretty_formats
1118 " "" "${cur##--format=}"
1119 return
1120 ;;
1121 --date=*)
1122 __gitcomp "
1123 relative iso8601 rfc2822 short local default
1124 " "" "${cur##--date=}"
1125 return
1126 ;;
1127 --*)
1128 __gitcomp "
1129 $__git_log_common_options
1130 $__git_log_shortlog_options
1131 $__git_log_gitk_options
1132 --root --topo-order --date-order --reverse
1133 --follow
1134 --abbrev-commit --abbrev=
1135 --relative-date --date=
1136 --pretty= --format= --oneline
1137 --cherry-pick
1138 --graph
1139 --decorate
1140 --walk-reflogs
1141 --parents --children
1142 $merge
1143 $__git_diff_common_options
1144 --pickaxe-all --pickaxe-regex
1145 "
1146 return
1147 ;;
1148 esac
1149 __git_complete_revlist
1150}
1151
1152__git_merge_options="
1153 --no-commit --no-stat --log --no-log --squash --strategy
1154 --commit --stat --no-squash --ff --no-ff
1155"
1156
1157_git_merge ()
1158{
1159 __git_complete_strategy && return
1160
1161 local cur="${COMP_WORDS[COMP_CWORD]}"
1162 case "$cur" in
1163 --*)
1164 __gitcomp "$__git_merge_options"
1165 return
1166 esac
1167 __gitcomp "$(__git_refs)"
1168}
1169
1170_git_mergetool ()
1171{
1172 local cur="${COMP_WORDS[COMP_CWORD]}"
1173 case "$cur" in
1174 --tool=*)
1175 __gitcomp "
1176 kdiff3 tkdiff meld xxdiff emerge
1177 vimdiff gvimdiff ecmerge diffuse
1178 opendiff
1179 " "" "${cur##--tool=}"
1180 return
1181 ;;
1182 --*)
1183 __gitcomp "--tool="
1184 return
1185 ;;
1186 esac
1187 COMPREPLY=()
1188}
1189
1190_git_merge_base ()
1191{
1192 __gitcomp "$(__git_refs)"
1193}
1194
1195_git_mv ()
1196{
1197 local cur="${COMP_WORDS[COMP_CWORD]}"
1198 case "$cur" in
1199 --*)
1200 __gitcomp "--dry-run"
1201 return
1202 ;;
1203 esac
1204 COMPREPLY=()
1205}
1206
1207_git_name_rev ()
1208{
1209 __gitcomp "--tags --all --stdin"
1210}
1211
1212_git_pull ()
1213{
1214 __git_complete_strategy && return
1215
1216 local cur="${COMP_WORDS[COMP_CWORD]}"
1217 case "$cur" in
1218 --*)
1219 __gitcomp "
1220 --rebase --no-rebase
1221 $__git_merge_options
1222 $__git_fetch_options
1223 "
1224 return
1225 ;;
1226 esac
1227 __git_complete_remote_or_refspec
1228}
1229
1230_git_push ()
1231{
1232 local cur="${COMP_WORDS[COMP_CWORD]}"
1233 case "${COMP_WORDS[COMP_CWORD-1]}" in
1234 --repo)
1235 __gitcomp "$(__git_remotes)"
1236 return
1237 esac
1238 case "$cur" in
1239 --repo=*)
1240 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1241 return
1242 ;;
1243 --*)
1244 __gitcomp "
1245 --all --mirror --tags --dry-run --force --verbose
1246 --receive-pack= --repo=
1247 "
1248 return
1249 ;;
1250 esac
1251 __git_complete_remote_or_refspec
1252}
1253
1254_git_rebase ()
1255{
1256 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1257 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1258 __gitcomp "--continue --skip --abort"
1259 return
1260 fi
1261 __git_complete_strategy && return
1262 case "$cur" in
1263 --*)
1264 __gitcomp "--onto --merge --strategy --interactive"
1265 return
1266 esac
1267 __gitcomp "$(__git_refs)"
1268}
1269
1270_git_send_email ()
1271{
1272 local cur="${COMP_WORDS[COMP_CWORD]}"
1273 case "$cur" in
1274 --*)
1275 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1276 --compose --dry-run --envelope-sender --from --identity
1277 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1278 --no-suppress-from --no-thread --quiet
1279 --signed-off-by-cc --smtp-pass --smtp-server
1280 --smtp-server-port --smtp-ssl --smtp-user --subject
1281 --suppress-cc --suppress-from --thread --to
1282 --validate --no-validate"
1283 return
1284 ;;
1285 esac
1286 COMPREPLY=()
1287}
1288
1289_git_config ()
1290{
1291 local cur="${COMP_WORDS[COMP_CWORD]}"
1292 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1293 case "$prv" in
1294 branch.*.remote)
1295 __gitcomp "$(__git_remotes)"
1296 return
1297 ;;
1298 branch.*.merge)
1299 __gitcomp "$(__git_refs)"
1300 return
1301 ;;
1302 remote.*.fetch)
1303 local remote="${prv#remote.}"
1304 remote="${remote%.fetch}"
1305 __gitcomp "$(__git_refs_remotes "$remote")"
1306 return
1307 ;;
1308 remote.*.push)
1309 local remote="${prv#remote.}"
1310 remote="${remote%.push}"
1311 __gitcomp "$(git --git-dir="$(__gitdir)" \
1312 for-each-ref --format='%(refname):%(refname)' \
1313 refs/heads)"
1314 return
1315 ;;
1316 pull.twohead|pull.octopus)
1317 __gitcomp "$(__git_merge_strategies)"
1318 return
1319 ;;
1320 color.branch|color.diff|color.interactive|color.status|color.ui)
1321 __gitcomp "always never auto"
1322 return
1323 ;;
1324 color.pager)
1325 __gitcomp "false true"
1326 return
1327 ;;
1328 color.*.*)
1329 __gitcomp "
1330 normal black red green yellow blue magenta cyan white
1331 bold dim ul blink reverse
1332 "
1333 return
1334 ;;
1335 *.*)
1336 COMPREPLY=()
1337 return
1338 ;;
1339 esac
1340 case "$cur" in
1341 --*)
1342 __gitcomp "
1343 --global --system --file=
1344 --list --replace-all
1345 --get --get-all --get-regexp
1346 --add --unset --unset-all
1347 --remove-section --rename-section
1348 "
1349 return
1350 ;;
1351 branch.*.*)
1352 local pfx="${cur%.*}."
1353 cur="${cur##*.}"
1354 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1355 return
1356 ;;
1357 branch.*)
1358 local pfx="${cur%.*}."
1359 cur="${cur#*.}"
1360 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1361 return
1362 ;;
1363 remote.*.*)
1364 local pfx="${cur%.*}."
1365 cur="${cur##*.}"
1366 __gitcomp "
1367 url proxy fetch push mirror skipDefaultUpdate
1368 receivepack uploadpack tagopt
1369 " "$pfx" "$cur"
1370 return
1371 ;;
1372 remote.*)
1373 local pfx="${cur%.*}."
1374 cur="${cur#*.}"
1375 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1376 return
1377 ;;
1378 esac
1379 __gitcomp "
1380 apply.whitespace
1381 branch.autosetupmerge
1382 branch.autosetuprebase
1383 clean.requireForce
1384 color.branch
1385 color.branch.current
1386 color.branch.local
1387 color.branch.plain
1388 color.branch.remote
1389 color.diff
1390 color.diff.commit
1391 color.diff.frag
1392 color.diff.meta
1393 color.diff.new
1394 color.diff.old
1395 color.diff.plain
1396 color.diff.whitespace
1397 color.interactive
1398 color.interactive.header
1399 color.interactive.help
1400 color.interactive.prompt
1401 color.pager
1402 color.status
1403 color.status.added
1404 color.status.changed
1405 color.status.header
1406 color.status.nobranch
1407 color.status.untracked
1408 color.status.updated
1409 color.ui
1410 commit.template
1411 core.autocrlf
1412 core.bare
1413 core.compression
1414 core.deltaBaseCacheLimit
1415 core.editor
1416 core.excludesfile
1417 core.fileMode
1418 core.fsyncobjectfiles
1419 core.gitProxy
1420 core.ignoreCygwinFSTricks
1421 core.ignoreStat
1422 core.logAllRefUpdates
1423 core.loosecompression
1424 core.packedGitLimit
1425 core.packedGitWindowSize
1426 core.pager
1427 core.preferSymlinkRefs
1428 core.preloadindex
1429 core.quotepath
1430 core.repositoryFormatVersion
1431 core.safecrlf
1432 core.sharedRepository
1433 core.symlinks
1434 core.trustctime
1435 core.warnAmbiguousRefs
1436 core.whitespace
1437 core.worktree
1438 diff.autorefreshindex
1439 diff.external
1440 diff.mnemonicprefix
1441 diff.renameLimit
1442 diff.renameLimit.
1443 diff.renames
1444 fetch.unpackLimit
1445 format.headers
1446 format.numbered
1447 format.pretty
1448 format.suffix
1449 gc.aggressiveWindow
1450 gc.auto
1451 gc.autopacklimit
1452 gc.packrefs
1453 gc.pruneexpire
1454 gc.reflogexpire
1455 gc.reflogexpireunreachable
1456 gc.rerereresolved
1457 gc.rerereunresolved
1458 gitcvs.allbinary
1459 gitcvs.dbTableNamePrefix
1460 gitcvs.dbdriver
1461 gitcvs.dbname
1462 gitcvs.dbpass
1463 gitcvs.dbuser
1464 gitcvs.enabled
1465 gitcvs.logfile
1466 gitcvs.usecrlfattr
1467 gui.blamehistoryctx
1468 gui.commitmsgwidth
1469 gui.copyblamethreshold
1470 gui.diffcontext
1471 gui.encoding
1472 gui.fastcopyblame
1473 gui.matchtrackingbranch
1474 gui.newbranchtemplate
1475 gui.pruneduringfetch
1476 gui.spellingdictionary
1477 gui.trustmtime
1478 help.autocorrect
1479 help.browser
1480 help.format
1481 http.lowSpeedLimit
1482 http.lowSpeedTime
1483 http.maxRequests
1484 http.noEPSV
1485 http.proxy
1486 http.sslCAInfo
1487 http.sslCAPath
1488 http.sslCert
1489 http.sslKey
1490 http.sslVerify
1491 i18n.commitEncoding
1492 i18n.logOutputEncoding
1493 instaweb.browser
1494 instaweb.httpd
1495 instaweb.local
1496 instaweb.modulepath
1497 instaweb.port
1498 log.date
1499 log.showroot
1500 man.viewer
1501 merge.conflictstyle
1502 merge.log
1503 merge.renameLimit
1504 merge.stat
1505 merge.tool
1506 merge.verbosity
1507 mergetool.keepBackup
1508 pack.compression
1509 pack.deltaCacheLimit
1510 pack.deltaCacheSize
1511 pack.depth
1512 pack.indexVersion
1513 pack.packSizeLimit
1514 pack.threads
1515 pack.window
1516 pack.windowMemory
1517 pull.octopus
1518 pull.twohead
1519 receive.denyCurrentBranch
1520 receive.denyDeletes
1521 receive.denyNonFastForwards
1522 receive.fsckObjects
1523 receive.unpackLimit
1524 repack.usedeltabaseoffset
1525 rerere.autoupdate
1526 rerere.enabled
1527 showbranch.default
1528 status.relativePaths
1529 status.showUntrackedFiles
1530 tar.umask
1531 transfer.unpackLimit
1532 user.email
1533 user.name
1534 user.signingkey
1535 web.browser
1536 branch. remote.
1537 "
1538}
1539
1540_git_remote ()
1541{
1542 local subcommands="add rename rm show prune update set-head"
1543 local subcommand="$(__git_find_subcommand "$subcommands")"
1544 if [ -z "$subcommand" ]; then
1545 __gitcomp "$subcommands"
1546 return
1547 fi
1548
1549 case "$subcommand" in
1550 rename|rm|show|prune)
1551 __gitcomp "$(__git_remotes)"
1552 ;;
1553 update)
1554 local i c='' IFS=$'\n'
1555 for i in $(git --git-dir="$(__gitdir)" config --list); do
1556 case "$i" in
1557 remotes.*)
1558 i="${i#remotes.}"
1559 c="$c ${i/=*/}"
1560 ;;
1561 esac
1562 done
1563 __gitcomp "$c"
1564 ;;
1565 *)
1566 COMPREPLY=()
1567 ;;
1568 esac
1569}
1570
1571_git_reset ()
1572{
1573 __git_has_doubledash && return
1574
1575 local cur="${COMP_WORDS[COMP_CWORD]}"
1576 case "$cur" in
1577 --*)
1578 __gitcomp "--merge --mixed --hard --soft"
1579 return
1580 ;;
1581 esac
1582 __gitcomp "$(__git_refs)"
1583}
1584
1585_git_revert ()
1586{
1587 local cur="${COMP_WORDS[COMP_CWORD]}"
1588 case "$cur" in
1589 --*)
1590 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1591 return
1592 ;;
1593 esac
1594 __gitcomp "$(__git_refs)"
1595}
1596
1597_git_rm ()
1598{
1599 __git_has_doubledash && return
1600
1601 local cur="${COMP_WORDS[COMP_CWORD]}"
1602 case "$cur" in
1603 --*)
1604 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1605 return
1606 ;;
1607 esac
1608 COMPREPLY=()
1609}
1610
1611_git_shortlog ()
1612{
1613 __git_has_doubledash && return
1614
1615 local cur="${COMP_WORDS[COMP_CWORD]}"
1616 case "$cur" in
1617 --*)
1618 __gitcomp "
1619 $__git_log_common_options
1620 $__git_log_shortlog_options
1621 --numbered --summary
1622 "
1623 return
1624 ;;
1625 esac
1626 __git_complete_revlist
1627}
1628
1629_git_show ()
1630{
1631 __git_has_doubledash && return
1632
1633 local cur="${COMP_WORDS[COMP_CWORD]}"
1634 case "$cur" in
1635 --pretty=*)
1636 __gitcomp "$__git_log_pretty_formats
1637 " "" "${cur##--pretty=}"
1638 return
1639 ;;
1640 --format=*)
1641 __gitcomp "$__git_log_pretty_formats
1642 " "" "${cur##--format=}"
1643 return
1644 ;;
1645 --*)
1646 __gitcomp "--pretty= --format=
1647 $__git_diff_common_options
1648 "
1649 return
1650 ;;
1651 esac
1652 __git_complete_file
1653}
1654
1655_git_show_branch ()
1656{
1657 local cur="${COMP_WORDS[COMP_CWORD]}"
1658 case "$cur" in
1659 --*)
1660 __gitcomp "
1661 --all --remotes --topo-order --current --more=
1662 --list --independent --merge-base --no-name
1663 --sha1-name --topics --reflog
1664 "
1665 return
1666 ;;
1667 esac
1668 __git_complete_revlist
1669}
1670
1671_git_stash ()
1672{
1673 local subcommands='save list show apply clear drop pop create branch'
1674 local subcommand="$(__git_find_subcommand "$subcommands")"
1675 if [ -z "$subcommand" ]; then
1676 __gitcomp "$subcommands"
1677 else
1678 local cur="${COMP_WORDS[COMP_CWORD]}"
1679 case "$subcommand,$cur" in
1680 save,--*)
1681 __gitcomp "--keep-index"
1682 ;;
1683 apply,--*)
1684 __gitcomp "--index"
1685 ;;
1686 show,--*|drop,--*|pop,--*|branch,--*)
1687 COMPREPLY=()
1688 ;;
1689 show,*|apply,*|drop,*|pop,*|branch,*)
1690 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1691 | sed -n -e 's/:.*//p')"
1692 ;;
1693 *)
1694 COMPREPLY=()
1695 ;;
1696 esac
1697 fi
1698}
1699
1700_git_submodule ()
1701{
1702 __git_has_doubledash && return
1703
1704 local subcommands="add status init update summary foreach sync"
1705 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1706 local cur="${COMP_WORDS[COMP_CWORD]}"
1707 case "$cur" in
1708 --*)
1709 __gitcomp "--quiet --cached"
1710 ;;
1711 *)
1712 __gitcomp "$subcommands"
1713 ;;
1714 esac
1715 return
1716 fi
1717}
1718
1719_git_svn ()
1720{
1721 local subcommands="
1722 init fetch clone rebase dcommit log find-rev
1723 set-tree commit-diff info create-ignore propget
1724 proplist show-ignore show-externals branch tag blame
1725 migrate
1726 "
1727 local subcommand="$(__git_find_subcommand "$subcommands")"
1728 if [ -z "$subcommand" ]; then
1729 __gitcomp "$subcommands"
1730 else
1731 local remote_opts="--username= --config-dir= --no-auth-cache"
1732 local fc_opts="
1733 --follow-parent --authors-file= --repack=
1734 --no-metadata --use-svm-props --use-svnsync-props
1735 --log-window-size= --no-checkout --quiet
1736 --repack-flags --use-log-author --localtime
1737 --ignore-paths= $remote_opts
1738 "
1739 local init_opts="
1740 --template= --shared= --trunk= --tags=
1741 --branches= --stdlayout --minimize-url
1742 --no-metadata --use-svm-props --use-svnsync-props
1743 --rewrite-root= --prefix= --use-log-author
1744 --add-author-from $remote_opts
1745 "
1746 local cmt_opts="
1747 --edit --rmdir --find-copies-harder --copy-similarity=
1748 "
1749
1750 local cur="${COMP_WORDS[COMP_CWORD]}"
1751 case "$subcommand,$cur" in
1752 fetch,--*)
1753 __gitcomp "--revision= --fetch-all $fc_opts"
1754 ;;
1755 clone,--*)
1756 __gitcomp "--revision= $fc_opts $init_opts"
1757 ;;
1758 init,--*)
1759 __gitcomp "$init_opts"
1760 ;;
1761 dcommit,--*)
1762 __gitcomp "
1763 --merge --strategy= --verbose --dry-run
1764 --fetch-all --no-rebase --commit-url
1765 --revision $cmt_opts $fc_opts
1766 "
1767 ;;
1768 set-tree,--*)
1769 __gitcomp "--stdin $cmt_opts $fc_opts"
1770 ;;
1771 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1772 show-externals,--*)
1773 __gitcomp "--revision="
1774 ;;
1775 log,--*)
1776 __gitcomp "
1777 --limit= --revision= --verbose --incremental
1778 --oneline --show-commit --non-recursive
1779 --authors-file= --color
1780 "
1781 ;;
1782 rebase,--*)
1783 __gitcomp "
1784 --merge --verbose --strategy= --local
1785 --fetch-all --dry-run $fc_opts
1786 "
1787 ;;
1788 commit-diff,--*)
1789 __gitcomp "--message= --file= --revision= $cmt_opts"
1790 ;;
1791 info,--*)
1792 __gitcomp "--url"
1793 ;;
1794 branch,--*)
1795 __gitcomp "--dry-run --message --tag"
1796 ;;
1797 tag,--*)
1798 __gitcomp "--dry-run --message"
1799 ;;
1800 blame,--*)
1801 __gitcomp "--git-format"
1802 ;;
1803 migrate,--*)
1804 __gitcomp "
1805 --config-dir= --ignore-paths= --minimize
1806 --no-auth-cache --username=
1807 "
1808 ;;
1809 *)
1810 COMPREPLY=()
1811 ;;
1812 esac
1813 fi
1814}
1815
1816_git_tag ()
1817{
1818 local i c=1 f=0
1819 while [ $c -lt $COMP_CWORD ]; do
1820 i="${COMP_WORDS[c]}"
1821 case "$i" in
1822 -d|-v)
1823 __gitcomp "$(__git_tags)"
1824 return
1825 ;;
1826 -f)
1827 f=1
1828 ;;
1829 esac
1830 c=$((++c))
1831 done
1832
1833 case "${COMP_WORDS[COMP_CWORD-1]}" in
1834 -m|-F)
1835 COMPREPLY=()
1836 ;;
1837 -*|tag)
1838 if [ $f = 1 ]; then
1839 __gitcomp "$(__git_tags)"
1840 else
1841 COMPREPLY=()
1842 fi
1843 ;;
1844 *)
1845 __gitcomp "$(__git_refs)"
1846 ;;
1847 esac
1848}
1849
1850_git ()
1851{
1852 local i c=1 command __git_dir
1853
1854 while [ $c -lt $COMP_CWORD ]; do
1855 i="${COMP_WORDS[c]}"
1856 case "$i" in
1857 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1858 --bare) __git_dir="." ;;
1859 --version|-p|--paginate) ;;
1860 --help) command="help"; break ;;
1861 *) command="$i"; break ;;
1862 esac
1863 c=$((++c))
1864 done
1865
1866 if [ -z "$command" ]; then
1867 case "${COMP_WORDS[COMP_CWORD]}" in
1868 --*) __gitcomp "
1869 --paginate
1870 --no-pager
1871 --git-dir=
1872 --bare
1873 --version
1874 --exec-path
1875 --work-tree=
1876 --help
1877 "
1878 ;;
1879 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1880 esac
1881 return
1882 fi
1883
1884 local expansion=$(__git_aliased_command "$command")
1885 [ "$expansion" ] && command="$expansion"
1886
1887 case "$command" in
1888 am) _git_am ;;
1889 add) _git_add ;;
1890 apply) _git_apply ;;
1891 archive) _git_archive ;;
1892 bisect) _git_bisect ;;
1893 bundle) _git_bundle ;;
1894 branch) _git_branch ;;
1895 checkout) _git_checkout ;;
1896 cherry) _git_cherry ;;
1897 cherry-pick) _git_cherry_pick ;;
1898 clean) _git_clean ;;
1899 clone) _git_clone ;;
1900 commit) _git_commit ;;
1901 config) _git_config ;;
1902 describe) _git_describe ;;
1903 diff) _git_diff ;;
1904 fetch) _git_fetch ;;
1905 format-patch) _git_format_patch ;;
1906 fsck) _git_fsck ;;
1907 gc) _git_gc ;;
1908 grep) _git_grep ;;
1909 help) _git_help ;;
1910 init) _git_init ;;
1911 log) _git_log ;;
1912 ls-files) _git_ls_files ;;
1913 ls-remote) _git_ls_remote ;;
1914 ls-tree) _git_ls_tree ;;
1915 merge) _git_merge;;
1916 mergetool) _git_mergetool;;
1917 merge-base) _git_merge_base ;;
1918 mv) _git_mv ;;
1919 name-rev) _git_name_rev ;;
1920 pull) _git_pull ;;
1921 push) _git_push ;;
1922 rebase) _git_rebase ;;
1923 remote) _git_remote ;;
1924 reset) _git_reset ;;
1925 revert) _git_revert ;;
1926 rm) _git_rm ;;
1927 send-email) _git_send_email ;;
1928 shortlog) _git_shortlog ;;
1929 show) _git_show ;;
1930 show-branch) _git_show_branch ;;
1931 stash) _git_stash ;;
1932 stage) _git_add ;;
1933 submodule) _git_submodule ;;
1934 svn) _git_svn ;;
1935 tag) _git_tag ;;
1936 whatchanged) _git_log ;;
1937 *) COMPREPLY=() ;;
1938 esac
1939}
1940
1941_gitk ()
1942{
1943 __git_has_doubledash && return
1944
1945 local cur="${COMP_WORDS[COMP_CWORD]}"
1946 local g="$(__gitdir)"
1947 local merge=""
1948 if [ -f "$g/MERGE_HEAD" ]; then
1949 merge="--merge"
1950 fi
1951 case "$cur" in
1952 --*)
1953 __gitcomp "
1954 $__git_log_common_options
1955 $__git_log_gitk_options
1956 $merge
1957 "
1958 return
1959 ;;
1960 esac
1961 __git_complete_revlist
1962}
1963
1964complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
1965 || complete -o default -o nospace -F _git git
1966complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
1967 || complete -o default -o nospace -F _gitk gitk
1968
1969# The following are necessary only for Cygwin, and only are needed
1970# when the user has tab-completed the executable name and consequently
1971# included the '.exe' suffix.
1972#
1973if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1974complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
1975 || complete -o default -o nospace -F _git git.exe
1976fi