4e724a5b7648b96539e635bc3328fb066d576864
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 () {
838 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
839 then
840 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
841 else
842 git --list-cmds=main,others
843 fi
844}
845
846__git_list_all_commands ()
847{
848 local i IFS=" "$'\n'
849 for i in $(__git_commands)
850 do
851 case $i in
852 *--*) : helper pattern;;
853 *) echo $i;;
854 esac
855 done
856}
857
858__git_all_commands=
859__git_compute_all_commands ()
860{
861 test -n "$__git_all_commands" ||
862 __git_all_commands=$(__git_list_all_commands)
863}
864
865__git_list_porcelain_commands ()
866{
867 local i IFS=" "$'\n'
868 __git_compute_all_commands
869 for i in $__git_all_commands
870 do
871 case $i in
872 *--*) : helper pattern;;
873 applymbox) : ask gittus;;
874 applypatch) : ask gittus;;
875 archimport) : import;;
876 cat-file) : plumbing;;
877 check-attr) : plumbing;;
878 check-ignore) : plumbing;;
879 check-mailmap) : plumbing;;
880 check-ref-format) : plumbing;;
881 checkout-index) : plumbing;;
882 column) : internal helper;;
883 commit-tree) : plumbing;;
884 count-objects) : infrequent;;
885 credential) : credentials;;
886 credential-*) : credentials helper;;
887 cvsexportcommit) : export;;
888 cvsimport) : import;;
889 cvsserver) : daemon;;
890 daemon) : daemon;;
891 diff-files) : plumbing;;
892 diff-index) : plumbing;;
893 diff-tree) : plumbing;;
894 fast-import) : import;;
895 fast-export) : export;;
896 fsck-objects) : plumbing;;
897 fetch-pack) : plumbing;;
898 fmt-merge-msg) : plumbing;;
899 for-each-ref) : plumbing;;
900 hash-object) : plumbing;;
901 http-*) : transport;;
902 index-pack) : plumbing;;
903 init-db) : deprecated;;
904 local-fetch) : plumbing;;
905 ls-files) : plumbing;;
906 ls-remote) : plumbing;;
907 ls-tree) : plumbing;;
908 mailinfo) : plumbing;;
909 mailsplit) : plumbing;;
910 merge-*) : plumbing;;
911 mktree) : plumbing;;
912 mktag) : plumbing;;
913 pack-objects) : plumbing;;
914 pack-redundant) : plumbing;;
915 pack-refs) : plumbing;;
916 parse-remote) : plumbing;;
917 patch-id) : plumbing;;
918 prune) : plumbing;;
919 prune-packed) : plumbing;;
920 quiltimport) : import;;
921 read-tree) : plumbing;;
922 receive-pack) : plumbing;;
923 remote-*) : transport;;
924 rerere) : plumbing;;
925 rev-list) : plumbing;;
926 rev-parse) : plumbing;;
927 runstatus) : plumbing;;
928 sh-setup) : internal;;
929 shell) : daemon;;
930 show-ref) : plumbing;;
931 send-pack) : plumbing;;
932 show-index) : plumbing;;
933 ssh-*) : transport;;
934 stripspace) : plumbing;;
935 symbolic-ref) : plumbing;;
936 unpack-file) : plumbing;;
937 unpack-objects) : plumbing;;
938 update-index) : plumbing;;
939 update-ref) : plumbing;;
940 update-server-info) : daemon;;
941 upload-archive) : plumbing;;
942 upload-pack) : plumbing;;
943 write-tree) : plumbing;;
944 var) : infrequent;;
945 verify-pack) : infrequent;;
946 verify-tag) : plumbing;;
947 *) echo $i;;
948 esac
949 done
950}
951
952__git_porcelain_commands=
953__git_compute_porcelain_commands ()
954{
955 test -n "$__git_porcelain_commands" ||
956 __git_porcelain_commands=$(__git_list_porcelain_commands)
957}
958
959# Lists all set config variables starting with the given section prefix,
960# with the prefix removed.
961__git_get_config_variables ()
962{
963 local section="$1" i IFS=$'\n'
964 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
965 echo "${i#$section.}"
966 done
967}
968
969__git_pretty_aliases ()
970{
971 __git_get_config_variables "pretty"
972}
973
974__git_aliases ()
975{
976 __git_get_config_variables "alias"
977}
978
979# __git_aliased_command requires 1 argument
980__git_aliased_command ()
981{
982 local word cmdline=$(__git config --get "alias.$1")
983 for word in $cmdline; do
984 case "$word" in
985 \!gitk|gitk)
986 echo "gitk"
987 return
988 ;;
989 \!*) : shell command alias ;;
990 -*) : option ;;
991 *=*) : setting env ;;
992 git) : git itself ;;
993 \(\)) : skip parens of shell function definition ;;
994 {) : skip start of shell helper function ;;
995 :) : skip null command ;;
996 \'*) : skip opening quote after sh -c ;;
997 *)
998 echo "$word"
999 return
1000 esac
1001 done
1002}
1003
1004# __git_find_on_cmdline requires 1 argument
1005__git_find_on_cmdline ()
1006{
1007 local word subcommand c=1
1008 while [ $c -lt $cword ]; do
1009 word="${words[c]}"
1010 for subcommand in $1; do
1011 if [ "$subcommand" = "$word" ]; then
1012 echo "$subcommand"
1013 return
1014 fi
1015 done
1016 ((c++))
1017 done
1018}
1019
1020# Echo the value of an option set on the command line or config
1021#
1022# $1: short option name
1023# $2: long option name including =
1024# $3: list of possible values
1025# $4: config string (optional)
1026#
1027# example:
1028# result="$(__git_get_option_value "-d" "--do-something=" \
1029# "yes no" "core.doSomething")"
1030#
1031# result is then either empty (no option set) or "yes" or "no"
1032#
1033# __git_get_option_value requires 3 arguments
1034__git_get_option_value ()
1035{
1036 local c short_opt long_opt val
1037 local result= values config_key word
1038
1039 short_opt="$1"
1040 long_opt="$2"
1041 values="$3"
1042 config_key="$4"
1043
1044 ((c = $cword - 1))
1045 while [ $c -ge 0 ]; do
1046 word="${words[c]}"
1047 for val in $values; do
1048 if [ "$short_opt$val" = "$word" ] ||
1049 [ "$long_opt$val" = "$word" ]; then
1050 result="$val"
1051 break 2
1052 fi
1053 done
1054 ((c--))
1055 done
1056
1057 if [ -n "$config_key" ] && [ -z "$result" ]; then
1058 result="$(__git config "$config_key")"
1059 fi
1060
1061 echo "$result"
1062}
1063
1064__git_has_doubledash ()
1065{
1066 local c=1
1067 while [ $c -lt $cword ]; do
1068 if [ "--" = "${words[c]}" ]; then
1069 return 0
1070 fi
1071 ((c++))
1072 done
1073 return 1
1074}
1075
1076# Try to count non option arguments passed on the command line for the
1077# specified git command.
1078# When options are used, it is necessary to use the special -- option to
1079# tell the implementation were non option arguments begin.
1080# XXX this can not be improved, since options can appear everywhere, as
1081# an example:
1082# git mv x -n y
1083#
1084# __git_count_arguments requires 1 argument: the git command executed.
1085__git_count_arguments ()
1086{
1087 local word i c=0
1088
1089 # Skip "git" (first argument)
1090 for ((i=1; i < ${#words[@]}; i++)); do
1091 word="${words[i]}"
1092
1093 case "$word" in
1094 --)
1095 # Good; we can assume that the following are only non
1096 # option arguments.
1097 ((c = 0))
1098 ;;
1099 "$1")
1100 # Skip the specified git command and discard git
1101 # main options
1102 ((c = 0))
1103 ;;
1104 ?*)
1105 ((c++))
1106 ;;
1107 esac
1108 done
1109
1110 printf "%d" $c
1111}
1112
1113__git_whitespacelist="nowarn warn error error-all fix"
1114__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1115
1116_git_am ()
1117{
1118 __git_find_repo_path
1119 if [ -d "$__git_repo_path"/rebase-apply ]; then
1120 __gitcomp "$__git_am_inprogress_options"
1121 return
1122 fi
1123 case "$cur" in
1124 --whitespace=*)
1125 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1126 return
1127 ;;
1128 --*)
1129 __gitcomp_builtin am "--no-utf8" \
1130 "$__git_am_inprogress_options"
1131 return
1132 esac
1133}
1134
1135_git_apply ()
1136{
1137 case "$cur" in
1138 --whitespace=*)
1139 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1140 return
1141 ;;
1142 --*)
1143 __gitcomp_builtin apply
1144 return
1145 esac
1146}
1147
1148_git_add ()
1149{
1150 case "$cur" in
1151 --*)
1152 __gitcomp_builtin add
1153 return
1154 esac
1155
1156 local complete_opt="--others --modified --directory --no-empty-directory"
1157 if test -n "$(__git_find_on_cmdline "-u --update")"
1158 then
1159 complete_opt="--modified"
1160 fi
1161 __git_complete_index_file "$complete_opt"
1162}
1163
1164_git_archive ()
1165{
1166 case "$cur" in
1167 --format=*)
1168 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1169 return
1170 ;;
1171 --remote=*)
1172 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1173 return
1174 ;;
1175 --*)
1176 __gitcomp "
1177 --format= --list --verbose
1178 --prefix= --remote= --exec= --output
1179 "
1180 return
1181 ;;
1182 esac
1183 __git_complete_file
1184}
1185
1186_git_bisect ()
1187{
1188 __git_has_doubledash && return
1189
1190 local subcommands="start bad good skip reset visualize replay log run"
1191 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1192 if [ -z "$subcommand" ]; then
1193 __git_find_repo_path
1194 if [ -f "$__git_repo_path"/BISECT_START ]; then
1195 __gitcomp "$subcommands"
1196 else
1197 __gitcomp "replay start"
1198 fi
1199 return
1200 fi
1201
1202 case "$subcommand" in
1203 bad|good|reset|skip|start)
1204 __git_complete_refs
1205 ;;
1206 *)
1207 ;;
1208 esac
1209}
1210
1211_git_branch ()
1212{
1213 local i c=1 only_local_ref="n" has_r="n"
1214
1215 while [ $c -lt $cword ]; do
1216 i="${words[c]}"
1217 case "$i" in
1218 -d|--delete|-m|--move) only_local_ref="y" ;;
1219 -r|--remotes) has_r="y" ;;
1220 esac
1221 ((c++))
1222 done
1223
1224 case "$cur" in
1225 --set-upstream-to=*)
1226 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1227 ;;
1228 --*)
1229 __gitcomp_builtin branch "--no-color --no-abbrev
1230 --no-track --no-column
1231 "
1232 ;;
1233 *)
1234 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1235 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1236 else
1237 __git_complete_refs
1238 fi
1239 ;;
1240 esac
1241}
1242
1243_git_bundle ()
1244{
1245 local cmd="${words[2]}"
1246 case "$cword" in
1247 2)
1248 __gitcomp "create list-heads verify unbundle"
1249 ;;
1250 3)
1251 # looking for a file
1252 ;;
1253 *)
1254 case "$cmd" in
1255 create)
1256 __git_complete_revlist
1257 ;;
1258 esac
1259 ;;
1260 esac
1261}
1262
1263_git_checkout ()
1264{
1265 __git_has_doubledash && return
1266
1267 case "$cur" in
1268 --conflict=*)
1269 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1270 ;;
1271 --*)
1272 __gitcomp_builtin checkout "--no-track --no-recurse-submodules"
1273 ;;
1274 *)
1275 # check if --track, --no-track, or --no-guess was specified
1276 # if so, disable DWIM mode
1277 local flags="--track --no-track --no-guess" track_opt="--track"
1278 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1279 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1280 track_opt=''
1281 fi
1282 __git_complete_refs $track_opt
1283 ;;
1284 esac
1285}
1286
1287_git_cherry ()
1288{
1289 case "$cur" in
1290 --*)
1291 __gitcomp_builtin cherry
1292 return
1293 esac
1294
1295 __git_complete_refs
1296}
1297
1298__git_cherry_pick_inprogress_options="--continue --quit --abort"
1299
1300_git_cherry_pick ()
1301{
1302 __git_find_repo_path
1303 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1304 __gitcomp "$__git_cherry_pick_inprogress_options"
1305 return
1306 fi
1307 case "$cur" in
1308 --*)
1309 __gitcomp_builtin cherry-pick "" \
1310 "$__git_cherry_pick_inprogress_options"
1311 ;;
1312 *)
1313 __git_complete_refs
1314 ;;
1315 esac
1316}
1317
1318_git_clean ()
1319{
1320 case "$cur" in
1321 --*)
1322 __gitcomp_builtin clean
1323 return
1324 ;;
1325 esac
1326
1327 # XXX should we check for -x option ?
1328 __git_complete_index_file "--others --directory"
1329}
1330
1331_git_clone ()
1332{
1333 case "$cur" in
1334 --*)
1335 __gitcomp_builtin clone "--no-single-branch"
1336 return
1337 ;;
1338 esac
1339}
1340
1341__git_untracked_file_modes="all no normal"
1342
1343_git_commit ()
1344{
1345 case "$prev" in
1346 -c|-C)
1347 __git_complete_refs
1348 return
1349 ;;
1350 esac
1351
1352 case "$cur" in
1353 --cleanup=*)
1354 __gitcomp "default scissors strip verbatim whitespace
1355 " "" "${cur##--cleanup=}"
1356 return
1357 ;;
1358 --reuse-message=*|--reedit-message=*|\
1359 --fixup=*|--squash=*)
1360 __git_complete_refs --cur="${cur#*=}"
1361 return
1362 ;;
1363 --untracked-files=*)
1364 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1365 return
1366 ;;
1367 --*)
1368 __gitcomp_builtin commit "--no-edit --verify"
1369 return
1370 esac
1371
1372 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1373 __git_complete_index_file "--committable"
1374 else
1375 # This is the first commit
1376 __git_complete_index_file "--cached"
1377 fi
1378}
1379
1380_git_describe ()
1381{
1382 case "$cur" in
1383 --*)
1384 __gitcomp_builtin describe
1385 return
1386 esac
1387 __git_complete_refs
1388}
1389
1390__git_diff_algorithms="myers minimal patience histogram"
1391
1392__git_diff_submodule_formats="diff log short"
1393
1394__git_diff_common_options="--stat --numstat --shortstat --summary
1395 --patch-with-stat --name-only --name-status --color
1396 --no-color --color-words --no-renames --check
1397 --full-index --binary --abbrev --diff-filter=
1398 --find-copies-harder --ignore-cr-at-eol
1399 --text --ignore-space-at-eol --ignore-space-change
1400 --ignore-all-space --ignore-blank-lines --exit-code
1401 --quiet --ext-diff --no-ext-diff
1402 --no-prefix --src-prefix= --dst-prefix=
1403 --inter-hunk-context=
1404 --patience --histogram --minimal
1405 --raw --word-diff --word-diff-regex=
1406 --dirstat --dirstat= --dirstat-by-file
1407 --dirstat-by-file= --cumulative
1408 --diff-algorithm=
1409 --submodule --submodule= --ignore-submodules
1410"
1411
1412_git_diff ()
1413{
1414 __git_has_doubledash && return
1415
1416 case "$cur" in
1417 --diff-algorithm=*)
1418 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1419 return
1420 ;;
1421 --submodule=*)
1422 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1423 return
1424 ;;
1425 --*)
1426 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1427 --base --ours --theirs --no-index
1428 $__git_diff_common_options
1429 "
1430 return
1431 ;;
1432 esac
1433 __git_complete_revlist_file
1434}
1435
1436__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1437 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1438"
1439
1440_git_difftool ()
1441{
1442 __git_has_doubledash && return
1443
1444 case "$cur" in
1445 --tool=*)
1446 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1447 return
1448 ;;
1449 --*)
1450 __gitcomp_builtin difftool "$__git_diff_common_options
1451 --base --cached --ours --theirs
1452 --pickaxe-all --pickaxe-regex
1453 --relative --staged
1454 "
1455 return
1456 ;;
1457 esac
1458 __git_complete_revlist_file
1459}
1460
1461__git_fetch_recurse_submodules="yes on-demand no"
1462
1463_git_fetch ()
1464{
1465 case "$cur" in
1466 --recurse-submodules=*)
1467 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1468 return
1469 ;;
1470 --*)
1471 __gitcomp_builtin fetch "--no-tags"
1472 return
1473 ;;
1474 esac
1475 __git_complete_remote_or_refspec
1476}
1477
1478__git_format_patch_options="
1479 --stdout --attach --no-attach --thread --thread= --no-thread
1480 --numbered --start-number --numbered-files --keep-subject --signoff
1481 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1482 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1483 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1484 --output-directory --reroll-count --to= --quiet --notes
1485"
1486
1487_git_format_patch ()
1488{
1489 case "$cur" in
1490 --thread=*)
1491 __gitcomp "
1492 deep shallow
1493 " "" "${cur##--thread=}"
1494 return
1495 ;;
1496 --*)
1497 __gitcomp "$__git_format_patch_options"
1498 return
1499 ;;
1500 esac
1501 __git_complete_revlist
1502}
1503
1504_git_fsck ()
1505{
1506 case "$cur" in
1507 --*)
1508 __gitcomp_builtin fsck "--no-reflogs"
1509 return
1510 ;;
1511 esac
1512}
1513
1514_git_gitk ()
1515{
1516 _gitk
1517}
1518
1519# Lists matching symbol names from a tag (as in ctags) file.
1520# 1: List symbol names matching this word.
1521# 2: The tag file to list symbol names from.
1522# 3: A prefix to be added to each listed symbol name (optional).
1523# 4: A suffix to be appended to each listed symbol name (optional).
1524__git_match_ctag () {
1525 awk -v pfx="${3-}" -v sfx="${4-}" "
1526 /^${1//\//\\/}/ { print pfx \$1 sfx }
1527 " "$2"
1528}
1529
1530# Complete symbol names from a tag file.
1531# Usage: __git_complete_symbol [<option>]...
1532# --tags=<file>: The tag file to list symbol names from instead of the
1533# default "tags".
1534# --pfx=<prefix>: A prefix to be added to each symbol name.
1535# --cur=<word>: The current symbol name to be completed. Defaults to
1536# the current word to be completed.
1537# --sfx=<suffix>: A suffix to be appended to each symbol name instead
1538# of the default space.
1539__git_complete_symbol () {
1540 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1541
1542 while test $# != 0; do
1543 case "$1" in
1544 --tags=*) tags="${1##--tags=}" ;;
1545 --pfx=*) pfx="${1##--pfx=}" ;;
1546 --cur=*) cur_="${1##--cur=}" ;;
1547 --sfx=*) sfx="${1##--sfx=}" ;;
1548 *) return 1 ;;
1549 esac
1550 shift
1551 done
1552
1553 if test -r "$tags"; then
1554 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1555 fi
1556}
1557
1558_git_grep ()
1559{
1560 __git_has_doubledash && return
1561
1562 case "$cur" in
1563 --*)
1564 __gitcomp_builtin grep
1565 return
1566 ;;
1567 esac
1568
1569 case "$cword,$prev" in
1570 2,*|*,-*)
1571 __git_complete_symbol && return
1572 ;;
1573 esac
1574
1575 __git_complete_refs
1576}
1577
1578__git_all_guides=
1579__git_compute_all_guides ()
1580{
1581 test -n "$__git_all_guides" ||
1582 __git_all_guides=$(git --list-cmds=list-guide)
1583}
1584
1585_git_help ()
1586{
1587 case "$cur" in
1588 --*)
1589 __gitcomp_builtin help
1590 return
1591 ;;
1592 esac
1593 __git_compute_all_commands
1594 __git_compute_all_guides
1595 __gitcomp "$__git_all_commands $(__git_aliases) $__git_all_guides
1596 gitk
1597 "
1598}
1599
1600_git_init ()
1601{
1602 case "$cur" in
1603 --shared=*)
1604 __gitcomp "
1605 false true umask group all world everybody
1606 " "" "${cur##--shared=}"
1607 return
1608 ;;
1609 --*)
1610 __gitcomp_builtin init
1611 return
1612 ;;
1613 esac
1614}
1615
1616_git_ls_files ()
1617{
1618 case "$cur" in
1619 --*)
1620 __gitcomp_builtin ls-files "--no-empty-directory"
1621 return
1622 ;;
1623 esac
1624
1625 # XXX ignore options like --modified and always suggest all cached
1626 # files.
1627 __git_complete_index_file "--cached"
1628}
1629
1630_git_ls_remote ()
1631{
1632 case "$cur" in
1633 --*)
1634 __gitcomp_builtin ls-remote
1635 return
1636 ;;
1637 esac
1638 __gitcomp_nl "$(__git_remotes)"
1639}
1640
1641_git_ls_tree ()
1642{
1643 case "$cur" in
1644 --*)
1645 __gitcomp_builtin ls-tree
1646 return
1647 ;;
1648 esac
1649
1650 __git_complete_file
1651}
1652
1653# Options that go well for log, shortlog and gitk
1654__git_log_common_options="
1655 --not --all
1656 --branches --tags --remotes
1657 --first-parent --merges --no-merges
1658 --max-count=
1659 --max-age= --since= --after=
1660 --min-age= --until= --before=
1661 --min-parents= --max-parents=
1662 --no-min-parents --no-max-parents
1663"
1664# Options that go well for log and gitk (not shortlog)
1665__git_log_gitk_options="
1666 --dense --sparse --full-history
1667 --simplify-merges --simplify-by-decoration
1668 --left-right --notes --no-notes
1669"
1670# Options that go well for log and shortlog (not gitk)
1671__git_log_shortlog_options="
1672 --author= --committer= --grep=
1673 --all-match --invert-grep
1674"
1675
1676__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1677__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1678
1679_git_log ()
1680{
1681 __git_has_doubledash && return
1682 __git_find_repo_path
1683
1684 local merge=""
1685 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1686 merge="--merge"
1687 fi
1688 case "$prev,$cur" in
1689 -L,:*:*)
1690 return # fall back to Bash filename completion
1691 ;;
1692 -L,:*)
1693 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1694 return
1695 ;;
1696 -G,*|-S,*)
1697 __git_complete_symbol
1698 return
1699 ;;
1700 esac
1701 case "$cur" in
1702 --pretty=*|--format=*)
1703 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1704 " "" "${cur#*=}"
1705 return
1706 ;;
1707 --date=*)
1708 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1709 return
1710 ;;
1711 --decorate=*)
1712 __gitcomp "full short no" "" "${cur##--decorate=}"
1713 return
1714 ;;
1715 --diff-algorithm=*)
1716 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1717 return
1718 ;;
1719 --submodule=*)
1720 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1721 return
1722 ;;
1723 --*)
1724 __gitcomp "
1725 $__git_log_common_options
1726 $__git_log_shortlog_options
1727 $__git_log_gitk_options
1728 --root --topo-order --date-order --reverse
1729 --follow --full-diff
1730 --abbrev-commit --abbrev=
1731 --relative-date --date=
1732 --pretty= --format= --oneline
1733 --show-signature
1734 --cherry-mark
1735 --cherry-pick
1736 --graph
1737 --decorate --decorate=
1738 --walk-reflogs
1739 --parents --children
1740 $merge
1741 $__git_diff_common_options
1742 --pickaxe-all --pickaxe-regex
1743 "
1744 return
1745 ;;
1746 -L:*:*)
1747 return # fall back to Bash filename completion
1748 ;;
1749 -L:*)
1750 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1751 return
1752 ;;
1753 -G*)
1754 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1755 return
1756 ;;
1757 -S*)
1758 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1759 return
1760 ;;
1761 esac
1762 __git_complete_revlist
1763}
1764
1765_git_merge ()
1766{
1767 __git_complete_strategy && return
1768
1769 case "$cur" in
1770 --*)
1771 __gitcomp_builtin merge "--no-rerere-autoupdate
1772 --no-commit --no-edit --no-ff
1773 --no-log --no-progress
1774 --no-squash --no-stat
1775 --no-verify-signatures
1776 "
1777 return
1778 esac
1779 __git_complete_refs
1780}
1781
1782_git_mergetool ()
1783{
1784 case "$cur" in
1785 --tool=*)
1786 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1787 return
1788 ;;
1789 --*)
1790 __gitcomp "--tool= --prompt --no-prompt"
1791 return
1792 ;;
1793 esac
1794}
1795
1796_git_merge_base ()
1797{
1798 case "$cur" in
1799 --*)
1800 __gitcomp_builtin merge-base
1801 return
1802 ;;
1803 esac
1804 __git_complete_refs
1805}
1806
1807_git_mv ()
1808{
1809 case "$cur" in
1810 --*)
1811 __gitcomp_builtin mv
1812 return
1813 ;;
1814 esac
1815
1816 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1817 # We need to show both cached and untracked files (including
1818 # empty directories) since this may not be the last argument.
1819 __git_complete_index_file "--cached --others --directory"
1820 else
1821 __git_complete_index_file "--cached"
1822 fi
1823}
1824
1825_git_notes ()
1826{
1827 local subcommands='add append copy edit get-ref list merge prune remove show'
1828 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1829
1830 case "$subcommand,$cur" in
1831 ,--*)
1832 __gitcomp_builtin notes
1833 ;;
1834 ,*)
1835 case "$prev" in
1836 --ref)
1837 __git_complete_refs
1838 ;;
1839 *)
1840 __gitcomp "$subcommands --ref"
1841 ;;
1842 esac
1843 ;;
1844 *,--reuse-message=*|*,--reedit-message=*)
1845 __git_complete_refs --cur="${cur#*=}"
1846 ;;
1847 *,--*)
1848 __gitcomp_builtin notes_$subcommand
1849 ;;
1850 prune,*|get-ref,*)
1851 # this command does not take a ref, do not complete it
1852 ;;
1853 *)
1854 case "$prev" in
1855 -m|-F)
1856 ;;
1857 *)
1858 __git_complete_refs
1859 ;;
1860 esac
1861 ;;
1862 esac
1863}
1864
1865_git_pull ()
1866{
1867 __git_complete_strategy && return
1868
1869 case "$cur" in
1870 --recurse-submodules=*)
1871 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1872 return
1873 ;;
1874 --*)
1875 __gitcomp_builtin pull "--no-autostash --no-commit --no-edit
1876 --no-ff --no-log --no-progress --no-rebase
1877 --no-squash --no-stat --no-tags
1878 --no-verify-signatures"
1879
1880 return
1881 ;;
1882 esac
1883 __git_complete_remote_or_refspec
1884}
1885
1886__git_push_recurse_submodules="check on-demand only"
1887
1888__git_complete_force_with_lease ()
1889{
1890 local cur_=$1
1891
1892 case "$cur_" in
1893 --*=)
1894 ;;
1895 *:*)
1896 __git_complete_refs --cur="${cur_#*:}"
1897 ;;
1898 *)
1899 __git_complete_refs --cur="$cur_"
1900 ;;
1901 esac
1902}
1903
1904_git_push ()
1905{
1906 case "$prev" in
1907 --repo)
1908 __gitcomp_nl "$(__git_remotes)"
1909 return
1910 ;;
1911 --recurse-submodules)
1912 __gitcomp "$__git_push_recurse_submodules"
1913 return
1914 ;;
1915 esac
1916 case "$cur" in
1917 --repo=*)
1918 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1919 return
1920 ;;
1921 --recurse-submodules=*)
1922 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1923 return
1924 ;;
1925 --force-with-lease=*)
1926 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1927 return
1928 ;;
1929 --*)
1930 __gitcomp_builtin push
1931 return
1932 ;;
1933 esac
1934 __git_complete_remote_or_refspec
1935}
1936
1937_git_rebase ()
1938{
1939 __git_find_repo_path
1940 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1941 __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
1942 return
1943 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1944 [ -d "$__git_repo_path"/rebase-merge ]; then
1945 __gitcomp "--continue --skip --abort --quit --show-current-patch"
1946 return
1947 fi
1948 __git_complete_strategy && return
1949 case "$cur" in
1950 --whitespace=*)
1951 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1952 return
1953 ;;
1954 --*)
1955 __gitcomp "
1956 --onto --merge --strategy --interactive
1957 --preserve-merges --stat --no-stat
1958 --committer-date-is-author-date --ignore-date
1959 --ignore-whitespace --whitespace=
1960 --autosquash --no-autosquash
1961 --fork-point --no-fork-point
1962 --autostash --no-autostash
1963 --verify --no-verify
1964 --keep-empty --root --force-rebase --no-ff
1965 --rerere-autoupdate
1966 --exec
1967 "
1968
1969 return
1970 esac
1971 __git_complete_refs
1972}
1973
1974_git_reflog ()
1975{
1976 local subcommands="show delete expire"
1977 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1978
1979 if [ -z "$subcommand" ]; then
1980 __gitcomp "$subcommands"
1981 else
1982 __git_complete_refs
1983 fi
1984}
1985
1986__git_send_email_confirm_options="always never auto cc compose"
1987__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1988
1989_git_send_email ()
1990{
1991 case "$prev" in
1992 --to|--cc|--bcc|--from)
1993 __gitcomp "$(__git send-email --dump-aliases)"
1994 return
1995 ;;
1996 esac
1997
1998 case "$cur" in
1999 --confirm=*)
2000 __gitcomp "
2001 $__git_send_email_confirm_options
2002 " "" "${cur##--confirm=}"
2003 return
2004 ;;
2005 --suppress-cc=*)
2006 __gitcomp "
2007 $__git_send_email_suppresscc_options
2008 " "" "${cur##--suppress-cc=}"
2009
2010 return
2011 ;;
2012 --smtp-encryption=*)
2013 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2014 return
2015 ;;
2016 --thread=*)
2017 __gitcomp "
2018 deep shallow
2019 " "" "${cur##--thread=}"
2020 return
2021 ;;
2022 --to=*|--cc=*|--bcc=*|--from=*)
2023 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2024 return
2025 ;;
2026 --*)
2027 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2028 --compose --confirm= --dry-run --envelope-sender
2029 --from --identity
2030 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2031 --no-suppress-from --no-thread --quiet --reply-to
2032 --signed-off-by-cc --smtp-pass --smtp-server
2033 --smtp-server-port --smtp-encryption= --smtp-user
2034 --subject --suppress-cc= --suppress-from --thread --to
2035 --validate --no-validate
2036 $__git_format_patch_options"
2037 return
2038 ;;
2039 esac
2040 __git_complete_revlist
2041}
2042
2043_git_stage ()
2044{
2045 _git_add
2046}
2047
2048_git_status ()
2049{
2050 local complete_opt
2051 local untracked_state
2052
2053 case "$cur" in
2054 --ignore-submodules=*)
2055 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2056 return
2057 ;;
2058 --untracked-files=*)
2059 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2060 return
2061 ;;
2062 --column=*)
2063 __gitcomp "
2064 always never auto column row plain dense nodense
2065 " "" "${cur##--column=}"
2066 return
2067 ;;
2068 --*)
2069 __gitcomp_builtin status "--no-column"
2070 return
2071 ;;
2072 esac
2073
2074 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2075 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2076
2077 case "$untracked_state" in
2078 no)
2079 # --ignored option does not matter
2080 complete_opt=
2081 ;;
2082 all|normal|*)
2083 complete_opt="--cached --directory --no-empty-directory --others"
2084
2085 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2086 complete_opt="$complete_opt --ignored --exclude=*"
2087 fi
2088 ;;
2089 esac
2090
2091 __git_complete_index_file "$complete_opt"
2092}
2093
2094__git_config_get_set_variables ()
2095{
2096 local prevword word config_file= c=$cword
2097 while [ $c -gt 1 ]; do
2098 word="${words[c]}"
2099 case "$word" in
2100 --system|--global|--local|--file=*)
2101 config_file="$word"
2102 break
2103 ;;
2104 -f|--file)
2105 config_file="$word $prevword"
2106 break
2107 ;;
2108 esac
2109 prevword=$word
2110 c=$((--c))
2111 done
2112
2113 __git config $config_file --name-only --list
2114}
2115
2116_git_config ()
2117{
2118 case "$prev" in
2119 branch.*.remote|branch.*.pushremote)
2120 __gitcomp_nl "$(__git_remotes)"
2121 return
2122 ;;
2123 branch.*.merge)
2124 __git_complete_refs
2125 return
2126 ;;
2127 branch.*.rebase)
2128 __gitcomp "false true preserve interactive"
2129 return
2130 ;;
2131 remote.pushdefault)
2132 __gitcomp_nl "$(__git_remotes)"
2133 return
2134 ;;
2135 remote.*.fetch)
2136 local remote="${prev#remote.}"
2137 remote="${remote%.fetch}"
2138 if [ -z "$cur" ]; then
2139 __gitcomp_nl "refs/heads/" "" "" ""
2140 return
2141 fi
2142 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2143 return
2144 ;;
2145 remote.*.push)
2146 local remote="${prev#remote.}"
2147 remote="${remote%.push}"
2148 __gitcomp_nl "$(__git for-each-ref \
2149 --format='%(refname):%(refname)' refs/heads)"
2150 return
2151 ;;
2152 pull.twohead|pull.octopus)
2153 __git_compute_merge_strategies
2154 __gitcomp "$__git_merge_strategies"
2155 return
2156 ;;
2157 color.branch|color.diff|color.interactive|\
2158 color.showbranch|color.status|color.ui)
2159 __gitcomp "always never auto"
2160 return
2161 ;;
2162 color.pager)
2163 __gitcomp "false true"
2164 return
2165 ;;
2166 color.*.*)
2167 __gitcomp "
2168 normal black red green yellow blue magenta cyan white
2169 bold dim ul blink reverse
2170 "
2171 return
2172 ;;
2173 diff.submodule)
2174 __gitcomp "log short"
2175 return
2176 ;;
2177 help.format)
2178 __gitcomp "man info web html"
2179 return
2180 ;;
2181 log.date)
2182 __gitcomp "$__git_log_date_formats"
2183 return
2184 ;;
2185 sendemail.aliasesfiletype)
2186 __gitcomp "mutt mailrc pine elm gnus"
2187 return
2188 ;;
2189 sendemail.confirm)
2190 __gitcomp "$__git_send_email_confirm_options"
2191 return
2192 ;;
2193 sendemail.suppresscc)
2194 __gitcomp "$__git_send_email_suppresscc_options"
2195 return
2196 ;;
2197 sendemail.transferencoding)
2198 __gitcomp "7bit 8bit quoted-printable base64"
2199 return
2200 ;;
2201 --get|--get-all|--unset|--unset-all)
2202 __gitcomp_nl "$(__git_config_get_set_variables)"
2203 return
2204 ;;
2205 *.*)
2206 return
2207 ;;
2208 esac
2209 case "$cur" in
2210 --*)
2211 __gitcomp_builtin config
2212 return
2213 ;;
2214 branch.*.*)
2215 local pfx="${cur%.*}." cur_="${cur##*.}"
2216 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2217 return
2218 ;;
2219 branch.*)
2220 local pfx="${cur%.*}." cur_="${cur#*.}"
2221 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2222 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2223 return
2224 ;;
2225 guitool.*.*)
2226 local pfx="${cur%.*}." cur_="${cur##*.}"
2227 __gitcomp "
2228 argprompt cmd confirm needsfile noconsole norescan
2229 prompt revprompt revunmerged title
2230 " "$pfx" "$cur_"
2231 return
2232 ;;
2233 difftool.*.*)
2234 local pfx="${cur%.*}." cur_="${cur##*.}"
2235 __gitcomp "cmd path" "$pfx" "$cur_"
2236 return
2237 ;;
2238 man.*.*)
2239 local pfx="${cur%.*}." cur_="${cur##*.}"
2240 __gitcomp "cmd path" "$pfx" "$cur_"
2241 return
2242 ;;
2243 mergetool.*.*)
2244 local pfx="${cur%.*}." cur_="${cur##*.}"
2245 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2246 return
2247 ;;
2248 pager.*)
2249 local pfx="${cur%.*}." cur_="${cur#*.}"
2250 __git_compute_all_commands
2251 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2252 return
2253 ;;
2254 remote.*.*)
2255 local pfx="${cur%.*}." cur_="${cur##*.}"
2256 __gitcomp "
2257 url proxy fetch push mirror skipDefaultUpdate
2258 receivepack uploadpack tagopt pushurl
2259 " "$pfx" "$cur_"
2260 return
2261 ;;
2262 remote.*)
2263 local pfx="${cur%.*}." cur_="${cur#*.}"
2264 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2265 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2266 return
2267 ;;
2268 url.*.*)
2269 local pfx="${cur%.*}." cur_="${cur##*.}"
2270 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2271 return
2272 ;;
2273 esac
2274 __gitcomp "
2275 add.ignoreErrors
2276 advice.amWorkDir
2277 advice.commitBeforeMerge
2278 advice.detachedHead
2279 advice.implicitIdentity
2280 advice.pushAlreadyExists
2281 advice.pushFetchFirst
2282 advice.pushNeedsForce
2283 advice.pushNonFFCurrent
2284 advice.pushNonFFMatching
2285 advice.pushUpdateRejected
2286 advice.resolveConflict
2287 advice.rmHints
2288 advice.statusHints
2289 advice.statusUoption
2290 advice.ignoredHook
2291 alias.
2292 am.keepcr
2293 am.threeWay
2294 apply.ignorewhitespace
2295 apply.whitespace
2296 branch.autosetupmerge
2297 branch.autosetuprebase
2298 browser.
2299 clean.requireForce
2300 color.branch
2301 color.branch.current
2302 color.branch.local
2303 color.branch.plain
2304 color.branch.remote
2305 color.decorate.HEAD
2306 color.decorate.branch
2307 color.decorate.remoteBranch
2308 color.decorate.stash
2309 color.decorate.tag
2310 color.diff
2311 color.diff.commit
2312 color.diff.frag
2313 color.diff.func
2314 color.diff.meta
2315 color.diff.new
2316 color.diff.old
2317 color.diff.plain
2318 color.diff.whitespace
2319 color.grep
2320 color.grep.context
2321 color.grep.filename
2322 color.grep.function
2323 color.grep.linenumber
2324 color.grep.match
2325 color.grep.selected
2326 color.grep.separator
2327 color.interactive
2328 color.interactive.error
2329 color.interactive.header
2330 color.interactive.help
2331 color.interactive.prompt
2332 color.pager
2333 color.showbranch
2334 color.status
2335 color.status.added
2336 color.status.changed
2337 color.status.header
2338 color.status.localBranch
2339 color.status.nobranch
2340 color.status.remoteBranch
2341 color.status.unmerged
2342 color.status.untracked
2343 color.status.updated
2344 color.ui
2345 commit.cleanup
2346 commit.gpgSign
2347 commit.status
2348 commit.template
2349 commit.verbose
2350 core.abbrev
2351 core.askpass
2352 core.attributesfile
2353 core.autocrlf
2354 core.bare
2355 core.bigFileThreshold
2356 core.checkStat
2357 core.commentChar
2358 core.compression
2359 core.createObject
2360 core.deltaBaseCacheLimit
2361 core.editor
2362 core.eol
2363 core.excludesfile
2364 core.fileMode
2365 core.fsyncobjectfiles
2366 core.gitProxy
2367 core.hideDotFiles
2368 core.hooksPath
2369 core.ignoreStat
2370 core.ignorecase
2371 core.logAllRefUpdates
2372 core.loosecompression
2373 core.notesRef
2374 core.packedGitLimit
2375 core.packedGitWindowSize
2376 core.packedRefsTimeout
2377 core.pager
2378 core.precomposeUnicode
2379 core.preferSymlinkRefs
2380 core.preloadindex
2381 core.protectHFS
2382 core.protectNTFS
2383 core.quotepath
2384 core.repositoryFormatVersion
2385 core.safecrlf
2386 core.sharedRepository
2387 core.sparseCheckout
2388 core.splitIndex
2389 core.sshCommand
2390 core.symlinks
2391 core.trustctime
2392 core.untrackedCache
2393 core.warnAmbiguousRefs
2394 core.whitespace
2395 core.worktree
2396 credential.helper
2397 credential.useHttpPath
2398 credential.username
2399 credentialCache.ignoreSIGHUP
2400 diff.autorefreshindex
2401 diff.external
2402 diff.ignoreSubmodules
2403 diff.mnemonicprefix
2404 diff.noprefix
2405 diff.renameLimit
2406 diff.renames
2407 diff.statGraphWidth
2408 diff.submodule
2409 diff.suppressBlankEmpty
2410 diff.tool
2411 diff.wordRegex
2412 diff.algorithm
2413 difftool.
2414 difftool.prompt
2415 fetch.recurseSubmodules
2416 fetch.unpackLimit
2417 format.attach
2418 format.cc
2419 format.coverLetter
2420 format.from
2421 format.headers
2422 format.numbered
2423 format.pretty
2424 format.signature
2425 format.signoff
2426 format.subjectprefix
2427 format.suffix
2428 format.thread
2429 format.to
2430 gc.
2431 gc.aggressiveDepth
2432 gc.aggressiveWindow
2433 gc.auto
2434 gc.autoDetach
2435 gc.autopacklimit
2436 gc.logExpiry
2437 gc.packrefs
2438 gc.pruneexpire
2439 gc.reflogexpire
2440 gc.reflogexpireunreachable
2441 gc.rerereresolved
2442 gc.rerereunresolved
2443 gc.worktreePruneExpire
2444 gitcvs.allbinary
2445 gitcvs.commitmsgannotation
2446 gitcvs.dbTableNamePrefix
2447 gitcvs.dbdriver
2448 gitcvs.dbname
2449 gitcvs.dbpass
2450 gitcvs.dbuser
2451 gitcvs.enabled
2452 gitcvs.logfile
2453 gitcvs.usecrlfattr
2454 guitool.
2455 gui.blamehistoryctx
2456 gui.commitmsgwidth
2457 gui.copyblamethreshold
2458 gui.diffcontext
2459 gui.encoding
2460 gui.fastcopyblame
2461 gui.matchtrackingbranch
2462 gui.newbranchtemplate
2463 gui.pruneduringfetch
2464 gui.spellingdictionary
2465 gui.trustmtime
2466 help.autocorrect
2467 help.browser
2468 help.format
2469 http.lowSpeedLimit
2470 http.lowSpeedTime
2471 http.maxRequests
2472 http.minSessions
2473 http.noEPSV
2474 http.postBuffer
2475 http.proxy
2476 http.sslCipherList
2477 http.sslVersion
2478 http.sslCAInfo
2479 http.sslCAPath
2480 http.sslCert
2481 http.sslCertPasswordProtected
2482 http.sslKey
2483 http.sslVerify
2484 http.useragent
2485 i18n.commitEncoding
2486 i18n.logOutputEncoding
2487 imap.authMethod
2488 imap.folder
2489 imap.host
2490 imap.pass
2491 imap.port
2492 imap.preformattedHTML
2493 imap.sslverify
2494 imap.tunnel
2495 imap.user
2496 init.templatedir
2497 instaweb.browser
2498 instaweb.httpd
2499 instaweb.local
2500 instaweb.modulepath
2501 instaweb.port
2502 interactive.singlekey
2503 log.date
2504 log.decorate
2505 log.showroot
2506 mailmap.file
2507 man.
2508 man.viewer
2509 merge.
2510 merge.conflictstyle
2511 merge.log
2512 merge.renameLimit
2513 merge.renormalize
2514 merge.stat
2515 merge.tool
2516 merge.verbosity
2517 mergetool.
2518 mergetool.keepBackup
2519 mergetool.keepTemporaries
2520 mergetool.prompt
2521 notes.displayRef
2522 notes.rewrite.
2523 notes.rewrite.amend
2524 notes.rewrite.rebase
2525 notes.rewriteMode
2526 notes.rewriteRef
2527 pack.compression
2528 pack.deltaCacheLimit
2529 pack.deltaCacheSize
2530 pack.depth
2531 pack.indexVersion
2532 pack.packSizeLimit
2533 pack.threads
2534 pack.window
2535 pack.windowMemory
2536 pager.
2537 pretty.
2538 pull.octopus
2539 pull.twohead
2540 push.default
2541 push.followTags
2542 rebase.autosquash
2543 rebase.stat
2544 receive.autogc
2545 receive.denyCurrentBranch
2546 receive.denyDeleteCurrent
2547 receive.denyDeletes
2548 receive.denyNonFastForwards
2549 receive.fsckObjects
2550 receive.unpackLimit
2551 receive.updateserverinfo
2552 remote.pushdefault
2553 remotes.
2554 repack.usedeltabaseoffset
2555 rerere.autoupdate
2556 rerere.enabled
2557 sendemail.
2558 sendemail.aliasesfile
2559 sendemail.aliasfiletype
2560 sendemail.bcc
2561 sendemail.cc
2562 sendemail.cccmd
2563 sendemail.chainreplyto
2564 sendemail.confirm
2565 sendemail.envelopesender
2566 sendemail.from
2567 sendemail.identity
2568 sendemail.multiedit
2569 sendemail.signedoffbycc
2570 sendemail.smtpdomain
2571 sendemail.smtpencryption
2572 sendemail.smtppass
2573 sendemail.smtpserver
2574 sendemail.smtpserveroption
2575 sendemail.smtpserverport
2576 sendemail.smtpuser
2577 sendemail.suppresscc
2578 sendemail.suppressfrom
2579 sendemail.thread
2580 sendemail.to
2581 sendemail.tocmd
2582 sendemail.validate
2583 sendemail.smtpbatchsize
2584 sendemail.smtprelogindelay
2585 showbranch.default
2586 status.relativePaths
2587 status.showUntrackedFiles
2588 status.submodulesummary
2589 submodule.
2590 tar.umask
2591 transfer.unpackLimit
2592 url.
2593 user.email
2594 user.name
2595 user.signingkey
2596 web.browser
2597 branch. remote.
2598 "
2599}
2600
2601_git_remote ()
2602{
2603 local subcommands="
2604 add rename remove set-head set-branches
2605 get-url set-url show prune update
2606 "
2607 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2608 if [ -z "$subcommand" ]; then
2609 case "$cur" in
2610 --*)
2611 __gitcomp_builtin remote
2612 ;;
2613 *)
2614 __gitcomp "$subcommands"
2615 ;;
2616 esac
2617 return
2618 fi
2619
2620 case "$subcommand,$cur" in
2621 add,--*)
2622 __gitcomp_builtin remote_add "--no-tags"
2623 ;;
2624 add,*)
2625 ;;
2626 set-head,--*)
2627 __gitcomp_builtin remote_set-head
2628 ;;
2629 set-branches,--*)
2630 __gitcomp_builtin remote_set-branches
2631 ;;
2632 set-head,*|set-branches,*)
2633 __git_complete_remote_or_refspec
2634 ;;
2635 update,--*)
2636 __gitcomp_builtin remote_update
2637 ;;
2638 update,*)
2639 __gitcomp "$(__git_get_config_variables "remotes")"
2640 ;;
2641 set-url,--*)
2642 __gitcomp_builtin remote_set-url
2643 ;;
2644 get-url,--*)
2645 __gitcomp_builtin remote_get-url
2646 ;;
2647 prune,--*)
2648 __gitcomp_builtin remote_prune
2649 ;;
2650 *)
2651 __gitcomp_nl "$(__git_remotes)"
2652 ;;
2653 esac
2654}
2655
2656_git_replace ()
2657{
2658 case "$cur" in
2659 --*)
2660 __gitcomp_builtin replace
2661 return
2662 ;;
2663 esac
2664 __git_complete_refs
2665}
2666
2667_git_rerere ()
2668{
2669 local subcommands="clear forget diff remaining status gc"
2670 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2671 if test -z "$subcommand"
2672 then
2673 __gitcomp "$subcommands"
2674 return
2675 fi
2676}
2677
2678_git_reset ()
2679{
2680 __git_has_doubledash && return
2681
2682 case "$cur" in
2683 --*)
2684 __gitcomp_builtin reset
2685 return
2686 ;;
2687 esac
2688 __git_complete_refs
2689}
2690
2691__git_revert_inprogress_options="--continue --quit --abort"
2692
2693_git_revert ()
2694{
2695 __git_find_repo_path
2696 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2697 __gitcomp "$__git_revert_inprogress_options"
2698 return
2699 fi
2700 case "$cur" in
2701 --*)
2702 __gitcomp_builtin revert "--no-edit" \
2703 "$__git_revert_inprogress_options"
2704 return
2705 ;;
2706 esac
2707 __git_complete_refs
2708}
2709
2710_git_rm ()
2711{
2712 case "$cur" in
2713 --*)
2714 __gitcomp_builtin rm
2715 return
2716 ;;
2717 esac
2718
2719 __git_complete_index_file "--cached"
2720}
2721
2722_git_shortlog ()
2723{
2724 __git_has_doubledash && return
2725
2726 case "$cur" in
2727 --*)
2728 __gitcomp "
2729 $__git_log_common_options
2730 $__git_log_shortlog_options
2731 --numbered --summary --email
2732 "
2733 return
2734 ;;
2735 esac
2736 __git_complete_revlist
2737}
2738
2739_git_show ()
2740{
2741 __git_has_doubledash && return
2742
2743 case "$cur" in
2744 --pretty=*|--format=*)
2745 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2746 " "" "${cur#*=}"
2747 return
2748 ;;
2749 --diff-algorithm=*)
2750 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2751 return
2752 ;;
2753 --submodule=*)
2754 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2755 return
2756 ;;
2757 --*)
2758 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2759 --show-signature
2760 $__git_diff_common_options
2761 "
2762 return
2763 ;;
2764 esac
2765 __git_complete_revlist_file
2766}
2767
2768_git_show_branch ()
2769{
2770 case "$cur" in
2771 --*)
2772 __gitcomp_builtin show-branch "--no-color"
2773 return
2774 ;;
2775 esac
2776 __git_complete_revlist
2777}
2778
2779_git_stash ()
2780{
2781 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2782 local subcommands='push save list show apply clear drop pop create branch'
2783 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2784 if [ -z "$subcommand" ]; then
2785 case "$cur" in
2786 --*)
2787 __gitcomp "$save_opts"
2788 ;;
2789 *)
2790 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2791 __gitcomp "$subcommands"
2792 fi
2793 ;;
2794 esac
2795 else
2796 case "$subcommand,$cur" in
2797 push,--*)
2798 __gitcomp "$save_opts --message"
2799 ;;
2800 save,--*)
2801 __gitcomp "$save_opts"
2802 ;;
2803 apply,--*|pop,--*)
2804 __gitcomp "--index --quiet"
2805 ;;
2806 drop,--*)
2807 __gitcomp "--quiet"
2808 ;;
2809 show,--*|branch,--*)
2810 ;;
2811 branch,*)
2812 if [ $cword -eq 3 ]; then
2813 __git_complete_refs
2814 else
2815 __gitcomp_nl "$(__git stash list \
2816 | sed -n -e 's/:.*//p')"
2817 fi
2818 ;;
2819 show,*|apply,*|drop,*|pop,*)
2820 __gitcomp_nl "$(__git stash list \
2821 | sed -n -e 's/:.*//p')"
2822 ;;
2823 *)
2824 ;;
2825 esac
2826 fi
2827}
2828
2829_git_submodule ()
2830{
2831 __git_has_doubledash && return
2832
2833 local subcommands="add status init deinit update summary foreach sync"
2834 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2835 if [ -z "$subcommand" ]; then
2836 case "$cur" in
2837 --*)
2838 __gitcomp "--quiet"
2839 ;;
2840 *)
2841 __gitcomp "$subcommands"
2842 ;;
2843 esac
2844 return
2845 fi
2846
2847 case "$subcommand,$cur" in
2848 add,--*)
2849 __gitcomp "--branch --force --name --reference --depth"
2850 ;;
2851 status,--*)
2852 __gitcomp "--cached --recursive"
2853 ;;
2854 deinit,--*)
2855 __gitcomp "--force --all"
2856 ;;
2857 update,--*)
2858 __gitcomp "
2859 --init --remote --no-fetch
2860 --recommend-shallow --no-recommend-shallow
2861 --force --rebase --merge --reference --depth --recursive --jobs
2862 "
2863 ;;
2864 summary,--*)
2865 __gitcomp "--cached --files --summary-limit"
2866 ;;
2867 foreach,--*|sync,--*)
2868 __gitcomp "--recursive"
2869 ;;
2870 *)
2871 ;;
2872 esac
2873}
2874
2875_git_svn ()
2876{
2877 local subcommands="
2878 init fetch clone rebase dcommit log find-rev
2879 set-tree commit-diff info create-ignore propget
2880 proplist show-ignore show-externals branch tag blame
2881 migrate mkdirs reset gc
2882 "
2883 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2884 if [ -z "$subcommand" ]; then
2885 __gitcomp "$subcommands"
2886 else
2887 local remote_opts="--username= --config-dir= --no-auth-cache"
2888 local fc_opts="
2889 --follow-parent --authors-file= --repack=
2890 --no-metadata --use-svm-props --use-svnsync-props
2891 --log-window-size= --no-checkout --quiet
2892 --repack-flags --use-log-author --localtime
2893 --add-author-from
2894 --ignore-paths= --include-paths= $remote_opts
2895 "
2896 local init_opts="
2897 --template= --shared= --trunk= --tags=
2898 --branches= --stdlayout --minimize-url
2899 --no-metadata --use-svm-props --use-svnsync-props
2900 --rewrite-root= --prefix= $remote_opts
2901 "
2902 local cmt_opts="
2903 --edit --rmdir --find-copies-harder --copy-similarity=
2904 "
2905
2906 case "$subcommand,$cur" in
2907 fetch,--*)
2908 __gitcomp "--revision= --fetch-all $fc_opts"
2909 ;;
2910 clone,--*)
2911 __gitcomp "--revision= $fc_opts $init_opts"
2912 ;;
2913 init,--*)
2914 __gitcomp "$init_opts"
2915 ;;
2916 dcommit,--*)
2917 __gitcomp "
2918 --merge --strategy= --verbose --dry-run
2919 --fetch-all --no-rebase --commit-url
2920 --revision --interactive $cmt_opts $fc_opts
2921 "
2922 ;;
2923 set-tree,--*)
2924 __gitcomp "--stdin $cmt_opts $fc_opts"
2925 ;;
2926 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2927 show-externals,--*|mkdirs,--*)
2928 __gitcomp "--revision="
2929 ;;
2930 log,--*)
2931 __gitcomp "
2932 --limit= --revision= --verbose --incremental
2933 --oneline --show-commit --non-recursive
2934 --authors-file= --color
2935 "
2936 ;;
2937 rebase,--*)
2938 __gitcomp "
2939 --merge --verbose --strategy= --local
2940 --fetch-all --dry-run $fc_opts
2941 "
2942 ;;
2943 commit-diff,--*)
2944 __gitcomp "--message= --file= --revision= $cmt_opts"
2945 ;;
2946 info,--*)
2947 __gitcomp "--url"
2948 ;;
2949 branch,--*)
2950 __gitcomp "--dry-run --message --tag"
2951 ;;
2952 tag,--*)
2953 __gitcomp "--dry-run --message"
2954 ;;
2955 blame,--*)
2956 __gitcomp "--git-format"
2957 ;;
2958 migrate,--*)
2959 __gitcomp "
2960 --config-dir= --ignore-paths= --minimize
2961 --no-auth-cache --username=
2962 "
2963 ;;
2964 reset,--*)
2965 __gitcomp "--revision= --parent"
2966 ;;
2967 *)
2968 ;;
2969 esac
2970 fi
2971}
2972
2973_git_tag ()
2974{
2975 local i c=1 f=0
2976 while [ $c -lt $cword ]; do
2977 i="${words[c]}"
2978 case "$i" in
2979 -d|--delete|-v|--verify)
2980 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2981 return
2982 ;;
2983 -f)
2984 f=1
2985 ;;
2986 esac
2987 ((c++))
2988 done
2989
2990 case "$prev" in
2991 -m|-F)
2992 ;;
2993 -*|tag)
2994 if [ $f = 1 ]; then
2995 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2996 fi
2997 ;;
2998 *)
2999 __git_complete_refs
3000 ;;
3001 esac
3002
3003 case "$cur" in
3004 --*)
3005 __gitcomp_builtin tag
3006 ;;
3007 esac
3008}
3009
3010_git_whatchanged ()
3011{
3012 _git_log
3013}
3014
3015_git_worktree ()
3016{
3017 local subcommands="add list lock move prune remove unlock"
3018 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3019 if [ -z "$subcommand" ]; then
3020 __gitcomp "$subcommands"
3021 else
3022 case "$subcommand,$cur" in
3023 add,--*)
3024 __gitcomp_builtin worktree_add
3025 ;;
3026 list,--*)
3027 __gitcomp_builtin worktree_list
3028 ;;
3029 lock,--*)
3030 __gitcomp_builtin worktree_lock
3031 ;;
3032 prune,--*)
3033 __gitcomp_builtin worktree_prune
3034 ;;
3035 remove,--*)
3036 __gitcomp "--force"
3037 ;;
3038 *)
3039 ;;
3040 esac
3041 fi
3042}
3043
3044__git_complete_common () {
3045 local command="$1"
3046
3047 case "$cur" in
3048 --*)
3049 __gitcomp_builtin "$command"
3050 ;;
3051 esac
3052}
3053
3054__git_cmds_with_parseopt_helper=
3055__git_support_parseopt_helper () {
3056 test -n "$__git_cmds_with_parseopt_helper" ||
3057 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
3058
3059 case " $__git_cmds_with_parseopt_helper " in
3060 *" $1 "*)
3061 return 0
3062 ;;
3063 *)
3064 return 1
3065 ;;
3066 esac
3067}
3068
3069__git_complete_command () {
3070 local command="$1"
3071 local completion_func="_git_${command//-/_}"
3072 if declare -f $completion_func >/dev/null 2>/dev/null; then
3073 $completion_func
3074 return 0
3075 elif __git_support_parseopt_helper "$command"; then
3076 __git_complete_common "$command"
3077 return 0
3078 else
3079 return 1
3080 fi
3081}
3082
3083__git_main ()
3084{
3085 local i c=1 command __git_dir __git_repo_path
3086 local __git_C_args C_args_count=0
3087
3088 while [ $c -lt $cword ]; do
3089 i="${words[c]}"
3090 case "$i" in
3091 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
3092 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
3093 --bare) __git_dir="." ;;
3094 --help) command="help"; break ;;
3095 -c|--work-tree|--namespace) ((c++)) ;;
3096 -C) __git_C_args[C_args_count++]=-C
3097 ((c++))
3098 __git_C_args[C_args_count++]="${words[c]}"
3099 ;;
3100 -*) ;;
3101 *) command="$i"; break ;;
3102 esac
3103 ((c++))
3104 done
3105
3106 if [ -z "$command" ]; then
3107 case "$prev" in
3108 --git-dir|-C|--work-tree)
3109 # these need a path argument, let's fall back to
3110 # Bash filename completion
3111 return
3112 ;;
3113 -c|--namespace)
3114 # we don't support completing these options' arguments
3115 return
3116 ;;
3117 esac
3118 case "$cur" in
3119 --*) __gitcomp "
3120 --paginate
3121 --no-pager
3122 --git-dir=
3123 --bare
3124 --version
3125 --exec-path
3126 --exec-path=
3127 --html-path
3128 --man-path
3129 --info-path
3130 --work-tree=
3131 --namespace=
3132 --no-replace-objects
3133 --help
3134 "
3135 ;;
3136 *) __git_compute_porcelain_commands
3137 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
3138 esac
3139 return
3140 fi
3141
3142 __git_complete_command "$command" && return
3143
3144 local expansion=$(__git_aliased_command "$command")
3145 if [ -n "$expansion" ]; then
3146 words[1]=$expansion
3147 __git_complete_command "$expansion"
3148 fi
3149}
3150
3151__gitk_main ()
3152{
3153 __git_has_doubledash && return
3154
3155 local __git_repo_path
3156 __git_find_repo_path
3157
3158 local merge=""
3159 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3160 merge="--merge"
3161 fi
3162 case "$cur" in
3163 --*)
3164 __gitcomp "
3165 $__git_log_common_options
3166 $__git_log_gitk_options
3167 $merge
3168 "
3169 return
3170 ;;
3171 esac
3172 __git_complete_revlist
3173}
3174
3175if [[ -n ${ZSH_VERSION-} ]]; then
3176 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3177
3178 autoload -U +X compinit && compinit
3179
3180 __gitcomp ()
3181 {
3182 emulate -L zsh
3183
3184 local cur_="${3-$cur}"
3185
3186 case "$cur_" in
3187 --*=)
3188 ;;
3189 *)
3190 local c IFS=$' \t\n'
3191 local -a array
3192 for c in ${=1}; do
3193 c="$c${4-}"
3194 case $c in
3195 --*=*|*.) ;;
3196 *) c="$c " ;;
3197 esac
3198 array[${#array[@]}+1]="$c"
3199 done
3200 compset -P '*[=:]'
3201 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3202 ;;
3203 esac
3204 }
3205
3206 __gitcomp_direct ()
3207 {
3208 emulate -L zsh
3209
3210 local IFS=$'\n'
3211 compset -P '*[=:]'
3212 compadd -Q -- ${=1} && _ret=0
3213 }
3214
3215 __gitcomp_nl ()
3216 {
3217 emulate -L zsh
3218
3219 local IFS=$'\n'
3220 compset -P '*[=:]'
3221 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3222 }
3223
3224 __gitcomp_file ()
3225 {
3226 emulate -L zsh
3227
3228 local IFS=$'\n'
3229 compset -P '*[=:]'
3230 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3231 }
3232
3233 _git ()
3234 {
3235 local _ret=1 cur cword prev
3236 cur=${words[CURRENT]}
3237 prev=${words[CURRENT-1]}
3238 let cword=CURRENT-1
3239 emulate ksh -c __${service}_main
3240 let _ret && _default && _ret=0
3241 return _ret
3242 }
3243
3244 compdef _git git gitk
3245 return
3246fi
3247
3248__git_func_wrap ()
3249{
3250 local cur words cword prev
3251 _get_comp_words_by_ref -n =: cur words cword prev
3252 $1
3253}
3254
3255# Setup completion for certain functions defined above by setting common
3256# variables and workarounds.
3257# This is NOT a public function; use at your own risk.
3258__git_complete ()
3259{
3260 local wrapper="__git_wrap${2}"
3261 eval "$wrapper () { __git_func_wrap $2 ; }"
3262 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3263 || complete -o default -o nospace -F $wrapper $1
3264}
3265
3266# wrapper for backwards compatibility
3267_git ()
3268{
3269 __git_wrap__git_main
3270}
3271
3272# wrapper for backwards compatibility
3273_gitk ()
3274{
3275 __git_wrap__gitk_main
3276}
3277
3278__git_complete git __git_main
3279__git_complete gitk __gitk_main
3280
3281# The following are necessary only for Cygwin, and only are needed
3282# when the user has tab-completed the executable name and consequently
3283# included the '.exe' suffix.
3284#
3285if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3286__git_complete git.exe __git_main
3287fi