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 --ignore-submodules \
146 --quiet --exit-code || w="*"
147 if git rev-parse --quiet --verify HEAD >/dev/null; then
148 git diff-index --cached --quiet \
149 --ignore-submodules HEAD -- || i="+"
155 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
156 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
159 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
160 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
166 if [ -n "${1-}" ]; then
167 printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
169 printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
174 # __gitcomp_1 requires 2 arguments
177 local c IFS=' '$'\t'$'\n'
180 --*=*) printf %s$'\n' "$c$2" ;;
181 *.) printf %s$'\n' "$c$2" ;;
182 *) printf %s$'\n' "$c$2 " ;;
187 # __gitcomp accepts 1, 2, 3, or 4 arguments
188 # generates completion reply with compgen
191 local cur="${COMP_WORDS[COMP_CWORD]}"
192 if [ $# -gt 2 ]; then
201 COMPREPLY=($(compgen -P "${2-}" \
202 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
208 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
211 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
212 if [ -d "$dir" ]; then
213 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
217 for i in $(git ls-remote "${1-}" 2>/dev/null); do
218 case "$is_hash,$i" in
221 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
222 n,*) is_hash=y; echo "$i" ;;
227 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
230 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
231 if [ -d "$dir" ]; then
232 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
236 for i in $(git ls-remote "${1-}" 2>/dev/null); do
237 case "$is_hash,$i" in
240 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
241 n,*) is_hash=y; echo "$i" ;;
246 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
249 local i is_hash=y dir="$(__gitdir "${1-}")"
250 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
251 if [ -d "$dir" ]; then
258 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
259 format="refname:short"
260 refs="refs/tags refs/heads refs/remotes"
263 git --git-dir="$dir" for-each-ref --format="%($format)" \
267 for i in $(git ls-remote "$dir" 2>/dev/null); do
268 case "$is_hash,$i" in
271 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
272 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
273 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
274 n,*) is_hash=y; echo "$i" ;;
279 # __git_refs2 requires 1 argument (to pass to __git_refs)
283 for i in $(__git_refs "$1"); do
288 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
289 __git_refs_remotes ()
291 local cmd i is_hash=y
292 for i in $(git ls-remote "$1" 2>/dev/null); do
293 case "$is_hash,$i" in
296 echo "$i:refs/remotes/$1/${i#refs/heads/}"
300 n,refs/tags/*) is_hash=y;;
308 local i ngoff IFS=$'\n' d="$(__gitdir)"
309 shopt -q nullglob || ngoff=1
311 for i in "$d/remotes"/*; do
312 echo ${i#$d/remotes/}
314 [ "$ngoff" ] && shopt -u nullglob
315 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
321 __git_list_merge_strategies ()
323 git merge -s help 2>&1 |
324 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
333 __git_merge_strategies=
334 # 'git merge -s help' (and thus detection of the merge strategy
335 # list) fails, unfortunately, if run outside of any git working
336 # tree. __git_merge_strategies is set to the empty string in
337 # that case, and the detection will be repeated the next time it
339 __git_compute_merge_strategies ()
341 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
344 __git_complete_file ()
346 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
363 case "$COMP_WORDBREAKS" in
365 *) pfx="$ref:$pfx" ;;
369 COMPREPLY=($(compgen -P "$pfx" \
370 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
371 | sed '/^100... blob /{
387 __gitcomp "$(__git_refs)"
392 __git_complete_revlist ()
394 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
399 __gitcomp "$(__git_refs)" "$pfx" "$cur"
404 __gitcomp "$(__git_refs)" "$pfx" "$cur"
407 __gitcomp "$(__git_refs)"
412 __git_complete_remote_or_refspec ()
414 local cmd="${COMP_WORDS[1]}"
415 local cur="${COMP_WORDS[COMP_CWORD]}"
416 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
417 while [ $c -lt $COMP_CWORD ]; do
420 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
422 *) remote="$i"; break ;;
426 if [ -z "$remote" ]; then
427 __gitcomp "$(__git_remotes)"
430 if [ $no_complete_refspec = 1 ]; then
434 [ "$remote" = "." ] && remote=
437 case "$COMP_WORDBREAKS" in
439 *) pfx="${cur%%:*}:" ;;
451 if [ $lhs = 1 ]; then
452 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
454 __gitcomp "$(__git_refs)" "$pfx" "$cur"
458 if [ $lhs = 1 ]; then
459 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
461 __gitcomp "$(__git_refs)" "$pfx" "$cur"
465 if [ $lhs = 1 ]; then
466 __gitcomp "$(__git_refs)" "$pfx" "$cur"
468 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
474 __git_complete_strategy ()
476 __git_compute_merge_strategies
477 case "${COMP_WORDS[COMP_CWORD-1]}" in
479 __gitcomp "$__git_merge_strategies"
482 local cur="${COMP_WORDS[COMP_CWORD]}"
485 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
492 __git_list_all_commands ()
495 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
498 *--*) : helper pattern;;
505 __git_compute_all_commands ()
507 : ${__git_all_commands:=$(__git_list_all_commands)}
510 __git_list_porcelain_commands ()
513 __git_compute_all_commands
514 for i in "help" $__git_all_commands
517 *--*) : helper pattern;;
518 applymbox) : ask gittus;;
519 applypatch) : ask gittus;;
520 archimport) : import;;
521 cat-file) : plumbing;;
522 check-attr) : plumbing;;
523 check-ref-format) : plumbing;;
524 checkout-index) : plumbing;;
525 commit-tree) : plumbing;;
526 count-objects) : infrequent;;
527 cvsexportcommit) : export;;
528 cvsimport) : import;;
529 cvsserver) : daemon;;
531 diff-files) : plumbing;;
532 diff-index) : plumbing;;
533 diff-tree) : plumbing;;
534 fast-import) : import;;
535 fast-export) : export;;
536 fsck-objects) : plumbing;;
537 fetch-pack) : plumbing;;
538 fmt-merge-msg) : plumbing;;
539 for-each-ref) : plumbing;;
540 hash-object) : plumbing;;
541 http-*) : transport;;
542 index-pack) : plumbing;;
543 init-db) : deprecated;;
544 local-fetch) : plumbing;;
545 lost-found) : infrequent;;
546 ls-files) : plumbing;;
547 ls-remote) : plumbing;;
548 ls-tree) : plumbing;;
549 mailinfo) : plumbing;;
550 mailsplit) : plumbing;;
551 merge-*) : plumbing;;
554 pack-objects) : plumbing;;
555 pack-redundant) : plumbing;;
556 pack-refs) : plumbing;;
557 parse-remote) : plumbing;;
558 patch-id) : plumbing;;
559 peek-remote) : plumbing;;
561 prune-packed) : plumbing;;
562 quiltimport) : import;;
563 read-tree) : plumbing;;
564 receive-pack) : plumbing;;
566 repo-config) : deprecated;;
568 rev-list) : plumbing;;
569 rev-parse) : plumbing;;
570 runstatus) : plumbing;;
571 sh-setup) : internal;;
573 show-ref) : plumbing;;
574 send-pack) : plumbing;;
575 show-index) : plumbing;;
577 stripspace) : plumbing;;
578 symbolic-ref) : plumbing;;
579 tar-tree) : deprecated;;
580 unpack-file) : plumbing;;
581 unpack-objects) : plumbing;;
582 update-index) : plumbing;;
583 update-ref) : plumbing;;
584 update-server-info) : daemon;;
585 upload-archive) : plumbing;;
586 upload-pack) : plumbing;;
587 write-tree) : plumbing;;
589 verify-pack) : infrequent;;
590 verify-tag) : plumbing;;
596 __git_porcelain_commands=
597 __git_compute_porcelain_commands ()
599 __git_compute_all_commands
600 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
606 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
616 # __git_aliased_command requires 1 argument
617 __git_aliased_command ()
619 local word cmdline=$(git --git-dir="$(__gitdir)" \
620 config --get "alias.$1")
621 for word in $cmdline; do
622 if [ "${word##-*}" ]; then
629 # __git_find_on_cmdline requires 1 argument
630 __git_find_on_cmdline ()
632 local word subcommand c=1
634 while [ $c -lt $COMP_CWORD ]; do
635 word="${COMP_WORDS[c]}"
636 for subcommand in $1; do
637 if [ "$subcommand" = "$word" ]; then
646 __git_has_doubledash ()
649 while [ $c -lt $COMP_CWORD ]; do
650 if [ "--" = "${COMP_WORDS[c]}" ]; then
658 __git_whitespacelist="nowarn warn error error-all fix"
662 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
663 if [ -d "$dir"/rebase-apply ]; then
664 __gitcomp "--skip --resolved --abort"
669 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
674 --3way --committer-date-is-author-date --ignore-date
675 --ignore-whitespace --ignore-space-change
676 --interactive --keep --no-utf8 --signoff --utf8
677 --whitespace= --scissors
686 local cur="${COMP_WORDS[COMP_CWORD]}"
689 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
694 --stat --numstat --summary --check --index
695 --cached --index-info --reverse --reject --unidiff-zero
696 --apply --no-add --exclude=
697 --ignore-whitespace --ignore-space-change
698 --whitespace= --inaccurate-eof --verbose
707 __git_has_doubledash && return
709 local cur="${COMP_WORDS[COMP_CWORD]}"
713 --interactive --refresh --patch --update --dry-run
714 --ignore-errors --intent-to-add
723 local cur="${COMP_WORDS[COMP_CWORD]}"
726 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
730 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
735 --format= --list --verbose
736 --prefix= --remote= --exec=
746 __git_has_doubledash && return
748 local subcommands="start bad good skip reset visualize replay log run"
749 local subcommand="$(__git_find_on_cmdline "$subcommands")"
750 if [ -z "$subcommand" ]; then
751 __gitcomp "$subcommands"
755 case "$subcommand" in
757 __gitcomp "$(__git_refs)"
767 local i c=1 only_local_ref="n" has_r="n"
769 while [ $c -lt $COMP_CWORD ]; do
772 -d|-m) only_local_ref="y" ;;
778 case "${COMP_WORDS[COMP_CWORD]}" in
781 --color --no-color --verbose --abbrev= --no-abbrev
782 --track --no-track --contains --merged --no-merged
786 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
787 __gitcomp "$(__git_heads)"
789 __gitcomp "$(__git_refs)"
797 local cmd="${COMP_WORDS[2]}"
798 case "$COMP_CWORD" in
800 __gitcomp "create list-heads verify unbundle"
808 __git_complete_revlist
817 __git_has_doubledash && return
819 local cur="${COMP_WORDS[COMP_CWORD]}"
822 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
826 --quiet --ours --theirs --track --no-track --merge
831 __gitcomp "$(__git_refs)"
838 __gitcomp "$(__git_refs)"
843 local cur="${COMP_WORDS[COMP_CWORD]}"
846 __gitcomp "--edit --no-commit"
849 __gitcomp "$(__git_refs)"
856 __git_has_doubledash && return
858 local cur="${COMP_WORDS[COMP_CWORD]}"
861 __gitcomp "--dry-run --quiet"
870 local cur="${COMP_WORDS[COMP_CWORD]}"
895 __git_has_doubledash && return
897 local cur="${COMP_WORDS[COMP_CWORD]}"
901 --all --author= --signoff --verify --no-verify
902 --edit --amend --include --only --interactive
912 local cur="${COMP_WORDS[COMP_CWORD]}"
916 --all --tags --contains --abbrev= --candidates=
917 --exact-match --debug --long --match --always
921 __gitcomp "$(__git_refs)"
924 __git_diff_common_options="--stat --numstat --shortstat --summary
925 --patch-with-stat --name-only --name-status --color
926 --no-color --color-words --no-renames --check
927 --full-index --binary --abbrev --diff-filter=
929 --text --ignore-space-at-eol --ignore-space-change
930 --ignore-all-space --exit-code --quiet --ext-diff
932 --no-prefix --src-prefix= --dst-prefix=
933 --inter-hunk-context=
936 --dirstat --dirstat= --dirstat-by-file
937 --dirstat-by-file= --cumulative
942 __git_has_doubledash && return
944 local cur="${COMP_WORDS[COMP_CWORD]}"
947 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
948 --base --ours --theirs
949 $__git_diff_common_options
957 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
958 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
963 __git_has_doubledash && return
965 local cur="${COMP_WORDS[COMP_CWORD]}"
968 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
972 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
973 --base --ours --theirs
974 --no-renames --diff-filter= --find-copies-harder
975 --relative --ignore-submodules
983 __git_fetch_options="
984 --quiet --verbose --append --upload-pack --force --keep --depth=
990 local cur="${COMP_WORDS[COMP_CWORD]}"
993 __gitcomp "$__git_fetch_options"
997 __git_complete_remote_or_refspec
1000 _git_format_patch ()
1002 local cur="${COMP_WORDS[COMP_CWORD]}"
1007 " "" "${cur##--thread=}"
1012 --stdout --attach --no-attach --thread --thread=
1014 --numbered --start-number
1018 --in-reply-to= --cc=
1019 --full-index --binary
1022 --no-prefix --src-prefix= --dst-prefix=
1023 --inline --suffix= --ignore-if-in-upstream
1029 __git_complete_revlist
1034 local cur="${COMP_WORDS[COMP_CWORD]}"
1038 --tags --root --unreachable --cache --no-reflogs --full
1039 --strict --verbose --lost-found
1049 local cur="${COMP_WORDS[COMP_CWORD]}"
1052 __gitcomp "--prune --aggressive"
1061 __git_has_doubledash && return
1063 local cur="${COMP_WORDS[COMP_CWORD]}"
1068 --text --ignore-case --word-regexp --invert-match
1070 --extended-regexp --basic-regexp --fixed-strings
1071 --files-with-matches --name-only
1072 --files-without-match
1075 --and --or --not --all-match
1081 __gitcomp "$(__git_refs)"
1086 local cur="${COMP_WORDS[COMP_CWORD]}"
1089 __gitcomp "--all --info --man --web"
1093 __git_compute_all_commands
1094 __gitcomp "$__git_all_commands
1095 attributes cli core-tutorial cvs-migration
1096 diffcore gitk glossary hooks ignore modules
1097 repository-layout tutorial tutorial-2
1104 local cur="${COMP_WORDS[COMP_CWORD]}"
1108 false true umask group all world everybody
1109 " "" "${cur##--shared=}"
1113 __gitcomp "--quiet --bare --template= --shared --shared="
1122 __git_has_doubledash && return
1124 local cur="${COMP_WORDS[COMP_CWORD]}"
1127 __gitcomp "--cached --deleted --modified --others --ignored
1128 --stage --directory --no-empty-directory --unmerged
1129 --killed --exclude= --exclude-from=
1130 --exclude-per-directory= --exclude-standard
1131 --error-unmatch --with-tree= --full-name
1132 --abbrev --ignored --exclude-per-directory
1142 __gitcomp "$(__git_remotes)"
1150 # Options that go well for log, shortlog and gitk
1151 __git_log_common_options="
1153 --branches --tags --remotes
1154 --first-parent --merges --no-merges
1156 --max-age= --since= --after=
1157 --min-age= --until= --before=
1159 # Options that go well for log and gitk (not shortlog)
1160 __git_log_gitk_options="
1161 --dense --sparse --full-history
1162 --simplify-merges --simplify-by-decoration
1165 # Options that go well for log and shortlog (not gitk)
1166 __git_log_shortlog_options="
1167 --author= --committer= --grep=
1171 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1172 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1176 __git_has_doubledash && return
1178 local cur="${COMP_WORDS[COMP_CWORD]}"
1179 local g="$(git rev-parse --git-dir 2>/dev/null)"
1181 if [ -f "$g/MERGE_HEAD" ]; then
1186 __gitcomp "$__git_log_pretty_formats
1187 " "" "${cur##--pretty=}"
1191 __gitcomp "$__git_log_pretty_formats
1192 " "" "${cur##--format=}"
1196 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1200 __gitcomp "long short" "" "${cur##--decorate=}"
1205 $__git_log_common_options
1206 $__git_log_shortlog_options
1207 $__git_log_gitk_options
1208 --root --topo-order --date-order --reverse
1209 --follow --full-diff
1210 --abbrev-commit --abbrev=
1211 --relative-date --date=
1212 --pretty= --format= --oneline
1215 --decorate --decorate=
1217 --parents --children
1219 $__git_diff_common_options
1220 --pickaxe-all --pickaxe-regex
1225 __git_complete_revlist
1228 __git_merge_options="
1229 --no-commit --no-stat --log --no-log --squash --strategy
1230 --commit --stat --no-squash --ff --no-ff --ff-only
1235 __git_complete_strategy && return
1237 local cur="${COMP_WORDS[COMP_CWORD]}"
1240 __gitcomp "$__git_merge_options"
1243 __gitcomp "$(__git_refs)"
1248 local cur="${COMP_WORDS[COMP_CWORD]}"
1251 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1264 __gitcomp "$(__git_refs)"
1269 local cur="${COMP_WORDS[COMP_CWORD]}"
1272 __gitcomp "--dry-run"
1281 __gitcomp "--tags --all --stdin"
1286 __git_complete_strategy && return
1288 local cur="${COMP_WORDS[COMP_CWORD]}"
1292 --rebase --no-rebase
1293 $__git_merge_options
1294 $__git_fetch_options
1299 __git_complete_remote_or_refspec
1304 local cur="${COMP_WORDS[COMP_CWORD]}"
1305 case "${COMP_WORDS[COMP_CWORD-1]}" in
1307 __gitcomp "$(__git_remotes)"
1312 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1317 --all --mirror --tags --dry-run --force --verbose
1318 --receive-pack= --repo=
1323 __git_complete_remote_or_refspec
1328 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1329 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1330 __gitcomp "--continue --skip --abort"
1333 __git_complete_strategy && return
1336 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1341 --onto --merge --strategy --interactive
1342 --preserve-merges --stat --no-stat
1343 --committer-date-is-author-date --ignore-date
1344 --ignore-whitespace --whitespace=
1349 __gitcomp "$(__git_refs)"
1352 __git_send_email_confirm_options="always never auto cc compose"
1353 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1357 local cur="${COMP_WORDS[COMP_CWORD]}"
1361 $__git_send_email_confirm_options
1362 " "" "${cur##--confirm=}"
1367 $__git_send_email_suppresscc_options
1368 " "" "${cur##--suppress-cc=}"
1372 --smtp-encryption=*)
1373 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1377 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1378 --compose --confirm= --dry-run --envelope-sender
1380 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1381 --no-suppress-from --no-thread --quiet
1382 --signed-off-by-cc --smtp-pass --smtp-server
1383 --smtp-server-port --smtp-encryption= --smtp-user
1384 --subject --suppress-cc= --suppress-from --thread --to
1385 --validate --no-validate"
1392 __git_config_get_set_variables ()
1394 local prevword word config_file= c=$COMP_CWORD
1395 while [ $c -gt 1 ]; do
1396 word="${COMP_WORDS[c]}"
1398 --global|--system|--file=*)
1403 config_file="$word $prevword"
1411 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1424 local cur="${COMP_WORDS[COMP_CWORD]}"
1425 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1428 __gitcomp "$(__git_remotes)"
1432 __gitcomp "$(__git_refs)"
1436 local remote="${prv#remote.}"
1437 remote="${remote%.fetch}"
1438 __gitcomp "$(__git_refs_remotes "$remote")"
1442 local remote="${prv#remote.}"
1443 remote="${remote%.push}"
1444 __gitcomp "$(git --git-dir="$(__gitdir)" \
1445 for-each-ref --format='%(refname):%(refname)' \
1449 pull.twohead|pull.octopus)
1450 __git_compute_merge_strategies
1451 __gitcomp "$__git_merge_strategies"
1454 color.branch|color.diff|color.interactive|\
1455 color.showbranch|color.status|color.ui)
1456 __gitcomp "always never auto"
1460 __gitcomp "false true"
1465 normal black red green yellow blue magenta cyan white
1466 bold dim ul blink reverse
1471 __gitcomp "man info web html"
1475 __gitcomp "$__git_log_date_formats"
1478 sendemail.aliasesfiletype)
1479 __gitcomp "mutt mailrc pine elm gnus"
1483 __gitcomp "$__git_send_email_confirm_options"
1486 sendemail.suppresscc)
1487 __gitcomp "$__git_send_email_suppresscc_options"
1490 --get|--get-all|--unset|--unset-all)
1491 __gitcomp "$(__git_config_get_set_variables)"
1502 --global --system --file=
1503 --list --replace-all
1504 --get --get-all --get-regexp
1505 --add --unset --unset-all
1506 --remove-section --rename-section
1511 local pfx="${cur%.*}."
1513 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1517 local pfx="${cur%.*}."
1519 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1523 local pfx="${cur%.*}."
1526 argprompt cmd confirm needsfile noconsole norescan
1527 prompt revprompt revunmerged title
1532 local pfx="${cur%.*}."
1534 __gitcomp "cmd path" "$pfx" "$cur"
1538 local pfx="${cur%.*}."
1540 __gitcomp "cmd path" "$pfx" "$cur"
1544 local pfx="${cur%.*}."
1546 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1550 local pfx="${cur%.*}."
1552 __git_compute_all_commands
1553 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1557 local pfx="${cur%.*}."
1560 url proxy fetch push mirror skipDefaultUpdate
1561 receivepack uploadpack tagopt pushurl
1566 local pfx="${cur%.*}."
1568 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1572 local pfx="${cur%.*}."
1574 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1581 apply.ignorewhitespace
1583 branch.autosetupmerge
1584 branch.autosetuprebase
1587 color.branch.current
1598 color.diff.whitespace
1603 color.interactive.header
1604 color.interactive.help
1605 color.interactive.prompt
1610 color.status.changed
1612 color.status.nobranch
1613 color.status.untracked
1614 color.status.updated
1621 core.deltaBaseCacheLimit
1625 core.fsyncobjectfiles
1627 core.ignoreCygwinFSTricks
1629 core.logAllRefUpdates
1630 core.loosecompression
1632 core.packedGitWindowSize
1634 core.preferSymlinkRefs
1637 core.repositoryFormatVersion
1639 core.sharedRepository
1642 core.warnAmbiguousRefs
1645 diff.autorefreshindex
1651 diff.suppressBlankEmpty
1663 format.subjectprefix
1672 gc.reflogexpireunreachable
1676 gitcvs.commitmsgannotation
1677 gitcvs.dbTableNamePrefix
1688 gui.copyblamethreshold
1692 gui.matchtrackingbranch
1693 gui.newbranchtemplate
1694 gui.pruneduringfetch
1695 gui.spellingdictionary
1711 i18n.logOutputEncoding
1716 imap.preformattedHTML
1725 interactive.singlekey
1738 mergetool.keepBackup
1741 pack.deltaCacheLimit
1754 receive.denyCurrentBranch
1756 receive.denyNonFastForwards
1759 repack.usedeltabaseoffset
1762 sendemail.aliasesfile
1763 sendemail.aliasesfiletype
1767 sendemail.chainreplyto
1769 sendemail.envelopesender
1771 sendemail.signedoffbycc
1772 sendemail.smtpencryption
1774 sendemail.smtpserver
1775 sendemail.smtpserverport
1777 sendemail.suppresscc
1778 sendemail.suppressfrom
1783 status.relativePaths
1784 status.showUntrackedFiles
1786 transfer.unpackLimit
1798 local subcommands="add rename rm show prune update set-head"
1799 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1800 if [ -z "$subcommand" ]; then
1801 __gitcomp "$subcommands"
1805 case "$subcommand" in
1806 rename|rm|show|prune)
1807 __gitcomp "$(__git_remotes)"
1810 local i c='' IFS=$'\n'
1811 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1825 __gitcomp "$(__git_refs)"
1830 __git_has_doubledash && return
1832 local cur="${COMP_WORDS[COMP_CWORD]}"
1835 __gitcomp "--merge --mixed --hard --soft --patch"
1839 __gitcomp "$(__git_refs)"
1844 local cur="${COMP_WORDS[COMP_CWORD]}"
1847 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1851 __gitcomp "$(__git_refs)"
1856 __git_has_doubledash && return
1858 local cur="${COMP_WORDS[COMP_CWORD]}"
1861 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1870 __git_has_doubledash && return
1872 local cur="${COMP_WORDS[COMP_CWORD]}"
1876 $__git_log_common_options
1877 $__git_log_shortlog_options
1878 --numbered --summary
1883 __git_complete_revlist
1888 __git_has_doubledash && return
1890 local cur="${COMP_WORDS[COMP_CWORD]}"
1893 __gitcomp "$__git_log_pretty_formats
1894 " "" "${cur##--pretty=}"
1898 __gitcomp "$__git_log_pretty_formats
1899 " "" "${cur##--format=}"
1903 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1904 $__git_diff_common_options
1914 local cur="${COMP_WORDS[COMP_CWORD]}"
1918 --all --remotes --topo-order --current --more=
1919 --list --independent --merge-base --no-name
1921 --sha1-name --sparse --topics --reflog
1926 __git_complete_revlist
1931 local cur="${COMP_WORDS[COMP_CWORD]}"
1932 local save_opts='--keep-index --no-keep-index --quiet --patch'
1933 local subcommands='save list show apply clear drop pop create branch'
1934 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1935 if [ -z "$subcommand" ]; then
1938 __gitcomp "$save_opts"
1941 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1942 __gitcomp "$subcommands"
1949 case "$subcommand,$cur" in
1951 __gitcomp "$save_opts"
1954 __gitcomp "--index --quiet"
1956 show,--*|drop,--*|branch,--*)
1959 show,*|apply,*|drop,*|pop,*|branch,*)
1960 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1961 | sed -n -e 's/:.*//p')"
1972 __git_has_doubledash && return
1974 local subcommands="add status init update summary foreach sync"
1975 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1976 local cur="${COMP_WORDS[COMP_CWORD]}"
1979 __gitcomp "--quiet --cached"
1982 __gitcomp "$subcommands"
1992 init fetch clone rebase dcommit log find-rev
1993 set-tree commit-diff info create-ignore propget
1994 proplist show-ignore show-externals branch tag blame
1997 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1998 if [ -z "$subcommand" ]; then
1999 __gitcomp "$subcommands"
2001 local remote_opts="--username= --config-dir= --no-auth-cache"
2003 --follow-parent --authors-file= --repack=
2004 --no-metadata --use-svm-props --use-svnsync-props
2005 --log-window-size= --no-checkout --quiet
2006 --repack-flags --use-log-author --localtime
2007 --ignore-paths= $remote_opts
2010 --template= --shared= --trunk= --tags=
2011 --branches= --stdlayout --minimize-url
2012 --no-metadata --use-svm-props --use-svnsync-props
2013 --rewrite-root= --prefix= --use-log-author
2014 --add-author-from $remote_opts
2017 --edit --rmdir --find-copies-harder --copy-similarity=
2020 local cur="${COMP_WORDS[COMP_CWORD]}"
2021 case "$subcommand,$cur" in
2023 __gitcomp "--revision= --fetch-all $fc_opts"
2026 __gitcomp "--revision= $fc_opts $init_opts"
2029 __gitcomp "$init_opts"
2033 --merge --strategy= --verbose --dry-run
2034 --fetch-all --no-rebase --commit-url
2035 --revision $cmt_opts $fc_opts
2039 __gitcomp "--stdin $cmt_opts $fc_opts"
2041 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2043 __gitcomp "--revision="
2047 --limit= --revision= --verbose --incremental
2048 --oneline --show-commit --non-recursive
2049 --authors-file= --color
2054 --merge --verbose --strategy= --local
2055 --fetch-all --dry-run $fc_opts
2059 __gitcomp "--message= --file= --revision= $cmt_opts"
2065 __gitcomp "--dry-run --message --tag"
2068 __gitcomp "--dry-run --message"
2071 __gitcomp "--git-format"
2075 --config-dir= --ignore-paths= --minimize
2076 --no-auth-cache --username=
2089 while [ $c -lt $COMP_CWORD ]; do
2090 i="${COMP_WORDS[c]}"
2093 __gitcomp "$(__git_tags)"
2103 case "${COMP_WORDS[COMP_CWORD-1]}" in
2109 __gitcomp "$(__git_tags)"
2115 __gitcomp "$(__git_refs)"
2122 local i c=1 command __git_dir
2124 while [ $c -lt $COMP_CWORD ]; do
2125 i="${COMP_WORDS[c]}"
2127 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2128 --bare) __git_dir="." ;;
2129 --version|-p|--paginate) ;;
2130 --help) command="help"; break ;;
2131 *) command="$i"; break ;;
2136 if [ -z "$command" ]; then
2137 case "${COMP_WORDS[COMP_CWORD]}" in
2150 *) __git_compute_porcelain_commands
2151 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2156 local expansion=$(__git_aliased_command "$command")
2157 [ "$expansion" ] && command="$expansion"
2162 apply) _git_apply ;;
2163 archive) _git_archive ;;
2164 bisect) _git_bisect ;;
2165 bundle) _git_bundle ;;
2166 branch) _git_branch ;;
2167 checkout) _git_checkout ;;
2168 cherry) _git_cherry ;;
2169 cherry-pick) _git_cherry_pick ;;
2170 clean) _git_clean ;;
2171 clone) _git_clone ;;
2172 commit) _git_commit ;;
2173 config) _git_config ;;
2174 describe) _git_describe ;;
2176 difftool) _git_difftool ;;
2177 fetch) _git_fetch ;;
2178 format-patch) _git_format_patch ;;
2185 ls-files) _git_ls_files ;;
2186 ls-remote) _git_ls_remote ;;
2187 ls-tree) _git_ls_tree ;;
2189 mergetool) _git_mergetool;;
2190 merge-base) _git_merge_base ;;
2192 name-rev) _git_name_rev ;;
2195 rebase) _git_rebase ;;
2196 remote) _git_remote ;;
2197 replace) _git_replace ;;
2198 reset) _git_reset ;;
2199 revert) _git_revert ;;
2201 send-email) _git_send_email ;;
2202 shortlog) _git_shortlog ;;
2204 show-branch) _git_show_branch ;;
2205 stash) _git_stash ;;
2207 submodule) _git_submodule ;;
2210 whatchanged) _git_log ;;
2217 __git_has_doubledash && return
2219 local cur="${COMP_WORDS[COMP_CWORD]}"
2220 local g="$(__gitdir)"
2222 if [ -f "$g/MERGE_HEAD" ]; then
2228 $__git_log_common_options
2229 $__git_log_gitk_options
2235 __git_complete_revlist
2238 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2239 || complete -o default -o nospace -F _git git
2240 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2241 || complete -o default -o nospace -F _gitk gitk
2243 # The following are necessary only for Cygwin, and only are needed
2244 # when the user has tab-completed the executable name and consequently
2245 # included the '.exe' suffix.
2247 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2248 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2249 || complete -o default -o nospace -F _git git.exe