bash: fix misspelled 'git svn' option
[git.git] / contrib / completion / git-completion.bash
blob412d2c0dab8118689c37b8ecbe29c7c0b2a2575a
1 #!bash
3 # bash completion support for core Git.
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.
9 # The contained completion routines provide support for completing:
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
18 # To use these routines:
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
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.
30 # 4) Consider changing your PS1 to also show the current branch:
31 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
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.
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.
43 # To submit patches:
45 # *) Read Documentation/SubmittingPatches
46 # *) Send all patches to the current maintainer:
48 # "Shawn O. Pearce" <spearce@spearce.org>
50 # *) Always CC the Git mailing list:
52 # git@vger.kernel.org
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 ()
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
72 elif [ -d "$1/.git" ]; then
73 echo "$1/.git"
74 else
75 echo "$1"
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 ()
83 local g="$(git rev-parse --git-dir 2>/dev/null)"
84 if [ -n "$g" ]; then
85 local r
86 local b
87 if [ -d "$g/rebase-apply" ]
88 then
89 if test -f "$g/rebase-apply/rebasing"
90 then
91 r="|REBASE"
92 elif test -f "$g/rebase-apply/applying"
93 then
94 r="|AM"
95 else
96 r="|AM/REBASE"
98 b="$(git symbolic-ref HEAD 2>/dev/null)"
99 elif [ -f "$g/rebase-merge/interactive" ]
100 then
101 r="|REBASE-i"
102 b="$(cat "$g/rebase-merge/head-name")"
103 elif [ -d "$g/rebase-merge" ]
104 then
105 r="|REBASE-m"
106 b="$(cat "$g/rebase-merge/head-name")"
107 elif [ -f "$g/MERGE_HEAD" ]
108 then
109 r="|MERGING"
110 b="$(git symbolic-ref HEAD 2>/dev/null)"
111 else
112 if [ -f "$g/BISECT_LOG" ]
113 then
114 r="|BISECTING"
116 if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
117 then
118 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
119 then
120 b="$(cut -c1-7 "$g/HEAD")..."
125 local w
126 local i
128 if test -n "${GIT_PS1_SHOWDIRTYSTATE-}"; then
129 if test "$(git config --bool bash.showDirtyState)" != "false"; then
130 git diff --no-ext-diff --ignore-submodules \
131 --quiet --exit-code || w="*"
132 if git rev-parse --quiet --verify HEAD >/dev/null; then
133 git diff-index --cached --quiet \
134 --ignore-submodules HEAD -- || i="+"
135 else
136 i="#"
141 if [ -n "${1-}" ]; then
142 printf "$1" "${b##refs/heads/}$w$i$r"
143 else
144 printf " (%s)" "${b##refs/heads/}$w$i$r"
149 # __gitcomp_1 requires 2 arguments
150 __gitcomp_1 ()
152 local c IFS=' '$'\t'$'\n'
153 for c in $1; do
154 case "$c$2" in
155 --*=*) printf %s$'\n' "$c$2" ;;
156 *.) printf %s$'\n' "$c$2" ;;
157 *) printf %s$'\n' "$c$2 " ;;
158 esac
159 done
162 # __gitcomp accepts 1, 2, 3, or 4 arguments
163 # generates completion reply with compgen
164 __gitcomp ()
166 local cur="${COMP_WORDS[COMP_CWORD]}"
167 if [ $# -gt 2 ]; then
168 cur="$3"
170 case "$cur" in
171 --*=)
172 COMPREPLY=()
175 local IFS=$'\n'
176 COMPREPLY=($(compgen -P "${2-}" \
177 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
178 -- "$cur"))
180 esac
183 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
184 __git_heads ()
186 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
187 if [ -d "$dir" ]; then
188 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
189 refs/heads
190 return
192 for i in $(git ls-remote "${1-}" 2>/dev/null); do
193 case "$is_hash,$i" in
194 y,*) is_hash=n ;;
195 n,*^{}) is_hash=y ;;
196 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
197 n,*) is_hash=y; echo "$i" ;;
198 esac
199 done
202 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
203 __git_tags ()
205 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
206 if [ -d "$dir" ]; then
207 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
208 refs/tags
209 return
211 for i in $(git ls-remote "${1-}" 2>/dev/null); do
212 case "$is_hash,$i" in
213 y,*) is_hash=n ;;
214 n,*^{}) is_hash=y ;;
215 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
216 n,*) is_hash=y; echo "$i" ;;
217 esac
218 done
221 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
222 __git_refs ()
224 local i is_hash=y dir="$(__gitdir "${1-}")"
225 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
226 if [ -d "$dir" ]; then
227 case "$cur" in
228 refs|refs/*)
229 format="refname"
230 refs="${cur%/*}"
233 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
234 format="refname:short"
235 refs="refs/tags refs/heads refs/remotes"
237 esac
238 git --git-dir="$dir" for-each-ref --format="%($format)" \
239 $refs
240 return
242 for i in $(git ls-remote "$dir" 2>/dev/null); do
243 case "$is_hash,$i" in
244 y,*) is_hash=n ;;
245 n,*^{}) is_hash=y ;;
246 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
247 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
248 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
249 n,*) is_hash=y; echo "$i" ;;
250 esac
251 done
254 # __git_refs2 requires 1 argument (to pass to __git_refs)
255 __git_refs2 ()
257 local i
258 for i in $(__git_refs "$1"); do
259 echo "$i:$i"
260 done
263 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
264 __git_refs_remotes ()
266 local cmd i is_hash=y
267 for i in $(git ls-remote "$1" 2>/dev/null); do
268 case "$is_hash,$i" in
269 n,refs/heads/*)
270 is_hash=y
271 echo "$i:refs/remotes/$1/${i#refs/heads/}"
273 y,*) is_hash=n ;;
274 n,*^{}) is_hash=y ;;
275 n,refs/tags/*) is_hash=y;;
276 n,*) is_hash=y; ;;
277 esac
278 done
281 __git_remotes ()
283 local i ngoff IFS=$'\n' d="$(__gitdir)"
284 shopt -q nullglob || ngoff=1
285 shopt -s nullglob
286 for i in "$d/remotes"/*; do
287 echo ${i#$d/remotes/}
288 done
289 [ "$ngoff" ] && shopt -u nullglob
290 for i in $(git --git-dir="$d" config --list); do
291 case "$i" in
292 remote.*.url=*)
293 i="${i#remote.}"
294 echo "${i/.url=*/}"
296 esac
297 done
300 __git_merge_strategies ()
302 if [ -n "$__git_merge_strategylist" ]; then
303 echo "$__git_merge_strategylist"
304 return
306 git merge -s help 2>&1 |
307 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
308 s/\.$//
309 s/.*://
310 s/^[ ]*//
311 s/[ ]*$//
315 __git_merge_strategylist=
316 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
318 __git_complete_file ()
320 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
321 case "$cur" in
322 ?*:*)
323 ref="${cur%%:*}"
324 cur="${cur#*:}"
325 case "$cur" in
326 ?*/*)
327 pfx="${cur%/*}"
328 cur="${cur##*/}"
329 ls="$ref:$pfx"
330 pfx="$pfx/"
333 ls="$ref"
335 esac
337 case "$COMP_WORDBREAKS" in
338 *:*) : great ;;
339 *) pfx="$ref:$pfx" ;;
340 esac
342 local IFS=$'\n'
343 COMPREPLY=($(compgen -P "$pfx" \
344 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
345 | sed '/^100... blob /{
346 s,^.* ,,
347 s,$, ,
349 /^120000 blob /{
350 s,^.* ,,
351 s,$, ,
353 /^040000 tree /{
354 s,^.* ,,
355 s,$,/,
357 s/^.* //')" \
358 -- "$cur"))
361 __gitcomp "$(__git_refs)"
363 esac
366 __git_complete_revlist ()
368 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
369 case "$cur" in
370 *...*)
371 pfx="${cur%...*}..."
372 cur="${cur#*...}"
373 __gitcomp "$(__git_refs)" "$pfx" "$cur"
375 *..*)
376 pfx="${cur%..*}.."
377 cur="${cur#*..}"
378 __gitcomp "$(__git_refs)" "$pfx" "$cur"
381 __gitcomp "$(__git_refs)"
383 esac
386 __git_all_commands ()
388 if [ -n "$__git_all_commandlist" ]; then
389 echo "$__git_all_commandlist"
390 return
392 local i IFS=" "$'\n'
393 for i in $(git help -a|egrep '^ ')
395 case $i in
396 *--*) : helper pattern;;
397 *) echo $i;;
398 esac
399 done
401 __git_all_commandlist=
402 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
404 __git_porcelain_commands ()
406 if [ -n "$__git_porcelain_commandlist" ]; then
407 echo "$__git_porcelain_commandlist"
408 return
410 local i IFS=" "$'\n'
411 for i in "help" $(__git_all_commands)
413 case $i in
414 *--*) : helper pattern;;
415 applymbox) : ask gittus;;
416 applypatch) : ask gittus;;
417 archimport) : import;;
418 cat-file) : plumbing;;
419 check-attr) : plumbing;;
420 check-ref-format) : plumbing;;
421 checkout-index) : plumbing;;
422 commit-tree) : plumbing;;
423 count-objects) : infrequent;;
424 cvsexportcommit) : export;;
425 cvsimport) : import;;
426 cvsserver) : daemon;;
427 daemon) : daemon;;
428 diff-files) : plumbing;;
429 diff-index) : plumbing;;
430 diff-tree) : plumbing;;
431 fast-import) : import;;
432 fast-export) : export;;
433 fsck-objects) : plumbing;;
434 fetch-pack) : plumbing;;
435 fmt-merge-msg) : plumbing;;
436 for-each-ref) : plumbing;;
437 hash-object) : plumbing;;
438 http-*) : transport;;
439 index-pack) : plumbing;;
440 init-db) : deprecated;;
441 local-fetch) : plumbing;;
442 lost-found) : infrequent;;
443 ls-files) : plumbing;;
444 ls-remote) : plumbing;;
445 ls-tree) : plumbing;;
446 mailinfo) : plumbing;;
447 mailsplit) : plumbing;;
448 merge-*) : plumbing;;
449 mktree) : plumbing;;
450 mktag) : plumbing;;
451 pack-objects) : plumbing;;
452 pack-redundant) : plumbing;;
453 pack-refs) : plumbing;;
454 parse-remote) : plumbing;;
455 patch-id) : plumbing;;
456 peek-remote) : plumbing;;
457 prune) : plumbing;;
458 prune-packed) : plumbing;;
459 quiltimport) : import;;
460 read-tree) : plumbing;;
461 receive-pack) : plumbing;;
462 reflog) : plumbing;;
463 repo-config) : deprecated;;
464 rerere) : plumbing;;
465 rev-list) : plumbing;;
466 rev-parse) : plumbing;;
467 runstatus) : plumbing;;
468 sh-setup) : internal;;
469 shell) : daemon;;
470 show-ref) : plumbing;;
471 send-pack) : plumbing;;
472 show-index) : plumbing;;
473 ssh-*) : transport;;
474 stripspace) : plumbing;;
475 symbolic-ref) : plumbing;;
476 tar-tree) : deprecated;;
477 unpack-file) : plumbing;;
478 unpack-objects) : plumbing;;
479 update-index) : plumbing;;
480 update-ref) : plumbing;;
481 update-server-info) : daemon;;
482 upload-archive) : plumbing;;
483 upload-pack) : plumbing;;
484 write-tree) : plumbing;;
485 var) : infrequent;;
486 verify-pack) : infrequent;;
487 verify-tag) : plumbing;;
488 *) echo $i;;
489 esac
490 done
492 __git_porcelain_commandlist=
493 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
495 __git_aliases ()
497 local i IFS=$'\n'
498 for i in $(git --git-dir="$(__gitdir)" config --list); do
499 case "$i" in
500 alias.*)
501 i="${i#alias.}"
502 echo "${i/=*/}"
504 esac
505 done
508 # __git_aliased_command requires 1 argument
509 __git_aliased_command ()
511 local word cmdline=$(git --git-dir="$(__gitdir)" \
512 config --get "alias.$1")
513 for word in $cmdline; do
514 if [ "${word##-*}" ]; then
515 echo $word
516 return
518 done
521 # __git_find_subcommand requires 1 argument
522 __git_find_subcommand ()
524 local word subcommand c=1
526 while [ $c -lt $COMP_CWORD ]; do
527 word="${COMP_WORDS[c]}"
528 for subcommand in $1; do
529 if [ "$subcommand" = "$word" ]; then
530 echo "$subcommand"
531 return
533 done
534 c=$((++c))
535 done
538 __git_has_doubledash ()
540 local c=1
541 while [ $c -lt $COMP_CWORD ]; do
542 if [ "--" = "${COMP_WORDS[c]}" ]; then
543 return 0
545 c=$((++c))
546 done
547 return 1
550 __git_whitespacelist="nowarn warn error error-all fix"
552 _git_am ()
554 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
555 if [ -d "$dir"/rebase-apply ]; then
556 __gitcomp "--skip --resolved --abort"
557 return
559 case "$cur" in
560 --whitespace=*)
561 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
562 return
564 --*)
565 __gitcomp "
566 --signoff --utf8 --binary --3way --interactive
567 --whitespace=
569 return
570 esac
571 COMPREPLY=()
574 _git_apply ()
576 local cur="${COMP_WORDS[COMP_CWORD]}"
577 case "$cur" in
578 --whitespace=*)
579 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
580 return
582 --*)
583 __gitcomp "
584 --stat --numstat --summary --check --index
585 --cached --index-info --reverse --reject --unidiff-zero
586 --apply --no-add --exclude=
587 --whitespace= --inaccurate-eof --verbose
589 return
590 esac
591 COMPREPLY=()
594 _git_add ()
596 __git_has_doubledash && return
598 local cur="${COMP_WORDS[COMP_CWORD]}"
599 case "$cur" in
600 --*)
601 __gitcomp "
602 --interactive --refresh --patch --update --dry-run
603 --ignore-errors --intent-to-add
605 return
606 esac
607 COMPREPLY=()
610 _git_archive ()
612 local cur="${COMP_WORDS[COMP_CWORD]}"
613 case "$cur" in
614 --format=*)
615 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
616 return
618 --remote=*)
619 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
620 return
622 --*)
623 __gitcomp "
624 --format= --list --verbose
625 --prefix= --remote= --exec=
627 return
629 esac
630 __git_complete_file
633 _git_bisect ()
635 __git_has_doubledash && return
637 local subcommands="start bad good skip reset visualize replay log run"
638 local subcommand="$(__git_find_subcommand "$subcommands")"
639 if [ -z "$subcommand" ]; then
640 __gitcomp "$subcommands"
641 return
644 case "$subcommand" in
645 bad|good|reset|skip)
646 __gitcomp "$(__git_refs)"
649 COMPREPLY=()
651 esac
654 _git_branch ()
656 local i c=1 only_local_ref="n" has_r="n"
658 while [ $c -lt $COMP_CWORD ]; do
659 i="${COMP_WORDS[c]}"
660 case "$i" in
661 -d|-m) only_local_ref="y" ;;
662 -r) has_r="y" ;;
663 esac
664 c=$((++c))
665 done
667 case "${COMP_WORDS[COMP_CWORD]}" in
668 --*)
669 __gitcomp "
670 --color --no-color --verbose --abbrev= --no-abbrev
671 --track --no-track --contains --merged --no-merged
675 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
676 __gitcomp "$(__git_heads)"
677 else
678 __gitcomp "$(__git_refs)"
681 esac
684 _git_bundle ()
686 local cmd="${COMP_WORDS[2]}"
687 case "$COMP_CWORD" in
689 __gitcomp "create list-heads verify unbundle"
692 # looking for a file
695 case "$cmd" in
696 create)
697 __git_complete_revlist
699 esac
701 esac
704 _git_checkout ()
706 __git_has_doubledash && return
708 __gitcomp "$(__git_refs)"
711 _git_cherry ()
713 __gitcomp "$(__git_refs)"
716 _git_cherry_pick ()
718 local cur="${COMP_WORDS[COMP_CWORD]}"
719 case "$cur" in
720 --*)
721 __gitcomp "--edit --no-commit"
724 __gitcomp "$(__git_refs)"
726 esac
729 _git_clean ()
731 __git_has_doubledash && return
733 local cur="${COMP_WORDS[COMP_CWORD]}"
734 case "$cur" in
735 --*)
736 __gitcomp "--dry-run --quiet"
737 return
739 esac
740 COMPREPLY=()
743 _git_clone ()
745 local cur="${COMP_WORDS[COMP_CWORD]}"
746 case "$cur" in
747 --*)
748 __gitcomp "
749 --local
750 --no-hardlinks
751 --shared
752 --reference
753 --quiet
754 --no-checkout
755 --bare
756 --mirror
757 --origin
758 --upload-pack
759 --template=
760 --depth
762 return
764 esac
765 COMPREPLY=()
768 _git_commit ()
770 __git_has_doubledash && return
772 local cur="${COMP_WORDS[COMP_CWORD]}"
773 case "$cur" in
774 --*)
775 __gitcomp "
776 --all --author= --signoff --verify --no-verify
777 --edit --amend --include --only --interactive
779 return
780 esac
781 COMPREPLY=()
784 _git_describe ()
786 local cur="${COMP_WORDS[COMP_CWORD]}"
787 case "$cur" in
788 --*)
789 __gitcomp "
790 --all --tags --contains --abbrev= --candidates=
791 --exact-match --debug --long --match --always
793 return
794 esac
795 __gitcomp "$(__git_refs)"
798 __git_diff_common_options="--stat --numstat --shortstat --summary
799 --patch-with-stat --name-only --name-status --color
800 --no-color --color-words --no-renames --check
801 --full-index --binary --abbrev --diff-filter=
802 --find-copies-harder
803 --text --ignore-space-at-eol --ignore-space-change
804 --ignore-all-space --exit-code --quiet --ext-diff
805 --no-ext-diff
806 --no-prefix --src-prefix= --dst-prefix=
807 --inter-hunk-context=
808 --patience
809 --raw
812 _git_diff ()
814 __git_has_doubledash && return
816 local cur="${COMP_WORDS[COMP_CWORD]}"
817 case "$cur" in
818 --*)
819 __gitcomp "--cached --pickaxe-all --pickaxe-regex
820 --base --ours --theirs
821 $__git_diff_common_options
823 return
825 esac
826 __git_complete_file
829 _git_fetch ()
831 local cur="${COMP_WORDS[COMP_CWORD]}"
833 if [ "$COMP_CWORD" = 2 ]; then
834 __gitcomp "$(__git_remotes)"
835 else
836 case "$cur" in
837 *:*)
838 local pfx=""
839 case "$COMP_WORDBREAKS" in
840 *:*) : great ;;
841 *) pfx="${cur%%:*}:" ;;
842 esac
843 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
846 __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
848 esac
852 _git_format_patch ()
854 local cur="${COMP_WORDS[COMP_CWORD]}"
855 case "$cur" in
856 --*)
857 __gitcomp "
858 --stdout --attach --thread
859 --output-directory
860 --numbered --start-number
861 --numbered-files
862 --keep-subject
863 --signoff
864 --in-reply-to=
865 --full-index --binary
866 --not --all
867 --cover-letter
868 --no-prefix --src-prefix= --dst-prefix=
869 --inline --suffix= --ignore-if-in-upstream
870 --subject-prefix=
872 return
874 esac
875 __git_complete_revlist
878 _git_gc ()
880 local cur="${COMP_WORDS[COMP_CWORD]}"
881 case "$cur" in
882 --*)
883 __gitcomp "--prune --aggressive"
884 return
886 esac
887 COMPREPLY=()
890 _git_grep ()
892 __git_has_doubledash && return
894 local cur="${COMP_WORDS[COMP_CWORD]}"
895 case "$cur" in
896 --*)
897 __gitcomp "
898 --cached
899 --text --ignore-case --word-regexp --invert-match
900 --full-name
901 --extended-regexp --basic-regexp --fixed-strings
902 --files-with-matches --name-only
903 --files-without-match
904 --count
905 --and --or --not --all-match
907 return
909 esac
910 COMPREPLY=()
913 _git_help ()
915 local cur="${COMP_WORDS[COMP_CWORD]}"
916 case "$cur" in
917 --*)
918 __gitcomp "--all --info --man --web"
919 return
921 esac
922 __gitcomp "$(__git_all_commands)
923 attributes cli core-tutorial cvs-migration
924 diffcore gitk glossary hooks ignore modules
925 repository-layout tutorial tutorial-2
926 workflows
930 _git_init ()
932 local cur="${COMP_WORDS[COMP_CWORD]}"
933 case "$cur" in
934 --shared=*)
935 __gitcomp "
936 false true umask group all world everybody
937 " "" "${cur##--shared=}"
938 return
940 --*)
941 __gitcomp "--quiet --bare --template= --shared --shared="
942 return
944 esac
945 COMPREPLY=()
948 _git_ls_files ()
950 __git_has_doubledash && return
952 local cur="${COMP_WORDS[COMP_CWORD]}"
953 case "$cur" in
954 --*)
955 __gitcomp "--cached --deleted --modified --others --ignored
956 --stage --directory --no-empty-directory --unmerged
957 --killed --exclude= --exclude-from=
958 --exclude-per-directory= --exclude-standard
959 --error-unmatch --with-tree= --full-name
960 --abbrev --ignored --exclude-per-directory
962 return
964 esac
965 COMPREPLY=()
968 _git_ls_remote ()
970 __gitcomp "$(__git_remotes)"
973 _git_ls_tree ()
975 __git_complete_file
978 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
980 _git_log ()
982 __git_has_doubledash && return
984 local cur="${COMP_WORDS[COMP_CWORD]}"
985 case "$cur" in
986 --pretty=*)
987 __gitcomp "$__git_log_pretty_formats
988 " "" "${cur##--pretty=}"
989 return
991 --date=*)
992 __gitcomp "
993 relative iso8601 rfc2822 short local default
994 " "" "${cur##--date=}"
995 return
997 --*)
998 __gitcomp "
999 --max-count= --max-age= --since= --after=
1000 --min-age= --before= --until=
1001 --root --topo-order --date-order --reverse
1002 --no-merges --follow
1003 --abbrev-commit --abbrev=
1004 --relative-date --date=
1005 --author= --committer= --grep=
1006 --all-match
1007 --pretty=
1008 --not --all
1009 --left-right --cherry-pick
1010 --graph
1011 --decorate
1012 --walk-reflogs
1013 --parents --children --full-history
1014 --merge
1015 $__git_diff_common_options
1016 --pickaxe-all --pickaxe-regex
1018 return
1020 esac
1021 __git_complete_revlist
1024 _git_merge ()
1026 local cur="${COMP_WORDS[COMP_CWORD]}"
1027 case "${COMP_WORDS[COMP_CWORD-1]}" in
1028 -s|--strategy)
1029 __gitcomp "$(__git_merge_strategies)"
1030 return
1031 esac
1032 case "$cur" in
1033 --strategy=*)
1034 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1035 return
1037 --*)
1038 __gitcomp "
1039 --no-commit --no-stat --log --no-log --squash --strategy
1041 return
1042 esac
1043 __gitcomp "$(__git_refs)"
1046 _git_mergetool ()
1048 local cur="${COMP_WORDS[COMP_CWORD]}"
1049 case "$cur" in
1050 --tool=*)
1051 __gitcomp "
1052 kdiff3 tkdiff meld xxdiff emerge
1053 vimdiff gvimdiff ecmerge opendiff
1054 " "" "${cur##--tool=}"
1055 return
1057 --*)
1058 __gitcomp "--tool="
1059 return
1061 esac
1062 COMPREPLY=()
1065 _git_merge_base ()
1067 __gitcomp "$(__git_refs)"
1070 _git_mv ()
1072 local cur="${COMP_WORDS[COMP_CWORD]}"
1073 case "$cur" in
1074 --*)
1075 __gitcomp "--dry-run"
1076 return
1078 esac
1079 COMPREPLY=()
1082 _git_name_rev ()
1084 __gitcomp "--tags --all --stdin"
1087 _git_pull ()
1089 local cur="${COMP_WORDS[COMP_CWORD]}"
1091 if [ "$COMP_CWORD" = 2 ]; then
1092 __gitcomp "$(__git_remotes)"
1093 else
1094 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1098 _git_push ()
1100 local cur="${COMP_WORDS[COMP_CWORD]}"
1102 if [ "$COMP_CWORD" = 2 ]; then
1103 __gitcomp "$(__git_remotes)"
1104 else
1105 case "$cur" in
1106 *:*)
1107 local pfx=""
1108 case "$COMP_WORDBREAKS" in
1109 *:*) : great ;;
1110 *) pfx="${cur%%:*}:" ;;
1111 esac
1113 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1116 __gitcomp "$(__git_refs)" + "${cur#+}"
1119 __gitcomp "$(__git_refs)"
1121 esac
1125 _git_rebase ()
1127 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1128 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1129 __gitcomp "--continue --skip --abort"
1130 return
1132 case "${COMP_WORDS[COMP_CWORD-1]}" in
1133 -s|--strategy)
1134 __gitcomp "$(__git_merge_strategies)"
1135 return
1136 esac
1137 case "$cur" in
1138 --strategy=*)
1139 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1140 return
1142 --*)
1143 __gitcomp "--onto --merge --strategy --interactive"
1144 return
1145 esac
1146 __gitcomp "$(__git_refs)"
1149 _git_send_email ()
1151 local cur="${COMP_WORDS[COMP_CWORD]}"
1152 case "$cur" in
1153 --*)
1154 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1155 --dry-run --envelope-sender --from --identity
1156 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1157 --no-suppress-from --no-thread --quiet
1158 --signed-off-by-cc --smtp-pass --smtp-server
1159 --smtp-server-port --smtp-ssl --smtp-user --subject
1160 --suppress-cc --suppress-from --thread --to
1161 --validate --no-validate"
1162 return
1164 esac
1165 COMPREPLY=()
1168 _git_config ()
1170 local cur="${COMP_WORDS[COMP_CWORD]}"
1171 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1172 case "$prv" in
1173 branch.*.remote)
1174 __gitcomp "$(__git_remotes)"
1175 return
1177 branch.*.merge)
1178 __gitcomp "$(__git_refs)"
1179 return
1181 remote.*.fetch)
1182 local remote="${prv#remote.}"
1183 remote="${remote%.fetch}"
1184 __gitcomp "$(__git_refs_remotes "$remote")"
1185 return
1187 remote.*.push)
1188 local remote="${prv#remote.}"
1189 remote="${remote%.push}"
1190 __gitcomp "$(git --git-dir="$(__gitdir)" \
1191 for-each-ref --format='%(refname):%(refname)' \
1192 refs/heads)"
1193 return
1195 pull.twohead|pull.octopus)
1196 __gitcomp "$(__git_merge_strategies)"
1197 return
1199 color.branch|color.diff|color.interactive|color.status|color.ui)
1200 __gitcomp "always never auto"
1201 return
1203 color.pager)
1204 __gitcomp "false true"
1205 return
1207 color.*.*)
1208 __gitcomp "
1209 normal black red green yellow blue magenta cyan white
1210 bold dim ul blink reverse
1212 return
1214 *.*)
1215 COMPREPLY=()
1216 return
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
1228 return
1230 branch.*.*)
1231 local pfx="${cur%.*}."
1232 cur="${cur##*.}"
1233 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1234 return
1236 branch.*)
1237 local pfx="${cur%.*}."
1238 cur="${cur#*.}"
1239 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1240 return
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
1251 remote.*)
1252 local pfx="${cur%.*}."
1253 cur="${cur#*.}"
1254 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1255 return
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.
1419 _git_remote ()
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
1428 case "$subcommand" in
1429 rename|rm|show|prune)
1430 __gitcomp "$(__git_remotes)"
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/=*/}"
1440 esac
1441 done
1442 __gitcomp "$c"
1445 COMPREPLY=()
1447 esac
1450 _git_reset ()
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
1460 esac
1461 __gitcomp "$(__git_refs)"
1464 _git_revert ()
1466 local cur="${COMP_WORDS[COMP_CWORD]}"
1467 case "$cur" in
1468 --*)
1469 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1470 return
1472 esac
1473 __gitcomp "$(__git_refs)"
1476 _git_rm ()
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
1486 esac
1487 COMPREPLY=()
1490 _git_shortlog ()
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
1506 return
1508 esac
1509 __git_complete_revlist
1512 _git_show ()
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
1523 --*)
1524 __gitcomp "--pretty=
1525 $__git_diff_common_options
1527 return
1529 esac
1530 __git_complete_file
1533 _git_show_branch ()
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
1543 return
1545 esac
1546 __git_complete_revlist
1549 _git_stash ()
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"
1561 apply,--*)
1562 __gitcomp "--index"
1564 show,--*|drop,--*|pop,--*|branch,--*)
1565 COMPREPLY=()
1567 show,*|apply,*|drop,*|pop,*|branch,*)
1568 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1569 | sed -n -e 's/:.*//p')"
1572 COMPREPLY=()
1574 esac
1578 _git_submodule ()
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"
1590 __gitcomp "$subcommands"
1592 esac
1593 return
1597 _git_svn ()
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
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 --use-log-author --localtime $remote_opts
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
1621 local cmt_opts="
1622 --edit --rmdir --find-copies-harder --copy-similarity=
1625 local cur="${COMP_WORDS[COMP_CWORD]}"
1626 case "$subcommand,$cur" in
1627 fetch,--*)
1628 __gitcomp "--revision= --fetch-all $fc_opts"
1630 clone,--*)
1631 __gitcomp "--revision= $fc_opts $init_opts"
1633 init,--*)
1634 __gitcomp "$init_opts"
1636 dcommit,--*)
1637 __gitcomp "
1638 --merge --strategy= --verbose --dry-run
1639 --fetch-all --no-rebase $cmt_opts $fc_opts
1642 set-tree,--*)
1643 __gitcomp "--stdin $cmt_opts $fc_opts"
1645 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1646 show-externals,--*)
1647 __gitcomp "--revision="
1649 log,--*)
1650 __gitcomp "
1651 --limit= --revision= --verbose --incremental
1652 --oneline --show-commit --non-recursive
1653 --authors-file=
1656 rebase,--*)
1657 __gitcomp "
1658 --merge --verbose --strategy= --local
1659 --fetch-all $fc_opts
1662 commit-diff,--*)
1663 __gitcomp "--message= --file= --revision= $cmt_opts"
1665 info,--*)
1666 __gitcomp "--url"
1669 COMPREPLY=()
1671 esac
1675 _git_tag ()
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
1688 esac
1689 c=$((++c))
1690 done
1692 case "${COMP_WORDS[COMP_CWORD-1]}" in
1693 -m|-F)
1694 COMPREPLY=()
1696 -*|tag)
1697 if [ $f = 1 ]; then
1698 __gitcomp "$(__git_tags)"
1699 else
1700 COMPREPLY=()
1704 __gitcomp "$(__git_refs)"
1706 esac
1709 _git ()
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
1738 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1739 esac
1740 return
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
1799 _gitk ()
1801 __git_has_doubledash && return
1803 local cur="${COMP_WORDS[COMP_CWORD]}"
1804 local g="$(git rev-parse --git-dir 2>/dev/null)"
1805 local merge=""
1806 if [ -f $g/MERGE_HEAD ]; then
1807 merge="--merge"
1809 case "$cur" in
1810 --*)
1811 __gitcomp "--not --all $merge"
1812 return
1814 esac
1815 __git_complete_revlist
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.
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