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 # The following function is based on code from:
326 # bash_completion - programmable completion functions for bash 3.2+
328 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
329 # © 2009-2010, Bash Completion Maintainers
330 # <bash-completion-devel@lists.alioth.debian.org>
332 # This program is free software; you can redistribute it and/or modify
333 # it under the terms of the GNU General Public License as published by
334 # the Free Software Foundation; either version 2, or (at your option)
337 # This program is distributed in the hope that it will be useful,
338 # but WITHOUT ANY WARRANTY; without even the implied warranty of
339 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
340 # GNU General Public License for more details.
342 # You should have received a copy of the GNU General Public License
343 # along with this program; if not, write to the Free Software Foundation,
344 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
346 # The latest version of this software can be obtained here:
348 # http://bash-completion.alioth.debian.org/
352 # This function can be used to access a tokenized list of words
353 # on the command line:
355 # __git_reassemble_comp_words_by_ref '=:'
356 # if test "${words_[cword_-1]}" = -w
361 # The argument should be a collection of characters from the list of
362 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
365 # This is roughly equivalent to going back in time and setting
366 # COMP_WORDBREAKS to exclude those characters. The intent is to
367 # make option types like --date=<type> and <rev>:<path> easy to
368 # recognize by treating each shell word as a single token.
370 # It is best not to set COMP_WORDBREAKS directly because the value is
371 # shared with other completion scripts. By the time the completion
372 # function gets called, COMP_WORDS has already been populated so local
373 # changes to COMP_WORDBREAKS have no effect.
375 # Output: words_, cword_, cur_.
377 __git_reassemble_comp_words_by_ref
()
379 local exclude i j first
380 # Which word separators to exclude?
381 exclude
="${1//[^$COMP_WORDBREAKS]}"
383 if [ -z "$exclude" ]; then
384 words_
=("${COMP_WORDS[@]}")
387 # List of word completion separators has shrunk;
388 # re-assemble words to complete.
389 for ((i
=0, j
=0; i
< ${#COMP_WORDS[@]}; i
++, j
++)); do
390 # Append each nonempty word consisting of just
391 # word separator characters to the current word.
395 [ -n "${COMP_WORDS[$i]}" ] &&
396 # word consists of excluded word separators
397 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
399 # Attach to the previous token,
400 # unless the previous token is the command name.
401 if [ $j -ge 2 ] && [ -n "$first" ]; then
405 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
406 if [ $i = $COMP_CWORD ]; then
409 if (($i < ${#COMP_WORDS[@]} - 1)); then
416 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
417 if [ $i = $COMP_CWORD ]; then
423 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
424 _get_comp_words_by_ref
()
426 local exclude cur_ words_ cword_
427 if [ "$1" = "-n" ]; then
431 __git_reassemble_comp_words_by_ref
"$exclude"
432 cur_
=${words_[cword_]}
433 while [ $# -gt 0 ]; do
439 prev
=${words_[$cword_-1]}
442 words
=("${words_[@]}")
453 # __gitcomp accepts 1, 2, 3, or 4 arguments
454 # generates completion reply with compgen
458 _get_comp_words_by_ref
-n =: cur
459 if [ $# -gt 2 ]; then
468 COMPREPLY
=($
(compgen
-P "${2-}" \
469 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
475 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
478 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
479 if [ -d "$dir" ]; then
480 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
484 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
485 case "$is_hash,$i" in
488 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
489 n
,*) is_hash
=y
; echo "$i" ;;
494 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
497 local cmd i is_hash
=y dir
="$(__gitdir "${1-}")"
498 if [ -d "$dir" ]; then
499 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
503 for i
in $
(git ls-remote
"${1-}" 2>/dev
/null
); do
504 case "$is_hash,$i" in
507 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
508 n
,*) is_hash
=y
; echo "$i" ;;
513 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
516 local i is_hash
=y dir
="$(__gitdir "${1-}")"
517 local cur format refs
518 _get_comp_words_by_ref
-n =: cur
519 if [ -d "$dir" ]; then
526 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
527 if [ -e "$dir/$i" ]; then echo $i; fi
529 format
="refname:short"
530 refs
="refs/tags refs/heads refs/remotes"
533 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
537 for i
in $
(git ls-remote
"$dir" 2>/dev
/null
); do
538 case "$is_hash,$i" in
541 n
,refs
/tags
/*) is_hash
=y
; echo "${i#refs/tags/}" ;;
542 n
,refs
/heads
/*) is_hash
=y
; echo "${i#refs/heads/}" ;;
543 n
,refs
/remotes
/*) is_hash
=y
; echo "${i#refs/remotes/}" ;;
544 n
,*) is_hash
=y
; echo "$i" ;;
549 # __git_refs2 requires 1 argument (to pass to __git_refs)
553 for i
in $
(__git_refs
"$1"); do
558 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
559 __git_refs_remotes
()
561 local cmd i is_hash
=y
562 for i
in $
(git ls-remote
"$1" 2>/dev
/null
); do
563 case "$is_hash,$i" in
566 echo "$i:refs/remotes/$1/${i#refs/heads/}"
570 n
,refs
/tags
/*) is_hash
=y
;;
578 local i ngoff IFS
=$
'\n' d
="$(__gitdir)"
579 shopt -q nullglob || ngoff
=1
581 for i
in "$d/remotes"/*; do
582 echo ${i#$d/remotes/}
584 [ "$ngoff" ] && shopt -u nullglob
585 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
591 __git_list_merge_strategies
()
593 git merge
-s help 2>&1 |
594 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
603 __git_merge_strategies
=
604 # 'git merge -s help' (and thus detection of the merge strategy
605 # list) fails, unfortunately, if run outside of any git working
606 # tree. __git_merge_strategies is set to the empty string in
607 # that case, and the detection will be repeated the next time it
609 __git_compute_merge_strategies
()
611 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
614 __git_complete_file
()
617 _get_comp_words_by_ref
-n =: cur
634 case "$COMP_WORDBREAKS" in
636 *) pfx
="$ref:$pfx" ;;
640 COMPREPLY
=($
(compgen
-P "$pfx" \
641 -W "$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" \
642 | sed '/^100... blob /{
658 __gitcomp
"$(__git_refs)"
663 __git_complete_revlist
()
666 _get_comp_words_by_ref
-n =: cur
671 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
676 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
679 __gitcomp
"$(__git_refs)"
684 __git_complete_remote_or_refspec
()
686 local cur words cword
687 _get_comp_words_by_ref
-n =: cur words cword
688 local cmd
="${words[1]}"
689 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
690 while [ $c -lt $cword ]; do
693 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
696 push
) no_complete_refspec
=1 ;;
705 *) remote
="$i"; break ;;
709 if [ -z "$remote" ]; then
710 __gitcomp
"$(__git_remotes)"
713 if [ $no_complete_refspec = 1 ]; then
717 [ "$remote" = "." ] && remote
=
720 case "$COMP_WORDBREAKS" in
722 *) pfx
="${cur%%:*}:" ;;
734 if [ $lhs = 1 ]; then
735 __gitcomp
"$(__git_refs2 "$remote")" "$pfx" "$cur"
737 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
741 if [ $lhs = 1 ]; then
742 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
744 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
748 if [ $lhs = 1 ]; then
749 __gitcomp
"$(__git_refs)" "$pfx" "$cur"
751 __gitcomp
"$(__git_refs "$remote")" "$pfx" "$cur"
757 __git_complete_strategy
()
760 _get_comp_words_by_ref
-n =: cur prev
761 __git_compute_merge_strategies
764 __gitcomp
"$__git_merge_strategies"
769 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
776 __git_list_all_commands
()
779 for i
in $
(git
help -a|
egrep '^ [a-zA-Z0-9]')
782 *--*) : helper pattern
;;
789 __git_compute_all_commands
()
791 : ${__git_all_commands:=$(__git_list_all_commands)}
794 __git_list_porcelain_commands
()
797 __git_compute_all_commands
798 for i
in "help" $__git_all_commands
801 *--*) : helper pattern
;;
802 applymbox
) : ask gittus
;;
803 applypatch
) : ask gittus
;;
804 archimport
) : import
;;
805 cat-file
) : plumbing
;;
806 check-attr
) : plumbing
;;
807 check-ref-format
) : plumbing
;;
808 checkout-index
) : plumbing
;;
809 commit-tree
) : plumbing
;;
810 count-objects
) : infrequent
;;
811 cvsexportcommit
) : export;;
812 cvsimport
) : import
;;
813 cvsserver
) : daemon
;;
815 diff-files
) : plumbing
;;
816 diff-index
) : plumbing
;;
817 diff-tree
) : plumbing
;;
818 fast-import
) : import
;;
819 fast-export
) : export;;
820 fsck-objects
) : plumbing
;;
821 fetch-pack
) : plumbing
;;
822 fmt-merge-msg
) : plumbing
;;
823 for-each-ref
) : plumbing
;;
824 hash-object
) : plumbing
;;
825 http-
*) : transport
;;
826 index-pack
) : plumbing
;;
827 init-db
) : deprecated
;;
828 local-fetch
) : plumbing
;;
829 lost-found
) : infrequent
;;
830 ls-files
) : plumbing
;;
831 ls-remote
) : plumbing
;;
832 ls-tree
) : plumbing
;;
833 mailinfo
) : plumbing
;;
834 mailsplit
) : plumbing
;;
835 merge-
*) : plumbing
;;
838 pack-objects
) : plumbing
;;
839 pack-redundant
) : plumbing
;;
840 pack-refs
) : plumbing
;;
841 parse-remote
) : plumbing
;;
842 patch-id
) : plumbing
;;
843 peek-remote
) : plumbing
;;
845 prune-packed
) : plumbing
;;
846 quiltimport
) : import
;;
847 read-tree
) : plumbing
;;
848 receive-pack
) : plumbing
;;
850 remote-
*) : transport
;;
851 repo-config
) : deprecated
;;
853 rev-list
) : plumbing
;;
854 rev-parse
) : plumbing
;;
855 runstatus
) : plumbing
;;
856 sh-setup
) : internal
;;
858 show-ref
) : plumbing
;;
859 send-pack
) : plumbing
;;
860 show-index
) : plumbing
;;
862 stripspace
) : plumbing
;;
863 symbolic-ref
) : plumbing
;;
864 tar-tree
) : deprecated
;;
865 unpack-file
) : plumbing
;;
866 unpack-objects
) : plumbing
;;
867 update-index
) : plumbing
;;
868 update-ref
) : plumbing
;;
869 update-server-info
) : daemon
;;
870 upload-archive
) : plumbing
;;
871 upload-pack
) : plumbing
;;
872 write-tree
) : plumbing
;;
874 verify-pack
) : infrequent
;;
875 verify-tag
) : plumbing
;;
881 __git_porcelain_commands
=
882 __git_compute_porcelain_commands
()
884 __git_compute_all_commands
885 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
891 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
901 # __git_aliased_command requires 1 argument
902 __git_aliased_command
()
904 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
905 config
--get "alias.$1")
906 for word
in $cmdline; do
912 \
!*) : shell
command alias ;;
914 *=*) : setting env
;;
923 # __git_find_on_cmdline requires 1 argument
924 __git_find_on_cmdline
()
926 local word subcommand c
=1 words cword
927 _get_comp_words_by_ref
-n =: words cword
928 while [ $c -lt $cword ]; do
930 for subcommand
in $1; do
931 if [ "$subcommand" = "$word" ]; then
940 __git_has_doubledash
()
942 local c
=1 words cword
943 _get_comp_words_by_ref
-n =: words cword
944 while [ $c -lt $cword ]; do
945 if [ "--" = "${words[c]}" ]; then
953 __git_whitespacelist
="nowarn warn error error-all fix"
957 local cur dir
="$(__gitdir)"
958 _get_comp_words_by_ref
-n =: cur
959 if [ -d "$dir"/rebase-apply
]; then
960 __gitcomp
"--skip --continue --resolved --abort"
965 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
970 --3way --committer-date-is-author-date --ignore-date
971 --ignore-whitespace --ignore-space-change
972 --interactive --keep --no-utf8 --signoff --utf8
973 --whitespace= --scissors
983 _get_comp_words_by_ref
-n =: cur
986 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
991 --stat --numstat --summary --check --index
992 --cached --index-info --reverse --reject --unidiff-zero
993 --apply --no-add --exclude=
994 --ignore-whitespace --ignore-space-change
995 --whitespace= --inaccurate-eof --verbose
1004 __git_has_doubledash
&& return
1007 _get_comp_words_by_ref
-n =: cur
1011 --interactive --refresh --patch --update --dry-run
1012 --ignore-errors --intent-to-add
1022 _get_comp_words_by_ref
-n =: cur
1025 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
1029 __gitcomp
"$(__git_remotes)" "" "${cur##--remote=}"
1034 --format= --list --verbose
1035 --prefix= --remote= --exec=
1045 __git_has_doubledash
&& return
1047 local subcommands
="start bad good skip reset visualize replay log run"
1048 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1049 if [ -z "$subcommand" ]; then
1050 __gitcomp
"$subcommands"
1054 case "$subcommand" in
1055 bad|good|
reset|skip
)
1056 __gitcomp
"$(__git_refs)"
1066 local i c
=1 only_local_ref
="n" has_r
="n" cur words cword
1068 _get_comp_words_by_ref
-n =: cur words cword
1069 while [ $c -lt $cword ]; do
1072 -d|
-m) only_local_ref
="y" ;;
1081 --color --no-color --verbose --abbrev= --no-abbrev
1082 --track --no-track --contains --merged --no-merged
1087 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1088 __gitcomp
"$(__git_heads)"
1090 __gitcomp
"$(__git_refs)"
1099 _get_comp_words_by_ref
-n =: words cword
1100 local cmd
="${words[2]}"
1103 __gitcomp
"create list-heads verify unbundle"
1106 # looking for a file
1111 __git_complete_revlist
1120 __git_has_doubledash
&& return
1123 _get_comp_words_by_ref
-n =: cur
1126 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1130 --quiet --ours --theirs --track --no-track --merge
1131 --conflict= --orphan --patch
1135 __gitcomp
"$(__git_refs)"
1142 __gitcomp
"$(__git_refs)"
1148 _get_comp_words_by_ref
-n =: cur
1151 __gitcomp
"--edit --no-commit"
1154 __gitcomp
"$(__git_refs)"
1161 __git_has_doubledash
&& return
1164 _get_comp_words_by_ref
-n =: cur
1167 __gitcomp
"--dry-run --quiet"
1177 _get_comp_words_by_ref
-n =: cur
1202 __git_has_doubledash
&& return
1205 _get_comp_words_by_ref
-n =: cur
1208 __gitcomp
"default strip verbatim whitespace
1209 " "" "${cur##--cleanup=}"
1213 __gitcomp
"$(__git_refs)" "" "${cur##--reuse-message=}"
1217 __gitcomp
"$(__git_refs)" "" "${cur##--reedit-message=}"
1220 --untracked-files=*)
1221 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1226 --all --author= --signoff --verify --no-verify
1227 --edit --amend --include --only --interactive
1228 --dry-run --reuse-message= --reedit-message=
1229 --reset-author --file= --message= --template=
1230 --cleanup= --untracked-files --untracked-files=
1241 _get_comp_words_by_ref
-n =: cur
1245 --all --tags --contains --abbrev= --candidates=
1246 --exact-match --debug --long --match --always
1250 __gitcomp
"$(__git_refs)"
1253 __git_diff_common_options
="--stat --numstat --shortstat --summary
1254 --patch-with-stat --name-only --name-status --color
1255 --no-color --color-words --no-renames --check
1256 --full-index --binary --abbrev --diff-filter=
1257 --find-copies-harder
1258 --text --ignore-space-at-eol --ignore-space-change
1259 --ignore-all-space --exit-code --quiet --ext-diff
1261 --no-prefix --src-prefix= --dst-prefix=
1262 --inter-hunk-context=
1265 --dirstat --dirstat= --dirstat-by-file
1266 --dirstat-by-file= --cumulative
1271 __git_has_doubledash
&& return
1274 _get_comp_words_by_ref
-n =: cur
1277 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1278 --base --ours --theirs
1279 $__git_diff_common_options
1287 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1288 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1293 __git_has_doubledash
&& return
1296 _get_comp_words_by_ref
-n =: cur
1299 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1303 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1304 --base --ours --theirs
1305 --no-renames --diff-filter= --find-copies-harder
1306 --relative --ignore-submodules
1314 __git_fetch_options
="
1315 --quiet --verbose --append --upload-pack --force --keep --depth=
1316 --tags --no-tags --all --prune --dry-run
1322 _get_comp_words_by_ref
-n =: cur
1325 __gitcomp
"$__git_fetch_options"
1329 __git_complete_remote_or_refspec
1332 _git_format_patch
()
1335 _get_comp_words_by_ref
-n =: cur
1340 " "" "${cur##--thread=}"
1345 --stdout --attach --no-attach --thread --thread=
1347 --numbered --start-number
1350 --signoff --signature --no-signature
1351 --in-reply-to= --cc=
1352 --full-index --binary
1355 --no-prefix --src-prefix= --dst-prefix=
1356 --inline --suffix= --ignore-if-in-upstream
1362 __git_complete_revlist
1368 _get_comp_words_by_ref
-n =: cur
1372 --tags --root --unreachable --cache --no-reflogs --full
1373 --strict --verbose --lost-found
1384 _get_comp_words_by_ref
-n =: cur
1387 __gitcomp
"--prune --aggressive"
1401 __git_has_doubledash
&& return
1404 _get_comp_words_by_ref
-n =: cur
1409 --text --ignore-case --word-regexp --invert-match
1411 --extended-regexp --basic-regexp --fixed-strings
1412 --files-with-matches --name-only
1413 --files-without-match
1416 --and --or --not --all-match
1422 __gitcomp
"$(__git_refs)"
1428 _get_comp_words_by_ref
-n =: cur
1431 __gitcomp
"--all --info --man --web"
1435 __git_compute_all_commands
1436 __gitcomp
"$__git_all_commands
1437 attributes cli core-tutorial cvs-migration
1438 diffcore gitk glossary hooks ignore modules
1439 repository-layout tutorial tutorial-2
1447 _get_comp_words_by_ref
-n =: cur
1451 false true umask group all world everybody
1452 " "" "${cur##--shared=}"
1456 __gitcomp
"--quiet --bare --template= --shared --shared="
1465 __git_has_doubledash
&& return
1468 _get_comp_words_by_ref
-n =: cur
1471 __gitcomp
"--cached --deleted --modified --others --ignored
1472 --stage --directory --no-empty-directory --unmerged
1473 --killed --exclude= --exclude-from=
1474 --exclude-per-directory= --exclude-standard
1475 --error-unmatch --with-tree= --full-name
1476 --abbrev --ignored --exclude-per-directory
1486 __gitcomp
"$(__git_remotes)"
1494 # Options that go well for log, shortlog and gitk
1495 __git_log_common_options
="
1497 --branches --tags --remotes
1498 --first-parent --merges --no-merges
1500 --max-age= --since= --after=
1501 --min-age= --until= --before=
1503 # Options that go well for log and gitk (not shortlog)
1504 __git_log_gitk_options
="
1505 --dense --sparse --full-history
1506 --simplify-merges --simplify-by-decoration
1509 # Options that go well for log and shortlog (not gitk)
1510 __git_log_shortlog_options
="
1511 --author= --committer= --grep=
1515 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1516 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1520 __git_has_doubledash
&& return
1522 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1524 if [ -f "$g/MERGE_HEAD" ]; then
1528 _get_comp_words_by_ref
-n =: cur
1531 __gitcomp
"$__git_log_pretty_formats
1532 " "" "${cur##--pretty=}"
1536 __gitcomp
"$__git_log_pretty_formats
1537 " "" "${cur##--format=}"
1541 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1545 __gitcomp
"long short" "" "${cur##--decorate=}"
1550 $__git_log_common_options
1551 $__git_log_shortlog_options
1552 $__git_log_gitk_options
1553 --root --topo-order --date-order --reverse
1554 --follow --full-diff
1555 --abbrev-commit --abbrev=
1556 --relative-date --date=
1557 --pretty= --format= --oneline
1560 --decorate --decorate=
1562 --parents --children
1564 $__git_diff_common_options
1565 --pickaxe-all --pickaxe-regex
1570 __git_complete_revlist
1573 __git_merge_options
="
1574 --no-commit --no-stat --log --no-log --squash --strategy
1575 --commit --stat --no-squash --ff --no-ff --ff-only
1580 __git_complete_strategy
&& return
1583 _get_comp_words_by_ref
-n =: cur
1586 __gitcomp
"$__git_merge_options"
1589 __gitcomp
"$(__git_refs)"
1595 _get_comp_words_by_ref
-n =: cur
1598 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1611 __gitcomp
"$(__git_refs)"
1617 _get_comp_words_by_ref
-n =: cur
1620 __gitcomp
"--dry-run"
1629 __gitcomp
"--tags --all --stdin"
1634 local subcommands
="edit show"
1636 _get_comp_words_by_ref
-n =: words cword
1637 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1638 __gitcomp
"$subcommands"
1642 case "${words[cword-1]}" in
1647 __gitcomp
"$(__git_refs)"
1654 __git_complete_strategy
&& return
1657 _get_comp_words_by_ref
-n =: cur
1661 --rebase --no-rebase
1662 $__git_merge_options
1663 $__git_fetch_options
1668 __git_complete_remote_or_refspec
1674 _get_comp_words_by_ref
-n =: cur prev
1677 __gitcomp
"$(__git_remotes)"
1682 __gitcomp
"$(__git_remotes)" "" "${cur##--repo=}"
1687 --all --mirror --tags --dry-run --force --verbose
1688 --receive-pack= --repo=
1693 __git_complete_remote_or_refspec
1698 local dir
="$(__gitdir)"
1700 _get_comp_words_by_ref
-n =: cur
1701 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1702 __gitcomp
"--continue --skip --abort"
1705 __git_complete_strategy
&& return
1708 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1713 --onto --merge --strategy --interactive
1714 --preserve-merges --stat --no-stat
1715 --committer-date-is-author-date --ignore-date
1716 --ignore-whitespace --whitespace=
1722 __gitcomp
"$(__git_refs)"
1725 __git_send_email_confirm_options
="always never auto cc compose"
1726 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1731 _get_comp_words_by_ref
-n =: cur
1735 $__git_send_email_confirm_options
1736 " "" "${cur##--confirm=}"
1741 $__git_send_email_suppresscc_options
1742 " "" "${cur##--suppress-cc=}"
1746 --smtp-encryption=*)
1747 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1751 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1752 --compose --confirm= --dry-run --envelope-sender
1754 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1755 --no-suppress-from --no-thread --quiet
1756 --signed-off-by-cc --smtp-pass --smtp-server
1757 --smtp-server-port --smtp-encryption= --smtp-user
1758 --subject --suppress-cc= --suppress-from --thread --to
1759 --validate --no-validate"
1771 __git_config_get_set_variables
()
1774 _get_comp_words_by_ref
-n =: words cword
1775 local prevword word config_file
= c
=$cword
1776 while [ $c -gt 1 ]; do
1779 --global|
--system|
--file=*)
1784 config_file
="$word $prevword"
1792 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1806 _get_comp_words_by_ref
-n =: cur prev
1809 __gitcomp
"$(__git_remotes)"
1813 __gitcomp
"$(__git_refs)"
1817 local remote
="${prev#remote.}"
1818 remote
="${remote%.fetch}"
1819 __gitcomp
"$(__git_refs_remotes "$remote")"
1823 local remote
="${prev#remote.}"
1824 remote
="${remote%.push}"
1825 __gitcomp
"$(git --git-dir="$
(__gitdir
)" \
1826 for-each-ref --format='%(refname):%(refname)' \
1830 pull.twohead|pull.octopus
)
1831 __git_compute_merge_strategies
1832 __gitcomp
"$__git_merge_strategies"
1835 color.branch|color.
diff|color.interactive|\
1836 color.showbranch|color.status|color.ui
)
1837 __gitcomp
"always never auto"
1841 __gitcomp
"false true"
1846 normal black red green yellow blue magenta cyan white
1847 bold dim ul blink reverse
1852 __gitcomp
"man info web html"
1856 __gitcomp
"$__git_log_date_formats"
1859 sendemail.aliasesfiletype
)
1860 __gitcomp
"mutt mailrc pine elm gnus"
1864 __gitcomp
"$__git_send_email_confirm_options"
1867 sendemail.suppresscc
)
1868 __gitcomp
"$__git_send_email_suppresscc_options"
1871 --get|
--get-all|
--unset|
--unset-all)
1872 __gitcomp
"$(__git_config_get_set_variables)"
1883 --global --system --file=
1884 --list --replace-all
1885 --get --get-all --get-regexp
1886 --add --unset --unset-all
1887 --remove-section --rename-section
1892 local pfx
="${cur%.*}."
1894 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur"
1898 local pfx
="${cur%.*}."
1900 __gitcomp
"$(__git_heads)" "$pfx" "$cur" "."
1904 local pfx
="${cur%.*}."
1907 argprompt cmd confirm needsfile noconsole norescan
1908 prompt revprompt revunmerged title
1913 local pfx
="${cur%.*}."
1915 __gitcomp
"cmd path" "$pfx" "$cur"
1919 local pfx
="${cur%.*}."
1921 __gitcomp
"cmd path" "$pfx" "$cur"
1925 local pfx
="${cur%.*}."
1927 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur"
1931 local pfx
="${cur%.*}."
1933 __git_compute_all_commands
1934 __gitcomp
"$__git_all_commands" "$pfx" "$cur"
1938 local pfx
="${cur%.*}."
1941 url proxy fetch push mirror skipDefaultUpdate
1942 receivepack uploadpack tagopt pushurl
1947 local pfx
="${cur%.*}."
1949 __gitcomp
"$(__git_remotes)" "$pfx" "$cur" "."
1953 local pfx
="${cur%.*}."
1955 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur"
1962 apply.ignorewhitespace
1964 branch.autosetupmerge
1965 branch.autosetuprebase
1968 color.branch.current
1979 color.diff.whitespace
1984 color.interactive.header
1985 color.interactive.help
1986 color.interactive.prompt
1991 color.status.changed
1993 color.status.nobranch
1994 color.status.untracked
1995 color.status.updated
2002 core.deltaBaseCacheLimit
2006 core.fsyncobjectfiles
2008 core.ignoreCygwinFSTricks
2010 core.logAllRefUpdates
2011 core.loosecompression
2013 core.packedGitWindowSize
2015 core.preferSymlinkRefs
2018 core.repositoryFormatVersion
2020 core.sharedRepository
2023 core.warnAmbiguousRefs
2026 diff.autorefreshindex
2032 diff.suppressBlankEmpty
2045 format.subjectprefix
2054 gc.reflogexpireunreachable
2058 gitcvs.commitmsgannotation
2059 gitcvs.dbTableNamePrefix
2070 gui.copyblamethreshold
2074 gui.matchtrackingbranch
2075 gui.newbranchtemplate
2076 gui.pruneduringfetch
2077 gui.spellingdictionary
2093 i18n.logOutputEncoding
2098 imap.preformattedHTML
2107 interactive.singlekey
2120 mergetool.keepBackup
2123 pack.deltaCacheLimit
2136 receive.denyCurrentBranch
2138 receive.denyNonFastForwards
2141 repack.usedeltabaseoffset
2144 sendemail.aliasesfile
2145 sendemail.aliasesfiletype
2149 sendemail.chainreplyto
2151 sendemail.envelopesender
2153 sendemail.signedoffbycc
2154 sendemail.smtpencryption
2156 sendemail.smtpserver
2157 sendemail.smtpserverport
2159 sendemail.suppresscc
2160 sendemail.suppressfrom
2165 status.relativePaths
2166 status.showUntrackedFiles
2168 transfer.unpackLimit
2180 local subcommands
="add rename rm show prune update set-head"
2181 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2182 if [ -z "$subcommand" ]; then
2183 __gitcomp
"$subcommands"
2187 case "$subcommand" in
2188 rename|
rm|show|prune
)
2189 __gitcomp
"$(__git_remotes)"
2192 local i c
='' IFS
=$
'\n'
2193 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2207 __gitcomp
"$(__git_refs)"
2212 __git_has_doubledash
&& return
2215 _get_comp_words_by_ref
-n =: cur
2218 __gitcomp
"--merge --mixed --hard --soft --patch"
2222 __gitcomp
"$(__git_refs)"
2228 _get_comp_words_by_ref
-n =: cur
2231 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2235 __gitcomp
"$(__git_refs)"
2240 __git_has_doubledash
&& return
2243 _get_comp_words_by_ref
-n =: cur
2246 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2255 __git_has_doubledash
&& return
2258 _get_comp_words_by_ref
-n =: cur
2262 $__git_log_common_options
2263 $__git_log_shortlog_options
2264 --numbered --summary
2269 __git_complete_revlist
2274 __git_has_doubledash
&& return
2277 _get_comp_words_by_ref
-n =: cur
2280 __gitcomp
"$__git_log_pretty_formats
2281 " "" "${cur##--pretty=}"
2285 __gitcomp
"$__git_log_pretty_formats
2286 " "" "${cur##--format=}"
2290 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2291 $__git_diff_common_options
2302 _get_comp_words_by_ref
-n =: cur
2306 --all --remotes --topo-order --current --more=
2307 --list --independent --merge-base --no-name
2309 --sha1-name --sparse --topics --reflog
2314 __git_complete_revlist
2320 _get_comp_words_by_ref
-n =: cur
2321 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2322 local subcommands
='save list show apply clear drop pop create branch'
2323 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2324 if [ -z "$subcommand" ]; then
2327 __gitcomp
"$save_opts"
2330 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2331 __gitcomp
"$subcommands"
2338 case "$subcommand,$cur" in
2340 __gitcomp
"$save_opts"
2343 __gitcomp
"--index --quiet"
2345 show
,--*|drop
,--*|branch
,--*)
2348 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2349 __gitcomp
"$(git --git-dir="$
(__gitdir
)" stash list \
2350 | sed -n -e 's/:.*//p')"
2361 __git_has_doubledash
&& return
2363 local subcommands
="add status init update summary foreach sync"
2364 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2366 _get_comp_words_by_ref
-n =: cur
2369 __gitcomp
"--quiet --cached"
2372 __gitcomp
"$subcommands"
2382 init fetch clone rebase dcommit log find-rev
2383 set-tree commit-diff info create-ignore propget
2384 proplist show-ignore show-externals branch tag blame
2385 migrate mkdirs reset gc
2387 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2388 if [ -z "$subcommand" ]; then
2389 __gitcomp
"$subcommands"
2391 local remote_opts
="--username= --config-dir= --no-auth-cache"
2393 --follow-parent --authors-file= --repack=
2394 --no-metadata --use-svm-props --use-svnsync-props
2395 --log-window-size= --no-checkout --quiet
2396 --repack-flags --use-log-author --localtime
2397 --ignore-paths= $remote_opts
2400 --template= --shared= --trunk= --tags=
2401 --branches= --stdlayout --minimize-url
2402 --no-metadata --use-svm-props --use-svnsync-props
2403 --rewrite-root= --prefix= --use-log-author
2404 --add-author-from $remote_opts
2407 --edit --rmdir --find-copies-harder --copy-similarity=
2411 _get_comp_words_by_ref
-n =: cur
2412 case "$subcommand,$cur" in
2414 __gitcomp
"--revision= --fetch-all $fc_opts"
2417 __gitcomp
"--revision= $fc_opts $init_opts"
2420 __gitcomp
"$init_opts"
2424 --merge --strategy= --verbose --dry-run
2425 --fetch-all --no-rebase --commit-url
2426 --revision $cmt_opts $fc_opts
2430 __gitcomp
"--stdin $cmt_opts $fc_opts"
2432 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2433 show-externals
,--*|mkdirs
,--*)
2434 __gitcomp
"--revision="
2438 --limit= --revision= --verbose --incremental
2439 --oneline --show-commit --non-recursive
2440 --authors-file= --color
2445 --merge --verbose --strategy= --local
2446 --fetch-all --dry-run $fc_opts
2450 __gitcomp
"--message= --file= --revision= $cmt_opts"
2456 __gitcomp
"--dry-run --message --tag"
2459 __gitcomp
"--dry-run --message"
2462 __gitcomp
"--git-format"
2466 --config-dir= --ignore-paths= --minimize
2467 --no-auth-cache --username=
2471 __gitcomp
"--revision= --parent"
2483 local words cword prev
2484 _get_comp_words_by_ref
-n =: words cword prev
2485 while [ $c -lt $cword ]; do
2489 __gitcomp
"$(__git_tags)"
2505 __gitcomp
"$(__git_tags)"
2511 __gitcomp
"$(__git_refs)"
2523 local i c
=1 command __git_dir
2525 local cur words cword
2526 _get_comp_words_by_ref
-n =: cur words cword
2527 while [ $c -lt $cword ]; do
2530 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2531 --bare) __git_dir
="." ;;
2532 --version|
-p|
--paginate) ;;
2533 --help) command="help"; break ;;
2534 *) command="$i"; break ;;
2539 if [ -z "$command" ]; then
2553 *) __git_compute_porcelain_commands
2554 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2559 local completion_func
="_git_${command//-/_}"
2560 declare -F $completion_func >/dev
/null
&& $completion_func && return
2562 local expansion
=$
(__git_aliased_command
"$command")
2563 if [ -n "$expansion" ]; then
2564 completion_func
="_git_${expansion//-/_}"
2565 declare -F $completion_func >/dev
/null
&& $completion_func
2571 __git_has_doubledash
&& return
2574 local g
="$(__gitdir)"
2576 if [ -f "$g/MERGE_HEAD" ]; then
2579 _get_comp_words_by_ref
-n =: cur
2583 $__git_log_common_options
2584 $__git_log_gitk_options
2590 __git_complete_revlist
2593 complete
-o bashdefault
-o default
-o nospace
-F _git git
2>/dev
/null \
2594 || complete
-o default
-o nospace
-F _git git
2595 complete
-o bashdefault
-o default
-o nospace
-F _gitk gitk
2>/dev
/null \
2596 || complete
-o default
-o nospace
-F _gitk gitk
2598 # The following are necessary only for Cygwin, and only are needed
2599 # when the user has tab-completed the executable name and consequently
2600 # included the '.exe' suffix.
2602 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2603 complete
-o bashdefault
-o default
-o nospace
-F _git git.exe
2>/dev
/null \
2604 || complete
-o default
-o nospace
-F _git git.exe