3 # bash 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) Added the following line to your .bashrc:
22 # source ~/.git-completion.sh
24 # 3) You may want to make sure the git executable is available
25 # in your PATH before this script is sourced, as some caching
26 # is performed while the script loads. If git isn't found
27 # at source time then all lookups will be done on demand,
28 # which may be slightly slower.
30 # 4) Consider changing your PS1 to also show the current branch:
31 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
33 # The argument to __git_ps1 will be displayed only if you
34 # are currently in a git repository. The %s token will be
35 # the name of the current branch.
37 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
38 # value, unstaged (*) and staged (+) changes will be shown next
39 # to the branch name. You can configure this per-repository
40 # with the bash.showDirtyState variable, which defaults to true
41 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
43 # You can also see if currently something is stashed, by setting
44 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
45 # then a '$' will be shown next to the branch name.
47 # If you would like to see if there're untracked files, then you can
48 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
49 # untracked files, then a '%' will be shown next to the branch name.
53 # *) Read Documentation/SubmittingPatches
54 # *) Send all patches to the current maintainer:
56 # "Shawn O. Pearce" <spearce@spearce.org>
58 # *) Always CC the Git mailing list:
63 case "$COMP_WORDBREAKS" in
65 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
68 # __gitdir accepts 0 or 1 arguments (i.e., location)
69 # returns location of .git repo
72 if [ -z "${1-}" ]; then
73 if [ -n "${__git_dir-}" ]; then
75 elif [ -d .git ]; then
78 git rev-parse --git-dir 2>/dev/null
80 elif [ -d "$1/.git" ]; then
87 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
88 # returns text to add to bash PS1 prompt (includes branch name)
95 if [ -f "$g/rebase-merge/interactive" ]; then
97 b="$(cat "$g/rebase-merge/head-name")"
98 elif [ -d "$g/rebase-merge" ]; then
100 b="$(cat "$g/rebase-merge/head-name")"
102 if [ -d "$g/rebase-apply" ]; then
103 if [ -f "$g/rebase-apply/rebasing" ]; then
105 elif [ -f "$g/rebase-apply/applying" ]; then
110 elif [ -f "$g/MERGE_HEAD" ]; then
112 elif [ -f "$g/BISECT_LOG" ]; then
116 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
119 case "${GIT_PS1_DESCRIBE_STYLE-}" in
121 git describe --contains HEAD ;;
123 git describe --contains --all HEAD ;;
127 git describe --exact-match HEAD ;;
128 esac 2>/dev/null)" ||
130 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
142 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
143 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
148 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
149 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
150 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
151 git diff --no-ext-diff --quiet --exit-code || w="*"
152 if git rev-parse --quiet --verify HEAD >/dev/null; then
153 git diff-index --cached --quiet HEAD -- || i="+"
159 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
160 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
163 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
164 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
170 if [ -n "${1-}" ]; then
171 printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
173 printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
178 # __gitcomp_1 requires 2 arguments
181 local c IFS=' '$'\t'$'\n'
184 --*=*) printf %s$'\n' "$c$2" ;;
185 *.) printf %s$'\n' "$c$2" ;;
186 *) printf %s$'\n' "$c$2 " ;;
191 # __gitcomp accepts 1, 2, 3, or 4 arguments
192 # generates completion reply with compgen
195 local cur="${COMP_WORDS[COMP_CWORD]}"
196 if [ $# -gt 2 ]; then
205 COMPREPLY=($(compgen -P "${2-}" \
206 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
212 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
215 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
216 if [ -d "$dir" ]; then
217 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
221 for i in $(git ls-remote "${1-}" 2>/dev/null); do
222 case "$is_hash,$i" in
225 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
226 n,*) is_hash=y; echo "$i" ;;
231 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
234 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
235 if [ -d "$dir" ]; then
236 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
240 for i in $(git ls-remote "${1-}" 2>/dev/null); do
241 case "$is_hash,$i" in
244 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
245 n,*) is_hash=y; echo "$i" ;;
250 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
253 local i is_hash=y dir="$(__gitdir "${1-}")"
254 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
255 if [ -d "$dir" ]; then
262 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
263 format="refname:short"
264 refs="refs/tags refs/heads refs/remotes"
267 git --git-dir="$dir" for-each-ref --format="%($format)" \
271 for i in $(git ls-remote "$dir" 2>/dev/null); do
272 case "$is_hash,$i" in
275 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
276 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
277 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
278 n,*) is_hash=y; echo "$i" ;;
283 # __git_refs2 requires 1 argument (to pass to __git_refs)
287 for i in $(__git_refs "$1"); do
292 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
293 __git_refs_remotes ()
295 local cmd i is_hash=y
296 for i in $(git ls-remote "$1" 2>/dev/null); do
297 case "$is_hash,$i" in
300 echo "$i:refs/remotes/$1/${i#refs/heads/}"
304 n,refs/tags/*) is_hash=y;;
312 local i ngoff IFS=$'\n' d="$(__gitdir)"
313 shopt -q nullglob || ngoff=1
315 for i in "$d/remotes"/*; do
316 echo ${i#$d/remotes/}
318 [ "$ngoff" ] && shopt -u nullglob
319 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
325 __git_merge_strategies ()
327 if [ -n "${__git_merge_strategylist-}" ]; then
328 echo "$__git_merge_strategylist"
331 git merge -s help 2>&1 |
332 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
340 __git_merge_strategylist=
341 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
343 __git_complete_file ()
345 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
362 case "$COMP_WORDBREAKS" in
364 *) pfx="$ref:$pfx" ;;
368 COMPREPLY=($(compgen -P "$pfx" \
369 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
370 | sed '/^100... blob /{
386 __gitcomp "$(__git_refs)"
391 __git_complete_revlist ()
393 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
398 __gitcomp "$(__git_refs)" "$pfx" "$cur"
403 __gitcomp "$(__git_refs)" "$pfx" "$cur"
406 __gitcomp "$(__git_refs)"
411 __git_complete_remote_or_refspec ()
413 local cmd="${COMP_WORDS[1]}"
414 local cur="${COMP_WORDS[COMP_CWORD]}"
415 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
416 while [ $c -lt $COMP_CWORD ]; do
419 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
421 *) remote="$i"; break ;;
425 if [ -z "$remote" ]; then
426 __gitcomp "$(__git_remotes)"
429 if [ $no_complete_refspec = 1 ]; then
433 [ "$remote" = "." ] && remote=
436 case "$COMP_WORDBREAKS" in
438 *) pfx="${cur%%:*}:" ;;
450 if [ $lhs = 1 ]; then
451 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
453 __gitcomp "$(__git_refs)" "$pfx" "$cur"
457 if [ $lhs = 1 ]; then
458 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
460 __gitcomp "$(__git_refs)" "$pfx" "$cur"
464 if [ $lhs = 1 ]; then
465 __gitcomp "$(__git_refs)" "$pfx" "$cur"
467 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
473 __git_complete_strategy ()
475 case "${COMP_WORDS[COMP_CWORD-1]}" in
477 __gitcomp "$(__git_merge_strategies)"
480 local cur="${COMP_WORDS[COMP_CWORD]}"
483 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
490 __git_all_commands ()
492 if [ -n "${__git_all_commandlist-}" ]; then
493 echo "$__git_all_commandlist"
497 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
500 *--*) : helper pattern;;
505 __git_all_commandlist=
506 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
508 __git_porcelain_commands ()
510 if [ -n "${__git_porcelain_commandlist-}" ]; then
511 echo "$__git_porcelain_commandlist"
515 for i in "help" $(__git_all_commands)
518 *--*) : helper pattern;;
519 applymbox) : ask gittus;;
520 applypatch) : ask gittus;;
521 archimport) : import;;
522 cat-file) : plumbing;;
523 check-attr) : plumbing;;
524 check-ref-format) : plumbing;;
525 checkout-index) : plumbing;;
526 commit-tree) : plumbing;;
527 count-objects) : infrequent;;
528 cvsexportcommit) : export;;
529 cvsimport) : import;;
530 cvsserver) : daemon;;
532 diff-files) : plumbing;;
533 diff-index) : plumbing;;
534 diff-tree) : plumbing;;
535 fast-import) : import;;
536 fast-export) : export;;
537 fsck-objects) : plumbing;;
538 fetch-pack) : plumbing;;
539 fmt-merge-msg) : plumbing;;
540 for-each-ref) : plumbing;;
541 hash-object) : plumbing;;
542 http-*) : transport;;
543 index-pack) : plumbing;;
544 init-db) : deprecated;;
545 local-fetch) : plumbing;;
546 lost-found) : infrequent;;
547 ls-files) : plumbing;;
548 ls-remote) : plumbing;;
549 ls-tree) : plumbing;;
550 mailinfo) : plumbing;;
551 mailsplit) : plumbing;;
552 merge-*) : plumbing;;
555 pack-objects) : plumbing;;
556 pack-redundant) : plumbing;;
557 pack-refs) : plumbing;;
558 parse-remote) : plumbing;;
559 patch-id) : plumbing;;
560 peek-remote) : plumbing;;
562 prune-packed) : plumbing;;
563 quiltimport) : import;;
564 read-tree) : plumbing;;
565 receive-pack) : plumbing;;
567 repo-config) : deprecated;;
569 rev-list) : plumbing;;
570 rev-parse) : plumbing;;
571 runstatus) : plumbing;;
572 sh-setup) : internal;;
574 show-ref) : plumbing;;
575 send-pack) : plumbing;;
576 show-index) : plumbing;;
578 stripspace) : plumbing;;
579 symbolic-ref) : plumbing;;
580 tar-tree) : deprecated;;
581 unpack-file) : plumbing;;
582 unpack-objects) : plumbing;;
583 update-index) : plumbing;;
584 update-ref) : plumbing;;
585 update-server-info) : daemon;;
586 upload-archive) : plumbing;;
587 upload-pack) : plumbing;;
588 write-tree) : plumbing;;
590 verify-pack) : infrequent;;
591 verify-tag) : plumbing;;
596 __git_porcelain_commandlist=
597 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
602 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
612 # __git_aliased_command requires 1 argument
613 __git_aliased_command ()
615 local word cmdline=$(git --git-dir="$(__gitdir)" \
616 config --get "alias.$1")
617 for word in $cmdline; do
618 if [ "${word##-*}" ]; then
625 # __git_find_on_cmdline requires 1 argument
626 __git_find_on_cmdline ()
628 local word subcommand c=1
630 while [ $c -lt $COMP_CWORD ]; do
631 word="${COMP_WORDS[c]}"
632 for subcommand in $1; do
633 if [ "$subcommand" = "$word" ]; then
642 __git_has_doubledash ()
645 while [ $c -lt $COMP_CWORD ]; do
646 if [ "--" = "${COMP_WORDS[c]}" ]; then
654 __git_whitespacelist="nowarn warn error error-all fix"
658 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
659 if [ -d "$dir"/rebase-apply ]; then
660 __gitcomp "--skip --resolved --abort"
665 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
670 --3way --committer-date-is-author-date --ignore-date
671 --ignore-whitespace --ignore-space-change
672 --interactive --keep --no-utf8 --signoff --utf8
673 --whitespace= --scissors
682 local cur="${COMP_WORDS[COMP_CWORD]}"
685 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
690 --stat --numstat --summary --check --index
691 --cached --index-info --reverse --reject --unidiff-zero
692 --apply --no-add --exclude=
693 --ignore-whitespace --ignore-space-change
694 --whitespace= --inaccurate-eof --verbose
703 __git_has_doubledash && return
705 local cur="${COMP_WORDS[COMP_CWORD]}"
709 --interactive --refresh --patch --update --dry-run
710 --ignore-errors --intent-to-add
719 local cur="${COMP_WORDS[COMP_CWORD]}"
722 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
726 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
731 --format= --list --verbose
732 --prefix= --remote= --exec=
742 __git_has_doubledash && return
744 local subcommands="start bad good skip reset visualize replay log run"
745 local subcommand="$(__git_find_on_cmdline "$subcommands")"
746 if [ -z "$subcommand" ]; then
747 __gitcomp "$subcommands"
751 case "$subcommand" in
753 __gitcomp "$(__git_refs)"
763 local i c=1 only_local_ref="n" has_r="n"
765 while [ $c -lt $COMP_CWORD ]; do
768 -d|-m) only_local_ref="y" ;;
774 case "${COMP_WORDS[COMP_CWORD]}" in
777 --color --no-color --verbose --abbrev= --no-abbrev
778 --track --no-track --contains --merged --no-merged
782 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
783 __gitcomp "$(__git_heads)"
785 __gitcomp "$(__git_refs)"
793 local cmd="${COMP_WORDS[2]}"
794 case "$COMP_CWORD" in
796 __gitcomp "create list-heads verify unbundle"
804 __git_complete_revlist
813 __git_has_doubledash && return
815 local cur="${COMP_WORDS[COMP_CWORD]}"
818 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
822 --quiet --ours --theirs --track --no-track --merge
827 __gitcomp "$(__git_refs)"
834 __gitcomp "$(__git_refs)"
839 local cur="${COMP_WORDS[COMP_CWORD]}"
842 __gitcomp "--edit --no-commit"
845 __gitcomp "$(__git_refs)"
852 __git_has_doubledash && return
854 local cur="${COMP_WORDS[COMP_CWORD]}"
857 __gitcomp "--dry-run --quiet"
866 local cur="${COMP_WORDS[COMP_CWORD]}"
891 __git_has_doubledash && return
893 local cur="${COMP_WORDS[COMP_CWORD]}"
897 --all --author= --signoff --verify --no-verify
898 --edit --amend --include --only --interactive
908 local cur="${COMP_WORDS[COMP_CWORD]}"
912 --all --tags --contains --abbrev= --candidates=
913 --exact-match --debug --long --match --always
917 __gitcomp "$(__git_refs)"
920 __git_diff_common_options="--stat --numstat --shortstat --summary
921 --patch-with-stat --name-only --name-status --color
922 --no-color --color-words --no-renames --check
923 --full-index --binary --abbrev --diff-filter=
925 --text --ignore-space-at-eol --ignore-space-change
926 --ignore-all-space --exit-code --quiet --ext-diff
928 --no-prefix --src-prefix= --dst-prefix=
929 --inter-hunk-context=
932 --dirstat --dirstat= --dirstat-by-file
933 --dirstat-by-file= --cumulative
938 __git_has_doubledash && return
940 local cur="${COMP_WORDS[COMP_CWORD]}"
943 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
944 --base --ours --theirs
945 $__git_diff_common_options
953 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
954 tkdiff vimdiff gvimdiff xxdiff araxis
959 local cur="${COMP_WORDS[COMP_CWORD]}"
962 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
973 __git_fetch_options="
974 --quiet --verbose --append --upload-pack --force --keep --depth=
980 local cur="${COMP_WORDS[COMP_CWORD]}"
983 __gitcomp "$__git_fetch_options"
987 __git_complete_remote_or_refspec
992 local cur="${COMP_WORDS[COMP_CWORD]}"
997 " "" "${cur##--thread=}"
1002 --stdout --attach --no-attach --thread --thread=
1004 --numbered --start-number
1008 --in-reply-to= --cc=
1009 --full-index --binary
1012 --no-prefix --src-prefix= --dst-prefix=
1013 --inline --suffix= --ignore-if-in-upstream
1019 __git_complete_revlist
1024 local cur="${COMP_WORDS[COMP_CWORD]}"
1028 --tags --root --unreachable --cache --no-reflogs --full
1029 --strict --verbose --lost-found
1039 local cur="${COMP_WORDS[COMP_CWORD]}"
1042 __gitcomp "--prune --aggressive"
1051 __git_has_doubledash && return
1053 local cur="${COMP_WORDS[COMP_CWORD]}"
1058 --text --ignore-case --word-regexp --invert-match
1060 --extended-regexp --basic-regexp --fixed-strings
1061 --files-with-matches --name-only
1062 --files-without-match
1065 --and --or --not --all-match
1075 local cur="${COMP_WORDS[COMP_CWORD]}"
1078 __gitcomp "--all --info --man --web"
1082 __gitcomp "$(__git_all_commands)
1083 attributes cli core-tutorial cvs-migration
1084 diffcore gitk glossary hooks ignore modules
1085 repository-layout tutorial tutorial-2
1092 local cur="${COMP_WORDS[COMP_CWORD]}"
1096 false true umask group all world everybody
1097 " "" "${cur##--shared=}"
1101 __gitcomp "--quiet --bare --template= --shared --shared="
1110 __git_has_doubledash && return
1112 local cur="${COMP_WORDS[COMP_CWORD]}"
1115 __gitcomp "--cached --deleted --modified --others --ignored
1116 --stage --directory --no-empty-directory --unmerged
1117 --killed --exclude= --exclude-from=
1118 --exclude-per-directory= --exclude-standard
1119 --error-unmatch --with-tree= --full-name
1120 --abbrev --ignored --exclude-per-directory
1130 __gitcomp "$(__git_remotes)"
1138 # Options that go well for log, shortlog and gitk
1139 __git_log_common_options="
1141 --branches --tags --remotes
1142 --first-parent --merges --no-merges
1144 --max-age= --since= --after=
1145 --min-age= --until= --before=
1147 # Options that go well for log and gitk (not shortlog)
1148 __git_log_gitk_options="
1149 --dense --sparse --full-history
1150 --simplify-merges --simplify-by-decoration
1153 # Options that go well for log and shortlog (not gitk)
1154 __git_log_shortlog_options="
1155 --author= --committer= --grep=
1159 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1160 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1164 __git_has_doubledash && return
1166 local cur="${COMP_WORDS[COMP_CWORD]}"
1167 local g="$(git rev-parse --git-dir 2>/dev/null)"
1169 if [ -f "$g/MERGE_HEAD" ]; then
1174 __gitcomp "$__git_log_pretty_formats
1175 " "" "${cur##--pretty=}"
1179 __gitcomp "$__git_log_pretty_formats
1180 " "" "${cur##--format=}"
1184 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1188 __gitcomp "long short" "" "${cur##--decorate=}"
1193 $__git_log_common_options
1194 $__git_log_shortlog_options
1195 $__git_log_gitk_options
1196 --root --topo-order --date-order --reverse
1197 --follow --full-diff
1198 --abbrev-commit --abbrev=
1199 --relative-date --date=
1200 --pretty= --format= --oneline
1203 --decorate --decorate=
1205 --parents --children
1207 $__git_diff_common_options
1208 --pickaxe-all --pickaxe-regex
1213 __git_complete_revlist
1216 __git_merge_options="
1217 --no-commit --no-stat --log --no-log --squash --strategy
1218 --commit --stat --no-squash --ff --no-ff
1223 __git_complete_strategy && return
1225 local cur="${COMP_WORDS[COMP_CWORD]}"
1228 __gitcomp "$__git_merge_options"
1231 __gitcomp "$(__git_refs)"
1236 local cur="${COMP_WORDS[COMP_CWORD]}"
1239 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1252 __gitcomp "$(__git_refs)"
1257 local cur="${COMP_WORDS[COMP_CWORD]}"
1260 __gitcomp "--dry-run"
1269 __gitcomp "--tags --all --stdin"
1274 __git_complete_strategy && return
1276 local cur="${COMP_WORDS[COMP_CWORD]}"
1280 --rebase --no-rebase
1281 $__git_merge_options
1282 $__git_fetch_options
1287 __git_complete_remote_or_refspec
1292 local cur="${COMP_WORDS[COMP_CWORD]}"
1293 case "${COMP_WORDS[COMP_CWORD-1]}" in
1295 __gitcomp "$(__git_remotes)"
1300 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1305 --all --mirror --tags --dry-run --force --verbose
1306 --receive-pack= --repo=
1311 __git_complete_remote_or_refspec
1316 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1317 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1318 __gitcomp "--continue --skip --abort"
1321 __git_complete_strategy && return
1324 __gitcomp "--onto --merge --strategy --interactive"
1327 __gitcomp "$(__git_refs)"
1330 __git_send_email_confirm_options="always never auto cc compose"
1331 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1335 local cur="${COMP_WORDS[COMP_CWORD]}"
1339 $__git_send_email_confirm_options
1340 " "" "${cur##--confirm=}"
1345 $__git_send_email_suppresscc_options
1346 " "" "${cur##--suppress-cc=}"
1350 --smtp-encryption=*)
1351 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1355 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1356 --compose --confirm= --dry-run --envelope-sender
1358 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1359 --no-suppress-from --no-thread --quiet
1360 --signed-off-by-cc --smtp-pass --smtp-server
1361 --smtp-server-port --smtp-encryption= --smtp-user
1362 --subject --suppress-cc= --suppress-from --thread --to
1363 --validate --no-validate"
1370 __git_config_get_set_variables ()
1372 local prevword word config_file= c=$COMP_CWORD
1373 while [ $c -gt 1 ]; do
1374 word="${COMP_WORDS[c]}"
1376 --global|--system|--file=*)
1381 config_file="$word $prevword"
1389 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1402 local cur="${COMP_WORDS[COMP_CWORD]}"
1403 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1406 __gitcomp "$(__git_remotes)"
1410 __gitcomp "$(__git_refs)"
1414 local remote="${prv#remote.}"
1415 remote="${remote%.fetch}"
1416 __gitcomp "$(__git_refs_remotes "$remote")"
1420 local remote="${prv#remote.}"
1421 remote="${remote%.push}"
1422 __gitcomp "$(git --git-dir="$(__gitdir)" \
1423 for-each-ref --format='%(refname):%(refname)' \
1427 pull.twohead|pull.octopus)
1428 __gitcomp "$(__git_merge_strategies)"
1431 color.branch|color.diff|color.interactive|\
1432 color.showbranch|color.status|color.ui)
1433 __gitcomp "always never auto"
1437 __gitcomp "false true"
1442 normal black red green yellow blue magenta cyan white
1443 bold dim ul blink reverse
1448 __gitcomp "man info web html"
1452 __gitcomp "$__git_log_date_formats"
1455 sendemail.aliasesfiletype)
1456 __gitcomp "mutt mailrc pine elm gnus"
1460 __gitcomp "$__git_send_email_confirm_options"
1463 sendemail.suppresscc)
1464 __gitcomp "$__git_send_email_suppresscc_options"
1467 --get|--get-all|--unset|--unset-all)
1468 __gitcomp "$(__git_config_get_set_variables)"
1479 --global --system --file=
1480 --list --replace-all
1481 --get --get-all --get-regexp
1482 --add --unset --unset-all
1483 --remove-section --rename-section
1488 local pfx="${cur%.*}."
1490 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1494 local pfx="${cur%.*}."
1496 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1500 local pfx="${cur%.*}."
1503 argprompt cmd confirm needsfile noconsole norescan
1504 prompt revprompt revunmerged title
1509 local pfx="${cur%.*}."
1511 __gitcomp "cmd path" "$pfx" "$cur"
1515 local pfx="${cur%.*}."
1517 __gitcomp "cmd path" "$pfx" "$cur"
1521 local pfx="${cur%.*}."
1523 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1527 local pfx="${cur%.*}."
1529 __gitcomp "$(__git_all_commands)" "$pfx" "$cur"
1533 local pfx="${cur%.*}."
1536 url proxy fetch push mirror skipDefaultUpdate
1537 receivepack uploadpack tagopt pushurl
1542 local pfx="${cur%.*}."
1544 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1548 local pfx="${cur%.*}."
1550 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1557 apply.ignorewhitespace
1559 branch.autosetupmerge
1560 branch.autosetuprebase
1563 color.branch.current
1574 color.diff.whitespace
1579 color.interactive.header
1580 color.interactive.help
1581 color.interactive.prompt
1586 color.status.changed
1588 color.status.nobranch
1589 color.status.untracked
1590 color.status.updated
1597 core.deltaBaseCacheLimit
1601 core.fsyncobjectfiles
1603 core.ignoreCygwinFSTricks
1605 core.logAllRefUpdates
1606 core.loosecompression
1608 core.packedGitWindowSize
1610 core.preferSymlinkRefs
1613 core.repositoryFormatVersion
1615 core.sharedRepository
1618 core.warnAmbiguousRefs
1621 diff.autorefreshindex
1627 diff.suppressBlankEmpty
1639 format.subjectprefix
1648 gc.reflogexpireunreachable
1652 gitcvs.commitmsgannotation
1653 gitcvs.dbTableNamePrefix
1664 gui.copyblamethreshold
1668 gui.matchtrackingbranch
1669 gui.newbranchtemplate
1670 gui.pruneduringfetch
1671 gui.spellingdictionary
1687 i18n.logOutputEncoding
1692 imap.preformattedHTML
1701 interactive.singlekey
1714 mergetool.keepBackup
1717 pack.deltaCacheLimit
1730 receive.denyCurrentBranch
1732 receive.denyNonFastForwards
1735 repack.usedeltabaseoffset
1738 sendemail.aliasesfile
1739 sendemail.aliasesfiletype
1743 sendemail.chainreplyto
1745 sendemail.envelopesender
1747 sendemail.signedoffbycc
1748 sendemail.smtpencryption
1750 sendemail.smtpserver
1751 sendemail.smtpserverport
1753 sendemail.suppresscc
1754 sendemail.suppressfrom
1759 status.relativePaths
1760 status.showUntrackedFiles
1762 transfer.unpackLimit
1774 local subcommands="add rename rm show prune update set-head"
1775 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1776 if [ -z "$subcommand" ]; then
1777 __gitcomp "$subcommands"
1781 case "$subcommand" in
1782 rename|rm|show|prune)
1783 __gitcomp "$(__git_remotes)"
1786 local i c='' IFS=$'\n'
1787 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1801 __gitcomp "$(__git_refs)"
1806 __git_has_doubledash && return
1808 local cur="${COMP_WORDS[COMP_CWORD]}"
1811 __gitcomp "--merge --mixed --hard --soft --patch"
1815 __gitcomp "$(__git_refs)"
1820 local cur="${COMP_WORDS[COMP_CWORD]}"
1823 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1827 __gitcomp "$(__git_refs)"
1832 __git_has_doubledash && return
1834 local cur="${COMP_WORDS[COMP_CWORD]}"
1837 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1846 __git_has_doubledash && return
1848 local cur="${COMP_WORDS[COMP_CWORD]}"
1852 $__git_log_common_options
1853 $__git_log_shortlog_options
1854 --numbered --summary
1859 __git_complete_revlist
1864 __git_has_doubledash && return
1866 local cur="${COMP_WORDS[COMP_CWORD]}"
1869 __gitcomp "$__git_log_pretty_formats
1870 " "" "${cur##--pretty=}"
1874 __gitcomp "$__git_log_pretty_formats
1875 " "" "${cur##--format=}"
1879 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1880 $__git_diff_common_options
1890 local cur="${COMP_WORDS[COMP_CWORD]}"
1894 --all --remotes --topo-order --current --more=
1895 --list --independent --merge-base --no-name
1897 --sha1-name --sparse --topics --reflog
1902 __git_complete_revlist
1907 local cur="${COMP_WORDS[COMP_CWORD]}"
1908 local save_opts='--keep-index --no-keep-index --quiet --patch'
1909 local subcommands='save list show apply clear drop pop create branch'
1910 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1911 if [ -z "$subcommand" ]; then
1914 __gitcomp "$save_opts"
1917 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1918 __gitcomp "$subcommands"
1925 case "$subcommand,$cur" in
1927 __gitcomp "$save_opts"
1930 __gitcomp "--index --quiet"
1932 show,--*|drop,--*|branch,--*)
1935 show,*|apply,*|drop,*|pop,*|branch,*)
1936 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1937 | sed -n -e 's/:.*//p')"
1948 __git_has_doubledash && return
1950 local subcommands="add status init update summary foreach sync"
1951 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1952 local cur="${COMP_WORDS[COMP_CWORD]}"
1955 __gitcomp "--quiet --cached"
1958 __gitcomp "$subcommands"
1968 init fetch clone rebase dcommit log find-rev
1969 set-tree commit-diff info create-ignore propget
1970 proplist show-ignore show-externals branch tag blame
1973 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1974 if [ -z "$subcommand" ]; then
1975 __gitcomp "$subcommands"
1977 local remote_opts="--username= --config-dir= --no-auth-cache"
1979 --follow-parent --authors-file= --repack=
1980 --no-metadata --use-svm-props --use-svnsync-props
1981 --log-window-size= --no-checkout --quiet
1982 --repack-flags --use-log-author --localtime
1983 --ignore-paths= $remote_opts
1986 --template= --shared= --trunk= --tags=
1987 --branches= --stdlayout --minimize-url
1988 --no-metadata --use-svm-props --use-svnsync-props
1989 --rewrite-root= --prefix= --use-log-author
1990 --add-author-from $remote_opts
1993 --edit --rmdir --find-copies-harder --copy-similarity=
1996 local cur="${COMP_WORDS[COMP_CWORD]}"
1997 case "$subcommand,$cur" in
1999 __gitcomp "--revision= --fetch-all $fc_opts"
2002 __gitcomp "--revision= $fc_opts $init_opts"
2005 __gitcomp "$init_opts"
2009 --merge --strategy= --verbose --dry-run
2010 --fetch-all --no-rebase --commit-url
2011 --revision $cmt_opts $fc_opts
2015 __gitcomp "--stdin $cmt_opts $fc_opts"
2017 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2019 __gitcomp "--revision="
2023 --limit= --revision= --verbose --incremental
2024 --oneline --show-commit --non-recursive
2025 --authors-file= --color
2030 --merge --verbose --strategy= --local
2031 --fetch-all --dry-run $fc_opts
2035 __gitcomp "--message= --file= --revision= $cmt_opts"
2041 __gitcomp "--dry-run --message --tag"
2044 __gitcomp "--dry-run --message"
2047 __gitcomp "--git-format"
2051 --config-dir= --ignore-paths= --minimize
2052 --no-auth-cache --username=
2065 while [ $c -lt $COMP_CWORD ]; do
2066 i="${COMP_WORDS[c]}"
2069 __gitcomp "$(__git_tags)"
2079 case "${COMP_WORDS[COMP_CWORD-1]}" in
2085 __gitcomp "$(__git_tags)"
2091 __gitcomp "$(__git_refs)"
2098 local i c=1 command __git_dir
2100 while [ $c -lt $COMP_CWORD ]; do
2101 i="${COMP_WORDS[c]}"
2103 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2104 --bare) __git_dir="." ;;
2105 --version|-p|--paginate) ;;
2106 --help) command="help"; break ;;
2107 *) command="$i"; break ;;
2112 if [ -z "$command" ]; then
2113 case "${COMP_WORDS[COMP_CWORD]}" in
2126 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
2131 local expansion=$(__git_aliased_command "$command")
2132 [ "$expansion" ] && command="$expansion"
2137 apply) _git_apply ;;
2138 archive) _git_archive ;;
2139 bisect) _git_bisect ;;
2140 bundle) _git_bundle ;;
2141 branch) _git_branch ;;
2142 checkout) _git_checkout ;;
2143 cherry) _git_cherry ;;
2144 cherry-pick) _git_cherry_pick ;;
2145 clean) _git_clean ;;
2146 clone) _git_clone ;;
2147 commit) _git_commit ;;
2148 config) _git_config ;;
2149 describe) _git_describe ;;
2151 difftool) _git_difftool ;;
2152 fetch) _git_fetch ;;
2153 format-patch) _git_format_patch ;;
2160 ls-files) _git_ls_files ;;
2161 ls-remote) _git_ls_remote ;;
2162 ls-tree) _git_ls_tree ;;
2164 mergetool) _git_mergetool;;
2165 merge-base) _git_merge_base ;;
2167 name-rev) _git_name_rev ;;
2170 rebase) _git_rebase ;;
2171 remote) _git_remote ;;
2172 replace) _git_replace ;;
2173 reset) _git_reset ;;
2174 revert) _git_revert ;;
2176 send-email) _git_send_email ;;
2177 shortlog) _git_shortlog ;;
2179 show-branch) _git_show_branch ;;
2180 stash) _git_stash ;;
2182 submodule) _git_submodule ;;
2185 whatchanged) _git_log ;;
2192 __git_has_doubledash && return
2194 local cur="${COMP_WORDS[COMP_CWORD]}"
2195 local g="$(__gitdir)"
2197 if [ -f "$g/MERGE_HEAD" ]; then
2203 $__git_log_common_options
2204 $__git_log_gitk_options
2210 __git_complete_revlist
2213 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2214 || complete -o default -o nospace -F _git git
2215 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2216 || complete -o default -o nospace -F _gitk gitk
2218 # The following are necessary only for Cygwin, and only are needed
2219 # when the user has tab-completed the executable name and consequently
2220 # included the '.exe' suffix.
2222 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2223 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2224 || complete -o default -o nospace -F _git git.exe