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)}
759 __git_pretty_aliases
()
762 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "pretty\..*" 2>/dev
/null
); do
775 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
785 # __git_aliased_command requires 1 argument
786 __git_aliased_command
()
788 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
789 config
--get "alias.$1")
790 for word
in $cmdline; do
796 \
!*) : shell
command alias ;;
798 *=*) : setting env
;;
807 # __git_find_on_cmdline requires 1 argument
808 __git_find_on_cmdline
()
810 local word subcommand c
=1
812 while [ $c -lt $COMP_CWORD ]; do
813 word
="${COMP_WORDS[c]}"
814 for subcommand
in $1; do
815 if [ "$subcommand" = "$word" ]; then
824 __git_has_doubledash
()
827 while [ $c -lt $COMP_CWORD ]; do
828 if [ "--" = "${COMP_WORDS[c]}" ]; then
836 __git_whitespacelist
="nowarn warn error error-all fix"
840 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
841 if [ -d "$dir"/rebase-apply
]; then
842 __gitcomp
"--skip --continue --resolved --abort"
847 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
852 --3way --committer-date-is-author-date --ignore-date
853 --ignore-whitespace --ignore-space-change
854 --interactive --keep --no-utf8 --signoff --utf8
855 --whitespace= --scissors
864 local cur
="${COMP_WORDS[COMP_CWORD]}"
867 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
872 --stat --numstat --summary --check --index
873 --cached --index-info --reverse --reject --unidiff-zero
874 --apply --no-add --exclude=
875 --ignore-whitespace --ignore-space-change
876 --whitespace= --inaccurate-eof --verbose
885 __git_has_doubledash
&& return
887 local cur
="${COMP_WORDS[COMP_CWORD]}"
891 --interactive --refresh --patch --update --dry-run
892 --ignore-errors --intent-to-add
901 local cur
="${COMP_WORDS[COMP_CWORD]}"
904 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
908 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
913 --format= --list --verbose
914 --prefix= --remote= --exec=
924 __git_has_doubledash
&& return
926 local subcommands
="start bad good skip reset visualize replay log run"
927 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
928 if [ -z "$subcommand" ]; then
929 if [ -f "$(__gitdir)"/BISECT_START
]; then
930 __gitcomp
"$subcommands"
932 __gitcomp
"replay start"
937 case "$subcommand" in
938 bad|good|
reset|skip|start
)
939 __gitcomp
"$(__git_refs)"
949 local i c
=1 only_local_ref
="n" has_r
="n"
951 while [ $c -lt $COMP_CWORD ]; do
954 -d|
-m) only_local_ref
="y" ;;
960 case "${COMP_WORDS[COMP_CWORD]}" in
963 --color --no-color --verbose --abbrev= --no-abbrev
964 --track --no-track --contains --merged --no-merged
969 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
970 __gitcomp
"$(__git_heads)"
972 __gitcomp
"$(__git_refs)"
980 local cmd
="${COMP_WORDS[2]}"
981 case "$COMP_CWORD" in
983 __gitcomp
"create list-heads verify unbundle"
991 __git_complete_revlist
1000 __git_has_doubledash
&& return
1002 local cur
="${COMP_WORDS[COMP_CWORD]}"
1005 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1009 --quiet --ours --theirs --track --no-track --merge
1010 --conflict= --orphan --patch
1014 __gitcomp
"$(__git_refs)"
1021 __gitcomp
"$(__git_refs)"
1026 local cur
="${COMP_WORDS[COMP_CWORD]}"
1029 __gitcomp
"--edit --no-commit"
1032 __gitcomp
"$(__git_refs)"
1039 __git_has_doubledash
&& return
1041 local cur
="${COMP_WORDS[COMP_CWORD]}"
1044 __gitcomp
"--dry-run --quiet"
1053 local cur
="${COMP_WORDS[COMP_CWORD]}"
1078 __git_has_doubledash
&& return
1080 local cur
="${COMP_WORDS[COMP_CWORD]}"
1083 __gitcomp
"default strip verbatim whitespace
1084 " "" "${cur##--cleanup=}"
1088 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1092 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1095 --untracked-files=*)
1096 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1101 --all --author= --signoff --verify --no-verify
1102 --edit --amend --include --only --interactive
1103 --dry-run --reuse-message= --reedit-message=
1104 --reset-author --file= --message= --template=
1105 --cleanup= --untracked-files --untracked-files=
1115 local cur
="${COMP_WORDS[COMP_CWORD]}"
1119 --all --tags --contains --abbrev= --candidates=
1120 --exact-match --debug --long --match --always
1124 __gitcomp
"$(__git_refs)"
1127 __git_diff_common_options
="--stat --numstat --shortstat --summary
1128 --patch-with-stat --name-only --name-status --color
1129 --no-color --color-words --no-renames --check
1130 --full-index --binary --abbrev --diff-filter=
1131 --find-copies-harder
1132 --text --ignore-space-at-eol --ignore-space-change
1133 --ignore-all-space --exit-code --quiet --ext-diff
1135 --no-prefix --src-prefix= --dst-prefix=
1136 --inter-hunk-context=
1139 --dirstat --dirstat= --dirstat-by-file
1140 --dirstat-by-file= --cumulative
1145 __git_has_doubledash
&& return
1147 local cur
="${COMP_WORDS[COMP_CWORD]}"
1150 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1151 --base --ours --theirs --no-index
1152 $__git_diff_common_options
1160 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1161 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1166 __git_has_doubledash
&& return
1168 local cur
="${COMP_WORDS[COMP_CWORD]}"
1171 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1175 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1176 --base --ours --theirs
1177 --no-renames --diff-filter= --find-copies-harder
1178 --relative --ignore-submodules
1186 __git_fetch_options
="
1187 --quiet --verbose --append --upload-pack --force --keep --depth=
1188 --tags --no-tags --all --prune --dry-run
1193 local cur
="${COMP_WORDS[COMP_CWORD]}"
1196 __gitcomp
"$__git_fetch_options"
1200 __git_complete_remote_or_refspec
1203 _git_format_patch
()
1205 local cur
="${COMP_WORDS[COMP_CWORD]}"
1210 " "" "${cur##--thread=}"
1215 --stdout --attach --no-attach --thread --thread=
1217 --numbered --start-number
1220 --signoff --signature --no-signature
1221 --in-reply-to= --cc=
1222 --full-index --binary
1225 --no-prefix --src-prefix= --dst-prefix=
1226 --inline --suffix= --ignore-if-in-upstream
1232 __git_complete_revlist
1237 local cur
="${COMP_WORDS[COMP_CWORD]}"
1241 --tags --root --unreachable --cache --no-reflogs --full
1242 --strict --verbose --lost-found
1252 local cur
="${COMP_WORDS[COMP_CWORD]}"
1255 __gitcomp
"--prune --aggressive"
1269 __git_has_doubledash
&& return
1271 local cur
="${COMP_WORDS[COMP_CWORD]}"
1276 --text --ignore-case --word-regexp --invert-match
1278 --extended-regexp --basic-regexp --fixed-strings
1279 --files-with-matches --name-only
1280 --files-without-match
1283 --and --or --not --all-match
1289 __gitcomp
"$(__git_refs)"
1294 local cur
="${COMP_WORDS[COMP_CWORD]}"
1297 __gitcomp
"--all --info --man --web"
1301 __git_compute_all_commands
1302 __gitcomp
"$__git_all_commands
1303 attributes cli core-tutorial cvs-migration
1304 diffcore gitk glossary hooks ignore modules
1305 repository-layout tutorial tutorial-2
1312 local cur
="${COMP_WORDS[COMP_CWORD]}"
1316 false true umask group all world everybody
1317 " "" "${cur##--shared=}"
1321 __gitcomp
"--quiet --bare --template= --shared --shared="
1330 __git_has_doubledash
&& return
1332 local cur
="${COMP_WORDS[COMP_CWORD]}"
1335 __gitcomp
"--cached --deleted --modified --others --ignored
1336 --stage --directory --no-empty-directory --unmerged
1337 --killed --exclude= --exclude-from=
1338 --exclude-per-directory= --exclude-standard
1339 --error-unmatch --with-tree= --full-name
1340 --abbrev --ignored --exclude-per-directory
1350 __gitcomp
"$(__git_remotes)"
1358 # Options that go well for log, shortlog and gitk
1359 __git_log_common_options
="
1361 --branches --tags --remotes
1362 --first-parent --merges --no-merges
1364 --max-age= --since= --after=
1365 --min-age= --until= --before=
1367 # Options that go well for log and gitk (not shortlog)
1368 __git_log_gitk_options
="
1369 --dense --sparse --full-history
1370 --simplify-merges --simplify-by-decoration
1373 # Options that go well for log and shortlog (not gitk)
1374 __git_log_shortlog_options
="
1375 --author= --committer= --grep=
1379 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1380 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1384 __git_has_doubledash
&& return
1386 local cur
="${COMP_WORDS[COMP_CWORD]}"
1387 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1389 if [ -f "$g/MERGE_HEAD" ]; then
1394 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1395 " "" "${cur##--pretty=}"
1399 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1400 " "" "${cur##--format=}"
1404 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1408 __gitcomp
"long short" "" "${cur##--decorate=}"
1413 $__git_log_common_options
1414 $__git_log_shortlog_options
1415 $__git_log_gitk_options
1416 --root --topo-order --date-order --reverse
1417 --follow --full-diff
1418 --abbrev-commit --abbrev=
1419 --relative-date --date=
1420 --pretty= --format= --oneline
1423 --decorate --decorate=
1425 --parents --children
1427 $__git_diff_common_options
1428 --pickaxe-all --pickaxe-regex
1433 __git_complete_revlist
1436 __git_merge_options
="
1437 --no-commit --no-stat --log --no-log --squash --strategy
1438 --commit --stat --no-squash --ff --no-ff --ff-only
1443 __git_complete_strategy
&& return
1445 local cur
="${COMP_WORDS[COMP_CWORD]}"
1448 __gitcomp
"$__git_merge_options"
1451 __gitcomp
"$(__git_refs)"
1456 local cur
="${COMP_WORDS[COMP_CWORD]}"
1459 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1472 __gitcomp
"$(__git_refs)"
1477 local cur
="${COMP_WORDS[COMP_CWORD]}"
1480 __gitcomp
"--dry-run"
1489 __gitcomp
"--tags --all --stdin"
1494 local subcommands
='add append copy edit list prune remove show'
1495 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1496 local cur
="${COMP_WORDS[COMP_CWORD]}"
1498 case "$subcommand,$cur" in
1503 case "${COMP_WORDS[COMP_CWORD-1]}" in
1505 __gitcomp
"$(__git_refs)"
1508 __gitcomp
"$subcommands --ref"
1512 add
,--reuse-message=*|append
,--reuse-message=*)
1513 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1515 add
,--reedit-message=*|append
,--reedit-message=*)
1516 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1519 __gitcomp
'--file= --message= --reedit-message=
1526 __gitcomp
'--dry-run --verbose'
1531 case "${COMP_WORDS[COMP_CWORD-1]}" in
1535 __gitcomp
"$(__git_refs)"
1544 __git_complete_strategy
&& return
1546 local cur
="${COMP_WORDS[COMP_CWORD]}"
1550 --rebase --no-rebase
1551 $__git_merge_options
1552 $__git_fetch_options
1557 __git_complete_remote_or_refspec
1562 local cur
="${COMP_WORDS[COMP_CWORD]}"
1563 case "${COMP_WORDS[COMP_CWORD-1]}" in
1565 __gitcomp
"$(__git_remotes)"
1570 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1575 --all --mirror --tags --dry-run --force --verbose
1576 --receive-pack= --repo=
1581 __git_complete_remote_or_refspec
1586 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
1587 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1588 __gitcomp
"--continue --skip --abort"
1591 __git_complete_strategy
&& return
1594 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1599 --onto --merge --strategy --interactive
1600 --preserve-merges --stat --no-stat
1601 --committer-date-is-author-date --ignore-date
1602 --ignore-whitespace --whitespace=
1608 __gitcomp
"$(__git_refs)"
1611 __git_send_email_confirm_options
="always never auto cc compose"
1612 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1616 local cur
="${COMP_WORDS[COMP_CWORD]}"
1620 $__git_send_email_confirm_options
1621 " "" "${cur##--confirm=}"
1626 $__git_send_email_suppresscc_options
1627 " "" "${cur##--suppress-cc=}"
1631 --smtp-encryption=*)
1632 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1636 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1637 --compose --confirm= --dry-run --envelope-sender
1639 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1640 --no-suppress-from --no-thread --quiet
1641 --signed-off-by-cc --smtp-pass --smtp-server
1642 --smtp-server-port --smtp-encryption= --smtp-user
1643 --subject --suppress-cc= --suppress-from --thread --to
1644 --validate --no-validate"
1656 __git_config_get_set_variables
()
1658 local prevword word config_file
= c
=$COMP_CWORD
1659 while [ $c -gt 1 ]; do
1660 word
="${COMP_WORDS[c]}"
1662 --global|
--system|
--file=*)
1667 config_file
="$word $prevword"
1675 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1688 local cur
="${COMP_WORDS[COMP_CWORD]}"
1689 local prv
="${COMP_WORDS[COMP_CWORD-1]}"
1692 __gitcomp
"$(__git_remotes)"
1696 __gitcomp
"$(__git_refs)"
1700 local remote
="${prv#remote.}"
1701 remote
="${remote%.fetch}"
1702 __gitcomp
"$(__git_refs_remotes "$remote")"
1706 local remote
="${prv#remote.}"
1707 remote
="${remote%.push}"
1708 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1709 for-each-ref --format='%(refname):%(refname)' \
1713 pull.twohead|pull.octopus
)
1714 __git_compute_merge_strategies
1715 __gitcomp
"$__git_merge_strategies"
1718 color.branch|color.
diff|color.interactive|\
1719 color.showbranch|color.status|color.ui
)
1720 __gitcomp
"always never auto"
1724 __gitcomp
"false true"
1729 normal black red green yellow blue magenta cyan white
1730 bold dim ul blink reverse
1735 __gitcomp
"man info web html"
1739 __gitcomp
"$__git_log_date_formats"
1742 sendemail.aliasesfiletype
)
1743 __gitcomp
"mutt mailrc pine elm gnus"
1747 __gitcomp
"$__git_send_email_confirm_options"
1750 sendemail.suppresscc
)
1751 __gitcomp
"$__git_send_email_suppresscc_options"
1754 --get|
--get-all|
--unset|
--unset-all)
1755 __gitcomp
"$(__git_config_get_set_variables)"
1766 --global --system --file=
1767 --list --replace-all
1768 --get --get-all --get-regexp
1769 --add --unset --unset-all
1770 --remove-section --rename-section
1775 local pfx
="${cur%.*}."
1777 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur"
1781 local pfx
="${cur%.*}."
1783 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1787 local pfx
="${cur%.*}."
1790 argprompt cmd confirm needsfile noconsole norescan
1791 prompt revprompt revunmerged title
1796 local pfx
="${cur%.*}."
1798 __gitcomp
"cmd path" "$pfx" "$cur"
1802 local pfx
="${cur%.*}."
1804 __gitcomp
"cmd path" "$pfx" "$cur"
1808 local pfx
="${cur%.*}."
1810 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1814 local pfx
="${cur%.*}."
1816 __git_compute_all_commands
1817 __gitcomp
"$__git_all_commands" "$pfx" "$cur"
1821 local pfx
="${cur%.*}."
1824 url proxy fetch push mirror skipDefaultUpdate
1825 receivepack uploadpack tagopt pushurl
1830 local pfx
="${cur%.*}."
1832 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1836 local pfx
="${cur%.*}."
1838 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur"
1845 apply.ignorewhitespace
1847 branch.autosetupmerge
1848 branch.autosetuprebase
1851 color.branch.current
1862 color.diff.whitespace
1867 color.interactive.header
1868 color.interactive.help
1869 color.interactive.prompt
1874 color.status.changed
1876 color.status.nobranch
1877 color.status.untracked
1878 color.status.updated
1885 core.deltaBaseCacheLimit
1889 core.fsyncobjectfiles
1891 core.ignoreCygwinFSTricks
1893 core.logAllRefUpdates
1894 core.loosecompression
1896 core.packedGitWindowSize
1898 core.preferSymlinkRefs
1901 core.repositoryFormatVersion
1903 core.sharedRepository
1906 core.warnAmbiguousRefs
1909 diff.autorefreshindex
1915 diff.suppressBlankEmpty
1928 format.subjectprefix
1937 gc.reflogexpireunreachable
1941 gitcvs.commitmsgannotation
1942 gitcvs.dbTableNamePrefix
1953 gui.copyblamethreshold
1957 gui.matchtrackingbranch
1958 gui.newbranchtemplate
1959 gui.pruneduringfetch
1960 gui.spellingdictionary
1976 i18n.logOutputEncoding
1981 imap.preformattedHTML
1990 interactive.singlekey
2003 mergetool.keepBackup
2006 pack.deltaCacheLimit
2019 receive.denyCurrentBranch
2021 receive.denyNonFastForwards
2024 repack.usedeltabaseoffset
2027 sendemail.aliasesfile
2028 sendemail.aliasesfiletype
2032 sendemail.chainreplyto
2034 sendemail.envelopesender
2036 sendemail.signedoffbycc
2037 sendemail.smtpencryption
2039 sendemail.smtpserver
2040 sendemail.smtpserverport
2042 sendemail.suppresscc
2043 sendemail.suppressfrom
2048 status.relativePaths
2049 status.showUntrackedFiles
2051 transfer.unpackLimit
2063 local subcommands
="add rename rm show prune update set-head"
2064 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2065 if [ -z "$subcommand" ]; then
2066 __gitcomp
"$subcommands"
2070 case "$subcommand" in
2071 rename|
rm|show|prune
)
2072 __gitcomp
"$(__git_remotes)"
2075 local i c
='' IFS
=$
'\n'
2076 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2090 __gitcomp
"$(__git_refs)"
2095 __git_has_doubledash
&& return
2097 local cur
="${COMP_WORDS[COMP_CWORD]}"
2100 __gitcomp
"--merge --mixed --hard --soft --patch"
2104 __gitcomp
"$(__git_refs)"
2109 local cur
="${COMP_WORDS[COMP_CWORD]}"
2112 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2116 __gitcomp
"$(__git_refs)"
2121 __git_has_doubledash
&& return
2123 local cur
="${COMP_WORDS[COMP_CWORD]}"
2126 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2135 __git_has_doubledash
&& return
2137 local cur
="${COMP_WORDS[COMP_CWORD]}"
2141 $__git_log_common_options
2142 $__git_log_shortlog_options
2143 --numbered --summary
2148 __git_complete_revlist
2153 __git_has_doubledash
&& return
2155 local cur
="${COMP_WORDS[COMP_CWORD]}"
2158 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2159 " "" "${cur##--pretty=}"
2163 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2164 " "" "${cur##--format=}"
2168 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2169 $__git_diff_common_options
2179 local cur
="${COMP_WORDS[COMP_CWORD]}"
2183 --all --remotes --topo-order --current --more=
2184 --list --independent --merge-base --no-name
2186 --sha1-name --sparse --topics --reflog
2191 __git_complete_revlist
2196 local cur
="${COMP_WORDS[COMP_CWORD]}"
2197 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2198 local subcommands
='save list show apply clear drop pop create branch'
2199 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2200 if [ -z "$subcommand" ]; then
2203 __gitcomp
"$save_opts"
2206 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2207 __gitcomp
"$subcommands"
2214 case "$subcommand,$cur" in
2216 __gitcomp
"$save_opts"
2219 __gitcomp
"--index --quiet"
2221 show
,--*|drop
,--*|branch
,--*)
2224 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2225 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
2226 | sed -n -e 's/:.*//p')"
2237 __git_has_doubledash
&& return
2239 local subcommands
="add status init update summary foreach sync"
2240 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2241 local cur
="${COMP_WORDS[COMP_CWORD]}"
2244 __gitcomp
"--quiet --cached"
2247 __gitcomp
"$subcommands"
2257 init fetch clone rebase dcommit log find-rev
2258 set-tree commit-diff info create-ignore propget
2259 proplist show-ignore show-externals branch tag blame
2260 migrate mkdirs reset gc
2262 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2263 if [ -z "$subcommand" ]; then
2264 __gitcomp
"$subcommands"
2266 local remote_opts
="--username= --config-dir= --no-auth-cache"
2268 --follow-parent --authors-file= --repack=
2269 --no-metadata --use-svm-props --use-svnsync-props
2270 --log-window-size= --no-checkout --quiet
2271 --repack-flags --use-log-author --localtime
2272 --ignore-paths= $remote_opts
2275 --template= --shared= --trunk= --tags=
2276 --branches= --stdlayout --minimize-url
2277 --no-metadata --use-svm-props --use-svnsync-props
2278 --rewrite-root= --prefix= --use-log-author
2279 --add-author-from $remote_opts
2282 --edit --rmdir --find-copies-harder --copy-similarity=
2285 local cur
="${COMP_WORDS[COMP_CWORD]}"
2286 case "$subcommand,$cur" in
2288 __gitcomp
"--revision= --fetch-all $fc_opts"
2291 __gitcomp
"--revision= $fc_opts $init_opts"
2294 __gitcomp
"$init_opts"
2298 --merge --strategy= --verbose --dry-run
2299 --fetch-all --no-rebase --commit-url
2300 --revision $cmt_opts $fc_opts
2304 __gitcomp
"--stdin $cmt_opts $fc_opts"
2306 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2307 show-externals
,--*|mkdirs
,--*)
2308 __gitcomp
"--revision="
2312 --limit= --revision= --verbose --incremental
2313 --oneline --show-commit --non-recursive
2314 --authors-file= --color
2319 --merge --verbose --strategy= --local
2320 --fetch-all --dry-run $fc_opts
2324 __gitcomp
"--message= --file= --revision= $cmt_opts"
2330 __gitcomp
"--dry-run --message --tag"
2333 __gitcomp
"--dry-run --message"
2336 __gitcomp
"--git-format"
2340 --config-dir= --ignore-paths= --minimize
2341 --no-auth-cache --username=
2345 __gitcomp
"--revision= --parent"
2357 while [ $c -lt $COMP_CWORD ]; do
2358 i
="${COMP_WORDS[c]}"
2361 __gitcomp
"$(__git_tags)"
2371 case "${COMP_WORDS[COMP_CWORD-1]}" in
2377 __gitcomp
"$(__git_tags)"
2383 __gitcomp
"$(__git_refs)"
2395 local i c
=1 command __git_dir
2397 if [[ -n ${ZSH_VERSION-} ]]; then
2402 while [ $c -lt $COMP_CWORD ]; do
2403 i
="${COMP_WORDS[c]}"
2405 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2406 --bare) __git_dir
="." ;;
2407 --version|
-p|
--paginate) ;;
2408 --help) command="help"; break ;;
2409 *) command="$i"; break ;;
2414 if [ -z "$command" ]; then
2415 case "${COMP_WORDS[COMP_CWORD]}" in
2428 *) __git_compute_porcelain_commands
2429 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2434 local completion_func
="_git_${command//-/_}"
2435 declare -f $completion_func >/dev
/null
&& $completion_func && return
2437 local expansion
=$
(__git_aliased_command
"$command")
2438 if [ -n "$expansion" ]; then
2439 completion_func
="_git_${expansion//-/_}"
2440 declare -f $completion_func >/dev
/null
&& $completion_func
2446 if [[ -n ${ZSH_VERSION-} ]]; then
2451 __git_has_doubledash
&& return
2453 local cur
="${COMP_WORDS[COMP_CWORD]}"
2454 local g
="$(__gitdir)"
2456 if [ -f "$g/MERGE_HEAD" ]; then
2462 $__git_log_common_options
2463 $__git_log_gitk_options
2469 __git_complete_revlist
2472 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2473 || complete
-o default
-o nospace
-F _git git
2474 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2475 || complete
-o default
-o nospace
-F _gitk gitk
2477 # The following are necessary only for Cygwin, and only are needed
2478 # when the user has tab-completed the executable name and consequently
2479 # included the '.exe' suffix.
2481 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2482 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2483 || complete
-o default
-o nospace
-F _git git.exe
2486 if [[ -n ${ZSH_VERSION-} ]]; then
2489 if [ $# -ne 2 ]; then
2490 echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2498 echo "$0: invalid option: $2" >&2
2502 -q) setopt |
grep -q "$option" ;;
2503 -u) unsetopt
"$option" ;;
2504 -s) setopt
"$option" ;;
2506 echo "$0: invalid flag: $1" >&2