3 # bash/zsh completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) file paths within current working directory and index
17 # *) common --long-options
19 # To use these routines:
21 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
22 # 2) Add the following line to your .bashrc/.zshrc:
23 # source ~/.git-completion.sh
24 # 3) Consider changing your PS1 to also show the current branch,
25 # see git-prompt.sh for details.
27 case "$COMP_WORDBREAKS" in
29 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
32 # __gitdir accepts 0 or 1 arguments (i.e., location)
33 # returns location of .git repo
36 # Note: this function is duplicated in git-prompt.sh
37 # When updating it, make sure you update the other one to match.
38 if [ -z "${1-}" ]; then
39 if [ -n "${__git_dir-}" ]; then
41 elif [ -n "${GIT_DIR-}" ]; then
42 test -d "${GIT_DIR-}" ||
return 1
44 elif [ -d .git
]; then
47 git rev-parse
--git-dir 2>/dev
/null
49 elif [ -d "$1/.git" ]; then
56 # The following function is based on code from:
58 # bash_completion - programmable completion functions for bash 3.2+
60 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
61 # © 2009-2010, Bash Completion Maintainers
62 # <bash-completion-devel@lists.alioth.debian.org>
64 # This program is free software; you can redistribute it and/or modify
65 # it under the terms of the GNU General Public License as published by
66 # the Free Software Foundation; either version 2, or (at your option)
69 # This program is distributed in the hope that it will be useful,
70 # but WITHOUT ANY WARRANTY; without even the implied warranty of
71 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72 # GNU General Public License for more details.
74 # You should have received a copy of the GNU General Public License
75 # along with this program; if not, write to the Free Software Foundation,
76 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
78 # The latest version of this software can be obtained here:
80 # http://bash-completion.alioth.debian.org/
84 # This function can be used to access a tokenized list of words
85 # on the command line:
87 # __git_reassemble_comp_words_by_ref '=:'
88 # if test "${words_[cword_-1]}" = -w
93 # The argument should be a collection of characters from the list of
94 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
97 # This is roughly equivalent to going back in time and setting
98 # COMP_WORDBREAKS to exclude those characters. The intent is to
99 # make option types like --date=<type> and <rev>:<path> easy to
100 # recognize by treating each shell word as a single token.
102 # It is best not to set COMP_WORDBREAKS directly because the value is
103 # shared with other completion scripts. By the time the completion
104 # function gets called, COMP_WORDS has already been populated so local
105 # changes to COMP_WORDBREAKS have no effect.
107 # Output: words_, cword_, cur_.
109 __git_reassemble_comp_words_by_ref
()
111 local exclude i j first
112 # Which word separators to exclude?
113 exclude
="${1//[^$COMP_WORDBREAKS]}"
115 if [ -z "$exclude" ]; then
116 words_
=("${COMP_WORDS[@]}")
119 # List of word completion separators has shrunk;
120 # re-assemble words to complete.
121 for ((i
=0, j
=0; i
< ${#COMP_WORDS[@]}; i
++, j
++)); do
122 # Append each nonempty word consisting of just
123 # word separator characters to the current word.
127 [ -n "${COMP_WORDS[$i]}" ] &&
128 # word consists of excluded word separators
129 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
131 # Attach to the previous token,
132 # unless the previous token is the command name.
133 if [ $j -ge 2 ] && [ -n "$first" ]; then
137 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
138 if [ $i = $COMP_CWORD ]; then
141 if (($i < ${#COMP_WORDS[@]} - 1)); then
148 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
149 if [ $i = $COMP_CWORD ]; then
155 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
156 _get_comp_words_by_ref
()
158 local exclude cur_ words_ cword_
159 if [ "$1" = "-n" ]; then
163 __git_reassemble_comp_words_by_ref
"$exclude"
164 cur_
=${words_[cword_]}
165 while [ $# -gt 0 ]; do
171 prev
=${words_[$cword_-1]}
174 words
=("${words_[@]}")
189 if [[ "$x" == "$3"* ]]; then
190 COMPREPLY
[i
++]="$2$x$4"
195 # Generates completion reply, appending a space to possible completion words,
197 # It accepts 1 to 4 arguments:
198 # 1: List of possible completion words.
199 # 2: A prefix to be added to each possible completion word (optional).
200 # 3: Generate possible completion matches for this word (optional).
201 # 4: A suffix to be appended to each possible completion word (optional).
204 local cur_
="${3-$cur}"
210 local c i
=0 IFS
=$
' \t\n'
213 if [[ $c == "$cur_"* ]]; then
218 COMPREPLY
[i
++]="${2-}$c"
225 # Generates completion reply from newline-separated possible completion words
226 # by appending a space to all of them.
227 # It accepts 1 to 4 arguments:
228 # 1: List of possible completion words, separated by a single newline.
229 # 2: A prefix to be added to each possible completion word (optional).
230 # 3: Generate possible completion matches for this word (optional).
231 # 4: A suffix to be appended to each possible completion word instead of
232 # the default space (optional). If specified but empty, nothing is
237 __gitcompadd
"$1" "${2-}" "${3-$cur}" "${4- }"
240 # Generates completion reply with compgen from newline-separated possible
241 # completion filenames.
242 # It accepts 1 to 3 arguments:
243 # 1: List of possible completion filenames, separated by a single newline.
244 # 2: A directory prefix to be added to each possible completion filename
246 # 3: Generate possible completion matches for this word (optional).
251 # XXX does not work when the directory prefix contains a tilde,
252 # since tilde expansion is not applied.
253 # This means that COMPREPLY will be empty and Bash default
254 # completion will be used.
255 __gitcompadd
"$1" "${2-}" "${3-$cur}" ""
257 # use a hack to enable file mode in bash < 4
258 compopt
-o filenames
2>/dev
/null ||
259 compgen
-f /non-existing-dir
/ > /dev
/null
262 # Process path list returned by "ls-files" and "diff-index --name-only"
263 # commands, in order to list only file names relative to a specified
264 # directory, and append a slash to directory names.
265 __git_index_file_list_filter
()
269 while read -r path
; do
272 echo "${path%%/*}" ;;
279 # Execute 'git ls-files', unless the --committable option is specified, in
280 # which case it runs 'git diff-index' to find out the files that can be
281 # committed. It return paths relative to the directory specified in the first
282 # argument, and using the options specified in the second argument.
283 __git_ls_files_helper
()
286 test -n "${CDPATH+set}" && unset CDPATH
288 if [ "$2" == "--committable" ]; then
289 git diff-index
--name-only --relative HEAD
291 # NOTE: $2 is not quoted in order to support multiple options
292 git ls-files
--exclude-standard $2
298 # __git_index_files accepts 1 or 2 arguments:
299 # 1: Options to pass to ls-files (required).
300 # 2: A directory path (optional).
301 # If provided, only files within the specified directory are listed.
302 # Sub directories are never recursed. Path must have a trailing
306 local dir
="$(__gitdir)" root
="${2-.}"
308 if [ -d "$dir" ]; then
309 __git_ls_files_helper
"$root" "$1" | __git_index_file_list_filter |
316 local dir
="$(__gitdir)"
317 if [ -d "$dir" ]; then
318 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
326 local dir
="$(__gitdir)"
327 if [ -d "$dir" ]; then
328 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
334 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
335 # presence of 2nd argument means use the guess heuristic employed
336 # by checkout for tracking branches
339 local i
hash dir
="$(__gitdir "${1-}")" track
="${2-}"
341 if [ -d "$dir" ]; then
349 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
350 if [ -e "$dir/$i" ]; then echo $i; fi
352 format
="refname:short"
353 refs
="refs/tags refs/heads refs/remotes"
356 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
358 if [ -n "$track" ]; then
359 # employ the heuristic used by git checkout
360 # Try to find a remote branch that matches the completion word
361 # but only output if the branch name is unique
363 git
--git-dir="$dir" for-each-ref
--shell --format="ref=%(refname:short)" \
365 while read -r entry
; do
368 if [[ "$ref" == "$cur"* ]]; then
371 done |
sort |
uniq -u
377 git ls-remote
"$dir" "$cur*" 2>/dev
/null | \
378 while read -r hash i
; do
386 git ls-remote
"$dir" HEAD ORIG_HEAD
'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev
/null | \
387 while read -r hash i
; do
390 refs
/*) echo "${i#refs/*/}" ;;
398 # __git_refs2 requires 1 argument (to pass to __git_refs)
402 for i
in $
(__git_refs
"$1"); do
407 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
408 __git_refs_remotes
()
411 git ls-remote
"$1" 'refs/heads/*' 2>/dev
/null | \
412 while read -r hash i
; do
413 echo "$i:refs/remotes/$1/${i#refs/heads/}"
419 local i IFS
=$
'\n' d
="$(__gitdir)"
420 test -d "$d/remotes" && ls -1 "$d/remotes"
421 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
427 __git_list_merge_strategies
()
429 git merge
-s help 2>&1 |
430 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
439 __git_merge_strategies
=
440 # 'git merge -s help' (and thus detection of the merge strategy
441 # list) fails, unfortunately, if run outside of any git working
442 # tree. __git_merge_strategies is set to the empty string in
443 # that case, and the detection will be repeated the next time it
445 __git_compute_merge_strategies
()
447 test -n "$__git_merge_strategies" ||
448 __git_merge_strategies
=$
(__git_list_merge_strategies
)
451 __git_complete_revlist_file
()
453 local pfx
ls ref cur_
="$cur"
473 case "$COMP_WORDBREAKS" in
475 *) pfx
="$ref:$pfx" ;;
478 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" 2>/dev/null \
479 | sed '/^100... blob /{
495 pfx
="${cur_%...*}..."
497 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
502 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
505 __gitcomp_nl
"$(__git_refs)"
511 # __git_complete_index_file requires 1 argument:
512 # 1: the options to pass to ls-file
514 # The exception is --committable, which finds the files appropriate commit.
515 __git_complete_index_file
()
517 local pfx
="" cur_
="$cur"
527 __gitcomp_file
"$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
530 __git_complete_file
()
532 __git_complete_revlist_file
535 __git_complete_revlist
()
537 __git_complete_revlist_file
540 __git_complete_remote_or_refspec
()
542 local cur_
="$cur" cmd
="${words[1]}"
543 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
544 if [ "$cmd" = "remote" ]; then
547 while [ $c -lt $cword ]; do
550 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
553 push
) no_complete_refspec
=1 ;;
561 *) remote
="$i"; break ;;
565 if [ -z "$remote" ]; then
566 __gitcomp_nl
"$(__git_remotes)"
569 if [ $no_complete_refspec = 1 ]; then
572 [ "$remote" = "." ] && remote
=
575 case "$COMP_WORDBREAKS" in
577 *) pfx
="${cur_%%:*}:" ;;
589 if [ $lhs = 1 ]; then
590 __gitcomp_nl
"$(__git_refs2 "$remote")" "$pfx" "$cur_"
592 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
596 if [ $lhs = 1 ]; then
597 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
599 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
603 if [ $lhs = 1 ]; then
604 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
606 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
612 __git_complete_strategy
()
614 __git_compute_merge_strategies
617 __gitcomp
"$__git_merge_strategies"
622 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
630 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
632 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
634 git
help -a|
egrep '^ [a-zA-Z0-9]'
638 __git_list_all_commands
()
641 for i
in $
(__git_commands
)
644 *--*) : helper pattern
;;
651 __git_compute_all_commands
()
653 test -n "$__git_all_commands" ||
654 __git_all_commands
=$
(__git_list_all_commands
)
657 __git_list_porcelain_commands
()
660 __git_compute_all_commands
661 for i
in $__git_all_commands
664 *--*) : helper pattern
;;
665 applymbox
) : ask gittus
;;
666 applypatch
) : ask gittus
;;
667 archimport
) : import
;;
668 cat-file
) : plumbing
;;
669 check-attr
) : plumbing
;;
670 check-ignore
) : plumbing
;;
671 check-ref-format
) : plumbing
;;
672 checkout-index
) : plumbing
;;
673 commit-tree
) : plumbing
;;
674 count-objects
) : infrequent
;;
675 credential-cache
) : credentials helper
;;
676 credential-store
) : credentials helper
;;
677 cvsexportcommit
) : export;;
678 cvsimport
) : import
;;
679 cvsserver
) : daemon
;;
681 diff-files
) : plumbing
;;
682 diff-index
) : plumbing
;;
683 diff-tree
) : plumbing
;;
684 fast-import
) : import
;;
685 fast-export
) : export;;
686 fsck-objects
) : plumbing
;;
687 fetch-pack
) : plumbing
;;
688 fmt-merge-msg
) : plumbing
;;
689 for-each-ref
) : plumbing
;;
690 hash-object
) : plumbing
;;
691 http-
*) : transport
;;
692 index-pack
) : plumbing
;;
693 init-db
) : deprecated
;;
694 local-fetch
) : plumbing
;;
695 lost-found
) : infrequent
;;
696 ls-files
) : plumbing
;;
697 ls-remote
) : plumbing
;;
698 ls-tree
) : plumbing
;;
699 mailinfo
) : plumbing
;;
700 mailsplit
) : plumbing
;;
701 merge-
*) : plumbing
;;
704 pack-objects
) : plumbing
;;
705 pack-redundant
) : plumbing
;;
706 pack-refs
) : plumbing
;;
707 parse-remote
) : plumbing
;;
708 patch-id
) : plumbing
;;
709 peek-remote
) : plumbing
;;
711 prune-packed
) : plumbing
;;
712 quiltimport
) : import
;;
713 read-tree
) : plumbing
;;
714 receive-pack
) : plumbing
;;
715 remote-
*) : transport
;;
716 repo-config
) : deprecated
;;
718 rev-list
) : plumbing
;;
719 rev-parse
) : plumbing
;;
720 runstatus
) : plumbing
;;
721 sh-setup
) : internal
;;
723 show-ref
) : plumbing
;;
724 send-pack
) : plumbing
;;
725 show-index
) : plumbing
;;
727 stripspace
) : plumbing
;;
728 symbolic-ref
) : plumbing
;;
729 tar-tree
) : deprecated
;;
730 unpack-file
) : plumbing
;;
731 unpack-objects
) : plumbing
;;
732 update-index
) : plumbing
;;
733 update-ref
) : plumbing
;;
734 update-server-info
) : daemon
;;
735 upload-archive
) : plumbing
;;
736 upload-pack
) : plumbing
;;
737 write-tree
) : plumbing
;;
739 verify-pack
) : infrequent
;;
740 verify-tag
) : plumbing
;;
746 __git_porcelain_commands
=
747 __git_compute_porcelain_commands
()
749 __git_compute_all_commands
750 test -n "$__git_porcelain_commands" ||
751 __git_porcelain_commands
=$
(__git_list_porcelain_commands
)
754 __git_pretty_aliases
()
757 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "pretty\..*" 2>/dev
/null
); do
770 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
780 # __git_aliased_command requires 1 argument
781 __git_aliased_command
()
783 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
784 config
--get "alias.$1")
785 for word
in $cmdline; do
791 \
!*) : shell
command alias ;;
793 *=*) : setting env
;;
802 # __git_find_on_cmdline requires 1 argument
803 __git_find_on_cmdline
()
805 local word subcommand c
=1
806 while [ $c -lt $cword ]; do
808 for subcommand
in $1; do
809 if [ "$subcommand" = "$word" ]; then
818 __git_has_doubledash
()
821 while [ $c -lt $cword ]; do
822 if [ "--" = "${words[c]}" ]; then
830 # Try to count non option arguments passed on the command line for the
831 # specified git command.
832 # When options are used, it is necessary to use the special -- option to
833 # tell the implementation were non option arguments begin.
834 # XXX this can not be improved, since options can appear everywhere, as
838 # __git_count_arguments requires 1 argument: the git command executed.
839 __git_count_arguments
()
843 # Skip "git" (first argument)
844 for ((i
=1; i
< ${#words[@]}; i
++)); do
849 # Good; we can assume that the following are only non
854 # Skip the specified git command and discard git
867 __git_whitespacelist
="nowarn warn error error-all fix"
871 local dir
="$(__gitdir)"
872 if [ -d "$dir"/rebase-apply
]; then
873 __gitcomp
"--skip --continue --resolved --abort"
878 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
883 --3way --committer-date-is-author-date --ignore-date
884 --ignore-whitespace --ignore-space-change
885 --interactive --keep --no-utf8 --signoff --utf8
886 --whitespace= --scissors
896 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
901 --stat --numstat --summary --check --index
902 --cached --index-info --reverse --reject --unidiff-zero
903 --apply --no-add --exclude=
904 --ignore-whitespace --ignore-space-change
905 --whitespace= --inaccurate-eof --verbose
916 --interactive --refresh --patch --update --dry-run
917 --ignore-errors --intent-to-add
922 # XXX should we check for --update and --all options ?
923 __git_complete_index_file
"--others --modified"
930 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
934 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--remote=}"
939 --format= --list --verbose
940 --prefix= --remote= --exec=
950 __git_has_doubledash
&& return
952 local subcommands
="start bad good skip reset visualize replay log run"
953 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
954 if [ -z "$subcommand" ]; then
955 if [ -f "$(__gitdir)"/BISECT_START
]; then
956 __gitcomp
"$subcommands"
958 __gitcomp
"replay start"
963 case "$subcommand" in
964 bad|good|
reset|skip|start
)
965 __gitcomp_nl
"$(__git_refs)"
974 local i c
=1 only_local_ref
="n" has_r
="n"
976 while [ $c -lt $cword ]; do
979 -d|
-m) only_local_ref
="y" ;;
987 __gitcomp
"$(__git_refs)" "" "${cur##--set-upstream-to=}"
991 --color --no-color --verbose --abbrev= --no-abbrev
992 --track --no-track --contains --merged --no-merged
993 --set-upstream-to= --edit-description --list
998 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
999 __gitcomp_nl
"$(__git_heads)"
1001 __gitcomp_nl
"$(__git_refs)"
1009 local cmd
="${words[2]}"
1012 __gitcomp
"create list-heads verify unbundle"
1015 # looking for a file
1020 __git_complete_revlist
1029 __git_has_doubledash
&& return
1033 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1037 --quiet --ours --theirs --track --no-track --merge
1038 --conflict= --orphan --patch
1042 # check if --track, --no-track, or --no-guess was specified
1043 # if so, disable DWIM mode
1044 local flags
="--track --no-track --no-guess" track
=1
1045 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1048 __gitcomp_nl
"$(__git_refs '' $track)"
1055 __gitcomp
"$(__git_refs)"
1060 local dir
="$(__gitdir)"
1061 if [ -f "$dir"/CHERRY_PICK_HEAD
]; then
1062 __gitcomp
"--continue --quit --abort"
1067 __gitcomp
"--edit --no-commit --signoff --strategy= --mainline"
1070 __gitcomp_nl
"$(__git_refs)"
1079 __gitcomp
"--dry-run --quiet"
1084 # XXX should we check for -x option ?
1085 __git_complete_index_file
"--others"
1117 __gitcomp_nl
"$(__git_refs)" "" "${cur}"
1124 __gitcomp
"default strip verbatim whitespace
1125 " "" "${cur##--cleanup=}"
1128 --reuse-message=*|
--reedit-message=*|\
1129 --fixup=*|
--squash=*)
1130 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1133 --untracked-files=*)
1134 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1139 --all --author= --signoff --verify --no-verify
1141 --amend --include --only --interactive
1142 --dry-run --reuse-message= --reedit-message=
1143 --reset-author --file= --message= --template=
1144 --cleanup= --untracked-files --untracked-files=
1145 --verbose --quiet --fixup= --squash=
1150 if git rev-parse
--verify --quiet HEAD
>/dev
/null
; then
1151 __git_complete_index_file
"--committable"
1153 # This is the first commit
1154 __git_complete_index_file
"--cached"
1163 --all --tags --contains --abbrev= --candidates=
1164 --exact-match --debug --long --match --always
1168 __gitcomp_nl
"$(__git_refs)"
1171 __git_diff_algorithms
="myers minimal patience histogram"
1173 __git_diff_common_options
="--stat --numstat --shortstat --summary
1174 --patch-with-stat --name-only --name-status --color
1175 --no-color --color-words --no-renames --check
1176 --full-index --binary --abbrev --diff-filter=
1177 --find-copies-harder
1178 --text --ignore-space-at-eol --ignore-space-change
1179 --ignore-all-space --exit-code --quiet --ext-diff
1181 --no-prefix --src-prefix= --dst-prefix=
1182 --inter-hunk-context=
1183 --patience --histogram --minimal
1185 --dirstat --dirstat= --dirstat-by-file
1186 --dirstat-by-file= --cumulative
1192 __git_has_doubledash
&& return
1196 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1200 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1201 --base --ours --theirs --no-index
1202 $__git_diff_common_options
1207 __git_complete_revlist_file
1210 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1211 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1216 __git_has_doubledash
&& return
1220 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1224 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1225 --base --ours --theirs
1226 --no-renames --diff-filter= --find-copies-harder
1227 --relative --ignore-submodules
1235 __git_fetch_options
="
1236 --quiet --verbose --append --upload-pack --force --keep --depth=
1237 --tags --no-tags --all --prune --dry-run
1244 __gitcomp
"$__git_fetch_options"
1248 __git_complete_remote_or_refspec
1251 __git_format_patch_options
="
1252 --stdout --attach --no-attach --thread --thread= --output-directory
1253 --numbered --start-number --numbered-files --keep-subject --signoff
1254 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1255 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1256 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1259 _git_format_patch
()
1265 " "" "${cur##--thread=}"
1269 __gitcomp
"$__git_format_patch_options"
1273 __git_complete_revlist
1281 --tags --root --unreachable --cache --no-reflogs --full
1282 --strict --verbose --lost-found
1293 __gitcomp
"--prune --aggressive"
1304 __git_match_ctag
() {
1305 awk "/^${1////\\/}/ { print \$1 }" "$2"
1310 __git_has_doubledash
&& return
1316 --text --ignore-case --word-regexp --invert-match
1317 --full-name --line-number
1318 --extended-regexp --basic-regexp --fixed-strings
1320 --files-with-matches --name-only
1321 --files-without-match
1324 --and --or --not --all-match
1330 case "$cword,$prev" in
1332 if test -r tags
; then
1333 __gitcomp_nl
"$(__git_match_ctag "$cur" tags)"
1339 __gitcomp_nl
"$(__git_refs)"
1346 __gitcomp
"--all --info --man --web"
1350 __git_compute_all_commands
1351 __gitcomp
"$__git_all_commands $(__git_aliases)
1352 attributes cli core-tutorial cvs-migration
1353 diffcore gitk glossary hooks ignore modules
1354 namespaces repository-layout tutorial tutorial-2
1364 false true umask group all world everybody
1365 " "" "${cur##--shared=}"
1369 __gitcomp
"--quiet --bare --template= --shared --shared="
1379 __gitcomp
"--cached --deleted --modified --others --ignored
1380 --stage --directory --no-empty-directory --unmerged
1381 --killed --exclude= --exclude-from=
1382 --exclude-per-directory= --exclude-standard
1383 --error-unmatch --with-tree= --full-name
1384 --abbrev --ignored --exclude-per-directory
1390 # XXX ignore options like --modified and always suggest all cached
1392 __git_complete_index_file
"--cached"
1397 __gitcomp_nl
"$(__git_remotes)"
1405 # Options that go well for log, shortlog and gitk
1406 __git_log_common_options
="
1408 --branches --tags --remotes
1409 --first-parent --merges --no-merges
1411 --max-age= --since= --after=
1412 --min-age= --until= --before=
1413 --min-parents= --max-parents=
1414 --no-min-parents --no-max-parents
1416 # Options that go well for log and gitk (not shortlog)
1417 __git_log_gitk_options
="
1418 --dense --sparse --full-history
1419 --simplify-merges --simplify-by-decoration
1420 --left-right --notes --no-notes
1422 # Options that go well for log and shortlog (not gitk)
1423 __git_log_shortlog_options
="
1424 --author= --committer= --grep=
1428 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1429 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1433 __git_has_doubledash
&& return
1435 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1437 if [ -f "$g/MERGE_HEAD" ]; then
1441 --pretty=*|
--format=*)
1442 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1447 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1451 __gitcomp
"long short" "" "${cur##--decorate=}"
1456 $__git_log_common_options
1457 $__git_log_shortlog_options
1458 $__git_log_gitk_options
1459 --root --topo-order --date-order --reverse
1460 --follow --full-diff
1461 --abbrev-commit --abbrev=
1462 --relative-date --date=
1463 --pretty= --format= --oneline
1466 --decorate --decorate=
1468 --parents --children
1470 $__git_diff_common_options
1471 --pickaxe-all --pickaxe-regex
1476 __git_complete_revlist
1479 __git_merge_options
="
1480 --no-commit --no-stat --log --no-log --squash --strategy
1481 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1486 __git_complete_strategy
&& return
1490 __gitcomp
"$__git_merge_options"
1493 __gitcomp_nl
"$(__git_refs)"
1500 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1512 __gitcomp_nl
"$(__git_refs)"
1519 __gitcomp
"--dry-run"
1524 if [ $
(__git_count_arguments
"mv") -gt 0 ]; then
1525 # We need to show both cached and untracked files (including
1526 # empty directories) since this may not be the last argument.
1527 __git_complete_index_file
"--cached --others --directory"
1529 __git_complete_index_file
"--cached"
1535 __gitcomp
"--tags --all --stdin"
1540 local subcommands
='add append copy edit list prune remove show'
1541 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1543 case "$subcommand,$cur" in
1550 __gitcomp_nl
"$(__git_refs)"
1553 __gitcomp
"$subcommands --ref"
1557 add
,--reuse-message=*|append
,--reuse-message=*|\
1558 add
,--reedit-message=*|append
,--reedit-message=*)
1559 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1562 __gitcomp
'--file= --message= --reedit-message=
1569 __gitcomp
'--dry-run --verbose'
1578 __gitcomp_nl
"$(__git_refs)"
1587 __git_complete_strategy
&& return
1592 --rebase --no-rebase
1593 $__git_merge_options
1594 $__git_fetch_options
1599 __git_complete_remote_or_refspec
1606 __gitcomp_nl
"$(__git_remotes)"
1611 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--repo=}"
1616 --all --mirror --tags --dry-run --force --verbose
1617 --receive-pack= --repo= --set-upstream
1622 __git_complete_remote_or_refspec
1627 local dir
="$(__gitdir)"
1628 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1629 __gitcomp
"--continue --skip --abort"
1632 __git_complete_strategy
&& return
1635 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1640 --onto --merge --strategy --interactive
1641 --preserve-merges --stat --no-stat
1642 --committer-date-is-author-date --ignore-date
1643 --ignore-whitespace --whitespace=
1649 __gitcomp_nl
"$(__git_refs)"
1654 local subcommands
="show delete expire"
1655 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1657 if [ -z "$subcommand" ]; then
1658 __gitcomp
"$subcommands"
1660 __gitcomp_nl
"$(__git_refs)"
1664 __git_send_email_confirm_options
="always never auto cc compose"
1665 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1672 $__git_send_email_confirm_options
1673 " "" "${cur##--confirm=}"
1678 $__git_send_email_suppresscc_options
1679 " "" "${cur##--suppress-cc=}"
1683 --smtp-encryption=*)
1684 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1690 " "" "${cur##--thread=}"
1694 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1695 --compose --confirm= --dry-run --envelope-sender
1697 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1698 --no-suppress-from --no-thread --quiet
1699 --signed-off-by-cc --smtp-pass --smtp-server
1700 --smtp-server-port --smtp-encryption= --smtp-user
1701 --subject --suppress-cc= --suppress-from --thread --to
1702 --validate --no-validate
1703 $__git_format_patch_options"
1707 __git_complete_revlist
1715 __git_config_get_set_variables
()
1717 local prevword word config_file
= c
=$cword
1718 while [ $c -gt 1 ]; do
1721 --system|
--global|
--local|
--file=*)
1726 config_file
="$word $prevword"
1734 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1749 __gitcomp_nl
"$(__git_remotes)"
1753 __gitcomp_nl
"$(__git_refs)"
1757 local remote
="${prev#remote.}"
1758 remote
="${remote%.fetch}"
1759 if [ -z "$cur" ]; then
1760 __gitcompadd
"refs/heads/" "" "" ""
1763 __gitcomp_nl
"$(__git_refs_remotes "$remote")"
1767 local remote
="${prev#remote.}"
1768 remote
="${remote%.push}"
1769 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" \
1770 for-each-ref --format='%(refname):%(refname)' \
1774 pull.twohead|pull.octopus
)
1775 __git_compute_merge_strategies
1776 __gitcomp
"$__git_merge_strategies"
1779 color.branch|color.
diff|color.interactive|\
1780 color.showbranch|color.status|color.ui
)
1781 __gitcomp
"always never auto"
1785 __gitcomp
"false true"
1790 normal black red green yellow blue magenta cyan white
1791 bold dim ul blink reverse
1796 __gitcomp
"man info web html"
1800 __gitcomp
"$__git_log_date_formats"
1803 sendemail.aliasesfiletype
)
1804 __gitcomp
"mutt mailrc pine elm gnus"
1808 __gitcomp
"$__git_send_email_confirm_options"
1811 sendemail.suppresscc
)
1812 __gitcomp
"$__git_send_email_suppresscc_options"
1815 --get|
--get-all|
--unset|
--unset-all)
1816 __gitcomp_nl
"$(__git_config_get_set_variables)"
1826 --system --global --local --file=
1827 --list --replace-all
1828 --get --get-all --get-regexp
1829 --add --unset --unset-all
1830 --remove-section --rename-section
1835 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1836 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur_"
1840 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1841 __gitcomp_nl
"$(__git_heads)" "$pfx" "$cur_" "."
1845 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1847 argprompt cmd confirm needsfile noconsole norescan
1848 prompt revprompt revunmerged title
1853 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1854 __gitcomp
"cmd path" "$pfx" "$cur_"
1858 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1859 __gitcomp
"cmd path" "$pfx" "$cur_"
1863 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1864 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur_"
1868 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1869 __git_compute_all_commands
1870 __gitcomp_nl
"$__git_all_commands" "$pfx" "$cur_"
1874 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1876 url proxy fetch push mirror skipDefaultUpdate
1877 receivepack uploadpack tagopt pushurl
1882 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1883 __gitcomp_nl
"$(__git_remotes)" "$pfx" "$cur_" "."
1887 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1888 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur_"
1894 advice.commitBeforeMerge
1896 advice.implicitIdentity
1897 advice.pushNonFastForward
1898 advice.resolveConflict
1902 apply.ignorewhitespace
1904 branch.autosetupmerge
1905 branch.autosetuprebase
1909 color.branch.current
1914 color.decorate.branch
1915 color.decorate.remoteBranch
1916 color.decorate.stash
1926 color.diff.whitespace
1931 color.grep.linenumber
1934 color.grep.separator
1936 color.interactive.error
1937 color.interactive.header
1938 color.interactive.help
1939 color.interactive.prompt
1944 color.status.changed
1946 color.status.nobranch
1947 color.status.untracked
1948 color.status.updated
1957 core.bigFileThreshold
1960 core.deltaBaseCacheLimit
1965 core.fsyncobjectfiles
1967 core.ignoreCygwinFSTricks
1970 core.logAllRefUpdates
1971 core.loosecompression
1974 core.packedGitWindowSize
1976 core.preferSymlinkRefs
1979 core.repositoryFormatVersion
1981 core.sharedRepository
1985 core.warnAmbiguousRefs
1988 diff.autorefreshindex
1991 diff.ignoreSubmodules
1996 diff.suppressBlankEmpty
2002 fetch.recurseSubmodules
2011 format.subjectprefix
2022 gc.reflogexpireunreachable
2026 gitcvs.commitmsgannotation
2027 gitcvs.dbTableNamePrefix
2038 gui.copyblamethreshold
2042 gui.matchtrackingbranch
2043 gui.newbranchtemplate
2044 gui.pruneduringfetch
2045 gui.spellingdictionary
2060 http.sslCertPasswordProtected
2065 i18n.logOutputEncoding
2071 imap.preformattedHTML
2081 interactive.singlekey
2097 mergetool.keepBackup
2098 mergetool.keepTemporaries
2103 notes.rewrite.rebase
2107 pack.deltaCacheLimit
2123 receive.denyCurrentBranch
2124 receive.denyDeleteCurrent
2126 receive.denyNonFastForwards
2129 receive.updateserverinfo
2131 repack.usedeltabaseoffset
2135 sendemail.aliasesfile
2136 sendemail.aliasfiletype
2140 sendemail.chainreplyto
2142 sendemail.envelopesender
2146 sendemail.signedoffbycc
2147 sendemail.smtpdomain
2148 sendemail.smtpencryption
2150 sendemail.smtpserver
2151 sendemail.smtpserveroption
2152 sendemail.smtpserverport
2154 sendemail.suppresscc
2155 sendemail.suppressfrom
2160 status.relativePaths
2161 status.showUntrackedFiles
2162 status.submodulesummary
2165 transfer.unpackLimit
2177 local subcommands
="add rename remove set-head set-branches set-url show prune update"
2178 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2179 if [ -z "$subcommand" ]; then
2180 __gitcomp
"$subcommands"
2184 case "$subcommand" in
2185 rename|remove|set-url|show|prune
)
2186 __gitcomp_nl
"$(__git_remotes)"
2188 set-head|set-branches
)
2189 __git_complete_remote_or_refspec
2192 local i c
='' IFS
=$
'\n'
2193 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2206 __gitcomp_nl
"$(__git_refs)"
2211 __git_has_doubledash
&& return
2215 __gitcomp
"--merge --mixed --hard --soft --patch"
2219 __gitcomp_nl
"$(__git_refs)"
2226 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2230 __gitcomp_nl
"$(__git_refs)"
2237 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2242 __git_complete_index_file
"--cached"
2247 __git_has_doubledash
&& return
2252 $__git_log_common_options
2253 $__git_log_shortlog_options
2254 --numbered --summary
2259 __git_complete_revlist
2264 __git_has_doubledash
&& return
2267 --pretty=*|
--format=*)
2268 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2273 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2277 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2278 $__git_diff_common_options
2291 --all --remotes --topo-order --current --more=
2292 --list --independent --merge-base --no-name
2294 --sha1-name --sparse --topics --reflog
2299 __git_complete_revlist
2304 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2305 local subcommands
='save list show apply clear drop pop create branch'
2306 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2307 if [ -z "$subcommand" ]; then
2310 __gitcomp
"$save_opts"
2313 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2314 __gitcomp
"$subcommands"
2319 case "$subcommand,$cur" in
2321 __gitcomp
"$save_opts"
2324 __gitcomp
"--index --quiet"
2326 show
,--*|drop
,--*|branch
,--*)
2328 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2329 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" stash list \
2330 | sed -n -e 's/:.*//p')"
2340 __git_has_doubledash
&& return
2342 local subcommands
="add status init deinit update summary foreach sync"
2343 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2346 __gitcomp
"--quiet --cached"
2349 __gitcomp
"$subcommands"
2359 init fetch clone rebase dcommit log find-rev
2360 set-tree commit-diff info create-ignore propget
2361 proplist show-ignore show-externals branch tag blame
2362 migrate mkdirs reset gc
2364 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2365 if [ -z "$subcommand" ]; then
2366 __gitcomp
"$subcommands"
2368 local remote_opts
="--username= --config-dir= --no-auth-cache"
2370 --follow-parent --authors-file= --repack=
2371 --no-metadata --use-svm-props --use-svnsync-props
2372 --log-window-size= --no-checkout --quiet
2373 --repack-flags --use-log-author --localtime
2374 --ignore-paths= $remote_opts
2377 --template= --shared= --trunk= --tags=
2378 --branches= --stdlayout --minimize-url
2379 --no-metadata --use-svm-props --use-svnsync-props
2380 --rewrite-root= --prefix= --use-log-author
2381 --add-author-from $remote_opts
2384 --edit --rmdir --find-copies-harder --copy-similarity=
2387 case "$subcommand,$cur" in
2389 __gitcomp
"--revision= --fetch-all $fc_opts"
2392 __gitcomp
"--revision= $fc_opts $init_opts"
2395 __gitcomp
"$init_opts"
2399 --merge --strategy= --verbose --dry-run
2400 --fetch-all --no-rebase --commit-url
2401 --revision --interactive $cmt_opts $fc_opts
2405 __gitcomp
"--stdin $cmt_opts $fc_opts"
2407 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2408 show-externals
,--*|mkdirs
,--*)
2409 __gitcomp
"--revision="
2413 --limit= --revision= --verbose --incremental
2414 --oneline --show-commit --non-recursive
2415 --authors-file= --color
2420 --merge --verbose --strategy= --local
2421 --fetch-all --dry-run $fc_opts
2425 __gitcomp
"--message= --file= --revision= $cmt_opts"
2431 __gitcomp
"--dry-run --message --tag"
2434 __gitcomp
"--dry-run --message"
2437 __gitcomp
"--git-format"
2441 --config-dir= --ignore-paths= --minimize
2442 --no-auth-cache --username=
2446 __gitcomp
"--revision= --parent"
2457 while [ $c -lt $cword ]; do
2461 __gitcomp_nl
"$(__git_tags)"
2476 __gitcomp_nl
"$(__git_tags)"
2480 __gitcomp_nl
"$(__git_refs)"
2492 local i c
=1 command __git_dir
2494 while [ $c -lt $cword ]; do
2497 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2498 --bare) __git_dir
="." ;;
2499 --help) command="help"; break ;;
2502 *) command="$i"; break ;;
2507 if [ -z "$command" ]; then
2521 --no-replace-objects
2525 *) __git_compute_porcelain_commands
2526 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2531 local completion_func
="_git_${command//-/_}"
2532 declare -f $completion_func >/dev
/null
&& $completion_func && return
2534 local expansion
=$
(__git_aliased_command
"$command")
2535 if [ -n "$expansion" ]; then
2536 completion_func
="_git_${expansion//-/_}"
2537 declare -f $completion_func >/dev
/null
&& $completion_func
2543 __git_has_doubledash
&& return
2545 local g
="$(__gitdir)"
2547 if [ -f "$g/MERGE_HEAD" ]; then
2553 $__git_log_common_options
2554 $__git_log_gitk_options
2560 __git_complete_revlist
2563 if [[ -n ${ZSH_VERSION-} ]]; then
2564 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2566 autoload
-U +X compinit
&& compinit
2572 local cur_
="${3-$cur}"
2578 local c IFS
=$
' \t\n'
2586 array
[$#array+1]="$c"
2589 compadd
-Q -S '' -p "${2-}" -a -- array
&& _ret
=0
2600 compadd
-Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2609 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2615 local cur cword prev
2616 cur=${words[CURRENT-1]}
2617 prev=${words[CURRENT-2]}
2627 let _ret && _default -S '' && _ret=0
2631 compdef _git git gitk
2637 local cur words cword prev
2638 _get_comp_words_by_ref -n =: cur words cword prev
2642 # Setup completion for certain functions defined above by setting common
2643 # variables and workarounds.
2644 # This is NOT a public function; use at your own risk.
2647 local wrapper="__git_wrap
${2}"
2648 eval "$wrapper () { __git_func_wrap
$2 ; }"
2649 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2650 || complete -o default -o nospace -F $wrapper $1
2653 # wrapper for backwards compatibility
2656 __git_wrap__git_main
2659 # wrapper for backwards compatibility
2662 __git_wrap__gitk_main
2665 __git_complete git __git_main
2666 __git_complete gitk __gitk_main
2668 # The following are necessary only for Cygwin, and only are needed
2669 # when the user has tab-completed the executable name and consequently
2670 # included the '.exe' suffix.
2672 if [ Cygwin = "$
(uname
-o 2>/dev
/null
)" ]; then
2673 __git_complete git.exe __git_main