2c2a0d4614a5180a08adfa59414d06fdbe7754f0
1#!bash
2#
3# bash completion support for core Git.
4#
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.
8#
9# The contained completion routines provide support for completing:
10#
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
17#
18# To use these routines:
19#
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
23#
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.
29#
30# 4) Consider changing your PS1 to also show the current branch:
31# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
32#
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.
36#
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.
42#
43# You can also see if currently something is stashed, by setting
44# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
45# then a '$' will be shown next to the branch name.
46#
47# If you would like to see if there're untracked files, then you can
48# set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
49# untracked files, then a '%' will be shown next to the branch name.
50#
51# To submit patches:
52#
53# *) Read Documentation/SubmittingPatches
54# *) Send all patches to the current maintainer:
55#
56# "Shawn O. Pearce" <spearce@spearce.org>
57#
58# *) Always CC the Git mailing list:
59#
60# git@vger.kernel.org
61#
62
63case "$COMP_WORDBREAKS" in
64*:*) : great ;;
65*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
66esac
67
68# __gitdir accepts 0 or 1 arguments (i.e., location)
69# returns location of .git repo
70__gitdir ()
71{
72 if [ -z "${1-}" ]; then
73 if [ -n "${__git_dir-}" ]; then
74 echo "$__git_dir"
75 elif [ -d .git ]; then
76 echo .git
77 else
78 git rev-parse --git-dir 2>/dev/null
79 fi
80 elif [ -d "$1/.git" ]; then
81 echo "$1/.git"
82 else
83 echo "$1"
84 fi
85}
86
87# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
88# returns text to add to bash PS1 prompt (includes branch name)
89__git_ps1 ()
90{
91 local g="$(__gitdir)"
92 if [ -n "$g" ]; then
93 local r
94 local b
95 if [ -f "$g/rebase-merge/interactive" ]; then
96 r="|REBASE-i"
97 b="$(cat "$g/rebase-merge/head-name")"
98 elif [ -d "$g/rebase-merge" ]; then
99 r="|REBASE-m"
100 b="$(cat "$g/rebase-merge/head-name")"
101 else
102 if [ -d "$g/rebase-apply" ]; then
103 if [ -f "$g/rebase-apply/rebasing" ]; then
104 r="|REBASE"
105 elif [ -f "$g/rebase-apply/applying" ]; then
106 r="|AM"
107 else
108 r="|AM/REBASE"
109 fi
110 elif [ -f "$g/MERGE_HEAD" ]; then
111 r="|MERGING"
112 elif [ -f "$g/BISECT_LOG" ]; then
113 r="|BISECTING"
114 fi
115
116 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
117
118 b="$(
119 case "${GIT_PS1_DESCRIBE_STYLE-}" in
120 (contains)
121 git describe --contains HEAD ;;
122 (branch)
123 git describe --contains --all HEAD ;;
124 (describe)
125 git describe HEAD ;;
126 (* | default)
127 git describe --exact-match HEAD ;;
128 esac 2>/dev/null)" ||
129
130 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
131 b="unknown"
132 b="($b)"
133 }
134 fi
135
136 local w
137 local i
138 local s
139 local u
140 local c
141
142 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
143 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
144 c="BARE:"
145 else
146 b="GIT_DIR!"
147 fi
148 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
149 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
150 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
151 git diff --no-ext-diff --ignore-submodules \
152 --quiet --exit-code || w="*"
153 if git rev-parse --quiet --verify HEAD >/dev/null; then
154 git diff-index --cached --quiet \
155 --ignore-submodules HEAD -- || i="+"
156 else
157 i="#"
158 fi
159 fi
160 fi
161 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
162 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
163 fi
164
165 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
166 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
167 u="%"
168 fi
169 fi
170 fi
171
172 if [ -n "${1-}" ]; then
173 printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
174 else
175 printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
176 fi
177 fi
178}
179
180# __gitcomp_1 requires 2 arguments
181__gitcomp_1 ()
182{
183 local c IFS=' '$'\t'$'\n'
184 for c in $1; do
185 case "$c$2" in
186 --*=*) printf %s$'\n' "$c$2" ;;
187 *.) printf %s$'\n' "$c$2" ;;
188 *) printf %s$'\n' "$c$2 " ;;
189 esac
190 done
191}
192
193# __gitcomp accepts 1, 2, 3, or 4 arguments
194# generates completion reply with compgen
195__gitcomp ()
196{
197 local cur="${COMP_WORDS[COMP_CWORD]}"
198 if [ $# -gt 2 ]; then
199 cur="$3"
200 fi
201 case "$cur" in
202 --*=)
203 COMPREPLY=()
204 ;;
205 *)
206 local IFS=$'\n'
207 COMPREPLY=($(compgen -P "${2-}" \
208 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
209 -- "$cur"))
210 ;;
211 esac
212}
213
214# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
215__git_heads ()
216{
217 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
218 if [ -d "$dir" ]; then
219 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
220 refs/heads
221 return
222 fi
223 for i in $(git ls-remote "${1-}" 2>/dev/null); do
224 case "$is_hash,$i" in
225 y,*) is_hash=n ;;
226 n,*^{}) is_hash=y ;;
227 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
228 n,*) is_hash=y; echo "$i" ;;
229 esac
230 done
231}
232
233# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
234__git_tags ()
235{
236 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
237 if [ -d "$dir" ]; then
238 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
239 refs/tags
240 return
241 fi
242 for i in $(git ls-remote "${1-}" 2>/dev/null); do
243 case "$is_hash,$i" in
244 y,*) is_hash=n ;;
245 n,*^{}) is_hash=y ;;
246 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
247 n,*) is_hash=y; echo "$i" ;;
248 esac
249 done
250}
251
252# __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
253__git_refs ()
254{
255 local i is_hash=y dir="$(__gitdir "${1-}")"
256 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
257 if [ -d "$dir" ]; then
258 case "$cur" in
259 refs|refs/*)
260 format="refname"
261 refs="${cur%/*}"
262 ;;
263 *)
264 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
265 format="refname:short"
266 refs="refs/tags refs/heads refs/remotes"
267 ;;
268 esac
269 git --git-dir="$dir" for-each-ref --format="%($format)" \
270 $refs
271 return
272 fi
273 for i in $(git ls-remote "$dir" 2>/dev/null); do
274 case "$is_hash,$i" in
275 y,*) is_hash=n ;;
276 n,*^{}) is_hash=y ;;
277 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
278 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
279 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
280 n,*) is_hash=y; echo "$i" ;;
281 esac
282 done
283}
284
285# __git_refs2 requires 1 argument (to pass to __git_refs)
286__git_refs2 ()
287{
288 local i
289 for i in $(__git_refs "$1"); do
290 echo "$i:$i"
291 done
292}
293
294# __git_refs_remotes requires 1 argument (to pass to ls-remote)
295__git_refs_remotes ()
296{
297 local cmd i is_hash=y
298 for i in $(git ls-remote "$1" 2>/dev/null); do
299 case "$is_hash,$i" in
300 n,refs/heads/*)
301 is_hash=y
302 echo "$i:refs/remotes/$1/${i#refs/heads/}"
303 ;;
304 y,*) is_hash=n ;;
305 n,*^{}) is_hash=y ;;
306 n,refs/tags/*) is_hash=y;;
307 n,*) is_hash=y; ;;
308 esac
309 done
310}
311
312__git_remotes ()
313{
314 local i ngoff IFS=$'\n' d="$(__gitdir)"
315 shopt -q nullglob || ngoff=1
316 shopt -s nullglob
317 for i in "$d/remotes"/*; do
318 echo ${i#$d/remotes/}
319 done
320 [ "$ngoff" ] && shopt -u nullglob
321 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
322 i="${i#remote.}"
323 echo "${i/.url*/}"
324 done
325}
326
327__git_merge_strategies ()
328{
329 if [ -n "${__git_merge_strategylist-}" ]; then
330 echo "$__git_merge_strategylist"
331 return
332 fi
333 git merge -s help 2>&1 |
334 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
335 s/\.$//
336 s/.*://
337 s/^[ ]*//
338 s/[ ]*$//
339 p
340 }'
341}
342__git_merge_strategylist=
343__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
344
345__git_complete_file ()
346{
347 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
348 case "$cur" in
349 ?*:*)
350 ref="${cur%%:*}"
351 cur="${cur#*:}"
352 case "$cur" in
353 ?*/*)
354 pfx="${cur%/*}"
355 cur="${cur##*/}"
356 ls="$ref:$pfx"
357 pfx="$pfx/"
358 ;;
359 *)
360 ls="$ref"
361 ;;
362 esac
363
364 case "$COMP_WORDBREAKS" in
365 *:*) : great ;;
366 *) pfx="$ref:$pfx" ;;
367 esac
368
369 local IFS=$'\n'
370 COMPREPLY=($(compgen -P "$pfx" \
371 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
372 | sed '/^100... blob /{
373 s,^.* ,,
374 s,$, ,
375 }
376 /^120000 blob /{
377 s,^.* ,,
378 s,$, ,
379 }
380 /^040000 tree /{
381 s,^.* ,,
382 s,$,/,
383 }
384 s/^.* //')" \
385 -- "$cur"))
386 ;;
387 *)
388 __gitcomp "$(__git_refs)"
389 ;;
390 esac
391}
392
393__git_complete_revlist ()
394{
395 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
396 case "$cur" in
397 *...*)
398 pfx="${cur%...*}..."
399 cur="${cur#*...}"
400 __gitcomp "$(__git_refs)" "$pfx" "$cur"
401 ;;
402 *..*)
403 pfx="${cur%..*}.."
404 cur="${cur#*..}"
405 __gitcomp "$(__git_refs)" "$pfx" "$cur"
406 ;;
407 *)
408 __gitcomp "$(__git_refs)"
409 ;;
410 esac
411}
412
413__git_complete_remote_or_refspec ()
414{
415 local cmd="${COMP_WORDS[1]}"
416 local cur="${COMP_WORDS[COMP_CWORD]}"
417 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
418 while [ $c -lt $COMP_CWORD ]; do
419 i="${COMP_WORDS[c]}"
420 case "$i" in
421 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
422 -*) ;;
423 *) remote="$i"; break ;;
424 esac
425 c=$((++c))
426 done
427 if [ -z "$remote" ]; then
428 __gitcomp "$(__git_remotes)"
429 return
430 fi
431 if [ $no_complete_refspec = 1 ]; then
432 COMPREPLY=()
433 return
434 fi
435 [ "$remote" = "." ] && remote=
436 case "$cur" in
437 *:*)
438 case "$COMP_WORDBREAKS" in
439 *:*) : great ;;
440 *) pfx="${cur%%:*}:" ;;
441 esac
442 cur="${cur#*:}"
443 lhs=0
444 ;;
445 +*)
446 pfx="+"
447 cur="${cur#+}"
448 ;;
449 esac
450 case "$cmd" in
451 fetch)
452 if [ $lhs = 1 ]; then
453 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
454 else
455 __gitcomp "$(__git_refs)" "$pfx" "$cur"
456 fi
457 ;;
458 pull)
459 if [ $lhs = 1 ]; then
460 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
461 else
462 __gitcomp "$(__git_refs)" "$pfx" "$cur"
463 fi
464 ;;
465 push)
466 if [ $lhs = 1 ]; then
467 __gitcomp "$(__git_refs)" "$pfx" "$cur"
468 else
469 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
470 fi
471 ;;
472 esac
473}
474
475__git_complete_strategy ()
476{
477 case "${COMP_WORDS[COMP_CWORD-1]}" in
478 -s|--strategy)
479 __gitcomp "$(__git_merge_strategies)"
480 return 0
481 esac
482 local cur="${COMP_WORDS[COMP_CWORD]}"
483 case "$cur" in
484 --strategy=*)
485 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
486 return 0
487 ;;
488 esac
489 return 1
490}
491
492__git_all_commands ()
493{
494 if [ -n "${__git_all_commandlist-}" ]; then
495 echo "$__git_all_commandlist"
496 return
497 fi
498 local i IFS=" "$'\n'
499 for i in $(git help -a|egrep '^ ')
500 do
501 case $i in
502 *--*) : helper pattern;;
503 *) echo $i;;
504 esac
505 done
506}
507__git_all_commandlist=
508__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
509
510__git_porcelain_commands ()
511{
512 if [ -n "${__git_porcelain_commandlist-}" ]; then
513 echo "$__git_porcelain_commandlist"
514 return
515 fi
516 local i IFS=" "$'\n'
517 for i in "help" $(__git_all_commands)
518 do
519 case $i in
520 *--*) : helper pattern;;
521 applymbox) : ask gittus;;
522 applypatch) : ask gittus;;
523 archimport) : import;;
524 cat-file) : plumbing;;
525 check-attr) : plumbing;;
526 check-ref-format) : plumbing;;
527 checkout-index) : plumbing;;
528 commit-tree) : plumbing;;
529 count-objects) : infrequent;;
530 cvsexportcommit) : export;;
531 cvsimport) : import;;
532 cvsserver) : daemon;;
533 daemon) : daemon;;
534 diff-files) : plumbing;;
535 diff-index) : plumbing;;
536 diff-tree) : plumbing;;
537 fast-import) : import;;
538 fast-export) : export;;
539 fsck-objects) : plumbing;;
540 fetch-pack) : plumbing;;
541 fmt-merge-msg) : plumbing;;
542 for-each-ref) : plumbing;;
543 hash-object) : plumbing;;
544 http-*) : transport;;
545 index-pack) : plumbing;;
546 init-db) : deprecated;;
547 local-fetch) : plumbing;;
548 lost-found) : infrequent;;
549 ls-files) : plumbing;;
550 ls-remote) : plumbing;;
551 ls-tree) : plumbing;;
552 mailinfo) : plumbing;;
553 mailsplit) : plumbing;;
554 merge-*) : plumbing;;
555 mktree) : plumbing;;
556 mktag) : plumbing;;
557 pack-objects) : plumbing;;
558 pack-redundant) : plumbing;;
559 pack-refs) : plumbing;;
560 parse-remote) : plumbing;;
561 patch-id) : plumbing;;
562 peek-remote) : plumbing;;
563 prune) : plumbing;;
564 prune-packed) : plumbing;;
565 quiltimport) : import;;
566 read-tree) : plumbing;;
567 receive-pack) : plumbing;;
568 reflog) : plumbing;;
569 repo-config) : deprecated;;
570 rerere) : plumbing;;
571 rev-list) : plumbing;;
572 rev-parse) : plumbing;;
573 runstatus) : plumbing;;
574 sh-setup) : internal;;
575 shell) : daemon;;
576 show-ref) : plumbing;;
577 send-pack) : plumbing;;
578 show-index) : plumbing;;
579 ssh-*) : transport;;
580 stripspace) : plumbing;;
581 symbolic-ref) : plumbing;;
582 tar-tree) : deprecated;;
583 unpack-file) : plumbing;;
584 unpack-objects) : plumbing;;
585 update-index) : plumbing;;
586 update-ref) : plumbing;;
587 update-server-info) : daemon;;
588 upload-archive) : plumbing;;
589 upload-pack) : plumbing;;
590 write-tree) : plumbing;;
591 var) : infrequent;;
592 verify-pack) : infrequent;;
593 verify-tag) : plumbing;;
594 *) echo $i;;
595 esac
596 done
597}
598__git_porcelain_commandlist=
599__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
600
601__git_aliases ()
602{
603 local i IFS=$'\n'
604 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
605 i="${i#alias.}"
606 echo "${i/ */}"
607 done
608}
609
610# __git_aliased_command requires 1 argument
611__git_aliased_command ()
612{
613 local word cmdline=$(git --git-dir="$(__gitdir)" \
614 config --get "alias.$1")
615 for word in $cmdline; do
616 if [ "${word##-*}" ]; then
617 echo $word
618 return
619 fi
620 done
621}
622
623# __git_find_on_cmdline requires 1 argument
624__git_find_on_cmdline ()
625{
626 local word subcommand c=1
627
628 while [ $c -lt $COMP_CWORD ]; do
629 word="${COMP_WORDS[c]}"
630 for subcommand in $1; do
631 if [ "$subcommand" = "$word" ]; then
632 echo "$subcommand"
633 return
634 fi
635 done
636 c=$((++c))
637 done
638}
639
640__git_has_doubledash ()
641{
642 local c=1
643 while [ $c -lt $COMP_CWORD ]; do
644 if [ "--" = "${COMP_WORDS[c]}" ]; then
645 return 0
646 fi
647 c=$((++c))
648 done
649 return 1
650}
651
652__git_whitespacelist="nowarn warn error error-all fix"
653
654_git_am ()
655{
656 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
657 if [ -d "$dir"/rebase-apply ]; then
658 __gitcomp "--skip --resolved --abort"
659 return
660 fi
661 case "$cur" in
662 --whitespace=*)
663 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
664 return
665 ;;
666 --*)
667 __gitcomp "
668 --3way --committer-date-is-author-date --ignore-date
669 --ignore-whitespace --ignore-space-change
670 --interactive --keep --no-utf8 --signoff --utf8
671 --whitespace=
672 "
673 return
674 esac
675 COMPREPLY=()
676}
677
678_git_apply ()
679{
680 local cur="${COMP_WORDS[COMP_CWORD]}"
681 case "$cur" in
682 --whitespace=*)
683 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
684 return
685 ;;
686 --*)
687 __gitcomp "
688 --stat --numstat --summary --check --index
689 --cached --index-info --reverse --reject --unidiff-zero
690 --apply --no-add --exclude=
691 --ignore-whitespace --ignore-space-change
692 --whitespace= --inaccurate-eof --verbose
693 "
694 return
695 esac
696 COMPREPLY=()
697}
698
699_git_add ()
700{
701 __git_has_doubledash && return
702
703 local cur="${COMP_WORDS[COMP_CWORD]}"
704 case "$cur" in
705 --*)
706 __gitcomp "
707 --interactive --refresh --patch --update --dry-run
708 --ignore-errors --intent-to-add
709 "
710 return
711 esac
712 COMPREPLY=()
713}
714
715_git_archive ()
716{
717 local cur="${COMP_WORDS[COMP_CWORD]}"
718 case "$cur" in
719 --format=*)
720 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
721 return
722 ;;
723 --remote=*)
724 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
725 return
726 ;;
727 --*)
728 __gitcomp "
729 --format= --list --verbose
730 --prefix= --remote= --exec=
731 "
732 return
733 ;;
734 esac
735 __git_complete_file
736}
737
738_git_bisect ()
739{
740 __git_has_doubledash && return
741
742 local subcommands="start bad good skip reset visualize replay log run"
743 local subcommand="$(__git_find_on_cmdline "$subcommands")"
744 if [ -z "$subcommand" ]; then
745 __gitcomp "$subcommands"
746 return
747 fi
748
749 case "$subcommand" in
750 bad|good|reset|skip)
751 __gitcomp "$(__git_refs)"
752 ;;
753 *)
754 COMPREPLY=()
755 ;;
756 esac
757}
758
759_git_branch ()
760{
761 local i c=1 only_local_ref="n" has_r="n"
762
763 while [ $c -lt $COMP_CWORD ]; do
764 i="${COMP_WORDS[c]}"
765 case "$i" in
766 -d|-m) only_local_ref="y" ;;
767 -r) has_r="y" ;;
768 esac
769 c=$((++c))
770 done
771
772 case "${COMP_WORDS[COMP_CWORD]}" in
773 --*)
774 __gitcomp "
775 --color --no-color --verbose --abbrev= --no-abbrev
776 --track --no-track --contains --merged --no-merged
777 "
778 ;;
779 *)
780 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
781 __gitcomp "$(__git_heads)"
782 else
783 __gitcomp "$(__git_refs)"
784 fi
785 ;;
786 esac
787}
788
789_git_bundle ()
790{
791 local cmd="${COMP_WORDS[2]}"
792 case "$COMP_CWORD" in
793 2)
794 __gitcomp "create list-heads verify unbundle"
795 ;;
796 3)
797 # looking for a file
798 ;;
799 *)
800 case "$cmd" in
801 create)
802 __git_complete_revlist
803 ;;
804 esac
805 ;;
806 esac
807}
808
809_git_checkout ()
810{
811 __git_has_doubledash && return
812
813 local cur="${COMP_WORDS[COMP_CWORD]}"
814 case "$cur" in
815 --conflict=*)
816 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
817 ;;
818 --*)
819 __gitcomp "
820 --quiet --ours --theirs --track --no-track --merge
821 --conflict= --patch
822 "
823 ;;
824 *)
825 __gitcomp "$(__git_refs)"
826 ;;
827 esac
828}
829
830_git_cherry ()
831{
832 __gitcomp "$(__git_refs)"
833}
834
835_git_cherry_pick ()
836{
837 local cur="${COMP_WORDS[COMP_CWORD]}"
838 case "$cur" in
839 --*)
840 __gitcomp "--edit --no-commit"
841 ;;
842 *)
843 __gitcomp "$(__git_refs)"
844 ;;
845 esac
846}
847
848_git_clean ()
849{
850 __git_has_doubledash && return
851
852 local cur="${COMP_WORDS[COMP_CWORD]}"
853 case "$cur" in
854 --*)
855 __gitcomp "--dry-run --quiet"
856 return
857 ;;
858 esac
859 COMPREPLY=()
860}
861
862_git_clone ()
863{
864 local cur="${COMP_WORDS[COMP_CWORD]}"
865 case "$cur" in
866 --*)
867 __gitcomp "
868 --local
869 --no-hardlinks
870 --shared
871 --reference
872 --quiet
873 --no-checkout
874 --bare
875 --mirror
876 --origin
877 --upload-pack
878 --template=
879 --depth
880 "
881 return
882 ;;
883 esac
884 COMPREPLY=()
885}
886
887_git_commit ()
888{
889 __git_has_doubledash && return
890
891 local cur="${COMP_WORDS[COMP_CWORD]}"
892 case "$cur" in
893 --*)
894 __gitcomp "
895 --all --author= --signoff --verify --no-verify
896 --edit --amend --include --only --interactive
897 "
898 return
899 esac
900 COMPREPLY=()
901}
902
903_git_describe ()
904{
905 local cur="${COMP_WORDS[COMP_CWORD]}"
906 case "$cur" in
907 --*)
908 __gitcomp "
909 --all --tags --contains --abbrev= --candidates=
910 --exact-match --debug --long --match --always
911 "
912 return
913 esac
914 __gitcomp "$(__git_refs)"
915}
916
917__git_diff_common_options="--stat --numstat --shortstat --summary
918 --patch-with-stat --name-only --name-status --color
919 --no-color --color-words --no-renames --check
920 --full-index --binary --abbrev --diff-filter=
921 --find-copies-harder
922 --text --ignore-space-at-eol --ignore-space-change
923 --ignore-all-space --exit-code --quiet --ext-diff
924 --no-ext-diff
925 --no-prefix --src-prefix= --dst-prefix=
926 --inter-hunk-context=
927 --patience
928 --raw
929"
930
931_git_diff ()
932{
933 __git_has_doubledash && return
934
935 local cur="${COMP_WORDS[COMP_CWORD]}"
936 case "$cur" in
937 --*)
938 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
939 --base --ours --theirs
940 $__git_diff_common_options
941 "
942 return
943 ;;
944 esac
945 __git_complete_file
946}
947
948__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
949 tkdiff vimdiff gvimdiff xxdiff araxis
950"
951
952_git_difftool ()
953{
954 local cur="${COMP_WORDS[COMP_CWORD]}"
955 case "$cur" in
956 --tool=*)
957 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
958 return
959 ;;
960 --*)
961 __gitcomp "--tool="
962 return
963 ;;
964 esac
965 COMPREPLY=()
966}
967
968__git_fetch_options="
969 --quiet --verbose --append --upload-pack --force --keep --depth=
970 --tags --no-tags
971"
972
973_git_fetch ()
974{
975 local cur="${COMP_WORDS[COMP_CWORD]}"
976 case "$cur" in
977 --*)
978 __gitcomp "$__git_fetch_options"
979 return
980 ;;
981 esac
982 __git_complete_remote_or_refspec
983}
984
985_git_format_patch ()
986{
987 local cur="${COMP_WORDS[COMP_CWORD]}"
988 case "$cur" in
989 --thread=*)
990 __gitcomp "
991 deep shallow
992 " "" "${cur##--thread=}"
993 return
994 ;;
995 --*)
996 __gitcomp "
997 --stdout --attach --no-attach --thread --thread=
998 --output-directory
999 --numbered --start-number
1000 --numbered-files
1001 --keep-subject
1002 --signoff
1003 --in-reply-to= --cc=
1004 --full-index --binary
1005 --not --all
1006 --cover-letter
1007 --no-prefix --src-prefix= --dst-prefix=
1008 --inline --suffix= --ignore-if-in-upstream
1009 --subject-prefix=
1010 "
1011 return
1012 ;;
1013 esac
1014 __git_complete_revlist
1015}
1016
1017_git_fsck ()
1018{
1019 local cur="${COMP_WORDS[COMP_CWORD]}"
1020 case "$cur" in
1021 --*)
1022 __gitcomp "
1023 --tags --root --unreachable --cache --no-reflogs --full
1024 --strict --verbose --lost-found
1025 "
1026 return
1027 ;;
1028 esac
1029 COMPREPLY=()
1030}
1031
1032_git_gc ()
1033{
1034 local cur="${COMP_WORDS[COMP_CWORD]}"
1035 case "$cur" in
1036 --*)
1037 __gitcomp "--prune --aggressive"
1038 return
1039 ;;
1040 esac
1041 COMPREPLY=()
1042}
1043
1044_git_grep ()
1045{
1046 __git_has_doubledash && return
1047
1048 local cur="${COMP_WORDS[COMP_CWORD]}"
1049 case "$cur" in
1050 --*)
1051 __gitcomp "
1052 --cached
1053 --text --ignore-case --word-regexp --invert-match
1054 --full-name
1055 --extended-regexp --basic-regexp --fixed-strings
1056 --files-with-matches --name-only
1057 --files-without-match
1058 --max-depth
1059 --count
1060 --and --or --not --all-match
1061 "
1062 return
1063 ;;
1064 esac
1065 COMPREPLY=()
1066}
1067
1068_git_help ()
1069{
1070 local cur="${COMP_WORDS[COMP_CWORD]}"
1071 case "$cur" in
1072 --*)
1073 __gitcomp "--all --info --man --web"
1074 return
1075 ;;
1076 esac
1077 __gitcomp "$(__git_all_commands)
1078 attributes cli core-tutorial cvs-migration
1079 diffcore gitk glossary hooks ignore modules
1080 repository-layout tutorial tutorial-2
1081 workflows
1082 "
1083}
1084
1085_git_init ()
1086{
1087 local cur="${COMP_WORDS[COMP_CWORD]}"
1088 case "$cur" in
1089 --shared=*)
1090 __gitcomp "
1091 false true umask group all world everybody
1092 " "" "${cur##--shared=}"
1093 return
1094 ;;
1095 --*)
1096 __gitcomp "--quiet --bare --template= --shared --shared="
1097 return
1098 ;;
1099 esac
1100 COMPREPLY=()
1101}
1102
1103_git_ls_files ()
1104{
1105 __git_has_doubledash && return
1106
1107 local cur="${COMP_WORDS[COMP_CWORD]}"
1108 case "$cur" in
1109 --*)
1110 __gitcomp "--cached --deleted --modified --others --ignored
1111 --stage --directory --no-empty-directory --unmerged
1112 --killed --exclude= --exclude-from=
1113 --exclude-per-directory= --exclude-standard
1114 --error-unmatch --with-tree= --full-name
1115 --abbrev --ignored --exclude-per-directory
1116 "
1117 return
1118 ;;
1119 esac
1120 COMPREPLY=()
1121}
1122
1123_git_ls_remote ()
1124{
1125 __gitcomp "$(__git_remotes)"
1126}
1127
1128_git_ls_tree ()
1129{
1130 __git_complete_file
1131}
1132
1133# Options that go well for log, shortlog and gitk
1134__git_log_common_options="
1135 --not --all
1136 --branches --tags --remotes
1137 --first-parent --merges --no-merges
1138 --max-count=
1139 --max-age= --since= --after=
1140 --min-age= --until= --before=
1141"
1142# Options that go well for log and gitk (not shortlog)
1143__git_log_gitk_options="
1144 --dense --sparse --full-history
1145 --simplify-merges --simplify-by-decoration
1146 --left-right
1147"
1148# Options that go well for log and shortlog (not gitk)
1149__git_log_shortlog_options="
1150 --author= --committer= --grep=
1151 --all-match
1152"
1153
1154__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1155__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1156
1157_git_log ()
1158{
1159 __git_has_doubledash && return
1160
1161 local cur="${COMP_WORDS[COMP_CWORD]}"
1162 local g="$(git rev-parse --git-dir 2>/dev/null)"
1163 local merge=""
1164 if [ -f "$g/MERGE_HEAD" ]; then
1165 merge="--merge"
1166 fi
1167 case "$cur" in
1168 --pretty=*)
1169 __gitcomp "$__git_log_pretty_formats
1170 " "" "${cur##--pretty=}"
1171 return
1172 ;;
1173 --format=*)
1174 __gitcomp "$__git_log_pretty_formats
1175 " "" "${cur##--format=}"
1176 return
1177 ;;
1178 --date=*)
1179 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1180 return
1181 ;;
1182 --*)
1183 __gitcomp "
1184 $__git_log_common_options
1185 $__git_log_shortlog_options
1186 $__git_log_gitk_options
1187 --root --topo-order --date-order --reverse
1188 --follow --full-diff
1189 --abbrev-commit --abbrev=
1190 --relative-date --date=
1191 --pretty= --format= --oneline
1192 --cherry-pick
1193 --graph
1194 --decorate
1195 --walk-reflogs
1196 --parents --children
1197 $merge
1198 $__git_diff_common_options
1199 --pickaxe-all --pickaxe-regex
1200 "
1201 return
1202 ;;
1203 esac
1204 __git_complete_revlist
1205}
1206
1207__git_merge_options="
1208 --no-commit --no-stat --log --no-log --squash --strategy
1209 --commit --stat --no-squash --ff --no-ff
1210"
1211
1212_git_merge ()
1213{
1214 __git_complete_strategy && return
1215
1216 local cur="${COMP_WORDS[COMP_CWORD]}"
1217 case "$cur" in
1218 --*)
1219 __gitcomp "$__git_merge_options"
1220 return
1221 esac
1222 __gitcomp "$(__git_refs)"
1223}
1224
1225_git_mergetool ()
1226{
1227 local cur="${COMP_WORDS[COMP_CWORD]}"
1228 case "$cur" in
1229 --tool=*)
1230 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1231 return
1232 ;;
1233 --*)
1234 __gitcomp "--tool="
1235 return
1236 ;;
1237 esac
1238 COMPREPLY=()
1239}
1240
1241_git_merge_base ()
1242{
1243 __gitcomp "$(__git_refs)"
1244}
1245
1246_git_mv ()
1247{
1248 local cur="${COMP_WORDS[COMP_CWORD]}"
1249 case "$cur" in
1250 --*)
1251 __gitcomp "--dry-run"
1252 return
1253 ;;
1254 esac
1255 COMPREPLY=()
1256}
1257
1258_git_name_rev ()
1259{
1260 __gitcomp "--tags --all --stdin"
1261}
1262
1263_git_pull ()
1264{
1265 __git_complete_strategy && return
1266
1267 local cur="${COMP_WORDS[COMP_CWORD]}"
1268 case "$cur" in
1269 --*)
1270 __gitcomp "
1271 --rebase --no-rebase
1272 $__git_merge_options
1273 $__git_fetch_options
1274 "
1275 return
1276 ;;
1277 esac
1278 __git_complete_remote_or_refspec
1279}
1280
1281_git_push ()
1282{
1283 local cur="${COMP_WORDS[COMP_CWORD]}"
1284 case "${COMP_WORDS[COMP_CWORD-1]}" in
1285 --repo)
1286 __gitcomp "$(__git_remotes)"
1287 return
1288 esac
1289 case "$cur" in
1290 --repo=*)
1291 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1292 return
1293 ;;
1294 --*)
1295 __gitcomp "
1296 --all --mirror --tags --dry-run --force --verbose
1297 --receive-pack= --repo=
1298 "
1299 return
1300 ;;
1301 esac
1302 __git_complete_remote_or_refspec
1303}
1304
1305_git_rebase ()
1306{
1307 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1308 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1309 __gitcomp "--continue --skip --abort"
1310 return
1311 fi
1312 __git_complete_strategy && return
1313 case "$cur" in
1314 --*)
1315 __gitcomp "--onto --merge --strategy --interactive"
1316 return
1317 esac
1318 __gitcomp "$(__git_refs)"
1319}
1320
1321__git_send_email_confirm_options="always never auto cc compose"
1322__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1323
1324_git_send_email ()
1325{
1326 local cur="${COMP_WORDS[COMP_CWORD]}"
1327 case "$cur" in
1328 --confirm=*)
1329 __gitcomp "
1330 $__git_send_email_confirm_options
1331 " "" "${cur##--confirm=}"
1332 return
1333 ;;
1334 --suppress-cc=*)
1335 __gitcomp "
1336 $__git_send_email_suppresscc_options
1337 " "" "${cur##--suppress-cc=}"
1338
1339 return
1340 ;;
1341 --smtp-encryption=*)
1342 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1343 return
1344 ;;
1345 --*)
1346 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1347 --compose --confirm= --dry-run --envelope-sender
1348 --from --identity
1349 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1350 --no-suppress-from --no-thread --quiet
1351 --signed-off-by-cc --smtp-pass --smtp-server
1352 --smtp-server-port --smtp-encryption= --smtp-user
1353 --subject --suppress-cc= --suppress-from --thread --to
1354 --validate --no-validate"
1355 return
1356 ;;
1357 esac
1358 COMPREPLY=()
1359}
1360
1361__git_config_get_set_variables ()
1362{
1363 local prevword word config_file= c=$COMP_CWORD
1364 while [ $c -gt 1 ]; do
1365 word="${COMP_WORDS[c]}"
1366 case "$word" in
1367 --global|--system|--file=*)
1368 config_file="$word"
1369 break
1370 ;;
1371 -f|--file)
1372 config_file="$word $prevword"
1373 break
1374 ;;
1375 esac
1376 prevword=$word
1377 c=$((--c))
1378 done
1379
1380 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1381 while read line
1382 do
1383 case "$line" in
1384 *.*=*)
1385 echo "${line/=*/}"
1386 ;;
1387 esac
1388 done
1389}
1390
1391_git_config ()
1392{
1393 local cur="${COMP_WORDS[COMP_CWORD]}"
1394 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1395 case "$prv" in
1396 branch.*.remote)
1397 __gitcomp "$(__git_remotes)"
1398 return
1399 ;;
1400 branch.*.merge)
1401 __gitcomp "$(__git_refs)"
1402 return
1403 ;;
1404 remote.*.fetch)
1405 local remote="${prv#remote.}"
1406 remote="${remote%.fetch}"
1407 __gitcomp "$(__git_refs_remotes "$remote")"
1408 return
1409 ;;
1410 remote.*.push)
1411 local remote="${prv#remote.}"
1412 remote="${remote%.push}"
1413 __gitcomp "$(git --git-dir="$(__gitdir)" \
1414 for-each-ref --format='%(refname):%(refname)' \
1415 refs/heads)"
1416 return
1417 ;;
1418 pull.twohead|pull.octopus)
1419 __gitcomp "$(__git_merge_strategies)"
1420 return
1421 ;;
1422 color.branch|color.diff|color.interactive|\
1423 color.showbranch|color.status|color.ui)
1424 __gitcomp "always never auto"
1425 return
1426 ;;
1427 color.pager)
1428 __gitcomp "false true"
1429 return
1430 ;;
1431 color.*.*)
1432 __gitcomp "
1433 normal black red green yellow blue magenta cyan white
1434 bold dim ul blink reverse
1435 "
1436 return
1437 ;;
1438 help.format)
1439 __gitcomp "man info web html"
1440 return
1441 ;;
1442 log.date)
1443 __gitcomp "$__git_log_date_formats"
1444 return
1445 ;;
1446 sendemail.aliasesfiletype)
1447 __gitcomp "mutt mailrc pine elm gnus"
1448 return
1449 ;;
1450 sendemail.confirm)
1451 __gitcomp "$__git_send_email_confirm_options"
1452 return
1453 ;;
1454 sendemail.suppresscc)
1455 __gitcomp "$__git_send_email_suppresscc_options"
1456 return
1457 ;;
1458 --get|--get-all|--unset|--unset-all)
1459 __gitcomp "$(__git_config_get_set_variables)"
1460 return
1461 ;;
1462 *.*)
1463 COMPREPLY=()
1464 return
1465 ;;
1466 esac
1467 case "$cur" in
1468 --*)
1469 __gitcomp "
1470 --global --system --file=
1471 --list --replace-all
1472 --get --get-all --get-regexp
1473 --add --unset --unset-all
1474 --remove-section --rename-section
1475 "
1476 return
1477 ;;
1478 branch.*.*)
1479 local pfx="${cur%.*}."
1480 cur="${cur##*.}"
1481 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1482 return
1483 ;;
1484 branch.*)
1485 local pfx="${cur%.*}."
1486 cur="${cur#*.}"
1487 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1488 return
1489 ;;
1490 guitool.*.*)
1491 local pfx="${cur%.*}."
1492 cur="${cur##*.}"
1493 __gitcomp "
1494 argprompt cmd confirm needsfile noconsole norescan
1495 prompt revprompt revunmerged title
1496 " "$pfx" "$cur"
1497 return
1498 ;;
1499 difftool.*.*)
1500 local pfx="${cur%.*}."
1501 cur="${cur##*.}"
1502 __gitcomp "cmd path" "$pfx" "$cur"
1503 return
1504 ;;
1505 man.*.*)
1506 local pfx="${cur%.*}."
1507 cur="${cur##*.}"
1508 __gitcomp "cmd path" "$pfx" "$cur"
1509 return
1510 ;;
1511 mergetool.*.*)
1512 local pfx="${cur%.*}."
1513 cur="${cur##*.}"
1514 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1515 return
1516 ;;
1517 pager.*)
1518 local pfx="${cur%.*}."
1519 cur="${cur#*.}"
1520 __gitcomp "$(__git_all_commands)" "$pfx" "$cur"
1521 return
1522 ;;
1523 remote.*.*)
1524 local pfx="${cur%.*}."
1525 cur="${cur##*.}"
1526 __gitcomp "
1527 url proxy fetch push mirror skipDefaultUpdate
1528 receivepack uploadpack tagopt pushurl
1529 " "$pfx" "$cur"
1530 return
1531 ;;
1532 remote.*)
1533 local pfx="${cur%.*}."
1534 cur="${cur#*.}"
1535 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1536 return
1537 ;;
1538 url.*.*)
1539 local pfx="${cur%.*}."
1540 cur="${cur##*.}"
1541 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1542 return
1543 ;;
1544 esac
1545 __gitcomp "
1546 add.ignore-errors
1547 alias.
1548 apply.ignorewhitespace
1549 apply.whitespace
1550 branch.autosetupmerge
1551 branch.autosetuprebase
1552 clean.requireForce
1553 color.branch
1554 color.branch.current
1555 color.branch.local
1556 color.branch.plain
1557 color.branch.remote
1558 color.diff
1559 color.diff.commit
1560 color.diff.frag
1561 color.diff.meta
1562 color.diff.new
1563 color.diff.old
1564 color.diff.plain
1565 color.diff.whitespace
1566 color.grep
1567 color.grep.external
1568 color.grep.match
1569 color.interactive
1570 color.interactive.header
1571 color.interactive.help
1572 color.interactive.prompt
1573 color.pager
1574 color.showbranch
1575 color.status
1576 color.status.added
1577 color.status.changed
1578 color.status.header
1579 color.status.nobranch
1580 color.status.untracked
1581 color.status.updated
1582 color.ui
1583 commit.template
1584 core.autocrlf
1585 core.bare
1586 core.compression
1587 core.createObject
1588 core.deltaBaseCacheLimit
1589 core.editor
1590 core.excludesfile
1591 core.fileMode
1592 core.fsyncobjectfiles
1593 core.gitProxy
1594 core.ignoreCygwinFSTricks
1595 core.ignoreStat
1596 core.logAllRefUpdates
1597 core.loosecompression
1598 core.packedGitLimit
1599 core.packedGitWindowSize
1600 core.pager
1601 core.preferSymlinkRefs
1602 core.preloadindex
1603 core.quotepath
1604 core.repositoryFormatVersion
1605 core.safecrlf
1606 core.sharedRepository
1607 core.symlinks
1608 core.trustctime
1609 core.warnAmbiguousRefs
1610 core.whitespace
1611 core.worktree
1612 diff.autorefreshindex
1613 diff.external
1614 diff.mnemonicprefix
1615 diff.renameLimit
1616 diff.renameLimit.
1617 diff.renames
1618 diff.suppressBlankEmpty
1619 diff.tool
1620 diff.wordRegex
1621 difftool.
1622 difftool.prompt
1623 fetch.unpackLimit
1624 format.attach
1625 format.cc
1626 format.headers
1627 format.numbered
1628 format.pretty
1629 format.signoff
1630 format.subjectprefix
1631 format.suffix
1632 format.thread
1633 gc.aggressiveWindow
1634 gc.auto
1635 gc.autopacklimit
1636 gc.packrefs
1637 gc.pruneexpire
1638 gc.reflogexpire
1639 gc.reflogexpireunreachable
1640 gc.rerereresolved
1641 gc.rerereunresolved
1642 gitcvs.allbinary
1643 gitcvs.commitmsgannotation
1644 gitcvs.dbTableNamePrefix
1645 gitcvs.dbdriver
1646 gitcvs.dbname
1647 gitcvs.dbpass
1648 gitcvs.dbuser
1649 gitcvs.enabled
1650 gitcvs.logfile
1651 gitcvs.usecrlfattr
1652 guitool.
1653 gui.blamehistoryctx
1654 gui.commitmsgwidth
1655 gui.copyblamethreshold
1656 gui.diffcontext
1657 gui.encoding
1658 gui.fastcopyblame
1659 gui.matchtrackingbranch
1660 gui.newbranchtemplate
1661 gui.pruneduringfetch
1662 gui.spellingdictionary
1663 gui.trustmtime
1664 help.autocorrect
1665 help.browser
1666 help.format
1667 http.lowSpeedLimit
1668 http.lowSpeedTime
1669 http.maxRequests
1670 http.noEPSV
1671 http.proxy
1672 http.sslCAInfo
1673 http.sslCAPath
1674 http.sslCert
1675 http.sslKey
1676 http.sslVerify
1677 i18n.commitEncoding
1678 i18n.logOutputEncoding
1679 imap.folder
1680 imap.host
1681 imap.pass
1682 imap.port
1683 imap.preformattedHTML
1684 imap.sslverify
1685 imap.tunnel
1686 imap.user
1687 instaweb.browser
1688 instaweb.httpd
1689 instaweb.local
1690 instaweb.modulepath
1691 instaweb.port
1692 interactive.singlekey
1693 log.date
1694 log.showroot
1695 mailmap.file
1696 man.
1697 man.viewer
1698 merge.conflictstyle
1699 merge.log
1700 merge.renameLimit
1701 merge.stat
1702 merge.tool
1703 merge.verbosity
1704 mergetool.
1705 mergetool.keepBackup
1706 mergetool.prompt
1707 pack.compression
1708 pack.deltaCacheLimit
1709 pack.deltaCacheSize
1710 pack.depth
1711 pack.indexVersion
1712 pack.packSizeLimit
1713 pack.threads
1714 pack.window
1715 pack.windowMemory
1716 pager.
1717 pull.octopus
1718 pull.twohead
1719 push.default
1720 rebase.stat
1721 receive.denyCurrentBranch
1722 receive.denyDeletes
1723 receive.denyNonFastForwards
1724 receive.fsckObjects
1725 receive.unpackLimit
1726 repack.usedeltabaseoffset
1727 rerere.autoupdate
1728 rerere.enabled
1729 sendemail.aliasesfile
1730 sendemail.aliasesfiletype
1731 sendemail.bcc
1732 sendemail.cc
1733 sendemail.cccmd
1734 sendemail.chainreplyto
1735 sendemail.confirm
1736 sendemail.envelopesender
1737 sendemail.multiedit
1738 sendemail.signedoffbycc
1739 sendemail.smtpencryption
1740 sendemail.smtppass
1741 sendemail.smtpserver
1742 sendemail.smtpserverport
1743 sendemail.smtpuser
1744 sendemail.suppresscc
1745 sendemail.suppressfrom
1746 sendemail.thread
1747 sendemail.to
1748 sendemail.validate
1749 showbranch.default
1750 status.relativePaths
1751 status.showUntrackedFiles
1752 tar.umask
1753 transfer.unpackLimit
1754 url.
1755 user.email
1756 user.name
1757 user.signingkey
1758 web.browser
1759 branch. remote.
1760 "
1761}
1762
1763_git_remote ()
1764{
1765 local subcommands="add rename rm show prune update set-head"
1766 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1767 if [ -z "$subcommand" ]; then
1768 __gitcomp "$subcommands"
1769 return
1770 fi
1771
1772 case "$subcommand" in
1773 rename|rm|show|prune)
1774 __gitcomp "$(__git_remotes)"
1775 ;;
1776 update)
1777 local i c='' IFS=$'\n'
1778 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1779 i="${i#remotes.}"
1780 c="$c ${i/ */}"
1781 done
1782 __gitcomp "$c"
1783 ;;
1784 *)
1785 COMPREPLY=()
1786 ;;
1787 esac
1788}
1789
1790_git_reset ()
1791{
1792 __git_has_doubledash && return
1793
1794 local cur="${COMP_WORDS[COMP_CWORD]}"
1795 case "$cur" in
1796 --*)
1797 __gitcomp "--merge --mixed --hard --soft --patch"
1798 return
1799 ;;
1800 esac
1801 __gitcomp "$(__git_refs)"
1802}
1803
1804_git_revert ()
1805{
1806 local cur="${COMP_WORDS[COMP_CWORD]}"
1807 case "$cur" in
1808 --*)
1809 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1810 return
1811 ;;
1812 esac
1813 __gitcomp "$(__git_refs)"
1814}
1815
1816_git_rm ()
1817{
1818 __git_has_doubledash && return
1819
1820 local cur="${COMP_WORDS[COMP_CWORD]}"
1821 case "$cur" in
1822 --*)
1823 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1824 return
1825 ;;
1826 esac
1827 COMPREPLY=()
1828}
1829
1830_git_shortlog ()
1831{
1832 __git_has_doubledash && return
1833
1834 local cur="${COMP_WORDS[COMP_CWORD]}"
1835 case "$cur" in
1836 --*)
1837 __gitcomp "
1838 $__git_log_common_options
1839 $__git_log_shortlog_options
1840 --numbered --summary
1841 "
1842 return
1843 ;;
1844 esac
1845 __git_complete_revlist
1846}
1847
1848_git_show ()
1849{
1850 __git_has_doubledash && return
1851
1852 local cur="${COMP_WORDS[COMP_CWORD]}"
1853 case "$cur" in
1854 --pretty=*)
1855 __gitcomp "$__git_log_pretty_formats
1856 " "" "${cur##--pretty=}"
1857 return
1858 ;;
1859 --format=*)
1860 __gitcomp "$__git_log_pretty_formats
1861 " "" "${cur##--format=}"
1862 return
1863 ;;
1864 --*)
1865 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1866 $__git_diff_common_options
1867 "
1868 return
1869 ;;
1870 esac
1871 __git_complete_file
1872}
1873
1874_git_show_branch ()
1875{
1876 local cur="${COMP_WORDS[COMP_CWORD]}"
1877 case "$cur" in
1878 --*)
1879 __gitcomp "
1880 --all --remotes --topo-order --current --more=
1881 --list --independent --merge-base --no-name
1882 --color --no-color
1883 --sha1-name --sparse --topics --reflog
1884 "
1885 return
1886 ;;
1887 esac
1888 __git_complete_revlist
1889}
1890
1891_git_stash ()
1892{
1893 local cur="${COMP_WORDS[COMP_CWORD]}"
1894 local save_opts='--keep-index --no-keep-index --quiet --patch'
1895 local subcommands='save list show apply clear drop pop create branch'
1896 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1897 if [ -z "$subcommand" ]; then
1898 case "$cur" in
1899 --*)
1900 __gitcomp "$save_opts"
1901 ;;
1902 *)
1903 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1904 __gitcomp "$subcommands"
1905 else
1906 COMPREPLY=()
1907 fi
1908 ;;
1909 esac
1910 else
1911 case "$subcommand,$cur" in
1912 save,--*)
1913 __gitcomp "$save_opts"
1914 ;;
1915 apply,--*|pop,--*)
1916 __gitcomp "--index --quiet"
1917 ;;
1918 show,--*|drop,--*|branch,--*)
1919 COMPREPLY=()
1920 ;;
1921 show,*|apply,*|drop,*|pop,*|branch,*)
1922 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1923 | sed -n -e 's/:.*//p')"
1924 ;;
1925 *)
1926 COMPREPLY=()
1927 ;;
1928 esac
1929 fi
1930}
1931
1932_git_submodule ()
1933{
1934 __git_has_doubledash && return
1935
1936 local subcommands="add status init update summary foreach sync"
1937 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1938 local cur="${COMP_WORDS[COMP_CWORD]}"
1939 case "$cur" in
1940 --*)
1941 __gitcomp "--quiet --cached"
1942 ;;
1943 *)
1944 __gitcomp "$subcommands"
1945 ;;
1946 esac
1947 return
1948 fi
1949}
1950
1951_git_svn ()
1952{
1953 local subcommands="
1954 init fetch clone rebase dcommit log find-rev
1955 set-tree commit-diff info create-ignore propget
1956 proplist show-ignore show-externals branch tag blame
1957 migrate
1958 "
1959 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1960 if [ -z "$subcommand" ]; then
1961 __gitcomp "$subcommands"
1962 else
1963 local remote_opts="--username= --config-dir= --no-auth-cache"
1964 local fc_opts="
1965 --follow-parent --authors-file= --repack=
1966 --no-metadata --use-svm-props --use-svnsync-props
1967 --log-window-size= --no-checkout --quiet
1968 --repack-flags --use-log-author --localtime
1969 --ignore-paths= $remote_opts
1970 "
1971 local init_opts="
1972 --template= --shared= --trunk= --tags=
1973 --branches= --stdlayout --minimize-url
1974 --no-metadata --use-svm-props --use-svnsync-props
1975 --rewrite-root= --prefix= --use-log-author
1976 --add-author-from $remote_opts
1977 "
1978 local cmt_opts="
1979 --edit --rmdir --find-copies-harder --copy-similarity=
1980 "
1981
1982 local cur="${COMP_WORDS[COMP_CWORD]}"
1983 case "$subcommand,$cur" in
1984 fetch,--*)
1985 __gitcomp "--revision= --fetch-all $fc_opts"
1986 ;;
1987 clone,--*)
1988 __gitcomp "--revision= $fc_opts $init_opts"
1989 ;;
1990 init,--*)
1991 __gitcomp "$init_opts"
1992 ;;
1993 dcommit,--*)
1994 __gitcomp "
1995 --merge --strategy= --verbose --dry-run
1996 --fetch-all --no-rebase --commit-url
1997 --revision $cmt_opts $fc_opts
1998 "
1999 ;;
2000 set-tree,--*)
2001 __gitcomp "--stdin $cmt_opts $fc_opts"
2002 ;;
2003 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2004 show-externals,--*)
2005 __gitcomp "--revision="
2006 ;;
2007 log,--*)
2008 __gitcomp "
2009 --limit= --revision= --verbose --incremental
2010 --oneline --show-commit --non-recursive
2011 --authors-file= --color
2012 "
2013 ;;
2014 rebase,--*)
2015 __gitcomp "
2016 --merge --verbose --strategy= --local
2017 --fetch-all --dry-run $fc_opts
2018 "
2019 ;;
2020 commit-diff,--*)
2021 __gitcomp "--message= --file= --revision= $cmt_opts"
2022 ;;
2023 info,--*)
2024 __gitcomp "--url"
2025 ;;
2026 branch,--*)
2027 __gitcomp "--dry-run --message --tag"
2028 ;;
2029 tag,--*)
2030 __gitcomp "--dry-run --message"
2031 ;;
2032 blame,--*)
2033 __gitcomp "--git-format"
2034 ;;
2035 migrate,--*)
2036 __gitcomp "
2037 --config-dir= --ignore-paths= --minimize
2038 --no-auth-cache --username=
2039 "
2040 ;;
2041 *)
2042 COMPREPLY=()
2043 ;;
2044 esac
2045 fi
2046}
2047
2048_git_tag ()
2049{
2050 local i c=1 f=0
2051 while [ $c -lt $COMP_CWORD ]; do
2052 i="${COMP_WORDS[c]}"
2053 case "$i" in
2054 -d|-v)
2055 __gitcomp "$(__git_tags)"
2056 return
2057 ;;
2058 -f)
2059 f=1
2060 ;;
2061 esac
2062 c=$((++c))
2063 done
2064
2065 case "${COMP_WORDS[COMP_CWORD-1]}" in
2066 -m|-F)
2067 COMPREPLY=()
2068 ;;
2069 -*|tag)
2070 if [ $f = 1 ]; then
2071 __gitcomp "$(__git_tags)"
2072 else
2073 COMPREPLY=()
2074 fi
2075 ;;
2076 *)
2077 __gitcomp "$(__git_refs)"
2078 ;;
2079 esac
2080}
2081
2082_git ()
2083{
2084 local i c=1 command __git_dir
2085
2086 while [ $c -lt $COMP_CWORD ]; do
2087 i="${COMP_WORDS[c]}"
2088 case "$i" in
2089 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2090 --bare) __git_dir="." ;;
2091 --version|-p|--paginate) ;;
2092 --help) command="help"; break ;;
2093 *) command="$i"; break ;;
2094 esac
2095 c=$((++c))
2096 done
2097
2098 if [ -z "$command" ]; then
2099 case "${COMP_WORDS[COMP_CWORD]}" in
2100 --*) __gitcomp "
2101 --paginate
2102 --no-pager
2103 --git-dir=
2104 --bare
2105 --version
2106 --exec-path
2107 --html-path
2108 --work-tree=
2109 --help
2110 "
2111 ;;
2112 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
2113 esac
2114 return
2115 fi
2116
2117 local expansion=$(__git_aliased_command "$command")
2118 [ "$expansion" ] && command="$expansion"
2119
2120 case "$command" in
2121 am) _git_am ;;
2122 add) _git_add ;;
2123 apply) _git_apply ;;
2124 archive) _git_archive ;;
2125 bisect) _git_bisect ;;
2126 bundle) _git_bundle ;;
2127 branch) _git_branch ;;
2128 checkout) _git_checkout ;;
2129 cherry) _git_cherry ;;
2130 cherry-pick) _git_cherry_pick ;;
2131 clean) _git_clean ;;
2132 clone) _git_clone ;;
2133 commit) _git_commit ;;
2134 config) _git_config ;;
2135 describe) _git_describe ;;
2136 diff) _git_diff ;;
2137 difftool) _git_difftool ;;
2138 fetch) _git_fetch ;;
2139 format-patch) _git_format_patch ;;
2140 fsck) _git_fsck ;;
2141 gc) _git_gc ;;
2142 grep) _git_grep ;;
2143 help) _git_help ;;
2144 init) _git_init ;;
2145 log) _git_log ;;
2146 ls-files) _git_ls_files ;;
2147 ls-remote) _git_ls_remote ;;
2148 ls-tree) _git_ls_tree ;;
2149 merge) _git_merge;;
2150 mergetool) _git_mergetool;;
2151 merge-base) _git_merge_base ;;
2152 mv) _git_mv ;;
2153 name-rev) _git_name_rev ;;
2154 pull) _git_pull ;;
2155 push) _git_push ;;
2156 rebase) _git_rebase ;;
2157 remote) _git_remote ;;
2158 reset) _git_reset ;;
2159 revert) _git_revert ;;
2160 rm) _git_rm ;;
2161 send-email) _git_send_email ;;
2162 shortlog) _git_shortlog ;;
2163 show) _git_show ;;
2164 show-branch) _git_show_branch ;;
2165 stash) _git_stash ;;
2166 stage) _git_add ;;
2167 submodule) _git_submodule ;;
2168 svn) _git_svn ;;
2169 tag) _git_tag ;;
2170 whatchanged) _git_log ;;
2171 *) COMPREPLY=() ;;
2172 esac
2173}
2174
2175_gitk ()
2176{
2177 __git_has_doubledash && return
2178
2179 local cur="${COMP_WORDS[COMP_CWORD]}"
2180 local g="$(__gitdir)"
2181 local merge=""
2182 if [ -f "$g/MERGE_HEAD" ]; then
2183 merge="--merge"
2184 fi
2185 case "$cur" in
2186 --*)
2187 __gitcomp "
2188 $__git_log_common_options
2189 $__git_log_gitk_options
2190 $merge
2191 "
2192 return
2193 ;;
2194 esac
2195 __git_complete_revlist
2196}
2197
2198complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2199 || complete -o default -o nospace -F _git git
2200complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2201 || complete -o default -o nospace -F _gitk gitk
2202
2203# The following are necessary only for Cygwin, and only are needed
2204# when the user has tab-completed the executable name and consequently
2205# included the '.exe' suffix.
2206#
2207if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2208complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2209 || complete -o default -o nospace -F _git git.exe
2210fi