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)}
756 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
766 # __git_aliased_command requires 1 argument
767 __git_aliased_command
()
769 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
770 config
--get "alias.$1")
771 for word
in $cmdline; do
777 \
!*) : shell
command alias ;;
779 *=*) : setting env
;;
788 # __git_find_on_cmdline requires 1 argument
789 __git_find_on_cmdline
()
791 local word subcommand c
=1
793 while [ $c -lt $COMP_CWORD ]; do
794 word
="${COMP_WORDS[c]}"
795 for subcommand
in $1; do
796 if [ "$subcommand" = "$word" ]; then
805 __git_has_doubledash
()
808 while [ $c -lt $COMP_CWORD ]; do
809 if [ "--" = "${COMP_WORDS[c]}" ]; then
817 __git_whitespacelist
="nowarn warn error error-all fix"
821 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
822 if [ -d "$dir"/rebase-apply
]; then
823 __gitcomp
"--skip --continue --resolved --abort"
828 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
833 --3way --committer-date-is-author-date --ignore-date
834 --ignore-whitespace --ignore-space-change
835 --interactive --keep --no-utf8 --signoff --utf8
836 --whitespace= --scissors
845 local cur
="${COMP_WORDS[COMP_CWORD]}"
848 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
853 --stat --numstat --summary --check --index
854 --cached --index-info --reverse --reject --unidiff-zero
855 --apply --no-add --exclude=
856 --ignore-whitespace --ignore-space-change
857 --whitespace= --inaccurate-eof --verbose
866 __git_has_doubledash
&& return
868 local cur
="${COMP_WORDS[COMP_CWORD]}"
872 --interactive --refresh --patch --update --dry-run
873 --ignore-errors --intent-to-add
882 local cur
="${COMP_WORDS[COMP_CWORD]}"
885 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
889 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
894 --format= --list --verbose
895 --prefix= --remote= --exec=
905 __git_has_doubledash
&& return
907 local subcommands
="start bad good skip reset visualize replay log run"
908 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
909 if [ -z "$subcommand" ]; then
910 __gitcomp
"$subcommands"
914 case "$subcommand" in
916 __gitcomp
"$(__git_refs)"
926 local i c
=1 only_local_ref
="n" has_r
="n"
928 while [ $c -lt $COMP_CWORD ]; do
931 -d|
-m) only_local_ref
="y" ;;
937 case "${COMP_WORDS[COMP_CWORD]}" in
940 --color --no-color --verbose --abbrev= --no-abbrev
941 --track --no-track --contains --merged --no-merged
946 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
947 __gitcomp
"$(__git_heads)"
949 __gitcomp
"$(__git_refs)"
957 local cmd
="${COMP_WORDS[2]}"
958 case "$COMP_CWORD" in
960 __gitcomp
"create list-heads verify unbundle"
968 __git_complete_revlist
977 __git_has_doubledash
&& return
979 local cur
="${COMP_WORDS[COMP_CWORD]}"
982 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
986 --quiet --ours --theirs --track --no-track --merge
987 --conflict= --orphan --patch
991 __gitcomp
"$(__git_refs)"
998 __gitcomp
"$(__git_refs)"
1003 local cur
="${COMP_WORDS[COMP_CWORD]}"
1006 __gitcomp
"--edit --no-commit"
1009 __gitcomp
"$(__git_refs)"
1016 __git_has_doubledash
&& return
1018 local cur
="${COMP_WORDS[COMP_CWORD]}"
1021 __gitcomp
"--dry-run --quiet"
1030 local cur
="${COMP_WORDS[COMP_CWORD]}"
1055 __git_has_doubledash
&& return
1057 local cur
="${COMP_WORDS[COMP_CWORD]}"
1060 __gitcomp
"default strip verbatim whitespace
1061 " "" "${cur##--cleanup=}"
1065 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1069 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1072 --untracked-files=*)
1073 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1078 --all --author= --signoff --verify --no-verify
1079 --edit --amend --include --only --interactive
1080 --dry-run --reuse-message= --reedit-message=
1081 --reset-author --file= --message= --template=
1082 --cleanup= --untracked-files --untracked-files=
1092 local cur
="${COMP_WORDS[COMP_CWORD]}"
1096 --all --tags --contains --abbrev= --candidates=
1097 --exact-match --debug --long --match --always
1101 __gitcomp
"$(__git_refs)"
1104 __git_diff_common_options
="--stat --numstat --shortstat --summary
1105 --patch-with-stat --name-only --name-status --color
1106 --no-color --color-words --no-renames --check
1107 --full-index --binary --abbrev --diff-filter=
1108 --find-copies-harder
1109 --text --ignore-space-at-eol --ignore-space-change
1110 --ignore-all-space --exit-code --quiet --ext-diff
1112 --no-prefix --src-prefix= --dst-prefix=
1113 --inter-hunk-context=
1116 --dirstat --dirstat= --dirstat-by-file
1117 --dirstat-by-file= --cumulative
1122 __git_has_doubledash
&& return
1124 local cur
="${COMP_WORDS[COMP_CWORD]}"
1127 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1128 --base --ours --theirs
1129 $__git_diff_common_options
1137 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1138 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1143 __git_has_doubledash
&& return
1145 local cur
="${COMP_WORDS[COMP_CWORD]}"
1148 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1152 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1153 --base --ours --theirs
1154 --no-renames --diff-filter= --find-copies-harder
1155 --relative --ignore-submodules
1163 __git_fetch_options
="
1164 --quiet --verbose --append --upload-pack --force --keep --depth=
1165 --tags --no-tags --all --prune --dry-run
1170 local cur
="${COMP_WORDS[COMP_CWORD]}"
1173 __gitcomp
"$__git_fetch_options"
1177 __git_complete_remote_or_refspec
1180 _git_format_patch
()
1182 local cur
="${COMP_WORDS[COMP_CWORD]}"
1187 " "" "${cur##--thread=}"
1192 --stdout --attach --no-attach --thread --thread=
1194 --numbered --start-number
1197 --signoff --signature --no-signature
1198 --in-reply-to= --cc=
1199 --full-index --binary
1202 --no-prefix --src-prefix= --dst-prefix=
1203 --inline --suffix= --ignore-if-in-upstream
1209 __git_complete_revlist
1214 local cur
="${COMP_WORDS[COMP_CWORD]}"
1218 --tags --root --unreachable --cache --no-reflogs --full
1219 --strict --verbose --lost-found
1229 local cur
="${COMP_WORDS[COMP_CWORD]}"
1232 __gitcomp
"--prune --aggressive"
1246 __git_has_doubledash
&& return
1248 local cur
="${COMP_WORDS[COMP_CWORD]}"
1253 --text --ignore-case --word-regexp --invert-match
1255 --extended-regexp --basic-regexp --fixed-strings
1256 --files-with-matches --name-only
1257 --files-without-match
1260 --and --or --not --all-match
1266 __gitcomp
"$(__git_refs)"
1271 local cur
="${COMP_WORDS[COMP_CWORD]}"
1274 __gitcomp
"--all --info --man --web"
1278 __git_compute_all_commands
1279 __gitcomp
"$__git_all_commands
1280 attributes cli core-tutorial cvs-migration
1281 diffcore gitk glossary hooks ignore modules
1282 repository-layout tutorial tutorial-2
1289 local cur
="${COMP_WORDS[COMP_CWORD]}"
1293 false true umask group all world everybody
1294 " "" "${cur##--shared=}"
1298 __gitcomp
"--quiet --bare --template= --shared --shared="
1307 __git_has_doubledash
&& return
1309 local cur
="${COMP_WORDS[COMP_CWORD]}"
1312 __gitcomp
"--cached --deleted --modified --others --ignored
1313 --stage --directory --no-empty-directory --unmerged
1314 --killed --exclude= --exclude-from=
1315 --exclude-per-directory= --exclude-standard
1316 --error-unmatch --with-tree= --full-name
1317 --abbrev --ignored --exclude-per-directory
1327 __gitcomp
"$(__git_remotes)"
1335 # Options that go well for log, shortlog and gitk
1336 __git_log_common_options
="
1338 --branches --tags --remotes
1339 --first-parent --merges --no-merges
1341 --max-age= --since= --after=
1342 --min-age= --until= --before=
1344 # Options that go well for log and gitk (not shortlog)
1345 __git_log_gitk_options
="
1346 --dense --sparse --full-history
1347 --simplify-merges --simplify-by-decoration
1350 # Options that go well for log and shortlog (not gitk)
1351 __git_log_shortlog_options
="
1352 --author= --committer= --grep=
1356 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1357 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1361 __git_has_doubledash
&& return
1363 local cur
="${COMP_WORDS[COMP_CWORD]}"
1364 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1366 if [ -f "$g/MERGE_HEAD" ]; then
1371 __gitcomp
"$__git_log_pretty_formats
1372 " "" "${cur##--pretty=}"
1376 __gitcomp
"$__git_log_pretty_formats
1377 " "" "${cur##--format=}"
1381 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1385 __gitcomp
"long short" "" "${cur##--decorate=}"
1390 $__git_log_common_options
1391 $__git_log_shortlog_options
1392 $__git_log_gitk_options
1393 --root --topo-order --date-order --reverse
1394 --follow --full-diff
1395 --abbrev-commit --abbrev=
1396 --relative-date --date=
1397 --pretty= --format= --oneline
1400 --decorate --decorate=
1402 --parents --children
1404 $__git_diff_common_options
1405 --pickaxe-all --pickaxe-regex
1410 __git_complete_revlist
1413 __git_merge_options
="
1414 --no-commit --no-stat --log --no-log --squash --strategy
1415 --commit --stat --no-squash --ff --no-ff --ff-only
1420 __git_complete_strategy
&& return
1422 local cur
="${COMP_WORDS[COMP_CWORD]}"
1425 __gitcomp
"$__git_merge_options"
1428 __gitcomp
"$(__git_refs)"
1433 local cur
="${COMP_WORDS[COMP_CWORD]}"
1436 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1449 __gitcomp
"$(__git_refs)"
1454 local cur
="${COMP_WORDS[COMP_CWORD]}"
1457 __gitcomp
"--dry-run"
1466 __gitcomp
"--tags --all --stdin"
1471 local subcommands
="edit show"
1472 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1473 __gitcomp
"$subcommands"
1477 case "${COMP_WORDS[COMP_CWORD-1]}" in
1482 __gitcomp
"$(__git_refs)"
1489 __git_complete_strategy
&& return
1491 local cur
="${COMP_WORDS[COMP_CWORD]}"
1495 --rebase --no-rebase
1496 $__git_merge_options
1497 $__git_fetch_options
1502 __git_complete_remote_or_refspec
1507 local cur
="${COMP_WORDS[COMP_CWORD]}"
1508 case "${COMP_WORDS[COMP_CWORD-1]}" in
1510 __gitcomp
"$(__git_remotes)"
1515 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1520 --all --mirror --tags --dry-run --force --verbose
1521 --receive-pack= --repo=
1526 __git_complete_remote_or_refspec
1531 local cur
="${COMP_WORDS[COMP_CWORD]}" dir
="$(__gitdir)"
1532 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1533 __gitcomp
"--continue --skip --abort"
1536 __git_complete_strategy
&& return
1539 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1544 --onto --merge --strategy --interactive
1545 --preserve-merges --stat --no-stat
1546 --committer-date-is-author-date --ignore-date
1547 --ignore-whitespace --whitespace=
1553 __gitcomp
"$(__git_refs)"
1556 __git_send_email_confirm_options
="always never auto cc compose"
1557 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1561 local cur
="${COMP_WORDS[COMP_CWORD]}"
1565 $__git_send_email_confirm_options
1566 " "" "${cur##--confirm=}"
1571 $__git_send_email_suppresscc_options
1572 " "" "${cur##--suppress-cc=}"
1576 --smtp-encryption=*)
1577 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1581 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1582 --compose --confirm= --dry-run --envelope-sender
1584 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1585 --no-suppress-from --no-thread --quiet
1586 --signed-off-by-cc --smtp-pass --smtp-server
1587 --smtp-server-port --smtp-encryption= --smtp-user
1588 --subject --suppress-cc= --suppress-from --thread --to
1589 --validate --no-validate"
1601 __git_config_get_set_variables
()
1603 local prevword word config_file
= c
=$COMP_CWORD
1604 while [ $c -gt 1 ]; do
1605 word
="${COMP_WORDS[c]}"
1607 --global|
--system|
--file=*)
1612 config_file
="$word $prevword"
1620 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1633 local cur
="${COMP_WORDS[COMP_CWORD]}"
1634 local prv
="${COMP_WORDS[COMP_CWORD-1]}"
1637 __gitcomp
"$(__git_remotes)"
1641 __gitcomp
"$(__git_refs)"
1645 local remote
="${prv#remote.}"
1646 remote
="${remote%.fetch}"
1647 __gitcomp
"$(__git_refs_remotes "$remote")"
1651 local remote
="${prv#remote.}"
1652 remote
="${remote%.push}"
1653 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1654 for-each-ref --format='%(refname):%(refname)' \
1658 pull.twohead|pull.octopus
)
1659 __git_compute_merge_strategies
1660 __gitcomp
"$__git_merge_strategies"
1663 color.branch|color.
diff|color.interactive|\
1664 color.showbranch|color.status|color.ui
)
1665 __gitcomp
"always never auto"
1669 __gitcomp
"false true"
1674 normal black red green yellow blue magenta cyan white
1675 bold dim ul blink reverse
1680 __gitcomp
"man info web html"
1684 __gitcomp
"$__git_log_date_formats"
1687 sendemail.aliasesfiletype
)
1688 __gitcomp
"mutt mailrc pine elm gnus"
1692 __gitcomp
"$__git_send_email_confirm_options"
1695 sendemail.suppresscc
)
1696 __gitcomp
"$__git_send_email_suppresscc_options"
1699 --get|
--get-all|
--unset|
--unset-all)
1700 __gitcomp
"$(__git_config_get_set_variables)"
1711 --global --system --file=
1712 --list --replace-all
1713 --get --get-all --get-regexp
1714 --add --unset --unset-all
1715 --remove-section --rename-section
1720 local pfx
="${cur%.*}."
1722 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur"
1726 local pfx
="${cur%.*}."
1728 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1732 local pfx
="${cur%.*}."
1735 argprompt cmd confirm needsfile noconsole norescan
1736 prompt revprompt revunmerged title
1741 local pfx
="${cur%.*}."
1743 __gitcomp
"cmd path" "$pfx" "$cur"
1747 local pfx
="${cur%.*}."
1749 __gitcomp
"cmd path" "$pfx" "$cur"
1753 local pfx
="${cur%.*}."
1755 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1759 local pfx
="${cur%.*}."
1761 __git_compute_all_commands
1762 __gitcomp
"$__git_all_commands" "$pfx" "$cur"
1766 local pfx
="${cur%.*}."
1769 url proxy fetch push mirror skipDefaultUpdate
1770 receivepack uploadpack tagopt pushurl
1775 local pfx
="${cur%.*}."
1777 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1781 local pfx
="${cur%.*}."
1783 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur"
1790 apply.ignorewhitespace
1792 branch.autosetupmerge
1793 branch.autosetuprebase
1796 color.branch.current
1807 color.diff.whitespace
1812 color.interactive.header
1813 color.interactive.help
1814 color.interactive.prompt
1819 color.status.changed
1821 color.status.nobranch
1822 color.status.untracked
1823 color.status.updated
1830 core.deltaBaseCacheLimit
1834 core.fsyncobjectfiles
1836 core.ignoreCygwinFSTricks
1838 core.logAllRefUpdates
1839 core.loosecompression
1841 core.packedGitWindowSize
1843 core.preferSymlinkRefs
1846 core.repositoryFormatVersion
1848 core.sharedRepository
1851 core.warnAmbiguousRefs
1854 diff.autorefreshindex
1860 diff.suppressBlankEmpty
1873 format.subjectprefix
1882 gc.reflogexpireunreachable
1886 gitcvs.commitmsgannotation
1887 gitcvs.dbTableNamePrefix
1898 gui.copyblamethreshold
1902 gui.matchtrackingbranch
1903 gui.newbranchtemplate
1904 gui.pruneduringfetch
1905 gui.spellingdictionary
1921 i18n.logOutputEncoding
1926 imap.preformattedHTML
1935 interactive.singlekey
1948 mergetool.keepBackup
1951 pack.deltaCacheLimit
1964 receive.denyCurrentBranch
1966 receive.denyNonFastForwards
1969 repack.usedeltabaseoffset
1972 sendemail.aliasesfile
1973 sendemail.aliasesfiletype
1977 sendemail.chainreplyto
1979 sendemail.envelopesender
1981 sendemail.signedoffbycc
1982 sendemail.smtpencryption
1984 sendemail.smtpserver
1985 sendemail.smtpserverport
1987 sendemail.suppresscc
1988 sendemail.suppressfrom
1993 status.relativePaths
1994 status.showUntrackedFiles
1996 transfer.unpackLimit
2008 local subcommands
="add rename rm show prune update set-head"
2009 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2010 if [ -z "$subcommand" ]; then
2011 __gitcomp
"$subcommands"
2015 case "$subcommand" in
2016 rename|
rm|show|prune
)
2017 __gitcomp
"$(__git_remotes)"
2020 local i c
='' IFS
=$
'\n'
2021 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2035 __gitcomp
"$(__git_refs)"
2040 __git_has_doubledash
&& return
2042 local cur
="${COMP_WORDS[COMP_CWORD]}"
2045 __gitcomp
"--merge --mixed --hard --soft --patch"
2049 __gitcomp
"$(__git_refs)"
2054 local cur
="${COMP_WORDS[COMP_CWORD]}"
2057 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2061 __gitcomp
"$(__git_refs)"
2066 __git_has_doubledash
&& return
2068 local cur
="${COMP_WORDS[COMP_CWORD]}"
2071 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2080 __git_has_doubledash
&& return
2082 local cur
="${COMP_WORDS[COMP_CWORD]}"
2086 $__git_log_common_options
2087 $__git_log_shortlog_options
2088 --numbered --summary
2093 __git_complete_revlist
2098 __git_has_doubledash
&& return
2100 local cur
="${COMP_WORDS[COMP_CWORD]}"
2103 __gitcomp
"$__git_log_pretty_formats
2104 " "" "${cur##--pretty=}"
2108 __gitcomp
"$__git_log_pretty_formats
2109 " "" "${cur##--format=}"
2113 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2114 $__git_diff_common_options
2124 local cur
="${COMP_WORDS[COMP_CWORD]}"
2128 --all --remotes --topo-order --current --more=
2129 --list --independent --merge-base --no-name
2131 --sha1-name --sparse --topics --reflog
2136 __git_complete_revlist
2141 local cur
="${COMP_WORDS[COMP_CWORD]}"
2142 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2143 local subcommands
='save list show apply clear drop pop create branch'
2144 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2145 if [ -z "$subcommand" ]; then
2148 __gitcomp
"$save_opts"
2151 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2152 __gitcomp
"$subcommands"
2159 case "$subcommand,$cur" in
2161 __gitcomp
"$save_opts"
2164 __gitcomp
"--index --quiet"
2166 show
,--*|drop
,--*|branch
,--*)
2169 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2170 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
2171 | sed -n -e 's/:.*//p')"
2182 __git_has_doubledash
&& return
2184 local subcommands
="add status init update summary foreach sync"
2185 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2186 local cur
="${COMP_WORDS[COMP_CWORD]}"
2189 __gitcomp
"--quiet --cached"
2192 __gitcomp
"$subcommands"
2202 init fetch clone rebase dcommit log find-rev
2203 set-tree commit-diff info create-ignore propget
2204 proplist show-ignore show-externals branch tag blame
2205 migrate mkdirs reset gc
2207 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2208 if [ -z "$subcommand" ]; then
2209 __gitcomp
"$subcommands"
2211 local remote_opts
="--username= --config-dir= --no-auth-cache"
2213 --follow-parent --authors-file= --repack=
2214 --no-metadata --use-svm-props --use-svnsync-props
2215 --log-window-size= --no-checkout --quiet
2216 --repack-flags --use-log-author --localtime
2217 --ignore-paths= $remote_opts
2220 --template= --shared= --trunk= --tags=
2221 --branches= --stdlayout --minimize-url
2222 --no-metadata --use-svm-props --use-svnsync-props
2223 --rewrite-root= --prefix= --use-log-author
2224 --add-author-from $remote_opts
2227 --edit --rmdir --find-copies-harder --copy-similarity=
2230 local cur
="${COMP_WORDS[COMP_CWORD]}"
2231 case "$subcommand,$cur" in
2233 __gitcomp
"--revision= --fetch-all $fc_opts"
2236 __gitcomp
"--revision= $fc_opts $init_opts"
2239 __gitcomp
"$init_opts"
2243 --merge --strategy= --verbose --dry-run
2244 --fetch-all --no-rebase --commit-url
2245 --revision $cmt_opts $fc_opts
2249 __gitcomp
"--stdin $cmt_opts $fc_opts"
2251 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2252 show-externals
,--*|mkdirs
,--*)
2253 __gitcomp
"--revision="
2257 --limit= --revision= --verbose --incremental
2258 --oneline --show-commit --non-recursive
2259 --authors-file= --color
2264 --merge --verbose --strategy= --local
2265 --fetch-all --dry-run $fc_opts
2269 __gitcomp
"--message= --file= --revision= $cmt_opts"
2275 __gitcomp
"--dry-run --message --tag"
2278 __gitcomp
"--dry-run --message"
2281 __gitcomp
"--git-format"
2285 --config-dir= --ignore-paths= --minimize
2286 --no-auth-cache --username=
2290 __gitcomp
"--revision= --parent"
2302 while [ $c -lt $COMP_CWORD ]; do
2303 i
="${COMP_WORDS[c]}"
2306 __gitcomp
"$(__git_tags)"
2316 case "${COMP_WORDS[COMP_CWORD-1]}" in
2322 __gitcomp
"$(__git_tags)"
2328 __gitcomp
"$(__git_refs)"
2340 local i c
=1 command __git_dir
2342 while [ $c -lt $COMP_CWORD ]; do
2343 i
="${COMP_WORDS[c]}"
2345 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2346 --bare) __git_dir
="." ;;
2347 --version|
-p|
--paginate) ;;
2348 --help) command="help"; break ;;
2349 *) command="$i"; break ;;
2354 if [ -z "$command" ]; then
2355 case "${COMP_WORDS[COMP_CWORD]}" in
2368 *) __git_compute_porcelain_commands
2369 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2374 local completion_func
="_git_${command//-/_}"
2375 declare -F $completion_func >/dev
/null
&& $completion_func && return
2377 local expansion
=$
(__git_aliased_command
"$command")
2378 if [ -n "$expansion" ]; then
2379 completion_func
="_git_${expansion//-/_}"
2380 declare -F $completion_func >/dev
/null
&& $completion_func
2386 __git_has_doubledash
&& return
2388 local cur
="${COMP_WORDS[COMP_CWORD]}"
2389 local g
="$(__gitdir)"
2391 if [ -f "$g/MERGE_HEAD" ]; then
2397 $__git_log_common_options
2398 $__git_log_gitk_options
2404 __git_complete_revlist
2407 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2408 || complete
-o default
-o nospace
-F _git git
2409 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2410 || complete
-o default
-o nospace
-F _gitk gitk
2412 # The following are necessary only for Cygwin, and only are needed
2413 # when the user has tab-completed the executable name and consequently
2414 # included the '.exe' suffix.
2416 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2417 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2418 || complete
-o default
-o nospace
-F _git git.exe