bash: complete full refs
[git/spearce.git] / contrib / completion / git-completion.bash
blob5fb34c49dc44b962dfeea447d58b11957d875bc5
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 mycword="$COMP_CWORD"
651 case "${COMP_WORDS[0]}" in
652 git)
653 local cmd="${COMP_WORDS[2]}"
654 mycword="$((mycword-1))"
656 git-bundle*)
657 local cmd="${COMP_WORDS[1]}"
659 esac
660 case "$mycword" in
662 __gitcomp "create list-heads verify unbundle"
665 # looking for a file
668 case "$cmd" in
669 create)
670 __git_complete_revlist
672 esac
674 esac
677 _git_checkout ()
679 __git_has_doubledash && return
681 __gitcomp "$(__git_refs)"
684 _git_cherry ()
686 __gitcomp "$(__git_refs)"
689 _git_cherry_pick ()
691 local cur="${COMP_WORDS[COMP_CWORD]}"
692 case "$cur" in
693 --*)
694 __gitcomp "--edit --no-commit"
697 __gitcomp "$(__git_refs)"
699 esac
702 _git_clean ()
704 __git_has_doubledash && return
706 local cur="${COMP_WORDS[COMP_CWORD]}"
707 case "$cur" in
708 --*)
709 __gitcomp "--dry-run --quiet"
710 return
712 esac
713 COMPREPLY=()
716 _git_clone ()
718 local cur="${COMP_WORDS[COMP_CWORD]}"
719 case "$cur" in
720 --*)
721 __gitcomp "
722 --local
723 --no-hardlinks
724 --shared
725 --reference
726 --quiet
727 --no-checkout
728 --bare
729 --mirror
730 --origin
731 --upload-pack
732 --template=
733 --depth
735 return
737 esac
738 COMPREPLY=()
741 _git_commit ()
743 __git_has_doubledash && return
745 local cur="${COMP_WORDS[COMP_CWORD]}"
746 case "$cur" in
747 --*)
748 __gitcomp "
749 --all --author= --signoff --verify --no-verify
750 --edit --amend --include --only --interactive
752 return
753 esac
754 COMPREPLY=()
757 _git_describe ()
759 local cur="${COMP_WORDS[COMP_CWORD]}"
760 case "$cur" in
761 --*)
762 __gitcomp "
763 --all --tags --contains --abbrev= --candidates=
764 --exact-match --debug --long --match --always
766 return
767 esac
768 __gitcomp "$(__git_refs)"
771 _git_diff ()
773 __git_has_doubledash && return
775 local cur="${COMP_WORDS[COMP_CWORD]}"
776 case "$cur" in
777 --*)
778 __gitcomp "--cached --stat --numstat --shortstat --summary
779 --patch-with-stat --name-only --name-status --color
780 --no-color --color-words --no-renames --check
781 --full-index --binary --abbrev --diff-filter=
782 --find-copies-harder --pickaxe-all --pickaxe-regex
783 --text --ignore-space-at-eol --ignore-space-change
784 --ignore-all-space --exit-code --quiet --ext-diff
785 --no-ext-diff
786 --no-prefix --src-prefix= --dst-prefix=
787 --base --ours --theirs
789 return
791 esac
792 __git_complete_file
795 _git_fetch ()
797 local cur="${COMP_WORDS[COMP_CWORD]}"
799 if [ "$COMP_CWORD" = 2 ]; then
800 __gitcomp "$(__git_remotes)"
801 else
802 case "$cur" in
803 *:*)
804 local pfx=""
805 case "$COMP_WORDBREAKS" in
806 *:*) : great ;;
807 *) pfx="${cur%%:*}:" ;;
808 esac
809 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
812 local remote
813 case "${COMP_WORDS[0]}" in
814 git-fetch) remote="${COMP_WORDS[1]}" ;;
815 git) remote="${COMP_WORDS[2]}" ;;
816 esac
817 __gitcomp "$(__git_refs2 "$remote")"
819 esac
823 _git_format_patch ()
825 local cur="${COMP_WORDS[COMP_CWORD]}"
826 case "$cur" in
827 --*)
828 __gitcomp "
829 --stdout --attach --thread
830 --output-directory
831 --numbered --start-number
832 --numbered-files
833 --keep-subject
834 --signoff
835 --in-reply-to=
836 --full-index --binary
837 --not --all
838 --cover-letter
839 --no-prefix --src-prefix= --dst-prefix=
841 return
843 esac
844 __git_complete_revlist
847 _git_gc ()
849 local cur="${COMP_WORDS[COMP_CWORD]}"
850 case "$cur" in
851 --*)
852 __gitcomp "--prune --aggressive"
853 return
855 esac
856 COMPREPLY=()
859 _git_grep ()
861 __git_has_doubledash && return
863 local cur="${COMP_WORDS[COMP_CWORD]}"
864 case "$cur" in
865 --*)
866 __gitcomp "
867 --cached
868 --text --ignore-case --word-regexp --invert-match
869 --full-name
870 --extended-regexp --basic-regexp --fixed-strings
871 --files-with-matches --name-only
872 --files-without-match
873 --count
874 --and --or --not --all-match
876 return
878 esac
879 COMPREPLY=()
882 _git_help ()
884 local cur="${COMP_WORDS[COMP_CWORD]}"
885 case "$cur" in
886 --*)
887 __gitcomp "--all --info --man --web"
888 return
890 esac
891 __gitcomp "$(__git_all_commands)
892 attributes cli core-tutorial cvs-migration
893 diffcore gitk glossary hooks ignore modules
894 repository-layout tutorial tutorial-2
895 workflows
899 _git_init ()
901 local cur="${COMP_WORDS[COMP_CWORD]}"
902 case "$cur" in
903 --shared=*)
904 __gitcomp "
905 false true umask group all world everybody
906 " "" "${cur##--shared=}"
907 return
909 --*)
910 __gitcomp "--quiet --bare --template= --shared --shared="
911 return
913 esac
914 COMPREPLY=()
917 _git_ls_files ()
919 __git_has_doubledash && return
921 local cur="${COMP_WORDS[COMP_CWORD]}"
922 case "$cur" in
923 --*)
924 __gitcomp "--cached --deleted --modified --others --ignored
925 --stage --directory --no-empty-directory --unmerged
926 --killed --exclude= --exclude-from=
927 --exclude-per-directory= --exclude-standard
928 --error-unmatch --with-tree= --full-name
929 --abbrev --ignored --exclude-per-directory
931 return
933 esac
934 COMPREPLY=()
937 _git_ls_remote ()
939 __gitcomp "$(__git_remotes)"
942 _git_ls_tree ()
944 __git_complete_file
947 _git_log ()
949 __git_has_doubledash && return
951 local cur="${COMP_WORDS[COMP_CWORD]}"
952 case "$cur" in
953 --pretty=*)
954 __gitcomp "
955 oneline short medium full fuller email raw
956 " "" "${cur##--pretty=}"
957 return
959 --date=*)
960 __gitcomp "
961 relative iso8601 rfc2822 short local default
962 " "" "${cur##--date=}"
963 return
965 --*)
966 __gitcomp "
967 --max-count= --max-age= --since= --after=
968 --min-age= --before= --until=
969 --root --topo-order --date-order --reverse
970 --no-merges --follow
971 --abbrev-commit --abbrev=
972 --relative-date --date=
973 --author= --committer= --grep=
974 --all-match
975 --pretty= --name-status --name-only --raw
976 --not --all
977 --left-right --cherry-pick
978 --graph
979 --stat --numstat --shortstat
980 --decorate --diff-filter=
981 --color-words --walk-reflogs
982 --parents --children --full-history
983 --merge
985 return
987 esac
988 __git_complete_revlist
991 _git_merge ()
993 local cur="${COMP_WORDS[COMP_CWORD]}"
994 case "${COMP_WORDS[COMP_CWORD-1]}" in
995 -s|--strategy)
996 __gitcomp "$(__git_merge_strategies)"
997 return
998 esac
999 case "$cur" in
1000 --strategy=*)
1001 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1002 return
1004 --*)
1005 __gitcomp "
1006 --no-commit --no-stat --log --no-log --squash --strategy
1008 return
1009 esac
1010 __gitcomp "$(__git_refs)"
1013 _git_mergetool ()
1015 local cur="${COMP_WORDS[COMP_CWORD]}"
1016 case "$cur" in
1017 --tool=*)
1018 __gitcomp "
1019 kdiff3 tkdiff meld xxdiff emerge
1020 vimdiff gvimdiff ecmerge opendiff
1021 " "" "${cur##--tool=}"
1022 return
1024 --*)
1025 __gitcomp "--tool="
1026 return
1028 esac
1029 COMPREPLY=()
1032 _git_merge_base ()
1034 __gitcomp "$(__git_refs)"
1037 _git_mv ()
1039 local cur="${COMP_WORDS[COMP_CWORD]}"
1040 case "$cur" in
1041 --*)
1042 __gitcomp "--dry-run"
1043 return
1045 esac
1046 COMPREPLY=()
1049 _git_name_rev ()
1051 __gitcomp "--tags --all --stdin"
1054 _git_pull ()
1056 local cur="${COMP_WORDS[COMP_CWORD]}"
1058 if [ "$COMP_CWORD" = 2 ]; then
1059 __gitcomp "$(__git_remotes)"
1060 else
1061 local remote
1062 case "${COMP_WORDS[0]}" in
1063 git-pull) remote="${COMP_WORDS[1]}" ;;
1064 git) remote="${COMP_WORDS[2]}" ;;
1065 esac
1066 __gitcomp "$(__git_refs "$remote")"
1070 _git_push ()
1072 local cur="${COMP_WORDS[COMP_CWORD]}"
1074 if [ "$COMP_CWORD" = 2 ]; then
1075 __gitcomp "$(__git_remotes)"
1076 else
1077 case "$cur" in
1078 *:*)
1079 local remote
1080 case "${COMP_WORDS[0]}" in
1081 git-push) remote="${COMP_WORDS[1]}" ;;
1082 git) remote="${COMP_WORDS[2]}" ;;
1083 esac
1085 local pfx=""
1086 case "$COMP_WORDBREAKS" in
1087 *:*) : great ;;
1088 *) pfx="${cur%%:*}:" ;;
1089 esac
1091 __gitcomp "$(__git_refs "$remote")" "$pfx" "${cur#*:}"
1094 __gitcomp "$(__git_refs)" + "${cur#+}"
1097 __gitcomp "$(__git_refs)"
1099 esac
1103 _git_rebase ()
1105 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1106 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1107 __gitcomp "--continue --skip --abort"
1108 return
1110 case "${COMP_WORDS[COMP_CWORD-1]}" in
1111 -s|--strategy)
1112 __gitcomp "$(__git_merge_strategies)"
1113 return
1114 esac
1115 case "$cur" in
1116 --strategy=*)
1117 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1118 return
1120 --*)
1121 __gitcomp "--onto --merge --strategy --interactive"
1122 return
1123 esac
1124 __gitcomp "$(__git_refs)"
1127 _git_send_email ()
1129 local cur="${COMP_WORDS[COMP_CWORD]}"
1130 case "$cur" in
1131 --*)
1132 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1133 --dry-run --envelope-sender --from --identity
1134 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1135 --no-suppress-from --no-thread --quiet
1136 --signed-off-by-cc --smtp-pass --smtp-server
1137 --smtp-server-port --smtp-ssl --smtp-user --subject
1138 --suppress-cc --suppress-from --thread --to
1139 --validate --no-validate"
1140 return
1142 esac
1143 COMPREPLY=()
1146 _git_config ()
1148 local cur="${COMP_WORDS[COMP_CWORD]}"
1149 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1150 case "$prv" in
1151 branch.*.remote)
1152 __gitcomp "$(__git_remotes)"
1153 return
1155 branch.*.merge)
1156 __gitcomp "$(__git_refs)"
1157 return
1159 remote.*.fetch)
1160 local remote="${prv#remote.}"
1161 remote="${remote%.fetch}"
1162 __gitcomp "$(__git_refs_remotes "$remote")"
1163 return
1165 remote.*.push)
1166 local remote="${prv#remote.}"
1167 remote="${remote%.push}"
1168 __gitcomp "$(git --git-dir="$(__gitdir)" \
1169 for-each-ref --format='%(refname):%(refname)' \
1170 refs/heads)"
1171 return
1173 pull.twohead|pull.octopus)
1174 __gitcomp "$(__git_merge_strategies)"
1175 return
1177 color.branch|color.diff|color.status)
1178 __gitcomp "always never auto"
1179 return
1181 color.*.*)
1182 __gitcomp "
1183 black red green yellow blue magenta cyan white
1184 bold dim ul blink reverse
1186 return
1188 *.*)
1189 COMPREPLY=()
1190 return
1192 esac
1193 case "$cur" in
1194 --*)
1195 __gitcomp "
1196 --global --system --file=
1197 --list --replace-all
1198 --get --get-all --get-regexp
1199 --add --unset --unset-all
1200 --remove-section --rename-section
1202 return
1204 branch.*.*)
1205 local pfx="${cur%.*}."
1206 cur="${cur##*.}"
1207 __gitcomp "remote merge" "$pfx" "$cur"
1208 return
1210 branch.*)
1211 local pfx="${cur%.*}."
1212 cur="${cur#*.}"
1213 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1214 return
1216 remote.*.*)
1217 local pfx="${cur%.*}."
1218 cur="${cur##*.}"
1219 __gitcomp "
1220 url fetch push skipDefaultUpdate
1221 receivepack uploadpack tagopt
1222 " "$pfx" "$cur"
1223 return
1225 remote.*)
1226 local pfx="${cur%.*}."
1227 cur="${cur#*.}"
1228 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1229 return
1231 esac
1232 __gitcomp "
1233 apply.whitespace
1234 core.fileMode
1235 core.gitProxy
1236 core.ignoreStat
1237 core.preferSymlinkRefs
1238 core.logAllRefUpdates
1239 core.loosecompression
1240 core.repositoryFormatVersion
1241 core.sharedRepository
1242 core.warnAmbiguousRefs
1243 core.compression
1244 core.packedGitWindowSize
1245 core.packedGitLimit
1246 clean.requireForce
1247 color.branch
1248 color.branch.current
1249 color.branch.local
1250 color.branch.remote
1251 color.branch.plain
1252 color.diff
1253 color.diff.plain
1254 color.diff.meta
1255 color.diff.frag
1256 color.diff.old
1257 color.diff.new
1258 color.diff.commit
1259 color.diff.whitespace
1260 color.pager
1261 color.status
1262 color.status.header
1263 color.status.added
1264 color.status.changed
1265 color.status.untracked
1266 diff.renameLimit
1267 diff.renames
1268 fetch.unpackLimit
1269 format.headers
1270 format.subjectprefix
1271 gitcvs.enabled
1272 gitcvs.logfile
1273 gitcvs.allbinary
1274 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
1275 gitcvs.dbtablenameprefix
1276 gc.packrefs
1277 gc.reflogexpire
1278 gc.reflogexpireunreachable
1279 gc.rerereresolved
1280 gc.rerereunresolved
1281 http.sslVerify
1282 http.sslCert
1283 http.sslKey
1284 http.sslCAInfo
1285 http.sslCAPath
1286 http.maxRequests
1287 http.lowSpeedLimit
1288 http.lowSpeedTime
1289 http.noEPSV
1290 i18n.commitEncoding
1291 i18n.logOutputEncoding
1292 log.showroot
1293 merge.tool
1294 merge.summary
1295 merge.verbosity
1296 pack.window
1297 pack.depth
1298 pack.windowMemory
1299 pack.compression
1300 pack.deltaCacheSize
1301 pack.deltaCacheLimit
1302 pull.octopus
1303 pull.twohead
1304 repack.useDeltaBaseOffset
1305 showbranch.default
1306 tar.umask
1307 transfer.unpackLimit
1308 receive.unpackLimit
1309 receive.denyNonFastForwards
1310 user.name
1311 user.email
1312 user.signingkey
1313 branch. remote.
1317 _git_remote ()
1319 local subcommands="add rm show prune update"
1320 local subcommand="$(__git_find_subcommand "$subcommands")"
1321 if [ -z "$subcommand" ]; then
1322 __gitcomp "$subcommands"
1323 return
1326 case "$subcommand" in
1327 rm|show|prune)
1328 __gitcomp "$(__git_remotes)"
1330 update)
1331 local i c='' IFS=$'\n'
1332 for i in $(git --git-dir="$(__gitdir)" config --list); do
1333 case "$i" in
1334 remotes.*)
1335 i="${i#remotes.}"
1336 c="$c ${i/=*/}"
1338 esac
1339 done
1340 __gitcomp "$c"
1343 COMPREPLY=()
1345 esac
1348 _git_reset ()
1350 __git_has_doubledash && return
1352 local cur="${COMP_WORDS[COMP_CWORD]}"
1353 case "$cur" in
1354 --*)
1355 __gitcomp "--mixed --hard --soft"
1356 return
1358 esac
1359 __gitcomp "$(__git_refs)"
1362 _git_revert ()
1364 local cur="${COMP_WORDS[COMP_CWORD]}"
1365 case "$cur" in
1366 --*)
1367 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1368 return
1370 esac
1371 COMPREPLY=()
1374 _git_rm ()
1376 __git_has_doubledash && return
1378 local cur="${COMP_WORDS[COMP_CWORD]}"
1379 case "$cur" in
1380 --*)
1381 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1382 return
1384 esac
1385 COMPREPLY=()
1388 _git_shortlog ()
1390 __git_has_doubledash && return
1392 local cur="${COMP_WORDS[COMP_CWORD]}"
1393 case "$cur" in
1394 --*)
1395 __gitcomp "
1396 --max-count= --max-age= --since= --after=
1397 --min-age= --before= --until=
1398 --no-merges
1399 --author= --committer= --grep=
1400 --all-match
1401 --not --all
1402 --numbered --summary
1404 return
1406 esac
1407 __git_complete_revlist
1410 _git_show ()
1412 __git_has_doubledash && return
1414 local cur="${COMP_WORDS[COMP_CWORD]}"
1415 case "$cur" in
1416 --pretty=*)
1417 __gitcomp "
1418 oneline short medium full fuller email raw
1419 " "" "${cur##--pretty=}"
1420 return
1422 --*)
1423 __gitcomp "--pretty="
1424 return
1426 esac
1427 __git_complete_file
1430 _git_show_branch ()
1432 local cur="${COMP_WORDS[COMP_CWORD]}"
1433 case "$cur" in
1434 --*)
1435 __gitcomp "
1436 --all --remotes --topo-order --current --more=
1437 --list --independent --merge-base --no-name
1438 --sha1-name --topics --reflog
1440 return
1442 esac
1443 __git_complete_revlist
1446 _git_stash ()
1448 local subcommands='save list show apply clear drop pop create branch'
1449 local subcommand="$(__git_find_subcommand "$subcommands")"
1450 if [ -z "$subcommand" ]; then
1451 __gitcomp "$subcommands"
1452 else
1453 local cur="${COMP_WORDS[COMP_CWORD]}"
1454 case "$subcommand,$cur" in
1455 save,--*)
1456 __gitcomp "--keep-index"
1458 apply,--*)
1459 __gitcomp "--index"
1461 show,--*|drop,--*|pop,--*|branch,--*)
1462 COMPREPLY=()
1464 show,*|apply,*|drop,*|pop,*|branch,*)
1465 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1466 | sed -n -e 's/:.*//p')"
1469 COMPREPLY=()
1471 esac
1475 _git_submodule ()
1477 __git_has_doubledash && return
1479 local subcommands="add status init update summary foreach sync"
1480 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1481 local cur="${COMP_WORDS[COMP_CWORD]}"
1482 case "$cur" in
1483 --*)
1484 __gitcomp "--quiet --cached"
1487 __gitcomp "$subcommands"
1489 esac
1490 return
1494 _git_svn ()
1496 local subcommands="
1497 init fetch clone rebase dcommit log find-rev
1498 set-tree commit-diff info create-ignore propget
1499 proplist show-ignore show-externals
1501 local subcommand="$(__git_find_subcommand "$subcommands")"
1502 if [ -z "$subcommand" ]; then
1503 __gitcomp "$subcommands"
1504 else
1505 local remote_opts="--username= --config-dir= --no-auth-cache"
1506 local fc_opts="
1507 --follow-parent --authors-file= --repack=
1508 --no-metadata --use-svm-props --use-svnsync-props
1509 --log-window-size= --no-checkout --quiet
1510 --repack-flags --user-log-author $remote_opts
1512 local init_opts="
1513 --template= --shared= --trunk= --tags=
1514 --branches= --stdlayout --minimize-url
1515 --no-metadata --use-svm-props --use-svnsync-props
1516 --rewrite-root= $remote_opts
1518 local cmt_opts="
1519 --edit --rmdir --find-copies-harder --copy-similarity=
1522 local cur="${COMP_WORDS[COMP_CWORD]}"
1523 case "$subcommand,$cur" in
1524 fetch,--*)
1525 __gitcomp "--revision= --fetch-all $fc_opts"
1527 clone,--*)
1528 __gitcomp "--revision= $fc_opts $init_opts"
1530 init,--*)
1531 __gitcomp "$init_opts"
1533 dcommit,--*)
1534 __gitcomp "
1535 --merge --strategy= --verbose --dry-run
1536 --fetch-all --no-rebase $cmt_opts $fc_opts
1539 set-tree,--*)
1540 __gitcomp "--stdin $cmt_opts $fc_opts"
1542 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1543 show-externals,--*)
1544 __gitcomp "--revision="
1546 log,--*)
1547 __gitcomp "
1548 --limit= --revision= --verbose --incremental
1549 --oneline --show-commit --non-recursive
1550 --authors-file=
1553 rebase,--*)
1554 __gitcomp "
1555 --merge --verbose --strategy= --local
1556 --fetch-all $fc_opts
1559 commit-diff,--*)
1560 __gitcomp "--message= --file= --revision= $cmt_opts"
1562 info,--*)
1563 __gitcomp "--url"
1566 COMPREPLY=()
1568 esac
1572 _git_tag ()
1574 local i c=1 f=0
1575 while [ $c -lt $COMP_CWORD ]; do
1576 i="${COMP_WORDS[c]}"
1577 case "$i" in
1578 -d|-v)
1579 __gitcomp "$(__git_tags)"
1580 return
1585 esac
1586 c=$((++c))
1587 done
1589 case "${COMP_WORDS[COMP_CWORD-1]}" in
1590 -m|-F)
1591 COMPREPLY=()
1593 -*|tag|git-tag)
1594 if [ $f = 1 ]; then
1595 __gitcomp "$(__git_tags)"
1596 else
1597 COMPREPLY=()
1601 __gitcomp "$(__git_refs)"
1603 esac
1606 _git ()
1608 local i c=1 command __git_dir
1610 while [ $c -lt $COMP_CWORD ]; do
1611 i="${COMP_WORDS[c]}"
1612 case "$i" in
1613 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1614 --bare) __git_dir="." ;;
1615 --version|-p|--paginate) ;;
1616 --help) command="help"; break ;;
1617 *) command="$i"; break ;;
1618 esac
1619 c=$((++c))
1620 done
1622 if [ -z "$command" ]; then
1623 case "${COMP_WORDS[COMP_CWORD]}" in
1624 --*=*) COMPREPLY=() ;;
1625 --*) __gitcomp "
1626 --paginate
1627 --no-pager
1628 --git-dir=
1629 --bare
1630 --version
1631 --exec-path
1632 --work-tree=
1633 --help
1636 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1637 esac
1638 return
1641 local expansion=$(__git_aliased_command "$command")
1642 [ "$expansion" ] && command="$expansion"
1644 case "$command" in
1645 am) _git_am ;;
1646 add) _git_add ;;
1647 apply) _git_apply ;;
1648 archive) _git_archive ;;
1649 bisect) _git_bisect ;;
1650 bundle) _git_bundle ;;
1651 branch) _git_branch ;;
1652 checkout) _git_checkout ;;
1653 cherry) _git_cherry ;;
1654 cherry-pick) _git_cherry_pick ;;
1655 clean) _git_clean ;;
1656 clone) _git_clone ;;
1657 commit) _git_commit ;;
1658 config) _git_config ;;
1659 describe) _git_describe ;;
1660 diff) _git_diff ;;
1661 fetch) _git_fetch ;;
1662 format-patch) _git_format_patch ;;
1663 gc) _git_gc ;;
1664 grep) _git_grep ;;
1665 help) _git_help ;;
1666 init) _git_init ;;
1667 log) _git_log ;;
1668 ls-files) _git_ls_files ;;
1669 ls-remote) _git_ls_remote ;;
1670 ls-tree) _git_ls_tree ;;
1671 merge) _git_merge;;
1672 mergetool) _git_mergetool;;
1673 merge-base) _git_merge_base ;;
1674 mv) _git_mv ;;
1675 name-rev) _git_name_rev ;;
1676 pull) _git_pull ;;
1677 push) _git_push ;;
1678 rebase) _git_rebase ;;
1679 remote) _git_remote ;;
1680 reset) _git_reset ;;
1681 revert) _git_revert ;;
1682 rm) _git_rm ;;
1683 send-email) _git_send_email ;;
1684 shortlog) _git_shortlog ;;
1685 show) _git_show ;;
1686 show-branch) _git_show_branch ;;
1687 stash) _git_stash ;;
1688 submodule) _git_submodule ;;
1689 svn) _git_svn ;;
1690 tag) _git_tag ;;
1691 whatchanged) _git_log ;;
1692 *) COMPREPLY=() ;;
1693 esac
1696 _gitk ()
1698 __git_has_doubledash && return
1700 local cur="${COMP_WORDS[COMP_CWORD]}"
1701 local g="$(git rev-parse --git-dir 2>/dev/null)"
1702 local merge=""
1703 if [ -f $g/MERGE_HEAD ]; then
1704 merge="--merge"
1706 case "$cur" in
1707 --*)
1708 __gitcomp "--not --all $merge"
1709 return
1711 esac
1712 __git_complete_revlist
1715 complete -o default -o nospace -F _git git
1716 complete -o default -o nospace -F _gitk gitk
1718 # The following are necessary only for Cygwin, and only are needed
1719 # when the user has tab-completed the executable name and consequently
1720 # included the '.exe' suffix.
1722 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1723 complete -o default -o nospace -F _git git.exe