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) Consider changing your PS1 to also show the current branch:
25 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
27 # The argument to __git_ps1 will be displayed only if you
28 # are currently in a git repository. The %s token will be
29 # the name of the current branch.
31 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
32 # value, unstaged (*) and staged (+) changes will be shown next
33 # to the branch name. You can configure this per-repository
34 # with the bash.showDirtyState variable, which defaults to true
35 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
37 # You can also see if currently something is stashed, by setting
38 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
39 # then a '$' will be shown next to the branch name.
41 # If you would like to see if there're untracked files, then you can
42 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
43 # untracked files, then a '%' will be shown next to the branch name.
47 # *) Read Documentation/SubmittingPatches
48 # *) Send all patches to the current maintainer:
50 # "Shawn O. Pearce" <spearce@spearce.org>
52 # *) Always CC the Git mailing list:
57 case "$COMP_WORDBREAKS" in
59 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
62 # __gitdir accepts 0 or 1 arguments (i.e., location)
63 # returns location of .git repo
66 if [ -z "${1-}" ]; then
67 if [ -n "${__git_dir-}" ]; then
69 elif [ -d .git ]; then
72 git rev-parse --git-dir 2>/dev/null
74 elif [ -d "$1/.git" ]; then
81 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
82 # returns text to add to bash PS1 prompt (includes branch name)
89 if [ -f "$g/rebase-merge/interactive" ]; then
91 b="$(cat "$g/rebase-merge/head-name")"
92 elif [ -d "$g/rebase-merge" ]; then
94 b="$(cat "$g/rebase-merge/head-name")"
96 if [ -d "$g/rebase-apply" ]; then
97 if [ -f "$g/rebase-apply/rebasing" ]; then
99 elif [ -f "$g/rebase-apply/applying" ]; then
104 elif [ -f "$g/MERGE_HEAD" ]; then
106 elif [ -f "$g/BISECT_LOG" ]; then
110 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
113 case "${GIT_PS1_DESCRIBE_STYLE-}" in
115 git describe --contains HEAD ;;
117 git describe --contains --all HEAD ;;
121 git describe --exact-match HEAD ;;
122 esac 2>/dev/null)" ||
124 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
136 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
137 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
142 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
143 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
144 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
145 git diff --no-ext-diff --quiet --exit-code || w="*"
146 if git rev-parse --quiet --verify HEAD >/dev/null; then
147 git diff-index --cached --quiet HEAD -- || i="+"
153 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
154 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
157 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
158 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
164 if [ -n "${1-}" ]; then
165 printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
167 printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
172 # __gitcomp_1 requires 2 arguments
175 local c IFS=' '$'\t'$'\n'
178 --*=*) printf %s$'\n' "$c$2" ;;
179 *.) printf %s$'\n' "$c$2" ;;
180 *) printf %s$'\n' "$c$2 " ;;
185 # __gitcomp accepts 1, 2, 3, or 4 arguments
186 # generates completion reply with compgen
189 local cur="${COMP_WORDS[COMP_CWORD]}"
190 if [ $# -gt 2 ]; then
199 COMPREPLY=($(compgen -P "${2-}" \
200 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
206 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
209 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
210 if [ -d "$dir" ]; then
211 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
215 for i in $(git ls-remote "${1-}" 2>/dev/null); do
216 case "$is_hash,$i" in
219 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
220 n,*) is_hash=y; echo "$i" ;;
225 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
228 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
229 if [ -d "$dir" ]; then
230 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
234 for i in $(git ls-remote "${1-}" 2>/dev/null); do
235 case "$is_hash,$i" in
238 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
239 n,*) is_hash=y; echo "$i" ;;
244 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
247 local i is_hash=y dir="$(__gitdir "${1-}")"
248 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
249 if [ -d "$dir" ]; then
256 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
257 format="refname:short"
258 refs="refs/tags refs/heads refs/remotes"
261 git --git-dir="$dir" for-each-ref --format="%($format)" \
265 for i in $(git ls-remote "$dir" 2>/dev/null); do
266 case "$is_hash,$i" in
269 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
270 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
271 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
272 n,*) is_hash=y; echo "$i" ;;
277 # __git_refs2 requires 1 argument (to pass to __git_refs)
281 for i in $(__git_refs "$1"); do
286 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
287 __git_refs_remotes ()
289 local cmd i is_hash=y
290 for i in $(git ls-remote "$1" 2>/dev/null); do
291 case "$is_hash,$i" in
294 echo "$i:refs/remotes/$1/${i#refs/heads/}"
298 n,refs/tags/*) is_hash=y;;
306 local i ngoff IFS=$'\n' d="$(__gitdir)"
307 shopt -q nullglob || ngoff=1
309 for i in "$d/remotes"/*; do
310 echo ${i#$d/remotes/}
312 [ "$ngoff" ] && shopt -u nullglob
313 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
319 __git_list_merge_strategies ()
321 git merge -s help 2>&1 |
322 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
331 __git_merge_strategies=
332 # 'git merge -s help' (and thus detection of the merge strategy
333 # list) fails, unfortunately, if run outside of any git working
334 # tree. __git_merge_strategies is set to the empty string in
335 # that case, and the detection will be repeated the next time it
337 __git_compute_merge_strategies ()
339 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
342 __git_complete_file ()
344 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
361 case "$COMP_WORDBREAKS" in
363 *) pfx="$ref:$pfx" ;;
367 COMPREPLY=($(compgen -P "$pfx" \
368 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
369 | sed '/^100... blob /{
385 __gitcomp "$(__git_refs)"
390 __git_complete_revlist ()
392 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
397 __gitcomp "$(__git_refs)" "$pfx" "$cur"
402 __gitcomp "$(__git_refs)" "$pfx" "$cur"
405 __gitcomp "$(__git_refs)"
410 __git_complete_remote_or_refspec ()
412 local cmd="${COMP_WORDS[1]}"
413 local cur="${COMP_WORDS[COMP_CWORD]}"
414 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
415 while [ $c -lt $COMP_CWORD ]; do
418 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
421 push) no_complete_refspec=1 ;;
430 *) remote="$i"; break ;;
434 if [ -z "$remote" ]; then
435 __gitcomp "$(__git_remotes)"
438 if [ $no_complete_refspec = 1 ]; then
442 [ "$remote" = "." ] && remote=
445 case "$COMP_WORDBREAKS" in
447 *) pfx="${cur%%:*}:" ;;
459 if [ $lhs = 1 ]; then
460 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
462 __gitcomp "$(__git_refs)" "$pfx" "$cur"
466 if [ $lhs = 1 ]; then
467 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
469 __gitcomp "$(__git_refs)" "$pfx" "$cur"
473 if [ $lhs = 1 ]; then
474 __gitcomp "$(__git_refs)" "$pfx" "$cur"
476 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
482 __git_complete_strategy ()
484 __git_compute_merge_strategies
485 case "${COMP_WORDS[COMP_CWORD-1]}" in
487 __gitcomp "$__git_merge_strategies"
490 local cur="${COMP_WORDS[COMP_CWORD]}"
493 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
500 __git_list_all_commands ()
503 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
506 *--*) : helper pattern;;
513 __git_compute_all_commands ()
515 : ${__git_all_commands:=$(__git_list_all_commands)}
518 __git_list_porcelain_commands ()
521 __git_compute_all_commands
522 for i in "help" $__git_all_commands
525 *--*) : helper pattern;;
526 applymbox) : ask gittus;;
527 applypatch) : ask gittus;;
528 archimport) : import;;
529 cat-file) : plumbing;;
530 check-attr) : plumbing;;
531 check-ref-format) : plumbing;;
532 checkout-index) : plumbing;;
533 commit-tree) : plumbing;;
534 count-objects) : infrequent;;
535 cvsexportcommit) : export;;
536 cvsimport) : import;;
537 cvsserver) : daemon;;
539 diff-files) : plumbing;;
540 diff-index) : plumbing;;
541 diff-tree) : plumbing;;
542 fast-import) : import;;
543 fast-export) : export;;
544 fsck-objects) : plumbing;;
545 fetch-pack) : plumbing;;
546 fmt-merge-msg) : plumbing;;
547 for-each-ref) : plumbing;;
548 hash-object) : plumbing;;
549 http-*) : transport;;
550 index-pack) : plumbing;;
551 init-db) : deprecated;;
552 local-fetch) : plumbing;;
553 lost-found) : infrequent;;
554 ls-files) : plumbing;;
555 ls-remote) : plumbing;;
556 ls-tree) : plumbing;;
557 mailinfo) : plumbing;;
558 mailsplit) : plumbing;;
559 merge-*) : plumbing;;
562 pack-objects) : plumbing;;
563 pack-redundant) : plumbing;;
564 pack-refs) : plumbing;;
565 parse-remote) : plumbing;;
566 patch-id) : plumbing;;
567 peek-remote) : plumbing;;
569 prune-packed) : plumbing;;
570 quiltimport) : import;;
571 read-tree) : plumbing;;
572 receive-pack) : plumbing;;
574 repo-config) : deprecated;;
576 rev-list) : plumbing;;
577 rev-parse) : plumbing;;
578 runstatus) : plumbing;;
579 sh-setup) : internal;;
581 show-ref) : plumbing;;
582 send-pack) : plumbing;;
583 show-index) : plumbing;;
585 stripspace) : plumbing;;
586 symbolic-ref) : plumbing;;
587 tar-tree) : deprecated;;
588 unpack-file) : plumbing;;
589 unpack-objects) : plumbing;;
590 update-index) : plumbing;;
591 update-ref) : plumbing;;
592 update-server-info) : daemon;;
593 upload-archive) : plumbing;;
594 upload-pack) : plumbing;;
595 write-tree) : plumbing;;
597 verify-pack) : infrequent;;
598 verify-tag) : plumbing;;
604 __git_porcelain_commands=
605 __git_compute_porcelain_commands ()
607 __git_compute_all_commands
608 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
614 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
624 # __git_aliased_command requires 1 argument
625 __git_aliased_command ()
627 local word cmdline=$(git --git-dir="$(__gitdir)" \
628 config --get "alias.$1")
629 for word in $cmdline; do
630 if [ "${word##-*}" ]; then
637 # __git_find_on_cmdline requires 1 argument
638 __git_find_on_cmdline ()
640 local word subcommand c=1
642 while [ $c -lt $COMP_CWORD ]; do
643 word="${COMP_WORDS[c]}"
644 for subcommand in $1; do
645 if [ "$subcommand" = "$word" ]; then
654 __git_has_doubledash ()
657 while [ $c -lt $COMP_CWORD ]; do
658 if [ "--" = "${COMP_WORDS[c]}" ]; then
666 __git_whitespacelist="nowarn warn error error-all fix"
670 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
671 if [ -d "$dir"/rebase-apply ]; then
672 __gitcomp "--skip --resolved --abort"
677 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
682 --3way --committer-date-is-author-date --ignore-date
683 --ignore-whitespace --ignore-space-change
684 --interactive --keep --no-utf8 --signoff --utf8
685 --whitespace= --scissors
694 local cur="${COMP_WORDS[COMP_CWORD]}"
697 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
702 --stat --numstat --summary --check --index
703 --cached --index-info --reverse --reject --unidiff-zero
704 --apply --no-add --exclude=
705 --ignore-whitespace --ignore-space-change
706 --whitespace= --inaccurate-eof --verbose
715 __git_has_doubledash && return
717 local cur="${COMP_WORDS[COMP_CWORD]}"
721 --interactive --refresh --patch --update --dry-run
722 --ignore-errors --intent-to-add
731 local cur="${COMP_WORDS[COMP_CWORD]}"
734 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
738 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
743 --format= --list --verbose
744 --prefix= --remote= --exec=
754 __git_has_doubledash && return
756 local subcommands="start bad good skip reset visualize replay log run"
757 local subcommand="$(__git_find_on_cmdline "$subcommands")"
758 if [ -z "$subcommand" ]; then
759 __gitcomp "$subcommands"
763 case "$subcommand" in
765 __gitcomp "$(__git_refs)"
775 local i c=1 only_local_ref="n" has_r="n"
777 while [ $c -lt $COMP_CWORD ]; do
780 -d|-m) only_local_ref="y" ;;
786 case "${COMP_WORDS[COMP_CWORD]}" in
789 --color --no-color --verbose --abbrev= --no-abbrev
790 --track --no-track --contains --merged --no-merged
794 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
795 __gitcomp "$(__git_heads)"
797 __gitcomp "$(__git_refs)"
805 local cmd="${COMP_WORDS[2]}"
806 case "$COMP_CWORD" in
808 __gitcomp "create list-heads verify unbundle"
816 __git_complete_revlist
825 __git_has_doubledash && return
827 local cur="${COMP_WORDS[COMP_CWORD]}"
830 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
834 --quiet --ours --theirs --track --no-track --merge
839 __gitcomp "$(__git_refs)"
846 __gitcomp "$(__git_refs)"
851 local cur="${COMP_WORDS[COMP_CWORD]}"
854 __gitcomp "--edit --no-commit"
857 __gitcomp "$(__git_refs)"
864 __git_has_doubledash && return
866 local cur="${COMP_WORDS[COMP_CWORD]}"
869 __gitcomp "--dry-run --quiet"
878 local cur="${COMP_WORDS[COMP_CWORD]}"
903 __git_has_doubledash && return
905 local cur="${COMP_WORDS[COMP_CWORD]}"
908 __gitcomp "default strip verbatim whitespace
909 " "" "${cur##--cleanup=}"
913 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
917 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
921 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
926 --all --author= --signoff --verify --no-verify
927 --edit --amend --include --only --interactive
928 --dry-run --reuse-message= --reedit-message=
929 --reset-author --file= --message= --template=
930 --cleanup= --untracked-files --untracked-files=
940 local cur="${COMP_WORDS[COMP_CWORD]}"
944 --all --tags --contains --abbrev= --candidates=
945 --exact-match --debug --long --match --always
949 __gitcomp "$(__git_refs)"
952 __git_diff_common_options="--stat --numstat --shortstat --summary
953 --patch-with-stat --name-only --name-status --color
954 --no-color --color-words --no-renames --check
955 --full-index --binary --abbrev --diff-filter=
957 --text --ignore-space-at-eol --ignore-space-change
958 --ignore-all-space --exit-code --quiet --ext-diff
960 --no-prefix --src-prefix= --dst-prefix=
961 --inter-hunk-context=
964 --dirstat --dirstat= --dirstat-by-file
965 --dirstat-by-file= --cumulative
970 __git_has_doubledash && return
972 local cur="${COMP_WORDS[COMP_CWORD]}"
975 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
976 --base --ours --theirs
977 $__git_diff_common_options
985 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
986 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
991 __git_has_doubledash && return
993 local cur="${COMP_WORDS[COMP_CWORD]}"
996 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1000 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1001 --base --ours --theirs
1002 --no-renames --diff-filter= --find-copies-harder
1003 --relative --ignore-submodules
1011 __git_fetch_options="
1012 --quiet --verbose --append --upload-pack --force --keep --depth=
1013 --tags --no-tags --all --prune --dry-run
1018 local cur="${COMP_WORDS[COMP_CWORD]}"
1021 __gitcomp "$__git_fetch_options"
1025 __git_complete_remote_or_refspec
1028 _git_format_patch ()
1030 local cur="${COMP_WORDS[COMP_CWORD]}"
1035 " "" "${cur##--thread=}"
1040 --stdout --attach --no-attach --thread --thread=
1042 --numbered --start-number
1046 --in-reply-to= --cc=
1047 --full-index --binary
1050 --no-prefix --src-prefix= --dst-prefix=
1051 --inline --suffix= --ignore-if-in-upstream
1057 __git_complete_revlist
1062 local cur="${COMP_WORDS[COMP_CWORD]}"
1066 --tags --root --unreachable --cache --no-reflogs --full
1067 --strict --verbose --lost-found
1077 local cur="${COMP_WORDS[COMP_CWORD]}"
1080 __gitcomp "--prune --aggressive"
1089 __git_has_doubledash && return
1091 local cur="${COMP_WORDS[COMP_CWORD]}"
1096 --text --ignore-case --word-regexp --invert-match
1098 --extended-regexp --basic-regexp --fixed-strings
1099 --files-with-matches --name-only
1100 --files-without-match
1103 --and --or --not --all-match
1109 __gitcomp "$(__git_refs)"
1114 local cur="${COMP_WORDS[COMP_CWORD]}"
1117 __gitcomp "--all --info --man --web"
1121 __git_compute_all_commands
1122 __gitcomp "$__git_all_commands
1123 attributes cli core-tutorial cvs-migration
1124 diffcore gitk glossary hooks ignore modules
1125 repository-layout tutorial tutorial-2
1132 local cur="${COMP_WORDS[COMP_CWORD]}"
1136 false true umask group all world everybody
1137 " "" "${cur##--shared=}"
1141 __gitcomp "--quiet --bare --template= --shared --shared="
1150 __git_has_doubledash && return
1152 local cur="${COMP_WORDS[COMP_CWORD]}"
1155 __gitcomp "--cached --deleted --modified --others --ignored
1156 --stage --directory --no-empty-directory --unmerged
1157 --killed --exclude= --exclude-from=
1158 --exclude-per-directory= --exclude-standard
1159 --error-unmatch --with-tree= --full-name
1160 --abbrev --ignored --exclude-per-directory
1170 __gitcomp "$(__git_remotes)"
1178 # Options that go well for log, shortlog and gitk
1179 __git_log_common_options="
1181 --branches --tags --remotes
1182 --first-parent --merges --no-merges
1184 --max-age= --since= --after=
1185 --min-age= --until= --before=
1187 # Options that go well for log and gitk (not shortlog)
1188 __git_log_gitk_options="
1189 --dense --sparse --full-history
1190 --simplify-merges --simplify-by-decoration
1193 # Options that go well for log and shortlog (not gitk)
1194 __git_log_shortlog_options="
1195 --author= --committer= --grep=
1199 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1200 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1204 __git_has_doubledash && return
1206 local cur="${COMP_WORDS[COMP_CWORD]}"
1207 local g="$(git rev-parse --git-dir 2>/dev/null)"
1209 if [ -f "$g/MERGE_HEAD" ]; then
1214 __gitcomp "$__git_log_pretty_formats
1215 " "" "${cur##--pretty=}"
1219 __gitcomp "$__git_log_pretty_formats
1220 " "" "${cur##--format=}"
1224 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1228 __gitcomp "long short" "" "${cur##--decorate=}"
1233 $__git_log_common_options
1234 $__git_log_shortlog_options
1235 $__git_log_gitk_options
1236 --root --topo-order --date-order --reverse
1237 --follow --full-diff
1238 --abbrev-commit --abbrev=
1239 --relative-date --date=
1240 --pretty= --format= --oneline
1243 --decorate --decorate=
1245 --parents --children
1247 $__git_diff_common_options
1248 --pickaxe-all --pickaxe-regex
1253 __git_complete_revlist
1256 __git_merge_options="
1257 --no-commit --no-stat --log --no-log --squash --strategy
1258 --commit --stat --no-squash --ff --no-ff --ff-only
1263 __git_complete_strategy && return
1265 local cur="${COMP_WORDS[COMP_CWORD]}"
1268 __gitcomp "$__git_merge_options"
1271 __gitcomp "$(__git_refs)"
1276 local cur="${COMP_WORDS[COMP_CWORD]}"
1279 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1292 __gitcomp "$(__git_refs)"
1297 local cur="${COMP_WORDS[COMP_CWORD]}"
1300 __gitcomp "--dry-run"
1309 __gitcomp "--tags --all --stdin"
1314 __git_complete_strategy && return
1316 local cur="${COMP_WORDS[COMP_CWORD]}"
1320 --rebase --no-rebase
1321 $__git_merge_options
1322 $__git_fetch_options
1327 __git_complete_remote_or_refspec
1332 local cur="${COMP_WORDS[COMP_CWORD]}"
1333 case "${COMP_WORDS[COMP_CWORD-1]}" in
1335 __gitcomp "$(__git_remotes)"
1340 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1345 --all --mirror --tags --dry-run --force --verbose
1346 --receive-pack= --repo=
1351 __git_complete_remote_or_refspec
1356 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1357 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1358 __gitcomp "--continue --skip --abort"
1361 __git_complete_strategy && return
1364 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1369 --onto --merge --strategy --interactive
1370 --preserve-merges --stat --no-stat
1371 --committer-date-is-author-date --ignore-date
1372 --ignore-whitespace --whitespace=
1377 __gitcomp "$(__git_refs)"
1380 __git_send_email_confirm_options="always never auto cc compose"
1381 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1385 local cur="${COMP_WORDS[COMP_CWORD]}"
1389 $__git_send_email_confirm_options
1390 " "" "${cur##--confirm=}"
1395 $__git_send_email_suppresscc_options
1396 " "" "${cur##--suppress-cc=}"
1400 --smtp-encryption=*)
1401 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1405 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1406 --compose --confirm= --dry-run --envelope-sender
1408 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1409 --no-suppress-from --no-thread --quiet
1410 --signed-off-by-cc --smtp-pass --smtp-server
1411 --smtp-server-port --smtp-encryption= --smtp-user
1412 --subject --suppress-cc= --suppress-from --thread --to
1413 --validate --no-validate"
1420 __git_config_get_set_variables ()
1422 local prevword word config_file= c=$COMP_CWORD
1423 while [ $c -gt 1 ]; do
1424 word="${COMP_WORDS[c]}"
1426 --global|--system|--file=*)
1431 config_file="$word $prevword"
1439 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1452 local cur="${COMP_WORDS[COMP_CWORD]}"
1453 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1456 __gitcomp "$(__git_remotes)"
1460 __gitcomp "$(__git_refs)"
1464 local remote="${prv#remote.}"
1465 remote="${remote%.fetch}"
1466 __gitcomp "$(__git_refs_remotes "$remote")"
1470 local remote="${prv#remote.}"
1471 remote="${remote%.push}"
1472 __gitcomp "$(git --git-dir="$(__gitdir)" \
1473 for-each-ref --format='%(refname):%(refname)' \
1477 pull.twohead|pull.octopus)
1478 __git_compute_merge_strategies
1479 __gitcomp "$__git_merge_strategies"
1482 color.branch|color.diff|color.interactive|\
1483 color.showbranch|color.status|color.ui)
1484 __gitcomp "always never auto"
1488 __gitcomp "false true"
1493 normal black red green yellow blue magenta cyan white
1494 bold dim ul blink reverse
1499 __gitcomp "man info web html"
1503 __gitcomp "$__git_log_date_formats"
1506 sendemail.aliasesfiletype)
1507 __gitcomp "mutt mailrc pine elm gnus"
1511 __gitcomp "$__git_send_email_confirm_options"
1514 sendemail.suppresscc)
1515 __gitcomp "$__git_send_email_suppresscc_options"
1518 --get|--get-all|--unset|--unset-all)
1519 __gitcomp "$(__git_config_get_set_variables)"
1530 --global --system --file=
1531 --list --replace-all
1532 --get --get-all --get-regexp
1533 --add --unset --unset-all
1534 --remove-section --rename-section
1539 local pfx="${cur%.*}."
1541 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1545 local pfx="${cur%.*}."
1547 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1551 local pfx="${cur%.*}."
1554 argprompt cmd confirm needsfile noconsole norescan
1555 prompt revprompt revunmerged title
1560 local pfx="${cur%.*}."
1562 __gitcomp "cmd path" "$pfx" "$cur"
1566 local pfx="${cur%.*}."
1568 __gitcomp "cmd path" "$pfx" "$cur"
1572 local pfx="${cur%.*}."
1574 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1578 local pfx="${cur%.*}."
1580 __git_compute_all_commands
1581 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1585 local pfx="${cur%.*}."
1588 url proxy fetch push mirror skipDefaultUpdate
1589 receivepack uploadpack tagopt pushurl
1594 local pfx="${cur%.*}."
1596 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1600 local pfx="${cur%.*}."
1602 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1609 apply.ignorewhitespace
1611 branch.autosetupmerge
1612 branch.autosetuprebase
1615 color.branch.current
1626 color.diff.whitespace
1631 color.interactive.header
1632 color.interactive.help
1633 color.interactive.prompt
1638 color.status.changed
1640 color.status.nobranch
1641 color.status.untracked
1642 color.status.updated
1649 core.deltaBaseCacheLimit
1653 core.fsyncobjectfiles
1655 core.ignoreCygwinFSTricks
1657 core.logAllRefUpdates
1658 core.loosecompression
1660 core.packedGitWindowSize
1662 core.preferSymlinkRefs
1665 core.repositoryFormatVersion
1667 core.sharedRepository
1670 core.warnAmbiguousRefs
1673 diff.autorefreshindex
1679 diff.suppressBlankEmpty
1691 format.subjectprefix
1700 gc.reflogexpireunreachable
1704 gitcvs.commitmsgannotation
1705 gitcvs.dbTableNamePrefix
1716 gui.copyblamethreshold
1720 gui.matchtrackingbranch
1721 gui.newbranchtemplate
1722 gui.pruneduringfetch
1723 gui.spellingdictionary
1739 i18n.logOutputEncoding
1744 imap.preformattedHTML
1753 interactive.singlekey
1766 mergetool.keepBackup
1769 pack.deltaCacheLimit
1782 receive.denyCurrentBranch
1784 receive.denyNonFastForwards
1787 repack.usedeltabaseoffset
1790 sendemail.aliasesfile
1791 sendemail.aliasesfiletype
1795 sendemail.chainreplyto
1797 sendemail.envelopesender
1799 sendemail.signedoffbycc
1800 sendemail.smtpencryption
1802 sendemail.smtpserver
1803 sendemail.smtpserverport
1805 sendemail.suppresscc
1806 sendemail.suppressfrom
1811 status.relativePaths
1812 status.showUntrackedFiles
1814 transfer.unpackLimit
1826 local subcommands="add rename rm show prune update set-head"
1827 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1828 if [ -z "$subcommand" ]; then
1829 __gitcomp "$subcommands"
1833 case "$subcommand" in
1834 rename|rm|show|prune)
1835 __gitcomp "$(__git_remotes)"
1838 local i c='' IFS=$'\n'
1839 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1853 __gitcomp "$(__git_refs)"
1858 __git_has_doubledash && return
1860 local cur="${COMP_WORDS[COMP_CWORD]}"
1863 __gitcomp "--merge --mixed --hard --soft --patch"
1867 __gitcomp "$(__git_refs)"
1872 local cur="${COMP_WORDS[COMP_CWORD]}"
1875 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1879 __gitcomp "$(__git_refs)"
1884 __git_has_doubledash && return
1886 local cur="${COMP_WORDS[COMP_CWORD]}"
1889 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1898 __git_has_doubledash && return
1900 local cur="${COMP_WORDS[COMP_CWORD]}"
1904 $__git_log_common_options
1905 $__git_log_shortlog_options
1906 --numbered --summary
1911 __git_complete_revlist
1916 __git_has_doubledash && return
1918 local cur="${COMP_WORDS[COMP_CWORD]}"
1921 __gitcomp "$__git_log_pretty_formats
1922 " "" "${cur##--pretty=}"
1926 __gitcomp "$__git_log_pretty_formats
1927 " "" "${cur##--format=}"
1931 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1932 $__git_diff_common_options
1942 local cur="${COMP_WORDS[COMP_CWORD]}"
1946 --all --remotes --topo-order --current --more=
1947 --list --independent --merge-base --no-name
1949 --sha1-name --sparse --topics --reflog
1954 __git_complete_revlist
1959 local cur="${COMP_WORDS[COMP_CWORD]}"
1960 local save_opts='--keep-index --no-keep-index --quiet --patch'
1961 local subcommands='save list show apply clear drop pop create branch'
1962 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1963 if [ -z "$subcommand" ]; then
1966 __gitcomp "$save_opts"
1969 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1970 __gitcomp "$subcommands"
1977 case "$subcommand,$cur" in
1979 __gitcomp "$save_opts"
1982 __gitcomp "--index --quiet"
1984 show,--*|drop,--*|branch,--*)
1987 show,*|apply,*|drop,*|pop,*|branch,*)
1988 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1989 | sed -n -e 's/:.*//p')"
2000 __git_has_doubledash && return
2002 local subcommands="add status init update summary foreach sync"
2003 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2004 local cur="${COMP_WORDS[COMP_CWORD]}"
2007 __gitcomp "--quiet --cached"
2010 __gitcomp "$subcommands"
2020 init fetch clone rebase dcommit log find-rev
2021 set-tree commit-diff info create-ignore propget
2022 proplist show-ignore show-externals branch tag blame
2025 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2026 if [ -z "$subcommand" ]; then
2027 __gitcomp "$subcommands"
2029 local remote_opts="--username= --config-dir= --no-auth-cache"
2031 --follow-parent --authors-file= --repack=
2032 --no-metadata --use-svm-props --use-svnsync-props
2033 --log-window-size= --no-checkout --quiet
2034 --repack-flags --use-log-author --localtime
2035 --ignore-paths= $remote_opts
2038 --template= --shared= --trunk= --tags=
2039 --branches= --stdlayout --minimize-url
2040 --no-metadata --use-svm-props --use-svnsync-props
2041 --rewrite-root= --prefix= --use-log-author
2042 --add-author-from $remote_opts
2045 --edit --rmdir --find-copies-harder --copy-similarity=
2048 local cur="${COMP_WORDS[COMP_CWORD]}"
2049 case "$subcommand,$cur" in
2051 __gitcomp "--revision= --fetch-all $fc_opts"
2054 __gitcomp "--revision= $fc_opts $init_opts"
2057 __gitcomp "$init_opts"
2061 --merge --strategy= --verbose --dry-run
2062 --fetch-all --no-rebase --commit-url
2063 --revision $cmt_opts $fc_opts
2067 __gitcomp "--stdin $cmt_opts $fc_opts"
2069 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2071 __gitcomp "--revision="
2075 --limit= --revision= --verbose --incremental
2076 --oneline --show-commit --non-recursive
2077 --authors-file= --color
2082 --merge --verbose --strategy= --local
2083 --fetch-all --dry-run $fc_opts
2087 __gitcomp "--message= --file= --revision= $cmt_opts"
2093 __gitcomp "--dry-run --message --tag"
2096 __gitcomp "--dry-run --message"
2099 __gitcomp "--git-format"
2103 --config-dir= --ignore-paths= --minimize
2104 --no-auth-cache --username=
2117 while [ $c -lt $COMP_CWORD ]; do
2118 i="${COMP_WORDS[c]}"
2121 __gitcomp "$(__git_tags)"
2131 case "${COMP_WORDS[COMP_CWORD-1]}" in
2137 __gitcomp "$(__git_tags)"
2143 __gitcomp "$(__git_refs)"
2150 local i c=1 command __git_dir
2152 while [ $c -lt $COMP_CWORD ]; do
2153 i="${COMP_WORDS[c]}"
2155 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2156 --bare) __git_dir="." ;;
2157 --version|-p|--paginate) ;;
2158 --help) command="help"; break ;;
2159 *) command="$i"; break ;;
2164 if [ -z "$command" ]; then
2165 case "${COMP_WORDS[COMP_CWORD]}" in
2178 *) __git_compute_porcelain_commands
2179 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2184 local expansion=$(__git_aliased_command "$command")
2185 [ "$expansion" ] && command="$expansion"
2190 apply) _git_apply ;;
2191 archive) _git_archive ;;
2192 bisect) _git_bisect ;;
2193 bundle) _git_bundle ;;
2194 branch) _git_branch ;;
2195 checkout) _git_checkout ;;
2196 cherry) _git_cherry ;;
2197 cherry-pick) _git_cherry_pick ;;
2198 clean) _git_clean ;;
2199 clone) _git_clone ;;
2200 commit) _git_commit ;;
2201 config) _git_config ;;
2202 describe) _git_describe ;;
2204 difftool) _git_difftool ;;
2205 fetch) _git_fetch ;;
2206 format-patch) _git_format_patch ;;
2213 ls-files) _git_ls_files ;;
2214 ls-remote) _git_ls_remote ;;
2215 ls-tree) _git_ls_tree ;;
2217 mergetool) _git_mergetool;;
2218 merge-base) _git_merge_base ;;
2220 name-rev) _git_name_rev ;;
2223 rebase) _git_rebase ;;
2224 remote) _git_remote ;;
2225 replace) _git_replace ;;
2226 reset) _git_reset ;;
2227 revert) _git_revert ;;
2229 send-email) _git_send_email ;;
2230 shortlog) _git_shortlog ;;
2232 show-branch) _git_show_branch ;;
2233 stash) _git_stash ;;
2235 submodule) _git_submodule ;;
2238 whatchanged) _git_log ;;
2245 __git_has_doubledash && return
2247 local cur="${COMP_WORDS[COMP_CWORD]}"
2248 local g="$(__gitdir)"
2250 if [ -f "$g/MERGE_HEAD" ]; then
2256 $__git_log_common_options
2257 $__git_log_gitk_options
2263 __git_complete_revlist
2266 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2267 || complete -o default -o nospace -F _git git
2268 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2269 || complete -o default -o nospace -F _gitk gitk
2271 # The following are necessary only for Cygwin, and only are needed
2272 # when the user has tab-completed the executable name and consequently
2273 # included the '.exe' suffix.
2275 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2276 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2277 || complete -o default -o nospace -F _git git.exe