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