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 case "$COMP_WORDBREAKS" in
28 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
31 # __gitdir accepts 0 or 1 arguments (i.e., location)
32 # returns location of .git repo
35 # Note: this function is duplicated in git-prompt.sh
36 # When updating it, make sure you update the other one to match.
37 if [ -z "${1-}" ]; then
38 if [ -n "${__git_dir-}" ]; then
40 elif [ -n "${GIT_DIR-}" ]; then
41 test -d "${GIT_DIR-}" || return 1
43 elif [ -d .git ]; then
46 git rev-parse --git-dir 2>/dev/null
48 elif [ -d "$1/.git" ]; then
68 # The following function is based on code from:
70 # bash_completion - programmable completion functions for bash 3.2+
72 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
73 # © 2009-2010, Bash Completion Maintainers
74 # <bash-completion-devel@lists.alioth.debian.org>
76 # This program is free software; you can redistribute it and/or modify
77 # it under the terms of the GNU General Public License as published by
78 # the Free Software Foundation; either version 2, or (at your option)
81 # This program is distributed in the hope that it will be useful,
82 # but WITHOUT ANY WARRANTY; without even the implied warranty of
83 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84 # GNU General Public License for more details.
86 # You should have received a copy of the GNU General Public License
87 # along with this program; if not, write to the Free Software Foundation,
88 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
90 # The latest version of this software can be obtained here:
92 # http://bash-completion.alioth.debian.org/
96 # This function can be used to access a tokenized list of words
97 # on the command line:
99 # __git_reassemble_comp_words_by_ref '=:'
100 # if test "${words_[cword_-1]}" = -w
105 # The argument should be a collection of characters from the list of
106 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
109 # This is roughly equivalent to going back in time and setting
110 # COMP_WORDBREAKS to exclude those characters. The intent is to
111 # make option types like --date=<type> and <rev>:<path> easy to
112 # recognize by treating each shell word as a single token.
114 # It is best not to set COMP_WORDBREAKS directly because the value is
115 # shared with other completion scripts. By the time the completion
116 # function gets called, COMP_WORDS has already been populated so local
117 # changes to COMP_WORDBREAKS have no effect.
119 # Output: words_, cword_, cur_.
121 __git_reassemble_comp_words_by_ref()
123 local exclude i j first
124 # Which word separators to exclude?
125 exclude="${1//[^$COMP_WORDBREAKS]}"
127 if [ -z "$exclude" ]; then
128 words_=("${COMP_WORDS[@]}")
131 # List of word completion separators has shrunk;
132 # re-assemble words to complete.
133 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
134 # Append each nonempty word consisting of just
135 # word separator characters to the current word.
139 [ -n "${COMP_WORDS[$i]}" ] &&
140 # word consists of excluded word separators
141 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
143 # Attach to the previous token,
144 # unless the previous token is the command name.
145 if [ $j -ge 2 ] && [ -n "$first" ]; then
149 words_[$j]=${words_[j]}${COMP_WORDS[i]}
150 if [ $i = $COMP_CWORD ]; then
153 if (($i < ${#COMP_WORDS[@]} - 1)); then
160 words_[$j]=${words_[j]}${COMP_WORDS[i]}
161 if [ $i = $COMP_CWORD ]; then
167 if ! type _get_comp_words_by_ref >/dev/null 2>&1; 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_[@]}")
197 # Generates completion reply with compgen, appending a space to possible
198 # completion words, if necessary.
199 # It accepts 1 to 4 arguments:
200 # 1: List of possible completion words.
201 # 2: A prefix to be added to each possible completion word (optional).
202 # 3: Generate possible completion matches for this word (optional).
203 # 4: A suffix to be appended to each possible completion word (optional).
206 local cur_="${3-$cur}"
214 COMPREPLY=($(compgen -P "${2-}" \
215 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
221 # Generates completion reply with compgen from newline-separated possible
222 # completion words by appending a space to all of them.
223 # It accepts 1 to 4 arguments:
224 # 1: List of possible completion words, separated by a single newline.
225 # 2: A prefix to be added to each possible completion word (optional).
226 # 3: Generate possible completion matches for this word (optional).
227 # 4: A suffix to be appended to each possible completion word instead of
228 # the default space (optional). If specified but empty, nothing is
233 COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
238 local dir="$(__gitdir)"
239 if [ -d "$dir" ]; then
240 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
248 local dir="$(__gitdir)"
249 if [ -d "$dir" ]; then
250 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
256 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
257 # presence of 2nd argument means use the guess heuristic employed
258 # by checkout for tracking branches
261 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
263 if [ -d "$dir" ]; then
271 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
272 if [ -e "$dir/$i" ]; then echo $i; fi
274 format="refname:short"
275 refs="refs/tags refs/heads refs/remotes"
278 git --git-dir="$dir" for-each-ref --format="%($format)" \
280 if [ -n "$track" ]; then
281 # employ the heuristic used by git checkout
282 # Try to find a remote branch that matches the completion word
283 # but only output if the branch name is unique
285 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
287 while read -r entry; do
290 if [[ "$ref" == "$cur"* ]]; then
293 done | sort | uniq -u
299 git ls-remote "$dir" "$cur*" 2>/dev/null | \
300 while read -r hash i; do
308 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
309 while read -r hash i; do
312 refs/*) echo "${i#refs/*/}" ;;
320 # __git_refs2 requires 1 argument (to pass to __git_refs)
324 for i in $(__git_refs "$1"); do
329 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
330 __git_refs_remotes ()
333 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
334 while read -r hash i; do
335 echo "$i:refs/remotes/$1/${i#refs/heads/}"
341 local i IFS=$'\n' d="$(__gitdir)"
342 test -d "$d/remotes" && ls -1 "$d/remotes"
343 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
349 __git_list_merge_strategies ()
351 git merge -s help 2>&1 |
352 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
361 __git_merge_strategies=
362 # 'git merge -s help' (and thus detection of the merge strategy
363 # list) fails, unfortunately, if run outside of any git working
364 # tree. __git_merge_strategies is set to the empty string in
365 # that case, and the detection will be repeated the next time it
367 __git_compute_merge_strategies ()
369 test -n "$__git_merge_strategies" ||
370 __git_merge_strategies=$(__git_list_merge_strategies)
373 __git_complete_revlist_file ()
375 local pfx ls ref cur_="$cur"
395 case "$COMP_WORDBREAKS" in
397 *) pfx="$ref:$pfx" ;;
400 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
401 | sed '/^100... blob /{
417 pfx="${cur_%...*}..."
419 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
424 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
427 __gitcomp_nl "$(__git_refs)"
433 __git_complete_file ()
435 __git_complete_revlist_file
438 __git_complete_revlist ()
440 __git_complete_revlist_file
443 __git_complete_remote_or_refspec ()
445 local cur_="$cur" cmd="${words[1]}"
446 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
447 if [ "$cmd" = "remote" ]; then
450 while [ $c -lt $cword ]; do
453 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
456 push) no_complete_refspec=1 ;;
465 *) remote="$i"; break ;;
469 if [ -z "$remote" ]; then
470 __gitcomp_nl "$(__git_remotes)"
473 if [ $no_complete_refspec = 1 ]; then
477 [ "$remote" = "." ] && remote=
480 case "$COMP_WORDBREAKS" in
482 *) pfx="${cur_%%:*}:" ;;
494 if [ $lhs = 1 ]; then
495 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
497 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
501 if [ $lhs = 1 ]; then
502 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
504 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
508 if [ $lhs = 1 ]; then
509 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
511 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
517 __git_complete_strategy ()
519 __git_compute_merge_strategies
522 __gitcomp "$__git_merge_strategies"
527 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
535 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
537 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
539 git help -a|egrep '^ [a-zA-Z0-9]'
543 __git_list_all_commands ()
546 for i in $(__git_commands)
549 *--*) : helper pattern;;
556 __git_compute_all_commands ()
558 test -n "$__git_all_commands" ||
559 __git_all_commands=$(__git_list_all_commands)
562 __git_list_porcelain_commands ()
565 __git_compute_all_commands
566 for i in $__git_all_commands
569 *--*) : helper pattern;;
570 applymbox) : ask gittus;;
571 applypatch) : ask gittus;;
572 archimport) : import;;
573 cat-file) : plumbing;;
574 check-attr) : plumbing;;
575 check-ref-format) : plumbing;;
576 checkout-index) : plumbing;;
577 commit-tree) : plumbing;;
578 count-objects) : infrequent;;
579 credential-cache) : credentials helper;;
580 credential-store) : credentials helper;;
581 cvsexportcommit) : export;;
582 cvsimport) : import;;
583 cvsserver) : daemon;;
585 diff-files) : plumbing;;
586 diff-index) : plumbing;;
587 diff-tree) : plumbing;;
588 fast-import) : import;;
589 fast-export) : export;;
590 fsck-objects) : plumbing;;
591 fetch-pack) : plumbing;;
592 fmt-merge-msg) : plumbing;;
593 for-each-ref) : plumbing;;
594 hash-object) : plumbing;;
595 http-*) : transport;;
596 index-pack) : plumbing;;
597 init-db) : deprecated;;
598 local-fetch) : plumbing;;
599 lost-found) : infrequent;;
600 ls-files) : plumbing;;
601 ls-remote) : plumbing;;
602 ls-tree) : plumbing;;
603 mailinfo) : plumbing;;
604 mailsplit) : plumbing;;
605 merge-*) : plumbing;;
608 pack-objects) : plumbing;;
609 pack-redundant) : plumbing;;
610 pack-refs) : plumbing;;
611 parse-remote) : plumbing;;
612 patch-id) : plumbing;;
613 peek-remote) : plumbing;;
615 prune-packed) : plumbing;;
616 quiltimport) : import;;
617 read-tree) : plumbing;;
618 receive-pack) : plumbing;;
619 remote-*) : transport;;
620 repo-config) : deprecated;;
622 rev-list) : plumbing;;
623 rev-parse) : plumbing;;
624 runstatus) : plumbing;;
625 sh-setup) : internal;;
627 show-ref) : plumbing;;
628 send-pack) : plumbing;;
629 show-index) : plumbing;;
631 stripspace) : plumbing;;
632 symbolic-ref) : plumbing;;
633 tar-tree) : deprecated;;
634 unpack-file) : plumbing;;
635 unpack-objects) : plumbing;;
636 update-index) : plumbing;;
637 update-ref) : plumbing;;
638 update-server-info) : daemon;;
639 upload-archive) : plumbing;;
640 upload-pack) : plumbing;;
641 write-tree) : plumbing;;
643 verify-pack) : infrequent;;
644 verify-tag) : plumbing;;
650 __git_porcelain_commands=
651 __git_compute_porcelain_commands ()
653 __git_compute_all_commands
654 test -n "$__git_porcelain_commands" ||
655 __git_porcelain_commands=$(__git_list_porcelain_commands)
658 __git_pretty_aliases ()
661 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
674 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
684 # __git_aliased_command requires 1 argument
685 __git_aliased_command ()
687 local word cmdline=$(git --git-dir="$(__gitdir)" \
688 config --get "alias.$1")
689 for word in $cmdline; do
695 \!*) : shell command alias ;;
697 *=*) : setting env ;;
706 # __git_find_on_cmdline requires 1 argument
707 __git_find_on_cmdline ()
709 local word subcommand c=1
710 while [ $c -lt $cword ]; do
712 for subcommand in $1; do
713 if [ "$subcommand" = "$word" ]; then
722 __git_has_doubledash ()
725 while [ $c -lt $cword ]; do
726 if [ "--" = "${words[c]}" ]; then
734 __git_whitespacelist="nowarn warn error error-all fix"
738 local dir="$(__gitdir)"
739 if [ -d "$dir"/rebase-apply ]; then
740 __gitcomp "--skip --continue --resolved --abort"
745 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
750 --3way --committer-date-is-author-date --ignore-date
751 --ignore-whitespace --ignore-space-change
752 --interactive --keep --no-utf8 --signoff --utf8
753 --whitespace= --scissors
764 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
769 --stat --numstat --summary --check --index
770 --cached --index-info --reverse --reject --unidiff-zero
771 --apply --no-add --exclude=
772 --ignore-whitespace --ignore-space-change
773 --whitespace= --inaccurate-eof --verbose
782 __git_has_doubledash && return
787 --interactive --refresh --patch --update --dry-run
788 --ignore-errors --intent-to-add
799 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
803 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
808 --format= --list --verbose
809 --prefix= --remote= --exec=
819 __git_has_doubledash && return
821 local subcommands="start bad good skip reset visualize replay log run"
822 local subcommand="$(__git_find_on_cmdline "$subcommands")"
823 if [ -z "$subcommand" ]; then
824 if [ -f "$(__gitdir)"/BISECT_START ]; then
825 __gitcomp "$subcommands"
827 __gitcomp "replay start"
832 case "$subcommand" in
833 bad|good|reset|skip|start)
834 __gitcomp_nl "$(__git_refs)"
844 local i c=1 only_local_ref="n" has_r="n"
846 while [ $c -lt $cword ]; do
849 -d|-m) only_local_ref="y" ;;
857 __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
861 --color --no-color --verbose --abbrev= --no-abbrev
862 --track --no-track --contains --merged --no-merged
863 --set-upstream-to= --edit-description --list
868 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
869 __gitcomp_nl "$(__git_heads)"
871 __gitcomp_nl "$(__git_refs)"
879 local cmd="${words[2]}"
882 __gitcomp "create list-heads verify unbundle"
890 __git_complete_revlist
899 __git_has_doubledash && return
903 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
907 --quiet --ours --theirs --track --no-track --merge
908 --conflict= --orphan --patch
912 # check if --track, --no-track, or --no-guess was specified
913 # if so, disable DWIM mode
914 local flags="--track --no-track --no-guess" track=1
915 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
918 __gitcomp_nl "$(__git_refs '' $track)"
925 __gitcomp "$(__git_refs)"
932 __gitcomp "--edit --no-commit"
935 __gitcomp_nl "$(__git_refs)"
942 __git_has_doubledash && return
946 __gitcomp "--dry-run --quiet"
981 __git_has_doubledash && return
985 __gitcomp_nl "$(__git_refs)" "" "${cur}"
992 __gitcomp "default strip verbatim whitespace
993 " "" "${cur##--cleanup=}"
996 --reuse-message=*|--reedit-message=*|\
997 --fixup=*|--squash=*)
998 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1001 --untracked-files=*)
1002 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1007 --all --author= --signoff --verify --no-verify
1009 --amend --include --only --interactive
1010 --dry-run --reuse-message= --reedit-message=
1011 --reset-author --file= --message= --template=
1012 --cleanup= --untracked-files --untracked-files=
1013 --verbose --quiet --fixup= --squash=
1025 --all --tags --contains --abbrev= --candidates=
1026 --exact-match --debug --long --match --always
1030 __gitcomp_nl "$(__git_refs)"
1033 __git_diff_common_options="--stat --numstat --shortstat --summary
1034 --patch-with-stat --name-only --name-status --color
1035 --no-color --color-words --no-renames --check
1036 --full-index --binary --abbrev --diff-filter=
1037 --find-copies-harder
1038 --text --ignore-space-at-eol --ignore-space-change
1039 --ignore-all-space --exit-code --quiet --ext-diff
1041 --no-prefix --src-prefix= --dst-prefix=
1042 --inter-hunk-context=
1045 --dirstat --dirstat= --dirstat-by-file
1046 --dirstat-by-file= --cumulative
1051 __git_has_doubledash && return
1055 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1056 --base --ours --theirs --no-index
1057 $__git_diff_common_options
1062 __git_complete_revlist_file
1065 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1066 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1071 __git_has_doubledash && return
1075 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1079 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1080 --base --ours --theirs
1081 --no-renames --diff-filter= --find-copies-harder
1082 --relative --ignore-submodules
1090 __git_fetch_options="
1091 --quiet --verbose --append --upload-pack --force --keep --depth=
1092 --tags --no-tags --all --prune --dry-run
1099 __gitcomp "$__git_fetch_options"
1103 __git_complete_remote_or_refspec
1106 __git_format_patch_options="
1107 --stdout --attach --no-attach --thread --thread= --output-directory
1108 --numbered --start-number --numbered-files --keep-subject --signoff
1109 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1110 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1111 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1114 _git_format_patch ()
1120 " "" "${cur##--thread=}"
1124 __gitcomp "$__git_format_patch_options"
1128 __git_complete_revlist
1136 --tags --root --unreachable --cache --no-reflogs --full
1137 --strict --verbose --lost-found
1149 __gitcomp "--prune --aggressive"
1161 __git_match_ctag() {
1162 awk "/^${1////\\/}/ { print \$1 }" "$2"
1167 __git_has_doubledash && return
1173 --text --ignore-case --word-regexp --invert-match
1174 --full-name --line-number
1175 --extended-regexp --basic-regexp --fixed-strings
1177 --files-with-matches --name-only
1178 --files-without-match
1181 --and --or --not --all-match
1187 case "$cword,$prev" in
1189 if test -r tags; then
1190 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1196 __gitcomp_nl "$(__git_refs)"
1203 __gitcomp "--all --info --man --web"
1207 __git_compute_all_commands
1208 __gitcomp "$__git_all_commands $(__git_aliases)
1209 attributes cli core-tutorial cvs-migration
1210 diffcore gitk glossary hooks ignore modules
1211 namespaces repository-layout tutorial tutorial-2
1221 false true umask group all world everybody
1222 " "" "${cur##--shared=}"
1226 __gitcomp "--quiet --bare --template= --shared --shared="
1235 __git_has_doubledash && return
1239 __gitcomp "--cached --deleted --modified --others --ignored
1240 --stage --directory --no-empty-directory --unmerged
1241 --killed --exclude= --exclude-from=
1242 --exclude-per-directory= --exclude-standard
1243 --error-unmatch --with-tree= --full-name
1244 --abbrev --ignored --exclude-per-directory
1254 __gitcomp_nl "$(__git_remotes)"
1262 # Options that go well for log, shortlog and gitk
1263 __git_log_common_options="
1265 --branches --tags --remotes
1266 --first-parent --merges --no-merges
1268 --max-age= --since= --after=
1269 --min-age= --until= --before=
1270 --min-parents= --max-parents=
1271 --no-min-parents --no-max-parents
1273 # Options that go well for log and gitk (not shortlog)
1274 __git_log_gitk_options="
1275 --dense --sparse --full-history
1276 --simplify-merges --simplify-by-decoration
1277 --left-right --notes --no-notes
1279 # Options that go well for log and shortlog (not gitk)
1280 __git_log_shortlog_options="
1281 --author= --committer= --grep=
1285 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1286 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1290 __git_has_doubledash && return
1292 local g="$(git rev-parse --git-dir 2>/dev/null)"
1294 if [ -f "$g/MERGE_HEAD" ]; then
1298 --pretty=*|--format=*)
1299 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1304 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1308 __gitcomp "long short" "" "${cur##--decorate=}"
1313 $__git_log_common_options
1314 $__git_log_shortlog_options
1315 $__git_log_gitk_options
1316 --root --topo-order --date-order --reverse
1317 --follow --full-diff
1318 --abbrev-commit --abbrev=
1319 --relative-date --date=
1320 --pretty= --format= --oneline
1323 --decorate --decorate=
1325 --parents --children
1327 $__git_diff_common_options
1328 --pickaxe-all --pickaxe-regex
1333 __git_complete_revlist
1336 __git_merge_options="
1337 --no-commit --no-stat --log --no-log --squash --strategy
1338 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1343 __git_complete_strategy && return
1347 __gitcomp "$__git_merge_options"
1350 __gitcomp_nl "$(__git_refs)"
1357 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1370 __gitcomp_nl "$(__git_refs)"
1377 __gitcomp "--dry-run"
1386 __gitcomp "--tags --all --stdin"
1391 local subcommands='add append copy edit list prune remove show'
1392 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1394 case "$subcommand,$cur" in
1401 __gitcomp_nl "$(__git_refs)"
1404 __gitcomp "$subcommands --ref"
1408 add,--reuse-message=*|append,--reuse-message=*|\
1409 add,--reedit-message=*|append,--reedit-message=*)
1410 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1413 __gitcomp '--file= --message= --reedit-message=
1420 __gitcomp '--dry-run --verbose'
1429 __gitcomp_nl "$(__git_refs)"
1438 __git_complete_strategy && return
1443 --rebase --no-rebase
1444 $__git_merge_options
1445 $__git_fetch_options
1450 __git_complete_remote_or_refspec
1457 __gitcomp_nl "$(__git_remotes)"
1462 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1467 --all --mirror --tags --dry-run --force --verbose
1468 --receive-pack= --repo= --set-upstream
1473 __git_complete_remote_or_refspec
1478 local dir="$(__gitdir)"
1479 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1480 __gitcomp "--continue --skip --abort"
1483 __git_complete_strategy && return
1486 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1491 --onto --merge --strategy --interactive
1492 --preserve-merges --stat --no-stat
1493 --committer-date-is-author-date --ignore-date
1494 --ignore-whitespace --whitespace=
1500 __gitcomp_nl "$(__git_refs)"
1505 local subcommands="show delete expire"
1506 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1508 if [ -z "$subcommand" ]; then
1509 __gitcomp "$subcommands"
1511 __gitcomp_nl "$(__git_refs)"
1515 __git_send_email_confirm_options="always never auto cc compose"
1516 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1523 $__git_send_email_confirm_options
1524 " "" "${cur##--confirm=}"
1529 $__git_send_email_suppresscc_options
1530 " "" "${cur##--suppress-cc=}"
1534 --smtp-encryption=*)
1535 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1541 " "" "${cur##--thread=}"
1545 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1546 --compose --confirm= --dry-run --envelope-sender
1548 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1549 --no-suppress-from --no-thread --quiet
1550 --signed-off-by-cc --smtp-pass --smtp-server
1551 --smtp-server-port --smtp-encryption= --smtp-user
1552 --subject --suppress-cc= --suppress-from --thread --to
1553 --validate --no-validate
1554 $__git_format_patch_options"
1558 __git_complete_revlist
1566 __git_config_get_set_variables ()
1568 local prevword word config_file= c=$cword
1569 while [ $c -gt 1 ]; do
1572 --global|--system|--file=*)
1577 config_file="$word $prevword"
1585 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1600 __gitcomp_nl "$(__git_remotes)"
1604 __gitcomp_nl "$(__git_refs)"
1608 local remote="${prev#remote.}"
1609 remote="${remote%.fetch}"
1610 if [ -z "$cur" ]; then
1611 COMPREPLY=("refs/heads/")
1614 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1618 local remote="${prev#remote.}"
1619 remote="${remote%.push}"
1620 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1621 for-each-ref --format='%(refname):%(refname)' \
1625 pull.twohead|pull.octopus)
1626 __git_compute_merge_strategies
1627 __gitcomp "$__git_merge_strategies"
1630 color.branch|color.diff|color.interactive|\
1631 color.showbranch|color.status|color.ui)
1632 __gitcomp "always never auto"
1636 __gitcomp "false true"
1641 normal black red green yellow blue magenta cyan white
1642 bold dim ul blink reverse
1647 __gitcomp "man info web html"
1651 __gitcomp "$__git_log_date_formats"
1654 sendemail.aliasesfiletype)
1655 __gitcomp "mutt mailrc pine elm gnus"
1659 __gitcomp "$__git_send_email_confirm_options"
1662 sendemail.suppresscc)
1663 __gitcomp "$__git_send_email_suppresscc_options"
1666 --get|--get-all|--unset|--unset-all)
1667 __gitcomp_nl "$(__git_config_get_set_variables)"
1678 --global --system --file=
1679 --list --replace-all
1680 --get --get-all --get-regexp
1681 --add --unset --unset-all
1682 --remove-section --rename-section
1687 local pfx="${cur%.*}." cur_="${cur##*.}"
1688 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1692 local pfx="${cur%.*}." cur_="${cur#*.}"
1693 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1697 local pfx="${cur%.*}." cur_="${cur##*.}"
1699 argprompt cmd confirm needsfile noconsole norescan
1700 prompt revprompt revunmerged title
1705 local pfx="${cur%.*}." cur_="${cur##*.}"
1706 __gitcomp "cmd path" "$pfx" "$cur_"
1710 local pfx="${cur%.*}." cur_="${cur##*.}"
1711 __gitcomp "cmd path" "$pfx" "$cur_"
1715 local pfx="${cur%.*}." cur_="${cur##*.}"
1716 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1720 local pfx="${cur%.*}." cur_="${cur#*.}"
1721 __git_compute_all_commands
1722 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1726 local pfx="${cur%.*}." cur_="${cur##*.}"
1728 url proxy fetch push mirror skipDefaultUpdate
1729 receivepack uploadpack tagopt pushurl
1734 local pfx="${cur%.*}." cur_="${cur#*.}"
1735 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1739 local pfx="${cur%.*}." cur_="${cur##*.}"
1740 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1746 advice.commitBeforeMerge
1748 advice.implicitIdentity
1749 advice.pushNonFastForward
1750 advice.resolveConflict
1754 apply.ignorewhitespace
1756 branch.autosetupmerge
1757 branch.autosetuprebase
1761 color.branch.current
1766 color.decorate.branch
1767 color.decorate.remoteBranch
1768 color.decorate.stash
1778 color.diff.whitespace
1783 color.grep.linenumber
1786 color.grep.separator
1788 color.interactive.error
1789 color.interactive.header
1790 color.interactive.help
1791 color.interactive.prompt
1796 color.status.changed
1798 color.status.nobranch
1799 color.status.untracked
1800 color.status.updated
1809 core.bigFileThreshold
1812 core.deltaBaseCacheLimit
1817 core.fsyncobjectfiles
1819 core.ignoreCygwinFSTricks
1822 core.logAllRefUpdates
1823 core.loosecompression
1826 core.packedGitWindowSize
1828 core.preferSymlinkRefs
1831 core.repositoryFormatVersion
1833 core.sharedRepository
1837 core.warnAmbiguousRefs
1840 diff.autorefreshindex
1843 diff.ignoreSubmodules
1848 diff.suppressBlankEmpty
1853 fetch.recurseSubmodules
1862 format.subjectprefix
1873 gc.reflogexpireunreachable
1877 gitcvs.commitmsgannotation
1878 gitcvs.dbTableNamePrefix
1889 gui.copyblamethreshold
1893 gui.matchtrackingbranch
1894 gui.newbranchtemplate
1895 gui.pruneduringfetch
1896 gui.spellingdictionary
1911 http.sslCertPasswordProtected
1916 i18n.logOutputEncoding
1922 imap.preformattedHTML
1932 interactive.singlekey
1948 mergetool.keepBackup
1949 mergetool.keepTemporaries
1954 notes.rewrite.rebase
1958 pack.deltaCacheLimit
1974 receive.denyCurrentBranch
1975 receive.denyDeleteCurrent
1977 receive.denyNonFastForwards
1980 receive.updateserverinfo
1982 repack.usedeltabaseoffset
1986 sendemail.aliasesfile
1987 sendemail.aliasfiletype
1991 sendemail.chainreplyto
1993 sendemail.envelopesender
1997 sendemail.signedoffbycc
1998 sendemail.smtpdomain
1999 sendemail.smtpencryption
2001 sendemail.smtpserver
2002 sendemail.smtpserveroption
2003 sendemail.smtpserverport
2005 sendemail.suppresscc
2006 sendemail.suppressfrom
2011 status.relativePaths
2012 status.showUntrackedFiles
2013 status.submodulesummary
2016 transfer.unpackLimit
2028 local subcommands="add rename remove set-head set-branches set-url show prune update"
2029 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2030 if [ -z "$subcommand" ]; then
2031 __gitcomp "$subcommands"
2035 case "$subcommand" in
2036 rename|remove|set-url|show|prune)
2037 __gitcomp_nl "$(__git_remotes)"
2039 set-head|set-branches)
2040 __git_complete_remote_or_refspec
2043 local i c='' IFS=$'\n'
2044 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2058 __gitcomp_nl "$(__git_refs)"
2063 __git_has_doubledash && return
2067 __gitcomp "--merge --mixed --hard --soft --patch"
2071 __gitcomp_nl "$(__git_refs)"
2078 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2082 __gitcomp_nl "$(__git_refs)"
2087 __git_has_doubledash && return
2091 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2100 __git_has_doubledash && return
2105 $__git_log_common_options
2106 $__git_log_shortlog_options
2107 --numbered --summary
2112 __git_complete_revlist
2117 __git_has_doubledash && return
2120 --pretty=*|--format=*)
2121 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2126 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2127 $__git_diff_common_options
2140 --all --remotes --topo-order --current --more=
2141 --list --independent --merge-base --no-name
2143 --sha1-name --sparse --topics --reflog
2148 __git_complete_revlist
2153 local save_opts='--keep-index --no-keep-index --quiet --patch'
2154 local subcommands='save list show apply clear drop pop create branch'
2155 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2156 if [ -z "$subcommand" ]; then
2159 __gitcomp "$save_opts"
2162 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2163 __gitcomp "$subcommands"
2170 case "$subcommand,$cur" in
2172 __gitcomp "$save_opts"
2175 __gitcomp "--index --quiet"
2177 show,--*|drop,--*|branch,--*)
2180 show,*|apply,*|drop,*|pop,*|branch,*)
2181 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2182 | sed -n -e 's/:.*//p')"
2193 __git_has_doubledash && return
2195 local subcommands="add status init update summary foreach sync"
2196 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2199 __gitcomp "--quiet --cached"
2202 __gitcomp "$subcommands"
2212 init fetch clone rebase dcommit log find-rev
2213 set-tree commit-diff info create-ignore propget
2214 proplist show-ignore show-externals branch tag blame
2215 migrate mkdirs reset gc
2217 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2218 if [ -z "$subcommand" ]; then
2219 __gitcomp "$subcommands"
2221 local remote_opts="--username= --config-dir= --no-auth-cache"
2223 --follow-parent --authors-file= --repack=
2224 --no-metadata --use-svm-props --use-svnsync-props
2225 --log-window-size= --no-checkout --quiet
2226 --repack-flags --use-log-author --localtime
2227 --ignore-paths= $remote_opts
2230 --template= --shared= --trunk= --tags=
2231 --branches= --stdlayout --minimize-url
2232 --no-metadata --use-svm-props --use-svnsync-props
2233 --rewrite-root= --prefix= --use-log-author
2234 --add-author-from $remote_opts
2237 --edit --rmdir --find-copies-harder --copy-similarity=
2240 case "$subcommand,$cur" in
2242 __gitcomp "--revision= --fetch-all $fc_opts"
2245 __gitcomp "--revision= $fc_opts $init_opts"
2248 __gitcomp "$init_opts"
2252 --merge --strategy= --verbose --dry-run
2253 --fetch-all --no-rebase --commit-url
2254 --revision --interactive $cmt_opts $fc_opts
2258 __gitcomp "--stdin $cmt_opts $fc_opts"
2260 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2261 show-externals,--*|mkdirs,--*)
2262 __gitcomp "--revision="
2266 --limit= --revision= --verbose --incremental
2267 --oneline --show-commit --non-recursive
2268 --authors-file= --color
2273 --merge --verbose --strategy= --local
2274 --fetch-all --dry-run $fc_opts
2278 __gitcomp "--message= --file= --revision= $cmt_opts"
2284 __gitcomp "--dry-run --message --tag"
2287 __gitcomp "--dry-run --message"
2290 __gitcomp "--git-format"
2294 --config-dir= --ignore-paths= --minimize
2295 --no-auth-cache --username=
2299 __gitcomp "--revision= --parent"
2311 while [ $c -lt $cword ]; do
2315 __gitcomp_nl "$(__git_tags)"
2331 __gitcomp_nl "$(__git_tags)"
2337 __gitcomp_nl "$(__git_refs)"
2349 local i c=1 command __git_dir
2351 while [ $c -lt $cword ]; do
2354 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2355 --bare) __git_dir="." ;;
2356 --help) command="help"; break ;;
2359 *) command="$i"; break ;;
2364 if [ -z "$command" ]; then
2378 --no-replace-objects
2382 *) __git_compute_porcelain_commands
2383 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2388 local completion_func="_git_${command//-/_}"
2389 declare -f $completion_func >/dev/null && $completion_func && return
2391 local expansion=$(__git_aliased_command "$command")
2392 if [ -n "$expansion" ]; then
2393 completion_func="_git_${expansion//-/_}"
2394 declare -f $completion_func >/dev/null && $completion_func
2400 __git_has_doubledash && return
2402 local g="$(__gitdir)"
2404 if [ -f "$g/MERGE_HEAD" ]; then
2410 $__git_log_common_options
2411 $__git_log_gitk_options
2417 __git_complete_revlist
2420 if [[ -n ${ZSH_VERSION-} ]]; then
2421 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2423 autoload -U +X compinit && compinit
2429 local cur_="${3-$cur}"
2435 local c IFS=$' \t\n'
2443 array[$#array+1]="$c"
2446 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2457 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2463 local cur cword prev
2464 cur=${words[CURRENT-1]}
2465 prev=${words[CURRENT-2]}
2475 let _ret && _default -S '' && _ret=0
2479 compdef _git git gitk
2485 local cur words cword prev
2486 _get_comp_words_by_ref -n =: cur words cword prev
2490 # Setup completion for certain functions defined above by setting common
2491 # variables and workarounds.
2492 # This is NOT a public function; use at your own risk.
2495 local wrapper="__git_wrap${2}"
2496 eval "$wrapper () { __git_func_wrap $2 ; }"
2497 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2498 || complete -o default -o nospace -F $wrapper $1
2501 # wrapper for backwards compatibility
2504 __git_wrap__git_main
2507 # wrapper for backwards compatibility
2510 __git_wrap__gitk_main
2513 __git_complete git __git_main
2514 __git_complete gitk __gitk_main
2516 # The following are necessary only for Cygwin, and only are needed
2517 # when the user has tab-completed the executable name and consequently
2518 # included the '.exe' suffix.
2520 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2521 __git_complete git.exe __git_main