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 # Can be the name of a configured remote, a path, or a URL.
342 # 2: In addition to local refs, list unique branches from refs/remotes/ for
343 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
346 local i hash dir="$(__gitdir)" track="${2-}"
347 local list_refs_from=path remote="${1-}"
348 local format refs pfx
350 if [ -z "$remote" ]; then
351 if [ -z "$dir" ]; then
355 if __git_is_configured_remote "$remote"; then
356 # configured remote takes precedence over a
357 # local directory with the same name
358 list_refs_from=remote
359 elif [ -d "$remote/.git" ]; then
361 elif [ -d "$remote" ]; then
368 if [ "$list_refs_from" = path ]; then
376 [[ "$cur" == ^* ]] && pfx="^"
377 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
378 if [ -e "$dir/$i" ]; then echo $pfx$i; fi
380 format="refname:short"
381 refs="refs/tags refs/heads refs/remotes"
384 git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \
386 if [ -n "$track" ]; then
387 # employ the heuristic used by git checkout
388 # Try to find a remote branch that matches the completion word
389 # but only output if the branch name is unique
391 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
393 while read -r entry; do
396 if [[ "$ref" == "$cur"* ]]; then
399 done | sort | uniq -u
405 git --git-dir="$dir" ls-remote "$remote" "$cur*" 2>/dev/null | \
406 while read -r hash i; do
414 if [ "$list_refs_from" = remote ]; then
416 git --git-dir="$dir" for-each-ref --format="%(refname:short)" \
417 "refs/remotes/$remote/" 2>/dev/null | sed -e "s#^$remote/##"
419 git --git-dir="$dir" ls-remote "$remote" HEAD \
420 "refs/tags/*" "refs/heads/*" "refs/remotes/*" 2>/dev/null |
421 while read -r hash i; do
424 refs/*) echo "${i#refs/*/}" ;;
425 *) echo "$i" ;; # symbolic refs
433 # __git_refs2 requires 1 argument (to pass to __git_refs)
437 for i in $(__git_refs "$1"); do
442 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
443 __git_refs_remotes ()
446 git --git-dir="$(__gitdir)" ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
447 while read -r hash i; do
448 echo "$i:refs/remotes/$1/${i#refs/heads/}"
454 local d="$(__gitdir)"
455 test -d "$d/remotes" && ls -1 "$d/remotes"
456 git --git-dir="$d" remote
459 # Returns true if $1 matches the name of a configured remote, false otherwise.
460 __git_is_configured_remote ()
463 for remote in $(__git_remotes); do
464 if [ "$remote" = "$1" ]; then
471 __git_list_merge_strategies ()
473 git merge -s help 2>&1 |
474 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
483 __git_merge_strategies=
484 # 'git merge -s help' (and thus detection of the merge strategy
485 # list) fails, unfortunately, if run outside of any git working
486 # tree. __git_merge_strategies is set to the empty string in
487 # that case, and the detection will be repeated the next time it
489 __git_compute_merge_strategies ()
491 test -n "$__git_merge_strategies" ||
492 __git_merge_strategies=$(__git_list_merge_strategies)
495 __git_complete_revlist_file ()
497 local pfx ls ref cur_="$cur"
517 case "$COMP_WORDBREAKS" in
519 *) pfx="$ref:$pfx" ;;
522 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
523 | sed '/^100... blob /{
539 pfx="${cur_%...*}..."
541 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
546 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
549 __gitcomp_nl "$(__git_refs)"
555 # __git_complete_index_file requires 1 argument:
556 # 1: the options to pass to ls-file
558 # The exception is --committable, which finds the files appropriate commit.
559 __git_complete_index_file ()
561 local pfx="" cur_="$cur"
571 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
574 __git_complete_file ()
576 __git_complete_revlist_file
579 __git_complete_revlist ()
581 __git_complete_revlist_file
584 __git_complete_remote_or_refspec ()
586 local cur_="$cur" cmd="${words[1]}"
587 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
588 if [ "$cmd" = "remote" ]; then
591 while [ $c -lt $cword ]; do
594 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
597 push) no_complete_refspec=1 ;;
605 *) remote="$i"; break ;;
609 if [ -z "$remote" ]; then
610 __gitcomp_nl "$(__git_remotes)"
613 if [ $no_complete_refspec = 1 ]; then
616 [ "$remote" = "." ] && remote=
619 case "$COMP_WORDBREAKS" in
621 *) pfx="${cur_%%:*}:" ;;
633 if [ $lhs = 1 ]; then
634 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
636 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
640 if [ $lhs = 1 ]; then
641 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
643 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
647 if [ $lhs = 1 ]; then
648 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
650 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
656 __git_complete_strategy ()
658 __git_compute_merge_strategies
661 __gitcomp "$__git_merge_strategies"
666 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
674 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
676 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
678 git help -a|egrep '^ [a-zA-Z0-9]'
682 __git_list_all_commands ()
685 for i in $(__git_commands)
688 *--*) : helper pattern;;
695 __git_compute_all_commands ()
697 test -n "$__git_all_commands" ||
698 __git_all_commands=$(__git_list_all_commands)
701 __git_list_porcelain_commands ()
704 __git_compute_all_commands
705 for i in $__git_all_commands
708 *--*) : helper pattern;;
709 applymbox) : ask gittus;;
710 applypatch) : ask gittus;;
711 archimport) : import;;
712 cat-file) : plumbing;;
713 check-attr) : plumbing;;
714 check-ignore) : plumbing;;
715 check-mailmap) : plumbing;;
716 check-ref-format) : plumbing;;
717 checkout-index) : plumbing;;
718 column) : internal helper;;
719 commit-tree) : plumbing;;
720 count-objects) : infrequent;;
721 credential) : credentials;;
722 credential-*) : credentials helper;;
723 cvsexportcommit) : export;;
724 cvsimport) : import;;
725 cvsserver) : daemon;;
727 diff-files) : plumbing;;
728 diff-index) : plumbing;;
729 diff-tree) : plumbing;;
730 fast-import) : import;;
731 fast-export) : export;;
732 fsck-objects) : plumbing;;
733 fetch-pack) : plumbing;;
734 fmt-merge-msg) : plumbing;;
735 for-each-ref) : plumbing;;
736 hash-object) : plumbing;;
737 http-*) : transport;;
738 index-pack) : plumbing;;
739 init-db) : deprecated;;
740 local-fetch) : plumbing;;
741 ls-files) : plumbing;;
742 ls-remote) : plumbing;;
743 ls-tree) : plumbing;;
744 mailinfo) : plumbing;;
745 mailsplit) : plumbing;;
746 merge-*) : plumbing;;
749 pack-objects) : plumbing;;
750 pack-redundant) : plumbing;;
751 pack-refs) : plumbing;;
752 parse-remote) : plumbing;;
753 patch-id) : plumbing;;
755 prune-packed) : plumbing;;
756 quiltimport) : import;;
757 read-tree) : plumbing;;
758 receive-pack) : plumbing;;
759 remote-*) : transport;;
761 rev-list) : plumbing;;
762 rev-parse) : plumbing;;
763 runstatus) : plumbing;;
764 sh-setup) : internal;;
766 show-ref) : plumbing;;
767 send-pack) : plumbing;;
768 show-index) : plumbing;;
770 stripspace) : plumbing;;
771 symbolic-ref) : plumbing;;
772 unpack-file) : plumbing;;
773 unpack-objects) : plumbing;;
774 update-index) : plumbing;;
775 update-ref) : plumbing;;
776 update-server-info) : daemon;;
777 upload-archive) : plumbing;;
778 upload-pack) : plumbing;;
779 write-tree) : plumbing;;
781 verify-pack) : infrequent;;
782 verify-tag) : plumbing;;
788 __git_porcelain_commands=
789 __git_compute_porcelain_commands ()
791 test -n "$__git_porcelain_commands" ||
792 __git_porcelain_commands=$(__git_list_porcelain_commands)
795 # Lists all set config variables starting with the given section prefix,
796 # with the prefix removed.
797 __git_get_config_variables ()
799 local section="$1" i IFS=$'\n'
800 for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
801 echo "${i#$section.}"
805 __git_pretty_aliases ()
807 __git_get_config_variables "pretty"
812 __git_get_config_variables "alias"
815 # __git_aliased_command requires 1 argument
816 __git_aliased_command ()
818 local word cmdline=$(git --git-dir="$(__gitdir)" \
819 config --get "alias.$1")
820 for word in $cmdline; do
826 \!*) : shell command alias ;;
828 *=*) : setting env ;;
830 \(\)) : skip parens of shell function definition ;;
831 {) : skip start of shell helper function ;;
832 :) : skip null command ;;
833 \'*) : skip opening quote after sh -c ;;
841 # __git_find_on_cmdline requires 1 argument
842 __git_find_on_cmdline ()
844 local word subcommand c=1
845 while [ $c -lt $cword ]; do
847 for subcommand in $1; do
848 if [ "$subcommand" = "$word" ]; then
857 # Echo the value of an option set on the command line or config
859 # $1: short option name
860 # $2: long option name including =
861 # $3: list of possible values
862 # $4: config string (optional)
865 # result="$(__git_get_option_value "-d" "--do-something=" \
866 # "yes no" "core.doSomething")"
868 # result is then either empty (no option set) or "yes" or "no"
870 # __git_get_option_value requires 3 arguments
871 __git_get_option_value ()
873 local c short_opt long_opt val
874 local result= values config_key word
882 while [ $c -ge 0 ]; do
884 for val in $values; do
885 if [ "$short_opt$val" = "$word" ] ||
886 [ "$long_opt$val" = "$word" ]; then
894 if [ -n "$config_key" ] && [ -z "$result" ]; then
895 result="$(git --git-dir="$(__gitdir)" config "$config_key")"
901 __git_has_doubledash ()
904 while [ $c -lt $cword ]; do
905 if [ "--" = "${words[c]}" ]; then
913 # Try to count non option arguments passed on the command line for the
914 # specified git command.
915 # When options are used, it is necessary to use the special -- option to
916 # tell the implementation were non option arguments begin.
917 # XXX this can not be improved, since options can appear everywhere, as
921 # __git_count_arguments requires 1 argument: the git command executed.
922 __git_count_arguments ()
926 # Skip "git" (first argument)
927 for ((i=1; i < ${#words[@]}; i++)); do
932 # Good; we can assume that the following are only non
937 # Skip the specified git command and discard git
950 __git_whitespacelist="nowarn warn error error-all fix"
954 local dir="$(__gitdir)"
955 if [ -d "$dir"/rebase-apply ]; then
956 __gitcomp "--skip --continue --resolved --abort"
961 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
966 --3way --committer-date-is-author-date --ignore-date
967 --ignore-whitespace --ignore-space-change
968 --interactive --keep --no-utf8 --signoff --utf8
969 --whitespace= --scissors
979 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
984 --stat --numstat --summary --check --index
985 --cached --index-info --reverse --reject --unidiff-zero
986 --apply --no-add --exclude=
987 --ignore-whitespace --ignore-space-change
988 --whitespace= --inaccurate-eof --verbose
999 --interactive --refresh --patch --update --dry-run
1000 --ignore-errors --intent-to-add
1005 # XXX should we check for --update and --all options ?
1006 __git_complete_index_file "--others --modified --directory --no-empty-directory"
1013 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1017 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1022 --format= --list --verbose
1023 --prefix= --remote= --exec=
1033 __git_has_doubledash && return
1035 local subcommands="start bad good skip reset visualize replay log run"
1036 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1037 if [ -z "$subcommand" ]; then
1038 if [ -f "$(__gitdir)"/BISECT_START ]; then
1039 __gitcomp "$subcommands"
1041 __gitcomp "replay start"
1046 case "$subcommand" in
1047 bad|good|reset|skip|start)
1048 __gitcomp_nl "$(__git_refs)"
1057 local i c=1 only_local_ref="n" has_r="n"
1059 while [ $c -lt $cword ]; do
1062 -d|--delete|-m|--move) only_local_ref="y" ;;
1063 -r|--remotes) has_r="y" ;;
1069 --set-upstream-to=*)
1070 __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1074 --color --no-color --verbose --abbrev= --no-abbrev
1075 --track --no-track --contains --merged --no-merged
1076 --set-upstream-to= --edit-description --list
1077 --unset-upstream --delete --move --remotes
1081 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1082 __gitcomp_nl "$(__git_heads)"
1084 __gitcomp_nl "$(__git_refs)"
1092 local cmd="${words[2]}"
1095 __gitcomp "create list-heads verify unbundle"
1098 # looking for a file
1103 __git_complete_revlist
1112 __git_has_doubledash && return
1116 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1120 --quiet --ours --theirs --track --no-track --merge
1121 --conflict= --orphan --patch
1125 # check if --track, --no-track, or --no-guess was specified
1126 # if so, disable DWIM mode
1127 local flags="--track --no-track --no-guess" track=1
1128 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1131 __gitcomp_nl "$(__git_refs '' $track)"
1138 __gitcomp_nl "$(__git_refs)"
1143 local dir="$(__gitdir)"
1144 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1145 __gitcomp "--continue --quit --abort"
1150 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1153 __gitcomp_nl "$(__git_refs)"
1162 __gitcomp "--dry-run --quiet"
1167 # XXX should we check for -x option ?
1168 __git_complete_index_file "--others --directory"
1190 --recurse-submodules
1197 __git_untracked_file_modes="all no normal"
1203 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1210 __gitcomp "default scissors strip verbatim whitespace
1211 " "" "${cur##--cleanup=}"
1214 --reuse-message=*|--reedit-message=*|\
1215 --fixup=*|--squash=*)
1216 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1219 --untracked-files=*)
1220 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1225 --all --author= --signoff --verify --no-verify
1227 --amend --include --only --interactive
1228 --dry-run --reuse-message= --reedit-message=
1229 --reset-author --file= --message= --template=
1230 --cleanup= --untracked-files --untracked-files=
1231 --verbose --quiet --fixup= --squash=
1236 if git --git-dir="$(__gitdir)" rev-parse --verify --quiet HEAD >/dev/null; then
1237 __git_complete_index_file "--committable"
1239 # This is the first commit
1240 __git_complete_index_file "--cached"
1249 --all --tags --contains --abbrev= --candidates=
1250 --exact-match --debug --long --match --always
1254 __gitcomp_nl "$(__git_refs)"
1257 __git_diff_algorithms="myers minimal patience histogram"
1259 __git_diff_submodule_formats="diff log short"
1261 __git_diff_common_options="--stat --numstat --shortstat --summary
1262 --patch-with-stat --name-only --name-status --color
1263 --no-color --color-words --no-renames --check
1264 --full-index --binary --abbrev --diff-filter=
1265 --find-copies-harder
1266 --text --ignore-space-at-eol --ignore-space-change
1267 --ignore-all-space --ignore-blank-lines --exit-code
1268 --quiet --ext-diff --no-ext-diff
1269 --no-prefix --src-prefix= --dst-prefix=
1270 --inter-hunk-context=
1271 --patience --histogram --minimal
1272 --raw --word-diff --word-diff-regex=
1273 --dirstat --dirstat= --dirstat-by-file
1274 --dirstat-by-file= --cumulative
1276 --submodule --submodule=
1281 __git_has_doubledash && return
1285 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1289 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1293 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1294 --base --ours --theirs --no-index
1295 $__git_diff_common_options
1300 __git_complete_revlist_file
1303 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1304 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1309 __git_has_doubledash && return
1313 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1317 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1318 --base --ours --theirs
1319 --no-renames --diff-filter= --find-copies-harder
1320 --relative --ignore-submodules
1325 __git_complete_revlist_file
1328 __git_fetch_recurse_submodules="yes on-demand no"
1330 __git_fetch_options="
1331 --quiet --verbose --append --upload-pack --force --keep --depth=
1332 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1338 --recurse-submodules=*)
1339 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1343 __gitcomp "$__git_fetch_options"
1347 __git_complete_remote_or_refspec
1350 __git_format_patch_options="
1351 --stdout --attach --no-attach --thread --thread= --no-thread
1352 --numbered --start-number --numbered-files --keep-subject --signoff
1353 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1354 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1355 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1356 --output-directory --reroll-count --to= --quiet --notes
1359 _git_format_patch ()
1365 " "" "${cur##--thread=}"
1369 __gitcomp "$__git_format_patch_options"
1373 __git_complete_revlist
1381 --tags --root --unreachable --cache --no-reflogs --full
1382 --strict --verbose --lost-found
1393 __gitcomp "--prune --aggressive"
1404 __git_match_ctag() {
1405 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1410 __git_has_doubledash && return
1416 --text --ignore-case --word-regexp --invert-match
1417 --full-name --line-number
1418 --extended-regexp --basic-regexp --fixed-strings
1421 --files-with-matches --name-only
1422 --files-without-match
1425 --and --or --not --all-match
1431 case "$cword,$prev" in
1433 if test -r tags; then
1434 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1440 __gitcomp_nl "$(__git_refs)"
1447 __gitcomp "--all --guides --info --man --web"
1451 __git_compute_all_commands
1452 __gitcomp "$__git_all_commands $(__git_aliases)
1453 attributes cli core-tutorial cvs-migration
1454 diffcore everyday gitk glossary hooks ignore modules
1455 namespaces repository-layout revisions tutorial tutorial-2
1465 false true umask group all world everybody
1466 " "" "${cur##--shared=}"
1470 __gitcomp "--quiet --bare --template= --shared --shared="
1480 __gitcomp "--cached --deleted --modified --others --ignored
1481 --stage --directory --no-empty-directory --unmerged
1482 --killed --exclude= --exclude-from=
1483 --exclude-per-directory= --exclude-standard
1484 --error-unmatch --with-tree= --full-name
1485 --abbrev --ignored --exclude-per-directory
1491 # XXX ignore options like --modified and always suggest all cached
1493 __git_complete_index_file "--cached"
1498 __gitcomp_nl "$(__git_remotes)"
1506 # Options that go well for log, shortlog and gitk
1507 __git_log_common_options="
1509 --branches --tags --remotes
1510 --first-parent --merges --no-merges
1512 --max-age= --since= --after=
1513 --min-age= --until= --before=
1514 --min-parents= --max-parents=
1515 --no-min-parents --no-max-parents
1517 # Options that go well for log and gitk (not shortlog)
1518 __git_log_gitk_options="
1519 --dense --sparse --full-history
1520 --simplify-merges --simplify-by-decoration
1521 --left-right --notes --no-notes
1523 # Options that go well for log and shortlog (not gitk)
1524 __git_log_shortlog_options="
1525 --author= --committer= --grep=
1526 --all-match --invert-grep
1529 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1530 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1534 __git_has_doubledash && return
1536 local g="$(__gitdir)"
1538 if [ -f "$g/MERGE_HEAD" ]; then
1542 --pretty=*|--format=*)
1543 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1548 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1552 __gitcomp "full short no" "" "${cur##--decorate=}"
1556 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1560 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1565 $__git_log_common_options
1566 $__git_log_shortlog_options
1567 $__git_log_gitk_options
1568 --root --topo-order --date-order --reverse
1569 --follow --full-diff
1570 --abbrev-commit --abbrev=
1571 --relative-date --date=
1572 --pretty= --format= --oneline
1577 --decorate --decorate=
1579 --parents --children
1581 $__git_diff_common_options
1582 --pickaxe-all --pickaxe-regex
1587 __git_complete_revlist
1590 # Common merge options shared by git-merge(1) and git-pull(1).
1591 __git_merge_options="
1592 --no-commit --no-stat --log --no-log --squash --strategy
1593 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1594 --verify-signatures --no-verify-signatures --gpg-sign
1595 --quiet --verbose --progress --no-progress
1600 __git_complete_strategy && return
1604 __gitcomp "$__git_merge_options
1605 --rerere-autoupdate --no-rerere-autoupdate --abort --continue"
1608 __gitcomp_nl "$(__git_refs)"
1615 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1629 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1633 __gitcomp_nl "$(__git_refs)"
1640 __gitcomp "--dry-run"
1645 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1646 # We need to show both cached and untracked files (including
1647 # empty directories) since this may not be the last argument.
1648 __git_complete_index_file "--cached --others --directory"
1650 __git_complete_index_file "--cached"
1656 __gitcomp "--tags --all --stdin"
1661 local subcommands='add append copy edit list prune remove show'
1662 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1664 case "$subcommand,$cur" in
1671 __gitcomp_nl "$(__git_refs)"
1674 __gitcomp "$subcommands --ref"
1678 add,--reuse-message=*|append,--reuse-message=*|\
1679 add,--reedit-message=*|append,--reedit-message=*)
1680 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1683 __gitcomp '--file= --message= --reedit-message=
1690 __gitcomp '--dry-run --verbose'
1699 __gitcomp_nl "$(__git_refs)"
1708 __git_complete_strategy && return
1711 --recurse-submodules=*)
1712 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1717 --rebase --no-rebase
1718 $__git_merge_options
1719 $__git_fetch_options
1724 __git_complete_remote_or_refspec
1727 __git_push_recurse_submodules="check on-demand"
1729 __git_complete_force_with_lease ()
1737 __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
1740 __gitcomp_nl "$(__git_refs)" "" "$cur_"
1749 __gitcomp_nl "$(__git_remotes)"
1752 --recurse-submodules)
1753 __gitcomp "$__git_push_recurse_submodules"
1759 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1762 --recurse-submodules=*)
1763 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1766 --force-with-lease=*)
1767 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1772 --all --mirror --tags --dry-run --force --verbose
1773 --quiet --prune --delete --follow-tags
1774 --receive-pack= --repo= --set-upstream
1775 --force-with-lease --force-with-lease= --recurse-submodules=
1780 __git_complete_remote_or_refspec
1785 local dir="$(__gitdir)"
1786 if [ -f "$dir"/rebase-merge/interactive ]; then
1787 __gitcomp "--continue --skip --abort --quit --edit-todo"
1789 elif [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1790 __gitcomp "--continue --skip --abort --quit"
1793 __git_complete_strategy && return
1796 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1801 --onto --merge --strategy --interactive
1802 --preserve-merges --stat --no-stat
1803 --committer-date-is-author-date --ignore-date
1804 --ignore-whitespace --whitespace=
1805 --autosquash --no-autosquash
1806 --fork-point --no-fork-point
1807 --autostash --no-autostash
1808 --verify --no-verify
1809 --keep-empty --root --force-rebase --no-ff
1815 __gitcomp_nl "$(__git_refs)"
1820 local subcommands="show delete expire"
1821 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1823 if [ -z "$subcommand" ]; then
1824 __gitcomp "$subcommands"
1826 __gitcomp_nl "$(__git_refs)"
1830 __git_send_email_confirm_options="always never auto cc compose"
1831 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1836 --to|--cc|--bcc|--from)
1838 $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
1847 $__git_send_email_confirm_options
1848 " "" "${cur##--confirm=}"
1853 $__git_send_email_suppresscc_options
1854 " "" "${cur##--suppress-cc=}"
1858 --smtp-encryption=*)
1859 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1865 " "" "${cur##--thread=}"
1868 --to=*|--cc=*|--bcc=*|--from=*)
1870 $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
1875 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1876 --compose --confirm= --dry-run --envelope-sender
1878 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1879 --no-suppress-from --no-thread --quiet
1880 --signed-off-by-cc --smtp-pass --smtp-server
1881 --smtp-server-port --smtp-encryption= --smtp-user
1882 --subject --suppress-cc= --suppress-from --thread --to
1883 --validate --no-validate
1884 $__git_format_patch_options"
1888 __git_complete_revlist
1899 local untracked_state
1902 --ignore-submodules=*)
1903 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
1906 --untracked-files=*)
1907 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1912 always never auto column row plain dense nodense
1913 " "" "${cur##--column=}"
1918 --short --branch --porcelain --long --verbose
1919 --untracked-files= --ignore-submodules= --ignored
1920 --column= --no-column
1926 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
1927 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
1929 case "$untracked_state" in
1931 # --ignored option does not matter
1935 complete_opt="--cached --directory --no-empty-directory --others"
1937 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
1938 complete_opt="$complete_opt --ignored --exclude=*"
1943 __git_complete_index_file "$complete_opt"
1946 __git_config_get_set_variables ()
1948 local prevword word config_file= c=$cword
1949 while [ $c -gt 1 ]; do
1952 --system|--global|--local|--file=*)
1957 config_file="$word $prevword"
1965 git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null
1971 branch.*.remote|branch.*.pushremote)
1972 __gitcomp_nl "$(__git_remotes)"
1976 __gitcomp_nl "$(__git_refs)"
1980 __gitcomp "false true preserve interactive"
1984 __gitcomp_nl "$(__git_remotes)"
1988 local remote="${prev#remote.}"
1989 remote="${remote%.fetch}"
1990 if [ -z "$cur" ]; then
1991 __gitcomp_nl "refs/heads/" "" "" ""
1994 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1998 local remote="${prev#remote.}"
1999 remote="${remote%.push}"
2000 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
2001 for-each-ref --format='%(refname):%(refname)' \
2005 pull.twohead|pull.octopus)
2006 __git_compute_merge_strategies
2007 __gitcomp "$__git_merge_strategies"
2010 color.branch|color.diff|color.interactive|\
2011 color.showbranch|color.status|color.ui)
2012 __gitcomp "always never auto"
2016 __gitcomp "false true"
2021 normal black red green yellow blue magenta cyan white
2022 bold dim ul blink reverse
2027 __gitcomp "log short"
2031 __gitcomp "man info web html"
2035 __gitcomp "$__git_log_date_formats"
2038 sendemail.aliasesfiletype)
2039 __gitcomp "mutt mailrc pine elm gnus"
2043 __gitcomp "$__git_send_email_confirm_options"
2046 sendemail.suppresscc)
2047 __gitcomp "$__git_send_email_suppresscc_options"
2050 sendemail.transferencoding)
2051 __gitcomp "7bit 8bit quoted-printable base64"
2054 --get|--get-all|--unset|--unset-all)
2055 __gitcomp_nl "$(__git_config_get_set_variables)"
2065 --system --global --local --file=
2066 --list --replace-all
2067 --get --get-all --get-regexp
2068 --add --unset --unset-all
2069 --remove-section --rename-section
2075 local pfx="${cur%.*}." cur_="${cur##*.}"
2076 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
2080 local pfx="${cur%.*}." cur_="${cur#*.}"
2081 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
2082 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
2086 local pfx="${cur%.*}." cur_="${cur##*.}"
2088 argprompt cmd confirm needsfile noconsole norescan
2089 prompt revprompt revunmerged title
2094 local pfx="${cur%.*}." cur_="${cur##*.}"
2095 __gitcomp "cmd path" "$pfx" "$cur_"
2099 local pfx="${cur%.*}." cur_="${cur##*.}"
2100 __gitcomp "cmd path" "$pfx" "$cur_"
2104 local pfx="${cur%.*}." cur_="${cur##*.}"
2105 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
2109 local pfx="${cur%.*}." cur_="${cur#*.}"
2110 __git_compute_all_commands
2111 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
2115 local pfx="${cur%.*}." cur_="${cur##*.}"
2117 url proxy fetch push mirror skipDefaultUpdate
2118 receivepack uploadpack tagopt pushurl
2123 local pfx="${cur%.*}." cur_="${cur#*.}"
2124 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2125 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2129 local pfx="${cur%.*}." cur_="${cur##*.}"
2130 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
2136 advice.commitBeforeMerge
2138 advice.implicitIdentity
2139 advice.pushNonFastForward
2140 advice.resolveConflict
2144 apply.ignorewhitespace
2146 branch.autosetupmerge
2147 branch.autosetuprebase
2151 color.branch.current
2156 color.decorate.branch
2157 color.decorate.remoteBranch
2158 color.decorate.stash
2168 color.diff.whitespace
2173 color.grep.linenumber
2176 color.grep.separator
2178 color.interactive.error
2179 color.interactive.header
2180 color.interactive.help
2181 color.interactive.prompt
2186 color.status.changed
2188 color.status.nobranch
2189 color.status.unmerged
2190 color.status.untracked
2191 color.status.updated
2200 core.bigFileThreshold
2203 core.deltaBaseCacheLimit
2208 core.fsyncobjectfiles
2212 core.logAllRefUpdates
2213 core.loosecompression
2216 core.packedGitWindowSize
2218 core.preferSymlinkRefs
2221 core.repositoryFormatVersion
2223 core.sharedRepository
2228 core.warnAmbiguousRefs
2231 diff.autorefreshindex
2233 diff.ignoreSubmodules
2240 diff.suppressBlankEmpty
2246 fetch.recurseSubmodules
2257 format.subjectprefix
2268 gc.reflogexpireunreachable
2272 gitcvs.commitmsgannotation
2273 gitcvs.dbTableNamePrefix
2284 gui.copyblamethreshold
2288 gui.matchtrackingbranch
2289 gui.newbranchtemplate
2290 gui.pruneduringfetch
2291 gui.spellingdictionary
2308 http.sslCertPasswordProtected
2313 i18n.logOutputEncoding
2319 imap.preformattedHTML
2329 interactive.singlekey
2345 mergetool.keepBackup
2346 mergetool.keepTemporaries
2351 notes.rewrite.rebase
2355 pack.deltaCacheLimit
2372 receive.denyCurrentBranch
2373 receive.denyDeleteCurrent
2375 receive.denyNonFastForwards
2378 receive.updateserverinfo
2381 repack.usedeltabaseoffset
2385 sendemail.aliasesfile
2386 sendemail.aliasfiletype
2390 sendemail.chainreplyto
2392 sendemail.envelopesender
2396 sendemail.signedoffbycc
2397 sendemail.smtpdomain
2398 sendemail.smtpencryption
2400 sendemail.smtpserver
2401 sendemail.smtpserveroption
2402 sendemail.smtpserverport
2404 sendemail.suppresscc
2405 sendemail.suppressfrom
2410 status.relativePaths
2411 status.showUntrackedFiles
2412 status.submodulesummary
2415 transfer.unpackLimit
2427 local subcommands="add rename remove set-head set-branches set-url show prune update"
2428 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2429 if [ -z "$subcommand" ]; then
2430 __gitcomp "$subcommands"
2434 case "$subcommand" in
2435 rename|remove|set-url|show|prune)
2436 __gitcomp_nl "$(__git_remotes)"
2438 set-head|set-branches)
2439 __git_complete_remote_or_refspec
2442 __gitcomp "$(__git_get_config_variables "remotes")"
2451 __gitcomp_nl "$(__git_refs)"
2456 __git_has_doubledash && return
2460 __gitcomp "--merge --mixed --hard --soft --patch"
2464 __gitcomp_nl "$(__git_refs)"
2469 local dir="$(__gitdir)"
2470 if [ -f "$dir"/REVERT_HEAD ]; then
2471 __gitcomp "--continue --quit --abort"
2476 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2480 __gitcomp_nl "$(__git_refs)"
2487 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2492 __git_complete_index_file "--cached"
2497 __git_has_doubledash && return
2502 $__git_log_common_options
2503 $__git_log_shortlog_options
2504 --numbered --summary
2509 __git_complete_revlist
2514 __git_has_doubledash && return
2517 --pretty=*|--format=*)
2518 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2523 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2527 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2531 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2533 $__git_diff_common_options
2538 __git_complete_revlist_file
2546 --all --remotes --topo-order --date-order --current --more=
2547 --list --independent --merge-base --no-name
2549 --sha1-name --sparse --topics --reflog
2554 __git_complete_revlist
2559 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2560 local subcommands='save list show apply clear drop pop create branch'
2561 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2562 if [ -z "$subcommand" ]; then
2565 __gitcomp "$save_opts"
2568 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2569 __gitcomp "$subcommands"
2574 case "$subcommand,$cur" in
2576 __gitcomp "$save_opts"
2579 __gitcomp "--index --quiet"
2584 show,--*|branch,--*)
2587 if [ $cword -eq 3 ]; then
2588 __gitcomp_nl "$(__git_refs)";
2590 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2591 | sed -n -e 's/:.*//p')"
2594 show,*|apply,*|drop,*|pop,*)
2595 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2596 | sed -n -e 's/:.*//p')"
2606 __git_has_doubledash && return
2608 local subcommands="add status init deinit update summary foreach sync"
2609 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2612 __gitcomp "--quiet --cached"
2615 __gitcomp "$subcommands"
2625 init fetch clone rebase dcommit log find-rev
2626 set-tree commit-diff info create-ignore propget
2627 proplist show-ignore show-externals branch tag blame
2628 migrate mkdirs reset gc
2630 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2631 if [ -z "$subcommand" ]; then
2632 __gitcomp "$subcommands"
2634 local remote_opts="--username= --config-dir= --no-auth-cache"
2636 --follow-parent --authors-file= --repack=
2637 --no-metadata --use-svm-props --use-svnsync-props
2638 --log-window-size= --no-checkout --quiet
2639 --repack-flags --use-log-author --localtime
2640 --ignore-paths= --include-paths= $remote_opts
2643 --template= --shared= --trunk= --tags=
2644 --branches= --stdlayout --minimize-url
2645 --no-metadata --use-svm-props --use-svnsync-props
2646 --rewrite-root= --prefix= --use-log-author
2647 --add-author-from $remote_opts
2650 --edit --rmdir --find-copies-harder --copy-similarity=
2653 case "$subcommand,$cur" in
2655 __gitcomp "--revision= --fetch-all $fc_opts"
2658 __gitcomp "--revision= $fc_opts $init_opts"
2661 __gitcomp "$init_opts"
2665 --merge --strategy= --verbose --dry-run
2666 --fetch-all --no-rebase --commit-url
2667 --revision --interactive $cmt_opts $fc_opts
2671 __gitcomp "--stdin $cmt_opts $fc_opts"
2673 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2674 show-externals,--*|mkdirs,--*)
2675 __gitcomp "--revision="
2679 --limit= --revision= --verbose --incremental
2680 --oneline --show-commit --non-recursive
2681 --authors-file= --color
2686 --merge --verbose --strategy= --local
2687 --fetch-all --dry-run $fc_opts
2691 __gitcomp "--message= --file= --revision= $cmt_opts"
2697 __gitcomp "--dry-run --message --tag"
2700 __gitcomp "--dry-run --message"
2703 __gitcomp "--git-format"
2707 --config-dir= --ignore-paths= --minimize
2708 --no-auth-cache --username=
2712 __gitcomp "--revision= --parent"
2723 while [ $c -lt $cword ]; do
2727 __gitcomp_nl "$(__git_tags)"
2742 __gitcomp_nl "$(__git_tags)"
2746 __gitcomp_nl "$(__git_refs)"
2753 --list --delete --verify --annotate --message --file
2754 --sign --cleanup --local-user --force --column --sort
2755 --contains --points-at
2768 local subcommands="add list lock prune unlock"
2769 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2770 if [ -z "$subcommand" ]; then
2771 __gitcomp "$subcommands"
2773 case "$subcommand,$cur" in
2775 __gitcomp "--detach"
2778 __gitcomp "--porcelain"
2781 __gitcomp "--reason"
2784 __gitcomp "--dry-run --expire --verbose"
2794 local i c=1 command __git_dir
2796 while [ $c -lt $cword ]; do
2799 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2800 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2801 --bare) __git_dir="." ;;
2802 --help) command="help"; break ;;
2803 -c|--work-tree|--namespace) ((c++)) ;;
2805 *) command="$i"; break ;;
2810 if [ -z "$command" ]; then
2812 --git-dir|-C|--work-tree)
2813 # these need a path argument, let's fall back to
2814 # Bash filename completion
2818 # we don't support completing these options' arguments
2836 --no-replace-objects
2840 *) __git_compute_porcelain_commands
2841 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2846 local completion_func="_git_${command//-/_}"
2847 declare -f $completion_func >/dev/null && $completion_func && return
2849 local expansion=$(__git_aliased_command "$command")
2850 if [ -n "$expansion" ]; then
2852 completion_func="_git_${expansion//-/_}"
2853 declare -f $completion_func >/dev/null && $completion_func
2859 __git_has_doubledash && return
2861 local g="$(__gitdir)"
2863 if [ -f "$g/MERGE_HEAD" ]; then
2869 $__git_log_common_options
2870 $__git_log_gitk_options
2876 __git_complete_revlist
2879 if [[ -n ${ZSH_VERSION-} ]]; then
2880 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2882 autoload -U +X compinit && compinit
2888 local cur_="${3-$cur}"
2894 local c IFS=$' \t\n'
2902 array[${#array[@]}+1]="$c"
2905 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2916 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2925 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2930 local _ret=1 cur cword prev
2931 cur=${words[CURRENT]}
2932 prev=${words[CURRENT-1]}
2934 emulate ksh -c __${service}_main
2935 let _ret && _default && _ret=0
2939 compdef _git git gitk
2945 local cur words cword prev
2946 _get_comp_words_by_ref -n =: cur words cword prev
2950 # Setup completion for certain functions defined above by setting common
2951 # variables and workarounds.
2952 # This is NOT a public function; use at your own risk.
2955 local wrapper="__git_wrap${2}"
2956 eval "$wrapper () { __git_func_wrap $2 ; }"
2957 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2958 || complete -o default -o nospace -F $wrapper $1
2961 # wrapper for backwards compatibility
2964 __git_wrap__git_main
2967 # wrapper for backwards compatibility
2970 __git_wrap__gitk_main
2973 __git_complete git __git_main
2974 __git_complete gitk __gitk_main
2976 # The following are necessary only for Cygwin, and only are needed
2977 # when the user has tab-completed the executable name and consequently
2978 # included the '.exe' suffix.
2980 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2981 __git_complete git.exe __git_main