OILS / testdata / completion / git View on Github | oilshell.org

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