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