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
167 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r"
171 # __gitcomp_1 requires 2 arguments
174 local c IFS=' '$'\t'$'\n'
177 --*=*) printf %s$'\n' "$c$2" ;;
178 *.) printf %s$'\n' "$c$2" ;;
179 *) printf %s$'\n' "$c$2 " ;;
184 # __gitcomp accepts 1, 2, 3, or 4 arguments
185 # generates completion reply with compgen
188 local cur="${COMP_WORDS[COMP_CWORD]}"
189 if [ $# -gt 2 ]; then
198 COMPREPLY=($(compgen -P "${2-}" \
199 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
205 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
208 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
209 if [ -d "$dir" ]; then
210 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
214 for i in $(git ls-remote "${1-}" 2>/dev/null); do
215 case "$is_hash,$i" in
218 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
219 n,*) is_hash=y; echo "$i" ;;
224 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
227 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
228 if [ -d "$dir" ]; then
229 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
233 for i in $(git ls-remote "${1-}" 2>/dev/null); do
234 case "$is_hash,$i" in
237 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
238 n,*) is_hash=y; echo "$i" ;;
243 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
246 local i is_hash=y dir="$(__gitdir "${1-}")"
247 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
248 if [ -d "$dir" ]; then
255 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
256 format="refname:short"
257 refs="refs/tags refs/heads refs/remotes"
260 git --git-dir="$dir" for-each-ref --format="%($format)" \
264 for i in $(git ls-remote "$dir" 2>/dev/null); do
265 case "$is_hash,$i" in
268 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
269 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
270 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
271 n,*) is_hash=y; echo "$i" ;;
276 # __git_refs2 requires 1 argument (to pass to __git_refs)
280 for i in $(__git_refs "$1"); do
285 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
286 __git_refs_remotes ()
288 local cmd i is_hash=y
289 for i in $(git ls-remote "$1" 2>/dev/null); do
290 case "$is_hash,$i" in
293 echo "$i:refs/remotes/$1/${i#refs/heads/}"
297 n,refs/tags/*) is_hash=y;;
305 local i ngoff IFS=$'\n' d="$(__gitdir)"
306 shopt -q nullglob || ngoff=1
308 for i in "$d/remotes"/*; do
309 echo ${i#$d/remotes/}
311 [ "$ngoff" ] && shopt -u nullglob
312 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
318 __git_list_merge_strategies ()
320 git merge -s help 2>&1 |
321 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
330 __git_merge_strategies=
331 # 'git merge -s help' (and thus detection of the merge strategy
332 # list) fails, unfortunately, if run outside of any git working
333 # tree. __git_merge_strategies is set to the empty string in
334 # that case, and the detection will be repeated the next time it
336 __git_compute_merge_strategies ()
338 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
341 __git_complete_file ()
343 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
360 case "$COMP_WORDBREAKS" in
362 *) pfx="$ref:$pfx" ;;
366 COMPREPLY=($(compgen -P "$pfx" \
367 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
368 | sed '/^100... blob /{
384 __gitcomp "$(__git_refs)"
389 __git_complete_revlist ()
391 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
396 __gitcomp "$(__git_refs)" "$pfx" "$cur"
401 __gitcomp "$(__git_refs)" "$pfx" "$cur"
404 __gitcomp "$(__git_refs)"
409 __git_complete_remote_or_refspec ()
411 local cmd="${COMP_WORDS[1]}"
412 local cur="${COMP_WORDS[COMP_CWORD]}"
413 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
414 while [ $c -lt $COMP_CWORD ]; do
417 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
420 push) no_complete_refspec=1 ;;
429 *) remote="$i"; break ;;
433 if [ -z "$remote" ]; then
434 __gitcomp "$(__git_remotes)"
437 if [ $no_complete_refspec = 1 ]; then
441 [ "$remote" = "." ] && remote=
444 case "$COMP_WORDBREAKS" in
446 *) pfx="${cur%%:*}:" ;;
458 if [ $lhs = 1 ]; then
459 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
461 __gitcomp "$(__git_refs)" "$pfx" "$cur"
465 if [ $lhs = 1 ]; then
466 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
468 __gitcomp "$(__git_refs)" "$pfx" "$cur"
472 if [ $lhs = 1 ]; then
473 __gitcomp "$(__git_refs)" "$pfx" "$cur"
475 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
481 __git_complete_strategy ()
483 __git_compute_merge_strategies
484 case "${COMP_WORDS[COMP_CWORD-1]}" in
486 __gitcomp "$__git_merge_strategies"
489 local cur="${COMP_WORDS[COMP_CWORD]}"
492 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
499 __git_list_all_commands ()
502 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
505 *--*) : helper pattern;;
512 __git_compute_all_commands ()
514 : ${__git_all_commands:=$(__git_list_all_commands)}
517 __git_list_porcelain_commands ()
520 __git_compute_all_commands
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;;
603 __git_porcelain_commands=
604 __git_compute_porcelain_commands ()
606 __git_compute_all_commands
607 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
613 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
623 # __git_aliased_command requires 1 argument
624 __git_aliased_command ()
626 local word cmdline=$(git --git-dir="$(__gitdir)" \
627 config --get "alias.$1")
628 for word in $cmdline; do
629 if [ "${word##-*}" ]; then
636 # __git_find_on_cmdline requires 1 argument
637 __git_find_on_cmdline ()
639 local word subcommand c=1
641 while [ $c -lt $COMP_CWORD ]; do
642 word="${COMP_WORDS[c]}"
643 for subcommand in $1; do
644 if [ "$subcommand" = "$word" ]; then
653 __git_has_doubledash ()
656 while [ $c -lt $COMP_CWORD ]; do
657 if [ "--" = "${COMP_WORDS[c]}" ]; then
665 __git_whitespacelist="nowarn warn error error-all fix"
669 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
670 if [ -d "$dir"/rebase-apply ]; then
671 __gitcomp "--skip --resolved --abort"
676 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
681 --3way --committer-date-is-author-date --ignore-date
682 --ignore-whitespace --ignore-space-change
683 --interactive --keep --no-utf8 --signoff --utf8
684 --whitespace= --scissors
693 local cur="${COMP_WORDS[COMP_CWORD]}"
696 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
701 --stat --numstat --summary --check --index
702 --cached --index-info --reverse --reject --unidiff-zero
703 --apply --no-add --exclude=
704 --ignore-whitespace --ignore-space-change
705 --whitespace= --inaccurate-eof --verbose
714 __git_has_doubledash && return
716 local cur="${COMP_WORDS[COMP_CWORD]}"
720 --interactive --refresh --patch --update --dry-run
721 --ignore-errors --intent-to-add
730 local cur="${COMP_WORDS[COMP_CWORD]}"
733 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
737 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
742 --format= --list --verbose
743 --prefix= --remote= --exec=
753 __git_has_doubledash && return
755 local subcommands="start bad good skip reset visualize replay log run"
756 local subcommand="$(__git_find_on_cmdline "$subcommands")"
757 if [ -z "$subcommand" ]; then
758 __gitcomp "$subcommands"
762 case "$subcommand" in
764 __gitcomp "$(__git_refs)"
774 local i c=1 only_local_ref="n" has_r="n"
776 while [ $c -lt $COMP_CWORD ]; do
779 -d|-m) only_local_ref="y" ;;
785 case "${COMP_WORDS[COMP_CWORD]}" in
788 --color --no-color --verbose --abbrev= --no-abbrev
789 --track --no-track --contains --merged --no-merged
793 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
794 __gitcomp "$(__git_heads)"
796 __gitcomp "$(__git_refs)"
804 local cmd="${COMP_WORDS[2]}"
805 case "$COMP_CWORD" in
807 __gitcomp "create list-heads verify unbundle"
815 __git_complete_revlist
824 __git_has_doubledash && return
826 local cur="${COMP_WORDS[COMP_CWORD]}"
829 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
833 --quiet --ours --theirs --track --no-track --merge
838 __gitcomp "$(__git_refs)"
845 __gitcomp "$(__git_refs)"
850 local cur="${COMP_WORDS[COMP_CWORD]}"
853 __gitcomp "--edit --no-commit"
856 __gitcomp "$(__git_refs)"
863 __git_has_doubledash && return
865 local cur="${COMP_WORDS[COMP_CWORD]}"
868 __gitcomp "--dry-run --quiet"
877 local cur="${COMP_WORDS[COMP_CWORD]}"
902 __git_has_doubledash && return
904 local cur="${COMP_WORDS[COMP_CWORD]}"
907 __gitcomp "default strip verbatim whitespace
908 " "" "${cur##--cleanup=}"
912 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
916 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
920 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
925 --all --author= --signoff --verify --no-verify
926 --edit --amend --include --only --interactive
927 --dry-run --reuse-message= --reedit-message=
928 --reset-author --file= --message= --template=
929 --cleanup= --untracked-files --untracked-files=
939 local cur="${COMP_WORDS[COMP_CWORD]}"
943 --all --tags --contains --abbrev= --candidates=
944 --exact-match --debug --long --match --always
948 __gitcomp "$(__git_refs)"
951 __git_diff_common_options="--stat --numstat --shortstat --summary
952 --patch-with-stat --name-only --name-status --color
953 --no-color --color-words --no-renames --check
954 --full-index --binary --abbrev --diff-filter=
956 --text --ignore-space-at-eol --ignore-space-change
957 --ignore-all-space --exit-code --quiet --ext-diff
959 --no-prefix --src-prefix= --dst-prefix=
960 --inter-hunk-context=
963 --dirstat --dirstat= --dirstat-by-file
964 --dirstat-by-file= --cumulative
969 __git_has_doubledash && return
971 local cur="${COMP_WORDS[COMP_CWORD]}"
974 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
975 --base --ours --theirs
976 $__git_diff_common_options
984 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
985 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
990 __git_has_doubledash && return
992 local cur="${COMP_WORDS[COMP_CWORD]}"
995 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
999 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1000 --base --ours --theirs
1001 --no-renames --diff-filter= --find-copies-harder
1002 --relative --ignore-submodules
1010 __git_fetch_options="
1011 --quiet --verbose --append --upload-pack --force --keep --depth=
1012 --tags --no-tags --all --prune --dry-run
1017 local cur="${COMP_WORDS[COMP_CWORD]}"
1020 __gitcomp "$__git_fetch_options"
1024 __git_complete_remote_or_refspec
1027 _git_format_patch ()
1029 local cur="${COMP_WORDS[COMP_CWORD]}"
1034 " "" "${cur##--thread=}"
1039 --stdout --attach --no-attach --thread --thread=
1041 --numbered --start-number
1045 --in-reply-to= --cc=
1046 --full-index --binary
1049 --no-prefix --src-prefix= --dst-prefix=
1050 --inline --suffix= --ignore-if-in-upstream
1056 __git_complete_revlist
1061 local cur="${COMP_WORDS[COMP_CWORD]}"
1065 --tags --root --unreachable --cache --no-reflogs --full
1066 --strict --verbose --lost-found
1076 local cur="${COMP_WORDS[COMP_CWORD]}"
1079 __gitcomp "--prune --aggressive"
1088 __git_has_doubledash && return
1090 local cur="${COMP_WORDS[COMP_CWORD]}"
1095 --text --ignore-case --word-regexp --invert-match
1097 --extended-regexp --basic-regexp --fixed-strings
1098 --files-with-matches --name-only
1099 --files-without-match
1102 --and --or --not --all-match
1108 __gitcomp "$(__git_refs)"
1113 local cur="${COMP_WORDS[COMP_CWORD]}"
1116 __gitcomp "--all --info --man --web"
1120 __git_compute_all_commands
1121 __gitcomp "$__git_all_commands
1122 attributes cli core-tutorial cvs-migration
1123 diffcore gitk glossary hooks ignore modules
1124 repository-layout tutorial tutorial-2
1131 local cur="${COMP_WORDS[COMP_CWORD]}"
1135 false true umask group all world everybody
1136 " "" "${cur##--shared=}"
1140 __gitcomp "--quiet --bare --template= --shared --shared="
1149 __git_has_doubledash && return
1151 local cur="${COMP_WORDS[COMP_CWORD]}"
1154 __gitcomp "--cached --deleted --modified --others --ignored
1155 --stage --directory --no-empty-directory --unmerged
1156 --killed --exclude= --exclude-from=
1157 --exclude-per-directory= --exclude-standard
1158 --error-unmatch --with-tree= --full-name
1159 --abbrev --ignored --exclude-per-directory
1169 __gitcomp "$(__git_remotes)"
1177 # Options that go well for log, shortlog and gitk
1178 __git_log_common_options="
1180 --branches --tags --remotes
1181 --first-parent --merges --no-merges
1183 --max-age= --since= --after=
1184 --min-age= --until= --before=
1186 # Options that go well for log and gitk (not shortlog)
1187 __git_log_gitk_options="
1188 --dense --sparse --full-history
1189 --simplify-merges --simplify-by-decoration
1192 # Options that go well for log and shortlog (not gitk)
1193 __git_log_shortlog_options="
1194 --author= --committer= --grep=
1198 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1199 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1203 __git_has_doubledash && return
1205 local cur="${COMP_WORDS[COMP_CWORD]}"
1206 local g="$(git rev-parse --git-dir 2>/dev/null)"
1208 if [ -f "$g/MERGE_HEAD" ]; then
1213 __gitcomp "$__git_log_pretty_formats
1214 " "" "${cur##--pretty=}"
1218 __gitcomp "$__git_log_pretty_formats
1219 " "" "${cur##--format=}"
1223 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1227 __gitcomp "long short" "" "${cur##--decorate=}"
1232 $__git_log_common_options
1233 $__git_log_shortlog_options
1234 $__git_log_gitk_options
1235 --root --topo-order --date-order --reverse
1236 --follow --full-diff
1237 --abbrev-commit --abbrev=
1238 --relative-date --date=
1239 --pretty= --format= --oneline
1242 --decorate --decorate=
1244 --parents --children
1246 $__git_diff_common_options
1247 --pickaxe-all --pickaxe-regex
1252 __git_complete_revlist
1255 __git_merge_options="
1256 --no-commit --no-stat --log --no-log --squash --strategy
1257 --commit --stat --no-squash --ff --no-ff --ff-only
1262 __git_complete_strategy && return
1264 local cur="${COMP_WORDS[COMP_CWORD]}"
1267 __gitcomp "$__git_merge_options"
1270 __gitcomp "$(__git_refs)"
1275 local cur="${COMP_WORDS[COMP_CWORD]}"
1278 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1291 __gitcomp "$(__git_refs)"
1296 local cur="${COMP_WORDS[COMP_CWORD]}"
1299 __gitcomp "--dry-run"
1308 __gitcomp "--tags --all --stdin"
1313 __git_complete_strategy && return
1315 local cur="${COMP_WORDS[COMP_CWORD]}"
1319 --rebase --no-rebase
1320 $__git_merge_options
1321 $__git_fetch_options
1326 __git_complete_remote_or_refspec
1331 local cur="${COMP_WORDS[COMP_CWORD]}"
1332 case "${COMP_WORDS[COMP_CWORD-1]}" in
1334 __gitcomp "$(__git_remotes)"
1339 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1344 --all --mirror --tags --dry-run --force --verbose
1345 --receive-pack= --repo=
1350 __git_complete_remote_or_refspec
1355 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1356 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1357 __gitcomp "--continue --skip --abort"
1360 __git_complete_strategy && return
1363 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1368 --onto --merge --strategy --interactive
1369 --preserve-merges --stat --no-stat
1370 --committer-date-is-author-date --ignore-date
1371 --ignore-whitespace --whitespace=
1376 __gitcomp "$(__git_refs)"
1379 __git_send_email_confirm_options="always never auto cc compose"
1380 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1384 local cur="${COMP_WORDS[COMP_CWORD]}"
1388 $__git_send_email_confirm_options
1389 " "" "${cur##--confirm=}"
1394 $__git_send_email_suppresscc_options
1395 " "" "${cur##--suppress-cc=}"
1399 --smtp-encryption=*)
1400 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1404 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1405 --compose --confirm= --dry-run --envelope-sender
1407 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1408 --no-suppress-from --no-thread --quiet
1409 --signed-off-by-cc --smtp-pass --smtp-server
1410 --smtp-server-port --smtp-encryption= --smtp-user
1411 --subject --suppress-cc= --suppress-from --thread --to
1412 --validate --no-validate"
1419 __git_config_get_set_variables ()
1421 local prevword word config_file= c=$COMP_CWORD
1422 while [ $c -gt 1 ]; do
1423 word="${COMP_WORDS[c]}"
1425 --global|--system|--file=*)
1430 config_file="$word $prevword"
1438 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1451 local cur="${COMP_WORDS[COMP_CWORD]}"
1452 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1455 __gitcomp "$(__git_remotes)"
1459 __gitcomp "$(__git_refs)"
1463 local remote="${prv#remote.}"
1464 remote="${remote%.fetch}"
1465 __gitcomp "$(__git_refs_remotes "$remote")"
1469 local remote="${prv#remote.}"
1470 remote="${remote%.push}"
1471 __gitcomp "$(git --git-dir="$(__gitdir)" \
1472 for-each-ref --format='%(refname):%(refname)' \
1476 pull.twohead|pull.octopus)
1477 __git_compute_merge_strategies
1478 __gitcomp "$__git_merge_strategies"
1481 color.branch|color.diff|color.interactive|\
1482 color.showbranch|color.status|color.ui)
1483 __gitcomp "always never auto"
1487 __gitcomp "false true"
1492 normal black red green yellow blue magenta cyan white
1493 bold dim ul blink reverse
1498 __gitcomp "man info web html"
1502 __gitcomp "$__git_log_date_formats"
1505 sendemail.aliasesfiletype)
1506 __gitcomp "mutt mailrc pine elm gnus"
1510 __gitcomp "$__git_send_email_confirm_options"
1513 sendemail.suppresscc)
1514 __gitcomp "$__git_send_email_suppresscc_options"
1517 --get|--get-all|--unset|--unset-all)
1518 __gitcomp "$(__git_config_get_set_variables)"
1529 --global --system --file=
1530 --list --replace-all
1531 --get --get-all --get-regexp
1532 --add --unset --unset-all
1533 --remove-section --rename-section
1538 local pfx="${cur%.*}."
1540 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1544 local pfx="${cur%.*}."
1546 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1550 local pfx="${cur%.*}."
1553 argprompt cmd confirm needsfile noconsole norescan
1554 prompt revprompt revunmerged title
1559 local pfx="${cur%.*}."
1561 __gitcomp "cmd path" "$pfx" "$cur"
1565 local pfx="${cur%.*}."
1567 __gitcomp "cmd path" "$pfx" "$cur"
1571 local pfx="${cur%.*}."
1573 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1577 local pfx="${cur%.*}."
1579 __git_compute_all_commands
1580 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1584 local pfx="${cur%.*}."
1587 url proxy fetch push mirror skipDefaultUpdate
1588 receivepack uploadpack tagopt pushurl
1593 local pfx="${cur%.*}."
1595 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1599 local pfx="${cur%.*}."
1601 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1608 apply.ignorewhitespace
1610 branch.autosetupmerge
1611 branch.autosetuprebase
1614 color.branch.current
1625 color.diff.whitespace
1630 color.interactive.header
1631 color.interactive.help
1632 color.interactive.prompt
1637 color.status.changed
1639 color.status.nobranch
1640 color.status.untracked
1641 color.status.updated
1648 core.deltaBaseCacheLimit
1652 core.fsyncobjectfiles
1654 core.ignoreCygwinFSTricks
1656 core.logAllRefUpdates
1657 core.loosecompression
1659 core.packedGitWindowSize
1661 core.preferSymlinkRefs
1664 core.repositoryFormatVersion
1666 core.sharedRepository
1669 core.warnAmbiguousRefs
1672 diff.autorefreshindex
1678 diff.suppressBlankEmpty
1690 format.subjectprefix
1699 gc.reflogexpireunreachable
1703 gitcvs.commitmsgannotation
1704 gitcvs.dbTableNamePrefix
1715 gui.copyblamethreshold
1719 gui.matchtrackingbranch
1720 gui.newbranchtemplate
1721 gui.pruneduringfetch
1722 gui.spellingdictionary
1738 i18n.logOutputEncoding
1743 imap.preformattedHTML
1752 interactive.singlekey
1765 mergetool.keepBackup
1768 pack.deltaCacheLimit
1781 receive.denyCurrentBranch
1783 receive.denyNonFastForwards
1786 repack.usedeltabaseoffset
1789 sendemail.aliasesfile
1790 sendemail.aliasesfiletype
1794 sendemail.chainreplyto
1796 sendemail.envelopesender
1798 sendemail.signedoffbycc
1799 sendemail.smtpencryption
1801 sendemail.smtpserver
1802 sendemail.smtpserverport
1804 sendemail.suppresscc
1805 sendemail.suppressfrom
1810 status.relativePaths
1811 status.showUntrackedFiles
1813 transfer.unpackLimit
1825 local subcommands="add rename rm show prune update set-head"
1826 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1827 if [ -z "$subcommand" ]; then
1828 __gitcomp "$subcommands"
1832 case "$subcommand" in
1833 rename|rm|show|prune)
1834 __gitcomp "$(__git_remotes)"
1837 local i c='' IFS=$'\n'
1838 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1852 __gitcomp "$(__git_refs)"
1857 __git_has_doubledash && return
1859 local cur="${COMP_WORDS[COMP_CWORD]}"
1862 __gitcomp "--merge --mixed --hard --soft --patch"
1866 __gitcomp "$(__git_refs)"
1871 local cur="${COMP_WORDS[COMP_CWORD]}"
1874 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1878 __gitcomp "$(__git_refs)"
1883 __git_has_doubledash && return
1885 local cur="${COMP_WORDS[COMP_CWORD]}"
1888 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1897 __git_has_doubledash && return
1899 local cur="${COMP_WORDS[COMP_CWORD]}"
1903 $__git_log_common_options
1904 $__git_log_shortlog_options
1905 --numbered --summary
1910 __git_complete_revlist
1915 __git_has_doubledash && return
1917 local cur="${COMP_WORDS[COMP_CWORD]}"
1920 __gitcomp "$__git_log_pretty_formats
1921 " "" "${cur##--pretty=}"
1925 __gitcomp "$__git_log_pretty_formats
1926 " "" "${cur##--format=}"
1930 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1931 $__git_diff_common_options
1941 local cur="${COMP_WORDS[COMP_CWORD]}"
1945 --all --remotes --topo-order --current --more=
1946 --list --independent --merge-base --no-name
1948 --sha1-name --sparse --topics --reflog
1953 __git_complete_revlist
1958 local cur="${COMP_WORDS[COMP_CWORD]}"
1959 local save_opts='--keep-index --no-keep-index --quiet --patch'
1960 local subcommands='save list show apply clear drop pop create branch'
1961 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1962 if [ -z "$subcommand" ]; then
1965 __gitcomp "$save_opts"
1968 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1969 __gitcomp "$subcommands"
1976 case "$subcommand,$cur" in
1978 __gitcomp "$save_opts"
1981 __gitcomp "--index --quiet"
1983 show,--*|drop,--*|branch,--*)
1986 show,*|apply,*|drop,*|pop,*|branch,*)
1987 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1988 | sed -n -e 's/:.*//p')"
1999 __git_has_doubledash && return
2001 local subcommands="add status init update summary foreach sync"
2002 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2003 local cur="${COMP_WORDS[COMP_CWORD]}"
2006 __gitcomp "--quiet --cached"
2009 __gitcomp "$subcommands"
2019 init fetch clone rebase dcommit log find-rev
2020 set-tree commit-diff info create-ignore propget
2021 proplist show-ignore show-externals branch tag blame
2022 migrate mkdirs reset gc
2024 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2025 if [ -z "$subcommand" ]; then
2026 __gitcomp "$subcommands"
2028 local remote_opts="--username= --config-dir= --no-auth-cache"
2030 --follow-parent --authors-file= --repack=
2031 --no-metadata --use-svm-props --use-svnsync-props
2032 --log-window-size= --no-checkout --quiet
2033 --repack-flags --use-log-author --localtime
2034 --ignore-paths= $remote_opts
2037 --template= --shared= --trunk= --tags=
2038 --branches= --stdlayout --minimize-url
2039 --no-metadata --use-svm-props --use-svnsync-props
2040 --rewrite-root= --prefix= --use-log-author
2041 --add-author-from $remote_opts
2044 --edit --rmdir --find-copies-harder --copy-similarity=
2047 local cur="${COMP_WORDS[COMP_CWORD]}"
2048 case "$subcommand,$cur" in
2050 __gitcomp "--revision= --fetch-all $fc_opts"
2053 __gitcomp "--revision= $fc_opts $init_opts"
2056 __gitcomp "$init_opts"
2060 --merge --strategy= --verbose --dry-run
2061 --fetch-all --no-rebase --commit-url
2062 --revision $cmt_opts $fc_opts
2066 __gitcomp "--stdin $cmt_opts $fc_opts"
2068 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2069 show-externals,--*|mkdirs,--*)
2070 __gitcomp "--revision="
2074 --limit= --revision= --verbose --incremental
2075 --oneline --show-commit --non-recursive
2076 --authors-file= --color
2081 --merge --verbose --strategy= --local
2082 --fetch-all --dry-run $fc_opts
2086 __gitcomp "--message= --file= --revision= $cmt_opts"
2092 __gitcomp "--dry-run --message --tag"
2095 __gitcomp "--dry-run --message"
2098 __gitcomp "--git-format"
2102 --config-dir= --ignore-paths= --minimize
2103 --no-auth-cache --username=
2107 __gitcomp "--revision= --parent"
2119 while [ $c -lt $COMP_CWORD ]; do
2120 i="${COMP_WORDS[c]}"
2123 __gitcomp "$(__git_tags)"
2133 case "${COMP_WORDS[COMP_CWORD-1]}" in
2139 __gitcomp "$(__git_tags)"
2145 __gitcomp "$(__git_refs)"
2152 local i c=1 command __git_dir
2154 while [ $c -lt $COMP_CWORD ]; do
2155 i="${COMP_WORDS[c]}"
2157 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2158 --bare) __git_dir="." ;;
2159 --version|-p|--paginate) ;;
2160 --help) command="help"; break ;;
2161 *) command="$i"; break ;;
2166 if [ -z "$command" ]; then
2167 case "${COMP_WORDS[COMP_CWORD]}" in
2180 *) __git_compute_porcelain_commands
2181 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2186 local expansion=$(__git_aliased_command "$command")
2187 [ "$expansion" ] && command="$expansion"
2192 apply) _git_apply ;;
2193 archive) _git_archive ;;
2194 bisect) _git_bisect ;;
2195 bundle) _git_bundle ;;
2196 branch) _git_branch ;;
2197 checkout) _git_checkout ;;
2198 cherry) _git_cherry ;;
2199 cherry-pick) _git_cherry_pick ;;
2200 clean) _git_clean ;;
2201 clone) _git_clone ;;
2202 commit) _git_commit ;;
2203 config) _git_config ;;
2204 describe) _git_describe ;;
2206 difftool) _git_difftool ;;
2207 fetch) _git_fetch ;;
2208 format-patch) _git_format_patch ;;
2215 ls-files) _git_ls_files ;;
2216 ls-remote) _git_ls_remote ;;
2217 ls-tree) _git_ls_tree ;;
2219 mergetool) _git_mergetool;;
2220 merge-base) _git_merge_base ;;
2222 name-rev) _git_name_rev ;;
2225 rebase) _git_rebase ;;
2226 remote) _git_remote ;;
2227 replace) _git_replace ;;
2228 reset) _git_reset ;;
2229 revert) _git_revert ;;
2231 send-email) _git_send_email ;;
2232 shortlog) _git_shortlog ;;
2234 show-branch) _git_show_branch ;;
2235 stash) _git_stash ;;
2237 submodule) _git_submodule ;;
2240 whatchanged) _git_log ;;
2247 __git_has_doubledash && return
2249 local cur="${COMP_WORDS[COMP_CWORD]}"
2250 local g="$(__gitdir)"
2252 if [ -f "$g/MERGE_HEAD" ]; then
2258 $__git_log_common_options
2259 $__git_log_gitk_options
2265 __git_complete_revlist
2268 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2269 || complete -o default -o nospace -F _git git
2270 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2271 || complete -o default -o nospace -F _gitk gitk
2273 # The following are necessary only for Cygwin, and only are needed
2274 # when the user has tab-completed the executable name and consequently
2275 # included the '.exe' suffix.
2277 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2278 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2279 || complete -o default -o nospace -F _git git.exe