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 --ignore-submodules \
152 --quiet --exit-code || w="*"
153 if git rev-parse --quiet --verify HEAD >/dev/null; then
154 git diff-index --cached --quiet \
155 --ignore-submodules HEAD -- || i="+"
161 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
162 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
165 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
166 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
172 if [ -n "${1-}" ]; then
173 printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
175 printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
180 # __gitcomp_1 requires 2 arguments
183 local c IFS=' '$'\t'$'\n'
186 --*=*) printf %s$'\n' "$c$2" ;;
187 *.) printf %s$'\n' "$c$2" ;;
188 *) printf %s$'\n' "$c$2 " ;;
193 # __gitcomp accepts 1, 2, 3, or 4 arguments
194 # generates completion reply with compgen
197 local cur="${COMP_WORDS[COMP_CWORD]}"
198 if [ $# -gt 2 ]; then
207 COMPREPLY=($(compgen -P "${2-}" \
208 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
214 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
217 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
218 if [ -d "$dir" ]; then
219 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
223 for i in $(git ls-remote "${1-}" 2>/dev/null); do
224 case "$is_hash,$i" in
227 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
228 n,*) is_hash=y; echo "$i" ;;
233 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
236 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
237 if [ -d "$dir" ]; then
238 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
242 for i in $(git ls-remote "${1-}" 2>/dev/null); do
243 case "$is_hash,$i" in
246 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
247 n,*) is_hash=y; echo "$i" ;;
252 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
255 local i is_hash=y dir="$(__gitdir "${1-}")"
256 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
257 if [ -d "$dir" ]; then
264 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
265 format="refname:short"
266 refs="refs/tags refs/heads refs/remotes"
269 git --git-dir="$dir" for-each-ref --format="%($format)" \
273 for i in $(git ls-remote "$dir" 2>/dev/null); do
274 case "$is_hash,$i" in
277 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
278 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
279 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
280 n,*) is_hash=y; echo "$i" ;;
285 # __git_refs2 requires 1 argument (to pass to __git_refs)
289 for i in $(__git_refs "$1"); do
294 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
295 __git_refs_remotes ()
297 local cmd i is_hash=y
298 for i in $(git ls-remote "$1" 2>/dev/null); do
299 case "$is_hash,$i" in
302 echo "$i:refs/remotes/$1/${i#refs/heads/}"
306 n,refs/tags/*) is_hash=y;;
314 local i ngoff IFS=$'\n' d="$(__gitdir)"
315 shopt -q nullglob || ngoff=1
317 for i in "$d/remotes"/*; do
318 echo ${i#$d/remotes/}
320 [ "$ngoff" ] && shopt -u nullglob
321 for i in $(git --git-dir="$d" config --list); do
331 __git_merge_strategies ()
333 if [ -n "${__git_merge_strategylist-}" ]; then
334 echo "$__git_merge_strategylist"
337 git merge -s help 2>&1 |
338 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
346 __git_merge_strategylist=
347 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
349 __git_complete_file ()
351 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
368 case "$COMP_WORDBREAKS" in
370 *) pfx="$ref:$pfx" ;;
374 COMPREPLY=($(compgen -P "$pfx" \
375 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
376 | sed '/^100... blob /{
392 __gitcomp "$(__git_refs)"
397 __git_complete_revlist ()
399 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
404 __gitcomp "$(__git_refs)" "$pfx" "$cur"
409 __gitcomp "$(__git_refs)" "$pfx" "$cur"
412 __gitcomp "$(__git_refs)"
417 __git_complete_remote_or_refspec ()
419 local cmd="${COMP_WORDS[1]}"
420 local cur="${COMP_WORDS[COMP_CWORD]}"
421 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
422 while [ $c -lt $COMP_CWORD ]; do
425 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
427 *) remote="$i"; break ;;
431 if [ -z "$remote" ]; then
432 __gitcomp "$(__git_remotes)"
435 if [ $no_complete_refspec = 1 ]; then
439 [ "$remote" = "." ] && remote=
442 case "$COMP_WORDBREAKS" in
444 *) pfx="${cur%%:*}:" ;;
456 if [ $lhs = 1 ]; then
457 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
459 __gitcomp "$(__git_refs)" "$pfx" "$cur"
463 if [ $lhs = 1 ]; then
464 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
466 __gitcomp "$(__git_refs)" "$pfx" "$cur"
470 if [ $lhs = 1 ]; then
471 __gitcomp "$(__git_refs)" "$pfx" "$cur"
473 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
479 __git_complete_strategy ()
481 case "${COMP_WORDS[COMP_CWORD-1]}" in
483 __gitcomp "$(__git_merge_strategies)"
486 local cur="${COMP_WORDS[COMP_CWORD]}"
489 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
496 __git_all_commands ()
498 if [ -n "${__git_all_commandlist-}" ]; then
499 echo "$__git_all_commandlist"
503 for i in $(git help -a|egrep '^ ')
506 *--*) : helper pattern;;
511 __git_all_commandlist=
512 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
514 __git_porcelain_commands ()
516 if [ -n "${__git_porcelain_commandlist-}" ]; then
517 echo "$__git_porcelain_commandlist"
521 for i in "help" $(__git_all_commands)
524 *--*) : helper pattern;;
525 applymbox) : ask gittus;;
526 applypatch) : ask gittus;;
527 archimport) : import;;
528 cat-file) : plumbing;;
529 check-attr) : plumbing;;
530 check-ref-format) : plumbing;;
531 checkout-index) : plumbing;;
532 commit-tree) : plumbing;;
533 count-objects) : infrequent;;
534 cvsexportcommit) : export;;
535 cvsimport) : import;;
536 cvsserver) : daemon;;
538 diff-files) : plumbing;;
539 diff-index) : plumbing;;
540 diff-tree) : plumbing;;
541 fast-import) : import;;
542 fast-export) : export;;
543 fsck-objects) : plumbing;;
544 fetch-pack) : plumbing;;
545 fmt-merge-msg) : plumbing;;
546 for-each-ref) : plumbing;;
547 hash-object) : plumbing;;
548 http-*) : transport;;
549 index-pack) : plumbing;;
550 init-db) : deprecated;;
551 local-fetch) : plumbing;;
552 lost-found) : infrequent;;
553 ls-files) : plumbing;;
554 ls-remote) : plumbing;;
555 ls-tree) : plumbing;;
556 mailinfo) : plumbing;;
557 mailsplit) : plumbing;;
558 merge-*) : plumbing;;
561 pack-objects) : plumbing;;
562 pack-redundant) : plumbing;;
563 pack-refs) : plumbing;;
564 parse-remote) : plumbing;;
565 patch-id) : plumbing;;
566 peek-remote) : plumbing;;
568 prune-packed) : plumbing;;
569 quiltimport) : import;;
570 read-tree) : plumbing;;
571 receive-pack) : plumbing;;
573 repo-config) : deprecated;;
575 rev-list) : plumbing;;
576 rev-parse) : plumbing;;
577 runstatus) : plumbing;;
578 sh-setup) : internal;;
580 show-ref) : plumbing;;
581 send-pack) : plumbing;;
582 show-index) : plumbing;;
584 stripspace) : plumbing;;
585 symbolic-ref) : plumbing;;
586 tar-tree) : deprecated;;
587 unpack-file) : plumbing;;
588 unpack-objects) : plumbing;;
589 update-index) : plumbing;;
590 update-ref) : plumbing;;
591 update-server-info) : daemon;;
592 upload-archive) : plumbing;;
593 upload-pack) : plumbing;;
594 write-tree) : plumbing;;
596 verify-pack) : infrequent;;
597 verify-tag) : plumbing;;
602 __git_porcelain_commandlist=
603 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
608 for i in $(git --git-dir="$(__gitdir)" config --list); do
618 # __git_aliased_command requires 1 argument
619 __git_aliased_command ()
621 local word cmdline=$(git --git-dir="$(__gitdir)" \
622 config --get "alias.$1")
623 for word in $cmdline; do
624 if [ "${word##-*}" ]; then
631 # __git_find_subcommand requires 1 argument
632 __git_find_subcommand ()
634 local word subcommand c=1
636 while [ $c -lt $COMP_CWORD ]; do
637 word="${COMP_WORDS[c]}"
638 for subcommand in $1; do
639 if [ "$subcommand" = "$word" ]; then
648 __git_has_doubledash ()
651 while [ $c -lt $COMP_CWORD ]; do
652 if [ "--" = "${COMP_WORDS[c]}" ]; then
660 __git_whitespacelist="nowarn warn error error-all fix"
664 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
665 if [ -d "$dir"/rebase-apply ]; then
666 __gitcomp "--skip --resolved --abort"
671 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
676 --3way --committer-date-is-author-date --ignore-date
677 --ignore-whitespace --ignore-space-change
678 --interactive --keep --no-utf8 --signoff --utf8
688 local cur="${COMP_WORDS[COMP_CWORD]}"
691 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
696 --stat --numstat --summary --check --index
697 --cached --index-info --reverse --reject --unidiff-zero
698 --apply --no-add --exclude=
699 --ignore-whitespace --ignore-space-change
700 --whitespace= --inaccurate-eof --verbose
709 __git_has_doubledash && return
711 local cur="${COMP_WORDS[COMP_CWORD]}"
715 --interactive --refresh --patch --update --dry-run
716 --ignore-errors --intent-to-add
725 local cur="${COMP_WORDS[COMP_CWORD]}"
728 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
732 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
737 --format= --list --verbose
738 --prefix= --remote= --exec=
748 __git_has_doubledash && return
750 local subcommands="start bad good skip reset visualize replay log run"
751 local subcommand="$(__git_find_subcommand "$subcommands")"
752 if [ -z "$subcommand" ]; then
753 __gitcomp "$subcommands"
757 case "$subcommand" in
759 __gitcomp "$(__git_refs)"
769 local i c=1 only_local_ref="n" has_r="n"
771 while [ $c -lt $COMP_CWORD ]; do
774 -d|-m) only_local_ref="y" ;;
780 case "${COMP_WORDS[COMP_CWORD]}" in
783 --color --no-color --verbose --abbrev= --no-abbrev
784 --track --no-track --contains --merged --no-merged
788 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
789 __gitcomp "$(__git_heads)"
791 __gitcomp "$(__git_refs)"
799 local cmd="${COMP_WORDS[2]}"
800 case "$COMP_CWORD" in
802 __gitcomp "create list-heads verify unbundle"
810 __git_complete_revlist
819 __git_has_doubledash && return
821 __gitcomp "$(__git_refs)"
826 __gitcomp "$(__git_refs)"
831 local cur="${COMP_WORDS[COMP_CWORD]}"
834 __gitcomp "--edit --no-commit"
837 __gitcomp "$(__git_refs)"
844 __git_has_doubledash && return
846 local cur="${COMP_WORDS[COMP_CWORD]}"
849 __gitcomp "--dry-run --quiet"
858 local cur="${COMP_WORDS[COMP_CWORD]}"
883 __git_has_doubledash && return
885 local cur="${COMP_WORDS[COMP_CWORD]}"
889 --all --author= --signoff --verify --no-verify
890 --edit --amend --include --only --interactive
899 local cur="${COMP_WORDS[COMP_CWORD]}"
903 --all --tags --contains --abbrev= --candidates=
904 --exact-match --debug --long --match --always
908 __gitcomp "$(__git_refs)"
911 __git_diff_common_options="--stat --numstat --shortstat --summary
912 --patch-with-stat --name-only --name-status --color
913 --no-color --color-words --no-renames --check
914 --full-index --binary --abbrev --diff-filter=
916 --text --ignore-space-at-eol --ignore-space-change
917 --ignore-all-space --exit-code --quiet --ext-diff
919 --no-prefix --src-prefix= --dst-prefix=
920 --inter-hunk-context=
927 __git_has_doubledash && return
929 local cur="${COMP_WORDS[COMP_CWORD]}"
932 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
933 --base --ours --theirs
934 $__git_diff_common_options
942 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
943 tkdiff vimdiff gvimdiff xxdiff araxis
948 local cur="${COMP_WORDS[COMP_CWORD]}"
951 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
962 __git_fetch_options="
963 --quiet --verbose --append --upload-pack --force --keep --depth=
969 local cur="${COMP_WORDS[COMP_CWORD]}"
972 __gitcomp "$__git_fetch_options"
976 __git_complete_remote_or_refspec
981 local cur="${COMP_WORDS[COMP_CWORD]}"
986 " "" "${cur##--thread=}"
991 --stdout --attach --no-attach --thread --thread=
993 --numbered --start-number
998 --full-index --binary
1001 --no-prefix --src-prefix= --dst-prefix=
1002 --inline --suffix= --ignore-if-in-upstream
1008 __git_complete_revlist
1013 local cur="${COMP_WORDS[COMP_CWORD]}"
1017 --tags --root --unreachable --cache --no-reflogs --full
1018 --strict --verbose --lost-found
1028 local cur="${COMP_WORDS[COMP_CWORD]}"
1031 __gitcomp "--prune --aggressive"
1040 __git_has_doubledash && return
1042 local cur="${COMP_WORDS[COMP_CWORD]}"
1047 --text --ignore-case --word-regexp --invert-match
1049 --extended-regexp --basic-regexp --fixed-strings
1050 --files-with-matches --name-only
1051 --files-without-match
1054 --and --or --not --all-match
1064 local cur="${COMP_WORDS[COMP_CWORD]}"
1067 __gitcomp "--all --info --man --web"
1071 __gitcomp "$(__git_all_commands)
1072 attributes cli core-tutorial cvs-migration
1073 diffcore gitk glossary hooks ignore modules
1074 repository-layout tutorial tutorial-2
1081 local cur="${COMP_WORDS[COMP_CWORD]}"
1085 false true umask group all world everybody
1086 " "" "${cur##--shared=}"
1090 __gitcomp "--quiet --bare --template= --shared --shared="
1099 __git_has_doubledash && return
1101 local cur="${COMP_WORDS[COMP_CWORD]}"
1104 __gitcomp "--cached --deleted --modified --others --ignored
1105 --stage --directory --no-empty-directory --unmerged
1106 --killed --exclude= --exclude-from=
1107 --exclude-per-directory= --exclude-standard
1108 --error-unmatch --with-tree= --full-name
1109 --abbrev --ignored --exclude-per-directory
1119 __gitcomp "$(__git_remotes)"
1127 # Options that go well for log, shortlog and gitk
1128 __git_log_common_options="
1130 --branches --tags --remotes
1131 --first-parent --merges --no-merges
1133 --max-age= --since= --after=
1134 --min-age= --until= --before=
1136 # Options that go well for log and gitk (not shortlog)
1137 __git_log_gitk_options="
1138 --dense --sparse --full-history
1139 --simplify-merges --simplify-by-decoration
1142 # Options that go well for log and shortlog (not gitk)
1143 __git_log_shortlog_options="
1144 --author= --committer= --grep=
1148 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1149 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1153 __git_has_doubledash && return
1155 local cur="${COMP_WORDS[COMP_CWORD]}"
1156 local g="$(git rev-parse --git-dir 2>/dev/null)"
1158 if [ -f "$g/MERGE_HEAD" ]; then
1163 __gitcomp "$__git_log_pretty_formats
1164 " "" "${cur##--pretty=}"
1168 __gitcomp "$__git_log_pretty_formats
1169 " "" "${cur##--format=}"
1173 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1178 $__git_log_common_options
1179 $__git_log_shortlog_options
1180 $__git_log_gitk_options
1181 --root --topo-order --date-order --reverse
1182 --follow --full-diff
1183 --abbrev-commit --abbrev=
1184 --relative-date --date=
1185 --pretty= --format= --oneline
1190 --parents --children
1192 $__git_diff_common_options
1193 --pickaxe-all --pickaxe-regex
1198 __git_complete_revlist
1201 __git_merge_options="
1202 --no-commit --no-stat --log --no-log --squash --strategy
1203 --commit --stat --no-squash --ff --no-ff
1208 __git_complete_strategy && return
1210 local cur="${COMP_WORDS[COMP_CWORD]}"
1213 __gitcomp "$__git_merge_options"
1216 __gitcomp "$(__git_refs)"
1221 local cur="${COMP_WORDS[COMP_CWORD]}"
1224 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1237 __gitcomp "$(__git_refs)"
1242 local cur="${COMP_WORDS[COMP_CWORD]}"
1245 __gitcomp "--dry-run"
1254 __gitcomp "--tags --all --stdin"
1259 __git_complete_strategy && return
1261 local cur="${COMP_WORDS[COMP_CWORD]}"
1265 --rebase --no-rebase
1266 $__git_merge_options
1267 $__git_fetch_options
1272 __git_complete_remote_or_refspec
1277 local cur="${COMP_WORDS[COMP_CWORD]}"
1278 case "${COMP_WORDS[COMP_CWORD-1]}" in
1280 __gitcomp "$(__git_remotes)"
1285 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1290 --all --mirror --tags --dry-run --force --verbose
1291 --receive-pack= --repo=
1296 __git_complete_remote_or_refspec
1301 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1302 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1303 __gitcomp "--continue --skip --abort"
1306 __git_complete_strategy && return
1309 __gitcomp "--onto --merge --strategy --interactive"
1312 __gitcomp "$(__git_refs)"
1315 __git_send_email_confirm_options="always never auto cc compose"
1316 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1320 local cur="${COMP_WORDS[COMP_CWORD]}"
1324 $__git_send_email_confirm_options
1325 " "" "${cur##--confirm=}"
1330 $__git_send_email_suppresscc_options
1331 " "" "${cur##--suppress-cc=}"
1335 --smtp-encryption=*)
1336 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1340 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1341 --compose --confirm= --dry-run --envelope-sender
1343 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1344 --no-suppress-from --no-thread --quiet
1345 --signed-off-by-cc --smtp-pass --smtp-server
1346 --smtp-server-port --smtp-encryption= --smtp-user
1347 --subject --suppress-cc= --suppress-from --thread --to
1348 --validate --no-validate"
1355 __git_config_get_set_variables ()
1357 local prevword word config_file= c=$COMP_CWORD
1358 while [ $c -gt 1 ]; do
1359 word="${COMP_WORDS[c]}"
1361 --global|--system|--file=*)
1366 config_file="$word $prevword"
1374 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1387 local cur="${COMP_WORDS[COMP_CWORD]}"
1388 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1391 __gitcomp "$(__git_remotes)"
1395 __gitcomp "$(__git_refs)"
1399 local remote="${prv#remote.}"
1400 remote="${remote%.fetch}"
1401 __gitcomp "$(__git_refs_remotes "$remote")"
1405 local remote="${prv#remote.}"
1406 remote="${remote%.push}"
1407 __gitcomp "$(git --git-dir="$(__gitdir)" \
1408 for-each-ref --format='%(refname):%(refname)' \
1412 pull.twohead|pull.octopus)
1413 __gitcomp "$(__git_merge_strategies)"
1416 color.branch|color.diff|color.interactive|\
1417 color.showbranch|color.status|color.ui)
1418 __gitcomp "always never auto"
1422 __gitcomp "false true"
1427 normal black red green yellow blue magenta cyan white
1428 bold dim ul blink reverse
1433 __gitcomp "man info web html"
1437 __gitcomp "$__git_log_date_formats"
1440 sendemail.aliasesfiletype)
1441 __gitcomp "mutt mailrc pine elm gnus"
1445 __gitcomp "$__git_send_email_confirm_options"
1448 sendemail.suppresscc)
1449 __gitcomp "$__git_send_email_suppresscc_options"
1452 --get|--get-all|--unset|--unset-all)
1453 __gitcomp "$(__git_config_get_set_variables)"
1464 --global --system --file=
1465 --list --replace-all
1466 --get --get-all --get-regexp
1467 --add --unset --unset-all
1468 --remove-section --rename-section
1473 local pfx="${cur%.*}."
1475 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1479 local pfx="${cur%.*}."
1481 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1485 local pfx="${cur%.*}."
1488 argprompt cmd confirm needsfile noconsole norescan
1489 prompt revprompt revunmerged title
1494 local pfx="${cur%.*}."
1496 __gitcomp "cmd path" "$pfx" "$cur"
1500 local pfx="${cur%.*}."
1502 __gitcomp "cmd path" "$pfx" "$cur"
1506 local pfx="${cur%.*}."
1508 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1512 local pfx="${cur%.*}."
1514 __gitcomp "$(__git_all_commands)" "$pfx" "$cur"
1518 local pfx="${cur%.*}."
1521 url proxy fetch push mirror skipDefaultUpdate
1522 receivepack uploadpack tagopt pushurl
1527 local pfx="${cur%.*}."
1529 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1533 local pfx="${cur%.*}."
1535 __gitcomp "insteadof" "$pfx" "$cur"
1542 apply.ignorewhitespace
1544 branch.autosetupmerge
1545 branch.autosetuprebase
1548 color.branch.current
1559 color.diff.whitespace
1564 color.interactive.header
1565 color.interactive.help
1566 color.interactive.prompt
1571 color.status.changed
1573 color.status.nobranch
1574 color.status.untracked
1575 color.status.updated
1582 core.deltaBaseCacheLimit
1586 core.fsyncobjectfiles
1588 core.ignoreCygwinFSTricks
1590 core.logAllRefUpdates
1591 core.loosecompression
1593 core.packedGitWindowSize
1595 core.preferSymlinkRefs
1598 core.repositoryFormatVersion
1600 core.sharedRepository
1603 core.warnAmbiguousRefs
1606 diff.autorefreshindex
1612 diff.suppressBlankEmpty
1624 format.subjectprefix
1633 gc.reflogexpireunreachable
1637 gitcvs.commitmsgannotation
1638 gitcvs.dbTableNamePrefix
1649 gui.copyblamethreshold
1653 gui.matchtrackingbranch
1654 gui.newbranchtemplate
1655 gui.pruneduringfetch
1656 gui.spellingdictionary
1672 i18n.logOutputEncoding
1677 imap.preformattedHTML
1686 interactive.singlekey
1699 mergetool.keepBackup
1702 pack.deltaCacheLimit
1715 receive.denyCurrentBranch
1717 receive.denyNonFastForwards
1720 repack.usedeltabaseoffset
1723 sendemail.aliasesfile
1724 sendemail.aliasesfiletype
1728 sendemail.chainreplyto
1730 sendemail.envelopesender
1732 sendemail.signedoffbycc
1733 sendemail.smtpencryption
1735 sendemail.smtpserver
1736 sendemail.smtpserverport
1738 sendemail.suppresscc
1739 sendemail.suppressfrom
1744 status.relativePaths
1745 status.showUntrackedFiles
1747 transfer.unpackLimit
1759 local subcommands="add rename rm show prune update set-head"
1760 local subcommand="$(__git_find_subcommand "$subcommands")"
1761 if [ -z "$subcommand" ]; then
1762 __gitcomp "$subcommands"
1766 case "$subcommand" in
1767 rename|rm|show|prune)
1768 __gitcomp "$(__git_remotes)"
1771 local i c='' IFS=$'\n'
1772 for i in $(git --git-dir="$(__gitdir)" config --list); do
1790 __git_has_doubledash && return
1792 local cur="${COMP_WORDS[COMP_CWORD]}"
1795 __gitcomp "--merge --mixed --hard --soft"
1799 __gitcomp "$(__git_refs)"
1804 local cur="${COMP_WORDS[COMP_CWORD]}"
1807 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1811 __gitcomp "$(__git_refs)"
1816 __git_has_doubledash && return
1818 local cur="${COMP_WORDS[COMP_CWORD]}"
1821 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1830 __git_has_doubledash && return
1832 local cur="${COMP_WORDS[COMP_CWORD]}"
1836 $__git_log_common_options
1837 $__git_log_shortlog_options
1838 --numbered --summary
1843 __git_complete_revlist
1848 __git_has_doubledash && return
1850 local cur="${COMP_WORDS[COMP_CWORD]}"
1853 __gitcomp "$__git_log_pretty_formats
1854 " "" "${cur##--pretty=}"
1858 __gitcomp "$__git_log_pretty_formats
1859 " "" "${cur##--format=}"
1863 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1864 $__git_diff_common_options
1874 local cur="${COMP_WORDS[COMP_CWORD]}"
1878 --all --remotes --topo-order --current --more=
1879 --list --independent --merge-base --no-name
1881 --sha1-name --sparse --topics --reflog
1886 __git_complete_revlist
1891 local subcommands='save list show apply clear drop pop create branch'
1892 local subcommand="$(__git_find_subcommand "$subcommands")"
1893 if [ -z "$subcommand" ]; then
1894 __gitcomp "$subcommands"
1896 local cur="${COMP_WORDS[COMP_CWORD]}"
1897 case "$subcommand,$cur" in
1899 __gitcomp "--keep-index"
1904 show,--*|drop,--*|branch,--*)
1907 show,*|apply,*|drop,*|pop,*|branch,*)
1908 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1909 | sed -n -e 's/:.*//p')"
1920 __git_has_doubledash && return
1922 local subcommands="add status init update summary foreach sync"
1923 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1924 local cur="${COMP_WORDS[COMP_CWORD]}"
1927 __gitcomp "--quiet --cached"
1930 __gitcomp "$subcommands"
1940 init fetch clone rebase dcommit log find-rev
1941 set-tree commit-diff info create-ignore propget
1942 proplist show-ignore show-externals branch tag blame
1945 local subcommand="$(__git_find_subcommand "$subcommands")"
1946 if [ -z "$subcommand" ]; then
1947 __gitcomp "$subcommands"
1949 local remote_opts="--username= --config-dir= --no-auth-cache"
1951 --follow-parent --authors-file= --repack=
1952 --no-metadata --use-svm-props --use-svnsync-props
1953 --log-window-size= --no-checkout --quiet
1954 --repack-flags --use-log-author --localtime
1955 --ignore-paths= $remote_opts
1958 --template= --shared= --trunk= --tags=
1959 --branches= --stdlayout --minimize-url
1960 --no-metadata --use-svm-props --use-svnsync-props
1961 --rewrite-root= --prefix= --use-log-author
1962 --add-author-from $remote_opts
1965 --edit --rmdir --find-copies-harder --copy-similarity=
1968 local cur="${COMP_WORDS[COMP_CWORD]}"
1969 case "$subcommand,$cur" in
1971 __gitcomp "--revision= --fetch-all $fc_opts"
1974 __gitcomp "--revision= $fc_opts $init_opts"
1977 __gitcomp "$init_opts"
1981 --merge --strategy= --verbose --dry-run
1982 --fetch-all --no-rebase --commit-url
1983 --revision $cmt_opts $fc_opts
1987 __gitcomp "--stdin $cmt_opts $fc_opts"
1989 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1991 __gitcomp "--revision="
1995 --limit= --revision= --verbose --incremental
1996 --oneline --show-commit --non-recursive
1997 --authors-file= --color
2002 --merge --verbose --strategy= --local
2003 --fetch-all --dry-run $fc_opts
2007 __gitcomp "--message= --file= --revision= $cmt_opts"
2013 __gitcomp "--dry-run --message --tag"
2016 __gitcomp "--dry-run --message"
2019 __gitcomp "--git-format"
2023 --config-dir= --ignore-paths= --minimize
2024 --no-auth-cache --username=
2037 while [ $c -lt $COMP_CWORD ]; do
2038 i="${COMP_WORDS[c]}"
2041 __gitcomp "$(__git_tags)"
2051 case "${COMP_WORDS[COMP_CWORD-1]}" in
2057 __gitcomp "$(__git_tags)"
2063 __gitcomp "$(__git_refs)"
2070 local i c=1 command __git_dir
2072 while [ $c -lt $COMP_CWORD ]; do
2073 i="${COMP_WORDS[c]}"
2075 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2076 --bare) __git_dir="." ;;
2077 --version|-p|--paginate) ;;
2078 --help) command="help"; break ;;
2079 *) command="$i"; break ;;
2084 if [ -z "$command" ]; then
2085 case "${COMP_WORDS[COMP_CWORD]}" in
2098 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
2103 local expansion=$(__git_aliased_command "$command")
2104 [ "$expansion" ] && command="$expansion"
2109 apply) _git_apply ;;
2110 archive) _git_archive ;;
2111 bisect) _git_bisect ;;
2112 bundle) _git_bundle ;;
2113 branch) _git_branch ;;
2114 checkout) _git_checkout ;;
2115 cherry) _git_cherry ;;
2116 cherry-pick) _git_cherry_pick ;;
2117 clean) _git_clean ;;
2118 clone) _git_clone ;;
2119 commit) _git_commit ;;
2120 config) _git_config ;;
2121 describe) _git_describe ;;
2123 difftool) _git_difftool ;;
2124 fetch) _git_fetch ;;
2125 format-patch) _git_format_patch ;;
2132 ls-files) _git_ls_files ;;
2133 ls-remote) _git_ls_remote ;;
2134 ls-tree) _git_ls_tree ;;
2136 mergetool) _git_mergetool;;
2137 merge-base) _git_merge_base ;;
2139 name-rev) _git_name_rev ;;
2142 rebase) _git_rebase ;;
2143 remote) _git_remote ;;
2144 reset) _git_reset ;;
2145 revert) _git_revert ;;
2147 send-email) _git_send_email ;;
2148 shortlog) _git_shortlog ;;
2150 show-branch) _git_show_branch ;;
2151 stash) _git_stash ;;
2153 submodule) _git_submodule ;;
2156 whatchanged) _git_log ;;
2163 __git_has_doubledash && return
2165 local cur="${COMP_WORDS[COMP_CWORD]}"
2166 local g="$(__gitdir)"
2168 if [ -f "$g/MERGE_HEAD" ]; then
2174 $__git_log_common_options
2175 $__git_log_gitk_options
2181 __git_complete_revlist
2184 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2185 || complete -o default -o nospace -F _git git
2186 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2187 || complete -o default -o nospace -F _gitk gitk
2189 # The following are necessary only for Cygwin, and only are needed
2190 # when the user has tab-completed the executable name and consequently
2191 # included the '.exe' suffix.
2193 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2194 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2195 || complete -o default -o nospace -F _git git.exe