3 # bash completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 # 2) Added the following line to your .bashrc:
22 # source ~/.git-completion.sh
24 # 3) You may want to make sure the git executable is available
25 # in your PATH before this script is sourced, as some caching
26 # is performed while the script loads. If git isn't found
27 # at source time then all lookups will be done on demand,
28 # which may be slightly slower.
30 # 4) Consider changing your PS1 to also show the current branch:
31 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
33 # The argument to __git_ps1 will be displayed only if you
34 # are currently in a git repository. The %s token will be
35 # the name of the current branch.
37 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
38 # value, unstaged (*) and staged (+) changes will be shown next
39 # to the branch name. You can configure this per-repository
40 # with the bash.showDirtyState variable, which defaults to true
41 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
45 # *) Read Documentation/SubmittingPatches
46 # *) Send all patches to the current maintainer:
48 # "Shawn O. Pearce" <spearce@spearce.org>
50 # *) Always CC the Git mailing list:
55 case "$COMP_WORDBREAKS" in
57 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
60 # __gitdir accepts 0 or 1 arguments (i.e., location)
61 # returns location of .git repo
64 if [ -z "${1-}" ]; then
65 if [ -n "${__git_dir-}" ]; then
67 elif [ -d .git
]; then
70 git rev-parse
--git-dir 2>/dev
/null
72 elif [ -d "$1/.git" ]; then
79 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
80 # returns text to add to bash PS1 prompt (includes branch name)
87 if [ -d "$g/rebase-apply" ]; then
88 if [ -f "$g/rebase-apply/rebasing" ]; then
90 elif [ -f "$g/rebase-apply/applying" ]; then
95 b
="$(git symbolic-ref HEAD 2>/dev/null)"
96 elif [ -f "$g/rebase-merge/interactive" ]; then
98 b
="$(cat "$g/rebase-merge
/head-name
")"
99 elif [ -d "$g/rebase-merge" ]; then
101 b
="$(cat "$g/rebase-merge
/head-name
")"
103 if [ -f "$g/MERGE_HEAD" ]; then
106 if [ -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)..." ||
134 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
135 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
140 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
141 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
142 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
143 git
diff --no-ext-diff --ignore-submodules \
144 --quiet --exit-code || w
="*"
145 if git rev-parse
--quiet --verify HEAD
>/dev
/null
; then
146 git diff-index
--cached --quiet \
147 --ignore-submodules HEAD
-- || i
="+"
156 if [ -n "${1-}" ]; then
157 printf "$1" "$c${b##refs/heads/}$w$i$r"
159 printf " (%s)" "$c${b##refs/heads/}$w$i$r"
165 # __gitcomp_1 requires 2 arguments
168 local c IFS
=' '$
'\t'$
'\n'
171 --*=*) printf %s$
'\n' "$c$2" ;;
172 *.
) printf %s$
'\n' "$c$2" ;;
173 *) printf %s$
'\n' "$c$2 " ;;
178 # __gitcomp accepts 1, 2, 3, or 4 arguments
179 # generates completion reply with compgen
182 local cur
="${COMP_WORDS[COMP_CWORD]}"
183 if [ $# -gt 2 ]; then
192 COMPREPLY
=($
(compgen
-P "${2-}" \
193 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
199 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
202 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
203 if [ -d "$dir" ]; then
204 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
208 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
209 case "$is_hash,$i" in
212 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
213 n
,*) is_hash
=y
; echo "$i" ;;
218 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
221 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
222 if [ -d "$dir" ]; then
223 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
227 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
228 case "$is_hash,$i" in
231 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
232 n
,*) is_hash
=y
; echo "$i" ;;
237 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
240 local i is_hash
=y dir
="$(__gitdir "${1-}")"
241 local cur
="${COMP_WORDS[COMP_CWORD]}" format refs
242 if [ -d "$dir" ]; then
249 if [ -e "$dir/HEAD" ]; then echo HEAD
; fi
250 format
="refname:short"
251 refs
="refs/tags refs/heads refs/remotes"
254 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
258 for i
in $
(git ls-remote
"$dir" 2>/dev
/null
); do
259 case "$is_hash,$i" in
262 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
263 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
264 n
,refs
/remotes
/*) is_hash
=y
; echo "${i#refs/remotes/}" ;;
265 n
,*) is_hash
=y
; echo "$i" ;;
270 # __git_refs2 requires 1 argument (to pass to __git_refs)
274 for i
in $
(__git_refs
"$1"); do
279 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
280 __git_refs_remotes
()
282 local cmd i is_hash
=y
283 for i
in $
(git ls-remote
"$1" 2>/dev
/null
); do
284 case "$is_hash,$i" in
287 echo "$i:refs/remotes/$1/${i#refs/heads/}"
291 n
,refs
/tags
/*) is_hash
=y
;;
299 local i ngoff IFS
=$
'\n' d
="$(__gitdir)"
300 shopt -q nullglob || ngoff
=1
302 for i
in "$d/remotes"/*; do
303 echo ${i#$d/remotes/}
305 [ "$ngoff" ] && shopt -u nullglob
306 for i
in $
(git
--git-dir="$d" config
--list); do
316 __git_merge_strategies
()
318 if [ -n "${__git_merge_strategylist-}" ]; then
319 echo "$__git_merge_strategylist"
322 git merge
-s help 2>&1 |
323 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
331 __git_merge_strategylist
=
332 __git_merge_strategylist
=$
(__git_merge_strategies
2>/dev
/null
)
334 __git_complete_file
()
336 local pfx
ls ref cur
="${COMP_WORDS[COMP_CWORD]}"
353 case "$COMP_WORDBREAKS" in
355 *) pfx
="$ref:$pfx" ;;
359 COMPREPLY
=($
(compgen
-P "$pfx" \
360 -W "$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" \
361 | sed '/^100... blob /{
377 __gitcomp
"$(__git_refs)"
382 __git_complete_revlist
()
384 local pfx cur
="${COMP_WORDS[COMP_CWORD]}"
389 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
394 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
397 __gitcomp
"$(__git_refs)"
402 __git_complete_remote_or_refspec
()
404 local cmd
="${COMP_WORDS[1]}"
405 local cur
="${COMP_WORDS[COMP_CWORD]}"
406 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
407 while [ $c -lt $COMP_CWORD ]; do
410 --all|
--mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
412 *) remote
="$i"; break ;;
416 if [ -z "$remote" ]; then
417 __gitcomp
"$(__git_remotes)"
420 if [ $no_complete_refspec = 1 ]; then
424 [ "$remote" = "." ] && remote
=
427 case "$COMP_WORDBREAKS" in
429 *) pfx
="${cur%%:*}:" ;;
441 if [ $lhs = 1 ]; then
442 __gitcomp
"$(__git_refs2 "$remote")" "$pfx" "$cur"
444 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
448 if [ $lhs = 1 ]; then
449 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
451 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
455 if [ $lhs = 1 ]; then
456 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
458 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
464 __git_complete_strategy
()
466 case "${COMP_WORDS[COMP_CWORD-1]}" in
468 __gitcomp
"$(__git_merge_strategies)"
471 local cur
="${COMP_WORDS[COMP_CWORD]}"
474 __gitcomp
"$(__git_merge_strategies)" "" "${cur##--strategy=}"
481 __git_all_commands
()
483 if [ -n "${__git_all_commandlist-}" ]; then
484 echo "$__git_all_commandlist"
488 for i
in $
(git
help -a|
egrep '^ ')
491 *--*) : helper pattern
;;
496 __git_all_commandlist
=
497 __git_all_commandlist
="$(__git_all_commands 2>/dev/null)"
499 __git_porcelain_commands
()
501 if [ -n "${__git_porcelain_commandlist-}" ]; then
502 echo "$__git_porcelain_commandlist"
506 for i
in "help" $
(__git_all_commands
)
509 *--*) : helper pattern
;;
510 applymbox
) : ask gittus
;;
511 applypatch
) : ask gittus
;;
512 archimport
) : import
;;
513 cat-file
) : plumbing
;;
514 check-attr
) : plumbing
;;
515 check-ref-format
) : plumbing
;;
516 checkout-index
) : plumbing
;;
517 commit-tree
) : plumbing
;;
518 count-objects
) : infrequent
;;
519 cvsexportcommit
) : export;;
520 cvsimport
) : import
;;
521 cvsserver
) : daemon
;;
523 diff-files
) : plumbing
;;
524 diff-index
) : plumbing
;;
525 diff-tree
) : plumbing
;;
526 fast-import
) : import
;;
527 fast-export
) : export;;
528 fsck-objects
) : plumbing
;;
529 fetch-pack
) : plumbing
;;
530 fmt-merge-msg
) : plumbing
;;
531 for-each-ref
) : plumbing
;;
532 hash-object
) : plumbing
;;
533 http-
*) : transport
;;
534 index-pack
) : plumbing
;;
535 init-db
) : deprecated
;;
536 local-fetch
) : plumbing
;;
537 lost-found
) : infrequent
;;
538 ls-files
) : plumbing
;;
539 ls-remote
) : plumbing
;;
540 ls-tree
) : plumbing
;;
541 mailinfo
) : plumbing
;;
542 mailsplit
) : plumbing
;;
543 merge-
*) : plumbing
;;
546 pack-objects
) : plumbing
;;
547 pack-redundant
) : plumbing
;;
548 pack-refs
) : plumbing
;;
549 parse-remote
) : plumbing
;;
550 patch-id
) : plumbing
;;
551 peek-remote
) : plumbing
;;
553 prune-packed
) : plumbing
;;
554 quiltimport
) : import
;;
555 read-tree
) : plumbing
;;
556 receive-pack
) : plumbing
;;
558 repo-config
) : deprecated
;;
560 rev-list
) : plumbing
;;
561 rev-parse
) : plumbing
;;
562 runstatus
) : plumbing
;;
563 sh-setup
) : internal
;;
565 show-ref
) : plumbing
;;
566 send-pack
) : plumbing
;;
567 show-index
) : plumbing
;;
569 stripspace
) : plumbing
;;
570 symbolic-ref
) : plumbing
;;
571 tar-tree
) : deprecated
;;
572 unpack-file
) : plumbing
;;
573 unpack-objects
) : plumbing
;;
574 update-index
) : plumbing
;;
575 update-ref
) : plumbing
;;
576 update-server-info
) : daemon
;;
577 upload-archive
) : plumbing
;;
578 upload-pack
) : plumbing
;;
579 write-tree
) : plumbing
;;
581 verify-pack
) : infrequent
;;
582 verify-tag
) : plumbing
;;
587 __git_porcelain_commandlist
=
588 __git_porcelain_commandlist
="$(__git_porcelain_commands 2>/dev/null)"
593 for i
in $
(git
--git-dir="$(__gitdir)" config
--list); do
603 # __git_aliased_command requires 1 argument
604 __git_aliased_command
()
606 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
607 config
--get "alias.$1")
608 for word
in $cmdline; do
609 if [ "${word##-*}" ]; then
616 # __git_find_subcommand requires 1 argument
617 __git_find_subcommand
()
619 local word subcommand c
=1
621 while [ $c -lt $COMP_CWORD ]; do
622 word
="${COMP_WORDS[c]}"
623 for subcommand
in $1; do
624 if [ "$subcommand" = "$word" ]; then
633 __git_has_doubledash
()
636 while [ $c -lt $COMP_CWORD ]; do
637 if [ "--" = "${COMP_WORDS[c]}" ]; then
645 __git_whitespacelist
="nowarn warn error error-all fix"
649 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
650 if [ -d "$dir"/rebase-apply
]; then
651 __gitcomp
"--skip --resolved --abort"
656 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
661 --3way --committer-date-is-author-date --ignore-date
662 --interactive --keep --no-utf8 --signoff --utf8
672 local cur
="${COMP_WORDS[COMP_CWORD]}"
675 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
680 --stat --numstat --summary --check --index
681 --cached --index-info --reverse --reject --unidiff-zero
682 --apply --no-add --exclude=
683 --whitespace= --inaccurate-eof --verbose
692 __git_has_doubledash
&& return
694 local cur
="${COMP_WORDS[COMP_CWORD]}"
698 --interactive --refresh --patch --update --dry-run
699 --ignore-errors --intent-to-add
708 local cur
="${COMP_WORDS[COMP_CWORD]}"
711 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
715 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
720 --format= --list --verbose
721 --prefix= --remote= --exec=
731 __git_has_doubledash
&& return
733 local subcommands
="start bad good skip reset visualize replay log run"
734 local subcommand
="$(__git_find_subcommand "$subcommands")"
735 if [ -z "$subcommand" ]; then
736 __gitcomp
"$subcommands"
740 case "$subcommand" in
742 __gitcomp
"$(__git_refs)"
752 local i c
=1 only_local_ref
="n" has_r
="n"
754 while [ $c -lt $COMP_CWORD ]; do
757 -d|
-m) only_local_ref
="y" ;;
763 case "${COMP_WORDS[COMP_CWORD]}" in
766 --color --no-color --verbose --abbrev= --no-abbrev
767 --track --no-track --contains --merged --no-merged
771 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
772 __gitcomp
"$(__git_heads)"
774 __gitcomp
"$(__git_refs)"
782 local cmd
="${COMP_WORDS[2]}"
783 case "$COMP_CWORD" in
785 __gitcomp
"create list-heads verify unbundle"
793 __git_complete_revlist
802 __git_has_doubledash
&& return
804 __gitcomp
"$(__git_refs)"
809 __gitcomp
"$(__git_refs)"
814 local cur
="${COMP_WORDS[COMP_CWORD]}"
817 __gitcomp
"--edit --no-commit"
820 __gitcomp
"$(__git_refs)"
827 __git_has_doubledash
&& return
829 local cur
="${COMP_WORDS[COMP_CWORD]}"
832 __gitcomp
"--dry-run --quiet"
841 local cur
="${COMP_WORDS[COMP_CWORD]}"
866 __git_has_doubledash
&& return
868 local cur
="${COMP_WORDS[COMP_CWORD]}"
872 --all --author= --signoff --verify --no-verify
873 --edit --amend --include --only --interactive
882 local cur
="${COMP_WORDS[COMP_CWORD]}"
886 --all --tags --contains --abbrev= --candidates=
887 --exact-match --debug --long --match --always
891 __gitcomp
"$(__git_refs)"
894 __git_diff_common_options
="--stat --numstat --shortstat --summary
895 --patch-with-stat --name-only --name-status --color
896 --no-color --color-words --no-renames --check
897 --full-index --binary --abbrev --diff-filter=
899 --text --ignore-space-at-eol --ignore-space-change
900 --ignore-all-space --exit-code --quiet --ext-diff
902 --no-prefix --src-prefix= --dst-prefix=
903 --inter-hunk-context=
910 __git_has_doubledash
&& return
912 local cur
="${COMP_WORDS[COMP_CWORD]}"
915 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
916 --base --ours --theirs
917 $__git_diff_common_options
925 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
926 tkdiff vimdiff gvimdiff xxdiff
931 local cur
="${COMP_WORDS[COMP_CWORD]}"
934 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
945 __git_fetch_options
="
946 --quiet --verbose --append --upload-pack --force --keep --depth=
952 local cur
="${COMP_WORDS[COMP_CWORD]}"
955 __gitcomp
"$__git_fetch_options"
959 __git_complete_remote_or_refspec
964 local cur
="${COMP_WORDS[COMP_CWORD]}"
969 " "" "${cur##--thread=}"
974 --stdout --attach --no-attach --thread --thread=
976 --numbered --start-number
981 --full-index --binary
984 --no-prefix --src-prefix= --dst-prefix=
985 --inline --suffix= --ignore-if-in-upstream
991 __git_complete_revlist
996 local cur
="${COMP_WORDS[COMP_CWORD]}"
1000 --tags --root --unreachable --cache --no-reflogs --full
1001 --strict --verbose --lost-found
1011 local cur
="${COMP_WORDS[COMP_CWORD]}"
1014 __gitcomp
"--prune --aggressive"
1023 __git_has_doubledash
&& return
1025 local cur
="${COMP_WORDS[COMP_CWORD]}"
1030 --text --ignore-case --word-regexp --invert-match
1032 --extended-regexp --basic-regexp --fixed-strings
1033 --files-with-matches --name-only
1034 --files-without-match
1036 --and --or --not --all-match
1046 local cur
="${COMP_WORDS[COMP_CWORD]}"
1049 __gitcomp
"--all --info --man --web"
1053 __gitcomp
"$(__git_all_commands)
1054 attributes cli core-tutorial cvs-migration
1055 diffcore gitk glossary hooks ignore modules
1056 repository-layout tutorial tutorial-2
1063 local cur
="${COMP_WORDS[COMP_CWORD]}"
1067 false true umask group all world everybody
1068 " "" "${cur##--shared=}"
1072 __gitcomp
"--quiet --bare --template= --shared --shared="
1081 __git_has_doubledash
&& return
1083 local cur
="${COMP_WORDS[COMP_CWORD]}"
1086 __gitcomp
"--cached --deleted --modified --others --ignored
1087 --stage --directory --no-empty-directory --unmerged
1088 --killed --exclude= --exclude-from=
1089 --exclude-per-directory= --exclude-standard
1090 --error-unmatch --with-tree= --full-name
1091 --abbrev --ignored --exclude-per-directory
1101 __gitcomp
"$(__git_remotes)"
1109 # Options that go well for log, shortlog and gitk
1110 __git_log_common_options
="
1112 --branches --tags --remotes
1113 --first-parent --no-merges
1115 --max-age= --since= --after=
1116 --min-age= --until= --before=
1118 # Options that go well for log and gitk (not shortlog)
1119 __git_log_gitk_options
="
1120 --dense --sparse --full-history
1121 --simplify-merges --simplify-by-decoration
1124 # Options that go well for log and shortlog (not gitk)
1125 __git_log_shortlog_options
="
1126 --author= --committer= --grep=
1130 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1131 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1135 __git_has_doubledash
&& return
1137 local cur
="${COMP_WORDS[COMP_CWORD]}"
1138 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1140 if [ -f "$g/MERGE_HEAD" ]; then
1145 __gitcomp
"$__git_log_pretty_formats
1146 " "" "${cur##--pretty=}"
1150 __gitcomp
"$__git_log_pretty_formats
1151 " "" "${cur##--format=}"
1155 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1160 $__git_log_common_options
1161 $__git_log_shortlog_options
1162 $__git_log_gitk_options
1163 --root --topo-order --date-order --reverse
1165 --abbrev-commit --abbrev=
1166 --relative-date --date=
1167 --pretty= --format= --oneline
1172 --parents --children
1174 $__git_diff_common_options
1175 --pickaxe-all --pickaxe-regex
1180 __git_complete_revlist
1183 __git_merge_options
="
1184 --no-commit --no-stat --log --no-log --squash --strategy
1185 --commit --stat --no-squash --ff --no-ff
1190 __git_complete_strategy
&& return
1192 local cur
="${COMP_WORDS[COMP_CWORD]}"
1195 __gitcomp
"$__git_merge_options"
1198 __gitcomp
"$(__git_refs)"
1203 local cur
="${COMP_WORDS[COMP_CWORD]}"
1206 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1219 __gitcomp
"$(__git_refs)"
1224 local cur
="${COMP_WORDS[COMP_CWORD]}"
1227 __gitcomp
"--dry-run"
1236 __gitcomp
"--tags --all --stdin"
1241 __git_complete_strategy
&& return
1243 local cur
="${COMP_WORDS[COMP_CWORD]}"
1247 --rebase --no-rebase
1248 $__git_merge_options
1249 $__git_fetch_options
1254 __git_complete_remote_or_refspec
1259 local cur
="${COMP_WORDS[COMP_CWORD]}"
1260 case "${COMP_WORDS[COMP_CWORD-1]}" in
1262 __gitcomp
"$(__git_remotes)"
1267 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1272 --all --mirror --tags --dry-run --force --verbose
1273 --receive-pack= --repo=
1278 __git_complete_remote_or_refspec
1283 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
1284 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1285 __gitcomp
"--continue --skip --abort"
1288 __git_complete_strategy
&& return
1291 __gitcomp
"--onto --merge --strategy --interactive"
1294 __gitcomp
"$(__git_refs)"
1297 __git_send_email_confirm_options
="always never auto cc compose"
1298 __git_send_email_suppresscc_options
="author self cc ccbody sob cccmd body all"
1302 local cur
="${COMP_WORDS[COMP_CWORD]}"
1306 $__git_send_email_confirm_options
1307 " "" "${cur##--confirm=}"
1312 $__git_send_email_suppresscc_options
1313 " "" "${cur##--suppress-cc=}"
1317 --smtp-encryption=*)
1318 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1322 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1323 --compose --confirm= --dry-run --envelope-sender
1325 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1326 --no-suppress-from --no-thread --quiet
1327 --signed-off-by-cc --smtp-pass --smtp-server
1328 --smtp-server-port --smtp-encryption= --smtp-user
1329 --subject --suppress-cc= --suppress-from --thread --to
1330 --validate --no-validate"
1337 __git_config_get_set_variables
()
1339 local prevword word config_file
= c
=$COMP_CWORD
1340 while [ $c -gt 1 ]; do
1341 word
="${COMP_WORDS[c]}"
1343 --global|
--system|
--file=*)
1348 config_file
="$word $prevword"
1356 for i
in $
(git
--git-dir="$(__gitdir)" config
$config_file --list \
1368 local cur
="${COMP_WORDS[COMP_CWORD]}"
1369 local prv
="${COMP_WORDS[COMP_CWORD-1]}"
1372 __gitcomp
"$(__git_remotes)"
1376 __gitcomp
"$(__git_refs)"
1380 local remote
="${prv#remote.}"
1381 remote
="${remote%.fetch}"
1382 __gitcomp
"$(__git_refs_remotes "$remote")"
1386 local remote
="${prv#remote.}"
1387 remote
="${remote%.push}"
1388 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1389 for-each-ref --format='%(refname):%(refname)' \
1393 pull.twohead|pull.octopus
)
1394 __gitcomp
"$(__git_merge_strategies)"
1397 color.branch|color.
diff|color.interactive|\
1398 color.showbranch|color.status|color.ui
)
1399 __gitcomp
"always never auto"
1403 __gitcomp
"false true"
1408 normal black red green yellow blue magenta cyan white
1409 bold dim ul blink reverse
1414 __gitcomp
"man info web html"
1418 __gitcomp
"$__git_log_date_formats"
1421 sendemail.aliasesfiletype
)
1422 __gitcomp
"mutt mailrc pine elm gnus"
1426 __gitcomp
"$__git_send_email_confirm_options"
1429 sendemail.suppresscc
)
1430 __gitcomp
"$__git_send_email_suppresscc_options"
1433 --get|
--get-all|
--unset|
--unset-all)
1434 __gitcomp
"$(__git_config_get_set_variables)"
1445 --global --system --file=
1446 --list --replace-all
1447 --get --get-all --get-regexp
1448 --add --unset --unset-all
1449 --remove-section --rename-section
1454 local pfx
="${cur%.*}."
1456 __gitcomp
"remote merge mergeoptions" "$pfx" "$cur"
1460 local pfx
="${cur%.*}."
1462 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1466 local pfx
="${cur%.*}."
1469 argprompt cmd confirm needsfile noconsole norescan
1470 prompt revprompt revunmerged title
1475 local pfx
="${cur%.*}."
1477 __gitcomp
"cmd path" "$pfx" "$cur"
1481 local pfx
="${cur%.*}."
1483 __gitcomp
"cmd path" "$pfx" "$cur"
1487 local pfx
="${cur%.*}."
1489 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1493 local pfx
="${cur%.*}."
1495 __gitcomp
"$(__git_all_commands)" "$pfx" "$cur"
1499 local pfx
="${cur%.*}."
1502 url proxy fetch push mirror skipDefaultUpdate
1503 receivepack uploadpack tagopt
1508 local pfx
="${cur%.*}."
1510 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1514 local pfx
="${cur%.*}."
1516 __gitcomp
"insteadof" "$pfx" "$cur"
1523 branch.autosetupmerge
1524 branch.autosetuprebase
1527 color.branch.current
1538 color.diff.whitespace
1543 color.interactive.header
1544 color.interactive.help
1545 color.interactive.prompt
1550 color.status.changed
1552 color.status.nobranch
1553 color.status.untracked
1554 color.status.updated
1561 core.deltaBaseCacheLimit
1565 core.fsyncobjectfiles
1567 core.ignoreCygwinFSTricks
1569 core.logAllRefUpdates
1570 core.loosecompression
1572 core.packedGitWindowSize
1574 core.preferSymlinkRefs
1577 core.repositoryFormatVersion
1579 core.sharedRepository
1582 core.warnAmbiguousRefs
1585 diff.autorefreshindex
1591 diff.suppressBlankEmpty
1603 format.subjectprefix
1612 gc.reflogexpireunreachable
1616 gitcvs.commitmsgannotation
1617 gitcvs.dbTableNamePrefix
1628 gui.copyblamethreshold
1632 gui.matchtrackingbranch
1633 gui.newbranchtemplate
1634 gui.pruneduringfetch
1635 gui.spellingdictionary
1651 i18n.logOutputEncoding
1656 imap.preformattedHTML
1665 interactive.singlekey
1678 mergetool.keepBackup
1681 pack.deltaCacheLimit
1694 receive.denyCurrentBranch
1696 receive.denyNonFastForwards
1699 repack.usedeltabaseoffset
1702 sendemail.aliasesfile
1703 sendemail.aliasesfiletype
1707 sendemail.chainreplyto
1709 sendemail.envelopesender
1711 sendemail.signedoffbycc
1712 sendemail.smtpencryption
1714 sendemail.smtpserver
1715 sendemail.smtpserverport
1717 sendemail.suppresscc
1718 sendemail.suppressfrom
1723 status.relativePaths
1724 status.showUntrackedFiles
1726 transfer.unpackLimit
1738 local subcommands
="add rename rm show prune update set-head"
1739 local subcommand
="$(__git_find_subcommand "$subcommands")"
1740 if [ -z "$subcommand" ]; then
1741 __gitcomp
"$subcommands"
1745 case "$subcommand" in
1746 rename|
rm|show|prune
)
1747 __gitcomp
"$(__git_remotes)"
1750 local i c
='' IFS
=$
'\n'
1751 for i
in $
(git
--git-dir="$(__gitdir)" config
--list); do
1769 __git_has_doubledash
&& return
1771 local cur
="${COMP_WORDS[COMP_CWORD]}"
1774 __gitcomp
"--merge --mixed --hard --soft"
1778 __gitcomp
"$(__git_refs)"
1783 local cur
="${COMP_WORDS[COMP_CWORD]}"
1786 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
1790 __gitcomp
"$(__git_refs)"
1795 __git_has_doubledash
&& return
1797 local cur
="${COMP_WORDS[COMP_CWORD]}"
1800 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
1809 __git_has_doubledash
&& return
1811 local cur
="${COMP_WORDS[COMP_CWORD]}"
1815 $__git_log_common_options
1816 $__git_log_shortlog_options
1817 --numbered --summary
1822 __git_complete_revlist
1827 __git_has_doubledash
&& return
1829 local cur
="${COMP_WORDS[COMP_CWORD]}"
1832 __gitcomp
"$__git_log_pretty_formats
1833 " "" "${cur##--pretty=}"
1837 __gitcomp
"$__git_log_pretty_formats
1838 " "" "${cur##--format=}"
1842 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
1843 $__git_diff_common_options
1853 local cur
="${COMP_WORDS[COMP_CWORD]}"
1857 --all --remotes --topo-order --current --more=
1858 --list --independent --merge-base --no-name
1860 --sha1-name --sparse --topics --reflog
1865 __git_complete_revlist
1870 local subcommands
='save list show apply clear drop pop create branch'
1871 local subcommand
="$(__git_find_subcommand "$subcommands")"
1872 if [ -z "$subcommand" ]; then
1873 __gitcomp
"$subcommands"
1875 local cur
="${COMP_WORDS[COMP_CWORD]}"
1876 case "$subcommand,$cur" in
1878 __gitcomp
"--keep-index"
1883 show
,--*|drop
,--*|pop
,--*|branch
,--*)
1886 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
1887 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
1888 | sed -n -e 's/:.*//p')"
1899 __git_has_doubledash
&& return
1901 local subcommands
="add status init update summary foreach sync"
1902 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1903 local cur
="${COMP_WORDS[COMP_CWORD]}"
1906 __gitcomp
"--quiet --cached"
1909 __gitcomp
"$subcommands"
1919 init fetch clone rebase dcommit log find-rev
1920 set-tree commit-diff info create-ignore propget
1921 proplist show-ignore show-externals branch tag blame
1924 local subcommand
="$(__git_find_subcommand "$subcommands")"
1925 if [ -z "$subcommand" ]; then
1926 __gitcomp
"$subcommands"
1928 local remote_opts
="--username= --config-dir= --no-auth-cache"
1930 --follow-parent --authors-file= --repack=
1931 --no-metadata --use-svm-props --use-svnsync-props
1932 --log-window-size= --no-checkout --quiet
1933 --repack-flags --use-log-author --localtime
1934 --ignore-paths= $remote_opts
1937 --template= --shared= --trunk= --tags=
1938 --branches= --stdlayout --minimize-url
1939 --no-metadata --use-svm-props --use-svnsync-props
1940 --rewrite-root= --prefix= --use-log-author
1941 --add-author-from $remote_opts
1944 --edit --rmdir --find-copies-harder --copy-similarity=
1947 local cur
="${COMP_WORDS[COMP_CWORD]}"
1948 case "$subcommand,$cur" in
1950 __gitcomp
"--revision= --fetch-all $fc_opts"
1953 __gitcomp
"--revision= $fc_opts $init_opts"
1956 __gitcomp
"$init_opts"
1960 --merge --strategy= --verbose --dry-run
1961 --fetch-all --no-rebase --commit-url
1962 --revision $cmt_opts $fc_opts
1966 __gitcomp
"--stdin $cmt_opts $fc_opts"
1968 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
1970 __gitcomp
"--revision="
1974 --limit= --revision= --verbose --incremental
1975 --oneline --show-commit --non-recursive
1976 --authors-file= --color
1981 --merge --verbose --strategy= --local
1982 --fetch-all --dry-run $fc_opts
1986 __gitcomp
"--message= --file= --revision= $cmt_opts"
1992 __gitcomp
"--dry-run --message --tag"
1995 __gitcomp
"--dry-run --message"
1998 __gitcomp
"--git-format"
2002 --config-dir= --ignore-paths= --minimize
2003 --no-auth-cache --username=
2016 while [ $c -lt $COMP_CWORD ]; do
2017 i
="${COMP_WORDS[c]}"
2020 __gitcomp
"$(__git_tags)"
2030 case "${COMP_WORDS[COMP_CWORD-1]}" in
2036 __gitcomp
"$(__git_tags)"
2042 __gitcomp
"$(__git_refs)"
2049 local i c
=1 command __git_dir
2051 while [ $c -lt $COMP_CWORD ]; do
2052 i
="${COMP_WORDS[c]}"
2054 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2055 --bare) __git_dir
="." ;;
2056 --version|
-p|
--paginate) ;;
2057 --help) command="help"; break ;;
2058 *) command="$i"; break ;;
2063 if [ -z "$command" ]; then
2064 case "${COMP_WORDS[COMP_CWORD]}" in
2077 *) __gitcomp
"$(__git_porcelain_commands) $(__git_aliases)" ;;
2082 local expansion
=$
(__git_aliased_command
"$command")
2083 [ "$expansion" ] && command="$expansion"
2088 apply
) _git_apply
;;
2089 archive
) _git_archive
;;
2090 bisect
) _git_bisect
;;
2091 bundle
) _git_bundle
;;
2092 branch
) _git_branch
;;
2093 checkout
) _git_checkout
;;
2094 cherry
) _git_cherry
;;
2095 cherry-pick
) _git_cherry_pick
;;
2096 clean
) _git_clean
;;
2097 clone
) _git_clone
;;
2098 commit
) _git_commit
;;
2099 config
) _git_config
;;
2100 describe
) _git_describe
;;
2102 difftool
) _git_difftool
;;
2103 fetch
) _git_fetch
;;
2104 format-patch
) _git_format_patch
;;
2111 ls-files
) _git_ls_files
;;
2112 ls-remote
) _git_ls_remote
;;
2113 ls-tree
) _git_ls_tree
;;
2115 mergetool
) _git_mergetool
;;
2116 merge-base
) _git_merge_base
;;
2118 name-rev
) _git_name_rev
;;
2121 rebase
) _git_rebase
;;
2122 remote
) _git_remote
;;
2123 reset) _git_reset
;;
2124 revert
) _git_revert
;;
2126 send-email
) _git_send_email
;;
2127 shortlog
) _git_shortlog
;;
2129 show-branch
) _git_show_branch
;;
2130 stash
) _git_stash
;;
2132 submodule
) _git_submodule
;;
2135 whatchanged
) _git_log
;;
2142 __git_has_doubledash
&& return
2144 local cur
="${COMP_WORDS[COMP_CWORD]}"
2145 local g
="$(__gitdir)"
2147 if [ -f "$g/MERGE_HEAD" ]; then
2153 $__git_log_common_options
2154 $__git_log_gitk_options
2160 __git_complete_revlist
2163 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2164 || complete
-o default
-o nospace
-F _git git
2165 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2166 || complete
-o default
-o nospace
-F _gitk gitk
2168 # The following are necessary only for Cygwin, and only are needed
2169 # when the user has tab-completed the executable name and consequently
2170 # included the '.exe' suffix.
2172 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2173 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2174 || complete
-o default
-o nospace
-F _git git.exe