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
1004 --recount --directory=
1015 --interactive --refresh --patch --update --dry-run
1016 --ignore-errors --intent-to-add --force --edit --chmod=
1021 local complete_opt="--others --modified --directory --no-empty-directory"
1022 if test -n "$(__git_find_on_cmdline "-u --update")"
1024 complete_opt="--modified"
1026 __git_complete_index_file "$complete_opt"
1033 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1037 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1042 --format= --list --verbose
1043 --prefix= --remote= --exec= --output
1053 __git_has_doubledash && return
1055 local subcommands="start bad good skip reset visualize replay log run"
1056 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1057 if [ -z "$subcommand" ]; then
1058 __git_find_repo_path
1059 if [ -f "$__git_repo_path"/BISECT_START ]; then
1060 __gitcomp "$subcommands"
1062 __gitcomp "replay start"
1067 case "$subcommand" in
1068 bad|good|reset|skip|start)
1069 __gitcomp_nl "$(__git_refs)"
1078 local i c=1 only_local_ref="n" has_r="n"
1080 while [ $c -lt $cword ]; do
1083 -d|--delete|-m|--move) only_local_ref="y" ;;
1084 -r|--remotes) has_r="y" ;;
1090 --set-upstream-to=*)
1091 __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1095 --color --no-color --verbose --abbrev= --no-abbrev
1096 --track --no-track --contains --merged --no-merged
1097 --set-upstream-to= --edit-description --list
1098 --unset-upstream --delete --move --remotes
1099 --column --no-column --sort= --points-at
1103 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1104 __gitcomp_nl "$(__git_heads)"
1106 __gitcomp_nl "$(__git_refs)"
1114 local cmd="${words[2]}"
1117 __gitcomp "create list-heads verify unbundle"
1120 # looking for a file
1125 __git_complete_revlist
1134 __git_has_doubledash && return
1138 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1142 --quiet --ours --theirs --track --no-track --merge
1143 --conflict= --orphan --patch
1147 # check if --track, --no-track, or --no-guess was specified
1148 # if so, disable DWIM mode
1149 local flags="--track --no-track --no-guess" track=1
1150 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1153 __gitcomp_nl "$(__git_refs '' $track)"
1160 __gitcomp_nl "$(__git_refs)"
1165 __git_find_repo_path
1166 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1167 __gitcomp "--continue --quit --abort"
1172 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1175 __gitcomp_nl "$(__git_refs)"
1184 __gitcomp "--dry-run --quiet"
1189 # XXX should we check for -x option ?
1190 __git_complete_index_file "--others --directory"
1212 --recurse-submodules
1214 --shallow-submodules
1221 __git_untracked_file_modes="all no normal"
1227 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1234 __gitcomp "default scissors strip verbatim whitespace
1235 " "" "${cur##--cleanup=}"
1238 --reuse-message=*|--reedit-message=*|\
1239 --fixup=*|--squash=*)
1240 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1243 --untracked-files=*)
1244 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1249 --all --author= --signoff --verify --no-verify
1251 --amend --include --only --interactive
1252 --dry-run --reuse-message= --reedit-message=
1253 --reset-author --file= --message= --template=
1254 --cleanup= --untracked-files --untracked-files=
1255 --verbose --quiet --fixup= --squash=
1256 --patch --short --date --allow-empty
1261 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1262 __git_complete_index_file "--committable"
1264 # This is the first commit
1265 __git_complete_index_file "--cached"
1274 --all --tags --contains --abbrev= --candidates=
1275 --exact-match --debug --long --match --always --first-parent
1280 __gitcomp_nl "$(__git_refs)"
1283 __git_diff_algorithms="myers minimal patience histogram"
1285 __git_diff_submodule_formats="diff log short"
1287 __git_diff_common_options="--stat --numstat --shortstat --summary
1288 --patch-with-stat --name-only --name-status --color
1289 --no-color --color-words --no-renames --check
1290 --full-index --binary --abbrev --diff-filter=
1291 --find-copies-harder
1292 --text --ignore-space-at-eol --ignore-space-change
1293 --ignore-all-space --ignore-blank-lines --exit-code
1294 --quiet --ext-diff --no-ext-diff
1295 --no-prefix --src-prefix= --dst-prefix=
1296 --inter-hunk-context=
1297 --patience --histogram --minimal
1298 --raw --word-diff --word-diff-regex=
1299 --dirstat --dirstat= --dirstat-by-file
1300 --dirstat-by-file= --cumulative
1302 --submodule --submodule=
1307 __git_has_doubledash && return
1311 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1315 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1319 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1320 --base --ours --theirs --no-index
1321 $__git_diff_common_options
1326 __git_complete_revlist_file
1329 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1330 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1335 __git_has_doubledash && return
1339 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1343 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1344 --base --ours --theirs
1345 --no-renames --diff-filter= --find-copies-harder
1346 --relative --ignore-submodules
1351 __git_complete_revlist_file
1354 __git_fetch_recurse_submodules="yes on-demand no"
1356 __git_fetch_options="
1357 --quiet --verbose --append --upload-pack --force --keep --depth=
1358 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1359 --unshallow --update-shallow
1365 --recurse-submodules=*)
1366 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1370 __gitcomp "$__git_fetch_options"
1374 __git_complete_remote_or_refspec
1377 __git_format_patch_options="
1378 --stdout --attach --no-attach --thread --thread= --no-thread
1379 --numbered --start-number --numbered-files --keep-subject --signoff
1380 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1381 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1382 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1383 --output-directory --reroll-count --to= --quiet --notes
1386 _git_format_patch ()
1392 " "" "${cur##--thread=}"
1396 __gitcomp "$__git_format_patch_options"
1400 __git_complete_revlist
1408 --tags --root --unreachable --cache --no-reflogs --full
1409 --strict --verbose --lost-found --name-objects
1420 __gitcomp "--prune --aggressive"
1431 __git_match_ctag() {
1432 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1437 __git_has_doubledash && return
1443 --text --ignore-case --word-regexp --invert-match
1444 --full-name --line-number
1445 --extended-regexp --basic-regexp --fixed-strings
1448 --files-with-matches --name-only
1449 --files-without-match
1452 --and --or --not --all-match
1453 --break --heading --show-function --function-context
1454 --untracked --no-index
1460 case "$cword,$prev" in
1462 if test -r tags; then
1463 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1469 __gitcomp_nl "$(__git_refs)"
1476 __gitcomp "--all --guides --info --man --web"
1480 __git_compute_all_commands
1481 __gitcomp "$__git_all_commands $(__git_aliases)
1482 attributes cli core-tutorial cvs-migration
1483 diffcore everyday gitk glossary hooks ignore modules
1484 namespaces repository-layout revisions tutorial tutorial-2
1494 false true umask group all world everybody
1495 " "" "${cur##--shared=}"
1499 __gitcomp "--quiet --bare --template= --shared --shared="
1509 __gitcomp "--cached --deleted --modified --others --ignored
1510 --stage --directory --no-empty-directory --unmerged
1511 --killed --exclude= --exclude-from=
1512 --exclude-per-directory= --exclude-standard
1513 --error-unmatch --with-tree= --full-name
1514 --abbrev --ignored --exclude-per-directory
1520 # XXX ignore options like --modified and always suggest all cached
1522 __git_complete_index_file "--cached"
1529 __gitcomp "--heads --tags --refs --get-url --symref"
1533 __gitcomp_nl "$(__git_remotes)"
1541 # Options that go well for log, shortlog and gitk
1542 __git_log_common_options="
1544 --branches --tags --remotes
1545 --first-parent --merges --no-merges
1547 --max-age= --since= --after=
1548 --min-age= --until= --before=
1549 --min-parents= --max-parents=
1550 --no-min-parents --no-max-parents
1552 # Options that go well for log and gitk (not shortlog)
1553 __git_log_gitk_options="
1554 --dense --sparse --full-history
1555 --simplify-merges --simplify-by-decoration
1556 --left-right --notes --no-notes
1558 # Options that go well for log and shortlog (not gitk)
1559 __git_log_shortlog_options="
1560 --author= --committer= --grep=
1561 --all-match --invert-grep
1564 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1565 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1569 __git_has_doubledash && return
1570 __git_find_repo_path
1573 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1577 --pretty=*|--format=*)
1578 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1583 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1587 __gitcomp "full short no" "" "${cur##--decorate=}"
1591 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1595 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1600 $__git_log_common_options
1601 $__git_log_shortlog_options
1602 $__git_log_gitk_options
1603 --root --topo-order --date-order --reverse
1604 --follow --full-diff
1605 --abbrev-commit --abbrev=
1606 --relative-date --date=
1607 --pretty= --format= --oneline
1612 --decorate --decorate=
1614 --parents --children
1616 $__git_diff_common_options
1617 --pickaxe-all --pickaxe-regex
1622 __git_complete_revlist
1625 # Common merge options shared by git-merge(1) and git-pull(1).
1626 __git_merge_options="
1627 --no-commit --no-stat --log --no-log --squash --strategy
1628 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1629 --verify-signatures --no-verify-signatures --gpg-sign
1630 --quiet --verbose --progress --no-progress
1635 __git_complete_strategy && return
1639 __gitcomp "$__git_merge_options
1640 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1643 __gitcomp_nl "$(__git_refs)"
1650 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1654 __gitcomp "--tool= --prompt --no-prompt"
1664 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1668 __gitcomp_nl "$(__git_refs)"
1675 __gitcomp "--dry-run"
1680 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1681 # We need to show both cached and untracked files (including
1682 # empty directories) since this may not be the last argument.
1683 __git_complete_index_file "--cached --others --directory"
1685 __git_complete_index_file "--cached"
1691 __gitcomp "--tags --all --stdin"
1696 local subcommands='add append copy edit list prune remove show'
1697 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1699 case "$subcommand,$cur" in
1706 __gitcomp_nl "$(__git_refs)"
1709 __gitcomp "$subcommands --ref"
1713 add,--reuse-message=*|append,--reuse-message=*|\
1714 add,--reedit-message=*|append,--reedit-message=*)
1715 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1718 __gitcomp '--file= --message= --reedit-message=
1725 __gitcomp '--dry-run --verbose'
1734 __gitcomp_nl "$(__git_refs)"
1743 __git_complete_strategy && return
1746 --recurse-submodules=*)
1747 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1752 --rebase --no-rebase
1753 $__git_merge_options
1754 $__git_fetch_options
1759 __git_complete_remote_or_refspec
1762 __git_push_recurse_submodules="check on-demand only"
1764 __git_complete_force_with_lease ()
1772 __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
1775 __gitcomp_nl "$(__git_refs)" "" "$cur_"
1784 __gitcomp_nl "$(__git_remotes)"
1787 --recurse-submodules)
1788 __gitcomp "$__git_push_recurse_submodules"
1794 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1797 --recurse-submodules=*)
1798 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1801 --force-with-lease=*)
1802 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1807 --all --mirror --tags --dry-run --force --verbose
1808 --quiet --prune --delete --follow-tags
1809 --receive-pack= --repo= --set-upstream
1810 --force-with-lease --force-with-lease= --recurse-submodules=
1815 __git_complete_remote_or_refspec
1820 __git_find_repo_path
1821 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
1822 __gitcomp "--continue --skip --abort --quit --edit-todo"
1824 elif [ -d "$__git_repo_path"/rebase-apply ] || \
1825 [ -d "$__git_repo_path"/rebase-merge ]; then
1826 __gitcomp "--continue --skip --abort --quit"
1829 __git_complete_strategy && return
1832 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1837 --onto --merge --strategy --interactive
1838 --preserve-merges --stat --no-stat
1839 --committer-date-is-author-date --ignore-date
1840 --ignore-whitespace --whitespace=
1841 --autosquash --no-autosquash
1842 --fork-point --no-fork-point
1843 --autostash --no-autostash
1844 --verify --no-verify
1845 --keep-empty --root --force-rebase --no-ff
1851 __gitcomp_nl "$(__git_refs)"
1856 local subcommands="show delete expire"
1857 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1859 if [ -z "$subcommand" ]; then
1860 __gitcomp "$subcommands"
1862 __gitcomp_nl "$(__git_refs)"
1866 __git_send_email_confirm_options="always never auto cc compose"
1867 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1872 --to|--cc|--bcc|--from)
1873 __gitcomp "$(__git send-email --dump-aliases)"
1881 $__git_send_email_confirm_options
1882 " "" "${cur##--confirm=}"
1887 $__git_send_email_suppresscc_options
1888 " "" "${cur##--suppress-cc=}"
1892 --smtp-encryption=*)
1893 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1899 " "" "${cur##--thread=}"
1902 --to=*|--cc=*|--bcc=*|--from=*)
1903 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
1907 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1908 --compose --confirm= --dry-run --envelope-sender
1910 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1911 --no-suppress-from --no-thread --quiet
1912 --signed-off-by-cc --smtp-pass --smtp-server
1913 --smtp-server-port --smtp-encryption= --smtp-user
1914 --subject --suppress-cc= --suppress-from --thread --to
1915 --validate --no-validate
1916 $__git_format_patch_options"
1920 __git_complete_revlist
1931 local untracked_state
1934 --ignore-submodules=*)
1935 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1938 --untracked-files=*)
1939 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1944 always never auto column row plain dense nodense
1945 " "" "${cur##--column=}"
1950 --short --branch --porcelain --long --verbose
1951 --untracked-files= --ignore-submodules= --ignored
1952 --column= --no-column
1958 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1959 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
1961 case "$untracked_state" in
1963 # --ignored option does not matter
1967 complete_opt="--cached --directory --no-empty-directory --others"
1969 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1970 complete_opt="$complete_opt --ignored --exclude=*"
1975 __git_complete_index_file "$complete_opt"
1978 __git_config_get_set_variables ()
1980 local prevword word config_file= c=$cword
1981 while [ $c -gt 1 ]; do
1984 --system|--global|--local|--file=*)
1989 config_file="$word $prevword"
1997 __git config $config_file --name-only --list
2003 branch.*.remote|branch.*.pushremote)
2004 __gitcomp_nl "$(__git_remotes)"
2008 __gitcomp_nl "$(__git_refs)"
2012 __gitcomp "false true preserve interactive"
2016 __gitcomp_nl "$(__git_remotes)"
2020 local remote="${prev#remote.}"
2021 remote="${remote%.fetch}"
2022 if [ -z "$cur" ]; then
2023 __gitcomp_nl "refs/heads/" "" "" ""
2026 __gitcomp_nl "$(__git_refs_remotes "$remote")"
2030 local remote="${prev#remote.}"
2031 remote="${remote%.push}"
2032 __gitcomp_nl "$(__git for-each-ref \
2033 --format='%(refname):%(refname)' refs/heads)"
2036 pull.twohead|pull.octopus)
2037 __git_compute_merge_strategies
2038 __gitcomp "$__git_merge_strategies"
2041 color.branch|color.diff|color.interactive|\
2042 color.showbranch|color.status|color.ui)
2043 __gitcomp "always never auto"
2047 __gitcomp "false true"
2052 normal black red green yellow blue magenta cyan white
2053 bold dim ul blink reverse
2058 __gitcomp "log short"
2062 __gitcomp "man info web html"
2066 __gitcomp "$__git_log_date_formats"
2069 sendemail.aliasesfiletype)
2070 __gitcomp "mutt mailrc pine elm gnus"
2074 __gitcomp "$__git_send_email_confirm_options"
2077 sendemail.suppresscc)
2078 __gitcomp "$__git_send_email_suppresscc_options"
2081 sendemail.transferencoding)
2082 __gitcomp "7bit 8bit quoted-printable base64"
2085 --get|--get-all|--unset|--unset-all)
2086 __gitcomp_nl "$(__git_config_get_set_variables)"
2096 --system --global --local --file=
2097 --list --replace-all
2098 --get --get-all --get-regexp
2099 --add --unset --unset-all
2100 --remove-section --rename-section
2106 local pfx="${cur%.*}." cur_="${cur##*.}"
2107 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2111 local pfx="${cur%.*}." cur_="${cur#*.}"
2112 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
2113 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2117 local pfx="${cur%.*}." cur_="${cur##*.}"
2119 argprompt cmd confirm needsfile noconsole norescan
2120 prompt revprompt revunmerged title
2125 local pfx="${cur%.*}." cur_="${cur##*.}"
2126 __gitcomp "cmd path" "$pfx" "$cur_"
2130 local pfx="${cur%.*}." cur_="${cur##*.}"
2131 __gitcomp "cmd path" "$pfx" "$cur_"
2135 local pfx="${cur%.*}." cur_="${cur##*.}"
2136 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2140 local pfx="${cur%.*}." cur_="${cur#*.}"
2141 __git_compute_all_commands
2142 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2146 local pfx="${cur%.*}." cur_="${cur##*.}"
2148 url proxy fetch push mirror skipDefaultUpdate
2149 receivepack uploadpack tagopt pushurl
2154 local pfx="${cur%.*}." cur_="${cur#*.}"
2155 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2156 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2160 local pfx="${cur%.*}." cur_="${cur##*.}"
2161 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2167 advice.commitBeforeMerge
2169 advice.implicitIdentity
2170 advice.pushNonFastForward
2171 advice.resolveConflict
2175 apply.ignorewhitespace
2177 branch.autosetupmerge
2178 branch.autosetuprebase
2182 color.branch.current
2187 color.decorate.branch
2188 color.decorate.remoteBranch
2189 color.decorate.stash
2199 color.diff.whitespace
2204 color.grep.linenumber
2207 color.grep.separator
2209 color.interactive.error
2210 color.interactive.header
2211 color.interactive.help
2212 color.interactive.prompt
2217 color.status.changed
2219 color.status.nobranch
2220 color.status.unmerged
2221 color.status.untracked
2222 color.status.updated
2231 core.bigFileThreshold
2234 core.deltaBaseCacheLimit
2239 core.fsyncobjectfiles
2243 core.logAllRefUpdates
2244 core.loosecompression
2247 core.packedGitWindowSize
2249 core.preferSymlinkRefs
2252 core.repositoryFormatVersion
2254 core.sharedRepository
2259 core.warnAmbiguousRefs
2262 diff.autorefreshindex
2264 diff.ignoreSubmodules
2271 diff.suppressBlankEmpty
2277 fetch.recurseSubmodules
2288 format.subjectprefix
2299 gc.reflogexpireunreachable
2303 gitcvs.commitmsgannotation
2304 gitcvs.dbTableNamePrefix
2315 gui.copyblamethreshold
2319 gui.matchtrackingbranch
2320 gui.newbranchtemplate
2321 gui.pruneduringfetch
2322 gui.spellingdictionary
2339 http.sslCertPasswordProtected
2344 i18n.logOutputEncoding
2350 imap.preformattedHTML
2360 interactive.singlekey
2376 mergetool.keepBackup
2377 mergetool.keepTemporaries
2382 notes.rewrite.rebase
2386 pack.deltaCacheLimit
2403 receive.denyCurrentBranch
2404 receive.denyDeleteCurrent
2406 receive.denyNonFastForwards
2409 receive.updateserverinfo
2412 repack.usedeltabaseoffset
2416 sendemail.aliasesfile
2417 sendemail.aliasfiletype
2421 sendemail.chainreplyto
2423 sendemail.envelopesender
2427 sendemail.signedoffbycc
2428 sendemail.smtpdomain
2429 sendemail.smtpencryption
2431 sendemail.smtpserver
2432 sendemail.smtpserveroption
2433 sendemail.smtpserverport
2435 sendemail.suppresscc
2436 sendemail.suppressfrom
2441 status.relativePaths
2442 status.showUntrackedFiles
2443 status.submodulesummary
2446 transfer.unpackLimit
2459 add rename remove set-head set-branches
2460 get-url set-url show prune update
2462 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2463 if [ -z "$subcommand" ]; then
2466 __gitcomp "--verbose"
2469 __gitcomp "$subcommands"
2475 case "$subcommand,$cur" in
2477 __gitcomp "--track --master --fetch --tags --no-tags --mirror="
2482 __gitcomp "--auto --delete"
2487 set-head,*|set-branches,*)
2488 __git_complete_remote_or_refspec
2494 __gitcomp "$(__git_get_config_variables "remotes")"
2497 __gitcomp "--push --add --delete"
2500 __gitcomp "--push --all"
2503 __gitcomp "--dry-run"
2506 __gitcomp_nl "$(__git_remotes)"
2515 __gitcomp "--edit --graft --format= --list --delete"
2519 __gitcomp_nl "$(__git_refs)"
2524 local subcommands="clear forget diff remaining status gc"
2525 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2526 if test -z "$subcommand"
2528 __gitcomp "$subcommands"
2535 __git_has_doubledash && return
2539 __gitcomp "--merge --mixed --hard --soft --patch --keep"
2543 __gitcomp_nl "$(__git_refs)"
2548 __git_find_repo_path
2549 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2550 __gitcomp "--continue --quit --abort"
2556 --edit --mainline --no-edit --no-commit --signoff
2557 --strategy= --strategy-option=
2562 __gitcomp_nl "$(__git_refs)"
2569 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2574 __git_complete_index_file "--cached"
2579 __git_has_doubledash && return
2584 $__git_log_common_options
2585 $__git_log_shortlog_options
2586 --numbered --summary --email
2591 __git_complete_revlist
2596 __git_has_doubledash && return
2599 --pretty=*|--format=*)
2600 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2605 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2609 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2613 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2615 $__git_diff_common_options
2620 __git_complete_revlist_file
2628 --all --remotes --topo-order --date-order --current --more=
2629 --list --independent --merge-base --no-name
2631 --sha1-name --sparse --topics --reflog
2636 __git_complete_revlist
2641 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2642 local subcommands='save list show apply clear drop pop create branch'
2643 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2644 if [ -z "$subcommand" ]; then
2647 __gitcomp "$save_opts"
2650 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2651 __gitcomp "$subcommands"
2656 case "$subcommand,$cur" in
2658 __gitcomp "$save_opts"
2661 __gitcomp "--index --quiet"
2666 show,--*|branch,--*)
2669 if [ $cword -eq 3 ]; then
2670 __gitcomp_nl "$(__git_refs)";
2672 __gitcomp_nl "$(__git stash list \
2673 | sed -n -e 's/:.*//p')"
2676 show,*|apply,*|drop,*|pop,*)
2677 __gitcomp_nl "$(__git stash list \
2678 | sed -n -e 's/:.*//p')"
2688 __git_has_doubledash && return
2690 local subcommands="add status init deinit update summary foreach sync"
2691 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2692 if [ -z "$subcommand" ]; then
2698 __gitcomp "$subcommands"
2704 case "$subcommand,$cur" in
2706 __gitcomp "--branch --force --name --reference --depth"
2709 __gitcomp "--cached --recursive"
2712 __gitcomp "--force --all"
2716 --init --remote --no-fetch
2717 --recommend-shallow --no-recommend-shallow
2718 --force --rebase --merge --reference --depth --recursive --jobs
2722 __gitcomp "--cached --files --summary-limit"
2724 foreach,--*|sync,--*)
2725 __gitcomp "--recursive"
2735 init fetch clone rebase dcommit log find-rev
2736 set-tree commit-diff info create-ignore propget
2737 proplist show-ignore show-externals branch tag blame
2738 migrate mkdirs reset gc
2740 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2741 if [ -z "$subcommand" ]; then
2742 __gitcomp "$subcommands"
2744 local remote_opts="--username= --config-dir= --no-auth-cache"
2746 --follow-parent --authors-file= --repack=
2747 --no-metadata --use-svm-props --use-svnsync-props
2748 --log-window-size= --no-checkout --quiet
2749 --repack-flags --use-log-author --localtime
2751 --ignore-paths= --include-paths= $remote_opts
2754 --template= --shared= --trunk= --tags=
2755 --branches= --stdlayout --minimize-url
2756 --no-metadata --use-svm-props --use-svnsync-props
2757 --rewrite-root= --prefix= $remote_opts
2760 --edit --rmdir --find-copies-harder --copy-similarity=
2763 case "$subcommand,$cur" in
2765 __gitcomp "--revision= --fetch-all $fc_opts"
2768 __gitcomp "--revision= $fc_opts $init_opts"
2771 __gitcomp "$init_opts"
2775 --merge --strategy= --verbose --dry-run
2776 --fetch-all --no-rebase --commit-url
2777 --revision --interactive $cmt_opts $fc_opts
2781 __gitcomp "--stdin $cmt_opts $fc_opts"
2783 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2784 show-externals,--*|mkdirs,--*)
2785 __gitcomp "--revision="
2789 --limit= --revision= --verbose --incremental
2790 --oneline --show-commit --non-recursive
2791 --authors-file= --color
2796 --merge --verbose --strategy= --local
2797 --fetch-all --dry-run $fc_opts
2801 __gitcomp "--message= --file= --revision= $cmt_opts"
2807 __gitcomp "--dry-run --message --tag"
2810 __gitcomp "--dry-run --message"
2813 __gitcomp "--git-format"
2817 --config-dir= --ignore-paths= --minimize
2818 --no-auth-cache --username=
2822 __gitcomp "--revision= --parent"
2833 while [ $c -lt $cword ]; do
2837 __gitcomp_nl "$(__git_tags)"
2852 __gitcomp_nl "$(__git_tags)"
2856 __gitcomp_nl "$(__git_refs)"
2863 --list --delete --verify --annotate --message --file
2864 --sign --cleanup --local-user --force --column --sort=
2865 --contains --points-at --merged --no-merged --create-reflog
2878 local subcommands="add list lock prune unlock"
2879 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2880 if [ -z "$subcommand" ]; then
2881 __gitcomp "$subcommands"
2883 case "$subcommand,$cur" in
2885 __gitcomp "--detach"
2888 __gitcomp "--porcelain"
2891 __gitcomp "--reason"
2894 __gitcomp "--dry-run --expire --verbose"
2904 local i c=1 command __git_dir __git_repo_path
2905 local __git_C_args C_args_count=0
2907 while [ $c -lt $cword ]; do
2910 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2911 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2912 --bare) __git_dir="." ;;
2913 --help) command="help"; break ;;
2914 -c|--work-tree|--namespace) ((c++)) ;;
2915 -C) __git_C_args[C_args_count++]=-C
2917 __git_C_args[C_args_count++]="${words[c]}"
2920 *) command="$i"; break ;;
2925 if [ -z "$command" ]; then
2927 --git-dir|-C|--work-tree)
2928 # these need a path argument, let's fall back to
2929 # Bash filename completion
2933 # we don't support completing these options' arguments
2951 --no-replace-objects
2955 *) __git_compute_porcelain_commands
2956 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2961 local completion_func="_git_${command//-/_}"
2962 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return
2964 local expansion=$(__git_aliased_command "$command")
2965 if [ -n "$expansion" ]; then
2967 completion_func="_git_${expansion//-/_}"
2968 declare -f $completion_func >/dev/null 2>/dev/null && $completion_func
2974 __git_has_doubledash && return
2976 local __git_repo_path
2977 __git_find_repo_path
2980 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
2986 $__git_log_common_options
2987 $__git_log_gitk_options
2993 __git_complete_revlist
2996 if [[ -n ${ZSH_VERSION-} ]]; then
2997 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2999 autoload -U +X compinit && compinit
3005 local cur_="${3-$cur}"
3011 local c IFS=$' \t\n'
3019 array[${#array[@]}+1]="$c"
3022 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
3033 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
3042 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
3047 local _ret=1 cur cword prev
3048 cur=${words[CURRENT]}
3049 prev=${words[CURRENT-1]}
3051 emulate ksh -c __${service}_main
3052 let _ret && _default && _ret=0
3056 compdef _git git gitk
3062 local cur words cword prev
3063 _get_comp_words_by_ref -n =: cur words cword prev
3067 # Setup completion for certain functions defined above by setting common
3068 # variables and workarounds.
3069 # This is NOT a public function; use at your own risk.
3072 local wrapper="__git_wrap${2}"
3073 eval "$wrapper () { __git_func_wrap $2 ; }"
3074 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3075 || complete -o default -o nospace -F $wrapper $1
3078 # wrapper for backwards compatibility
3081 __git_wrap__git_main
3084 # wrapper for backwards compatibility
3087 __git_wrap__gitk_main
3090 __git_complete git __git_main
3091 __git_complete gitk __gitk_main
3093 # The following are necessary only for Cygwin, and only are needed
3094 # when the user has tab-completed the executable name and consequently
3095 # included the '.exe' suffix.
3097 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
3098 __git_complete git.exe __git_main