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