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