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 --tags --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 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
325 _get_comp_words_by_ref
()
327 while [ $# -gt 0 ]; do
330 cur
=${COMP_WORDS[COMP_CWORD]}
333 prev
=${COMP_WORDS[COMP_CWORD-1]}
336 words
=("${COMP_WORDS[@]}")
342 # assume COMP_WORDBREAKS is already set sanely
351 # __gitcomp accepts 1, 2, 3, or 4 arguments
352 # generates completion reply with compgen
356 _get_comp_words_by_ref
-n =: cur
357 if [ $# -gt 2 ]; then
366 COMPREPLY
=($
(compgen
-P "${2-}" \
367 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
373 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
376 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
377 if [ -d "$dir" ]; then
378 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
382 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
383 case "$is_hash,$i" in
386 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
387 n
,*) is_hash
=y
; echo "$i" ;;
392 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
395 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
396 if [ -d "$dir" ]; then
397 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
401 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
402 case "$is_hash,$i" in
405 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
406 n
,*) is_hash
=y
; echo "$i" ;;
411 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
414 local i is_hash
=y dir
="$(__gitdir "${1-}")"
415 local cur format refs
416 _get_comp_words_by_ref
-n =: cur
417 if [ -d "$dir" ]; then
424 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
425 if [ -e "$dir/$i" ]; then echo $i; fi
427 format
="refname:short"
428 refs
="refs/tags refs/heads refs/remotes"
431 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
435 for i
in $
(git ls-remote
"$dir" 2>/dev
/null
); do
436 case "$is_hash,$i" in
439 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
440 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
441 n
,refs
/remotes
/*) is_hash
=y
; echo "${i#refs/remotes/}" ;;
442 n
,*) is_hash
=y
; echo "$i" ;;
447 # __git_refs2 requires 1 argument (to pass to __git_refs)
451 for i
in $
(__git_refs
"$1"); do
456 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
457 __git_refs_remotes
()
459 local cmd i is_hash
=y
460 for i
in $
(git ls-remote
"$1" 2>/dev
/null
); do
461 case "$is_hash,$i" in
464 echo "$i:refs/remotes/$1/${i#refs/heads/}"
468 n
,refs
/tags
/*) is_hash
=y
;;
476 local i ngoff IFS
=$
'\n' d
="$(__gitdir)"
477 shopt -q nullglob || ngoff
=1
479 for i
in "$d/remotes"/*; do
480 echo ${i#$d/remotes/}
482 [ "$ngoff" ] && shopt -u nullglob
483 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
489 __git_list_merge_strategies
()
491 git merge
-s help 2>&1 |
492 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
501 __git_merge_strategies
=
502 # 'git merge -s help' (and thus detection of the merge strategy
503 # list) fails, unfortunately, if run outside of any git working
504 # tree. __git_merge_strategies is set to the empty string in
505 # that case, and the detection will be repeated the next time it
507 __git_compute_merge_strategies
()
509 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
512 __git_complete_file
()
515 _get_comp_words_by_ref
-n =: cur
532 case "$COMP_WORDBREAKS" in
534 *) pfx
="$ref:$pfx" ;;
538 COMPREPLY
=($
(compgen
-P "$pfx" \
539 -W "$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" \
540 | sed '/^100... blob /{
556 __gitcomp
"$(__git_refs)"
561 __git_complete_revlist
()
564 _get_comp_words_by_ref
-n =: cur
569 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
574 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
577 __gitcomp
"$(__git_refs)"
582 __git_complete_remote_or_refspec
()
584 local cur words cword
585 _get_comp_words_by_ref
-n =: cur words cword
586 local cmd
="${words[1]}"
587 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
588 while [ $c -lt $cword ]; do
591 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
594 push
) no_complete_refspec
=1 ;;
603 *) remote
="$i"; break ;;
607 if [ -z "$remote" ]; then
608 __gitcomp
"$(__git_remotes)"
611 if [ $no_complete_refspec = 1 ]; then
615 [ "$remote" = "." ] && remote
=
618 case "$COMP_WORDBREAKS" in
620 *) pfx
="${cur%%:*}:" ;;
632 if [ $lhs = 1 ]; then
633 __gitcomp
"$(__git_refs2 "$remote")" "$pfx" "$cur"
635 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
639 if [ $lhs = 1 ]; then
640 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
642 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
646 if [ $lhs = 1 ]; then
647 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
649 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
655 __git_complete_strategy
()
658 _get_comp_words_by_ref
-n =: cur prev
659 __git_compute_merge_strategies
662 __gitcomp
"$__git_merge_strategies"
667 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
674 __git_list_all_commands
()
677 for i
in $
(git
help -a|
egrep '^ [a-zA-Z0-9]')
680 *--*) : helper pattern
;;
687 __git_compute_all_commands
()
689 : ${__git_all_commands:=$(__git_list_all_commands)}
692 __git_list_porcelain_commands
()
695 __git_compute_all_commands
696 for i
in "help" $__git_all_commands
699 *--*) : helper pattern
;;
700 applymbox
) : ask gittus
;;
701 applypatch
) : ask gittus
;;
702 archimport
) : import
;;
703 cat-file
) : plumbing
;;
704 check-attr
) : plumbing
;;
705 check-ref-format
) : plumbing
;;
706 checkout-index
) : plumbing
;;
707 commit-tree
) : plumbing
;;
708 count-objects
) : infrequent
;;
709 cvsexportcommit
) : export;;
710 cvsimport
) : import
;;
711 cvsserver
) : daemon
;;
713 diff-files
) : plumbing
;;
714 diff-index
) : plumbing
;;
715 diff-tree
) : plumbing
;;
716 fast-import
) : import
;;
717 fast-export
) : export;;
718 fsck-objects
) : plumbing
;;
719 fetch-pack
) : plumbing
;;
720 fmt-merge-msg
) : plumbing
;;
721 for-each-ref
) : plumbing
;;
722 hash-object
) : plumbing
;;
723 http-
*) : transport
;;
724 index-pack
) : plumbing
;;
725 init-db
) : deprecated
;;
726 local-fetch
) : plumbing
;;
727 lost-found
) : infrequent
;;
728 ls-files
) : plumbing
;;
729 ls-remote
) : plumbing
;;
730 ls-tree
) : plumbing
;;
731 mailinfo
) : plumbing
;;
732 mailsplit
) : plumbing
;;
733 merge-
*) : plumbing
;;
736 pack-objects
) : plumbing
;;
737 pack-redundant
) : plumbing
;;
738 pack-refs
) : plumbing
;;
739 parse-remote
) : plumbing
;;
740 patch-id
) : plumbing
;;
741 peek-remote
) : plumbing
;;
743 prune-packed
) : plumbing
;;
744 quiltimport
) : import
;;
745 read-tree
) : plumbing
;;
746 receive-pack
) : plumbing
;;
748 remote-
*) : transport
;;
749 repo-config
) : deprecated
;;
751 rev-list
) : plumbing
;;
752 rev-parse
) : plumbing
;;
753 runstatus
) : plumbing
;;
754 sh-setup
) : internal
;;
756 show-ref
) : plumbing
;;
757 send-pack
) : plumbing
;;
758 show-index
) : plumbing
;;
760 stripspace
) : plumbing
;;
761 symbolic-ref
) : plumbing
;;
762 tar-tree
) : deprecated
;;
763 unpack-file
) : plumbing
;;
764 unpack-objects
) : plumbing
;;
765 update-index
) : plumbing
;;
766 update-ref
) : plumbing
;;
767 update-server-info
) : daemon
;;
768 upload-archive
) : plumbing
;;
769 upload-pack
) : plumbing
;;
770 write-tree
) : plumbing
;;
772 verify-pack
) : infrequent
;;
773 verify-tag
) : plumbing
;;
779 __git_porcelain_commands
=
780 __git_compute_porcelain_commands
()
782 __git_compute_all_commands
783 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
789 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
799 # __git_aliased_command requires 1 argument
800 __git_aliased_command
()
802 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
803 config
--get "alias.$1")
804 for word
in $cmdline; do
810 \
!*) : shell
command alias ;;
812 *=*) : setting env
;;
821 # __git_find_on_cmdline requires 1 argument
822 __git_find_on_cmdline
()
824 local word subcommand c
=1 words cword
825 _get_comp_words_by_ref
-n =: words cword
826 while [ $c -lt $cword ]; do
828 for subcommand
in $1; do
829 if [ "$subcommand" = "$word" ]; then
838 __git_has_doubledash
()
840 local c
=1 words cword
841 _get_comp_words_by_ref
-n =: words cword
842 while [ $c -lt $cword ]; do
843 if [ "--" = "${words[c]}" ]; then
851 __git_whitespacelist
="nowarn warn error error-all fix"
855 local cur dir
="$(__gitdir)"
856 _get_comp_words_by_ref
-n =: cur
857 if [ -d "$dir"/rebase-apply
]; then
858 __gitcomp
"--skip --continue --resolved --abort"
863 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
868 --3way --committer-date-is-author-date --ignore-date
869 --ignore-whitespace --ignore-space-change
870 --interactive --keep --no-utf8 --signoff --utf8
871 --whitespace= --scissors
881 _get_comp_words_by_ref
-n =: cur
884 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
889 --stat --numstat --summary --check --index
890 --cached --index-info --reverse --reject --unidiff-zero
891 --apply --no-add --exclude=
892 --ignore-whitespace --ignore-space-change
893 --whitespace= --inaccurate-eof --verbose
902 __git_has_doubledash
&& return
905 _get_comp_words_by_ref
-n =: cur
909 --interactive --refresh --patch --update --dry-run
910 --ignore-errors --intent-to-add
920 _get_comp_words_by_ref
-n =: cur
923 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
927 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
932 --format= --list --verbose
933 --prefix= --remote= --exec=
943 __git_has_doubledash
&& return
945 local subcommands
="start bad good skip reset visualize replay log run"
946 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
947 if [ -z "$subcommand" ]; then
948 __gitcomp
"$subcommands"
952 case "$subcommand" in
954 __gitcomp
"$(__git_refs)"
964 local i c
=1 only_local_ref
="n" has_r
="n" cur words cword
966 _get_comp_words_by_ref
-n =: cur words cword
967 while [ $c -lt $cword ]; do
970 -d|
-m) only_local_ref
="y" ;;
979 --color --no-color --verbose --abbrev= --no-abbrev
980 --track --no-track --contains --merged --no-merged
985 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
986 __gitcomp
"$(__git_heads)"
988 __gitcomp
"$(__git_refs)"
997 _get_comp_words_by_ref
-n =: words cword
998 local cmd
="${words[2]}"
1001 __gitcomp
"create list-heads verify unbundle"
1004 # looking for a file
1009 __git_complete_revlist
1018 __git_has_doubledash
&& return
1021 _get_comp_words_by_ref
-n =: cur
1024 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1028 --quiet --ours --theirs --track --no-track --merge
1029 --conflict= --orphan --patch
1033 __gitcomp
"$(__git_refs)"
1040 __gitcomp
"$(__git_refs)"
1046 _get_comp_words_by_ref
-n =: cur
1049 __gitcomp
"--edit --no-commit"
1052 __gitcomp
"$(__git_refs)"
1059 __git_has_doubledash
&& return
1062 _get_comp_words_by_ref
-n =: cur
1065 __gitcomp
"--dry-run --quiet"
1075 _get_comp_words_by_ref
-n =: cur
1100 __git_has_doubledash
&& return
1103 _get_comp_words_by_ref
-n =: cur
1106 __gitcomp
"default strip verbatim whitespace
1107 " "" "${cur##--cleanup=}"
1111 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1115 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1118 --untracked-files=*)
1119 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1124 --all --author= --signoff --verify --no-verify
1125 --edit --amend --include --only --interactive
1126 --dry-run --reuse-message= --reedit-message=
1127 --reset-author --file= --message= --template=
1128 --cleanup= --untracked-files --untracked-files=
1139 _get_comp_words_by_ref
-n =: cur
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
1172 _get_comp_words_by_ref
-n =: cur
1175 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1176 --base --ours --theirs
1177 $__git_diff_common_options
1185 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1186 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1191 __git_has_doubledash
&& return
1194 _get_comp_words_by_ref
-n =: cur
1197 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1201 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1202 --base --ours --theirs
1203 --no-renames --diff-filter= --find-copies-harder
1204 --relative --ignore-submodules
1212 __git_fetch_options
="
1213 --quiet --verbose --append --upload-pack --force --keep --depth=
1214 --tags --no-tags --all --prune --dry-run
1220 _get_comp_words_by_ref
-n =: cur
1223 __gitcomp
"$__git_fetch_options"
1227 __git_complete_remote_or_refspec
1230 _git_format_patch
()
1233 _get_comp_words_by_ref
-n =: cur
1238 " "" "${cur##--thread=}"
1243 --stdout --attach --no-attach --thread --thread=
1245 --numbered --start-number
1248 --signoff --signature --no-signature
1249 --in-reply-to= --cc=
1250 --full-index --binary
1253 --no-prefix --src-prefix= --dst-prefix=
1254 --inline --suffix= --ignore-if-in-upstream
1260 __git_complete_revlist
1266 _get_comp_words_by_ref
-n =: cur
1270 --tags --root --unreachable --cache --no-reflogs --full
1271 --strict --verbose --lost-found
1282 _get_comp_words_by_ref
-n =: cur
1285 __gitcomp
"--prune --aggressive"
1299 __git_has_doubledash
&& return
1302 _get_comp_words_by_ref
-n =: cur
1307 --text --ignore-case --word-regexp --invert-match
1309 --extended-regexp --basic-regexp --fixed-strings
1310 --files-with-matches --name-only
1311 --files-without-match
1314 --and --or --not --all-match
1320 __gitcomp
"$(__git_refs)"
1326 _get_comp_words_by_ref
-n =: cur
1329 __gitcomp
"--all --info --man --web"
1333 __git_compute_all_commands
1334 __gitcomp
"$__git_all_commands
1335 attributes cli core-tutorial cvs-migration
1336 diffcore gitk glossary hooks ignore modules
1337 repository-layout tutorial tutorial-2
1345 _get_comp_words_by_ref
-n =: cur
1349 false true umask group all world everybody
1350 " "" "${cur##--shared=}"
1354 __gitcomp
"--quiet --bare --template= --shared --shared="
1363 __git_has_doubledash
&& return
1366 _get_comp_words_by_ref
-n =: cur
1369 __gitcomp
"--cached --deleted --modified --others --ignored
1370 --stage --directory --no-empty-directory --unmerged
1371 --killed --exclude= --exclude-from=
1372 --exclude-per-directory= --exclude-standard
1373 --error-unmatch --with-tree= --full-name
1374 --abbrev --ignored --exclude-per-directory
1384 __gitcomp
"$(__git_remotes)"
1392 # Options that go well for log, shortlog and gitk
1393 __git_log_common_options
="
1395 --branches --tags --remotes
1396 --first-parent --merges --no-merges
1398 --max-age= --since= --after=
1399 --min-age= --until= --before=
1401 # Options that go well for log and gitk (not shortlog)
1402 __git_log_gitk_options
="
1403 --dense --sparse --full-history
1404 --simplify-merges --simplify-by-decoration
1407 # Options that go well for log and shortlog (not gitk)
1408 __git_log_shortlog_options
="
1409 --author= --committer= --grep=
1413 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1414 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1418 __git_has_doubledash
&& return
1420 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1422 if [ -f "$g/MERGE_HEAD" ]; then
1426 _get_comp_words_by_ref
-n =: cur
1429 __gitcomp
"$__git_log_pretty_formats
1430 " "" "${cur##--pretty=}"
1434 __gitcomp
"$__git_log_pretty_formats
1435 " "" "${cur##--format=}"
1439 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1443 __gitcomp
"long short" "" "${cur##--decorate=}"
1448 $__git_log_common_options
1449 $__git_log_shortlog_options
1450 $__git_log_gitk_options
1451 --root --topo-order --date-order --reverse
1452 --follow --full-diff
1453 --abbrev-commit --abbrev=
1454 --relative-date --date=
1455 --pretty= --format= --oneline
1458 --decorate --decorate=
1460 --parents --children
1462 $__git_diff_common_options
1463 --pickaxe-all --pickaxe-regex
1468 __git_complete_revlist
1471 __git_merge_options
="
1472 --no-commit --no-stat --log --no-log --squash --strategy
1473 --commit --stat --no-squash --ff --no-ff --ff-only
1478 __git_complete_strategy
&& return
1481 _get_comp_words_by_ref
-n =: cur
1484 __gitcomp
"$__git_merge_options"
1487 __gitcomp
"$(__git_refs)"
1493 _get_comp_words_by_ref
-n =: cur
1496 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1509 __gitcomp
"$(__git_refs)"
1515 _get_comp_words_by_ref
-n =: cur
1518 __gitcomp
"--dry-run"
1527 __gitcomp
"--tags --all --stdin"
1532 local subcommands
="edit show"
1534 _get_comp_words_by_ref
-n =: words cword
1535 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1536 __gitcomp
"$subcommands"
1540 case "${words[cword-1]}" in
1545 __gitcomp
"$(__git_refs)"
1552 __git_complete_strategy
&& return
1555 _get_comp_words_by_ref
-n =: cur
1559 --rebase --no-rebase
1560 $__git_merge_options
1561 $__git_fetch_options
1566 __git_complete_remote_or_refspec
1572 _get_comp_words_by_ref
-n =: cur prev
1575 __gitcomp
"$(__git_remotes)"
1580 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1585 --all --mirror --tags --dry-run --force --verbose
1586 --receive-pack= --repo=
1591 __git_complete_remote_or_refspec
1596 local dir
="$(__gitdir)"
1598 _get_comp_words_by_ref
-n =: cur
1599 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1600 __gitcomp
"--continue --skip --abort"
1603 __git_complete_strategy
&& return
1606 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1611 --onto --merge --strategy --interactive
1612 --preserve-merges --stat --no-stat
1613 --committer-date-is-author-date --ignore-date
1614 --ignore-whitespace --whitespace=
1620 __gitcomp
"$(__git_refs)"
1623 __git_send_email_confirm_options
="always never auto cc compose"
1624 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1629 _get_comp_words_by_ref
-n =: cur
1633 $__git_send_email_confirm_options
1634 " "" "${cur##--confirm=}"
1639 $__git_send_email_suppresscc_options
1640 " "" "${cur##--suppress-cc=}"
1644 --smtp-encryption=*)
1645 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1649 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1650 --compose --confirm= --dry-run --envelope-sender
1652 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1653 --no-suppress-from --no-thread --quiet
1654 --signed-off-by-cc --smtp-pass --smtp-server
1655 --smtp-server-port --smtp-encryption= --smtp-user
1656 --subject --suppress-cc= --suppress-from --thread --to
1657 --validate --no-validate"
1669 __git_config_get_set_variables
()
1672 _get_comp_words_by_ref
-n =: words cword
1673 local prevword word config_file
= c
=$cword
1674 while [ $c -gt 1 ]; do
1677 --global|
--system|
--file=*)
1682 config_file
="$word $prevword"
1690 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1704 _get_comp_words_by_ref
-n =: cur prev
1707 __gitcomp
"$(__git_remotes)"
1711 __gitcomp
"$(__git_refs)"
1715 local remote
="${prev#remote.}"
1716 remote
="${remote%.fetch}"
1717 __gitcomp
"$(__git_refs_remotes "$remote")"
1721 local remote
="${prev#remote.}"
1722 remote
="${remote%.push}"
1723 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1724 for-each-ref --format='%(refname):%(refname)' \
1728 pull.twohead|pull.octopus
)
1729 __git_compute_merge_strategies
1730 __gitcomp
"$__git_merge_strategies"
1733 color.branch|color.
diff|color.interactive|\
1734 color.showbranch|color.status|color.ui
)
1735 __gitcomp
"always never auto"
1739 __gitcomp
"false true"
1744 normal black red green yellow blue magenta cyan white
1745 bold dim ul blink reverse
1750 __gitcomp
"man info web html"
1754 __gitcomp
"$__git_log_date_formats"
1757 sendemail.aliasesfiletype
)
1758 __gitcomp
"mutt mailrc pine elm gnus"
1762 __gitcomp
"$__git_send_email_confirm_options"
1765 sendemail.suppresscc
)
1766 __gitcomp
"$__git_send_email_suppresscc_options"
1769 --get|
--get-all|
--unset|
--unset-all)
1770 __gitcomp
"$(__git_config_get_set_variables)"
1781 --global --system --file=
1782 --list --replace-all
1783 --get --get-all --get-regexp
1784 --add --unset --unset-all
1785 --remove-section --rename-section
1790 local pfx
="${cur%.*}."
1792 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur"
1796 local pfx
="${cur%.*}."
1798 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1802 local pfx
="${cur%.*}."
1805 argprompt cmd confirm needsfile noconsole norescan
1806 prompt revprompt revunmerged title
1811 local pfx
="${cur%.*}."
1813 __gitcomp
"cmd path" "$pfx" "$cur"
1817 local pfx
="${cur%.*}."
1819 __gitcomp
"cmd path" "$pfx" "$cur"
1823 local pfx
="${cur%.*}."
1825 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1829 local pfx
="${cur%.*}."
1831 __git_compute_all_commands
1832 __gitcomp
"$__git_all_commands" "$pfx" "$cur"
1836 local pfx
="${cur%.*}."
1839 url proxy fetch push mirror skipDefaultUpdate
1840 receivepack uploadpack tagopt pushurl
1845 local pfx
="${cur%.*}."
1847 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1851 local pfx
="${cur%.*}."
1853 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur"
1860 apply.ignorewhitespace
1862 branch.autosetupmerge
1863 branch.autosetuprebase
1866 color.branch.current
1877 color.diff.whitespace
1882 color.interactive.header
1883 color.interactive.help
1884 color.interactive.prompt
1889 color.status.changed
1891 color.status.nobranch
1892 color.status.untracked
1893 color.status.updated
1900 core.deltaBaseCacheLimit
1904 core.fsyncobjectfiles
1906 core.ignoreCygwinFSTricks
1908 core.logAllRefUpdates
1909 core.loosecompression
1911 core.packedGitWindowSize
1913 core.preferSymlinkRefs
1916 core.repositoryFormatVersion
1918 core.sharedRepository
1921 core.warnAmbiguousRefs
1924 diff.autorefreshindex
1930 diff.suppressBlankEmpty
1943 format.subjectprefix
1952 gc.reflogexpireunreachable
1956 gitcvs.commitmsgannotation
1957 gitcvs.dbTableNamePrefix
1968 gui.copyblamethreshold
1972 gui.matchtrackingbranch
1973 gui.newbranchtemplate
1974 gui.pruneduringfetch
1975 gui.spellingdictionary
1991 i18n.logOutputEncoding
1996 imap.preformattedHTML
2005 interactive.singlekey
2018 mergetool.keepBackup
2021 pack.deltaCacheLimit
2034 receive.denyCurrentBranch
2036 receive.denyNonFastForwards
2039 repack.usedeltabaseoffset
2042 sendemail.aliasesfile
2043 sendemail.aliasesfiletype
2047 sendemail.chainreplyto
2049 sendemail.envelopesender
2051 sendemail.signedoffbycc
2052 sendemail.smtpencryption
2054 sendemail.smtpserver
2055 sendemail.smtpserverport
2057 sendemail.suppresscc
2058 sendemail.suppressfrom
2063 status.relativePaths
2064 status.showUntrackedFiles
2066 transfer.unpackLimit
2078 local subcommands
="add rename rm show prune update set-head"
2079 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2080 if [ -z "$subcommand" ]; then
2081 __gitcomp
"$subcommands"
2085 case "$subcommand" in
2086 rename|
rm|show|prune
)
2087 __gitcomp
"$(__git_remotes)"
2090 local i c
='' IFS
=$
'\n'
2091 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2105 __gitcomp
"$(__git_refs)"
2110 __git_has_doubledash
&& return
2113 _get_comp_words_by_ref
-n =: cur
2116 __gitcomp
"--merge --mixed --hard --soft --patch"
2120 __gitcomp
"$(__git_refs)"
2126 _get_comp_words_by_ref
-n =: cur
2129 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2133 __gitcomp
"$(__git_refs)"
2138 __git_has_doubledash
&& return
2141 _get_comp_words_by_ref
-n =: cur
2144 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2153 __git_has_doubledash
&& return
2156 _get_comp_words_by_ref
-n =: cur
2160 $__git_log_common_options
2161 $__git_log_shortlog_options
2162 --numbered --summary
2167 __git_complete_revlist
2172 __git_has_doubledash
&& return
2175 _get_comp_words_by_ref
-n =: cur
2178 __gitcomp
"$__git_log_pretty_formats
2179 " "" "${cur##--pretty=}"
2183 __gitcomp
"$__git_log_pretty_formats
2184 " "" "${cur##--format=}"
2188 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2189 $__git_diff_common_options
2200 _get_comp_words_by_ref
-n =: cur
2204 --all --remotes --topo-order --current --more=
2205 --list --independent --merge-base --no-name
2207 --sha1-name --sparse --topics --reflog
2212 __git_complete_revlist
2218 _get_comp_words_by_ref
-n =: cur
2219 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2220 local subcommands
='save list show apply clear drop pop create branch'
2221 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2222 if [ -z "$subcommand" ]; then
2225 __gitcomp
"$save_opts"
2228 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2229 __gitcomp
"$subcommands"
2236 case "$subcommand,$cur" in
2238 __gitcomp
"$save_opts"
2241 __gitcomp
"--index --quiet"
2243 show
,--*|drop
,--*|branch
,--*)
2246 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2247 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
2248 | sed -n -e 's/:.*//p')"
2259 __git_has_doubledash
&& return
2261 local subcommands
="add status init update summary foreach sync"
2262 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2264 _get_comp_words_by_ref
-n =: cur
2267 __gitcomp
"--quiet --cached"
2270 __gitcomp
"$subcommands"
2280 init fetch clone rebase dcommit log find-rev
2281 set-tree commit-diff info create-ignore propget
2282 proplist show-ignore show-externals branch tag blame
2283 migrate mkdirs reset gc
2285 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2286 if [ -z "$subcommand" ]; then
2287 __gitcomp
"$subcommands"
2289 local remote_opts
="--username= --config-dir= --no-auth-cache"
2291 --follow-parent --authors-file= --repack=
2292 --no-metadata --use-svm-props --use-svnsync-props
2293 --log-window-size= --no-checkout --quiet
2294 --repack-flags --use-log-author --localtime
2295 --ignore-paths= $remote_opts
2298 --template= --shared= --trunk= --tags=
2299 --branches= --stdlayout --minimize-url
2300 --no-metadata --use-svm-props --use-svnsync-props
2301 --rewrite-root= --prefix= --use-log-author
2302 --add-author-from $remote_opts
2305 --edit --rmdir --find-copies-harder --copy-similarity=
2309 _get_comp_words_by_ref
-n =: cur
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 local words cword prev
2382 _get_comp_words_by_ref
-n =: words cword prev
2383 while [ $c -lt $cword ]; do
2387 __gitcomp
"$(__git_tags)"
2403 __gitcomp
"$(__git_tags)"
2409 __gitcomp
"$(__git_refs)"
2421 local i c
=1 command __git_dir
2423 local cur words cword
2424 _get_comp_words_by_ref
-n =: cur words cword
2425 while [ $c -lt $cword ]; do
2428 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2429 --bare) __git_dir
="." ;;
2430 --version|
-p|
--paginate) ;;
2431 --help) command="help"; break ;;
2432 *) command="$i"; break ;;
2437 if [ -z "$command" ]; then
2451 *) __git_compute_porcelain_commands
2452 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2457 local completion_func
="_git_${command//-/_}"
2458 declare -F $completion_func >/dev
/null
&& $completion_func && return
2460 local expansion
=$
(__git_aliased_command
"$command")
2461 if [ -n "$expansion" ]; then
2462 completion_func
="_git_${expansion//-/_}"
2463 declare -F $completion_func >/dev
/null
&& $completion_func
2469 __git_has_doubledash
&& return
2472 local g
="$(__gitdir)"
2474 if [ -f "$g/MERGE_HEAD" ]; then
2477 _get_comp_words_by_ref
-n =: cur
2481 $__git_log_common_options
2482 $__git_log_gitk_options
2488 __git_complete_revlist
2491 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2492 || complete
-o default
-o nospace
-F _git git
2493 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2494 || complete
-o default
-o nospace
-F _gitk gitk
2496 # The following are necessary only for Cygwin, and only are needed
2497 # when the user has tab-completed the executable name and consequently
2498 # included the '.exe' suffix.
2500 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2501 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2502 || complete
-o default
-o nospace
-F _git git.exe