completion: simplify "current branch" in __git_ps1()
[git/dkf.git] / contrib / completion / git-completion.bash
blobbe591468dbf9314f658721392c5a38a50a4fb6f9
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 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
38 # value, unstaged (*) and staged (+) changes will be shown next
39 # to the branch name. You can configure this per-repository
40 # with the bash.showDirtyState variable, which defaults to true
41 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
43 # To submit patches:
45 # *) Read Documentation/SubmittingPatches
46 # *) Send all patches to the current maintainer:
48 # "Shawn O. Pearce" <spearce@spearce.org>
50 # *) Always CC the Git mailing list:
52 # git@vger.kernel.org
55 case "$COMP_WORDBREAKS" in
56 *:*) : great ;;
57 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
58 esac
60 # __gitdir accepts 0 or 1 arguments (i.e., location)
61 # returns location of .git repo
62 __gitdir ()
64 if [ -z "${1-}" ]; then
65 if [ -n "${__git_dir-}" ]; then
66 echo "$__git_dir"
67 elif [ -d .git ]; then
68 echo .git
69 else
70 git rev-parse --git-dir 2>/dev/null
72 elif [ -d "$1/.git" ]; then
73 echo "$1/.git"
74 else
75 echo "$1"
79 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
80 # returns text to add to bash PS1 prompt (includes branch name)
81 __git_ps1 ()
83 local g="$(__gitdir)"
84 if [ -n "$g" ]; then
85 local r
86 local b
87 if [ -d "$g/rebase-apply" ]; then
88 if [ -f "$g/rebase-apply/rebasing" ]; then
89 r="|REBASE"
90 elif [ -f "$g/rebase-apply/applying" ]; then
91 r="|AM"
92 else
93 r="|AM/REBASE"
95 b="$(git symbolic-ref HEAD 2>/dev/null)"
96 elif [ -f "$g/rebase-merge/interactive" ]; then
97 r="|REBASE-i"
98 b="$(cat "$g/rebase-merge/head-name")"
99 elif [ -d "$g/rebase-merge" ]; then
100 r="|REBASE-m"
101 b="$(cat "$g/rebase-merge/head-name")"
102 else
103 if [ -f "$g/MERGE_HEAD" ]; then
104 r="|MERGING"
106 if [ -f "$g/BISECT_LOG" ]; then
107 r="|BISECTING"
110 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
111 b="$(git describe --exact-match HEAD 2>/dev/null)" ||
112 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
113 b="unknown"
115 b="($b)"
119 local w
120 local i
121 local c
123 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
124 if [ "true" = "$(git config --bool core.bare 2>/dev/null)" ]; then
125 c="BARE:"
126 else
127 b="GIT_DIR!"
129 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
130 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
131 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
132 git diff --no-ext-diff --ignore-submodules \
133 --quiet --exit-code || w="*"
134 if git rev-parse --quiet --verify HEAD >/dev/null; then
135 git diff-index --cached --quiet \
136 --ignore-submodules HEAD -- || i="+"
137 else
138 i="#"
144 if [ -n "$b" ]; then
145 if [ -n "${1-}" ]; then
146 printf "$1" "$c${b##refs/heads/}$w$i$r"
147 else
148 printf " (%s)" "$c${b##refs/heads/}$w$i$r"
154 # __gitcomp_1 requires 2 arguments
155 __gitcomp_1 ()
157 local c IFS=' '$'\t'$'\n'
158 for c in $1; do
159 case "$c$2" in
160 --*=*) printf %s$'\n' "$c$2" ;;
161 *.) printf %s$'\n' "$c$2" ;;
162 *) printf %s$'\n' "$c$2 " ;;
163 esac
164 done
167 # __gitcomp accepts 1, 2, 3, or 4 arguments
168 # generates completion reply with compgen
169 __gitcomp ()
171 local cur="${COMP_WORDS[COMP_CWORD]}"
172 if [ $# -gt 2 ]; then
173 cur="$3"
175 case "$cur" in
176 --*=)
177 COMPREPLY=()
180 local IFS=$'\n'
181 COMPREPLY=($(compgen -P "${2-}" \
182 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
183 -- "$cur"))
185 esac
188 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
189 __git_heads ()
191 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
192 if [ -d "$dir" ]; then
193 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
194 refs/heads
195 return
197 for i in $(git ls-remote "${1-}" 2>/dev/null); do
198 case "$is_hash,$i" in
199 y,*) is_hash=n ;;
200 n,*^{}) is_hash=y ;;
201 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
202 n,*) is_hash=y; echo "$i" ;;
203 esac
204 done
207 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
208 __git_tags ()
210 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
211 if [ -d "$dir" ]; then
212 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
213 refs/tags
214 return
216 for i in $(git ls-remote "${1-}" 2>/dev/null); do
217 case "$is_hash,$i" in
218 y,*) is_hash=n ;;
219 n,*^{}) is_hash=y ;;
220 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
221 n,*) is_hash=y; echo "$i" ;;
222 esac
223 done
226 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
227 __git_refs ()
229 local i is_hash=y dir="$(__gitdir "${1-}")"
230 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
231 if [ -d "$dir" ]; then
232 case "$cur" in
233 refs|refs/*)
234 format="refname"
235 refs="${cur%/*}"
238 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
239 format="refname:short"
240 refs="refs/tags refs/heads refs/remotes"
242 esac
243 git --git-dir="$dir" for-each-ref --format="%($format)" \
244 $refs
245 return
247 for i in $(git ls-remote "$dir" 2>/dev/null); do
248 case "$is_hash,$i" in
249 y,*) is_hash=n ;;
250 n,*^{}) is_hash=y ;;
251 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
252 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
253 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
254 n,*) is_hash=y; echo "$i" ;;
255 esac
256 done
259 # __git_refs2 requires 1 argument (to pass to __git_refs)
260 __git_refs2 ()
262 local i
263 for i in $(__git_refs "$1"); do
264 echo "$i:$i"
265 done
268 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
269 __git_refs_remotes ()
271 local cmd i is_hash=y
272 for i in $(git ls-remote "$1" 2>/dev/null); do
273 case "$is_hash,$i" in
274 n,refs/heads/*)
275 is_hash=y
276 echo "$i:refs/remotes/$1/${i#refs/heads/}"
278 y,*) is_hash=n ;;
279 n,*^{}) is_hash=y ;;
280 n,refs/tags/*) is_hash=y;;
281 n,*) is_hash=y; ;;
282 esac
283 done
286 __git_remotes ()
288 local i ngoff IFS=$'\n' d="$(__gitdir)"
289 shopt -q nullglob || ngoff=1
290 shopt -s nullglob
291 for i in "$d/remotes"/*; do
292 echo ${i#$d/remotes/}
293 done
294 [ "$ngoff" ] && shopt -u nullglob
295 for i in $(git --git-dir="$d" config --list); do
296 case "$i" in
297 remote.*.url=*)
298 i="${i#remote.}"
299 echo "${i/.url=*/}"
301 esac
302 done
305 __git_merge_strategies ()
307 if [ -n "${__git_merge_strategylist-}" ]; then
308 echo "$__git_merge_strategylist"
309 return
311 git merge -s help 2>&1 |
312 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
313 s/\.$//
314 s/.*://
315 s/^[ ]*//
316 s/[ ]*$//
320 __git_merge_strategylist=
321 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
323 __git_complete_file ()
325 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
326 case "$cur" in
327 ?*:*)
328 ref="${cur%%:*}"
329 cur="${cur#*:}"
330 case "$cur" in
331 ?*/*)
332 pfx="${cur%/*}"
333 cur="${cur##*/}"
334 ls="$ref:$pfx"
335 pfx="$pfx/"
338 ls="$ref"
340 esac
342 case "$COMP_WORDBREAKS" in
343 *:*) : great ;;
344 *) pfx="$ref:$pfx" ;;
345 esac
347 local IFS=$'\n'
348 COMPREPLY=($(compgen -P "$pfx" \
349 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
350 | sed '/^100... blob /{
351 s,^.* ,,
352 s,$, ,
354 /^120000 blob /{
355 s,^.* ,,
356 s,$, ,
358 /^040000 tree /{
359 s,^.* ,,
360 s,$,/,
362 s/^.* //')" \
363 -- "$cur"))
366 __gitcomp "$(__git_refs)"
368 esac
371 __git_complete_revlist ()
373 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
374 case "$cur" in
375 *...*)
376 pfx="${cur%...*}..."
377 cur="${cur#*...}"
378 __gitcomp "$(__git_refs)" "$pfx" "$cur"
380 *..*)
381 pfx="${cur%..*}.."
382 cur="${cur#*..}"
383 __gitcomp "$(__git_refs)" "$pfx" "$cur"
386 __gitcomp "$(__git_refs)"
388 esac
391 __git_complete_remote_or_refspec ()
393 local cmd="${COMP_WORDS[1]}"
394 local cur="${COMP_WORDS[COMP_CWORD]}"
395 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
396 while [ $c -lt $COMP_CWORD ]; do
397 i="${COMP_WORDS[c]}"
398 case "$i" in
399 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
400 -*) ;;
401 *) remote="$i"; break ;;
402 esac
403 c=$((++c))
404 done
405 if [ -z "$remote" ]; then
406 __gitcomp "$(__git_remotes)"
407 return
409 if [ $no_complete_refspec = 1 ]; then
410 COMPREPLY=()
411 return
413 [ "$remote" = "." ] && remote=
414 case "$cur" in
415 *:*)
416 case "$COMP_WORDBREAKS" in
417 *:*) : great ;;
418 *) pfx="${cur%%:*}:" ;;
419 esac
420 cur="${cur#*:}"
421 lhs=0
424 pfx="+"
425 cur="${cur#+}"
427 esac
428 case "$cmd" in
429 fetch)
430 if [ $lhs = 1 ]; then
431 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
432 else
433 __gitcomp "$(__git_refs)" "$pfx" "$cur"
436 pull)
437 if [ $lhs = 1 ]; then
438 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
439 else
440 __gitcomp "$(__git_refs)" "$pfx" "$cur"
443 push)
444 if [ $lhs = 1 ]; then
445 __gitcomp "$(__git_refs)" "$pfx" "$cur"
446 else
447 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
450 esac
453 __git_complete_strategy ()
455 case "${COMP_WORDS[COMP_CWORD-1]}" in
456 -s|--strategy)
457 __gitcomp "$(__git_merge_strategies)"
458 return 0
459 esac
460 local cur="${COMP_WORDS[COMP_CWORD]}"
461 case "$cur" in
462 --strategy=*)
463 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
464 return 0
466 esac
467 return 1
470 __git_all_commands ()
472 if [ -n "${__git_all_commandlist-}" ]; then
473 echo "$__git_all_commandlist"
474 return
476 local i IFS=" "$'\n'
477 for i in $(git help -a|egrep '^ ')
479 case $i in
480 *--*) : helper pattern;;
481 *) echo $i;;
482 esac
483 done
485 __git_all_commandlist=
486 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
488 __git_porcelain_commands ()
490 if [ -n "${__git_porcelain_commandlist-}" ]; then
491 echo "$__git_porcelain_commandlist"
492 return
494 local i IFS=" "$'\n'
495 for i in "help" $(__git_all_commands)
497 case $i in
498 *--*) : helper pattern;;
499 applymbox) : ask gittus;;
500 applypatch) : ask gittus;;
501 archimport) : import;;
502 cat-file) : plumbing;;
503 check-attr) : plumbing;;
504 check-ref-format) : plumbing;;
505 checkout-index) : plumbing;;
506 commit-tree) : plumbing;;
507 count-objects) : infrequent;;
508 cvsexportcommit) : export;;
509 cvsimport) : import;;
510 cvsserver) : daemon;;
511 daemon) : daemon;;
512 diff-files) : plumbing;;
513 diff-index) : plumbing;;
514 diff-tree) : plumbing;;
515 fast-import) : import;;
516 fast-export) : export;;
517 fsck-objects) : plumbing;;
518 fetch-pack) : plumbing;;
519 fmt-merge-msg) : plumbing;;
520 for-each-ref) : plumbing;;
521 hash-object) : plumbing;;
522 http-*) : transport;;
523 index-pack) : plumbing;;
524 init-db) : deprecated;;
525 local-fetch) : plumbing;;
526 lost-found) : infrequent;;
527 ls-files) : plumbing;;
528 ls-remote) : plumbing;;
529 ls-tree) : plumbing;;
530 mailinfo) : plumbing;;
531 mailsplit) : plumbing;;
532 merge-*) : plumbing;;
533 mktree) : plumbing;;
534 mktag) : plumbing;;
535 pack-objects) : plumbing;;
536 pack-redundant) : plumbing;;
537 pack-refs) : plumbing;;
538 parse-remote) : plumbing;;
539 patch-id) : plumbing;;
540 peek-remote) : plumbing;;
541 prune) : plumbing;;
542 prune-packed) : plumbing;;
543 quiltimport) : import;;
544 read-tree) : plumbing;;
545 receive-pack) : plumbing;;
546 reflog) : plumbing;;
547 repo-config) : deprecated;;
548 rerere) : plumbing;;
549 rev-list) : plumbing;;
550 rev-parse) : plumbing;;
551 runstatus) : plumbing;;
552 sh-setup) : internal;;
553 shell) : daemon;;
554 show-ref) : plumbing;;
555 send-pack) : plumbing;;
556 show-index) : plumbing;;
557 ssh-*) : transport;;
558 stripspace) : plumbing;;
559 symbolic-ref) : plumbing;;
560 tar-tree) : deprecated;;
561 unpack-file) : plumbing;;
562 unpack-objects) : plumbing;;
563 update-index) : plumbing;;
564 update-ref) : plumbing;;
565 update-server-info) : daemon;;
566 upload-archive) : plumbing;;
567 upload-pack) : plumbing;;
568 write-tree) : plumbing;;
569 var) : infrequent;;
570 verify-pack) : infrequent;;
571 verify-tag) : plumbing;;
572 *) echo $i;;
573 esac
574 done
576 __git_porcelain_commandlist=
577 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
579 __git_aliases ()
581 local i IFS=$'\n'
582 for i in $(git --git-dir="$(__gitdir)" config --list); do
583 case "$i" in
584 alias.*)
585 i="${i#alias.}"
586 echo "${i/=*/}"
588 esac
589 done
592 # __git_aliased_command requires 1 argument
593 __git_aliased_command ()
595 local word cmdline=$(git --git-dir="$(__gitdir)" \
596 config --get "alias.$1")
597 for word in $cmdline; do
598 if [ "${word##-*}" ]; then
599 echo $word
600 return
602 done
605 # __git_find_subcommand requires 1 argument
606 __git_find_subcommand ()
608 local word subcommand c=1
610 while [ $c -lt $COMP_CWORD ]; do
611 word="${COMP_WORDS[c]}"
612 for subcommand in $1; do
613 if [ "$subcommand" = "$word" ]; then
614 echo "$subcommand"
615 return
617 done
618 c=$((++c))
619 done
622 __git_has_doubledash ()
624 local c=1
625 while [ $c -lt $COMP_CWORD ]; do
626 if [ "--" = "${COMP_WORDS[c]}" ]; then
627 return 0
629 c=$((++c))
630 done
631 return 1
634 __git_whitespacelist="nowarn warn error error-all fix"
636 _git_am ()
638 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
639 if [ -d "$dir"/rebase-apply ]; then
640 __gitcomp "--skip --resolved --abort"
641 return
643 case "$cur" in
644 --whitespace=*)
645 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
646 return
648 --*)
649 __gitcomp "
650 --3way --committer-date-is-author-date --ignore-date
651 --interactive --keep --no-utf8 --signoff --utf8
652 --whitespace=
654 return
655 esac
656 COMPREPLY=()
659 _git_apply ()
661 local cur="${COMP_WORDS[COMP_CWORD]}"
662 case "$cur" in
663 --whitespace=*)
664 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
665 return
667 --*)
668 __gitcomp "
669 --stat --numstat --summary --check --index
670 --cached --index-info --reverse --reject --unidiff-zero
671 --apply --no-add --exclude=
672 --whitespace= --inaccurate-eof --verbose
674 return
675 esac
676 COMPREPLY=()
679 _git_add ()
681 __git_has_doubledash && return
683 local cur="${COMP_WORDS[COMP_CWORD]}"
684 case "$cur" in
685 --*)
686 __gitcomp "
687 --interactive --refresh --patch --update --dry-run
688 --ignore-errors --intent-to-add
690 return
691 esac
692 COMPREPLY=()
695 _git_archive ()
697 local cur="${COMP_WORDS[COMP_CWORD]}"
698 case "$cur" in
699 --format=*)
700 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
701 return
703 --remote=*)
704 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
705 return
707 --*)
708 __gitcomp "
709 --format= --list --verbose
710 --prefix= --remote= --exec=
712 return
714 esac
715 __git_complete_file
718 _git_bisect ()
720 __git_has_doubledash && return
722 local subcommands="start bad good skip reset visualize replay log run"
723 local subcommand="$(__git_find_subcommand "$subcommands")"
724 if [ -z "$subcommand" ]; then
725 __gitcomp "$subcommands"
726 return
729 case "$subcommand" in
730 bad|good|reset|skip)
731 __gitcomp "$(__git_refs)"
734 COMPREPLY=()
736 esac
739 _git_branch ()
741 local i c=1 only_local_ref="n" has_r="n"
743 while [ $c -lt $COMP_CWORD ]; do
744 i="${COMP_WORDS[c]}"
745 case "$i" in
746 -d|-m) only_local_ref="y" ;;
747 -r) has_r="y" ;;
748 esac
749 c=$((++c))
750 done
752 case "${COMP_WORDS[COMP_CWORD]}" in
753 --*)
754 __gitcomp "
755 --color --no-color --verbose --abbrev= --no-abbrev
756 --track --no-track --contains --merged --no-merged
760 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
761 __gitcomp "$(__git_heads)"
762 else
763 __gitcomp "$(__git_refs)"
766 esac
769 _git_bundle ()
771 local cmd="${COMP_WORDS[2]}"
772 case "$COMP_CWORD" in
774 __gitcomp "create list-heads verify unbundle"
777 # looking for a file
780 case "$cmd" in
781 create)
782 __git_complete_revlist
784 esac
786 esac
789 _git_checkout ()
791 __git_has_doubledash && return
793 __gitcomp "$(__git_refs)"
796 _git_cherry ()
798 __gitcomp "$(__git_refs)"
801 _git_cherry_pick ()
803 local cur="${COMP_WORDS[COMP_CWORD]}"
804 case "$cur" in
805 --*)
806 __gitcomp "--edit --no-commit"
809 __gitcomp "$(__git_refs)"
811 esac
814 _git_clean ()
816 __git_has_doubledash && return
818 local cur="${COMP_WORDS[COMP_CWORD]}"
819 case "$cur" in
820 --*)
821 __gitcomp "--dry-run --quiet"
822 return
824 esac
825 COMPREPLY=()
828 _git_clone ()
830 local cur="${COMP_WORDS[COMP_CWORD]}"
831 case "$cur" in
832 --*)
833 __gitcomp "
834 --local
835 --no-hardlinks
836 --shared
837 --reference
838 --quiet
839 --no-checkout
840 --bare
841 --mirror
842 --origin
843 --upload-pack
844 --template=
845 --depth
847 return
849 esac
850 COMPREPLY=()
853 _git_commit ()
855 __git_has_doubledash && return
857 local cur="${COMP_WORDS[COMP_CWORD]}"
858 case "$cur" in
859 --*)
860 __gitcomp "
861 --all --author= --signoff --verify --no-verify
862 --edit --amend --include --only --interactive
864 return
865 esac
866 COMPREPLY=()
869 _git_describe ()
871 local cur="${COMP_WORDS[COMP_CWORD]}"
872 case "$cur" in
873 --*)
874 __gitcomp "
875 --all --tags --contains --abbrev= --candidates=
876 --exact-match --debug --long --match --always
878 return
879 esac
880 __gitcomp "$(__git_refs)"
883 __git_diff_common_options="--stat --numstat --shortstat --summary
884 --patch-with-stat --name-only --name-status --color
885 --no-color --color-words --no-renames --check
886 --full-index --binary --abbrev --diff-filter=
887 --find-copies-harder
888 --text --ignore-space-at-eol --ignore-space-change
889 --ignore-all-space --exit-code --quiet --ext-diff
890 --no-ext-diff
891 --no-prefix --src-prefix= --dst-prefix=
892 --inter-hunk-context=
893 --patience
894 --raw
897 _git_diff ()
899 __git_has_doubledash && return
901 local cur="${COMP_WORDS[COMP_CWORD]}"
902 case "$cur" in
903 --*)
904 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
905 --base --ours --theirs
906 $__git_diff_common_options
908 return
910 esac
911 __git_complete_file
914 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
915 tkdiff vimdiff gvimdiff xxdiff
918 _git_difftool ()
920 local cur="${COMP_WORDS[COMP_CWORD]}"
921 case "$cur" in
922 --tool=*)
923 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
924 return
926 --*)
927 __gitcomp "--tool="
928 return
930 esac
931 COMPREPLY=()
934 __git_fetch_options="
935 --quiet --verbose --append --upload-pack --force --keep --depth=
936 --tags --no-tags
939 _git_fetch ()
941 local cur="${COMP_WORDS[COMP_CWORD]}"
942 case "$cur" in
943 --*)
944 __gitcomp "$__git_fetch_options"
945 return
947 esac
948 __git_complete_remote_or_refspec
951 _git_format_patch ()
953 local cur="${COMP_WORDS[COMP_CWORD]}"
954 case "$cur" in
955 --thread=*)
956 __gitcomp "
957 deep shallow
958 " "" "${cur##--thread=}"
959 return
961 --*)
962 __gitcomp "
963 --stdout --attach --no-attach --thread --thread=
964 --output-directory
965 --numbered --start-number
966 --numbered-files
967 --keep-subject
968 --signoff
969 --in-reply-to= --cc=
970 --full-index --binary
971 --not --all
972 --cover-letter
973 --no-prefix --src-prefix= --dst-prefix=
974 --inline --suffix= --ignore-if-in-upstream
975 --subject-prefix=
977 return
979 esac
980 __git_complete_revlist
983 _git_fsck ()
985 local cur="${COMP_WORDS[COMP_CWORD]}"
986 case "$cur" in
987 --*)
988 __gitcomp "
989 --tags --root --unreachable --cache --no-reflogs --full
990 --strict --verbose --lost-found
992 return
994 esac
995 COMPREPLY=()
998 _git_gc ()
1000 local cur="${COMP_WORDS[COMP_CWORD]}"
1001 case "$cur" in
1002 --*)
1003 __gitcomp "--prune --aggressive"
1004 return
1006 esac
1007 COMPREPLY=()
1010 _git_grep ()
1012 __git_has_doubledash && return
1014 local cur="${COMP_WORDS[COMP_CWORD]}"
1015 case "$cur" in
1016 --*)
1017 __gitcomp "
1018 --cached
1019 --text --ignore-case --word-regexp --invert-match
1020 --full-name
1021 --extended-regexp --basic-regexp --fixed-strings
1022 --files-with-matches --name-only
1023 --files-without-match
1024 --count
1025 --and --or --not --all-match
1027 return
1029 esac
1030 COMPREPLY=()
1033 _git_help ()
1035 local cur="${COMP_WORDS[COMP_CWORD]}"
1036 case "$cur" in
1037 --*)
1038 __gitcomp "--all --info --man --web"
1039 return
1041 esac
1042 __gitcomp "$(__git_all_commands)
1043 attributes cli core-tutorial cvs-migration
1044 diffcore gitk glossary hooks ignore modules
1045 repository-layout tutorial tutorial-2
1046 workflows
1050 _git_init ()
1052 local cur="${COMP_WORDS[COMP_CWORD]}"
1053 case "$cur" in
1054 --shared=*)
1055 __gitcomp "
1056 false true umask group all world everybody
1057 " "" "${cur##--shared=}"
1058 return
1060 --*)
1061 __gitcomp "--quiet --bare --template= --shared --shared="
1062 return
1064 esac
1065 COMPREPLY=()
1068 _git_ls_files ()
1070 __git_has_doubledash && return
1072 local cur="${COMP_WORDS[COMP_CWORD]}"
1073 case "$cur" in
1074 --*)
1075 __gitcomp "--cached --deleted --modified --others --ignored
1076 --stage --directory --no-empty-directory --unmerged
1077 --killed --exclude= --exclude-from=
1078 --exclude-per-directory= --exclude-standard
1079 --error-unmatch --with-tree= --full-name
1080 --abbrev --ignored --exclude-per-directory
1082 return
1084 esac
1085 COMPREPLY=()
1088 _git_ls_remote ()
1090 __gitcomp "$(__git_remotes)"
1093 _git_ls_tree ()
1095 __git_complete_file
1098 # Options that go well for log, shortlog and gitk
1099 __git_log_common_options="
1100 --not --all
1101 --branches --tags --remotes
1102 --first-parent --no-merges
1103 --max-count=
1104 --max-age= --since= --after=
1105 --min-age= --until= --before=
1107 # Options that go well for log and gitk (not shortlog)
1108 __git_log_gitk_options="
1109 --dense --sparse --full-history
1110 --simplify-merges --simplify-by-decoration
1111 --left-right
1113 # Options that go well for log and shortlog (not gitk)
1114 __git_log_shortlog_options="
1115 --author= --committer= --grep=
1116 --all-match
1119 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1120 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1122 _git_log ()
1124 __git_has_doubledash && return
1126 local cur="${COMP_WORDS[COMP_CWORD]}"
1127 local g="$(git rev-parse --git-dir 2>/dev/null)"
1128 local merge=""
1129 if [ -f "$g/MERGE_HEAD" ]; then
1130 merge="--merge"
1132 case "$cur" in
1133 --pretty=*)
1134 __gitcomp "$__git_log_pretty_formats
1135 " "" "${cur##--pretty=}"
1136 return
1138 --format=*)
1139 __gitcomp "$__git_log_pretty_formats
1140 " "" "${cur##--format=}"
1141 return
1143 --date=*)
1144 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1145 return
1147 --*)
1148 __gitcomp "
1149 $__git_log_common_options
1150 $__git_log_shortlog_options
1151 $__git_log_gitk_options
1152 --root --topo-order --date-order --reverse
1153 --follow
1154 --abbrev-commit --abbrev=
1155 --relative-date --date=
1156 --pretty= --format= --oneline
1157 --cherry-pick
1158 --graph
1159 --decorate
1160 --walk-reflogs
1161 --parents --children
1162 $merge
1163 $__git_diff_common_options
1164 --pickaxe-all --pickaxe-regex
1166 return
1168 esac
1169 __git_complete_revlist
1172 __git_merge_options="
1173 --no-commit --no-stat --log --no-log --squash --strategy
1174 --commit --stat --no-squash --ff --no-ff
1177 _git_merge ()
1179 __git_complete_strategy && return
1181 local cur="${COMP_WORDS[COMP_CWORD]}"
1182 case "$cur" in
1183 --*)
1184 __gitcomp "$__git_merge_options"
1185 return
1186 esac
1187 __gitcomp "$(__git_refs)"
1190 _git_mergetool ()
1192 local cur="${COMP_WORDS[COMP_CWORD]}"
1193 case "$cur" in
1194 --tool=*)
1195 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1196 return
1198 --*)
1199 __gitcomp "--tool="
1200 return
1202 esac
1203 COMPREPLY=()
1206 _git_merge_base ()
1208 __gitcomp "$(__git_refs)"
1211 _git_mv ()
1213 local cur="${COMP_WORDS[COMP_CWORD]}"
1214 case "$cur" in
1215 --*)
1216 __gitcomp "--dry-run"
1217 return
1219 esac
1220 COMPREPLY=()
1223 _git_name_rev ()
1225 __gitcomp "--tags --all --stdin"
1228 _git_pull ()
1230 __git_complete_strategy && return
1232 local cur="${COMP_WORDS[COMP_CWORD]}"
1233 case "$cur" in
1234 --*)
1235 __gitcomp "
1236 --rebase --no-rebase
1237 $__git_merge_options
1238 $__git_fetch_options
1240 return
1242 esac
1243 __git_complete_remote_or_refspec
1246 _git_push ()
1248 local cur="${COMP_WORDS[COMP_CWORD]}"
1249 case "${COMP_WORDS[COMP_CWORD-1]}" in
1250 --repo)
1251 __gitcomp "$(__git_remotes)"
1252 return
1253 esac
1254 case "$cur" in
1255 --repo=*)
1256 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1257 return
1259 --*)
1260 __gitcomp "
1261 --all --mirror --tags --dry-run --force --verbose
1262 --receive-pack= --repo=
1264 return
1266 esac
1267 __git_complete_remote_or_refspec
1270 _git_rebase ()
1272 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1273 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1274 __gitcomp "--continue --skip --abort"
1275 return
1277 __git_complete_strategy && return
1278 case "$cur" in
1279 --*)
1280 __gitcomp "--onto --merge --strategy --interactive"
1281 return
1282 esac
1283 __gitcomp "$(__git_refs)"
1286 __git_send_email_confirm_options="always never auto cc compose"
1287 __git_send_email_suppresscc_options="author self cc ccbody sob cccmd body all"
1289 _git_send_email ()
1291 local cur="${COMP_WORDS[COMP_CWORD]}"
1292 case "$cur" in
1293 --confirm=*)
1294 __gitcomp "
1295 $__git_send_email_confirm_options
1296 " "" "${cur##--confirm=}"
1297 return
1299 --suppress-cc=*)
1300 __gitcomp "
1301 $__git_send_email_suppresscc_options
1302 " "" "${cur##--suppress-cc=}"
1304 return
1306 --smtp-encryption=*)
1307 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1308 return
1310 --*)
1311 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1312 --compose --confirm= --dry-run --envelope-sender
1313 --from --identity
1314 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1315 --no-suppress-from --no-thread --quiet
1316 --signed-off-by-cc --smtp-pass --smtp-server
1317 --smtp-server-port --smtp-encryption= --smtp-user
1318 --subject --suppress-cc= --suppress-from --thread --to
1319 --validate --no-validate"
1320 return
1322 esac
1323 COMPREPLY=()
1326 _git_config ()
1328 local cur="${COMP_WORDS[COMP_CWORD]}"
1329 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1330 case "$prv" in
1331 branch.*.remote)
1332 __gitcomp "$(__git_remotes)"
1333 return
1335 branch.*.merge)
1336 __gitcomp "$(__git_refs)"
1337 return
1339 remote.*.fetch)
1340 local remote="${prv#remote.}"
1341 remote="${remote%.fetch}"
1342 __gitcomp "$(__git_refs_remotes "$remote")"
1343 return
1345 remote.*.push)
1346 local remote="${prv#remote.}"
1347 remote="${remote%.push}"
1348 __gitcomp "$(git --git-dir="$(__gitdir)" \
1349 for-each-ref --format='%(refname):%(refname)' \
1350 refs/heads)"
1351 return
1353 pull.twohead|pull.octopus)
1354 __gitcomp "$(__git_merge_strategies)"
1355 return
1357 color.branch|color.diff|color.interactive|color.status|color.ui)
1358 __gitcomp "always never auto"
1359 return
1361 color.pager)
1362 __gitcomp "false true"
1363 return
1365 color.*.*)
1366 __gitcomp "
1367 normal black red green yellow blue magenta cyan white
1368 bold dim ul blink reverse
1370 return
1372 help.format)
1373 __gitcomp "man info web html"
1374 return
1376 log.date)
1377 __gitcomp "$__git_log_date_formats"
1378 return
1380 sendemail.aliasesfiletype)
1381 __gitcomp "mutt mailrc pine elm gnus"
1382 return
1384 sendemail.confirm)
1385 __gitcomp "$__git_send_email_confirm_options"
1386 return
1388 sendemail.suppresscc)
1389 __gitcomp "$__git_send_email_suppresscc_options"
1390 return
1392 *.*)
1393 COMPREPLY=()
1394 return
1396 esac
1397 case "$cur" in
1398 --*)
1399 __gitcomp "
1400 --global --system --file=
1401 --list --replace-all
1402 --get --get-all --get-regexp
1403 --add --unset --unset-all
1404 --remove-section --rename-section
1406 return
1408 branch.*.*)
1409 local pfx="${cur%.*}."
1410 cur="${cur##*.}"
1411 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1412 return
1414 branch.*)
1415 local pfx="${cur%.*}."
1416 cur="${cur#*.}"
1417 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1418 return
1420 guitool.*.*)
1421 local pfx="${cur%.*}."
1422 cur="${cur##*.}"
1423 __gitcomp "
1424 argprompt cmd confirm needsfile noconsole norescan
1425 prompt revprompt revunmerged title
1426 " "$pfx" "$cur"
1427 return
1429 difftool.*.*)
1430 local pfx="${cur%.*}."
1431 cur="${cur##*.}"
1432 __gitcomp "cmd path" "$pfx" "$cur"
1433 return
1435 man.*.*)
1436 local pfx="${cur%.*}."
1437 cur="${cur##*.}"
1438 __gitcomp "cmd path" "$pfx" "$cur"
1439 return
1441 mergetool.*.*)
1442 local pfx="${cur%.*}."
1443 cur="${cur##*.}"
1444 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1445 return
1447 pager.*)
1448 local pfx="${cur%.*}."
1449 cur="${cur#*.}"
1450 __gitcomp "$(__git_all_commands)" "$pfx" "$cur"
1451 return
1453 remote.*.*)
1454 local pfx="${cur%.*}."
1455 cur="${cur##*.}"
1456 __gitcomp "
1457 url proxy fetch push mirror skipDefaultUpdate
1458 receivepack uploadpack tagopt
1459 " "$pfx" "$cur"
1460 return
1462 remote.*)
1463 local pfx="${cur%.*}."
1464 cur="${cur#*.}"
1465 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1466 return
1468 url.*.*)
1469 local pfx="${cur%.*}."
1470 cur="${cur##*.}"
1471 __gitcomp "insteadof" "$pfx" "$cur"
1472 return
1474 esac
1475 __gitcomp "
1476 alias.
1477 apply.whitespace
1478 branch.autosetupmerge
1479 branch.autosetuprebase
1480 clean.requireForce
1481 color.branch
1482 color.branch.current
1483 color.branch.local
1484 color.branch.plain
1485 color.branch.remote
1486 color.diff
1487 color.diff.commit
1488 color.diff.frag
1489 color.diff.meta
1490 color.diff.new
1491 color.diff.old
1492 color.diff.plain
1493 color.diff.whitespace
1494 color.grep
1495 color.grep.external
1496 color.grep.match
1497 color.interactive
1498 color.interactive.header
1499 color.interactive.help
1500 color.interactive.prompt
1501 color.pager
1502 color.status
1503 color.status.added
1504 color.status.changed
1505 color.status.header
1506 color.status.nobranch
1507 color.status.untracked
1508 color.status.updated
1509 color.ui
1510 commit.template
1511 core.autocrlf
1512 core.bare
1513 core.compression
1514 core.createObject
1515 core.deltaBaseCacheLimit
1516 core.editor
1517 core.excludesfile
1518 core.fileMode
1519 core.fsyncobjectfiles
1520 core.gitProxy
1521 core.ignoreCygwinFSTricks
1522 core.ignoreStat
1523 core.logAllRefUpdates
1524 core.loosecompression
1525 core.packedGitLimit
1526 core.packedGitWindowSize
1527 core.pager
1528 core.preferSymlinkRefs
1529 core.preloadindex
1530 core.quotepath
1531 core.repositoryFormatVersion
1532 core.safecrlf
1533 core.sharedRepository
1534 core.symlinks
1535 core.trustctime
1536 core.warnAmbiguousRefs
1537 core.whitespace
1538 core.worktree
1539 diff.autorefreshindex
1540 diff.external
1541 diff.mnemonicprefix
1542 diff.renameLimit
1543 diff.renameLimit.
1544 diff.renames
1545 diff.suppressBlankEmpty
1546 diff.tool
1547 diff.wordRegex
1548 difftool.
1549 difftool.prompt
1550 fetch.unpackLimit
1551 format.attach
1552 format.cc
1553 format.headers
1554 format.numbered
1555 format.pretty
1556 format.signoff
1557 format.subjectprefix
1558 format.suffix
1559 format.thread
1560 gc.aggressiveWindow
1561 gc.auto
1562 gc.autopacklimit
1563 gc.packrefs
1564 gc.pruneexpire
1565 gc.reflogexpire
1566 gc.reflogexpireunreachable
1567 gc.rerereresolved
1568 gc.rerereunresolved
1569 gitcvs.allbinary
1570 gitcvs.commitmsgannotation
1571 gitcvs.dbTableNamePrefix
1572 gitcvs.dbdriver
1573 gitcvs.dbname
1574 gitcvs.dbpass
1575 gitcvs.dbuser
1576 gitcvs.enabled
1577 gitcvs.logfile
1578 gitcvs.usecrlfattr
1579 guitool.
1580 gui.blamehistoryctx
1581 gui.commitmsgwidth
1582 gui.copyblamethreshold
1583 gui.diffcontext
1584 gui.encoding
1585 gui.fastcopyblame
1586 gui.matchtrackingbranch
1587 gui.newbranchtemplate
1588 gui.pruneduringfetch
1589 gui.spellingdictionary
1590 gui.trustmtime
1591 help.autocorrect
1592 help.browser
1593 help.format
1594 http.lowSpeedLimit
1595 http.lowSpeedTime
1596 http.maxRequests
1597 http.noEPSV
1598 http.proxy
1599 http.sslCAInfo
1600 http.sslCAPath
1601 http.sslCert
1602 http.sslKey
1603 http.sslVerify
1604 i18n.commitEncoding
1605 i18n.logOutputEncoding
1606 imap.folder
1607 imap.host
1608 imap.pass
1609 imap.port
1610 imap.preformattedHTML
1611 imap.sslverify
1612 imap.tunnel
1613 imap.user
1614 instaweb.browser
1615 instaweb.httpd
1616 instaweb.local
1617 instaweb.modulepath
1618 instaweb.port
1619 interactive.singlekey
1620 log.date
1621 log.showroot
1622 mailmap.file
1623 man.
1624 man.viewer
1625 merge.conflictstyle
1626 merge.log
1627 merge.renameLimit
1628 merge.stat
1629 merge.tool
1630 merge.verbosity
1631 mergetool.
1632 mergetool.keepBackup
1633 mergetool.prompt
1634 pack.compression
1635 pack.deltaCacheLimit
1636 pack.deltaCacheSize
1637 pack.depth
1638 pack.indexVersion
1639 pack.packSizeLimit
1640 pack.threads
1641 pack.window
1642 pack.windowMemory
1643 pager.
1644 pull.octopus
1645 pull.twohead
1646 push.default
1647 rebase.stat
1648 receive.denyCurrentBranch
1649 receive.denyDeletes
1650 receive.denyNonFastForwards
1651 receive.fsckObjects
1652 receive.unpackLimit
1653 repack.usedeltabaseoffset
1654 rerere.autoupdate
1655 rerere.enabled
1656 sendemail.aliasesfile
1657 sendemail.aliasesfiletype
1658 sendemail.bcc
1659 sendemail.cc
1660 sendemail.cccmd
1661 sendemail.chainreplyto
1662 sendemail.confirm
1663 sendemail.envelopesender
1664 sendemail.multiedit
1665 sendemail.signedoffbycc
1666 sendemail.smtpencryption
1667 sendemail.smtppass
1668 sendemail.smtpserver
1669 sendemail.smtpserverport
1670 sendemail.smtpuser
1671 sendemail.suppresscc
1672 sendemail.suppressfrom
1673 sendemail.thread
1674 sendemail.to
1675 sendemail.validate
1676 showbranch.default
1677 status.relativePaths
1678 status.showUntrackedFiles
1679 tar.umask
1680 transfer.unpackLimit
1681 url.
1682 user.email
1683 user.name
1684 user.signingkey
1685 web.browser
1686 branch. remote.
1690 _git_remote ()
1692 local subcommands="add rename rm show prune update set-head"
1693 local subcommand="$(__git_find_subcommand "$subcommands")"
1694 if [ -z "$subcommand" ]; then
1695 __gitcomp "$subcommands"
1696 return
1699 case "$subcommand" in
1700 rename|rm|show|prune)
1701 __gitcomp "$(__git_remotes)"
1703 update)
1704 local i c='' IFS=$'\n'
1705 for i in $(git --git-dir="$(__gitdir)" config --list); do
1706 case "$i" in
1707 remotes.*)
1708 i="${i#remotes.}"
1709 c="$c ${i/=*/}"
1711 esac
1712 done
1713 __gitcomp "$c"
1716 COMPREPLY=()
1718 esac
1721 _git_reset ()
1723 __git_has_doubledash && return
1725 local cur="${COMP_WORDS[COMP_CWORD]}"
1726 case "$cur" in
1727 --*)
1728 __gitcomp "--merge --mixed --hard --soft"
1729 return
1731 esac
1732 __gitcomp "$(__git_refs)"
1735 _git_revert ()
1737 local cur="${COMP_WORDS[COMP_CWORD]}"
1738 case "$cur" in
1739 --*)
1740 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1741 return
1743 esac
1744 __gitcomp "$(__git_refs)"
1747 _git_rm ()
1749 __git_has_doubledash && return
1751 local cur="${COMP_WORDS[COMP_CWORD]}"
1752 case "$cur" in
1753 --*)
1754 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1755 return
1757 esac
1758 COMPREPLY=()
1761 _git_shortlog ()
1763 __git_has_doubledash && return
1765 local cur="${COMP_WORDS[COMP_CWORD]}"
1766 case "$cur" in
1767 --*)
1768 __gitcomp "
1769 $__git_log_common_options
1770 $__git_log_shortlog_options
1771 --numbered --summary
1773 return
1775 esac
1776 __git_complete_revlist
1779 _git_show ()
1781 __git_has_doubledash && return
1783 local cur="${COMP_WORDS[COMP_CWORD]}"
1784 case "$cur" in
1785 --pretty=*)
1786 __gitcomp "$__git_log_pretty_formats
1787 " "" "${cur##--pretty=}"
1788 return
1790 --format=*)
1791 __gitcomp "$__git_log_pretty_formats
1792 " "" "${cur##--format=}"
1793 return
1795 --*)
1796 __gitcomp "--pretty= --format=
1797 $__git_diff_common_options
1799 return
1801 esac
1802 __git_complete_file
1805 _git_show_branch ()
1807 local cur="${COMP_WORDS[COMP_CWORD]}"
1808 case "$cur" in
1809 --*)
1810 __gitcomp "
1811 --all --remotes --topo-order --current --more=
1812 --list --independent --merge-base --no-name
1813 --sha1-name --topics --reflog
1815 return
1817 esac
1818 __git_complete_revlist
1821 _git_stash ()
1823 local subcommands='save list show apply clear drop pop create branch'
1824 local subcommand="$(__git_find_subcommand "$subcommands")"
1825 if [ -z "$subcommand" ]; then
1826 __gitcomp "$subcommands"
1827 else
1828 local cur="${COMP_WORDS[COMP_CWORD]}"
1829 case "$subcommand,$cur" in
1830 save,--*)
1831 __gitcomp "--keep-index"
1833 apply,--*)
1834 __gitcomp "--index"
1836 show,--*|drop,--*|pop,--*|branch,--*)
1837 COMPREPLY=()
1839 show,*|apply,*|drop,*|pop,*|branch,*)
1840 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1841 | sed -n -e 's/:.*//p')"
1844 COMPREPLY=()
1846 esac
1850 _git_submodule ()
1852 __git_has_doubledash && return
1854 local subcommands="add status init update summary foreach sync"
1855 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1856 local cur="${COMP_WORDS[COMP_CWORD]}"
1857 case "$cur" in
1858 --*)
1859 __gitcomp "--quiet --cached"
1862 __gitcomp "$subcommands"
1864 esac
1865 return
1869 _git_svn ()
1871 local subcommands="
1872 init fetch clone rebase dcommit log find-rev
1873 set-tree commit-diff info create-ignore propget
1874 proplist show-ignore show-externals branch tag blame
1875 migrate
1877 local subcommand="$(__git_find_subcommand "$subcommands")"
1878 if [ -z "$subcommand" ]; then
1879 __gitcomp "$subcommands"
1880 else
1881 local remote_opts="--username= --config-dir= --no-auth-cache"
1882 local fc_opts="
1883 --follow-parent --authors-file= --repack=
1884 --no-metadata --use-svm-props --use-svnsync-props
1885 --log-window-size= --no-checkout --quiet
1886 --repack-flags --use-log-author --localtime
1887 --ignore-paths= $remote_opts
1889 local init_opts="
1890 --template= --shared= --trunk= --tags=
1891 --branches= --stdlayout --minimize-url
1892 --no-metadata --use-svm-props --use-svnsync-props
1893 --rewrite-root= --prefix= --use-log-author
1894 --add-author-from $remote_opts
1896 local cmt_opts="
1897 --edit --rmdir --find-copies-harder --copy-similarity=
1900 local cur="${COMP_WORDS[COMP_CWORD]}"
1901 case "$subcommand,$cur" in
1902 fetch,--*)
1903 __gitcomp "--revision= --fetch-all $fc_opts"
1905 clone,--*)
1906 __gitcomp "--revision= $fc_opts $init_opts"
1908 init,--*)
1909 __gitcomp "$init_opts"
1911 dcommit,--*)
1912 __gitcomp "
1913 --merge --strategy= --verbose --dry-run
1914 --fetch-all --no-rebase --commit-url
1915 --revision $cmt_opts $fc_opts
1918 set-tree,--*)
1919 __gitcomp "--stdin $cmt_opts $fc_opts"
1921 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1922 show-externals,--*)
1923 __gitcomp "--revision="
1925 log,--*)
1926 __gitcomp "
1927 --limit= --revision= --verbose --incremental
1928 --oneline --show-commit --non-recursive
1929 --authors-file= --color
1932 rebase,--*)
1933 __gitcomp "
1934 --merge --verbose --strategy= --local
1935 --fetch-all --dry-run $fc_opts
1938 commit-diff,--*)
1939 __gitcomp "--message= --file= --revision= $cmt_opts"
1941 info,--*)
1942 __gitcomp "--url"
1944 branch,--*)
1945 __gitcomp "--dry-run --message --tag"
1947 tag,--*)
1948 __gitcomp "--dry-run --message"
1950 blame,--*)
1951 __gitcomp "--git-format"
1953 migrate,--*)
1954 __gitcomp "
1955 --config-dir= --ignore-paths= --minimize
1956 --no-auth-cache --username=
1960 COMPREPLY=()
1962 esac
1966 _git_tag ()
1968 local i c=1 f=0
1969 while [ $c -lt $COMP_CWORD ]; do
1970 i="${COMP_WORDS[c]}"
1971 case "$i" in
1972 -d|-v)
1973 __gitcomp "$(__git_tags)"
1974 return
1979 esac
1980 c=$((++c))
1981 done
1983 case "${COMP_WORDS[COMP_CWORD-1]}" in
1984 -m|-F)
1985 COMPREPLY=()
1987 -*|tag)
1988 if [ $f = 1 ]; then
1989 __gitcomp "$(__git_tags)"
1990 else
1991 COMPREPLY=()
1995 __gitcomp "$(__git_refs)"
1997 esac
2000 _git ()
2002 local i c=1 command __git_dir
2004 while [ $c -lt $COMP_CWORD ]; do
2005 i="${COMP_WORDS[c]}"
2006 case "$i" in
2007 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2008 --bare) __git_dir="." ;;
2009 --version|-p|--paginate) ;;
2010 --help) command="help"; break ;;
2011 *) command="$i"; break ;;
2012 esac
2013 c=$((++c))
2014 done
2016 if [ -z "$command" ]; then
2017 case "${COMP_WORDS[COMP_CWORD]}" in
2018 --*) __gitcomp "
2019 --paginate
2020 --no-pager
2021 --git-dir=
2022 --bare
2023 --version
2024 --exec-path
2025 --html-path
2026 --work-tree=
2027 --help
2030 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
2031 esac
2032 return
2035 local expansion=$(__git_aliased_command "$command")
2036 [ "$expansion" ] && command="$expansion"
2038 case "$command" in
2039 am) _git_am ;;
2040 add) _git_add ;;
2041 apply) _git_apply ;;
2042 archive) _git_archive ;;
2043 bisect) _git_bisect ;;
2044 bundle) _git_bundle ;;
2045 branch) _git_branch ;;
2046 checkout) _git_checkout ;;
2047 cherry) _git_cherry ;;
2048 cherry-pick) _git_cherry_pick ;;
2049 clean) _git_clean ;;
2050 clone) _git_clone ;;
2051 commit) _git_commit ;;
2052 config) _git_config ;;
2053 describe) _git_describe ;;
2054 diff) _git_diff ;;
2055 difftool) _git_difftool ;;
2056 fetch) _git_fetch ;;
2057 format-patch) _git_format_patch ;;
2058 fsck) _git_fsck ;;
2059 gc) _git_gc ;;
2060 grep) _git_grep ;;
2061 help) _git_help ;;
2062 init) _git_init ;;
2063 log) _git_log ;;
2064 ls-files) _git_ls_files ;;
2065 ls-remote) _git_ls_remote ;;
2066 ls-tree) _git_ls_tree ;;
2067 merge) _git_merge;;
2068 mergetool) _git_mergetool;;
2069 merge-base) _git_merge_base ;;
2070 mv) _git_mv ;;
2071 name-rev) _git_name_rev ;;
2072 pull) _git_pull ;;
2073 push) _git_push ;;
2074 rebase) _git_rebase ;;
2075 remote) _git_remote ;;
2076 reset) _git_reset ;;
2077 revert) _git_revert ;;
2078 rm) _git_rm ;;
2079 send-email) _git_send_email ;;
2080 shortlog) _git_shortlog ;;
2081 show) _git_show ;;
2082 show-branch) _git_show_branch ;;
2083 stash) _git_stash ;;
2084 stage) _git_add ;;
2085 submodule) _git_submodule ;;
2086 svn) _git_svn ;;
2087 tag) _git_tag ;;
2088 whatchanged) _git_log ;;
2089 *) COMPREPLY=() ;;
2090 esac
2093 _gitk ()
2095 __git_has_doubledash && return
2097 local cur="${COMP_WORDS[COMP_CWORD]}"
2098 local g="$(__gitdir)"
2099 local merge=""
2100 if [ -f "$g/MERGE_HEAD" ]; then
2101 merge="--merge"
2103 case "$cur" in
2104 --*)
2105 __gitcomp "
2106 $__git_log_common_options
2107 $__git_log_gitk_options
2108 $merge
2110 return
2112 esac
2113 __git_complete_revlist
2116 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2117 || complete -o default -o nospace -F _git git
2118 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2119 || complete -o default -o nospace -F _gitk gitk
2121 # The following are necessary only for Cygwin, and only are needed
2122 # when the user has tab-completed the executable name and consequently
2123 # included the '.exe' suffix.
2125 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2126 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2127 || complete -o default -o nospace -F _git git.exe