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