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 or 1 arguments (to pass to __gitdir)
386 local i is_hash
=y dir
="$(__gitdir "${1-}")"
387 local cur
="${COMP_WORDS[COMP_CWORD]}" format refs
388 if [ -d "$dir" ]; then
395 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
396 if [ -e "$dir/$i" ]; then echo $i; fi
398 format
="refname:short"
399 refs
="refs/tags refs/heads refs/remotes"
402 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
406 for i
in $
(git ls-remote
"$dir" 2>/dev
/null
); do
407 case "$is_hash,$i" in
410 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
411 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
412 n
,refs
/remotes
/*) is_hash
=y
; echo "${i#refs/remotes/}" ;;
413 n
,*) is_hash
=y
; echo "$i" ;;
418 # __git_refs2 requires 1 argument (to pass to __git_refs)
422 for i
in $
(__git_refs
"$1"); do
427 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
428 __git_refs_remotes
()
430 local cmd i is_hash
=y
431 for i
in $
(git ls-remote
"$1" 2>/dev
/null
); do
432 case "$is_hash,$i" in
435 echo "$i:refs/remotes/$1/${i#refs/heads/}"
439 n
,refs
/tags
/*) is_hash
=y
;;
447 local i ngoff IFS
=$
'\n' d
="$(__gitdir)"
448 shopt -q nullglob || ngoff
=1
450 for i
in "$d/remotes"/*; do
451 echo ${i#$d/remotes/}
453 [ "$ngoff" ] && shopt -u nullglob
454 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
460 __git_list_merge_strategies
()
462 git merge
-s help 2>&1 |
463 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
472 __git_merge_strategies
=
473 # 'git merge -s help' (and thus detection of the merge strategy
474 # list) fails, unfortunately, if run outside of any git working
475 # tree. __git_merge_strategies is set to the empty string in
476 # that case, and the detection will be repeated the next time it
478 __git_compute_merge_strategies
()
480 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
483 __git_complete_file
()
485 local pfx
ls ref cur
="${COMP_WORDS[COMP_CWORD]}"
502 case "$COMP_WORDBREAKS" in
504 *) pfx
="$ref:$pfx" ;;
508 COMPREPLY
=($
(compgen
-P "$pfx" \
509 -W "$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" \
510 | sed '/^100... blob /{
526 __gitcomp
"$(__git_refs)"
531 __git_complete_revlist
()
533 local pfx cur
="${COMP_WORDS[COMP_CWORD]}"
538 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
543 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
546 __gitcomp
"$(__git_refs)"
551 __git_complete_remote_or_refspec
()
553 local cmd
="${COMP_WORDS[1]}"
554 local cur
="${COMP_WORDS[COMP_CWORD]}"
555 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
556 while [ $c -lt $COMP_CWORD ]; do
559 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
562 push
) no_complete_refspec
=1 ;;
571 *) remote
="$i"; break ;;
575 if [ -z "$remote" ]; then
576 __gitcomp
"$(__git_remotes)"
579 if [ $no_complete_refspec = 1 ]; then
583 [ "$remote" = "." ] && remote
=
586 case "$COMP_WORDBREAKS" in
588 *) pfx
="${cur%%:*}:" ;;
600 if [ $lhs = 1 ]; then
601 __gitcomp
"$(__git_refs2 "$remote")" "$pfx" "$cur"
603 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
607 if [ $lhs = 1 ]; then
608 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
610 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
614 if [ $lhs = 1 ]; then
615 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
617 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
623 __git_complete_strategy
()
625 __git_compute_merge_strategies
626 case "${COMP_WORDS[COMP_CWORD-1]}" in
628 __gitcomp
"$__git_merge_strategies"
631 local cur
="${COMP_WORDS[COMP_CWORD]}"
634 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
641 __git_list_all_commands
()
644 for i
in $
(git
help -a|
egrep '^ [a-zA-Z0-9]')
647 *--*) : helper pattern
;;
654 __git_compute_all_commands
()
656 : ${__git_all_commands:=$(__git_list_all_commands)}
659 __git_list_porcelain_commands
()
662 __git_compute_all_commands
663 for i
in "help" $__git_all_commands
666 *--*) : helper pattern
;;
667 applymbox
) : ask gittus
;;
668 applypatch
) : ask gittus
;;
669 archimport
) : import
;;
670 cat-file
) : plumbing
;;
671 check-attr
) : plumbing
;;
672 check-ref-format
) : plumbing
;;
673 checkout-index
) : plumbing
;;
674 commit-tree
) : plumbing
;;
675 count-objects
) : infrequent
;;
676 cvsexportcommit
) : export;;
677 cvsimport
) : import
;;
678 cvsserver
) : daemon
;;
680 diff-files
) : plumbing
;;
681 diff-index
) : plumbing
;;
682 diff-tree
) : plumbing
;;
683 fast-import
) : import
;;
684 fast-export
) : export;;
685 fsck-objects
) : plumbing
;;
686 fetch-pack
) : plumbing
;;
687 fmt-merge-msg
) : plumbing
;;
688 for-each-ref
) : plumbing
;;
689 hash-object
) : plumbing
;;
690 http-
*) : transport
;;
691 index-pack
) : plumbing
;;
692 init-db
) : deprecated
;;
693 local-fetch
) : plumbing
;;
694 lost-found
) : infrequent
;;
695 ls-files
) : plumbing
;;
696 ls-remote
) : plumbing
;;
697 ls-tree
) : plumbing
;;
698 mailinfo
) : plumbing
;;
699 mailsplit
) : plumbing
;;
700 merge-
*) : plumbing
;;
703 pack-objects
) : plumbing
;;
704 pack-redundant
) : plumbing
;;
705 pack-refs
) : plumbing
;;
706 parse-remote
) : plumbing
;;
707 patch-id
) : plumbing
;;
708 peek-remote
) : plumbing
;;
710 prune-packed
) : plumbing
;;
711 quiltimport
) : import
;;
712 read-tree
) : plumbing
;;
713 receive-pack
) : plumbing
;;
715 remote-
*) : transport
;;
716 repo-config
) : deprecated
;;
718 rev-list
) : plumbing
;;
719 rev-parse
) : plumbing
;;
720 runstatus
) : plumbing
;;
721 sh-setup
) : internal
;;
723 show-ref
) : plumbing
;;
724 send-pack
) : plumbing
;;
725 show-index
) : plumbing
;;
727 stripspace
) : plumbing
;;
728 symbolic-ref
) : plumbing
;;
729 tar-tree
) : deprecated
;;
730 unpack-file
) : plumbing
;;
731 unpack-objects
) : plumbing
;;
732 update-index
) : plumbing
;;
733 update-ref
) : plumbing
;;
734 update-server-info
) : daemon
;;
735 upload-archive
) : plumbing
;;
736 upload-pack
) : plumbing
;;
737 write-tree
) : plumbing
;;
739 verify-pack
) : infrequent
;;
740 verify-tag
) : plumbing
;;
746 __git_porcelain_commands
=
747 __git_compute_porcelain_commands
()
749 __git_compute_all_commands
750 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
753 __git_pretty_aliases
()
756 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "pretty\..*" 2>/dev
/null
); do
769 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
779 # __git_aliased_command requires 1 argument
780 __git_aliased_command
()
782 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
783 config
--get "alias.$1")
784 for word
in $cmdline; do
790 \
!*) : shell
command alias ;;
792 *=*) : setting env
;;
801 # __git_find_on_cmdline requires 1 argument
802 __git_find_on_cmdline
()
804 local word subcommand c
=1
806 while [ $c -lt $COMP_CWORD ]; do
807 word
="${COMP_WORDS[c]}"
808 for subcommand
in $1; do
809 if [ "$subcommand" = "$word" ]; then
818 __git_has_doubledash
()
821 while [ $c -lt $COMP_CWORD ]; do
822 if [ "--" = "${COMP_WORDS[c]}" ]; then
830 __git_whitespacelist
="nowarn warn error error-all fix"
834 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
835 if [ -d "$dir"/rebase-apply
]; then
836 __gitcomp
"--skip --continue --resolved --abort"
841 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
846 --3way --committer-date-is-author-date --ignore-date
847 --ignore-whitespace --ignore-space-change
848 --interactive --keep --no-utf8 --signoff --utf8
849 --whitespace= --scissors
858 local cur
="${COMP_WORDS[COMP_CWORD]}"
861 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
866 --stat --numstat --summary --check --index
867 --cached --index-info --reverse --reject --unidiff-zero
868 --apply --no-add --exclude=
869 --ignore-whitespace --ignore-space-change
870 --whitespace= --inaccurate-eof --verbose
879 __git_has_doubledash
&& return
881 local cur
="${COMP_WORDS[COMP_CWORD]}"
885 --interactive --refresh --patch --update --dry-run
886 --ignore-errors --intent-to-add
895 local cur
="${COMP_WORDS[COMP_CWORD]}"
898 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
902 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
907 --format= --list --verbose
908 --prefix= --remote= --exec=
918 __git_has_doubledash
&& return
920 local subcommands
="start bad good skip reset visualize replay log run"
921 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
922 if [ -z "$subcommand" ]; then
923 if [ -f "$(__gitdir)"/BISECT_START
]; then
924 __gitcomp
"$subcommands"
926 __gitcomp
"replay start"
931 case "$subcommand" in
932 bad|good|
reset|skip|start
)
933 __gitcomp
"$(__git_refs)"
943 local i c
=1 only_local_ref
="n" has_r
="n"
945 while [ $c -lt $COMP_CWORD ]; do
948 -d|
-m) only_local_ref
="y" ;;
954 case "${COMP_WORDS[COMP_CWORD]}" in
957 --color --no-color --verbose --abbrev= --no-abbrev
958 --track --no-track --contains --merged --no-merged
963 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
964 __gitcomp
"$(__git_heads)"
966 __gitcomp
"$(__git_refs)"
974 local cmd
="${COMP_WORDS[2]}"
975 case "$COMP_CWORD" in
977 __gitcomp
"create list-heads verify unbundle"
985 __git_complete_revlist
994 __git_has_doubledash
&& return
996 local cur
="${COMP_WORDS[COMP_CWORD]}"
999 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1003 --quiet --ours --theirs --track --no-track --merge
1004 --conflict= --orphan --patch
1008 __gitcomp
"$(__git_refs)"
1015 __gitcomp
"$(__git_refs)"
1020 local cur
="${COMP_WORDS[COMP_CWORD]}"
1023 __gitcomp
"--edit --no-commit"
1026 __gitcomp
"$(__git_refs)"
1033 __git_has_doubledash
&& return
1035 local cur
="${COMP_WORDS[COMP_CWORD]}"
1038 __gitcomp
"--dry-run --quiet"
1047 local cur
="${COMP_WORDS[COMP_CWORD]}"
1072 __git_has_doubledash
&& return
1074 local cur
="${COMP_WORDS[COMP_CWORD]}"
1077 __gitcomp
"default strip verbatim whitespace
1078 " "" "${cur##--cleanup=}"
1082 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1086 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1089 --untracked-files=*)
1090 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1095 --all --author= --signoff --verify --no-verify
1096 --edit --amend --include --only --interactive
1097 --dry-run --reuse-message= --reedit-message=
1098 --reset-author --file= --message= --template=
1099 --cleanup= --untracked-files --untracked-files=
1109 local cur
="${COMP_WORDS[COMP_CWORD]}"
1113 --all --tags --contains --abbrev= --candidates=
1114 --exact-match --debug --long --match --always
1118 __gitcomp
"$(__git_refs)"
1121 __git_diff_common_options
="--stat --numstat --shortstat --summary
1122 --patch-with-stat --name-only --name-status --color
1123 --no-color --color-words --no-renames --check
1124 --full-index --binary --abbrev --diff-filter=
1125 --find-copies-harder
1126 --text --ignore-space-at-eol --ignore-space-change
1127 --ignore-all-space --exit-code --quiet --ext-diff
1129 --no-prefix --src-prefix= --dst-prefix=
1130 --inter-hunk-context=
1133 --dirstat --dirstat= --dirstat-by-file
1134 --dirstat-by-file= --cumulative
1139 __git_has_doubledash
&& return
1141 local cur
="${COMP_WORDS[COMP_CWORD]}"
1144 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1145 --base --ours --theirs --no-index
1146 $__git_diff_common_options
1154 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1155 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1160 __git_has_doubledash
&& return
1162 local cur
="${COMP_WORDS[COMP_CWORD]}"
1165 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1169 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1170 --base --ours --theirs
1171 --no-renames --diff-filter= --find-copies-harder
1172 --relative --ignore-submodules
1180 __git_fetch_options
="
1181 --quiet --verbose --append --upload-pack --force --keep --depth=
1182 --tags --no-tags --all --prune --dry-run
1187 local cur
="${COMP_WORDS[COMP_CWORD]}"
1190 __gitcomp
"$__git_fetch_options"
1194 __git_complete_remote_or_refspec
1197 _git_format_patch
()
1199 local cur
="${COMP_WORDS[COMP_CWORD]}"
1204 " "" "${cur##--thread=}"
1209 --stdout --attach --no-attach --thread --thread=
1211 --numbered --start-number
1214 --signoff --signature --no-signature
1215 --in-reply-to= --cc=
1216 --full-index --binary
1219 --no-prefix --src-prefix= --dst-prefix=
1220 --inline --suffix= --ignore-if-in-upstream
1226 __git_complete_revlist
1231 local cur
="${COMP_WORDS[COMP_CWORD]}"
1235 --tags --root --unreachable --cache --no-reflogs --full
1236 --strict --verbose --lost-found
1246 local cur
="${COMP_WORDS[COMP_CWORD]}"
1249 __gitcomp
"--prune --aggressive"
1263 __git_has_doubledash
&& return
1265 local cur
="${COMP_WORDS[COMP_CWORD]}"
1270 --text --ignore-case --word-regexp --invert-match
1272 --extended-regexp --basic-regexp --fixed-strings
1273 --files-with-matches --name-only
1274 --files-without-match
1277 --and --or --not --all-match
1283 __gitcomp
"$(__git_refs)"
1288 local cur
="${COMP_WORDS[COMP_CWORD]}"
1291 __gitcomp
"--all --info --man --web"
1295 __git_compute_all_commands
1296 __gitcomp
"$__git_all_commands
1297 attributes cli core-tutorial cvs-migration
1298 diffcore gitk glossary hooks ignore modules
1299 repository-layout tutorial tutorial-2
1306 local cur
="${COMP_WORDS[COMP_CWORD]}"
1310 false true umask group all world everybody
1311 " "" "${cur##--shared=}"
1315 __gitcomp
"--quiet --bare --template= --shared --shared="
1324 __git_has_doubledash
&& return
1326 local cur
="${COMP_WORDS[COMP_CWORD]}"
1329 __gitcomp
"--cached --deleted --modified --others --ignored
1330 --stage --directory --no-empty-directory --unmerged
1331 --killed --exclude= --exclude-from=
1332 --exclude-per-directory= --exclude-standard
1333 --error-unmatch --with-tree= --full-name
1334 --abbrev --ignored --exclude-per-directory
1344 __gitcomp
"$(__git_remotes)"
1352 # Options that go well for log, shortlog and gitk
1353 __git_log_common_options
="
1355 --branches --tags --remotes
1356 --first-parent --merges --no-merges
1358 --max-age= --since= --after=
1359 --min-age= --until= --before=
1361 # Options that go well for log and gitk (not shortlog)
1362 __git_log_gitk_options
="
1363 --dense --sparse --full-history
1364 --simplify-merges --simplify-by-decoration
1367 # Options that go well for log and shortlog (not gitk)
1368 __git_log_shortlog_options
="
1369 --author= --committer= --grep=
1373 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1374 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1378 __git_has_doubledash
&& return
1380 local cur
="${COMP_WORDS[COMP_CWORD]}"
1381 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1383 if [ -f "$g/MERGE_HEAD" ]; then
1388 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1389 " "" "${cur##--pretty=}"
1393 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1394 " "" "${cur##--format=}"
1398 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1402 __gitcomp
"long short" "" "${cur##--decorate=}"
1407 $__git_log_common_options
1408 $__git_log_shortlog_options
1409 $__git_log_gitk_options
1410 --root --topo-order --date-order --reverse
1411 --follow --full-diff
1412 --abbrev-commit --abbrev=
1413 --relative-date --date=
1414 --pretty= --format= --oneline
1417 --decorate --decorate=
1419 --parents --children
1421 $__git_diff_common_options
1422 --pickaxe-all --pickaxe-regex
1427 __git_complete_revlist
1430 __git_merge_options
="
1431 --no-commit --no-stat --log --no-log --squash --strategy
1432 --commit --stat --no-squash --ff --no-ff --ff-only
1437 __git_complete_strategy
&& return
1439 local cur
="${COMP_WORDS[COMP_CWORD]}"
1442 __gitcomp
"$__git_merge_options"
1445 __gitcomp
"$(__git_refs)"
1450 local cur
="${COMP_WORDS[COMP_CWORD]}"
1453 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1466 __gitcomp
"$(__git_refs)"
1471 local cur
="${COMP_WORDS[COMP_CWORD]}"
1474 __gitcomp
"--dry-run"
1483 __gitcomp
"--tags --all --stdin"
1488 local subcommands
='add append copy edit list prune remove show'
1489 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1490 local cur
="${COMP_WORDS[COMP_CWORD]}"
1492 case "$subcommand,$cur" in
1497 case "${COMP_WORDS[COMP_CWORD-1]}" in
1499 __gitcomp
"$(__git_refs)"
1502 __gitcomp
"$subcommands --ref"
1506 add
,--reuse-message=*|append
,--reuse-message=*)
1507 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1509 add
,--reedit-message=*|append
,--reedit-message=*)
1510 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1513 __gitcomp
'--file= --message= --reedit-message=
1520 __gitcomp
'--dry-run --verbose'
1525 case "${COMP_WORDS[COMP_CWORD-1]}" in
1529 __gitcomp
"$(__git_refs)"
1538 __git_complete_strategy
&& return
1540 local cur
="${COMP_WORDS[COMP_CWORD]}"
1544 --rebase --no-rebase
1545 $__git_merge_options
1546 $__git_fetch_options
1551 __git_complete_remote_or_refspec
1556 local cur
="${COMP_WORDS[COMP_CWORD]}"
1557 case "${COMP_WORDS[COMP_CWORD-1]}" in
1559 __gitcomp
"$(__git_remotes)"
1564 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1569 --all --mirror --tags --dry-run --force --verbose
1570 --receive-pack= --repo=
1575 __git_complete_remote_or_refspec
1580 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
1581 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1582 __gitcomp
"--continue --skip --abort"
1585 __git_complete_strategy
&& return
1588 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1593 --onto --merge --strategy --interactive
1594 --preserve-merges --stat --no-stat
1595 --committer-date-is-author-date --ignore-date
1596 --ignore-whitespace --whitespace=
1602 __gitcomp
"$(__git_refs)"
1605 __git_send_email_confirm_options
="always never auto cc compose"
1606 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1610 local cur
="${COMP_WORDS[COMP_CWORD]}"
1614 $__git_send_email_confirm_options
1615 " "" "${cur##--confirm=}"
1620 $__git_send_email_suppresscc_options
1621 " "" "${cur##--suppress-cc=}"
1625 --smtp-encryption=*)
1626 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1630 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1631 --compose --confirm= --dry-run --envelope-sender
1633 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1634 --no-suppress-from --no-thread --quiet
1635 --signed-off-by-cc --smtp-pass --smtp-server
1636 --smtp-server-port --smtp-encryption= --smtp-user
1637 --subject --suppress-cc= --suppress-from --thread --to
1638 --validate --no-validate"
1650 __git_config_get_set_variables
()
1652 local prevword word config_file
= c
=$COMP_CWORD
1653 while [ $c -gt 1 ]; do
1654 word
="${COMP_WORDS[c]}"
1656 --global|
--system|
--file=*)
1661 config_file
="$word $prevword"
1669 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1682 local cur
="${COMP_WORDS[COMP_CWORD]}"
1683 local prv
="${COMP_WORDS[COMP_CWORD-1]}"
1686 __gitcomp
"$(__git_remotes)"
1690 __gitcomp
"$(__git_refs)"
1694 local remote
="${prv#remote.}"
1695 remote
="${remote%.fetch}"
1696 __gitcomp
"$(__git_refs_remotes "$remote")"
1700 local remote
="${prv#remote.}"
1701 remote
="${remote%.push}"
1702 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1703 for-each-ref --format='%(refname):%(refname)' \
1707 pull.twohead|pull.octopus
)
1708 __git_compute_merge_strategies
1709 __gitcomp
"$__git_merge_strategies"
1712 color.branch|color.
diff|color.interactive|\
1713 color.showbranch|color.status|color.ui
)
1714 __gitcomp
"always never auto"
1718 __gitcomp
"false true"
1723 normal black red green yellow blue magenta cyan white
1724 bold dim ul blink reverse
1729 __gitcomp
"man info web html"
1733 __gitcomp
"$__git_log_date_formats"
1736 sendemail.aliasesfiletype
)
1737 __gitcomp
"mutt mailrc pine elm gnus"
1741 __gitcomp
"$__git_send_email_confirm_options"
1744 sendemail.suppresscc
)
1745 __gitcomp
"$__git_send_email_suppresscc_options"
1748 --get|
--get-all|
--unset|
--unset-all)
1749 __gitcomp
"$(__git_config_get_set_variables)"
1760 --global --system --file=
1761 --list --replace-all
1762 --get --get-all --get-regexp
1763 --add --unset --unset-all
1764 --remove-section --rename-section
1769 local pfx
="${cur%.*}."
1771 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur"
1775 local pfx
="${cur%.*}."
1777 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1781 local pfx
="${cur%.*}."
1784 argprompt cmd confirm needsfile noconsole norescan
1785 prompt revprompt revunmerged title
1790 local pfx
="${cur%.*}."
1792 __gitcomp
"cmd path" "$pfx" "$cur"
1796 local pfx
="${cur%.*}."
1798 __gitcomp
"cmd path" "$pfx" "$cur"
1802 local pfx
="${cur%.*}."
1804 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1808 local pfx
="${cur%.*}."
1810 __git_compute_all_commands
1811 __gitcomp
"$__git_all_commands" "$pfx" "$cur"
1815 local pfx
="${cur%.*}."
1818 url proxy fetch push mirror skipDefaultUpdate
1819 receivepack uploadpack tagopt pushurl
1824 local pfx
="${cur%.*}."
1826 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1830 local pfx
="${cur%.*}."
1832 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur"
1839 apply.ignorewhitespace
1841 branch.autosetupmerge
1842 branch.autosetuprebase
1845 color.branch.current
1856 color.diff.whitespace
1861 color.interactive.header
1862 color.interactive.help
1863 color.interactive.prompt
1868 color.status.changed
1870 color.status.nobranch
1871 color.status.untracked
1872 color.status.updated
1879 core.deltaBaseCacheLimit
1883 core.fsyncobjectfiles
1885 core.ignoreCygwinFSTricks
1887 core.logAllRefUpdates
1888 core.loosecompression
1890 core.packedGitWindowSize
1892 core.preferSymlinkRefs
1895 core.repositoryFormatVersion
1897 core.sharedRepository
1900 core.warnAmbiguousRefs
1903 diff.autorefreshindex
1909 diff.suppressBlankEmpty
1922 format.subjectprefix
1931 gc.reflogexpireunreachable
1935 gitcvs.commitmsgannotation
1936 gitcvs.dbTableNamePrefix
1947 gui.copyblamethreshold
1951 gui.matchtrackingbranch
1952 gui.newbranchtemplate
1953 gui.pruneduringfetch
1954 gui.spellingdictionary
1970 i18n.logOutputEncoding
1975 imap.preformattedHTML
1984 interactive.singlekey
1997 mergetool.keepBackup
2000 pack.deltaCacheLimit
2013 receive.denyCurrentBranch
2015 receive.denyNonFastForwards
2018 repack.usedeltabaseoffset
2021 sendemail.aliasesfile
2022 sendemail.aliasesfiletype
2026 sendemail.chainreplyto
2028 sendemail.envelopesender
2030 sendemail.signedoffbycc
2031 sendemail.smtpencryption
2033 sendemail.smtpserver
2034 sendemail.smtpserverport
2036 sendemail.suppresscc
2037 sendemail.suppressfrom
2042 status.relativePaths
2043 status.showUntrackedFiles
2045 transfer.unpackLimit
2057 local subcommands
="add rename rm show prune update set-head"
2058 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2059 if [ -z "$subcommand" ]; then
2060 __gitcomp
"$subcommands"
2064 case "$subcommand" in
2065 rename|
rm|show|prune
)
2066 __gitcomp
"$(__git_remotes)"
2069 local i c
='' IFS
=$
'\n'
2070 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2084 __gitcomp
"$(__git_refs)"
2089 __git_has_doubledash
&& return
2091 local cur
="${COMP_WORDS[COMP_CWORD]}"
2094 __gitcomp
"--merge --mixed --hard --soft --patch"
2098 __gitcomp
"$(__git_refs)"
2103 local cur
="${COMP_WORDS[COMP_CWORD]}"
2106 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2110 __gitcomp
"$(__git_refs)"
2115 __git_has_doubledash
&& return
2117 local cur
="${COMP_WORDS[COMP_CWORD]}"
2120 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2129 __git_has_doubledash
&& return
2131 local cur
="${COMP_WORDS[COMP_CWORD]}"
2135 $__git_log_common_options
2136 $__git_log_shortlog_options
2137 --numbered --summary
2142 __git_complete_revlist
2147 __git_has_doubledash
&& return
2149 local cur
="${COMP_WORDS[COMP_CWORD]}"
2152 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2153 " "" "${cur##--pretty=}"
2157 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2158 " "" "${cur##--format=}"
2162 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2163 $__git_diff_common_options
2173 local cur
="${COMP_WORDS[COMP_CWORD]}"
2177 --all --remotes --topo-order --current --more=
2178 --list --independent --merge-base --no-name
2180 --sha1-name --sparse --topics --reflog
2185 __git_complete_revlist
2190 local cur
="${COMP_WORDS[COMP_CWORD]}"
2191 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2192 local subcommands
='save list show apply clear drop pop create branch'
2193 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2194 if [ -z "$subcommand" ]; then
2197 __gitcomp
"$save_opts"
2200 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2201 __gitcomp
"$subcommands"
2208 case "$subcommand,$cur" in
2210 __gitcomp
"$save_opts"
2213 __gitcomp
"--index --quiet"
2215 show
,--*|drop
,--*|branch
,--*)
2218 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2219 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
2220 | sed -n -e 's/:.*//p')"
2231 __git_has_doubledash
&& return
2233 local subcommands
="add status init update summary foreach sync"
2234 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2235 local cur
="${COMP_WORDS[COMP_CWORD]}"
2238 __gitcomp
"--quiet --cached"
2241 __gitcomp
"$subcommands"
2251 init fetch clone rebase dcommit log find-rev
2252 set-tree commit-diff info create-ignore propget
2253 proplist show-ignore show-externals branch tag blame
2254 migrate mkdirs reset gc
2256 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2257 if [ -z "$subcommand" ]; then
2258 __gitcomp
"$subcommands"
2260 local remote_opts
="--username= --config-dir= --no-auth-cache"
2262 --follow-parent --authors-file= --repack=
2263 --no-metadata --use-svm-props --use-svnsync-props
2264 --log-window-size= --no-checkout --quiet
2265 --repack-flags --use-log-author --localtime
2266 --ignore-paths= $remote_opts
2269 --template= --shared= --trunk= --tags=
2270 --branches= --stdlayout --minimize-url
2271 --no-metadata --use-svm-props --use-svnsync-props
2272 --rewrite-root= --prefix= --use-log-author
2273 --add-author-from $remote_opts
2276 --edit --rmdir --find-copies-harder --copy-similarity=
2279 local cur
="${COMP_WORDS[COMP_CWORD]}"
2280 case "$subcommand,$cur" in
2282 __gitcomp
"--revision= --fetch-all $fc_opts"
2285 __gitcomp
"--revision= $fc_opts $init_opts"
2288 __gitcomp
"$init_opts"
2292 --merge --strategy= --verbose --dry-run
2293 --fetch-all --no-rebase --commit-url
2294 --revision $cmt_opts $fc_opts
2298 __gitcomp
"--stdin $cmt_opts $fc_opts"
2300 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2301 show-externals
,--*|mkdirs
,--*)
2302 __gitcomp
"--revision="
2306 --limit= --revision= --verbose --incremental
2307 --oneline --show-commit --non-recursive
2308 --authors-file= --color
2313 --merge --verbose --strategy= --local
2314 --fetch-all --dry-run $fc_opts
2318 __gitcomp
"--message= --file= --revision= $cmt_opts"
2324 __gitcomp
"--dry-run --message --tag"
2327 __gitcomp
"--dry-run --message"
2330 __gitcomp
"--git-format"
2334 --config-dir= --ignore-paths= --minimize
2335 --no-auth-cache --username=
2339 __gitcomp
"--revision= --parent"
2351 while [ $c -lt $COMP_CWORD ]; do
2352 i
="${COMP_WORDS[c]}"
2355 __gitcomp
"$(__git_tags)"
2365 case "${COMP_WORDS[COMP_CWORD-1]}" in
2371 __gitcomp
"$(__git_tags)"
2377 __gitcomp
"$(__git_refs)"
2389 local i c
=1 command __git_dir
2391 while [ $c -lt $COMP_CWORD ]; do
2392 i
="${COMP_WORDS[c]}"
2394 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2395 --bare) __git_dir
="." ;;
2396 --version|
-p|
--paginate) ;;
2397 --help) command="help"; break ;;
2398 *) command="$i"; break ;;
2403 if [ -z "$command" ]; then
2404 case "${COMP_WORDS[COMP_CWORD]}" in
2417 *) __git_compute_porcelain_commands
2418 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2423 local completion_func
="_git_${command//-/_}"
2424 declare -F $completion_func >/dev
/null
&& $completion_func && return
2426 local expansion
=$
(__git_aliased_command
"$command")
2427 if [ -n "$expansion" ]; then
2428 completion_func
="_git_${expansion//-/_}"
2429 declare -F $completion_func >/dev
/null
&& $completion_func
2435 __git_has_doubledash
&& return
2437 local cur
="${COMP_WORDS[COMP_CWORD]}"
2438 local g
="$(__gitdir)"
2440 if [ -f "$g/MERGE_HEAD" ]; then
2446 $__git_log_common_options
2447 $__git_log_gitk_options
2453 __git_complete_revlist
2456 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2457 || complete
-o default
-o nospace
-F _git git
2458 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2459 || complete
-o default
-o nospace
-F _gitk gitk
2461 # The following are necessary only for Cygwin, and only are needed
2462 # when the user has tab-completed the executable name and consequently
2463 # included the '.exe' suffix.
2465 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2466 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2467 || complete
-o default
-o nospace
-F _git git.exe