3 # bash/zsh completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.sh
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 if [[ -n ${ZSH_VERSION-} ]]; then
27 autoload
-U +X bashcompinit
&& bashcompinit
30 case "$COMP_WORDBREAKS" in
32 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
35 # __gitdir accepts 0 or 1 arguments (i.e., location)
36 # returns location of .git repo
39 if [ -z "${1-}" ]; then
40 if [ -n "${__git_dir-}" ]; then
42 elif [ -d .git
]; then
45 git rev-parse
--git-dir 2>/dev
/null
47 elif [ -d "$1/.git" ]; then
67 # The following function is based on code from:
69 # bash_completion - programmable completion functions for bash 3.2+
71 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
72 # © 2009-2010, Bash Completion Maintainers
73 # <bash-completion-devel@lists.alioth.debian.org>
75 # This program is free software; you can redistribute it and/or modify
76 # it under the terms of the GNU General Public License as published by
77 # the Free Software Foundation; either version 2, or (at your option)
80 # This program is distributed in the hope that it will be useful,
81 # but WITHOUT ANY WARRANTY; without even the implied warranty of
82 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83 # GNU General Public License for more details.
85 # You should have received a copy of the GNU General Public License
86 # along with this program; if not, write to the Free Software Foundation,
87 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
89 # The latest version of this software can be obtained here:
91 # http://bash-completion.alioth.debian.org/
95 # This function can be used to access a tokenized list of words
96 # on the command line:
98 # __git_reassemble_comp_words_by_ref '=:'
99 # if test "${words_[cword_-1]}" = -w
104 # The argument should be a collection of characters from the list of
105 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
108 # This is roughly equivalent to going back in time and setting
109 # COMP_WORDBREAKS to exclude those characters. The intent is to
110 # make option types like --date=<type> and <rev>:<path> easy to
111 # recognize by treating each shell word as a single token.
113 # It is best not to set COMP_WORDBREAKS directly because the value is
114 # shared with other completion scripts. By the time the completion
115 # function gets called, COMP_WORDS has already been populated so local
116 # changes to COMP_WORDBREAKS have no effect.
118 # Output: words_, cword_, cur_.
120 __git_reassemble_comp_words_by_ref
()
122 local exclude i j first
123 # Which word separators to exclude?
124 exclude
="${1//[^$COMP_WORDBREAKS]}"
126 if [ -z "$exclude" ]; then
127 words_
=("${COMP_WORDS[@]}")
130 # List of word completion separators has shrunk;
131 # re-assemble words to complete.
132 for ((i
=0, j
=0; i
< ${#COMP_WORDS[@]}; i
++, j
++)); do
133 # Append each nonempty word consisting of just
134 # word separator characters to the current word.
138 [ -n "${COMP_WORDS[$i]}" ] &&
139 # word consists of excluded word separators
140 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
142 # Attach to the previous token,
143 # unless the previous token is the command name.
144 if [ $j -ge 2 ] && [ -n "$first" ]; then
148 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
149 if [ $i = $COMP_CWORD ]; then
152 if (($i < ${#COMP_WORDS[@]} - 1)); then
159 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
160 if [ $i = $COMP_CWORD ]; then
166 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
167 if [[ -z ${ZSH_VERSION:+set} ]]; then
168 _get_comp_words_by_ref
()
170 local exclude cur_ words_ cword_
171 if [ "$1" = "-n" ]; then
175 __git_reassemble_comp_words_by_ref
"$exclude"
176 cur_
=${words_[cword_]}
177 while [ $# -gt 0 ]; do
183 prev
=${words_[$cword_-1]}
186 words
=("${words_[@]}")
196 _get_comp_words_by_ref
()
198 while [ $# -gt 0 ]; do
201 cur
=${COMP_WORDS[COMP_CWORD]}
204 prev
=${COMP_WORDS[COMP_CWORD-1]}
207 words
=("${COMP_WORDS[@]}")
213 # assume COMP_WORDBREAKS is already set sanely
223 # Generates completion reply with compgen, appending a space to possible
224 # completion words, if necessary.
225 # It accepts 1 to 4 arguments:
226 # 1: List of possible completion words.
227 # 2: A prefix to be added to each possible completion word (optional).
228 # 3: Generate possible completion matches for this word (optional).
229 # 4: A suffix to be appended to each possible completion word (optional).
232 local cur_
="${3-$cur}"
240 COMPREPLY
=($
(compgen
-P "${2-}" \
241 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
247 # Generates completion reply with compgen from newline-separated possible
248 # completion words by appending a space to all of them.
249 # It accepts 1 to 4 arguments:
250 # 1: List of possible completion words, separated by a single newline.
251 # 2: A prefix to be added to each possible completion word (optional).
252 # 3: Generate possible completion matches for this word (optional).
253 # 4: A suffix to be appended to each possible completion word instead of
254 # the default space (optional). If specified but empty, nothing is
259 COMPREPLY
=($
(compgen
-P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
264 local dir
="$(__gitdir)"
265 if [ -d "$dir" ]; then
266 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
274 local dir
="$(__gitdir)"
275 if [ -d "$dir" ]; then
276 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
282 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
283 # presence of 2nd argument means use the guess heuristic employed
284 # by checkout for tracking branches
287 local i
hash dir
="$(__gitdir "${1-}")" track
="${2-}"
289 if [ -d "$dir" ]; then
297 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
298 if [ -e "$dir/$i" ]; then echo $i; fi
300 format
="refname:short"
301 refs
="refs/tags refs/heads refs/remotes"
304 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
306 if [ -n "$track" ]; then
307 # employ the heuristic used by git checkout
308 # Try to find a remote branch that matches the completion word
309 # but only output if the branch name is unique
311 git
--git-dir="$dir" for-each-ref
--shell --format="ref=%(refname:short)" \
313 while read -r entry
; do
316 if [[ "$ref" == "$cur"* ]]; then
325 git ls-remote
"$dir" "$cur*" 2>/dev
/null | \
326 while read -r hash i
; do
334 git ls-remote
"$dir" HEAD ORIG_HEAD
'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev
/null | \
335 while read -r hash i
; do
338 refs
/*) echo "${i#refs/*/}" ;;
346 # __git_refs2 requires 1 argument (to pass to __git_refs)
350 for i
in $
(__git_refs
"$1"); do
355 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
356 __git_refs_remotes
()
359 git ls-remote
"$1" 'refs/heads/*' 2>/dev
/null | \
360 while read -r hash i
; do
361 echo "$i:refs/remotes/$1/${i#refs/heads/}"
367 local i IFS
=$
'\n' d
="$(__gitdir)"
368 test -d "$d/remotes" && ls -1 "$d/remotes"
369 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
375 __git_list_merge_strategies
()
377 git merge
-s help 2>&1 |
378 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
387 __git_merge_strategies
=
388 # 'git merge -s help' (and thus detection of the merge strategy
389 # list) fails, unfortunately, if run outside of any git working
390 # tree. __git_merge_strategies is set to the empty string in
391 # that case, and the detection will be repeated the next time it
393 __git_compute_merge_strategies
()
395 test -n "$__git_merge_strategies" ||
396 __git_merge_strategies
=$
(__git_list_merge_strategies
)
399 __git_complete_revlist_file
()
401 local pfx
ls ref cur_
="$cur"
421 case "$COMP_WORDBREAKS" in
423 *) pfx
="$ref:$pfx" ;;
427 COMPREPLY
=($
(compgen
-P "$pfx" \
428 -W "$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" \
429 | sed '/^100... blob /{
445 pfx
="${cur_%...*}..."
447 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
452 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
455 __gitcomp_nl
"$(__git_refs)"
461 __git_complete_file
()
463 __git_complete_revlist_file
466 __git_complete_revlist
()
468 __git_complete_revlist_file
471 __git_complete_remote_or_refspec
()
473 local cur_
="$cur" cmd
="${words[1]}"
474 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
475 if [ "$cmd" = "remote" ]; then
478 while [ $c -lt $cword ]; do
481 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
484 push
) no_complete_refspec
=1 ;;
493 *) remote
="$i"; break ;;
497 if [ -z "$remote" ]; then
498 __gitcomp_nl
"$(__git_remotes)"
501 if [ $no_complete_refspec = 1 ]; then
505 [ "$remote" = "." ] && remote
=
508 case "$COMP_WORDBREAKS" in
510 *) pfx
="${cur_%%:*}:" ;;
522 if [ $lhs = 1 ]; then
523 __gitcomp_nl
"$(__git_refs2 "$remote")" "$pfx" "$cur_"
525 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
529 if [ $lhs = 1 ]; then
530 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
532 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
536 if [ $lhs = 1 ]; then
537 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
539 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
545 __git_complete_strategy
()
547 __git_compute_merge_strategies
550 __gitcomp
"$__git_merge_strategies"
555 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
562 __git_list_all_commands
()
565 for i
in $
(git
help -a|
egrep '^ [a-zA-Z0-9]')
568 *--*) : helper pattern
;;
575 __git_compute_all_commands
()
577 test -n "$__git_all_commands" ||
578 __git_all_commands
=$
(__git_list_all_commands
)
581 __git_list_porcelain_commands
()
584 __git_compute_all_commands
585 for i
in "help" $__git_all_commands
588 *--*) : helper pattern
;;
589 applymbox
) : ask gittus
;;
590 applypatch
) : ask gittus
;;
591 archimport
) : import
;;
592 cat-file
) : plumbing
;;
593 check-attr
) : plumbing
;;
594 check-ref-format
) : plumbing
;;
595 checkout-index
) : plumbing
;;
596 commit-tree
) : plumbing
;;
597 count-objects
) : infrequent
;;
598 cvsexportcommit
) : export;;
599 cvsimport
) : import
;;
600 cvsserver
) : daemon
;;
602 diff-files
) : plumbing
;;
603 diff-index
) : plumbing
;;
604 diff-tree
) : plumbing
;;
605 fast-import
) : import
;;
606 fast-export
) : export;;
607 fsck-objects
) : plumbing
;;
608 fetch-pack
) : plumbing
;;
609 fmt-merge-msg
) : plumbing
;;
610 for-each-ref
) : plumbing
;;
611 hash-object
) : plumbing
;;
612 http-
*) : transport
;;
613 index-pack
) : plumbing
;;
614 init-db
) : deprecated
;;
615 local-fetch
) : plumbing
;;
616 lost-found
) : infrequent
;;
617 ls-files
) : plumbing
;;
618 ls-remote
) : plumbing
;;
619 ls-tree
) : plumbing
;;
620 mailinfo
) : plumbing
;;
621 mailsplit
) : plumbing
;;
622 merge-
*) : plumbing
;;
625 pack-objects
) : plumbing
;;
626 pack-redundant
) : plumbing
;;
627 pack-refs
) : plumbing
;;
628 parse-remote
) : plumbing
;;
629 patch-id
) : plumbing
;;
630 peek-remote
) : plumbing
;;
632 prune-packed
) : plumbing
;;
633 quiltimport
) : import
;;
634 read-tree
) : plumbing
;;
635 receive-pack
) : plumbing
;;
636 remote-
*) : transport
;;
637 repo-config
) : deprecated
;;
639 rev-list
) : plumbing
;;
640 rev-parse
) : plumbing
;;
641 runstatus
) : plumbing
;;
642 sh-setup
) : internal
;;
644 show-ref
) : plumbing
;;
645 send-pack
) : plumbing
;;
646 show-index
) : plumbing
;;
648 stripspace
) : plumbing
;;
649 symbolic-ref
) : plumbing
;;
650 tar-tree
) : deprecated
;;
651 unpack-file
) : plumbing
;;
652 unpack-objects
) : plumbing
;;
653 update-index
) : plumbing
;;
654 update-ref
) : plumbing
;;
655 update-server-info
) : daemon
;;
656 upload-archive
) : plumbing
;;
657 upload-pack
) : plumbing
;;
658 write-tree
) : plumbing
;;
660 verify-pack
) : infrequent
;;
661 verify-tag
) : plumbing
;;
667 __git_porcelain_commands
=
668 __git_compute_porcelain_commands
()
670 __git_compute_all_commands
671 test -n "$__git_porcelain_commands" ||
672 __git_porcelain_commands
=$
(__git_list_porcelain_commands
)
675 __git_pretty_aliases
()
678 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "pretty\..*" 2>/dev
/null
); do
691 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
701 # __git_aliased_command requires 1 argument
702 __git_aliased_command
()
704 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
705 config
--get "alias.$1")
706 for word
in $cmdline; do
712 \
!*) : shell
command alias ;;
714 *=*) : setting env
;;
723 # __git_find_on_cmdline requires 1 argument
724 __git_find_on_cmdline
()
726 local word subcommand c
=1
727 while [ $c -lt $cword ]; do
729 for subcommand
in $1; do
730 if [ "$subcommand" = "$word" ]; then
739 __git_has_doubledash
()
742 while [ $c -lt $cword ]; do
743 if [ "--" = "${words[c]}" ]; then
751 __git_whitespacelist
="nowarn warn error error-all fix"
755 local dir
="$(__gitdir)"
756 if [ -d "$dir"/rebase-apply
]; then
757 __gitcomp
"--skip --continue --resolved --abort"
762 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
767 --3way --committer-date-is-author-date --ignore-date
768 --ignore-whitespace --ignore-space-change
769 --interactive --keep --no-utf8 --signoff --utf8
770 --whitespace= --scissors
781 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
786 --stat --numstat --summary --check --index
787 --cached --index-info --reverse --reject --unidiff-zero
788 --apply --no-add --exclude=
789 --ignore-whitespace --ignore-space-change
790 --whitespace= --inaccurate-eof --verbose
799 __git_has_doubledash
&& return
804 --interactive --refresh --patch --update --dry-run
805 --ignore-errors --intent-to-add
816 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
820 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--remote=}"
825 --format= --list --verbose
826 --prefix= --remote= --exec=
836 __git_has_doubledash
&& return
838 local subcommands
="start bad good skip reset visualize replay log run"
839 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
840 if [ -z "$subcommand" ]; then
841 if [ -f "$(__gitdir)"/BISECT_START
]; then
842 __gitcomp
"$subcommands"
844 __gitcomp
"replay start"
849 case "$subcommand" in
850 bad|good|
reset|skip|start
)
851 __gitcomp_nl
"$(__git_refs)"
861 local i c
=1 only_local_ref
="n" has_r
="n"
863 while [ $c -lt $cword ]; do
866 -d|
-m) only_local_ref
="y" ;;
875 --color --no-color --verbose --abbrev= --no-abbrev
876 --track --no-track --contains --merged --no-merged
877 --set-upstream --edit-description --list
881 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
882 __gitcomp_nl
"$(__git_heads)"
884 __gitcomp_nl
"$(__git_refs)"
892 local cmd
="${words[2]}"
895 __gitcomp
"create list-heads verify unbundle"
903 __git_complete_revlist
912 __git_has_doubledash
&& return
916 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
920 --quiet --ours --theirs --track --no-track --merge
921 --conflict= --orphan --patch
925 # check if --track, --no-track, or --no-guess was specified
926 # if so, disable DWIM mode
927 local flags
="--track --no-track --no-guess" track
=1
928 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
931 __gitcomp_nl
"$(__git_refs '' $track)"
938 __gitcomp
"$(__git_refs)"
945 __gitcomp
"--edit --no-commit"
948 __gitcomp_nl
"$(__git_refs)"
955 __git_has_doubledash
&& return
959 __gitcomp
"--dry-run --quiet"
992 __git_has_doubledash
&& return
996 __gitcomp
"default strip verbatim whitespace
997 " "" "${cur##--cleanup=}"
1000 --reuse-message=*|
--reedit-message=*|\
1001 --fixup=*|
--squash=*)
1002 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1005 --untracked-files=*)
1006 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1011 --all --author= --signoff --verify --no-verify
1012 --edit --amend --include --only --interactive
1013 --dry-run --reuse-message= --reedit-message=
1014 --reset-author --file= --message= --template=
1015 --cleanup= --untracked-files --untracked-files=
1016 --verbose --quiet --fixup= --squash=
1028 --all --tags --contains --abbrev= --candidates=
1029 --exact-match --debug --long --match --always
1033 __gitcomp_nl
"$(__git_refs)"
1036 __git_diff_common_options
="--stat --numstat --shortstat --summary
1037 --patch-with-stat --name-only --name-status --color
1038 --no-color --color-words --no-renames --check
1039 --full-index --binary --abbrev --diff-filter=
1040 --find-copies-harder
1041 --text --ignore-space-at-eol --ignore-space-change
1042 --ignore-all-space --exit-code --quiet --ext-diff
1044 --no-prefix --src-prefix= --dst-prefix=
1045 --inter-hunk-context=
1048 --dirstat --dirstat= --dirstat-by-file
1049 --dirstat-by-file= --cumulative
1054 __git_has_doubledash
&& return
1058 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1059 --base --ours --theirs --no-index
1060 $__git_diff_common_options
1065 __git_complete_revlist_file
1068 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1069 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
1074 __git_has_doubledash
&& return
1078 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1082 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1083 --base --ours --theirs
1084 --no-renames --diff-filter= --find-copies-harder
1085 --relative --ignore-submodules
1093 __git_fetch_options
="
1094 --quiet --verbose --append --upload-pack --force --keep --depth=
1095 --tags --no-tags --all --prune --dry-run
1102 __gitcomp
"$__git_fetch_options"
1106 __git_complete_remote_or_refspec
1109 _git_format_patch
()
1115 " "" "${cur##--thread=}"
1120 --stdout --attach --no-attach --thread --thread=
1122 --numbered --start-number
1125 --signoff --signature --no-signature
1126 --in-reply-to= --cc=
1127 --full-index --binary
1130 --no-prefix --src-prefix= --dst-prefix=
1131 --inline --suffix= --ignore-if-in-upstream
1137 __git_complete_revlist
1145 --tags --root --unreachable --cache --no-reflogs --full
1146 --strict --verbose --lost-found
1158 __gitcomp
"--prune --aggressive"
1170 __git_match_ctag
() {
1171 awk "/^${1////\\/}/ { print \$1 }" "$2"
1176 __git_has_doubledash
&& return
1182 --text --ignore-case --word-regexp --invert-match
1183 --full-name --line-number
1184 --extended-regexp --basic-regexp --fixed-strings
1186 --files-with-matches --name-only
1187 --files-without-match
1190 --and --or --not --all-match
1196 case "$cword,$prev" in
1198 if test -r tags
; then
1199 __gitcomp_nl
"$(__git_match_ctag "$cur" tags)"
1205 __gitcomp_nl
"$(__git_refs)"
1212 __gitcomp
"--all --info --man --web"
1216 __git_compute_all_commands
1217 __gitcomp
"$__git_all_commands $(__git_aliases)
1218 attributes cli core-tutorial cvs-migration
1219 diffcore gitk glossary hooks ignore modules
1220 namespaces repository-layout tutorial tutorial-2
1230 false true umask group all world everybody
1231 " "" "${cur##--shared=}"
1235 __gitcomp
"--quiet --bare --template= --shared --shared="
1244 __git_has_doubledash
&& return
1248 __gitcomp
"--cached --deleted --modified --others --ignored
1249 --stage --directory --no-empty-directory --unmerged
1250 --killed --exclude= --exclude-from=
1251 --exclude-per-directory= --exclude-standard
1252 --error-unmatch --with-tree= --full-name
1253 --abbrev --ignored --exclude-per-directory
1263 __gitcomp_nl
"$(__git_remotes)"
1271 # Options that go well for log, shortlog and gitk
1272 __git_log_common_options
="
1274 --branches --tags --remotes
1275 --first-parent --merges --no-merges
1277 --max-age= --since= --after=
1278 --min-age= --until= --before=
1279 --min-parents= --max-parents=
1280 --no-min-parents --no-max-parents
1282 # Options that go well for log and gitk (not shortlog)
1283 __git_log_gitk_options
="
1284 --dense --sparse --full-history
1285 --simplify-merges --simplify-by-decoration
1286 --left-right --notes --no-notes
1288 # Options that go well for log and shortlog (not gitk)
1289 __git_log_shortlog_options
="
1290 --author= --committer= --grep=
1294 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1295 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1299 __git_has_doubledash
&& return
1301 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1303 if [ -f "$g/MERGE_HEAD" ]; then
1307 --pretty=*|
--format=*)
1308 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1313 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1317 __gitcomp
"long short" "" "${cur##--decorate=}"
1322 $__git_log_common_options
1323 $__git_log_shortlog_options
1324 $__git_log_gitk_options
1325 --root --topo-order --date-order --reverse
1326 --follow --full-diff
1327 --abbrev-commit --abbrev=
1328 --relative-date --date=
1329 --pretty= --format= --oneline
1332 --decorate --decorate=
1334 --parents --children
1336 $__git_diff_common_options
1337 --pickaxe-all --pickaxe-regex
1342 __git_complete_revlist
1345 __git_merge_options
="
1346 --no-commit --no-stat --log --no-log --squash --strategy
1347 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1352 __git_complete_strategy
&& return
1356 __gitcomp
"$__git_merge_options"
1359 __gitcomp_nl
"$(__git_refs)"
1366 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1379 __gitcomp_nl
"$(__git_refs)"
1386 __gitcomp
"--dry-run"
1395 __gitcomp
"--tags --all --stdin"
1400 local subcommands
='add append copy edit list prune remove show'
1401 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1403 case "$subcommand,$cur" in
1410 __gitcomp_nl
"$(__git_refs)"
1413 __gitcomp
"$subcommands --ref"
1417 add
,--reuse-message=*|append
,--reuse-message=*|\
1418 add
,--reedit-message=*|append
,--reedit-message=*)
1419 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1422 __gitcomp
'--file= --message= --reedit-message=
1429 __gitcomp
'--dry-run --verbose'
1438 __gitcomp_nl
"$(__git_refs)"
1447 __git_complete_strategy
&& return
1452 --rebase --no-rebase
1453 $__git_merge_options
1454 $__git_fetch_options
1459 __git_complete_remote_or_refspec
1466 __gitcomp_nl
"$(__git_remotes)"
1471 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--repo=}"
1476 --all --mirror --tags --dry-run --force --verbose
1477 --receive-pack= --repo= --set-upstream
1482 __git_complete_remote_or_refspec
1487 local dir
="$(__gitdir)"
1488 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1489 __gitcomp
"--continue --skip --abort"
1492 __git_complete_strategy
&& return
1495 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1500 --onto --merge --strategy --interactive
1501 --preserve-merges --stat --no-stat
1502 --committer-date-is-author-date --ignore-date
1503 --ignore-whitespace --whitespace=
1509 __gitcomp_nl
"$(__git_refs)"
1514 local subcommands
="show delete expire"
1515 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1517 if [ -z "$subcommand" ]; then
1518 __gitcomp
"$subcommands"
1520 __gitcomp_nl
"$(__git_refs)"
1524 __git_send_email_confirm_options
="always never auto cc compose"
1525 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1532 $__git_send_email_confirm_options
1533 " "" "${cur##--confirm=}"
1538 $__git_send_email_suppresscc_options
1539 " "" "${cur##--suppress-cc=}"
1543 --smtp-encryption=*)
1544 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1548 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1549 --compose --confirm= --dry-run --envelope-sender
1551 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1552 --no-suppress-from --no-thread --quiet
1553 --signed-off-by-cc --smtp-pass --smtp-server
1554 --smtp-server-port --smtp-encryption= --smtp-user
1555 --subject --suppress-cc= --suppress-from --thread --to
1556 --validate --no-validate"
1568 __git_config_get_set_variables
()
1570 local prevword word config_file
= c
=$cword
1571 while [ $c -gt 1 ]; do
1574 --global|
--system|
--file=*)
1579 config_file
="$word $prevword"
1587 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1602 __gitcomp_nl
"$(__git_remotes)"
1606 __gitcomp_nl
"$(__git_refs)"
1610 local remote
="${prev#remote.}"
1611 remote
="${remote%.fetch}"
1612 if [ -z "$cur" ]; then
1613 COMPREPLY
=("refs/heads/")
1616 __gitcomp_nl
"$(__git_refs_remotes "$remote")"
1620 local remote
="${prev#remote.}"
1621 remote
="${remote%.push}"
1622 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" \
1623 for-each-ref --format='%(refname):%(refname)' \
1627 pull.twohead|pull.octopus
)
1628 __git_compute_merge_strategies
1629 __gitcomp
"$__git_merge_strategies"
1632 color.branch|color.
diff|color.interactive|\
1633 color.showbranch|color.status|color.ui
)
1634 __gitcomp
"always never auto"
1638 __gitcomp
"false true"
1643 normal black red green yellow blue magenta cyan white
1644 bold dim ul blink reverse
1649 __gitcomp
"man info web html"
1653 __gitcomp
"$__git_log_date_formats"
1656 sendemail.aliasesfiletype
)
1657 __gitcomp
"mutt mailrc pine elm gnus"
1661 __gitcomp
"$__git_send_email_confirm_options"
1664 sendemail.suppresscc
)
1665 __gitcomp
"$__git_send_email_suppresscc_options"
1668 --get|
--get-all|
--unset|
--unset-all)
1669 __gitcomp_nl
"$(__git_config_get_set_variables)"
1680 --global --system --file=
1681 --list --replace-all
1682 --get --get-all --get-regexp
1683 --add --unset --unset-all
1684 --remove-section --rename-section
1689 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1690 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur_"
1694 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1695 __gitcomp_nl
"$(__git_heads)" "$pfx" "$cur_" "."
1699 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1701 argprompt cmd confirm needsfile noconsole norescan
1702 prompt revprompt revunmerged title
1707 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1708 __gitcomp
"cmd path" "$pfx" "$cur_"
1712 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1713 __gitcomp
"cmd path" "$pfx" "$cur_"
1717 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1718 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur_"
1722 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1723 __git_compute_all_commands
1724 __gitcomp_nl
"$__git_all_commands" "$pfx" "$cur_"
1728 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1730 url proxy fetch push mirror skipDefaultUpdate
1731 receivepack uploadpack tagopt pushurl
1736 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1737 __gitcomp_nl
"$(__git_remotes)" "$pfx" "$cur_" "."
1741 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1742 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur_"
1748 advice.commitBeforeMerge
1750 advice.implicitIdentity
1751 advice.pushNonFastForward
1752 advice.resolveConflict
1756 apply.ignorewhitespace
1758 branch.autosetupmerge
1759 branch.autosetuprebase
1763 color.branch.current
1768 color.decorate.branch
1769 color.decorate.remoteBranch
1770 color.decorate.stash
1780 color.diff.whitespace
1785 color.grep.linenumber
1788 color.grep.separator
1790 color.interactive.error
1791 color.interactive.header
1792 color.interactive.help
1793 color.interactive.prompt
1798 color.status.changed
1800 color.status.nobranch
1801 color.status.untracked
1802 color.status.updated
1811 core.bigFileThreshold
1814 core.deltaBaseCacheLimit
1819 core.fsyncobjectfiles
1821 core.ignoreCygwinFSTricks
1824 core.logAllRefUpdates
1825 core.loosecompression
1828 core.packedGitWindowSize
1830 core.preferSymlinkRefs
1833 core.repositoryFormatVersion
1835 core.sharedRepository
1839 core.warnAmbiguousRefs
1842 diff.autorefreshindex
1845 diff.ignoreSubmodules
1850 diff.suppressBlankEmpty
1855 fetch.recurseSubmodules
1864 format.subjectprefix
1875 gc.reflogexpireunreachable
1879 gitcvs.commitmsgannotation
1880 gitcvs.dbTableNamePrefix
1891 gui.copyblamethreshold
1895 gui.matchtrackingbranch
1896 gui.newbranchtemplate
1897 gui.pruneduringfetch
1898 gui.spellingdictionary
1913 http.sslCertPasswordProtected
1918 i18n.logOutputEncoding
1924 imap.preformattedHTML
1934 interactive.singlekey
1950 mergetool.keepBackup
1951 mergetool.keepTemporaries
1956 notes.rewrite.rebase
1960 pack.deltaCacheLimit
1976 receive.denyCurrentBranch
1977 receive.denyDeleteCurrent
1979 receive.denyNonFastForwards
1982 receive.updateserverinfo
1984 repack.usedeltabaseoffset
1988 sendemail.aliasesfile
1989 sendemail.aliasfiletype
1993 sendemail.chainreplyto
1995 sendemail.envelopesender
1999 sendemail.signedoffbycc
2000 sendemail.smtpdomain
2001 sendemail.smtpencryption
2003 sendemail.smtpserver
2004 sendemail.smtpserveroption
2005 sendemail.smtpserverport
2007 sendemail.suppresscc
2008 sendemail.suppressfrom
2013 status.relativePaths
2014 status.showUntrackedFiles
2015 status.submodulesummary
2018 transfer.unpackLimit
2030 local subcommands
="add rename rm set-head set-branches set-url show prune update"
2031 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2032 if [ -z "$subcommand" ]; then
2033 __gitcomp
"$subcommands"
2037 case "$subcommand" in
2038 rename|
rm|set-url|show|prune
)
2039 __gitcomp_nl
"$(__git_remotes)"
2041 set-head|set-branches
)
2042 __git_complete_remote_or_refspec
2045 local i c
='' IFS
=$
'\n'
2046 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2060 __gitcomp_nl
"$(__git_refs)"
2065 __git_has_doubledash
&& return
2069 __gitcomp
"--merge --mixed --hard --soft --patch"
2073 __gitcomp_nl
"$(__git_refs)"
2080 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2084 __gitcomp_nl
"$(__git_refs)"
2089 __git_has_doubledash
&& return
2093 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2102 __git_has_doubledash
&& return
2107 $__git_log_common_options
2108 $__git_log_shortlog_options
2109 --numbered --summary
2114 __git_complete_revlist
2119 __git_has_doubledash
&& return
2122 --pretty=*|
--format=*)
2123 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2128 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2129 $__git_diff_common_options
2142 --all --remotes --topo-order --current --more=
2143 --list --independent --merge-base --no-name
2145 --sha1-name --sparse --topics --reflog
2150 __git_complete_revlist
2155 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2156 local subcommands
='save list show apply clear drop pop create branch'
2157 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2158 if [ -z "$subcommand" ]; then
2161 __gitcomp
"$save_opts"
2164 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2165 __gitcomp
"$subcommands"
2172 case "$subcommand,$cur" in
2174 __gitcomp
"$save_opts"
2177 __gitcomp
"--index --quiet"
2179 show
,--*|drop
,--*|branch
,--*)
2182 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2183 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" stash list \
2184 | sed -n -e 's/:.*//p')"
2195 __git_has_doubledash
&& return
2197 local subcommands
="add status init update summary foreach sync"
2198 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2201 __gitcomp
"--quiet --cached"
2204 __gitcomp
"$subcommands"
2214 init fetch clone rebase dcommit log find-rev
2215 set-tree commit-diff info create-ignore propget
2216 proplist show-ignore show-externals branch tag blame
2217 migrate mkdirs reset gc
2219 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2220 if [ -z "$subcommand" ]; then
2221 __gitcomp
"$subcommands"
2223 local remote_opts
="--username= --config-dir= --no-auth-cache"
2225 --follow-parent --authors-file= --repack=
2226 --no-metadata --use-svm-props --use-svnsync-props
2227 --log-window-size= --no-checkout --quiet
2228 --repack-flags --use-log-author --localtime
2229 --ignore-paths= $remote_opts
2232 --template= --shared= --trunk= --tags=
2233 --branches= --stdlayout --minimize-url
2234 --no-metadata --use-svm-props --use-svnsync-props
2235 --rewrite-root= --prefix= --use-log-author
2236 --add-author-from $remote_opts
2239 --edit --rmdir --find-copies-harder --copy-similarity=
2242 case "$subcommand,$cur" in
2244 __gitcomp
"--revision= --fetch-all $fc_opts"
2247 __gitcomp
"--revision= $fc_opts $init_opts"
2250 __gitcomp
"$init_opts"
2254 --merge --strategy= --verbose --dry-run
2255 --fetch-all --no-rebase --commit-url
2256 --revision --interactive $cmt_opts $fc_opts
2260 __gitcomp
"--stdin $cmt_opts $fc_opts"
2262 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2263 show-externals
,--*|mkdirs
,--*)
2264 __gitcomp
"--revision="
2268 --limit= --revision= --verbose --incremental
2269 --oneline --show-commit --non-recursive
2270 --authors-file= --color
2275 --merge --verbose --strategy= --local
2276 --fetch-all --dry-run $fc_opts
2280 __gitcomp
"--message= --file= --revision= $cmt_opts"
2286 __gitcomp
"--dry-run --message --tag"
2289 __gitcomp
"--dry-run --message"
2292 __gitcomp
"--git-format"
2296 --config-dir= --ignore-paths= --minimize
2297 --no-auth-cache --username=
2301 __gitcomp
"--revision= --parent"
2313 while [ $c -lt $cword ]; do
2317 __gitcomp_nl
"$(__git_tags)"
2333 __gitcomp_nl
"$(__git_tags)"
2339 __gitcomp_nl
"$(__git_refs)"
2351 local i c
=1 command __git_dir
2353 while [ $c -lt $cword ]; do
2356 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2357 --bare) __git_dir
="." ;;
2358 --help) command="help"; break ;;
2361 *) command="$i"; break ;;
2366 if [ -z "$command" ]; then
2380 --no-replace-objects
2384 *) __git_compute_porcelain_commands
2385 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2390 local completion_func
="_git_${command//-/_}"
2391 declare -f $completion_func >/dev
/null
&& $completion_func && return
2393 local expansion
=$
(__git_aliased_command
"$command")
2394 if [ -n "$expansion" ]; then
2395 completion_func
="_git_${expansion//-/_}"
2396 declare -f $completion_func >/dev
/null
&& $completion_func
2402 __git_has_doubledash
&& return
2404 local g
="$(__gitdir)"
2406 if [ -f "$g/MERGE_HEAD" ]; then
2412 $__git_log_common_options
2413 $__git_log_gitk_options
2419 __git_complete_revlist
2424 if [[ -n ${ZSH_VERSION-} ]]; then
2428 # workaround zsh's bug that leaves 'words' as a special
2429 # variable in versions < 4.3.12
2432 # workaround zsh's bug that quotes spaces in the COMPREPLY
2433 # array if IFS doesn't contain spaces.
2436 local cur words cword prev
2437 _get_comp_words_by_ref
-n =: cur words cword prev
2441 # Setup completion for certain functions defined above by setting common
2442 # variables and workarounds.
2443 # This is NOT a public function; use at your own risk.
2446 local wrapper
="__git_wrap${2}"
2447 eval "$wrapper () { __git_func_wrap $2 ; }"
2448 complete
-o bashdefault
-o default
-o nospace
-F $wrapper $1 2>/dev
/null \
2449 || complete
-o default
-o nospace
-F $wrapper $1
2452 __git_complete git _git
2453 __git_complete gitk _gitk
2455 # The following are necessary only for Cygwin, and only are needed
2456 # when the user has tab-completed the executable name and consequently
2457 # included the '.exe' suffix.
2459 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2460 __git_complete git.exe _git