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