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