Merge branch 'rs/diff-ihc'
[git/trast.git] / contrib / completion / git-completion.bash
blob8ec782dc54c9eb49873e38b75d925babe9a7746c
2 # bash completion support for core Git.
4 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
5 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
6 # Distributed under the GNU General Public License, version 2.0.
8 # The contained completion routines provide support for completing:
10 # *) local and remote branch names
11 # *) local and remote tag names
12 # *) .git/remotes file names
13 # *) git 'subcommands'
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) common --long-options
17 # To use these routines:
19 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
20 # 2) Added the following line to your .bashrc:
21 # source ~/.git-completion.sh
23 # 3) You may want to make sure the git executable is available
24 # in your PATH before this script is sourced, as some caching
25 # is performed while the script loads. If git isn't found
26 # at source time then all lookups will be done on demand,
27 # which may be slightly slower.
29 # 4) Consider changing your PS1 to also show the current branch:
30 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
32 # The argument to __git_ps1 will be displayed only if you
33 # are currently in a git repository. The %s token will be
34 # the name of the current branch.
36 # To submit patches:
38 # *) Read Documentation/SubmittingPatches
39 # *) Send all patches to the current maintainer:
41 # "Shawn O. Pearce" <spearce@spearce.org>
43 # *) Always CC the Git mailing list:
45 # git@vger.kernel.org
48 case "$COMP_WORDBREAKS" in
49 *:*) : great ;;
50 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
51 esac
53 __gitdir ()
55 if [ -z "$1" ]; then
56 if [ -n "$__git_dir" ]; then
57 echo "$__git_dir"
58 elif [ -d .git ]; then
59 echo .git
60 else
61 git rev-parse --git-dir 2>/dev/null
63 elif [ -d "$1/.git" ]; then
64 echo "$1/.git"
65 else
66 echo "$1"
70 __git_ps1 ()
72 local g="$(git rev-parse --git-dir 2>/dev/null)"
73 if [ -n "$g" ]; then
74 local r
75 local b
76 if [ -d "$g/rebase-apply" ]
77 then
78 if test -f "$g/rebase-apply/rebasing"
79 then
80 r="|REBASE"
81 elif test -f "$g/rebase-apply/applying"
82 then
83 r="|AM"
84 else
85 r="|AM/REBASE"
87 b="$(git symbolic-ref HEAD 2>/dev/null)"
88 elif [ -f "$g/rebase-merge/interactive" ]
89 then
90 r="|REBASE-i"
91 b="$(cat "$g/rebase-merge/head-name")"
92 elif [ -d "$g/rebase-merge" ]
93 then
94 r="|REBASE-m"
95 b="$(cat "$g/rebase-merge/head-name")"
96 elif [ -f "$g/MERGE_HEAD" ]
97 then
98 r="|MERGING"
99 b="$(git symbolic-ref HEAD 2>/dev/null)"
100 else
101 if [ -f "$g/BISECT_LOG" ]
102 then
103 r="|BISECTING"
105 if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
106 then
107 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
108 then
109 b="$(cut -c1-7 "$g/HEAD")..."
114 if [ -n "$1" ]; then
115 printf "$1" "${b##refs/heads/}$r"
116 else
117 printf " (%s)" "${b##refs/heads/}$r"
122 __gitcomp_1 ()
124 local c IFS=' '$'\t'$'\n'
125 for c in $1; do
126 case "$c$2" in
127 --*=*) printf %s$'\n' "$c$2" ;;
128 *.) printf %s$'\n' "$c$2" ;;
129 *) printf %s$'\n' "$c$2 " ;;
130 esac
131 done
134 __gitcomp ()
136 local cur="${COMP_WORDS[COMP_CWORD]}"
137 if [ $# -gt 2 ]; then
138 cur="$3"
140 case "$cur" in
141 --*=)
142 COMPREPLY=()
145 local IFS=$'\n'
146 COMPREPLY=($(compgen -P "$2" \
147 -W "$(__gitcomp_1 "$1" "$4")" \
148 -- "$cur"))
150 esac
153 __git_heads ()
155 local cmd i is_hash=y dir="$(__gitdir "$1")"
156 if [ -d "$dir" ]; then
157 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
158 refs/heads
159 return
161 for i in $(git ls-remote "$1" 2>/dev/null); do
162 case "$is_hash,$i" in
163 y,*) is_hash=n ;;
164 n,*^{}) is_hash=y ;;
165 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
166 n,*) is_hash=y; echo "$i" ;;
167 esac
168 done
171 __git_tags ()
173 local cmd i is_hash=y dir="$(__gitdir "$1")"
174 if [ -d "$dir" ]; then
175 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
176 refs/tags
177 return
179 for i in $(git ls-remote "$1" 2>/dev/null); do
180 case "$is_hash,$i" in
181 y,*) is_hash=n ;;
182 n,*^{}) is_hash=y ;;
183 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
184 n,*) is_hash=y; echo "$i" ;;
185 esac
186 done
189 __git_refs ()
191 local i is_hash=y dir="$(__gitdir "$1")"
192 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
193 if [ -d "$dir" ]; then
194 case "$cur" in
195 refs|refs/*)
196 format="refname"
197 refs="${cur%/*}"
200 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
201 format="refname:short"
202 refs="refs/tags refs/heads refs/remotes"
204 esac
205 git --git-dir="$dir" for-each-ref --format="%($format)" \
206 $refs
207 return
209 for i in $(git ls-remote "$dir" 2>/dev/null); do
210 case "$is_hash,$i" in
211 y,*) is_hash=n ;;
212 n,*^{}) is_hash=y ;;
213 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
214 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
215 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
216 n,*) is_hash=y; echo "$i" ;;
217 esac
218 done
221 __git_refs2 ()
223 local i
224 for i in $(__git_refs "$1"); do
225 echo "$i:$i"
226 done
229 __git_refs_remotes ()
231 local cmd i is_hash=y
232 for i in $(git ls-remote "$1" 2>/dev/null); do
233 case "$is_hash,$i" in
234 n,refs/heads/*)
235 is_hash=y
236 echo "$i:refs/remotes/$1/${i#refs/heads/}"
238 y,*) is_hash=n ;;
239 n,*^{}) is_hash=y ;;
240 n,refs/tags/*) is_hash=y;;
241 n,*) is_hash=y; ;;
242 esac
243 done
246 __git_remotes ()
248 local i ngoff IFS=$'\n' d="$(__gitdir)"
249 shopt -q nullglob || ngoff=1
250 shopt -s nullglob
251 for i in "$d/remotes"/*; do
252 echo ${i#$d/remotes/}
253 done
254 [ "$ngoff" ] && shopt -u nullglob
255 for i in $(git --git-dir="$d" config --list); do
256 case "$i" in
257 remote.*.url=*)
258 i="${i#remote.}"
259 echo "${i/.url=*/}"
261 esac
262 done
265 __git_merge_strategies ()
267 if [ -n "$__git_merge_strategylist" ]; then
268 echo "$__git_merge_strategylist"
269 return
271 git merge -s help 2>&1 |
272 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
273 s/\.$//
274 s/.*://
275 s/^[ ]*//
276 s/[ ]*$//
280 __git_merge_strategylist=
281 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
283 __git_complete_file ()
285 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
286 case "$cur" in
287 ?*:*)
288 ref="${cur%%:*}"
289 cur="${cur#*:}"
290 case "$cur" in
291 ?*/*)
292 pfx="${cur%/*}"
293 cur="${cur##*/}"
294 ls="$ref:$pfx"
295 pfx="$pfx/"
298 ls="$ref"
300 esac
302 case "$COMP_WORDBREAKS" in
303 *:*) : great ;;
304 *) pfx="$ref:$pfx" ;;
305 esac
307 local IFS=$'\n'
308 COMPREPLY=($(compgen -P "$pfx" \
309 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
310 | sed '/^100... blob /{
311 s,^.* ,,
312 s,$, ,
314 /^120000 blob /{
315 s,^.* ,,
316 s,$, ,
318 /^040000 tree /{
319 s,^.* ,,
320 s,$,/,
322 s/^.* //')" \
323 -- "$cur"))
326 __gitcomp "$(__git_refs)"
328 esac
331 __git_complete_revlist ()
333 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
334 case "$cur" in
335 *...*)
336 pfx="${cur%...*}..."
337 cur="${cur#*...}"
338 __gitcomp "$(__git_refs)" "$pfx" "$cur"
340 *..*)
341 pfx="${cur%..*}.."
342 cur="${cur#*..}"
343 __gitcomp "$(__git_refs)" "$pfx" "$cur"
346 __gitcomp "$(__git_refs)"
348 esac
351 __git_all_commands ()
353 if [ -n "$__git_all_commandlist" ]; then
354 echo "$__git_all_commandlist"
355 return
357 local i IFS=" "$'\n'
358 for i in $(git help -a|egrep '^ ')
360 case $i in
361 *--*) : helper pattern;;
362 *) echo $i;;
363 esac
364 done
366 __git_all_commandlist=
367 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
369 __git_porcelain_commands ()
371 if [ -n "$__git_porcelain_commandlist" ]; then
372 echo "$__git_porcelain_commandlist"
373 return
375 local i IFS=" "$'\n'
376 for i in "help" $(__git_all_commands)
378 case $i in
379 *--*) : helper pattern;;
380 applymbox) : ask gittus;;
381 applypatch) : ask gittus;;
382 archimport) : import;;
383 cat-file) : plumbing;;
384 check-attr) : plumbing;;
385 check-ref-format) : plumbing;;
386 checkout-index) : plumbing;;
387 commit-tree) : plumbing;;
388 count-objects) : infrequent;;
389 cvsexportcommit) : export;;
390 cvsimport) : import;;
391 cvsserver) : daemon;;
392 daemon) : daemon;;
393 diff-files) : plumbing;;
394 diff-index) : plumbing;;
395 diff-tree) : plumbing;;
396 fast-import) : import;;
397 fast-export) : export;;
398 fsck-objects) : plumbing;;
399 fetch-pack) : plumbing;;
400 fmt-merge-msg) : plumbing;;
401 for-each-ref) : plumbing;;
402 hash-object) : plumbing;;
403 http-*) : transport;;
404 index-pack) : plumbing;;
405 init-db) : deprecated;;
406 local-fetch) : plumbing;;
407 lost-found) : infrequent;;
408 ls-files) : plumbing;;
409 ls-remote) : plumbing;;
410 ls-tree) : plumbing;;
411 mailinfo) : plumbing;;
412 mailsplit) : plumbing;;
413 merge-*) : plumbing;;
414 mktree) : plumbing;;
415 mktag) : plumbing;;
416 pack-objects) : plumbing;;
417 pack-redundant) : plumbing;;
418 pack-refs) : plumbing;;
419 parse-remote) : plumbing;;
420 patch-id) : plumbing;;
421 peek-remote) : plumbing;;
422 prune) : plumbing;;
423 prune-packed) : plumbing;;
424 quiltimport) : import;;
425 read-tree) : plumbing;;
426 receive-pack) : plumbing;;
427 reflog) : plumbing;;
428 repo-config) : deprecated;;
429 rerere) : plumbing;;
430 rev-list) : plumbing;;
431 rev-parse) : plumbing;;
432 runstatus) : plumbing;;
433 sh-setup) : internal;;
434 shell) : daemon;;
435 show-ref) : plumbing;;
436 send-pack) : plumbing;;
437 show-index) : plumbing;;
438 ssh-*) : transport;;
439 stripspace) : plumbing;;
440 symbolic-ref) : plumbing;;
441 tar-tree) : deprecated;;
442 unpack-file) : plumbing;;
443 unpack-objects) : plumbing;;
444 update-index) : plumbing;;
445 update-ref) : plumbing;;
446 update-server-info) : daemon;;
447 upload-archive) : plumbing;;
448 upload-pack) : plumbing;;
449 write-tree) : plumbing;;
450 var) : infrequent;;
451 verify-pack) : infrequent;;
452 verify-tag) : plumbing;;
453 *) echo $i;;
454 esac
455 done
457 __git_porcelain_commandlist=
458 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
460 __git_aliases ()
462 local i IFS=$'\n'
463 for i in $(git --git-dir="$(__gitdir)" config --list); do
464 case "$i" in
465 alias.*)
466 i="${i#alias.}"
467 echo "${i/=*/}"
469 esac
470 done
473 __git_aliased_command ()
475 local word cmdline=$(git --git-dir="$(__gitdir)" \
476 config --get "alias.$1")
477 for word in $cmdline; do
478 if [ "${word##-*}" ]; then
479 echo $word
480 return
482 done
485 __git_find_subcommand ()
487 local word subcommand c=1
489 while [ $c -lt $COMP_CWORD ]; do
490 word="${COMP_WORDS[c]}"
491 for subcommand in $1; do
492 if [ "$subcommand" = "$word" ]; then
493 echo "$subcommand"
494 return
496 done
497 c=$((++c))
498 done
501 __git_has_doubledash ()
503 local c=1
504 while [ $c -lt $COMP_CWORD ]; do
505 if [ "--" = "${COMP_WORDS[c]}" ]; then
506 return 0
508 c=$((++c))
509 done
510 return 1
513 __git_whitespacelist="nowarn warn error error-all fix"
515 _git_am ()
517 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
518 if [ -d "$dir"/rebase-apply ]; then
519 __gitcomp "--skip --resolved --abort"
520 return
522 case "$cur" in
523 --whitespace=*)
524 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
525 return
527 --*)
528 __gitcomp "
529 --signoff --utf8 --binary --3way --interactive
530 --whitespace=
532 return
533 esac
534 COMPREPLY=()
537 _git_apply ()
539 local cur="${COMP_WORDS[COMP_CWORD]}"
540 case "$cur" in
541 --whitespace=*)
542 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
543 return
545 --*)
546 __gitcomp "
547 --stat --numstat --summary --check --index
548 --cached --index-info --reverse --reject --unidiff-zero
549 --apply --no-add --exclude=
550 --whitespace= --inaccurate-eof --verbose
552 return
553 esac
554 COMPREPLY=()
557 _git_add ()
559 __git_has_doubledash && return
561 local cur="${COMP_WORDS[COMP_CWORD]}"
562 case "$cur" in
563 --*)
564 __gitcomp "
565 --interactive --refresh --patch --update --dry-run
566 --ignore-errors
568 return
569 esac
570 COMPREPLY=()
573 _git_archive ()
575 local cur="${COMP_WORDS[COMP_CWORD]}"
576 case "$cur" in
577 --format=*)
578 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
579 return
581 --remote=*)
582 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
583 return
585 --*)
586 __gitcomp "
587 --format= --list --verbose
588 --prefix= --remote= --exec=
590 return
592 esac
593 __git_complete_file
596 _git_bisect ()
598 __git_has_doubledash && return
600 local subcommands="start bad good skip reset visualize replay log run"
601 local subcommand="$(__git_find_subcommand "$subcommands")"
602 if [ -z "$subcommand" ]; then
603 __gitcomp "$subcommands"
604 return
607 case "$subcommand" in
608 bad|good|reset|skip)
609 __gitcomp "$(__git_refs)"
612 COMPREPLY=()
614 esac
617 _git_branch ()
619 local i c=1 only_local_ref="n" has_r="n"
621 while [ $c -lt $COMP_CWORD ]; do
622 i="${COMP_WORDS[c]}"
623 case "$i" in
624 -d|-m) only_local_ref="y" ;;
625 -r) has_r="y" ;;
626 esac
627 c=$((++c))
628 done
630 case "${COMP_WORDS[COMP_CWORD]}" in
631 --*=*) COMPREPLY=() ;;
632 --*)
633 __gitcomp "
634 --color --no-color --verbose --abbrev= --no-abbrev
635 --track --no-track --contains --merged --no-merged
639 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
640 __gitcomp "$(__git_heads)"
641 else
642 __gitcomp "$(__git_refs)"
645 esac
648 _git_bundle ()
650 local cmd="${COMP_WORDS[2]}"
651 case "$COMP_CWORD" in
653 __gitcomp "create list-heads verify unbundle"
656 # looking for a file
659 case "$cmd" in
660 create)
661 __git_complete_revlist
663 esac
665 esac
668 _git_checkout ()
670 __git_has_doubledash && return
672 __gitcomp "$(__git_refs)"
675 _git_cherry ()
677 __gitcomp "$(__git_refs)"
680 _git_cherry_pick ()
682 local cur="${COMP_WORDS[COMP_CWORD]}"
683 case "$cur" in
684 --*)
685 __gitcomp "--edit --no-commit"
688 __gitcomp "$(__git_refs)"
690 esac
693 _git_clean ()
695 __git_has_doubledash && return
697 local cur="${COMP_WORDS[COMP_CWORD]}"
698 case "$cur" in
699 --*)
700 __gitcomp "--dry-run --quiet"
701 return
703 esac
704 COMPREPLY=()
707 _git_clone ()
709 local cur="${COMP_WORDS[COMP_CWORD]}"
710 case "$cur" in
711 --*)
712 __gitcomp "
713 --local
714 --no-hardlinks
715 --shared
716 --reference
717 --quiet
718 --no-checkout
719 --bare
720 --mirror
721 --origin
722 --upload-pack
723 --template=
724 --depth
726 return
728 esac
729 COMPREPLY=()
732 _git_commit ()
734 __git_has_doubledash && return
736 local cur="${COMP_WORDS[COMP_CWORD]}"
737 case "$cur" in
738 --*)
739 __gitcomp "
740 --all --author= --signoff --verify --no-verify
741 --edit --amend --include --only --interactive
743 return
744 esac
745 COMPREPLY=()
748 _git_describe ()
750 local cur="${COMP_WORDS[COMP_CWORD]}"
751 case "$cur" in
752 --*)
753 __gitcomp "
754 --all --tags --contains --abbrev= --candidates=
755 --exact-match --debug --long --match --always
757 return
758 esac
759 __gitcomp "$(__git_refs)"
762 _git_diff ()
764 __git_has_doubledash && return
766 local cur="${COMP_WORDS[COMP_CWORD]}"
767 case "$cur" in
768 --*)
769 __gitcomp "--cached --stat --numstat --shortstat --summary
770 --patch-with-stat --name-only --name-status --color
771 --no-color --color-words --no-renames --check
772 --full-index --binary --abbrev --diff-filter=
773 --find-copies-harder --pickaxe-all --pickaxe-regex
774 --text --ignore-space-at-eol --ignore-space-change
775 --ignore-all-space --exit-code --quiet --ext-diff
776 --no-ext-diff
777 --no-prefix --src-prefix= --dst-prefix=
778 --base --ours --theirs
779 --inter-hunk-context=
781 return
783 esac
784 __git_complete_file
787 _git_fetch ()
789 local cur="${COMP_WORDS[COMP_CWORD]}"
791 if [ "$COMP_CWORD" = 2 ]; then
792 __gitcomp "$(__git_remotes)"
793 else
794 case "$cur" in
795 *:*)
796 local pfx=""
797 case "$COMP_WORDBREAKS" in
798 *:*) : great ;;
799 *) pfx="${cur%%:*}:" ;;
800 esac
801 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
804 __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
806 esac
810 _git_format_patch ()
812 local cur="${COMP_WORDS[COMP_CWORD]}"
813 case "$cur" in
814 --*)
815 __gitcomp "
816 --stdout --attach --thread
817 --output-directory
818 --numbered --start-number
819 --numbered-files
820 --keep-subject
821 --signoff
822 --in-reply-to=
823 --full-index --binary
824 --not --all
825 --cover-letter
826 --no-prefix --src-prefix= --dst-prefix=
828 return
830 esac
831 __git_complete_revlist
834 _git_gc ()
836 local cur="${COMP_WORDS[COMP_CWORD]}"
837 case "$cur" in
838 --*)
839 __gitcomp "--prune --aggressive"
840 return
842 esac
843 COMPREPLY=()
846 _git_grep ()
848 __git_has_doubledash && return
850 local cur="${COMP_WORDS[COMP_CWORD]}"
851 case "$cur" in
852 --*)
853 __gitcomp "
854 --cached
855 --text --ignore-case --word-regexp --invert-match
856 --full-name
857 --extended-regexp --basic-regexp --fixed-strings
858 --files-with-matches --name-only
859 --files-without-match
860 --count
861 --and --or --not --all-match
863 return
865 esac
866 COMPREPLY=()
869 _git_help ()
871 local cur="${COMP_WORDS[COMP_CWORD]}"
872 case "$cur" in
873 --*)
874 __gitcomp "--all --info --man --web"
875 return
877 esac
878 __gitcomp "$(__git_all_commands)
879 attributes cli core-tutorial cvs-migration
880 diffcore gitk glossary hooks ignore modules
881 repository-layout tutorial tutorial-2
882 workflows
886 _git_init ()
888 local cur="${COMP_WORDS[COMP_CWORD]}"
889 case "$cur" in
890 --shared=*)
891 __gitcomp "
892 false true umask group all world everybody
893 " "" "${cur##--shared=}"
894 return
896 --*)
897 __gitcomp "--quiet --bare --template= --shared --shared="
898 return
900 esac
901 COMPREPLY=()
904 _git_ls_files ()
906 __git_has_doubledash && return
908 local cur="${COMP_WORDS[COMP_CWORD]}"
909 case "$cur" in
910 --*)
911 __gitcomp "--cached --deleted --modified --others --ignored
912 --stage --directory --no-empty-directory --unmerged
913 --killed --exclude= --exclude-from=
914 --exclude-per-directory= --exclude-standard
915 --error-unmatch --with-tree= --full-name
916 --abbrev --ignored --exclude-per-directory
918 return
920 esac
921 COMPREPLY=()
924 _git_ls_remote ()
926 __gitcomp "$(__git_remotes)"
929 _git_ls_tree ()
931 __git_complete_file
934 _git_log ()
936 __git_has_doubledash && return
938 local cur="${COMP_WORDS[COMP_CWORD]}"
939 case "$cur" in
940 --pretty=*)
941 __gitcomp "
942 oneline short medium full fuller email raw
943 " "" "${cur##--pretty=}"
944 return
946 --date=*)
947 __gitcomp "
948 relative iso8601 rfc2822 short local default
949 " "" "${cur##--date=}"
950 return
952 --*)
953 __gitcomp "
954 --max-count= --max-age= --since= --after=
955 --min-age= --before= --until=
956 --root --topo-order --date-order --reverse
957 --no-merges --follow
958 --abbrev-commit --abbrev=
959 --relative-date --date=
960 --author= --committer= --grep=
961 --all-match
962 --pretty= --name-status --name-only --raw
963 --not --all
964 --left-right --cherry-pick
965 --graph
966 --stat --numstat --shortstat
967 --decorate --diff-filter=
968 --color-words --walk-reflogs
969 --parents --children --full-history
970 --merge
971 --inter-hunk-context=
973 return
975 esac
976 __git_complete_revlist
979 _git_merge ()
981 local cur="${COMP_WORDS[COMP_CWORD]}"
982 case "${COMP_WORDS[COMP_CWORD-1]}" in
983 -s|--strategy)
984 __gitcomp "$(__git_merge_strategies)"
985 return
986 esac
987 case "$cur" in
988 --strategy=*)
989 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
990 return
992 --*)
993 __gitcomp "
994 --no-commit --no-stat --log --no-log --squash --strategy
996 return
997 esac
998 __gitcomp "$(__git_refs)"
1001 _git_mergetool ()
1003 local cur="${COMP_WORDS[COMP_CWORD]}"
1004 case "$cur" in
1005 --tool=*)
1006 __gitcomp "
1007 kdiff3 tkdiff meld xxdiff emerge
1008 vimdiff gvimdiff ecmerge opendiff
1009 " "" "${cur##--tool=}"
1010 return
1012 --*)
1013 __gitcomp "--tool="
1014 return
1016 esac
1017 COMPREPLY=()
1020 _git_merge_base ()
1022 __gitcomp "$(__git_refs)"
1025 _git_mv ()
1027 local cur="${COMP_WORDS[COMP_CWORD]}"
1028 case "$cur" in
1029 --*)
1030 __gitcomp "--dry-run"
1031 return
1033 esac
1034 COMPREPLY=()
1037 _git_name_rev ()
1039 __gitcomp "--tags --all --stdin"
1042 _git_pull ()
1044 local cur="${COMP_WORDS[COMP_CWORD]}"
1046 if [ "$COMP_CWORD" = 2 ]; then
1047 __gitcomp "$(__git_remotes)"
1048 else
1049 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1053 _git_push ()
1055 local cur="${COMP_WORDS[COMP_CWORD]}"
1057 if [ "$COMP_CWORD" = 2 ]; then
1058 __gitcomp "$(__git_remotes)"
1059 else
1060 case "$cur" in
1061 *:*)
1062 local pfx=""
1063 case "$COMP_WORDBREAKS" in
1064 *:*) : great ;;
1065 *) pfx="${cur%%:*}:" ;;
1066 esac
1068 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1071 __gitcomp "$(__git_refs)" + "${cur#+}"
1074 __gitcomp "$(__git_refs)"
1076 esac
1080 _git_rebase ()
1082 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1083 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1084 __gitcomp "--continue --skip --abort"
1085 return
1087 case "${COMP_WORDS[COMP_CWORD-1]}" in
1088 -s|--strategy)
1089 __gitcomp "$(__git_merge_strategies)"
1090 return
1091 esac
1092 case "$cur" in
1093 --strategy=*)
1094 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1095 return
1097 --*)
1098 __gitcomp "--onto --merge --strategy --interactive"
1099 return
1100 esac
1101 __gitcomp "$(__git_refs)"
1104 _git_send_email ()
1106 local cur="${COMP_WORDS[COMP_CWORD]}"
1107 case "$cur" in
1108 --*)
1109 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1110 --dry-run --envelope-sender --from --identity
1111 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1112 --no-suppress-from --no-thread --quiet
1113 --signed-off-by-cc --smtp-pass --smtp-server
1114 --smtp-server-port --smtp-ssl --smtp-user --subject
1115 --suppress-cc --suppress-from --thread --to
1116 --validate --no-validate"
1117 return
1119 esac
1120 COMPREPLY=()
1123 _git_config ()
1125 local cur="${COMP_WORDS[COMP_CWORD]}"
1126 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1127 case "$prv" in
1128 branch.*.remote)
1129 __gitcomp "$(__git_remotes)"
1130 return
1132 branch.*.merge)
1133 __gitcomp "$(__git_refs)"
1134 return
1136 remote.*.fetch)
1137 local remote="${prv#remote.}"
1138 remote="${remote%.fetch}"
1139 __gitcomp "$(__git_refs_remotes "$remote")"
1140 return
1142 remote.*.push)
1143 local remote="${prv#remote.}"
1144 remote="${remote%.push}"
1145 __gitcomp "$(git --git-dir="$(__gitdir)" \
1146 for-each-ref --format='%(refname):%(refname)' \
1147 refs/heads)"
1148 return
1150 pull.twohead|pull.octopus)
1151 __gitcomp "$(__git_merge_strategies)"
1152 return
1154 color.branch|color.diff|color.status)
1155 __gitcomp "always never auto"
1156 return
1158 color.*.*)
1159 __gitcomp "
1160 normal black red green yellow blue magenta cyan white
1161 bold dim ul blink reverse
1163 return
1165 *.*)
1166 COMPREPLY=()
1167 return
1169 esac
1170 case "$cur" in
1171 --*)
1172 __gitcomp "
1173 --global --system --file=
1174 --list --replace-all
1175 --get --get-all --get-regexp
1176 --add --unset --unset-all
1177 --remove-section --rename-section
1179 return
1181 branch.*.*)
1182 local pfx="${cur%.*}."
1183 cur="${cur##*.}"
1184 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1185 return
1187 branch.*)
1188 local pfx="${cur%.*}."
1189 cur="${cur#*.}"
1190 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1191 return
1193 remote.*.*)
1194 local pfx="${cur%.*}."
1195 cur="${cur##*.}"
1196 __gitcomp "
1197 url proxy fetch push mirror skipDefaultUpdate
1198 receivepack uploadpack tagopt
1199 " "$pfx" "$cur"
1200 return
1202 remote.*)
1203 local pfx="${cur%.*}."
1204 cur="${cur#*.}"
1205 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1206 return
1208 esac
1209 __gitcomp "
1210 apply.whitespace
1211 branch.autosetupmerge
1212 branch.autosetuprebase
1213 clean.requireForce
1214 color.branch
1215 color.branch.current
1216 color.branch.local
1217 color.branch.plain
1218 color.branch.remote
1219 color.diff
1220 color.diff.commit
1221 color.diff.frag
1222 color.diff.meta
1223 color.diff.new
1224 color.diff.old
1225 color.diff.plain
1226 color.diff.whitespace
1227 color.interactive
1228 color.interactive.header
1229 color.interactive.help
1230 color.interactive.prompt
1231 color.pager
1232 color.status
1233 color.status.added
1234 color.status.changed
1235 color.status.header
1236 color.status.nobranch
1237 color.status.untracked
1238 color.status.updated
1239 color.ui
1240 commit.template
1241 core.autocrlf
1242 core.bare
1243 core.compression
1244 core.deltaBaseCacheLimit
1245 core.editor
1246 core.excludesfile
1247 core.fileMode
1248 core.fsyncobjectfiles
1249 core.gitProxy
1250 core.ignoreCygwinFSTricks
1251 core.ignoreStat
1252 core.logAllRefUpdates
1253 core.loosecompression
1254 core.packedGitLimit
1255 core.packedGitWindowSize
1256 core.pager
1257 core.preferSymlinkRefs
1258 core.preloadindex
1259 core.quotepath
1260 core.repositoryFormatVersion
1261 core.safecrlf
1262 core.sharedRepository
1263 core.symlinks
1264 core.trustctime
1265 core.warnAmbiguousRefs
1266 core.whitespace
1267 core.worktree
1268 diff.autorefreshindex
1269 diff.external
1270 diff.mnemonicprefix
1271 diff.renameLimit
1272 diff.renameLimit.
1273 diff.renames
1274 fetch.unpackLimit
1275 format.headers
1276 format.numbered
1277 format.pretty
1278 format.suffix
1279 gc.aggressiveWindow
1280 gc.auto
1281 gc.autopacklimit
1282 gc.packrefs
1283 gc.pruneexpire
1284 gc.reflogexpire
1285 gc.reflogexpireunreachable
1286 gc.rerereresolved
1287 gc.rerereunresolved
1288 gitcvs.allbinary
1289 gitcvs.dbTableNamePrefix
1290 gitcvs.dbdriver
1291 gitcvs.dbname
1292 gitcvs.dbpass
1293 gitcvs.dbuser
1294 gitcvs.enabled
1295 gitcvs.logfile
1296 gitcvs.usecrlfattr
1297 gui.blamehistoryctx
1298 gui.commitmsgwidth
1299 gui.copyblamethreshold
1300 gui.diffcontext
1301 gui.encoding
1302 gui.fastcopyblame
1303 gui.matchtrackingbranch
1304 gui.newbranchtemplate
1305 gui.pruneduringfetch
1306 gui.spellingdictionary
1307 gui.trustmtime
1308 help.autocorrect
1309 help.browser
1310 help.format
1311 http.lowSpeedLimit
1312 http.lowSpeedTime
1313 http.maxRequests
1314 http.noEPSV
1315 http.proxy
1316 http.sslCAInfo
1317 http.sslCAPath
1318 http.sslCert
1319 http.sslKey
1320 http.sslVerify
1321 i18n.commitEncoding
1322 i18n.logOutputEncoding
1323 instaweb.browser
1324 instaweb.httpd
1325 instaweb.local
1326 instaweb.modulepath
1327 instaweb.port
1328 log.date
1329 log.showroot
1330 man.viewer
1331 merge.conflictstyle
1332 merge.log
1333 merge.renameLimit
1334 merge.stat
1335 merge.tool
1336 merge.verbosity
1337 mergetool.keepBackup
1338 pack.compression
1339 pack.deltaCacheLimit
1340 pack.deltaCacheSize
1341 pack.depth
1342 pack.indexVersion
1343 pack.packSizeLimit
1344 pack.threads
1345 pack.window
1346 pack.windowMemory
1347 pull.octopus
1348 pull.twohead
1349 receive.denyCurrentBranch
1350 receive.denyDeletes
1351 receive.denyNonFastForwards
1352 receive.fsckObjects
1353 receive.unpackLimit
1354 repack.usedeltabaseoffset
1355 rerere.autoupdate
1356 rerere.enabled
1357 showbranch.default
1358 status.relativePaths
1359 status.showUntrackedFiles
1360 tar.umask
1361 transfer.unpackLimit
1362 user.email
1363 user.name
1364 user.signingkey
1365 web.browser
1366 branch. remote.
1370 _git_remote ()
1372 local subcommands="add rm show prune update"
1373 local subcommand="$(__git_find_subcommand "$subcommands")"
1374 if [ -z "$subcommand" ]; then
1375 __gitcomp "$subcommands"
1376 return
1379 case "$subcommand" in
1380 rm|show|prune)
1381 __gitcomp "$(__git_remotes)"
1383 update)
1384 local i c='' IFS=$'\n'
1385 for i in $(git --git-dir="$(__gitdir)" config --list); do
1386 case "$i" in
1387 remotes.*)
1388 i="${i#remotes.}"
1389 c="$c ${i/=*/}"
1391 esac
1392 done
1393 __gitcomp "$c"
1396 COMPREPLY=()
1398 esac
1401 _git_reset ()
1403 __git_has_doubledash && return
1405 local cur="${COMP_WORDS[COMP_CWORD]}"
1406 case "$cur" in
1407 --*)
1408 __gitcomp "--merge --mixed --hard --soft"
1409 return
1411 esac
1412 __gitcomp "$(__git_refs)"
1415 _git_revert ()
1417 local cur="${COMP_WORDS[COMP_CWORD]}"
1418 case "$cur" in
1419 --*)
1420 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1421 return
1423 esac
1424 __gitcomp "$(__git_refs)"
1427 _git_rm ()
1429 __git_has_doubledash && return
1431 local cur="${COMP_WORDS[COMP_CWORD]}"
1432 case "$cur" in
1433 --*)
1434 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1435 return
1437 esac
1438 COMPREPLY=()
1441 _git_shortlog ()
1443 __git_has_doubledash && return
1445 local cur="${COMP_WORDS[COMP_CWORD]}"
1446 case "$cur" in
1447 --*)
1448 __gitcomp "
1449 --max-count= --max-age= --since= --after=
1450 --min-age= --before= --until=
1451 --no-merges
1452 --author= --committer= --grep=
1453 --all-match
1454 --not --all
1455 --numbered --summary
1457 return
1459 esac
1460 __git_complete_revlist
1463 _git_show ()
1465 __git_has_doubledash && return
1467 local cur="${COMP_WORDS[COMP_CWORD]}"
1468 case "$cur" in
1469 --pretty=*)
1470 __gitcomp "
1471 oneline short medium full fuller email raw
1472 " "" "${cur##--pretty=}"
1473 return
1475 --*)
1476 __gitcomp "--pretty="
1477 return
1479 esac
1480 __git_complete_file
1483 _git_show_branch ()
1485 local cur="${COMP_WORDS[COMP_CWORD]}"
1486 case "$cur" in
1487 --*)
1488 __gitcomp "
1489 --all --remotes --topo-order --current --more=
1490 --list --independent --merge-base --no-name
1491 --sha1-name --topics --reflog
1493 return
1495 esac
1496 __git_complete_revlist
1499 _git_stash ()
1501 local subcommands='save list show apply clear drop pop create branch'
1502 local subcommand="$(__git_find_subcommand "$subcommands")"
1503 if [ -z "$subcommand" ]; then
1504 __gitcomp "$subcommands"
1505 else
1506 local cur="${COMP_WORDS[COMP_CWORD]}"
1507 case "$subcommand,$cur" in
1508 save,--*)
1509 __gitcomp "--keep-index"
1511 apply,--*)
1512 __gitcomp "--index"
1514 show,--*|drop,--*|pop,--*|branch,--*)
1515 COMPREPLY=()
1517 show,*|apply,*|drop,*|pop,*|branch,*)
1518 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1519 | sed -n -e 's/:.*//p')"
1522 COMPREPLY=()
1524 esac
1528 _git_submodule ()
1530 __git_has_doubledash && return
1532 local subcommands="add status init update summary foreach sync"
1533 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1534 local cur="${COMP_WORDS[COMP_CWORD]}"
1535 case "$cur" in
1536 --*)
1537 __gitcomp "--quiet --cached"
1540 __gitcomp "$subcommands"
1542 esac
1543 return
1547 _git_svn ()
1549 local subcommands="
1550 init fetch clone rebase dcommit log find-rev
1551 set-tree commit-diff info create-ignore propget
1552 proplist show-ignore show-externals
1554 local subcommand="$(__git_find_subcommand "$subcommands")"
1555 if [ -z "$subcommand" ]; then
1556 __gitcomp "$subcommands"
1557 else
1558 local remote_opts="--username= --config-dir= --no-auth-cache"
1559 local fc_opts="
1560 --follow-parent --authors-file= --repack=
1561 --no-metadata --use-svm-props --use-svnsync-props
1562 --log-window-size= --no-checkout --quiet
1563 --repack-flags --user-log-author $remote_opts
1565 local init_opts="
1566 --template= --shared= --trunk= --tags=
1567 --branches= --stdlayout --minimize-url
1568 --no-metadata --use-svm-props --use-svnsync-props
1569 --rewrite-root= $remote_opts
1571 local cmt_opts="
1572 --edit --rmdir --find-copies-harder --copy-similarity=
1575 local cur="${COMP_WORDS[COMP_CWORD]}"
1576 case "$subcommand,$cur" in
1577 fetch,--*)
1578 __gitcomp "--revision= --fetch-all $fc_opts"
1580 clone,--*)
1581 __gitcomp "--revision= $fc_opts $init_opts"
1583 init,--*)
1584 __gitcomp "$init_opts"
1586 dcommit,--*)
1587 __gitcomp "
1588 --merge --strategy= --verbose --dry-run
1589 --fetch-all --no-rebase $cmt_opts $fc_opts
1592 set-tree,--*)
1593 __gitcomp "--stdin $cmt_opts $fc_opts"
1595 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1596 show-externals,--*)
1597 __gitcomp "--revision="
1599 log,--*)
1600 __gitcomp "
1601 --limit= --revision= --verbose --incremental
1602 --oneline --show-commit --non-recursive
1603 --authors-file=
1606 rebase,--*)
1607 __gitcomp "
1608 --merge --verbose --strategy= --local
1609 --fetch-all $fc_opts
1612 commit-diff,--*)
1613 __gitcomp "--message= --file= --revision= $cmt_opts"
1615 info,--*)
1616 __gitcomp "--url"
1619 COMPREPLY=()
1621 esac
1625 _git_tag ()
1627 local i c=1 f=0
1628 while [ $c -lt $COMP_CWORD ]; do
1629 i="${COMP_WORDS[c]}"
1630 case "$i" in
1631 -d|-v)
1632 __gitcomp "$(__git_tags)"
1633 return
1638 esac
1639 c=$((++c))
1640 done
1642 case "${COMP_WORDS[COMP_CWORD-1]}" in
1643 -m|-F)
1644 COMPREPLY=()
1646 -*|tag)
1647 if [ $f = 1 ]; then
1648 __gitcomp "$(__git_tags)"
1649 else
1650 COMPREPLY=()
1654 __gitcomp "$(__git_refs)"
1656 esac
1659 _git ()
1661 local i c=1 command __git_dir
1663 while [ $c -lt $COMP_CWORD ]; do
1664 i="${COMP_WORDS[c]}"
1665 case "$i" in
1666 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1667 --bare) __git_dir="." ;;
1668 --version|-p|--paginate) ;;
1669 --help) command="help"; break ;;
1670 *) command="$i"; break ;;
1671 esac
1672 c=$((++c))
1673 done
1675 if [ -z "$command" ]; then
1676 case "${COMP_WORDS[COMP_CWORD]}" in
1677 --*=*) COMPREPLY=() ;;
1678 --*) __gitcomp "
1679 --paginate
1680 --no-pager
1681 --git-dir=
1682 --bare
1683 --version
1684 --exec-path
1685 --work-tree=
1686 --help
1689 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1690 esac
1691 return
1694 local expansion=$(__git_aliased_command "$command")
1695 [ "$expansion" ] && command="$expansion"
1697 case "$command" in
1698 am) _git_am ;;
1699 add) _git_add ;;
1700 apply) _git_apply ;;
1701 archive) _git_archive ;;
1702 bisect) _git_bisect ;;
1703 bundle) _git_bundle ;;
1704 branch) _git_branch ;;
1705 checkout) _git_checkout ;;
1706 cherry) _git_cherry ;;
1707 cherry-pick) _git_cherry_pick ;;
1708 clean) _git_clean ;;
1709 clone) _git_clone ;;
1710 commit) _git_commit ;;
1711 config) _git_config ;;
1712 describe) _git_describe ;;
1713 diff) _git_diff ;;
1714 fetch) _git_fetch ;;
1715 format-patch) _git_format_patch ;;
1716 gc) _git_gc ;;
1717 grep) _git_grep ;;
1718 help) _git_help ;;
1719 init) _git_init ;;
1720 log) _git_log ;;
1721 ls-files) _git_ls_files ;;
1722 ls-remote) _git_ls_remote ;;
1723 ls-tree) _git_ls_tree ;;
1724 merge) _git_merge;;
1725 mergetool) _git_mergetool;;
1726 merge-base) _git_merge_base ;;
1727 mv) _git_mv ;;
1728 name-rev) _git_name_rev ;;
1729 pull) _git_pull ;;
1730 push) _git_push ;;
1731 rebase) _git_rebase ;;
1732 remote) _git_remote ;;
1733 reset) _git_reset ;;
1734 revert) _git_revert ;;
1735 rm) _git_rm ;;
1736 send-email) _git_send_email ;;
1737 shortlog) _git_shortlog ;;
1738 show) _git_show ;;
1739 show-branch) _git_show_branch ;;
1740 stash) _git_stash ;;
1741 submodule) _git_submodule ;;
1742 svn) _git_svn ;;
1743 tag) _git_tag ;;
1744 whatchanged) _git_log ;;
1745 *) COMPREPLY=() ;;
1746 esac
1749 _gitk ()
1751 __git_has_doubledash && return
1753 local cur="${COMP_WORDS[COMP_CWORD]}"
1754 local g="$(git rev-parse --git-dir 2>/dev/null)"
1755 local merge=""
1756 if [ -f $g/MERGE_HEAD ]; then
1757 merge="--merge"
1759 case "$cur" in
1760 --*)
1761 __gitcomp "--not --all $merge"
1762 return
1764 esac
1765 __git_complete_revlist
1768 complete -o default -o nospace -F _git git
1769 complete -o default -o nospace -F _gitk gitk
1771 # The following are necessary only for Cygwin, and only are needed
1772 # when the user has tab-completed the executable name and consequently
1773 # included the '.exe' suffix.
1775 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1776 complete -o default -o nospace -F _git git.exe