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 # Tell Bash that compspec generates filenames.
258 compopt
-o filenames
2>/dev
/null
261 __git_index_file_list_filter_compat
()
265 while read -r path
; do
267 ?
*/*) echo "${path%%/*}/" ;;
273 __git_index_file_list_filter_bash
()
277 while read -r path
; do
280 # XXX if we append a slash to directory names when using
281 # `compopt -o filenames`, Bash will append another slash.
282 # This is pretty stupid, and this the reason why we have to
283 # define a compatible version for this function.
284 echo "${path%%/*}" ;;
291 # Process path list returned by "ls-files" and "diff-index --name-only"
292 # commands, in order to list only file names relative to a specified
293 # directory, and append a slash to directory names.
294 __git_index_file_list_filter
()
296 # Default to Bash >= 4.x
297 __git_index_file_list_filter_bash
300 # Execute 'git ls-files', unless the --committable option is specified, in
301 # which case it runs 'git diff-index' to find out the files that can be
302 # committed. It return paths relative to the directory specified in the first
303 # argument, and using the options specified in the second argument.
304 __git_ls_files_helper
()
307 test -n "${CDPATH+set}" && unset CDPATH
309 if [ "$2" == "--committable" ]; then
310 git diff-index
--name-only --relative HEAD
312 # NOTE: $2 is not quoted in order to support multiple options
313 git ls-files
--exclude-standard $2
319 # __git_index_files accepts 1 or 2 arguments:
320 # 1: Options to pass to ls-files (required).
321 # 2: A directory path (optional).
322 # If provided, only files within the specified directory are listed.
323 # Sub directories are never recursed. Path must have a trailing
327 local dir
="$(__gitdir)" root
="${2-.}"
329 if [ -d "$dir" ]; then
330 __git_ls_files_helper
"$root" "$1" | __git_index_file_list_filter |
337 local dir
="$(__gitdir)"
338 if [ -d "$dir" ]; then
339 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
347 local dir
="$(__gitdir)"
348 if [ -d "$dir" ]; then
349 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
355 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
356 # presence of 2nd argument means use the guess heuristic employed
357 # by checkout for tracking branches
360 local i
hash dir
="$(__gitdir "${1-}")" track
="${2-}"
362 if [ -d "$dir" ]; then
370 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
371 if [ -e "$dir/$i" ]; then echo $i; fi
373 format
="refname:short"
374 refs
="refs/tags refs/heads refs/remotes"
377 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
379 if [ -n "$track" ]; then
380 # employ the heuristic used by git checkout
381 # Try to find a remote branch that matches the completion word
382 # but only output if the branch name is unique
384 git
--git-dir="$dir" for-each-ref
--shell --format="ref=%(refname:short)" \
386 while read -r entry
; do
389 if [[ "$ref" == "$cur"* ]]; then
392 done |
sort |
uniq -u
398 git ls-remote
"$dir" "$cur*" 2>/dev
/null | \
399 while read -r hash i
; do
407 git ls-remote
"$dir" HEAD ORIG_HEAD
'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev
/null | \
408 while read -r hash i
; do
411 refs
/*) echo "${i#refs/*/}" ;;
419 # __git_refs2 requires 1 argument (to pass to __git_refs)
423 for i
in $
(__git_refs
"$1"); do
428 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
429 __git_refs_remotes
()
432 git ls-remote
"$1" 'refs/heads/*' 2>/dev
/null | \
433 while read -r hash i
; do
434 echo "$i:refs/remotes/$1/${i#refs/heads/}"
440 local i IFS
=$
'\n' d
="$(__gitdir)"
441 test -d "$d/remotes" && ls -1 "$d/remotes"
442 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
448 __git_list_merge_strategies
()
450 git merge
-s help 2>&1 |
451 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
460 __git_merge_strategies
=
461 # 'git merge -s help' (and thus detection of the merge strategy
462 # list) fails, unfortunately, if run outside of any git working
463 # tree. __git_merge_strategies is set to the empty string in
464 # that case, and the detection will be repeated the next time it
466 __git_compute_merge_strategies
()
468 test -n "$__git_merge_strategies" ||
469 __git_merge_strategies
=$
(__git_list_merge_strategies
)
472 __git_complete_revlist_file
()
474 local pfx
ls ref cur_
="$cur"
494 case "$COMP_WORDBREAKS" in
496 *) pfx
="$ref:$pfx" ;;
499 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" 2>/dev/null \
500 | sed '/^100... blob /{
516 pfx
="${cur_%...*}..."
518 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
523 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
526 __gitcomp_nl
"$(__git_refs)"
532 # __git_complete_index_file requires 1 argument:
533 # 1: the options to pass to ls-file
535 # The exception is --committable, which finds the files appropriate commit.
536 __git_complete_index_file
()
538 local pfx
="" cur_
="$cur"
548 __gitcomp_file
"$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
551 __git_complete_file
()
553 __git_complete_revlist_file
556 __git_complete_revlist
()
558 __git_complete_revlist_file
561 __git_complete_remote_or_refspec
()
563 local cur_
="$cur" cmd
="${words[1]}"
564 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
565 if [ "$cmd" = "remote" ]; then
568 while [ $c -lt $cword ]; do
571 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
574 push
) no_complete_refspec
=1 ;;
582 *) remote
="$i"; break ;;
586 if [ -z "$remote" ]; then
587 __gitcomp_nl
"$(__git_remotes)"
590 if [ $no_complete_refspec = 1 ]; then
593 [ "$remote" = "." ] && remote
=
596 case "$COMP_WORDBREAKS" in
598 *) pfx
="${cur_%%:*}:" ;;
610 if [ $lhs = 1 ]; then
611 __gitcomp_nl
"$(__git_refs2 "$remote")" "$pfx" "$cur_"
613 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
617 if [ $lhs = 1 ]; then
618 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
620 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
624 if [ $lhs = 1 ]; then
625 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
627 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
633 __git_complete_strategy
()
635 __git_compute_merge_strategies
638 __gitcomp
"$__git_merge_strategies"
643 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
651 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
653 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
655 git
help -a|
egrep '^ [a-zA-Z0-9]'
659 __git_list_all_commands
()
662 for i
in $
(__git_commands
)
665 *--*) : helper pattern
;;
672 __git_compute_all_commands
()
674 test -n "$__git_all_commands" ||
675 __git_all_commands
=$
(__git_list_all_commands
)
678 __git_list_porcelain_commands
()
681 __git_compute_all_commands
682 for i
in $__git_all_commands
685 *--*) : helper pattern
;;
686 applymbox
) : ask gittus
;;
687 applypatch
) : ask gittus
;;
688 archimport
) : import
;;
689 cat-file
) : plumbing
;;
690 check-attr
) : plumbing
;;
691 check-ignore
) : plumbing
;;
692 check-ref-format
) : plumbing
;;
693 checkout-index
) : plumbing
;;
694 commit-tree
) : plumbing
;;
695 count-objects
) : infrequent
;;
696 credential-cache
) : credentials helper
;;
697 credential-store
) : credentials helper
;;
698 cvsexportcommit
) : export;;
699 cvsimport
) : import
;;
700 cvsserver
) : daemon
;;
702 diff-files
) : plumbing
;;
703 diff-index
) : plumbing
;;
704 diff-tree
) : plumbing
;;
705 fast-import
) : import
;;
706 fast-export
) : export;;
707 fsck-objects
) : plumbing
;;
708 fetch-pack
) : plumbing
;;
709 fmt-merge-msg
) : plumbing
;;
710 for-each-ref
) : plumbing
;;
711 hash-object
) : plumbing
;;
712 http-
*) : transport
;;
713 index-pack
) : plumbing
;;
714 init-db
) : deprecated
;;
715 local-fetch
) : plumbing
;;
716 lost-found
) : infrequent
;;
717 ls-files
) : plumbing
;;
718 ls-remote
) : plumbing
;;
719 ls-tree
) : plumbing
;;
720 mailinfo
) : plumbing
;;
721 mailsplit
) : plumbing
;;
722 merge-
*) : plumbing
;;
725 pack-objects
) : plumbing
;;
726 pack-redundant
) : plumbing
;;
727 pack-refs
) : plumbing
;;
728 parse-remote
) : plumbing
;;
729 patch-id
) : plumbing
;;
730 peek-remote
) : plumbing
;;
732 prune-packed
) : plumbing
;;
733 quiltimport
) : import
;;
734 read-tree
) : plumbing
;;
735 receive-pack
) : plumbing
;;
736 remote-
*) : transport
;;
737 repo-config
) : deprecated
;;
739 rev-list
) : plumbing
;;
740 rev-parse
) : plumbing
;;
741 runstatus
) : plumbing
;;
742 sh-setup
) : internal
;;
744 show-ref
) : plumbing
;;
745 send-pack
) : plumbing
;;
746 show-index
) : plumbing
;;
748 stripspace
) : plumbing
;;
749 symbolic-ref
) : plumbing
;;
750 tar-tree
) : deprecated
;;
751 unpack-file
) : plumbing
;;
752 unpack-objects
) : plumbing
;;
753 update-index
) : plumbing
;;
754 update-ref
) : plumbing
;;
755 update-server-info
) : daemon
;;
756 upload-archive
) : plumbing
;;
757 upload-pack
) : plumbing
;;
758 write-tree
) : plumbing
;;
760 verify-pack
) : infrequent
;;
761 verify-tag
) : plumbing
;;
767 __git_porcelain_commands
=
768 __git_compute_porcelain_commands
()
770 __git_compute_all_commands
771 test -n "$__git_porcelain_commands" ||
772 __git_porcelain_commands
=$
(__git_list_porcelain_commands
)
775 __git_pretty_aliases
()
778 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "pretty\..*" 2>/dev
/null
); do
791 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
801 # __git_aliased_command requires 1 argument
802 __git_aliased_command
()
804 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
805 config
--get "alias.$1")
806 for word
in $cmdline; do
812 \
!*) : shell
command alias ;;
814 *=*) : setting env
;;
823 # __git_find_on_cmdline requires 1 argument
824 __git_find_on_cmdline
()
826 local word subcommand c
=1
827 while [ $c -lt $cword ]; do
829 for subcommand
in $1; do
830 if [ "$subcommand" = "$word" ]; then
839 __git_has_doubledash
()
842 while [ $c -lt $cword ]; do
843 if [ "--" = "${words[c]}" ]; then
851 # Try to count non option arguments passed on the command line for the
852 # specified git command.
853 # When options are used, it is necessary to use the special -- option to
854 # tell the implementation were non option arguments begin.
855 # XXX this can not be improved, since options can appear everywhere, as
859 # __git_count_arguments requires 1 argument: the git command executed.
860 __git_count_arguments
()
864 # Skip "git" (first argument)
865 for ((i
=1; i
< ${#words[@]}; i
++)); do
870 # Good; we can assume that the following are only non
875 # Skip the specified git command and discard git
888 __git_whitespacelist
="nowarn warn error error-all fix"
892 local dir
="$(__gitdir)"
893 if [ -d "$dir"/rebase-apply
]; then
894 __gitcomp
"--skip --continue --resolved --abort"
899 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
904 --3way --committer-date-is-author-date --ignore-date
905 --ignore-whitespace --ignore-space-change
906 --interactive --keep --no-utf8 --signoff --utf8
907 --whitespace= --scissors
917 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
922 --stat --numstat --summary --check --index
923 --cached --index-info --reverse --reject --unidiff-zero
924 --apply --no-add --exclude=
925 --ignore-whitespace --ignore-space-change
926 --whitespace= --inaccurate-eof --verbose
937 --interactive --refresh --patch --update --dry-run
938 --ignore-errors --intent-to-add
943 # XXX should we check for --update and --all options ?
944 __git_complete_index_file
"--others --modified"
951 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
955 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--remote=}"
960 --format= --list --verbose
961 --prefix= --remote= --exec=
971 __git_has_doubledash
&& return
973 local subcommands
="start bad good skip reset visualize replay log run"
974 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
975 if [ -z "$subcommand" ]; then
976 if [ -f "$(__gitdir)"/BISECT_START
]; then
977 __gitcomp
"$subcommands"
979 __gitcomp
"replay start"
984 case "$subcommand" in
985 bad|good|
reset|skip|start
)
986 __gitcomp_nl
"$(__git_refs)"
995 local i c
=1 only_local_ref
="n" has_r
="n"
997 while [ $c -lt $cword ]; do
1000 -d|
-m) only_local_ref
="y" ;;
1007 --set-upstream-to=*)
1008 __gitcomp
"$(__git_refs)" "" "${cur##--set-upstream-to=}"
1012 --color --no-color --verbose --abbrev= --no-abbrev
1013 --track --no-track --contains --merged --no-merged
1014 --set-upstream-to= --edit-description --list
1019 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1020 __gitcomp_nl
"$(__git_heads)"
1022 __gitcomp_nl
"$(__git_refs)"
1030 local cmd
="${words[2]}"
1033 __gitcomp
"create list-heads verify unbundle"
1036 # looking for a file
1041 __git_complete_revlist
1050 __git_has_doubledash
&& return
1054 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1058 --quiet --ours --theirs --track --no-track --merge
1059 --conflict= --orphan --patch
1063 # check if --track, --no-track, or --no-guess was specified
1064 # if so, disable DWIM mode
1065 local flags
="--track --no-track --no-guess" track
=1
1066 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1069 __gitcomp_nl
"$(__git_refs '' $track)"
1076 __gitcomp
"$(__git_refs)"
1081 local dir
="$(__gitdir)"
1082 if [ -f "$dir"/CHERRY_PICK_HEAD
]; then
1083 __gitcomp
"--continue --quit --abort"
1088 __gitcomp
"--edit --no-commit --signoff --strategy= --mainline"
1091 __gitcomp_nl
"$(__git_refs)"
1100 __gitcomp
"--dry-run --quiet"
1105 # XXX should we check for -x option ?
1106 __git_complete_index_file
"--others"
1138 __gitcomp_nl
"$(__git_refs)" "" "${cur}"
1145 __gitcomp
"default strip verbatim whitespace
1146 " "" "${cur##--cleanup=}"
1149 --reuse-message=*|
--reedit-message=*|\
1150 --fixup=*|
--squash=*)
1151 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1154 --untracked-files=*)
1155 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1160 --all --author= --signoff --verify --no-verify
1162 --amend --include --only --interactive
1163 --dry-run --reuse-message= --reedit-message=
1164 --reset-author --file= --message= --template=
1165 --cleanup= --untracked-files --untracked-files=
1166 --verbose --quiet --fixup= --squash=
1171 if git rev-parse
--verify --quiet HEAD
>/dev
/null
; then
1172 __git_complete_index_file
"--committable"
1174 # This is the first commit
1175 __git_complete_index_file
"--cached"
1184 --all --tags --contains --abbrev= --candidates=
1185 --exact-match --debug --long --match --always
1189 __gitcomp_nl
"$(__git_refs)"
1192 __git_diff_algorithms
="myers minimal patience histogram"
1194 __git_diff_common_options
="--stat --numstat --shortstat --summary
1195 --patch-with-stat --name-only --name-status --color
1196 --no-color --color-words --no-renames --check
1197 --full-index --binary --abbrev --diff-filter=
1198 --find-copies-harder
1199 --text --ignore-space-at-eol --ignore-space-change
1200 --ignore-all-space --exit-code --quiet --ext-diff
1202 --no-prefix --src-prefix= --dst-prefix=
1203 --inter-hunk-context=
1204 --patience --histogram --minimal
1206 --dirstat --dirstat= --dirstat-by-file
1207 --dirstat-by-file= --cumulative
1213 __git_has_doubledash
&& return
1217 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1221 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1222 --base --ours --theirs --no-index
1223 $__git_diff_common_options
1228 __git_complete_revlist_file
1231 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1232 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1237 __git_has_doubledash
&& return
1241 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1245 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1246 --base --ours --theirs
1247 --no-renames --diff-filter= --find-copies-harder
1248 --relative --ignore-submodules
1256 __git_fetch_options
="
1257 --quiet --verbose --append --upload-pack --force --keep --depth=
1258 --tags --no-tags --all --prune --dry-run
1265 __gitcomp
"$__git_fetch_options"
1269 __git_complete_remote_or_refspec
1272 __git_format_patch_options
="
1273 --stdout --attach --no-attach --thread --thread= --output-directory
1274 --numbered --start-number --numbered-files --keep-subject --signoff
1275 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1276 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1277 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1280 _git_format_patch
()
1286 " "" "${cur##--thread=}"
1290 __gitcomp
"$__git_format_patch_options"
1294 __git_complete_revlist
1302 --tags --root --unreachable --cache --no-reflogs --full
1303 --strict --verbose --lost-found
1314 __gitcomp
"--prune --aggressive"
1325 __git_match_ctag
() {
1326 awk "/^${1////\\/}/ { print \$1 }" "$2"
1331 __git_has_doubledash
&& return
1337 --text --ignore-case --word-regexp --invert-match
1338 --full-name --line-number
1339 --extended-regexp --basic-regexp --fixed-strings
1341 --files-with-matches --name-only
1342 --files-without-match
1345 --and --or --not --all-match
1351 case "$cword,$prev" in
1353 if test -r tags
; then
1354 __gitcomp_nl
"$(__git_match_ctag "$cur" tags)"
1360 __gitcomp_nl
"$(__git_refs)"
1367 __gitcomp
"--all --info --man --web"
1371 __git_compute_all_commands
1372 __gitcomp
"$__git_all_commands $(__git_aliases)
1373 attributes cli core-tutorial cvs-migration
1374 diffcore gitk glossary hooks ignore modules
1375 namespaces repository-layout tutorial tutorial-2
1385 false true umask group all world everybody
1386 " "" "${cur##--shared=}"
1390 __gitcomp
"--quiet --bare --template= --shared --shared="
1400 __gitcomp
"--cached --deleted --modified --others --ignored
1401 --stage --directory --no-empty-directory --unmerged
1402 --killed --exclude= --exclude-from=
1403 --exclude-per-directory= --exclude-standard
1404 --error-unmatch --with-tree= --full-name
1405 --abbrev --ignored --exclude-per-directory
1411 # XXX ignore options like --modified and always suggest all cached
1413 __git_complete_index_file
"--cached"
1418 __gitcomp_nl
"$(__git_remotes)"
1426 # Options that go well for log, shortlog and gitk
1427 __git_log_common_options
="
1429 --branches --tags --remotes
1430 --first-parent --merges --no-merges
1432 --max-age= --since= --after=
1433 --min-age= --until= --before=
1434 --min-parents= --max-parents=
1435 --no-min-parents --no-max-parents
1437 # Options that go well for log and gitk (not shortlog)
1438 __git_log_gitk_options
="
1439 --dense --sparse --full-history
1440 --simplify-merges --simplify-by-decoration
1441 --left-right --notes --no-notes
1443 # Options that go well for log and shortlog (not gitk)
1444 __git_log_shortlog_options
="
1445 --author= --committer= --grep=
1449 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1450 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1454 __git_has_doubledash
&& return
1456 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1458 if [ -f "$g/MERGE_HEAD" ]; then
1462 --pretty=*|
--format=*)
1463 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1468 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1472 __gitcomp
"long short" "" "${cur##--decorate=}"
1477 $__git_log_common_options
1478 $__git_log_shortlog_options
1479 $__git_log_gitk_options
1480 --root --topo-order --date-order --reverse
1481 --follow --full-diff
1482 --abbrev-commit --abbrev=
1483 --relative-date --date=
1484 --pretty= --format= --oneline
1487 --decorate --decorate=
1489 --parents --children
1491 $__git_diff_common_options
1492 --pickaxe-all --pickaxe-regex
1497 __git_complete_revlist
1500 __git_merge_options
="
1501 --no-commit --no-stat --log --no-log --squash --strategy
1502 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1507 __git_complete_strategy
&& return
1511 __gitcomp
"$__git_merge_options"
1514 __gitcomp_nl
"$(__git_refs)"
1521 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1533 __gitcomp_nl
"$(__git_refs)"
1540 __gitcomp
"--dry-run"
1545 if [ $
(__git_count_arguments
"mv") -gt 0 ]; then
1546 # We need to show both cached and untracked files (including
1547 # empty directories) since this may not be the last argument.
1548 __git_complete_index_file
"--cached --others --directory"
1550 __git_complete_index_file
"--cached"
1556 __gitcomp
"--tags --all --stdin"
1561 local subcommands
='add append copy edit list prune remove show'
1562 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1564 case "$subcommand,$cur" in
1571 __gitcomp_nl
"$(__git_refs)"
1574 __gitcomp
"$subcommands --ref"
1578 add
,--reuse-message=*|append
,--reuse-message=*|\
1579 add
,--reedit-message=*|append
,--reedit-message=*)
1580 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1583 __gitcomp
'--file= --message= --reedit-message=
1590 __gitcomp
'--dry-run --verbose'
1599 __gitcomp_nl
"$(__git_refs)"
1608 __git_complete_strategy
&& return
1613 --rebase --no-rebase
1614 $__git_merge_options
1615 $__git_fetch_options
1620 __git_complete_remote_or_refspec
1627 __gitcomp_nl
"$(__git_remotes)"
1632 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--repo=}"
1637 --all --mirror --tags --dry-run --force --verbose
1638 --receive-pack= --repo= --set-upstream
1643 __git_complete_remote_or_refspec
1648 local dir
="$(__gitdir)"
1649 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1650 __gitcomp
"--continue --skip --abort"
1653 __git_complete_strategy
&& return
1656 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1661 --onto --merge --strategy --interactive
1662 --preserve-merges --stat --no-stat
1663 --committer-date-is-author-date --ignore-date
1664 --ignore-whitespace --whitespace=
1670 __gitcomp_nl
"$(__git_refs)"
1675 local subcommands
="show delete expire"
1676 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1678 if [ -z "$subcommand" ]; then
1679 __gitcomp
"$subcommands"
1681 __gitcomp_nl
"$(__git_refs)"
1685 __git_send_email_confirm_options
="always never auto cc compose"
1686 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1693 $__git_send_email_confirm_options
1694 " "" "${cur##--confirm=}"
1699 $__git_send_email_suppresscc_options
1700 " "" "${cur##--suppress-cc=}"
1704 --smtp-encryption=*)
1705 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1711 " "" "${cur##--thread=}"
1715 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1716 --compose --confirm= --dry-run --envelope-sender
1718 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1719 --no-suppress-from --no-thread --quiet
1720 --signed-off-by-cc --smtp-pass --smtp-server
1721 --smtp-server-port --smtp-encryption= --smtp-user
1722 --subject --suppress-cc= --suppress-from --thread --to
1723 --validate --no-validate
1724 $__git_format_patch_options"
1728 __git_complete_revlist
1736 __git_config_get_set_variables
()
1738 local prevword word config_file
= c
=$cword
1739 while [ $c -gt 1 ]; do
1742 --system|
--global|
--local|
--file=*)
1747 config_file
="$word $prevword"
1755 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1770 __gitcomp_nl
"$(__git_remotes)"
1774 __gitcomp_nl
"$(__git_refs)"
1778 local remote
="${prev#remote.}"
1779 remote
="${remote%.fetch}"
1780 if [ -z "$cur" ]; then
1781 __gitcompadd
"refs/heads/" "" "" ""
1784 __gitcomp_nl
"$(__git_refs_remotes "$remote")"
1788 local remote
="${prev#remote.}"
1789 remote
="${remote%.push}"
1790 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" \
1791 for-each-ref --format='%(refname):%(refname)' \
1795 pull.twohead|pull.octopus
)
1796 __git_compute_merge_strategies
1797 __gitcomp
"$__git_merge_strategies"
1800 color.branch|color.
diff|color.interactive|\
1801 color.showbranch|color.status|color.ui
)
1802 __gitcomp
"always never auto"
1806 __gitcomp
"false true"
1811 normal black red green yellow blue magenta cyan white
1812 bold dim ul blink reverse
1817 __gitcomp
"man info web html"
1821 __gitcomp
"$__git_log_date_formats"
1824 sendemail.aliasesfiletype
)
1825 __gitcomp
"mutt mailrc pine elm gnus"
1829 __gitcomp
"$__git_send_email_confirm_options"
1832 sendemail.suppresscc
)
1833 __gitcomp
"$__git_send_email_suppresscc_options"
1836 --get|
--get-all|
--unset|
--unset-all)
1837 __gitcomp_nl
"$(__git_config_get_set_variables)"
1847 --system --global --local --file=
1848 --list --replace-all
1849 --get --get-all --get-regexp
1850 --add --unset --unset-all
1851 --remove-section --rename-section
1856 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1857 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur_"
1861 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1862 __gitcomp_nl
"$(__git_heads)" "$pfx" "$cur_" "."
1866 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1868 argprompt cmd confirm needsfile noconsole norescan
1869 prompt revprompt revunmerged title
1874 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1875 __gitcomp
"cmd path" "$pfx" "$cur_"
1879 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1880 __gitcomp
"cmd path" "$pfx" "$cur_"
1884 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1885 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur_"
1889 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1890 __git_compute_all_commands
1891 __gitcomp_nl
"$__git_all_commands" "$pfx" "$cur_"
1895 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1897 url proxy fetch push mirror skipDefaultUpdate
1898 receivepack uploadpack tagopt pushurl
1903 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1904 __gitcomp_nl
"$(__git_remotes)" "$pfx" "$cur_" "."
1908 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1909 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur_"
1915 advice.commitBeforeMerge
1917 advice.implicitIdentity
1918 advice.pushNonFastForward
1919 advice.resolveConflict
1923 apply.ignorewhitespace
1925 branch.autosetupmerge
1926 branch.autosetuprebase
1930 color.branch.current
1935 color.decorate.branch
1936 color.decorate.remoteBranch
1937 color.decorate.stash
1947 color.diff.whitespace
1952 color.grep.linenumber
1955 color.grep.separator
1957 color.interactive.error
1958 color.interactive.header
1959 color.interactive.help
1960 color.interactive.prompt
1965 color.status.changed
1967 color.status.nobranch
1968 color.status.untracked
1969 color.status.updated
1978 core.bigFileThreshold
1981 core.deltaBaseCacheLimit
1986 core.fsyncobjectfiles
1988 core.ignoreCygwinFSTricks
1991 core.logAllRefUpdates
1992 core.loosecompression
1995 core.packedGitWindowSize
1997 core.preferSymlinkRefs
2000 core.repositoryFormatVersion
2002 core.sharedRepository
2006 core.warnAmbiguousRefs
2009 diff.autorefreshindex
2012 diff.ignoreSubmodules
2017 diff.suppressBlankEmpty
2023 fetch.recurseSubmodules
2032 format.subjectprefix
2043 gc.reflogexpireunreachable
2047 gitcvs.commitmsgannotation
2048 gitcvs.dbTableNamePrefix
2059 gui.copyblamethreshold
2063 gui.matchtrackingbranch
2064 gui.newbranchtemplate
2065 gui.pruneduringfetch
2066 gui.spellingdictionary
2081 http.sslCertPasswordProtected
2086 i18n.logOutputEncoding
2092 imap.preformattedHTML
2102 interactive.singlekey
2118 mergetool.keepBackup
2119 mergetool.keepTemporaries
2124 notes.rewrite.rebase
2128 pack.deltaCacheLimit
2144 receive.denyCurrentBranch
2145 receive.denyDeleteCurrent
2147 receive.denyNonFastForwards
2150 receive.updateserverinfo
2152 repack.usedeltabaseoffset
2156 sendemail.aliasesfile
2157 sendemail.aliasfiletype
2161 sendemail.chainreplyto
2163 sendemail.envelopesender
2167 sendemail.signedoffbycc
2168 sendemail.smtpdomain
2169 sendemail.smtpencryption
2171 sendemail.smtpserver
2172 sendemail.smtpserveroption
2173 sendemail.smtpserverport
2175 sendemail.suppresscc
2176 sendemail.suppressfrom
2181 status.relativePaths
2182 status.showUntrackedFiles
2183 status.submodulesummary
2186 transfer.unpackLimit
2198 local subcommands
="add rename remove set-head set-branches set-url show prune update"
2199 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2200 if [ -z "$subcommand" ]; then
2201 __gitcomp
"$subcommands"
2205 case "$subcommand" in
2206 rename|remove|set-url|show|prune
)
2207 __gitcomp_nl
"$(__git_remotes)"
2209 set-head|set-branches
)
2210 __git_complete_remote_or_refspec
2213 local i c
='' IFS
=$
'\n'
2214 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2227 __gitcomp_nl
"$(__git_refs)"
2232 __git_has_doubledash
&& return
2236 __gitcomp
"--merge --mixed --hard --soft --patch"
2240 __gitcomp_nl
"$(__git_refs)"
2247 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2251 __gitcomp_nl
"$(__git_refs)"
2258 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2263 __git_complete_index_file
"--cached"
2268 __git_has_doubledash
&& return
2273 $__git_log_common_options
2274 $__git_log_shortlog_options
2275 --numbered --summary
2280 __git_complete_revlist
2285 __git_has_doubledash
&& return
2288 --pretty=*|
--format=*)
2289 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2294 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2298 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2299 $__git_diff_common_options
2312 --all --remotes --topo-order --current --more=
2313 --list --independent --merge-base --no-name
2315 --sha1-name --sparse --topics --reflog
2320 __git_complete_revlist
2325 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2326 local subcommands
='save list show apply clear drop pop create branch'
2327 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2328 if [ -z "$subcommand" ]; then
2331 __gitcomp
"$save_opts"
2334 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2335 __gitcomp
"$subcommands"
2340 case "$subcommand,$cur" in
2342 __gitcomp
"$save_opts"
2345 __gitcomp
"--index --quiet"
2347 show
,--*|drop
,--*|branch
,--*)
2349 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2350 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" stash list \
2351 | sed -n -e 's/:.*//p')"
2361 __git_has_doubledash
&& return
2363 local subcommands
="add status init deinit update summary foreach sync"
2364 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2367 __gitcomp
"--quiet --cached"
2370 __gitcomp
"$subcommands"
2380 init fetch clone rebase dcommit log find-rev
2381 set-tree commit-diff info create-ignore propget
2382 proplist show-ignore show-externals branch tag blame
2383 migrate mkdirs reset gc
2385 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2386 if [ -z "$subcommand" ]; then
2387 __gitcomp
"$subcommands"
2389 local remote_opts
="--username= --config-dir= --no-auth-cache"
2391 --follow-parent --authors-file= --repack=
2392 --no-metadata --use-svm-props --use-svnsync-props
2393 --log-window-size= --no-checkout --quiet
2394 --repack-flags --use-log-author --localtime
2395 --ignore-paths= $remote_opts
2398 --template= --shared= --trunk= --tags=
2399 --branches= --stdlayout --minimize-url
2400 --no-metadata --use-svm-props --use-svnsync-props
2401 --rewrite-root= --prefix= --use-log-author
2402 --add-author-from $remote_opts
2405 --edit --rmdir --find-copies-harder --copy-similarity=
2408 case "$subcommand,$cur" in
2410 __gitcomp
"--revision= --fetch-all $fc_opts"
2413 __gitcomp
"--revision= $fc_opts $init_opts"
2416 __gitcomp
"$init_opts"
2420 --merge --strategy= --verbose --dry-run
2421 --fetch-all --no-rebase --commit-url
2422 --revision --interactive $cmt_opts $fc_opts
2426 __gitcomp
"--stdin $cmt_opts $fc_opts"
2428 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2429 show-externals
,--*|mkdirs
,--*)
2430 __gitcomp
"--revision="
2434 --limit= --revision= --verbose --incremental
2435 --oneline --show-commit --non-recursive
2436 --authors-file= --color
2441 --merge --verbose --strategy= --local
2442 --fetch-all --dry-run $fc_opts
2446 __gitcomp
"--message= --file= --revision= $cmt_opts"
2452 __gitcomp
"--dry-run --message --tag"
2455 __gitcomp
"--dry-run --message"
2458 __gitcomp
"--git-format"
2462 --config-dir= --ignore-paths= --minimize
2463 --no-auth-cache --username=
2467 __gitcomp
"--revision= --parent"
2478 while [ $c -lt $cword ]; do
2482 __gitcomp_nl
"$(__git_tags)"
2497 __gitcomp_nl
"$(__git_tags)"
2501 __gitcomp_nl
"$(__git_refs)"
2513 local i c
=1 command __git_dir
2515 while [ $c -lt $cword ]; do
2518 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2519 --bare) __git_dir
="." ;;
2520 --help) command="help"; break ;;
2523 *) command="$i"; break ;;
2528 if [ -z "$command" ]; then
2542 --no-replace-objects
2546 *) __git_compute_porcelain_commands
2547 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2552 local completion_func
="_git_${command//-/_}"
2553 declare -f $completion_func >/dev
/null
&& $completion_func && return
2555 local expansion
=$
(__git_aliased_command
"$command")
2556 if [ -n "$expansion" ]; then
2557 completion_func
="_git_${expansion//-/_}"
2558 declare -f $completion_func >/dev
/null
&& $completion_func
2564 __git_has_doubledash
&& return
2566 local g
="$(__gitdir)"
2568 if [ -f "$g/MERGE_HEAD" ]; then
2574 $__git_log_common_options
2575 $__git_log_gitk_options
2581 __git_complete_revlist
2584 if [[ -n ${ZSH_VERSION-} ]]; then
2585 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2587 autoload
-U +X compinit
&& compinit
2593 local cur_
="${3-$cur}"
2599 local c IFS
=$
' \t\n'
2607 array
[$#array+1]="$c"
2610 compadd
-Q -S '' -p "${2-}" -a -- array
&& _ret
=0
2621 compadd
-Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2630 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2636 local cur cword prev
2637 cur=${words[CURRENT-1]}
2638 prev=${words[CURRENT-2]}
2648 let _ret && _default -S '' && _ret=0
2652 compdef _git git gitk
2654 elif [[ -n ${BASH_VERSION-} ]]; then
2655 if ((${BASH_VERSINFO[0]} < 4)); then
2656 # compopt is not supported
2657 __git_index_file_list_filter ()
2659 __git_index_file_list_filter_compat
2666 local cur words cword prev
2667 _get_comp_words_by_ref -n =: cur words cword prev
2671 # Setup completion for certain functions defined above by setting common
2672 # variables and workarounds.
2673 # This is NOT a public function; use at your own risk.
2676 local wrapper="__git_wrap
${2}"
2677 eval "$wrapper () { __git_func_wrap
$2 ; }"
2678 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2679 || complete -o default -o nospace -F $wrapper $1
2682 # wrapper for backwards compatibility
2685 __git_wrap__git_main
2688 # wrapper for backwards compatibility
2691 __git_wrap__gitk_main
2694 __git_complete git __git_main
2695 __git_complete gitk __gitk_main
2697 # The following are necessary only for Cygwin, and only are needed
2698 # when the user has tab-completed the executable name and consequently
2699 # included the '.exe' suffix.
2701 if [ Cygwin = "$
(uname
-o 2>/dev
/null
)" ]; then
2702 __git_complete git.exe __git_main