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, 1 (to pass to __gitdir), or 2 arguments
390 # presence of 2nd argument means use the guess heuristic employed
391 # by checkout for tracking branches
394 local i is_hash
=y dir
="$(__gitdir "${1-}")" track
="${2-}"
395 local cur
="${COMP_WORDS[COMP_CWORD]}" format refs
396 if [ -d "$dir" ]; then
404 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
405 if [ -e "$dir/$i" ]; then echo $i; fi
407 format
="refname:short"
408 refs
="refs/tags refs/heads refs/remotes"
411 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
413 if [ -n "$track" ]; then
414 # employ the heuristic used by git checkout
415 # Try to find a remote branch that matches the completion word
416 # but only output if the branch name is unique
418 git
--git-dir="$dir" for-each-ref
--shell --format="ref=%(refname:short)" \
423 if [[ "$ref" == "$cur"* ]]; then
430 for i
in $
(git ls-remote
"$dir" 2>/dev
/null
); do
431 case "$is_hash,$i" in
434 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
435 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
436 n
,refs
/remotes
/*) is_hash
=y
; echo "${i#refs/remotes/}" ;;
437 n
,*) is_hash
=y
; echo "$i" ;;
442 # __git_refs2 requires 1 argument (to pass to __git_refs)
446 for i
in $
(__git_refs
"$1"); do
451 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
452 __git_refs_remotes
()
454 local cmd i is_hash
=y
455 for i
in $
(git ls-remote
"$1" 2>/dev
/null
); do
456 case "$is_hash,$i" in
459 echo "$i:refs/remotes/$1/${i#refs/heads/}"
463 n
,refs
/tags
/*) is_hash
=y
;;
471 local i ngoff IFS
=$
'\n' d
="$(__gitdir)"
472 shopt -q nullglob || ngoff
=1
474 for i
in "$d/remotes"/*; do
475 echo ${i#$d/remotes/}
477 [ "$ngoff" ] && shopt -u nullglob
478 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
484 __git_list_merge_strategies
()
486 git merge
-s help 2>&1 |
487 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
496 __git_merge_strategies
=
497 # 'git merge -s help' (and thus detection of the merge strategy
498 # list) fails, unfortunately, if run outside of any git working
499 # tree. __git_merge_strategies is set to the empty string in
500 # that case, and the detection will be repeated the next time it
502 __git_compute_merge_strategies
()
504 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
507 __git_complete_file
()
509 local pfx
ls ref cur
="${COMP_WORDS[COMP_CWORD]}"
526 case "$COMP_WORDBREAKS" in
528 *) pfx
="$ref:$pfx" ;;
532 COMPREPLY
=($
(compgen
-P "$pfx" \
533 -W "$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" \
534 | sed '/^100... blob /{
550 __gitcomp
"$(__git_refs)"
555 __git_complete_revlist
()
557 local pfx cur
="${COMP_WORDS[COMP_CWORD]}"
562 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
567 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
570 __gitcomp
"$(__git_refs)"
575 __git_complete_remote_or_refspec
()
577 local cmd
="${COMP_WORDS[1]}"
578 local cur
="${COMP_WORDS[COMP_CWORD]}"
579 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
580 while [ $c -lt $COMP_CWORD ]; do
583 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
586 push
) no_complete_refspec
=1 ;;
595 *) remote
="$i"; break ;;
599 if [ -z "$remote" ]; then
600 __gitcomp
"$(__git_remotes)"
603 if [ $no_complete_refspec = 1 ]; then
607 [ "$remote" = "." ] && remote
=
610 case "$COMP_WORDBREAKS" in
612 *) pfx
="${cur%%:*}:" ;;
624 if [ $lhs = 1 ]; then
625 __gitcomp
"$(__git_refs2 "$remote")" "$pfx" "$cur"
627 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
631 if [ $lhs = 1 ]; then
632 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
634 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
638 if [ $lhs = 1 ]; then
639 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
641 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
647 __git_complete_strategy
()
649 __git_compute_merge_strategies
650 case "${COMP_WORDS[COMP_CWORD-1]}" in
652 __gitcomp
"$__git_merge_strategies"
655 local cur
="${COMP_WORDS[COMP_CWORD]}"
658 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
665 __git_list_all_commands
()
668 for i
in $
(git
help -a|
egrep '^ [a-zA-Z0-9]')
671 *--*) : helper pattern
;;
678 __git_compute_all_commands
()
680 : ${__git_all_commands:=$(__git_list_all_commands)}
683 __git_list_porcelain_commands
()
686 __git_compute_all_commands
687 for i
in "help" $__git_all_commands
690 *--*) : helper pattern
;;
691 applymbox
) : ask gittus
;;
692 applypatch
) : ask gittus
;;
693 archimport
) : import
;;
694 cat-file
) : plumbing
;;
695 check-attr
) : plumbing
;;
696 check-ref-format
) : plumbing
;;
697 checkout-index
) : plumbing
;;
698 commit-tree
) : plumbing
;;
699 count-objects
) : infrequent
;;
700 cvsexportcommit
) : export;;
701 cvsimport
) : import
;;
702 cvsserver
) : daemon
;;
704 diff-files
) : plumbing
;;
705 diff-index
) : plumbing
;;
706 diff-tree
) : plumbing
;;
707 fast-import
) : import
;;
708 fast-export
) : export;;
709 fsck-objects
) : plumbing
;;
710 fetch-pack
) : plumbing
;;
711 fmt-merge-msg
) : plumbing
;;
712 for-each-ref
) : plumbing
;;
713 hash-object
) : plumbing
;;
714 http-
*) : transport
;;
715 index-pack
) : plumbing
;;
716 init-db
) : deprecated
;;
717 local-fetch
) : plumbing
;;
718 lost-found
) : infrequent
;;
719 ls-files
) : plumbing
;;
720 ls-remote
) : plumbing
;;
721 ls-tree
) : plumbing
;;
722 mailinfo
) : plumbing
;;
723 mailsplit
) : plumbing
;;
724 merge-
*) : plumbing
;;
727 pack-objects
) : plumbing
;;
728 pack-redundant
) : plumbing
;;
729 pack-refs
) : plumbing
;;
730 parse-remote
) : plumbing
;;
731 patch-id
) : plumbing
;;
732 peek-remote
) : plumbing
;;
734 prune-packed
) : plumbing
;;
735 quiltimport
) : import
;;
736 read-tree
) : plumbing
;;
737 receive-pack
) : plumbing
;;
739 remote-
*) : transport
;;
740 repo-config
) : deprecated
;;
742 rev-list
) : plumbing
;;
743 rev-parse
) : plumbing
;;
744 runstatus
) : plumbing
;;
745 sh-setup
) : internal
;;
747 show-ref
) : plumbing
;;
748 send-pack
) : plumbing
;;
749 show-index
) : plumbing
;;
751 stripspace
) : plumbing
;;
752 symbolic-ref
) : plumbing
;;
753 tar-tree
) : deprecated
;;
754 unpack-file
) : plumbing
;;
755 unpack-objects
) : plumbing
;;
756 update-index
) : plumbing
;;
757 update-ref
) : plumbing
;;
758 update-server-info
) : daemon
;;
759 upload-archive
) : plumbing
;;
760 upload-pack
) : plumbing
;;
761 write-tree
) : plumbing
;;
763 verify-pack
) : infrequent
;;
764 verify-tag
) : plumbing
;;
770 __git_porcelain_commands
=
771 __git_compute_porcelain_commands
()
773 __git_compute_all_commands
774 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
777 __git_pretty_aliases
()
780 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "pretty\..*" 2>/dev
/null
); do
793 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
803 # __git_aliased_command requires 1 argument
804 __git_aliased_command
()
806 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
807 config
--get "alias.$1")
808 for word
in $cmdline; do
814 \
!*) : shell
command alias ;;
816 *=*) : setting env
;;
825 # __git_find_on_cmdline requires 1 argument
826 __git_find_on_cmdline
()
828 local word subcommand c
=1
830 while [ $c -lt $COMP_CWORD ]; do
831 word
="${COMP_WORDS[c]}"
832 for subcommand
in $1; do
833 if [ "$subcommand" = "$word" ]; then
842 __git_has_doubledash
()
845 while [ $c -lt $COMP_CWORD ]; do
846 if [ "--" = "${COMP_WORDS[c]}" ]; then
854 __git_whitespacelist
="nowarn warn error error-all fix"
858 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
859 if [ -d "$dir"/rebase-apply
]; then
860 __gitcomp
"--skip --continue --resolved --abort"
865 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
870 --3way --committer-date-is-author-date --ignore-date
871 --ignore-whitespace --ignore-space-change
872 --interactive --keep --no-utf8 --signoff --utf8
873 --whitespace= --scissors
882 local cur
="${COMP_WORDS[COMP_CWORD]}"
885 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
890 --stat --numstat --summary --check --index
891 --cached --index-info --reverse --reject --unidiff-zero
892 --apply --no-add --exclude=
893 --ignore-whitespace --ignore-space-change
894 --whitespace= --inaccurate-eof --verbose
903 __git_has_doubledash
&& return
905 local cur
="${COMP_WORDS[COMP_CWORD]}"
909 --interactive --refresh --patch --update --dry-run
910 --ignore-errors --intent-to-add
919 local cur
="${COMP_WORDS[COMP_CWORD]}"
922 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
926 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
931 --format= --list --verbose
932 --prefix= --remote= --exec=
942 __git_has_doubledash
&& return
944 local subcommands
="start bad good skip reset visualize replay log run"
945 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
946 if [ -z "$subcommand" ]; then
947 if [ -f "$(__gitdir)"/BISECT_START
]; then
948 __gitcomp
"$subcommands"
950 __gitcomp
"replay start"
955 case "$subcommand" in
956 bad|good|
reset|skip|start
)
957 __gitcomp
"$(__git_refs)"
967 local i c
=1 only_local_ref
="n" has_r
="n"
969 while [ $c -lt $COMP_CWORD ]; do
972 -d|
-m) only_local_ref
="y" ;;
978 case "${COMP_WORDS[COMP_CWORD]}" in
981 --color --no-color --verbose --abbrev= --no-abbrev
982 --track --no-track --contains --merged --no-merged
987 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
988 __gitcomp
"$(__git_heads)"
990 __gitcomp
"$(__git_refs)"
998 local cmd
="${COMP_WORDS[2]}"
999 case "$COMP_CWORD" in
1001 __gitcomp
"create list-heads verify unbundle"
1004 # looking for a file
1009 __git_complete_revlist
1018 __git_has_doubledash
&& return
1020 local cur
="${COMP_WORDS[COMP_CWORD]}"
1023 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1027 --quiet --ours --theirs --track --no-track --merge
1028 --conflict= --orphan --patch
1032 # check if --track, --no-track, or --no-guess was specified
1033 # if so, disable DWIM mode
1034 local flags
="--track --no-track --no-guess" track
=1
1035 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1038 __gitcomp
"$(__git_refs '' $track)"
1045 __gitcomp
"$(__git_refs)"
1050 local cur
="${COMP_WORDS[COMP_CWORD]}"
1053 __gitcomp
"--edit --no-commit"
1056 __gitcomp
"$(__git_refs)"
1063 __git_has_doubledash
&& return
1065 local cur
="${COMP_WORDS[COMP_CWORD]}"
1068 __gitcomp
"--dry-run --quiet"
1077 local cur
="${COMP_WORDS[COMP_CWORD]}"
1102 __git_has_doubledash
&& return
1104 local cur
="${COMP_WORDS[COMP_CWORD]}"
1107 __gitcomp
"default strip verbatim whitespace
1108 " "" "${cur##--cleanup=}"
1112 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1116 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1119 --untracked-files=*)
1120 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1125 --all --author= --signoff --verify --no-verify
1126 --edit --amend --include --only --interactive
1127 --dry-run --reuse-message= --reedit-message=
1128 --reset-author --file= --message= --template=
1129 --cleanup= --untracked-files --untracked-files=
1139 local cur
="${COMP_WORDS[COMP_CWORD]}"
1143 --all --tags --contains --abbrev= --candidates=
1144 --exact-match --debug --long --match --always
1148 __gitcomp
"$(__git_refs)"
1151 __git_diff_common_options
="--stat --numstat --shortstat --summary
1152 --patch-with-stat --name-only --name-status --color
1153 --no-color --color-words --no-renames --check
1154 --full-index --binary --abbrev --diff-filter=
1155 --find-copies-harder
1156 --text --ignore-space-at-eol --ignore-space-change
1157 --ignore-all-space --exit-code --quiet --ext-diff
1159 --no-prefix --src-prefix= --dst-prefix=
1160 --inter-hunk-context=
1163 --dirstat --dirstat= --dirstat-by-file
1164 --dirstat-by-file= --cumulative
1169 __git_has_doubledash
&& return
1171 local cur
="${COMP_WORDS[COMP_CWORD]}"
1174 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1175 --base --ours --theirs --no-index
1176 $__git_diff_common_options
1184 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1185 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1190 __git_has_doubledash
&& return
1192 local cur
="${COMP_WORDS[COMP_CWORD]}"
1195 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1199 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1200 --base --ours --theirs
1201 --no-renames --diff-filter= --find-copies-harder
1202 --relative --ignore-submodules
1210 __git_fetch_options
="
1211 --quiet --verbose --append --upload-pack --force --keep --depth=
1212 --tags --no-tags --all --prune --dry-run
1217 local cur
="${COMP_WORDS[COMP_CWORD]}"
1220 __gitcomp
"$__git_fetch_options"
1224 __git_complete_remote_or_refspec
1227 _git_format_patch
()
1229 local cur
="${COMP_WORDS[COMP_CWORD]}"
1234 " "" "${cur##--thread=}"
1239 --stdout --attach --no-attach --thread --thread=
1241 --numbered --start-number
1244 --signoff --signature --no-signature
1245 --in-reply-to= --cc=
1246 --full-index --binary
1249 --no-prefix --src-prefix= --dst-prefix=
1250 --inline --suffix= --ignore-if-in-upstream
1256 __git_complete_revlist
1261 local cur
="${COMP_WORDS[COMP_CWORD]}"
1265 --tags --root --unreachable --cache --no-reflogs --full
1266 --strict --verbose --lost-found
1276 local cur
="${COMP_WORDS[COMP_CWORD]}"
1279 __gitcomp
"--prune --aggressive"
1293 __git_has_doubledash
&& return
1295 local cur
="${COMP_WORDS[COMP_CWORD]}"
1300 --text --ignore-case --word-regexp --invert-match
1302 --extended-regexp --basic-regexp --fixed-strings
1303 --files-with-matches --name-only
1304 --files-without-match
1307 --and --or --not --all-match
1313 __gitcomp
"$(__git_refs)"
1318 local cur
="${COMP_WORDS[COMP_CWORD]}"
1321 __gitcomp
"--all --info --man --web"
1325 __git_compute_all_commands
1326 __gitcomp
"$__git_all_commands
1327 attributes cli core-tutorial cvs-migration
1328 diffcore gitk glossary hooks ignore modules
1329 repository-layout tutorial tutorial-2
1336 local cur
="${COMP_WORDS[COMP_CWORD]}"
1340 false true umask group all world everybody
1341 " "" "${cur##--shared=}"
1345 __gitcomp
"--quiet --bare --template= --shared --shared="
1354 __git_has_doubledash
&& return
1356 local cur
="${COMP_WORDS[COMP_CWORD]}"
1359 __gitcomp
"--cached --deleted --modified --others --ignored
1360 --stage --directory --no-empty-directory --unmerged
1361 --killed --exclude= --exclude-from=
1362 --exclude-per-directory= --exclude-standard
1363 --error-unmatch --with-tree= --full-name
1364 --abbrev --ignored --exclude-per-directory
1374 __gitcomp
"$(__git_remotes)"
1382 # Options that go well for log, shortlog and gitk
1383 __git_log_common_options
="
1385 --branches --tags --remotes
1386 --first-parent --merges --no-merges
1388 --max-age= --since= --after=
1389 --min-age= --until= --before=
1391 # Options that go well for log and gitk (not shortlog)
1392 __git_log_gitk_options
="
1393 --dense --sparse --full-history
1394 --simplify-merges --simplify-by-decoration
1397 # Options that go well for log and shortlog (not gitk)
1398 __git_log_shortlog_options
="
1399 --author= --committer= --grep=
1403 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1404 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1408 __git_has_doubledash
&& return
1410 local cur
="${COMP_WORDS[COMP_CWORD]}"
1411 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1413 if [ -f "$g/MERGE_HEAD" ]; then
1418 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1419 " "" "${cur##--pretty=}"
1423 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1424 " "" "${cur##--format=}"
1428 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1432 __gitcomp
"long short" "" "${cur##--decorate=}"
1437 $__git_log_common_options
1438 $__git_log_shortlog_options
1439 $__git_log_gitk_options
1440 --root --topo-order --date-order --reverse
1441 --follow --full-diff
1442 --abbrev-commit --abbrev=
1443 --relative-date --date=
1444 --pretty= --format= --oneline
1447 --decorate --decorate=
1449 --parents --children
1451 $__git_diff_common_options
1452 --pickaxe-all --pickaxe-regex
1457 __git_complete_revlist
1460 __git_merge_options
="
1461 --no-commit --no-stat --log --no-log --squash --strategy
1462 --commit --stat --no-squash --ff --no-ff --ff-only
1467 __git_complete_strategy
&& return
1469 local cur
="${COMP_WORDS[COMP_CWORD]}"
1472 __gitcomp
"$__git_merge_options"
1475 __gitcomp
"$(__git_refs)"
1480 local cur
="${COMP_WORDS[COMP_CWORD]}"
1483 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1496 __gitcomp
"$(__git_refs)"
1501 local cur
="${COMP_WORDS[COMP_CWORD]}"
1504 __gitcomp
"--dry-run"
1513 __gitcomp
"--tags --all --stdin"
1518 local subcommands
='add append copy edit list prune remove show'
1519 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1520 local cur
="${COMP_WORDS[COMP_CWORD]}"
1522 case "$subcommand,$cur" in
1527 case "${COMP_WORDS[COMP_CWORD-1]}" in
1529 __gitcomp
"$(__git_refs)"
1532 __gitcomp
"$subcommands --ref"
1536 add
,--reuse-message=*|append
,--reuse-message=*)
1537 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1539 add
,--reedit-message=*|append
,--reedit-message=*)
1540 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1543 __gitcomp
'--file= --message= --reedit-message=
1550 __gitcomp
'--dry-run --verbose'
1555 case "${COMP_WORDS[COMP_CWORD-1]}" in
1559 __gitcomp
"$(__git_refs)"
1568 __git_complete_strategy
&& return
1570 local cur
="${COMP_WORDS[COMP_CWORD]}"
1574 --rebase --no-rebase
1575 $__git_merge_options
1576 $__git_fetch_options
1581 __git_complete_remote_or_refspec
1586 local cur
="${COMP_WORDS[COMP_CWORD]}"
1587 case "${COMP_WORDS[COMP_CWORD-1]}" in
1589 __gitcomp
"$(__git_remotes)"
1594 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1599 --all --mirror --tags --dry-run --force --verbose
1600 --receive-pack= --repo=
1605 __git_complete_remote_or_refspec
1610 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
1611 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1612 __gitcomp
"--continue --skip --abort"
1615 __git_complete_strategy
&& return
1618 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1623 --onto --merge --strategy --interactive
1624 --preserve-merges --stat --no-stat
1625 --committer-date-is-author-date --ignore-date
1626 --ignore-whitespace --whitespace=
1632 __gitcomp
"$(__git_refs)"
1635 __git_send_email_confirm_options
="always never auto cc compose"
1636 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1640 local cur
="${COMP_WORDS[COMP_CWORD]}"
1644 $__git_send_email_confirm_options
1645 " "" "${cur##--confirm=}"
1650 $__git_send_email_suppresscc_options
1651 " "" "${cur##--suppress-cc=}"
1655 --smtp-encryption=*)
1656 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1660 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1661 --compose --confirm= --dry-run --envelope-sender
1663 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1664 --no-suppress-from --no-thread --quiet
1665 --signed-off-by-cc --smtp-pass --smtp-server
1666 --smtp-server-port --smtp-encryption= --smtp-user
1667 --subject --suppress-cc= --suppress-from --thread --to
1668 --validate --no-validate"
1680 __git_config_get_set_variables
()
1682 local prevword word config_file
= c
=$COMP_CWORD
1683 while [ $c -gt 1 ]; do
1684 word
="${COMP_WORDS[c]}"
1686 --global|
--system|
--file=*)
1691 config_file
="$word $prevword"
1699 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1712 local cur
="${COMP_WORDS[COMP_CWORD]}"
1713 local prv
="${COMP_WORDS[COMP_CWORD-1]}"
1716 __gitcomp
"$(__git_remotes)"
1720 __gitcomp
"$(__git_refs)"
1724 local remote
="${prv#remote.}"
1725 remote
="${remote%.fetch}"
1726 __gitcomp
"$(__git_refs_remotes "$remote")"
1730 local remote
="${prv#remote.}"
1731 remote
="${remote%.push}"
1732 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1733 for-each-ref --format='%(refname):%(refname)' \
1737 pull.twohead|pull.octopus
)
1738 __git_compute_merge_strategies
1739 __gitcomp
"$__git_merge_strategies"
1742 color.branch|color.
diff|color.interactive|\
1743 color.showbranch|color.status|color.ui
)
1744 __gitcomp
"always never auto"
1748 __gitcomp
"false true"
1753 normal black red green yellow blue magenta cyan white
1754 bold dim ul blink reverse
1759 __gitcomp
"man info web html"
1763 __gitcomp
"$__git_log_date_formats"
1766 sendemail.aliasesfiletype
)
1767 __gitcomp
"mutt mailrc pine elm gnus"
1771 __gitcomp
"$__git_send_email_confirm_options"
1774 sendemail.suppresscc
)
1775 __gitcomp
"$__git_send_email_suppresscc_options"
1778 --get|
--get-all|
--unset|
--unset-all)
1779 __gitcomp
"$(__git_config_get_set_variables)"
1790 --global --system --file=
1791 --list --replace-all
1792 --get --get-all --get-regexp
1793 --add --unset --unset-all
1794 --remove-section --rename-section
1799 local pfx
="${cur%.*}."
1801 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur"
1805 local pfx
="${cur%.*}."
1807 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1811 local pfx
="${cur%.*}."
1814 argprompt cmd confirm needsfile noconsole norescan
1815 prompt revprompt revunmerged title
1820 local pfx
="${cur%.*}."
1822 __gitcomp
"cmd path" "$pfx" "$cur"
1826 local pfx
="${cur%.*}."
1828 __gitcomp
"cmd path" "$pfx" "$cur"
1832 local pfx
="${cur%.*}."
1834 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1838 local pfx
="${cur%.*}."
1840 __git_compute_all_commands
1841 __gitcomp
"$__git_all_commands" "$pfx" "$cur"
1845 local pfx
="${cur%.*}."
1848 url proxy fetch push mirror skipDefaultUpdate
1849 receivepack uploadpack tagopt pushurl
1854 local pfx
="${cur%.*}."
1856 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1860 local pfx
="${cur%.*}."
1862 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur"
1869 apply.ignorewhitespace
1871 branch.autosetupmerge
1872 branch.autosetuprebase
1875 color.branch.current
1886 color.diff.whitespace
1891 color.interactive.header
1892 color.interactive.help
1893 color.interactive.prompt
1898 color.status.changed
1900 color.status.nobranch
1901 color.status.untracked
1902 color.status.updated
1909 core.deltaBaseCacheLimit
1913 core.fsyncobjectfiles
1915 core.ignoreCygwinFSTricks
1917 core.logAllRefUpdates
1918 core.loosecompression
1920 core.packedGitWindowSize
1922 core.preferSymlinkRefs
1925 core.repositoryFormatVersion
1927 core.sharedRepository
1930 core.warnAmbiguousRefs
1933 diff.autorefreshindex
1939 diff.suppressBlankEmpty
1952 format.subjectprefix
1961 gc.reflogexpireunreachable
1965 gitcvs.commitmsgannotation
1966 gitcvs.dbTableNamePrefix
1977 gui.copyblamethreshold
1981 gui.matchtrackingbranch
1982 gui.newbranchtemplate
1983 gui.pruneduringfetch
1984 gui.spellingdictionary
2000 i18n.logOutputEncoding
2005 imap.preformattedHTML
2014 interactive.singlekey
2027 mergetool.keepBackup
2030 pack.deltaCacheLimit
2043 receive.denyCurrentBranch
2045 receive.denyNonFastForwards
2048 repack.usedeltabaseoffset
2051 sendemail.aliasesfile
2052 sendemail.aliasesfiletype
2056 sendemail.chainreplyto
2058 sendemail.envelopesender
2060 sendemail.signedoffbycc
2061 sendemail.smtpencryption
2063 sendemail.smtpserver
2064 sendemail.smtpserverport
2066 sendemail.suppresscc
2067 sendemail.suppressfrom
2072 status.relativePaths
2073 status.showUntrackedFiles
2075 transfer.unpackLimit
2087 local subcommands
="add rename rm show prune update set-head"
2088 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2089 if [ -z "$subcommand" ]; then
2090 __gitcomp
"$subcommands"
2094 case "$subcommand" in
2095 rename|
rm|show|prune
)
2096 __gitcomp
"$(__git_remotes)"
2099 local i c
='' IFS
=$
'\n'
2100 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2114 __gitcomp
"$(__git_refs)"
2119 __git_has_doubledash
&& return
2121 local cur
="${COMP_WORDS[COMP_CWORD]}"
2124 __gitcomp
"--merge --mixed --hard --soft --patch"
2128 __gitcomp
"$(__git_refs)"
2133 local cur
="${COMP_WORDS[COMP_CWORD]}"
2136 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2140 __gitcomp
"$(__git_refs)"
2145 __git_has_doubledash
&& return
2147 local cur
="${COMP_WORDS[COMP_CWORD]}"
2150 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2159 __git_has_doubledash
&& return
2161 local cur
="${COMP_WORDS[COMP_CWORD]}"
2165 $__git_log_common_options
2166 $__git_log_shortlog_options
2167 --numbered --summary
2172 __git_complete_revlist
2177 __git_has_doubledash
&& return
2179 local cur
="${COMP_WORDS[COMP_CWORD]}"
2182 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2183 " "" "${cur##--pretty=}"
2187 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2188 " "" "${cur##--format=}"
2192 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2193 $__git_diff_common_options
2203 local cur
="${COMP_WORDS[COMP_CWORD]}"
2207 --all --remotes --topo-order --current --more=
2208 --list --independent --merge-base --no-name
2210 --sha1-name --sparse --topics --reflog
2215 __git_complete_revlist
2220 local cur
="${COMP_WORDS[COMP_CWORD]}"
2221 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2222 local subcommands
='save list show apply clear drop pop create branch'
2223 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2224 if [ -z "$subcommand" ]; then
2227 __gitcomp
"$save_opts"
2230 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2231 __gitcomp
"$subcommands"
2238 case "$subcommand,$cur" in
2240 __gitcomp
"$save_opts"
2243 __gitcomp
"--index --quiet"
2245 show
,--*|drop
,--*|branch
,--*)
2248 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2249 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
2250 | sed -n -e 's/:.*//p')"
2261 __git_has_doubledash
&& return
2263 local subcommands
="add status init update summary foreach sync"
2264 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2265 local cur
="${COMP_WORDS[COMP_CWORD]}"
2268 __gitcomp
"--quiet --cached"
2271 __gitcomp
"$subcommands"
2281 init fetch clone rebase dcommit log find-rev
2282 set-tree commit-diff info create-ignore propget
2283 proplist show-ignore show-externals branch tag blame
2284 migrate mkdirs reset gc
2286 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2287 if [ -z "$subcommand" ]; then
2288 __gitcomp
"$subcommands"
2290 local remote_opts
="--username= --config-dir= --no-auth-cache"
2292 --follow-parent --authors-file= --repack=
2293 --no-metadata --use-svm-props --use-svnsync-props
2294 --log-window-size= --no-checkout --quiet
2295 --repack-flags --use-log-author --localtime
2296 --ignore-paths= $remote_opts
2299 --template= --shared= --trunk= --tags=
2300 --branches= --stdlayout --minimize-url
2301 --no-metadata --use-svm-props --use-svnsync-props
2302 --rewrite-root= --prefix= --use-log-author
2303 --add-author-from $remote_opts
2306 --edit --rmdir --find-copies-harder --copy-similarity=
2309 local cur
="${COMP_WORDS[COMP_CWORD]}"
2310 case "$subcommand,$cur" in
2312 __gitcomp
"--revision= --fetch-all $fc_opts"
2315 __gitcomp
"--revision= $fc_opts $init_opts"
2318 __gitcomp
"$init_opts"
2322 --merge --strategy= --verbose --dry-run
2323 --fetch-all --no-rebase --commit-url
2324 --revision $cmt_opts $fc_opts
2328 __gitcomp
"--stdin $cmt_opts $fc_opts"
2330 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2331 show-externals
,--*|mkdirs
,--*)
2332 __gitcomp
"--revision="
2336 --limit= --revision= --verbose --incremental
2337 --oneline --show-commit --non-recursive
2338 --authors-file= --color
2343 --merge --verbose --strategy= --local
2344 --fetch-all --dry-run $fc_opts
2348 __gitcomp
"--message= --file= --revision= $cmt_opts"
2354 __gitcomp
"--dry-run --message --tag"
2357 __gitcomp
"--dry-run --message"
2360 __gitcomp
"--git-format"
2364 --config-dir= --ignore-paths= --minimize
2365 --no-auth-cache --username=
2369 __gitcomp
"--revision= --parent"
2381 while [ $c -lt $COMP_CWORD ]; do
2382 i
="${COMP_WORDS[c]}"
2385 __gitcomp
"$(__git_tags)"
2395 case "${COMP_WORDS[COMP_CWORD-1]}" in
2401 __gitcomp
"$(__git_tags)"
2407 __gitcomp
"$(__git_refs)"
2419 local i c
=1 command __git_dir
2421 if [[ -n ${ZSH_VERSION-} ]]; then
2426 while [ $c -lt $COMP_CWORD ]; do
2427 i
="${COMP_WORDS[c]}"
2429 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2430 --bare) __git_dir
="." ;;
2431 --version|
-p|
--paginate) ;;
2432 --help) command="help"; break ;;
2433 *) command="$i"; break ;;
2438 if [ -z "$command" ]; then
2439 case "${COMP_WORDS[COMP_CWORD]}" in
2452 *) __git_compute_porcelain_commands
2453 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2458 local completion_func
="_git_${command//-/_}"
2459 declare -f $completion_func >/dev
/null
&& $completion_func && return
2461 local expansion
=$
(__git_aliased_command
"$command")
2462 if [ -n "$expansion" ]; then
2463 completion_func
="_git_${expansion//-/_}"
2464 declare -f $completion_func >/dev
/null
&& $completion_func
2470 if [[ -n ${ZSH_VERSION-} ]]; then
2475 __git_has_doubledash
&& return
2477 local cur
="${COMP_WORDS[COMP_CWORD]}"
2478 local g
="$(__gitdir)"
2480 if [ -f "$g/MERGE_HEAD" ]; then
2486 $__git_log_common_options
2487 $__git_log_gitk_options
2493 __git_complete_revlist
2496 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2497 || complete
-o default
-o nospace
-F _git git
2498 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2499 || complete
-o default
-o nospace
-F _gitk gitk
2501 # The following are necessary only for Cygwin, and only are needed
2502 # when the user has tab-completed the executable name and consequently
2503 # included the '.exe' suffix.
2505 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2506 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2507 || complete
-o default
-o nospace
-F _git git.exe
2510 if [[ -n ${ZSH_VERSION-} ]]; then
2513 if [ $# -ne 2 ]; then
2514 echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2522 echo "$0: invalid option: $2" >&2
2526 -q) setopt |
grep -q "$option" ;;
2527 -u) unsetopt
"$option" ;;
2528 -s) setopt
"$option" ;;
2530 echo "$0: invalid flag: $1" >&2