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