Merge branch 'maint'
[git/mingw.git] / contrib / completion / git-completion.bash
blob15073d4c9fbccb06e9b17dff4a8d134e805aed6d
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 cmd i is_hash=y dir="$(__gitdir "$1")"
192 if [ -d "$dir" ]; then
193 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
194 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
195 refs/tags refs/heads refs/remotes
196 return
198 for i in $(git ls-remote "$dir" 2>/dev/null); do
199 case "$is_hash,$i" in
200 y,*) is_hash=n ;;
201 n,*^{}) is_hash=y ;;
202 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
203 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
204 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
205 n,*) is_hash=y; echo "$i" ;;
206 esac
207 done
210 __git_refs2 ()
212 local i
213 for i in $(__git_refs "$1"); do
214 echo "$i:$i"
215 done
218 __git_refs_remotes ()
220 local cmd i is_hash=y
221 for i in $(git ls-remote "$1" 2>/dev/null); do
222 case "$is_hash,$i" in
223 n,refs/heads/*)
224 is_hash=y
225 echo "$i:refs/remotes/$1/${i#refs/heads/}"
227 y,*) is_hash=n ;;
228 n,*^{}) is_hash=y ;;
229 n,refs/tags/*) is_hash=y;;
230 n,*) is_hash=y; ;;
231 esac
232 done
235 __git_remotes ()
237 local i ngoff IFS=$'\n' d="$(__gitdir)"
238 shopt -q nullglob || ngoff=1
239 shopt -s nullglob
240 for i in "$d/remotes"/*; do
241 echo ${i#$d/remotes/}
242 done
243 [ "$ngoff" ] && shopt -u nullglob
244 for i in $(git --git-dir="$d" config --list); do
245 case "$i" in
246 remote.*.url=*)
247 i="${i#remote.}"
248 echo "${i/.url=*/}"
250 esac
251 done
254 __git_merge_strategies ()
256 if [ -n "$__git_merge_strategylist" ]; then
257 echo "$__git_merge_strategylist"
258 return
260 git merge -s help 2>&1 |
261 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
262 s/\.$//
263 s/.*://
264 s/^[ ]*//
265 s/[ ]*$//
269 __git_merge_strategylist=
270 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
272 __git_complete_file ()
274 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
275 case "$cur" in
276 ?*:*)
277 ref="${cur%%:*}"
278 cur="${cur#*:}"
279 case "$cur" in
280 ?*/*)
281 pfx="${cur%/*}"
282 cur="${cur##*/}"
283 ls="$ref:$pfx"
284 pfx="$pfx/"
287 ls="$ref"
289 esac
291 case "$COMP_WORDBREAKS" in
292 *:*) : great ;;
293 *) pfx="$ref:$pfx" ;;
294 esac
296 local IFS=$'\n'
297 COMPREPLY=($(compgen -P "$pfx" \
298 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
299 | sed '/^100... blob /{
300 s,^.* ,,
301 s,$, ,
303 /^120000 blob /{
304 s,^.* ,,
305 s,$, ,
307 /^040000 tree /{
308 s,^.* ,,
309 s,$,/,
311 s/^.* //')" \
312 -- "$cur"))
315 __gitcomp "$(__git_refs)"
317 esac
320 __git_complete_revlist ()
322 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
323 case "$cur" in
324 *...*)
325 pfx="${cur%...*}..."
326 cur="${cur#*...}"
327 __gitcomp "$(__git_refs)" "$pfx" "$cur"
329 *..*)
330 pfx="${cur%..*}.."
331 cur="${cur#*..}"
332 __gitcomp "$(__git_refs)" "$pfx" "$cur"
335 __gitcomp "$(__git_refs)"
337 esac
340 __git_all_commands ()
342 if [ -n "$__git_all_commandlist" ]; then
343 echo "$__git_all_commandlist"
344 return
346 local i IFS=" "$'\n'
347 for i in $(git help -a|egrep '^ ')
349 case $i in
350 *--*) : helper pattern;;
351 *) echo $i;;
352 esac
353 done
355 __git_all_commandlist=
356 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
358 __git_porcelain_commands ()
360 if [ -n "$__git_porcelain_commandlist" ]; then
361 echo "$__git_porcelain_commandlist"
362 return
364 local i IFS=" "$'\n'
365 for i in "help" $(__git_all_commands)
367 case $i in
368 *--*) : helper pattern;;
369 applymbox) : ask gittus;;
370 applypatch) : ask gittus;;
371 archimport) : import;;
372 cat-file) : plumbing;;
373 check-attr) : plumbing;;
374 check-ref-format) : plumbing;;
375 checkout-index) : plumbing;;
376 commit-tree) : plumbing;;
377 count-objects) : infrequent;;
378 cvsexportcommit) : export;;
379 cvsimport) : import;;
380 cvsserver) : daemon;;
381 daemon) : daemon;;
382 diff-files) : plumbing;;
383 diff-index) : plumbing;;
384 diff-tree) : plumbing;;
385 fast-import) : import;;
386 fast-export) : export;;
387 fsck-objects) : plumbing;;
388 fetch-pack) : plumbing;;
389 fmt-merge-msg) : plumbing;;
390 for-each-ref) : plumbing;;
391 hash-object) : plumbing;;
392 http-*) : transport;;
393 index-pack) : plumbing;;
394 init-db) : deprecated;;
395 local-fetch) : plumbing;;
396 lost-found) : infrequent;;
397 ls-files) : plumbing;;
398 ls-remote) : plumbing;;
399 ls-tree) : plumbing;;
400 mailinfo) : plumbing;;
401 mailsplit) : plumbing;;
402 merge-*) : plumbing;;
403 mktree) : plumbing;;
404 mktag) : plumbing;;
405 pack-objects) : plumbing;;
406 pack-redundant) : plumbing;;
407 pack-refs) : plumbing;;
408 parse-remote) : plumbing;;
409 patch-id) : plumbing;;
410 peek-remote) : plumbing;;
411 prune) : plumbing;;
412 prune-packed) : plumbing;;
413 quiltimport) : import;;
414 read-tree) : plumbing;;
415 receive-pack) : plumbing;;
416 reflog) : plumbing;;
417 repo-config) : deprecated;;
418 rerere) : plumbing;;
419 rev-list) : plumbing;;
420 rev-parse) : plumbing;;
421 runstatus) : plumbing;;
422 sh-setup) : internal;;
423 shell) : daemon;;
424 show-ref) : plumbing;;
425 send-pack) : plumbing;;
426 show-index) : plumbing;;
427 ssh-*) : transport;;
428 stripspace) : plumbing;;
429 symbolic-ref) : plumbing;;
430 tar-tree) : deprecated;;
431 unpack-file) : plumbing;;
432 unpack-objects) : plumbing;;
433 update-index) : plumbing;;
434 update-ref) : plumbing;;
435 update-server-info) : daemon;;
436 upload-archive) : plumbing;;
437 upload-pack) : plumbing;;
438 write-tree) : plumbing;;
439 var) : infrequent;;
440 verify-pack) : infrequent;;
441 verify-tag) : plumbing;;
442 *) echo $i;;
443 esac
444 done
446 __git_porcelain_commandlist=
447 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
449 __git_aliases ()
451 local i IFS=$'\n'
452 for i in $(git --git-dir="$(__gitdir)" config --list); do
453 case "$i" in
454 alias.*)
455 i="${i#alias.}"
456 echo "${i/=*/}"
458 esac
459 done
462 __git_aliased_command ()
464 local word cmdline=$(git --git-dir="$(__gitdir)" \
465 config --get "alias.$1")
466 for word in $cmdline; do
467 if [ "${word##-*}" ]; then
468 echo $word
469 return
471 done
474 __git_find_subcommand ()
476 local word subcommand c=1
478 while [ $c -lt $COMP_CWORD ]; do
479 word="${COMP_WORDS[c]}"
480 for subcommand in $1; do
481 if [ "$subcommand" = "$word" ]; then
482 echo "$subcommand"
483 return
485 done
486 c=$((++c))
487 done
490 __git_has_doubledash ()
492 local c=1
493 while [ $c -lt $COMP_CWORD ]; do
494 if [ "--" = "${COMP_WORDS[c]}" ]; then
495 return 0
497 c=$((++c))
498 done
499 return 1
502 __git_whitespacelist="nowarn warn error error-all fix"
504 _git_am ()
506 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
507 if [ -d "$dir"/rebase-apply ]; then
508 __gitcomp "--skip --resolved --abort"
509 return
511 case "$cur" in
512 --whitespace=*)
513 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
514 return
516 --*)
517 __gitcomp "
518 --signoff --utf8 --binary --3way --interactive
519 --whitespace=
521 return
522 esac
523 COMPREPLY=()
526 _git_apply ()
528 local cur="${COMP_WORDS[COMP_CWORD]}"
529 case "$cur" in
530 --whitespace=*)
531 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
532 return
534 --*)
535 __gitcomp "
536 --stat --numstat --summary --check --index
537 --cached --index-info --reverse --reject --unidiff-zero
538 --apply --no-add --exclude=
539 --whitespace= --inaccurate-eof --verbose
541 return
542 esac
543 COMPREPLY=()
546 _git_add ()
548 __git_has_doubledash && return
550 local cur="${COMP_WORDS[COMP_CWORD]}"
551 case "$cur" in
552 --*)
553 __gitcomp "
554 --interactive --refresh --patch --update --dry-run
555 --ignore-errors
557 return
558 esac
559 COMPREPLY=()
562 _git_archive ()
564 local cur="${COMP_WORDS[COMP_CWORD]}"
565 case "$cur" in
566 --format=*)
567 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
568 return
570 --remote=*)
571 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
572 return
574 --*)
575 __gitcomp "
576 --format= --list --verbose
577 --prefix= --remote= --exec=
579 return
581 esac
582 __git_complete_file
585 _git_bisect ()
587 __git_has_doubledash && return
589 local subcommands="start bad good skip reset visualize replay log run"
590 local subcommand="$(__git_find_subcommand "$subcommands")"
591 if [ -z "$subcommand" ]; then
592 __gitcomp "$subcommands"
593 return
596 case "$subcommand" in
597 bad|good|reset|skip)
598 __gitcomp "$(__git_refs)"
601 COMPREPLY=()
603 esac
606 _git_branch ()
608 local i c=1 only_local_ref="n" has_r="n"
610 while [ $c -lt $COMP_CWORD ]; do
611 i="${COMP_WORDS[c]}"
612 case "$i" in
613 -d|-m) only_local_ref="y" ;;
614 -r) has_r="y" ;;
615 esac
616 c=$((++c))
617 done
619 case "${COMP_WORDS[COMP_CWORD]}" in
620 --*=*) COMPREPLY=() ;;
621 --*)
622 __gitcomp "
623 --color --no-color --verbose --abbrev= --no-abbrev
624 --track --no-track --contains --merged --no-merged
628 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
629 __gitcomp "$(__git_heads)"
630 else
631 __gitcomp "$(__git_refs)"
634 esac
637 _git_bundle ()
639 local mycword="$COMP_CWORD"
640 case "${COMP_WORDS[0]}" in
641 git)
642 local cmd="${COMP_WORDS[2]}"
643 mycword="$((mycword-1))"
645 git-bundle*)
646 local cmd="${COMP_WORDS[1]}"
648 esac
649 case "$mycword" in
651 __gitcomp "create list-heads verify unbundle"
654 # looking for a file
657 case "$cmd" in
658 create)
659 __git_complete_revlist
661 esac
663 esac
666 _git_checkout ()
668 __git_has_doubledash && return
670 __gitcomp "$(__git_refs)"
673 _git_cherry ()
675 __gitcomp "$(__git_refs)"
678 _git_cherry_pick ()
680 local cur="${COMP_WORDS[COMP_CWORD]}"
681 case "$cur" in
682 --*)
683 __gitcomp "--edit --no-commit"
686 __gitcomp "$(__git_refs)"
688 esac
691 _git_clean ()
693 __git_has_doubledash && return
695 local cur="${COMP_WORDS[COMP_CWORD]}"
696 case "$cur" in
697 --*)
698 __gitcomp "--dry-run --quiet"
699 return
701 esac
702 COMPREPLY=()
705 _git_clone ()
707 local cur="${COMP_WORDS[COMP_CWORD]}"
708 case "$cur" in
709 --*)
710 __gitcomp "
711 --local
712 --no-hardlinks
713 --shared
714 --reference
715 --quiet
716 --no-checkout
717 --bare
718 --mirror
719 --origin
720 --upload-pack
721 --template=
722 --depth
724 return
726 esac
727 COMPREPLY=()
730 _git_commit ()
732 __git_has_doubledash && return
734 local cur="${COMP_WORDS[COMP_CWORD]}"
735 case "$cur" in
736 --*)
737 __gitcomp "
738 --all --author= --signoff --verify --no-verify
739 --edit --amend --include --only --interactive
741 return
742 esac
743 COMPREPLY=()
746 _git_describe ()
748 local cur="${COMP_WORDS[COMP_CWORD]}"
749 case "$cur" in
750 --*)
751 __gitcomp "
752 --all --tags --contains --abbrev= --candidates=
753 --exact-match --debug --long --match --always
755 return
756 esac
757 __gitcomp "$(__git_refs)"
760 _git_diff ()
762 __git_has_doubledash && return
764 local cur="${COMP_WORDS[COMP_CWORD]}"
765 case "$cur" in
766 --*)
767 __gitcomp "--cached --stat --numstat --shortstat --summary
768 --patch-with-stat --name-only --name-status --color
769 --no-color --color-words --no-renames --check
770 --full-index --binary --abbrev --diff-filter=
771 --find-copies-harder --pickaxe-all --pickaxe-regex
772 --text --ignore-space-at-eol --ignore-space-change
773 --ignore-all-space --exit-code --quiet --ext-diff
774 --no-ext-diff
775 --no-prefix --src-prefix= --dst-prefix=
776 --base --ours --theirs
778 return
780 esac
781 __git_complete_file
784 _git_fetch ()
786 local cur="${COMP_WORDS[COMP_CWORD]}"
788 if [ "$COMP_CWORD" = 2 ]; then
789 __gitcomp "$(__git_remotes)"
790 else
791 case "$cur" in
792 *:*)
793 local pfx=""
794 case "$COMP_WORDBREAKS" in
795 *:*) : great ;;
796 *) pfx="${cur%%:*}:" ;;
797 esac
798 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
801 local remote
802 case "${COMP_WORDS[0]}" in
803 git-fetch) remote="${COMP_WORDS[1]}" ;;
804 git) remote="${COMP_WORDS[2]}" ;;
805 esac
806 __gitcomp "$(__git_refs2 "$remote")"
808 esac
812 _git_format_patch ()
814 local cur="${COMP_WORDS[COMP_CWORD]}"
815 case "$cur" in
816 --*)
817 __gitcomp "
818 --stdout --attach --thread
819 --output-directory
820 --numbered --start-number
821 --numbered-files
822 --keep-subject
823 --signoff
824 --in-reply-to=
825 --full-index --binary
826 --not --all
827 --cover-letter
828 --no-prefix --src-prefix= --dst-prefix=
830 return
832 esac
833 __git_complete_revlist
836 _git_gc ()
838 local cur="${COMP_WORDS[COMP_CWORD]}"
839 case "$cur" in
840 --*)
841 __gitcomp "--prune --aggressive"
842 return
844 esac
845 COMPREPLY=()
848 _git_grep ()
850 __git_has_doubledash && return
852 local cur="${COMP_WORDS[COMP_CWORD]}"
853 case "$cur" in
854 --*)
855 __gitcomp "
856 --cached
857 --text --ignore-case --word-regexp --invert-match
858 --full-name
859 --extended-regexp --basic-regexp --fixed-strings
860 --files-with-matches --name-only
861 --files-without-match
862 --count
863 --and --or --not --all-match
865 return
867 esac
868 COMPREPLY=()
871 _git_help ()
873 local cur="${COMP_WORDS[COMP_CWORD]}"
874 case "$cur" in
875 --*)
876 __gitcomp "--all --info --man --web"
877 return
879 esac
880 __gitcomp "$(__git_all_commands)
881 attributes cli core-tutorial cvs-migration
882 diffcore gitk glossary hooks ignore modules
883 repository-layout tutorial tutorial-2
887 _git_init ()
889 local cur="${COMP_WORDS[COMP_CWORD]}"
890 case "$cur" in
891 --shared=*)
892 __gitcomp "
893 false true umask group all world everybody
894 " "" "${cur##--shared=}"
895 return
897 --*)
898 __gitcomp "--quiet --bare --template= --shared --shared="
899 return
901 esac
902 COMPREPLY=()
905 _git_ls_files ()
907 __git_has_doubledash && return
909 local cur="${COMP_WORDS[COMP_CWORD]}"
910 case "$cur" in
911 --*)
912 __gitcomp "--cached --deleted --modified --others --ignored
913 --stage --directory --no-empty-directory --unmerged
914 --killed --exclude= --exclude-from=
915 --exclude-per-directory= --exclude-standard
916 --error-unmatch --with-tree= --full-name
917 --abbrev --ignored --exclude-per-directory
919 return
921 esac
922 COMPREPLY=()
925 _git_ls_remote ()
927 __gitcomp "$(__git_remotes)"
930 _git_ls_tree ()
932 __git_complete_file
935 _git_log ()
937 __git_has_doubledash && return
939 local cur="${COMP_WORDS[COMP_CWORD]}"
940 case "$cur" in
941 --pretty=*)
942 __gitcomp "
943 oneline short medium full fuller email raw
944 " "" "${cur##--pretty=}"
945 return
947 --date=*)
948 __gitcomp "
949 relative iso8601 rfc2822 short local default
950 " "" "${cur##--date=}"
951 return
953 --*)
954 __gitcomp "
955 --max-count= --max-age= --since= --after=
956 --min-age= --before= --until=
957 --root --topo-order --date-order --reverse
958 --no-merges --follow
959 --abbrev-commit --abbrev=
960 --relative-date --date=
961 --author= --committer= --grep=
962 --all-match
963 --pretty= --name-status --name-only --raw
964 --not --all
965 --left-right --cherry-pick
966 --graph
967 --stat --numstat --shortstat
968 --decorate --diff-filter=
969 --color-words --walk-reflogs
970 --parents --children --full-history
971 --merge
973 return
975 esac
976 __git_complete_revlist
979 _git_merge ()
981 local cur="${COMP_WORDS[COMP_CWORD]}"
982 case "${COMP_WORDS[COMP_CWORD-1]}" in
983 -s|--strategy)
984 __gitcomp "$(__git_merge_strategies)"
985 return
986 esac
987 case "$cur" in
988 --strategy=*)
989 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
990 return
992 --*)
993 __gitcomp "
994 --no-commit --no-stat --log --no-log --squash --strategy
996 return
997 esac
998 __gitcomp "$(__git_refs)"
1001 _git_mergetool ()
1003 local cur="${COMP_WORDS[COMP_CWORD]}"
1004 case "$cur" in
1005 --tool=*)
1006 __gitcomp "
1007 kdiff3 tkdiff meld xxdiff emerge
1008 vimdiff gvimdiff ecmerge opendiff
1009 " "" "${cur##--tool=}"
1010 return
1012 --*)
1013 __gitcomp "--tool="
1014 return
1016 esac
1017 COMPREPLY=()
1020 _git_merge_base ()
1022 __gitcomp "$(__git_refs)"
1025 _git_mv ()
1027 local cur="${COMP_WORDS[COMP_CWORD]}"
1028 case "$cur" in
1029 --*)
1030 __gitcomp "--dry-run"
1031 return
1033 esac
1034 COMPREPLY=()
1037 _git_name_rev ()
1039 __gitcomp "--tags --all --stdin"
1042 _git_pull ()
1044 local cur="${COMP_WORDS[COMP_CWORD]}"
1046 if [ "$COMP_CWORD" = 2 ]; then
1047 __gitcomp "$(__git_remotes)"
1048 else
1049 local remote
1050 case "${COMP_WORDS[0]}" in
1051 git-pull) remote="${COMP_WORDS[1]}" ;;
1052 git) remote="${COMP_WORDS[2]}" ;;
1053 esac
1054 __gitcomp "$(__git_refs "$remote")"
1058 _git_push ()
1060 local cur="${COMP_WORDS[COMP_CWORD]}"
1062 if [ "$COMP_CWORD" = 2 ]; then
1063 __gitcomp "$(__git_remotes)"
1064 else
1065 case "$cur" in
1066 *:*)
1067 local remote
1068 case "${COMP_WORDS[0]}" in
1069 git-push) remote="${COMP_WORDS[1]}" ;;
1070 git) remote="${COMP_WORDS[2]}" ;;
1071 esac
1073 local pfx=""
1074 case "$COMP_WORDBREAKS" in
1075 *:*) : great ;;
1076 *) pfx="${cur%%:*}:" ;;
1077 esac
1079 __gitcomp "$(__git_refs "$remote")" "$pfx" "${cur#*:}"
1082 __gitcomp "$(__git_refs)" + "${cur#+}"
1085 __gitcomp "$(__git_refs)"
1087 esac
1091 _git_rebase ()
1093 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1094 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1095 __gitcomp "--continue --skip --abort"
1096 return
1098 case "${COMP_WORDS[COMP_CWORD-1]}" in
1099 -s|--strategy)
1100 __gitcomp "$(__git_merge_strategies)"
1101 return
1102 esac
1103 case "$cur" in
1104 --strategy=*)
1105 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1106 return
1108 --*)
1109 __gitcomp "--onto --merge --strategy --interactive"
1110 return
1111 esac
1112 __gitcomp "$(__git_refs)"
1115 _git_send_email ()
1117 local cur="${COMP_WORDS[COMP_CWORD]}"
1118 case "$cur" in
1119 --*)
1120 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1121 --dry-run --envelope-sender --from --identity
1122 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1123 --no-suppress-from --no-thread --quiet
1124 --signed-off-by-cc --smtp-pass --smtp-server
1125 --smtp-server-port --smtp-ssl --smtp-user --subject
1126 --suppress-cc --suppress-from --thread --to"
1127 return
1129 esac
1130 COMPREPLY=()
1133 _git_config ()
1135 local cur="${COMP_WORDS[COMP_CWORD]}"
1136 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1137 case "$prv" in
1138 branch.*.remote)
1139 __gitcomp "$(__git_remotes)"
1140 return
1142 branch.*.merge)
1143 __gitcomp "$(__git_refs)"
1144 return
1146 remote.*.fetch)
1147 local remote="${prv#remote.}"
1148 remote="${remote%.fetch}"
1149 __gitcomp "$(__git_refs_remotes "$remote")"
1150 return
1152 remote.*.push)
1153 local remote="${prv#remote.}"
1154 remote="${remote%.push}"
1155 __gitcomp "$(git --git-dir="$(__gitdir)" \
1156 for-each-ref --format='%(refname):%(refname)' \
1157 refs/heads)"
1158 return
1160 pull.twohead|pull.octopus)
1161 __gitcomp "$(__git_merge_strategies)"
1162 return
1164 color.branch|color.diff|color.status)
1165 __gitcomp "always never auto"
1166 return
1168 color.*.*)
1169 __gitcomp "
1170 black red green yellow blue magenta cyan white
1171 bold dim ul blink reverse
1173 return
1175 *.*)
1176 COMPREPLY=()
1177 return
1179 esac
1180 case "$cur" in
1181 --*)
1182 __gitcomp "
1183 --global --system --file=
1184 --list --replace-all
1185 --get --get-all --get-regexp
1186 --add --unset --unset-all
1187 --remove-section --rename-section
1189 return
1191 branch.*.*)
1192 local pfx="${cur%.*}."
1193 cur="${cur##*.}"
1194 __gitcomp "remote merge" "$pfx" "$cur"
1195 return
1197 branch.*)
1198 local pfx="${cur%.*}."
1199 cur="${cur#*.}"
1200 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1201 return
1203 remote.*.*)
1204 local pfx="${cur%.*}."
1205 cur="${cur##*.}"
1206 __gitcomp "
1207 url fetch push skipDefaultUpdate
1208 receivepack uploadpack tagopt
1209 " "$pfx" "$cur"
1210 return
1212 remote.*)
1213 local pfx="${cur%.*}."
1214 cur="${cur#*.}"
1215 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1216 return
1218 esac
1219 __gitcomp "
1220 apply.whitespace
1221 core.fileMode
1222 core.gitProxy
1223 core.ignoreStat
1224 core.preferSymlinkRefs
1225 core.logAllRefUpdates
1226 core.loosecompression
1227 core.repositoryFormatVersion
1228 core.sharedRepository
1229 core.warnAmbiguousRefs
1230 core.compression
1231 core.packedGitWindowSize
1232 core.packedGitLimit
1233 clean.requireForce
1234 color.branch
1235 color.branch.current
1236 color.branch.local
1237 color.branch.remote
1238 color.branch.plain
1239 color.diff
1240 color.diff.plain
1241 color.diff.meta
1242 color.diff.frag
1243 color.diff.old
1244 color.diff.new
1245 color.diff.commit
1246 color.diff.whitespace
1247 color.pager
1248 color.status
1249 color.status.header
1250 color.status.added
1251 color.status.changed
1252 color.status.untracked
1253 diff.renameLimit
1254 diff.renames
1255 fetch.unpackLimit
1256 format.headers
1257 format.subjectprefix
1258 gitcvs.enabled
1259 gitcvs.logfile
1260 gitcvs.allbinary
1261 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
1262 gitcvs.dbtablenameprefix
1263 gc.packrefs
1264 gc.reflogexpire
1265 gc.reflogexpireunreachable
1266 gc.rerereresolved
1267 gc.rerereunresolved
1268 http.sslVerify
1269 http.sslCert
1270 http.sslKey
1271 http.sslCAInfo
1272 http.sslCAPath
1273 http.maxRequests
1274 http.lowSpeedLimit
1275 http.lowSpeedTime
1276 http.noEPSV
1277 i18n.commitEncoding
1278 i18n.logOutputEncoding
1279 log.showroot
1280 merge.tool
1281 merge.summary
1282 merge.verbosity
1283 pack.window
1284 pack.depth
1285 pack.windowMemory
1286 pack.compression
1287 pack.deltaCacheSize
1288 pack.deltaCacheLimit
1289 pull.octopus
1290 pull.twohead
1291 repack.useDeltaBaseOffset
1292 showbranch.default
1293 tar.umask
1294 transfer.unpackLimit
1295 receive.unpackLimit
1296 receive.denyNonFastForwards
1297 user.name
1298 user.email
1299 user.signingkey
1300 branch. remote.
1304 _git_remote ()
1306 local subcommands="add rm show prune update"
1307 local subcommand="$(__git_find_subcommand "$subcommands")"
1308 if [ -z "$subcommand" ]; then
1309 __gitcomp "$subcommands"
1310 return
1313 case "$subcommand" in
1314 rm|show|prune)
1315 __gitcomp "$(__git_remotes)"
1317 update)
1318 local i c='' IFS=$'\n'
1319 for i in $(git --git-dir="$(__gitdir)" config --list); do
1320 case "$i" in
1321 remotes.*)
1322 i="${i#remotes.}"
1323 c="$c ${i/=*/}"
1325 esac
1326 done
1327 __gitcomp "$c"
1330 COMPREPLY=()
1332 esac
1335 _git_reset ()
1337 __git_has_doubledash && return
1339 local cur="${COMP_WORDS[COMP_CWORD]}"
1340 case "$cur" in
1341 --*)
1342 __gitcomp "--mixed --hard --soft"
1343 return
1345 esac
1346 __gitcomp "$(__git_refs)"
1349 _git_revert ()
1351 local cur="${COMP_WORDS[COMP_CWORD]}"
1352 case "$cur" in
1353 --*)
1354 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1355 return
1357 esac
1358 COMPREPLY=()
1361 _git_rm ()
1363 __git_has_doubledash && return
1365 local cur="${COMP_WORDS[COMP_CWORD]}"
1366 case "$cur" in
1367 --*)
1368 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1369 return
1371 esac
1372 COMPREPLY=()
1375 _git_shortlog ()
1377 __git_has_doubledash && return
1379 local cur="${COMP_WORDS[COMP_CWORD]}"
1380 case "$cur" in
1381 --*)
1382 __gitcomp "
1383 --max-count= --max-age= --since= --after=
1384 --min-age= --before= --until=
1385 --no-merges
1386 --author= --committer= --grep=
1387 --all-match
1388 --not --all
1389 --numbered --summary
1391 return
1393 esac
1394 __git_complete_revlist
1397 _git_show ()
1399 local cur="${COMP_WORDS[COMP_CWORD]}"
1400 case "$cur" in
1401 --pretty=*)
1402 __gitcomp "
1403 oneline short medium full fuller email raw
1404 " "" "${cur##--pretty=}"
1405 return
1407 --*)
1408 __gitcomp "--pretty="
1409 return
1411 esac
1412 __git_complete_file
1415 _git_show_branch ()
1417 local cur="${COMP_WORDS[COMP_CWORD]}"
1418 case "$cur" in
1419 --*)
1420 __gitcomp "
1421 --all --remotes --topo-order --current --more=
1422 --list --independent --merge-base --no-name
1423 --sha1-name --topics --reflog
1425 return
1427 esac
1428 __git_complete_revlist
1431 _git_stash ()
1433 local subcommands='save list show apply clear drop pop create branch'
1434 local subcommand="$(__git_find_subcommand "$subcommands")"
1435 if [ -z "$subcommand" ]; then
1436 __gitcomp "$subcommands"
1437 else
1438 local cur="${COMP_WORDS[COMP_CWORD]}"
1439 case "$subcommand,$cur" in
1440 save,--*)
1441 __gitcomp "--keep-index"
1443 apply,--*)
1444 __gitcomp "--index"
1446 show,--*|drop,--*|pop,--*|branch,--*)
1447 COMPREPLY=()
1449 show,*|apply,*|drop,*|pop,*|branch,*)
1450 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1451 | sed -n -e 's/:.*//p')"
1454 COMPREPLY=()
1456 esac
1460 _git_submodule ()
1462 __git_has_doubledash && return
1464 local subcommands="add status init update summary foreach sync"
1465 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1466 local cur="${COMP_WORDS[COMP_CWORD]}"
1467 case "$cur" in
1468 --*)
1469 __gitcomp "--quiet --cached"
1472 __gitcomp "$subcommands"
1474 esac
1475 return
1479 _git_svn ()
1481 local subcommands="
1482 init fetch clone rebase dcommit log find-rev
1483 set-tree commit-diff info create-ignore propget
1484 proplist show-ignore show-externals
1486 local subcommand="$(__git_find_subcommand "$subcommands")"
1487 if [ -z "$subcommand" ]; then
1488 __gitcomp "$subcommands"
1489 else
1490 local remote_opts="--username= --config-dir= --no-auth-cache"
1491 local fc_opts="
1492 --follow-parent --authors-file= --repack=
1493 --no-metadata --use-svm-props --use-svnsync-props
1494 --log-window-size= --no-checkout --quiet
1495 --repack-flags --user-log-author $remote_opts
1497 local init_opts="
1498 --template= --shared= --trunk= --tags=
1499 --branches= --stdlayout --minimize-url
1500 --no-metadata --use-svm-props --use-svnsync-props
1501 --rewrite-root= $remote_opts
1503 local cmt_opts="
1504 --edit --rmdir --find-copies-harder --copy-similarity=
1507 local cur="${COMP_WORDS[COMP_CWORD]}"
1508 case "$subcommand,$cur" in
1509 fetch,--*)
1510 __gitcomp "--revision= --fetch-all $fc_opts"
1512 clone,--*)
1513 __gitcomp "--revision= $fc_opts $init_opts"
1515 init,--*)
1516 __gitcomp "$init_opts"
1518 dcommit,--*)
1519 __gitcomp "
1520 --merge --strategy= --verbose --dry-run
1521 --fetch-all --no-rebase $cmt_opts $fc_opts
1524 set-tree,--*)
1525 __gitcomp "--stdin $cmt_opts $fc_opts"
1527 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1528 show-externals,--*)
1529 __gitcomp "--revision="
1531 log,--*)
1532 __gitcomp "
1533 --limit= --revision= --verbose --incremental
1534 --oneline --show-commit --non-recursive
1535 --authors-file=
1538 rebase,--*)
1539 __gitcomp "
1540 --merge --verbose --strategy= --local
1541 --fetch-all $fc_opts
1544 commit-diff,--*)
1545 __gitcomp "--message= --file= --revision= $cmt_opts"
1547 info,--*)
1548 __gitcomp "--url"
1551 COMPREPLY=()
1553 esac
1557 _git_tag ()
1559 local i c=1 f=0
1560 while [ $c -lt $COMP_CWORD ]; do
1561 i="${COMP_WORDS[c]}"
1562 case "$i" in
1563 -d|-v)
1564 __gitcomp "$(__git_tags)"
1565 return
1570 esac
1571 c=$((++c))
1572 done
1574 case "${COMP_WORDS[COMP_CWORD-1]}" in
1575 -m|-F)
1576 COMPREPLY=()
1578 -*|tag|git-tag)
1579 if [ $f = 1 ]; then
1580 __gitcomp "$(__git_tags)"
1581 else
1582 COMPREPLY=()
1586 __gitcomp "$(__git_refs)"
1588 esac
1591 _git ()
1593 local i c=1 command __git_dir
1595 while [ $c -lt $COMP_CWORD ]; do
1596 i="${COMP_WORDS[c]}"
1597 case "$i" in
1598 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1599 --bare) __git_dir="." ;;
1600 --version|-p|--paginate) ;;
1601 --help) command="help"; break ;;
1602 *) command="$i"; break ;;
1603 esac
1604 c=$((++c))
1605 done
1607 if [ -z "$command" ]; then
1608 case "${COMP_WORDS[COMP_CWORD]}" in
1609 --*=*) COMPREPLY=() ;;
1610 --*) __gitcomp "
1611 --paginate
1612 --no-pager
1613 --git-dir=
1614 --bare
1615 --version
1616 --exec-path
1617 --work-tree=
1618 --help
1621 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1622 esac
1623 return
1626 local expansion=$(__git_aliased_command "$command")
1627 [ "$expansion" ] && command="$expansion"
1629 case "$command" in
1630 am) _git_am ;;
1631 add) _git_add ;;
1632 apply) _git_apply ;;
1633 archive) _git_archive ;;
1634 bisect) _git_bisect ;;
1635 bundle) _git_bundle ;;
1636 branch) _git_branch ;;
1637 checkout) _git_checkout ;;
1638 cherry) _git_cherry ;;
1639 cherry-pick) _git_cherry_pick ;;
1640 clean) _git_clean ;;
1641 clone) _git_clone ;;
1642 commit) _git_commit ;;
1643 config) _git_config ;;
1644 describe) _git_describe ;;
1645 diff) _git_diff ;;
1646 fetch) _git_fetch ;;
1647 format-patch) _git_format_patch ;;
1648 gc) _git_gc ;;
1649 grep) _git_grep ;;
1650 help) _git_help ;;
1651 init) _git_init ;;
1652 log) _git_log ;;
1653 ls-files) _git_ls_files ;;
1654 ls-remote) _git_ls_remote ;;
1655 ls-tree) _git_ls_tree ;;
1656 merge) _git_merge;;
1657 mergetool) _git_mergetool;;
1658 merge-base) _git_merge_base ;;
1659 mv) _git_mv ;;
1660 name-rev) _git_name_rev ;;
1661 pull) _git_pull ;;
1662 push) _git_push ;;
1663 rebase) _git_rebase ;;
1664 remote) _git_remote ;;
1665 reset) _git_reset ;;
1666 revert) _git_revert ;;
1667 rm) _git_rm ;;
1668 send-email) _git_send_email ;;
1669 shortlog) _git_shortlog ;;
1670 show) _git_show ;;
1671 show-branch) _git_show_branch ;;
1672 stash) _git_stash ;;
1673 submodule) _git_submodule ;;
1674 svn) _git_svn ;;
1675 tag) _git_tag ;;
1676 whatchanged) _git_log ;;
1677 *) COMPREPLY=() ;;
1678 esac
1681 _gitk ()
1683 __git_has_doubledash && return
1685 local cur="${COMP_WORDS[COMP_CWORD]}"
1686 local g="$(git rev-parse --git-dir 2>/dev/null)"
1687 local merge=""
1688 if [ -f $g/MERGE_HEAD ]; then
1689 merge="--merge"
1691 case "$cur" in
1692 --*)
1693 __gitcomp "--not --all $merge"
1694 return
1696 esac
1697 __git_complete_revlist
1700 complete -o default -o nospace -F _git git
1701 complete -o default -o nospace -F _gitk gitk
1703 # The following are necessary only for Cygwin, and only are needed
1704 # when the user has tab-completed the executable name and consequently
1705 # included the '.exe' suffix.
1707 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1708 complete -o default -o nospace -F _git git.exe