3 # bash completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 # 2) Added the following line to your .bashrc:
22 # source ~/.git-completion.sh
24 # 3) Consider changing your PS1 to also show the current branch:
25 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
27 # The argument to __git_ps1 will be displayed only if you
28 # are currently in a git repository. The %s token will be
29 # the name of the current branch.
31 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
32 # value, unstaged (*) and staged (+) changes will be shown next
33 # to the branch name. You can configure this per-repository
34 # with the bash.showDirtyState variable, which defaults to true
35 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
37 # You can also see if currently something is stashed, by setting
38 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
39 # then a '$' will be shown next to the branch name.
41 # If you would like to see if there're untracked files, then you can
42 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
43 # untracked files, then a '%' will be shown next to the branch name.
45 # If you would like to see the difference between HEAD and its
46 # upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates
47 # you are behind, ">" indicates you are ahead, and "<>"
48 # indicates you have diverged. You can further control
49 # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
51 # verbose show number of commits ahead/behind (+/-) upstream
52 # legacy don't use the '--count' option available in recent
53 # versions of git-rev-list
54 # git always compare HEAD to @{upstream}
55 # svn always compare HEAD to your SVN upstream
56 # By default, __git_ps1 will compare HEAD to your SVN upstream
57 # if it can find one, or @{upstream} otherwise. Once you have
58 # set GIT_PS1_SHOWUPSTREAM, you can override it on a
59 # per-repository basis by setting the bash.showUpstream config
65 # *) Read Documentation/SubmittingPatches
66 # *) Send all patches to the current maintainer:
68 # "Shawn O. Pearce" <spearce@spearce.org>
70 # *) Always CC the Git mailing list:
75 case "$COMP_WORDBREAKS" in
77 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
80 # __gitdir accepts 0 or 1 arguments (i.e., location)
81 # returns location of .git repo
84 if [ -z "${1-}" ]; then
85 if [ -n "${__git_dir-}" ]; then
87 elif [ -d .git
]; then
90 git rev-parse
--git-dir 2>/dev
/null
92 elif [ -d "$1/.git" ]; then
99 # stores the divergence from upstream in $p
100 # used by GIT_PS1_SHOWUPSTREAM
101 __git_ps1_show_upstream
()
104 local svn_remote
=() svn_url_pattern count n
105 local upstream
=git legacy
="" verbose
=""
107 # get some config options from git-config
108 while read key value
; do
111 GIT_PS1_SHOWUPSTREAM
="$value"
112 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
118 svn_remote
[ $
((${#svn_remote[@]} + 1)) ]="$value"
119 svn_url_pattern
+="\\|$value"
120 upstream
=svn
+git
# default upstream is SVN if available, else git
123 done < <(git config
-z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev
/null |
tr '\0\n' '\n ')
125 # parse configuration values
126 for option
in ${GIT_PS1_SHOWUPSTREAM}; do
128 git|svn
) upstream
="$option" ;;
129 verbose
) verbose
=1 ;;
136 git
) upstream
="@{upstream}" ;;
138 # get the upstream from the "git-svn-id: ..." in a commit message
139 # (git-svn uses essentially the same procedure internally)
140 local svn_upstream
=($
(git log
--first-parent -1 \
141 --grep="^git-svn-id: \(${svn_url_pattern:2}\)" 2>/dev
/null
))
142 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
143 svn_upstream
=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
144 svn_upstream
=${svn_upstream%@*}
145 for ((n
=1; "$n" <= "${#svn_remote[@]}"; ++n
)); do
146 svn_upstream
=${svn_upstream#${svn_remote[$n]}}
149 if [[ -z "$svn_upstream" ]]; then
150 # default branch name for checkouts with no layout:
151 upstream
=${GIT_SVN_ID:-git-svn}
153 upstream
=${svn_upstream#/}
155 elif [[ "svn+git" = "$upstream" ]]; then
156 upstream
="@{upstream}"
161 # Find how many commits we are ahead/behind our upstream
162 if [[ -z "$legacy" ]]; then
163 count
="$(git rev-list --count --left-right \
164 "$upstream"...HEAD 2>/dev/null)"
166 # produce equivalent output to --count for older versions of git
168 if commits
="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
170 local commit behind
=0 ahead
=0
171 for commit
in $commits
180 count
="$behind $ahead"
186 # calculate the result
187 if [[ -z "$verbose" ]]; then
191 "0 0") # equal to upstream
193 "0 "*) # ahead of upstream
195 *" 0") # behind upstream
197 *) # diverged from upstream
204 "0 0") # equal to upstream
206 "0 "*) # ahead of upstream
207 p
=" u+${count#0 }" ;;
208 *" 0") # behind upstream
209 p
=" u-${count% 0}" ;;
210 *) # diverged from upstream
211 p
=" u+${count#* }-${count% *}" ;;
218 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
219 # returns text to add to bash PS1 prompt (includes branch name)
222 local g
="$(__gitdir)"
226 if [ -f "$g/rebase-merge/interactive" ]; then
228 b
="$(cat "$g/rebase-merge
/head-name
")"
229 elif [ -d "$g/rebase-merge" ]; then
231 b
="$(cat "$g/rebase-merge
/head-name
")"
233 if [ -d "$g/rebase-apply" ]; then
234 if [ -f "$g/rebase-apply/rebasing" ]; then
236 elif [ -f "$g/rebase-apply/applying" ]; then
241 elif [ -f "$g/MERGE_HEAD" ]; then
243 elif [ -f "$g/BISECT_LOG" ]; then
247 b
="$(git symbolic-ref HEAD 2>/dev/null)" ||
{
250 case "${GIT_PS1_DESCRIBE_STYLE-}" in
252 git describe --contains HEAD ;;
254 git describe --contains --all HEAD ;;
258 git describe --exact-match HEAD ;;
259 esac 2>/dev/null)" ||
261 b
="$(cut -c1-7 "$g/HEAD
" 2>/dev/null)..." ||
274 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
275 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
280 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
281 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
282 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
283 git
diff --no-ext-diff --quiet --exit-code || w
="*"
284 if git rev-parse
--quiet --verify HEAD
>/dev
/null
; then
285 git diff-index
--cached --quiet HEAD
-- || i
="+"
291 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
292 git rev-parse
--verify refs
/stash
>/dev
/null
2>&1 && s
="$"
295 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
296 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
301 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
302 __git_ps1_show_upstream
307 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
311 # __gitcomp_1 requires 2 arguments
314 local c IFS
=' '$
'\t'$
'\n'
317 --*=*) printf %s$
'\n' "$c$2" ;;
318 *.
) printf %s$
'\n' "$c$2" ;;
319 *) printf %s$
'\n' "$c$2 " ;;
324 # __gitcomp accepts 1, 2, 3, or 4 arguments
325 # generates completion reply with compgen
328 local cur
="${COMP_WORDS[COMP_CWORD]}"
329 if [ $# -gt 2 ]; then
338 COMPREPLY
=($
(compgen
-P "${2-}" \
339 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
345 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
348 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
349 if [ -d "$dir" ]; then
350 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
354 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
355 case "$is_hash,$i" in
358 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
359 n
,*) is_hash
=y
; echo "$i" ;;
364 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
367 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
368 if [ -d "$dir" ]; then
369 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
373 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
374 case "$is_hash,$i" in
377 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
378 n
,*) is_hash
=y
; echo "$i" ;;
383 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
384 # presence of 2nd argument means use the guess heuristic employed
385 # by checkout for tracking branches
388 local i is_hash
=y dir
="$(__gitdir "${1-}")" track
="${2-}"
389 local cur
="${COMP_WORDS[COMP_CWORD]}" format refs
390 if [ -d "$dir" ]; then
398 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
399 if [ -e "$dir/$i" ]; then echo $i; fi
401 format
="refname:short"
402 refs
="refs/tags refs/heads refs/remotes"
405 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
407 if [ -n "$track" ]; then
408 # employ the heuristic used by git checkout
409 # Try to find a remote branch that matches the completion word
410 # but only output if the branch name is unique
412 git
--git-dir="$dir" for-each-ref
--shell --format="ref=%(refname:short)" \
417 if [[ "$ref" == "$cur"* ]]; then
424 for i
in $
(git ls-remote
"$dir" 2>/dev
/null
); do
425 case "$is_hash,$i" in
428 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
429 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
430 n
,refs
/remotes
/*) is_hash
=y
; echo "${i#refs/remotes/}" ;;
431 n
,*) is_hash
=y
; echo "$i" ;;
436 # __git_refs2 requires 1 argument (to pass to __git_refs)
440 for i
in $
(__git_refs
"$1"); do
445 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
446 __git_refs_remotes
()
448 local cmd i is_hash
=y
449 for i
in $
(git ls-remote
"$1" 2>/dev
/null
); do
450 case "$is_hash,$i" in
453 echo "$i:refs/remotes/$1/${i#refs/heads/}"
457 n
,refs
/tags
/*) is_hash
=y
;;
465 local i ngoff IFS
=$
'\n' d
="$(__gitdir)"
466 shopt -q nullglob || ngoff
=1
468 for i
in "$d/remotes"/*; do
469 echo ${i#$d/remotes/}
471 [ "$ngoff" ] && shopt -u nullglob
472 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
478 __git_list_merge_strategies
()
480 git merge
-s help 2>&1 |
481 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
490 __git_merge_strategies
=
491 # 'git merge -s help' (and thus detection of the merge strategy
492 # list) fails, unfortunately, if run outside of any git working
493 # tree. __git_merge_strategies is set to the empty string in
494 # that case, and the detection will be repeated the next time it
496 __git_compute_merge_strategies
()
498 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
501 __git_complete_file
()
503 local pfx
ls ref cur
="${COMP_WORDS[COMP_CWORD]}"
520 case "$COMP_WORDBREAKS" in
522 *) pfx
="$ref:$pfx" ;;
526 COMPREPLY
=($
(compgen
-P "$pfx" \
527 -W "$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" \
528 | sed '/^100... blob /{
544 __gitcomp
"$(__git_refs)"
549 __git_complete_revlist
()
551 local pfx cur
="${COMP_WORDS[COMP_CWORD]}"
556 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
561 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
564 __gitcomp
"$(__git_refs)"
569 __git_complete_remote_or_refspec
()
571 local cmd
="${COMP_WORDS[1]}"
572 local cur
="${COMP_WORDS[COMP_CWORD]}"
573 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
574 while [ $c -lt $COMP_CWORD ]; do
577 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
580 push
) no_complete_refspec
=1 ;;
589 *) remote
="$i"; break ;;
593 if [ -z "$remote" ]; then
594 __gitcomp
"$(__git_remotes)"
597 if [ $no_complete_refspec = 1 ]; then
601 [ "$remote" = "." ] && remote
=
604 case "$COMP_WORDBREAKS" in
606 *) pfx
="${cur%%:*}:" ;;
618 if [ $lhs = 1 ]; then
619 __gitcomp
"$(__git_refs2 "$remote")" "$pfx" "$cur"
621 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
625 if [ $lhs = 1 ]; then
626 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
628 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
632 if [ $lhs = 1 ]; then
633 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
635 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
641 __git_complete_strategy
()
643 __git_compute_merge_strategies
644 case "${COMP_WORDS[COMP_CWORD-1]}" in
646 __gitcomp
"$__git_merge_strategies"
649 local cur
="${COMP_WORDS[COMP_CWORD]}"
652 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
659 __git_list_all_commands
()
662 for i
in $
(git
help -a|
egrep '^ [a-zA-Z0-9]')
665 *--*) : helper pattern
;;
672 __git_compute_all_commands
()
674 : ${__git_all_commands:=$(__git_list_all_commands)}
677 __git_list_porcelain_commands
()
680 __git_compute_all_commands
681 for i
in "help" $__git_all_commands
684 *--*) : helper pattern
;;
685 applymbox
) : ask gittus
;;
686 applypatch
) : ask gittus
;;
687 archimport
) : import
;;
688 cat-file
) : plumbing
;;
689 check-attr
) : plumbing
;;
690 check-ref-format
) : plumbing
;;
691 checkout-index
) : plumbing
;;
692 commit-tree
) : plumbing
;;
693 count-objects
) : infrequent
;;
694 cvsexportcommit
) : export;;
695 cvsimport
) : import
;;
696 cvsserver
) : daemon
;;
698 diff-files
) : plumbing
;;
699 diff-index
) : plumbing
;;
700 diff-tree
) : plumbing
;;
701 fast-import
) : import
;;
702 fast-export
) : export;;
703 fsck-objects
) : plumbing
;;
704 fetch-pack
) : plumbing
;;
705 fmt-merge-msg
) : plumbing
;;
706 for-each-ref
) : plumbing
;;
707 hash-object
) : plumbing
;;
708 http-
*) : transport
;;
709 index-pack
) : plumbing
;;
710 init-db
) : deprecated
;;
711 local-fetch
) : plumbing
;;
712 lost-found
) : infrequent
;;
713 ls-files
) : plumbing
;;
714 ls-remote
) : plumbing
;;
715 ls-tree
) : plumbing
;;
716 mailinfo
) : plumbing
;;
717 mailsplit
) : plumbing
;;
718 merge-
*) : plumbing
;;
721 pack-objects
) : plumbing
;;
722 pack-redundant
) : plumbing
;;
723 pack-refs
) : plumbing
;;
724 parse-remote
) : plumbing
;;
725 patch-id
) : plumbing
;;
726 peek-remote
) : plumbing
;;
728 prune-packed
) : plumbing
;;
729 quiltimport
) : import
;;
730 read-tree
) : plumbing
;;
731 receive-pack
) : plumbing
;;
733 remote-
*) : transport
;;
734 repo-config
) : deprecated
;;
736 rev-list
) : plumbing
;;
737 rev-parse
) : plumbing
;;
738 runstatus
) : plumbing
;;
739 sh-setup
) : internal
;;
741 show-ref
) : plumbing
;;
742 send-pack
) : plumbing
;;
743 show-index
) : plumbing
;;
745 stripspace
) : plumbing
;;
746 symbolic-ref
) : plumbing
;;
747 tar-tree
) : deprecated
;;
748 unpack-file
) : plumbing
;;
749 unpack-objects
) : plumbing
;;
750 update-index
) : plumbing
;;
751 update-ref
) : plumbing
;;
752 update-server-info
) : daemon
;;
753 upload-archive
) : plumbing
;;
754 upload-pack
) : plumbing
;;
755 write-tree
) : plumbing
;;
757 verify-pack
) : infrequent
;;
758 verify-tag
) : plumbing
;;
764 __git_porcelain_commands
=
765 __git_compute_porcelain_commands
()
767 __git_compute_all_commands
768 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
774 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
784 # __git_aliased_command requires 1 argument
785 __git_aliased_command
()
787 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
788 config
--get "alias.$1")
789 for word
in $cmdline; do
795 \
!*) : shell
command alias ;;
797 *=*) : setting env
;;
806 # __git_find_on_cmdline requires 1 argument
807 __git_find_on_cmdline
()
809 local word subcommand c
=1
811 while [ $c -lt $COMP_CWORD ]; do
812 word
="${COMP_WORDS[c]}"
813 for subcommand
in $1; do
814 if [ "$subcommand" = "$word" ]; then
823 __git_has_doubledash
()
826 while [ $c -lt $COMP_CWORD ]; do
827 if [ "--" = "${COMP_WORDS[c]}" ]; then
835 __git_whitespacelist
="nowarn warn error error-all fix"
839 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
840 if [ -d "$dir"/rebase-apply
]; then
841 __gitcomp
"--skip --continue --resolved --abort"
846 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
851 --3way --committer-date-is-author-date --ignore-date
852 --ignore-whitespace --ignore-space-change
853 --interactive --keep --no-utf8 --signoff --utf8
854 --whitespace= --scissors
863 local cur
="${COMP_WORDS[COMP_CWORD]}"
866 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
871 --stat --numstat --summary --check --index
872 --cached --index-info --reverse --reject --unidiff-zero
873 --apply --no-add --exclude=
874 --ignore-whitespace --ignore-space-change
875 --whitespace= --inaccurate-eof --verbose
884 __git_has_doubledash
&& return
886 local cur
="${COMP_WORDS[COMP_CWORD]}"
890 --interactive --refresh --patch --update --dry-run
891 --ignore-errors --intent-to-add
900 local cur
="${COMP_WORDS[COMP_CWORD]}"
903 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
907 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
912 --format= --list --verbose
913 --prefix= --remote= --exec=
923 __git_has_doubledash
&& return
925 local subcommands
="start bad good skip reset visualize replay log run"
926 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
927 if [ -z "$subcommand" ]; then
928 __gitcomp
"$subcommands"
932 case "$subcommand" in
934 __gitcomp
"$(__git_refs)"
944 local i c
=1 only_local_ref
="n" has_r
="n"
946 while [ $c -lt $COMP_CWORD ]; do
949 -d|
-m) only_local_ref
="y" ;;
955 case "${COMP_WORDS[COMP_CWORD]}" in
958 --color --no-color --verbose --abbrev= --no-abbrev
959 --track --no-track --contains --merged --no-merged
964 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
965 __gitcomp
"$(__git_heads)"
967 __gitcomp
"$(__git_refs)"
975 local cmd
="${COMP_WORDS[2]}"
976 case "$COMP_CWORD" in
978 __gitcomp
"create list-heads verify unbundle"
986 __git_complete_revlist
995 __git_has_doubledash
&& return
997 local cur
="${COMP_WORDS[COMP_CWORD]}"
1000 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1004 --quiet --ours --theirs --track --no-track --merge
1005 --conflict= --orphan --patch
1009 # check if --track, --no-track, or --no-guess was specified
1010 # if so, disable DWIM mode
1011 local flags
="--track --no-track --no-guess" track
=1
1012 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1015 __gitcomp
"$(__git_refs '' $track)"
1022 __gitcomp
"$(__git_refs)"
1027 local cur
="${COMP_WORDS[COMP_CWORD]}"
1030 __gitcomp
"--edit --no-commit"
1033 __gitcomp
"$(__git_refs)"
1040 __git_has_doubledash
&& return
1042 local cur
="${COMP_WORDS[COMP_CWORD]}"
1045 __gitcomp
"--dry-run --quiet"
1054 local cur
="${COMP_WORDS[COMP_CWORD]}"
1079 __git_has_doubledash
&& return
1081 local cur
="${COMP_WORDS[COMP_CWORD]}"
1084 __gitcomp
"default strip verbatim whitespace
1085 " "" "${cur##--cleanup=}"
1089 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1093 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1096 --untracked-files=*)
1097 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1102 --all --author= --signoff --verify --no-verify
1103 --edit --amend --include --only --interactive
1104 --dry-run --reuse-message= --reedit-message=
1105 --reset-author --file= --message= --template=
1106 --cleanup= --untracked-files --untracked-files=
1116 local cur
="${COMP_WORDS[COMP_CWORD]}"
1120 --all --tags --contains --abbrev= --candidates=
1121 --exact-match --debug --long --match --always
1125 __gitcomp
"$(__git_refs)"
1128 __git_diff_common_options
="--stat --numstat --shortstat --summary
1129 --patch-with-stat --name-only --name-status --color
1130 --no-color --color-words --no-renames --check
1131 --full-index --binary --abbrev --diff-filter=
1132 --find-copies-harder
1133 --text --ignore-space-at-eol --ignore-space-change
1134 --ignore-all-space --exit-code --quiet --ext-diff
1136 --no-prefix --src-prefix= --dst-prefix=
1137 --inter-hunk-context=
1140 --dirstat --dirstat= --dirstat-by-file
1141 --dirstat-by-file= --cumulative
1146 __git_has_doubledash
&& return
1148 local cur
="${COMP_WORDS[COMP_CWORD]}"
1151 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1152 --base --ours --theirs --no-index
1153 $__git_diff_common_options
1161 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1162 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1167 __git_has_doubledash
&& return
1169 local cur
="${COMP_WORDS[COMP_CWORD]}"
1172 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1176 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1177 --base --ours --theirs
1178 --no-renames --diff-filter= --find-copies-harder
1179 --relative --ignore-submodules
1187 __git_fetch_options
="
1188 --quiet --verbose --append --upload-pack --force --keep --depth=
1189 --tags --no-tags --all --prune --dry-run
1194 local cur
="${COMP_WORDS[COMP_CWORD]}"
1197 __gitcomp
"$__git_fetch_options"
1201 __git_complete_remote_or_refspec
1204 _git_format_patch
()
1206 local cur
="${COMP_WORDS[COMP_CWORD]}"
1211 " "" "${cur##--thread=}"
1216 --stdout --attach --no-attach --thread --thread=
1218 --numbered --start-number
1221 --signoff --signature --no-signature
1222 --in-reply-to= --cc=
1223 --full-index --binary
1226 --no-prefix --src-prefix= --dst-prefix=
1227 --inline --suffix= --ignore-if-in-upstream
1233 __git_complete_revlist
1238 local cur
="${COMP_WORDS[COMP_CWORD]}"
1242 --tags --root --unreachable --cache --no-reflogs --full
1243 --strict --verbose --lost-found
1253 local cur
="${COMP_WORDS[COMP_CWORD]}"
1256 __gitcomp
"--prune --aggressive"
1270 __git_has_doubledash
&& return
1272 local cur
="${COMP_WORDS[COMP_CWORD]}"
1277 --text --ignore-case --word-regexp --invert-match
1279 --extended-regexp --basic-regexp --fixed-strings
1280 --files-with-matches --name-only
1281 --files-without-match
1284 --and --or --not --all-match
1290 __gitcomp
"$(__git_refs)"
1295 local cur
="${COMP_WORDS[COMP_CWORD]}"
1298 __gitcomp
"--all --info --man --web"
1302 __git_compute_all_commands
1303 __gitcomp
"$__git_all_commands
1304 attributes cli core-tutorial cvs-migration
1305 diffcore gitk glossary hooks ignore modules
1306 repository-layout tutorial tutorial-2
1313 local cur
="${COMP_WORDS[COMP_CWORD]}"
1317 false true umask group all world everybody
1318 " "" "${cur##--shared=}"
1322 __gitcomp
"--quiet --bare --template= --shared --shared="
1331 __git_has_doubledash
&& return
1333 local cur
="${COMP_WORDS[COMP_CWORD]}"
1336 __gitcomp
"--cached --deleted --modified --others --ignored
1337 --stage --directory --no-empty-directory --unmerged
1338 --killed --exclude= --exclude-from=
1339 --exclude-per-directory= --exclude-standard
1340 --error-unmatch --with-tree= --full-name
1341 --abbrev --ignored --exclude-per-directory
1351 __gitcomp
"$(__git_remotes)"
1359 # Options that go well for log, shortlog and gitk
1360 __git_log_common_options
="
1362 --branches --tags --remotes
1363 --first-parent --merges --no-merges
1365 --max-age= --since= --after=
1366 --min-age= --until= --before=
1368 # Options that go well for log and gitk (not shortlog)
1369 __git_log_gitk_options
="
1370 --dense --sparse --full-history
1371 --simplify-merges --simplify-by-decoration
1374 # Options that go well for log and shortlog (not gitk)
1375 __git_log_shortlog_options
="
1376 --author= --committer= --grep=
1380 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1381 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1385 __git_has_doubledash
&& return
1387 local cur
="${COMP_WORDS[COMP_CWORD]}"
1388 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1390 if [ -f "$g/MERGE_HEAD" ]; then
1395 __gitcomp
"$__git_log_pretty_formats
1396 " "" "${cur##--pretty=}"
1400 __gitcomp
"$__git_log_pretty_formats
1401 " "" "${cur##--format=}"
1405 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1409 __gitcomp
"long short" "" "${cur##--decorate=}"
1414 $__git_log_common_options
1415 $__git_log_shortlog_options
1416 $__git_log_gitk_options
1417 --root --topo-order --date-order --reverse
1418 --follow --full-diff
1419 --abbrev-commit --abbrev=
1420 --relative-date --date=
1421 --pretty= --format= --oneline
1424 --decorate --decorate=
1426 --parents --children
1428 $__git_diff_common_options
1429 --pickaxe-all --pickaxe-regex
1434 __git_complete_revlist
1437 __git_merge_options
="
1438 --no-commit --no-stat --log --no-log --squash --strategy
1439 --commit --stat --no-squash --ff --no-ff --ff-only
1444 __git_complete_strategy
&& return
1446 local cur
="${COMP_WORDS[COMP_CWORD]}"
1449 __gitcomp
"$__git_merge_options"
1452 __gitcomp
"$(__git_refs)"
1457 local cur
="${COMP_WORDS[COMP_CWORD]}"
1460 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1473 __gitcomp
"$(__git_refs)"
1478 local cur
="${COMP_WORDS[COMP_CWORD]}"
1481 __gitcomp
"--dry-run"
1490 __gitcomp
"--tags --all --stdin"
1495 local subcommands
="edit show"
1496 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1497 __gitcomp
"$subcommands"
1501 case "${COMP_WORDS[COMP_CWORD-1]}" in
1506 __gitcomp
"$(__git_refs)"
1513 __git_complete_strategy
&& return
1515 local cur
="${COMP_WORDS[COMP_CWORD]}"
1519 --rebase --no-rebase
1520 $__git_merge_options
1521 $__git_fetch_options
1526 __git_complete_remote_or_refspec
1531 local cur
="${COMP_WORDS[COMP_CWORD]}"
1532 case "${COMP_WORDS[COMP_CWORD-1]}" in
1534 __gitcomp
"$(__git_remotes)"
1539 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1544 --all --mirror --tags --dry-run --force --verbose
1545 --receive-pack= --repo=
1550 __git_complete_remote_or_refspec
1555 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
1556 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1557 __gitcomp
"--continue --skip --abort"
1560 __git_complete_strategy
&& return
1563 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1568 --onto --merge --strategy --interactive
1569 --preserve-merges --stat --no-stat
1570 --committer-date-is-author-date --ignore-date
1571 --ignore-whitespace --whitespace=
1577 __gitcomp
"$(__git_refs)"
1580 __git_send_email_confirm_options
="always never auto cc compose"
1581 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1585 local cur
="${COMP_WORDS[COMP_CWORD]}"
1589 $__git_send_email_confirm_options
1590 " "" "${cur##--confirm=}"
1595 $__git_send_email_suppresscc_options
1596 " "" "${cur##--suppress-cc=}"
1600 --smtp-encryption=*)
1601 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1605 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1606 --compose --confirm= --dry-run --envelope-sender
1608 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1609 --no-suppress-from --no-thread --quiet
1610 --signed-off-by-cc --smtp-pass --smtp-server
1611 --smtp-server-port --smtp-encryption= --smtp-user
1612 --subject --suppress-cc= --suppress-from --thread --to
1613 --validate --no-validate"
1625 __git_config_get_set_variables
()
1627 local prevword word config_file
= c
=$COMP_CWORD
1628 while [ $c -gt 1 ]; do
1629 word
="${COMP_WORDS[c]}"
1631 --global|
--system|
--file=*)
1636 config_file
="$word $prevword"
1644 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1657 local cur
="${COMP_WORDS[COMP_CWORD]}"
1658 local prv
="${COMP_WORDS[COMP_CWORD-1]}"
1661 __gitcomp
"$(__git_remotes)"
1665 __gitcomp
"$(__git_refs)"
1669 local remote
="${prv#remote.}"
1670 remote
="${remote%.fetch}"
1671 __gitcomp
"$(__git_refs_remotes "$remote")"
1675 local remote
="${prv#remote.}"
1676 remote
="${remote%.push}"
1677 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1678 for-each-ref --format='%(refname):%(refname)' \
1682 pull.twohead|pull.octopus
)
1683 __git_compute_merge_strategies
1684 __gitcomp
"$__git_merge_strategies"
1687 color.branch|color.
diff|color.interactive|\
1688 color.showbranch|color.status|color.ui
)
1689 __gitcomp
"always never auto"
1693 __gitcomp
"false true"
1698 normal black red green yellow blue magenta cyan white
1699 bold dim ul blink reverse
1704 __gitcomp
"man info web html"
1708 __gitcomp
"$__git_log_date_formats"
1711 sendemail.aliasesfiletype
)
1712 __gitcomp
"mutt mailrc pine elm gnus"
1716 __gitcomp
"$__git_send_email_confirm_options"
1719 sendemail.suppresscc
)
1720 __gitcomp
"$__git_send_email_suppresscc_options"
1723 --get|
--get-all|
--unset|
--unset-all)
1724 __gitcomp
"$(__git_config_get_set_variables)"
1735 --global --system --file=
1736 --list --replace-all
1737 --get --get-all --get-regexp
1738 --add --unset --unset-all
1739 --remove-section --rename-section
1744 local pfx
="${cur%.*}."
1746 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur"
1750 local pfx
="${cur%.*}."
1752 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1756 local pfx
="${cur%.*}."
1759 argprompt cmd confirm needsfile noconsole norescan
1760 prompt revprompt revunmerged title
1765 local pfx
="${cur%.*}."
1767 __gitcomp
"cmd path" "$pfx" "$cur"
1771 local pfx
="${cur%.*}."
1773 __gitcomp
"cmd path" "$pfx" "$cur"
1777 local pfx
="${cur%.*}."
1779 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1783 local pfx
="${cur%.*}."
1785 __git_compute_all_commands
1786 __gitcomp
"$__git_all_commands" "$pfx" "$cur"
1790 local pfx
="${cur%.*}."
1793 url proxy fetch push mirror skipDefaultUpdate
1794 receivepack uploadpack tagopt pushurl
1799 local pfx
="${cur%.*}."
1801 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1805 local pfx
="${cur%.*}."
1807 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur"
1814 apply.ignorewhitespace
1816 branch.autosetupmerge
1817 branch.autosetuprebase
1820 color.branch.current
1831 color.diff.whitespace
1836 color.interactive.header
1837 color.interactive.help
1838 color.interactive.prompt
1843 color.status.changed
1845 color.status.nobranch
1846 color.status.untracked
1847 color.status.updated
1854 core.deltaBaseCacheLimit
1858 core.fsyncobjectfiles
1860 core.ignoreCygwinFSTricks
1862 core.logAllRefUpdates
1863 core.loosecompression
1865 core.packedGitWindowSize
1867 core.preferSymlinkRefs
1870 core.repositoryFormatVersion
1872 core.sharedRepository
1875 core.warnAmbiguousRefs
1878 diff.autorefreshindex
1884 diff.suppressBlankEmpty
1897 format.subjectprefix
1906 gc.reflogexpireunreachable
1910 gitcvs.commitmsgannotation
1911 gitcvs.dbTableNamePrefix
1922 gui.copyblamethreshold
1926 gui.matchtrackingbranch
1927 gui.newbranchtemplate
1928 gui.pruneduringfetch
1929 gui.spellingdictionary
1945 i18n.logOutputEncoding
1950 imap.preformattedHTML
1959 interactive.singlekey
1972 mergetool.keepBackup
1975 pack.deltaCacheLimit
1988 receive.denyCurrentBranch
1990 receive.denyNonFastForwards
1993 repack.usedeltabaseoffset
1996 sendemail.aliasesfile
1997 sendemail.aliasesfiletype
2001 sendemail.chainreplyto
2003 sendemail.envelopesender
2005 sendemail.signedoffbycc
2006 sendemail.smtpencryption
2008 sendemail.smtpserver
2009 sendemail.smtpserverport
2011 sendemail.suppresscc
2012 sendemail.suppressfrom
2017 status.relativePaths
2018 status.showUntrackedFiles
2020 transfer.unpackLimit
2032 local subcommands
="add rename rm show prune update set-head"
2033 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2034 if [ -z "$subcommand" ]; then
2035 __gitcomp
"$subcommands"
2039 case "$subcommand" in
2040 rename|
rm|show|prune
)
2041 __gitcomp
"$(__git_remotes)"
2044 local i c
='' IFS
=$
'\n'
2045 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2059 __gitcomp
"$(__git_refs)"
2064 __git_has_doubledash
&& return
2066 local cur
="${COMP_WORDS[COMP_CWORD]}"
2069 __gitcomp
"--merge --mixed --hard --soft --patch"
2073 __gitcomp
"$(__git_refs)"
2078 local cur
="${COMP_WORDS[COMP_CWORD]}"
2081 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2085 __gitcomp
"$(__git_refs)"
2090 __git_has_doubledash
&& return
2092 local cur
="${COMP_WORDS[COMP_CWORD]}"
2095 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2104 __git_has_doubledash
&& return
2106 local cur
="${COMP_WORDS[COMP_CWORD]}"
2110 $__git_log_common_options
2111 $__git_log_shortlog_options
2112 --numbered --summary
2117 __git_complete_revlist
2122 __git_has_doubledash
&& return
2124 local cur
="${COMP_WORDS[COMP_CWORD]}"
2127 __gitcomp
"$__git_log_pretty_formats
2128 " "" "${cur##--pretty=}"
2132 __gitcomp
"$__git_log_pretty_formats
2133 " "" "${cur##--format=}"
2137 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2138 $__git_diff_common_options
2148 local cur
="${COMP_WORDS[COMP_CWORD]}"
2152 --all --remotes --topo-order --current --more=
2153 --list --independent --merge-base --no-name
2155 --sha1-name --sparse --topics --reflog
2160 __git_complete_revlist
2165 local cur
="${COMP_WORDS[COMP_CWORD]}"
2166 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2167 local subcommands
='save list show apply clear drop pop create branch'
2168 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2169 if [ -z "$subcommand" ]; then
2172 __gitcomp
"$save_opts"
2175 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2176 __gitcomp
"$subcommands"
2183 case "$subcommand,$cur" in
2185 __gitcomp
"$save_opts"
2188 __gitcomp
"--index --quiet"
2190 show
,--*|drop
,--*|branch
,--*)
2193 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2194 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
2195 | sed -n -e 's/:.*//p')"
2206 __git_has_doubledash
&& return
2208 local subcommands
="add status init update summary foreach sync"
2209 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2210 local cur
="${COMP_WORDS[COMP_CWORD]}"
2213 __gitcomp
"--quiet --cached"
2216 __gitcomp
"$subcommands"
2226 init fetch clone rebase dcommit log find-rev
2227 set-tree commit-diff info create-ignore propget
2228 proplist show-ignore show-externals branch tag blame
2229 migrate mkdirs reset gc
2231 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2232 if [ -z "$subcommand" ]; then
2233 __gitcomp
"$subcommands"
2235 local remote_opts
="--username= --config-dir= --no-auth-cache"
2237 --follow-parent --authors-file= --repack=
2238 --no-metadata --use-svm-props --use-svnsync-props
2239 --log-window-size= --no-checkout --quiet
2240 --repack-flags --use-log-author --localtime
2241 --ignore-paths= $remote_opts
2244 --template= --shared= --trunk= --tags=
2245 --branches= --stdlayout --minimize-url
2246 --no-metadata --use-svm-props --use-svnsync-props
2247 --rewrite-root= --prefix= --use-log-author
2248 --add-author-from $remote_opts
2251 --edit --rmdir --find-copies-harder --copy-similarity=
2254 local cur
="${COMP_WORDS[COMP_CWORD]}"
2255 case "$subcommand,$cur" in
2257 __gitcomp
"--revision= --fetch-all $fc_opts"
2260 __gitcomp
"--revision= $fc_opts $init_opts"
2263 __gitcomp
"$init_opts"
2267 --merge --strategy= --verbose --dry-run
2268 --fetch-all --no-rebase --commit-url
2269 --revision $cmt_opts $fc_opts
2273 __gitcomp
"--stdin $cmt_opts $fc_opts"
2275 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2276 show-externals
,--*|mkdirs
,--*)
2277 __gitcomp
"--revision="
2281 --limit= --revision= --verbose --incremental
2282 --oneline --show-commit --non-recursive
2283 --authors-file= --color
2288 --merge --verbose --strategy= --local
2289 --fetch-all --dry-run $fc_opts
2293 __gitcomp
"--message= --file= --revision= $cmt_opts"
2299 __gitcomp
"--dry-run --message --tag"
2302 __gitcomp
"--dry-run --message"
2305 __gitcomp
"--git-format"
2309 --config-dir= --ignore-paths= --minimize
2310 --no-auth-cache --username=
2314 __gitcomp
"--revision= --parent"
2326 while [ $c -lt $COMP_CWORD ]; do
2327 i
="${COMP_WORDS[c]}"
2330 __gitcomp
"$(__git_tags)"
2340 case "${COMP_WORDS[COMP_CWORD-1]}" in
2346 __gitcomp
"$(__git_tags)"
2352 __gitcomp
"$(__git_refs)"
2364 local i c
=1 command __git_dir
2366 while [ $c -lt $COMP_CWORD ]; do
2367 i
="${COMP_WORDS[c]}"
2369 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2370 --bare) __git_dir
="." ;;
2371 --version|
-p|
--paginate) ;;
2372 --help) command="help"; break ;;
2373 *) command="$i"; break ;;
2378 if [ -z "$command" ]; then
2379 case "${COMP_WORDS[COMP_CWORD]}" in
2392 *) __git_compute_porcelain_commands
2393 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2398 local completion_func
="_git_${command//-/_}"
2399 declare -F $completion_func >/dev
/null
&& $completion_func && return
2401 local expansion
=$
(__git_aliased_command
"$command")
2402 if [ -n "$expansion" ]; then
2403 completion_func
="_git_${expansion//-/_}"
2404 declare -F $completion_func >/dev
/null
&& $completion_func
2410 __git_has_doubledash
&& return
2412 local cur
="${COMP_WORDS[COMP_CWORD]}"
2413 local g
="$(__gitdir)"
2415 if [ -f "$g/MERGE_HEAD" ]; then
2421 $__git_log_common_options
2422 $__git_log_gitk_options
2428 __git_complete_revlist
2431 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2432 || complete
-o default
-o nospace
-F _git git
2433 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2434 || complete
-o default
-o nospace
-F _gitk gitk
2436 # The following are necessary only for Cygwin, and only are needed
2437 # when the user has tab-completed the executable name and consequently
2438 # included the '.exe' suffix.
2440 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2441 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2442 || complete
-o default
-o nospace
-F _git git.exe