952e660f06742270e84fb26afb3c98932787d432
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.
287if [[ -n ${ZSH_VERSION-} ]]; then
288 unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
289else
290 unset $(compgen -v __gitcomp_builtin_)
291fi
292
293# This function is equivalent to
294#
295# __gitcomp "$(git xxx --git-completion-helper) ..."
296#
297# except that the output is cached. Accept 1-3 arguments:
298# 1: the git command to execute, this is also the cache key
299# 2: extra options to be added on top (e.g. negative forms)
300# 3: options to be excluded
301__gitcomp_builtin ()
302{
303 # spaces must be replaced with underscore for multi-word
304 # commands, e.g. "git remote add" becomes remote_add.
305 local cmd="$1"
306 local incl="$2"
307 local excl="$3"
308
309 local var=__gitcomp_builtin_"${cmd/-/_}"
310 local options
311 eval "options=\$$var"
312
313 if [ -z "$options" ]; then
314 # leading and trailing spaces are significant to make
315 # option removal work correctly.
316 options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
317 for i in $excl; do
318 options="${options/ $i / }"
319 done
320 eval "$var=\"$options\""
321 fi
322
323 __gitcomp "$options"
324}
325
326# Variation of __gitcomp_nl () that appends to the existing list of
327# completion candidates, COMPREPLY.
328__gitcomp_nl_append ()
329{
330 local IFS=$'\n'
331 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
332}
333
334# Generates completion reply from newline-separated possible completion words
335# by appending a space to all of them.
336# It accepts 1 to 4 arguments:
337# 1: List of possible completion words, separated by a single newline.
338# 2: A prefix to be added to each possible completion word (optional).
339# 3: Generate possible completion matches for this word (optional).
340# 4: A suffix to be appended to each possible completion word instead of
341# the default space (optional). If specified but empty, nothing is
342# appended.
343__gitcomp_nl ()
344{
345 COMPREPLY=()
346 __gitcomp_nl_append "$@"
347}
348
349# Generates completion reply with compgen from newline-separated possible
350# completion filenames.
351# It accepts 1 to 3 arguments:
352# 1: List of possible completion filenames, separated by a single newline.
353# 2: A directory prefix to be added to each possible completion filename
354# (optional).
355# 3: Generate possible completion matches for this word (optional).
356__gitcomp_file ()
357{
358 local IFS=$'\n'
359
360 # XXX does not work when the directory prefix contains a tilde,
361 # since tilde expansion is not applied.
362 # This means that COMPREPLY will be empty and Bash default
363 # completion will be used.
364 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
365
366 # use a hack to enable file mode in bash < 4
367 compopt -o filenames +o nospace 2>/dev/null ||
368 compgen -f /non-existing-dir/ > /dev/null
369}
370
371# Execute 'git ls-files', unless the --committable option is specified, in
372# which case it runs 'git diff-index' to find out the files that can be
373# committed. It return paths relative to the directory specified in the first
374# argument, and using the options specified in the second argument.
375__git_ls_files_helper ()
376{
377 if [ "$2" == "--committable" ]; then
378 __git -C "$1" diff-index --name-only --relative HEAD
379 else
380 # NOTE: $2 is not quoted in order to support multiple options
381 __git -C "$1" ls-files --exclude-standard $2
382 fi
383}
384
385
386# __git_index_files accepts 1 or 2 arguments:
387# 1: Options to pass to ls-files (required).
388# 2: A directory path (optional).
389# If provided, only files within the specified directory are listed.
390# Sub directories are never recursed. Path must have a trailing
391# slash.
392__git_index_files ()
393{
394 local root="${2-.}" file
395
396 __git_ls_files_helper "$root" "$1" |
397 cut -f1 -d/ | sort | uniq
398}
399
400# Lists branches from the local repository.
401# 1: A prefix to be added to each listed branch (optional).
402# 2: List only branches matching this word (optional; list all branches if
403# unset or empty).
404# 3: A suffix to be appended to each listed branch (optional).
405__git_heads ()
406{
407 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
408
409 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
410 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
411}
412
413# Lists tags from the local repository.
414# Accepts the same positional parameters as __git_heads() above.
415__git_tags ()
416{
417 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
418
419 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
420 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
421}
422
423# Lists refs from the local (by default) or from a remote repository.
424# It accepts 0, 1 or 2 arguments:
425# 1: The remote to list refs from (optional; ignored, if set but empty).
426# Can be the name of a configured remote, a path, or a URL.
427# 2: In addition to local refs, list unique branches from refs/remotes/ for
428# 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
429# 3: A prefix to be added to each listed ref (optional).
430# 4: List only refs matching this word (optional; list all refs if unset or
431# empty).
432# 5: A suffix to be appended to each listed ref (optional; ignored, if set
433# but empty).
434#
435# Use __git_complete_refs() instead.
436__git_refs ()
437{
438 local i hash dir track="${2-}"
439 local list_refs_from=path remote="${1-}"
440 local format refs
441 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
442 local match="${4-}"
443 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
444
445 __git_find_repo_path
446 dir="$__git_repo_path"
447
448 if [ -z "$remote" ]; then
449 if [ -z "$dir" ]; then
450 return
451 fi
452 else
453 if __git_is_configured_remote "$remote"; then
454 # configured remote takes precedence over a
455 # local directory with the same name
456 list_refs_from=remote
457 elif [ -d "$remote/.git" ]; then
458 dir="$remote/.git"
459 elif [ -d "$remote" ]; then
460 dir="$remote"
461 else
462 list_refs_from=url
463 fi
464 fi
465
466 if [ "$list_refs_from" = path ]; then
467 if [[ "$cur_" == ^* ]]; then
468 pfx="$pfx^"
469 fer_pfx="$fer_pfx^"
470 cur_=${cur_#^}
471 match=${match#^}
472 fi
473 case "$cur_" in
474 refs|refs/*)
475 format="refname"
476 refs=("$match*" "$match*/**")
477 track=""
478 ;;
479 *)
480 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
481 case "$i" in
482 $match*)
483 if [ -e "$dir/$i" ]; then
484 echo "$pfx$i$sfx"
485 fi
486 ;;
487 esac
488 done
489 format="refname:strip=2"
490 refs=("refs/tags/$match*" "refs/tags/$match*/**"
491 "refs/heads/$match*" "refs/heads/$match*/**"
492 "refs/remotes/$match*" "refs/remotes/$match*/**")
493 ;;
494 esac
495 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
496 "${refs[@]}"
497 if [ -n "$track" ]; then
498 # employ the heuristic used by git checkout
499 # Try to find a remote branch that matches the completion word
500 # but only output if the branch name is unique
501 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
502 --sort="refname:strip=3" \
503 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
504 uniq -u
505 fi
506 return
507 fi
508 case "$cur_" in
509 refs|refs/*)
510 __git ls-remote "$remote" "$match*" | \
511 while read -r hash i; do
512 case "$i" in
513 *^{}) ;;
514 *) echo "$pfx$i$sfx" ;;
515 esac
516 done
517 ;;
518 *)
519 if [ "$list_refs_from" = remote ]; then
520 case "HEAD" in
521 $match*) echo "${pfx}HEAD$sfx" ;;
522 esac
523 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
524 "refs/remotes/$remote/$match*" \
525 "refs/remotes/$remote/$match*/**"
526 else
527 local query_symref
528 case "HEAD" in
529 $match*) query_symref="HEAD" ;;
530 esac
531 __git ls-remote "$remote" $query_symref \
532 "refs/tags/$match*" "refs/heads/$match*" \
533 "refs/remotes/$match*" |
534 while read -r hash i; do
535 case "$i" in
536 *^{}) ;;
537 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
538 *) echo "$pfx$i$sfx" ;; # symbolic refs
539 esac
540 done
541 fi
542 ;;
543 esac
544}
545
546# Completes refs, short and long, local and remote, symbolic and pseudo.
547#
548# Usage: __git_complete_refs [<option>]...
549# --remote=<remote>: The remote to list refs from, can be the name of a
550# configured remote, a path, or a URL.
551# --track: List unique remote branches for 'git checkout's tracking DWIMery.
552# --pfx=<prefix>: A prefix to be added to each ref.
553# --cur=<word>: The current ref to be completed. Defaults to the current
554# word to be completed.
555# --sfx=<suffix>: A suffix to be appended to each ref instead of the default
556# space.
557__git_complete_refs ()
558{
559 local remote track pfx cur_="$cur" sfx=" "
560
561 while test $# != 0; do
562 case "$1" in
563 --remote=*) remote="${1##--remote=}" ;;
564 --track) track="yes" ;;
565 --pfx=*) pfx="${1##--pfx=}" ;;
566 --cur=*) cur_="${1##--cur=}" ;;
567 --sfx=*) sfx="${1##--sfx=}" ;;
568 *) return 1 ;;
569 esac
570 shift
571 done
572
573 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
574}
575
576# __git_refs2 requires 1 argument (to pass to __git_refs)
577# Deprecated: use __git_complete_fetch_refspecs() instead.
578__git_refs2 ()
579{
580 local i
581 for i in $(__git_refs "$1"); do
582 echo "$i:$i"
583 done
584}
585
586# Completes refspecs for fetching from a remote repository.
587# 1: The remote repository.
588# 2: A prefix to be added to each listed refspec (optional).
589# 3: The ref to be completed as a refspec instead of the current word to be
590# completed (optional)
591# 4: A suffix to be appended to each listed refspec instead of the default
592# space (optional).
593__git_complete_fetch_refspecs ()
594{
595 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
596
597 __gitcomp_direct "$(
598 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
599 echo "$pfx$i:$i$sfx"
600 done
601 )"
602}
603
604# __git_refs_remotes requires 1 argument (to pass to ls-remote)
605__git_refs_remotes ()
606{
607 local i hash
608 __git ls-remote "$1" 'refs/heads/*' | \
609 while read -r hash i; do
610 echo "$i:refs/remotes/$1/${i#refs/heads/}"
611 done
612}
613
614__git_remotes ()
615{
616 __git_find_repo_path
617 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
618 __git remote
619}
620
621# Returns true if $1 matches the name of a configured remote, false otherwise.
622__git_is_configured_remote ()
623{
624 local remote
625 for remote in $(__git_remotes); do
626 if [ "$remote" = "$1" ]; then
627 return 0
628 fi
629 done
630 return 1
631}
632
633__git_list_merge_strategies ()
634{
635 LANG=C LC_ALL=C git merge -s help 2>&1 |
636 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
637 s/\.$//
638 s/.*://
639 s/^[ ]*//
640 s/[ ]*$//
641 p
642 }'
643}
644
645__git_merge_strategies=
646# 'git merge -s help' (and thus detection of the merge strategy
647# list) fails, unfortunately, if run outside of any git working
648# tree. __git_merge_strategies is set to the empty string in
649# that case, and the detection will be repeated the next time it
650# is needed.
651__git_compute_merge_strategies ()
652{
653 test -n "$__git_merge_strategies" ||
654 __git_merge_strategies=$(__git_list_merge_strategies)
655}
656
657__git_complete_revlist_file ()
658{
659 local pfx ls ref cur_="$cur"
660 case "$cur_" in
661 *..?*:*)
662 return
663 ;;
664 ?*:*)
665 ref="${cur_%%:*}"
666 cur_="${cur_#*:}"
667 case "$cur_" in
668 ?*/*)
669 pfx="${cur_%/*}"
670 cur_="${cur_##*/}"
671 ls="$ref:$pfx"
672 pfx="$pfx/"
673 ;;
674 *)
675 ls="$ref"
676 ;;
677 esac
678
679 case "$COMP_WORDBREAKS" in
680 *:*) : great ;;
681 *) pfx="$ref:$pfx" ;;
682 esac
683
684 __gitcomp_nl "$(__git ls-tree "$ls" \
685 | sed '/^100... blob /{
686 s,^.* ,,
687 s,$, ,
688 }
689 /^120000 blob /{
690 s,^.* ,,
691 s,$, ,
692 }
693 /^040000 tree /{
694 s,^.* ,,
695 s,$,/,
696 }
697 s/^.* //')" \
698 "$pfx" "$cur_" ""
699 ;;
700 *...*)
701 pfx="${cur_%...*}..."
702 cur_="${cur_#*...}"
703 __git_complete_refs --pfx="$pfx" --cur="$cur_"
704 ;;
705 *..*)
706 pfx="${cur_%..*}.."
707 cur_="${cur_#*..}"
708 __git_complete_refs --pfx="$pfx" --cur="$cur_"
709 ;;
710 *)
711 __git_complete_refs
712 ;;
713 esac
714}
715
716
717# __git_complete_index_file requires 1 argument:
718# 1: the options to pass to ls-file
719#
720# The exception is --committable, which finds the files appropriate commit.
721__git_complete_index_file ()
722{
723 local pfx="" cur_="$cur"
724
725 case "$cur_" in
726 ?*/*)
727 pfx="${cur_%/*}"
728 cur_="${cur_##*/}"
729 pfx="${pfx}/"
730 ;;
731 esac
732
733 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
734}
735
736__git_complete_file ()
737{
738 __git_complete_revlist_file
739}
740
741__git_complete_revlist ()
742{
743 __git_complete_revlist_file
744}
745
746__git_complete_remote_or_refspec ()
747{
748 local cur_="$cur" cmd="${words[1]}"
749 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
750 if [ "$cmd" = "remote" ]; then
751 ((c++))
752 fi
753 while [ $c -lt $cword ]; do
754 i="${words[c]}"
755 case "$i" in
756 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
757 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
758 --all)
759 case "$cmd" in
760 push) no_complete_refspec=1 ;;
761 fetch)
762 return
763 ;;
764 *) ;;
765 esac
766 ;;
767 -*) ;;
768 *) remote="$i"; break ;;
769 esac
770 ((c++))
771 done
772 if [ -z "$remote" ]; then
773 __gitcomp_nl "$(__git_remotes)"
774 return
775 fi
776 if [ $no_complete_refspec = 1 ]; then
777 return
778 fi
779 [ "$remote" = "." ] && remote=
780 case "$cur_" in
781 *:*)
782 case "$COMP_WORDBREAKS" in
783 *:*) : great ;;
784 *) pfx="${cur_%%:*}:" ;;
785 esac
786 cur_="${cur_#*:}"
787 lhs=0
788 ;;
789 +*)
790 pfx="+"
791 cur_="${cur_#+}"
792 ;;
793 esac
794 case "$cmd" in
795 fetch)
796 if [ $lhs = 1 ]; then
797 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
798 else
799 __git_complete_refs --pfx="$pfx" --cur="$cur_"
800 fi
801 ;;
802 pull|remote)
803 if [ $lhs = 1 ]; then
804 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
805 else
806 __git_complete_refs --pfx="$pfx" --cur="$cur_"
807 fi
808 ;;
809 push)
810 if [ $lhs = 1 ]; then
811 __git_complete_refs --pfx="$pfx" --cur="$cur_"
812 else
813 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
814 fi
815 ;;
816 esac
817}
818
819__git_complete_strategy ()
820{
821 __git_compute_merge_strategies
822 case "$prev" in
823 -s|--strategy)
824 __gitcomp "$__git_merge_strategies"
825 return 0
826 esac
827 case "$cur" in
828 --strategy=*)
829 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
830 return 0
831 ;;
832 esac
833 return 1
834}
835
836__git_commands () {
837 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
838 then
839 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
840 else
841 git help -a|egrep '^ [a-zA-Z0-9]'
842 fi
843}
844
845__git_list_all_commands ()
846{
847 local i IFS=" "$'\n'
848 for i in $(__git_commands)
849 do
850 case $i in
851 *--*) : helper pattern;;
852 *) echo $i;;
853 esac
854 done
855}
856
857__git_all_commands=
858__git_compute_all_commands ()
859{
860 test -n "$__git_all_commands" ||
861 __git_all_commands=$(__git_list_all_commands)
862}
863
864__git_list_porcelain_commands ()
865{
866 local i IFS=" "$'\n'
867 __git_compute_all_commands
868 for i in $__git_all_commands
869 do
870 case $i in
871 *--*) : helper pattern;;
872 applymbox) : ask gittus;;
873 applypatch) : ask gittus;;
874 archimport) : import;;
875 cat-file) : plumbing;;
876 check-attr) : plumbing;;
877 check-ignore) : plumbing;;
878 check-mailmap) : plumbing;;
879 check-ref-format) : plumbing;;
880 checkout-index) : plumbing;;
881 column) : internal helper;;
882 commit-graph) : plumbing;;
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 "" \
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
1230 ;;
1231 *)
1232 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1233 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1234 else
1235 __git_complete_refs
1236 fi
1237 ;;
1238 esac
1239}
1240
1241_git_bundle ()
1242{
1243 local cmd="${words[2]}"
1244 case "$cword" in
1245 2)
1246 __gitcomp "create list-heads verify unbundle"
1247 ;;
1248 3)
1249 # looking for a file
1250 ;;
1251 *)
1252 case "$cmd" in
1253 create)
1254 __git_complete_revlist
1255 ;;
1256 esac
1257 ;;
1258 esac
1259}
1260
1261_git_checkout ()
1262{
1263 __git_has_doubledash && return
1264
1265 case "$cur" in
1266 --conflict=*)
1267 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1268 ;;
1269 --*)
1270 __gitcomp_builtin checkout
1271 ;;
1272 *)
1273 # check if --track, --no-track, or --no-guess was specified
1274 # if so, disable DWIM mode
1275 local flags="--track --no-track --no-guess" track_opt="--track"
1276 if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
1277 [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1278 track_opt=''
1279 fi
1280 __git_complete_refs $track_opt
1281 ;;
1282 esac
1283}
1284
1285_git_cherry ()
1286{
1287 case "$cur" in
1288 --*)
1289 __gitcomp_builtin cherry
1290 return
1291 esac
1292
1293 __git_complete_refs
1294}
1295
1296__git_cherry_pick_inprogress_options="--continue --quit --abort"
1297
1298_git_cherry_pick ()
1299{
1300 __git_find_repo_path
1301 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1302 __gitcomp "$__git_cherry_pick_inprogress_options"
1303 return
1304 fi
1305 case "$cur" in
1306 --*)
1307 __gitcomp_builtin cherry-pick "" \
1308 "$__git_cherry_pick_inprogress_options"
1309 ;;
1310 *)
1311 __git_complete_refs
1312 ;;
1313 esac
1314}
1315
1316_git_clean ()
1317{
1318 case "$cur" in
1319 --*)
1320 __gitcomp_builtin clean
1321 return
1322 ;;
1323 esac
1324
1325 # XXX should we check for -x option ?
1326 __git_complete_index_file "--others --directory"
1327}
1328
1329_git_clone ()
1330{
1331 case "$cur" in
1332 --*)
1333 __gitcomp_builtin clone
1334 return
1335 ;;
1336 esac
1337}
1338
1339__git_untracked_file_modes="all no normal"
1340
1341_git_commit ()
1342{
1343 case "$prev" in
1344 -c|-C)
1345 __git_complete_refs
1346 return
1347 ;;
1348 esac
1349
1350 case "$cur" in
1351 --cleanup=*)
1352 __gitcomp "default scissors strip verbatim whitespace
1353 " "" "${cur##--cleanup=}"
1354 return
1355 ;;
1356 --reuse-message=*|--reedit-message=*|\
1357 --fixup=*|--squash=*)
1358 __git_complete_refs --cur="${cur#*=}"
1359 return
1360 ;;
1361 --untracked-files=*)
1362 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1363 return
1364 ;;
1365 --*)
1366 __gitcomp_builtin commit
1367 return
1368 esac
1369
1370 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1371 __git_complete_index_file "--committable"
1372 else
1373 # This is the first commit
1374 __git_complete_index_file "--cached"
1375 fi
1376}
1377
1378_git_describe ()
1379{
1380 case "$cur" in
1381 --*)
1382 __gitcomp_builtin describe
1383 return
1384 esac
1385 __git_complete_refs
1386}
1387
1388__git_diff_algorithms="myers minimal patience histogram"
1389
1390__git_diff_submodule_formats="diff log short"
1391
1392__git_diff_common_options="--stat --numstat --shortstat --summary
1393 --patch-with-stat --name-only --name-status --color
1394 --no-color --color-words --no-renames --check
1395 --full-index --binary --abbrev --diff-filter=
1396 --find-copies-harder --ignore-cr-at-eol
1397 --text --ignore-space-at-eol --ignore-space-change
1398 --ignore-all-space --ignore-blank-lines --exit-code
1399 --quiet --ext-diff --no-ext-diff
1400 --no-prefix --src-prefix= --dst-prefix=
1401 --inter-hunk-context=
1402 --patience --histogram --minimal
1403 --raw --word-diff --word-diff-regex=
1404 --dirstat --dirstat= --dirstat-by-file
1405 --dirstat-by-file= --cumulative
1406 --diff-algorithm=
1407 --submodule --submodule= --ignore-submodules
1408"
1409
1410_git_diff ()
1411{
1412 __git_has_doubledash && return
1413
1414 case "$cur" in
1415 --diff-algorithm=*)
1416 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1417 return
1418 ;;
1419 --submodule=*)
1420 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1421 return
1422 ;;
1423 --*)
1424 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1425 --base --ours --theirs --no-index
1426 $__git_diff_common_options
1427 "
1428 return
1429 ;;
1430 esac
1431 __git_complete_revlist_file
1432}
1433
1434__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1435 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1436"
1437
1438_git_difftool ()
1439{
1440 __git_has_doubledash && return
1441
1442 case "$cur" in
1443 --tool=*)
1444 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1445 return
1446 ;;
1447 --*)
1448 __gitcomp_builtin difftool "$__git_diff_common_options
1449 --base --cached --ours --theirs
1450 --pickaxe-all --pickaxe-regex
1451 --relative --staged
1452 "
1453 return
1454 ;;
1455 esac
1456 __git_complete_revlist_file
1457}
1458
1459__git_fetch_recurse_submodules="yes on-demand no"
1460
1461_git_fetch ()
1462{
1463 case "$cur" in
1464 --recurse-submodules=*)
1465 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1466 return
1467 ;;
1468 --*)
1469 __gitcomp_builtin fetch
1470 return
1471 ;;
1472 esac
1473 __git_complete_remote_or_refspec
1474}
1475
1476__git_format_patch_options="
1477 --stdout --attach --no-attach --thread --thread= --no-thread
1478 --numbered --start-number --numbered-files --keep-subject --signoff
1479 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1480 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1481 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1482 --output-directory --reroll-count --to= --quiet --notes
1483"
1484
1485_git_format_patch ()
1486{
1487 case "$cur" in
1488 --thread=*)
1489 __gitcomp "
1490 deep shallow
1491 " "" "${cur##--thread=}"
1492 return
1493 ;;
1494 --*)
1495 __gitcomp "$__git_format_patch_options"
1496 return
1497 ;;
1498 esac
1499 __git_complete_revlist
1500}
1501
1502_git_fsck ()
1503{
1504 case "$cur" in
1505 --*)
1506 __gitcomp_builtin fsck
1507 return
1508 ;;
1509 esac
1510}
1511
1512_git_gitk ()
1513{
1514 _gitk
1515}
1516
1517# Lists matching symbol names from a tag (as in ctags) file.
1518# 1: List symbol names matching this word.
1519# 2: The tag file to list symbol names from.
1520# 3: A prefix to be added to each listed symbol name (optional).
1521# 4: A suffix to be appended to each listed symbol name (optional).
1522__git_match_ctag () {
1523 awk -v pfx="${3-}" -v sfx="${4-}" "
1524 /^${1//\//\\/}/ { print pfx \$1 sfx }
1525 " "$2"
1526}
1527
1528# Complete symbol names from a tag file.
1529# Usage: __git_complete_symbol [<option>]...
1530# --tags=<file>: The tag file to list symbol names from instead of the
1531# default "tags".
1532# --pfx=<prefix>: A prefix to be added to each symbol name.
1533# --cur=<word>: The current symbol name to be completed. Defaults to
1534# the current word to be completed.
1535# --sfx=<suffix>: A suffix to be appended to each symbol name instead
1536# of the default space.
1537__git_complete_symbol () {
1538 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1539
1540 while test $# != 0; do
1541 case "$1" in
1542 --tags=*) tags="${1##--tags=}" ;;
1543 --pfx=*) pfx="${1##--pfx=}" ;;
1544 --cur=*) cur_="${1##--cur=}" ;;
1545 --sfx=*) sfx="${1##--sfx=}" ;;
1546 *) return 1 ;;
1547 esac
1548 shift
1549 done
1550
1551 if test -r "$tags"; then
1552 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1553 fi
1554}
1555
1556_git_grep ()
1557{
1558 __git_has_doubledash && return
1559
1560 case "$cur" in
1561 --*)
1562 __gitcomp_builtin grep
1563 return
1564 ;;
1565 esac
1566
1567 case "$cword,$prev" in
1568 2,*|*,-*)
1569 __git_complete_symbol && return
1570 ;;
1571 esac
1572
1573 __git_complete_refs
1574}
1575
1576_git_help ()
1577{
1578 case "$cur" in
1579 --*)
1580 __gitcomp_builtin help
1581 return
1582 ;;
1583 esac
1584 __git_compute_all_commands
1585 __gitcomp "$__git_all_commands $(__git_aliases)
1586 attributes cli core-tutorial cvs-migration
1587 diffcore everyday gitk glossary hooks ignore modules
1588 namespaces repository-layout revisions tutorial tutorial-2
1589 workflows
1590 "
1591}
1592
1593_git_init ()
1594{
1595 case "$cur" in
1596 --shared=*)
1597 __gitcomp "
1598 false true umask group all world everybody
1599 " "" "${cur##--shared=}"
1600 return
1601 ;;
1602 --*)
1603 __gitcomp_builtin init
1604 return
1605 ;;
1606 esac
1607}
1608
1609_git_ls_files ()
1610{
1611 case "$cur" in
1612 --*)
1613 __gitcomp_builtin ls-files
1614 return
1615 ;;
1616 esac
1617
1618 # XXX ignore options like --modified and always suggest all cached
1619 # files.
1620 __git_complete_index_file "--cached"
1621}
1622
1623_git_ls_remote ()
1624{
1625 case "$cur" in
1626 --*)
1627 __gitcomp_builtin ls-remote
1628 return
1629 ;;
1630 esac
1631 __gitcomp_nl "$(__git_remotes)"
1632}
1633
1634_git_ls_tree ()
1635{
1636 case "$cur" in
1637 --*)
1638 __gitcomp_builtin ls-tree
1639 return
1640 ;;
1641 esac
1642
1643 __git_complete_file
1644}
1645
1646# Options that go well for log, shortlog and gitk
1647__git_log_common_options="
1648 --not --all
1649 --branches --tags --remotes
1650 --first-parent --merges --no-merges
1651 --max-count=
1652 --max-age= --since= --after=
1653 --min-age= --until= --before=
1654 --min-parents= --max-parents=
1655 --no-min-parents --no-max-parents
1656"
1657# Options that go well for log and gitk (not shortlog)
1658__git_log_gitk_options="
1659 --dense --sparse --full-history
1660 --simplify-merges --simplify-by-decoration
1661 --left-right --notes --no-notes
1662"
1663# Options that go well for log and shortlog (not gitk)
1664__git_log_shortlog_options="
1665 --author= --committer= --grep=
1666 --all-match --invert-grep
1667"
1668
1669__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1670__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1671
1672_git_log ()
1673{
1674 __git_has_doubledash && return
1675 __git_find_repo_path
1676
1677 local merge=""
1678 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1679 merge="--merge"
1680 fi
1681 case "$prev,$cur" in
1682 -L,:*:*)
1683 return # fall back to Bash filename completion
1684 ;;
1685 -L,:*)
1686 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1687 return
1688 ;;
1689 -G,*|-S,*)
1690 __git_complete_symbol
1691 return
1692 ;;
1693 esac
1694 case "$cur" in
1695 --pretty=*|--format=*)
1696 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1697 " "" "${cur#*=}"
1698 return
1699 ;;
1700 --date=*)
1701 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1702 return
1703 ;;
1704 --decorate=*)
1705 __gitcomp "full short no" "" "${cur##--decorate=}"
1706 return
1707 ;;
1708 --diff-algorithm=*)
1709 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1710 return
1711 ;;
1712 --submodule=*)
1713 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1714 return
1715 ;;
1716 --*)
1717 __gitcomp "
1718 $__git_log_common_options
1719 $__git_log_shortlog_options
1720 $__git_log_gitk_options
1721 --root --topo-order --date-order --reverse
1722 --follow --full-diff
1723 --abbrev-commit --abbrev=
1724 --relative-date --date=
1725 --pretty= --format= --oneline
1726 --show-signature
1727 --cherry-mark
1728 --cherry-pick
1729 --graph
1730 --decorate --decorate=
1731 --walk-reflogs
1732 --parents --children
1733 $merge
1734 $__git_diff_common_options
1735 --pickaxe-all --pickaxe-regex
1736 "
1737 return
1738 ;;
1739 -L:*:*)
1740 return # fall back to Bash filename completion
1741 ;;
1742 -L:*)
1743 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
1744 return
1745 ;;
1746 -G*)
1747 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
1748 return
1749 ;;
1750 -S*)
1751 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
1752 return
1753 ;;
1754 esac
1755 __git_complete_revlist
1756}
1757
1758_git_merge ()
1759{
1760 __git_complete_strategy && return
1761
1762 case "$cur" in
1763 --*)
1764 __gitcomp_builtin merge
1765 return
1766 esac
1767 __git_complete_refs
1768}
1769
1770_git_mergetool ()
1771{
1772 case "$cur" in
1773 --tool=*)
1774 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1775 return
1776 ;;
1777 --*)
1778 __gitcomp "--tool= --prompt --no-prompt"
1779 return
1780 ;;
1781 esac
1782}
1783
1784_git_merge_base ()
1785{
1786 case "$cur" in
1787 --*)
1788 __gitcomp_builtin merge-base
1789 return
1790 ;;
1791 esac
1792 __git_complete_refs
1793}
1794
1795_git_mv ()
1796{
1797 case "$cur" in
1798 --*)
1799 __gitcomp_builtin mv
1800 return
1801 ;;
1802 esac
1803
1804 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1805 # We need to show both cached and untracked files (including
1806 # empty directories) since this may not be the last argument.
1807 __git_complete_index_file "--cached --others --directory"
1808 else
1809 __git_complete_index_file "--cached"
1810 fi
1811}
1812
1813_git_notes ()
1814{
1815 local subcommands='add append copy edit get-ref list merge prune remove show'
1816 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1817
1818 case "$subcommand,$cur" in
1819 ,--*)
1820 __gitcomp_builtin notes
1821 ;;
1822 ,*)
1823 case "$prev" in
1824 --ref)
1825 __git_complete_refs
1826 ;;
1827 *)
1828 __gitcomp "$subcommands --ref"
1829 ;;
1830 esac
1831 ;;
1832 *,--reuse-message=*|*,--reedit-message=*)
1833 __git_complete_refs --cur="${cur#*=}"
1834 ;;
1835 *,--*)
1836 __gitcomp_builtin notes_$subcommand
1837 ;;
1838 prune,*|get-ref,*)
1839 # this command does not take a ref, do not complete it
1840 ;;
1841 *)
1842 case "$prev" in
1843 -m|-F)
1844 ;;
1845 *)
1846 __git_complete_refs
1847 ;;
1848 esac
1849 ;;
1850 esac
1851}
1852
1853_git_pull ()
1854{
1855 __git_complete_strategy && return
1856
1857 case "$cur" in
1858 --recurse-submodules=*)
1859 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1860 return
1861 ;;
1862 --*)
1863 __gitcomp_builtin pull
1864
1865 return
1866 ;;
1867 esac
1868 __git_complete_remote_or_refspec
1869}
1870
1871__git_push_recurse_submodules="check on-demand only"
1872
1873__git_complete_force_with_lease ()
1874{
1875 local cur_=$1
1876
1877 case "$cur_" in
1878 --*=)
1879 ;;
1880 *:*)
1881 __git_complete_refs --cur="${cur_#*:}"
1882 ;;
1883 *)
1884 __git_complete_refs --cur="$cur_"
1885 ;;
1886 esac
1887}
1888
1889_git_push ()
1890{
1891 case "$prev" in
1892 --repo)
1893 __gitcomp_nl "$(__git_remotes)"
1894 return
1895 ;;
1896 --recurse-submodules)
1897 __gitcomp "$__git_push_recurse_submodules"
1898 return
1899 ;;
1900 esac
1901 case "$cur" in
1902 --repo=*)
1903 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1904 return
1905 ;;
1906 --recurse-submodules=*)
1907 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1908 return
1909 ;;
1910 --force-with-lease=*)
1911 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1912 return
1913 ;;
1914 --*)
1915 __gitcomp_builtin push
1916 return
1917 ;;
1918 esac
1919 __git_complete_remote_or_refspec
1920}
1921
1922_git_rebase ()
1923{
1924 __git_find_repo_path
1925 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1926 __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
1927 return
1928 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1929 [ -d "$__git_repo_path"/rebase-merge ]; then
1930 __gitcomp "--continue --skip --abort --quit --show-current-patch"
1931 return
1932 fi
1933 __git_complete_strategy && return
1934 case "$cur" in
1935 --whitespace=*)
1936 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1937 return
1938 ;;
1939 --*)
1940 __gitcomp "
1941 --onto --merge --strategy --interactive
1942 --rebase-merges --preserve-merges --stat --no-stat
1943 --committer-date-is-author-date --ignore-date
1944 --ignore-whitespace --whitespace=
1945 --autosquash --no-autosquash
1946 --fork-point --no-fork-point
1947 --autostash --no-autostash
1948 --verify --no-verify
1949 --keep-empty --root --force-rebase --no-ff
1950 --rerere-autoupdate
1951 --exec
1952 "
1953
1954 return
1955 esac
1956 __git_complete_refs
1957}
1958
1959_git_reflog ()
1960{
1961 local subcommands="show delete expire"
1962 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1963
1964 if [ -z "$subcommand" ]; then
1965 __gitcomp "$subcommands"
1966 else
1967 __git_complete_refs
1968 fi
1969}
1970
1971__git_send_email_confirm_options="always never auto cc compose"
1972__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1973
1974_git_send_email ()
1975{
1976 case "$prev" in
1977 --to|--cc|--bcc|--from)
1978 __gitcomp "$(__git send-email --dump-aliases)"
1979 return
1980 ;;
1981 esac
1982
1983 case "$cur" in
1984 --confirm=*)
1985 __gitcomp "
1986 $__git_send_email_confirm_options
1987 " "" "${cur##--confirm=}"
1988 return
1989 ;;
1990 --suppress-cc=*)
1991 __gitcomp "
1992 $__git_send_email_suppresscc_options
1993 " "" "${cur##--suppress-cc=}"
1994
1995 return
1996 ;;
1997 --smtp-encryption=*)
1998 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1999 return
2000 ;;
2001 --thread=*)
2002 __gitcomp "
2003 deep shallow
2004 " "" "${cur##--thread=}"
2005 return
2006 ;;
2007 --to=*|--cc=*|--bcc=*|--from=*)
2008 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2009 return
2010 ;;
2011 --*)
2012 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2013 --compose --confirm= --dry-run --envelope-sender
2014 --from --identity
2015 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2016 --no-suppress-from --no-thread --quiet --reply-to
2017 --signed-off-by-cc --smtp-pass --smtp-server
2018 --smtp-server-port --smtp-encryption= --smtp-user
2019 --subject --suppress-cc= --suppress-from --thread --to
2020 --validate --no-validate
2021 $__git_format_patch_options"
2022 return
2023 ;;
2024 esac
2025 __git_complete_revlist
2026}
2027
2028_git_stage ()
2029{
2030 _git_add
2031}
2032
2033_git_status ()
2034{
2035 local complete_opt
2036 local untracked_state
2037
2038 case "$cur" in
2039 --ignore-submodules=*)
2040 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2041 return
2042 ;;
2043 --untracked-files=*)
2044 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2045 return
2046 ;;
2047 --column=*)
2048 __gitcomp "
2049 always never auto column row plain dense nodense
2050 " "" "${cur##--column=}"
2051 return
2052 ;;
2053 --*)
2054 __gitcomp_builtin status
2055 return
2056 ;;
2057 esac
2058
2059 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2060 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2061
2062 case "$untracked_state" in
2063 no)
2064 # --ignored option does not matter
2065 complete_opt=
2066 ;;
2067 all|normal|*)
2068 complete_opt="--cached --directory --no-empty-directory --others"
2069
2070 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2071 complete_opt="$complete_opt --ignored --exclude=*"
2072 fi
2073 ;;
2074 esac
2075
2076 __git_complete_index_file "$complete_opt"
2077}
2078
2079__git_config_get_set_variables ()
2080{
2081 local prevword word config_file= c=$cword
2082 while [ $c -gt 1 ]; do
2083 word="${words[c]}"
2084 case "$word" in
2085 --system|--global|--local|--file=*)
2086 config_file="$word"
2087 break
2088 ;;
2089 -f|--file)
2090 config_file="$word $prevword"
2091 break
2092 ;;
2093 esac
2094 prevword=$word
2095 c=$((--c))
2096 done
2097
2098 __git config $config_file --name-only --list
2099}
2100
2101_git_config ()
2102{
2103 case "$prev" in
2104 branch.*.remote|branch.*.pushremote)
2105 __gitcomp_nl "$(__git_remotes)"
2106 return
2107 ;;
2108 branch.*.merge)
2109 __git_complete_refs
2110 return
2111 ;;
2112 branch.*.rebase)
2113 __gitcomp "false true merges preserve interactive"
2114 return
2115 ;;
2116 remote.pushdefault)
2117 __gitcomp_nl "$(__git_remotes)"
2118 return
2119 ;;
2120 remote.*.fetch)
2121 local remote="${prev#remote.}"
2122 remote="${remote%.fetch}"
2123 if [ -z "$cur" ]; then
2124 __gitcomp_nl "refs/heads/" "" "" ""
2125 return
2126 fi
2127 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2128 return
2129 ;;
2130 remote.*.push)
2131 local remote="${prev#remote.}"
2132 remote="${remote%.push}"
2133 __gitcomp_nl "$(__git for-each-ref \
2134 --format='%(refname):%(refname)' refs/heads)"
2135 return
2136 ;;
2137 pull.twohead|pull.octopus)
2138 __git_compute_merge_strategies
2139 __gitcomp "$__git_merge_strategies"
2140 return
2141 ;;
2142 color.branch|color.diff|color.interactive|\
2143 color.showbranch|color.status|color.ui)
2144 __gitcomp "always never auto"
2145 return
2146 ;;
2147 color.pager)
2148 __gitcomp "false true"
2149 return
2150 ;;
2151 color.*.*)
2152 __gitcomp "
2153 normal black red green yellow blue magenta cyan white
2154 bold dim ul blink reverse
2155 "
2156 return
2157 ;;
2158 diff.submodule)
2159 __gitcomp "log short"
2160 return
2161 ;;
2162 help.format)
2163 __gitcomp "man info web html"
2164 return
2165 ;;
2166 log.date)
2167 __gitcomp "$__git_log_date_formats"
2168 return
2169 ;;
2170 sendemail.aliasfiletype)
2171 __gitcomp "mutt mailrc pine elm gnus"
2172 return
2173 ;;
2174 sendemail.confirm)
2175 __gitcomp "$__git_send_email_confirm_options"
2176 return
2177 ;;
2178 sendemail.suppresscc)
2179 __gitcomp "$__git_send_email_suppresscc_options"
2180 return
2181 ;;
2182 sendemail.transferencoding)
2183 __gitcomp "7bit 8bit quoted-printable base64"
2184 return
2185 ;;
2186 --get|--get-all|--unset|--unset-all)
2187 __gitcomp_nl "$(__git_config_get_set_variables)"
2188 return
2189 ;;
2190 *.*)
2191 return
2192 ;;
2193 esac
2194 case "$cur" in
2195 --*)
2196 __gitcomp_builtin config
2197 return
2198 ;;
2199 branch.*.*)
2200 local pfx="${cur%.*}." cur_="${cur##*.}"
2201 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2202 return
2203 ;;
2204 branch.*)
2205 local pfx="${cur%.*}." cur_="${cur#*.}"
2206 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2207 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2208 return
2209 ;;
2210 guitool.*.*)
2211 local pfx="${cur%.*}." cur_="${cur##*.}"
2212 __gitcomp "
2213 argprompt cmd confirm needsfile noconsole norescan
2214 prompt revprompt revunmerged title
2215 " "$pfx" "$cur_"
2216 return
2217 ;;
2218 difftool.*.*)
2219 local pfx="${cur%.*}." cur_="${cur##*.}"
2220 __gitcomp "cmd path" "$pfx" "$cur_"
2221 return
2222 ;;
2223 man.*.*)
2224 local pfx="${cur%.*}." cur_="${cur##*.}"
2225 __gitcomp "cmd path" "$pfx" "$cur_"
2226 return
2227 ;;
2228 mergetool.*.*)
2229 local pfx="${cur%.*}." cur_="${cur##*.}"
2230 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2231 return
2232 ;;
2233 pager.*)
2234 local pfx="${cur%.*}." cur_="${cur#*.}"
2235 __git_compute_all_commands
2236 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2237 return
2238 ;;
2239 remote.*.*)
2240 local pfx="${cur%.*}." cur_="${cur##*.}"
2241 __gitcomp "
2242 url proxy fetch push mirror skipDefaultUpdate
2243 receivepack uploadpack tagopt pushurl
2244 " "$pfx" "$cur_"
2245 return
2246 ;;
2247 remote.*)
2248 local pfx="${cur%.*}." cur_="${cur#*.}"
2249 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2250 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2251 return
2252 ;;
2253 url.*.*)
2254 local pfx="${cur%.*}." cur_="${cur##*.}"
2255 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2256 return
2257 ;;
2258 esac
2259 __gitcomp "
2260 add.ignoreErrors
2261 advice.amWorkDir
2262 advice.commitBeforeMerge
2263 advice.detachedHead
2264 advice.implicitIdentity
2265 advice.pushAlreadyExists
2266 advice.pushFetchFirst
2267 advice.pushNeedsForce
2268 advice.pushNonFFCurrent
2269 advice.pushNonFFMatching
2270 advice.pushUpdateRejected
2271 advice.resolveConflict
2272 advice.rmHints
2273 advice.statusHints
2274 advice.statusUoption
2275 advice.ignoredHook
2276 alias.
2277 am.keepcr
2278 am.threeWay
2279 apply.ignorewhitespace
2280 apply.whitespace
2281 branch.autosetupmerge
2282 branch.autosetuprebase
2283 browser.
2284 clean.requireForce
2285 color.branch
2286 color.branch.current
2287 color.branch.local
2288 color.branch.plain
2289 color.branch.remote
2290 color.decorate.HEAD
2291 color.decorate.branch
2292 color.decorate.remoteBranch
2293 color.decorate.stash
2294 color.decorate.tag
2295 color.diff
2296 color.diff.commit
2297 color.diff.frag
2298 color.diff.func
2299 color.diff.meta
2300 color.diff.new
2301 color.diff.old
2302 color.diff.plain
2303 color.diff.whitespace
2304 color.grep
2305 color.grep.context
2306 color.grep.filename
2307 color.grep.function
2308 color.grep.linenumber
2309 color.grep.match
2310 color.grep.selected
2311 color.grep.separator
2312 color.interactive
2313 color.interactive.error
2314 color.interactive.header
2315 color.interactive.help
2316 color.interactive.prompt
2317 color.pager
2318 color.showbranch
2319 color.status
2320 color.status.added
2321 color.status.changed
2322 color.status.header
2323 color.status.localBranch
2324 color.status.nobranch
2325 color.status.remoteBranch
2326 color.status.unmerged
2327 color.status.untracked
2328 color.status.updated
2329 color.ui
2330 commit.cleanup
2331 commit.gpgSign
2332 commit.status
2333 commit.template
2334 commit.verbose
2335 core.abbrev
2336 core.askpass
2337 core.attributesfile
2338 core.autocrlf
2339 core.bare
2340 core.bigFileThreshold
2341 core.checkStat
2342 core.commentChar
2343 core.commitGraph
2344 core.compression
2345 core.createObject
2346 core.deltaBaseCacheLimit
2347 core.editor
2348 core.eol
2349 core.excludesfile
2350 core.fileMode
2351 core.fsyncobjectfiles
2352 core.gitProxy
2353 core.hideDotFiles
2354 core.hooksPath
2355 core.ignoreStat
2356 core.ignorecase
2357 core.logAllRefUpdates
2358 core.loosecompression
2359 core.notesRef
2360 core.packedGitLimit
2361 core.packedGitWindowSize
2362 core.packedRefsTimeout
2363 core.pager
2364 core.precomposeUnicode
2365 core.preferSymlinkRefs
2366 core.preloadindex
2367 core.protectHFS
2368 core.protectNTFS
2369 core.quotepath
2370 core.repositoryFormatVersion
2371 core.safecrlf
2372 core.sharedRepository
2373 core.sparseCheckout
2374 core.splitIndex
2375 core.sshCommand
2376 core.symlinks
2377 core.trustctime
2378 core.untrackedCache
2379 core.warnAmbiguousRefs
2380 core.whitespace
2381 core.worktree
2382 credential.helper
2383 credential.useHttpPath
2384 credential.username
2385 credentialCache.ignoreSIGHUP
2386 diff.autorefreshindex
2387 diff.external
2388 diff.ignoreSubmodules
2389 diff.mnemonicprefix
2390 diff.noprefix
2391 diff.renameLimit
2392 diff.renames
2393 diff.statGraphWidth
2394 diff.submodule
2395 diff.suppressBlankEmpty
2396 diff.tool
2397 diff.wordRegex
2398 diff.algorithm
2399 difftool.
2400 difftool.prompt
2401 fetch.recurseSubmodules
2402 fetch.unpackLimit
2403 format.attach
2404 format.cc
2405 format.coverLetter
2406 format.from
2407 format.headers
2408 format.numbered
2409 format.pretty
2410 format.signature
2411 format.signoff
2412 format.subjectprefix
2413 format.suffix
2414 format.thread
2415 format.to
2416 gc.
2417 gc.aggressiveDepth
2418 gc.aggressiveWindow
2419 gc.auto
2420 gc.autoDetach
2421 gc.autopacklimit
2422 gc.logExpiry
2423 gc.packrefs
2424 gc.pruneexpire
2425 gc.reflogexpire
2426 gc.reflogexpireunreachable
2427 gc.rerereresolved
2428 gc.rerereunresolved
2429 gc.worktreePruneExpire
2430 gitcvs.allbinary
2431 gitcvs.commitmsgannotation
2432 gitcvs.dbTableNamePrefix
2433 gitcvs.dbdriver
2434 gitcvs.dbname
2435 gitcvs.dbpass
2436 gitcvs.dbuser
2437 gitcvs.enabled
2438 gitcvs.logfile
2439 gitcvs.usecrlfattr
2440 guitool.
2441 gui.blamehistoryctx
2442 gui.commitmsgwidth
2443 gui.copyblamethreshold
2444 gui.diffcontext
2445 gui.encoding
2446 gui.fastcopyblame
2447 gui.matchtrackingbranch
2448 gui.newbranchtemplate
2449 gui.pruneduringfetch
2450 gui.spellingdictionary
2451 gui.trustmtime
2452 help.autocorrect
2453 help.browser
2454 help.format
2455 http.lowSpeedLimit
2456 http.lowSpeedTime
2457 http.maxRequests
2458 http.minSessions
2459 http.noEPSV
2460 http.postBuffer
2461 http.proxy
2462 http.sslCipherList
2463 http.sslVersion
2464 http.sslCAInfo
2465 http.sslCAPath
2466 http.sslCert
2467 http.sslCertPasswordProtected
2468 http.sslKey
2469 http.sslVerify
2470 http.useragent
2471 i18n.commitEncoding
2472 i18n.logOutputEncoding
2473 imap.authMethod
2474 imap.folder
2475 imap.host
2476 imap.pass
2477 imap.port
2478 imap.preformattedHTML
2479 imap.sslverify
2480 imap.tunnel
2481 imap.user
2482 init.templatedir
2483 instaweb.browser
2484 instaweb.httpd
2485 instaweb.local
2486 instaweb.modulepath
2487 instaweb.port
2488 interactive.singlekey
2489 log.date
2490 log.decorate
2491 log.showroot
2492 mailmap.file
2493 man.
2494 man.viewer
2495 merge.
2496 merge.conflictstyle
2497 merge.log
2498 merge.renameLimit
2499 merge.renormalize
2500 merge.stat
2501 merge.tool
2502 merge.verbosity
2503 mergetool.
2504 mergetool.keepBackup
2505 mergetool.keepTemporaries
2506 mergetool.prompt
2507 notes.displayRef
2508 notes.rewrite.
2509 notes.rewrite.amend
2510 notes.rewrite.rebase
2511 notes.rewriteMode
2512 notes.rewriteRef
2513 pack.compression
2514 pack.deltaCacheLimit
2515 pack.deltaCacheSize
2516 pack.depth
2517 pack.indexVersion
2518 pack.packSizeLimit
2519 pack.threads
2520 pack.window
2521 pack.windowMemory
2522 pager.
2523 pretty.
2524 pull.octopus
2525 pull.twohead
2526 push.default
2527 push.followTags
2528 rebase.autosquash
2529 rebase.stat
2530 receive.autogc
2531 receive.denyCurrentBranch
2532 receive.denyDeleteCurrent
2533 receive.denyDeletes
2534 receive.denyNonFastForwards
2535 receive.fsckObjects
2536 receive.unpackLimit
2537 receive.updateserverinfo
2538 remote.pushdefault
2539 remotes.
2540 repack.usedeltabaseoffset
2541 rerere.autoupdate
2542 rerere.enabled
2543 sendemail.
2544 sendemail.aliasesfile
2545 sendemail.aliasfiletype
2546 sendemail.bcc
2547 sendemail.cc
2548 sendemail.cccmd
2549 sendemail.chainreplyto
2550 sendemail.confirm
2551 sendemail.envelopesender
2552 sendemail.from
2553 sendemail.identity
2554 sendemail.multiedit
2555 sendemail.signedoffbycc
2556 sendemail.smtpdomain
2557 sendemail.smtpencryption
2558 sendemail.smtppass
2559 sendemail.smtpserver
2560 sendemail.smtpserveroption
2561 sendemail.smtpserverport
2562 sendemail.smtpuser
2563 sendemail.suppresscc
2564 sendemail.suppressfrom
2565 sendemail.thread
2566 sendemail.to
2567 sendemail.tocmd
2568 sendemail.validate
2569 sendemail.smtpbatchsize
2570 sendemail.smtprelogindelay
2571 showbranch.default
2572 status.relativePaths
2573 status.showUntrackedFiles
2574 status.submodulesummary
2575 submodule.
2576 tar.umask
2577 transfer.unpackLimit
2578 url.
2579 user.email
2580 user.name
2581 user.signingkey
2582 web.browser
2583 branch. remote.
2584 "
2585}
2586
2587_git_remote ()
2588{
2589 local subcommands="
2590 add rename remove set-head set-branches
2591 get-url set-url show prune update
2592 "
2593 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2594 if [ -z "$subcommand" ]; then
2595 case "$cur" in
2596 --*)
2597 __gitcomp_builtin remote
2598 ;;
2599 *)
2600 __gitcomp "$subcommands"
2601 ;;
2602 esac
2603 return
2604 fi
2605
2606 case "$subcommand,$cur" in
2607 add,--*)
2608 __gitcomp_builtin remote_add
2609 ;;
2610 add,*)
2611 ;;
2612 set-head,--*)
2613 __gitcomp_builtin remote_set-head
2614 ;;
2615 set-branches,--*)
2616 __gitcomp_builtin remote_set-branches
2617 ;;
2618 set-head,*|set-branches,*)
2619 __git_complete_remote_or_refspec
2620 ;;
2621 update,--*)
2622 __gitcomp_builtin remote_update
2623 ;;
2624 update,*)
2625 __gitcomp "$(__git_get_config_variables "remotes")"
2626 ;;
2627 set-url,--*)
2628 __gitcomp_builtin remote_set-url
2629 ;;
2630 get-url,--*)
2631 __gitcomp_builtin remote_get-url
2632 ;;
2633 prune,--*)
2634 __gitcomp_builtin remote_prune
2635 ;;
2636 *)
2637 __gitcomp_nl "$(__git_remotes)"
2638 ;;
2639 esac
2640}
2641
2642_git_replace ()
2643{
2644 case "$cur" in
2645 --*)
2646 __gitcomp_builtin replace
2647 return
2648 ;;
2649 esac
2650 __git_complete_refs
2651}
2652
2653_git_rerere ()
2654{
2655 local subcommands="clear forget diff remaining status gc"
2656 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2657 if test -z "$subcommand"
2658 then
2659 __gitcomp "$subcommands"
2660 return
2661 fi
2662}
2663
2664_git_reset ()
2665{
2666 __git_has_doubledash && return
2667
2668 case "$cur" in
2669 --*)
2670 __gitcomp_builtin reset
2671 return
2672 ;;
2673 esac
2674 __git_complete_refs
2675}
2676
2677__git_revert_inprogress_options="--continue --quit --abort"
2678
2679_git_revert ()
2680{
2681 __git_find_repo_path
2682 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2683 __gitcomp "$__git_revert_inprogress_options"
2684 return
2685 fi
2686 case "$cur" in
2687 --*)
2688 __gitcomp_builtin revert "" \
2689 "$__git_revert_inprogress_options"
2690 return
2691 ;;
2692 esac
2693 __git_complete_refs
2694}
2695
2696_git_rm ()
2697{
2698 case "$cur" in
2699 --*)
2700 __gitcomp_builtin rm
2701 return
2702 ;;
2703 esac
2704
2705 __git_complete_index_file "--cached"
2706}
2707
2708_git_shortlog ()
2709{
2710 __git_has_doubledash && return
2711
2712 case "$cur" in
2713 --*)
2714 __gitcomp "
2715 $__git_log_common_options
2716 $__git_log_shortlog_options
2717 --numbered --summary --email
2718 "
2719 return
2720 ;;
2721 esac
2722 __git_complete_revlist
2723}
2724
2725_git_show ()
2726{
2727 __git_has_doubledash && return
2728
2729 case "$cur" in
2730 --pretty=*|--format=*)
2731 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2732 " "" "${cur#*=}"
2733 return
2734 ;;
2735 --diff-algorithm=*)
2736 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2737 return
2738 ;;
2739 --submodule=*)
2740 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2741 return
2742 ;;
2743 --*)
2744 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2745 --show-signature
2746 $__git_diff_common_options
2747 "
2748 return
2749 ;;
2750 esac
2751 __git_complete_revlist_file
2752}
2753
2754_git_show_branch ()
2755{
2756 case "$cur" in
2757 --*)
2758 __gitcomp_builtin show-branch
2759 return
2760 ;;
2761 esac
2762 __git_complete_revlist
2763}
2764
2765_git_stash ()
2766{
2767 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2768 local subcommands='push list show apply clear drop pop create branch'
2769 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
2770 if [ -n "$(__git_find_on_cmdline "-p")" ]; then
2771 subcommand="push"
2772 fi
2773 if [ -z "$subcommand" ]; then
2774 case "$cur" in
2775 --*)
2776 __gitcomp "$save_opts"
2777 ;;
2778 sa*)
2779 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2780 __gitcomp "save"
2781 fi
2782 ;;
2783 *)
2784 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2785 __gitcomp "$subcommands"
2786 fi
2787 ;;
2788 esac
2789 else
2790 case "$subcommand,$cur" in
2791 push,--*)
2792 __gitcomp "$save_opts --message"
2793 ;;
2794 save,--*)
2795 __gitcomp "$save_opts"
2796 ;;
2797 apply,--*|pop,--*)
2798 __gitcomp "--index --quiet"
2799 ;;
2800 drop,--*)
2801 __gitcomp "--quiet"
2802 ;;
2803 show,--*|branch,--*)
2804 ;;
2805 branch,*)
2806 if [ $cword -eq 3 ]; then
2807 __git_complete_refs
2808 else
2809 __gitcomp_nl "$(__git stash list \
2810 | sed -n -e 's/:.*//p')"
2811 fi
2812 ;;
2813 show,*|apply,*|drop,*|pop,*)
2814 __gitcomp_nl "$(__git stash list \
2815 | sed -n -e 's/:.*//p')"
2816 ;;
2817 *)
2818 ;;
2819 esac
2820 fi
2821}
2822
2823_git_submodule ()
2824{
2825 __git_has_doubledash && return
2826
2827 local subcommands="add status init deinit update summary foreach sync"
2828 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2829 if [ -z "$subcommand" ]; then
2830 case "$cur" in
2831 --*)
2832 __gitcomp "--quiet"
2833 ;;
2834 *)
2835 __gitcomp "$subcommands"
2836 ;;
2837 esac
2838 return
2839 fi
2840
2841 case "$subcommand,$cur" in
2842 add,--*)
2843 __gitcomp "--branch --force --name --reference --depth"
2844 ;;
2845 status,--*)
2846 __gitcomp "--cached --recursive"
2847 ;;
2848 deinit,--*)
2849 __gitcomp "--force --all"
2850 ;;
2851 update,--*)
2852 __gitcomp "
2853 --init --remote --no-fetch
2854 --recommend-shallow --no-recommend-shallow
2855 --force --rebase --merge --reference --depth --recursive --jobs
2856 "
2857 ;;
2858 summary,--*)
2859 __gitcomp "--cached --files --summary-limit"
2860 ;;
2861 foreach,--*|sync,--*)
2862 __gitcomp "--recursive"
2863 ;;
2864 *)
2865 ;;
2866 esac
2867}
2868
2869_git_svn ()
2870{
2871 local subcommands="
2872 init fetch clone rebase dcommit log find-rev
2873 set-tree commit-diff info create-ignore propget
2874 proplist show-ignore show-externals branch tag blame
2875 migrate mkdirs reset gc
2876 "
2877 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2878 if [ -z "$subcommand" ]; then
2879 __gitcomp "$subcommands"
2880 else
2881 local remote_opts="--username= --config-dir= --no-auth-cache"
2882 local fc_opts="
2883 --follow-parent --authors-file= --repack=
2884 --no-metadata --use-svm-props --use-svnsync-props
2885 --log-window-size= --no-checkout --quiet
2886 --repack-flags --use-log-author --localtime
2887 --add-author-from
2888 --ignore-paths= --include-paths= $remote_opts
2889 "
2890 local init_opts="
2891 --template= --shared= --trunk= --tags=
2892 --branches= --stdlayout --minimize-url
2893 --no-metadata --use-svm-props --use-svnsync-props
2894 --rewrite-root= --prefix= $remote_opts
2895 "
2896 local cmt_opts="
2897 --edit --rmdir --find-copies-harder --copy-similarity=
2898 "
2899
2900 case "$subcommand,$cur" in
2901 fetch,--*)
2902 __gitcomp "--revision= --fetch-all $fc_opts"
2903 ;;
2904 clone,--*)
2905 __gitcomp "--revision= $fc_opts $init_opts"
2906 ;;
2907 init,--*)
2908 __gitcomp "$init_opts"
2909 ;;
2910 dcommit,--*)
2911 __gitcomp "
2912 --merge --strategy= --verbose --dry-run
2913 --fetch-all --no-rebase --commit-url
2914 --revision --interactive $cmt_opts $fc_opts
2915 "
2916 ;;
2917 set-tree,--*)
2918 __gitcomp "--stdin $cmt_opts $fc_opts"
2919 ;;
2920 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2921 show-externals,--*|mkdirs,--*)
2922 __gitcomp "--revision="
2923 ;;
2924 log,--*)
2925 __gitcomp "
2926 --limit= --revision= --verbose --incremental
2927 --oneline --show-commit --non-recursive
2928 --authors-file= --color
2929 "
2930 ;;
2931 rebase,--*)
2932 __gitcomp "
2933 --merge --verbose --strategy= --local
2934 --fetch-all --dry-run $fc_opts
2935 "
2936 ;;
2937 commit-diff,--*)
2938 __gitcomp "--message= --file= --revision= $cmt_opts"
2939 ;;
2940 info,--*)
2941 __gitcomp "--url"
2942 ;;
2943 branch,--*)
2944 __gitcomp "--dry-run --message --tag"
2945 ;;
2946 tag,--*)
2947 __gitcomp "--dry-run --message"
2948 ;;
2949 blame,--*)
2950 __gitcomp "--git-format"
2951 ;;
2952 migrate,--*)
2953 __gitcomp "
2954 --config-dir= --ignore-paths= --minimize
2955 --no-auth-cache --username=
2956 "
2957 ;;
2958 reset,--*)
2959 __gitcomp "--revision= --parent"
2960 ;;
2961 *)
2962 ;;
2963 esac
2964 fi
2965}
2966
2967_git_tag ()
2968{
2969 local i c=1 f=0
2970 while [ $c -lt $cword ]; do
2971 i="${words[c]}"
2972 case "$i" in
2973 -d|--delete|-v|--verify)
2974 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2975 return
2976 ;;
2977 -f)
2978 f=1
2979 ;;
2980 esac
2981 ((c++))
2982 done
2983
2984 case "$prev" in
2985 -m|-F)
2986 ;;
2987 -*|tag)
2988 if [ $f = 1 ]; then
2989 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2990 fi
2991 ;;
2992 *)
2993 __git_complete_refs
2994 ;;
2995 esac
2996
2997 case "$cur" in
2998 --*)
2999 __gitcomp_builtin tag
3000 ;;
3001 esac
3002}
3003
3004_git_whatchanged ()
3005{
3006 _git_log
3007}
3008
3009_git_worktree ()
3010{
3011 local subcommands="add list lock move prune remove unlock"
3012 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3013 if [ -z "$subcommand" ]; then
3014 __gitcomp "$subcommands"
3015 else
3016 case "$subcommand,$cur" in
3017 add,--*)
3018 __gitcomp_builtin worktree_add
3019 ;;
3020 list,--*)
3021 __gitcomp_builtin worktree_list
3022 ;;
3023 lock,--*)
3024 __gitcomp_builtin worktree_lock
3025 ;;
3026 prune,--*)
3027 __gitcomp_builtin worktree_prune
3028 ;;
3029 remove,--*)
3030 __gitcomp "--force"
3031 ;;
3032 *)
3033 ;;
3034 esac
3035 fi
3036}
3037
3038__git_complete_common () {
3039 local command="$1"
3040
3041 case "$cur" in
3042 --*)
3043 __gitcomp_builtin "$command"
3044 ;;
3045 esac
3046}
3047
3048__git_cmds_with_parseopt_helper=
3049__git_support_parseopt_helper () {
3050 test -n "$__git_cmds_with_parseopt_helper" ||
3051 __git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
3052
3053 case " $__git_cmds_with_parseopt_helper " in
3054 *" $1 "*)
3055 return 0
3056 ;;
3057 *)
3058 return 1
3059 ;;
3060 esac
3061}
3062
3063__git_complete_command () {
3064 local command="$1"
3065 local completion_func="_git_${command//-/_}"
3066 if ! declare -f $completion_func >/dev/null 2>/dev/null &&
3067 declare -f _completion_loader >/dev/null 2>/dev/null
3068 then
3069 _completion_loader "git-$command"
3070 fi
3071 if declare -f $completion_func >/dev/null 2>/dev/null
3072 then
3073 $completion_func
3074 return 0
3075 elif __git_support_parseopt_helper "$command"
3076 then
3077 __git_complete_common "$command"
3078 return 0
3079 else
3080 return 1
3081 fi
3082}
3083
3084__git_main ()
3085{
3086 local i c=1 command __git_dir __git_repo_path
3087 local __git_C_args C_args_count=0
3088
3089 while [ $c -lt $cword ]; do
3090 i="${words[c]}"
3091 case "$i" in
3092 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
3093 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
3094 --bare) __git_dir="." ;;
3095 --help) command="help"; break ;;
3096 -c|--work-tree|--namespace) ((c++)) ;;
3097 -C) __git_C_args[C_args_count++]=-C
3098 ((c++))
3099 __git_C_args[C_args_count++]="${words[c]}"
3100 ;;
3101 -*) ;;
3102 *) command="$i"; break ;;
3103 esac
3104 ((c++))
3105 done
3106
3107 if [ -z "$command" ]; then
3108 case "$prev" in
3109 --git-dir|-C|--work-tree)
3110 # these need a path argument, let's fall back to
3111 # Bash filename completion
3112 return
3113 ;;
3114 -c|--namespace)
3115 # we don't support completing these options' arguments
3116 return
3117 ;;
3118 esac
3119 case "$cur" in
3120 --*) __gitcomp "
3121 --paginate
3122 --no-pager
3123 --git-dir=
3124 --bare
3125 --version
3126 --exec-path
3127 --exec-path=
3128 --html-path
3129 --man-path
3130 --info-path
3131 --work-tree=
3132 --namespace=
3133 --no-replace-objects
3134 --help
3135 "
3136 ;;
3137 *) __git_compute_porcelain_commands
3138 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
3139 esac
3140 return
3141 fi
3142
3143 __git_complete_command "$command" && return
3144
3145 local expansion=$(__git_aliased_command "$command")
3146 if [ -n "$expansion" ]; then
3147 words[1]=$expansion
3148 __git_complete_command "$expansion"
3149 fi
3150}
3151
3152__gitk_main ()
3153{
3154 __git_has_doubledash && return
3155
3156 local __git_repo_path
3157 __git_find_repo_path
3158
3159 local merge=""
3160 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3161 merge="--merge"
3162 fi
3163 case "$cur" in
3164 --*)
3165 __gitcomp "
3166 $__git_log_common_options
3167 $__git_log_gitk_options
3168 $merge
3169 "
3170 return
3171 ;;
3172 esac
3173 __git_complete_revlist
3174}
3175
3176if [[ -n ${ZSH_VERSION-} ]]; then
3177 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3178
3179 autoload -U +X compinit && compinit
3180
3181 __gitcomp ()
3182 {
3183 emulate -L zsh
3184
3185 local cur_="${3-$cur}"
3186
3187 case "$cur_" in
3188 --*=)
3189 ;;
3190 *)
3191 local c IFS=$' \t\n'
3192 local -a array
3193 for c in ${=1}; do
3194 c="$c${4-}"
3195 case $c in
3196 --*=*|*.) ;;
3197 *) c="$c " ;;
3198 esac
3199 array[${#array[@]}+1]="$c"
3200 done
3201 compset -P '*[=:]'
3202 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3203 ;;
3204 esac
3205 }
3206
3207 __gitcomp_direct ()
3208 {
3209 emulate -L zsh
3210
3211 local IFS=$'\n'
3212 compset -P '*[=:]'
3213 compadd -Q -- ${=1} && _ret=0
3214 }
3215
3216 __gitcomp_nl ()
3217 {
3218 emulate -L zsh
3219
3220 local IFS=$'\n'
3221 compset -P '*[=:]'
3222 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3223 }
3224
3225 __gitcomp_file ()
3226 {
3227 emulate -L zsh
3228
3229 local IFS=$'\n'
3230 compset -P '*[=:]'
3231 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3232 }
3233
3234 _git ()
3235 {
3236 local _ret=1 cur cword prev
3237 cur=${words[CURRENT]}
3238 prev=${words[CURRENT-1]}
3239 let cword=CURRENT-1
3240 emulate ksh -c __${service}_main
3241 let _ret && _default && _ret=0
3242 return _ret
3243 }
3244
3245 compdef _git git gitk
3246 return
3247fi
3248
3249__git_func_wrap ()
3250{
3251 local cur words cword prev
3252 _get_comp_words_by_ref -n =: cur words cword prev
3253 $1
3254}
3255
3256# Setup completion for certain functions defined above by setting common
3257# variables and workarounds.
3258# This is NOT a public function; use at your own risk.
3259__git_complete ()
3260{
3261 local wrapper="__git_wrap${2}"
3262 eval "$wrapper () { __git_func_wrap $2 ; }"
3263 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3264 || complete -o default -o nospace -F $wrapper $1
3265}
3266
3267# wrapper for backwards compatibility
3268_git ()
3269{
3270 __git_wrap__git_main
3271}
3272
3273# wrapper for backwards compatibility
3274_gitk ()
3275{
3276 __git_wrap__gitk_main
3277}
3278
3279__git_complete git __git_main
3280__git_complete gitk __gitk_main
3281
3282# The following are necessary only for Cygwin, and only are needed
3283# when the user has tab-completed the executable name and consequently
3284# included the '.exe' suffix.
3285#
3286if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3287__git_complete git.exe __git_main
3288fi