1 # bash/zsh completion support for core Git.
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.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) tree paths within 'ref:path/to/file' expressions
14 # *) file paths within current working directory and index
15 # *) common --long-options
17 # To use these routines:
19 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
20 # 2) Add the following line to your .bashrc/.zshrc:
21 # source ~/.git-completion.sh
22 # 3) Consider changing your PS1 to also show the current branch,
23 # see git-prompt.sh for details.
25 case "$COMP_WORDBREAKS" in
27 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
30 # __gitdir accepts 0 or 1 arguments (i.e., location)
31 # returns location of .git repo
34 if [ -z "${1-}" ]; then
35 if [ -n "${__git_dir-}" ]; then
37 elif [ -n "${GIT_DIR-}" ]; then
38 test -d "${GIT_DIR-}" ||
return 1
40 elif [ -d .git
]; then
43 git rev-parse
--git-dir 2>/dev
/null
45 elif [ -d "$1/.git" ]; then
52 # The following function is based on code from:
54 # bash_completion - programmable completion functions for bash 3.2+
56 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
57 # © 2009-2010, Bash Completion Maintainers
58 # <bash-completion-devel@lists.alioth.debian.org>
60 # This program is free software; you can redistribute it and/or modify
61 # it under the terms of the GNU General Public License as published by
62 # the Free Software Foundation; either version 2, or (at your option)
65 # This program is distributed in the hope that it will be useful,
66 # but WITHOUT ANY WARRANTY; without even the implied warranty of
67 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68 # GNU General Public License for more details.
70 # You should have received a copy of the GNU General Public License
71 # along with this program; if not, write to the Free Software Foundation,
72 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
74 # The latest version of this software can be obtained here:
76 # http://bash-completion.alioth.debian.org/
80 # This function can be used to access a tokenized list of words
81 # on the command line:
83 # __git_reassemble_comp_words_by_ref '=:'
84 # if test "${words_[cword_-1]}" = -w
89 # The argument should be a collection of characters from the list of
90 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
93 # This is roughly equivalent to going back in time and setting
94 # COMP_WORDBREAKS to exclude those characters. The intent is to
95 # make option types like --date=<type> and <rev>:<path> easy to
96 # recognize by treating each shell word as a single token.
98 # It is best not to set COMP_WORDBREAKS directly because the value is
99 # shared with other completion scripts. By the time the completion
100 # function gets called, COMP_WORDS has already been populated so local
101 # changes to COMP_WORDBREAKS have no effect.
103 # Output: words_, cword_, cur_.
105 __git_reassemble_comp_words_by_ref
()
107 local exclude i j first
108 # Which word separators to exclude?
109 exclude
="${1//[^$COMP_WORDBREAKS]}"
111 if [ -z "$exclude" ]; then
112 words_
=("${COMP_WORDS[@]}")
115 # List of word completion separators has shrunk;
116 # re-assemble words to complete.
117 for ((i
=0, j
=0; i
< ${#COMP_WORDS[@]}; i
++, j
++)); do
118 # Append each nonempty word consisting of just
119 # word separator characters to the current word.
123 [ -n "${COMP_WORDS[$i]}" ] &&
124 # word consists of excluded word separators
125 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
127 # Attach to the previous token,
128 # unless the previous token is the command name.
129 if [ $j -ge 2 ] && [ -n "$first" ]; then
133 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
134 if [ $i = $COMP_CWORD ]; then
137 if (($i < ${#COMP_WORDS[@]} - 1)); then
144 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
145 if [ $i = $COMP_CWORD ]; then
151 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
152 _get_comp_words_by_ref
()
154 local exclude cur_ words_ cword_
155 if [ "$1" = "-n" ]; then
159 __git_reassemble_comp_words_by_ref
"$exclude"
160 cur_
=${words_[cword_]}
161 while [ $# -gt 0 ]; do
167 prev
=${words_[$cword_-1]}
170 words
=("${words_[@]}")
185 if [[ "$x" == "$3"* ]]; then
186 COMPREPLY
[i
++]="$2$x$4"
191 # Generates completion reply, appending a space to possible completion words,
193 # It accepts 1 to 4 arguments:
194 # 1: List of possible completion words.
195 # 2: A prefix to be added to each possible completion word (optional).
196 # 3: Generate possible completion matches for this word (optional).
197 # 4: A suffix to be appended to each possible completion word (optional).
200 local cur_
="${3-$cur}"
206 local c i
=0 IFS
=$
' \t\n'
209 if [[ $c == "$cur_"* ]]; then
214 COMPREPLY
[i
++]="${2-}$c"
221 # Generates completion reply from newline-separated possible completion words
222 # by appending a space to all of them.
223 # It accepts 1 to 4 arguments:
224 # 1: List of possible completion words, separated by a single newline.
225 # 2: A prefix to be added to each possible completion word (optional).
226 # 3: Generate possible completion matches for this word (optional).
227 # 4: A suffix to be appended to each possible completion word instead of
228 # the default space (optional). If specified but empty, nothing is
233 __gitcompadd
"$1" "${2-}" "${3-$cur}" "${4- }"
236 # Generates completion reply with compgen from newline-separated possible
237 # completion filenames.
238 # It accepts 1 to 3 arguments:
239 # 1: List of possible completion filenames, separated by a single newline.
240 # 2: A directory prefix to be added to each possible completion filename
242 # 3: Generate possible completion matches for this word (optional).
247 # XXX does not work when the directory prefix contains a tilde,
248 # since tilde expansion is not applied.
249 # This means that COMPREPLY will be empty and Bash default
250 # completion will be used.
251 __gitcompadd
"$1" "${2-}" "${3-$cur}" ""
253 # use a hack to enable file mode in bash < 4
254 compopt
-o filenames
+o nospace
2>/dev
/null ||
255 compgen
-f /non-existing-dir
/ > /dev
/null
258 # Execute 'git ls-files', unless the --committable option is specified, in
259 # which case it runs 'git diff-index' to find out the files that can be
260 # committed. It return paths relative to the directory specified in the first
261 # argument, and using the options specified in the second argument.
262 __git_ls_files_helper
()
265 test -n "${CDPATH+set}" && unset CDPATH
267 if [ "$2" == "--committable" ]; then
268 git diff-index
--name-only --relative HEAD
270 # NOTE: $2 is not quoted in order to support multiple options
271 git ls-files
--exclude-standard $2
277 # __git_index_files accepts 1 or 2 arguments:
278 # 1: Options to pass to ls-files (required).
279 # 2: A directory path (optional).
280 # If provided, only files within the specified directory are listed.
281 # Sub directories are never recursed. Path must have a trailing
285 local dir
="$(__gitdir)" root
="${2-.}" file
287 if [ -d "$dir" ]; then
288 __git_ls_files_helper
"$root" "$1" |
289 while read -r file; do
291 ?
*/*) echo "${file%%/*}" ;;
300 local dir
="$(__gitdir)"
301 if [ -d "$dir" ]; then
302 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
310 local dir
="$(__gitdir)"
311 if [ -d "$dir" ]; then
312 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
318 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
319 # presence of 2nd argument means use the guess heuristic employed
320 # by checkout for tracking branches
323 local i
hash dir
="$(__gitdir "${1-}")" track
="${2-}"
325 if [ -d "$dir" ]; then
333 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
334 if [ -e "$dir/$i" ]; then echo $i; fi
336 format
="refname:short"
337 refs
="refs/tags refs/heads refs/remotes"
340 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
342 if [ -n "$track" ]; then
343 # employ the heuristic used by git checkout
344 # Try to find a remote branch that matches the completion word
345 # but only output if the branch name is unique
347 git
--git-dir="$dir" for-each-ref
--shell --format="ref=%(refname:short)" \
349 while read -r entry
; do
352 if [[ "$ref" == "$cur"* ]]; then
355 done |
sort |
uniq -u
361 git ls-remote
"$dir" "$cur*" 2>/dev
/null | \
362 while read -r hash i
; do
371 git for-each-ref
--format="%(refname:short)" -- "refs/remotes/$dir/" |
sed -e "s#^$dir/##"
376 # __git_refs2 requires 1 argument (to pass to __git_refs)
380 for i
in $
(__git_refs
"$1"); do
385 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
386 __git_refs_remotes
()
389 git ls-remote
"$1" 'refs/heads/*' 2>/dev
/null | \
390 while read -r hash i
; do
391 echo "$i:refs/remotes/$1/${i#refs/heads/}"
397 local i IFS
=$
'\n' d
="$(__gitdir)"
398 test -d "$d/remotes" && ls -1 "$d/remotes"
399 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
405 __git_list_merge_strategies
()
407 git merge
-s help 2>&1 |
408 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
417 __git_merge_strategies
=
418 # 'git merge -s help' (and thus detection of the merge strategy
419 # list) fails, unfortunately, if run outside of any git working
420 # tree. __git_merge_strategies is set to the empty string in
421 # that case, and the detection will be repeated the next time it
423 __git_compute_merge_strategies
()
425 test -n "$__git_merge_strategies" ||
426 __git_merge_strategies
=$
(__git_list_merge_strategies
)
429 __git_complete_revlist_file
()
431 local pfx
ls ref cur_
="$cur"
451 case "$COMP_WORDBREAKS" in
453 *) pfx
="$ref:$pfx" ;;
456 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" 2>/dev/null \
457 | sed '/^100... blob /{
473 pfx
="${cur_%...*}..."
475 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
480 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
483 __gitcomp_nl
"$(__git_refs)"
489 # __git_complete_index_file requires 1 argument:
490 # 1: the options to pass to ls-file
492 # The exception is --committable, which finds the files appropriate commit.
493 __git_complete_index_file
()
495 local pfx
="" cur_
="$cur"
505 __gitcomp_file
"$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
508 __git_complete_file
()
510 __git_complete_revlist_file
513 __git_complete_revlist
()
515 __git_complete_revlist_file
518 __git_complete_remote_or_refspec
()
520 local cur_
="$cur" cmd
="${words[1]}"
521 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
522 if [ "$cmd" = "remote" ]; then
525 while [ $c -lt $cword ]; do
528 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
531 push
) no_complete_refspec
=1 ;;
539 *) remote
="$i"; break ;;
543 if [ -z "$remote" ]; then
544 __gitcomp_nl
"$(__git_remotes)"
547 if [ $no_complete_refspec = 1 ]; then
550 [ "$remote" = "." ] && remote
=
553 case "$COMP_WORDBREAKS" in
555 *) pfx
="${cur_%%:*}:" ;;
567 if [ $lhs = 1 ]; then
568 __gitcomp_nl
"$(__git_refs2 "$remote")" "$pfx" "$cur_"
570 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
574 if [ $lhs = 1 ]; then
575 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
577 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
581 if [ $lhs = 1 ]; then
582 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
584 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
590 __git_complete_strategy
()
592 __git_compute_merge_strategies
595 __gitcomp
"$__git_merge_strategies"
600 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
608 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
610 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
612 git
help -a|
egrep '^ [a-zA-Z0-9]'
616 __git_list_all_commands
()
619 for i
in $
(__git_commands
)
622 *--*) : helper pattern
;;
629 __git_compute_all_commands
()
631 test -n "$__git_all_commands" ||
632 __git_all_commands
=$
(__git_list_all_commands
)
635 __git_list_porcelain_commands
()
638 __git_compute_all_commands
639 for i
in $__git_all_commands
642 *--*) : helper pattern
;;
643 applymbox
) : ask gittus
;;
644 applypatch
) : ask gittus
;;
645 archimport
) : import
;;
646 cat-file
) : plumbing
;;
647 check-attr
) : plumbing
;;
648 check-ignore
) : plumbing
;;
649 check-mailmap
) : plumbing
;;
650 check-ref-format
) : plumbing
;;
651 checkout-index
) : plumbing
;;
652 commit-tree
) : plumbing
;;
653 count-objects
) : infrequent
;;
654 credential-cache
) : credentials helper
;;
655 credential-store
) : credentials helper
;;
656 cvsexportcommit
) : export;;
657 cvsimport
) : import
;;
658 cvsserver
) : daemon
;;
660 diff-files
) : plumbing
;;
661 diff-index
) : plumbing
;;
662 diff-tree
) : plumbing
;;
663 fast-import
) : import
;;
664 fast-export
) : export;;
665 fsck-objects
) : plumbing
;;
666 fetch-pack
) : plumbing
;;
667 fmt-merge-msg
) : plumbing
;;
668 for-each-ref
) : plumbing
;;
669 hash-object
) : plumbing
;;
670 http-
*) : transport
;;
671 index-pack
) : plumbing
;;
672 init-db
) : deprecated
;;
673 local-fetch
) : plumbing
;;
674 ls-files
) : plumbing
;;
675 ls-remote
) : plumbing
;;
676 ls-tree
) : plumbing
;;
677 mailinfo
) : plumbing
;;
678 mailsplit
) : plumbing
;;
679 merge-
*) : plumbing
;;
682 pack-objects
) : plumbing
;;
683 pack-redundant
) : plumbing
;;
684 pack-refs
) : plumbing
;;
685 parse-remote
) : plumbing
;;
686 patch-id
) : plumbing
;;
688 prune-packed
) : plumbing
;;
689 quiltimport
) : import
;;
690 read-tree
) : plumbing
;;
691 receive-pack
) : plumbing
;;
692 remote-
*) : transport
;;
694 rev-list
) : plumbing
;;
695 rev-parse
) : plumbing
;;
696 runstatus
) : plumbing
;;
697 sh-setup
) : internal
;;
699 show-ref
) : plumbing
;;
700 send-pack
) : plumbing
;;
701 show-index
) : plumbing
;;
703 stripspace
) : plumbing
;;
704 symbolic-ref
) : plumbing
;;
705 unpack-file
) : plumbing
;;
706 unpack-objects
) : plumbing
;;
707 update-index
) : plumbing
;;
708 update-ref
) : plumbing
;;
709 update-server-info
) : daemon
;;
710 upload-archive
) : plumbing
;;
711 upload-pack
) : plumbing
;;
712 write-tree
) : plumbing
;;
714 verify-pack
) : infrequent
;;
715 verify-tag
) : plumbing
;;
721 __git_porcelain_commands
=
722 __git_compute_porcelain_commands
()
724 __git_compute_all_commands
725 test -n "$__git_porcelain_commands" ||
726 __git_porcelain_commands
=$
(__git_list_porcelain_commands
)
729 __git_pretty_aliases
()
732 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "pretty\..*" 2>/dev
/null
); do
745 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
755 # __git_aliased_command requires 1 argument
756 __git_aliased_command
()
758 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
759 config
--get "alias.$1")
760 for word
in $cmdline; do
766 \
!*) : shell
command alias ;;
768 *=*) : setting env
;;
777 # __git_find_on_cmdline requires 1 argument
778 __git_find_on_cmdline
()
780 local word subcommand c
=1
781 while [ $c -lt $cword ]; do
783 for subcommand
in $1; do
784 if [ "$subcommand" = "$word" ]; then
793 __git_has_doubledash
()
796 while [ $c -lt $cword ]; do
797 if [ "--" = "${words[c]}" ]; then
805 # Try to count non option arguments passed on the command line for the
806 # specified git command.
807 # When options are used, it is necessary to use the special -- option to
808 # tell the implementation were non option arguments begin.
809 # XXX this can not be improved, since options can appear everywhere, as
813 # __git_count_arguments requires 1 argument: the git command executed.
814 __git_count_arguments
()
818 # Skip "git" (first argument)
819 for ((i
=1; i
< ${#words[@]}; i
++)); do
824 # Good; we can assume that the following are only non
829 # Skip the specified git command and discard git
842 __git_whitespacelist
="nowarn warn error error-all fix"
846 local dir
="$(__gitdir)"
847 if [ -d "$dir"/rebase-apply
]; then
848 __gitcomp
"--skip --continue --resolved --abort"
853 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
858 --3way --committer-date-is-author-date --ignore-date
859 --ignore-whitespace --ignore-space-change
860 --interactive --keep --no-utf8 --signoff --utf8
861 --whitespace= --scissors
871 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
876 --stat --numstat --summary --check --index
877 --cached --index-info --reverse --reject --unidiff-zero
878 --apply --no-add --exclude=
879 --ignore-whitespace --ignore-space-change
880 --whitespace= --inaccurate-eof --verbose
891 --interactive --refresh --patch --update --dry-run
892 --ignore-errors --intent-to-add
897 # XXX should we check for --update and --all options ?
898 __git_complete_index_file
"--others --modified --directory --no-empty-directory"
905 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
909 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--remote=}"
914 --format= --list --verbose
915 --prefix= --remote= --exec=
925 __git_has_doubledash
&& return
927 local subcommands
="start bad good skip reset visualize replay log run"
928 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
929 if [ -z "$subcommand" ]; then
930 if [ -f "$(__gitdir)"/BISECT_START
]; then
931 __gitcomp
"$subcommands"
933 __gitcomp
"replay start"
938 case "$subcommand" in
939 bad|good|
reset|skip|start
)
940 __gitcomp_nl
"$(__git_refs)"
949 local i c
=1 only_local_ref
="n" has_r
="n"
951 while [ $c -lt $cword ]; do
954 -d|
-m) only_local_ref
="y" ;;
962 __gitcomp
"$(__git_refs)" "" "${cur##--set-upstream-to=}"
966 --color --no-color --verbose --abbrev= --no-abbrev
967 --track --no-track --contains --merged --no-merged
968 --set-upstream-to= --edit-description --list
973 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
974 __gitcomp_nl
"$(__git_heads)"
976 __gitcomp_nl
"$(__git_refs)"
984 local cmd
="${words[2]}"
987 __gitcomp
"create list-heads verify unbundle"
995 __git_complete_revlist
1004 __git_has_doubledash
&& return
1008 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1012 --quiet --ours --theirs --track --no-track --merge
1013 --conflict= --orphan --patch
1017 # check if --track, --no-track, or --no-guess was specified
1018 # if so, disable DWIM mode
1019 local flags
="--track --no-track --no-guess" track
=1
1020 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1023 __gitcomp_nl
"$(__git_refs '' $track)"
1030 __gitcomp
"$(__git_refs)"
1035 local dir
="$(__gitdir)"
1036 if [ -f "$dir"/CHERRY_PICK_HEAD
]; then
1037 __gitcomp
"--continue --quit --abort"
1042 __gitcomp
"--edit --no-commit --signoff --strategy= --mainline"
1045 __gitcomp_nl
"$(__git_refs)"
1054 __gitcomp
"--dry-run --quiet"
1059 # XXX should we check for -x option ?
1060 __git_complete_index_file
"--others --directory"
1092 __gitcomp_nl
"$(__git_refs)" "" "${cur}"
1099 __gitcomp
"default strip verbatim whitespace
1100 " "" "${cur##--cleanup=}"
1103 --reuse-message=*|
--reedit-message=*|\
1104 --fixup=*|
--squash=*)
1105 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1108 --untracked-files=*)
1109 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1114 --all --author= --signoff --verify --no-verify
1116 --amend --include --only --interactive
1117 --dry-run --reuse-message= --reedit-message=
1118 --reset-author --file= --message= --template=
1119 --cleanup= --untracked-files --untracked-files=
1120 --verbose --quiet --fixup= --squash=
1125 if git rev-parse
--verify --quiet HEAD
>/dev
/null
; then
1126 __git_complete_index_file
"--committable"
1128 # This is the first commit
1129 __git_complete_index_file
"--cached"
1138 --all --tags --contains --abbrev= --candidates=
1139 --exact-match --debug --long --match --always
1143 __gitcomp_nl
"$(__git_refs)"
1146 __git_diff_algorithms
="myers minimal patience histogram"
1148 __git_diff_common_options
="--stat --numstat --shortstat --summary
1149 --patch-with-stat --name-only --name-status --color
1150 --no-color --color-words --no-renames --check
1151 --full-index --binary --abbrev --diff-filter=
1152 --find-copies-harder
1153 --text --ignore-space-at-eol --ignore-space-change
1154 --ignore-all-space --exit-code --quiet --ext-diff
1156 --no-prefix --src-prefix= --dst-prefix=
1157 --inter-hunk-context=
1158 --patience --histogram --minimal
1160 --dirstat --dirstat= --dirstat-by-file
1161 --dirstat-by-file= --cumulative
1167 __git_has_doubledash
&& return
1171 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1175 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1176 --base --ours --theirs --no-index
1177 $__git_diff_common_options
1182 __git_complete_revlist_file
1185 __git_mergetools_common
="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1186 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1191 __git_has_doubledash
&& return
1195 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1199 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1200 --base --ours --theirs
1201 --no-renames --diff-filter= --find-copies-harder
1202 --relative --ignore-submodules
1207 __git_complete_revlist_file
1210 __git_fetch_options
="
1211 --quiet --verbose --append --upload-pack --force --keep --depth=
1212 --tags --no-tags --all --prune --dry-run
1219 __gitcomp
"$__git_fetch_options"
1223 __git_complete_remote_or_refspec
1226 __git_format_patch_options
="
1227 --stdout --attach --no-attach --thread --thread= --no-thread
1228 --numbered --start-number --numbered-files --keep-subject --signoff
1229 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1230 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1231 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1232 --output-directory --reroll-count --to= --quiet --notes
1235 _git_format_patch
()
1241 " "" "${cur##--thread=}"
1245 __gitcomp
"$__git_format_patch_options"
1249 __git_complete_revlist
1257 --tags --root --unreachable --cache --no-reflogs --full
1258 --strict --verbose --lost-found
1269 __gitcomp
"--prune --aggressive"
1280 __git_match_ctag
() {
1281 awk "/^${1////\\/}/ { print \$1 }" "$2"
1286 __git_has_doubledash
&& return
1292 --text --ignore-case --word-regexp --invert-match
1293 --full-name --line-number
1294 --extended-regexp --basic-regexp --fixed-strings
1296 --files-with-matches --name-only
1297 --files-without-match
1300 --and --or --not --all-match
1306 case "$cword,$prev" in
1308 if test -r tags
; then
1309 __gitcomp_nl
"$(__git_match_ctag "$cur" tags)"
1315 __gitcomp_nl
"$(__git_refs)"
1322 __gitcomp
"--all --info --man --web"
1326 __git_compute_all_commands
1327 __gitcomp
"$__git_all_commands $(__git_aliases)
1328 attributes cli core-tutorial cvs-migration
1329 diffcore gitk glossary hooks ignore modules
1330 namespaces repository-layout tutorial tutorial-2
1340 false true umask group all world everybody
1341 " "" "${cur##--shared=}"
1345 __gitcomp
"--quiet --bare --template= --shared --shared="
1355 __gitcomp
"--cached --deleted --modified --others --ignored
1356 --stage --directory --no-empty-directory --unmerged
1357 --killed --exclude= --exclude-from=
1358 --exclude-per-directory= --exclude-standard
1359 --error-unmatch --with-tree= --full-name
1360 --abbrev --ignored --exclude-per-directory
1366 # XXX ignore options like --modified and always suggest all cached
1368 __git_complete_index_file
"--cached"
1373 __gitcomp_nl
"$(__git_remotes)"
1381 # Options that go well for log, shortlog and gitk
1382 __git_log_common_options
="
1384 --branches --tags --remotes
1385 --first-parent --merges --no-merges
1387 --max-age= --since= --after=
1388 --min-age= --until= --before=
1389 --min-parents= --max-parents=
1390 --no-min-parents --no-max-parents
1392 # Options that go well for log and gitk (not shortlog)
1393 __git_log_gitk_options
="
1394 --dense --sparse --full-history
1395 --simplify-merges --simplify-by-decoration
1396 --left-right --notes --no-notes
1398 # Options that go well for log and shortlog (not gitk)
1399 __git_log_shortlog_options
="
1400 --author= --committer= --grep=
1404 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1405 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1409 __git_has_doubledash
&& return
1411 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1413 if [ -f "$g/MERGE_HEAD" ]; then
1417 --pretty=*|
--format=*)
1418 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1423 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1427 __gitcomp
"long short" "" "${cur##--decorate=}"
1432 $__git_log_common_options
1433 $__git_log_shortlog_options
1434 $__git_log_gitk_options
1435 --root --topo-order --date-order --reverse
1436 --follow --full-diff
1437 --abbrev-commit --abbrev=
1438 --relative-date --date=
1439 --pretty= --format= --oneline
1442 --decorate --decorate=
1444 --parents --children
1446 $__git_diff_common_options
1447 --pickaxe-all --pickaxe-regex
1452 __git_complete_revlist
1455 __git_merge_options
="
1456 --no-commit --no-stat --log --no-log --squash --strategy
1457 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1462 __git_complete_strategy
&& return
1466 __gitcomp
"$__git_merge_options"
1469 __gitcomp_nl
"$(__git_refs)"
1476 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1488 __gitcomp_nl
"$(__git_refs)"
1495 __gitcomp
"--dry-run"
1500 if [ $
(__git_count_arguments
"mv") -gt 0 ]; then
1501 # We need to show both cached and untracked files (including
1502 # empty directories) since this may not be the last argument.
1503 __git_complete_index_file
"--cached --others --directory"
1505 __git_complete_index_file
"--cached"
1511 __gitcomp
"--tags --all --stdin"
1516 local subcommands
='add append copy edit list prune remove show'
1517 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1519 case "$subcommand,$cur" in
1526 __gitcomp_nl
"$(__git_refs)"
1529 __gitcomp
"$subcommands --ref"
1533 add
,--reuse-message=*|append
,--reuse-message=*|\
1534 add
,--reedit-message=*|append
,--reedit-message=*)
1535 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1538 __gitcomp
'--file= --message= --reedit-message=
1545 __gitcomp
'--dry-run --verbose'
1554 __gitcomp_nl
"$(__git_refs)"
1563 __git_complete_strategy
&& return
1568 --rebase --no-rebase
1569 $__git_merge_options
1570 $__git_fetch_options
1575 __git_complete_remote_or_refspec
1582 __gitcomp_nl
"$(__git_remotes)"
1587 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--repo=}"
1592 --all --mirror --tags --dry-run --force --verbose
1593 --receive-pack= --repo= --set-upstream
1598 __git_complete_remote_or_refspec
1603 local dir
="$(__gitdir)"
1604 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1605 __gitcomp
"--continue --skip --abort"
1608 __git_complete_strategy
&& return
1611 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1616 --onto --merge --strategy --interactive
1617 --preserve-merges --stat --no-stat
1618 --committer-date-is-author-date --ignore-date
1619 --ignore-whitespace --whitespace=
1625 __gitcomp_nl
"$(__git_refs)"
1630 local subcommands
="show delete expire"
1631 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1633 if [ -z "$subcommand" ]; then
1634 __gitcomp
"$subcommands"
1636 __gitcomp_nl
"$(__git_refs)"
1640 __git_send_email_confirm_options
="always never auto cc compose"
1641 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1648 $__git_send_email_confirm_options
1649 " "" "${cur##--confirm=}"
1654 $__git_send_email_suppresscc_options
1655 " "" "${cur##--suppress-cc=}"
1659 --smtp-encryption=*)
1660 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1666 " "" "${cur##--thread=}"
1670 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1671 --compose --confirm= --dry-run --envelope-sender
1673 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1674 --no-suppress-from --no-thread --quiet
1675 --signed-off-by-cc --smtp-pass --smtp-server
1676 --smtp-server-port --smtp-encryption= --smtp-user
1677 --subject --suppress-cc= --suppress-from --thread --to
1678 --validate --no-validate
1679 $__git_format_patch_options"
1683 __git_complete_revlist
1691 __git_config_get_set_variables
()
1693 local prevword word config_file
= c
=$cword
1694 while [ $c -gt 1 ]; do
1697 --system|
--global|
--local|
--file=*)
1702 config_file
="$word $prevword"
1710 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1724 branch.
*.remote|branch.
*.pushremote
)
1725 __gitcomp_nl
"$(__git_remotes)"
1729 __gitcomp_nl
"$(__git_refs)"
1733 __gitcomp
"false true"
1737 __gitcomp_nl
"$(__git_remotes)"
1741 local remote
="${prev#remote.}"
1742 remote
="${remote%.fetch}"
1743 if [ -z "$cur" ]; then
1744 __gitcomp_nl
"refs/heads/" "" "" ""
1747 __gitcomp_nl
"$(__git_refs_remotes "$remote")"
1751 local remote
="${prev#remote.}"
1752 remote
="${remote%.push}"
1753 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" \
1754 for-each-ref --format='%(refname):%(refname)' \
1758 pull.twohead|pull.octopus
)
1759 __git_compute_merge_strategies
1760 __gitcomp
"$__git_merge_strategies"
1763 color.branch|color.
diff|color.interactive|\
1764 color.showbranch|color.status|color.ui
)
1765 __gitcomp
"always never auto"
1769 __gitcomp
"false true"
1774 normal black red green yellow blue magenta cyan white
1775 bold dim ul blink reverse
1780 __gitcomp
"log short"
1784 __gitcomp
"man info web html"
1788 __gitcomp
"$__git_log_date_formats"
1791 sendemail.aliasesfiletype
)
1792 __gitcomp
"mutt mailrc pine elm gnus"
1796 __gitcomp
"$__git_send_email_confirm_options"
1799 sendemail.suppresscc
)
1800 __gitcomp
"$__git_send_email_suppresscc_options"
1803 --get|
--get-all|
--unset|
--unset-all)
1804 __gitcomp_nl
"$(__git_config_get_set_variables)"
1814 --system --global --local --file=
1815 --list --replace-all
1816 --get --get-all --get-regexp
1817 --add --unset --unset-all
1818 --remove-section --rename-section
1823 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1824 __gitcomp
"remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
1828 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1829 __gitcomp_nl
"$(__git_heads)" "$pfx" "$cur_" "."
1833 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1835 argprompt cmd confirm needsfile noconsole norescan
1836 prompt revprompt revunmerged title
1841 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1842 __gitcomp
"cmd path" "$pfx" "$cur_"
1846 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1847 __gitcomp
"cmd path" "$pfx" "$cur_"
1851 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1852 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur_"
1856 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1857 __git_compute_all_commands
1858 __gitcomp_nl
"$__git_all_commands" "$pfx" "$cur_"
1862 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1864 url proxy fetch push mirror skipDefaultUpdate
1865 receivepack uploadpack tagopt pushurl
1870 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1871 __gitcomp_nl
"$(__git_remotes)" "$pfx" "$cur_" "."
1875 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1876 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur_"
1882 advice.commitBeforeMerge
1884 advice.implicitIdentity
1885 advice.pushNonFastForward
1886 advice.resolveConflict
1890 apply.ignorewhitespace
1892 branch.autosetupmerge
1893 branch.autosetuprebase
1897 color.branch.current
1902 color.decorate.branch
1903 color.decorate.remoteBranch
1904 color.decorate.stash
1914 color.diff.whitespace
1919 color.grep.linenumber
1922 color.grep.separator
1924 color.interactive.error
1925 color.interactive.header
1926 color.interactive.help
1927 color.interactive.prompt
1932 color.status.changed
1934 color.status.nobranch
1935 color.status.untracked
1936 color.status.updated
1945 core.bigFileThreshold
1948 core.deltaBaseCacheLimit
1953 core.fsyncobjectfiles
1957 core.logAllRefUpdates
1958 core.loosecompression
1961 core.packedGitWindowSize
1963 core.preferSymlinkRefs
1966 core.repositoryFormatVersion
1968 core.sharedRepository
1972 core.warnAmbiguousRefs
1975 diff.autorefreshindex
1977 diff.ignoreSubmodules
1984 diff.suppressBlankEmpty
1990 fetch.recurseSubmodules
2000 format.subjectprefix
2011 gc.reflogexpireunreachable
2015 gitcvs.commitmsgannotation
2016 gitcvs.dbTableNamePrefix
2027 gui.copyblamethreshold
2031 gui.matchtrackingbranch
2032 gui.newbranchtemplate
2033 gui.pruneduringfetch
2034 gui.spellingdictionary
2049 http.sslCertPasswordProtected
2054 i18n.logOutputEncoding
2060 imap.preformattedHTML
2070 interactive.singlekey
2086 mergetool.keepBackup
2087 mergetool.keepTemporaries
2092 notes.rewrite.rebase
2096 pack.deltaCacheLimit
2112 receive.denyCurrentBranch
2113 receive.denyDeleteCurrent
2115 receive.denyNonFastForwards
2118 receive.updateserverinfo
2121 repack.usedeltabaseoffset
2125 sendemail.aliasesfile
2126 sendemail.aliasfiletype
2130 sendemail.chainreplyto
2132 sendemail.envelopesender
2136 sendemail.signedoffbycc
2137 sendemail.smtpdomain
2138 sendemail.smtpencryption
2140 sendemail.smtpserver
2141 sendemail.smtpserveroption
2142 sendemail.smtpserverport
2144 sendemail.suppresscc
2145 sendemail.suppressfrom
2150 status.relativePaths
2151 status.showUntrackedFiles
2152 status.submodulesummary
2155 transfer.unpackLimit
2167 local subcommands
="add rename remove set-head set-branches set-url show prune update"
2168 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2169 if [ -z "$subcommand" ]; then
2170 __gitcomp
"$subcommands"
2174 case "$subcommand" in
2175 rename|remove|set-url|show|prune
)
2176 __gitcomp_nl
"$(__git_remotes)"
2178 set-head|set-branches
)
2179 __git_complete_remote_or_refspec
2182 local i c
='' IFS
=$
'\n'
2183 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2196 __gitcomp_nl
"$(__git_refs)"
2201 __git_has_doubledash
&& return
2205 __gitcomp
"--merge --mixed --hard --soft --patch"
2209 __gitcomp_nl
"$(__git_refs)"
2216 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2220 __gitcomp_nl
"$(__git_refs)"
2227 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2232 __git_complete_index_file
"--cached"
2237 __git_has_doubledash
&& return
2242 $__git_log_common_options
2243 $__git_log_shortlog_options
2244 --numbered --summary
2249 __git_complete_revlist
2254 __git_has_doubledash
&& return
2257 --pretty=*|
--format=*)
2258 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2263 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2267 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2268 $__git_diff_common_options
2273 __git_complete_revlist_file
2281 --all --remotes --topo-order --current --more=
2282 --list --independent --merge-base --no-name
2284 --sha1-name --sparse --topics --reflog
2289 __git_complete_revlist
2294 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2295 local subcommands
='save list show apply clear drop pop create branch'
2296 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2297 if [ -z "$subcommand" ]; then
2300 __gitcomp
"$save_opts"
2303 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2304 __gitcomp
"$subcommands"
2309 case "$subcommand,$cur" in
2311 __gitcomp
"$save_opts"
2314 __gitcomp
"--index --quiet"
2316 show
,--*|drop
,--*|branch
,--*)
2318 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2319 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" stash list \
2320 | sed -n -e 's/:.*//p')"
2330 __git_has_doubledash
&& return
2332 local subcommands
="add status init deinit update summary foreach sync"
2333 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2336 __gitcomp
"--quiet --cached"
2339 __gitcomp
"$subcommands"
2349 init fetch clone rebase dcommit log find-rev
2350 set-tree commit-diff info create-ignore propget
2351 proplist show-ignore show-externals branch tag blame
2352 migrate mkdirs reset gc
2354 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2355 if [ -z "$subcommand" ]; then
2356 __gitcomp
"$subcommands"
2358 local remote_opts
="--username= --config-dir= --no-auth-cache"
2360 --follow-parent --authors-file= --repack=
2361 --no-metadata --use-svm-props --use-svnsync-props
2362 --log-window-size= --no-checkout --quiet
2363 --repack-flags --use-log-author --localtime
2364 --ignore-paths= --include-paths= $remote_opts
2367 --template= --shared= --trunk= --tags=
2368 --branches= --stdlayout --minimize-url
2369 --no-metadata --use-svm-props --use-svnsync-props
2370 --rewrite-root= --prefix= --use-log-author
2371 --add-author-from $remote_opts
2374 --edit --rmdir --find-copies-harder --copy-similarity=
2377 case "$subcommand,$cur" in
2379 __gitcomp
"--revision= --fetch-all $fc_opts"
2382 __gitcomp
"--revision= $fc_opts $init_opts"
2385 __gitcomp
"$init_opts"
2389 --merge --strategy= --verbose --dry-run
2390 --fetch-all --no-rebase --commit-url
2391 --revision --interactive $cmt_opts $fc_opts
2395 __gitcomp
"--stdin $cmt_opts $fc_opts"
2397 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2398 show-externals
,--*|mkdirs
,--*)
2399 __gitcomp
"--revision="
2403 --limit= --revision= --verbose --incremental
2404 --oneline --show-commit --non-recursive
2405 --authors-file= --color
2410 --merge --verbose --strategy= --local
2411 --fetch-all --dry-run $fc_opts
2415 __gitcomp
"--message= --file= --revision= $cmt_opts"
2421 __gitcomp
"--dry-run --message --tag"
2424 __gitcomp
"--dry-run --message"
2427 __gitcomp
"--git-format"
2431 --config-dir= --ignore-paths= --minimize
2432 --no-auth-cache --username=
2436 __gitcomp
"--revision= --parent"
2447 while [ $c -lt $cword ]; do
2451 __gitcomp_nl
"$(__git_tags)"
2466 __gitcomp_nl
"$(__git_tags)"
2470 __gitcomp_nl
"$(__git_refs)"
2482 local i c
=1 command __git_dir
2484 while [ $c -lt $cword ]; do
2487 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2488 --git-dir) ((c
++)) ; __git_dir
="${words[c]}" ;;
2489 --bare) __git_dir
="." ;;
2490 --help) command="help"; break ;;
2491 -c|
--work-tree|
--namespace) ((c
++)) ;;
2493 *) command="$i"; break ;;
2498 if [ -z "$command" ]; then
2513 --no-replace-objects
2517 *) __git_compute_porcelain_commands
2518 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2523 local completion_func
="_git_${command//-/_}"
2524 declare -f $completion_func >/dev
/null
&& $completion_func && return
2526 local expansion
=$
(__git_aliased_command
"$command")
2527 if [ -n "$expansion" ]; then
2528 completion_func
="_git_${expansion//-/_}"
2529 declare -f $completion_func >/dev
/null
&& $completion_func
2535 __git_has_doubledash
&& return
2537 local g
="$(__gitdir)"
2539 if [ -f "$g/MERGE_HEAD" ]; then
2545 $__git_log_common_options
2546 $__git_log_gitk_options
2552 __git_complete_revlist
2555 if [[ -n ${ZSH_VERSION-} ]]; then
2556 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2558 autoload
-U +X compinit
&& compinit
2564 local cur_
="${3-$cur}"
2570 local c IFS
=$
' \t\n'
2578 array
[${#array[@]}+1]="$c"
2581 compadd
-Q -S '' -p "${2-}" -a -- array
&& _ret
=0
2592 compadd
-Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2601 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2606 local _ret=1 cur cword prev
2607 cur=${words[CURRENT]}
2608 prev=${words[CURRENT-1]}
2610 emulate ksh -c __${service}_main
2611 let _ret && _default && _ret=0
2615 compdef _git git gitk
2621 local cur words cword prev
2622 _get_comp_words_by_ref -n =: cur words cword prev
2626 # Setup completion for certain functions defined above by setting common
2627 # variables and workarounds.
2628 # This is NOT a public function; use at your own risk.
2631 local wrapper="__git_wrap
${2}"
2632 eval "$wrapper () { __git_func_wrap
$2 ; }"
2633 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2634 || complete -o default -o nospace -F $wrapper $1
2637 # wrapper for backwards compatibility
2640 __git_wrap__git_main
2643 # wrapper for backwards compatibility
2646 __git_wrap__gitk_main
2649 __git_complete git __git_main
2650 __git_complete gitk __gitk_main
2652 # The following are necessary only for Cygwin, and only are needed
2653 # when the user has tab-completed the executable name and consequently
2654 # included the '.exe' suffix.
2656 if [ Cygwin = "$
(uname
-o 2>/dev
/null
)" ]; then
2657 __git_complete git.exe __git_main