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 # Or, add the following lines to your .zshrc:
25 # autoload bashcompinit
27 # source ~/.git-completion.sh
29 # 3) Consider changing your PS1 to also show the current branch:
30 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
32 # The argument to __git_ps1 will be displayed only if you
33 # are currently in a git repository. The %s token will be
34 # the name of the current branch.
36 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
37 # value, unstaged (*) and staged (+) changes will be shown next
38 # to the branch name. You can configure this per-repository
39 # with the bash.showDirtyState variable, which defaults to true
40 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
42 # You can also see if currently something is stashed, by setting
43 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
44 # then a '$' will be shown next to the branch name.
46 # If you would like to see if there're untracked files, then you can
47 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
48 # untracked files, then a '%' will be shown next to the branch name.
50 # If you would like to see the difference between HEAD and its
51 # upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates
52 # you are behind, ">" indicates you are ahead, and "<>"
53 # indicates you have diverged. You can further control
54 # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
56 # verbose show number of commits ahead/behind (+/-) upstream
57 # legacy don't use the '--count' option available in recent
58 # versions of git-rev-list
59 # git always compare HEAD to @{upstream}
60 # svn always compare HEAD to your SVN upstream
61 # By default, __git_ps1 will compare HEAD to your SVN upstream
62 # if it can find one, or @{upstream} otherwise. Once you have
63 # set GIT_PS1_SHOWUPSTREAM, you can override it on a
64 # per-repository basis by setting the bash.showUpstream config
70 # *) Read Documentation/SubmittingPatches
71 # *) Send all patches to the current maintainer:
73 # "Shawn O. Pearce" <spearce@spearce.org>
75 # *) Always CC the Git mailing list:
80 case "$COMP_WORDBREAKS" in
82 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
85 # __gitdir accepts 0 or 1 arguments (i.e., location)
86 # returns location of .git repo
89 if [ -z "${1-}" ]; then
90 if [ -n "${__git_dir-}" ]; then
92 elif [ -d .git
]; then
95 git rev-parse
--git-dir 2>/dev
/null
97 elif [ -d "$1/.git" ]; then
104 # stores the divergence from upstream in $p
105 # used by GIT_PS1_SHOWUPSTREAM
106 __git_ps1_show_upstream
()
109 local svn_remote
=() svn_url_pattern count n
110 local upstream
=git legacy
="" verbose
=""
112 # get some config options from git-config
113 while read key value
; do
116 GIT_PS1_SHOWUPSTREAM
="$value"
117 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
123 svn_remote
[ $
((${#svn_remote[@]} + 1)) ]="$value"
124 svn_url_pattern
+="\\|$value"
125 upstream
=svn
+git
# default upstream is SVN if available, else git
128 done < <(git config
-z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev
/null |
tr '\0\n' '\n ')
130 # parse configuration values
131 for option
in ${GIT_PS1_SHOWUPSTREAM}; do
133 git|svn
) upstream
="$option" ;;
134 verbose
) verbose
=1 ;;
141 git
) upstream
="@{upstream}" ;;
143 # get the upstream from the "git-svn-id: ..." in a commit message
144 # (git-svn uses essentially the same procedure internally)
145 local svn_upstream
=($
(git log
--first-parent -1 \
146 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev
/null
))
147 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
148 svn_upstream
=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
149 svn_upstream
=${svn_upstream%@*}
150 local n_stop
="${#svn_remote[@]}"
151 for ((n
=1; n
<= n_stop
; ++n
)); do
152 svn_upstream
=${svn_upstream#${svn_remote[$n]}}
155 if [[ -z "$svn_upstream" ]]; then
156 # default branch name for checkouts with no layout:
157 upstream
=${GIT_SVN_ID:-git-svn}
159 upstream
=${svn_upstream#/}
161 elif [[ "svn+git" = "$upstream" ]]; then
162 upstream
="@{upstream}"
167 # Find how many commits we are ahead/behind our upstream
168 if [[ -z "$legacy" ]]; then
169 count
="$(git rev-list --count --left-right \
170 "$upstream"...HEAD 2>/dev/null)"
172 # produce equivalent output to --count for older versions of git
174 if commits
="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
176 local commit behind
=0 ahead
=0
177 for commit
in $commits
186 count
="$behind $ahead"
192 # calculate the result
193 if [[ -z "$verbose" ]]; then
197 "0 0") # equal to upstream
199 "0 "*) # ahead of upstream
201 *" 0") # behind upstream
203 *) # diverged from upstream
210 "0 0") # equal to upstream
212 "0 "*) # ahead of upstream
213 p
=" u+${count#0 }" ;;
214 *" 0") # behind upstream
215 p
=" u-${count% 0}" ;;
216 *) # diverged from upstream
217 p
=" u+${count#* }-${count% *}" ;;
224 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
225 # returns text to add to bash PS1 prompt (includes branch name)
228 local g
="$(__gitdir)"
232 if [ -f "$g/rebase-merge/interactive" ]; then
234 b
="$(cat "$g/rebase-merge
/head-name
")"
235 elif [ -d "$g/rebase-merge" ]; then
237 b
="$(cat "$g/rebase-merge
/head-name
")"
239 if [ -d "$g/rebase-apply" ]; then
240 if [ -f "$g/rebase-apply/rebasing" ]; then
242 elif [ -f "$g/rebase-apply/applying" ]; then
247 elif [ -f "$g/MERGE_HEAD" ]; then
249 elif [ -f "$g/BISECT_LOG" ]; then
253 b
="$(git symbolic-ref HEAD 2>/dev/null)" ||
{
256 case "${GIT_PS1_DESCRIBE_STYLE-}" in
258 git describe --contains HEAD ;;
260 git describe --contains --all HEAD ;;
264 git describe --exact-match HEAD ;;
265 esac 2>/dev/null)" ||
267 b
="$(cut -c1-7 "$g/HEAD
" 2>/dev/null)..." ||
280 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
281 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
286 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
287 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
288 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
289 git
diff --no-ext-diff --quiet --exit-code || w
="*"
290 if git rev-parse
--quiet --verify HEAD
>/dev
/null
; then
291 git diff-index
--cached --quiet HEAD
-- || i
="+"
297 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
298 git rev-parse
--verify refs
/stash
>/dev
/null
2>&1 && s
="$"
301 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
302 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
307 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
308 __git_ps1_show_upstream
313 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
317 # __gitcomp_1 requires 2 arguments
320 local c IFS
=' '$
'\t'$
'\n'
323 --*=*) printf %s$
'\n' "$c$2" ;;
324 *.
) printf %s$
'\n' "$c$2" ;;
325 *) printf %s$
'\n' "$c$2 " ;;
330 # __gitcomp accepts 1, 2, 3, or 4 arguments
331 # generates completion reply with compgen
334 local cur
="${COMP_WORDS[COMP_CWORD]}"
335 if [ $# -gt 2 ]; then
344 COMPREPLY
=($
(compgen
-P "${2-}" \
345 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
351 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
354 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
355 if [ -d "$dir" ]; then
356 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
360 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
361 case "$is_hash,$i" in
364 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
365 n
,*) is_hash
=y
; echo "$i" ;;
370 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
373 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
374 if [ -d "$dir" ]; then
375 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
379 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
380 case "$is_hash,$i" in
383 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
384 n
,*) is_hash
=y
; echo "$i" ;;
389 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
392 local i is_hash
=y dir
="$(__gitdir "${1-}")"
393 local cur
="${COMP_WORDS[COMP_CWORD]}" format refs
394 if [ -d "$dir" ]; then
401 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
402 if [ -e "$dir/$i" ]; then echo $i; fi
404 format
="refname:short"
405 refs
="refs/tags refs/heads refs/remotes"
408 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
412 for i
in $
(git ls-remote
"$dir" 2>/dev
/null
); do
413 case "$is_hash,$i" in
416 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
417 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
418 n
,refs
/remotes
/*) is_hash
=y
; echo "${i#refs/remotes/}" ;;
419 n
,*) is_hash
=y
; echo "$i" ;;
424 # __git_refs2 requires 1 argument (to pass to __git_refs)
428 for i
in $
(__git_refs
"$1"); do
433 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
434 __git_refs_remotes
()
436 local cmd i is_hash
=y
437 for i
in $
(git ls-remote
"$1" 2>/dev
/null
); do
438 case "$is_hash,$i" in
441 echo "$i:refs/remotes/$1/${i#refs/heads/}"
445 n
,refs
/tags
/*) is_hash
=y
;;
453 local i ngoff IFS
=$
'\n' d
="$(__gitdir)"
454 shopt -q nullglob || ngoff
=1
456 for i
in "$d/remotes"/*; do
457 echo ${i#$d/remotes/}
459 [ "$ngoff" ] && shopt -u nullglob
460 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
466 __git_list_merge_strategies
()
468 git merge
-s help 2>&1 |
469 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
478 __git_merge_strategies
=
479 # 'git merge -s help' (and thus detection of the merge strategy
480 # list) fails, unfortunately, if run outside of any git working
481 # tree. __git_merge_strategies is set to the empty string in
482 # that case, and the detection will be repeated the next time it
484 __git_compute_merge_strategies
()
486 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
489 __git_complete_file
()
491 local pfx
ls ref cur
="${COMP_WORDS[COMP_CWORD]}"
508 case "$COMP_WORDBREAKS" in
510 *) pfx
="$ref:$pfx" ;;
514 COMPREPLY
=($
(compgen
-P "$pfx" \
515 -W "$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" \
516 | sed '/^100... blob /{
532 __gitcomp
"$(__git_refs)"
537 __git_complete_revlist
()
539 local pfx cur
="${COMP_WORDS[COMP_CWORD]}"
544 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
549 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
552 __gitcomp
"$(__git_refs)"
557 __git_complete_remote_or_refspec
()
559 local cmd
="${COMP_WORDS[1]}"
560 local cur
="${COMP_WORDS[COMP_CWORD]}"
561 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
562 while [ $c -lt $COMP_CWORD ]; do
565 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
568 push
) no_complete_refspec
=1 ;;
577 *) remote
="$i"; break ;;
581 if [ -z "$remote" ]; then
582 __gitcomp
"$(__git_remotes)"
585 if [ $no_complete_refspec = 1 ]; then
589 [ "$remote" = "." ] && remote
=
592 case "$COMP_WORDBREAKS" in
594 *) pfx
="${cur%%:*}:" ;;
606 if [ $lhs = 1 ]; then
607 __gitcomp
"$(__git_refs2 "$remote")" "$pfx" "$cur"
609 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
613 if [ $lhs = 1 ]; then
614 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
616 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
620 if [ $lhs = 1 ]; then
621 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
623 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
629 __git_complete_strategy
()
631 __git_compute_merge_strategies
632 case "${COMP_WORDS[COMP_CWORD-1]}" in
634 __gitcomp
"$__git_merge_strategies"
637 local cur
="${COMP_WORDS[COMP_CWORD]}"
640 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
647 __git_list_all_commands
()
650 for i
in $
(git
help -a|
egrep '^ [a-zA-Z0-9]')
653 *--*) : helper pattern
;;
660 __git_compute_all_commands
()
662 : ${__git_all_commands:=$(__git_list_all_commands)}
665 __git_list_porcelain_commands
()
668 __git_compute_all_commands
669 for i
in "help" $__git_all_commands
672 *--*) : helper pattern
;;
673 applymbox
) : ask gittus
;;
674 applypatch
) : ask gittus
;;
675 archimport
) : import
;;
676 cat-file
) : plumbing
;;
677 check-attr
) : plumbing
;;
678 check-ref-format
) : plumbing
;;
679 checkout-index
) : plumbing
;;
680 commit-tree
) : plumbing
;;
681 count-objects
) : infrequent
;;
682 cvsexportcommit
) : export;;
683 cvsimport
) : import
;;
684 cvsserver
) : daemon
;;
686 diff-files
) : plumbing
;;
687 diff-index
) : plumbing
;;
688 diff-tree
) : plumbing
;;
689 fast-import
) : import
;;
690 fast-export
) : export;;
691 fsck-objects
) : plumbing
;;
692 fetch-pack
) : plumbing
;;
693 fmt-merge-msg
) : plumbing
;;
694 for-each-ref
) : plumbing
;;
695 hash-object
) : plumbing
;;
696 http-
*) : transport
;;
697 index-pack
) : plumbing
;;
698 init-db
) : deprecated
;;
699 local-fetch
) : plumbing
;;
700 lost-found
) : infrequent
;;
701 ls-files
) : plumbing
;;
702 ls-remote
) : plumbing
;;
703 ls-tree
) : plumbing
;;
704 mailinfo
) : plumbing
;;
705 mailsplit
) : plumbing
;;
706 merge-
*) : plumbing
;;
709 pack-objects
) : plumbing
;;
710 pack-redundant
) : plumbing
;;
711 pack-refs
) : plumbing
;;
712 parse-remote
) : plumbing
;;
713 patch-id
) : plumbing
;;
714 peek-remote
) : plumbing
;;
716 prune-packed
) : plumbing
;;
717 quiltimport
) : import
;;
718 read-tree
) : plumbing
;;
719 receive-pack
) : plumbing
;;
721 remote-
*) : transport
;;
722 repo-config
) : deprecated
;;
724 rev-list
) : plumbing
;;
725 rev-parse
) : plumbing
;;
726 runstatus
) : plumbing
;;
727 sh-setup
) : internal
;;
729 show-ref
) : plumbing
;;
730 send-pack
) : plumbing
;;
731 show-index
) : plumbing
;;
733 stripspace
) : plumbing
;;
734 symbolic-ref
) : plumbing
;;
735 tar-tree
) : deprecated
;;
736 unpack-file
) : plumbing
;;
737 unpack-objects
) : plumbing
;;
738 update-index
) : plumbing
;;
739 update-ref
) : plumbing
;;
740 update-server-info
) : daemon
;;
741 upload-archive
) : plumbing
;;
742 upload-pack
) : plumbing
;;
743 write-tree
) : plumbing
;;
745 verify-pack
) : infrequent
;;
746 verify-tag
) : plumbing
;;
752 __git_porcelain_commands
=
753 __git_compute_porcelain_commands
()
755 __git_compute_all_commands
756 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
762 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
772 # __git_aliased_command requires 1 argument
773 __git_aliased_command
()
775 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
776 config
--get "alias.$1")
777 for word
in $cmdline; do
783 \
!*) : shell
command alias ;;
785 *=*) : setting env
;;
794 # __git_find_on_cmdline requires 1 argument
795 __git_find_on_cmdline
()
797 local word subcommand c
=1
799 while [ $c -lt $COMP_CWORD ]; do
800 word
="${COMP_WORDS[c]}"
801 for subcommand
in $1; do
802 if [ "$subcommand" = "$word" ]; then
811 __git_has_doubledash
()
814 while [ $c -lt $COMP_CWORD ]; do
815 if [ "--" = "${COMP_WORDS[c]}" ]; then
823 __git_whitespacelist
="nowarn warn error error-all fix"
827 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
828 if [ -d "$dir"/rebase-apply
]; then
829 __gitcomp
"--skip --continue --resolved --abort"
834 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
839 --3way --committer-date-is-author-date --ignore-date
840 --ignore-whitespace --ignore-space-change
841 --interactive --keep --no-utf8 --signoff --utf8
842 --whitespace= --scissors
851 local cur
="${COMP_WORDS[COMP_CWORD]}"
854 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
859 --stat --numstat --summary --check --index
860 --cached --index-info --reverse --reject --unidiff-zero
861 --apply --no-add --exclude=
862 --ignore-whitespace --ignore-space-change
863 --whitespace= --inaccurate-eof --verbose
872 __git_has_doubledash
&& return
874 local cur
="${COMP_WORDS[COMP_CWORD]}"
878 --interactive --refresh --patch --update --dry-run
879 --ignore-errors --intent-to-add
888 local cur
="${COMP_WORDS[COMP_CWORD]}"
891 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
895 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
900 --format= --list --verbose
901 --prefix= --remote= --exec=
911 __git_has_doubledash
&& return
913 local subcommands
="start bad good skip reset visualize replay log run"
914 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
915 if [ -z "$subcommand" ]; then
916 __gitcomp
"$subcommands"
920 case "$subcommand" in
922 __gitcomp
"$(__git_refs)"
932 local i c
=1 only_local_ref
="n" has_r
="n"
934 while [ $c -lt $COMP_CWORD ]; do
937 -d|
-m) only_local_ref
="y" ;;
943 case "${COMP_WORDS[COMP_CWORD]}" in
946 --color --no-color --verbose --abbrev= --no-abbrev
947 --track --no-track --contains --merged --no-merged
952 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
953 __gitcomp
"$(__git_heads)"
955 __gitcomp
"$(__git_refs)"
963 local cmd
="${COMP_WORDS[2]}"
964 case "$COMP_CWORD" in
966 __gitcomp
"create list-heads verify unbundle"
974 __git_complete_revlist
983 __git_has_doubledash
&& return
985 local cur
="${COMP_WORDS[COMP_CWORD]}"
988 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
992 --quiet --ours --theirs --track --no-track --merge
993 --conflict= --orphan --patch
997 __gitcomp
"$(__git_refs)"
1004 __gitcomp
"$(__git_refs)"
1009 local cur
="${COMP_WORDS[COMP_CWORD]}"
1012 __gitcomp
"--edit --no-commit"
1015 __gitcomp
"$(__git_refs)"
1022 __git_has_doubledash
&& return
1024 local cur
="${COMP_WORDS[COMP_CWORD]}"
1027 __gitcomp
"--dry-run --quiet"
1036 local cur
="${COMP_WORDS[COMP_CWORD]}"
1061 __git_has_doubledash
&& return
1063 local cur
="${COMP_WORDS[COMP_CWORD]}"
1066 __gitcomp
"default strip verbatim whitespace
1067 " "" "${cur##--cleanup=}"
1071 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1075 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1078 --untracked-files=*)
1079 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1084 --all --author= --signoff --verify --no-verify
1085 --edit --amend --include --only --interactive
1086 --dry-run --reuse-message= --reedit-message=
1087 --reset-author --file= --message= --template=
1088 --cleanup= --untracked-files --untracked-files=
1098 local cur
="${COMP_WORDS[COMP_CWORD]}"
1102 --all --tags --contains --abbrev= --candidates=
1103 --exact-match --debug --long --match --always
1107 __gitcomp
"$(__git_refs)"
1110 __git_diff_common_options
="--stat --numstat --shortstat --summary
1111 --patch-with-stat --name-only --name-status --color
1112 --no-color --color-words --no-renames --check
1113 --full-index --binary --abbrev --diff-filter=
1114 --find-copies-harder
1115 --text --ignore-space-at-eol --ignore-space-change
1116 --ignore-all-space --exit-code --quiet --ext-diff
1118 --no-prefix --src-prefix= --dst-prefix=
1119 --inter-hunk-context=
1122 --dirstat --dirstat= --dirstat-by-file
1123 --dirstat-by-file= --cumulative
1128 __git_has_doubledash
&& return
1130 local cur
="${COMP_WORDS[COMP_CWORD]}"
1133 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1134 --base --ours --theirs --no-index
1135 $__git_diff_common_options
1143 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1144 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1149 __git_has_doubledash
&& return
1151 local cur
="${COMP_WORDS[COMP_CWORD]}"
1154 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1158 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1159 --base --ours --theirs
1160 --no-renames --diff-filter= --find-copies-harder
1161 --relative --ignore-submodules
1169 __git_fetch_options
="
1170 --quiet --verbose --append --upload-pack --force --keep --depth=
1171 --tags --no-tags --all --prune --dry-run
1176 local cur
="${COMP_WORDS[COMP_CWORD]}"
1179 __gitcomp
"$__git_fetch_options"
1183 __git_complete_remote_or_refspec
1186 _git_format_patch
()
1188 local cur
="${COMP_WORDS[COMP_CWORD]}"
1193 " "" "${cur##--thread=}"
1198 --stdout --attach --no-attach --thread --thread=
1200 --numbered --start-number
1203 --signoff --signature --no-signature
1204 --in-reply-to= --cc=
1205 --full-index --binary
1208 --no-prefix --src-prefix= --dst-prefix=
1209 --inline --suffix= --ignore-if-in-upstream
1215 __git_complete_revlist
1220 local cur
="${COMP_WORDS[COMP_CWORD]}"
1224 --tags --root --unreachable --cache --no-reflogs --full
1225 --strict --verbose --lost-found
1235 local cur
="${COMP_WORDS[COMP_CWORD]}"
1238 __gitcomp
"--prune --aggressive"
1252 __git_has_doubledash
&& return
1254 local cur
="${COMP_WORDS[COMP_CWORD]}"
1259 --text --ignore-case --word-regexp --invert-match
1261 --extended-regexp --basic-regexp --fixed-strings
1262 --files-with-matches --name-only
1263 --files-without-match
1266 --and --or --not --all-match
1272 __gitcomp
"$(__git_refs)"
1277 local cur
="${COMP_WORDS[COMP_CWORD]}"
1280 __gitcomp
"--all --info --man --web"
1284 __git_compute_all_commands
1285 __gitcomp
"$__git_all_commands
1286 attributes cli core-tutorial cvs-migration
1287 diffcore gitk glossary hooks ignore modules
1288 repository-layout tutorial tutorial-2
1295 local cur
="${COMP_WORDS[COMP_CWORD]}"
1299 false true umask group all world everybody
1300 " "" "${cur##--shared=}"
1304 __gitcomp
"--quiet --bare --template= --shared --shared="
1313 __git_has_doubledash
&& return
1315 local cur
="${COMP_WORDS[COMP_CWORD]}"
1318 __gitcomp
"--cached --deleted --modified --others --ignored
1319 --stage --directory --no-empty-directory --unmerged
1320 --killed --exclude= --exclude-from=
1321 --exclude-per-directory= --exclude-standard
1322 --error-unmatch --with-tree= --full-name
1323 --abbrev --ignored --exclude-per-directory
1333 __gitcomp
"$(__git_remotes)"
1341 # Options that go well for log, shortlog and gitk
1342 __git_log_common_options
="
1344 --branches --tags --remotes
1345 --first-parent --merges --no-merges
1347 --max-age= --since= --after=
1348 --min-age= --until= --before=
1350 # Options that go well for log and gitk (not shortlog)
1351 __git_log_gitk_options
="
1352 --dense --sparse --full-history
1353 --simplify-merges --simplify-by-decoration
1356 # Options that go well for log and shortlog (not gitk)
1357 __git_log_shortlog_options
="
1358 --author= --committer= --grep=
1362 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1363 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1367 __git_has_doubledash
&& return
1369 local cur
="${COMP_WORDS[COMP_CWORD]}"
1370 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1372 if [ -f "$g/MERGE_HEAD" ]; then
1377 __gitcomp
"$__git_log_pretty_formats
1378 " "" "${cur##--pretty=}"
1382 __gitcomp
"$__git_log_pretty_formats
1383 " "" "${cur##--format=}"
1387 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1391 __gitcomp
"long short" "" "${cur##--decorate=}"
1396 $__git_log_common_options
1397 $__git_log_shortlog_options
1398 $__git_log_gitk_options
1399 --root --topo-order --date-order --reverse
1400 --follow --full-diff
1401 --abbrev-commit --abbrev=
1402 --relative-date --date=
1403 --pretty= --format= --oneline
1406 --decorate --decorate=
1408 --parents --children
1410 $__git_diff_common_options
1411 --pickaxe-all --pickaxe-regex
1416 __git_complete_revlist
1419 __git_merge_options
="
1420 --no-commit --no-stat --log --no-log --squash --strategy
1421 --commit --stat --no-squash --ff --no-ff --ff-only
1426 __git_complete_strategy
&& return
1428 local cur
="${COMP_WORDS[COMP_CWORD]}"
1431 __gitcomp
"$__git_merge_options"
1434 __gitcomp
"$(__git_refs)"
1439 local cur
="${COMP_WORDS[COMP_CWORD]}"
1442 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1455 __gitcomp
"$(__git_refs)"
1460 local cur
="${COMP_WORDS[COMP_CWORD]}"
1463 __gitcomp
"--dry-run"
1472 __gitcomp
"--tags --all --stdin"
1477 local subcommands
="edit show"
1478 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1479 __gitcomp
"$subcommands"
1483 case "${COMP_WORDS[COMP_CWORD-1]}" in
1488 __gitcomp
"$(__git_refs)"
1495 __git_complete_strategy
&& return
1497 local cur
="${COMP_WORDS[COMP_CWORD]}"
1501 --rebase --no-rebase
1502 $__git_merge_options
1503 $__git_fetch_options
1508 __git_complete_remote_or_refspec
1513 local cur
="${COMP_WORDS[COMP_CWORD]}"
1514 case "${COMP_WORDS[COMP_CWORD-1]}" in
1516 __gitcomp
"$(__git_remotes)"
1521 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1526 --all --mirror --tags --dry-run --force --verbose
1527 --receive-pack= --repo=
1532 __git_complete_remote_or_refspec
1537 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
1538 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1539 __gitcomp
"--continue --skip --abort"
1542 __git_complete_strategy
&& return
1545 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1550 --onto --merge --strategy --interactive
1551 --preserve-merges --stat --no-stat
1552 --committer-date-is-author-date --ignore-date
1553 --ignore-whitespace --whitespace=
1559 __gitcomp
"$(__git_refs)"
1562 __git_send_email_confirm_options
="always never auto cc compose"
1563 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1567 local cur
="${COMP_WORDS[COMP_CWORD]}"
1571 $__git_send_email_confirm_options
1572 " "" "${cur##--confirm=}"
1577 $__git_send_email_suppresscc_options
1578 " "" "${cur##--suppress-cc=}"
1582 --smtp-encryption=*)
1583 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1587 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1588 --compose --confirm= --dry-run --envelope-sender
1590 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1591 --no-suppress-from --no-thread --quiet
1592 --signed-off-by-cc --smtp-pass --smtp-server
1593 --smtp-server-port --smtp-encryption= --smtp-user
1594 --subject --suppress-cc= --suppress-from --thread --to
1595 --validate --no-validate"
1607 __git_config_get_set_variables
()
1609 local prevword word config_file
= c
=$COMP_CWORD
1610 while [ $c -gt 1 ]; do
1611 word
="${COMP_WORDS[c]}"
1613 --global|
--system|
--file=*)
1618 config_file
="$word $prevword"
1626 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1639 local cur
="${COMP_WORDS[COMP_CWORD]}"
1640 local prv
="${COMP_WORDS[COMP_CWORD-1]}"
1643 __gitcomp
"$(__git_remotes)"
1647 __gitcomp
"$(__git_refs)"
1651 local remote
="${prv#remote.}"
1652 remote
="${remote%.fetch}"
1653 __gitcomp
"$(__git_refs_remotes "$remote")"
1657 local remote
="${prv#remote.}"
1658 remote
="${remote%.push}"
1659 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1660 for-each-ref --format='%(refname):%(refname)' \
1664 pull.twohead|pull.octopus
)
1665 __git_compute_merge_strategies
1666 __gitcomp
"$__git_merge_strategies"
1669 color.branch|color.
diff|color.interactive|\
1670 color.showbranch|color.status|color.ui
)
1671 __gitcomp
"always never auto"
1675 __gitcomp
"false true"
1680 normal black red green yellow blue magenta cyan white
1681 bold dim ul blink reverse
1686 __gitcomp
"man info web html"
1690 __gitcomp
"$__git_log_date_formats"
1693 sendemail.aliasesfiletype
)
1694 __gitcomp
"mutt mailrc pine elm gnus"
1698 __gitcomp
"$__git_send_email_confirm_options"
1701 sendemail.suppresscc
)
1702 __gitcomp
"$__git_send_email_suppresscc_options"
1705 --get|
--get-all|
--unset|
--unset-all)
1706 __gitcomp
"$(__git_config_get_set_variables)"
1717 --global --system --file=
1718 --list --replace-all
1719 --get --get-all --get-regexp
1720 --add --unset --unset-all
1721 --remove-section --rename-section
1726 local pfx
="${cur%.*}."
1728 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur"
1732 local pfx
="${cur%.*}."
1734 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1738 local pfx
="${cur%.*}."
1741 argprompt cmd confirm needsfile noconsole norescan
1742 prompt revprompt revunmerged title
1747 local pfx
="${cur%.*}."
1749 __gitcomp
"cmd path" "$pfx" "$cur"
1753 local pfx
="${cur%.*}."
1755 __gitcomp
"cmd path" "$pfx" "$cur"
1759 local pfx
="${cur%.*}."
1761 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1765 local pfx
="${cur%.*}."
1767 __git_compute_all_commands
1768 __gitcomp
"$__git_all_commands" "$pfx" "$cur"
1772 local pfx
="${cur%.*}."
1775 url proxy fetch push mirror skipDefaultUpdate
1776 receivepack uploadpack tagopt pushurl
1781 local pfx
="${cur%.*}."
1783 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1787 local pfx
="${cur%.*}."
1789 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur"
1796 apply.ignorewhitespace
1798 branch.autosetupmerge
1799 branch.autosetuprebase
1802 color.branch.current
1813 color.diff.whitespace
1818 color.interactive.header
1819 color.interactive.help
1820 color.interactive.prompt
1825 color.status.changed
1827 color.status.nobranch
1828 color.status.untracked
1829 color.status.updated
1836 core.deltaBaseCacheLimit
1840 core.fsyncobjectfiles
1842 core.ignoreCygwinFSTricks
1844 core.logAllRefUpdates
1845 core.loosecompression
1847 core.packedGitWindowSize
1849 core.preferSymlinkRefs
1852 core.repositoryFormatVersion
1854 core.sharedRepository
1857 core.warnAmbiguousRefs
1860 diff.autorefreshindex
1866 diff.suppressBlankEmpty
1879 format.subjectprefix
1888 gc.reflogexpireunreachable
1892 gitcvs.commitmsgannotation
1893 gitcvs.dbTableNamePrefix
1904 gui.copyblamethreshold
1908 gui.matchtrackingbranch
1909 gui.newbranchtemplate
1910 gui.pruneduringfetch
1911 gui.spellingdictionary
1927 i18n.logOutputEncoding
1932 imap.preformattedHTML
1941 interactive.singlekey
1954 mergetool.keepBackup
1957 pack.deltaCacheLimit
1970 receive.denyCurrentBranch
1972 receive.denyNonFastForwards
1975 repack.usedeltabaseoffset
1978 sendemail.aliasesfile
1979 sendemail.aliasesfiletype
1983 sendemail.chainreplyto
1985 sendemail.envelopesender
1987 sendemail.signedoffbycc
1988 sendemail.smtpencryption
1990 sendemail.smtpserver
1991 sendemail.smtpserverport
1993 sendemail.suppresscc
1994 sendemail.suppressfrom
1999 status.relativePaths
2000 status.showUntrackedFiles
2002 transfer.unpackLimit
2014 local subcommands
="add rename rm show prune update set-head"
2015 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2016 if [ -z "$subcommand" ]; then
2017 __gitcomp
"$subcommands"
2021 case "$subcommand" in
2022 rename|
rm|show|prune
)
2023 __gitcomp
"$(__git_remotes)"
2026 local i c
='' IFS
=$
'\n'
2027 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2041 __gitcomp
"$(__git_refs)"
2046 __git_has_doubledash
&& return
2048 local cur
="${COMP_WORDS[COMP_CWORD]}"
2051 __gitcomp
"--merge --mixed --hard --soft --patch"
2055 __gitcomp
"$(__git_refs)"
2060 local cur
="${COMP_WORDS[COMP_CWORD]}"
2063 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2067 __gitcomp
"$(__git_refs)"
2072 __git_has_doubledash
&& return
2074 local cur
="${COMP_WORDS[COMP_CWORD]}"
2077 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2086 __git_has_doubledash
&& return
2088 local cur
="${COMP_WORDS[COMP_CWORD]}"
2092 $__git_log_common_options
2093 $__git_log_shortlog_options
2094 --numbered --summary
2099 __git_complete_revlist
2104 __git_has_doubledash
&& return
2106 local cur
="${COMP_WORDS[COMP_CWORD]}"
2109 __gitcomp
"$__git_log_pretty_formats
2110 " "" "${cur##--pretty=}"
2114 __gitcomp
"$__git_log_pretty_formats
2115 " "" "${cur##--format=}"
2119 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2120 $__git_diff_common_options
2130 local cur
="${COMP_WORDS[COMP_CWORD]}"
2134 --all --remotes --topo-order --current --more=
2135 --list --independent --merge-base --no-name
2137 --sha1-name --sparse --topics --reflog
2142 __git_complete_revlist
2147 local cur
="${COMP_WORDS[COMP_CWORD]}"
2148 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2149 local subcommands
='save list show apply clear drop pop create branch'
2150 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2151 if [ -z "$subcommand" ]; then
2154 __gitcomp
"$save_opts"
2157 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2158 __gitcomp
"$subcommands"
2165 case "$subcommand,$cur" in
2167 __gitcomp
"$save_opts"
2170 __gitcomp
"--index --quiet"
2172 show
,--*|drop
,--*|branch
,--*)
2175 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2176 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
2177 | sed -n -e 's/:.*//p')"
2188 __git_has_doubledash
&& return
2190 local subcommands
="add status init update summary foreach sync"
2191 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2192 local cur
="${COMP_WORDS[COMP_CWORD]}"
2195 __gitcomp
"--quiet --cached"
2198 __gitcomp
"$subcommands"
2208 init fetch clone rebase dcommit log find-rev
2209 set-tree commit-diff info create-ignore propget
2210 proplist show-ignore show-externals branch tag blame
2211 migrate mkdirs reset gc
2213 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2214 if [ -z "$subcommand" ]; then
2215 __gitcomp
"$subcommands"
2217 local remote_opts
="--username= --config-dir= --no-auth-cache"
2219 --follow-parent --authors-file= --repack=
2220 --no-metadata --use-svm-props --use-svnsync-props
2221 --log-window-size= --no-checkout --quiet
2222 --repack-flags --use-log-author --localtime
2223 --ignore-paths= $remote_opts
2226 --template= --shared= --trunk= --tags=
2227 --branches= --stdlayout --minimize-url
2228 --no-metadata --use-svm-props --use-svnsync-props
2229 --rewrite-root= --prefix= --use-log-author
2230 --add-author-from $remote_opts
2233 --edit --rmdir --find-copies-harder --copy-similarity=
2236 local cur
="${COMP_WORDS[COMP_CWORD]}"
2237 case "$subcommand,$cur" in
2239 __gitcomp
"--revision= --fetch-all $fc_opts"
2242 __gitcomp
"--revision= $fc_opts $init_opts"
2245 __gitcomp
"$init_opts"
2249 --merge --strategy= --verbose --dry-run
2250 --fetch-all --no-rebase --commit-url
2251 --revision $cmt_opts $fc_opts
2255 __gitcomp
"--stdin $cmt_opts $fc_opts"
2257 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2258 show-externals
,--*|mkdirs
,--*)
2259 __gitcomp
"--revision="
2263 --limit= --revision= --verbose --incremental
2264 --oneline --show-commit --non-recursive
2265 --authors-file= --color
2270 --merge --verbose --strategy= --local
2271 --fetch-all --dry-run $fc_opts
2275 __gitcomp
"--message= --file= --revision= $cmt_opts"
2281 __gitcomp
"--dry-run --message --tag"
2284 __gitcomp
"--dry-run --message"
2287 __gitcomp
"--git-format"
2291 --config-dir= --ignore-paths= --minimize
2292 --no-auth-cache --username=
2296 __gitcomp
"--revision= --parent"
2308 while [ $c -lt $COMP_CWORD ]; do
2309 i
="${COMP_WORDS[c]}"
2312 __gitcomp
"$(__git_tags)"
2322 case "${COMP_WORDS[COMP_CWORD-1]}" in
2328 __gitcomp
"$(__git_tags)"
2334 __gitcomp
"$(__git_refs)"
2346 local i c
=1 command __git_dir
2348 if [[ -n ${ZSH_VERSION-} ]]; then
2353 while [ $c -lt $COMP_CWORD ]; do
2354 i
="${COMP_WORDS[c]}"
2356 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2357 --bare) __git_dir
="." ;;
2358 --version|
-p|
--paginate) ;;
2359 --help) command="help"; break ;;
2360 *) command="$i"; break ;;
2365 if [ -z "$command" ]; then
2366 case "${COMP_WORDS[COMP_CWORD]}" in
2379 *) __git_compute_porcelain_commands
2380 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2385 local completion_func
="_git_${command//-/_}"
2386 declare -f $completion_func >/dev
/null
&& $completion_func && return
2388 local expansion
=$
(__git_aliased_command
"$command")
2389 if [ -n "$expansion" ]; then
2390 completion_func
="_git_${expansion//-/_}"
2391 declare -f $completion_func >/dev
/null
&& $completion_func
2397 if [[ -n ${ZSH_VERSION-} ]]; then
2402 __git_has_doubledash
&& return
2404 local cur
="${COMP_WORDS[COMP_CWORD]}"
2405 local g
="$(__gitdir)"
2407 if [ -f "$g/MERGE_HEAD" ]; then
2413 $__git_log_common_options
2414 $__git_log_gitk_options
2420 __git_complete_revlist
2423 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2424 || complete
-o default
-o nospace
-F _git git
2425 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2426 || complete
-o default
-o nospace
-F _gitk gitk
2428 # The following are necessary only for Cygwin, and only are needed
2429 # when the user has tab-completed the executable name and consequently
2430 # included the '.exe' suffix.
2432 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2433 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2434 || complete
-o default
-o nospace
-F _git git.exe
2437 if [[ -n ${ZSH_VERSION-} ]]; then
2440 if [ $# -ne 2 ]; then
2441 echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2449 echo "$0: invalid option: $2" >&2
2453 -q) setopt |
grep -q "$option" ;;
2454 -u) unsetopt
"$option" ;;
2455 -s) setopt
"$option" ;;
2457 echo "$0: invalid flag: $1" >&2