3 # bash completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 # 2) Added the following line to your .bashrc:
22 # source ~/.git-completion.sh
24 # 3) Consider changing your PS1 to also show the current branch:
25 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
27 # The argument to __git_ps1 will be displayed only if you
28 # are currently in a git repository. The %s token will be
29 # the name of the current branch.
31 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
32 # value, unstaged (*) and staged (+) changes will be shown next
33 # to the branch name. You can configure this per-repository
34 # with the bash.showDirtyState variable, which defaults to true
35 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
37 # You can also see if currently something is stashed, by setting
38 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
39 # then a '$' will be shown next to the branch name.
41 # If you would like to see if there're untracked files, then you can
42 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
43 # untracked files, then a '%' will be shown next to the branch name.
47 # *) Read Documentation/SubmittingPatches
48 # *) Send all patches to the current maintainer:
50 # "Shawn O. Pearce" <spearce@spearce.org>
52 # *) Always CC the Git mailing list:
57 case "$COMP_WORDBREAKS" in
59 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
62 # __gitdir accepts 0 or 1 arguments (i.e., location)
63 # returns location of .git repo
66 if [ -z "${1-}" ]; then
67 if [ -n "${__git_dir-}" ]; then
69 elif [ -d .git
]; then
72 git rev-parse
--git-dir 2>/dev
/null
74 elif [ -d "$1/.git" ]; then
81 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
82 # returns text to add to bash PS1 prompt (includes branch name)
89 if [ -f "$g/rebase-merge/interactive" ]; then
91 b
="$(cat "$g/rebase-merge
/head-name
")"
92 elif [ -d "$g/rebase-merge" ]; then
94 b
="$(cat "$g/rebase-merge
/head-name
")"
96 if [ -d "$g/rebase-apply" ]; then
97 if [ -f "$g/rebase-apply/rebasing" ]; then
99 elif [ -f "$g/rebase-apply/applying" ]; then
104 elif [ -f "$g/MERGE_HEAD" ]; then
106 elif [ -f "$g/BISECT_LOG" ]; then
110 b
="$(git symbolic-ref HEAD 2>/dev/null)" ||
{
113 case "${GIT_PS1_DESCRIBE_STYLE-}" in
115 git describe --contains HEAD ;;
117 git describe --contains --all HEAD ;;
121 git describe --exact-match HEAD ;;
122 esac 2>/dev/null)" ||
124 b
="$(cut -c1-7 "$g/HEAD
" 2>/dev/null)..." ||
136 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
137 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
142 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
143 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
144 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
145 git
diff --no-ext-diff --quiet --exit-code || w
="*"
146 if git rev-parse
--quiet --verify HEAD
>/dev
/null
; then
147 git diff-index
--cached --quiet HEAD
-- || i
="+"
153 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
154 git rev-parse
--verify refs
/stash
>/dev
/null
2>&1 && s
="$"
157 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
158 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
165 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r"
169 # __gitcomp_1 requires 2 arguments
172 local c IFS
=' '$
'\t'$
'\n'
175 --*=*) printf %s$
'\n' "$c$2" ;;
176 *.
) printf %s$
'\n' "$c$2" ;;
177 *) printf %s$
'\n' "$c$2 " ;;
182 # __gitcomp accepts 1, 2, 3, or 4 arguments
183 # generates completion reply with compgen
186 local cur
="${COMP_WORDS[COMP_CWORD]}"
187 if [ $# -gt 2 ]; then
196 COMPREPLY
=($
(compgen
-P "${2-}" \
197 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
203 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
206 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
207 if [ -d "$dir" ]; then
208 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
212 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
213 case "$is_hash,$i" in
216 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
217 n
,*) is_hash
=y
; echo "$i" ;;
222 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
225 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
226 if [ -d "$dir" ]; then
227 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
231 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
232 case "$is_hash,$i" in
235 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
236 n
,*) is_hash
=y
; echo "$i" ;;
241 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
244 local i is_hash
=y dir
="$(__gitdir "${1-}")"
245 local cur
="${COMP_WORDS[COMP_CWORD]}" format refs
246 if [ -d "$dir" ]; then
253 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
254 if [ -e "$dir/$i" ]; then echo $i; 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 remote-
*) : transport
;;
574 repo-config
) : deprecated
;;
576 rev-list
) : plumbing
;;
577 rev-parse
) : plumbing
;;
578 runstatus
) : plumbing
;;
579 sh-setup
) : internal
;;
581 show-ref
) : plumbing
;;
582 send-pack
) : plumbing
;;
583 show-index
) : plumbing
;;
585 stripspace
) : plumbing
;;
586 symbolic-ref
) : plumbing
;;
587 tar-tree
) : deprecated
;;
588 unpack-file
) : plumbing
;;
589 unpack-objects
) : plumbing
;;
590 update-index
) : plumbing
;;
591 update-ref
) : plumbing
;;
592 update-server-info
) : daemon
;;
593 upload-archive
) : plumbing
;;
594 upload-pack
) : plumbing
;;
595 write-tree
) : plumbing
;;
597 verify-pack
) : infrequent
;;
598 verify-tag
) : plumbing
;;
604 __git_porcelain_commands
=
605 __git_compute_porcelain_commands
()
607 __git_compute_all_commands
608 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
614 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
624 # __git_aliased_command requires 1 argument
625 __git_aliased_command
()
627 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
628 config
--get "alias.$1")
629 for word
in $cmdline; do
635 \
!*) : shell
command alias ;;
637 *=*) : setting env
;;
646 # __git_find_on_cmdline requires 1 argument
647 __git_find_on_cmdline
()
649 local word subcommand c
=1
651 while [ $c -lt $COMP_CWORD ]; do
652 word
="${COMP_WORDS[c]}"
653 for subcommand
in $1; do
654 if [ "$subcommand" = "$word" ]; then
663 __git_has_doubledash
()
666 while [ $c -lt $COMP_CWORD ]; do
667 if [ "--" = "${COMP_WORDS[c]}" ]; then
675 __git_whitespacelist
="nowarn warn error error-all fix"
679 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
680 if [ -d "$dir"/rebase-apply
]; then
681 __gitcomp
"--skip --continue --resolved --abort"
686 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
691 --3way --committer-date-is-author-date --ignore-date
692 --ignore-whitespace --ignore-space-change
693 --interactive --keep --no-utf8 --signoff --utf8
694 --whitespace= --scissors
703 local cur
="${COMP_WORDS[COMP_CWORD]}"
706 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
711 --stat --numstat --summary --check --index
712 --cached --index-info --reverse --reject --unidiff-zero
713 --apply --no-add --exclude=
714 --ignore-whitespace --ignore-space-change
715 --whitespace= --inaccurate-eof --verbose
724 __git_has_doubledash
&& return
726 local cur
="${COMP_WORDS[COMP_CWORD]}"
730 --interactive --refresh --patch --update --dry-run
731 --ignore-errors --intent-to-add
740 local cur
="${COMP_WORDS[COMP_CWORD]}"
743 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
747 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
752 --format= --list --verbose
753 --prefix= --remote= --exec=
763 __git_has_doubledash
&& return
765 local subcommands
="start bad good skip reset visualize replay log run"
766 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
767 if [ -z "$subcommand" ]; then
768 __gitcomp
"$subcommands"
772 case "$subcommand" in
774 __gitcomp
"$(__git_refs)"
784 local i c
=1 only_local_ref
="n" has_r
="n"
786 while [ $c -lt $COMP_CWORD ]; do
789 -d|
-m) only_local_ref
="y" ;;
795 case "${COMP_WORDS[COMP_CWORD]}" in
798 --color --no-color --verbose --abbrev= --no-abbrev
799 --track --no-track --contains --merged --no-merged
804 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
805 __gitcomp
"$(__git_heads)"
807 __gitcomp
"$(__git_refs)"
815 local cmd
="${COMP_WORDS[2]}"
816 case "$COMP_CWORD" in
818 __gitcomp
"create list-heads verify unbundle"
826 __git_complete_revlist
835 __git_has_doubledash
&& return
837 local cur
="${COMP_WORDS[COMP_CWORD]}"
840 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
844 --quiet --ours --theirs --track --no-track --merge
845 --conflict= --orphan --patch
849 __gitcomp
"$(__git_refs)"
856 __gitcomp
"$(__git_refs)"
861 local cur
="${COMP_WORDS[COMP_CWORD]}"
864 __gitcomp
"--edit --no-commit"
867 __gitcomp
"$(__git_refs)"
874 __git_has_doubledash
&& return
876 local cur
="${COMP_WORDS[COMP_CWORD]}"
879 __gitcomp
"--dry-run --quiet"
888 local cur
="${COMP_WORDS[COMP_CWORD]}"
913 __git_has_doubledash
&& return
915 local cur
="${COMP_WORDS[COMP_CWORD]}"
918 __gitcomp
"default strip verbatim whitespace
919 " "" "${cur##--cleanup=}"
923 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
927 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
931 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
936 --all --author= --signoff --verify --no-verify
937 --edit --amend --include --only --interactive
938 --dry-run --reuse-message= --reedit-message=
939 --reset-author --file= --message= --template=
940 --cleanup= --untracked-files --untracked-files=
950 local cur
="${COMP_WORDS[COMP_CWORD]}"
954 --all --tags --contains --abbrev= --candidates=
955 --exact-match --debug --long --match --always
959 __gitcomp
"$(__git_refs)"
962 __git_diff_common_options
="--stat --numstat --shortstat --summary
963 --patch-with-stat --name-only --name-status --color
964 --no-color --color-words --no-renames --check
965 --full-index --binary --abbrev --diff-filter=
967 --text --ignore-space-at-eol --ignore-space-change
968 --ignore-all-space --exit-code --quiet --ext-diff
970 --no-prefix --src-prefix= --dst-prefix=
971 --inter-hunk-context=
974 --dirstat --dirstat= --dirstat-by-file
975 --dirstat-by-file= --cumulative
980 __git_has_doubledash
&& return
982 local cur
="${COMP_WORDS[COMP_CWORD]}"
985 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
986 --base --ours --theirs
987 $__git_diff_common_options
995 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
996 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1001 __git_has_doubledash
&& return
1003 local cur
="${COMP_WORDS[COMP_CWORD]}"
1006 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1010 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1011 --base --ours --theirs
1012 --no-renames --diff-filter= --find-copies-harder
1013 --relative --ignore-submodules
1021 __git_fetch_options
="
1022 --quiet --verbose --append --upload-pack --force --keep --depth=
1023 --tags --no-tags --all --prune --dry-run
1028 local cur
="${COMP_WORDS[COMP_CWORD]}"
1031 __gitcomp
"$__git_fetch_options"
1035 __git_complete_remote_or_refspec
1038 _git_format_patch
()
1040 local cur
="${COMP_WORDS[COMP_CWORD]}"
1045 " "" "${cur##--thread=}"
1050 --stdout --attach --no-attach --thread --thread=
1052 --numbered --start-number
1055 --signoff --signature --no-signature
1056 --in-reply-to= --cc=
1057 --full-index --binary
1060 --no-prefix --src-prefix= --dst-prefix=
1061 --inline --suffix= --ignore-if-in-upstream
1067 __git_complete_revlist
1072 local cur
="${COMP_WORDS[COMP_CWORD]}"
1076 --tags --root --unreachable --cache --no-reflogs --full
1077 --strict --verbose --lost-found
1087 local cur
="${COMP_WORDS[COMP_CWORD]}"
1090 __gitcomp
"--prune --aggressive"
1104 __git_has_doubledash
&& return
1106 local cur
="${COMP_WORDS[COMP_CWORD]}"
1111 --text --ignore-case --word-regexp --invert-match
1113 --extended-regexp --basic-regexp --fixed-strings
1114 --files-with-matches --name-only
1115 --files-without-match
1118 --and --or --not --all-match
1124 __gitcomp
"$(__git_refs)"
1129 local cur
="${COMP_WORDS[COMP_CWORD]}"
1132 __gitcomp
"--all --info --man --web"
1136 __git_compute_all_commands
1137 __gitcomp
"$__git_all_commands
1138 attributes cli core-tutorial cvs-migration
1139 diffcore gitk glossary hooks ignore modules
1140 repository-layout tutorial tutorial-2
1147 local cur
="${COMP_WORDS[COMP_CWORD]}"
1151 false true umask group all world everybody
1152 " "" "${cur##--shared=}"
1156 __gitcomp
"--quiet --bare --template= --shared --shared="
1165 __git_has_doubledash
&& return
1167 local cur
="${COMP_WORDS[COMP_CWORD]}"
1170 __gitcomp
"--cached --deleted --modified --others --ignored
1171 --stage --directory --no-empty-directory --unmerged
1172 --killed --exclude= --exclude-from=
1173 --exclude-per-directory= --exclude-standard
1174 --error-unmatch --with-tree= --full-name
1175 --abbrev --ignored --exclude-per-directory
1185 __gitcomp
"$(__git_remotes)"
1193 # Options that go well for log, shortlog and gitk
1194 __git_log_common_options
="
1196 --branches --tags --remotes
1197 --first-parent --merges --no-merges
1199 --max-age= --since= --after=
1200 --min-age= --until= --before=
1202 # Options that go well for log and gitk (not shortlog)
1203 __git_log_gitk_options
="
1204 --dense --sparse --full-history
1205 --simplify-merges --simplify-by-decoration
1208 # Options that go well for log and shortlog (not gitk)
1209 __git_log_shortlog_options
="
1210 --author= --committer= --grep=
1214 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1215 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1219 __git_has_doubledash
&& return
1221 local cur
="${COMP_WORDS[COMP_CWORD]}"
1222 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1224 if [ -f "$g/MERGE_HEAD" ]; then
1229 __gitcomp
"$__git_log_pretty_formats
1230 " "" "${cur##--pretty=}"
1234 __gitcomp
"$__git_log_pretty_formats
1235 " "" "${cur##--format=}"
1239 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1243 __gitcomp
"long short" "" "${cur##--decorate=}"
1248 $__git_log_common_options
1249 $__git_log_shortlog_options
1250 $__git_log_gitk_options
1251 --root --topo-order --date-order --reverse
1252 --follow --full-diff
1253 --abbrev-commit --abbrev=
1254 --relative-date --date=
1255 --pretty= --format= --oneline
1258 --decorate --decorate=
1260 --parents --children
1262 $__git_diff_common_options
1263 --pickaxe-all --pickaxe-regex
1268 __git_complete_revlist
1271 __git_merge_options
="
1272 --no-commit --no-stat --log --no-log --squash --strategy
1273 --commit --stat --no-squash --ff --no-ff --ff-only
1278 __git_complete_strategy
&& return
1280 local cur
="${COMP_WORDS[COMP_CWORD]}"
1283 __gitcomp
"$__git_merge_options"
1286 __gitcomp
"$(__git_refs)"
1291 local cur
="${COMP_WORDS[COMP_CWORD]}"
1294 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1307 __gitcomp
"$(__git_refs)"
1312 local cur
="${COMP_WORDS[COMP_CWORD]}"
1315 __gitcomp
"--dry-run"
1324 __gitcomp
"--tags --all --stdin"
1329 local subcommands
="edit show"
1330 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1331 __gitcomp
"$subcommands"
1335 case "${COMP_WORDS[COMP_CWORD-1]}" in
1340 __gitcomp
"$(__git_refs)"
1347 __git_complete_strategy
&& return
1349 local cur
="${COMP_WORDS[COMP_CWORD]}"
1353 --rebase --no-rebase
1354 $__git_merge_options
1355 $__git_fetch_options
1360 __git_complete_remote_or_refspec
1365 local cur
="${COMP_WORDS[COMP_CWORD]}"
1366 case "${COMP_WORDS[COMP_CWORD-1]}" in
1368 __gitcomp
"$(__git_remotes)"
1373 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1378 --all --mirror --tags --dry-run --force --verbose
1379 --receive-pack= --repo=
1384 __git_complete_remote_or_refspec
1389 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
1390 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1391 __gitcomp
"--continue --skip --abort"
1394 __git_complete_strategy
&& return
1397 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1402 --onto --merge --strategy --interactive
1403 --preserve-merges --stat --no-stat
1404 --committer-date-is-author-date --ignore-date
1405 --ignore-whitespace --whitespace=
1411 __gitcomp
"$(__git_refs)"
1414 __git_send_email_confirm_options
="always never auto cc compose"
1415 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1419 local cur
="${COMP_WORDS[COMP_CWORD]}"
1423 $__git_send_email_confirm_options
1424 " "" "${cur##--confirm=}"
1429 $__git_send_email_suppresscc_options
1430 " "" "${cur##--suppress-cc=}"
1434 --smtp-encryption=*)
1435 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1439 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1440 --compose --confirm= --dry-run --envelope-sender
1442 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1443 --no-suppress-from --no-thread --quiet
1444 --signed-off-by-cc --smtp-pass --smtp-server
1445 --smtp-server-port --smtp-encryption= --smtp-user
1446 --subject --suppress-cc= --suppress-from --thread --to
1447 --validate --no-validate"
1459 __git_config_get_set_variables
()
1461 local prevword word config_file
= c
=$COMP_CWORD
1462 while [ $c -gt 1 ]; do
1463 word
="${COMP_WORDS[c]}"
1465 --global|
--system|
--file=*)
1470 config_file
="$word $prevword"
1478 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1491 local cur
="${COMP_WORDS[COMP_CWORD]}"
1492 local prv
="${COMP_WORDS[COMP_CWORD-1]}"
1495 __gitcomp
"$(__git_remotes)"
1499 __gitcomp
"$(__git_refs)"
1503 local remote
="${prv#remote.}"
1504 remote
="${remote%.fetch}"
1505 __gitcomp
"$(__git_refs_remotes "$remote")"
1509 local remote
="${prv#remote.}"
1510 remote
="${remote%.push}"
1511 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1512 for-each-ref --format='%(refname):%(refname)' \
1516 pull.twohead|pull.octopus
)
1517 __git_compute_merge_strategies
1518 __gitcomp
"$__git_merge_strategies"
1521 color.branch|color.
diff|color.interactive|\
1522 color.showbranch|color.status|color.ui
)
1523 __gitcomp
"always never auto"
1527 __gitcomp
"false true"
1532 normal black red green yellow blue magenta cyan white
1533 bold dim ul blink reverse
1538 __gitcomp
"man info web html"
1542 __gitcomp
"$__git_log_date_formats"
1545 sendemail.aliasesfiletype
)
1546 __gitcomp
"mutt mailrc pine elm gnus"
1550 __gitcomp
"$__git_send_email_confirm_options"
1553 sendemail.suppresscc
)
1554 __gitcomp
"$__git_send_email_suppresscc_options"
1557 --get|
--get-all|
--unset|
--unset-all)
1558 __gitcomp
"$(__git_config_get_set_variables)"
1569 --global --system --file=
1570 --list --replace-all
1571 --get --get-all --get-regexp
1572 --add --unset --unset-all
1573 --remove-section --rename-section
1578 local pfx
="${cur%.*}."
1580 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur"
1584 local pfx
="${cur%.*}."
1586 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1590 local pfx
="${cur%.*}."
1593 argprompt cmd confirm needsfile noconsole norescan
1594 prompt revprompt revunmerged title
1599 local pfx
="${cur%.*}."
1601 __gitcomp
"cmd path" "$pfx" "$cur"
1605 local pfx
="${cur%.*}."
1607 __gitcomp
"cmd path" "$pfx" "$cur"
1611 local pfx
="${cur%.*}."
1613 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1617 local pfx
="${cur%.*}."
1619 __git_compute_all_commands
1620 __gitcomp
"$__git_all_commands" "$pfx" "$cur"
1624 local pfx
="${cur%.*}."
1627 url proxy fetch push mirror skipDefaultUpdate
1628 receivepack uploadpack tagopt pushurl
1633 local pfx
="${cur%.*}."
1635 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1639 local pfx
="${cur%.*}."
1641 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur"
1648 apply.ignorewhitespace
1650 branch.autosetupmerge
1651 branch.autosetuprebase
1654 color.branch.current
1665 color.diff.whitespace
1670 color.interactive.header
1671 color.interactive.help
1672 color.interactive.prompt
1677 color.status.changed
1679 color.status.nobranch
1680 color.status.untracked
1681 color.status.updated
1688 core.deltaBaseCacheLimit
1692 core.fsyncobjectfiles
1694 core.ignoreCygwinFSTricks
1696 core.logAllRefUpdates
1697 core.loosecompression
1699 core.packedGitWindowSize
1701 core.preferSymlinkRefs
1704 core.repositoryFormatVersion
1706 core.sharedRepository
1709 core.warnAmbiguousRefs
1712 diff.autorefreshindex
1718 diff.suppressBlankEmpty
1731 format.subjectprefix
1740 gc.reflogexpireunreachable
1744 gitcvs.commitmsgannotation
1745 gitcvs.dbTableNamePrefix
1756 gui.copyblamethreshold
1760 gui.matchtrackingbranch
1761 gui.newbranchtemplate
1762 gui.pruneduringfetch
1763 gui.spellingdictionary
1779 i18n.logOutputEncoding
1784 imap.preformattedHTML
1793 interactive.singlekey
1806 mergetool.keepBackup
1809 pack.deltaCacheLimit
1822 receive.denyCurrentBranch
1824 receive.denyNonFastForwards
1827 repack.usedeltabaseoffset
1830 sendemail.aliasesfile
1831 sendemail.aliasesfiletype
1835 sendemail.chainreplyto
1837 sendemail.envelopesender
1839 sendemail.signedoffbycc
1840 sendemail.smtpencryption
1842 sendemail.smtpserver
1843 sendemail.smtpserverport
1845 sendemail.suppresscc
1846 sendemail.suppressfrom
1851 status.relativePaths
1852 status.showUntrackedFiles
1854 transfer.unpackLimit
1866 local subcommands
="add rename rm show prune update set-head"
1867 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1868 if [ -z "$subcommand" ]; then
1869 __gitcomp
"$subcommands"
1873 case "$subcommand" in
1874 rename|
rm|show|prune
)
1875 __gitcomp
"$(__git_remotes)"
1878 local i c
='' IFS
=$
'\n'
1879 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
1893 __gitcomp
"$(__git_refs)"
1898 __git_has_doubledash
&& return
1900 local cur
="${COMP_WORDS[COMP_CWORD]}"
1903 __gitcomp
"--merge --mixed --hard --soft --patch"
1907 __gitcomp
"$(__git_refs)"
1912 local cur
="${COMP_WORDS[COMP_CWORD]}"
1915 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
1919 __gitcomp
"$(__git_refs)"
1924 __git_has_doubledash
&& return
1926 local cur
="${COMP_WORDS[COMP_CWORD]}"
1929 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
1938 __git_has_doubledash
&& return
1940 local cur
="${COMP_WORDS[COMP_CWORD]}"
1944 $__git_log_common_options
1945 $__git_log_shortlog_options
1946 --numbered --summary
1951 __git_complete_revlist
1956 __git_has_doubledash
&& return
1958 local cur
="${COMP_WORDS[COMP_CWORD]}"
1961 __gitcomp
"$__git_log_pretty_formats
1962 " "" "${cur##--pretty=}"
1966 __gitcomp
"$__git_log_pretty_formats
1967 " "" "${cur##--format=}"
1971 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
1972 $__git_diff_common_options
1982 local cur
="${COMP_WORDS[COMP_CWORD]}"
1986 --all --remotes --topo-order --current --more=
1987 --list --independent --merge-base --no-name
1989 --sha1-name --sparse --topics --reflog
1994 __git_complete_revlist
1999 local cur
="${COMP_WORDS[COMP_CWORD]}"
2000 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2001 local subcommands
='save list show apply clear drop pop create branch'
2002 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2003 if [ -z "$subcommand" ]; then
2006 __gitcomp
"$save_opts"
2009 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2010 __gitcomp
"$subcommands"
2017 case "$subcommand,$cur" in
2019 __gitcomp
"$save_opts"
2022 __gitcomp
"--index --quiet"
2024 show
,--*|drop
,--*|branch
,--*)
2027 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2028 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
2029 | sed -n -e 's/:.*//p')"
2040 __git_has_doubledash
&& return
2042 local subcommands
="add status init update summary foreach sync"
2043 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2044 local cur
="${COMP_WORDS[COMP_CWORD]}"
2047 __gitcomp
"--quiet --cached"
2050 __gitcomp
"$subcommands"
2060 init fetch clone rebase dcommit log find-rev
2061 set-tree commit-diff info create-ignore propget
2062 proplist show-ignore show-externals branch tag blame
2063 migrate mkdirs reset gc
2065 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2066 if [ -z "$subcommand" ]; then
2067 __gitcomp
"$subcommands"
2069 local remote_opts
="--username= --config-dir= --no-auth-cache"
2071 --follow-parent --authors-file= --repack=
2072 --no-metadata --use-svm-props --use-svnsync-props
2073 --log-window-size= --no-checkout --quiet
2074 --repack-flags --use-log-author --localtime
2075 --ignore-paths= $remote_opts
2078 --template= --shared= --trunk= --tags=
2079 --branches= --stdlayout --minimize-url
2080 --no-metadata --use-svm-props --use-svnsync-props
2081 --rewrite-root= --prefix= --use-log-author
2082 --add-author-from $remote_opts
2085 --edit --rmdir --find-copies-harder --copy-similarity=
2088 local cur
="${COMP_WORDS[COMP_CWORD]}"
2089 case "$subcommand,$cur" in
2091 __gitcomp
"--revision= --fetch-all $fc_opts"
2094 __gitcomp
"--revision= $fc_opts $init_opts"
2097 __gitcomp
"$init_opts"
2101 --merge --strategy= --verbose --dry-run
2102 --fetch-all --no-rebase --commit-url
2103 --revision $cmt_opts $fc_opts
2107 __gitcomp
"--stdin $cmt_opts $fc_opts"
2109 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2110 show-externals
,--*|mkdirs
,--*)
2111 __gitcomp
"--revision="
2115 --limit= --revision= --verbose --incremental
2116 --oneline --show-commit --non-recursive
2117 --authors-file= --color
2122 --merge --verbose --strategy= --local
2123 --fetch-all --dry-run $fc_opts
2127 __gitcomp
"--message= --file= --revision= $cmt_opts"
2133 __gitcomp
"--dry-run --message --tag"
2136 __gitcomp
"--dry-run --message"
2139 __gitcomp
"--git-format"
2143 --config-dir= --ignore-paths= --minimize
2144 --no-auth-cache --username=
2148 __gitcomp
"--revision= --parent"
2160 while [ $c -lt $COMP_CWORD ]; do
2161 i
="${COMP_WORDS[c]}"
2164 __gitcomp
"$(__git_tags)"
2174 case "${COMP_WORDS[COMP_CWORD-1]}" in
2180 __gitcomp
"$(__git_tags)"
2186 __gitcomp
"$(__git_refs)"
2198 local i c
=1 command __git_dir
2200 while [ $c -lt $COMP_CWORD ]; do
2201 i
="${COMP_WORDS[c]}"
2203 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2204 --bare) __git_dir
="." ;;
2205 --version|
-p|
--paginate) ;;
2206 --help) command="help"; break ;;
2207 *) command="$i"; break ;;
2212 if [ -z "$command" ]; then
2213 case "${COMP_WORDS[COMP_CWORD]}" in
2226 *) __git_compute_porcelain_commands
2227 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2232 local completion_func
="_git_${command//-/_}"
2233 declare -F $completion_func >/dev
/null
&& $completion_func && return
2235 local expansion
=$
(__git_aliased_command
"$command")
2236 if [ -n "$expansion" ]; then
2237 completion_func
="_git_${expansion//-/_}"
2238 declare -F $completion_func >/dev
/null
&& $completion_func
2244 __git_has_doubledash
&& return
2246 local cur
="${COMP_WORDS[COMP_CWORD]}"
2247 local g
="$(__gitdir)"
2249 if [ -f "$g/MERGE_HEAD" ]; then
2255 $__git_log_common_options
2256 $__git_log_gitk_options
2262 __git_complete_revlist
2265 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2266 || complete
-o default
-o nospace
-F _git git
2267 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2268 || complete
-o default
-o nospace
-F _gitk gitk
2270 # The following are necessary only for Cygwin, and only are needed
2271 # when the user has tab-completed the executable name and consequently
2272 # included the '.exe' suffix.
2274 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2275 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2276 || complete
-o default
-o nospace
-F _git git.exe