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 # __gitdir accepts 0 or 1 arguments (i.e., location)
38 # returns location of .git repo
41 if [ -z "${1-}" ]; then
42 if [ -n "${__git_dir-}" ]; then
43 test -d "$__git_dir" || return 1
45 elif [ -n "${GIT_DIR-}" ]; then
46 test -d "${GIT_DIR-}" || return 1
48 elif [ -d .git ]; then
51 git rev-parse --git-dir 2>/dev/null
53 elif [ -d "$1/.git" ]; then
60 # The following function is based on code from:
62 # bash_completion - programmable completion functions for bash 3.2+
64 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
65 # © 2009-2010, Bash Completion Maintainers
66 # <bash-completion-devel@lists.alioth.debian.org>
68 # This program is free software; you can redistribute it and/or modify
69 # it under the terms of the GNU General Public License as published by
70 # the Free Software Foundation; either version 2, or (at your option)
73 # This program is distributed in the hope that it will be useful,
74 # but WITHOUT ANY WARRANTY; without even the implied warranty of
75 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76 # GNU General Public License for more details.
78 # You should have received a copy of the GNU General Public License
79 # along with this program; if not, write to the Free Software Foundation,
80 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
82 # The latest version of this software can be obtained here:
84 # http://bash-completion.alioth.debian.org/
88 # This function can be used to access a tokenized list of words
89 # on the command line:
91 # __git_reassemble_comp_words_by_ref '=:'
92 # if test "${words_[cword_-1]}" = -w
97 # The argument should be a collection of characters from the list of
98 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
101 # This is roughly equivalent to going back in time and setting
102 # COMP_WORDBREAKS to exclude those characters. The intent is to
103 # make option types like --date=<type> and <rev>:<path> easy to
104 # recognize by treating each shell word as a single token.
106 # It is best not to set COMP_WORDBREAKS directly because the value is
107 # shared with other completion scripts. By the time the completion
108 # function gets called, COMP_WORDS has already been populated so local
109 # changes to COMP_WORDBREAKS have no effect.
111 # Output: words_, cword_, cur_.
113 __git_reassemble_comp_words_by_ref()
115 local exclude i j first
116 # Which word separators to exclude?
117 exclude="${1//[^$COMP_WORDBREAKS]}"
119 if [ -z "$exclude" ]; then
120 words_=("${COMP_WORDS[@]}")
123 # List of word completion separators has shrunk;
124 # re-assemble words to complete.
125 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
126 # Append each nonempty word consisting of just
127 # word separator characters to the current word.
131 [ -n "${COMP_WORDS[$i]}" ] &&
132 # word consists of excluded word separators
133 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
135 # Attach to the previous token,
136 # unless the previous token is the command name.
137 if [ $j -ge 2 ] && [ -n "$first" ]; then
141 words_[$j]=${words_[j]}${COMP_WORDS[i]}
142 if [ $i = $COMP_CWORD ]; then
145 if (($i < ${#COMP_WORDS[@]} - 1)); then
152 words_[$j]=${words_[j]}${COMP_WORDS[i]}
153 if [ $i = $COMP_CWORD ]; then
159 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
160 _get_comp_words_by_ref ()
162 local exclude cur_ words_ cword_
163 if [ "$1" = "-n" ]; then
167 __git_reassemble_comp_words_by_ref "$exclude"
168 cur_=${words_[cword_]}
169 while [ $# -gt 0 ]; do
175 prev=${words_[$cword_-1]}
178 words=("${words_[@]}")
191 local x i=${#COMPREPLY[@]}
193 if [[ "$x" == "$3"* ]]; then
194 COMPREPLY[i++]="$2$x$4"
205 # Generates completion reply, appending a space to possible completion words,
207 # It accepts 1 to 4 arguments:
208 # 1: List of possible completion words.
209 # 2: A prefix to be added to each possible completion word (optional).
210 # 3: Generate possible completion matches for this word (optional).
211 # 4: A suffix to be appended to each possible completion word (optional).
214 local cur_="${3-$cur}"
220 local c i=0 IFS=$' \t\n'
223 if [[ $c == "$cur_"* ]]; then
228 COMPREPLY[i++]="${2-}$c"
235 # Variation of __gitcomp_nl () that appends to the existing list of
236 # completion candidates, COMPREPLY.
237 __gitcomp_nl_append ()
240 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
243 # Generates completion reply from newline-separated possible completion words
244 # by appending a space to all of them.
245 # It accepts 1 to 4 arguments:
246 # 1: List of possible completion words, separated by a single newline.
247 # 2: A prefix to be added to each possible completion word (optional).
248 # 3: Generate possible completion matches for this word (optional).
249 # 4: A suffix to be appended to each possible completion word instead of
250 # the default space (optional). If specified but empty, nothing is
255 __gitcomp_nl_append "$@"
258 # Generates completion reply with compgen from newline-separated possible
259 # completion filenames.
260 # It accepts 1 to 3 arguments:
261 # 1: List of possible completion filenames, separated by a single newline.
262 # 2: A directory prefix to be added to each possible completion filename
264 # 3: Generate possible completion matches for this word (optional).
269 # XXX does not work when the directory prefix contains a tilde,
270 # since tilde expansion is not applied.
271 # This means that COMPREPLY will be empty and Bash default
272 # completion will be used.
273 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
275 # use a hack to enable file mode in bash < 4
276 compopt -o filenames +o nospace 2>/dev/null ||
277 compgen -f /non-existing-dir/ > /dev/null
280 # Execute 'git ls-files', unless the --committable option is specified, in
281 # which case it runs 'git diff-index' to find out the files that can be
282 # committed. It return paths relative to the directory specified in the first
283 # argument, and using the options specified in the second argument.
284 __git_ls_files_helper ()
286 local dir="$(__gitdir)"
288 if [ "$2" == "--committable" ]; then
289 git --git-dir="$dir" -C "$1" diff-index --name-only --relative HEAD
291 # NOTE: $2 is not quoted in order to support multiple options
292 git --git-dir="$dir" -C "$1" ls-files --exclude-standard $2
297 # __git_index_files accepts 1 or 2 arguments:
298 # 1: Options to pass to ls-files (required).
299 # 2: A directory path (optional).
300 # If provided, only files within the specified directory are listed.
301 # Sub directories are never recursed. Path must have a trailing
305 local dir="$(__gitdir)" root="${2-.}" file
307 if [ -d "$dir" ]; then
308 __git_ls_files_helper "$root" "$1" |
309 while read -r file; do
311 ?*/*) echo "${file%%/*}" ;;
320 local dir="$(__gitdir)"
321 if [ -d "$dir" ]; then
322 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
330 local dir="$(__gitdir)"
331 if [ -d "$dir" ]; then
332 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
338 # Lists refs from the local (by default) or from a remote repository.
339 # It accepts 0, 1 or 2 arguments:
340 # 1: The remote to list refs from (optional; ignored, if set but empty).
341 # 2: In addition to local refs, list unique branches from refs/remotes/ for
342 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
345 local i hash dir="$(__gitdir)" track="${2-}"
346 local list_refs_from=path remote="${1-}"
347 local format refs pfx
349 if [ -n "$remote" ]; then
350 if [ -d "$remote/.git" ]; then
352 elif [ -d "$remote" ]; then
355 list_refs_from=remote
359 if [ "$list_refs_from" = path ] && [ -d "$dir" ]; then
367 [[ "$cur" == ^* ]] && pfx="^"
368 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
369 if [ -e "$dir/$i" ]; then echo $pfx$i; fi
371 format="refname:short"
372 refs="refs/tags refs/heads refs/remotes"
375 git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \
377 if [ -n "$track" ]; then
378 # employ the heuristic used by git checkout
379 # Try to find a remote branch that matches the completion word
380 # but only output if the branch name is unique
382 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
384 while read -r entry; do
387 if [[ "$ref" == "$cur"* ]]; then
390 done | sort | uniq -u
396 git --git-dir="$dir" ls-remote "$remote" "$cur*" 2>/dev/null | \
397 while read -r hash i; do
406 git --git-dir="$dir" for-each-ref --format="%(refname:short)" \
407 "refs/remotes/$remote/" 2>/dev/null | sed -e "s#^$remote/##"
412 # __git_refs2 requires 1 argument (to pass to __git_refs)
416 for i in $(__git_refs "$1"); do
421 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
422 __git_refs_remotes ()
425 git --git-dir="$(__gitdir)" ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
426 while read -r hash i; do
427 echo "$i:refs/remotes/$1/${i#refs/heads/}"
433 local d="$(__gitdir)"
434 test -d "$d/remotes" && ls -1 "$d/remotes"
435 git --git-dir="$d" remote
438 __git_list_merge_strategies ()
440 git merge -s help 2>&1 |
441 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
450 __git_merge_strategies=
451 # 'git merge -s help' (and thus detection of the merge strategy
452 # list) fails, unfortunately, if run outside of any git working
453 # tree. __git_merge_strategies is set to the empty string in
454 # that case, and the detection will be repeated the next time it
456 __git_compute_merge_strategies ()
458 test -n "$__git_merge_strategies" ||
459 __git_merge_strategies=$(__git_list_merge_strategies)
462 __git_complete_revlist_file ()
464 local pfx ls ref cur_="$cur"
484 case "$COMP_WORDBREAKS" in
486 *) pfx="$ref:$pfx" ;;
489 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
490 | sed '/^100... blob /{
506 pfx="${cur_%...*}..."
508 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
513 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
516 __gitcomp_nl "$(__git_refs)"
522 # __git_complete_index_file requires 1 argument:
523 # 1: the options to pass to ls-file
525 # The exception is --committable, which finds the files appropriate commit.
526 __git_complete_index_file ()
528 local pfx="" cur_="$cur"
538 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
541 __git_complete_file ()
543 __git_complete_revlist_file
546 __git_complete_revlist ()
548 __git_complete_revlist_file
551 __git_complete_remote_or_refspec ()
553 local cur_="$cur" cmd="${words[1]}"
554 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
555 if [ "$cmd" = "remote" ]; then
558 while [ $c -lt $cword ]; do
561 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
564 push) no_complete_refspec=1 ;;
572 *) remote="$i"; break ;;
576 if [ -z "$remote" ]; then
577 __gitcomp_nl "$(__git_remotes)"
580 if [ $no_complete_refspec = 1 ]; then
583 [ "$remote" = "." ] && remote=
586 case "$COMP_WORDBREAKS" in
588 *) pfx="${cur_%%:*}:" ;;
600 if [ $lhs = 1 ]; then
601 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
603 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
607 if [ $lhs = 1 ]; then
608 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
610 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
614 if [ $lhs = 1 ]; then
615 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
617 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
623 __git_complete_strategy ()
625 __git_compute_merge_strategies
628 __gitcomp "$__git_merge_strategies"
633 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
641 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
643 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
645 git help -a|egrep '^ [a-zA-Z0-9]'
649 __git_list_all_commands ()
652 for i in $(__git_commands)
655 *--*) : helper pattern;;
662 __git_compute_all_commands ()
664 test -n "$__git_all_commands" ||
665 __git_all_commands=$(__git_list_all_commands)
668 __git_list_porcelain_commands ()
671 __git_compute_all_commands
672 for i in $__git_all_commands
675 *--*) : helper pattern;;
676 applymbox) : ask gittus;;
677 applypatch) : ask gittus;;
678 archimport) : import;;
679 cat-file) : plumbing;;
680 check-attr) : plumbing;;
681 check-ignore) : plumbing;;
682 check-mailmap) : plumbing;;
683 check-ref-format) : plumbing;;
684 checkout-index) : plumbing;;
685 column) : internal helper;;
686 commit-tree) : plumbing;;
687 count-objects) : infrequent;;
688 credential) : credentials;;
689 credential-*) : credentials helper;;
690 cvsexportcommit) : export;;
691 cvsimport) : import;;
692 cvsserver) : daemon;;
694 diff-files) : plumbing;;
695 diff-index) : plumbing;;
696 diff-tree) : plumbing;;
697 fast-import) : import;;
698 fast-export) : export;;
699 fsck-objects) : plumbing;;
700 fetch-pack) : plumbing;;
701 fmt-merge-msg) : plumbing;;
702 for-each-ref) : plumbing;;
703 hash-object) : plumbing;;
704 http-*) : transport;;
705 index-pack) : plumbing;;
706 init-db) : deprecated;;
707 local-fetch) : plumbing;;
708 ls-files) : plumbing;;
709 ls-remote) : plumbing;;
710 ls-tree) : plumbing;;
711 mailinfo) : plumbing;;
712 mailsplit) : plumbing;;
713 merge-*) : plumbing;;
716 pack-objects) : plumbing;;
717 pack-redundant) : plumbing;;
718 pack-refs) : plumbing;;
719 parse-remote) : plumbing;;
720 patch-id) : plumbing;;
722 prune-packed) : plumbing;;
723 quiltimport) : import;;
724 read-tree) : plumbing;;
725 receive-pack) : plumbing;;
726 remote-*) : transport;;
728 rev-list) : plumbing;;
729 rev-parse) : plumbing;;
730 runstatus) : plumbing;;
731 sh-setup) : internal;;
733 show-ref) : plumbing;;
734 send-pack) : plumbing;;
735 show-index) : plumbing;;
737 stripspace) : plumbing;;
738 symbolic-ref) : plumbing;;
739 unpack-file) : plumbing;;
740 unpack-objects) : plumbing;;
741 update-index) : plumbing;;
742 update-ref) : plumbing;;
743 update-server-info) : daemon;;
744 upload-archive) : plumbing;;
745 upload-pack) : plumbing;;
746 write-tree) : plumbing;;
748 verify-pack) : infrequent;;
749 verify-tag) : plumbing;;
755 __git_porcelain_commands=
756 __git_compute_porcelain_commands ()
758 test -n "$__git_porcelain_commands" ||
759 __git_porcelain_commands=$(__git_list_porcelain_commands)
762 # Lists all set config variables starting with the given section prefix,
763 # with the prefix removed.
764 __git_get_config_variables ()
766 local section="$1" i IFS=$'\n'
767 for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
768 echo "${i#$section.}"
772 __git_pretty_aliases ()
774 __git_get_config_variables "pretty"
779 __git_get_config_variables "alias"
782 # __git_aliased_command requires 1 argument
783 __git_aliased_command ()
785 local word cmdline=$(git --git-dir="$(__gitdir)" \
786 config --get "alias.$1")
787 for word in $cmdline; do
793 \!*) : shell command alias ;;
795 *=*) : setting env ;;
797 \(\)) : skip parens of shell function definition ;;
798 {) : skip start of shell helper function ;;
799 :) : skip null command ;;
800 \'*) : skip opening quote after sh -c ;;
808 # __git_find_on_cmdline requires 1 argument
809 __git_find_on_cmdline ()
811 local word subcommand c=1
812 while [ $c -lt $cword ]; do
814 for subcommand in $1; do
815 if [ "$subcommand" = "$word" ]; then
824 # Echo the value of an option set on the command line or config
826 # $1: short option name
827 # $2: long option name including =
828 # $3: list of possible values
829 # $4: config string (optional)
832 # result="$(__git_get_option_value "-d" "--do-something=" \
833 # "yes no" "core.doSomething")"
835 # result is then either empty (no option set) or "yes" or "no"
837 # __git_get_option_value requires 3 arguments
838 __git_get_option_value ()
840 local c short_opt long_opt val
841 local result= values config_key word
849 while [ $c -ge 0 ]; do
851 for val in $values; do
852 if [ "$short_opt$val" = "$word" ] ||
853 [ "$long_opt$val" = "$word" ]; then
861 if [ -n "$config_key" ] && [ -z "$result" ]; then
862 result="$(git --git-dir="$(__gitdir)" config "$config_key")"
868 __git_has_doubledash ()
871 while [ $c -lt $cword ]; do
872 if [ "--" = "${words[c]}" ]; then
880 # Try to count non option arguments passed on the command line for the
881 # specified git command.
882 # When options are used, it is necessary to use the special -- option to
883 # tell the implementation were non option arguments begin.
884 # XXX this can not be improved, since options can appear everywhere, as
888 # __git_count_arguments requires 1 argument: the git command executed.
889 __git_count_arguments ()
893 # Skip "git" (first argument)
894 for ((i=1; i < ${#words[@]}; i++)); do
899 # Good; we can assume that the following are only non
904 # Skip the specified git command and discard git
917 __git_whitespacelist="nowarn warn error error-all fix"
921 local dir="$(__gitdir)"
922 if [ -d "$dir"/rebase-apply ]; then
923 __gitcomp "--skip --continue --resolved --abort"
928 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
933 --3way --committer-date-is-author-date --ignore-date
934 --ignore-whitespace --ignore-space-change
935 --interactive --keep --no-utf8 --signoff --utf8
936 --whitespace= --scissors
946 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
951 --stat --numstat --summary --check --index
952 --cached --index-info --reverse --reject --unidiff-zero
953 --apply --no-add --exclude=
954 --ignore-whitespace --ignore-space-change
955 --whitespace= --inaccurate-eof --verbose
966 --interactive --refresh --patch --update --dry-run
967 --ignore-errors --intent-to-add
972 # XXX should we check for --update and --all options ?
973 __git_complete_index_file "--others --modified --directory --no-empty-directory"
980 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
984 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
989 --format= --list --verbose
990 --prefix= --remote= --exec=
1000 __git_has_doubledash && return
1002 local subcommands="start bad good skip reset visualize replay log run"
1003 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1004 if [ -z "$subcommand" ]; then
1005 if [ -f "$(__gitdir)"/BISECT_START ]; then
1006 __gitcomp "$subcommands"
1008 __gitcomp "replay start"
1013 case "$subcommand" in
1014 bad|good|reset|skip|start)
1015 __gitcomp_nl "$(__git_refs)"
1024 local i c=1 only_local_ref="n" has_r="n"
1026 while [ $c -lt $cword ]; do
1029 -d|--delete|-m|--move) only_local_ref="y" ;;
1030 -r|--remotes) has_r="y" ;;
1036 --set-upstream-to=*)
1037 __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1041 --color --no-color --verbose --abbrev= --no-abbrev
1042 --track --no-track --contains --merged --no-merged
1043 --set-upstream-to= --edit-description --list
1044 --unset-upstream --delete --move --remotes
1048 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1049 __gitcomp_nl "$(__git_heads)"
1051 __gitcomp_nl "$(__git_refs)"
1059 local cmd="${words[2]}"
1062 __gitcomp "create list-heads verify unbundle"
1065 # looking for a file
1070 __git_complete_revlist
1079 __git_has_doubledash && return
1083 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1087 --quiet --ours --theirs --track --no-track --merge
1088 --conflict= --orphan --patch
1092 # check if --track, --no-track, or --no-guess was specified
1093 # if so, disable DWIM mode
1094 local flags="--track --no-track --no-guess" track=1
1095 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1098 __gitcomp_nl "$(__git_refs '' $track)"
1105 __gitcomp_nl "$(__git_refs)"
1110 local dir="$(__gitdir)"
1111 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1112 __gitcomp "--continue --quit --abort"
1117 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1120 __gitcomp_nl "$(__git_refs)"
1129 __gitcomp "--dry-run --quiet"
1134 # XXX should we check for -x option ?
1135 __git_complete_index_file "--others --directory"
1157 --recurse-submodules
1164 __git_untracked_file_modes="all no normal"
1170 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1177 __gitcomp "default scissors strip verbatim whitespace
1178 " "" "${cur##--cleanup=}"
1181 --reuse-message=*|--reedit-message=*|\
1182 --fixup=*|--squash=*)
1183 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1186 --untracked-files=*)
1187 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1192 --all --author= --signoff --verify --no-verify
1194 --amend --include --only --interactive
1195 --dry-run --reuse-message= --reedit-message=
1196 --reset-author --file= --message= --template=
1197 --cleanup= --untracked-files --untracked-files=
1198 --verbose --quiet --fixup= --squash=
1203 if git --git-dir="$(__gitdir)" rev-parse --verify --quiet HEAD >/dev/null; then
1204 __git_complete_index_file "--committable"
1206 # This is the first commit
1207 __git_complete_index_file "--cached"
1216 --all --tags --contains --abbrev= --candidates=
1217 --exact-match --debug --long --match --always
1221 __gitcomp_nl "$(__git_refs)"
1224 __git_diff_algorithms="myers minimal patience histogram"
1226 __git_diff_submodule_formats="diff log short"
1228 __git_diff_common_options="--stat --numstat --shortstat --summary
1229 --patch-with-stat --name-only --name-status --color
1230 --no-color --color-words --no-renames --check
1231 --full-index --binary --abbrev --diff-filter=
1232 --find-copies-harder
1233 --text --ignore-space-at-eol --ignore-space-change
1234 --ignore-all-space --ignore-blank-lines --exit-code
1235 --quiet --ext-diff --no-ext-diff
1236 --no-prefix --src-prefix= --dst-prefix=
1237 --inter-hunk-context=
1238 --patience --histogram --minimal
1239 --raw --word-diff --word-diff-regex=
1240 --dirstat --dirstat= --dirstat-by-file
1241 --dirstat-by-file= --cumulative
1243 --submodule --submodule=
1248 __git_has_doubledash && return
1252 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1256 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1260 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1261 --base --ours --theirs --no-index
1262 $__git_diff_common_options
1267 __git_complete_revlist_file
1270 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1271 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1276 __git_has_doubledash && return
1280 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1284 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1285 --base --ours --theirs
1286 --no-renames --diff-filter= --find-copies-harder
1287 --relative --ignore-submodules
1292 __git_complete_revlist_file
1295 __git_fetch_recurse_submodules="yes on-demand no"
1297 __git_fetch_options="
1298 --quiet --verbose --append --upload-pack --force --keep --depth=
1299 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1305 --recurse-submodules=*)
1306 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1310 __gitcomp "$__git_fetch_options"
1314 __git_complete_remote_or_refspec
1317 __git_format_patch_options="
1318 --stdout --attach --no-attach --thread --thread= --no-thread
1319 --numbered --start-number --numbered-files --keep-subject --signoff
1320 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1321 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1322 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1323 --output-directory --reroll-count --to= --quiet --notes
1326 _git_format_patch ()
1332 " "" "${cur##--thread=}"
1336 __gitcomp "$__git_format_patch_options"
1340 __git_complete_revlist
1348 --tags --root --unreachable --cache --no-reflogs --full
1349 --strict --verbose --lost-found
1360 __gitcomp "--prune --aggressive"
1371 __git_match_ctag() {
1372 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1377 __git_has_doubledash && return
1383 --text --ignore-case --word-regexp --invert-match
1384 --full-name --line-number
1385 --extended-regexp --basic-regexp --fixed-strings
1388 --files-with-matches --name-only
1389 --files-without-match
1392 --and --or --not --all-match
1398 case "$cword,$prev" in
1400 if test -r tags; then
1401 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1407 __gitcomp_nl "$(__git_refs)"
1414 __gitcomp "--all --guides --info --man --web"
1418 __git_compute_all_commands
1419 __gitcomp "$__git_all_commands $(__git_aliases)
1420 attributes cli core-tutorial cvs-migration
1421 diffcore everyday gitk glossary hooks ignore modules
1422 namespaces repository-layout revisions tutorial tutorial-2
1432 false true umask group all world everybody
1433 " "" "${cur##--shared=}"
1437 __gitcomp "--quiet --bare --template= --shared --shared="
1447 __gitcomp "--cached --deleted --modified --others --ignored
1448 --stage --directory --no-empty-directory --unmerged
1449 --killed --exclude= --exclude-from=
1450 --exclude-per-directory= --exclude-standard
1451 --error-unmatch --with-tree= --full-name
1452 --abbrev --ignored --exclude-per-directory
1458 # XXX ignore options like --modified and always suggest all cached
1460 __git_complete_index_file "--cached"
1465 __gitcomp_nl "$(__git_remotes)"
1473 # Options that go well for log, shortlog and gitk
1474 __git_log_common_options="
1476 --branches --tags --remotes
1477 --first-parent --merges --no-merges
1479 --max-age= --since= --after=
1480 --min-age= --until= --before=
1481 --min-parents= --max-parents=
1482 --no-min-parents --no-max-parents
1484 # Options that go well for log and gitk (not shortlog)
1485 __git_log_gitk_options="
1486 --dense --sparse --full-history
1487 --simplify-merges --simplify-by-decoration
1488 --left-right --notes --no-notes
1490 # Options that go well for log and shortlog (not gitk)
1491 __git_log_shortlog_options="
1492 --author= --committer= --grep=
1493 --all-match --invert-grep
1496 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1497 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1501 __git_has_doubledash && return
1503 local g="$(__gitdir)"
1505 if [ -f "$g/MERGE_HEAD" ]; then
1509 --pretty=*|--format=*)
1510 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1515 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1519 __gitcomp "full short no" "" "${cur##--decorate=}"
1523 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1527 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1532 $__git_log_common_options
1533 $__git_log_shortlog_options
1534 $__git_log_gitk_options
1535 --root --topo-order --date-order --reverse
1536 --follow --full-diff
1537 --abbrev-commit --abbrev=
1538 --relative-date --date=
1539 --pretty= --format= --oneline
1544 --decorate --decorate=
1546 --parents --children
1548 $__git_diff_common_options
1549 --pickaxe-all --pickaxe-regex
1554 __git_complete_revlist
1557 # Common merge options shared by git-merge(1) and git-pull(1).
1558 __git_merge_options="
1559 --no-commit --no-stat --log --no-log --squash --strategy
1560 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1561 --verify-signatures --no-verify-signatures --gpg-sign
1562 --quiet --verbose --progress --no-progress
1567 __git_complete_strategy && return
1571 __gitcomp "$__git_merge_options
1572 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1575 __gitcomp_nl "$(__git_refs)"
1582 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1596 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1600 __gitcomp_nl "$(__git_refs)"
1607 __gitcomp "--dry-run"
1612 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1613 # We need to show both cached and untracked files (including
1614 # empty directories) since this may not be the last argument.
1615 __git_complete_index_file "--cached --others --directory"
1617 __git_complete_index_file "--cached"
1623 __gitcomp "--tags --all --stdin"
1628 local subcommands='add append copy edit list prune remove show'
1629 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1631 case "$subcommand,$cur" in
1638 __gitcomp_nl "$(__git_refs)"
1641 __gitcomp "$subcommands --ref"
1645 add,--reuse-message=*|append,--reuse-message=*|\
1646 add,--reedit-message=*|append,--reedit-message=*)
1647 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1650 __gitcomp '--file= --message= --reedit-message=
1657 __gitcomp '--dry-run --verbose'
1666 __gitcomp_nl "$(__git_refs)"
1675 __git_complete_strategy && return
1678 --recurse-submodules=*)
1679 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1684 --rebase --no-rebase
1685 $__git_merge_options
1686 $__git_fetch_options
1691 __git_complete_remote_or_refspec
1694 __git_push_recurse_submodules="check on-demand"
1696 __git_complete_force_with_lease ()
1704 __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
1707 __gitcomp_nl "$(__git_refs)" "" "$cur_"
1716 __gitcomp_nl "$(__git_remotes)"
1719 --recurse-submodules)
1720 __gitcomp "$__git_push_recurse_submodules"
1726 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1729 --recurse-submodules=*)
1730 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1733 --force-with-lease=*)
1734 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1739 --all --mirror --tags --dry-run --force --verbose
1740 --quiet --prune --delete --follow-tags
1741 --receive-pack= --repo= --set-upstream
1742 --force-with-lease --force-with-lease= --recurse-submodules=
1747 __git_complete_remote_or_refspec
1752 local dir="$(__gitdir)"
1753 if [ -f "$dir"/rebase-merge/interactive ]; then
1754 __gitcomp "--continue --skip --abort --quit --edit-todo"
1756 elif [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1757 __gitcomp "--continue --skip --abort --quit"
1760 __git_complete_strategy && return
1763 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1768 --onto --merge --strategy --interactive
1769 --preserve-merges --stat --no-stat
1770 --committer-date-is-author-date --ignore-date
1771 --ignore-whitespace --whitespace=
1772 --autosquash --no-autosquash
1773 --fork-point --no-fork-point
1774 --autostash --no-autostash
1775 --verify --no-verify
1776 --keep-empty --root --force-rebase --no-ff
1782 __gitcomp_nl "$(__git_refs)"
1787 local subcommands="show delete expire"
1788 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1790 if [ -z "$subcommand" ]; then
1791 __gitcomp "$subcommands"
1793 __gitcomp_nl "$(__git_refs)"
1797 __git_send_email_confirm_options="always never auto cc compose"
1798 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1803 --to|--cc|--bcc|--from)
1805 $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
1814 $__git_send_email_confirm_options
1815 " "" "${cur##--confirm=}"
1820 $__git_send_email_suppresscc_options
1821 " "" "${cur##--suppress-cc=}"
1825 --smtp-encryption=*)
1826 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1832 " "" "${cur##--thread=}"
1835 --to=*|--cc=*|--bcc=*|--from=*)
1837 $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
1842 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1843 --compose --confirm= --dry-run --envelope-sender
1845 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1846 --no-suppress-from --no-thread --quiet
1847 --signed-off-by-cc --smtp-pass --smtp-server
1848 --smtp-server-port --smtp-encryption= --smtp-user
1849 --subject --suppress-cc= --suppress-from --thread --to
1850 --validate --no-validate
1851 $__git_format_patch_options"
1855 __git_complete_revlist
1866 local untracked_state
1869 --ignore-submodules=*)
1870 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1873 --untracked-files=*)
1874 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1879 always never auto column row plain dense nodense
1880 " "" "${cur##--column=}"
1885 --short --branch --porcelain --long --verbose
1886 --untracked-files= --ignore-submodules= --ignored
1887 --column= --no-column
1893 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1894 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
1896 case "$untracked_state" in
1898 # --ignored option does not matter
1902 complete_opt="--cached --directory --no-empty-directory --others"
1904 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1905 complete_opt="$complete_opt --ignored --exclude=*"
1910 __git_complete_index_file "$complete_opt"
1913 __git_config_get_set_variables ()
1915 local prevword word config_file= c=$cword
1916 while [ $c -gt 1 ]; do
1919 --system|--global|--local|--file=*)
1924 config_file="$word $prevword"
1932 git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null
1938 branch.*.remote|branch.*.pushremote)
1939 __gitcomp_nl "$(__git_remotes)"
1943 __gitcomp_nl "$(__git_refs)"
1947 __gitcomp "false true preserve interactive"
1951 __gitcomp_nl "$(__git_remotes)"
1955 local remote="${prev#remote.}"
1956 remote="${remote%.fetch}"
1957 if [ -z "$cur" ]; then
1958 __gitcomp_nl "refs/heads/" "" "" ""
1961 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1965 local remote="${prev#remote.}"
1966 remote="${remote%.push}"
1967 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1968 for-each-ref --format='%(refname):%(refname)' \
1972 pull.twohead|pull.octopus)
1973 __git_compute_merge_strategies
1974 __gitcomp "$__git_merge_strategies"
1977 color.branch|color.diff|color.interactive|\
1978 color.showbranch|color.status|color.ui)
1979 __gitcomp "always never auto"
1983 __gitcomp "false true"
1988 normal black red green yellow blue magenta cyan white
1989 bold dim ul blink reverse
1994 __gitcomp "log short"
1998 __gitcomp "man info web html"
2002 __gitcomp "$__git_log_date_formats"
2005 sendemail.aliasesfiletype)
2006 __gitcomp "mutt mailrc pine elm gnus"
2010 __gitcomp "$__git_send_email_confirm_options"
2013 sendemail.suppresscc)
2014 __gitcomp "$__git_send_email_suppresscc_options"
2017 sendemail.transferencoding)
2018 __gitcomp "7bit 8bit quoted-printable base64"
2021 --get|--get-all|--unset|--unset-all)
2022 __gitcomp_nl "$(__git_config_get_set_variables)"
2032 --system --global --local --file=
2033 --list --replace-all
2034 --get --get-all --get-regexp
2035 --add --unset --unset-all
2036 --remove-section --rename-section
2042 local pfx="${cur%.*}." cur_="${cur##*.}"
2043 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2047 local pfx="${cur%.*}." cur_="${cur#*.}"
2048 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
2049 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2053 local pfx="${cur%.*}." cur_="${cur##*.}"
2055 argprompt cmd confirm needsfile noconsole norescan
2056 prompt revprompt revunmerged title
2061 local pfx="${cur%.*}." cur_="${cur##*.}"
2062 __gitcomp "cmd path" "$pfx" "$cur_"
2066 local pfx="${cur%.*}." cur_="${cur##*.}"
2067 __gitcomp "cmd path" "$pfx" "$cur_"
2071 local pfx="${cur%.*}." cur_="${cur##*.}"
2072 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2076 local pfx="${cur%.*}." cur_="${cur#*.}"
2077 __git_compute_all_commands
2078 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2082 local pfx="${cur%.*}." cur_="${cur##*.}"
2084 url proxy fetch push mirror skipDefaultUpdate
2085 receivepack uploadpack tagopt pushurl
2090 local pfx="${cur%.*}." cur_="${cur#*.}"
2091 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2092 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2096 local pfx="${cur%.*}." cur_="${cur##*.}"
2097 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2103 advice.commitBeforeMerge
2105 advice.implicitIdentity
2106 advice.pushNonFastForward
2107 advice.resolveConflict
2111 apply.ignorewhitespace
2113 branch.autosetupmerge
2114 branch.autosetuprebase
2118 color.branch.current
2123 color.decorate.branch
2124 color.decorate.remoteBranch
2125 color.decorate.stash
2135 color.diff.whitespace
2140 color.grep.linenumber
2143 color.grep.separator
2145 color.interactive.error
2146 color.interactive.header
2147 color.interactive.help
2148 color.interactive.prompt
2153 color.status.changed
2155 color.status.nobranch
2156 color.status.unmerged
2157 color.status.untracked
2158 color.status.updated
2167 core.bigFileThreshold
2170 core.deltaBaseCacheLimit
2175 core.fsyncobjectfiles
2179 core.logAllRefUpdates
2180 core.loosecompression
2183 core.packedGitWindowSize
2185 core.preferSymlinkRefs
2188 core.repositoryFormatVersion
2190 core.sharedRepository
2195 core.warnAmbiguousRefs
2198 diff.autorefreshindex
2200 diff.ignoreSubmodules
2207 diff.suppressBlankEmpty
2213 fetch.recurseSubmodules
2224 format.subjectprefix
2235 gc.reflogexpireunreachable
2239 gitcvs.commitmsgannotation
2240 gitcvs.dbTableNamePrefix
2251 gui.copyblamethreshold
2255 gui.matchtrackingbranch
2256 gui.newbranchtemplate
2257 gui.pruneduringfetch
2258 gui.spellingdictionary
2275 http.sslCertPasswordProtected
2280 i18n.logOutputEncoding
2286 imap.preformattedHTML
2296 interactive.singlekey
2312 mergetool.keepBackup
2313 mergetool.keepTemporaries
2318 notes.rewrite.rebase
2322 pack.deltaCacheLimit
2339 receive.denyCurrentBranch
2340 receive.denyDeleteCurrent
2342 receive.denyNonFastForwards
2345 receive.updateserverinfo
2348 repack.usedeltabaseoffset
2352 sendemail.aliasesfile
2353 sendemail.aliasfiletype
2357 sendemail.chainreplyto
2359 sendemail.envelopesender
2363 sendemail.signedoffbycc
2364 sendemail.smtpdomain
2365 sendemail.smtpencryption
2367 sendemail.smtpserver
2368 sendemail.smtpserveroption
2369 sendemail.smtpserverport
2371 sendemail.suppresscc
2372 sendemail.suppressfrom
2377 status.relativePaths
2378 status.showUntrackedFiles
2379 status.submodulesummary
2382 transfer.unpackLimit
2394 local subcommands="add rename remove set-head set-branches set-url show prune update"
2395 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2396 if [ -z "$subcommand" ]; then
2397 __gitcomp "$subcommands"
2401 case "$subcommand" in
2402 rename|remove|set-url|show|prune)
2403 __gitcomp_nl "$(__git_remotes)"
2405 set-head|set-branches)
2406 __git_complete_remote_or_refspec
2409 __gitcomp "$(__git_get_config_variables "remotes")"
2418 __gitcomp_nl "$(__git_refs)"
2423 __git_has_doubledash && return
2427 __gitcomp "--merge --mixed --hard --soft --patch"
2431 __gitcomp_nl "$(__git_refs)"
2436 local dir="$(__gitdir)"
2437 if [ -f "$dir"/REVERT_HEAD ]; then
2438 __gitcomp "--continue --quit --abort"
2443 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2447 __gitcomp_nl "$(__git_refs)"
2454 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2459 __git_complete_index_file "--cached"
2464 __git_has_doubledash && return
2469 $__git_log_common_options
2470 $__git_log_shortlog_options
2471 --numbered --summary
2476 __git_complete_revlist
2481 __git_has_doubledash && return
2484 --pretty=*|--format=*)
2485 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2490 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2494 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2498 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2500 $__git_diff_common_options
2505 __git_complete_revlist_file
2513 --all --remotes --topo-order --date-order --current --more=
2514 --list --independent --merge-base --no-name
2516 --sha1-name --sparse --topics --reflog
2521 __git_complete_revlist
2526 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2527 local subcommands='save list show apply clear drop pop create branch'
2528 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2529 if [ -z "$subcommand" ]; then
2532 __gitcomp "$save_opts"
2535 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2536 __gitcomp "$subcommands"
2541 case "$subcommand,$cur" in
2543 __gitcomp "$save_opts"
2546 __gitcomp "--index --quiet"
2551 show,--*|branch,--*)
2554 if [ $cword -eq 3 ]; then
2555 __gitcomp_nl "$(__git_refs)";
2557 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2558 | sed -n -e 's/:.*//p')"
2561 show,*|apply,*|drop,*|pop,*)
2562 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2563 | sed -n -e 's/:.*//p')"
2573 __git_has_doubledash && return
2575 local subcommands="add status init deinit update summary foreach sync"
2576 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2579 __gitcomp "--quiet --cached"
2582 __gitcomp "$subcommands"
2592 init fetch clone rebase dcommit log find-rev
2593 set-tree commit-diff info create-ignore propget
2594 proplist show-ignore show-externals branch tag blame
2595 migrate mkdirs reset gc
2597 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2598 if [ -z "$subcommand" ]; then
2599 __gitcomp "$subcommands"
2601 local remote_opts="--username= --config-dir= --no-auth-cache"
2603 --follow-parent --authors-file= --repack=
2604 --no-metadata --use-svm-props --use-svnsync-props
2605 --log-window-size= --no-checkout --quiet
2606 --repack-flags --use-log-author --localtime
2607 --ignore-paths= --include-paths= $remote_opts
2610 --template= --shared= --trunk= --tags=
2611 --branches= --stdlayout --minimize-url
2612 --no-metadata --use-svm-props --use-svnsync-props
2613 --rewrite-root= --prefix= --use-log-author
2614 --add-author-from $remote_opts
2617 --edit --rmdir --find-copies-harder --copy-similarity=
2620 case "$subcommand,$cur" in
2622 __gitcomp "--revision= --fetch-all $fc_opts"
2625 __gitcomp "--revision= $fc_opts $init_opts"
2628 __gitcomp "$init_opts"
2632 --merge --strategy= --verbose --dry-run
2633 --fetch-all --no-rebase --commit-url
2634 --revision --interactive $cmt_opts $fc_opts
2638 __gitcomp "--stdin $cmt_opts $fc_opts"
2640 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2641 show-externals,--*|mkdirs,--*)
2642 __gitcomp "--revision="
2646 --limit= --revision= --verbose --incremental
2647 --oneline --show-commit --non-recursive
2648 --authors-file= --color
2653 --merge --verbose --strategy= --local
2654 --fetch-all --dry-run $fc_opts
2658 __gitcomp "--message= --file= --revision= $cmt_opts"
2664 __gitcomp "--dry-run --message --tag"
2667 __gitcomp "--dry-run --message"
2670 __gitcomp "--git-format"
2674 --config-dir= --ignore-paths= --minimize
2675 --no-auth-cache --username=
2679 __gitcomp "--revision= --parent"
2690 while [ $c -lt $cword ]; do
2694 __gitcomp_nl "$(__git_tags)"
2709 __gitcomp_nl "$(__git_tags)"
2713 __gitcomp_nl "$(__git_refs)"
2720 --list --delete --verify --annotate --message --file
2721 --sign --cleanup --local-user --force --column --sort
2722 --contains --points-at
2735 local subcommands="add list lock prune unlock"
2736 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2737 if [ -z "$subcommand" ]; then
2738 __gitcomp "$subcommands"
2740 case "$subcommand,$cur" in
2742 __gitcomp "--detach"
2745 __gitcomp "--porcelain"
2748 __gitcomp "--reason"
2751 __gitcomp "--dry-run --expire --verbose"
2761 local i c=1 command __git_dir
2763 while [ $c -lt $cword ]; do
2766 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2767 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2768 --bare) __git_dir="." ;;
2769 --help) command="help"; break ;;
2770 -c|--work-tree|--namespace) ((c++)) ;;
2772 *) command="$i"; break ;;
2777 if [ -z "$command" ]; then
2792 --no-replace-objects
2796 *) __git_compute_porcelain_commands
2797 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2802 local completion_func="_git_${command//-/_}"
2803 declare -f $completion_func >/dev/null && $completion_func && return
2805 local expansion=$(__git_aliased_command "$command")
2806 if [ -n "$expansion" ]; then
2808 completion_func="_git_${expansion//-/_}"
2809 declare -f $completion_func >/dev/null && $completion_func
2815 __git_has_doubledash && return
2817 local g="$(__gitdir)"
2819 if [ -f "$g/MERGE_HEAD" ]; then
2825 $__git_log_common_options
2826 $__git_log_gitk_options
2832 __git_complete_revlist
2835 if [[ -n ${ZSH_VERSION-} ]]; then
2836 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2838 autoload -U +X compinit && compinit
2844 local cur_="${3-$cur}"
2850 local c IFS=$' \t\n'
2858 array[${#array[@]}+1]="$c"
2861 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2872 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2881 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2886 local _ret=1 cur cword prev
2887 cur=${words[CURRENT]}
2888 prev=${words[CURRENT-1]}
2890 emulate ksh -c __${service}_main
2891 let _ret && _default && _ret=0
2895 compdef _git git gitk
2901 local cur words cword prev
2902 _get_comp_words_by_ref -n =: cur words cword prev
2906 # Setup completion for certain functions defined above by setting common
2907 # variables and workarounds.
2908 # This is NOT a public function; use at your own risk.
2911 local wrapper="__git_wrap${2}"
2912 eval "$wrapper () { __git_func_wrap $2 ; }"
2913 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2914 || complete -o default -o nospace -F $wrapper $1
2917 # wrapper for backwards compatibility
2920 __git_wrap__git_main
2923 # wrapper for backwards compatibility
2926 __git_wrap__gitk_main
2929 __git_complete git __git_main
2930 __git_complete gitk __gitk_main
2932 # The following are necessary only for Cygwin, and only are needed
2933 # when the user has tab-completed the executable name and consequently
2934 # included the '.exe' suffix.
2936 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2937 __git_complete git.exe __git_main