bash completion: Add --[no-]validate to "git send-email"
[git.git] / contrib / completion / git-completion.bash
blob7284c3b5a8d34f126632a3c87fda93d5bf7240a5
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 case "${COMP_WORDS[0]},$COMP_CWORD" in
789 git-fetch*,1)
790 __gitcomp "$(__git_remotes)"
792 git,2)
793 __gitcomp "$(__git_remotes)"
796 case "$cur" in
797 *:*)
798 local pfx=""
799 case "$COMP_WORDBREAKS" in
800 *:*) : great ;;
801 *) pfx="${cur%%:*}:" ;;
802 esac
803 __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
806 local remote
807 case "${COMP_WORDS[0]}" in
808 git-fetch) remote="${COMP_WORDS[1]}" ;;
809 git) remote="${COMP_WORDS[2]}" ;;
810 esac
811 __gitcomp "$(__git_refs2 "$remote")"
813 esac
815 esac
818 _git_format_patch ()
820 local cur="${COMP_WORDS[COMP_CWORD]}"
821 case "$cur" in
822 --*)
823 __gitcomp "
824 --stdout --attach --thread
825 --output-directory
826 --numbered --start-number
827 --numbered-files
828 --keep-subject
829 --signoff
830 --in-reply-to=
831 --full-index --binary
832 --not --all
833 --cover-letter
834 --no-prefix --src-prefix= --dst-prefix=
836 return
838 esac
839 __git_complete_revlist
842 _git_gc ()
844 local cur="${COMP_WORDS[COMP_CWORD]}"
845 case "$cur" in
846 --*)
847 __gitcomp "--prune --aggressive"
848 return
850 esac
851 COMPREPLY=()
854 _git_grep ()
856 __git_has_doubledash && return
858 local cur="${COMP_WORDS[COMP_CWORD]}"
859 case "$cur" in
860 --*)
861 __gitcomp "
862 --cached
863 --text --ignore-case --word-regexp --invert-match
864 --full-name
865 --extended-regexp --basic-regexp --fixed-strings
866 --files-with-matches --name-only
867 --files-without-match
868 --count
869 --and --or --not --all-match
871 return
873 esac
874 COMPREPLY=()
877 _git_help ()
879 local cur="${COMP_WORDS[COMP_CWORD]}"
880 case "$cur" in
881 --*)
882 __gitcomp "--all --info --man --web"
883 return
885 esac
886 __gitcomp "$(__git_all_commands)
887 attributes cli core-tutorial cvs-migration
888 diffcore gitk glossary hooks ignore modules
889 repository-layout tutorial tutorial-2
893 _git_init ()
895 local cur="${COMP_WORDS[COMP_CWORD]}"
896 case "$cur" in
897 --shared=*)
898 __gitcomp "
899 false true umask group all world everybody
900 " "" "${cur##--shared=}"
901 return
903 --*)
904 __gitcomp "--quiet --bare --template= --shared --shared="
905 return
907 esac
908 COMPREPLY=()
911 _git_ls_files ()
913 __git_has_doubledash && return
915 local cur="${COMP_WORDS[COMP_CWORD]}"
916 case "$cur" in
917 --*)
918 __gitcomp "--cached --deleted --modified --others --ignored
919 --stage --directory --no-empty-directory --unmerged
920 --killed --exclude= --exclude-from=
921 --exclude-per-directory= --exclude-standard
922 --error-unmatch --with-tree= --full-name
923 --abbrev --ignored --exclude-per-directory
925 return
927 esac
928 COMPREPLY=()
931 _git_ls_remote ()
933 __gitcomp "$(__git_remotes)"
936 _git_ls_tree ()
938 __git_complete_file
941 _git_log ()
943 __git_has_doubledash && return
945 local cur="${COMP_WORDS[COMP_CWORD]}"
946 case "$cur" in
947 --pretty=*)
948 __gitcomp "
949 oneline short medium full fuller email raw
950 " "" "${cur##--pretty=}"
951 return
953 --date=*)
954 __gitcomp "
955 relative iso8601 rfc2822 short local default
956 " "" "${cur##--date=}"
957 return
959 --*)
960 __gitcomp "
961 --max-count= --max-age= --since= --after=
962 --min-age= --before= --until=
963 --root --topo-order --date-order --reverse
964 --no-merges --follow
965 --abbrev-commit --abbrev=
966 --relative-date --date=
967 --author= --committer= --grep=
968 --all-match
969 --pretty= --name-status --name-only --raw
970 --not --all
971 --left-right --cherry-pick
972 --graph
973 --stat --numstat --shortstat
974 --decorate --diff-filter=
975 --color-words --walk-reflogs
976 --parents --children --full-history
977 --merge
979 return
981 esac
982 __git_complete_revlist
985 _git_merge ()
987 local cur="${COMP_WORDS[COMP_CWORD]}"
988 case "${COMP_WORDS[COMP_CWORD-1]}" in
989 -s|--strategy)
990 __gitcomp "$(__git_merge_strategies)"
991 return
992 esac
993 case "$cur" in
994 --strategy=*)
995 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
996 return
998 --*)
999 __gitcomp "
1000 --no-commit --no-stat --log --no-log --squash --strategy
1002 return
1003 esac
1004 __gitcomp "$(__git_refs)"
1007 _git_mergetool ()
1009 local cur="${COMP_WORDS[COMP_CWORD]}"
1010 case "$cur" in
1011 --tool=*)
1012 __gitcomp "
1013 kdiff3 tkdiff meld xxdiff emerge
1014 vimdiff gvimdiff ecmerge opendiff
1015 " "" "${cur##--tool=}"
1016 return
1018 --*)
1019 __gitcomp "--tool="
1020 return
1022 esac
1023 COMPREPLY=()
1026 _git_merge_base ()
1028 __gitcomp "$(__git_refs)"
1031 _git_mv ()
1033 local cur="${COMP_WORDS[COMP_CWORD]}"
1034 case "$cur" in
1035 --*)
1036 __gitcomp "--dry-run"
1037 return
1039 esac
1040 COMPREPLY=()
1043 _git_name_rev ()
1045 __gitcomp "--tags --all --stdin"
1048 _git_pull ()
1050 local cur="${COMP_WORDS[COMP_CWORD]}"
1052 case "${COMP_WORDS[0]},$COMP_CWORD" in
1053 git-pull*,1)
1054 __gitcomp "$(__git_remotes)"
1056 git,2)
1057 __gitcomp "$(__git_remotes)"
1060 local remote
1061 case "${COMP_WORDS[0]}" in
1062 git-pull) remote="${COMP_WORDS[1]}" ;;
1063 git) remote="${COMP_WORDS[2]}" ;;
1064 esac
1065 __gitcomp "$(__git_refs "$remote")"
1067 esac
1070 _git_push ()
1072 local cur="${COMP_WORDS[COMP_CWORD]}"
1074 case "${COMP_WORDS[0]},$COMP_CWORD" in
1075 git-push*,1)
1076 __gitcomp "$(__git_remotes)"
1078 git,2)
1079 __gitcomp "$(__git_remotes)"
1082 case "$cur" in
1083 *:*)
1084 local remote
1085 case "${COMP_WORDS[0]}" in
1086 git-push) remote="${COMP_WORDS[1]}" ;;
1087 git) remote="${COMP_WORDS[2]}" ;;
1088 esac
1090 local pfx=""
1091 case "$COMP_WORDBREAKS" in
1092 *:*) : great ;;
1093 *) pfx="${cur%%:*}:" ;;
1094 esac
1096 __gitcomp "$(__git_refs "$remote")" "$pfx" "${cur#*:}"
1099 __gitcomp "$(__git_refs)" + "${cur#+}"
1102 __gitcomp "$(__git_refs)"
1104 esac
1106 esac
1109 _git_rebase ()
1111 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1112 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1113 __gitcomp "--continue --skip --abort"
1114 return
1116 case "${COMP_WORDS[COMP_CWORD-1]}" in
1117 -s|--strategy)
1118 __gitcomp "$(__git_merge_strategies)"
1119 return
1120 esac
1121 case "$cur" in
1122 --strategy=*)
1123 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1124 return
1126 --*)
1127 __gitcomp "--onto --merge --strategy --interactive"
1128 return
1129 esac
1130 __gitcomp "$(__git_refs)"
1133 _git_send_email ()
1135 local cur="${COMP_WORDS[COMP_CWORD]}"
1136 case "$cur" in
1137 --*)
1138 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1139 --dry-run --envelope-sender --from --identity
1140 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1141 --no-suppress-from --no-thread --quiet
1142 --signed-off-by-cc --smtp-pass --smtp-server
1143 --smtp-server-port --smtp-ssl --smtp-user --subject
1144 --suppress-cc --suppress-from --thread --to
1145 --validate --no-validate"
1146 return
1148 esac
1149 COMPREPLY=()
1152 _git_config ()
1154 local cur="${COMP_WORDS[COMP_CWORD]}"
1155 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1156 case "$prv" in
1157 branch.*.remote)
1158 __gitcomp "$(__git_remotes)"
1159 return
1161 branch.*.merge)
1162 __gitcomp "$(__git_refs)"
1163 return
1165 remote.*.fetch)
1166 local remote="${prv#remote.}"
1167 remote="${remote%.fetch}"
1168 __gitcomp "$(__git_refs_remotes "$remote")"
1169 return
1171 remote.*.push)
1172 local remote="${prv#remote.}"
1173 remote="${remote%.push}"
1174 __gitcomp "$(git --git-dir="$(__gitdir)" \
1175 for-each-ref --format='%(refname):%(refname)' \
1176 refs/heads)"
1177 return
1179 pull.twohead|pull.octopus)
1180 __gitcomp "$(__git_merge_strategies)"
1181 return
1183 color.branch|color.diff|color.status)
1184 __gitcomp "always never auto"
1185 return
1187 color.*.*)
1188 __gitcomp "
1189 black red green yellow blue magenta cyan white
1190 bold dim ul blink reverse
1192 return
1194 *.*)
1195 COMPREPLY=()
1196 return
1198 esac
1199 case "$cur" in
1200 --*)
1201 __gitcomp "
1202 --global --system --file=
1203 --list --replace-all
1204 --get --get-all --get-regexp
1205 --add --unset --unset-all
1206 --remove-section --rename-section
1208 return
1210 branch.*.*)
1211 local pfx="${cur%.*}."
1212 cur="${cur##*.}"
1213 __gitcomp "remote merge" "$pfx" "$cur"
1214 return
1216 branch.*)
1217 local pfx="${cur%.*}."
1218 cur="${cur#*.}"
1219 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1220 return
1222 remote.*.*)
1223 local pfx="${cur%.*}."
1224 cur="${cur##*.}"
1225 __gitcomp "
1226 url fetch push skipDefaultUpdate
1227 receivepack uploadpack tagopt
1228 " "$pfx" "$cur"
1229 return
1231 remote.*)
1232 local pfx="${cur%.*}."
1233 cur="${cur#*.}"
1234 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1235 return
1237 esac
1238 __gitcomp "
1239 apply.whitespace
1240 core.fileMode
1241 core.gitProxy
1242 core.ignoreStat
1243 core.preferSymlinkRefs
1244 core.logAllRefUpdates
1245 core.loosecompression
1246 core.repositoryFormatVersion
1247 core.sharedRepository
1248 core.warnAmbiguousRefs
1249 core.compression
1250 core.packedGitWindowSize
1251 core.packedGitLimit
1252 clean.requireForce
1253 color.branch
1254 color.branch.current
1255 color.branch.local
1256 color.branch.remote
1257 color.branch.plain
1258 color.diff
1259 color.diff.plain
1260 color.diff.meta
1261 color.diff.frag
1262 color.diff.old
1263 color.diff.new
1264 color.diff.commit
1265 color.diff.whitespace
1266 color.pager
1267 color.status
1268 color.status.header
1269 color.status.added
1270 color.status.changed
1271 color.status.untracked
1272 diff.renameLimit
1273 diff.renames
1274 fetch.unpackLimit
1275 format.headers
1276 format.subjectprefix
1277 gitcvs.enabled
1278 gitcvs.logfile
1279 gitcvs.allbinary
1280 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
1281 gitcvs.dbtablenameprefix
1282 gc.packrefs
1283 gc.reflogexpire
1284 gc.reflogexpireunreachable
1285 gc.rerereresolved
1286 gc.rerereunresolved
1287 http.sslVerify
1288 http.sslCert
1289 http.sslKey
1290 http.sslCAInfo
1291 http.sslCAPath
1292 http.maxRequests
1293 http.lowSpeedLimit
1294 http.lowSpeedTime
1295 http.noEPSV
1296 i18n.commitEncoding
1297 i18n.logOutputEncoding
1298 log.showroot
1299 merge.tool
1300 merge.summary
1301 merge.verbosity
1302 pack.window
1303 pack.depth
1304 pack.windowMemory
1305 pack.compression
1306 pack.deltaCacheSize
1307 pack.deltaCacheLimit
1308 pull.octopus
1309 pull.twohead
1310 repack.useDeltaBaseOffset
1311 showbranch.default
1312 tar.umask
1313 transfer.unpackLimit
1314 receive.unpackLimit
1315 receive.denyNonFastForwards
1316 user.name
1317 user.email
1318 user.signingkey
1319 branch. remote.
1323 _git_remote ()
1325 local subcommands="add rm show prune update"
1326 local subcommand="$(__git_find_subcommand "$subcommands")"
1327 if [ -z "$subcommand" ]; then
1328 __gitcomp "$subcommands"
1329 return
1332 case "$subcommand" in
1333 rm|show|prune)
1334 __gitcomp "$(__git_remotes)"
1336 update)
1337 local i c='' IFS=$'\n'
1338 for i in $(git --git-dir="$(__gitdir)" config --list); do
1339 case "$i" in
1340 remotes.*)
1341 i="${i#remotes.}"
1342 c="$c ${i/=*/}"
1344 esac
1345 done
1346 __gitcomp "$c"
1349 COMPREPLY=()
1351 esac
1354 _git_reset ()
1356 __git_has_doubledash && return
1358 local cur="${COMP_WORDS[COMP_CWORD]}"
1359 case "$cur" in
1360 --*)
1361 __gitcomp "--mixed --hard --soft"
1362 return
1364 esac
1365 __gitcomp "$(__git_refs)"
1368 _git_revert ()
1370 local cur="${COMP_WORDS[COMP_CWORD]}"
1371 case "$cur" in
1372 --*)
1373 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1374 return
1376 esac
1377 COMPREPLY=()
1380 _git_rm ()
1382 __git_has_doubledash && return
1384 local cur="${COMP_WORDS[COMP_CWORD]}"
1385 case "$cur" in
1386 --*)
1387 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1388 return
1390 esac
1391 COMPREPLY=()
1394 _git_shortlog ()
1396 __git_has_doubledash && return
1398 local cur="${COMP_WORDS[COMP_CWORD]}"
1399 case "$cur" in
1400 --*)
1401 __gitcomp "
1402 --max-count= --max-age= --since= --after=
1403 --min-age= --before= --until=
1404 --no-merges
1405 --author= --committer= --grep=
1406 --all-match
1407 --not --all
1408 --numbered --summary
1410 return
1412 esac
1413 __git_complete_revlist
1416 _git_show ()
1418 local cur="${COMP_WORDS[COMP_CWORD]}"
1419 case "$cur" in
1420 --pretty=*)
1421 __gitcomp "
1422 oneline short medium full fuller email raw
1423 " "" "${cur##--pretty=}"
1424 return
1426 --*)
1427 __gitcomp "--pretty="
1428 return
1430 esac
1431 __git_complete_file
1434 _git_show_branch ()
1436 local cur="${COMP_WORDS[COMP_CWORD]}"
1437 case "$cur" in
1438 --*)
1439 __gitcomp "
1440 --all --remotes --topo-order --current --more=
1441 --list --independent --merge-base --no-name
1442 --sha1-name --topics --reflog
1444 return
1446 esac
1447 __git_complete_revlist
1450 _git_stash ()
1452 local subcommands='save list show apply clear drop pop create branch'
1453 local subcommand="$(__git_find_subcommand "$subcommands")"
1454 if [ -z "$subcommand" ]; then
1455 __gitcomp "$subcommands"
1456 else
1457 local cur="${COMP_WORDS[COMP_CWORD]}"
1458 case "$subcommand,$cur" in
1459 save,--*)
1460 __gitcomp "--keep-index"
1462 apply,--*)
1463 __gitcomp "--index"
1465 show,--*|drop,--*|pop,--*|branch,--*)
1466 COMPREPLY=()
1468 show,*|apply,*|drop,*|pop,*|branch,*)
1469 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1470 | sed -n -e 's/:.*//p')"
1473 COMPREPLY=()
1475 esac
1479 _git_submodule ()
1481 __git_has_doubledash && return
1483 local subcommands="add status init update summary foreach sync"
1484 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1485 local cur="${COMP_WORDS[COMP_CWORD]}"
1486 case "$cur" in
1487 --*)
1488 __gitcomp "--quiet --cached"
1491 __gitcomp "$subcommands"
1493 esac
1494 return
1498 _git_svn ()
1500 local subcommands="
1501 init fetch clone rebase dcommit log find-rev
1502 set-tree commit-diff info create-ignore propget
1503 proplist show-ignore show-externals
1505 local subcommand="$(__git_find_subcommand "$subcommands")"
1506 if [ -z "$subcommand" ]; then
1507 __gitcomp "$subcommands"
1508 else
1509 local remote_opts="--username= --config-dir= --no-auth-cache"
1510 local fc_opts="
1511 --follow-parent --authors-file= --repack=
1512 --no-metadata --use-svm-props --use-svnsync-props
1513 --log-window-size= --no-checkout --quiet
1514 --repack-flags --user-log-author $remote_opts
1516 local init_opts="
1517 --template= --shared= --trunk= --tags=
1518 --branches= --stdlayout --minimize-url
1519 --no-metadata --use-svm-props --use-svnsync-props
1520 --rewrite-root= $remote_opts
1522 local cmt_opts="
1523 --edit --rmdir --find-copies-harder --copy-similarity=
1526 local cur="${COMP_WORDS[COMP_CWORD]}"
1527 case "$subcommand,$cur" in
1528 fetch,--*)
1529 __gitcomp "--revision= --fetch-all $fc_opts"
1531 clone,--*)
1532 __gitcomp "--revision= $fc_opts $init_opts"
1534 init,--*)
1535 __gitcomp "$init_opts"
1537 dcommit,--*)
1538 __gitcomp "
1539 --merge --strategy= --verbose --dry-run
1540 --fetch-all --no-rebase $cmt_opts $fc_opts
1543 set-tree,--*)
1544 __gitcomp "--stdin $cmt_opts $fc_opts"
1546 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1547 show-externals,--*)
1548 __gitcomp "--revision="
1550 log,--*)
1551 __gitcomp "
1552 --limit= --revision= --verbose --incremental
1553 --oneline --show-commit --non-recursive
1554 --authors-file=
1557 rebase,--*)
1558 __gitcomp "
1559 --merge --verbose --strategy= --local
1560 --fetch-all $fc_opts
1563 commit-diff,--*)
1564 __gitcomp "--message= --file= --revision= $cmt_opts"
1566 info,--*)
1567 __gitcomp "--url"
1570 COMPREPLY=()
1572 esac
1576 _git_tag ()
1578 local i c=1 f=0
1579 while [ $c -lt $COMP_CWORD ]; do
1580 i="${COMP_WORDS[c]}"
1581 case "$i" in
1582 -d|-v)
1583 __gitcomp "$(__git_tags)"
1584 return
1589 esac
1590 c=$((++c))
1591 done
1593 case "${COMP_WORDS[COMP_CWORD-1]}" in
1594 -m|-F)
1595 COMPREPLY=()
1597 -*|tag|git-tag)
1598 if [ $f = 1 ]; then
1599 __gitcomp "$(__git_tags)"
1600 else
1601 COMPREPLY=()
1605 __gitcomp "$(__git_refs)"
1607 esac
1610 _git ()
1612 local i c=1 command __git_dir
1614 while [ $c -lt $COMP_CWORD ]; do
1615 i="${COMP_WORDS[c]}"
1616 case "$i" in
1617 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1618 --bare) __git_dir="." ;;
1619 --version|-p|--paginate) ;;
1620 --help) command="help"; break ;;
1621 *) command="$i"; break ;;
1622 esac
1623 c=$((++c))
1624 done
1626 if [ -z "$command" ]; then
1627 case "${COMP_WORDS[COMP_CWORD]}" in
1628 --*=*) COMPREPLY=() ;;
1629 --*) __gitcomp "
1630 --paginate
1631 --no-pager
1632 --git-dir=
1633 --bare
1634 --version
1635 --exec-path
1636 --work-tree=
1637 --help
1640 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1641 esac
1642 return
1645 local expansion=$(__git_aliased_command "$command")
1646 [ "$expansion" ] && command="$expansion"
1648 case "$command" in
1649 am) _git_am ;;
1650 add) _git_add ;;
1651 apply) _git_apply ;;
1652 archive) _git_archive ;;
1653 bisect) _git_bisect ;;
1654 bundle) _git_bundle ;;
1655 branch) _git_branch ;;
1656 checkout) _git_checkout ;;
1657 cherry) _git_cherry ;;
1658 cherry-pick) _git_cherry_pick ;;
1659 clean) _git_clean ;;
1660 clone) _git_clone ;;
1661 commit) _git_commit ;;
1662 config) _git_config ;;
1663 describe) _git_describe ;;
1664 diff) _git_diff ;;
1665 fetch) _git_fetch ;;
1666 format-patch) _git_format_patch ;;
1667 gc) _git_gc ;;
1668 grep) _git_grep ;;
1669 help) _git_help ;;
1670 init) _git_init ;;
1671 log) _git_log ;;
1672 ls-files) _git_ls_files ;;
1673 ls-remote) _git_ls_remote ;;
1674 ls-tree) _git_ls_tree ;;
1675 merge) _git_merge;;
1676 mergetool) _git_mergetool;;
1677 merge-base) _git_merge_base ;;
1678 mv) _git_mv ;;
1679 name-rev) _git_name_rev ;;
1680 pull) _git_pull ;;
1681 push) _git_push ;;
1682 rebase) _git_rebase ;;
1683 remote) _git_remote ;;
1684 reset) _git_reset ;;
1685 revert) _git_revert ;;
1686 rm) _git_rm ;;
1687 send-email) _git_send_email ;;
1688 shortlog) _git_shortlog ;;
1689 show) _git_show ;;
1690 show-branch) _git_show_branch ;;
1691 stash) _git_stash ;;
1692 submodule) _git_submodule ;;
1693 svn) _git_svn ;;
1694 tag) _git_tag ;;
1695 whatchanged) _git_log ;;
1696 *) COMPREPLY=() ;;
1697 esac
1700 _gitk ()
1702 __git_has_doubledash && return
1704 local cur="${COMP_WORDS[COMP_CWORD]}"
1705 local g="$(git rev-parse --git-dir 2>/dev/null)"
1706 local merge=""
1707 if [ -f $g/MERGE_HEAD ]; then
1708 merge="--merge"
1710 case "$cur" in
1711 --*)
1712 __gitcomp "--not --all $merge"
1713 return
1715 esac
1716 __git_complete_revlist
1719 complete -o default -o nospace -F _git git
1720 complete -o default -o nospace -F _gitk gitk
1722 # The following are necessary only for Cygwin, and only are needed
1723 # when the user has tab-completed the executable name and consequently
1724 # included the '.exe' suffix.
1726 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1727 complete -o default -o nospace -F _git git.exe