Use 'trash directory' thoroughly in t/test-lib.sh
[git/jnareb-git/bp-gitweb.git] / contrib / completion / git-completion.bash
blob2141b6b6ba4cfed2c2ea3beca1e1149d489b75fa
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 __gitdir ()
50 if [ -z "$1" ]; then
51 if [ -n "$__git_dir" ]; then
52 echo "$__git_dir"
53 elif [ -d .git ]; then
54 echo .git
55 else
56 git rev-parse --git-dir 2>/dev/null
58 elif [ -d "$1/.git" ]; then
59 echo "$1/.git"
60 else
61 echo "$1"
65 __git_ps1 ()
67 local g="$(git rev-parse --git-dir 2>/dev/null)"
68 if [ -n "$g" ]; then
69 local r
70 local b
71 if [ -d "$g/../.dotest" ]
72 then
73 if test -f "$g/../.dotest/rebasing"
74 then
75 r="|REBASE"
76 elif test -f "$g/../.dotest/applying"
77 then
78 r="|AM"
79 else
80 r="|AM/REBASE"
82 b="$(git symbolic-ref HEAD 2>/dev/null)"
83 elif [ -f "$g/.dotest-merge/interactive" ]
84 then
85 r="|REBASE-i"
86 b="$(cat "$g/.dotest-merge/head-name")"
87 elif [ -d "$g/.dotest-merge" ]
88 then
89 r="|REBASE-m"
90 b="$(cat "$g/.dotest-merge/head-name")"
91 elif [ -f "$g/MERGE_HEAD" ]
92 then
93 r="|MERGING"
94 b="$(git symbolic-ref HEAD 2>/dev/null)"
95 else
96 if [ -f "$g/BISECT_LOG" ]
97 then
98 r="|BISECTING"
100 if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
101 then
102 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
103 then
104 b="$(cut -c1-7 "$g/HEAD")..."
109 if [ -n "$1" ]; then
110 printf "$1" "${b##refs/heads/}$r"
111 else
112 printf " (%s)" "${b##refs/heads/}$r"
117 __gitcomp ()
119 local all c s=$'\n' IFS=' '$'\t'$'\n'
120 local cur="${COMP_WORDS[COMP_CWORD]}"
121 if [ $# -gt 2 ]; then
122 cur="$3"
124 case "$cur" in
125 --*=)
126 COMPREPLY=()
127 return
130 for c in $1; do
131 case "$c$4" in
132 --*=*) all="$all$c$4$s" ;;
133 *.) all="$all$c$4$s" ;;
134 *) all="$all$c$4 $s" ;;
135 esac
136 done
138 esac
139 IFS=$s
140 COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
141 return
144 __git_heads ()
146 local cmd i is_hash=y dir="$(__gitdir "$1")"
147 if [ -d "$dir" ]; then
148 for i in $(git --git-dir="$dir" \
149 for-each-ref --format='%(refname)' \
150 refs/heads ); do
151 echo "${i#refs/heads/}"
152 done
153 return
155 for i in $(git ls-remote "$1" 2>/dev/null); do
156 case "$is_hash,$i" in
157 y,*) is_hash=n ;;
158 n,*^{}) is_hash=y ;;
159 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
160 n,*) is_hash=y; echo "$i" ;;
161 esac
162 done
165 __git_tags ()
167 local cmd i is_hash=y dir="$(__gitdir "$1")"
168 if [ -d "$dir" ]; then
169 for i in $(git --git-dir="$dir" \
170 for-each-ref --format='%(refname)' \
171 refs/tags ); do
172 echo "${i#refs/tags/}"
173 done
174 return
176 for i in $(git ls-remote "$1" 2>/dev/null); do
177 case "$is_hash,$i" in
178 y,*) is_hash=n ;;
179 n,*^{}) is_hash=y ;;
180 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
181 n,*) is_hash=y; echo "$i" ;;
182 esac
183 done
186 __git_refs ()
188 local cmd i is_hash=y dir="$(__gitdir "$1")"
189 if [ -d "$dir" ]; then
190 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
191 for i in $(git --git-dir="$dir" \
192 for-each-ref --format='%(refname)' \
193 refs/tags refs/heads refs/remotes); do
194 case "$i" in
195 refs/tags/*) echo "${i#refs/tags/}" ;;
196 refs/heads/*) echo "${i#refs/heads/}" ;;
197 refs/remotes/*) echo "${i#refs/remotes/}" ;;
198 *) echo "$i" ;;
199 esac
200 done
201 return
203 for i in $(git ls-remote "$dir" 2>/dev/null); do
204 case "$is_hash,$i" in
205 y,*) is_hash=n ;;
206 n,*^{}) is_hash=y ;;
207 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
208 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
209 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
210 n,*) is_hash=y; echo "$i" ;;
211 esac
212 done
215 __git_refs2 ()
217 local i
218 for i in $(__git_refs "$1"); do
219 echo "$i:$i"
220 done
223 __git_refs_remotes ()
225 local cmd i is_hash=y
226 for i in $(git ls-remote "$1" 2>/dev/null); do
227 case "$is_hash,$i" in
228 n,refs/heads/*)
229 is_hash=y
230 echo "$i:refs/remotes/$1/${i#refs/heads/}"
232 y,*) is_hash=n ;;
233 n,*^{}) is_hash=y ;;
234 n,refs/tags/*) is_hash=y;;
235 n,*) is_hash=y; ;;
236 esac
237 done
240 __git_remotes ()
242 local i ngoff IFS=$'\n' d="$(__gitdir)"
243 shopt -q nullglob || ngoff=1
244 shopt -s nullglob
245 for i in "$d/remotes"/*; do
246 echo ${i#$d/remotes/}
247 done
248 [ "$ngoff" ] && shopt -u nullglob
249 for i in $(git --git-dir="$d" config --list); do
250 case "$i" in
251 remote.*.url=*)
252 i="${i#remote.}"
253 echo "${i/.url=*/}"
255 esac
256 done
259 __git_merge_strategies ()
261 if [ -n "$__git_merge_strategylist" ]; then
262 echo "$__git_merge_strategylist"
263 return
265 sed -n "/^all_strategies='/{
266 s/^all_strategies='//
267 s/'//
270 }" "$(git --exec-path)/git-merge"
272 __git_merge_strategylist=
273 __git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
275 __git_complete_file ()
277 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
278 case "$cur" in
279 ?*:*)
280 ref="${cur%%:*}"
281 cur="${cur#*:}"
282 case "$cur" in
283 ?*/*)
284 pfx="${cur%/*}"
285 cur="${cur##*/}"
286 ls="$ref:$pfx"
287 pfx="$pfx/"
290 ls="$ref"
292 esac
293 COMPREPLY=($(compgen -P "$pfx" \
294 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
295 | sed '/^100... blob /s,^.* ,,
296 /^040000 tree /{
297 s,^.* ,,
298 s,$,/,
300 s/^.* //')" \
301 -- "$cur"))
304 __gitcomp "$(__git_refs)"
306 esac
309 __git_complete_revlist ()
311 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
312 case "$cur" in
313 *...*)
314 pfx="${cur%...*}..."
315 cur="${cur#*...}"
316 __gitcomp "$(__git_refs)" "$pfx" "$cur"
318 *..*)
319 pfx="${cur%..*}.."
320 cur="${cur#*..}"
321 __gitcomp "$(__git_refs)" "$pfx" "$cur"
324 __gitcomp "$cur."
327 __gitcomp "$(__git_refs)"
329 esac
332 __git_commands ()
334 if [ -n "$__git_commandlist" ]; then
335 echo "$__git_commandlist"
336 return
338 local i IFS=" "$'\n'
339 for i in $(git help -a|egrep '^ ')
341 case $i in
342 *--*) : helper pattern;;
343 applymbox) : ask gittus;;
344 applypatch) : ask gittus;;
345 archimport) : import;;
346 cat-file) : plumbing;;
347 check-attr) : plumbing;;
348 check-ref-format) : plumbing;;
349 commit-tree) : plumbing;;
350 cvsexportcommit) : export;;
351 cvsimport) : import;;
352 cvsserver) : daemon;;
353 daemon) : daemon;;
354 diff-files) : plumbing;;
355 diff-index) : plumbing;;
356 diff-tree) : plumbing;;
357 fast-import) : import;;
358 fsck-objects) : plumbing;;
359 fetch-pack) : plumbing;;
360 fmt-merge-msg) : plumbing;;
361 for-each-ref) : plumbing;;
362 hash-object) : plumbing;;
363 http-*) : transport;;
364 index-pack) : plumbing;;
365 init-db) : deprecated;;
366 local-fetch) : plumbing;;
367 mailinfo) : plumbing;;
368 mailsplit) : plumbing;;
369 merge-*) : plumbing;;
370 mktree) : plumbing;;
371 mktag) : plumbing;;
372 pack-objects) : plumbing;;
373 pack-redundant) : plumbing;;
374 pack-refs) : plumbing;;
375 parse-remote) : plumbing;;
376 patch-id) : plumbing;;
377 peek-remote) : plumbing;;
378 prune) : plumbing;;
379 prune-packed) : plumbing;;
380 quiltimport) : import;;
381 read-tree) : plumbing;;
382 receive-pack) : plumbing;;
383 reflog) : plumbing;;
384 repo-config) : deprecated;;
385 rerere) : plumbing;;
386 rev-list) : plumbing;;
387 rev-parse) : plumbing;;
388 runstatus) : plumbing;;
389 sh-setup) : internal;;
390 shell) : daemon;;
391 send-pack) : plumbing;;
392 show-index) : plumbing;;
393 ssh-*) : transport;;
394 stripspace) : plumbing;;
395 symbolic-ref) : plumbing;;
396 tar-tree) : deprecated;;
397 unpack-file) : plumbing;;
398 unpack-objects) : plumbing;;
399 update-index) : plumbing;;
400 update-ref) : plumbing;;
401 update-server-info) : daemon;;
402 upload-archive) : plumbing;;
403 upload-pack) : plumbing;;
404 write-tree) : plumbing;;
405 verify-tag) : plumbing;;
406 *) echo $i;;
407 esac
408 done
410 __git_commandlist=
411 __git_commandlist="$(__git_commands 2>/dev/null)"
413 __git_aliases ()
415 local i IFS=$'\n'
416 for i in $(git --git-dir="$(__gitdir)" config --list); do
417 case "$i" in
418 alias.*)
419 i="${i#alias.}"
420 echo "${i/=*/}"
422 esac
423 done
426 __git_aliased_command ()
428 local word cmdline=$(git --git-dir="$(__gitdir)" \
429 config --get "alias.$1")
430 for word in $cmdline; do
431 if [ "${word##-*}" ]; then
432 echo $word
433 return
435 done
438 __git_find_subcommand ()
440 local word subcommand c=1
442 while [ $c -lt $COMP_CWORD ]; do
443 word="${COMP_WORDS[c]}"
444 for subcommand in $1; do
445 if [ "$subcommand" = "$word" ]; then
446 echo "$subcommand"
447 return
449 done
450 c=$((++c))
451 done
454 __git_whitespacelist="nowarn warn error error-all strip"
456 _git_am ()
458 local cur="${COMP_WORDS[COMP_CWORD]}"
459 if [ -d .dotest ]; then
460 __gitcomp "--skip --resolved"
461 return
463 case "$cur" in
464 --whitespace=*)
465 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
466 return
468 --*)
469 __gitcomp "
470 --signoff --utf8 --binary --3way --interactive
471 --whitespace=
473 return
474 esac
475 COMPREPLY=()
478 _git_apply ()
480 local cur="${COMP_WORDS[COMP_CWORD]}"
481 case "$cur" in
482 --whitespace=*)
483 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
484 return
486 --*)
487 __gitcomp "
488 --stat --numstat --summary --check --index
489 --cached --index-info --reverse --reject --unidiff-zero
490 --apply --no-add --exclude=
491 --whitespace= --inaccurate-eof --verbose
493 return
494 esac
495 COMPREPLY=()
498 _git_add ()
500 local cur="${COMP_WORDS[COMP_CWORD]}"
501 case "$cur" in
502 --*)
503 __gitcomp "
504 --interactive --refresh --patch --update --dry-run
505 --ignore-errors
507 return
508 esac
509 COMPREPLY=()
512 _git_bisect ()
514 local subcommands="start bad good reset visualize replay log"
515 local subcommand="$(__git_find_subcommand "$subcommands")"
516 if [ -z "$subcommand" ]; then
517 __gitcomp "$subcommands"
518 return
521 case "$subcommand" in
522 bad|good|reset)
523 __gitcomp "$(__git_refs)"
526 COMPREPLY=()
528 esac
531 _git_branch ()
533 local i c=1 only_local_ref="n" has_r="n"
535 while [ $c -lt $COMP_CWORD ]; do
536 i="${COMP_WORDS[c]}"
537 case "$i" in
538 -d|-m) only_local_ref="y" ;;
539 -r) has_r="y" ;;
540 esac
541 c=$((++c))
542 done
544 case "${COMP_WORDS[COMP_CWORD]}" in
545 --*=*) COMPREPLY=() ;;
546 --*)
547 __gitcomp "
548 --color --no-color --verbose --abbrev= --no-abbrev
549 --track --no-track
553 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
554 __gitcomp "$(__git_heads)"
555 else
556 __gitcomp "$(__git_refs)"
559 esac
562 _git_bundle ()
564 local mycword="$COMP_CWORD"
565 case "${COMP_WORDS[0]}" in
566 git)
567 local cmd="${COMP_WORDS[2]}"
568 mycword="$((mycword-1))"
570 git-bundle*)
571 local cmd="${COMP_WORDS[1]}"
573 esac
574 case "$mycword" in
576 __gitcomp "create list-heads verify unbundle"
579 # looking for a file
582 case "$cmd" in
583 create)
584 __git_complete_revlist
586 esac
588 esac
591 _git_checkout ()
593 __gitcomp "$(__git_refs)"
596 _git_cherry ()
598 __gitcomp "$(__git_refs)"
601 _git_cherry_pick ()
603 local cur="${COMP_WORDS[COMP_CWORD]}"
604 case "$cur" in
605 --*)
606 __gitcomp "--edit --no-commit"
609 __gitcomp "$(__git_refs)"
611 esac
614 _git_commit ()
616 local cur="${COMP_WORDS[COMP_CWORD]}"
617 case "$cur" in
618 --*)
619 __gitcomp "
620 --all --author= --signoff --verify --no-verify
621 --edit --amend --include --only
623 return
624 esac
625 COMPREPLY=()
628 _git_describe ()
630 __gitcomp "$(__git_refs)"
633 _git_diff ()
635 local cur="${COMP_WORDS[COMP_CWORD]}"
636 case "$cur" in
637 --*)
638 __gitcomp "--cached --stat --numstat --shortstat --summary
639 --patch-with-stat --name-only --name-status --color
640 --no-color --color-words --no-renames --check
641 --full-index --binary --abbrev --diff-filter
642 --find-copies-harder --pickaxe-all --pickaxe-regex
643 --text --ignore-space-at-eol --ignore-space-change
644 --ignore-all-space --exit-code --quiet --ext-diff
645 --no-ext-diff
646 --no-prefix --src-prefix= --dst-prefix=
647 --base --ours --theirs
649 return
651 esac
652 __git_complete_file
655 _git_diff_tree ()
657 __gitcomp "$(__git_refs)"
660 _git_fetch ()
662 local cur="${COMP_WORDS[COMP_CWORD]}"
664 case "${COMP_WORDS[0]},$COMP_CWORD" in
665 git-fetch*,1)
666 __gitcomp "$(__git_remotes)"
668 git,2)
669 __gitcomp "$(__git_remotes)"
672 case "$cur" in
673 *:*)
674 __gitcomp "$(__git_refs)" "" "${cur#*:}"
677 local remote
678 case "${COMP_WORDS[0]}" in
679 git-fetch) remote="${COMP_WORDS[1]}" ;;
680 git) remote="${COMP_WORDS[2]}" ;;
681 esac
682 __gitcomp "$(__git_refs2 "$remote")"
684 esac
686 esac
689 _git_format_patch ()
691 local cur="${COMP_WORDS[COMP_CWORD]}"
692 case "$cur" in
693 --*)
694 __gitcomp "
695 --stdout --attach --thread
696 --output-directory
697 --numbered --start-number
698 --numbered-files
699 --keep-subject
700 --signoff
701 --in-reply-to=
702 --full-index --binary
703 --not --all
704 --cover-letter
705 --no-prefix --src-prefix= --dst-prefix=
707 return
709 esac
710 __git_complete_revlist
713 _git_gc ()
715 local cur="${COMP_WORDS[COMP_CWORD]}"
716 case "$cur" in
717 --*)
718 __gitcomp "--prune --aggressive"
719 return
721 esac
722 COMPREPLY=()
725 _git_ls_remote ()
727 __gitcomp "$(__git_remotes)"
730 _git_ls_tree ()
732 __git_complete_file
735 _git_log ()
737 local cur="${COMP_WORDS[COMP_CWORD]}"
738 case "$cur" in
739 --pretty=*)
740 __gitcomp "
741 oneline short medium full fuller email raw
742 " "" "${cur##--pretty=}"
743 return
745 --date=*)
746 __gitcomp "
747 relative iso8601 rfc2822 short local default
748 " "" "${cur##--date=}"
749 return
751 --*)
752 __gitcomp "
753 --max-count= --max-age= --since= --after=
754 --min-age= --before= --until=
755 --root --topo-order --date-order --reverse
756 --no-merges --follow
757 --abbrev-commit --abbrev=
758 --relative-date --date=
759 --author= --committer= --grep=
760 --all-match
761 --pretty= --name-status --name-only --raw
762 --not --all
763 --left-right --cherry-pick
765 return
767 esac
768 __git_complete_revlist
771 _git_merge ()
773 local cur="${COMP_WORDS[COMP_CWORD]}"
774 case "${COMP_WORDS[COMP_CWORD-1]}" in
775 -s|--strategy)
776 __gitcomp "$(__git_merge_strategies)"
777 return
778 esac
779 case "$cur" in
780 --strategy=*)
781 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
782 return
784 --*)
785 __gitcomp "
786 --no-commit --no-stat --log --no-log --squash --strategy
788 return
789 esac
790 __gitcomp "$(__git_refs)"
793 _git_merge_base ()
795 __gitcomp "$(__git_refs)"
798 _git_name_rev ()
800 __gitcomp "--tags --all --stdin"
803 _git_pull ()
805 local cur="${COMP_WORDS[COMP_CWORD]}"
807 case "${COMP_WORDS[0]},$COMP_CWORD" in
808 git-pull*,1)
809 __gitcomp "$(__git_remotes)"
811 git,2)
812 __gitcomp "$(__git_remotes)"
815 local remote
816 case "${COMP_WORDS[0]}" in
817 git-pull) remote="${COMP_WORDS[1]}" ;;
818 git) remote="${COMP_WORDS[2]}" ;;
819 esac
820 __gitcomp "$(__git_refs "$remote")"
822 esac
825 _git_push ()
827 local cur="${COMP_WORDS[COMP_CWORD]}"
829 case "${COMP_WORDS[0]},$COMP_CWORD" in
830 git-push*,1)
831 __gitcomp "$(__git_remotes)"
833 git,2)
834 __gitcomp "$(__git_remotes)"
837 case "$cur" in
838 *:*)
839 local remote
840 case "${COMP_WORDS[0]}" in
841 git-push) remote="${COMP_WORDS[1]}" ;;
842 git) remote="${COMP_WORDS[2]}" ;;
843 esac
844 __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
847 __gitcomp "$(__git_refs)" + "${cur#+}"
850 __gitcomp "$(__git_refs)"
852 esac
854 esac
857 _git_rebase ()
859 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
860 if [ -d .dotest ] || [ -d "$dir"/.dotest-merge ]; then
861 __gitcomp "--continue --skip --abort"
862 return
864 case "${COMP_WORDS[COMP_CWORD-1]}" in
865 -s|--strategy)
866 __gitcomp "$(__git_merge_strategies)"
867 return
868 esac
869 case "$cur" in
870 --strategy=*)
871 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
872 return
874 --*)
875 __gitcomp "--onto --merge --strategy --interactive"
876 return
877 esac
878 __gitcomp "$(__git_refs)"
881 _git_config ()
883 local cur="${COMP_WORDS[COMP_CWORD]}"
884 local prv="${COMP_WORDS[COMP_CWORD-1]}"
885 case "$prv" in
886 branch.*.remote)
887 __gitcomp "$(__git_remotes)"
888 return
890 branch.*.merge)
891 __gitcomp "$(__git_refs)"
892 return
894 remote.*.fetch)
895 local remote="${prv#remote.}"
896 remote="${remote%.fetch}"
897 __gitcomp "$(__git_refs_remotes "$remote")"
898 return
900 remote.*.push)
901 local remote="${prv#remote.}"
902 remote="${remote%.push}"
903 __gitcomp "$(git --git-dir="$(__gitdir)" \
904 for-each-ref --format='%(refname):%(refname)' \
905 refs/heads)"
906 return
908 pull.twohead|pull.octopus)
909 __gitcomp "$(__git_merge_strategies)"
910 return
912 color.branch|color.diff|color.status)
913 __gitcomp "always never auto"
914 return
916 color.*.*)
917 __gitcomp "
918 black red green yellow blue magenta cyan white
919 bold dim ul blink reverse
921 return
923 *.*)
924 COMPREPLY=()
925 return
927 esac
928 case "$cur" in
929 --*)
930 __gitcomp "
931 --global --system --file=
932 --list --replace-all
933 --get --get-all --get-regexp
934 --add --unset --unset-all
935 --remove-section --rename-section
937 return
939 branch.*.*)
940 local pfx="${cur%.*}."
941 cur="${cur##*.}"
942 __gitcomp "remote merge" "$pfx" "$cur"
943 return
945 branch.*)
946 local pfx="${cur%.*}."
947 cur="${cur#*.}"
948 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
949 return
951 remote.*.*)
952 local pfx="${cur%.*}."
953 cur="${cur##*.}"
954 __gitcomp "
955 url fetch push skipDefaultUpdate
956 receivepack uploadpack tagopt
957 " "$pfx" "$cur"
958 return
960 remote.*)
961 local pfx="${cur%.*}."
962 cur="${cur#*.}"
963 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
964 return
966 esac
967 __gitcomp "
968 apply.whitespace
969 core.fileMode
970 core.gitProxy
971 core.ignoreStat
972 core.preferSymlinkRefs
973 core.logAllRefUpdates
974 core.loosecompression
975 core.repositoryFormatVersion
976 core.sharedRepository
977 core.warnAmbiguousRefs
978 core.compression
979 core.packedGitWindowSize
980 core.packedGitLimit
981 clean.requireForce
982 color.branch
983 color.branch.current
984 color.branch.local
985 color.branch.remote
986 color.branch.plain
987 color.diff
988 color.diff.plain
989 color.diff.meta
990 color.diff.frag
991 color.diff.old
992 color.diff.new
993 color.diff.commit
994 color.diff.whitespace
995 color.pager
996 color.status
997 color.status.header
998 color.status.added
999 color.status.changed
1000 color.status.untracked
1001 diff.renameLimit
1002 diff.renames
1003 fetch.unpackLimit
1004 format.headers
1005 format.subjectprefix
1006 gitcvs.enabled
1007 gitcvs.logfile
1008 gitcvs.allbinary
1009 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
1010 gitcvs.dbtablenameprefix
1011 gc.packrefs
1012 gc.reflogexpire
1013 gc.reflogexpireunreachable
1014 gc.rerereresolved
1015 gc.rerereunresolved
1016 http.sslVerify
1017 http.sslCert
1018 http.sslKey
1019 http.sslCAInfo
1020 http.sslCAPath
1021 http.maxRequests
1022 http.lowSpeedLimit
1023 http.lowSpeedTime
1024 http.noEPSV
1025 i18n.commitEncoding
1026 i18n.logOutputEncoding
1027 log.showroot
1028 merge.tool
1029 merge.summary
1030 merge.verbosity
1031 pack.window
1032 pack.depth
1033 pack.windowMemory
1034 pack.compression
1035 pack.deltaCacheSize
1036 pack.deltaCacheLimit
1037 pull.octopus
1038 pull.twohead
1039 repack.useDeltaBaseOffset
1040 show.difftree
1041 showbranch.default
1042 tar.umask
1043 transfer.unpackLimit
1044 receive.unpackLimit
1045 receive.denyNonFastForwards
1046 user.name
1047 user.email
1048 user.signingkey
1049 whatchanged.difftree
1050 branch. remote.
1054 _git_remote ()
1056 local subcommands="add rm show prune update"
1057 local subcommand="$(__git_find_subcommand "$subcommands")"
1058 if [ -z "$subcommand" ]; then
1059 __gitcomp "$subcommands"
1060 return
1063 case "$subcommand" in
1064 rm|show|prune)
1065 __gitcomp "$(__git_remotes)"
1067 update)
1068 local i c='' IFS=$'\n'
1069 for i in $(git --git-dir="$(__gitdir)" config --list); do
1070 case "$i" in
1071 remotes.*)
1072 i="${i#remotes.}"
1073 c="$c ${i/=*/}"
1075 esac
1076 done
1077 __gitcomp "$c"
1080 COMPREPLY=()
1082 esac
1085 _git_reset ()
1087 local cur="${COMP_WORDS[COMP_CWORD]}"
1088 case "$cur" in
1089 --*)
1090 __gitcomp "--mixed --hard --soft"
1091 return
1093 esac
1094 __gitcomp "$(__git_refs)"
1097 _git_shortlog ()
1099 local cur="${COMP_WORDS[COMP_CWORD]}"
1100 case "$cur" in
1101 --*)
1102 __gitcomp "
1103 --max-count= --max-age= --since= --after=
1104 --min-age= --before= --until=
1105 --no-merges
1106 --author= --committer= --grep=
1107 --all-match
1108 --not --all
1109 --numbered --summary
1111 return
1113 esac
1114 __git_complete_revlist
1117 _git_show ()
1119 local cur="${COMP_WORDS[COMP_CWORD]}"
1120 case "$cur" in
1121 --pretty=*)
1122 __gitcomp "
1123 oneline short medium full fuller email raw
1124 " "" "${cur##--pretty=}"
1125 return
1127 --*)
1128 __gitcomp "--pretty="
1129 return
1131 esac
1132 __git_complete_file
1135 _git_stash ()
1137 local subcommands='save list show apply clear drop pop create'
1138 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1139 __gitcomp "$subcommands"
1143 _git_submodule ()
1145 local subcommands="add status init update"
1146 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1147 local cur="${COMP_WORDS[COMP_CWORD]}"
1148 case "$cur" in
1149 --*)
1150 __gitcomp "--quiet --cached"
1153 __gitcomp "$subcommands"
1155 esac
1156 return
1160 _git_svn ()
1162 local subcommands="
1163 init fetch clone rebase dcommit log find-rev
1164 set-tree commit-diff info create-ignore propget
1165 proplist show-ignore show-externals
1167 local subcommand="$(__git_find_subcommand "$subcommands")"
1168 if [ -z "$subcommand" ]; then
1169 __gitcomp "$subcommands"
1170 else
1171 local remote_opts="--username= --config-dir= --no-auth-cache"
1172 local fc_opts="
1173 --follow-parent --authors-file= --repack=
1174 --no-metadata --use-svm-props --use-svnsync-props
1175 --log-window-size= --no-checkout --quiet
1176 --repack-flags --user-log-author $remote_opts
1178 local init_opts="
1179 --template= --shared= --trunk= --tags=
1180 --branches= --stdlayout --minimize-url
1181 --no-metadata --use-svm-props --use-svnsync-props
1182 --rewrite-root= $remote_opts
1184 local cmt_opts="
1185 --edit --rmdir --find-copies-harder --copy-similarity=
1188 local cur="${COMP_WORDS[COMP_CWORD]}"
1189 case "$subcommand,$cur" in
1190 fetch,--*)
1191 __gitcomp "--revision= --fetch-all $fc_opts"
1193 clone,--*)
1194 __gitcomp "--revision= $fc_opts $init_opts"
1196 init,--*)
1197 __gitcomp "$init_opts"
1199 dcommit,--*)
1200 __gitcomp "
1201 --merge --strategy= --verbose --dry-run
1202 --fetch-all --no-rebase $cmt_opts $fc_opts
1205 set-tree,--*)
1206 __gitcomp "--stdin $cmt_opts $fc_opts"
1208 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1209 show-externals,--*)
1210 __gitcomp "--revision="
1212 log,--*)
1213 __gitcomp "
1214 --limit= --revision= --verbose --incremental
1215 --oneline --show-commit --non-recursive
1216 --authors-file=
1219 rebase,--*)
1220 __gitcomp "
1221 --merge --verbose --strategy= --local
1222 --fetch-all $fc_opts
1225 commit-diff,--*)
1226 __gitcomp "--message= --file= --revision= $cmt_opts"
1228 info,--*)
1229 __gitcomp "--url"
1232 COMPREPLY=()
1234 esac
1238 _git_tag ()
1240 local i c=1 f=0
1241 while [ $c -lt $COMP_CWORD ]; do
1242 i="${COMP_WORDS[c]}"
1243 case "$i" in
1244 -d|-v)
1245 __gitcomp "$(__git_tags)"
1246 return
1251 esac
1252 c=$((++c))
1253 done
1255 case "${COMP_WORDS[COMP_CWORD-1]}" in
1256 -m|-F)
1257 COMPREPLY=()
1259 -*|tag|git-tag)
1260 if [ $f = 1 ]; then
1261 __gitcomp "$(__git_tags)"
1262 else
1263 COMPREPLY=()
1267 __gitcomp "$(__git_refs)"
1269 esac
1272 _git ()
1274 local i c=1 command __git_dir
1276 while [ $c -lt $COMP_CWORD ]; do
1277 i="${COMP_WORDS[c]}"
1278 case "$i" in
1279 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1280 --bare) __git_dir="." ;;
1281 --version|--help|-p|--paginate) ;;
1282 *) command="$i"; break ;;
1283 esac
1284 c=$((++c))
1285 done
1287 if [ -z "$command" ]; then
1288 case "${COMP_WORDS[COMP_CWORD]}" in
1289 --*=*) COMPREPLY=() ;;
1290 --*) __gitcomp "
1291 --paginate
1292 --no-pager
1293 --git-dir=
1294 --bare
1295 --version
1296 --exec-path
1297 --work-tree=
1298 --help
1301 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1302 esac
1303 return
1306 local expansion=$(__git_aliased_command "$command")
1307 [ "$expansion" ] && command="$expansion"
1309 case "$command" in
1310 am) _git_am ;;
1311 add) _git_add ;;
1312 apply) _git_apply ;;
1313 bisect) _git_bisect ;;
1314 bundle) _git_bundle ;;
1315 branch) _git_branch ;;
1316 checkout) _git_checkout ;;
1317 cherry) _git_cherry ;;
1318 cherry-pick) _git_cherry_pick ;;
1319 commit) _git_commit ;;
1320 config) _git_config ;;
1321 describe) _git_describe ;;
1322 diff) _git_diff ;;
1323 fetch) _git_fetch ;;
1324 format-patch) _git_format_patch ;;
1325 gc) _git_gc ;;
1326 log) _git_log ;;
1327 ls-remote) _git_ls_remote ;;
1328 ls-tree) _git_ls_tree ;;
1329 merge) _git_merge;;
1330 merge-base) _git_merge_base ;;
1331 name-rev) _git_name_rev ;;
1332 pull) _git_pull ;;
1333 push) _git_push ;;
1334 rebase) _git_rebase ;;
1335 remote) _git_remote ;;
1336 reset) _git_reset ;;
1337 shortlog) _git_shortlog ;;
1338 show) _git_show ;;
1339 show-branch) _git_log ;;
1340 stash) _git_stash ;;
1341 submodule) _git_submodule ;;
1342 svn) _git_svn ;;
1343 tag) _git_tag ;;
1344 whatchanged) _git_log ;;
1345 *) COMPREPLY=() ;;
1346 esac
1349 _gitk ()
1351 local cur="${COMP_WORDS[COMP_CWORD]}"
1352 local g="$(git rev-parse --git-dir 2>/dev/null)"
1353 local merge=""
1354 if [ -f $g/MERGE_HEAD ]; then
1355 merge="--merge"
1357 case "$cur" in
1358 --*)
1359 __gitcomp "--not --all $merge"
1360 return
1362 esac
1363 __git_complete_revlist
1366 complete -o default -o nospace -F _git git
1367 complete -o default -o nospace -F _gitk gitk
1368 complete -o default -o nospace -F _git_am git-am
1369 complete -o default -o nospace -F _git_apply git-apply
1370 complete -o default -o nospace -F _git_bisect git-bisect
1371 complete -o default -o nospace -F _git_branch git-branch
1372 complete -o default -o nospace -F _git_bundle git-bundle
1373 complete -o default -o nospace -F _git_checkout git-checkout
1374 complete -o default -o nospace -F _git_cherry git-cherry
1375 complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1376 complete -o default -o nospace -F _git_commit git-commit
1377 complete -o default -o nospace -F _git_describe git-describe
1378 complete -o default -o nospace -F _git_diff git-diff
1379 complete -o default -o nospace -F _git_fetch git-fetch
1380 complete -o default -o nospace -F _git_format_patch git-format-patch
1381 complete -o default -o nospace -F _git_gc git-gc
1382 complete -o default -o nospace -F _git_log git-log
1383 complete -o default -o nospace -F _git_ls_remote git-ls-remote
1384 complete -o default -o nospace -F _git_ls_tree git-ls-tree
1385 complete -o default -o nospace -F _git_merge git-merge
1386 complete -o default -o nospace -F _git_merge_base git-merge-base
1387 complete -o default -o nospace -F _git_name_rev git-name-rev
1388 complete -o default -o nospace -F _git_pull git-pull
1389 complete -o default -o nospace -F _git_push git-push
1390 complete -o default -o nospace -F _git_rebase git-rebase
1391 complete -o default -o nospace -F _git_config git-config
1392 complete -o default -o nospace -F _git_remote git-remote
1393 complete -o default -o nospace -F _git_reset git-reset
1394 complete -o default -o nospace -F _git_shortlog git-shortlog
1395 complete -o default -o nospace -F _git_show git-show
1396 complete -o default -o nospace -F _git_stash git-stash
1397 complete -o default -o nospace -F _git_submodule git-submodule
1398 complete -o default -o nospace -F _git_svn git-svn
1399 complete -o default -o nospace -F _git_log git-show-branch
1400 complete -o default -o nospace -F _git_tag git-tag
1401 complete -o default -o nospace -F _git_log git-whatchanged
1403 # The following are necessary only for Cygwin, and only are needed
1404 # when the user has tab-completed the executable name and consequently
1405 # included the '.exe' suffix.
1407 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1408 complete -o default -o nospace -F _git_add git-add.exe
1409 complete -o default -o nospace -F _git_apply git-apply.exe
1410 complete -o default -o nospace -F _git git.exe
1411 complete -o default -o nospace -F _git_branch git-branch.exe
1412 complete -o default -o nospace -F _git_bundle git-bundle.exe
1413 complete -o default -o nospace -F _git_cherry git-cherry.exe
1414 complete -o default -o nospace -F _git_describe git-describe.exe
1415 complete -o default -o nospace -F _git_diff git-diff.exe
1416 complete -o default -o nospace -F _git_format_patch git-format-patch.exe
1417 complete -o default -o nospace -F _git_log git-log.exe
1418 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
1419 complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1420 complete -o default -o nospace -F _git_name_rev git-name-rev.exe
1421 complete -o default -o nospace -F _git_push git-push.exe
1422 complete -o default -o nospace -F _git_config git-config
1423 complete -o default -o nospace -F _git_shortlog git-shortlog.exe
1424 complete -o default -o nospace -F _git_show git-show.exe
1425 complete -o default -o nospace -F _git_log git-show-branch.exe
1426 complete -o default -o nospace -F _git_tag git-tag.exe
1427 complete -o default -o nospace -F _git_log git-whatchanged.exe