completion: find out supported merge strategies correctly
[git/dscho.git] / contrib / completion / git-completion.bash
bloba31004088a969a231972267333ee1cafa1d47233
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 for i in $(git --git-dir="$dir" \
158 for-each-ref --format='%(refname)' \
159 refs/heads ); do
160 echo "${i#refs/heads/}"
161 done
162 return
164 for i in $(git ls-remote "$1" 2>/dev/null); do
165 case "$is_hash,$i" in
166 y,*) is_hash=n ;;
167 n,*^{}) is_hash=y ;;
168 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
169 n,*) is_hash=y; echo "$i" ;;
170 esac
171 done
174 __git_tags ()
176 local cmd i is_hash=y dir="$(__gitdir "$1")"
177 if [ -d "$dir" ]; then
178 for i in $(git --git-dir="$dir" \
179 for-each-ref --format='%(refname)' \
180 refs/tags ); do
181 echo "${i#refs/tags/}"
182 done
183 return
185 for i in $(git ls-remote "$1" 2>/dev/null); do
186 case "$is_hash,$i" in
187 y,*) is_hash=n ;;
188 n,*^{}) is_hash=y ;;
189 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
190 n,*) is_hash=y; echo "$i" ;;
191 esac
192 done
195 __git_refs ()
197 local cmd i is_hash=y dir="$(__gitdir "$1")"
198 if [ -d "$dir" ]; then
199 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
200 for i in $(git --git-dir="$dir" \
201 for-each-ref --format='%(refname)' \
202 refs/tags refs/heads refs/remotes); do
203 case "$i" in
204 refs/tags/*) echo "${i#refs/tags/}" ;;
205 refs/heads/*) echo "${i#refs/heads/}" ;;
206 refs/remotes/*) echo "${i#refs/remotes/}" ;;
207 *) echo "$i" ;;
208 esac
209 done
210 return
212 for i in $(git ls-remote "$dir" 2>/dev/null); do
213 case "$is_hash,$i" in
214 y,*) is_hash=n ;;
215 n,*^{}) is_hash=y ;;
216 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
217 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
218 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
219 n,*) is_hash=y; echo "$i" ;;
220 esac
221 done
224 __git_refs2 ()
226 local i
227 for i in $(__git_refs "$1"); do
228 echo "$i:$i"
229 done
232 __git_refs_remotes ()
234 local cmd i is_hash=y
235 for i in $(git ls-remote "$1" 2>/dev/null); do
236 case "$is_hash,$i" in
237 n,refs/heads/*)
238 is_hash=y
239 echo "$i:refs/remotes/$1/${i#refs/heads/}"
241 y,*) is_hash=n ;;
242 n,*^{}) is_hash=y ;;
243 n,refs/tags/*) is_hash=y;;
244 n,*) is_hash=y; ;;
245 esac
246 done
249 __git_remotes ()
251 local i ngoff IFS=$'\n' d="$(__gitdir)"
252 shopt -q nullglob || ngoff=1
253 shopt -s nullglob
254 for i in "$d/remotes"/*; do
255 echo ${i#$d/remotes/}
256 done
257 [ "$ngoff" ] && shopt -u nullglob
258 for i in $(git --git-dir="$d" config --list); do
259 case "$i" in
260 remote.*.url=*)
261 i="${i#remote.}"
262 echo "${i/.url=*/}"
264 esac
265 done
268 __git_merge_strategies ()
270 if [ -n "$__git_merge_strategylist" ]; then
271 echo "$__git_merge_strategylist"
272 return
274 git merge -s help 2>&1 |
275 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
276 s/\.$//
277 s/.*://
278 s/^[ ]*//
279 s/[ ]*$//
283 __git_merge_strategylist=
284 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
286 __git_complete_file ()
288 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
289 case "$cur" in
290 ?*:*)
291 ref="${cur%%:*}"
292 cur="${cur#*:}"
293 case "$cur" in
294 ?*/*)
295 pfx="${cur%/*}"
296 cur="${cur##*/}"
297 ls="$ref:$pfx"
298 pfx="$pfx/"
301 ls="$ref"
303 esac
305 case "$COMP_WORDBREAKS" in
306 *:*) : great ;;
307 *) pfx="$ref:$pfx" ;;
308 esac
310 local IFS=$'\n'
311 COMPREPLY=($(compgen -P "$pfx" \
312 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
313 | sed '/^100... blob /{
314 s,^.* ,,
315 s,$, ,
317 /^120000 blob /{
318 s,^.* ,,
319 s,$, ,
321 /^040000 tree /{
322 s,^.* ,,
323 s,$,/,
325 s/^.* //')" \
326 -- "$cur"))
329 __gitcomp "$(__git_refs)"
331 esac
334 __git_complete_revlist ()
336 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
337 case "$cur" in
338 *...*)
339 pfx="${cur%...*}..."
340 cur="${cur#*...}"
341 __gitcomp "$(__git_refs)" "$pfx" "$cur"
343 *..*)
344 pfx="${cur%..*}.."
345 cur="${cur#*..}"
346 __gitcomp "$(__git_refs)" "$pfx" "$cur"
349 __gitcomp "$(__git_refs)"
351 esac
354 __git_all_commands ()
356 if [ -n "$__git_all_commandlist" ]; then
357 echo "$__git_all_commandlist"
358 return
360 local i IFS=" "$'\n'
361 for i in $(git help -a|egrep '^ ')
363 case $i in
364 *--*) : helper pattern;;
365 *) echo $i;;
366 esac
367 done
369 __git_all_commandlist=
370 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
372 __git_porcelain_commands ()
374 if [ -n "$__git_porcelain_commandlist" ]; then
375 echo "$__git_porcelain_commandlist"
376 return
378 local i IFS=" "$'\n'
379 for i in "help" $(__git_all_commands)
381 case $i in
382 *--*) : helper pattern;;
383 applymbox) : ask gittus;;
384 applypatch) : ask gittus;;
385 archimport) : import;;
386 cat-file) : plumbing;;
387 check-attr) : plumbing;;
388 check-ref-format) : plumbing;;
389 commit-tree) : plumbing;;
390 cvsexportcommit) : export;;
391 cvsimport) : import;;
392 cvsserver) : daemon;;
393 daemon) : daemon;;
394 diff-files) : plumbing;;
395 diff-index) : plumbing;;
396 diff-tree) : plumbing;;
397 fast-import) : import;;
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 mailinfo) : plumbing;;
408 mailsplit) : plumbing;;
409 merge-*) : plumbing;;
410 mktree) : plumbing;;
411 mktag) : plumbing;;
412 pack-objects) : plumbing;;
413 pack-redundant) : plumbing;;
414 pack-refs) : plumbing;;
415 parse-remote) : plumbing;;
416 patch-id) : plumbing;;
417 peek-remote) : plumbing;;
418 prune) : plumbing;;
419 prune-packed) : plumbing;;
420 quiltimport) : import;;
421 read-tree) : plumbing;;
422 receive-pack) : plumbing;;
423 reflog) : plumbing;;
424 repo-config) : deprecated;;
425 rerere) : plumbing;;
426 rev-list) : plumbing;;
427 rev-parse) : plumbing;;
428 runstatus) : plumbing;;
429 sh-setup) : internal;;
430 shell) : daemon;;
431 send-pack) : plumbing;;
432 show-index) : plumbing;;
433 ssh-*) : transport;;
434 stripspace) : plumbing;;
435 symbolic-ref) : plumbing;;
436 tar-tree) : deprecated;;
437 unpack-file) : plumbing;;
438 unpack-objects) : plumbing;;
439 update-index) : plumbing;;
440 update-ref) : plumbing;;
441 update-server-info) : daemon;;
442 upload-archive) : plumbing;;
443 upload-pack) : plumbing;;
444 write-tree) : plumbing;;
445 verify-tag) : plumbing;;
446 *) echo $i;;
447 esac
448 done
450 __git_porcelain_commandlist=
451 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
453 __git_aliases ()
455 local i IFS=$'\n'
456 for i in $(git --git-dir="$(__gitdir)" config --list); do
457 case "$i" in
458 alias.*)
459 i="${i#alias.}"
460 echo "${i/=*/}"
462 esac
463 done
466 __git_aliased_command ()
468 local word cmdline=$(git --git-dir="$(__gitdir)" \
469 config --get "alias.$1")
470 for word in $cmdline; do
471 if [ "${word##-*}" ]; then
472 echo $word
473 return
475 done
478 __git_find_subcommand ()
480 local word subcommand c=1
482 while [ $c -lt $COMP_CWORD ]; do
483 word="${COMP_WORDS[c]}"
484 for subcommand in $1; do
485 if [ "$subcommand" = "$word" ]; then
486 echo "$subcommand"
487 return
489 done
490 c=$((++c))
491 done
494 __git_has_doubledash ()
496 local c=1
497 while [ $c -lt $COMP_CWORD ]; do
498 if [ "--" = "${COMP_WORDS[c]}" ]; then
499 return 0
501 c=$((++c))
502 done
503 return 1
506 __git_whitespacelist="nowarn warn error error-all fix"
508 _git_am ()
510 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
511 if [ -d "$dir"/rebase-apply ]; then
512 __gitcomp "--skip --resolved --abort"
513 return
515 case "$cur" in
516 --whitespace=*)
517 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
518 return
520 --*)
521 __gitcomp "
522 --signoff --utf8 --binary --3way --interactive
523 --whitespace=
525 return
526 esac
527 COMPREPLY=()
530 _git_apply ()
532 local cur="${COMP_WORDS[COMP_CWORD]}"
533 case "$cur" in
534 --whitespace=*)
535 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
536 return
538 --*)
539 __gitcomp "
540 --stat --numstat --summary --check --index
541 --cached --index-info --reverse --reject --unidiff-zero
542 --apply --no-add --exclude=
543 --whitespace= --inaccurate-eof --verbose
545 return
546 esac
547 COMPREPLY=()
550 _git_add ()
552 __git_has_doubledash && return
554 local cur="${COMP_WORDS[COMP_CWORD]}"
555 case "$cur" in
556 --*)
557 __gitcomp "
558 --interactive --refresh --patch --update --dry-run
559 --ignore-errors
561 return
562 esac
563 COMPREPLY=()
566 _git_archive ()
568 local cur="${COMP_WORDS[COMP_CWORD]}"
569 case "$cur" in
570 --format=*)
571 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
572 return
574 --remote=*)
575 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
576 return
578 --*)
579 __gitcomp "
580 --format= --list --verbose
581 --prefix= --remote= --exec=
583 return
585 esac
586 __git_complete_file
589 _git_bisect ()
591 __git_has_doubledash && return
593 local subcommands="start bad good skip reset visualize replay log run"
594 local subcommand="$(__git_find_subcommand "$subcommands")"
595 if [ -z "$subcommand" ]; then
596 __gitcomp "$subcommands"
597 return
600 case "$subcommand" in
601 bad|good|reset|skip)
602 __gitcomp "$(__git_refs)"
605 COMPREPLY=()
607 esac
610 _git_branch ()
612 local i c=1 only_local_ref="n" has_r="n"
614 while [ $c -lt $COMP_CWORD ]; do
615 i="${COMP_WORDS[c]}"
616 case "$i" in
617 -d|-m) only_local_ref="y" ;;
618 -r) has_r="y" ;;
619 esac
620 c=$((++c))
621 done
623 case "${COMP_WORDS[COMP_CWORD]}" in
624 --*=*) COMPREPLY=() ;;
625 --*)
626 __gitcomp "
627 --color --no-color --verbose --abbrev= --no-abbrev
628 --track --no-track --contains --merged --no-merged
632 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
633 __gitcomp "$(__git_heads)"
634 else
635 __gitcomp "$(__git_refs)"
638 esac
641 _git_bundle ()
643 local mycword="$COMP_CWORD"
644 case "${COMP_WORDS[0]}" in
645 git)
646 local cmd="${COMP_WORDS[2]}"
647 mycword="$((mycword-1))"
649 git-bundle*)
650 local cmd="${COMP_WORDS[1]}"
652 esac
653 case "$mycword" in
655 __gitcomp "create list-heads verify unbundle"
658 # looking for a file
661 case "$cmd" in
662 create)
663 __git_complete_revlist
665 esac
667 esac
670 _git_checkout ()
672 __git_has_doubledash && return
674 __gitcomp "$(__git_refs)"
677 _git_cherry ()
679 __gitcomp "$(__git_refs)"
682 _git_cherry_pick ()
684 local cur="${COMP_WORDS[COMP_CWORD]}"
685 case "$cur" in
686 --*)
687 __gitcomp "--edit --no-commit"
690 __gitcomp "$(__git_refs)"
692 esac
695 _git_clean ()
697 __git_has_doubledash && return
699 local cur="${COMP_WORDS[COMP_CWORD]}"
700 case "$cur" in
701 --*)
702 __gitcomp "--dry-run --quiet"
703 return
705 esac
706 COMPREPLY=()
709 _git_clone ()
711 local cur="${COMP_WORDS[COMP_CWORD]}"
712 case "$cur" in
713 --*)
714 __gitcomp "
715 --local
716 --no-hardlinks
717 --shared
718 --reference
719 --quiet
720 --no-checkout
721 --bare
722 --mirror
723 --origin
724 --upload-pack
725 --template=
726 --depth
728 return
730 esac
731 COMPREPLY=()
734 _git_commit ()
736 __git_has_doubledash && return
738 local cur="${COMP_WORDS[COMP_CWORD]}"
739 case "$cur" in
740 --*)
741 __gitcomp "
742 --all --author= --signoff --verify --no-verify
743 --edit --amend --include --only
745 return
746 esac
747 COMPREPLY=()
750 _git_describe ()
752 local cur="${COMP_WORDS[COMP_CWORD]}"
753 case "$cur" in
754 --*)
755 __gitcomp "
756 --all --tags --contains --abbrev= --candidates=
757 --exact-match --debug --long --match --always
759 return
760 esac
761 __gitcomp "$(__git_refs)"
764 _git_diff ()
766 __git_has_doubledash && return
768 local cur="${COMP_WORDS[COMP_CWORD]}"
769 case "$cur" in
770 --*)
771 __gitcomp "--cached --stat --numstat --shortstat --summary
772 --patch-with-stat --name-only --name-status --color
773 --no-color --color-words --no-renames --check
774 --full-index --binary --abbrev --diff-filter
775 --find-copies-harder --pickaxe-all --pickaxe-regex
776 --text --ignore-space-at-eol --ignore-space-change
777 --ignore-all-space --exit-code --quiet --ext-diff
778 --no-ext-diff
779 --no-prefix --src-prefix= --dst-prefix=
780 --base --ours --theirs
782 return
784 esac
785 __git_complete_file
788 _git_fetch ()
790 local cur="${COMP_WORDS[COMP_CWORD]}"
792 case "${COMP_WORDS[0]},$COMP_CWORD" in
793 git-fetch*,1)
794 __gitcomp "$(__git_remotes)"
796 git,2)
797 __gitcomp "$(__git_remotes)"
800 case "$cur" in
801 *:*)
802 local pfx=""
803 case "$COMP_WORDBREAKS" in
804 *:*) : great ;;
805 *) pfx="${cur%%:*}:" ;;
806 esac
807 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
810 local remote
811 case "${COMP_WORDS[0]}" in
812 git-fetch) remote="${COMP_WORDS[1]}" ;;
813 git) remote="${COMP_WORDS[2]}" ;;
814 esac
815 __gitcomp "$(__git_refs2 "$remote")"
817 esac
819 esac
822 _git_format_patch ()
824 local cur="${COMP_WORDS[COMP_CWORD]}"
825 case "$cur" in
826 --*)
827 __gitcomp "
828 --stdout --attach --thread
829 --output-directory
830 --numbered --start-number
831 --numbered-files
832 --keep-subject
833 --signoff
834 --in-reply-to=
835 --full-index --binary
836 --not --all
837 --cover-letter
838 --no-prefix --src-prefix= --dst-prefix=
840 return
842 esac
843 __git_complete_revlist
846 _git_gc ()
848 local cur="${COMP_WORDS[COMP_CWORD]}"
849 case "$cur" in
850 --*)
851 __gitcomp "--prune --aggressive"
852 return
854 esac
855 COMPREPLY=()
858 _git_grep ()
860 __git_has_doubledash && return
862 local cur="${COMP_WORDS[COMP_CWORD]}"
863 case "$cur" in
864 --*)
865 __gitcomp "
866 --cached
867 --text --ignore-case --word-regexp --invert-match
868 --full-name
869 --extended-regexp --basic-regexp --fixed-strings
870 --files-with-matches --name-only
871 --files-without-match
872 --count
873 --and --or --not --all-match
875 return
877 esac
878 COMPREPLY=()
881 _git_help ()
883 local cur="${COMP_WORDS[COMP_CWORD]}"
884 case "$cur" in
885 --*)
886 __gitcomp "--all --info --man --web"
887 return
889 esac
890 __gitcomp "$(__git_all_commands)
891 attributes cli core-tutorial cvs-migration
892 diffcore gitk glossary hooks ignore modules
893 repository-layout tutorial tutorial-2
897 _git_init ()
899 local cur="${COMP_WORDS[COMP_CWORD]}"
900 case "$cur" in
901 --shared=*)
902 __gitcomp "
903 false true umask group all world everybody
904 " "" "${cur##--shared=}"
905 return
907 --*)
908 __gitcomp "--quiet --bare --template= --shared --shared="
909 return
911 esac
912 COMPREPLY=()
915 _git_ls_files ()
917 __git_has_doubledash && return
919 local cur="${COMP_WORDS[COMP_CWORD]}"
920 case "$cur" in
921 --*)
922 __gitcomp "--cached --deleted --modified --others --ignored
923 --stage --directory --no-empty-directory --unmerged
924 --killed --exclude= --exclude-from=
925 --exclude-per-directory= --exclude-standard
926 --error-unmatch --with-tree= --full-name
927 --abbrev --ignored --exclude-per-directory
929 return
931 esac
932 COMPREPLY=()
935 _git_ls_remote ()
937 __gitcomp "$(__git_remotes)"
940 _git_ls_tree ()
942 __git_complete_file
945 _git_log ()
947 __git_has_doubledash && return
949 local cur="${COMP_WORDS[COMP_CWORD]}"
950 case "$cur" in
951 --pretty=*)
952 __gitcomp "
953 oneline short medium full fuller email raw
954 " "" "${cur##--pretty=}"
955 return
957 --date=*)
958 __gitcomp "
959 relative iso8601 rfc2822 short local default
960 " "" "${cur##--date=}"
961 return
963 --*)
964 __gitcomp "
965 --max-count= --max-age= --since= --after=
966 --min-age= --before= --until=
967 --root --topo-order --date-order --reverse
968 --no-merges --follow
969 --abbrev-commit --abbrev=
970 --relative-date --date=
971 --author= --committer= --grep=
972 --all-match
973 --pretty= --name-status --name-only --raw
974 --not --all
975 --left-right --cherry-pick
976 --graph
977 --stat --numstat --shortstat
978 --decorate --diff-filter=
979 --color-words --walk-reflogs
980 --parents --children --full-history
981 --merge
983 return
985 esac
986 __git_complete_revlist
989 _git_merge ()
991 local cur="${COMP_WORDS[COMP_CWORD]}"
992 case "${COMP_WORDS[COMP_CWORD-1]}" in
993 -s|--strategy)
994 __gitcomp "$(__git_merge_strategies)"
995 return
996 esac
997 case "$cur" in
998 --strategy=*)
999 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1000 return
1002 --*)
1003 __gitcomp "
1004 --no-commit --no-stat --log --no-log --squash --strategy
1006 return
1007 esac
1008 __gitcomp "$(__git_refs)"
1011 _git_mergetool ()
1013 local cur="${COMP_WORDS[COMP_CWORD]}"
1014 case "$cur" in
1015 --tool=*)
1016 __gitcomp "
1017 kdiff3 tkdiff meld xxdiff emerge
1018 vimdiff gvimdiff ecmerge opendiff
1019 " "" "${cur##--tool=}"
1020 return
1022 --*)
1023 __gitcomp "--tool="
1024 return
1026 esac
1027 COMPREPLY=()
1030 _git_merge_base ()
1032 __gitcomp "$(__git_refs)"
1035 _git_mv ()
1037 local cur="${COMP_WORDS[COMP_CWORD]}"
1038 case "$cur" in
1039 --*)
1040 __gitcomp "--dry-run"
1041 return
1043 esac
1044 COMPREPLY=()
1047 _git_name_rev ()
1049 __gitcomp "--tags --all --stdin"
1052 _git_pull ()
1054 local cur="${COMP_WORDS[COMP_CWORD]}"
1056 case "${COMP_WORDS[0]},$COMP_CWORD" in
1057 git-pull*,1)
1058 __gitcomp "$(__git_remotes)"
1060 git,2)
1061 __gitcomp "$(__git_remotes)"
1064 local remote
1065 case "${COMP_WORDS[0]}" in
1066 git-pull) remote="${COMP_WORDS[1]}" ;;
1067 git) remote="${COMP_WORDS[2]}" ;;
1068 esac
1069 __gitcomp "$(__git_refs "$remote")"
1071 esac
1074 _git_push ()
1076 local cur="${COMP_WORDS[COMP_CWORD]}"
1078 case "${COMP_WORDS[0]},$COMP_CWORD" in
1079 git-push*,1)
1080 __gitcomp "$(__git_remotes)"
1082 git,2)
1083 __gitcomp "$(__git_remotes)"
1086 case "$cur" in
1087 *:*)
1088 local remote
1089 case "${COMP_WORDS[0]}" in
1090 git-push) remote="${COMP_WORDS[1]}" ;;
1091 git) remote="${COMP_WORDS[2]}" ;;
1092 esac
1094 local pfx=""
1095 case "$COMP_WORDBREAKS" in
1096 *:*) : great ;;
1097 *) pfx="${cur%%:*}:" ;;
1098 esac
1100 __gitcomp "$(__git_refs "$remote")" "$pfx" "${cur#*:}"
1103 __gitcomp "$(__git_refs)" + "${cur#+}"
1106 __gitcomp "$(__git_refs)"
1108 esac
1110 esac
1113 _git_rebase ()
1115 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1116 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1117 __gitcomp "--continue --skip --abort"
1118 return
1120 case "${COMP_WORDS[COMP_CWORD-1]}" in
1121 -s|--strategy)
1122 __gitcomp "$(__git_merge_strategies)"
1123 return
1124 esac
1125 case "$cur" in
1126 --strategy=*)
1127 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1128 return
1130 --*)
1131 __gitcomp "--onto --merge --strategy --interactive"
1132 return
1133 esac
1134 __gitcomp "$(__git_refs)"
1137 _git_send_email ()
1139 local cur="${COMP_WORDS[COMP_CWORD]}"
1140 case "$cur" in
1141 --*)
1142 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1143 --dry-run --envelope-sender --from --identity
1144 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1145 --no-suppress-from --no-thread --quiet
1146 --signed-off-by-cc --smtp-pass --smtp-server
1147 --smtp-server-port --smtp-ssl --smtp-user --subject
1148 --suppress-cc --suppress-from --thread --to"
1149 return
1151 esac
1152 COMPREPLY=()
1155 _git_config ()
1157 local cur="${COMP_WORDS[COMP_CWORD]}"
1158 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1159 case "$prv" in
1160 branch.*.remote)
1161 __gitcomp "$(__git_remotes)"
1162 return
1164 branch.*.merge)
1165 __gitcomp "$(__git_refs)"
1166 return
1168 remote.*.fetch)
1169 local remote="${prv#remote.}"
1170 remote="${remote%.fetch}"
1171 __gitcomp "$(__git_refs_remotes "$remote")"
1172 return
1174 remote.*.push)
1175 local remote="${prv#remote.}"
1176 remote="${remote%.push}"
1177 __gitcomp "$(git --git-dir="$(__gitdir)" \
1178 for-each-ref --format='%(refname):%(refname)' \
1179 refs/heads)"
1180 return
1182 pull.twohead|pull.octopus)
1183 __gitcomp "$(__git_merge_strategies)"
1184 return
1186 color.branch|color.diff|color.status)
1187 __gitcomp "always never auto"
1188 return
1190 color.*.*)
1191 __gitcomp "
1192 black red green yellow blue magenta cyan white
1193 bold dim ul blink reverse
1195 return
1197 *.*)
1198 COMPREPLY=()
1199 return
1201 esac
1202 case "$cur" in
1203 --*)
1204 __gitcomp "
1205 --global --system --file=
1206 --list --replace-all
1207 --get --get-all --get-regexp
1208 --add --unset --unset-all
1209 --remove-section --rename-section
1211 return
1213 branch.*.*)
1214 local pfx="${cur%.*}."
1215 cur="${cur##*.}"
1216 __gitcomp "remote merge" "$pfx" "$cur"
1217 return
1219 branch.*)
1220 local pfx="${cur%.*}."
1221 cur="${cur#*.}"
1222 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1223 return
1225 remote.*.*)
1226 local pfx="${cur%.*}."
1227 cur="${cur##*.}"
1228 __gitcomp "
1229 url fetch push skipDefaultUpdate
1230 receivepack uploadpack tagopt
1231 " "$pfx" "$cur"
1232 return
1234 remote.*)
1235 local pfx="${cur%.*}."
1236 cur="${cur#*.}"
1237 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1238 return
1240 esac
1241 __gitcomp "
1242 apply.whitespace
1243 core.fileMode
1244 core.gitProxy
1245 core.ignoreStat
1246 core.preferSymlinkRefs
1247 core.logAllRefUpdates
1248 core.loosecompression
1249 core.repositoryFormatVersion
1250 core.sharedRepository
1251 core.warnAmbiguousRefs
1252 core.compression
1253 core.packedGitWindowSize
1254 core.packedGitLimit
1255 clean.requireForce
1256 color.branch
1257 color.branch.current
1258 color.branch.local
1259 color.branch.remote
1260 color.branch.plain
1261 color.diff
1262 color.diff.plain
1263 color.diff.meta
1264 color.diff.frag
1265 color.diff.old
1266 color.diff.new
1267 color.diff.commit
1268 color.diff.whitespace
1269 color.pager
1270 color.status
1271 color.status.header
1272 color.status.added
1273 color.status.changed
1274 color.status.untracked
1275 diff.renameLimit
1276 diff.renames
1277 fetch.unpackLimit
1278 format.headers
1279 format.subjectprefix
1280 gitcvs.enabled
1281 gitcvs.logfile
1282 gitcvs.allbinary
1283 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
1284 gitcvs.dbtablenameprefix
1285 gc.packrefs
1286 gc.reflogexpire
1287 gc.reflogexpireunreachable
1288 gc.rerereresolved
1289 gc.rerereunresolved
1290 http.sslVerify
1291 http.sslCert
1292 http.sslKey
1293 http.sslCAInfo
1294 http.sslCAPath
1295 http.maxRequests
1296 http.lowSpeedLimit
1297 http.lowSpeedTime
1298 http.noEPSV
1299 i18n.commitEncoding
1300 i18n.logOutputEncoding
1301 log.showroot
1302 merge.tool
1303 merge.summary
1304 merge.verbosity
1305 pack.window
1306 pack.depth
1307 pack.windowMemory
1308 pack.compression
1309 pack.deltaCacheSize
1310 pack.deltaCacheLimit
1311 pull.octopus
1312 pull.twohead
1313 repack.useDeltaBaseOffset
1314 showbranch.default
1315 tar.umask
1316 transfer.unpackLimit
1317 receive.unpackLimit
1318 receive.denyNonFastForwards
1319 user.name
1320 user.email
1321 user.signingkey
1322 branch. remote.
1326 _git_remote ()
1328 local subcommands="add rm show prune update"
1329 local subcommand="$(__git_find_subcommand "$subcommands")"
1330 if [ -z "$subcommand" ]; then
1331 __gitcomp "$subcommands"
1332 return
1335 case "$subcommand" in
1336 rm|show|prune)
1337 __gitcomp "$(__git_remotes)"
1339 update)
1340 local i c='' IFS=$'\n'
1341 for i in $(git --git-dir="$(__gitdir)" config --list); do
1342 case "$i" in
1343 remotes.*)
1344 i="${i#remotes.}"
1345 c="$c ${i/=*/}"
1347 esac
1348 done
1349 __gitcomp "$c"
1352 COMPREPLY=()
1354 esac
1357 _git_reset ()
1359 __git_has_doubledash && return
1361 local cur="${COMP_WORDS[COMP_CWORD]}"
1362 case "$cur" in
1363 --*)
1364 __gitcomp "--mixed --hard --soft"
1365 return
1367 esac
1368 __gitcomp "$(__git_refs)"
1371 _git_revert ()
1373 local cur="${COMP_WORDS[COMP_CWORD]}"
1374 case "$cur" in
1375 --*)
1376 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1377 return
1379 esac
1380 COMPREPLY=()
1383 _git_rm ()
1385 __git_has_doubledash && return
1387 local cur="${COMP_WORDS[COMP_CWORD]}"
1388 case "$cur" in
1389 --*)
1390 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1391 return
1393 esac
1394 COMPREPLY=()
1397 _git_shortlog ()
1399 __git_has_doubledash && return
1401 local cur="${COMP_WORDS[COMP_CWORD]}"
1402 case "$cur" in
1403 --*)
1404 __gitcomp "
1405 --max-count= --max-age= --since= --after=
1406 --min-age= --before= --until=
1407 --no-merges
1408 --author= --committer= --grep=
1409 --all-match
1410 --not --all
1411 --numbered --summary
1413 return
1415 esac
1416 __git_complete_revlist
1419 _git_show ()
1421 local cur="${COMP_WORDS[COMP_CWORD]}"
1422 case "$cur" in
1423 --pretty=*)
1424 __gitcomp "
1425 oneline short medium full fuller email raw
1426 " "" "${cur##--pretty=}"
1427 return
1429 --*)
1430 __gitcomp "--pretty="
1431 return
1433 esac
1434 __git_complete_file
1437 _git_show_branch ()
1439 local cur="${COMP_WORDS[COMP_CWORD]}"
1440 case "$cur" in
1441 --*)
1442 __gitcomp "
1443 --all --remotes --topo-order --current --more=
1444 --list --independent --merge-base --no-name
1445 --sha1-name --topics --reflog
1447 return
1449 esac
1450 __git_complete_revlist
1453 _git_stash ()
1455 local subcommands='save list show apply clear drop pop create branch'
1456 local subcommand="$(__git_find_subcommand "$subcommands")"
1457 if [ -z "$subcommand" ]; then
1458 __gitcomp "$subcommands"
1459 else
1460 local cur="${COMP_WORDS[COMP_CWORD]}"
1461 case "$subcommand,$cur" in
1462 save,--*)
1463 __gitcomp "--keep-index"
1465 apply,--*)
1466 __gitcomp "--index"
1468 show,--*|drop,--*|pop,--*|branch,--*)
1469 COMPREPLY=()
1471 show,*|apply,*|drop,*|pop,*|branch,*)
1472 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1473 | sed -n -e 's/:.*//p')"
1476 COMPREPLY=()
1478 esac
1482 _git_submodule ()
1484 __git_has_doubledash && return
1486 local subcommands="add status init update"
1487 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1488 local cur="${COMP_WORDS[COMP_CWORD]}"
1489 case "$cur" in
1490 --*)
1491 __gitcomp "--quiet --cached"
1494 __gitcomp "$subcommands"
1496 esac
1497 return
1501 _git_svn ()
1503 local subcommands="
1504 init fetch clone rebase dcommit log find-rev
1505 set-tree commit-diff info create-ignore propget
1506 proplist show-ignore show-externals
1508 local subcommand="$(__git_find_subcommand "$subcommands")"
1509 if [ -z "$subcommand" ]; then
1510 __gitcomp "$subcommands"
1511 else
1512 local remote_opts="--username= --config-dir= --no-auth-cache"
1513 local fc_opts="
1514 --follow-parent --authors-file= --repack=
1515 --no-metadata --use-svm-props --use-svnsync-props
1516 --log-window-size= --no-checkout --quiet
1517 --repack-flags --user-log-author $remote_opts
1519 local init_opts="
1520 --template= --shared= --trunk= --tags=
1521 --branches= --stdlayout --minimize-url
1522 --no-metadata --use-svm-props --use-svnsync-props
1523 --rewrite-root= $remote_opts
1525 local cmt_opts="
1526 --edit --rmdir --find-copies-harder --copy-similarity=
1529 local cur="${COMP_WORDS[COMP_CWORD]}"
1530 case "$subcommand,$cur" in
1531 fetch,--*)
1532 __gitcomp "--revision= --fetch-all $fc_opts"
1534 clone,--*)
1535 __gitcomp "--revision= $fc_opts $init_opts"
1537 init,--*)
1538 __gitcomp "$init_opts"
1540 dcommit,--*)
1541 __gitcomp "
1542 --merge --strategy= --verbose --dry-run
1543 --fetch-all --no-rebase $cmt_opts $fc_opts
1546 set-tree,--*)
1547 __gitcomp "--stdin $cmt_opts $fc_opts"
1549 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1550 show-externals,--*)
1551 __gitcomp "--revision="
1553 log,--*)
1554 __gitcomp "
1555 --limit= --revision= --verbose --incremental
1556 --oneline --show-commit --non-recursive
1557 --authors-file=
1560 rebase,--*)
1561 __gitcomp "
1562 --merge --verbose --strategy= --local
1563 --fetch-all $fc_opts
1566 commit-diff,--*)
1567 __gitcomp "--message= --file= --revision= $cmt_opts"
1569 info,--*)
1570 __gitcomp "--url"
1573 COMPREPLY=()
1575 esac
1579 _git_tag ()
1581 local i c=1 f=0
1582 while [ $c -lt $COMP_CWORD ]; do
1583 i="${COMP_WORDS[c]}"
1584 case "$i" in
1585 -d|-v)
1586 __gitcomp "$(__git_tags)"
1587 return
1592 esac
1593 c=$((++c))
1594 done
1596 case "${COMP_WORDS[COMP_CWORD-1]}" in
1597 -m|-F)
1598 COMPREPLY=()
1600 -*|tag|git-tag)
1601 if [ $f = 1 ]; then
1602 __gitcomp "$(__git_tags)"
1603 else
1604 COMPREPLY=()
1608 __gitcomp "$(__git_refs)"
1610 esac
1613 _git ()
1615 local i c=1 command __git_dir
1617 while [ $c -lt $COMP_CWORD ]; do
1618 i="${COMP_WORDS[c]}"
1619 case "$i" in
1620 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1621 --bare) __git_dir="." ;;
1622 --version|-p|--paginate) ;;
1623 --help) command="help"; break ;;
1624 *) command="$i"; break ;;
1625 esac
1626 c=$((++c))
1627 done
1629 if [ -z "$command" ]; then
1630 case "${COMP_WORDS[COMP_CWORD]}" in
1631 --*=*) COMPREPLY=() ;;
1632 --*) __gitcomp "
1633 --paginate
1634 --no-pager
1635 --git-dir=
1636 --bare
1637 --version
1638 --exec-path
1639 --work-tree=
1640 --help
1643 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1644 esac
1645 return
1648 local expansion=$(__git_aliased_command "$command")
1649 [ "$expansion" ] && command="$expansion"
1651 case "$command" in
1652 am) _git_am ;;
1653 add) _git_add ;;
1654 apply) _git_apply ;;
1655 archive) _git_archive ;;
1656 bisect) _git_bisect ;;
1657 bundle) _git_bundle ;;
1658 branch) _git_branch ;;
1659 checkout) _git_checkout ;;
1660 cherry) _git_cherry ;;
1661 cherry-pick) _git_cherry_pick ;;
1662 clean) _git_clean ;;
1663 clone) _git_clone ;;
1664 commit) _git_commit ;;
1665 config) _git_config ;;
1666 describe) _git_describe ;;
1667 diff) _git_diff ;;
1668 fetch) _git_fetch ;;
1669 format-patch) _git_format_patch ;;
1670 gc) _git_gc ;;
1671 grep) _git_grep ;;
1672 help) _git_help ;;
1673 init) _git_init ;;
1674 log) _git_log ;;
1675 ls-files) _git_ls_files ;;
1676 ls-remote) _git_ls_remote ;;
1677 ls-tree) _git_ls_tree ;;
1678 merge) _git_merge;;
1679 mergetool) _git_mergetool;;
1680 merge-base) _git_merge_base ;;
1681 mv) _git_mv ;;
1682 name-rev) _git_name_rev ;;
1683 pull) _git_pull ;;
1684 push) _git_push ;;
1685 rebase) _git_rebase ;;
1686 remote) _git_remote ;;
1687 reset) _git_reset ;;
1688 revert) _git_revert ;;
1689 rm) _git_rm ;;
1690 send-email) _git_send_email ;;
1691 shortlog) _git_shortlog ;;
1692 show) _git_show ;;
1693 show-branch) _git_show_branch ;;
1694 stash) _git_stash ;;
1695 submodule) _git_submodule ;;
1696 svn) _git_svn ;;
1697 tag) _git_tag ;;
1698 whatchanged) _git_log ;;
1699 *) COMPREPLY=() ;;
1700 esac
1703 _gitk ()
1705 __git_has_doubledash && return
1707 local cur="${COMP_WORDS[COMP_CWORD]}"
1708 local g="$(git rev-parse --git-dir 2>/dev/null)"
1709 local merge=""
1710 if [ -f $g/MERGE_HEAD ]; then
1711 merge="--merge"
1713 case "$cur" in
1714 --*)
1715 __gitcomp "--not --all $merge"
1716 return
1718 esac
1719 __git_complete_revlist
1722 complete -o default -o nospace -F _git git
1723 complete -o default -o nospace -F _gitk gitk
1725 # The following are necessary only for Cygwin, and only are needed
1726 # when the user has tab-completed the executable name and consequently
1727 # included the '.exe' suffix.
1729 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1730 complete -o default -o nospace -F _git git.exe