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