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]}"
900 __gitcomp "default strip verbatim whitespace
901 " "" "${cur##--cleanup=}"
905 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
909 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
913 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
918 --all --author= --signoff --verify --no-verify
919 --edit --amend --include --only --interactive
920 --dry-run --reuse-message= --reedit-message=
921 --reset-author --file= --message= --template=
922 --cleanup= --untracked-files --untracked-files=
932 local cur="${COMP_WORDS[COMP_CWORD]}"
936 --all --tags --contains --abbrev= --candidates=
937 --exact-match --debug --long --match --always
941 __gitcomp "$(__git_refs)"
944 __git_diff_common_options="--stat --numstat --shortstat --summary
945 --patch-with-stat --name-only --name-status --color
946 --no-color --color-words --no-renames --check
947 --full-index --binary --abbrev --diff-filter=
949 --text --ignore-space-at-eol --ignore-space-change
950 --ignore-all-space --exit-code --quiet --ext-diff
952 --no-prefix --src-prefix= --dst-prefix=
953 --inter-hunk-context=
956 --dirstat --dirstat= --dirstat-by-file
957 --dirstat-by-file= --cumulative
962 __git_has_doubledash && return
964 local cur="${COMP_WORDS[COMP_CWORD]}"
967 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
968 --base --ours --theirs
969 $__git_diff_common_options
977 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
978 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
983 __git_has_doubledash && return
985 local cur="${COMP_WORDS[COMP_CWORD]}"
988 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
992 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
993 --base --ours --theirs
994 --no-renames --diff-filter= --find-copies-harder
995 --relative --ignore-submodules
1003 __git_fetch_options="
1004 --quiet --verbose --append --upload-pack --force --keep --depth=
1010 local cur="${COMP_WORDS[COMP_CWORD]}"
1013 __gitcomp "$__git_fetch_options"
1017 __git_complete_remote_or_refspec
1020 _git_format_patch ()
1022 local cur="${COMP_WORDS[COMP_CWORD]}"
1027 " "" "${cur##--thread=}"
1032 --stdout --attach --no-attach --thread --thread=
1034 --numbered --start-number
1038 --in-reply-to= --cc=
1039 --full-index --binary
1042 --no-prefix --src-prefix= --dst-prefix=
1043 --inline --suffix= --ignore-if-in-upstream
1049 __git_complete_revlist
1054 local cur="${COMP_WORDS[COMP_CWORD]}"
1058 --tags --root --unreachable --cache --no-reflogs --full
1059 --strict --verbose --lost-found
1069 local cur="${COMP_WORDS[COMP_CWORD]}"
1072 __gitcomp "--prune --aggressive"
1081 __git_has_doubledash && return
1083 local cur="${COMP_WORDS[COMP_CWORD]}"
1088 --text --ignore-case --word-regexp --invert-match
1090 --extended-regexp --basic-regexp --fixed-strings
1091 --files-with-matches --name-only
1092 --files-without-match
1095 --and --or --not --all-match
1101 __gitcomp "$(__git_refs)"
1106 local cur="${COMP_WORDS[COMP_CWORD]}"
1109 __gitcomp "--all --info --man --web"
1113 __git_compute_all_commands
1114 __gitcomp "$__git_all_commands
1115 attributes cli core-tutorial cvs-migration
1116 diffcore gitk glossary hooks ignore modules
1117 repository-layout tutorial tutorial-2
1124 local cur="${COMP_WORDS[COMP_CWORD]}"
1128 false true umask group all world everybody
1129 " "" "${cur##--shared=}"
1133 __gitcomp "--quiet --bare --template= --shared --shared="
1142 __git_has_doubledash && return
1144 local cur="${COMP_WORDS[COMP_CWORD]}"
1147 __gitcomp "--cached --deleted --modified --others --ignored
1148 --stage --directory --no-empty-directory --unmerged
1149 --killed --exclude= --exclude-from=
1150 --exclude-per-directory= --exclude-standard
1151 --error-unmatch --with-tree= --full-name
1152 --abbrev --ignored --exclude-per-directory
1162 __gitcomp "$(__git_remotes)"
1170 # Options that go well for log, shortlog and gitk
1171 __git_log_common_options="
1173 --branches --tags --remotes
1174 --first-parent --merges --no-merges
1176 --max-age= --since= --after=
1177 --min-age= --until= --before=
1179 # Options that go well for log and gitk (not shortlog)
1180 __git_log_gitk_options="
1181 --dense --sparse --full-history
1182 --simplify-merges --simplify-by-decoration
1185 # Options that go well for log and shortlog (not gitk)
1186 __git_log_shortlog_options="
1187 --author= --committer= --grep=
1191 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1192 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1196 __git_has_doubledash && return
1198 local cur="${COMP_WORDS[COMP_CWORD]}"
1199 local g="$(git rev-parse --git-dir 2>/dev/null)"
1201 if [ -f "$g/MERGE_HEAD" ]; then
1206 __gitcomp "$__git_log_pretty_formats
1207 " "" "${cur##--pretty=}"
1211 __gitcomp "$__git_log_pretty_formats
1212 " "" "${cur##--format=}"
1216 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1220 __gitcomp "long short" "" "${cur##--decorate=}"
1225 $__git_log_common_options
1226 $__git_log_shortlog_options
1227 $__git_log_gitk_options
1228 --root --topo-order --date-order --reverse
1229 --follow --full-diff
1230 --abbrev-commit --abbrev=
1231 --relative-date --date=
1232 --pretty= --format= --oneline
1235 --decorate --decorate=
1237 --parents --children
1239 $__git_diff_common_options
1240 --pickaxe-all --pickaxe-regex
1245 __git_complete_revlist
1248 __git_merge_options="
1249 --no-commit --no-stat --log --no-log --squash --strategy
1250 --commit --stat --no-squash --ff --no-ff --ff-only
1255 __git_complete_strategy && return
1257 local cur="${COMP_WORDS[COMP_CWORD]}"
1260 __gitcomp "$__git_merge_options"
1263 __gitcomp "$(__git_refs)"
1268 local cur="${COMP_WORDS[COMP_CWORD]}"
1271 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1284 __gitcomp "$(__git_refs)"
1289 local cur="${COMP_WORDS[COMP_CWORD]}"
1292 __gitcomp "--dry-run"
1301 __gitcomp "--tags --all --stdin"
1306 __git_complete_strategy && return
1308 local cur="${COMP_WORDS[COMP_CWORD]}"
1312 --rebase --no-rebase
1313 $__git_merge_options
1314 $__git_fetch_options
1319 __git_complete_remote_or_refspec
1324 local cur="${COMP_WORDS[COMP_CWORD]}"
1325 case "${COMP_WORDS[COMP_CWORD-1]}" in
1327 __gitcomp "$(__git_remotes)"
1332 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1337 --all --mirror --tags --dry-run --force --verbose
1338 --receive-pack= --repo=
1343 __git_complete_remote_or_refspec
1348 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1349 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1350 __gitcomp "--continue --skip --abort"
1353 __git_complete_strategy && return
1356 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1361 --onto --merge --strategy --interactive
1362 --preserve-merges --stat --no-stat
1363 --committer-date-is-author-date --ignore-date
1364 --ignore-whitespace --whitespace=
1369 __gitcomp "$(__git_refs)"
1372 __git_send_email_confirm_options="always never auto cc compose"
1373 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1377 local cur="${COMP_WORDS[COMP_CWORD]}"
1381 $__git_send_email_confirm_options
1382 " "" "${cur##--confirm=}"
1387 $__git_send_email_suppresscc_options
1388 " "" "${cur##--suppress-cc=}"
1392 --smtp-encryption=*)
1393 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1397 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1398 --compose --confirm= --dry-run --envelope-sender
1400 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1401 --no-suppress-from --no-thread --quiet
1402 --signed-off-by-cc --smtp-pass --smtp-server
1403 --smtp-server-port --smtp-encryption= --smtp-user
1404 --subject --suppress-cc= --suppress-from --thread --to
1405 --validate --no-validate"
1412 __git_config_get_set_variables ()
1414 local prevword word config_file= c=$COMP_CWORD
1415 while [ $c -gt 1 ]; do
1416 word="${COMP_WORDS[c]}"
1418 --global|--system|--file=*)
1423 config_file="$word $prevword"
1431 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1444 local cur="${COMP_WORDS[COMP_CWORD]}"
1445 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1448 __gitcomp "$(__git_remotes)"
1452 __gitcomp "$(__git_refs)"
1456 local remote="${prv#remote.}"
1457 remote="${remote%.fetch}"
1458 __gitcomp "$(__git_refs_remotes "$remote")"
1462 local remote="${prv#remote.}"
1463 remote="${remote%.push}"
1464 __gitcomp "$(git --git-dir="$(__gitdir)" \
1465 for-each-ref --format='%(refname):%(refname)' \
1469 pull.twohead|pull.octopus)
1470 __git_compute_merge_strategies
1471 __gitcomp "$__git_merge_strategies"
1474 color.branch|color.diff|color.interactive|\
1475 color.showbranch|color.status|color.ui)
1476 __gitcomp "always never auto"
1480 __gitcomp "false true"
1485 normal black red green yellow blue magenta cyan white
1486 bold dim ul blink reverse
1491 __gitcomp "man info web html"
1495 __gitcomp "$__git_log_date_formats"
1498 sendemail.aliasesfiletype)
1499 __gitcomp "mutt mailrc pine elm gnus"
1503 __gitcomp "$__git_send_email_confirm_options"
1506 sendemail.suppresscc)
1507 __gitcomp "$__git_send_email_suppresscc_options"
1510 --get|--get-all|--unset|--unset-all)
1511 __gitcomp "$(__git_config_get_set_variables)"
1522 --global --system --file=
1523 --list --replace-all
1524 --get --get-all --get-regexp
1525 --add --unset --unset-all
1526 --remove-section --rename-section
1531 local pfx="${cur%.*}."
1533 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1537 local pfx="${cur%.*}."
1539 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1543 local pfx="${cur%.*}."
1546 argprompt cmd confirm needsfile noconsole norescan
1547 prompt revprompt revunmerged title
1552 local pfx="${cur%.*}."
1554 __gitcomp "cmd path" "$pfx" "$cur"
1558 local pfx="${cur%.*}."
1560 __gitcomp "cmd path" "$pfx" "$cur"
1564 local pfx="${cur%.*}."
1566 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1570 local pfx="${cur%.*}."
1572 __git_compute_all_commands
1573 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1577 local pfx="${cur%.*}."
1580 url proxy fetch push mirror skipDefaultUpdate
1581 receivepack uploadpack tagopt pushurl
1586 local pfx="${cur%.*}."
1588 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1592 local pfx="${cur%.*}."
1594 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1601 apply.ignorewhitespace
1603 branch.autosetupmerge
1604 branch.autosetuprebase
1607 color.branch.current
1618 color.diff.whitespace
1623 color.interactive.header
1624 color.interactive.help
1625 color.interactive.prompt
1630 color.status.changed
1632 color.status.nobranch
1633 color.status.untracked
1634 color.status.updated
1641 core.deltaBaseCacheLimit
1645 core.fsyncobjectfiles
1647 core.ignoreCygwinFSTricks
1649 core.logAllRefUpdates
1650 core.loosecompression
1652 core.packedGitWindowSize
1654 core.preferSymlinkRefs
1657 core.repositoryFormatVersion
1659 core.sharedRepository
1662 core.warnAmbiguousRefs
1665 diff.autorefreshindex
1671 diff.suppressBlankEmpty
1683 format.subjectprefix
1692 gc.reflogexpireunreachable
1696 gitcvs.commitmsgannotation
1697 gitcvs.dbTableNamePrefix
1708 gui.copyblamethreshold
1712 gui.matchtrackingbranch
1713 gui.newbranchtemplate
1714 gui.pruneduringfetch
1715 gui.spellingdictionary
1731 i18n.logOutputEncoding
1736 imap.preformattedHTML
1745 interactive.singlekey
1758 mergetool.keepBackup
1761 pack.deltaCacheLimit
1774 receive.denyCurrentBranch
1776 receive.denyNonFastForwards
1779 repack.usedeltabaseoffset
1782 sendemail.aliasesfile
1783 sendemail.aliasesfiletype
1787 sendemail.chainreplyto
1789 sendemail.envelopesender
1791 sendemail.signedoffbycc
1792 sendemail.smtpencryption
1794 sendemail.smtpserver
1795 sendemail.smtpserverport
1797 sendemail.suppresscc
1798 sendemail.suppressfrom
1803 status.relativePaths
1804 status.showUntrackedFiles
1806 transfer.unpackLimit
1818 local subcommands="add rename rm show prune update set-head"
1819 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1820 if [ -z "$subcommand" ]; then
1821 __gitcomp "$subcommands"
1825 case "$subcommand" in
1826 rename|rm|show|prune)
1827 __gitcomp "$(__git_remotes)"
1830 local i c='' IFS=$'\n'
1831 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1845 __gitcomp "$(__git_refs)"
1850 __git_has_doubledash && return
1852 local cur="${COMP_WORDS[COMP_CWORD]}"
1855 __gitcomp "--merge --mixed --hard --soft --patch"
1859 __gitcomp "$(__git_refs)"
1864 local cur="${COMP_WORDS[COMP_CWORD]}"
1867 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1871 __gitcomp "$(__git_refs)"
1876 __git_has_doubledash && return
1878 local cur="${COMP_WORDS[COMP_CWORD]}"
1881 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1890 __git_has_doubledash && return
1892 local cur="${COMP_WORDS[COMP_CWORD]}"
1896 $__git_log_common_options
1897 $__git_log_shortlog_options
1898 --numbered --summary
1903 __git_complete_revlist
1908 __git_has_doubledash && return
1910 local cur="${COMP_WORDS[COMP_CWORD]}"
1913 __gitcomp "$__git_log_pretty_formats
1914 " "" "${cur##--pretty=}"
1918 __gitcomp "$__git_log_pretty_formats
1919 " "" "${cur##--format=}"
1923 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1924 $__git_diff_common_options
1934 local cur="${COMP_WORDS[COMP_CWORD]}"
1938 --all --remotes --topo-order --current --more=
1939 --list --independent --merge-base --no-name
1941 --sha1-name --sparse --topics --reflog
1946 __git_complete_revlist
1951 local cur="${COMP_WORDS[COMP_CWORD]}"
1952 local save_opts='--keep-index --no-keep-index --quiet --patch'
1953 local subcommands='save list show apply clear drop pop create branch'
1954 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1955 if [ -z "$subcommand" ]; then
1958 __gitcomp "$save_opts"
1961 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1962 __gitcomp "$subcommands"
1969 case "$subcommand,$cur" in
1971 __gitcomp "$save_opts"
1974 __gitcomp "--index --quiet"
1976 show,--*|drop,--*|branch,--*)
1979 show,*|apply,*|drop,*|pop,*|branch,*)
1980 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1981 | sed -n -e 's/:.*//p')"
1992 __git_has_doubledash && return
1994 local subcommands="add status init update summary foreach sync"
1995 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1996 local cur="${COMP_WORDS[COMP_CWORD]}"
1999 __gitcomp "--quiet --cached"
2002 __gitcomp "$subcommands"
2012 init fetch clone rebase dcommit log find-rev
2013 set-tree commit-diff info create-ignore propget
2014 proplist show-ignore show-externals branch tag blame
2017 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2018 if [ -z "$subcommand" ]; then
2019 __gitcomp "$subcommands"
2021 local remote_opts="--username= --config-dir= --no-auth-cache"
2023 --follow-parent --authors-file= --repack=
2024 --no-metadata --use-svm-props --use-svnsync-props
2025 --log-window-size= --no-checkout --quiet
2026 --repack-flags --use-log-author --localtime
2027 --ignore-paths= $remote_opts
2030 --template= --shared= --trunk= --tags=
2031 --branches= --stdlayout --minimize-url
2032 --no-metadata --use-svm-props --use-svnsync-props
2033 --rewrite-root= --prefix= --use-log-author
2034 --add-author-from $remote_opts
2037 --edit --rmdir --find-copies-harder --copy-similarity=
2040 local cur="${COMP_WORDS[COMP_CWORD]}"
2041 case "$subcommand,$cur" in
2043 __gitcomp "--revision= --fetch-all $fc_opts"
2046 __gitcomp "--revision= $fc_opts $init_opts"
2049 __gitcomp "$init_opts"
2053 --merge --strategy= --verbose --dry-run
2054 --fetch-all --no-rebase --commit-url
2055 --revision $cmt_opts $fc_opts
2059 __gitcomp "--stdin $cmt_opts $fc_opts"
2061 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2063 __gitcomp "--revision="
2067 --limit= --revision= --verbose --incremental
2068 --oneline --show-commit --non-recursive
2069 --authors-file= --color
2074 --merge --verbose --strategy= --local
2075 --fetch-all --dry-run $fc_opts
2079 __gitcomp "--message= --file= --revision= $cmt_opts"
2085 __gitcomp "--dry-run --message --tag"
2088 __gitcomp "--dry-run --message"
2091 __gitcomp "--git-format"
2095 --config-dir= --ignore-paths= --minimize
2096 --no-auth-cache --username=
2109 while [ $c -lt $COMP_CWORD ]; do
2110 i="${COMP_WORDS[c]}"
2113 __gitcomp "$(__git_tags)"
2123 case "${COMP_WORDS[COMP_CWORD-1]}" in
2129 __gitcomp "$(__git_tags)"
2135 __gitcomp "$(__git_refs)"
2142 local i c=1 command __git_dir
2144 while [ $c -lt $COMP_CWORD ]; do
2145 i="${COMP_WORDS[c]}"
2147 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2148 --bare) __git_dir="." ;;
2149 --version|-p|--paginate) ;;
2150 --help) command="help"; break ;;
2151 *) command="$i"; break ;;
2156 if [ -z "$command" ]; then
2157 case "${COMP_WORDS[COMP_CWORD]}" in
2170 *) __git_compute_porcelain_commands
2171 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2176 local expansion=$(__git_aliased_command "$command")
2177 [ "$expansion" ] && command="$expansion"
2182 apply) _git_apply ;;
2183 archive) _git_archive ;;
2184 bisect) _git_bisect ;;
2185 bundle) _git_bundle ;;
2186 branch) _git_branch ;;
2187 checkout) _git_checkout ;;
2188 cherry) _git_cherry ;;
2189 cherry-pick) _git_cherry_pick ;;
2190 clean) _git_clean ;;
2191 clone) _git_clone ;;
2192 commit) _git_commit ;;
2193 config) _git_config ;;
2194 describe) _git_describe ;;
2196 difftool) _git_difftool ;;
2197 fetch) _git_fetch ;;
2198 format-patch) _git_format_patch ;;
2205 ls-files) _git_ls_files ;;
2206 ls-remote) _git_ls_remote ;;
2207 ls-tree) _git_ls_tree ;;
2209 mergetool) _git_mergetool;;
2210 merge-base) _git_merge_base ;;
2212 name-rev) _git_name_rev ;;
2215 rebase) _git_rebase ;;
2216 remote) _git_remote ;;
2217 replace) _git_replace ;;
2218 reset) _git_reset ;;
2219 revert) _git_revert ;;
2221 send-email) _git_send_email ;;
2222 shortlog) _git_shortlog ;;
2224 show-branch) _git_show_branch ;;
2225 stash) _git_stash ;;
2227 submodule) _git_submodule ;;
2230 whatchanged) _git_log ;;
2237 __git_has_doubledash && return
2239 local cur="${COMP_WORDS[COMP_CWORD]}"
2240 local g="$(__gitdir)"
2242 if [ -f "$g/MERGE_HEAD" ]; then
2248 $__git_log_common_options
2249 $__git_log_gitk_options
2255 __git_complete_revlist
2258 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2259 || complete -o default -o nospace -F _git git
2260 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2261 || complete -o default -o nospace -F _gitk gitk
2263 # The following are necessary only for Cygwin, and only are needed
2264 # when the user has tab-completed the executable name and consequently
2265 # included the '.exe' suffix.
2267 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2268 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2269 || complete -o default -o nospace -F _git git.exe