57fc7417f9bfd30710de5d84ca0ef461663b98c4
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# __git_complete_index_file requires 1 argument:
402# 1: the options to pass to ls-file
403#
404# The exception is --committable, which finds the files appropriate commit.
405__git_complete_index_file ()
406{
407 local pfx="" cur_="$cur"
408
409 case "$cur_" in
410 ?*/*)
411 pfx="${cur_%/*}/"
412 cur_="${cur_##*/}"
413 ;;
414 esac
415
416 __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
417}
418
419# Lists branches from the local repository.
420# 1: A prefix to be added to each listed branch (optional).
421# 2: List only branches matching this word (optional; list all branches if
422# unset or empty).
423# 3: A suffix to be appended to each listed branch (optional).
424__git_heads ()
425{
426 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
427
428 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
429 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
430}
431
432# Lists tags from the local repository.
433# Accepts the same positional parameters as __git_heads() above.
434__git_tags ()
435{
436 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
437
438 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
439 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
440}
441
442# Lists refs from the local (by default) or from a remote repository.
443# It accepts 0, 1 or 2 arguments:
444# 1: The remote to list refs from (optional; ignored, if set but empty).
445# Can be the name of a configured remote, a path, or a URL.
446# 2: In addition to local refs, list unique branches from refs/remotes/ for
447# 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
448# 3: A prefix to be added to each listed ref (optional).
449# 4: List only refs matching this word (optional; list all refs if unset or
450# empty).
451# 5: A suffix to be appended to each listed ref (optional; ignored, if set
452# but empty).
453#
454# Use __git_complete_refs() instead.
455__git_refs ()
456{
457 local i hash dir track="${2-}"
458 local list_refs_from=path remote="${1-}"
459 local format refs
460 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
461 local match="${4-}"
462 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
463
464 __git_find_repo_path
465 dir="$__git_repo_path"
466
467 if [ -z "$remote" ]; then
468 if [ -z "$dir" ]; then
469 return
470 fi
471 else
472 if __git_is_configured_remote "$remote"; then
473 # configured remote takes precedence over a
474 # local directory with the same name
475 list_refs_from=remote
476 elif [ -d "$remote/.git" ]; then
477 dir="$remote/.git"
478 elif [ -d "$remote" ]; then
479 dir="$remote"
480 else
481 list_refs_from=url
482 fi
483 fi
484
485 if [ "$list_refs_from" = path ]; then
486 if [[ "$cur_" == ^* ]]; then
487 pfx="$pfx^"
488 fer_pfx="$fer_pfx^"
489 cur_=${cur_#^}
490 match=${match#^}
491 fi
492 case "$cur_" in
493 refs|refs/*)
494 format="refname"
495 refs=("$match*" "$match*/**")
496 track=""
497 ;;
498 *)
499 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
500 case "$i" in
501 $match*)
502 if [ -e "$dir/$i" ]; then
503 echo "$pfx$i$sfx"
504 fi
505 ;;
506 esac
507 done
508 format="refname:strip=2"
509 refs=("refs/tags/$match*" "refs/tags/$match*/**"
510 "refs/heads/$match*" "refs/heads/$match*/**"
511 "refs/remotes/$match*" "refs/remotes/$match*/**")
512 ;;
513 esac
514 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
515 "${refs[@]}"
516 if [ -n "$track" ]; then
517 # employ the heuristic used by git checkout
518 # Try to find a remote branch that matches the completion word
519 # but only output if the branch name is unique
520 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
521 --sort="refname:strip=3" \
522 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
523 uniq -u
524 fi
525 return
526 fi
527 case "$cur_" in
528 refs|refs/*)
529 __git ls-remote "$remote" "$match*" | \
530 while read -r hash i; do
531 case "$i" in
532 *^{}) ;;
533 *) echo "$pfx$i$sfx" ;;
534 esac
535 done
536 ;;
537 *)
538 if [ "$list_refs_from" = remote ]; then
539 case "HEAD" in
540 $match*) echo "${pfx}HEAD$sfx" ;;
541 esac
542 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
543 "refs/remotes/$remote/$match*" \
544 "refs/remotes/$remote/$match*/**"
545 else
546 local query_symref
547 case "HEAD" in
548 $match*) query_symref="HEAD" ;;
549 esac
550 __git ls-remote "$remote" $query_symref \
551 "refs/tags/$match*" "refs/heads/$match*" \
552 "refs/remotes/$match*" |
553 while read -r hash i; do
554 case "$i" in
555 *^{}) ;;
556 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
557 *) echo "$pfx$i$sfx" ;; # symbolic refs
558 esac
559 done
560 fi
561 ;;
562 esac
563}
564
565# Completes refs, short and long, local and remote, symbolic and pseudo.
566#
567# Usage: __git_complete_refs [<option>]...
568# --remote=<remote>: The remote to list refs from, can be the name of a
569# configured remote, a path, or a URL.
570# --track: List unique remote branches for 'git checkout's tracking DWIMery.
571# --pfx=<prefix>: A prefix to be added to each ref.
572# --cur=<word>: The current ref to be completed. Defaults to the current
573# word to be completed.
574# --sfx=<suffix>: A suffix to be appended to each ref instead of the default
575# space.
576__git_complete_refs ()
577{
578 local remote track pfx cur_="$cur" sfx=" "
579
580 while test $# != 0; do
581 case "$1" in
582 --remote=*) remote="${1##--remote=}" ;;
583 --track) track="yes" ;;
584 --pfx=*) pfx="${1##--pfx=}" ;;
585 --cur=*) cur_="${1##--cur=}" ;;
586 --sfx=*) sfx="${1##--sfx=}" ;;
587 *) return 1 ;;
588 esac
589 shift
590 done
591
592 __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
593}
594
595# __git_refs2 requires 1 argument (to pass to __git_refs)
596# Deprecated: use __git_complete_fetch_refspecs() instead.
597__git_refs2 ()
598{
599 local i
600 for i in $(__git_refs "$1"); do
601 echo "$i:$i"
602 done
603}
604
605# Completes refspecs for fetching from a remote repository.
606# 1: The remote repository.
607# 2: A prefix to be added to each listed refspec (optional).
608# 3: The ref to be completed as a refspec instead of the current word to be
609# completed (optional)
610# 4: A suffix to be appended to each listed refspec instead of the default
611# space (optional).
612__git_complete_fetch_refspecs ()
613{
614 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
615
616 __gitcomp_direct "$(
617 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
618 echo "$pfx$i:$i$sfx"
619 done
620 )"
621}
622
623# __git_refs_remotes requires 1 argument (to pass to ls-remote)
624__git_refs_remotes ()
625{
626 local i hash
627 __git ls-remote "$1" 'refs/heads/*' | \
628 while read -r hash i; do
629 echo "$i:refs/remotes/$1/${i#refs/heads/}"
630 done
631}
632
633__git_remotes ()
634{
635 __git_find_repo_path
636 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
637 __git remote
638}
639
640# Returns true if $1 matches the name of a configured remote, false otherwise.
641__git_is_configured_remote ()
642{
643 local remote
644 for remote in $(__git_remotes); do
645 if [ "$remote" = "$1" ]; then
646 return 0
647 fi
648 done
649 return 1
650}
651
652__git_list_merge_strategies ()
653{
654 LANG=C LC_ALL=C git merge -s help 2>&1 |
655 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
656 s/\.$//
657 s/.*://
658 s/^[ ]*//
659 s/[ ]*$//
660 p
661 }'
662}
663
664__git_merge_strategies=
665# 'git merge -s help' (and thus detection of the merge strategy
666# list) fails, unfortunately, if run outside of any git working
667# tree. __git_merge_strategies is set to the empty string in
668# that case, and the detection will be repeated the next time it
669# is needed.
670__git_compute_merge_strategies ()
671{
672 test -n "$__git_merge_strategies" ||
673 __git_merge_strategies=$(__git_list_merge_strategies)
674}
675
676__git_complete_revlist_file ()
677{
678 local pfx ls ref cur_="$cur"
679 case "$cur_" in
680 *..?*:*)
681 return
682 ;;
683 ?*:*)
684 ref="${cur_%%:*}"
685 cur_="${cur_#*:}"
686 case "$cur_" in
687 ?*/*)
688 pfx="${cur_%/*}"
689 cur_="${cur_##*/}"
690 ls="$ref:$pfx"
691 pfx="$pfx/"
692 ;;
693 *)
694 ls="$ref"
695 ;;
696 esac
697
698 case "$COMP_WORDBREAKS" in
699 *:*) : great ;;
700 *) pfx="$ref:$pfx" ;;
701 esac
702
703 __gitcomp_nl "$(__git ls-tree "$ls" \
704 | sed '/^100... blob /{
705 s,^.* ,,
706 s,$, ,
707 }
708 /^120000 blob /{
709 s,^.* ,,
710 s,$, ,
711 }
712 /^040000 tree /{
713 s,^.* ,,
714 s,$,/,
715 }
716 s/^.* //')" \
717 "$pfx" "$cur_" ""
718 ;;
719 *...*)
720 pfx="${cur_%...*}..."
721 cur_="${cur_#*...}"
722 __git_complete_refs --pfx="$pfx" --cur="$cur_"
723 ;;
724 *..*)
725 pfx="${cur_%..*}.."
726 cur_="${cur_#*..}"
727 __git_complete_refs --pfx="$pfx" --cur="$cur_"
728 ;;
729 *)
730 __git_complete_refs
731 ;;
732 esac
733}
734
735__git_complete_file ()
736{
737 __git_complete_revlist_file
738}
739
740__git_complete_revlist ()
741{
742 __git_complete_revlist_file
743}
744
745__git_complete_remote_or_refspec ()
746{
747 local cur_="$cur" cmd="${words[1]}"
748 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
749 if [ "$cmd" = "remote" ]; then
750 ((c++))
751 fi
752 while [ $c -lt $cword ]; do
753 i="${words[c]}"
754 case "$i" in
755 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
756 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
757 --all)
758 case "$cmd" in
759 push) no_complete_refspec=1 ;;
760 fetch)
761 return
762 ;;
763 *) ;;
764 esac
765 ;;
766 -*) ;;
767 *) remote="$i"; break ;;
768 esac
769 ((c++))
770 done
771 if [ -z "$remote" ]; then
772 __gitcomp_nl "$(__git_remotes)"
773 return
774 fi
775 if [ $no_complete_refspec = 1 ]; then
776 return
777 fi
778 [ "$remote" = "." ] && remote=
779 case "$cur_" in
780 *:*)
781 case "$COMP_WORDBREAKS" in
782 *:*) : great ;;
783 *) pfx="${cur_%%:*}:" ;;
784 esac
785 cur_="${cur_#*:}"
786 lhs=0
787 ;;
788 +*)
789 pfx="+"
790 cur_="${cur_#+}"
791 ;;
792 esac
793 case "$cmd" in
794 fetch)
795 if [ $lhs = 1 ]; then
796 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
797 else
798 __git_complete_refs --pfx="$pfx" --cur="$cur_"
799 fi
800 ;;
801 pull|remote)
802 if [ $lhs = 1 ]; then
803 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
804 else
805 __git_complete_refs --pfx="$pfx" --cur="$cur_"
806 fi
807 ;;
808 push)
809 if [ $lhs = 1 ]; then
810 __git_complete_refs --pfx="$pfx" --cur="$cur_"
811 else
812 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
813 fi
814 ;;
815 esac
816}
817
818__git_complete_strategy ()
819{
820 __git_compute_merge_strategies
821 case "$prev" in
822 -s|--strategy)
823 __gitcomp "$__git_merge_strategies"
824 return 0
825 esac
826 case "$cur" in
827 --strategy=*)
828 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
829 return 0
830 ;;
831 esac
832 return 1
833}
834
835__git_commands () {
836 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
837 then
838 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
839 else
840 git help -a|egrep '^ [a-zA-Z0-9]'
841 fi
842}
843
844__git_list_all_commands ()
845{
846 local i IFS=" "$'\n'
847 for i in $(__git_commands)
848 do
849 case $i in
850 *--*) : helper pattern;;
851 *) echo $i;;
852 esac
853 done
854}
855
856__git_all_commands=
857__git_compute_all_commands ()
858{
859 test -n "$__git_all_commands" ||
860 __git_all_commands=$(__git_list_all_commands)
861}
862
863__git_list_porcelain_commands ()
864{
865 local i IFS=" "$'\n'
866 __git_compute_all_commands
867 for i in $__git_all_commands
868 do
869 case $i in
870 *--*) : helper pattern;;
871 applymbox) : ask gittus;;
872 applypatch) : ask gittus;;
873 archimport) : import;;
874 cat-file) : plumbing;;
875 check-attr) : plumbing;;
876 check-ignore) : plumbing;;
877 check-mailmap) : plumbing;;
878 check-ref-format) : plumbing;;
879 checkout-index) : plumbing;;
880 column) : internal helper;;
881 commit-tree) : plumbing;;
882 count-objects) : infrequent;;
883 credential) : credentials;;
884 credential-*) : credentials helper;;
885 cvsexportcommit) : export;;
886 cvsimport) : import;;
887 cvsserver) : daemon;;
888 daemon) : daemon;;
889 diff-files) : plumbing;;
890 diff-index) : plumbing;;
891 diff-tree) : plumbing;;
892 fast-import) : import;;
893 fast-export) : export;;
894 fsck-objects) : plumbing;;
895 fetch-pack) : plumbing;;
896 fmt-merge-msg) : plumbing;;
897 for-each-ref) : plumbing;;
898 hash-object) : plumbing;;
899 http-*) : transport;;
900 index-pack) : plumbing;;
901 init-db) : deprecated;;
902 local-fetch) : plumbing;;
903 ls-files) : plumbing;;
904 ls-remote) : plumbing;;
905 ls-tree) : plumbing;;
906 mailinfo) : plumbing;;
907 mailsplit) : plumbing;;
908 merge-*) : plumbing;;
909 mktree) : plumbing;;
910 mktag) : plumbing;;
911 pack-objects) : plumbing;;
912 pack-redundant) : plumbing;;
913 pack-refs) : plumbing;;
914 parse-remote) : plumbing;;
915 patch-id) : plumbing;;
916 prune) : plumbing;;
917 prune-packed) : plumbing;;
918 quiltimport) : import;;
919 read-tree) : plumbing;;
920 receive-pack) : plumbing;;
921 remote-*) : transport;;
922 rerere) : plumbing;;
923 rev-list) : plumbing;;
924 rev-parse) : plumbing;;
925 runstatus) : plumbing;;
926 sh-setup) : internal;;
927 shell) : daemon;;
928 show-ref) : plumbing;;
929 send-pack) : plumbing;;
930 show-index) : plumbing;;
931 ssh-*) : transport;;
932 stripspace) : plumbing;;
933 symbolic-ref) : plumbing;;
934 unpack-file) : plumbing;;
935 unpack-objects) : plumbing;;
936 update-index) : plumbing;;
937 update-ref) : plumbing;;
938 update-server-info) : daemon;;
939 upload-archive) : plumbing;;
940 upload-pack) : plumbing;;
941 write-tree) : plumbing;;
942 var) : infrequent;;
943 verify-pack) : infrequent;;
944 verify-tag) : plumbing;;
945 *) echo $i;;
946 esac
947 done
948}
949
950__git_porcelain_commands=
951__git_compute_porcelain_commands ()
952{
953 test -n "$__git_porcelain_commands" ||
954 __git_porcelain_commands=$(__git_list_porcelain_commands)
955}
956
957# Lists all set config variables starting with the given section prefix,
958# with the prefix removed.
959__git_get_config_variables ()
960{
961 local section="$1" i IFS=$'\n'
962 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
963 echo "${i#$section.}"
964 done
965}
966
967__git_pretty_aliases ()
968{
969 __git_get_config_variables "pretty"
970}
971
972__git_aliases ()
973{
974 __git_get_config_variables "alias"
975}
976
977# __git_aliased_command requires 1 argument
978__git_aliased_command ()
979{
980 local word cmdline=$(__git config --get "alias.$1")
981 for word in $cmdline; do
982 case "$word" in
983 \!gitk|gitk)
984 echo "gitk"
985 return
986 ;;
987 \!*) : shell command alias ;;
988 -*) : option ;;
989 *=*) : setting env ;;
990 git) : git itself ;;
991 \(\)) : skip parens of shell function definition ;;
992 {) : skip start of shell helper function ;;
993 :) : skip null command ;;
994 \'*) : skip opening quote after sh -c ;;
995 *)
996 echo "$word"
997 return
998 esac
999 done
1000}
1001
1002# __git_find_on_cmdline requires 1 argument
1003__git_find_on_cmdline ()
1004{
1005 local word subcommand c=1
1006 while [ $c -lt $cword ]; do
1007 word="${words[c]}"
1008 for subcommand in $1; do
1009 if [ "$subcommand" = "$word" ]; then
1010 echo "$subcommand"
1011 return
1012 fi
1013 done
1014 ((c++))
1015 done
1016}
1017
1018# Echo the value of an option set on the command line or config
1019#
1020# $1: short option name
1021# $2: long option name including =
1022# $3: list of possible values
1023# $4: config string (optional)
1024#
1025# example:
1026# result="$(__git_get_option_value "-d" "--do-something=" \
1027# "yes no" "core.doSomething")"
1028#
1029# result is then either empty (no option set) or "yes" or "no"
1030#
1031# __git_get_option_value requires 3 arguments
1032__git_get_option_value ()
1033{
1034 local c short_opt long_opt val
1035 local result= values config_key word
1036
1037 short_opt="$1"
1038 long_opt="$2"
1039 values="$3"
1040 config_key="$4"
1041
1042 ((c = $cword - 1))
1043 while [ $c -ge 0 ]; do
1044 word="${words[c]}"
1045 for val in $values; do
1046 if [ "$short_opt$val" = "$word" ] ||
1047 [ "$long_opt$val" = "$word" ]; then
1048 result="$val"
1049 break 2
1050 fi
1051 done
1052 ((c--))
1053 done
1054
1055 if [ -n "$config_key" ] && [ -z "$result" ]; then
1056 result="$(__git config "$config_key")"
1057 fi
1058
1059 echo "$result"
1060}
1061
1062__git_has_doubledash ()
1063{
1064 local c=1
1065 while [ $c -lt $cword ]; do
1066 if [ "--" = "${words[c]}" ]; then
1067 return 0
1068 fi
1069 ((c++))
1070 done
1071 return 1
1072}
1073
1074# Try to count non option arguments passed on the command line for the
1075# specified git command.
1076# When options are used, it is necessary to use the special -- option to
1077# tell the implementation were non option arguments begin.
1078# XXX this can not be improved, since options can appear everywhere, as
1079# an example:
1080# git mv x -n y
1081#
1082# __git_count_arguments requires 1 argument: the git command executed.
1083__git_count_arguments ()
1084{
1085 local word i c=0
1086
1087 # Skip "git" (first argument)
1088 for ((i=1; i < ${#words[@]}; i++)); do
1089 word="${words[i]}"
1090
1091 case "$word" in
1092 --)
1093 # Good; we can assume that the following are only non
1094 # option arguments.
1095 ((c = 0))
1096 ;;
1097 "$1")
1098 # Skip the specified git command and discard git
1099 # main options
1100 ((c = 0))
1101 ;;
1102 ?*)
1103 ((c++))
1104 ;;
1105 esac
1106 done
1107
1108 printf "%d" $c
1109}
1110
1111__git_whitespacelist="nowarn warn error error-all fix"
1112__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1113
1114_git_am ()
1115{
1116 __git_find_repo_path
1117 if [ -d "$__git_repo_path"/rebase-apply ]; then
1118 __gitcomp "$__git_am_inprogress_options"
1119 return
1120 fi
1121 case "$cur" in
1122 --whitespace=*)
1123 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1124 return
1125 ;;
1126 --*)
1127 __gitcomp_builtin am "--no-utf8" \
1128 "$__git_am_inprogress_options"
1129 return
1130 esac
1131}
1132
1133_git_apply ()
1134{
1135 case "$cur" in
1136 --whitespace=*)
1137 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1138 return
1139 ;;
1140 --*)
1141 __gitcomp_builtin apply
1142 return
1143 esac
1144}
1145
1146_git_add ()
1147{
1148 case "$cur" in
1149 --*)
1150 __gitcomp_builtin add
1151 return
1152 esac
1153
1154 local complete_opt="--others --modified --directory --no-empty-directory"
1155 if test -n "$(__git_find_on_cmdline "-u --update")"
1156 then
1157 complete_opt="--modified"
1158 fi
1159 __git_complete_index_file "$complete_opt"
1160}
1161
1162_git_archive ()
1163{
1164 case "$cur" in
1165 --format=*)
1166 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1167 return
1168 ;;
1169 --remote=*)
1170 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1171 return
1172 ;;
1173 --*)
1174 __gitcomp "
1175 --format= --list --verbose
1176 --prefix= --remote= --exec= --output
1177 "
1178 return
1179 ;;
1180 esac
1181 __git_complete_file
1182}
1183
1184_git_bisect ()
1185{
1186 __git_has_doubledash && return
1187
1188 local subcommands="start bad good skip reset visualize replay log run"
1189 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1190 if [ -z "$subcommand" ]; then
1191 __git_find_repo_path
1192 if [ -f "$__git_repo_path"/BISECT_START ]; then
1193 __gitcomp "$subcommands"
1194 else
1195 __gitcomp "replay start"
1196 fi
1197 return
1198 fi
1199
1200 case "$subcommand" in
1201 bad|good|reset|skip|start)
1202 __git_complete_refs
1203 ;;
1204 *)
1205 ;;
1206 esac
1207}
1208
1209_git_branch ()
1210{
1211 local i c=1 only_local_ref="n" has_r="n"
1212
1213 while [ $c -lt $cword ]; do
1214 i="${words[c]}"
1215 case "$i" in
1216 -d|--delete|-m|--move) only_local_ref="y" ;;
1217 -r|--remotes) has_r="y" ;;
1218 esac
1219 ((c++))
1220 done
1221
1222 case "$cur" in
1223 --set-upstream-to=*)
1224 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1225 ;;
1226 --*)
1227 __gitcomp_builtin branch "--no-color --no-abbrev
1228 --no-track --no-column
1229 "
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 "--no-track --no-recurse-submodules"
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 "--no-single-branch"
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 "--no-edit --verify"
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 "--no-tags"
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 "--no-reflogs"
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 "--no-empty-directory"
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 "--no-rerere-autoupdate
1765 --no-commit --no-edit --no-ff
1766 --no-log --no-progress
1767 --no-squash --no-stat
1768 --no-verify-signatures
1769 "
1770 return
1771 esac
1772 __git_complete_refs
1773}
1774
1775_git_mergetool ()
1776{
1777 case "$cur" in
1778 --tool=*)
1779 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1780 return
1781 ;;
1782 --*)
1783 __gitcomp "--tool= --prompt --no-prompt"
1784 return
1785 ;;
1786 esac
1787}
1788
1789_git_merge_base ()
1790{
1791 case "$cur" in
1792 --*)
1793 __gitcomp_builtin merge-base
1794 return
1795 ;;
1796 esac
1797 __git_complete_refs
1798}
1799
1800_git_mv ()
1801{
1802 case "$cur" in
1803 --*)
1804 __gitcomp_builtin mv
1805 return
1806 ;;
1807 esac
1808
1809 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1810 # We need to show both cached and untracked files (including
1811 # empty directories) since this may not be the last argument.
1812 __git_complete_index_file "--cached --others --directory"
1813 else
1814 __git_complete_index_file "--cached"
1815 fi
1816}
1817
1818_git_notes ()
1819{
1820 local subcommands='add append copy edit get-ref list merge prune remove show'
1821 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1822
1823 case "$subcommand,$cur" in
1824 ,--*)
1825 __gitcomp_builtin notes
1826 ;;
1827 ,*)
1828 case "$prev" in
1829 --ref)
1830 __git_complete_refs
1831 ;;
1832 *)
1833 __gitcomp "$subcommands --ref"
1834 ;;
1835 esac
1836 ;;
1837 *,--reuse-message=*|*,--reedit-message=*)
1838 __git_complete_refs --cur="${cur#*=}"
1839 ;;
1840 *,--*)
1841 __gitcomp_builtin notes_$subcommand
1842 ;;
1843 prune,*|get-ref,*)
1844 # this command does not take a ref, do not complete it
1845 ;;
1846 *)
1847 case "$prev" in
1848 -m|-F)
1849 ;;
1850 *)
1851 __git_complete_refs
1852 ;;
1853 esac
1854 ;;
1855 esac
1856}
1857
1858_git_pull ()
1859{
1860 __git_complete_strategy && return
1861
1862 case "$cur" in
1863 --recurse-submodules=*)
1864 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1865 return
1866 ;;
1867 --*)
1868 __gitcomp_builtin pull "--no-autostash --no-commit --no-edit
1869 --no-ff --no-log --no-progress --no-rebase
1870 --no-squash --no-stat --no-tags
1871 --no-verify-signatures"
1872
1873 return
1874 ;;
1875 esac
1876 __git_complete_remote_or_refspec
1877}
1878
1879__git_push_recurse_submodules="check on-demand only"
1880
1881__git_complete_force_with_lease ()
1882{
1883 local cur_=$1
1884
1885 case "$cur_" in
1886 --*=)
1887 ;;
1888 *:*)
1889 __git_complete_refs --cur="${cur_#*:}"
1890 ;;
1891 *)
1892 __git_complete_refs --cur="$cur_"
1893 ;;
1894 esac
1895}
1896
1897_git_push ()
1898{
1899 case "$prev" in
1900 --repo)
1901 __gitcomp_nl "$(__git_remotes)"
1902 return
1903 ;;
1904 --recurse-submodules)
1905 __gitcomp "$__git_push_recurse_submodules"
1906 return
1907 ;;
1908 esac
1909 case "$cur" in
1910 --repo=*)
1911 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1912 return
1913 ;;
1914 --recurse-submodules=*)
1915 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1916 return
1917 ;;
1918 --force-with-lease=*)
1919 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1920 return
1921 ;;
1922 --*)
1923 __gitcomp_builtin push
1924 return
1925 ;;
1926 esac
1927 __git_complete_remote_or_refspec
1928}
1929
1930_git_rebase ()
1931{
1932 __git_find_repo_path
1933 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1934 __gitcomp "--continue --skip --abort --quit --edit-todo --show-current-patch"
1935 return
1936 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1937 [ -d "$__git_repo_path"/rebase-merge ]; then
1938 __gitcomp "--continue --skip --abort --quit --show-current-patch"
1939 return
1940 fi
1941 __git_complete_strategy && return
1942 case "$cur" in
1943 --whitespace=*)
1944 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1945 return
1946 ;;
1947 --*)
1948 __gitcomp "
1949 --onto --merge --strategy --interactive
1950 --preserve-merges --stat --no-stat
1951 --committer-date-is-author-date --ignore-date
1952 --ignore-whitespace --whitespace=
1953 --autosquash --no-autosquash
1954 --fork-point --no-fork-point
1955 --autostash --no-autostash
1956 --verify --no-verify
1957 --keep-empty --root --force-rebase --no-ff
1958 --rerere-autoupdate
1959 --exec
1960 "
1961
1962 return
1963 esac
1964 __git_complete_refs
1965}
1966
1967_git_reflog ()
1968{
1969 local subcommands="show delete expire"
1970 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1971
1972 if [ -z "$subcommand" ]; then
1973 __gitcomp "$subcommands"
1974 else
1975 __git_complete_refs
1976 fi
1977}
1978
1979__git_send_email_confirm_options="always never auto cc compose"
1980__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1981
1982_git_send_email ()
1983{
1984 case "$prev" in
1985 --to|--cc|--bcc|--from)
1986 __gitcomp "$(__git send-email --dump-aliases)"
1987 return
1988 ;;
1989 esac
1990
1991 case "$cur" in
1992 --confirm=*)
1993 __gitcomp "
1994 $__git_send_email_confirm_options
1995 " "" "${cur##--confirm=}"
1996 return
1997 ;;
1998 --suppress-cc=*)
1999 __gitcomp "
2000 $__git_send_email_suppresscc_options
2001 " "" "${cur##--suppress-cc=}"
2002
2003 return
2004 ;;
2005 --smtp-encryption=*)
2006 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2007 return
2008 ;;
2009 --thread=*)
2010 __gitcomp "
2011 deep shallow
2012 " "" "${cur##--thread=}"
2013 return
2014 ;;
2015 --to=*|--cc=*|--bcc=*|--from=*)
2016 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2017 return
2018 ;;
2019 --*)
2020 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2021 --compose --confirm= --dry-run --envelope-sender
2022 --from --identity
2023 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2024 --no-suppress-from --no-thread --quiet --reply-to
2025 --signed-off-by-cc --smtp-pass --smtp-server
2026 --smtp-server-port --smtp-encryption= --smtp-user
2027 --subject --suppress-cc= --suppress-from --thread --to
2028 --validate --no-validate
2029 $__git_format_patch_options"
2030 return
2031 ;;
2032 esac
2033 __git_complete_revlist
2034}
2035
2036_git_stage ()
2037{
2038 _git_add
2039}
2040
2041_git_status ()
2042{
2043 local complete_opt
2044 local untracked_state
2045
2046 case "$cur" in
2047 --ignore-submodules=*)
2048 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2049 return
2050 ;;
2051 --untracked-files=*)
2052 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2053 return
2054 ;;
2055 --column=*)
2056 __gitcomp "
2057 always never auto column row plain dense nodense
2058 " "" "${cur##--column=}"
2059 return
2060 ;;
2061 --*)
2062 __gitcomp_builtin status "--no-column"
2063 return
2064 ;;
2065 esac
2066
2067 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2068 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2069
2070 case "$untracked_state" in
2071 no)
2072 # --ignored option does not matter
2073 complete_opt=
2074 ;;
2075 all|normal|*)
2076 complete_opt="--cached --directory --no-empty-directory --others"
2077
2078 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2079 complete_opt="$complete_opt --ignored --exclude=*"
2080 fi
2081 ;;
2082 esac
2083
2084 __git_complete_index_file "$complete_opt"
2085}
2086
2087__git_config_get_set_variables ()
2088{
2089 local prevword word config_file= c=$cword
2090 while [ $c -gt 1 ]; do
2091 word="${words[c]}"
2092 case "$word" in
2093 --system|--global|--local|--file=*)
2094 config_file="$word"
2095 break
2096 ;;
2097 -f|--file)
2098 config_file="$word $prevword"
2099 break
2100 ;;
2101 esac
2102 prevword=$word
2103 c=$((--c))
2104 done
2105
2106 __git config $config_file --name-only --list
2107}
2108
2109_git_config ()
2110{
2111 case "$prev" in
2112 branch.*.remote|branch.*.pushremote)
2113 __gitcomp_nl "$(__git_remotes)"
2114 return
2115 ;;
2116 branch.*.merge)
2117 __git_complete_refs
2118 return
2119 ;;
2120 branch.*.rebase)
2121 __gitcomp "false true preserve interactive"
2122 return
2123 ;;
2124 remote.pushdefault)
2125 __gitcomp_nl "$(__git_remotes)"
2126 return
2127 ;;
2128 remote.*.fetch)
2129 local remote="${prev#remote.}"
2130 remote="${remote%.fetch}"
2131 if [ -z "$cur" ]; then
2132 __gitcomp_nl "refs/heads/" "" "" ""
2133 return
2134 fi
2135 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2136 return
2137 ;;
2138 remote.*.push)
2139 local remote="${prev#remote.}"
2140 remote="${remote%.push}"
2141 __gitcomp_nl "$(__git for-each-ref \
2142 --format='%(refname):%(refname)' refs/heads)"
2143 return
2144 ;;
2145 pull.twohead|pull.octopus)
2146 __git_compute_merge_strategies
2147 __gitcomp "$__git_merge_strategies"
2148 return
2149 ;;
2150 color.branch|color.diff|color.interactive|\
2151 color.showbranch|color.status|color.ui)
2152 __gitcomp "always never auto"
2153 return
2154 ;;
2155 color.pager)
2156 __gitcomp "false true"
2157 return
2158 ;;
2159 color.*.*)
2160 __gitcomp "
2161 normal black red green yellow blue magenta cyan white
2162 bold dim ul blink reverse
2163 "
2164 return
2165 ;;
2166 diff.submodule)
2167 __gitcomp "log short"
2168 return
2169 ;;
2170 help.format)
2171 __gitcomp "man info web html"
2172 return
2173 ;;
2174 log.date)
2175 __gitcomp "$__git_log_date_formats"
2176 return
2177 ;;
2178 sendemail.aliasesfiletype)
2179 __gitcomp "mutt mailrc pine elm gnus"
2180 return
2181 ;;
2182 sendemail.confirm)
2183 __gitcomp "$__git_send_email_confirm_options"
2184 return
2185 ;;
2186 sendemail.suppresscc)
2187 __gitcomp "$__git_send_email_suppresscc_options"
2188 return
2189 ;;
2190 sendemail.transferencoding)
2191 __gitcomp "7bit 8bit quoted-printable base64"
2192 return
2193 ;;
2194 --get|--get-all|--unset|--unset-all)
2195 __gitcomp_nl "$(__git_config_get_set_variables)"
2196 return
2197 ;;
2198 *.*)
2199 return
2200 ;;
2201 esac
2202 case "$cur" in
2203 --*)
2204 __gitcomp_builtin config
2205 return
2206 ;;
2207 branch.*.*)
2208 local pfx="${cur%.*}." cur_="${cur##*.}"
2209 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2210 return
2211 ;;
2212 branch.*)
2213 local pfx="${cur%.*}." cur_="${cur#*.}"
2214 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2215 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2216 return
2217 ;;
2218 guitool.*.*)
2219 local pfx="${cur%.*}." cur_="${cur##*.}"
2220 __gitcomp "
2221 argprompt cmd confirm needsfile noconsole norescan
2222 prompt revprompt revunmerged title
2223 " "$pfx" "$cur_"
2224 return
2225 ;;
2226 difftool.*.*)
2227 local pfx="${cur%.*}." cur_="${cur##*.}"
2228 __gitcomp "cmd path" "$pfx" "$cur_"
2229 return
2230 ;;
2231 man.*.*)
2232 local pfx="${cur%.*}." cur_="${cur##*.}"
2233 __gitcomp "cmd path" "$pfx" "$cur_"
2234 return
2235 ;;
2236 mergetool.*.*)
2237 local pfx="${cur%.*}." cur_="${cur##*.}"
2238 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2239 return
2240 ;;
2241 pager.*)
2242 local pfx="${cur%.*}." cur_="${cur#*.}"
2243 __git_compute_all_commands
2244 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2245 return
2246 ;;
2247 remote.*.*)
2248 local pfx="${cur%.*}." cur_="${cur##*.}"
2249 __gitcomp "
2250 url proxy fetch push mirror skipDefaultUpdate
2251 receivepack uploadpack tagopt pushurl
2252 " "$pfx" "$cur_"
2253 return
2254 ;;
2255 remote.*)
2256 local pfx="${cur%.*}." cur_="${cur#*.}"
2257 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2258 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2259 return
2260 ;;
2261 url.*.*)
2262 local pfx="${cur%.*}." cur_="${cur##*.}"
2263 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2264 return
2265 ;;
2266 esac
2267 __gitcomp "
2268 add.ignoreErrors
2269 advice.amWorkDir
2270 advice.commitBeforeMerge
2271 advice.detachedHead
2272 advice.implicitIdentity
2273 advice.pushAlreadyExists
2274 advice.pushFetchFirst
2275 advice.pushNeedsForce
2276 advice.pushNonFFCurrent
2277 advice.pushNonFFMatching
2278 advice.pushUpdateRejected
2279 advice.resolveConflict
2280 advice.rmHints
2281 advice.statusHints
2282 advice.statusUoption
2283 advice.ignoredHook
2284 alias.
2285 am.keepcr
2286 am.threeWay
2287 apply.ignorewhitespace
2288 apply.whitespace
2289 branch.autosetupmerge
2290 branch.autosetuprebase
2291 browser.
2292 clean.requireForce
2293 color.branch
2294 color.branch.current
2295 color.branch.local
2296 color.branch.plain
2297 color.branch.remote
2298 color.decorate.HEAD
2299 color.decorate.branch
2300 color.decorate.remoteBranch
2301 color.decorate.stash
2302 color.decorate.tag
2303 color.diff
2304 color.diff.commit
2305 color.diff.frag
2306 color.diff.func
2307 color.diff.meta
2308 color.diff.new
2309 color.diff.old
2310 color.diff.plain
2311 color.diff.whitespace
2312 color.grep
2313 color.grep.context
2314 color.grep.filename
2315 color.grep.function
2316 color.grep.linenumber
2317 color.grep.match
2318 color.grep.selected
2319 color.grep.separator
2320 color.interactive
2321 color.interactive.error
2322 color.interactive.header
2323 color.interactive.help
2324 color.interactive.prompt
2325 color.pager
2326 color.showbranch
2327 color.status
2328 color.status.added
2329 color.status.changed
2330 color.status.header
2331 color.status.localBranch
2332 color.status.nobranch
2333 color.status.remoteBranch
2334 color.status.unmerged
2335 color.status.untracked
2336 color.status.updated
2337 color.ui
2338 commit.cleanup
2339 commit.gpgSign
2340 commit.status
2341 commit.template
2342 commit.verbose
2343 core.abbrev
2344 core.askpass
2345 core.attributesfile
2346 core.autocrlf
2347 core.bare
2348 core.bigFileThreshold
2349 core.checkStat
2350 core.commentChar
2351 core.compression
2352 core.createObject
2353 core.deltaBaseCacheLimit
2354 core.editor
2355 core.eol
2356 core.excludesfile
2357 core.fileMode
2358 core.fsyncobjectfiles
2359 core.gitProxy
2360 core.hideDotFiles
2361 core.hooksPath
2362 core.ignoreStat
2363 core.ignorecase
2364 core.logAllRefUpdates
2365 core.loosecompression
2366 core.notesRef
2367 core.packedGitLimit
2368 core.packedGitWindowSize
2369 core.packedRefsTimeout
2370 core.pager
2371 core.precomposeUnicode
2372 core.preferSymlinkRefs
2373 core.preloadindex
2374 core.protectHFS
2375 core.protectNTFS
2376 core.quotepath
2377 core.repositoryFormatVersion
2378 core.safecrlf
2379 core.sharedRepository
2380 core.sparseCheckout
2381 core.splitIndex
2382 core.sshCommand
2383 core.symlinks
2384 core.trustctime
2385 core.untrackedCache
2386 core.warnAmbiguousRefs
2387 core.whitespace
2388 core.worktree
2389 credential.helper
2390 credential.useHttpPath
2391 credential.username
2392 credentialCache.ignoreSIGHUP
2393 diff.autorefreshindex
2394 diff.external
2395 diff.ignoreSubmodules
2396 diff.mnemonicprefix
2397 diff.noprefix
2398 diff.renameLimit
2399 diff.renames
2400 diff.statGraphWidth
2401 diff.submodule
2402 diff.suppressBlankEmpty
2403 diff.tool
2404 diff.wordRegex
2405 diff.algorithm
2406 difftool.
2407 difftool.prompt
2408 fetch.recurseSubmodules
2409 fetch.unpackLimit
2410 format.attach
2411 format.cc
2412 format.coverLetter
2413 format.from
2414 format.headers
2415 format.numbered
2416 format.pretty
2417 format.signature
2418 format.signoff
2419 format.subjectprefix
2420 format.suffix
2421 format.thread
2422 format.to
2423 gc.
2424 gc.aggressiveDepth
2425 gc.aggressiveWindow
2426 gc.auto
2427 gc.autoDetach
2428 gc.autopacklimit
2429 gc.logExpiry
2430 gc.packrefs
2431 gc.pruneexpire
2432 gc.reflogexpire
2433 gc.reflogexpireunreachable
2434 gc.rerereresolved
2435 gc.rerereunresolved
2436 gc.worktreePruneExpire
2437 gitcvs.allbinary
2438 gitcvs.commitmsgannotation
2439 gitcvs.dbTableNamePrefix
2440 gitcvs.dbdriver
2441 gitcvs.dbname
2442 gitcvs.dbpass
2443 gitcvs.dbuser
2444 gitcvs.enabled
2445 gitcvs.logfile
2446 gitcvs.usecrlfattr
2447 guitool.
2448 gui.blamehistoryctx
2449 gui.commitmsgwidth
2450 gui.copyblamethreshold
2451 gui.diffcontext
2452 gui.encoding
2453 gui.fastcopyblame
2454 gui.matchtrackingbranch
2455 gui.newbranchtemplate
2456 gui.pruneduringfetch
2457 gui.spellingdictionary
2458 gui.trustmtime
2459 help.autocorrect
2460 help.browser
2461 help.format
2462 http.lowSpeedLimit
2463 http.lowSpeedTime
2464 http.maxRequests
2465 http.minSessions
2466 http.noEPSV
2467 http.postBuffer
2468 http.proxy
2469 http.sslCipherList
2470 http.sslVersion
2471 http.sslCAInfo
2472 http.sslCAPath
2473 http.sslCert
2474 http.sslCertPasswordProtected
2475 http.sslKey
2476 http.sslVerify
2477 http.useragent
2478 i18n.commitEncoding
2479 i18n.logOutputEncoding
2480 imap.authMethod
2481 imap.folder
2482 imap.host
2483 imap.pass
2484 imap.port
2485 imap.preformattedHTML
2486 imap.sslverify
2487 imap.tunnel
2488 imap.user
2489 init.templatedir
2490 instaweb.browser
2491 instaweb.httpd
2492 instaweb.local
2493 instaweb.modulepath
2494 instaweb.port
2495 interactive.singlekey
2496 log.date
2497 log.decorate
2498 log.showroot
2499 mailmap.file
2500 man.
2501 man.viewer
2502 merge.
2503 merge.conflictstyle
2504 merge.log
2505 merge.renameLimit
2506 merge.renormalize
2507 merge.stat
2508 merge.tool
2509 merge.verbosity
2510 mergetool.
2511 mergetool.keepBackup
2512 mergetool.keepTemporaries
2513 mergetool.prompt
2514 notes.displayRef
2515 notes.rewrite.
2516 notes.rewrite.amend
2517 notes.rewrite.rebase
2518 notes.rewriteMode
2519 notes.rewriteRef
2520 pack.compression
2521 pack.deltaCacheLimit
2522 pack.deltaCacheSize
2523 pack.depth
2524 pack.indexVersion
2525 pack.packSizeLimit
2526 pack.threads
2527 pack.window
2528 pack.windowMemory
2529 pager.
2530 pretty.
2531 pull.octopus
2532 pull.twohead
2533 push.default
2534 push.followTags
2535 rebase.autosquash
2536 rebase.stat
2537 receive.autogc
2538 receive.denyCurrentBranch
2539 receive.denyDeleteCurrent
2540 receive.denyDeletes
2541 receive.denyNonFastForwards
2542 receive.fsckObjects
2543 receive.unpackLimit
2544 receive.updateserverinfo
2545 remote.pushdefault
2546 remotes.
2547 repack.usedeltabaseoffset
2548 rerere.autoupdate
2549 rerere.enabled
2550 sendemail.
2551 sendemail.aliasesfile
2552 sendemail.aliasfiletype
2553 sendemail.bcc
2554 sendemail.cc
2555 sendemail.cccmd
2556 sendemail.chainreplyto
2557 sendemail.confirm
2558 sendemail.envelopesender
2559 sendemail.from
2560 sendemail.identity
2561 sendemail.multiedit
2562 sendemail.signedoffbycc
2563 sendemail.smtpdomain
2564 sendemail.smtpencryption
2565 sendemail.smtppass
2566 sendemail.smtpserver
2567 sendemail.smtpserveroption
2568 sendemail.smtpserverport
2569 sendemail.smtpuser
2570 sendemail.suppresscc
2571 sendemail.suppressfrom
2572 sendemail.thread
2573 sendemail.to
2574 sendemail.tocmd
2575 sendemail.validate
2576 sendemail.smtpbatchsize
2577 sendemail.smtprelogindelay
2578 showbranch.default
2579 status.relativePaths
2580 status.showUntrackedFiles
2581 status.submodulesummary
2582 submodule.
2583 tar.umask
2584 transfer.unpackLimit
2585 url.
2586 user.email
2587 user.name
2588 user.signingkey
2589 web.browser
2590 branch. remote.
2591 "
2592}
2593
2594_git_remote ()
2595{
2596 local subcommands="
2597 add rename remove set-head set-branches
2598 get-url set-url show prune update
2599 "
2600 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2601 if [ -z "$subcommand" ]; then
2602 case "$cur" in
2603 --*)
2604 __gitcomp_builtin remote
2605 ;;
2606 *)
2607 __gitcomp "$subcommands"
2608 ;;
2609 esac
2610 return
2611 fi
2612
2613 case "$subcommand,$cur" in
2614 add,--*)
2615 __gitcomp_builtin remote_add "--no-tags"
2616 ;;
2617 add,*)
2618 ;;
2619 set-head,--*)
2620 __gitcomp_builtin remote_set-head
2621 ;;
2622 set-branches,--*)
2623 __gitcomp_builtin remote_set-branches
2624 ;;
2625 set-head,*|set-branches,*)
2626 __git_complete_remote_or_refspec
2627 ;;
2628 update,--*)
2629 __gitcomp_builtin remote_update
2630 ;;
2631 update,*)
2632 __gitcomp "$(__git_get_config_variables "remotes")"
2633 ;;
2634 set-url,--*)
2635 __gitcomp_builtin remote_set-url
2636 ;;
2637 get-url,--*)
2638 __gitcomp_builtin remote_get-url
2639 ;;
2640 prune,--*)
2641 __gitcomp_builtin remote_prune
2642 ;;
2643 *)
2644 __gitcomp_nl "$(__git_remotes)"
2645 ;;
2646 esac
2647}
2648
2649_git_replace ()
2650{
2651 case "$cur" in
2652 --*)
2653 __gitcomp_builtin replace
2654 return
2655 ;;
2656 esac
2657 __git_complete_refs
2658}
2659
2660_git_rerere ()
2661{
2662 local subcommands="clear forget diff remaining status gc"
2663 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2664 if test -z "$subcommand"
2665 then
2666 __gitcomp "$subcommands"
2667 return
2668 fi
2669}
2670
2671_git_reset ()
2672{
2673 __git_has_doubledash && return
2674
2675 case "$cur" in
2676 --*)
2677 __gitcomp_builtin reset
2678 return
2679 ;;
2680 esac
2681 __git_complete_refs
2682}
2683
2684__git_revert_inprogress_options="--continue --quit --abort"
2685
2686_git_revert ()
2687{
2688 __git_find_repo_path
2689 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2690 __gitcomp "$__git_revert_inprogress_options"
2691 return
2692 fi
2693 case "$cur" in
2694 --*)
2695 __gitcomp_builtin revert "--no-edit" \
2696 "$__git_revert_inprogress_options"
2697 return
2698 ;;
2699 esac
2700 __git_complete_refs
2701}
2702
2703_git_rm ()
2704{
2705 case "$cur" in
2706 --*)
2707 __gitcomp_builtin rm
2708 return
2709 ;;
2710 esac
2711
2712 __git_complete_index_file "--cached"
2713}
2714
2715_git_shortlog ()
2716{
2717 __git_has_doubledash && return
2718
2719 case "$cur" in
2720 --*)
2721 __gitcomp "
2722 $__git_log_common_options
2723 $__git_log_shortlog_options
2724 --numbered --summary --email
2725 "
2726 return
2727 ;;
2728 esac
2729 __git_complete_revlist
2730}
2731
2732_git_show ()
2733{
2734 __git_has_doubledash && return
2735
2736 case "$cur" in
2737 --pretty=*|--format=*)
2738 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2739 " "" "${cur#*=}"
2740 return
2741 ;;
2742 --diff-algorithm=*)
2743 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2744 return
2745 ;;
2746 --submodule=*)
2747 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2748 return
2749 ;;
2750 --*)
2751 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2752 --show-signature
2753 $__git_diff_common_options
2754 "
2755 return
2756 ;;
2757 esac
2758 __git_complete_revlist_file
2759}
2760
2761_git_show_branch ()
2762{
2763 case "$cur" in
2764 --*)
2765 __gitcomp_builtin show-branch "--no-color"
2766 return
2767 ;;
2768 esac
2769 __git_complete_revlist
2770}
2771
2772_git_stash ()
2773{
2774 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2775 local subcommands='push save list show apply clear drop pop create branch'
2776 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2777 if [ -z "$subcommand" ]; then
2778 case "$cur" in
2779 --*)
2780 __gitcomp "$save_opts"
2781 ;;
2782 *)
2783 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2784 __gitcomp "$subcommands"
2785 fi
2786 ;;
2787 esac
2788 else
2789 case "$subcommand,$cur" in
2790 push,--*)
2791 __gitcomp "$save_opts --message"
2792 ;;
2793 save,--*)
2794 __gitcomp "$save_opts"
2795 ;;
2796 apply,--*|pop,--*)
2797 __gitcomp "--index --quiet"
2798 ;;
2799 drop,--*)
2800 __gitcomp "--quiet"
2801 ;;
2802 show,--*|branch,--*)
2803 ;;
2804 branch,*)
2805 if [ $cword -eq 3 ]; then
2806 __git_complete_refs
2807 else
2808 __gitcomp_nl "$(__git stash list \
2809 | sed -n -e 's/:.*//p')"
2810 fi
2811 ;;
2812 show,*|apply,*|drop,*|pop,*)
2813 __gitcomp_nl "$(__git stash list \
2814 | sed -n -e 's/:.*//p')"
2815 ;;
2816 *)
2817 ;;
2818 esac
2819 fi
2820}
2821
2822_git_submodule ()
2823{
2824 __git_has_doubledash && return
2825
2826 local subcommands="add status init deinit update summary foreach sync"
2827 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2828 if [ -z "$subcommand" ]; then
2829 case "$cur" in
2830 --*)
2831 __gitcomp "--quiet"
2832 ;;
2833 *)
2834 __gitcomp "$subcommands"
2835 ;;
2836 esac
2837 return
2838 fi
2839
2840 case "$subcommand,$cur" in
2841 add,--*)
2842 __gitcomp "--branch --force --name --reference --depth"
2843 ;;
2844 status,--*)
2845 __gitcomp "--cached --recursive"
2846 ;;
2847 deinit,--*)
2848 __gitcomp "--force --all"
2849 ;;
2850 update,--*)
2851 __gitcomp "
2852 --init --remote --no-fetch
2853 --recommend-shallow --no-recommend-shallow
2854 --force --rebase --merge --reference --depth --recursive --jobs
2855 "
2856 ;;
2857 summary,--*)
2858 __gitcomp "--cached --files --summary-limit"
2859 ;;
2860 foreach,--*|sync,--*)
2861 __gitcomp "--recursive"
2862 ;;
2863 *)
2864 ;;
2865 esac
2866}
2867
2868_git_svn ()
2869{
2870 local subcommands="
2871 init fetch clone rebase dcommit log find-rev
2872 set-tree commit-diff info create-ignore propget
2873 proplist show-ignore show-externals branch tag blame
2874 migrate mkdirs reset gc
2875 "
2876 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2877 if [ -z "$subcommand" ]; then
2878 __gitcomp "$subcommands"
2879 else
2880 local remote_opts="--username= --config-dir= --no-auth-cache"
2881 local fc_opts="
2882 --follow-parent --authors-file= --repack=
2883 --no-metadata --use-svm-props --use-svnsync-props
2884 --log-window-size= --no-checkout --quiet
2885 --repack-flags --use-log-author --localtime
2886 --add-author-from
2887 --ignore-paths= --include-paths= $remote_opts
2888 "
2889 local init_opts="
2890 --template= --shared= --trunk= --tags=
2891 --branches= --stdlayout --minimize-url
2892 --no-metadata --use-svm-props --use-svnsync-props
2893 --rewrite-root= --prefix= $remote_opts
2894 "
2895 local cmt_opts="
2896 --edit --rmdir --find-copies-harder --copy-similarity=
2897 "
2898
2899 case "$subcommand,$cur" in
2900 fetch,--*)
2901 __gitcomp "--revision= --fetch-all $fc_opts"
2902 ;;
2903 clone,--*)
2904 __gitcomp "--revision= $fc_opts $init_opts"
2905 ;;
2906 init,--*)
2907 __gitcomp "$init_opts"
2908 ;;
2909 dcommit,--*)
2910 __gitcomp "
2911 --merge --strategy= --verbose --dry-run
2912 --fetch-all --no-rebase --commit-url
2913 --revision --interactive $cmt_opts $fc_opts
2914 "
2915 ;;
2916 set-tree,--*)
2917 __gitcomp "--stdin $cmt_opts $fc_opts"
2918 ;;
2919 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2920 show-externals,--*|mkdirs,--*)
2921 __gitcomp "--revision="
2922 ;;
2923 log,--*)
2924 __gitcomp "
2925 --limit= --revision= --verbose --incremental
2926 --oneline --show-commit --non-recursive
2927 --authors-file= --color
2928 "
2929 ;;
2930 rebase,--*)
2931 __gitcomp "
2932 --merge --verbose --strategy= --local
2933 --fetch-all --dry-run $fc_opts
2934 "
2935 ;;
2936 commit-diff,--*)
2937 __gitcomp "--message= --file= --revision= $cmt_opts"
2938 ;;
2939 info,--*)
2940 __gitcomp "--url"
2941 ;;
2942 branch,--*)
2943 __gitcomp "--dry-run --message --tag"
2944 ;;
2945 tag,--*)
2946 __gitcomp "--dry-run --message"
2947 ;;
2948 blame,--*)
2949 __gitcomp "--git-format"
2950 ;;
2951 migrate,--*)
2952 __gitcomp "
2953 --config-dir= --ignore-paths= --minimize
2954 --no-auth-cache --username=
2955 "
2956 ;;
2957 reset,--*)
2958 __gitcomp "--revision= --parent"
2959 ;;
2960 *)
2961 ;;
2962 esac
2963 fi
2964}
2965
2966_git_tag ()
2967{
2968 local i c=1 f=0
2969 while [ $c -lt $cword ]; do
2970 i="${words[c]}"
2971 case "$i" in
2972 -d|--delete|-v|--verify)
2973 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2974 return
2975 ;;
2976 -f)
2977 f=1
2978 ;;
2979 esac
2980 ((c++))
2981 done
2982
2983 case "$prev" in
2984 -m|-F)
2985 ;;
2986 -*|tag)
2987 if [ $f = 1 ]; then
2988 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
2989 fi
2990 ;;
2991 *)
2992 __git_complete_refs
2993 ;;
2994 esac
2995
2996 case "$cur" in
2997 --*)
2998 __gitcomp_builtin tag
2999 ;;
3000 esac
3001}
3002
3003_git_whatchanged ()
3004{
3005 _git_log
3006}
3007
3008_git_worktree ()
3009{
3010 local subcommands="add list lock move prune remove unlock"
3011 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3012 if [ -z "$subcommand" ]; then
3013 __gitcomp "$subcommands"
3014 else
3015 case "$subcommand,$cur" in
3016 add,--*)
3017 __gitcomp_builtin worktree_add
3018 ;;
3019 list,--*)
3020 __gitcomp_builtin worktree_list
3021 ;;
3022 lock,--*)
3023 __gitcomp_builtin worktree_lock
3024 ;;
3025 prune,--*)
3026 __gitcomp_builtin worktree_prune
3027 ;;
3028 remove,--*)
3029 __gitcomp "--force"
3030 ;;
3031 *)
3032 ;;
3033 esac
3034 fi
3035}
3036
3037__git_complete_common () {
3038 local command="$1"
3039
3040 case "$cur" in
3041 --*)
3042 __gitcomp_builtin "$command"
3043 ;;
3044 esac
3045}
3046
3047__git_cmds_with_parseopt_helper=
3048__git_support_parseopt_helper () {
3049 test -n "$__git_cmds_with_parseopt_helper" ||
3050 __git_cmds_with_parseopt_helper="$(__git --list-parseopt-builtins)"
3051
3052 case " $__git_cmds_with_parseopt_helper " in
3053 *" $1 "*)
3054 return 0
3055 ;;
3056 *)
3057 return 1
3058 ;;
3059 esac
3060}
3061
3062__git_complete_command () {
3063 local command="$1"
3064 local completion_func="_git_${command//-/_}"
3065 if declare -f $completion_func >/dev/null 2>/dev/null; then
3066 $completion_func
3067 return 0
3068 elif __git_support_parseopt_helper "$command"; then
3069 __git_complete_common "$command"
3070 return 0
3071 else
3072 return 1
3073 fi
3074}
3075
3076__git_main ()
3077{
3078 local i c=1 command __git_dir __git_repo_path
3079 local __git_C_args C_args_count=0
3080
3081 while [ $c -lt $cword ]; do
3082 i="${words[c]}"
3083 case "$i" in
3084 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
3085 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
3086 --bare) __git_dir="." ;;
3087 --help) command="help"; break ;;
3088 -c|--work-tree|--namespace) ((c++)) ;;
3089 -C) __git_C_args[C_args_count++]=-C
3090 ((c++))
3091 __git_C_args[C_args_count++]="${words[c]}"
3092 ;;
3093 -*) ;;
3094 *) command="$i"; break ;;
3095 esac
3096 ((c++))
3097 done
3098
3099 if [ -z "$command" ]; then
3100 case "$prev" in
3101 --git-dir|-C|--work-tree)
3102 # these need a path argument, let's fall back to
3103 # Bash filename completion
3104 return
3105 ;;
3106 -c|--namespace)
3107 # we don't support completing these options' arguments
3108 return
3109 ;;
3110 esac
3111 case "$cur" in
3112 --*) __gitcomp "
3113 --paginate
3114 --no-pager
3115 --git-dir=
3116 --bare
3117 --version
3118 --exec-path
3119 --exec-path=
3120 --html-path
3121 --man-path
3122 --info-path
3123 --work-tree=
3124 --namespace=
3125 --no-replace-objects
3126 --help
3127 "
3128 ;;
3129 *) __git_compute_porcelain_commands
3130 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
3131 esac
3132 return
3133 fi
3134
3135 __git_complete_command "$command" && return
3136
3137 local expansion=$(__git_aliased_command "$command")
3138 if [ -n "$expansion" ]; then
3139 words[1]=$expansion
3140 __git_complete_command "$expansion"
3141 fi
3142}
3143
3144__gitk_main ()
3145{
3146 __git_has_doubledash && return
3147
3148 local __git_repo_path
3149 __git_find_repo_path
3150
3151 local merge=""
3152 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3153 merge="--merge"
3154 fi
3155 case "$cur" in
3156 --*)
3157 __gitcomp "
3158 $__git_log_common_options
3159 $__git_log_gitk_options
3160 $merge
3161 "
3162 return
3163 ;;
3164 esac
3165 __git_complete_revlist
3166}
3167
3168if [[ -n ${ZSH_VERSION-} ]]; then
3169 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
3170
3171 autoload -U +X compinit && compinit
3172
3173 __gitcomp ()
3174 {
3175 emulate -L zsh
3176
3177 local cur_="${3-$cur}"
3178
3179 case "$cur_" in
3180 --*=)
3181 ;;
3182 *)
3183 local c IFS=$' \t\n'
3184 local -a array
3185 for c in ${=1}; do
3186 c="$c${4-}"
3187 case $c in
3188 --*=*|*.) ;;
3189 *) c="$c " ;;
3190 esac
3191 array[${#array[@]}+1]="$c"
3192 done
3193 compset -P '*[=:]'
3194 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3195 ;;
3196 esac
3197 }
3198
3199 __gitcomp_direct ()
3200 {
3201 emulate -L zsh
3202
3203 local IFS=$'\n'
3204 compset -P '*[=:]'
3205 compadd -Q -- ${=1} && _ret=0
3206 }
3207
3208 __gitcomp_nl ()
3209 {
3210 emulate -L zsh
3211
3212 local IFS=$'\n'
3213 compset -P '*[=:]'
3214 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3215 }
3216
3217 __gitcomp_file ()
3218 {
3219 emulate -L zsh
3220
3221 local IFS=$'\n'
3222 compset -P '*[=:]'
3223 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3224 }
3225
3226 _git ()
3227 {
3228 local _ret=1 cur cword prev
3229 cur=${words[CURRENT]}
3230 prev=${words[CURRENT-1]}
3231 let cword=CURRENT-1
3232 emulate ksh -c __${service}_main
3233 let _ret && _default && _ret=0
3234 return _ret
3235 }
3236
3237 compdef _git git gitk
3238 return
3239fi
3240
3241__git_func_wrap ()
3242{
3243 local cur words cword prev
3244 _get_comp_words_by_ref -n =: cur words cword prev
3245 $1
3246}
3247
3248# Setup completion for certain functions defined above by setting common
3249# variables and workarounds.
3250# This is NOT a public function; use at your own risk.
3251__git_complete ()
3252{
3253 local wrapper="__git_wrap${2}"
3254 eval "$wrapper () { __git_func_wrap $2 ; }"
3255 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3256 || complete -o default -o nospace -F $wrapper $1
3257}
3258
3259# wrapper for backwards compatibility
3260_git ()
3261{
3262 __git_wrap__git_main
3263}
3264
3265# wrapper for backwards compatibility
3266_gitk ()
3267{
3268 __git_wrap__gitk_main
3269}
3270
3271__git_complete git __git_main
3272__git_complete gitk __gitk_main
3273
3274# The following are necessary only for Cygwin, and only are needed
3275# when the user has tab-completed the executable name and consequently
3276# included the '.exe' suffix.
3277#
3278if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3279__git_complete git.exe __git_main
3280fi