bash: remove unnecessary checks for long options with argument
[git/spearce.git] / contrib / completion / git-completion.bash
blob9021220421c3e42decef049e30e46a290ffdc113
1 #!bash
3 # bash completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 # 2) Added the following line to your .bashrc:
22 # source ~/.git-completion.sh
24 # 3) You may want to make sure the git executable is available
25 # in your PATH before this script is sourced, as some caching
26 # is performed while the script loads. If git isn't found
27 # at source time then all lookups will be done on demand,
28 # which may be slightly slower.
30 # 4) Consider changing your PS1 to also show the current branch:
31 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
33 # The argument to __git_ps1 will be displayed only if you
34 # are currently in a git repository. The %s token will be
35 # the name of the current branch.
37 # To submit patches:
39 # *) Read Documentation/SubmittingPatches
40 # *) Send all patches to the current maintainer:
42 # "Shawn O. Pearce" <spearce@spearce.org>
44 # *) Always CC the Git mailing list:
46 # git@vger.kernel.org
49 case "$COMP_WORDBREAKS" in
50 *:*) : great ;;
51 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
52 esac
54 # __gitdir accepts 0 or 1 arguments (i.e., location)
55 # returns location of .git repo
56 __gitdir ()
58 if [ -z "${1-}" ]; then
59 if [ -n "$__git_dir" ]; then
60 echo "$__git_dir"
61 elif [ -d .git ]; then
62 echo .git
63 else
64 git rev-parse --git-dir 2>/dev/null
66 elif [ -d "$1/.git" ]; then
67 echo "$1/.git"
68 else
69 echo "$1"
73 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
74 # returns text to add to bash PS1 prompt (includes branch name)
75 __git_ps1 ()
77 local g="$(git rev-parse --git-dir 2>/dev/null)"
78 if [ -n "$g" ]; then
79 local r
80 local b
81 if [ -d "$g/rebase-apply" ]
82 then
83 if test -f "$g/rebase-apply/rebasing"
84 then
85 r="|REBASE"
86 elif test -f "$g/rebase-apply/applying"
87 then
88 r="|AM"
89 else
90 r="|AM/REBASE"
92 b="$(git symbolic-ref HEAD 2>/dev/null)"
93 elif [ -f "$g/rebase-merge/interactive" ]
94 then
95 r="|REBASE-i"
96 b="$(cat "$g/rebase-merge/head-name")"
97 elif [ -d "$g/rebase-merge" ]
98 then
99 r="|REBASE-m"
100 b="$(cat "$g/rebase-merge/head-name")"
101 elif [ -f "$g/MERGE_HEAD" ]
102 then
103 r="|MERGING"
104 b="$(git symbolic-ref HEAD 2>/dev/null)"
105 else
106 if [ -f "$g/BISECT_LOG" ]
107 then
108 r="|BISECTING"
110 if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
111 then
112 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
113 then
114 b="$(cut -c1-7 "$g/HEAD")..."
119 if [ -n "${1-}" ]; then
120 printf "$1" "${b##refs/heads/}$r"
121 else
122 printf " (%s)" "${b##refs/heads/}$r"
127 # __gitcomp_1 requires 2 arguments
128 __gitcomp_1 ()
130 local c IFS=' '$'\t'$'\n'
131 for c in $1; do
132 case "$c$2" in
133 --*=*) printf %s$'\n' "$c$2" ;;
134 *.) printf %s$'\n' "$c$2" ;;
135 *) printf %s$'\n' "$c$2 " ;;
136 esac
137 done
140 # __gitcomp accepts 1, 2, 3, or 4 arguments
141 # generates completion reply with compgen
142 __gitcomp ()
144 local cur="${COMP_WORDS[COMP_CWORD]}"
145 if [ $# -gt 2 ]; then
146 cur="$3"
148 case "$cur" in
149 --*=)
150 COMPREPLY=()
153 local IFS=$'\n'
154 COMPREPLY=($(compgen -P "${2-}" \
155 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
156 -- "$cur"))
158 esac
161 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
162 __git_heads ()
164 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
165 if [ -d "$dir" ]; then
166 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
167 refs/heads
168 return
170 for i in $(git ls-remote "${1-}" 2>/dev/null); do
171 case "$is_hash,$i" in
172 y,*) is_hash=n ;;
173 n,*^{}) is_hash=y ;;
174 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
175 n,*) is_hash=y; echo "$i" ;;
176 esac
177 done
180 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
181 __git_tags ()
183 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
184 if [ -d "$dir" ]; then
185 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
186 refs/tags
187 return
189 for i in $(git ls-remote "${1-}" 2>/dev/null); do
190 case "$is_hash,$i" in
191 y,*) is_hash=n ;;
192 n,*^{}) is_hash=y ;;
193 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
194 n,*) is_hash=y; echo "$i" ;;
195 esac
196 done
199 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
200 __git_refs ()
202 local i is_hash=y dir="$(__gitdir "${1-}")"
203 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
204 if [ -d "$dir" ]; then
205 case "$cur" in
206 refs|refs/*)
207 format="refname"
208 refs="${cur%/*}"
211 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
212 format="refname:short"
213 refs="refs/tags refs/heads refs/remotes"
215 esac
216 git --git-dir="$dir" for-each-ref --format="%($format)" \
217 $refs
218 return
220 for i in $(git ls-remote "$dir" 2>/dev/null); do
221 case "$is_hash,$i" in
222 y,*) is_hash=n ;;
223 n,*^{}) is_hash=y ;;
224 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
225 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
226 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
227 n,*) is_hash=y; echo "$i" ;;
228 esac
229 done
232 # __git_refs2 requires 1 argument (to pass to __git_refs)
233 __git_refs2 ()
235 local i
236 for i in $(__git_refs "$1"); do
237 echo "$i:$i"
238 done
241 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
242 __git_refs_remotes ()
244 local cmd i is_hash=y
245 for i in $(git ls-remote "$1" 2>/dev/null); do
246 case "$is_hash,$i" in
247 n,refs/heads/*)
248 is_hash=y
249 echo "$i:refs/remotes/$1/${i#refs/heads/}"
251 y,*) is_hash=n ;;
252 n,*^{}) is_hash=y ;;
253 n,refs/tags/*) is_hash=y;;
254 n,*) is_hash=y; ;;
255 esac
256 done
259 __git_remotes ()
261 local i ngoff IFS=$'\n' d="$(__gitdir)"
262 shopt -q nullglob || ngoff=1
263 shopt -s nullglob
264 for i in "$d/remotes"/*; do
265 echo ${i#$d/remotes/}
266 done
267 [ "$ngoff" ] && shopt -u nullglob
268 for i in $(git --git-dir="$d" config --list); do
269 case "$i" in
270 remote.*.url=*)
271 i="${i#remote.}"
272 echo "${i/.url=*/}"
274 esac
275 done
278 __git_merge_strategies ()
280 if [ -n "$__git_merge_strategylist" ]; then
281 echo "$__git_merge_strategylist"
282 return
284 git merge -s help 2>&1 |
285 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
286 s/\.$//
287 s/.*://
288 s/^[ ]*//
289 s/[ ]*$//
293 __git_merge_strategylist=
294 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
296 __git_complete_file ()
298 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
299 case "$cur" in
300 ?*:*)
301 ref="${cur%%:*}"
302 cur="${cur#*:}"
303 case "$cur" in
304 ?*/*)
305 pfx="${cur%/*}"
306 cur="${cur##*/}"
307 ls="$ref:$pfx"
308 pfx="$pfx/"
311 ls="$ref"
313 esac
315 case "$COMP_WORDBREAKS" in
316 *:*) : great ;;
317 *) pfx="$ref:$pfx" ;;
318 esac
320 local IFS=$'\n'
321 COMPREPLY=($(compgen -P "$pfx" \
322 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
323 | sed '/^100... blob /{
324 s,^.* ,,
325 s,$, ,
327 /^120000 blob /{
328 s,^.* ,,
329 s,$, ,
331 /^040000 tree /{
332 s,^.* ,,
333 s,$,/,
335 s/^.* //')" \
336 -- "$cur"))
339 __gitcomp "$(__git_refs)"
341 esac
344 __git_complete_revlist ()
346 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
347 case "$cur" in
348 *...*)
349 pfx="${cur%...*}..."
350 cur="${cur#*...}"
351 __gitcomp "$(__git_refs)" "$pfx" "$cur"
353 *..*)
354 pfx="${cur%..*}.."
355 cur="${cur#*..}"
356 __gitcomp "$(__git_refs)" "$pfx" "$cur"
359 __gitcomp "$(__git_refs)"
361 esac
364 __git_all_commands ()
366 if [ -n "$__git_all_commandlist" ]; then
367 echo "$__git_all_commandlist"
368 return
370 local i IFS=" "$'\n'
371 for i in $(git help -a|egrep '^ ')
373 case $i in
374 *--*) : helper pattern;;
375 *) echo $i;;
376 esac
377 done
379 __git_all_commandlist=
380 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
382 __git_porcelain_commands ()
384 if [ -n "$__git_porcelain_commandlist" ]; then
385 echo "$__git_porcelain_commandlist"
386 return
388 local i IFS=" "$'\n'
389 for i in "help" $(__git_all_commands)
391 case $i in
392 *--*) : helper pattern;;
393 applymbox) : ask gittus;;
394 applypatch) : ask gittus;;
395 archimport) : import;;
396 cat-file) : plumbing;;
397 check-attr) : plumbing;;
398 check-ref-format) : plumbing;;
399 checkout-index) : plumbing;;
400 commit-tree) : plumbing;;
401 count-objects) : infrequent;;
402 cvsexportcommit) : export;;
403 cvsimport) : import;;
404 cvsserver) : daemon;;
405 daemon) : daemon;;
406 diff-files) : plumbing;;
407 diff-index) : plumbing;;
408 diff-tree) : plumbing;;
409 fast-import) : import;;
410 fast-export) : export;;
411 fsck-objects) : plumbing;;
412 fetch-pack) : plumbing;;
413 fmt-merge-msg) : plumbing;;
414 for-each-ref) : plumbing;;
415 hash-object) : plumbing;;
416 http-*) : transport;;
417 index-pack) : plumbing;;
418 init-db) : deprecated;;
419 local-fetch) : plumbing;;
420 lost-found) : infrequent;;
421 ls-files) : plumbing;;
422 ls-remote) : plumbing;;
423 ls-tree) : plumbing;;
424 mailinfo) : plumbing;;
425 mailsplit) : plumbing;;
426 merge-*) : plumbing;;
427 mktree) : plumbing;;
428 mktag) : plumbing;;
429 pack-objects) : plumbing;;
430 pack-redundant) : plumbing;;
431 pack-refs) : plumbing;;
432 parse-remote) : plumbing;;
433 patch-id) : plumbing;;
434 peek-remote) : plumbing;;
435 prune) : plumbing;;
436 prune-packed) : plumbing;;
437 quiltimport) : import;;
438 read-tree) : plumbing;;
439 receive-pack) : plumbing;;
440 reflog) : plumbing;;
441 repo-config) : deprecated;;
442 rerere) : plumbing;;
443 rev-list) : plumbing;;
444 rev-parse) : plumbing;;
445 runstatus) : plumbing;;
446 sh-setup) : internal;;
447 shell) : daemon;;
448 show-ref) : plumbing;;
449 send-pack) : plumbing;;
450 show-index) : plumbing;;
451 ssh-*) : transport;;
452 stripspace) : plumbing;;
453 symbolic-ref) : plumbing;;
454 tar-tree) : deprecated;;
455 unpack-file) : plumbing;;
456 unpack-objects) : plumbing;;
457 update-index) : plumbing;;
458 update-ref) : plumbing;;
459 update-server-info) : daemon;;
460 upload-archive) : plumbing;;
461 upload-pack) : plumbing;;
462 write-tree) : plumbing;;
463 var) : infrequent;;
464 verify-pack) : infrequent;;
465 verify-tag) : plumbing;;
466 *) echo $i;;
467 esac
468 done
470 __git_porcelain_commandlist=
471 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
473 __git_aliases ()
475 local i IFS=$'\n'
476 for i in $(git --git-dir="$(__gitdir)" config --list); do
477 case "$i" in
478 alias.*)
479 i="${i#alias.}"
480 echo "${i/=*/}"
482 esac
483 done
486 # __git_aliased_command requires 1 argument
487 __git_aliased_command ()
489 local word cmdline=$(git --git-dir="$(__gitdir)" \
490 config --get "alias.$1")
491 for word in $cmdline; do
492 if [ "${word##-*}" ]; then
493 echo $word
494 return
496 done
499 # __git_find_subcommand requires 1 argument
500 __git_find_subcommand ()
502 local word subcommand c=1
504 while [ $c -lt $COMP_CWORD ]; do
505 word="${COMP_WORDS[c]}"
506 for subcommand in $1; do
507 if [ "$subcommand" = "$word" ]; then
508 echo "$subcommand"
509 return
511 done
512 c=$((++c))
513 done
516 __git_has_doubledash ()
518 local c=1
519 while [ $c -lt $COMP_CWORD ]; do
520 if [ "--" = "${COMP_WORDS[c]}" ]; then
521 return 0
523 c=$((++c))
524 done
525 return 1
528 __git_whitespacelist="nowarn warn error error-all fix"
530 _git_am ()
532 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
533 if [ -d "$dir"/rebase-apply ]; then
534 __gitcomp "--skip --resolved --abort"
535 return
537 case "$cur" in
538 --whitespace=*)
539 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
540 return
542 --*)
543 __gitcomp "
544 --signoff --utf8 --binary --3way --interactive
545 --whitespace=
547 return
548 esac
549 COMPREPLY=()
552 _git_apply ()
554 local cur="${COMP_WORDS[COMP_CWORD]}"
555 case "$cur" in
556 --whitespace=*)
557 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
558 return
560 --*)
561 __gitcomp "
562 --stat --numstat --summary --check --index
563 --cached --index-info --reverse --reject --unidiff-zero
564 --apply --no-add --exclude=
565 --whitespace= --inaccurate-eof --verbose
567 return
568 esac
569 COMPREPLY=()
572 _git_add ()
574 __git_has_doubledash && return
576 local cur="${COMP_WORDS[COMP_CWORD]}"
577 case "$cur" in
578 --*)
579 __gitcomp "
580 --interactive --refresh --patch --update --dry-run
581 --ignore-errors --intent-to-add
583 return
584 esac
585 COMPREPLY=()
588 _git_archive ()
590 local cur="${COMP_WORDS[COMP_CWORD]}"
591 case "$cur" in
592 --format=*)
593 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
594 return
596 --remote=*)
597 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
598 return
600 --*)
601 __gitcomp "
602 --format= --list --verbose
603 --prefix= --remote= --exec=
605 return
607 esac
608 __git_complete_file
611 _git_bisect ()
613 __git_has_doubledash && return
615 local subcommands="start bad good skip reset visualize replay log run"
616 local subcommand="$(__git_find_subcommand "$subcommands")"
617 if [ -z "$subcommand" ]; then
618 __gitcomp "$subcommands"
619 return
622 case "$subcommand" in
623 bad|good|reset|skip)
624 __gitcomp "$(__git_refs)"
627 COMPREPLY=()
629 esac
632 _git_branch ()
634 local i c=1 only_local_ref="n" has_r="n"
636 while [ $c -lt $COMP_CWORD ]; do
637 i="${COMP_WORDS[c]}"
638 case "$i" in
639 -d|-m) only_local_ref="y" ;;
640 -r) has_r="y" ;;
641 esac
642 c=$((++c))
643 done
645 case "${COMP_WORDS[COMP_CWORD]}" in
646 --*)
647 __gitcomp "
648 --color --no-color --verbose --abbrev= --no-abbrev
649 --track --no-track --contains --merged --no-merged
653 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
654 __gitcomp "$(__git_heads)"
655 else
656 __gitcomp "$(__git_refs)"
659 esac
662 _git_bundle ()
664 local cmd="${COMP_WORDS[2]}"
665 case "$COMP_CWORD" in
667 __gitcomp "create list-heads verify unbundle"
670 # looking for a file
673 case "$cmd" in
674 create)
675 __git_complete_revlist
677 esac
679 esac
682 _git_checkout ()
684 __git_has_doubledash && return
686 __gitcomp "$(__git_refs)"
689 _git_cherry ()
691 __gitcomp "$(__git_refs)"
694 _git_cherry_pick ()
696 local cur="${COMP_WORDS[COMP_CWORD]}"
697 case "$cur" in
698 --*)
699 __gitcomp "--edit --no-commit"
702 __gitcomp "$(__git_refs)"
704 esac
707 _git_clean ()
709 __git_has_doubledash && return
711 local cur="${COMP_WORDS[COMP_CWORD]}"
712 case "$cur" in
713 --*)
714 __gitcomp "--dry-run --quiet"
715 return
717 esac
718 COMPREPLY=()
721 _git_clone ()
723 local cur="${COMP_WORDS[COMP_CWORD]}"
724 case "$cur" in
725 --*)
726 __gitcomp "
727 --local
728 --no-hardlinks
729 --shared
730 --reference
731 --quiet
732 --no-checkout
733 --bare
734 --mirror
735 --origin
736 --upload-pack
737 --template=
738 --depth
740 return
742 esac
743 COMPREPLY=()
746 _git_commit ()
748 __git_has_doubledash && return
750 local cur="${COMP_WORDS[COMP_CWORD]}"
751 case "$cur" in
752 --*)
753 __gitcomp "
754 --all --author= --signoff --verify --no-verify
755 --edit --amend --include --only --interactive
757 return
758 esac
759 COMPREPLY=()
762 _git_describe ()
764 local cur="${COMP_WORDS[COMP_CWORD]}"
765 case "$cur" in
766 --*)
767 __gitcomp "
768 --all --tags --contains --abbrev= --candidates=
769 --exact-match --debug --long --match --always
771 return
772 esac
773 __gitcomp "$(__git_refs)"
776 _git_diff ()
778 __git_has_doubledash && return
780 local cur="${COMP_WORDS[COMP_CWORD]}"
781 case "$cur" in
782 --*)
783 __gitcomp "--cached --stat --numstat --shortstat --summary
784 --patch-with-stat --name-only --name-status --color
785 --no-color --color-words --no-renames --check
786 --full-index --binary --abbrev --diff-filter=
787 --find-copies-harder --pickaxe-all --pickaxe-regex
788 --text --ignore-space-at-eol --ignore-space-change
789 --ignore-all-space --exit-code --quiet --ext-diff
790 --no-ext-diff
791 --no-prefix --src-prefix= --dst-prefix=
792 --base --ours --theirs
793 --inter-hunk-context=
795 return
797 esac
798 __git_complete_file
801 _git_fetch ()
803 local cur="${COMP_WORDS[COMP_CWORD]}"
805 if [ "$COMP_CWORD" = 2 ]; then
806 __gitcomp "$(__git_remotes)"
807 else
808 case "$cur" in
809 *:*)
810 local pfx=""
811 case "$COMP_WORDBREAKS" in
812 *:*) : great ;;
813 *) pfx="${cur%%:*}:" ;;
814 esac
815 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
818 __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
820 esac
824 _git_format_patch ()
826 local cur="${COMP_WORDS[COMP_CWORD]}"
827 case "$cur" in
828 --*)
829 __gitcomp "
830 --stdout --attach --thread
831 --output-directory
832 --numbered --start-number
833 --numbered-files
834 --keep-subject
835 --signoff
836 --in-reply-to=
837 --full-index --binary
838 --not --all
839 --cover-letter
840 --no-prefix --src-prefix= --dst-prefix=
842 return
844 esac
845 __git_complete_revlist
848 _git_gc ()
850 local cur="${COMP_WORDS[COMP_CWORD]}"
851 case "$cur" in
852 --*)
853 __gitcomp "--prune --aggressive"
854 return
856 esac
857 COMPREPLY=()
860 _git_grep ()
862 __git_has_doubledash && return
864 local cur="${COMP_WORDS[COMP_CWORD]}"
865 case "$cur" in
866 --*)
867 __gitcomp "
868 --cached
869 --text --ignore-case --word-regexp --invert-match
870 --full-name
871 --extended-regexp --basic-regexp --fixed-strings
872 --files-with-matches --name-only
873 --files-without-match
874 --count
875 --and --or --not --all-match
877 return
879 esac
880 COMPREPLY=()
883 _git_help ()
885 local cur="${COMP_WORDS[COMP_CWORD]}"
886 case "$cur" in
887 --*)
888 __gitcomp "--all --info --man --web"
889 return
891 esac
892 __gitcomp "$(__git_all_commands)
893 attributes cli core-tutorial cvs-migration
894 diffcore gitk glossary hooks ignore modules
895 repository-layout tutorial tutorial-2
896 workflows
900 _git_init ()
902 local cur="${COMP_WORDS[COMP_CWORD]}"
903 case "$cur" in
904 --shared=*)
905 __gitcomp "
906 false true umask group all world everybody
907 " "" "${cur##--shared=}"
908 return
910 --*)
911 __gitcomp "--quiet --bare --template= --shared --shared="
912 return
914 esac
915 COMPREPLY=()
918 _git_ls_files ()
920 __git_has_doubledash && return
922 local cur="${COMP_WORDS[COMP_CWORD]}"
923 case "$cur" in
924 --*)
925 __gitcomp "--cached --deleted --modified --others --ignored
926 --stage --directory --no-empty-directory --unmerged
927 --killed --exclude= --exclude-from=
928 --exclude-per-directory= --exclude-standard
929 --error-unmatch --with-tree= --full-name
930 --abbrev --ignored --exclude-per-directory
932 return
934 esac
935 COMPREPLY=()
938 _git_ls_remote ()
940 __gitcomp "$(__git_remotes)"
943 _git_ls_tree ()
945 __git_complete_file
948 _git_log ()
950 __git_has_doubledash && return
952 local cur="${COMP_WORDS[COMP_CWORD]}"
953 case "$cur" in
954 --pretty=*)
955 __gitcomp "
956 oneline short medium full fuller email raw
957 " "" "${cur##--pretty=}"
958 return
960 --date=*)
961 __gitcomp "
962 relative iso8601 rfc2822 short local default
963 " "" "${cur##--date=}"
964 return
966 --*)
967 __gitcomp "
968 --max-count= --max-age= --since= --after=
969 --min-age= --before= --until=
970 --root --topo-order --date-order --reverse
971 --no-merges --follow
972 --abbrev-commit --abbrev=
973 --relative-date --date=
974 --author= --committer= --grep=
975 --all-match
976 --pretty= --name-status --name-only --raw
977 --not --all
978 --left-right --cherry-pick
979 --graph
980 --stat --numstat --shortstat
981 --decorate --diff-filter=
982 --color-words --walk-reflogs
983 --parents --children --full-history
984 --merge
985 --inter-hunk-context=
987 return
989 esac
990 __git_complete_revlist
993 _git_merge ()
995 local cur="${COMP_WORDS[COMP_CWORD]}"
996 case "${COMP_WORDS[COMP_CWORD-1]}" in
997 -s|--strategy)
998 __gitcomp "$(__git_merge_strategies)"
999 return
1000 esac
1001 case "$cur" in
1002 --strategy=*)
1003 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1004 return
1006 --*)
1007 __gitcomp "
1008 --no-commit --no-stat --log --no-log --squash --strategy
1010 return
1011 esac
1012 __gitcomp "$(__git_refs)"
1015 _git_mergetool ()
1017 local cur="${COMP_WORDS[COMP_CWORD]}"
1018 case "$cur" in
1019 --tool=*)
1020 __gitcomp "
1021 kdiff3 tkdiff meld xxdiff emerge
1022 vimdiff gvimdiff ecmerge opendiff
1023 " "" "${cur##--tool=}"
1024 return
1026 --*)
1027 __gitcomp "--tool="
1028 return
1030 esac
1031 COMPREPLY=()
1034 _git_merge_base ()
1036 __gitcomp "$(__git_refs)"
1039 _git_mv ()
1041 local cur="${COMP_WORDS[COMP_CWORD]}"
1042 case "$cur" in
1043 --*)
1044 __gitcomp "--dry-run"
1045 return
1047 esac
1048 COMPREPLY=()
1051 _git_name_rev ()
1053 __gitcomp "--tags --all --stdin"
1056 _git_pull ()
1058 local cur="${COMP_WORDS[COMP_CWORD]}"
1060 if [ "$COMP_CWORD" = 2 ]; then
1061 __gitcomp "$(__git_remotes)"
1062 else
1063 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1067 _git_push ()
1069 local cur="${COMP_WORDS[COMP_CWORD]}"
1071 if [ "$COMP_CWORD" = 2 ]; then
1072 __gitcomp "$(__git_remotes)"
1073 else
1074 case "$cur" in
1075 *:*)
1076 local pfx=""
1077 case "$COMP_WORDBREAKS" in
1078 *:*) : great ;;
1079 *) pfx="${cur%%:*}:" ;;
1080 esac
1082 __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1085 __gitcomp "$(__git_refs)" + "${cur#+}"
1088 __gitcomp "$(__git_refs)"
1090 esac
1094 _git_rebase ()
1096 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1097 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1098 __gitcomp "--continue --skip --abort"
1099 return
1101 case "${COMP_WORDS[COMP_CWORD-1]}" in
1102 -s|--strategy)
1103 __gitcomp "$(__git_merge_strategies)"
1104 return
1105 esac
1106 case "$cur" in
1107 --strategy=*)
1108 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1109 return
1111 --*)
1112 __gitcomp "--onto --merge --strategy --interactive"
1113 return
1114 esac
1115 __gitcomp "$(__git_refs)"
1118 _git_send_email ()
1120 local cur="${COMP_WORDS[COMP_CWORD]}"
1121 case "$cur" in
1122 --*)
1123 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1124 --dry-run --envelope-sender --from --identity
1125 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1126 --no-suppress-from --no-thread --quiet
1127 --signed-off-by-cc --smtp-pass --smtp-server
1128 --smtp-server-port --smtp-ssl --smtp-user --subject
1129 --suppress-cc --suppress-from --thread --to
1130 --validate --no-validate"
1131 return
1133 esac
1134 COMPREPLY=()
1137 _git_config ()
1139 local cur="${COMP_WORDS[COMP_CWORD]}"
1140 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1141 case "$prv" in
1142 branch.*.remote)
1143 __gitcomp "$(__git_remotes)"
1144 return
1146 branch.*.merge)
1147 __gitcomp "$(__git_refs)"
1148 return
1150 remote.*.fetch)
1151 local remote="${prv#remote.}"
1152 remote="${remote%.fetch}"
1153 __gitcomp "$(__git_refs_remotes "$remote")"
1154 return
1156 remote.*.push)
1157 local remote="${prv#remote.}"
1158 remote="${remote%.push}"
1159 __gitcomp "$(git --git-dir="$(__gitdir)" \
1160 for-each-ref --format='%(refname):%(refname)' \
1161 refs/heads)"
1162 return
1164 pull.twohead|pull.octopus)
1165 __gitcomp "$(__git_merge_strategies)"
1166 return
1168 color.branch|color.diff|color.status)
1169 __gitcomp "always never auto"
1170 return
1172 color.*.*)
1173 __gitcomp "
1174 normal black red green yellow blue magenta cyan white
1175 bold dim ul blink reverse
1177 return
1179 *.*)
1180 COMPREPLY=()
1181 return
1183 esac
1184 case "$cur" in
1185 --*)
1186 __gitcomp "
1187 --global --system --file=
1188 --list --replace-all
1189 --get --get-all --get-regexp
1190 --add --unset --unset-all
1191 --remove-section --rename-section
1193 return
1195 branch.*.*)
1196 local pfx="${cur%.*}."
1197 cur="${cur##*.}"
1198 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1199 return
1201 branch.*)
1202 local pfx="${cur%.*}."
1203 cur="${cur#*.}"
1204 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1205 return
1207 remote.*.*)
1208 local pfx="${cur%.*}."
1209 cur="${cur##*.}"
1210 __gitcomp "
1211 url proxy fetch push mirror skipDefaultUpdate
1212 receivepack uploadpack tagopt
1213 " "$pfx" "$cur"
1214 return
1216 remote.*)
1217 local pfx="${cur%.*}."
1218 cur="${cur#*.}"
1219 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1220 return
1222 esac
1223 __gitcomp "
1224 apply.whitespace
1225 branch.autosetupmerge
1226 branch.autosetuprebase
1227 clean.requireForce
1228 color.branch
1229 color.branch.current
1230 color.branch.local
1231 color.branch.plain
1232 color.branch.remote
1233 color.diff
1234 color.diff.commit
1235 color.diff.frag
1236 color.diff.meta
1237 color.diff.new
1238 color.diff.old
1239 color.diff.plain
1240 color.diff.whitespace
1241 color.interactive
1242 color.interactive.header
1243 color.interactive.help
1244 color.interactive.prompt
1245 color.pager
1246 color.status
1247 color.status.added
1248 color.status.changed
1249 color.status.header
1250 color.status.nobranch
1251 color.status.untracked
1252 color.status.updated
1253 color.ui
1254 commit.template
1255 core.autocrlf
1256 core.bare
1257 core.compression
1258 core.deltaBaseCacheLimit
1259 core.editor
1260 core.excludesfile
1261 core.fileMode
1262 core.fsyncobjectfiles
1263 core.gitProxy
1264 core.ignoreCygwinFSTricks
1265 core.ignoreStat
1266 core.logAllRefUpdates
1267 core.loosecompression
1268 core.packedGitLimit
1269 core.packedGitWindowSize
1270 core.pager
1271 core.preferSymlinkRefs
1272 core.preloadindex
1273 core.quotepath
1274 core.repositoryFormatVersion
1275 core.safecrlf
1276 core.sharedRepository
1277 core.symlinks
1278 core.trustctime
1279 core.warnAmbiguousRefs
1280 core.whitespace
1281 core.worktree
1282 diff.autorefreshindex
1283 diff.external
1284 diff.mnemonicprefix
1285 diff.renameLimit
1286 diff.renameLimit.
1287 diff.renames
1288 fetch.unpackLimit
1289 format.headers
1290 format.numbered
1291 format.pretty
1292 format.suffix
1293 gc.aggressiveWindow
1294 gc.auto
1295 gc.autopacklimit
1296 gc.packrefs
1297 gc.pruneexpire
1298 gc.reflogexpire
1299 gc.reflogexpireunreachable
1300 gc.rerereresolved
1301 gc.rerereunresolved
1302 gitcvs.allbinary
1303 gitcvs.dbTableNamePrefix
1304 gitcvs.dbdriver
1305 gitcvs.dbname
1306 gitcvs.dbpass
1307 gitcvs.dbuser
1308 gitcvs.enabled
1309 gitcvs.logfile
1310 gitcvs.usecrlfattr
1311 gui.blamehistoryctx
1312 gui.commitmsgwidth
1313 gui.copyblamethreshold
1314 gui.diffcontext
1315 gui.encoding
1316 gui.fastcopyblame
1317 gui.matchtrackingbranch
1318 gui.newbranchtemplate
1319 gui.pruneduringfetch
1320 gui.spellingdictionary
1321 gui.trustmtime
1322 help.autocorrect
1323 help.browser
1324 help.format
1325 http.lowSpeedLimit
1326 http.lowSpeedTime
1327 http.maxRequests
1328 http.noEPSV
1329 http.proxy
1330 http.sslCAInfo
1331 http.sslCAPath
1332 http.sslCert
1333 http.sslKey
1334 http.sslVerify
1335 i18n.commitEncoding
1336 i18n.logOutputEncoding
1337 instaweb.browser
1338 instaweb.httpd
1339 instaweb.local
1340 instaweb.modulepath
1341 instaweb.port
1342 log.date
1343 log.showroot
1344 man.viewer
1345 merge.conflictstyle
1346 merge.log
1347 merge.renameLimit
1348 merge.stat
1349 merge.tool
1350 merge.verbosity
1351 mergetool.keepBackup
1352 pack.compression
1353 pack.deltaCacheLimit
1354 pack.deltaCacheSize
1355 pack.depth
1356 pack.indexVersion
1357 pack.packSizeLimit
1358 pack.threads
1359 pack.window
1360 pack.windowMemory
1361 pull.octopus
1362 pull.twohead
1363 receive.denyCurrentBranch
1364 receive.denyDeletes
1365 receive.denyNonFastForwards
1366 receive.fsckObjects
1367 receive.unpackLimit
1368 repack.usedeltabaseoffset
1369 rerere.autoupdate
1370 rerere.enabled
1371 showbranch.default
1372 status.relativePaths
1373 status.showUntrackedFiles
1374 tar.umask
1375 transfer.unpackLimit
1376 user.email
1377 user.name
1378 user.signingkey
1379 web.browser
1380 branch. remote.
1384 _git_remote ()
1386 local subcommands="add rm show prune update"
1387 local subcommand="$(__git_find_subcommand "$subcommands")"
1388 if [ -z "$subcommand" ]; then
1389 __gitcomp "$subcommands"
1390 return
1393 case "$subcommand" in
1394 rm|show|prune)
1395 __gitcomp "$(__git_remotes)"
1397 update)
1398 local i c='' IFS=$'\n'
1399 for i in $(git --git-dir="$(__gitdir)" config --list); do
1400 case "$i" in
1401 remotes.*)
1402 i="${i#remotes.}"
1403 c="$c ${i/=*/}"
1405 esac
1406 done
1407 __gitcomp "$c"
1410 COMPREPLY=()
1412 esac
1415 _git_reset ()
1417 __git_has_doubledash && return
1419 local cur="${COMP_WORDS[COMP_CWORD]}"
1420 case "$cur" in
1421 --*)
1422 __gitcomp "--merge --mixed --hard --soft"
1423 return
1425 esac
1426 __gitcomp "$(__git_refs)"
1429 _git_revert ()
1431 local cur="${COMP_WORDS[COMP_CWORD]}"
1432 case "$cur" in
1433 --*)
1434 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1435 return
1437 esac
1438 __gitcomp "$(__git_refs)"
1441 _git_rm ()
1443 __git_has_doubledash && return
1445 local cur="${COMP_WORDS[COMP_CWORD]}"
1446 case "$cur" in
1447 --*)
1448 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1449 return
1451 esac
1452 COMPREPLY=()
1455 _git_shortlog ()
1457 __git_has_doubledash && return
1459 local cur="${COMP_WORDS[COMP_CWORD]}"
1460 case "$cur" in
1461 --*)
1462 __gitcomp "
1463 --max-count= --max-age= --since= --after=
1464 --min-age= --before= --until=
1465 --no-merges
1466 --author= --committer= --grep=
1467 --all-match
1468 --not --all
1469 --numbered --summary
1471 return
1473 esac
1474 __git_complete_revlist
1477 _git_show ()
1479 __git_has_doubledash && return
1481 local cur="${COMP_WORDS[COMP_CWORD]}"
1482 case "$cur" in
1483 --pretty=*)
1484 __gitcomp "
1485 oneline short medium full fuller email raw
1486 " "" "${cur##--pretty=}"
1487 return
1489 --*)
1490 __gitcomp "--pretty="
1491 return
1493 esac
1494 __git_complete_file
1497 _git_show_branch ()
1499 local cur="${COMP_WORDS[COMP_CWORD]}"
1500 case "$cur" in
1501 --*)
1502 __gitcomp "
1503 --all --remotes --topo-order --current --more=
1504 --list --independent --merge-base --no-name
1505 --sha1-name --topics --reflog
1507 return
1509 esac
1510 __git_complete_revlist
1513 _git_stash ()
1515 local subcommands='save list show apply clear drop pop create branch'
1516 local subcommand="$(__git_find_subcommand "$subcommands")"
1517 if [ -z "$subcommand" ]; then
1518 __gitcomp "$subcommands"
1519 else
1520 local cur="${COMP_WORDS[COMP_CWORD]}"
1521 case "$subcommand,$cur" in
1522 save,--*)
1523 __gitcomp "--keep-index"
1525 apply,--*)
1526 __gitcomp "--index"
1528 show,--*|drop,--*|pop,--*|branch,--*)
1529 COMPREPLY=()
1531 show,*|apply,*|drop,*|pop,*|branch,*)
1532 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1533 | sed -n -e 's/:.*//p')"
1536 COMPREPLY=()
1538 esac
1542 _git_submodule ()
1544 __git_has_doubledash && return
1546 local subcommands="add status init update summary foreach sync"
1547 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1548 local cur="${COMP_WORDS[COMP_CWORD]}"
1549 case "$cur" in
1550 --*)
1551 __gitcomp "--quiet --cached"
1554 __gitcomp "$subcommands"
1556 esac
1557 return
1561 _git_svn ()
1563 local subcommands="
1564 init fetch clone rebase dcommit log find-rev
1565 set-tree commit-diff info create-ignore propget
1566 proplist show-ignore show-externals
1568 local subcommand="$(__git_find_subcommand "$subcommands")"
1569 if [ -z "$subcommand" ]; then
1570 __gitcomp "$subcommands"
1571 else
1572 local remote_opts="--username= --config-dir= --no-auth-cache"
1573 local fc_opts="
1574 --follow-parent --authors-file= --repack=
1575 --no-metadata --use-svm-props --use-svnsync-props
1576 --log-window-size= --no-checkout --quiet
1577 --repack-flags --user-log-author $remote_opts
1579 local init_opts="
1580 --template= --shared= --trunk= --tags=
1581 --branches= --stdlayout --minimize-url
1582 --no-metadata --use-svm-props --use-svnsync-props
1583 --rewrite-root= $remote_opts
1585 local cmt_opts="
1586 --edit --rmdir --find-copies-harder --copy-similarity=
1589 local cur="${COMP_WORDS[COMP_CWORD]}"
1590 case "$subcommand,$cur" in
1591 fetch,--*)
1592 __gitcomp "--revision= --fetch-all $fc_opts"
1594 clone,--*)
1595 __gitcomp "--revision= $fc_opts $init_opts"
1597 init,--*)
1598 __gitcomp "$init_opts"
1600 dcommit,--*)
1601 __gitcomp "
1602 --merge --strategy= --verbose --dry-run
1603 --fetch-all --no-rebase $cmt_opts $fc_opts
1606 set-tree,--*)
1607 __gitcomp "--stdin $cmt_opts $fc_opts"
1609 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1610 show-externals,--*)
1611 __gitcomp "--revision="
1613 log,--*)
1614 __gitcomp "
1615 --limit= --revision= --verbose --incremental
1616 --oneline --show-commit --non-recursive
1617 --authors-file=
1620 rebase,--*)
1621 __gitcomp "
1622 --merge --verbose --strategy= --local
1623 --fetch-all $fc_opts
1626 commit-diff,--*)
1627 __gitcomp "--message= --file= --revision= $cmt_opts"
1629 info,--*)
1630 __gitcomp "--url"
1633 COMPREPLY=()
1635 esac
1639 _git_tag ()
1641 local i c=1 f=0
1642 while [ $c -lt $COMP_CWORD ]; do
1643 i="${COMP_WORDS[c]}"
1644 case "$i" in
1645 -d|-v)
1646 __gitcomp "$(__git_tags)"
1647 return
1652 esac
1653 c=$((++c))
1654 done
1656 case "${COMP_WORDS[COMP_CWORD-1]}" in
1657 -m|-F)
1658 COMPREPLY=()
1660 -*|tag)
1661 if [ $f = 1 ]; then
1662 __gitcomp "$(__git_tags)"
1663 else
1664 COMPREPLY=()
1668 __gitcomp "$(__git_refs)"
1670 esac
1673 _git ()
1675 local i c=1 command __git_dir
1677 while [ $c -lt $COMP_CWORD ]; do
1678 i="${COMP_WORDS[c]}"
1679 case "$i" in
1680 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1681 --bare) __git_dir="." ;;
1682 --version|-p|--paginate) ;;
1683 --help) command="help"; break ;;
1684 *) command="$i"; break ;;
1685 esac
1686 c=$((++c))
1687 done
1689 if [ -z "$command" ]; then
1690 case "${COMP_WORDS[COMP_CWORD]}" in
1691 --*) __gitcomp "
1692 --paginate
1693 --no-pager
1694 --git-dir=
1695 --bare
1696 --version
1697 --exec-path
1698 --work-tree=
1699 --help
1702 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1703 esac
1704 return
1707 local expansion=$(__git_aliased_command "$command")
1708 [ "$expansion" ] && command="$expansion"
1710 case "$command" in
1711 am) _git_am ;;
1712 add) _git_add ;;
1713 apply) _git_apply ;;
1714 archive) _git_archive ;;
1715 bisect) _git_bisect ;;
1716 bundle) _git_bundle ;;
1717 branch) _git_branch ;;
1718 checkout) _git_checkout ;;
1719 cherry) _git_cherry ;;
1720 cherry-pick) _git_cherry_pick ;;
1721 clean) _git_clean ;;
1722 clone) _git_clone ;;
1723 commit) _git_commit ;;
1724 config) _git_config ;;
1725 describe) _git_describe ;;
1726 diff) _git_diff ;;
1727 fetch) _git_fetch ;;
1728 format-patch) _git_format_patch ;;
1729 gc) _git_gc ;;
1730 grep) _git_grep ;;
1731 help) _git_help ;;
1732 init) _git_init ;;
1733 log) _git_log ;;
1734 ls-files) _git_ls_files ;;
1735 ls-remote) _git_ls_remote ;;
1736 ls-tree) _git_ls_tree ;;
1737 merge) _git_merge;;
1738 mergetool) _git_mergetool;;
1739 merge-base) _git_merge_base ;;
1740 mv) _git_mv ;;
1741 name-rev) _git_name_rev ;;
1742 pull) _git_pull ;;
1743 push) _git_push ;;
1744 rebase) _git_rebase ;;
1745 remote) _git_remote ;;
1746 reset) _git_reset ;;
1747 revert) _git_revert ;;
1748 rm) _git_rm ;;
1749 send-email) _git_send_email ;;
1750 shortlog) _git_shortlog ;;
1751 show) _git_show ;;
1752 show-branch) _git_show_branch ;;
1753 stash) _git_stash ;;
1754 stage) _git_add ;;
1755 submodule) _git_submodule ;;
1756 svn) _git_svn ;;
1757 tag) _git_tag ;;
1758 whatchanged) _git_log ;;
1759 *) COMPREPLY=() ;;
1760 esac
1763 _gitk ()
1765 __git_has_doubledash && return
1767 local cur="${COMP_WORDS[COMP_CWORD]}"
1768 local g="$(git rev-parse --git-dir 2>/dev/null)"
1769 local merge=""
1770 if [ -f $g/MERGE_HEAD ]; then
1771 merge="--merge"
1773 case "$cur" in
1774 --*)
1775 __gitcomp "--not --all $merge"
1776 return
1778 esac
1779 __git_complete_revlist
1782 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
1783 || complete -o default -o nospace -F _git git
1784 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
1785 || complete -o default -o nospace -F _gitk gitk
1787 # The following are necessary only for Cygwin, and only are needed
1788 # when the user has tab-completed the executable name and consequently
1789 # included the '.exe' suffix.
1791 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1792 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
1793 || complete -o default -o nospace -F _git git.exe