3 # bash/zsh completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) file paths within current working directory and index
17 # *) common --long-options
19 # To use these routines:
21 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
22 # 2) Add the following line to your .bashrc/.zshrc:
23 # source ~/.git-completion.sh
24 # 3) Consider changing your PS1 to also show the current branch,
25 # see git-prompt.sh for details.
27 case "$COMP_WORDBREAKS" in
29 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
32 # __gitdir accepts 0 or 1 arguments (i.e., location)
33 # returns location of .git repo
36 # Note: this function is duplicated in git-prompt.sh
37 # When updating it, make sure you update the other one to match.
38 if [ -z "${1-}" ]; then
39 if [ -n "${__git_dir-}" ]; then
41 elif [ -n "${GIT_DIR-}" ]; then
42 test -d "${GIT_DIR-}" || return 1
44 elif [ -d .git ]; then
47 git rev-parse --git-dir 2>/dev/null
49 elif [ -d "$1/.git" ]; then
56 # The following function is based on code from:
58 # bash_completion - programmable completion functions for bash 3.2+
60 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
61 # © 2009-2010, Bash Completion Maintainers
62 # <bash-completion-devel@lists.alioth.debian.org>
64 # This program is free software; you can redistribute it and/or modify
65 # it under the terms of the GNU General Public License as published by
66 # the Free Software Foundation; either version 2, or (at your option)
69 # This program is distributed in the hope that it will be useful,
70 # but WITHOUT ANY WARRANTY; without even the implied warranty of
71 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72 # GNU General Public License for more details.
74 # You should have received a copy of the GNU General Public License
75 # along with this program; if not, write to the Free Software Foundation,
76 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
78 # The latest version of this software can be obtained here:
80 # http://bash-completion.alioth.debian.org/
84 # This function can be used to access a tokenized list of words
85 # on the command line:
87 # __git_reassemble_comp_words_by_ref '=:'
88 # if test "${words_[cword_-1]}" = -w
93 # The argument should be a collection of characters from the list of
94 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
97 # This is roughly equivalent to going back in time and setting
98 # COMP_WORDBREAKS to exclude those characters. The intent is to
99 # make option types like --date=<type> and <rev>:<path> easy to
100 # recognize by treating each shell word as a single token.
102 # It is best not to set COMP_WORDBREAKS directly because the value is
103 # shared with other completion scripts. By the time the completion
104 # function gets called, COMP_WORDS has already been populated so local
105 # changes to COMP_WORDBREAKS have no effect.
107 # Output: words_, cword_, cur_.
109 __git_reassemble_comp_words_by_ref()
111 local exclude i j first
112 # Which word separators to exclude?
113 exclude="${1//[^$COMP_WORDBREAKS]}"
115 if [ -z "$exclude" ]; then
116 words_=("${COMP_WORDS[@]}")
119 # List of word completion separators has shrunk;
120 # re-assemble words to complete.
121 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
122 # Append each nonempty word consisting of just
123 # word separator characters to the current word.
127 [ -n "${COMP_WORDS[$i]}" ] &&
128 # word consists of excluded word separators
129 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
131 # Attach to the previous token,
132 # unless the previous token is the command name.
133 if [ $j -ge 2 ] && [ -n "$first" ]; then
137 words_[$j]=${words_[j]}${COMP_WORDS[i]}
138 if [ $i = $COMP_CWORD ]; then
141 if (($i < ${#COMP_WORDS[@]} - 1)); then
148 words_[$j]=${words_[j]}${COMP_WORDS[i]}
149 if [ $i = $COMP_CWORD ]; then
155 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
156 _get_comp_words_by_ref ()
158 local exclude cur_ words_ cword_
159 if [ "$1" = "-n" ]; then
163 __git_reassemble_comp_words_by_ref "$exclude"
164 cur_=${words_[cword_]}
165 while [ $# -gt 0 ]; do
171 prev=${words_[$cword_-1]}
174 words=("${words_[@]}")
189 if [[ "$x" == "$3"* ]]; then
190 COMPREPLY[i++]="$2$x$4"
195 # Generates completion reply, appending a space to possible completion words,
197 # It accepts 1 to 4 arguments:
198 # 1: List of possible completion words.
199 # 2: A prefix to be added to each possible completion word (optional).
200 # 3: Generate possible completion matches for this word (optional).
201 # 4: A suffix to be appended to each possible completion word (optional).
204 local cur_="${3-$cur}"
210 local c i=0 IFS=$' \t\n'
213 if [[ $c == "$cur_"* ]]; then
218 COMPREPLY[i++]="${2-}$c"
225 # Generates completion reply from newline-separated possible completion words
226 # by appending a space to all of them.
227 # It accepts 1 to 4 arguments:
228 # 1: List of possible completion words, separated by a single newline.
229 # 2: A prefix to be added to each possible completion word (optional).
230 # 3: Generate possible completion matches for this word (optional).
231 # 4: A suffix to be appended to each possible completion word instead of
232 # the default space (optional). If specified but empty, nothing is
237 __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
240 # Generates completion reply with compgen from newline-separated possible
241 # completion filenames.
242 # It accepts 1 to 3 arguments:
243 # 1: List of possible completion filenames, separated by a single newline.
244 # 2: A directory prefix to be added to each possible completion filename
246 # 3: Generate possible completion matches for this word (optional).
251 # XXX does not work when the directory prefix contains a tilde,
252 # since tilde expansion is not applied.
253 # This means that COMPREPLY will be empty and Bash default
254 # completion will be used.
255 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
257 # use a hack to enable file mode in bash < 4
258 compopt -o filenames +o nospace 2>/dev/null ||
259 compgen -f /non-existing-dir/ > /dev/null
262 # Execute 'git ls-files', unless the --committable option is specified, in
263 # which case it runs 'git diff-index' to find out the files that can be
264 # committed. It return paths relative to the directory specified in the first
265 # argument, and using the options specified in the second argument.
266 __git_ls_files_helper ()
269 test -n "${CDPATH+set}" && unset CDPATH
271 if [ "$2" == "--committable" ]; then
272 git diff-index --name-only --relative HEAD
274 # NOTE: $2 is not quoted in order to support multiple options
275 git ls-files --exclude-standard $2
281 # __git_index_files accepts 1 or 2 arguments:
282 # 1: Options to pass to ls-files (required).
283 # 2: A directory path (optional).
284 # If provided, only files within the specified directory are listed.
285 # Sub directories are never recursed. Path must have a trailing
289 local dir="$(__gitdir)" root="${2-.}" file
291 if [ -d "$dir" ]; then
292 __git_ls_files_helper "$root" "$1" |
293 while read -r file; do
295 ?*/*) echo "${file%%/*}" ;;
304 local dir="$(__gitdir)"
305 if [ -d "$dir" ]; then
306 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
314 local dir="$(__gitdir)"
315 if [ -d "$dir" ]; then
316 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
322 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
323 # presence of 2nd argument means use the guess heuristic employed
324 # by checkout for tracking branches
327 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
329 if [ -d "$dir" ]; then
337 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
338 if [ -e "$dir/$i" ]; then echo $i; fi
340 format="refname:short"
341 refs="refs/tags refs/heads refs/remotes"
344 git --git-dir="$dir" for-each-ref --format="%($format)" \
346 if [ -n "$track" ]; then
347 # employ the heuristic used by git checkout
348 # Try to find a remote branch that matches the completion word
349 # but only output if the branch name is unique
351 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
353 while read -r entry; do
356 if [[ "$ref" == "$cur"* ]]; then
359 done | sort | uniq -u
365 git ls-remote "$dir" "$cur*" 2>/dev/null | \
366 while read -r hash i; do
374 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
375 while read -r hash i; do
378 refs/*) echo "${i#refs/*/}" ;;
386 # __git_refs2 requires 1 argument (to pass to __git_refs)
390 for i in $(__git_refs "$1"); do
395 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
396 __git_refs_remotes ()
399 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
400 while read -r hash i; do
401 echo "$i:refs/remotes/$1/${i#refs/heads/}"
407 local i IFS=$'\n' d="$(__gitdir)"
408 test -d "$d/remotes" && ls -1 "$d/remotes"
409 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
415 __git_list_merge_strategies ()
417 git merge -s help 2>&1 |
418 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
427 __git_merge_strategies=
428 # 'git merge -s help' (and thus detection of the merge strategy
429 # list) fails, unfortunately, if run outside of any git working
430 # tree. __git_merge_strategies is set to the empty string in
431 # that case, and the detection will be repeated the next time it
433 __git_compute_merge_strategies ()
435 test -n "$__git_merge_strategies" ||
436 __git_merge_strategies=$(__git_list_merge_strategies)
439 __git_complete_revlist_file ()
441 local pfx ls ref cur_="$cur"
461 case "$COMP_WORDBREAKS" in
463 *) pfx="$ref:$pfx" ;;
466 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
467 | sed '/^100... blob /{
483 pfx="${cur_%...*}..."
485 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
490 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
493 __gitcomp_nl "$(__git_refs)"
499 # __git_complete_index_file requires 1 argument:
500 # 1: the options to pass to ls-file
502 # The exception is --committable, which finds the files appropriate commit.
503 __git_complete_index_file ()
505 local pfx="" cur_="$cur"
515 __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
518 __git_complete_file ()
520 __git_complete_revlist_file
523 __git_complete_revlist ()
525 __git_complete_revlist_file
528 __git_complete_remote_or_refspec ()
530 local cur_="$cur" cmd="${words[1]}"
531 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
532 if [ "$cmd" = "remote" ]; then
535 while [ $c -lt $cword ]; do
538 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
541 push) no_complete_refspec=1 ;;
549 *) remote="$i"; break ;;
553 if [ -z "$remote" ]; then
554 __gitcomp_nl "$(__git_remotes)"
557 if [ $no_complete_refspec = 1 ]; then
560 [ "$remote" = "." ] && remote=
563 case "$COMP_WORDBREAKS" in
565 *) pfx="${cur_%%:*}:" ;;
577 if [ $lhs = 1 ]; then
578 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
580 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
584 if [ $lhs = 1 ]; then
585 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
587 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
591 if [ $lhs = 1 ]; then
592 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
594 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
600 __git_complete_strategy ()
602 __git_compute_merge_strategies
605 __gitcomp "$__git_merge_strategies"
610 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
618 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
620 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
622 git help -a|egrep '^ [a-zA-Z0-9]'
626 __git_list_all_commands ()
629 for i in $(__git_commands)
632 *--*) : helper pattern;;
639 __git_compute_all_commands ()
641 test -n "$__git_all_commands" ||
642 __git_all_commands=$(__git_list_all_commands)
645 __git_list_porcelain_commands ()
648 __git_compute_all_commands
649 for i in $__git_all_commands
652 *--*) : helper pattern;;
653 applymbox) : ask gittus;;
654 applypatch) : ask gittus;;
655 archimport) : import;;
656 cat-file) : plumbing;;
657 check-attr) : plumbing;;
658 check-ignore) : plumbing;;
659 check-ref-format) : plumbing;;
660 checkout-index) : plumbing;;
661 commit-tree) : plumbing;;
662 count-objects) : infrequent;;
663 credential-cache) : credentials helper;;
664 credential-store) : credentials helper;;
665 cvsexportcommit) : export;;
666 cvsimport) : import;;
667 cvsserver) : daemon;;
669 diff-files) : plumbing;;
670 diff-index) : plumbing;;
671 diff-tree) : plumbing;;
672 fast-import) : import;;
673 fast-export) : export;;
674 fsck-objects) : plumbing;;
675 fetch-pack) : plumbing;;
676 fmt-merge-msg) : plumbing;;
677 for-each-ref) : plumbing;;
678 hash-object) : plumbing;;
679 http-*) : transport;;
680 index-pack) : plumbing;;
681 init-db) : deprecated;;
682 local-fetch) : plumbing;;
683 lost-found) : infrequent;;
684 ls-files) : plumbing;;
685 ls-remote) : plumbing;;
686 ls-tree) : plumbing;;
687 mailinfo) : plumbing;;
688 mailsplit) : plumbing;;
689 merge-*) : plumbing;;
692 pack-objects) : plumbing;;
693 pack-redundant) : plumbing;;
694 pack-refs) : plumbing;;
695 parse-remote) : plumbing;;
696 patch-id) : plumbing;;
697 peek-remote) : plumbing;;
699 prune-packed) : plumbing;;
700 quiltimport) : import;;
701 read-tree) : plumbing;;
702 receive-pack) : plumbing;;
703 remote-*) : transport;;
704 repo-config) : deprecated;;
706 rev-list) : plumbing;;
707 rev-parse) : plumbing;;
708 runstatus) : plumbing;;
709 sh-setup) : internal;;
711 show-ref) : plumbing;;
712 send-pack) : plumbing;;
713 show-index) : plumbing;;
715 stripspace) : plumbing;;
716 symbolic-ref) : plumbing;;
717 tar-tree) : deprecated;;
718 unpack-file) : plumbing;;
719 unpack-objects) : plumbing;;
720 update-index) : plumbing;;
721 update-ref) : plumbing;;
722 update-server-info) : daemon;;
723 upload-archive) : plumbing;;
724 upload-pack) : plumbing;;
725 write-tree) : plumbing;;
727 verify-pack) : infrequent;;
728 verify-tag) : plumbing;;
734 __git_porcelain_commands=
735 __git_compute_porcelain_commands ()
737 __git_compute_all_commands
738 test -n "$__git_porcelain_commands" ||
739 __git_porcelain_commands=$(__git_list_porcelain_commands)
742 __git_pretty_aliases ()
745 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
758 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
768 # __git_aliased_command requires 1 argument
769 __git_aliased_command ()
771 local word cmdline=$(git --git-dir="$(__gitdir)" \
772 config --get "alias.$1")
773 for word in $cmdline; do
779 \!*) : shell command alias ;;
781 *=*) : setting env ;;
790 # __git_find_on_cmdline requires 1 argument
791 __git_find_on_cmdline ()
793 local word subcommand c=1
794 while [ $c -lt $cword ]; do
796 for subcommand in $1; do
797 if [ "$subcommand" = "$word" ]; then
806 __git_has_doubledash ()
809 while [ $c -lt $cword ]; do
810 if [ "--" = "${words[c]}" ]; then
818 # Try to count non option arguments passed on the command line for the
819 # specified git command.
820 # When options are used, it is necessary to use the special -- option to
821 # tell the implementation were non option arguments begin.
822 # XXX this can not be improved, since options can appear everywhere, as
826 # __git_count_arguments requires 1 argument: the git command executed.
827 __git_count_arguments ()
831 # Skip "git" (first argument)
832 for ((i=1; i < ${#words[@]}; i++)); do
837 # Good; we can assume that the following are only non
842 # Skip the specified git command and discard git
855 __git_whitespacelist="nowarn warn error error-all fix"
859 local dir="$(__gitdir)"
860 if [ -d "$dir"/rebase-apply ]; then
861 __gitcomp "--skip --continue --resolved --abort"
866 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
871 --3way --committer-date-is-author-date --ignore-date
872 --ignore-whitespace --ignore-space-change
873 --interactive --keep --no-utf8 --signoff --utf8
874 --whitespace= --scissors
884 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
889 --stat --numstat --summary --check --index
890 --cached --index-info --reverse --reject --unidiff-zero
891 --apply --no-add --exclude=
892 --ignore-whitespace --ignore-space-change
893 --whitespace= --inaccurate-eof --verbose
904 --interactive --refresh --patch --update --dry-run
905 --ignore-errors --intent-to-add
910 # XXX should we check for --update and --all options ?
911 __git_complete_index_file "--others --modified"
918 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
922 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
927 --format= --list --verbose
928 --prefix= --remote= --exec=
938 __git_has_doubledash && return
940 local subcommands="start bad good skip reset visualize replay log run"
941 local subcommand="$(__git_find_on_cmdline "$subcommands")"
942 if [ -z "$subcommand" ]; then
943 if [ -f "$(__gitdir)"/BISECT_START ]; then
944 __gitcomp "$subcommands"
946 __gitcomp "replay start"
951 case "$subcommand" in
952 bad|good|reset|skip|start)
953 __gitcomp_nl "$(__git_refs)"
962 local i c=1 only_local_ref="n" has_r="n"
964 while [ $c -lt $cword ]; do
967 -d|-m) only_local_ref="y" ;;
975 __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
979 --color --no-color --verbose --abbrev= --no-abbrev
980 --track --no-track --contains --merged --no-merged
981 --set-upstream-to= --edit-description --list
986 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
987 __gitcomp_nl "$(__git_heads)"
989 __gitcomp_nl "$(__git_refs)"
997 local cmd="${words[2]}"
1000 __gitcomp "create list-heads verify unbundle"
1003 # looking for a file
1008 __git_complete_revlist
1017 __git_has_doubledash && return
1021 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1025 --quiet --ours --theirs --track --no-track --merge
1026 --conflict= --orphan --patch
1030 # check if --track, --no-track, or --no-guess was specified
1031 # if so, disable DWIM mode
1032 local flags="--track --no-track --no-guess" track=1
1033 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1036 __gitcomp_nl "$(__git_refs '' $track)"
1043 __gitcomp "$(__git_refs)"
1048 local dir="$(__gitdir)"
1049 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1050 __gitcomp "--continue --quit --abort"
1055 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1058 __gitcomp_nl "$(__git_refs)"
1067 __gitcomp "--dry-run --quiet"
1072 # XXX should we check for -x option ?
1073 __git_complete_index_file "--others"
1105 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1112 __gitcomp "default strip verbatim whitespace
1113 " "" "${cur##--cleanup=}"
1116 --reuse-message=*|--reedit-message=*|\
1117 --fixup=*|--squash=*)
1118 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1121 --untracked-files=*)
1122 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1127 --all --author= --signoff --verify --no-verify
1129 --amend --include --only --interactive
1130 --dry-run --reuse-message= --reedit-message=
1131 --reset-author --file= --message= --template=
1132 --cleanup= --untracked-files --untracked-files=
1133 --verbose --quiet --fixup= --squash=
1138 if git rev-parse --verify --quiet HEAD >/dev/null; then
1139 __git_complete_index_file "--committable"
1141 # This is the first commit
1142 __git_complete_index_file "--cached"
1151 --all --tags --contains --abbrev= --candidates=
1152 --exact-match --debug --long --match --always
1156 __gitcomp_nl "$(__git_refs)"
1159 __git_diff_algorithms="myers minimal patience histogram"
1161 __git_diff_common_options="--stat --numstat --shortstat --summary
1162 --patch-with-stat --name-only --name-status --color
1163 --no-color --color-words --no-renames --check
1164 --full-index --binary --abbrev --diff-filter=
1165 --find-copies-harder
1166 --text --ignore-space-at-eol --ignore-space-change
1167 --ignore-all-space --exit-code --quiet --ext-diff
1169 --no-prefix --src-prefix= --dst-prefix=
1170 --inter-hunk-context=
1171 --patience --histogram --minimal
1173 --dirstat --dirstat= --dirstat-by-file
1174 --dirstat-by-file= --cumulative
1180 __git_has_doubledash && return
1184 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1188 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1189 --base --ours --theirs --no-index
1190 $__git_diff_common_options
1195 __git_complete_revlist_file
1198 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1199 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1204 __git_has_doubledash && return
1208 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1212 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1213 --base --ours --theirs
1214 --no-renames --diff-filter= --find-copies-harder
1215 --relative --ignore-submodules
1223 __git_fetch_options="
1224 --quiet --verbose --append --upload-pack --force --keep --depth=
1225 --tags --no-tags --all --prune --dry-run
1232 __gitcomp "$__git_fetch_options"
1236 __git_complete_remote_or_refspec
1239 __git_format_patch_options="
1240 --stdout --attach --no-attach --thread --thread= --output-directory
1241 --numbered --start-number --numbered-files --keep-subject --signoff
1242 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1243 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1244 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1247 _git_format_patch ()
1253 " "" "${cur##--thread=}"
1257 __gitcomp "$__git_format_patch_options"
1261 __git_complete_revlist
1269 --tags --root --unreachable --cache --no-reflogs --full
1270 --strict --verbose --lost-found
1281 __gitcomp "--prune --aggressive"
1292 __git_match_ctag() {
1293 awk "/^${1////\\/}/ { print \$1 }" "$2"
1298 __git_has_doubledash && return
1304 --text --ignore-case --word-regexp --invert-match
1305 --full-name --line-number
1306 --extended-regexp --basic-regexp --fixed-strings
1308 --files-with-matches --name-only
1309 --files-without-match
1312 --and --or --not --all-match
1318 case "$cword,$prev" in
1320 if test -r tags; then
1321 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1327 __gitcomp_nl "$(__git_refs)"
1334 __gitcomp "--all --info --man --web"
1338 __git_compute_all_commands
1339 __gitcomp "$__git_all_commands $(__git_aliases)
1340 attributes cli core-tutorial cvs-migration
1341 diffcore gitk glossary hooks ignore modules
1342 namespaces repository-layout tutorial tutorial-2
1352 false true umask group all world everybody
1353 " "" "${cur##--shared=}"
1357 __gitcomp "--quiet --bare --template= --shared --shared="
1367 __gitcomp "--cached --deleted --modified --others --ignored
1368 --stage --directory --no-empty-directory --unmerged
1369 --killed --exclude= --exclude-from=
1370 --exclude-per-directory= --exclude-standard
1371 --error-unmatch --with-tree= --full-name
1372 --abbrev --ignored --exclude-per-directory
1378 # XXX ignore options like --modified and always suggest all cached
1380 __git_complete_index_file "--cached"
1385 __gitcomp_nl "$(__git_remotes)"
1393 # Options that go well for log, shortlog and gitk
1394 __git_log_common_options="
1396 --branches --tags --remotes
1397 --first-parent --merges --no-merges
1399 --max-age= --since= --after=
1400 --min-age= --until= --before=
1401 --min-parents= --max-parents=
1402 --no-min-parents --no-max-parents
1404 # Options that go well for log and gitk (not shortlog)
1405 __git_log_gitk_options="
1406 --dense --sparse --full-history
1407 --simplify-merges --simplify-by-decoration
1408 --left-right --notes --no-notes
1410 # Options that go well for log and shortlog (not gitk)
1411 __git_log_shortlog_options="
1412 --author= --committer= --grep=
1416 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1417 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1421 __git_has_doubledash && return
1423 local g="$(git rev-parse --git-dir 2>/dev/null)"
1425 if [ -f "$g/MERGE_HEAD" ]; then
1429 --pretty=*|--format=*)
1430 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1435 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1439 __gitcomp "long short" "" "${cur##--decorate=}"
1444 $__git_log_common_options
1445 $__git_log_shortlog_options
1446 $__git_log_gitk_options
1447 --root --topo-order --date-order --reverse
1448 --follow --full-diff
1449 --abbrev-commit --abbrev=
1450 --relative-date --date=
1451 --pretty= --format= --oneline
1454 --decorate --decorate=
1456 --parents --children
1458 $__git_diff_common_options
1459 --pickaxe-all --pickaxe-regex
1464 __git_complete_revlist
1467 __git_merge_options="
1468 --no-commit --no-stat --log --no-log --squash --strategy
1469 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1474 __git_complete_strategy && return
1478 __gitcomp "$__git_merge_options"
1481 __gitcomp_nl "$(__git_refs)"
1488 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1500 __gitcomp_nl "$(__git_refs)"
1507 __gitcomp "--dry-run"
1512 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1513 # We need to show both cached and untracked files (including
1514 # empty directories) since this may not be the last argument.
1515 __git_complete_index_file "--cached --others --directory"
1517 __git_complete_index_file "--cached"
1523 __gitcomp "--tags --all --stdin"
1528 local subcommands='add append copy edit list prune remove show'
1529 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1531 case "$subcommand,$cur" in
1538 __gitcomp_nl "$(__git_refs)"
1541 __gitcomp "$subcommands --ref"
1545 add,--reuse-message=*|append,--reuse-message=*|\
1546 add,--reedit-message=*|append,--reedit-message=*)
1547 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1550 __gitcomp '--file= --message= --reedit-message=
1557 __gitcomp '--dry-run --verbose'
1566 __gitcomp_nl "$(__git_refs)"
1575 __git_complete_strategy && return
1580 --rebase --no-rebase
1581 $__git_merge_options
1582 $__git_fetch_options
1587 __git_complete_remote_or_refspec
1594 __gitcomp_nl "$(__git_remotes)"
1599 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1604 --all --mirror --tags --dry-run --force --verbose
1605 --receive-pack= --repo= --set-upstream
1610 __git_complete_remote_or_refspec
1615 local dir="$(__gitdir)"
1616 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1617 __gitcomp "--continue --skip --abort"
1620 __git_complete_strategy && return
1623 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1628 --onto --merge --strategy --interactive
1629 --preserve-merges --stat --no-stat
1630 --committer-date-is-author-date --ignore-date
1631 --ignore-whitespace --whitespace=
1637 __gitcomp_nl "$(__git_refs)"
1642 local subcommands="show delete expire"
1643 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1645 if [ -z "$subcommand" ]; then
1646 __gitcomp "$subcommands"
1648 __gitcomp_nl "$(__git_refs)"
1652 __git_send_email_confirm_options="always never auto cc compose"
1653 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1660 $__git_send_email_confirm_options
1661 " "" "${cur##--confirm=}"
1666 $__git_send_email_suppresscc_options
1667 " "" "${cur##--suppress-cc=}"
1671 --smtp-encryption=*)
1672 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1678 " "" "${cur##--thread=}"
1682 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1683 --compose --confirm= --dry-run --envelope-sender
1685 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1686 --no-suppress-from --no-thread --quiet
1687 --signed-off-by-cc --smtp-pass --smtp-server
1688 --smtp-server-port --smtp-encryption= --smtp-user
1689 --subject --suppress-cc= --suppress-from --thread --to
1690 --validate --no-validate
1691 $__git_format_patch_options"
1695 __git_complete_revlist
1703 __git_config_get_set_variables ()
1705 local prevword word config_file= c=$cword
1706 while [ $c -gt 1 ]; do
1709 --system|--global|--local|--file=*)
1714 config_file="$word $prevword"
1722 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1737 __gitcomp_nl "$(__git_remotes)"
1741 __gitcomp_nl "$(__git_refs)"
1745 local remote="${prev#remote.}"
1746 remote="${remote%.fetch}"
1747 if [ -z "$cur" ]; then
1748 __gitcompadd "refs/heads/" "" "" ""
1751 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1755 local remote="${prev#remote.}"
1756 remote="${remote%.push}"
1757 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1758 for-each-ref --format='%(refname):%(refname)' \
1762 pull.twohead|pull.octopus)
1763 __git_compute_merge_strategies
1764 __gitcomp "$__git_merge_strategies"
1767 color.branch|color.diff|color.interactive|\
1768 color.showbranch|color.status|color.ui)
1769 __gitcomp "always never auto"
1773 __gitcomp "false true"
1778 normal black red green yellow blue magenta cyan white
1779 bold dim ul blink reverse
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 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
1955 core.ignoreCygwinFSTricks
1958 core.logAllRefUpdates
1959 core.loosecompression
1962 core.packedGitWindowSize
1964 core.preferSymlinkRefs
1967 core.repositoryFormatVersion
1969 core.sharedRepository
1973 core.warnAmbiguousRefs
1976 diff.autorefreshindex
1979 diff.ignoreSubmodules
1984 diff.suppressBlankEmpty
1990 fetch.recurseSubmodules
1999 format.subjectprefix
2010 gc.reflogexpireunreachable
2014 gitcvs.commitmsgannotation
2015 gitcvs.dbTableNamePrefix
2026 gui.copyblamethreshold
2030 gui.matchtrackingbranch
2031 gui.newbranchtemplate
2032 gui.pruneduringfetch
2033 gui.spellingdictionary
2048 http.sslCertPasswordProtected
2053 i18n.logOutputEncoding
2059 imap.preformattedHTML
2069 interactive.singlekey
2085 mergetool.keepBackup
2086 mergetool.keepTemporaries
2091 notes.rewrite.rebase
2095 pack.deltaCacheLimit
2111 receive.denyCurrentBranch
2112 receive.denyDeleteCurrent
2114 receive.denyNonFastForwards
2117 receive.updateserverinfo
2119 repack.usedeltabaseoffset
2123 sendemail.aliasesfile
2124 sendemail.aliasfiletype
2128 sendemail.chainreplyto
2130 sendemail.envelopesender
2134 sendemail.signedoffbycc
2135 sendemail.smtpdomain
2136 sendemail.smtpencryption
2138 sendemail.smtpserver
2139 sendemail.smtpserveroption
2140 sendemail.smtpserverport
2142 sendemail.suppresscc
2143 sendemail.suppressfrom
2148 status.relativePaths
2149 status.showUntrackedFiles
2150 status.submodulesummary
2153 transfer.unpackLimit
2165 local subcommands="add rename remove set-head set-branches set-url show prune update"
2166 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2167 if [ -z "$subcommand" ]; then
2168 __gitcomp "$subcommands"
2172 case "$subcommand" in
2173 rename|remove|set-url|show|prune)
2174 __gitcomp_nl "$(__git_remotes)"
2176 set-head|set-branches)
2177 __git_complete_remote_or_refspec
2180 local i c='' IFS=$'\n'
2181 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2194 __gitcomp_nl "$(__git_refs)"
2199 __git_has_doubledash && return
2203 __gitcomp "--merge --mixed --hard --soft --patch"
2207 __gitcomp_nl "$(__git_refs)"
2214 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2218 __gitcomp_nl "$(__git_refs)"
2225 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2230 __git_complete_index_file "--cached"
2235 __git_has_doubledash && return
2240 $__git_log_common_options
2241 $__git_log_shortlog_options
2242 --numbered --summary
2247 __git_complete_revlist
2252 __git_has_doubledash && return
2255 --pretty=*|--format=*)
2256 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2261 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2265 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2266 $__git_diff_common_options
2279 --all --remotes --topo-order --current --more=
2280 --list --independent --merge-base --no-name
2282 --sha1-name --sparse --topics --reflog
2287 __git_complete_revlist
2292 local save_opts='--keep-index --no-keep-index --quiet --patch'
2293 local subcommands='save list show apply clear drop pop create branch'
2294 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2295 if [ -z "$subcommand" ]; then
2298 __gitcomp "$save_opts"
2301 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2302 __gitcomp "$subcommands"
2307 case "$subcommand,$cur" in
2309 __gitcomp "$save_opts"
2312 __gitcomp "--index --quiet"
2314 show,--*|drop,--*|branch,--*)
2316 show,*|apply,*|drop,*|pop,*|branch,*)
2317 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2318 | sed -n -e 's/:.*//p')"
2328 __git_has_doubledash && return
2330 local subcommands="add status init deinit update summary foreach sync"
2331 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2334 __gitcomp "--quiet --cached"
2337 __gitcomp "$subcommands"
2347 init fetch clone rebase dcommit log find-rev
2348 set-tree commit-diff info create-ignore propget
2349 proplist show-ignore show-externals branch tag blame
2350 migrate mkdirs reset gc
2352 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2353 if [ -z "$subcommand" ]; then
2354 __gitcomp "$subcommands"
2356 local remote_opts="--username= --config-dir= --no-auth-cache"
2358 --follow-parent --authors-file= --repack=
2359 --no-metadata --use-svm-props --use-svnsync-props
2360 --log-window-size= --no-checkout --quiet
2361 --repack-flags --use-log-author --localtime
2362 --ignore-paths= $remote_opts
2365 --template= --shared= --trunk= --tags=
2366 --branches= --stdlayout --minimize-url
2367 --no-metadata --use-svm-props --use-svnsync-props
2368 --rewrite-root= --prefix= --use-log-author
2369 --add-author-from $remote_opts
2372 --edit --rmdir --find-copies-harder --copy-similarity=
2375 case "$subcommand,$cur" in
2377 __gitcomp "--revision= --fetch-all $fc_opts"
2380 __gitcomp "--revision= $fc_opts $init_opts"
2383 __gitcomp "$init_opts"
2387 --merge --strategy= --verbose --dry-run
2388 --fetch-all --no-rebase --commit-url
2389 --revision --interactive $cmt_opts $fc_opts
2393 __gitcomp "--stdin $cmt_opts $fc_opts"
2395 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2396 show-externals,--*|mkdirs,--*)
2397 __gitcomp "--revision="
2401 --limit= --revision= --verbose --incremental
2402 --oneline --show-commit --non-recursive
2403 --authors-file= --color
2408 --merge --verbose --strategy= --local
2409 --fetch-all --dry-run $fc_opts
2413 __gitcomp "--message= --file= --revision= $cmt_opts"
2419 __gitcomp "--dry-run --message --tag"
2422 __gitcomp "--dry-run --message"
2425 __gitcomp "--git-format"
2429 --config-dir= --ignore-paths= --minimize
2430 --no-auth-cache --username=
2434 __gitcomp "--revision= --parent"
2445 while [ $c -lt $cword ]; do
2449 __gitcomp_nl "$(__git_tags)"
2464 __gitcomp_nl "$(__git_tags)"
2468 __gitcomp_nl "$(__git_refs)"
2480 local i c=1 command __git_dir
2482 while [ $c -lt $cword ]; do
2485 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2486 --bare) __git_dir="." ;;
2487 --help) command="help"; break ;;
2490 *) command="$i"; break ;;
2495 if [ -z "$command" ]; then
2509 --no-replace-objects
2513 *) __git_compute_porcelain_commands
2514 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2519 local completion_func="_git_${command//-/_}"
2520 declare -f $completion_func >/dev/null && $completion_func && return
2522 local expansion=$(__git_aliased_command "$command")
2523 if [ -n "$expansion" ]; then
2524 completion_func="_git_${expansion//-/_}"
2525 declare -f $completion_func >/dev/null && $completion_func
2531 __git_has_doubledash && return
2533 local g="$(__gitdir)"
2535 if [ -f "$g/MERGE_HEAD" ]; then
2541 $__git_log_common_options
2542 $__git_log_gitk_options
2548 __git_complete_revlist
2551 if [[ -n ${ZSH_VERSION-} ]]; then
2552 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2554 autoload -U +X compinit && compinit
2560 local cur_="${3-$cur}"
2566 local c IFS=$' \t\n'
2574 array[$#array+1]="$c"
2577 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2588 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2597 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2603 local cur cword prev
2604 cur=${words[CURRENT-1]}
2605 prev=${words[CURRENT-2]}
2615 let _ret && _default -S '' && _ret=0
2619 compdef _git git gitk
2625 local cur words cword prev
2626 _get_comp_words_by_ref -n =: cur words cword prev
2630 # Setup completion for certain functions defined above by setting common
2631 # variables and workarounds.
2632 # This is NOT a public function; use at your own risk.
2635 local wrapper="__git_wrap${2}"
2636 eval "$wrapper () { __git_func_wrap $2 ; }"
2637 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2638 || complete -o default -o nospace -F $wrapper $1
2641 # wrapper for backwards compatibility
2644 __git_wrap__git_main
2647 # wrapper for backwards compatibility
2650 __git_wrap__gitk_main
2653 __git_complete git __git_main
2654 __git_complete gitk __gitk_main
2656 # The following are necessary only for Cygwin, and only are needed
2657 # when the user has tab-completed the executable name and consequently
2658 # included the '.exe' suffix.
2660 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2661 __git_complete git.exe __git_main