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