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 # Note: this function is duplicated in git-prompt.sh
40 # When updating it, make sure you update the other one to match.
41 if [ -z "${1-}" ]; then
42 if [ -n "${__git_dir-}" ]; then
44 elif [ -d .git ]; then
47 git rev-parse --git-dir 2>/dev/null
49 elif [ -d "$1/.git" ]; then
69 # The following function is based on code from:
71 # bash_completion - programmable completion functions for bash 3.2+
73 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
74 # © 2009-2010, Bash Completion Maintainers
75 # <bash-completion-devel@lists.alioth.debian.org>
77 # This program is free software; you can redistribute it and/or modify
78 # it under the terms of the GNU General Public License as published by
79 # the Free Software Foundation; either version 2, or (at your option)
82 # This program is distributed in the hope that it will be useful,
83 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85 # GNU General Public License for more details.
87 # You should have received a copy of the GNU General Public License
88 # along with this program; if not, write to the Free Software Foundation,
89 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
91 # The latest version of this software can be obtained here:
93 # http://bash-completion.alioth.debian.org/
97 # This function can be used to access a tokenized list of words
98 # on the command line:
100 # __git_reassemble_comp_words_by_ref '=:'
101 # if test "${words_[cword_-1]}" = -w
106 # The argument should be a collection of characters from the list of
107 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
110 # This is roughly equivalent to going back in time and setting
111 # COMP_WORDBREAKS to exclude those characters. The intent is to
112 # make option types like --date=<type> and <rev>:<path> easy to
113 # recognize by treating each shell word as a single token.
115 # It is best not to set COMP_WORDBREAKS directly because the value is
116 # shared with other completion scripts. By the time the completion
117 # function gets called, COMP_WORDS has already been populated so local
118 # changes to COMP_WORDBREAKS have no effect.
120 # Output: words_, cword_, cur_.
122 __git_reassemble_comp_words_by_ref()
124 local exclude i j first
125 # Which word separators to exclude?
126 exclude="${1//[^$COMP_WORDBREAKS]}"
128 if [ -z "$exclude" ]; then
129 words_=("${COMP_WORDS[@]}")
132 # List of word completion separators has shrunk;
133 # re-assemble words to complete.
134 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
135 # Append each nonempty word consisting of just
136 # word separator characters to the current word.
140 [ -n "${COMP_WORDS[$i]}" ] &&
141 # word consists of excluded word separators
142 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
144 # Attach to the previous token,
145 # unless the previous token is the command name.
146 if [ $j -ge 2 ] && [ -n "$first" ]; then
150 words_[$j]=${words_[j]}${COMP_WORDS[i]}
151 if [ $i = $COMP_CWORD ]; then
154 if (($i < ${#COMP_WORDS[@]} - 1)); then
161 words_[$j]=${words_[j]}${COMP_WORDS[i]}
162 if [ $i = $COMP_CWORD ]; then
168 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
169 if [[ -z ${ZSH_VERSION:+set} ]]; then
170 _get_comp_words_by_ref ()
172 local exclude cur_ words_ cword_
173 if [ "$1" = "-n" ]; then
177 __git_reassemble_comp_words_by_ref "$exclude"
178 cur_=${words_[cword_]}
179 while [ $# -gt 0 ]; do
185 prev=${words_[$cword_-1]}
188 words=("${words_[@]}")
198 _get_comp_words_by_ref ()
200 while [ $# -gt 0 ]; do
203 cur=${COMP_WORDS[COMP_CWORD]}
206 prev=${COMP_WORDS[COMP_CWORD-1]}
209 words=("${COMP_WORDS[@]}")
215 # assume COMP_WORDBREAKS is already set sanely
225 # Generates completion reply with compgen, appending a space to possible
226 # completion words, if necessary.
227 # It accepts 1 to 4 arguments:
228 # 1: List of possible completion words.
229 # 2: A prefix to be added to each possible completion word (optional).
230 # 3: Generate possible completion matches for this word (optional).
231 # 4: A suffix to be appended to each possible completion word (optional).
234 local cur_="${3-$cur}"
242 COMPREPLY=($(compgen -P "${2-}" \
243 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
249 # Generates completion reply with compgen from newline-separated possible
250 # completion words by appending a space to all of them.
251 # It accepts 1 to 4 arguments:
252 # 1: List of possible completion words, separated by a single newline.
253 # 2: A prefix to be added to each possible completion word (optional).
254 # 3: Generate possible completion matches for this word (optional).
255 # 4: A suffix to be appended to each possible completion word instead of
256 # the default space (optional). If specified but empty, nothing is
261 COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
266 local dir="$(__gitdir)"
267 if [ -d "$dir" ]; then
268 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
276 local dir="$(__gitdir)"
277 if [ -d "$dir" ]; then
278 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
284 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
285 # presence of 2nd argument means use the guess heuristic employed
286 # by checkout for tracking branches
289 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
291 if [ -d "$dir" ]; then
299 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
300 if [ -e "$dir/$i" ]; then echo $i; fi
302 format="refname:short"
303 refs="refs/tags refs/heads refs/remotes"
306 git --git-dir="$dir" for-each-ref --format="%($format)" \
308 if [ -n "$track" ]; then
309 # employ the heuristic used by git checkout
310 # Try to find a remote branch that matches the completion word
311 # but only output if the branch name is unique
313 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
315 while read -r entry; do
318 if [[ "$ref" == "$cur"* ]]; then
327 git ls-remote "$dir" "$cur*" 2>/dev/null | \
328 while read -r hash i; do
336 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
337 while read -r hash i; do
340 refs/*) echo "${i#refs/*/}" ;;
348 # __git_refs2 requires 1 argument (to pass to __git_refs)
352 for i in $(__git_refs "$1"); do
357 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
358 __git_refs_remotes ()
361 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
362 while read -r hash i; do
363 echo "$i:refs/remotes/$1/${i#refs/heads/}"
369 local i IFS=$'\n' d="$(__gitdir)"
370 test -d "$d/remotes" && ls -1 "$d/remotes"
371 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
377 __git_list_merge_strategies ()
379 git merge -s help 2>&1 |
380 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
389 __git_merge_strategies=
390 # 'git merge -s help' (and thus detection of the merge strategy
391 # list) fails, unfortunately, if run outside of any git working
392 # tree. __git_merge_strategies is set to the empty string in
393 # that case, and the detection will be repeated the next time it
395 __git_compute_merge_strategies ()
397 test -n "$__git_merge_strategies" ||
398 __git_merge_strategies=$(__git_list_merge_strategies)
401 __git_complete_revlist_file ()
403 local pfx ls ref cur_="$cur"
423 case "$COMP_WORDBREAKS" in
425 *) pfx="$ref:$pfx" ;;
429 COMPREPLY=($(compgen -P "$pfx" \
430 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
431 | sed '/^100... blob /{
447 pfx="${cur_%...*}..."
449 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
454 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
457 __gitcomp_nl "$(__git_refs)"
463 __git_complete_file ()
465 __git_complete_revlist_file
468 __git_complete_revlist ()
470 __git_complete_revlist_file
473 __git_complete_remote_or_refspec ()
475 local cur_="$cur" cmd="${words[1]}"
476 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
477 if [ "$cmd" = "remote" ]; then
480 while [ $c -lt $cword ]; do
483 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
486 push) no_complete_refspec=1 ;;
495 *) remote="$i"; break ;;
499 if [ -z "$remote" ]; then
500 __gitcomp_nl "$(__git_remotes)"
503 if [ $no_complete_refspec = 1 ]; then
507 [ "$remote" = "." ] && remote=
510 case "$COMP_WORDBREAKS" in
512 *) pfx="${cur_%%:*}:" ;;
524 if [ $lhs = 1 ]; then
525 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
527 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
531 if [ $lhs = 1 ]; then
532 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
534 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
538 if [ $lhs = 1 ]; then
539 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
541 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
547 __git_complete_strategy ()
549 __git_compute_merge_strategies
552 __gitcomp "$__git_merge_strategies"
557 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
564 __git_list_all_commands ()
567 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
570 *--*) : helper pattern;;
577 __git_compute_all_commands ()
579 test -n "$__git_all_commands" ||
580 __git_all_commands=$(__git_list_all_commands)
583 __git_list_porcelain_commands ()
586 __git_compute_all_commands
587 for i in "help" $__git_all_commands
590 *--*) : helper pattern;;
591 applymbox) : ask gittus;;
592 applypatch) : ask gittus;;
593 archimport) : import;;
594 cat-file) : plumbing;;
595 check-attr) : plumbing;;
596 check-ref-format) : plumbing;;
597 checkout-index) : plumbing;;
598 commit-tree) : plumbing;;
599 count-objects) : infrequent;;
600 cvsexportcommit) : export;;
601 cvsimport) : import;;
602 cvsserver) : daemon;;
604 diff-files) : plumbing;;
605 diff-index) : plumbing;;
606 diff-tree) : plumbing;;
607 fast-import) : import;;
608 fast-export) : export;;
609 fsck-objects) : plumbing;;
610 fetch-pack) : plumbing;;
611 fmt-merge-msg) : plumbing;;
612 for-each-ref) : plumbing;;
613 hash-object) : plumbing;;
614 http-*) : transport;;
615 index-pack) : plumbing;;
616 init-db) : deprecated;;
617 local-fetch) : plumbing;;
618 lost-found) : infrequent;;
619 ls-files) : plumbing;;
620 ls-remote) : plumbing;;
621 ls-tree) : plumbing;;
622 mailinfo) : plumbing;;
623 mailsplit) : plumbing;;
624 merge-*) : plumbing;;
627 pack-objects) : plumbing;;
628 pack-redundant) : plumbing;;
629 pack-refs) : plumbing;;
630 parse-remote) : plumbing;;
631 patch-id) : plumbing;;
632 peek-remote) : plumbing;;
634 prune-packed) : plumbing;;
635 quiltimport) : import;;
636 read-tree) : plumbing;;
637 receive-pack) : plumbing;;
638 remote-*) : transport;;
639 repo-config) : deprecated;;
641 rev-list) : plumbing;;
642 rev-parse) : plumbing;;
643 runstatus) : plumbing;;
644 sh-setup) : internal;;
646 show-ref) : plumbing;;
647 send-pack) : plumbing;;
648 show-index) : plumbing;;
650 stripspace) : plumbing;;
651 symbolic-ref) : plumbing;;
652 tar-tree) : deprecated;;
653 unpack-file) : plumbing;;
654 unpack-objects) : plumbing;;
655 update-index) : plumbing;;
656 update-ref) : plumbing;;
657 update-server-info) : daemon;;
658 upload-archive) : plumbing;;
659 upload-pack) : plumbing;;
660 write-tree) : plumbing;;
662 verify-pack) : infrequent;;
663 verify-tag) : plumbing;;
669 __git_porcelain_commands=
670 __git_compute_porcelain_commands ()
672 __git_compute_all_commands
673 test -n "$__git_porcelain_commands" ||
674 __git_porcelain_commands=$(__git_list_porcelain_commands)
677 __git_pretty_aliases ()
680 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
693 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
703 # __git_aliased_command requires 1 argument
704 __git_aliased_command ()
706 local word cmdline=$(git --git-dir="$(__gitdir)" \
707 config --get "alias.$1")
708 for word in $cmdline; do
714 \!*) : shell command alias ;;
716 *=*) : setting env ;;
725 # __git_find_on_cmdline requires 1 argument
726 __git_find_on_cmdline ()
728 local word subcommand c=1
729 while [ $c -lt $cword ]; do
731 for subcommand in $1; do
732 if [ "$subcommand" = "$word" ]; then
741 __git_has_doubledash ()
744 while [ $c -lt $cword ]; do
745 if [ "--" = "${words[c]}" ]; then
753 __git_whitespacelist="nowarn warn error error-all fix"
757 local dir="$(__gitdir)"
758 if [ -d "$dir"/rebase-apply ]; then
759 __gitcomp "--skip --continue --resolved --abort"
764 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
769 --3way --committer-date-is-author-date --ignore-date
770 --ignore-whitespace --ignore-space-change
771 --interactive --keep --no-utf8 --signoff --utf8
772 --whitespace= --scissors
783 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
788 --stat --numstat --summary --check --index
789 --cached --index-info --reverse --reject --unidiff-zero
790 --apply --no-add --exclude=
791 --ignore-whitespace --ignore-space-change
792 --whitespace= --inaccurate-eof --verbose
801 __git_has_doubledash && return
806 --interactive --refresh --patch --update --dry-run
807 --ignore-errors --intent-to-add
818 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
822 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
827 --format= --list --verbose
828 --prefix= --remote= --exec=
838 __git_has_doubledash && return
840 local subcommands="start bad good skip reset visualize replay log run"
841 local subcommand="$(__git_find_on_cmdline "$subcommands")"
842 if [ -z "$subcommand" ]; then
843 if [ -f "$(__gitdir)"/BISECT_START ]; then
844 __gitcomp "$subcommands"
846 __gitcomp "replay start"
851 case "$subcommand" in
852 bad|good|reset|skip|start)
853 __gitcomp_nl "$(__git_refs)"
863 local i c=1 only_local_ref="n" has_r="n"
865 while [ $c -lt $cword ]; do
868 -d|-m) only_local_ref="y" ;;
877 --color --no-color --verbose --abbrev= --no-abbrev
878 --track --no-track --contains --merged --no-merged
879 --set-upstream --edit-description --list
883 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
884 __gitcomp_nl "$(__git_heads)"
886 __gitcomp_nl "$(__git_refs)"
894 local cmd="${words[2]}"
897 __gitcomp "create list-heads verify unbundle"
905 __git_complete_revlist
914 __git_has_doubledash && return
918 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
922 --quiet --ours --theirs --track --no-track --merge
923 --conflict= --orphan --patch
927 # check if --track, --no-track, or --no-guess was specified
928 # if so, disable DWIM mode
929 local flags="--track --no-track --no-guess" track=1
930 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
933 __gitcomp_nl "$(__git_refs '' $track)"
940 __gitcomp "$(__git_refs)"
947 __gitcomp "--edit --no-commit"
950 __gitcomp_nl "$(__git_refs)"
957 __git_has_doubledash && return
961 __gitcomp "--dry-run --quiet"
994 __git_has_doubledash && return
998 __gitcomp "default strip verbatim whitespace
999 " "" "${cur##--cleanup=}"
1002 --reuse-message=*|--reedit-message=*|\
1003 --fixup=*|--squash=*)
1004 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1007 --untracked-files=*)
1008 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1013 --all --author= --signoff --verify --no-verify
1014 --edit --amend --include --only --interactive
1015 --dry-run --reuse-message= --reedit-message=
1016 --reset-author --file= --message= --template=
1017 --cleanup= --untracked-files --untracked-files=
1018 --verbose --quiet --fixup= --squash=
1030 --all --tags --contains --abbrev= --candidates=
1031 --exact-match --debug --long --match --always
1035 __gitcomp_nl "$(__git_refs)"
1038 __git_diff_common_options="--stat --numstat --shortstat --summary
1039 --patch-with-stat --name-only --name-status --color
1040 --no-color --color-words --no-renames --check
1041 --full-index --binary --abbrev --diff-filter=
1042 --find-copies-harder
1043 --text --ignore-space-at-eol --ignore-space-change
1044 --ignore-all-space --exit-code --quiet --ext-diff
1046 --no-prefix --src-prefix= --dst-prefix=
1047 --inter-hunk-context=
1050 --dirstat --dirstat= --dirstat-by-file
1051 --dirstat-by-file= --cumulative
1056 __git_has_doubledash && return
1060 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1061 --base --ours --theirs --no-index
1062 $__git_diff_common_options
1067 __git_complete_revlist_file
1070 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1071 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
1076 __git_has_doubledash && return
1080 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1084 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1085 --base --ours --theirs
1086 --no-renames --diff-filter= --find-copies-harder
1087 --relative --ignore-submodules
1095 __git_fetch_options="
1096 --quiet --verbose --append --upload-pack --force --keep --depth=
1097 --tags --no-tags --all --prune --dry-run
1104 __gitcomp "$__git_fetch_options"
1108 __git_complete_remote_or_refspec
1111 _git_format_patch ()
1117 " "" "${cur##--thread=}"
1122 --stdout --attach --no-attach --thread --thread=
1124 --numbered --start-number
1127 --signoff --signature --no-signature
1128 --in-reply-to= --cc=
1129 --full-index --binary
1132 --no-prefix --src-prefix= --dst-prefix=
1133 --inline --suffix= --ignore-if-in-upstream
1139 __git_complete_revlist
1147 --tags --root --unreachable --cache --no-reflogs --full
1148 --strict --verbose --lost-found
1160 __gitcomp "--prune --aggressive"
1172 __git_match_ctag() {
1173 awk "/^${1////\\/}/ { print \$1 }" "$2"
1178 __git_has_doubledash && return
1184 --text --ignore-case --word-regexp --invert-match
1185 --full-name --line-number
1186 --extended-regexp --basic-regexp --fixed-strings
1188 --files-with-matches --name-only
1189 --files-without-match
1192 --and --or --not --all-match
1198 case "$cword,$prev" in
1200 if test -r tags; then
1201 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1207 __gitcomp_nl "$(__git_refs)"
1214 __gitcomp "--all --info --man --web"
1218 __git_compute_all_commands
1219 __gitcomp "$__git_all_commands $(__git_aliases)
1220 attributes cli core-tutorial cvs-migration
1221 diffcore gitk glossary hooks ignore modules
1222 namespaces repository-layout tutorial tutorial-2
1232 false true umask group all world everybody
1233 " "" "${cur##--shared=}"
1237 __gitcomp "--quiet --bare --template= --shared --shared="
1246 __git_has_doubledash && return
1250 __gitcomp "--cached --deleted --modified --others --ignored
1251 --stage --directory --no-empty-directory --unmerged
1252 --killed --exclude= --exclude-from=
1253 --exclude-per-directory= --exclude-standard
1254 --error-unmatch --with-tree= --full-name
1255 --abbrev --ignored --exclude-per-directory
1265 __gitcomp_nl "$(__git_remotes)"
1273 # Options that go well for log, shortlog and gitk
1274 __git_log_common_options="
1276 --branches --tags --remotes
1277 --first-parent --merges --no-merges
1279 --max-age= --since= --after=
1280 --min-age= --until= --before=
1281 --min-parents= --max-parents=
1282 --no-min-parents --no-max-parents
1284 # Options that go well for log and gitk (not shortlog)
1285 __git_log_gitk_options="
1286 --dense --sparse --full-history
1287 --simplify-merges --simplify-by-decoration
1288 --left-right --notes --no-notes
1290 # Options that go well for log and shortlog (not gitk)
1291 __git_log_shortlog_options="
1292 --author= --committer= --grep=
1296 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1297 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1301 __git_has_doubledash && return
1303 local g="$(git rev-parse --git-dir 2>/dev/null)"
1305 if [ -f "$g/MERGE_HEAD" ]; then
1309 --pretty=*|--format=*)
1310 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1315 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1319 __gitcomp "long short" "" "${cur##--decorate=}"
1324 $__git_log_common_options
1325 $__git_log_shortlog_options
1326 $__git_log_gitk_options
1327 --root --topo-order --date-order --reverse
1328 --follow --full-diff
1329 --abbrev-commit --abbrev=
1330 --relative-date --date=
1331 --pretty= --format= --oneline
1334 --decorate --decorate=
1336 --parents --children
1338 $__git_diff_common_options
1339 --pickaxe-all --pickaxe-regex
1344 __git_complete_revlist
1347 __git_merge_options="
1348 --no-commit --no-stat --log --no-log --squash --strategy
1349 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1354 __git_complete_strategy && return
1358 __gitcomp "$__git_merge_options"
1361 __gitcomp_nl "$(__git_refs)"
1368 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1381 __gitcomp_nl "$(__git_refs)"
1388 __gitcomp "--dry-run"
1397 __gitcomp "--tags --all --stdin"
1402 local subcommands='add append copy edit list prune remove show'
1403 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1405 case "$subcommand,$cur" in
1412 __gitcomp_nl "$(__git_refs)"
1415 __gitcomp "$subcommands --ref"
1419 add,--reuse-message=*|append,--reuse-message=*|\
1420 add,--reedit-message=*|append,--reedit-message=*)
1421 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1424 __gitcomp '--file= --message= --reedit-message=
1431 __gitcomp '--dry-run --verbose'
1440 __gitcomp_nl "$(__git_refs)"
1449 __git_complete_strategy && return
1454 --rebase --no-rebase
1455 $__git_merge_options
1456 $__git_fetch_options
1461 __git_complete_remote_or_refspec
1468 __gitcomp_nl "$(__git_remotes)"
1473 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1478 --all --mirror --tags --dry-run --force --verbose
1479 --receive-pack= --repo= --set-upstream
1484 __git_complete_remote_or_refspec
1489 local dir="$(__gitdir)"
1490 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1491 __gitcomp "--continue --skip --abort"
1494 __git_complete_strategy && return
1497 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1502 --onto --merge --strategy --interactive
1503 --preserve-merges --stat --no-stat
1504 --committer-date-is-author-date --ignore-date
1505 --ignore-whitespace --whitespace=
1511 __gitcomp_nl "$(__git_refs)"
1516 local subcommands="show delete expire"
1517 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1519 if [ -z "$subcommand" ]; then
1520 __gitcomp "$subcommands"
1522 __gitcomp_nl "$(__git_refs)"
1526 __git_send_email_confirm_options="always never auto cc compose"
1527 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1534 $__git_send_email_confirm_options
1535 " "" "${cur##--confirm=}"
1540 $__git_send_email_suppresscc_options
1541 " "" "${cur##--suppress-cc=}"
1545 --smtp-encryption=*)
1546 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1550 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1551 --compose --confirm= --dry-run --envelope-sender
1553 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1554 --no-suppress-from --no-thread --quiet
1555 --signed-off-by-cc --smtp-pass --smtp-server
1556 --smtp-server-port --smtp-encryption= --smtp-user
1557 --subject --suppress-cc= --suppress-from --thread --to
1558 --validate --no-validate"
1570 __git_config_get_set_variables ()
1572 local prevword word config_file= c=$cword
1573 while [ $c -gt 1 ]; do
1576 --global|--system|--file=*)
1581 config_file="$word $prevword"
1589 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1604 __gitcomp_nl "$(__git_remotes)"
1608 __gitcomp_nl "$(__git_refs)"
1612 local remote="${prev#remote.}"
1613 remote="${remote%.fetch}"
1614 if [ -z "$cur" ]; then
1615 COMPREPLY=("refs/heads/")
1618 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1622 local remote="${prev#remote.}"
1623 remote="${remote%.push}"
1624 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1625 for-each-ref --format='%(refname):%(refname)' \
1629 pull.twohead|pull.octopus)
1630 __git_compute_merge_strategies
1631 __gitcomp "$__git_merge_strategies"
1634 color.branch|color.diff|color.interactive|\
1635 color.showbranch|color.status|color.ui)
1636 __gitcomp "always never auto"
1640 __gitcomp "false true"
1645 normal black red green yellow blue magenta cyan white
1646 bold dim ul blink reverse
1651 __gitcomp "man info web html"
1655 __gitcomp "$__git_log_date_formats"
1658 sendemail.aliasesfiletype)
1659 __gitcomp "mutt mailrc pine elm gnus"
1663 __gitcomp "$__git_send_email_confirm_options"
1666 sendemail.suppresscc)
1667 __gitcomp "$__git_send_email_suppresscc_options"
1670 --get|--get-all|--unset|--unset-all)
1671 __gitcomp_nl "$(__git_config_get_set_variables)"
1682 --global --system --file=
1683 --list --replace-all
1684 --get --get-all --get-regexp
1685 --add --unset --unset-all
1686 --remove-section --rename-section
1691 local pfx="${cur%.*}." cur_="${cur##*.}"
1692 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1696 local pfx="${cur%.*}." cur_="${cur#*.}"
1697 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1701 local pfx="${cur%.*}." cur_="${cur##*.}"
1703 argprompt cmd confirm needsfile noconsole norescan
1704 prompt revprompt revunmerged title
1709 local pfx="${cur%.*}." cur_="${cur##*.}"
1710 __gitcomp "cmd path" "$pfx" "$cur_"
1714 local pfx="${cur%.*}." cur_="${cur##*.}"
1715 __gitcomp "cmd path" "$pfx" "$cur_"
1719 local pfx="${cur%.*}." cur_="${cur##*.}"
1720 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1724 local pfx="${cur%.*}." cur_="${cur#*.}"
1725 __git_compute_all_commands
1726 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1730 local pfx="${cur%.*}." cur_="${cur##*.}"
1732 url proxy fetch push mirror skipDefaultUpdate
1733 receivepack uploadpack tagopt pushurl
1738 local pfx="${cur%.*}." cur_="${cur#*.}"
1739 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1743 local pfx="${cur%.*}." cur_="${cur##*.}"
1744 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1750 advice.commitBeforeMerge
1752 advice.implicitIdentity
1753 advice.pushNonFastForward
1754 advice.resolveConflict
1758 apply.ignorewhitespace
1760 branch.autosetupmerge
1761 branch.autosetuprebase
1765 color.branch.current
1770 color.decorate.branch
1771 color.decorate.remoteBranch
1772 color.decorate.stash
1782 color.diff.whitespace
1787 color.grep.linenumber
1790 color.grep.separator
1792 color.interactive.error
1793 color.interactive.header
1794 color.interactive.help
1795 color.interactive.prompt
1800 color.status.changed
1802 color.status.nobranch
1803 color.status.untracked
1804 color.status.updated
1813 core.bigFileThreshold
1816 core.deltaBaseCacheLimit
1821 core.fsyncobjectfiles
1823 core.ignoreCygwinFSTricks
1826 core.logAllRefUpdates
1827 core.loosecompression
1830 core.packedGitWindowSize
1832 core.preferSymlinkRefs
1835 core.repositoryFormatVersion
1837 core.sharedRepository
1841 core.warnAmbiguousRefs
1844 diff.autorefreshindex
1847 diff.ignoreSubmodules
1852 diff.suppressBlankEmpty
1857 fetch.recurseSubmodules
1866 format.subjectprefix
1877 gc.reflogexpireunreachable
1881 gitcvs.commitmsgannotation
1882 gitcvs.dbTableNamePrefix
1893 gui.copyblamethreshold
1897 gui.matchtrackingbranch
1898 gui.newbranchtemplate
1899 gui.pruneduringfetch
1900 gui.spellingdictionary
1915 http.sslCertPasswordProtected
1920 i18n.logOutputEncoding
1926 imap.preformattedHTML
1936 interactive.singlekey
1952 mergetool.keepBackup
1953 mergetool.keepTemporaries
1958 notes.rewrite.rebase
1962 pack.deltaCacheLimit
1978 receive.denyCurrentBranch
1979 receive.denyDeleteCurrent
1981 receive.denyNonFastForwards
1984 receive.updateserverinfo
1986 repack.usedeltabaseoffset
1990 sendemail.aliasesfile
1991 sendemail.aliasfiletype
1995 sendemail.chainreplyto
1997 sendemail.envelopesender
2001 sendemail.signedoffbycc
2002 sendemail.smtpdomain
2003 sendemail.smtpencryption
2005 sendemail.smtpserver
2006 sendemail.smtpserveroption
2007 sendemail.smtpserverport
2009 sendemail.suppresscc
2010 sendemail.suppressfrom
2015 status.relativePaths
2016 status.showUntrackedFiles
2017 status.submodulesummary
2020 transfer.unpackLimit
2032 local subcommands="add rename rm set-head set-branches set-url show prune update"
2033 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2034 if [ -z "$subcommand" ]; then
2035 __gitcomp "$subcommands"
2039 case "$subcommand" in
2040 rename|rm|set-url|show|prune)
2041 __gitcomp_nl "$(__git_remotes)"
2043 set-head|set-branches)
2044 __git_complete_remote_or_refspec
2047 local i c='' IFS=$'\n'
2048 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2062 __gitcomp_nl "$(__git_refs)"
2067 __git_has_doubledash && return
2071 __gitcomp "--merge --mixed --hard --soft --patch"
2075 __gitcomp_nl "$(__git_refs)"
2082 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2086 __gitcomp_nl "$(__git_refs)"
2091 __git_has_doubledash && return
2095 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2104 __git_has_doubledash && return
2109 $__git_log_common_options
2110 $__git_log_shortlog_options
2111 --numbered --summary
2116 __git_complete_revlist
2121 __git_has_doubledash && return
2124 --pretty=*|--format=*)
2125 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2130 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2131 $__git_diff_common_options
2144 --all --remotes --topo-order --current --more=
2145 --list --independent --merge-base --no-name
2147 --sha1-name --sparse --topics --reflog
2152 __git_complete_revlist
2157 local save_opts='--keep-index --no-keep-index --quiet --patch'
2158 local subcommands='save list show apply clear drop pop create branch'
2159 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2160 if [ -z "$subcommand" ]; then
2163 __gitcomp "$save_opts"
2166 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2167 __gitcomp "$subcommands"
2174 case "$subcommand,$cur" in
2176 __gitcomp "$save_opts"
2179 __gitcomp "--index --quiet"
2181 show,--*|drop,--*|branch,--*)
2184 show,*|apply,*|drop,*|pop,*|branch,*)
2185 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2186 | sed -n -e 's/:.*//p')"
2197 __git_has_doubledash && return
2199 local subcommands="add status init update summary foreach sync"
2200 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2203 __gitcomp "--quiet --cached"
2206 __gitcomp "$subcommands"
2216 init fetch clone rebase dcommit log find-rev
2217 set-tree commit-diff info create-ignore propget
2218 proplist show-ignore show-externals branch tag blame
2219 migrate mkdirs reset gc
2221 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2222 if [ -z "$subcommand" ]; then
2223 __gitcomp "$subcommands"
2225 local remote_opts="--username= --config-dir= --no-auth-cache"
2227 --follow-parent --authors-file= --repack=
2228 --no-metadata --use-svm-props --use-svnsync-props
2229 --log-window-size= --no-checkout --quiet
2230 --repack-flags --use-log-author --localtime
2231 --ignore-paths= $remote_opts
2234 --template= --shared= --trunk= --tags=
2235 --branches= --stdlayout --minimize-url
2236 --no-metadata --use-svm-props --use-svnsync-props
2237 --rewrite-root= --prefix= --use-log-author
2238 --add-author-from $remote_opts
2241 --edit --rmdir --find-copies-harder --copy-similarity=
2244 case "$subcommand,$cur" in
2246 __gitcomp "--revision= --fetch-all $fc_opts"
2249 __gitcomp "--revision= $fc_opts $init_opts"
2252 __gitcomp "$init_opts"
2256 --merge --strategy= --verbose --dry-run
2257 --fetch-all --no-rebase --commit-url
2258 --revision --interactive $cmt_opts $fc_opts
2262 __gitcomp "--stdin $cmt_opts $fc_opts"
2264 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2265 show-externals,--*|mkdirs,--*)
2266 __gitcomp "--revision="
2270 --limit= --revision= --verbose --incremental
2271 --oneline --show-commit --non-recursive
2272 --authors-file= --color
2277 --merge --verbose --strategy= --local
2278 --fetch-all --dry-run $fc_opts
2282 __gitcomp "--message= --file= --revision= $cmt_opts"
2288 __gitcomp "--dry-run --message --tag"
2291 __gitcomp "--dry-run --message"
2294 __gitcomp "--git-format"
2298 --config-dir= --ignore-paths= --minimize
2299 --no-auth-cache --username=
2303 __gitcomp "--revision= --parent"
2315 while [ $c -lt $cword ]; do
2319 __gitcomp_nl "$(__git_tags)"
2335 __gitcomp_nl "$(__git_tags)"
2341 __gitcomp_nl "$(__git_refs)"
2353 local i c=1 command __git_dir
2355 while [ $c -lt $cword ]; do
2358 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2359 --bare) __git_dir="." ;;
2360 --help) command="help"; break ;;
2363 *) command="$i"; break ;;
2368 if [ -z "$command" ]; then
2382 --no-replace-objects
2386 *) __git_compute_porcelain_commands
2387 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2392 local completion_func="_git_${command//-/_}"
2393 declare -f $completion_func >/dev/null && $completion_func && return
2395 local expansion=$(__git_aliased_command "$command")
2396 if [ -n "$expansion" ]; then
2397 completion_func="_git_${expansion//-/_}"
2398 declare -f $completion_func >/dev/null && $completion_func
2404 __git_has_doubledash && return
2406 local g="$(__gitdir)"
2408 if [ -f "$g/MERGE_HEAD" ]; then
2414 $__git_log_common_options
2415 $__git_log_gitk_options
2421 __git_complete_revlist
2426 if [[ -n ${ZSH_VERSION-} ]]; then
2430 # workaround zsh's bug that leaves 'words' as a special
2431 # variable in versions < 4.3.12
2434 # workaround zsh's bug that quotes spaces in the COMPREPLY
2435 # array if IFS doesn't contain spaces.
2438 local cur words cword prev
2439 _get_comp_words_by_ref -n =: cur words cword prev
2443 # Setup completion for certain functions defined above by setting common
2444 # variables and workarounds.
2445 # This is NOT a public function; use at your own risk.
2448 local wrapper="__git_wrap${2}"
2449 eval "$wrapper () { __git_func_wrap $2 ; }"
2450 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2451 || complete -o default -o nospace -F $wrapper $1
2454 __git_complete git _git
2455 __git_complete gitk _gitk
2457 # The following are necessary only for Cygwin, and only are needed
2458 # when the user has tab-completed the executable name and consequently
2459 # included the '.exe' suffix.
2461 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2462 __git_complete git.exe _git