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 __gitcomp "$(__git_refs)"
814}
815
816_git_cherry ()
817{
818 __gitcomp "$(__git_refs)"
819}
820
821_git_cherry_pick ()
822{
823 local cur="${COMP_WORDS[COMP_CWORD]}"
824 case "$cur" in
825 --*)
826 __gitcomp "--edit --no-commit"
827 ;;
828 *)
829 __gitcomp "$(__git_refs)"
830 ;;
831 esac
832}
833
834_git_clean ()
835{
836 __git_has_doubledash && return
837
838 local cur="${COMP_WORDS[COMP_CWORD]}"
839 case "$cur" in
840 --*)
841 __gitcomp "--dry-run --quiet"
842 return
843 ;;
844 esac
845 COMPREPLY=()
846}
847
848_git_clone ()
849{
850 local cur="${COMP_WORDS[COMP_CWORD]}"
851 case "$cur" in
852 --*)
853 __gitcomp "
854 --local
855 --no-hardlinks
856 --shared
857 --reference
858 --quiet
859 --no-checkout
860 --bare
861 --mirror
862 --origin
863 --upload-pack
864 --template=
865 --depth
866 "
867 return
868 ;;
869 esac
870 COMPREPLY=()
871}
872
873_git_commit ()
874{
875 __git_has_doubledash && return
876
877 local cur="${COMP_WORDS[COMP_CWORD]}"
878 case "$cur" in
879 --*)
880 __gitcomp "
881 --all --author= --signoff --verify --no-verify
882 --edit --amend --include --only --interactive
883 "
884 return
885 esac
886 COMPREPLY=()
887}
888
889_git_describe ()
890{
891 local cur="${COMP_WORDS[COMP_CWORD]}"
892 case "$cur" in
893 --*)
894 __gitcomp "
895 --all --tags --contains --abbrev= --candidates=
896 --exact-match --debug --long --match --always
897 "
898 return
899 esac
900 __gitcomp "$(__git_refs)"
901}
902
903__git_diff_common_options="--stat --numstat --shortstat --summary
904 --patch-with-stat --name-only --name-status --color
905 --no-color --color-words --no-renames --check
906 --full-index --binary --abbrev --diff-filter=
907 --find-copies-harder
908 --text --ignore-space-at-eol --ignore-space-change
909 --ignore-all-space --exit-code --quiet --ext-diff
910 --no-ext-diff
911 --no-prefix --src-prefix= --dst-prefix=
912 --inter-hunk-context=
913 --patience
914 --raw
915"
916
917_git_diff ()
918{
919 __git_has_doubledash && return
920
921 local cur="${COMP_WORDS[COMP_CWORD]}"
922 case "$cur" in
923 --*)
924 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
925 --base --ours --theirs
926 $__git_diff_common_options
927 "
928 return
929 ;;
930 esac
931 __git_complete_file
932}
933
934__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
935 tkdiff vimdiff gvimdiff xxdiff araxis
936"
937
938_git_difftool ()
939{
940 local cur="${COMP_WORDS[COMP_CWORD]}"
941 case "$cur" in
942 --tool=*)
943 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
944 return
945 ;;
946 --*)
947 __gitcomp "--tool="
948 return
949 ;;
950 esac
951 COMPREPLY=()
952}
953
954__git_fetch_options="
955 --quiet --verbose --append --upload-pack --force --keep --depth=
956 --tags --no-tags
957"
958
959_git_fetch ()
960{
961 local cur="${COMP_WORDS[COMP_CWORD]}"
962 case "$cur" in
963 --*)
964 __gitcomp "$__git_fetch_options"
965 return
966 ;;
967 esac
968 __git_complete_remote_or_refspec
969}
970
971_git_format_patch ()
972{
973 local cur="${COMP_WORDS[COMP_CWORD]}"
974 case "$cur" in
975 --thread=*)
976 __gitcomp "
977 deep shallow
978 " "" "${cur##--thread=}"
979 return
980 ;;
981 --*)
982 __gitcomp "
983 --stdout --attach --no-attach --thread --thread=
984 --output-directory
985 --numbered --start-number
986 --numbered-files
987 --keep-subject
988 --signoff
989 --in-reply-to= --cc=
990 --full-index --binary
991 --not --all
992 --cover-letter
993 --no-prefix --src-prefix= --dst-prefix=
994 --inline --suffix= --ignore-if-in-upstream
995 --subject-prefix=
996 "
997 return
998 ;;
999 esac
1000 __git_complete_revlist
1001}
1002
1003_git_fsck ()
1004{
1005 local cur="${COMP_WORDS[COMP_CWORD]}"
1006 case "$cur" in
1007 --*)
1008 __gitcomp "
1009 --tags --root --unreachable --cache --no-reflogs --full
1010 --strict --verbose --lost-found
1011 "
1012 return
1013 ;;
1014 esac
1015 COMPREPLY=()
1016}
1017
1018_git_gc ()
1019{
1020 local cur="${COMP_WORDS[COMP_CWORD]}"
1021 case "$cur" in
1022 --*)
1023 __gitcomp "--prune --aggressive"
1024 return
1025 ;;
1026 esac
1027 COMPREPLY=()
1028}
1029
1030_git_grep ()
1031{
1032 __git_has_doubledash && return
1033
1034 local cur="${COMP_WORDS[COMP_CWORD]}"
1035 case "$cur" in
1036 --*)
1037 __gitcomp "
1038 --cached
1039 --text --ignore-case --word-regexp --invert-match
1040 --full-name
1041 --extended-regexp --basic-regexp --fixed-strings
1042 --files-with-matches --name-only
1043 --files-without-match
1044 --max-depth
1045 --count
1046 --and --or --not --all-match
1047 "
1048 return
1049 ;;
1050 esac
1051 COMPREPLY=()
1052}
1053
1054_git_help ()
1055{
1056 local cur="${COMP_WORDS[COMP_CWORD]}"
1057 case "$cur" in
1058 --*)
1059 __gitcomp "--all --info --man --web"
1060 return
1061 ;;
1062 esac
1063 __gitcomp "$(__git_all_commands)
1064 attributes cli core-tutorial cvs-migration
1065 diffcore gitk glossary hooks ignore modules
1066 repository-layout tutorial tutorial-2
1067 workflows
1068 "
1069}
1070
1071_git_init ()
1072{
1073 local cur="${COMP_WORDS[COMP_CWORD]}"
1074 case "$cur" in
1075 --shared=*)
1076 __gitcomp "
1077 false true umask group all world everybody
1078 " "" "${cur##--shared=}"
1079 return
1080 ;;
1081 --*)
1082 __gitcomp "--quiet --bare --template= --shared --shared="
1083 return
1084 ;;
1085 esac
1086 COMPREPLY=()
1087}
1088
1089_git_ls_files ()
1090{
1091 __git_has_doubledash && return
1092
1093 local cur="${COMP_WORDS[COMP_CWORD]}"
1094 case "$cur" in
1095 --*)
1096 __gitcomp "--cached --deleted --modified --others --ignored
1097 --stage --directory --no-empty-directory --unmerged
1098 --killed --exclude= --exclude-from=
1099 --exclude-per-directory= --exclude-standard
1100 --error-unmatch --with-tree= --full-name
1101 --abbrev --ignored --exclude-per-directory
1102 "
1103 return
1104 ;;
1105 esac
1106 COMPREPLY=()
1107}
1108
1109_git_ls_remote ()
1110{
1111 __gitcomp "$(__git_remotes)"
1112}
1113
1114_git_ls_tree ()
1115{
1116 __git_complete_file
1117}
1118
1119# Options that go well for log, shortlog and gitk
1120__git_log_common_options="
1121 --not --all
1122 --branches --tags --remotes
1123 --first-parent --merges --no-merges
1124 --max-count=
1125 --max-age= --since= --after=
1126 --min-age= --until= --before=
1127"
1128# Options that go well for log and gitk (not shortlog)
1129__git_log_gitk_options="
1130 --dense --sparse --full-history
1131 --simplify-merges --simplify-by-decoration
1132 --left-right
1133"
1134# Options that go well for log and shortlog (not gitk)
1135__git_log_shortlog_options="
1136 --author= --committer= --grep=
1137 --all-match
1138"
1139
1140__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1141__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1142
1143_git_log ()
1144{
1145 __git_has_doubledash && return
1146
1147 local cur="${COMP_WORDS[COMP_CWORD]}"
1148 local g="$(git rev-parse --git-dir 2>/dev/null)"
1149 local merge=""
1150 if [ -f "$g/MERGE_HEAD" ]; then
1151 merge="--merge"
1152 fi
1153 case "$cur" in
1154 --pretty=*)
1155 __gitcomp "$__git_log_pretty_formats
1156 " "" "${cur##--pretty=}"
1157 return
1158 ;;
1159 --format=*)
1160 __gitcomp "$__git_log_pretty_formats
1161 " "" "${cur##--format=}"
1162 return
1163 ;;
1164 --date=*)
1165 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1166 return
1167 ;;
1168 --*)
1169 __gitcomp "
1170 $__git_log_common_options
1171 $__git_log_shortlog_options
1172 $__git_log_gitk_options
1173 --root --topo-order --date-order --reverse
1174 --follow --full-diff
1175 --abbrev-commit --abbrev=
1176 --relative-date --date=
1177 --pretty= --format= --oneline
1178 --cherry-pick
1179 --graph
1180 --decorate
1181 --walk-reflogs
1182 --parents --children
1183 $merge
1184 $__git_diff_common_options
1185 --pickaxe-all --pickaxe-regex
1186 "
1187 return
1188 ;;
1189 esac
1190 __git_complete_revlist
1191}
1192
1193__git_merge_options="
1194 --no-commit --no-stat --log --no-log --squash --strategy
1195 --commit --stat --no-squash --ff --no-ff
1196"
1197
1198_git_merge ()
1199{
1200 __git_complete_strategy && return
1201
1202 local cur="${COMP_WORDS[COMP_CWORD]}"
1203 case "$cur" in
1204 --*)
1205 __gitcomp "$__git_merge_options"
1206 return
1207 esac
1208 __gitcomp "$(__git_refs)"
1209}
1210
1211_git_mergetool ()
1212{
1213 local cur="${COMP_WORDS[COMP_CWORD]}"
1214 case "$cur" in
1215 --tool=*)
1216 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1217 return
1218 ;;
1219 --*)
1220 __gitcomp "--tool="
1221 return
1222 ;;
1223 esac
1224 COMPREPLY=()
1225}
1226
1227_git_merge_base ()
1228{
1229 __gitcomp "$(__git_refs)"
1230}
1231
1232_git_mv ()
1233{
1234 local cur="${COMP_WORDS[COMP_CWORD]}"
1235 case "$cur" in
1236 --*)
1237 __gitcomp "--dry-run"
1238 return
1239 ;;
1240 esac
1241 COMPREPLY=()
1242}
1243
1244_git_name_rev ()
1245{
1246 __gitcomp "--tags --all --stdin"
1247}
1248
1249_git_pull ()
1250{
1251 __git_complete_strategy && return
1252
1253 local cur="${COMP_WORDS[COMP_CWORD]}"
1254 case "$cur" in
1255 --*)
1256 __gitcomp "
1257 --rebase --no-rebase
1258 $__git_merge_options
1259 $__git_fetch_options
1260 "
1261 return
1262 ;;
1263 esac
1264 __git_complete_remote_or_refspec
1265}
1266
1267_git_push ()
1268{
1269 local cur="${COMP_WORDS[COMP_CWORD]}"
1270 case "${COMP_WORDS[COMP_CWORD-1]}" in
1271 --repo)
1272 __gitcomp "$(__git_remotes)"
1273 return
1274 esac
1275 case "$cur" in
1276 --repo=*)
1277 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1278 return
1279 ;;
1280 --*)
1281 __gitcomp "
1282 --all --mirror --tags --dry-run --force --verbose
1283 --receive-pack= --repo=
1284 "
1285 return
1286 ;;
1287 esac
1288 __git_complete_remote_or_refspec
1289}
1290
1291_git_rebase ()
1292{
1293 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1294 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1295 __gitcomp "--continue --skip --abort"
1296 return
1297 fi
1298 __git_complete_strategy && return
1299 case "$cur" in
1300 --*)
1301 __gitcomp "--onto --merge --strategy --interactive"
1302 return
1303 esac
1304 __gitcomp "$(__git_refs)"
1305}
1306
1307__git_send_email_confirm_options="always never auto cc compose"
1308__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1309
1310_git_send_email ()
1311{
1312 local cur="${COMP_WORDS[COMP_CWORD]}"
1313 case "$cur" in
1314 --confirm=*)
1315 __gitcomp "
1316 $__git_send_email_confirm_options
1317 " "" "${cur##--confirm=}"
1318 return
1319 ;;
1320 --suppress-cc=*)
1321 __gitcomp "
1322 $__git_send_email_suppresscc_options
1323 " "" "${cur##--suppress-cc=}"
1324
1325 return
1326 ;;
1327 --smtp-encryption=*)
1328 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1329 return
1330 ;;
1331 --*)
1332 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1333 --compose --confirm= --dry-run --envelope-sender
1334 --from --identity
1335 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1336 --no-suppress-from --no-thread --quiet
1337 --signed-off-by-cc --smtp-pass --smtp-server
1338 --smtp-server-port --smtp-encryption= --smtp-user
1339 --subject --suppress-cc= --suppress-from --thread --to
1340 --validate --no-validate"
1341 return
1342 ;;
1343 esac
1344 COMPREPLY=()
1345}
1346
1347__git_config_get_set_variables ()
1348{
1349 local prevword word config_file= c=$COMP_CWORD
1350 while [ $c -gt 1 ]; do
1351 word="${COMP_WORDS[c]}"
1352 case "$word" in
1353 --global|--system|--file=*)
1354 config_file="$word"
1355 break
1356 ;;
1357 -f|--file)
1358 config_file="$word $prevword"
1359 break
1360 ;;
1361 esac
1362 prevword=$word
1363 c=$((--c))
1364 done
1365
1366 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1367 while read line
1368 do
1369 case "$line" in
1370 *.*=*)
1371 echo "${line/=*/}"
1372 ;;
1373 esac
1374 done
1375}
1376
1377_git_config ()
1378{
1379 local cur="${COMP_WORDS[COMP_CWORD]}"
1380 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1381 case "$prv" in
1382 branch.*.remote)
1383 __gitcomp "$(__git_remotes)"
1384 return
1385 ;;
1386 branch.*.merge)
1387 __gitcomp "$(__git_refs)"
1388 return
1389 ;;
1390 remote.*.fetch)
1391 local remote="${prv#remote.}"
1392 remote="${remote%.fetch}"
1393 __gitcomp "$(__git_refs_remotes "$remote")"
1394 return
1395 ;;
1396 remote.*.push)
1397 local remote="${prv#remote.}"
1398 remote="${remote%.push}"
1399 __gitcomp "$(git --git-dir="$(__gitdir)" \
1400 for-each-ref --format='%(refname):%(refname)' \
1401 refs/heads)"
1402 return
1403 ;;
1404 pull.twohead|pull.octopus)
1405 __gitcomp "$(__git_merge_strategies)"
1406 return
1407 ;;
1408 color.branch|color.diff|color.interactive|\
1409 color.showbranch|color.status|color.ui)
1410 __gitcomp "always never auto"
1411 return
1412 ;;
1413 color.pager)
1414 __gitcomp "false true"
1415 return
1416 ;;
1417 color.*.*)
1418 __gitcomp "
1419 normal black red green yellow blue magenta cyan white
1420 bold dim ul blink reverse
1421 "
1422 return
1423 ;;
1424 help.format)
1425 __gitcomp "man info web html"
1426 return
1427 ;;
1428 log.date)
1429 __gitcomp "$__git_log_date_formats"
1430 return
1431 ;;
1432 sendemail.aliasesfiletype)
1433 __gitcomp "mutt mailrc pine elm gnus"
1434 return
1435 ;;
1436 sendemail.confirm)
1437 __gitcomp "$__git_send_email_confirm_options"
1438 return
1439 ;;
1440 sendemail.suppresscc)
1441 __gitcomp "$__git_send_email_suppresscc_options"
1442 return
1443 ;;
1444 --get|--get-all|--unset|--unset-all)
1445 __gitcomp "$(__git_config_get_set_variables)"
1446 return
1447 ;;
1448 *.*)
1449 COMPREPLY=()
1450 return
1451 ;;
1452 esac
1453 case "$cur" in
1454 --*)
1455 __gitcomp "
1456 --global --system --file=
1457 --list --replace-all
1458 --get --get-all --get-regexp
1459 --add --unset --unset-all
1460 --remove-section --rename-section
1461 "
1462 return
1463 ;;
1464 branch.*.*)
1465 local pfx="${cur%.*}."
1466 cur="${cur##*.}"
1467 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1468 return
1469 ;;
1470 branch.*)
1471 local pfx="${cur%.*}."
1472 cur="${cur#*.}"
1473 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1474 return
1475 ;;
1476 guitool.*.*)
1477 local pfx="${cur%.*}."
1478 cur="${cur##*.}"
1479 __gitcomp "
1480 argprompt cmd confirm needsfile noconsole norescan
1481 prompt revprompt revunmerged title
1482 " "$pfx" "$cur"
1483 return
1484 ;;
1485 difftool.*.*)
1486 local pfx="${cur%.*}."
1487 cur="${cur##*.}"
1488 __gitcomp "cmd path" "$pfx" "$cur"
1489 return
1490 ;;
1491 man.*.*)
1492 local pfx="${cur%.*}."
1493 cur="${cur##*.}"
1494 __gitcomp "cmd path" "$pfx" "$cur"
1495 return
1496 ;;
1497 mergetool.*.*)
1498 local pfx="${cur%.*}."
1499 cur="${cur##*.}"
1500 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1501 return
1502 ;;
1503 pager.*)
1504 local pfx="${cur%.*}."
1505 cur="${cur#*.}"
1506 __gitcomp "$(__git_all_commands)" "$pfx" "$cur"
1507 return
1508 ;;
1509 remote.*.*)
1510 local pfx="${cur%.*}."
1511 cur="${cur##*.}"
1512 __gitcomp "
1513 url proxy fetch push mirror skipDefaultUpdate
1514 receivepack uploadpack tagopt pushurl
1515 " "$pfx" "$cur"
1516 return
1517 ;;
1518 remote.*)
1519 local pfx="${cur%.*}."
1520 cur="${cur#*.}"
1521 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1522 return
1523 ;;
1524 url.*.*)
1525 local pfx="${cur%.*}."
1526 cur="${cur##*.}"
1527 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1528 return
1529 ;;
1530 esac
1531 __gitcomp "
1532 add.ignore-errors
1533 alias.
1534 apply.ignorewhitespace
1535 apply.whitespace
1536 branch.autosetupmerge
1537 branch.autosetuprebase
1538 clean.requireForce
1539 color.branch
1540 color.branch.current
1541 color.branch.local
1542 color.branch.plain
1543 color.branch.remote
1544 color.diff
1545 color.diff.commit
1546 color.diff.frag
1547 color.diff.meta
1548 color.diff.new
1549 color.diff.old
1550 color.diff.plain
1551 color.diff.whitespace
1552 color.grep
1553 color.grep.external
1554 color.grep.match
1555 color.interactive
1556 color.interactive.header
1557 color.interactive.help
1558 color.interactive.prompt
1559 color.pager
1560 color.showbranch
1561 color.status
1562 color.status.added
1563 color.status.changed
1564 color.status.header
1565 color.status.nobranch
1566 color.status.untracked
1567 color.status.updated
1568 color.ui
1569 commit.template
1570 core.autocrlf
1571 core.bare
1572 core.compression
1573 core.createObject
1574 core.deltaBaseCacheLimit
1575 core.editor
1576 core.excludesfile
1577 core.fileMode
1578 core.fsyncobjectfiles
1579 core.gitProxy
1580 core.ignoreCygwinFSTricks
1581 core.ignoreStat
1582 core.logAllRefUpdates
1583 core.loosecompression
1584 core.packedGitLimit
1585 core.packedGitWindowSize
1586 core.pager
1587 core.preferSymlinkRefs
1588 core.preloadindex
1589 core.quotepath
1590 core.repositoryFormatVersion
1591 core.safecrlf
1592 core.sharedRepository
1593 core.symlinks
1594 core.trustctime
1595 core.warnAmbiguousRefs
1596 core.whitespace
1597 core.worktree
1598 diff.autorefreshindex
1599 diff.external
1600 diff.mnemonicprefix
1601 diff.renameLimit
1602 diff.renameLimit.
1603 diff.renames
1604 diff.suppressBlankEmpty
1605 diff.tool
1606 diff.wordRegex
1607 difftool.
1608 difftool.prompt
1609 fetch.unpackLimit
1610 format.attach
1611 format.cc
1612 format.headers
1613 format.numbered
1614 format.pretty
1615 format.signoff
1616 format.subjectprefix
1617 format.suffix
1618 format.thread
1619 gc.aggressiveWindow
1620 gc.auto
1621 gc.autopacklimit
1622 gc.packrefs
1623 gc.pruneexpire
1624 gc.reflogexpire
1625 gc.reflogexpireunreachable
1626 gc.rerereresolved
1627 gc.rerereunresolved
1628 gitcvs.allbinary
1629 gitcvs.commitmsgannotation
1630 gitcvs.dbTableNamePrefix
1631 gitcvs.dbdriver
1632 gitcvs.dbname
1633 gitcvs.dbpass
1634 gitcvs.dbuser
1635 gitcvs.enabled
1636 gitcvs.logfile
1637 gitcvs.usecrlfattr
1638 guitool.
1639 gui.blamehistoryctx
1640 gui.commitmsgwidth
1641 gui.copyblamethreshold
1642 gui.diffcontext
1643 gui.encoding
1644 gui.fastcopyblame
1645 gui.matchtrackingbranch
1646 gui.newbranchtemplate
1647 gui.pruneduringfetch
1648 gui.spellingdictionary
1649 gui.trustmtime
1650 help.autocorrect
1651 help.browser
1652 help.format
1653 http.lowSpeedLimit
1654 http.lowSpeedTime
1655 http.maxRequests
1656 http.noEPSV
1657 http.proxy
1658 http.sslCAInfo
1659 http.sslCAPath
1660 http.sslCert
1661 http.sslKey
1662 http.sslVerify
1663 i18n.commitEncoding
1664 i18n.logOutputEncoding
1665 imap.folder
1666 imap.host
1667 imap.pass
1668 imap.port
1669 imap.preformattedHTML
1670 imap.sslverify
1671 imap.tunnel
1672 imap.user
1673 instaweb.browser
1674 instaweb.httpd
1675 instaweb.local
1676 instaweb.modulepath
1677 instaweb.port
1678 interactive.singlekey
1679 log.date
1680 log.showroot
1681 mailmap.file
1682 man.
1683 man.viewer
1684 merge.conflictstyle
1685 merge.log
1686 merge.renameLimit
1687 merge.stat
1688 merge.tool
1689 merge.verbosity
1690 mergetool.
1691 mergetool.keepBackup
1692 mergetool.prompt
1693 pack.compression
1694 pack.deltaCacheLimit
1695 pack.deltaCacheSize
1696 pack.depth
1697 pack.indexVersion
1698 pack.packSizeLimit
1699 pack.threads
1700 pack.window
1701 pack.windowMemory
1702 pager.
1703 pull.octopus
1704 pull.twohead
1705 push.default
1706 rebase.stat
1707 receive.denyCurrentBranch
1708 receive.denyDeletes
1709 receive.denyNonFastForwards
1710 receive.fsckObjects
1711 receive.unpackLimit
1712 repack.usedeltabaseoffset
1713 rerere.autoupdate
1714 rerere.enabled
1715 sendemail.aliasesfile
1716 sendemail.aliasesfiletype
1717 sendemail.bcc
1718 sendemail.cc
1719 sendemail.cccmd
1720 sendemail.chainreplyto
1721 sendemail.confirm
1722 sendemail.envelopesender
1723 sendemail.multiedit
1724 sendemail.signedoffbycc
1725 sendemail.smtpencryption
1726 sendemail.smtppass
1727 sendemail.smtpserver
1728 sendemail.smtpserverport
1729 sendemail.smtpuser
1730 sendemail.suppresscc
1731 sendemail.suppressfrom
1732 sendemail.thread
1733 sendemail.to
1734 sendemail.validate
1735 showbranch.default
1736 status.relativePaths
1737 status.showUntrackedFiles
1738 tar.umask
1739 transfer.unpackLimit
1740 url.
1741 user.email
1742 user.name
1743 user.signingkey
1744 web.browser
1745 branch. remote.
1746 "
1747}
1748
1749_git_remote ()
1750{
1751 local subcommands="add rename rm show prune update set-head"
1752 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1753 if [ -z "$subcommand" ]; then
1754 __gitcomp "$subcommands"
1755 return
1756 fi
1757
1758 case "$subcommand" in
1759 rename|rm|show|prune)
1760 __gitcomp "$(__git_remotes)"
1761 ;;
1762 update)
1763 local i c='' IFS=$'\n'
1764 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1765 i="${i#remotes.}"
1766 c="$c ${i/ */}"
1767 done
1768 __gitcomp "$c"
1769 ;;
1770 *)
1771 COMPREPLY=()
1772 ;;
1773 esac
1774}
1775
1776_git_reset ()
1777{
1778 __git_has_doubledash && return
1779
1780 local cur="${COMP_WORDS[COMP_CWORD]}"
1781 case "$cur" in
1782 --*)
1783 __gitcomp "--merge --mixed --hard --soft"
1784 return
1785 ;;
1786 esac
1787 __gitcomp "$(__git_refs)"
1788}
1789
1790_git_revert ()
1791{
1792 local cur="${COMP_WORDS[COMP_CWORD]}"
1793 case "$cur" in
1794 --*)
1795 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1796 return
1797 ;;
1798 esac
1799 __gitcomp "$(__git_refs)"
1800}
1801
1802_git_rm ()
1803{
1804 __git_has_doubledash && return
1805
1806 local cur="${COMP_WORDS[COMP_CWORD]}"
1807 case "$cur" in
1808 --*)
1809 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1810 return
1811 ;;
1812 esac
1813 COMPREPLY=()
1814}
1815
1816_git_shortlog ()
1817{
1818 __git_has_doubledash && return
1819
1820 local cur="${COMP_WORDS[COMP_CWORD]}"
1821 case "$cur" in
1822 --*)
1823 __gitcomp "
1824 $__git_log_common_options
1825 $__git_log_shortlog_options
1826 --numbered --summary
1827 "
1828 return
1829 ;;
1830 esac
1831 __git_complete_revlist
1832}
1833
1834_git_show ()
1835{
1836 __git_has_doubledash && return
1837
1838 local cur="${COMP_WORDS[COMP_CWORD]}"
1839 case "$cur" in
1840 --pretty=*)
1841 __gitcomp "$__git_log_pretty_formats
1842 " "" "${cur##--pretty=}"
1843 return
1844 ;;
1845 --format=*)
1846 __gitcomp "$__git_log_pretty_formats
1847 " "" "${cur##--format=}"
1848 return
1849 ;;
1850 --*)
1851 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1852 $__git_diff_common_options
1853 "
1854 return
1855 ;;
1856 esac
1857 __git_complete_file
1858}
1859
1860_git_show_branch ()
1861{
1862 local cur="${COMP_WORDS[COMP_CWORD]}"
1863 case "$cur" in
1864 --*)
1865 __gitcomp "
1866 --all --remotes --topo-order --current --more=
1867 --list --independent --merge-base --no-name
1868 --color --no-color
1869 --sha1-name --sparse --topics --reflog
1870 "
1871 return
1872 ;;
1873 esac
1874 __git_complete_revlist
1875}
1876
1877_git_stash ()
1878{
1879 local subcommands='save list show apply clear drop pop create branch'
1880 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1881 if [ -z "$subcommand" ]; then
1882 __gitcomp "$subcommands"
1883 else
1884 local cur="${COMP_WORDS[COMP_CWORD]}"
1885 case "$subcommand,$cur" in
1886 save,--*)
1887 __gitcomp "--keep-index"
1888 ;;
1889 apply,--*|pop,--*)
1890 __gitcomp "--index"
1891 ;;
1892 show,--*|drop,--*|branch,--*)
1893 COMPREPLY=()
1894 ;;
1895 show,*|apply,*|drop,*|pop,*|branch,*)
1896 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1897 | sed -n -e 's/:.*//p')"
1898 ;;
1899 *)
1900 COMPREPLY=()
1901 ;;
1902 esac
1903 fi
1904}
1905
1906_git_submodule ()
1907{
1908 __git_has_doubledash && return
1909
1910 local subcommands="add status init update summary foreach sync"
1911 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1912 local cur="${COMP_WORDS[COMP_CWORD]}"
1913 case "$cur" in
1914 --*)
1915 __gitcomp "--quiet --cached"
1916 ;;
1917 *)
1918 __gitcomp "$subcommands"
1919 ;;
1920 esac
1921 return
1922 fi
1923}
1924
1925_git_svn ()
1926{
1927 local subcommands="
1928 init fetch clone rebase dcommit log find-rev
1929 set-tree commit-diff info create-ignore propget
1930 proplist show-ignore show-externals branch tag blame
1931 migrate
1932 "
1933 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1934 if [ -z "$subcommand" ]; then
1935 __gitcomp "$subcommands"
1936 else
1937 local remote_opts="--username= --config-dir= --no-auth-cache"
1938 local fc_opts="
1939 --follow-parent --authors-file= --repack=
1940 --no-metadata --use-svm-props --use-svnsync-props
1941 --log-window-size= --no-checkout --quiet
1942 --repack-flags --use-log-author --localtime
1943 --ignore-paths= $remote_opts
1944 "
1945 local init_opts="
1946 --template= --shared= --trunk= --tags=
1947 --branches= --stdlayout --minimize-url
1948 --no-metadata --use-svm-props --use-svnsync-props
1949 --rewrite-root= --prefix= --use-log-author
1950 --add-author-from $remote_opts
1951 "
1952 local cmt_opts="
1953 --edit --rmdir --find-copies-harder --copy-similarity=
1954 "
1955
1956 local cur="${COMP_WORDS[COMP_CWORD]}"
1957 case "$subcommand,$cur" in
1958 fetch,--*)
1959 __gitcomp "--revision= --fetch-all $fc_opts"
1960 ;;
1961 clone,--*)
1962 __gitcomp "--revision= $fc_opts $init_opts"
1963 ;;
1964 init,--*)
1965 __gitcomp "$init_opts"
1966 ;;
1967 dcommit,--*)
1968 __gitcomp "
1969 --merge --strategy= --verbose --dry-run
1970 --fetch-all --no-rebase --commit-url
1971 --revision $cmt_opts $fc_opts
1972 "
1973 ;;
1974 set-tree,--*)
1975 __gitcomp "--stdin $cmt_opts $fc_opts"
1976 ;;
1977 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1978 show-externals,--*)
1979 __gitcomp "--revision="
1980 ;;
1981 log,--*)
1982 __gitcomp "
1983 --limit= --revision= --verbose --incremental
1984 --oneline --show-commit --non-recursive
1985 --authors-file= --color
1986 "
1987 ;;
1988 rebase,--*)
1989 __gitcomp "
1990 --merge --verbose --strategy= --local
1991 --fetch-all --dry-run $fc_opts
1992 "
1993 ;;
1994 commit-diff,--*)
1995 __gitcomp "--message= --file= --revision= $cmt_opts"
1996 ;;
1997 info,--*)
1998 __gitcomp "--url"
1999 ;;
2000 branch,--*)
2001 __gitcomp "--dry-run --message --tag"
2002 ;;
2003 tag,--*)
2004 __gitcomp "--dry-run --message"
2005 ;;
2006 blame,--*)
2007 __gitcomp "--git-format"
2008 ;;
2009 migrate,--*)
2010 __gitcomp "
2011 --config-dir= --ignore-paths= --minimize
2012 --no-auth-cache --username=
2013 "
2014 ;;
2015 *)
2016 COMPREPLY=()
2017 ;;
2018 esac
2019 fi
2020}
2021
2022_git_tag ()
2023{
2024 local i c=1 f=0
2025 while [ $c -lt $COMP_CWORD ]; do
2026 i="${COMP_WORDS[c]}"
2027 case "$i" in
2028 -d|-v)
2029 __gitcomp "$(__git_tags)"
2030 return
2031 ;;
2032 -f)
2033 f=1
2034 ;;
2035 esac
2036 c=$((++c))
2037 done
2038
2039 case "${COMP_WORDS[COMP_CWORD-1]}" in
2040 -m|-F)
2041 COMPREPLY=()
2042 ;;
2043 -*|tag)
2044 if [ $f = 1 ]; then
2045 __gitcomp "$(__git_tags)"
2046 else
2047 COMPREPLY=()
2048 fi
2049 ;;
2050 *)
2051 __gitcomp "$(__git_refs)"
2052 ;;
2053 esac
2054}
2055
2056_git ()
2057{
2058 local i c=1 command __git_dir
2059
2060 while [ $c -lt $COMP_CWORD ]; do
2061 i="${COMP_WORDS[c]}"
2062 case "$i" in
2063 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2064 --bare) __git_dir="." ;;
2065 --version|-p|--paginate) ;;
2066 --help) command="help"; break ;;
2067 *) command="$i"; break ;;
2068 esac
2069 c=$((++c))
2070 done
2071
2072 if [ -z "$command" ]; then
2073 case "${COMP_WORDS[COMP_CWORD]}" in
2074 --*) __gitcomp "
2075 --paginate
2076 --no-pager
2077 --git-dir=
2078 --bare
2079 --version
2080 --exec-path
2081 --html-path
2082 --work-tree=
2083 --help
2084 "
2085 ;;
2086 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
2087 esac
2088 return
2089 fi
2090
2091 local expansion=$(__git_aliased_command "$command")
2092 [ "$expansion" ] && command="$expansion"
2093
2094 case "$command" in
2095 am) _git_am ;;
2096 add) _git_add ;;
2097 apply) _git_apply ;;
2098 archive) _git_archive ;;
2099 bisect) _git_bisect ;;
2100 bundle) _git_bundle ;;
2101 branch) _git_branch ;;
2102 checkout) _git_checkout ;;
2103 cherry) _git_cherry ;;
2104 cherry-pick) _git_cherry_pick ;;
2105 clean) _git_clean ;;
2106 clone) _git_clone ;;
2107 commit) _git_commit ;;
2108 config) _git_config ;;
2109 describe) _git_describe ;;
2110 diff) _git_diff ;;
2111 difftool) _git_difftool ;;
2112 fetch) _git_fetch ;;
2113 format-patch) _git_format_patch ;;
2114 fsck) _git_fsck ;;
2115 gc) _git_gc ;;
2116 grep) _git_grep ;;
2117 help) _git_help ;;
2118 init) _git_init ;;
2119 log) _git_log ;;
2120 ls-files) _git_ls_files ;;
2121 ls-remote) _git_ls_remote ;;
2122 ls-tree) _git_ls_tree ;;
2123 merge) _git_merge;;
2124 mergetool) _git_mergetool;;
2125 merge-base) _git_merge_base ;;
2126 mv) _git_mv ;;
2127 name-rev) _git_name_rev ;;
2128 pull) _git_pull ;;
2129 push) _git_push ;;
2130 rebase) _git_rebase ;;
2131 remote) _git_remote ;;
2132 reset) _git_reset ;;
2133 revert) _git_revert ;;
2134 rm) _git_rm ;;
2135 send-email) _git_send_email ;;
2136 shortlog) _git_shortlog ;;
2137 show) _git_show ;;
2138 show-branch) _git_show_branch ;;
2139 stash) _git_stash ;;
2140 stage) _git_add ;;
2141 submodule) _git_submodule ;;
2142 svn) _git_svn ;;
2143 tag) _git_tag ;;
2144 whatchanged) _git_log ;;
2145 *) COMPREPLY=() ;;
2146 esac
2147}
2148
2149_gitk ()
2150{
2151 __git_has_doubledash && return
2152
2153 local cur="${COMP_WORDS[COMP_CWORD]}"
2154 local g="$(__gitdir)"
2155 local merge=""
2156 if [ -f "$g/MERGE_HEAD" ]; then
2157 merge="--merge"
2158 fi
2159 case "$cur" in
2160 --*)
2161 __gitcomp "
2162 $__git_log_common_options
2163 $__git_log_gitk_options
2164 $merge
2165 "
2166 return
2167 ;;
2168 esac
2169 __git_complete_revlist
2170}
2171
2172complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2173 || complete -o default -o nospace -F _git git
2174complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2175 || complete -o default -o nospace -F _gitk gitk
2176
2177# The following are necessary only for Cygwin, and only are needed
2178# when the user has tab-completed the executable name and consequently
2179# included the '.exe' suffix.
2180#
2181if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2182complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2183 || complete -o default -o nospace -F _git git.exe
2184fi