1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 case "$COMP_WORDBREAKS" in
34 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
37 # Discovers the path to the git repository taking any '--git-dir=<path>' and
38 # '-C <path>' options into account and stores it in the $__git_repo_path
40 __git_find_repo_path ()
42 if [ -n "$__git_repo_path" ]; then
43 # we already know where it is
47 if [ -n "${__git_C_args-}" ]; then
48 __git_repo_path="$(git "${__git_C_args[@]}" \
49 ${__git_dir:+--git-dir="$__git_dir"} \
50 rev-parse --absolute-git-dir 2>/dev/null)"
51 elif [ -n "${__git_dir-}" ]; then
52 test -d "$__git_dir" &&
53 __git_repo_path="$__git_dir"
54 elif [ -n "${GIT_DIR-}" ]; then
55 test -d "${GIT_DIR-}" &&
56 __git_repo_path="$GIT_DIR"
57 elif [ -d .git ]; then
60 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
64 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
65 # __gitdir accepts 0 or 1 arguments (i.e., location)
66 # returns location of .git repo
69 if [ -z "${1-}" ]; then
70 __git_find_repo_path || return 1
71 echo "$__git_repo_path"
72 elif [ -d "$1/.git" ]; then
79 # Runs git with all the options given as argument, respecting any
80 # '--git-dir=<path>' and '-C <path>' options present on the command line
83 git ${__git_C_args:+"${__git_C_args[@]}"} \
84 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
87 # The following function is based on code from:
89 # bash_completion - programmable completion functions for bash 3.2+
91 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
92 # © 2009-2010, Bash Completion Maintainers
93 # <bash-completion-devel@lists.alioth.debian.org>
95 # This program is free software; you can redistribute it and/or modify
96 # it under the terms of the GNU General Public License as published by
97 # the Free Software Foundation; either version 2, or (at your option)
100 # This program is distributed in the hope that it will be useful,
101 # but WITHOUT ANY WARRANTY; without even the implied warranty of
102 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103 # GNU General Public License for more details.
105 # You should have received a copy of the GNU General Public License
106 # along with this program; if not, write to the Free Software Foundation,
107 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
109 # The latest version of this software can be obtained here:
111 # http://bash-completion.alioth.debian.org/
115 # This function can be used to access a tokenized list of words
116 # on the command line:
118 # __git_reassemble_comp_words_by_ref '=:'
119 # if test "${words_[cword_-1]}" = -w
124 # The argument should be a collection of characters from the list of
125 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
128 # This is roughly equivalent to going back in time and setting
129 # COMP_WORDBREAKS to exclude those characters. The intent is to
130 # make option types like --date=<type> and <rev>:<path> easy to
131 # recognize by treating each shell word as a single token.
133 # It is best not to set COMP_WORDBREAKS directly because the value is
134 # shared with other completion scripts. By the time the completion
135 # function gets called, COMP_WORDS has already been populated so local
136 # changes to COMP_WORDBREAKS have no effect.
138 # Output: words_, cword_, cur_.
140 __git_reassemble_comp_words_by_ref()
142 local exclude i j first
143 # Which word separators to exclude?
144 exclude="${1//[^$COMP_WORDBREAKS]}"
146 if [ -z "$exclude" ]; then
147 words_=("${COMP_WORDS[@]}")
150 # List of word completion separators has shrunk;
151 # re-assemble words to complete.
152 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
153 # Append each nonempty word consisting of just
154 # word separator characters to the current word.
158 [ -n "${COMP_WORDS[$i]}" ] &&
159 # word consists of excluded word separators
160 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
162 # Attach to the previous token,
163 # unless the previous token is the command name.
164 if [ $j -ge 2 ] && [ -n "$first" ]; then
168 words_[$j]=${words_[j]}${COMP_WORDS[i]}
169 if [ $i = $COMP_CWORD ]; then
172 if (($i < ${#COMP_WORDS[@]} - 1)); then
179 words_[$j]=${words_[j]}${COMP_WORDS[i]}
180 if [ $i = $COMP_CWORD ]; then
186 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
187 _get_comp_words_by_ref ()
189 local exclude cur_ words_ cword_
190 if [ "$1" = "-n" ]; then
194 __git_reassemble_comp_words_by_ref "$exclude"
195 cur_=${words_[cword_]}
196 while [ $# -gt 0 ]; do
202 prev=${words_[$cword_-1]}
205 words=("${words_[@]}")
218 local x i=${#COMPREPLY[@]}
220 if [[ "$x" == "$3"* ]]; then
221 COMPREPLY[i++]="$2$x$4"
232 # Generates completion reply, appending a space to possible completion words,
234 # It accepts 1 to 4 arguments:
235 # 1: List of possible completion words.
236 # 2: A prefix to be added to each possible completion word (optional).
237 # 3: Generate possible completion matches for this word (optional).
238 # 4: A suffix to be appended to each possible completion word (optional).
241 local cur_="${3-$cur}"
247 local c i=0 IFS=$' \t\n'
250 if [[ $c == "$cur_"* ]]; then
255 COMPREPLY[i++]="${2-}$c"
262 # Variation of __gitcomp_nl () that appends to the existing list of
263 # completion candidates, COMPREPLY.
264 __gitcomp_nl_append ()
267 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
270 # Generates completion reply from newline-separated possible completion words
271 # by appending a space to all of them.
272 # It accepts 1 to 4 arguments:
273 # 1: List of possible completion words, separated by a single newline.
274 # 2: A prefix to be added to each possible completion word (optional).
275 # 3: Generate possible completion matches for this word (optional).
276 # 4: A suffix to be appended to each possible completion word instead of
277 # the default space (optional). If specified but empty, nothing is
282 __gitcomp_nl_append "$@"
285 # Generates completion reply with compgen from newline-separated possible
286 # completion filenames.
287 # It accepts 1 to 3 arguments:
288 # 1: List of possible completion filenames, separated by a single newline.
289 # 2: A directory prefix to be added to each possible completion filename
291 # 3: Generate possible completion matches for this word (optional).
296 # XXX does not work when the directory prefix contains a tilde,
297 # since tilde expansion is not applied.
298 # This means that COMPREPLY will be empty and Bash default
299 # completion will be used.
300 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
302 # use a hack to enable file mode in bash < 4
303 compopt -o filenames +o nospace 2>/dev/null ||
304 compgen -f /non-existing-dir/ > /dev/null
307 # Execute 'git ls-files', unless the --committable option is specified, in
308 # which case it runs 'git diff-index' to find out the files that can be
309 # committed. It return paths relative to the directory specified in the first
310 # argument, and using the options specified in the second argument.
311 __git_ls_files_helper ()
313 if [ "$2" == "--committable" ]; then
314 __git -C "$1" diff-index --name-only --relative HEAD
316 # NOTE: $2 is not quoted in order to support multiple options
317 __git -C "$1" ls-files --exclude-standard $2
322 # __git_index_files accepts 1 or 2 arguments:
323 # 1: Options to pass to ls-files (required).
324 # 2: A directory path (optional).
325 # If provided, only files within the specified directory are listed.
326 # Sub directories are never recursed. Path must have a trailing
330 local root="${2-.}" file
332 __git_ls_files_helper "$root" "$1" |
333 while read -r file; do
335 ?*/*) echo "${file%%/*}" ;;
343 __git for-each-ref --format='%(refname:short)' refs/heads
348 __git for-each-ref --format='%(refname:short)' refs/tags
351 # Lists refs from the local (by default) or from a remote repository.
352 # It accepts 0, 1 or 2 arguments:
353 # 1: The remote to list refs from (optional; ignored, if set but empty).
354 # Can be the name of a configured remote, a path, or a URL.
355 # 2: In addition to local refs, list unique branches from refs/remotes/ for
356 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
359 local i hash dir track="${2-}"
360 local list_refs_from=path remote="${1-}"
361 local format refs pfx
364 dir="$__git_repo_path"
366 if [ -z "$remote" ]; then
367 if [ -z "$dir" ]; then
371 if __git_is_configured_remote "$remote"; then
372 # configured remote takes precedence over a
373 # local directory with the same name
374 list_refs_from=remote
375 elif [ -d "$remote/.git" ]; then
377 elif [ -d "$remote" ]; then
384 if [ "$list_refs_from" = path ]; then
392 [[ "$cur" == ^* ]] && pfx="^"
393 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
394 if [ -e "$dir/$i" ]; then echo $pfx$i; fi
396 format="refname:short"
397 refs="refs/tags refs/heads refs/remotes"
400 __git_dir="$dir" __git for-each-ref --format="$pfx%($format)" \
402 if [ -n "$track" ]; then
403 # employ the heuristic used by git checkout
404 # Try to find a remote branch that matches the completion word
405 # but only output if the branch name is unique
407 __git for-each-ref --shell --format="ref=%(refname:short)" \
409 while read -r entry; do
412 if [[ "$ref" == "$cur"* ]]; then
415 done | sort | uniq -u
421 __git ls-remote "$remote" "$cur*" | \
422 while read -r hash i; do
430 if [ "$list_refs_from" = remote ]; then
432 __git for-each-ref --format="%(refname:short)" \
433 "refs/remotes/$remote/" | sed -e "s#^$remote/##"
435 __git ls-remote "$remote" HEAD \
436 "refs/tags/*" "refs/heads/*" "refs/remotes/*" |
437 while read -r hash i; do
440 refs/*) echo "${i#refs/*/}" ;;
441 *) echo "$i" ;; # symbolic refs
449 # __git_refs2 requires 1 argument (to pass to __git_refs)
453 for i in $(__git_refs "$1"); do
458 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
459 __git_refs_remotes ()
462 __git ls-remote "$1" 'refs/heads/*' | \
463 while read -r hash i; do
464 echo "$i:refs/remotes/$1/${i#refs/heads/}"
471 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
475 # Returns true if $1 matches the name of a configured remote, false otherwise.
476 __git_is_configured_remote ()
479 for remote in $(__git_remotes); do
480 if [ "$remote" = "$1" ]; then
487 __git_list_merge_strategies ()
489 git merge -s help 2>&1 |
490 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
499 __git_merge_strategies=
500 # 'git merge -s help' (and thus detection of the merge strategy
501 # list) fails, unfortunately, if run outside of any git working
502 # tree. __git_merge_strategies is set to the empty string in
503 # that case, and the detection will be repeated the next time it
505 __git_compute_merge_strategies ()
507 test -n "$__git_merge_strategies" ||
508 __git_merge_strategies=$(__git_list_merge_strategies)
511 __git_complete_revlist_file ()
513 local pfx ls ref cur_="$cur"
533 case "$COMP_WORDBREAKS" in
535 *) pfx="$ref:$pfx" ;;
538 __gitcomp_nl "$(__git ls-tree "$ls" \
539 | sed '/^100... blob /{
555 pfx="${cur_%...*}..."
557 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
562 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
565 __gitcomp_nl "$(__git_refs)"
571 # __git_complete_index_file requires 1 argument:
572 # 1: the options to pass to ls-file
574 # The exception is --committable, which finds the files appropriate commit.
575 __git_complete_index_file ()
577 local pfx="" cur_="$cur"
587 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
590 __git_complete_file ()
592 __git_complete_revlist_file
595 __git_complete_revlist ()
597 __git_complete_revlist_file
600 __git_complete_remote_or_refspec ()
602 local cur_="$cur" cmd="${words[1]}"
603 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
604 if [ "$cmd" = "remote" ]; then
607 while [ $c -lt $cword ]; do
610 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
613 push) no_complete_refspec=1 ;;
621 *) remote="$i"; break ;;
625 if [ -z "$remote" ]; then
626 __gitcomp_nl "$(__git_remotes)"
629 if [ $no_complete_refspec = 1 ]; then
632 [ "$remote" = "." ] && remote=
635 case "$COMP_WORDBREAKS" in
637 *) pfx="${cur_%%:*}:" ;;
649 if [ $lhs = 1 ]; then
650 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
652 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
656 if [ $lhs = 1 ]; then
657 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
659 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
663 if [ $lhs = 1 ]; then
664 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
666 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
672 __git_complete_strategy ()
674 __git_compute_merge_strategies
677 __gitcomp "$__git_merge_strategies"
682 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
690 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
692 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
694 git help -a|egrep '^ [a-zA-Z0-9]'
698 __git_list_all_commands ()
701 for i in $(__git_commands)
704 *--*) : helper pattern;;
711 __git_compute_all_commands ()
713 test -n "$__git_all_commands" ||
714 __git_all_commands=$(__git_list_all_commands)
717 __git_list_porcelain_commands ()
720 __git_compute_all_commands
721 for i in $__git_all_commands
724 *--*) : helper pattern;;
725 applymbox) : ask gittus;;
726 applypatch) : ask gittus;;
727 archimport) : import;;
728 cat-file) : plumbing;;
729 check-attr) : plumbing;;
730 check-ignore) : plumbing;;
731 check-mailmap) : plumbing;;
732 check-ref-format) : plumbing;;
733 checkout-index) : plumbing;;
734 column) : internal helper;;
735 commit-tree) : plumbing;;
736 count-objects) : infrequent;;
737 credential) : credentials;;
738 credential-*) : credentials helper;;
739 cvsexportcommit) : export;;
740 cvsimport) : import;;
741 cvsserver) : daemon;;
743 diff-files) : plumbing;;
744 diff-index) : plumbing;;
745 diff-tree) : plumbing;;
746 fast-import) : import;;
747 fast-export) : export;;
748 fsck-objects) : plumbing;;
749 fetch-pack) : plumbing;;
750 fmt-merge-msg) : plumbing;;
751 for-each-ref) : plumbing;;
752 hash-object) : plumbing;;
753 http-*) : transport;;
754 index-pack) : plumbing;;
755 init-db) : deprecated;;
756 local-fetch) : plumbing;;
757 ls-files) : plumbing;;
758 ls-remote) : plumbing;;
759 ls-tree) : plumbing;;
760 mailinfo) : plumbing;;
761 mailsplit) : plumbing;;
762 merge-*) : plumbing;;
765 pack-objects) : plumbing;;
766 pack-redundant) : plumbing;;
767 pack-refs) : plumbing;;
768 parse-remote) : plumbing;;
769 patch-id) : plumbing;;
771 prune-packed) : plumbing;;
772 quiltimport) : import;;
773 read-tree) : plumbing;;
774 receive-pack) : plumbing;;
775 remote-*) : transport;;
777 rev-list) : plumbing;;
778 rev-parse) : plumbing;;
779 runstatus) : plumbing;;
780 sh-setup) : internal;;
782 show-ref) : plumbing;;
783 send-pack) : plumbing;;
784 show-index) : plumbing;;
786 stripspace) : plumbing;;
787 symbolic-ref) : plumbing;;
788 unpack-file) : plumbing;;
789 unpack-objects) : plumbing;;
790 update-index) : plumbing;;
791 update-ref) : plumbing;;
792 update-server-info) : daemon;;
793 upload-archive) : plumbing;;
794 upload-pack) : plumbing;;
795 write-tree) : plumbing;;
797 verify-pack) : infrequent;;
798 verify-tag) : plumbing;;
804 __git_porcelain_commands=
805 __git_compute_porcelain_commands ()
807 test -n "$__git_porcelain_commands" ||
808 __git_porcelain_commands=$(__git_list_porcelain_commands)
811 # Lists all set config variables starting with the given section prefix,
812 # with the prefix removed.
813 __git_get_config_variables ()
815 local section="$1" i IFS=$'\n'
816 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
817 echo "${i#$section.}"
821 __git_pretty_aliases ()
823 __git_get_config_variables "pretty"
828 __git_get_config_variables "alias"
831 # __git_aliased_command requires 1 argument
832 __git_aliased_command ()
834 local word cmdline=$(__git config --get "alias.$1")
835 for word in $cmdline; do
841 \!*) : shell command alias ;;
843 *=*) : setting env ;;
845 \(\)) : skip parens of shell function definition ;;
846 {) : skip start of shell helper function ;;
847 :) : skip null command ;;
848 \'*) : skip opening quote after sh -c ;;
856 # __git_find_on_cmdline requires 1 argument
857 __git_find_on_cmdline ()
859 local word subcommand c=1
860 while [ $c -lt $cword ]; do
862 for subcommand in $1; do
863 if [ "$subcommand" = "$word" ]; then
872 # Echo the value of an option set on the command line or config
874 # $1: short option name
875 # $2: long option name including =
876 # $3: list of possible values
877 # $4: config string (optional)
880 # result="$(__git_get_option_value "-d" "--do-something=" \
881 # "yes no" "core.doSomething")"
883 # result is then either empty (no option set) or "yes" or "no"
885 # __git_get_option_value requires 3 arguments
886 __git_get_option_value ()
888 local c short_opt long_opt val
889 local result= values config_key word
897 while [ $c -ge 0 ]; do
899 for val in $values; do
900 if [ "$short_opt$val" = "$word" ] ||
901 [ "$long_opt$val" = "$word" ]; then
909 if [ -n "$config_key" ] && [ -z "$result" ]; then
910 result="$(__git config "$config_key")"
916 __git_has_doubledash ()
919 while [ $c -lt $cword ]; do
920 if [ "--" = "${words[c]}" ]; then
928 # Try to count non option arguments passed on the command line for the
929 # specified git command.
930 # When options are used, it is necessary to use the special -- option to
931 # tell the implementation were non option arguments begin.
932 # XXX this can not be improved, since options can appear everywhere, as
936 # __git_count_arguments requires 1 argument: the git command executed.
937 __git_count_arguments ()
941 # Skip "git" (first argument)
942 for ((i=1; i < ${#words[@]}; i++)); do
947 # Good; we can assume that the following are only non
952 # Skip the specified git command and discard git
965 __git_whitespacelist="nowarn warn error error-all fix"
970 if [ -d "$__git_repo_path"/rebase-apply ]; then
971 __gitcomp "--skip --continue --resolved --abort"
976 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
981 --3way --committer-date-is-author-date --ignore-date
982 --ignore-whitespace --ignore-space-change
983 --interactive --keep --no-utf8 --signoff --utf8
984 --whitespace= --scissors
994 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
999 --stat --numstat --summary --check --index
1000 --cached --index-info --reverse --reject --unidiff-zero
1001 --apply --no-add --exclude=
1002 --ignore-whitespace --ignore-space-change
1003 --whitespace= --inaccurate-eof --verbose
1014 --interactive --refresh --patch --update --dry-run
1015 --ignore-errors --intent-to-add
1020 # XXX should we check for --update and --all options ?
1021 __git_complete_index_file "--others --modified --directory --no-empty-directory"
1028 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1032 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1037 --format= --list --verbose
1038 --prefix= --remote= --exec=
1048 __git_has_doubledash && return
1050 local subcommands="start bad good skip reset visualize replay log run"
1051 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1052 if [ -z "$subcommand" ]; then
1053 __git_find_repo_path
1054 if [ -f "$__git_repo_path"/BISECT_START ]; then
1055 __gitcomp "$subcommands"
1057 __gitcomp "replay start"
1062 case "$subcommand" in
1063 bad|good|reset|skip|start)
1064 __gitcomp_nl "$(__git_refs)"
1073 local i c=1 only_local_ref="n" has_r="n"
1075 while [ $c -lt $cword ]; do
1078 -d|--delete|-m|--move) only_local_ref="y" ;;
1079 -r|--remotes) has_r="y" ;;
1085 --set-upstream-to=*)
1086 __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1090 --color --no-color --verbose --abbrev= --no-abbrev
1091 --track --no-track --contains --merged --no-merged
1092 --set-upstream-to= --edit-description --list
1093 --unset-upstream --delete --move --remotes
1097 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1098 __gitcomp_nl "$(__git_heads)"
1100 __gitcomp_nl "$(__git_refs)"
1108 local cmd="${words[2]}"
1111 __gitcomp "create list-heads verify unbundle"
1114 # looking for a file
1119 __git_complete_revlist
1128 __git_has_doubledash && return
1132 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1136 --quiet --ours --theirs --track --no-track --merge
1137 --conflict= --orphan --patch
1141 # check if --track, --no-track, or --no-guess was specified
1142 # if so, disable DWIM mode
1143 local flags="--track --no-track --no-guess" track=1
1144 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1147 __gitcomp_nl "$(__git_refs '' $track)"
1154 __gitcomp_nl "$(__git_refs)"
1159 __git_find_repo_path
1160 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1161 __gitcomp "--continue --quit --abort"
1166 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1169 __gitcomp_nl "$(__git_refs)"
1178 __gitcomp "--dry-run --quiet"
1183 # XXX should we check for -x option ?
1184 __git_complete_index_file "--others --directory"
1206 --recurse-submodules
1213 __git_untracked_file_modes="all no normal"
1219 __gitcomp_nl "$(__git_refs)"
1226 __gitcomp "default scissors strip verbatim whitespace
1227 " "" "${cur##--cleanup=}"
1230 --reuse-message=*|--reedit-message=*|\
1231 --fixup=*|--squash=*)
1232 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1235 --untracked-files=*)
1236 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1241 --all --author= --signoff --verify --no-verify
1243 --amend --include --only --interactive
1244 --dry-run --reuse-message= --reedit-message=
1245 --reset-author --file= --message= --template=
1246 --cleanup= --untracked-files --untracked-files=
1247 --verbose --quiet --fixup= --squash=
1252 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1253 __git_complete_index_file "--committable"
1255 # This is the first commit
1256 __git_complete_index_file "--cached"
1265 --all --tags --contains --abbrev= --candidates=
1266 --exact-match --debug --long --match --always
1270 __gitcomp_nl "$(__git_refs)"
1273 __git_diff_algorithms="myers minimal patience histogram"
1275 __git_diff_submodule_formats="diff log short"
1277 __git_diff_common_options="--stat --numstat --shortstat --summary
1278 --patch-with-stat --name-only --name-status --color
1279 --no-color --color-words --no-renames --check
1280 --full-index --binary --abbrev --diff-filter=
1281 --find-copies-harder
1282 --text --ignore-space-at-eol --ignore-space-change
1283 --ignore-all-space --ignore-blank-lines --exit-code
1284 --quiet --ext-diff --no-ext-diff
1285 --no-prefix --src-prefix= --dst-prefix=
1286 --inter-hunk-context=
1287 --patience --histogram --minimal
1288 --raw --word-diff --word-diff-regex=
1289 --dirstat --dirstat= --dirstat-by-file
1290 --dirstat-by-file= --cumulative
1292 --submodule --submodule=
1297 __git_has_doubledash && return
1301 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1305 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1309 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1310 --base --ours --theirs --no-index
1311 $__git_diff_common_options
1316 __git_complete_revlist_file
1319 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1320 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1325 __git_has_doubledash && return
1329 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1333 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1334 --base --ours --theirs
1335 --no-renames --diff-filter= --find-copies-harder
1336 --relative --ignore-submodules
1341 __git_complete_revlist_file
1344 __git_fetch_recurse_submodules="yes on-demand no"
1346 __git_fetch_options="
1347 --quiet --verbose --append --upload-pack --force --keep --depth=
1348 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1354 --recurse-submodules=*)
1355 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1359 __gitcomp "$__git_fetch_options"
1363 __git_complete_remote_or_refspec
1366 __git_format_patch_options="
1367 --stdout --attach --no-attach --thread --thread= --no-thread
1368 --numbered --start-number --numbered-files --keep-subject --signoff
1369 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1370 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1371 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1372 --output-directory --reroll-count --to= --quiet --notes
1375 _git_format_patch ()
1381 " "" "${cur##--thread=}"
1385 __gitcomp "$__git_format_patch_options"
1389 __git_complete_revlist
1397 --tags --root --unreachable --cache --no-reflogs --full
1398 --strict --verbose --lost-found
1409 __gitcomp "--prune --aggressive"
1420 __git_match_ctag() {
1421 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1426 __git_has_doubledash && return
1432 --text --ignore-case --word-regexp --invert-match
1433 --full-name --line-number
1434 --extended-regexp --basic-regexp --fixed-strings
1437 --files-with-matches --name-only
1438 --files-without-match
1441 --and --or --not --all-match
1447 case "$cword,$prev" in
1449 if test -r tags; then
1450 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1456 __gitcomp_nl "$(__git_refs)"
1463 __gitcomp "--all --guides --info --man --web"
1467 __git_compute_all_commands
1468 __gitcomp "$__git_all_commands $(__git_aliases)
1469 attributes cli core-tutorial cvs-migration
1470 diffcore everyday gitk glossary hooks ignore modules
1471 namespaces repository-layout revisions tutorial tutorial-2
1481 false true umask group all world everybody
1482 " "" "${cur##--shared=}"
1486 __gitcomp "--quiet --bare --template= --shared --shared="
1496 __gitcomp "--cached --deleted --modified --others --ignored
1497 --stage --directory --no-empty-directory --unmerged
1498 --killed --exclude= --exclude-from=
1499 --exclude-per-directory= --exclude-standard
1500 --error-unmatch --with-tree= --full-name
1501 --abbrev --ignored --exclude-per-directory
1507 # XXX ignore options like --modified and always suggest all cached
1509 __git_complete_index_file "--cached"
1514 __gitcomp_nl "$(__git_remotes)"
1522 # Options that go well for log, shortlog and gitk
1523 __git_log_common_options="
1525 --branches --tags --remotes
1526 --first-parent --merges --no-merges
1528 --max-age= --since= --after=
1529 --min-age= --until= --before=
1530 --min-parents= --max-parents=
1531 --no-min-parents --no-max-parents
1533 # Options that go well for log and gitk (not shortlog)
1534 __git_log_gitk_options="
1535 --dense --sparse --full-history
1536 --simplify-merges --simplify-by-decoration
1537 --left-right --notes --no-notes
1539 # Options that go well for log and shortlog (not gitk)
1540 __git_log_shortlog_options="
1541 --author= --committer= --grep=
1542 --all-match --invert-grep
1545 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1546 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1550 __git_has_doubledash && return
1551 __git_find_repo_path
1554 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1558 --pretty=*|--format=*)
1559 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1564 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1568 __gitcomp "full short no" "" "${cur##--decorate=}"
1572 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1576 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1581 $__git_log_common_options
1582 $__git_log_shortlog_options
1583 $__git_log_gitk_options
1584 --root --topo-order --date-order --reverse
1585 --follow --full-diff
1586 --abbrev-commit --abbrev=
1587 --relative-date --date=
1588 --pretty= --format= --oneline
1593 --decorate --decorate=
1595 --parents --children
1597 $__git_diff_common_options
1598 --pickaxe-all --pickaxe-regex
1603 __git_complete_revlist
1606 # Common merge options shared by git-merge(1) and git-pull(1).
1607 __git_merge_options="
1608 --no-commit --no-stat --log --no-log --squash --strategy
1609 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1610 --verify-signatures --no-verify-signatures --gpg-sign
1611 --quiet --verbose --progress --no-progress
1616 __git_complete_strategy && return
1620 __gitcomp "$__git_merge_options
1621 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1624 __gitcomp_nl "$(__git_refs)"
1631 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1645 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1649 __gitcomp_nl "$(__git_refs)"
1656 __gitcomp "--dry-run"
1661 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1662 # We need to show both cached and untracked files (including
1663 # empty directories) since this may not be the last argument.
1664 __git_complete_index_file "--cached --others --directory"
1666 __git_complete_index_file "--cached"
1672 __gitcomp "--tags --all --stdin"
1677 local subcommands='add append copy edit list prune remove show'
1678 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1680 case "$subcommand,$cur" in
1687 __gitcomp_nl "$(__git_refs)"
1690 __gitcomp "$subcommands --ref"
1694 add,--reuse-message=*|append,--reuse-message=*|\
1695 add,--reedit-message=*|append,--reedit-message=*)
1696 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1699 __gitcomp '--file= --message= --reedit-message=
1706 __gitcomp '--dry-run --verbose'
1715 __gitcomp_nl "$(__git_refs)"
1724 __git_complete_strategy && return
1727 --recurse-submodules=*)
1728 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1733 --rebase --no-rebase
1734 $__git_merge_options
1735 $__git_fetch_options
1740 __git_complete_remote_or_refspec
1743 __git_push_recurse_submodules="check on-demand"
1745 __git_complete_force_with_lease ()
1753 __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
1756 __gitcomp_nl "$(__git_refs)" "" "$cur_"
1765 __gitcomp_nl "$(__git_remotes)"
1768 --recurse-submodules)
1769 __gitcomp "$__git_push_recurse_submodules"
1775 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1778 --recurse-submodules=*)
1779 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1782 --force-with-lease=*)
1783 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1788 --all --mirror --tags --dry-run --force --verbose
1789 --quiet --prune --delete --follow-tags
1790 --receive-pack= --repo= --set-upstream
1791 --force-with-lease --force-with-lease= --recurse-submodules=
1796 __git_complete_remote_or_refspec
1801 __git_find_repo_path
1802 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1803 __gitcomp "--continue --skip --abort --quit --edit-todo"
1805 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1806 [ -d "$__git_repo_path"/rebase-merge ]; then
1807 __gitcomp "--continue --skip --abort --quit"
1810 __git_complete_strategy && return
1813 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1818 --onto --merge --strategy --interactive
1819 --preserve-merges --stat --no-stat
1820 --committer-date-is-author-date --ignore-date
1821 --ignore-whitespace --whitespace=
1822 --autosquash --no-autosquash
1823 --fork-point --no-fork-point
1824 --autostash --no-autostash
1825 --verify --no-verify
1826 --keep-empty --root --force-rebase --no-ff
1832 __gitcomp_nl "$(__git_refs)"
1837 local subcommands="show delete expire"
1838 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1840 if [ -z "$subcommand" ]; then
1841 __gitcomp "$subcommands"
1843 __gitcomp_nl "$(__git_refs)"
1847 __git_send_email_confirm_options="always never auto cc compose"
1848 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1853 --to|--cc|--bcc|--from)
1854 __gitcomp "$(__git send-email --dump-aliases)"
1862 $__git_send_email_confirm_options
1863 " "" "${cur##--confirm=}"
1868 $__git_send_email_suppresscc_options
1869 " "" "${cur##--suppress-cc=}"
1873 --smtp-encryption=*)
1874 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1880 " "" "${cur##--thread=}"
1883 --to=*|--cc=*|--bcc=*|--from=*)
1884 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
1888 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1889 --compose --confirm= --dry-run --envelope-sender
1891 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1892 --no-suppress-from --no-thread --quiet
1893 --signed-off-by-cc --smtp-pass --smtp-server
1894 --smtp-server-port --smtp-encryption= --smtp-user
1895 --subject --suppress-cc= --suppress-from --thread --to
1896 --validate --no-validate
1897 $__git_format_patch_options"
1901 __git_complete_revlist
1912 local untracked_state
1915 --ignore-submodules=*)
1916 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1919 --untracked-files=*)
1920 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1925 always never auto column row plain dense nodense
1926 " "" "${cur##--column=}"
1931 --short --branch --porcelain --long --verbose
1932 --untracked-files= --ignore-submodules= --ignored
1933 --column= --no-column
1939 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1940 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
1942 case "$untracked_state" in
1944 # --ignored option does not matter
1948 complete_opt="--cached --directory --no-empty-directory --others"
1950 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1951 complete_opt="$complete_opt --ignored --exclude=*"
1956 __git_complete_index_file "$complete_opt"
1959 __git_config_get_set_variables ()
1961 local prevword word config_file= c=$cword
1962 while [ $c -gt 1 ]; do
1965 --system|--global|--local|--file=*)
1970 config_file="$word $prevword"
1978 __git config $config_file --name-only --list
1984 branch.*.remote|branch.*.pushremote)
1985 __gitcomp_nl "$(__git_remotes)"
1989 __gitcomp_nl "$(__git_refs)"
1993 __gitcomp "false true preserve interactive"
1997 __gitcomp_nl "$(__git_remotes)"
2001 local remote="${prev#remote.}"
2002 remote="${remote%.fetch}"
2003 if [ -z "$cur" ]; then
2004 __gitcomp_nl "refs/heads/" "" "" ""
2007 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2011 local remote="${prev#remote.}"
2012 remote="${remote%.push}"
2013 __gitcomp_nl "$(__git for-each-ref \
2014 --format='%(refname):%(refname)' refs/heads)"
2017 pull.twohead|pull.octopus)
2018 __git_compute_merge_strategies
2019 __gitcomp "$__git_merge_strategies"
2022 color.branch|color.diff|color.interactive|\
2023 color.showbranch|color.status|color.ui)
2024 __gitcomp "always never auto"
2028 __gitcomp "false true"
2033 normal black red green yellow blue magenta cyan white
2034 bold dim ul blink reverse
2039 __gitcomp "log short"
2043 __gitcomp "man info web html"
2047 __gitcomp "$__git_log_date_formats"
2050 sendemail.aliasesfiletype)
2051 __gitcomp "mutt mailrc pine elm gnus"
2055 __gitcomp "$__git_send_email_confirm_options"
2058 sendemail.suppresscc)
2059 __gitcomp "$__git_send_email_suppresscc_options"
2062 sendemail.transferencoding)
2063 __gitcomp "7bit 8bit quoted-printable base64"
2066 --get|--get-all|--unset|--unset-all)
2067 __gitcomp_nl "$(__git_config_get_set_variables)"
2077 --system --global --local --file=
2078 --list --replace-all
2079 --get --get-all --get-regexp
2080 --add --unset --unset-all
2081 --remove-section --rename-section
2087 local pfx="${cur%.*}." cur_="${cur##*.}"
2088 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2092 local pfx="${cur%.*}." cur_="${cur#*.}"
2093 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
2094 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2098 local pfx="${cur%.*}." cur_="${cur##*.}"
2100 argprompt cmd confirm needsfile noconsole norescan
2101 prompt revprompt revunmerged title
2106 local pfx="${cur%.*}." cur_="${cur##*.}"
2107 __gitcomp "cmd path" "$pfx" "$cur_"
2111 local pfx="${cur%.*}." cur_="${cur##*.}"
2112 __gitcomp "cmd path" "$pfx" "$cur_"
2116 local pfx="${cur%.*}." cur_="${cur##*.}"
2117 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2121 local pfx="${cur%.*}." cur_="${cur#*.}"
2122 __git_compute_all_commands
2123 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2127 local pfx="${cur%.*}." cur_="${cur##*.}"
2129 url proxy fetch push mirror skipDefaultUpdate
2130 receivepack uploadpack tagopt pushurl
2135 local pfx="${cur%.*}." cur_="${cur#*.}"
2136 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2137 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2141 local pfx="${cur%.*}." cur_="${cur##*.}"
2142 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2148 advice.commitBeforeMerge
2150 advice.implicitIdentity
2151 advice.pushNonFastForward
2152 advice.resolveConflict
2156 apply.ignorewhitespace
2158 branch.autosetupmerge
2159 branch.autosetuprebase
2163 color.branch.current
2168 color.decorate.branch
2169 color.decorate.remoteBranch
2170 color.decorate.stash
2180 color.diff.whitespace
2185 color.grep.linenumber
2188 color.grep.separator
2190 color.interactive.error
2191 color.interactive.header
2192 color.interactive.help
2193 color.interactive.prompt
2198 color.status.changed
2200 color.status.nobranch
2201 color.status.unmerged
2202 color.status.untracked
2203 color.status.updated
2212 core.bigFileThreshold
2215 core.deltaBaseCacheLimit
2220 core.fsyncobjectfiles
2224 core.logAllRefUpdates
2225 core.loosecompression
2228 core.packedGitWindowSize
2230 core.preferSymlinkRefs
2233 core.repositoryFormatVersion
2235 core.sharedRepository
2240 core.warnAmbiguousRefs
2243 diff.autorefreshindex
2245 diff.ignoreSubmodules
2252 diff.suppressBlankEmpty
2258 fetch.recurseSubmodules
2269 format.subjectprefix
2280 gc.reflogexpireunreachable
2284 gitcvs.commitmsgannotation
2285 gitcvs.dbTableNamePrefix
2296 gui.copyblamethreshold
2300 gui.matchtrackingbranch
2301 gui.newbranchtemplate
2302 gui.pruneduringfetch
2303 gui.spellingdictionary
2320 http.sslCertPasswordProtected
2325 i18n.logOutputEncoding
2331 imap.preformattedHTML
2341 interactive.singlekey
2357 mergetool.keepBackup
2358 mergetool.keepTemporaries
2363 notes.rewrite.rebase
2367 pack.deltaCacheLimit
2384 receive.denyCurrentBranch
2385 receive.denyDeleteCurrent
2387 receive.denyNonFastForwards
2390 receive.updateserverinfo
2393 repack.usedeltabaseoffset
2397 sendemail.aliasesfile
2398 sendemail.aliasfiletype
2402 sendemail.chainreplyto
2404 sendemail.envelopesender
2408 sendemail.signedoffbycc
2409 sendemail.smtpdomain
2410 sendemail.smtpencryption
2412 sendemail.smtpserver
2413 sendemail.smtpserveroption
2414 sendemail.smtpserverport
2416 sendemail.suppresscc
2417 sendemail.suppressfrom
2422 status.relativePaths
2423 status.showUntrackedFiles
2424 status.submodulesummary
2427 transfer.unpackLimit
2439 local subcommands="add rename remove set-head set-branches set-url show prune update"
2440 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2441 if [ -z "$subcommand" ]; then
2442 __gitcomp "$subcommands"
2446 case "$subcommand" in
2447 rename|remove|set-url|show|prune)
2448 __gitcomp_nl "$(__git_remotes)"
2450 set-head|set-branches)
2451 __git_complete_remote_or_refspec
2454 __gitcomp "$(__git_get_config_variables "remotes")"
2463 __gitcomp_nl "$(__git_refs)"
2468 __git_has_doubledash && return
2472 __gitcomp "--merge --mixed --hard --soft --patch"
2476 __gitcomp_nl "$(__git_refs)"
2481 __git_find_repo_path
2482 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2483 __gitcomp "--continue --quit --abort"
2488 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2492 __gitcomp_nl "$(__git_refs)"
2499 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2504 __git_complete_index_file "--cached"
2509 __git_has_doubledash && return
2514 $__git_log_common_options
2515 $__git_log_shortlog_options
2516 --numbered --summary
2521 __git_complete_revlist
2526 __git_has_doubledash && return
2529 --pretty=*|--format=*)
2530 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2535 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2539 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2543 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2545 $__git_diff_common_options
2550 __git_complete_revlist_file
2558 --all --remotes --topo-order --date-order --current --more=
2559 --list --independent --merge-base --no-name
2561 --sha1-name --sparse --topics --reflog
2566 __git_complete_revlist
2571 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2572 local subcommands='save list show apply clear drop pop create branch'
2573 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2574 if [ -z "$subcommand" ]; then
2577 __gitcomp "$save_opts"
2580 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2581 __gitcomp "$subcommands"
2586 case "$subcommand,$cur" in
2588 __gitcomp "$save_opts"
2591 __gitcomp "--index --quiet"
2596 show,--*|branch,--*)
2599 if [ $cword -eq 3 ]; then
2600 __gitcomp_nl "$(__git_refs)";
2602 __gitcomp_nl "$(__git stash list \
2603 | sed -n -e 's/:.*//p')"
2606 show,*|apply,*|drop,*|pop,*)
2607 __gitcomp_nl "$(__git stash list \
2608 | sed -n -e 's/:.*//p')"
2618 __git_has_doubledash && return
2620 local subcommands="add status init deinit update summary foreach sync"
2621 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2624 __gitcomp "--quiet --cached"
2627 __gitcomp "$subcommands"
2637 init fetch clone rebase dcommit log find-rev
2638 set-tree commit-diff info create-ignore propget
2639 proplist show-ignore show-externals branch tag blame
2640 migrate mkdirs reset gc
2642 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2643 if [ -z "$subcommand" ]; then
2644 __gitcomp "$subcommands"
2646 local remote_opts="--username= --config-dir= --no-auth-cache"
2648 --follow-parent --authors-file= --repack=
2649 --no-metadata --use-svm-props --use-svnsync-props
2650 --log-window-size= --no-checkout --quiet
2651 --repack-flags --use-log-author --localtime
2652 --ignore-paths= --include-paths= $remote_opts
2655 --template= --shared= --trunk= --tags=
2656 --branches= --stdlayout --minimize-url
2657 --no-metadata --use-svm-props --use-svnsync-props
2658 --rewrite-root= --prefix= --use-log-author
2659 --add-author-from $remote_opts
2662 --edit --rmdir --find-copies-harder --copy-similarity=
2665 case "$subcommand,$cur" in
2667 __gitcomp "--revision= --fetch-all $fc_opts"
2670 __gitcomp "--revision= $fc_opts $init_opts"
2673 __gitcomp "$init_opts"
2677 --merge --strategy= --verbose --dry-run
2678 --fetch-all --no-rebase --commit-url
2679 --revision --interactive $cmt_opts $fc_opts
2683 __gitcomp "--stdin $cmt_opts $fc_opts"
2685 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2686 show-externals,--*|mkdirs,--*)
2687 __gitcomp "--revision="
2691 --limit= --revision= --verbose --incremental
2692 --oneline --show-commit --non-recursive
2693 --authors-file= --color
2698 --merge --verbose --strategy= --local
2699 --fetch-all --dry-run $fc_opts
2703 __gitcomp "--message= --file= --revision= $cmt_opts"
2709 __gitcomp "--dry-run --message --tag"
2712 __gitcomp "--dry-run --message"
2715 __gitcomp "--git-format"
2719 --config-dir= --ignore-paths= --minimize
2720 --no-auth-cache --username=
2724 __gitcomp "--revision= --parent"
2735 while [ $c -lt $cword ]; do
2739 __gitcomp_nl "$(__git_tags)"
2754 __gitcomp_nl "$(__git_tags)"
2758 __gitcomp_nl "$(__git_refs)"
2765 --list --delete --verify --annotate --message --file
2766 --sign --cleanup --local-user --force --column --sort
2767 --contains --points-at
2780 local subcommands="add list lock prune unlock"
2781 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2782 if [ -z "$subcommand" ]; then
2783 __gitcomp "$subcommands"
2785 case "$subcommand,$cur" in
2787 __gitcomp "--detach"
2790 __gitcomp "--porcelain"
2793 __gitcomp "--reason"
2796 __gitcomp "--dry-run --expire --verbose"
2806 local i c=1 command __git_dir __git_repo_path
2807 local __git_C_args C_args_count=0
2809 while [ $c -lt $cword ]; do
2812 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2813 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2814 --bare) __git_dir="." ;;
2815 --help) command="help"; break ;;
2816 -c|--work-tree|--namespace) ((c++)) ;;
2817 -C) __git_C_args[C_args_count++]=-C
2819 __git_C_args[C_args_count++]="${words[c]}"
2822 *) command="$i"; break ;;
2827 if [ -z "$command" ]; then
2829 --git-dir|-C|--work-tree)
2830 # these need a path argument, let's fall back to
2831 # Bash filename completion
2835 # we don't support completing these options' arguments
2853 --no-replace-objects
2857 *) __git_compute_porcelain_commands
2858 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2863 local completion_func="_git_${command//-/_}"
2864 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
2866 local expansion=$(__git_aliased_command "$command")
2867 if [ -n "$expansion" ]; then
2869 completion_func="_git_${expansion//-/_}"
2870 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
2876 __git_has_doubledash && return
2878 local __git_repo_path
2879 __git_find_repo_path
2882 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2888 $__git_log_common_options
2889 $__git_log_gitk_options
2895 __git_complete_revlist
2898 if [[ -n ${ZSH_VERSION-} ]]; then
2899 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2901 autoload -U +X compinit && compinit
2907 local cur_="${3-$cur}"
2913 local c IFS=$' \t\n'
2921 array[${#array[@]}+1]="$c"
2924 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2935 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2944 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2949 local _ret=1 cur cword prev
2950 cur=${words[CURRENT]}
2951 prev=${words[CURRENT-1]}
2953 emulate ksh -c __${service}_main
2954 let _ret && _default && _ret=0
2958 compdef _git git gitk
2964 local cur words cword prev
2965 _get_comp_words_by_ref -n =: cur words cword prev
2969 # Setup completion for certain functions defined above by setting common
2970 # variables and workarounds.
2971 # This is NOT a public function; use at your own risk.
2974 local wrapper="__git_wrap${2}"
2975 eval "$wrapper () { __git_func_wrap $2 ; }"
2976 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2977 || complete -o default -o nospace -F $wrapper $1
2980 # wrapper for backwards compatibility
2983 __git_wrap__git_main
2986 # wrapper for backwards compatibility
2989 __git_wrap__gitk_main
2992 __git_complete git __git_main
2993 __git_complete gitk __gitk_main
2995 # The following are necessary only for Cygwin, and only are needed
2996 # when the user has tab-completed the executable name and consequently
2997 # included the '.exe' suffix.
2999 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3000 __git_complete git.exe __git_main