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
69 # The following function is based on code from:
71 # bash_completion - programmable completion functions for bash 3.2+
73 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
74 # © 2009-2010, Bash Completion Maintainers
75 # <bash-completion-devel@lists.alioth.debian.org>
77 # This program is free software; you can redistribute it and/or modify
78 # it under the terms of the GNU General Public License as published by
79 # the Free Software Foundation; either version 2, or (at your option)
82 # This program is distributed in the hope that it will be useful,
83 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85 # GNU General Public License for more details.
87 # You should have received a copy of the GNU General Public License
88 # along with this program; if not, write to the Free Software Foundation,
89 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
91 # The latest version of this software can be obtained here:
93 # http://bash-completion.alioth.debian.org/
97 # This function can be used to access a tokenized list of words
98 # on the command line:
100 # __git_reassemble_comp_words_by_ref '=:'
101 # if test "${words_[cword_-1]}" = -w
106 # The argument should be a collection of characters from the list of
107 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
110 # This is roughly equivalent to going back in time and setting
111 # COMP_WORDBREAKS to exclude those characters. The intent is to
112 # make option types like --date=<type> and <rev>:<path> easy to
113 # recognize by treating each shell word as a single token.
115 # It is best not to set COMP_WORDBREAKS directly because the value is
116 # shared with other completion scripts. By the time the completion
117 # function gets called, COMP_WORDS has already been populated so local
118 # changes to COMP_WORDBREAKS have no effect.
120 # Output: words_, cword_, cur_.
122 __git_reassemble_comp_words_by_ref
()
124 local exclude i j first
125 # Which word separators to exclude?
126 exclude
="${1//[^$COMP_WORDBREAKS]}"
128 if [ -z "$exclude" ]; then
129 words_
=("${COMP_WORDS[@]}")
132 # List of word completion separators has shrunk;
133 # re-assemble words to complete.
134 for ((i
=0, j
=0; i
< ${#COMP_WORDS[@]}; i
++, j
++)); do
135 # Append each nonempty word consisting of just
136 # word separator characters to the current word.
140 [ -n "${COMP_WORDS[$i]}" ] &&
141 # word consists of excluded word separators
142 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
144 # Attach to the previous token,
145 # unless the previous token is the command name.
146 if [ $j -ge 2 ] && [ -n "$first" ]; then
150 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
151 if [ $i = $COMP_CWORD ]; then
154 if (($i < ${#COMP_WORDS[@]} - 1)); then
161 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
162 if [ $i = $COMP_CWORD ]; then
168 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
169 _get_comp_words_by_ref
()
171 local exclude cur_ words_ cword_
172 if [ "$1" = "-n" ]; then
176 __git_reassemble_comp_words_by_ref
"$exclude"
177 cur_
=${words_[cword_]}
178 while [ $# -gt 0 ]; do
184 prev
=${words_[$cword_-1]}
187 words
=("${words_[@]}")
200 COMPREPLY
=($
(compgen
-W "$1" -P "$2" -S "$4" -- "$3"))
203 # Generates completion reply with compgen, appending a space to possible
204 # completion words, if necessary.
205 # It accepts 1 to 4 arguments:
206 # 1: List of possible completion words.
207 # 2: A prefix to be added to each possible completion word (optional).
208 # 3: Generate possible completion matches for this word (optional).
209 # 4: A suffix to be appended to each possible completion word (optional).
212 local cur_
="${3-$cur}"
219 __gitcompadd
"$(__gitcomp_1 "${1-}" "${4-}")" "${2-}" "$cur_" ""
224 # Generates completion reply with compgen from newline-separated possible
225 # completion words by appending a space to all of them.
226 # It accepts 1 to 4 arguments:
227 # 1: List of possible completion words, separated by a single newline.
228 # 2: A prefix to be added to each possible completion word (optional).
229 # 3: Generate possible completion matches for this word (optional).
230 # 4: A suffix to be appended to each possible completion word instead of
231 # the default space (optional). If specified but empty, nothing is
236 __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
239 # Generates completion reply with compgen from newline-separated possible
240 # completion filenames.
241 # It accepts 1 to 3 arguments:
242 # 1: List of possible completion filenames, separated by a single newline.
243 # 2: A directory prefix to be added to each possible completion filename
245 # 3: Generate possible completion matches for this word (optional).
250 # XXX does not work when the directory prefix contains a tilde,
251 # since tilde expansion is not applied.
252 # This means that COMPREPLY will be empty and Bash default
253 # completion will be used.
254 COMPREPLY=($(compgen -P "${2-}" -W "$1" -- "${3-$cur}"))
256 # Tell Bash that compspec generates filenames.
257 compopt -o filenames 2>/dev/null
260 __git_index_file_list_filter_compat ()
264 while read -r path; do
266 ?*/*) echo "${path%%/*}/" ;;
272 __git_index_file_list_filter_bash ()
276 while read -r path; do
279 # XXX if we append a slash to directory names when using
280 # `compopt -o filenames`, Bash will append another slash.
281 # This is pretty stupid, and this the reason why we have to
282 # define a compatible version for this function.
283 echo "${path%%/*}" ;;
290 # Process path list returned by "ls-files
" and "diff-index
--name-only"
291 # commands, in order to list only file names relative to a specified
292 # directory, and append a slash to directory names.
293 __git_index_file_list_filter ()
295 # Default to Bash >= 4.x
296 __git_index_file_list_filter_bash
299 # Execute git ls-files, returning paths relative to the directory
300 # specified in the first argument, and using the options specified in
301 # the second argument.
302 __git_ls_files_helper ()
305 test -n "${CDPATH+set}" && unset CDPATH
306 # NOTE: $2 is not quoted in order to support multiple options
307 cd "$1" && git ls-files --exclude-standard $2
312 # Execute git diff-index, returning paths relative to the directory
313 # specified in the first argument, and using the tree object id
314 # specified in the second argument.
315 __git_diff_index_helper ()
318 test -n "${CDPATH+set}" && unset CDPATH
319 cd "$1" && git diff-index --name-only --relative "$2"
323 # __git_index_files accepts 1 or 2 arguments:
324 # 1: Options to pass to ls-files (required).
325 # Supported options are --cached, --modified, --deleted, --others,
327 # 2: A directory path (optional).
328 # If provided, only files within the specified directory are listed.
329 # Sub directories are never recursed. Path must have a trailing
333 local dir="$
(__gitdir
)" root="${2-.}"
335 if [ -d "$dir" ]; then
336 __git_ls_files_helper "$root" "$1" | __git_index_file_list_filter |
341 # __git_diff_index_files accepts 1 or 2 arguments:
342 # 1) The id of a tree object.
343 # 2) A directory path (optional).
344 # If provided, only files within the specified directory are listed.
345 # Sub directories are never recursed. Path must have a trailing
347 __git_diff_index_files ()
349 local dir="$
(__gitdir
)" root="${2-.}"
351 if [ -d "$dir" ]; then
352 __git_diff_index_helper "$root" "$1" | __git_index_file_list_filter |
359 local dir="$
(__gitdir
)"
360 if [ -d "$dir" ]; then
361 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
369 local dir="$
(__gitdir
)"
370 if [ -d "$dir" ]; then
371 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
377 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
378 # presence of 2nd argument means use the guess heuristic employed
379 # by checkout for tracking branches
382 local i hash dir="$
(__gitdir
"${1-}")" track="${2-}"
384 if [ -d "$dir" ]; then
392 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
393 if [ -e "$dir/$i" ]; then echo $i; fi
395 format="refname
:short
"
396 refs="refs
/tags refs
/heads refs
/remotes
"
399 git --git-dir="$dir" for-each-ref --format="%($format)" \
401 if [ -n "$track" ]; then
402 # employ the heuristic used by git checkout
403 # Try to find a remote branch that matches the completion word
404 # but only output if the branch name is unique
406 git --git-dir="$dir" for-each-ref --shell --format="ref
=%(refname
:short
)" \
408 while read -r entry; do
411 if [[ "$ref" == "$cur"* ]]; then
414 done | sort | uniq -u
420 git ls-remote "$dir" "$cur*" 2>/dev/null | \
421 while read -r hash i; do
429 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
430 while read -r hash i; do
433 refs/*) echo "${i#refs/*/}" ;;
441 # __git_refs2 requires 1 argument (to pass to __git_refs)
445 for i in $(__git_refs "$1"); do
450 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
451 __git_refs_remotes ()
454 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
455 while read -r hash i; do
456 echo "$i:refs
/remotes
/$1/${i#refs/heads/}"
462 local i IFS=$'\n' d="$
(__gitdir
)"
463 test -d "$d/remotes
" && ls -1 "$d/remotes
"
464 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
470 __git_list_merge_strategies ()
472 git merge -s help 2>&1 |
473 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
482 __git_merge_strategies=
483 # 'git merge -s help' (and thus detection of the merge strategy
484 # list) fails, unfortunately, if run outside of any git working
485 # tree. __git_merge_strategies is set to the empty string in
486 # that case, and the detection will be repeated the next time it
488 __git_compute_merge_strategies ()
490 test -n "$__git_merge_strategies" ||
491 __git_merge_strategies=$(__git_list_merge_strategies)
494 __git_complete_revlist_file ()
496 local pfx ls ref cur_="$cur"
516 case "$COMP_WORDBREAKS" in
518 *) pfx="$ref:$pfx" ;;
521 __gitcomp_nl "$
(git
--git-dir="$(__gitdir)" ls-tree
"$ls" 2>/dev
/null \
522 |
sed '/^100... blob /{
538 pfx="${cur_%...*}...
"
540 __gitcomp_nl "$
(__git_refs
)" "$pfx" "$cur_"
545 __gitcomp_nl "$
(__git_refs
)" "$pfx" "$cur_"
548 __gitcomp_nl "$
(__git_refs
)"
554 # __git_complete_index_file requires 1 argument: the options to pass to
556 __git_complete_index_file ()
558 local pfx cur_="$cur"
566 __gitcomp_file "$
(__git_index_files
"$1" "$pfx")" "$pfx" "$cur_"
569 __gitcomp_file "$
(__git_index_files
"$1")" "" "$cur_"
574 # __git_complete_diff_index_file requires 1 argument: the id of a tree
576 __git_complete_diff_index_file ()
578 local pfx cur_="$cur"
586 __gitcomp_file "$
(__git_diff_index_files
"$1" "$pfx")" "$pfx" "$cur_"
589 __gitcomp_file "$
(__git_diff_index_files
"$1")" "" "$cur_"
594 __git_complete_file ()
596 __git_complete_revlist_file
599 __git_complete_revlist ()
601 __git_complete_revlist_file
604 __git_complete_remote_or_refspec ()
606 local cur_="$cur" cmd="${words[1]}"
607 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
608 if [ "$cmd" = "remote
" ]; then
611 while [ $c -lt $cword ]; do
614 --mirror) [ "$cmd" = "push
" ] && no_complete_refspec=1 ;;
617 push) no_complete_refspec=1 ;;
625 *) remote="$i"; break ;;
629 if [ -z "$remote" ]; then
630 __gitcomp_nl "$
(__git_remotes
)"
633 if [ $no_complete_refspec = 1 ]; then
636 [ "$remote" = ".
" ] && remote=
639 case "$COMP_WORDBREAKS" in
641 *) pfx="${cur_%%:*}:" ;;
653 if [ $lhs = 1 ]; then
654 __gitcomp_nl "$
(__git_refs2
"$remote")" "$pfx" "$cur_"
656 __gitcomp_nl "$
(__git_refs
)" "$pfx" "$cur_"
660 if [ $lhs = 1 ]; then
661 __gitcomp_nl "$
(__git_refs
"$remote")" "$pfx" "$cur_"
663 __gitcomp_nl "$
(__git_refs
)" "$pfx" "$cur_"
667 if [ $lhs = 1 ]; then
668 __gitcomp_nl "$
(__git_refs
)" "$pfx" "$cur_"
670 __gitcomp_nl "$
(__git_refs
"$remote")" "$pfx" "$cur_"
676 __git_complete_strategy ()
678 __git_compute_merge_strategies
681 __gitcomp "$__git_merge_strategies"
686 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
694 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
696 printf "%s
" "${GIT_TESTING_COMMAND_COMPLETION}"
698 git help -a|egrep '^ [a-zA-Z0-9]'
702 __git_list_all_commands ()
705 for i in $(__git_commands)
708 *--*) : helper pattern;;
715 __git_compute_all_commands ()
717 test -n "$__git_all_commands" ||
718 __git_all_commands=$(__git_list_all_commands)
721 __git_list_porcelain_commands ()
724 __git_compute_all_commands
725 for i in $__git_all_commands
728 *--*) : helper pattern;;
729 applymbox) : ask gittus;;
730 applypatch) : ask gittus;;
731 archimport) : import;;
732 cat-file) : plumbing;;
733 check-attr) : plumbing;;
734 check-ignore) : plumbing;;
735 check-ref-format) : plumbing;;
736 checkout-index) : plumbing;;
737 commit-tree) : plumbing;;
738 count-objects) : infrequent;;
739 credential-cache) : credentials helper;;
740 credential-store) : credentials helper;;
741 cvsexportcommit) : export;;
742 cvsimport) : import;;
743 cvsserver) : daemon;;
745 diff-files) : plumbing;;
746 diff-index) : plumbing;;
747 diff-tree) : plumbing;;
748 fast-import) : import;;
749 fast-export) : export;;
750 fsck-objects) : plumbing;;
751 fetch-pack) : plumbing;;
752 fmt-merge-msg) : plumbing;;
753 for-each-ref) : plumbing;;
754 hash-object) : plumbing;;
755 http-*) : transport;;
756 index-pack) : plumbing;;
757 init-db) : deprecated;;
758 local-fetch) : plumbing;;
759 lost-found) : infrequent;;
760 ls-files) : plumbing;;
761 ls-remote) : plumbing;;
762 ls-tree) : plumbing;;
763 mailinfo) : plumbing;;
764 mailsplit) : plumbing;;
765 merge-*) : plumbing;;
768 pack-objects) : plumbing;;
769 pack-redundant) : plumbing;;
770 pack-refs) : plumbing;;
771 parse-remote) : plumbing;;
772 patch-id) : plumbing;;
773 peek-remote) : plumbing;;
775 prune-packed) : plumbing;;
776 quiltimport) : import;;
777 read-tree) : plumbing;;
778 receive-pack) : plumbing;;
779 remote-*) : transport;;
780 repo-config) : deprecated;;
782 rev-list) : plumbing;;
783 rev-parse) : plumbing;;
784 runstatus) : plumbing;;
785 sh-setup) : internal;;
787 show-ref) : plumbing;;
788 send-pack) : plumbing;;
789 show-index) : plumbing;;
791 stripspace) : plumbing;;
792 symbolic-ref) : plumbing;;
793 tar-tree) : deprecated;;
794 unpack-file) : plumbing;;
795 unpack-objects) : plumbing;;
796 update-index) : plumbing;;
797 update-ref) : plumbing;;
798 update-server-info) : daemon;;
799 upload-archive) : plumbing;;
800 upload-pack) : plumbing;;
801 write-tree) : plumbing;;
803 verify-pack) : infrequent;;
804 verify-tag) : plumbing;;
810 __git_porcelain_commands=
811 __git_compute_porcelain_commands ()
813 __git_compute_all_commands
814 test -n "$__git_porcelain_commands" ||
815 __git_porcelain_commands=$(__git_list_porcelain_commands)
818 __git_pretty_aliases ()
821 for i in $(git --git-dir="$
(__gitdir
)" config --get-regexp "pretty\..
*" 2>/dev/null); do
834 for i in $(git --git-dir="$
(__gitdir
)" config --get-regexp "alias\..
*" 2>/dev/null); do
844 # __git_aliased_command requires 1 argument
845 __git_aliased_command ()
847 local word cmdline=$(git --git-dir="$
(__gitdir
)" \
848 config --get "alias.
$1")
849 for word in $cmdline; do
855 \!*) : shell command alias ;;
857 *=*) : setting env ;;
866 # __git_find_on_cmdline requires 1 argument
867 __git_find_on_cmdline ()
869 local word subcommand c=1
870 while [ $c -lt $cword ]; do
872 for subcommand in $1; do
873 if [ "$subcommand" = "$word" ]; then
882 __git_has_doubledash ()
885 while [ $c -lt $cword ]; do
886 if [ "--" = "${words[c]}" ]; then
894 # Try to count non option arguments passed on the command line for the
895 # specified git command.
896 # When options are used, it is necessary to use the special -- option to
897 # tell the implementation were non option arguments begin.
898 # XXX this can not be improved, since options can appear everywhere, as
902 # __git_count_arguments requires 1 argument: the git command executed.
903 __git_count_arguments ()
907 # Skip "git
" (first argument)
908 for ((i=1; i < ${#words[@]}; i++)); do
913 # Good; we can assume that the following are only non
918 # Skip the specified git command and discard git
931 __git_whitespacelist="nowarn warn error error-all fix
"
935 local dir="$
(__gitdir
)"
936 if [ -d "$dir"/rebase-apply ]; then
937 __gitcomp "--skip --continue --resolved --abort"
942 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
947 --3way --committer-date-is-author-date --ignore-date
948 --ignore-whitespace --ignore-space-change
949 --interactive --keep --no-utf8 --signoff --utf8
950 --whitespace= --scissors
960 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
965 --stat --numstat --summary --check --index
966 --cached --index-info --reverse --reject --unidiff-zero
967 --apply --no-add --exclude=
968 --ignore-whitespace --ignore-space-change
969 --whitespace= --inaccurate-eof --verbose
980 --interactive --refresh --patch --update --dry-run
981 --ignore-errors --intent-to-add
986 # XXX should we check for --update and --all options ?
987 __git_complete_index_file "--others --modified"
994 __gitcomp "$
(git archive
--list)" "" "${cur##--format=}"
998 __gitcomp_nl "$
(__git_remotes
)" "" "${cur##--remote=}"
1003 --format= --list --verbose
1004 --prefix= --remote= --exec=
1014 __git_has_doubledash && return
1016 local subcommands="start bad good skip
reset visualize replay log run
"
1017 local subcommand="$
(__git_find_on_cmdline
"$subcommands")"
1018 if [ -z "$subcommand" ]; then
1019 if [ -f "$
(__gitdir
)"/BISECT_START ]; then
1020 __gitcomp "$subcommands"
1022 __gitcomp "replay start
"
1027 case "$subcommand" in
1028 bad|good|reset|skip|start)
1029 __gitcomp_nl "$
(__git_refs
)"
1038 local i c=1 only_local_ref="n
" has_r="n
"
1040 while [ $c -lt $cword ]; do
1043 -d|-m) only_local_ref="y
" ;;
1050 --set-upstream-to=*)
1051 __gitcomp "$
(__git_refs
)" "" "${cur##--set-upstream-to=}"
1055 --color --no-color --verbose --abbrev= --no-abbrev
1056 --track --no-track --contains --merged --no-merged
1057 --set-upstream-to= --edit-description --list
1062 if [ $only_local_ref = "y
" -a $has_r = "n
" ]; then
1063 __gitcomp_nl "$
(__git_heads
)"
1065 __gitcomp_nl "$
(__git_refs
)"
1073 local cmd="${words[2]}"
1076 __gitcomp "create list-heads verify unbundle
"
1079 # looking for a file
1084 __git_complete_revlist
1093 __git_has_doubledash && return
1097 __gitcomp "diff3 merge
" "" "${cur##--conflict=}"
1101 --quiet --ours --theirs --track --no-track --merge
1102 --conflict= --orphan --patch
1106 # check if --track, --no-track, or --no-guess was specified
1107 # if so, disable DWIM mode
1108 local flags="--track --no-track --no-guess" track=1
1109 if [ -n "$
(__git_find_on_cmdline
"$flags")" ]; then
1112 __gitcomp_nl "$
(__git_refs
'' $track)"
1119 __gitcomp "$
(__git_refs
)"
1124 local dir="$
(__gitdir
)"
1125 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1126 __gitcomp "--continue --quit --abort"
1131 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1134 __gitcomp_nl "$
(__git_refs
)"
1143 __gitcomp "--dry-run --quiet"
1148 # XXX should we check for -x option ?
1149 __git_complete_index_file "--others"
1181 __gitcomp_nl "$
(__git_refs
)" "" "${cur}"
1188 __gitcomp_nl "$
(__git_refs
)" "" "${cur}"
1195 __gitcomp "default strip verbatim whitespace
1196 " "" "${cur##--cleanup=}"
1199 --reuse-message=*|--reedit-message=*|\
1200 --fixup=*|--squash=*)
1201 __gitcomp_nl "$
(__git_refs
)" "" "${cur#*=}"
1204 --untracked-files=*)
1205 __gitcomp "all no normal
" "" "${cur##--untracked-files=}"
1210 --all --author= --signoff --verify --no-verify
1212 --amend --include --only --interactive
1213 --dry-run --reuse-message= --reedit-message=
1214 --reset-author --file= --message= --template=
1215 --cleanup= --untracked-files --untracked-files=
1216 --verbose --quiet --fixup= --squash=
1221 if git rev-parse --verify --quiet HEAD >/dev/null; then
1222 __git_complete_diff_index_file "HEAD
"
1224 # This is the first commit
1225 __git_complete_index_file "--cached"
1234 --all --tags --contains --abbrev= --candidates=
1235 --exact-match --debug --long --match --always
1239 __gitcomp_nl "$
(__git_refs
)"
1242 __git_diff_algorithms="myers minimal patience histogram
"
1244 __git_diff_common_options="--stat --numstat --shortstat --summary
1245 --patch-with-stat --name-only --name-status --color
1246 --no-color --color-words --no-renames --check
1247 --full-index --binary --abbrev --diff-filter=
1248 --find-copies-harder
1249 --text --ignore-space-at-eol --ignore-space-change
1250 --ignore-all-space --exit-code --quiet --ext-diff
1252 --no-prefix --src-prefix= --dst-prefix=
1253 --inter-hunk-context=
1254 --patience --histogram --minimal
1256 --dirstat --dirstat= --dirstat-by-file
1257 --dirstat-by-file= --cumulative
1263 __git_has_doubledash && return
1267 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1271 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1272 --base --ours --theirs --no-index
1273 $__git_diff_common_options
1278 __git_complete_revlist_file
1281 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1282 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1287 __git_has_doubledash && return
1291 __gitcomp "$__git_mergetools_common kompare
" "" "${cur##--tool=}"
1295 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1296 --base --ours --theirs
1297 --no-renames --diff-filter= --find-copies-harder
1298 --relative --ignore-submodules
1306 __git_fetch_options="
1307 --quiet --verbose --append --upload-pack --force --keep --depth=
1308 --tags --no-tags --all --prune --dry-run
1315 __gitcomp "$__git_fetch_options"
1319 __git_complete_remote_or_refspec
1322 __git_format_patch_options="
1323 --stdout --attach --no-attach --thread --thread= --output-directory
1324 --numbered --start-number --numbered-files --keep-subject --signoff
1325 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1326 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1327 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1330 _git_format_patch ()
1336 " "" "${cur##--thread=}"
1340 __gitcomp "$__git_format_patch_options"
1344 __git_complete_revlist
1352 --tags --root --unreachable --cache --no-reflogs --full
1353 --strict --verbose --lost-found
1364 __gitcomp "--prune --aggressive"
1375 __git_match_ctag() {
1376 awk "/^
${1////\\/}/ { print \
$1 }" "$2"
1381 __git_has_doubledash && return
1387 --text --ignore-case --word-regexp --invert-match
1388 --full-name --line-number
1389 --extended-regexp --basic-regexp --fixed-strings
1391 --files-with-matches --name-only
1392 --files-without-match
1395 --and --or --not --all-match
1401 case "$cword,$prev" in
1403 if test -r tags; then
1404 __gitcomp_nl "$
(__git_match_ctag
"$cur" tags
)"
1410 __gitcomp_nl "$
(__git_refs
)"
1417 __gitcomp "--all --info --man --web"
1421 __git_compute_all_commands
1422 __gitcomp "$__git_all_commands $
(__git_aliases
)
1423 attributes cli core-tutorial cvs-migration
1424 diffcore gitk glossary hooks ignore modules
1425 namespaces repository-layout tutorial tutorial-2
1435 false true
umask group all world everybody
1436 " "" "${cur##--shared=}"
1440 __gitcomp "--quiet --bare --template= --shared --shared="
1450 __gitcomp "--cached --deleted --modified --others --ignored
1451 --stage --directory --no-empty-directory --unmerged
1452 --killed --exclude= --exclude-from=
1453 --exclude-per-directory= --exclude-standard
1454 --error-unmatch --with-tree= --full-name
1455 --abbrev --ignored --exclude-per-directory
1461 # XXX ignore options like --modified and always suggest all cached
1463 __git_complete_index_file "--cached"
1468 __gitcomp_nl "$
(__git_remotes
)"
1476 # Options that go well for log, shortlog and gitk
1477 __git_log_common_options="
1479 --branches --tags --remotes
1480 --first-parent --merges --no-merges
1482 --max-age= --since= --after=
1483 --min-age= --until= --before=
1484 --min-parents= --max-parents=
1485 --no-min-parents --no-max-parents
1487 # Options that go well for log and gitk (not shortlog)
1488 __git_log_gitk_options="
1489 --dense --sparse --full-history
1490 --simplify-merges --simplify-by-decoration
1491 --left-right --notes --no-notes
1493 # Options that go well for log and shortlog (not gitk)
1494 __git_log_shortlog_options="
1495 --author= --committer= --grep=
1499 __git_log_pretty_formats="oneline short medium full fuller email raw format
:"
1500 __git_log_date_formats="relative iso8601 rfc2822 short
local default raw
"
1504 __git_has_doubledash && return
1506 local g="$
(git rev-parse
--git-dir 2>/dev
/null
)"
1508 if [ -f "$g/MERGE_HEAD
" ]; then
1512 --pretty=*|--format=*)
1513 __gitcomp "$__git_log_pretty_formats $
(__git_pretty_aliases
)
1518 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1522 __gitcomp "long short
" "" "${cur##--decorate=}"
1527 $__git_log_common_options
1528 $__git_log_shortlog_options
1529 $__git_log_gitk_options
1530 --root --topo-order --date-order --reverse
1531 --follow --full-diff
1532 --abbrev-commit --abbrev=
1533 --relative-date --date=
1534 --pretty= --format= --oneline
1537 --decorate --decorate=
1539 --parents --children
1541 $__git_diff_common_options
1542 --pickaxe-all --pickaxe-regex
1547 __git_complete_revlist
1550 __git_merge_options="
1551 --no-commit --no-stat --log --no-log --squash --strategy
1552 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1557 __git_complete_strategy && return
1561 __gitcomp "$__git_merge_options"
1564 __gitcomp_nl "$
(__git_refs
)"
1571 __gitcomp "$__git_mergetools_common tortoisemerge
" "" "${cur##--tool=}"
1583 __gitcomp_nl "$
(__git_refs
)"
1590 __gitcomp "--dry-run"
1595 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1596 # We need to show both cached and untracked files (including
1597 # empty directories) since this may not be the last argument.
1598 __git_complete_index_file "--cached --others --directory"
1600 __git_complete_index_file "--cached"
1606 __gitcomp "--tags --all --stdin"
1611 local subcommands='add append copy edit list prune remove show'
1612 local subcommand="$
(__git_find_on_cmdline
"$subcommands")"
1614 case "$subcommand,$cur" in
1621 __gitcomp_nl "$
(__git_refs
)"
1624 __gitcomp "$subcommands --ref"
1628 add,--reuse-message=*|append,--reuse-message=*|\
1629 add,--reedit-message=*|append,--reedit-message=*)
1630 __gitcomp_nl "$
(__git_refs
)" "" "${cur#*=}"
1633 __gitcomp '--file= --message= --reedit-message=
1640 __gitcomp '--dry-run --verbose'
1649 __gitcomp_nl "$
(__git_refs
)"
1658 __git_complete_strategy && return
1663 --rebase --no-rebase
1664 $__git_merge_options
1665 $__git_fetch_options
1670 __git_complete_remote_or_refspec
1677 __gitcomp_nl "$
(__git_remotes
)"
1682 __gitcomp_nl "$
(__git_remotes
)" "" "${cur##--repo=}"
1687 --all --mirror --tags --dry-run --force --verbose
1688 --receive-pack= --repo= --set-upstream
1693 __git_complete_remote_or_refspec
1698 local dir="$
(__gitdir
)"
1699 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1700 __gitcomp "--continue --skip --abort"
1703 __git_complete_strategy && return
1706 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1711 --onto --merge --strategy --interactive
1712 --preserve-merges --stat --no-stat
1713 --committer-date-is-author-date --ignore-date
1714 --ignore-whitespace --whitespace=
1720 __gitcomp_nl "$
(__git_refs
)"
1725 local subcommands="show delete expire
"
1726 local subcommand="$
(__git_find_on_cmdline
"$subcommands")"
1728 if [ -z "$subcommand" ]; then
1729 __gitcomp "$subcommands"
1731 __gitcomp_nl "$
(__git_refs
)"
1735 __git_send_email_confirm_options="always never auto cc compose
"
1736 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all
"
1743 $__git_send_email_confirm_options
1744 " "" "${cur##--confirm=}"
1749 $__git_send_email_suppresscc_options
1750 " "" "${cur##--suppress-cc=}"
1754 --smtp-encryption=*)
1755 __gitcomp "ssl tls
" "" "${cur##--smtp-encryption=}"
1761 " "" "${cur##--thread=}"
1765 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1766 --compose --confirm= --dry-run --envelope-sender
1768 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1769 --no-suppress-from --no-thread --quiet
1770 --signed-off-by-cc --smtp-pass --smtp-server
1771 --smtp-server-port --smtp-encryption= --smtp-user
1772 --subject --suppress-cc= --suppress-from --thread --to
1773 --validate --no-validate
1774 $__git_format_patch_options"
1778 __git_complete_revlist
1786 __git_config_get_set_variables ()
1788 local prevword word config_file= c=$cword
1789 while [ $c -gt 1 ]; do
1792 --system|--global|--local|--file=*)
1797 config_file="$word $prevword"
1805 git --git-dir="$
(__gitdir
)" config $config_file --list 2>/dev/null |
1820 __gitcomp_nl "$
(__git_remotes
)"
1824 __gitcomp_nl "$
(__git_refs
)"
1828 local remote="${prev#remote.}"
1829 remote="${remote%.fetch}"
1830 if [ -z "$cur" ]; then
1831 __gitcompadd "refs
/heads
/" "" "" ""
1834 __gitcomp_nl "$
(__git_refs_remotes
"$remote")"
1838 local remote="${prev#remote.}"
1839 remote="${remote%.push}"
1840 __gitcomp_nl "$
(git
--git-dir="$(__gitdir)" \
1841 for-each-ref
--format='%(refname):%(refname)' \
1845 pull.twohead|pull.octopus)
1846 __git_compute_merge_strategies
1847 __gitcomp "$__git_merge_strategies"
1850 color.branch|color.diff|color.interactive|\
1851 color.showbranch|color.status|color.ui)
1852 __gitcomp "always never auto
"
1856 __gitcomp "false true
"
1861 normal black red green yellow blue magenta cyan white
1862 bold dim ul blink reverse
1867 __gitcomp "man info web html
"
1871 __gitcomp "$__git_log_date_formats"
1874 sendemail.aliasesfiletype)
1875 __gitcomp "mutt mailrc pine elm gnus
"
1879 __gitcomp "$__git_send_email_confirm_options"
1882 sendemail.suppresscc)
1883 __gitcomp "$__git_send_email_suppresscc_options"
1886 --get|--get-all|--unset|--unset-all)
1887 __gitcomp_nl "$
(__git_config_get_set_variables
)"
1897 --system --global --local --file=
1898 --list --replace-all
1899 --get --get-all --get-regexp
1900 --add --unset --unset-all
1901 --remove-section --rename-section
1906 local pfx="${cur%.*}.
" cur_="${cur##*.}"
1907 __gitcomp "remote merge mergeoptions rebase
" "$pfx" "$cur_"
1911 local pfx="${cur%.*}.
" cur_="${cur#*.}"
1912 __gitcomp_nl "$
(__git_heads
)" "$pfx" "$cur_" ".
"
1916 local pfx="${cur%.*}.
" cur_="${cur##*.}"
1918 argprompt cmd confirm needsfile noconsole norescan
1919 prompt revprompt revunmerged title
1924 local pfx="${cur%.*}.
" cur_="${cur##*.}"
1925 __gitcomp "cmd path
" "$pfx" "$cur_"
1929 local pfx="${cur%.*}.
" cur_="${cur##*.}"
1930 __gitcomp "cmd path
" "$pfx" "$cur_"
1934 local pfx="${cur%.*}.
" cur_="${cur##*.}"
1935 __gitcomp "cmd path trustExitCode
" "$pfx" "$cur_"
1939 local pfx="${cur%.*}.
" cur_="${cur#*.}"
1940 __git_compute_all_commands
1941 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1945 local pfx="${cur%.*}.
" cur_="${cur##*.}"
1947 url proxy fetch push mirror skipDefaultUpdate
1948 receivepack uploadpack tagopt pushurl
1953 local pfx="${cur%.*}.
" cur_="${cur#*.}"
1954 __gitcomp_nl "$
(__git_remotes
)" "$pfx" "$cur_" ".
"
1958 local pfx="${cur%.*}.
" cur_="${cur##*.}"
1959 __gitcomp "insteadOf pushInsteadOf
" "$pfx" "$cur_"
1965 advice.commitBeforeMerge
1967 advice.implicitIdentity
1968 advice.pushNonFastForward
1969 advice.resolveConflict
1973 apply.ignorewhitespace
1975 branch.autosetupmerge
1976 branch.autosetuprebase
1980 color.branch.current
1985 color.decorate.branch
1986 color.decorate.remoteBranch
1987 color.decorate.stash
1997 color.
diff.whitespace
2002 color.
grep.linenumber
2005 color.
grep.separator
2007 color.interactive.error
2008 color.interactive.header
2009 color.interactive.
help
2010 color.interactive.prompt
2015 color.status.changed
2017 color.status.nobranch
2018 color.status.untracked
2019 color.status.updated
2028 core.bigFileThreshold
2031 core.deltaBaseCacheLimit
2036 core.fsyncobjectfiles
2038 core.ignoreCygwinFSTricks
2041 core.logAllRefUpdates
2042 core.loosecompression
2045 core.packedGitWindowSize
2047 core.preferSymlinkRefs
2050 core.repositoryFormatVersion
2052 core.sharedRepository
2056 core.warnAmbiguousRefs
2059 diff.autorefreshindex
2062 diff.ignoreSubmodules
2067 diff.suppressBlankEmpty
2073 fetch.recurseSubmodules
2082 format.subjectprefix
2093 gc.reflogexpireunreachable
2097 gitcvs.commitmsgannotation
2098 gitcvs.dbTableNamePrefix
2109 gui.copyblamethreshold
2113 gui.matchtrackingbranch
2114 gui.newbranchtemplate
2115 gui.pruneduringfetch
2116 gui.spellingdictionary
2131 http.sslCertPasswordProtected
2136 i18n.logOutputEncoding
2142 imap.preformattedHTML
2152 interactive.singlekey
2168 mergetool.keepBackup
2169 mergetool.keepTemporaries
2174 notes.rewrite.rebase
2178 pack.deltaCacheLimit
2194 receive.denyCurrentBranch
2195 receive.denyDeleteCurrent
2197 receive.denyNonFastForwards
2200 receive.updateserverinfo
2202 repack.usedeltabaseoffset
2206 sendemail.aliasesfile
2207 sendemail.aliasfiletype
2211 sendemail.chainreplyto
2213 sendemail.envelopesender
2217 sendemail.signedoffbycc
2218 sendemail.smtpdomain
2219 sendemail.smtpencryption
2221 sendemail.smtpserver
2222 sendemail.smtpserveroption
2223 sendemail.smtpserverport
2225 sendemail.suppresscc
2226 sendemail.suppressfrom
2231 status.relativePaths
2232 status.showUntrackedFiles
2233 status.submodulesummary
2236 transfer.unpackLimit
2248 local subcommands="add rename remove set-head set-branches set-url show prune update
"
2249 local subcommand="$
(__git_find_on_cmdline
"$subcommands")"
2250 if [ -z "$subcommand" ]; then
2251 __gitcomp "$subcommands"
2255 case "$subcommand" in
2256 rename|remove|set-url|show|prune)
2257 __gitcomp_nl "$
(__git_remotes
)"
2259 set-head|set-branches)
2260 __git_complete_remote_or_refspec
2263 local i c='' IFS=$'\n'
2264 for i in $(git --git-dir="$
(__gitdir
)" config --get-regexp "remotes\..
*" 2>/dev/null); do
2277 __gitcomp_nl "$
(__git_refs
)"
2282 __git_has_doubledash && return
2286 __gitcomp "--merge --mixed --hard --soft --patch"
2290 __gitcomp_nl "$
(__git_refs
)"
2297 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2301 __gitcomp_nl "$
(__git_refs
)"
2308 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2313 __git_complete_index_file "--cached"
2318 __git_has_doubledash && return
2323 $__git_log_common_options
2324 $__git_log_shortlog_options
2325 --numbered --summary
2330 __git_complete_revlist
2335 __git_has_doubledash && return
2338 --pretty=*|--format=*)
2339 __gitcomp "$__git_log_pretty_formats $
(__git_pretty_aliases
)
2344 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2348 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2349 $__git_diff_common_options
2362 --all --remotes --topo-order --current --more=
2363 --list --independent --merge-base --no-name
2365 --sha1-name --sparse --topics --reflog
2370 __git_complete_revlist
2375 local save_opts='--keep-index --no-keep-index --quiet --patch'
2376 local subcommands='save list show apply clear drop pop create branch'
2377 local subcommand="$
(__git_find_on_cmdline
"$subcommands")"
2378 if [ -z "$subcommand" ]; then
2381 __gitcomp "$save_opts"
2384 if [ -z "$
(__git_find_on_cmdline
"$save_opts")" ]; then
2385 __gitcomp "$subcommands"
2390 case "$subcommand,$cur" in
2392 __gitcomp "$save_opts"
2395 __gitcomp "--index --quiet"
2397 show,--*|drop,--*|branch,--*)
2399 show,*|apply,*|drop,*|pop,*|branch,*)
2400 __gitcomp_nl "$
(git
--git-dir="$(__gitdir)" stash list \
2401 |
sed -n -e 's/:.*//p')"
2411 __git_has_doubledash && return
2413 local subcommands="add status init deinit update summary foreach sync
"
2414 if [ -z "$
(__git_find_on_cmdline
"$subcommands")" ]; then
2417 __gitcomp "--quiet --cached"
2420 __gitcomp "$subcommands"
2430 init fetch clone rebase dcommit log find-rev
2431 set-tree commit-diff info create-ignore propget
2432 proplist show-ignore show-externals branch tag blame
2433 migrate mkdirs
reset gc
2435 local subcommand="$
(__git_find_on_cmdline
"$subcommands")"
2436 if [ -z "$subcommand" ]; then
2437 __gitcomp "$subcommands"
2439 local remote_opts="--username= --config-dir= --no-auth-cache"
2441 --follow-parent --authors-file= --repack=
2442 --no-metadata --use-svm-props --use-svnsync-props
2443 --log-window-size= --no-checkout --quiet
2444 --repack-flags --use-log-author --localtime
2445 --ignore-paths= $remote_opts
2448 --template= --shared= --trunk= --tags=
2449 --branches= --stdlayout --minimize-url
2450 --no-metadata --use-svm-props --use-svnsync-props
2451 --rewrite-root= --prefix= --use-log-author
2452 --add-author-from $remote_opts
2455 --edit --rmdir --find-copies-harder --copy-similarity=
2458 case "$subcommand,$cur" in
2460 __gitcomp "--revision= --fetch-all $fc_opts"
2463 __gitcomp "--revision= $fc_opts $init_opts"
2466 __gitcomp "$init_opts"
2470 --merge --strategy= --verbose --dry-run
2471 --fetch-all --no-rebase --commit-url
2472 --revision --interactive $cmt_opts $fc_opts
2476 __gitcomp "--stdin $cmt_opts $fc_opts"
2478 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2479 show-externals,--*|mkdirs,--*)
2480 __gitcomp "--revision="
2484 --limit= --revision= --verbose --incremental
2485 --oneline --show-commit --non-recursive
2486 --authors-file= --color
2491 --merge --verbose --strategy= --local
2492 --fetch-all --dry-run $fc_opts
2496 __gitcomp "--message= --file= --revision= $cmt_opts"
2502 __gitcomp "--dry-run --message --tag"
2505 __gitcomp "--dry-run --message"
2508 __gitcomp "--git-format"
2512 --config-dir= --ignore-paths= --minimize
2513 --no-auth-cache --username=
2517 __gitcomp "--revision= --parent"
2528 while [ $c -lt $cword ]; do
2532 __gitcomp_nl "$
(__git_tags
)"
2547 __gitcomp_nl "$
(__git_tags
)"
2551 __gitcomp_nl "$
(__git_refs
)"
2563 local i c=1 command __git_dir
2565 while [ $c -lt $cword ]; do
2568 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2569 --bare) __git_dir=".
" ;;
2570 --help) command="help"; break ;;
2573 *) command="$i"; break ;;
2578 if [ -z "$command" ]; then
2592 --no-replace-objects
2596 *) __git_compute_porcelain_commands
2597 __gitcomp "$__git_porcelain_commands $
(__git_aliases
)" ;;
2602 local completion_func="_git_
${command//-/_}"
2603 declare -f $completion_func >/dev/null && $completion_func && return
2605 local expansion=$(__git_aliased_command "$command")
2606 if [ -n "$expansion" ]; then
2607 completion_func="_git_
${expansion//-/_}"
2608 declare -f $completion_func >/dev/null && $completion_func
2614 __git_has_doubledash && return
2616 local g="$
(__gitdir
)"
2618 if [ -f "$g/MERGE_HEAD
" ]; then
2624 $__git_log_common_options
2625 $__git_log_gitk_options
2631 __git_complete_revlist
2634 if [[ -n ${ZSH_VERSION-} ]]; then
2635 echo "WARNING
: this
script is deprecated
, please see git-completion.zsh
" 1>&2
2637 autoload -U +X compinit && compinit
2643 local cur_="${3-$cur}"
2649 local c IFS=$' \t\n'
2657 array[$#array+1]="$c"
2660 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2671 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret
=0
2680 compadd
-Q -p "${2-}" -f -- ${=1} && _ret
=0
2686 local cur cword prev
2687 cur
=${words[CURRENT-1]}
2688 prev
=${words[CURRENT-2]}
2698 let _ret
&& _default
-S '' && _ret
=0
2702 compdef _git git gitk
2704 elif [[ -n ${BASH_VERSION-} ]]; then
2705 if ((${BASH_VERSINFO[0]} < 4)); then
2706 # compopt is not supported
2707 __git_index_file_list_filter
()
2709 __git_index_file_list_filter_compat
2716 local cur words cword prev
2717 _get_comp_words_by_ref
-n =: cur words cword prev
2721 # Setup completion for certain functions defined above by setting common
2722 # variables and workarounds.
2723 # This is NOT a public function; use at your own risk.
2726 local wrapper
="__git_wrap${2}"
2727 eval "$wrapper () { __git_func_wrap $2 ; }"
2728 complete
-o bashdefault
-o default
-o nospace
-F $wrapper $1 2>/dev
/null \
2729 || complete
-o default
-o nospace
-F $wrapper $1
2732 # wrapper for backwards compatibility
2735 __git_wrap__git_main
2738 # wrapper for backwards compatibility
2741 __git_wrap__gitk_main
2744 __git_complete git __git_main
2745 __git_complete gitk __gitk_main
2747 # The following are necessary only for Cygwin, and only are needed
2748 # when the user has tab-completed the executable name and consequently
2749 # included the '.exe' suffix.
2751 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2752 __git_complete git.exe __git_main