3 # bash/zsh 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) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.sh
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 if [[ -n ${ZSH_VERSION-} ]]; then
27 autoload
-U +X bashcompinit
&& bashcompinit
30 case "$COMP_WORDBREAKS" in
32 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
35 # __gitdir accepts 0 or 1 arguments (i.e., location)
36 # returns location of .git repo
39 # Note: this function is duplicated in git-prompt.sh
40 # When updating it, make sure you update the other one to match.
41 if [ -z "${1-}" ]; then
42 if [ -n "${__git_dir-}" ]; then
44 elif [ -n "${GIT_DIR-}" ]; then
45 test -d "${GIT_DIR-}" ||
return 1
47 elif [ -d .git
]; then
50 git rev-parse
--git-dir 2>/dev
/null
52 elif [ -d "$1/.git" ]; then
72 # The following function is based on code from:
74 # bash_completion - programmable completion functions for bash 3.2+
76 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
77 # © 2009-2010, Bash Completion Maintainers
78 # <bash-completion-devel@lists.alioth.debian.org>
80 # This program is free software; you can redistribute it and/or modify
81 # it under the terms of the GNU General Public License as published by
82 # the Free Software Foundation; either version 2, or (at your option)
85 # This program is distributed in the hope that it will be useful,
86 # but WITHOUT ANY WARRANTY; without even the implied warranty of
87 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88 # GNU General Public License for more details.
90 # You should have received a copy of the GNU General Public License
91 # along with this program; if not, write to the Free Software Foundation,
92 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
94 # The latest version of this software can be obtained here:
96 # http://bash-completion.alioth.debian.org/
100 # This function can be used to access a tokenized list of words
101 # on the command line:
103 # __git_reassemble_comp_words_by_ref '=:'
104 # if test "${words_[cword_-1]}" = -w
109 # The argument should be a collection of characters from the list of
110 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
113 # This is roughly equivalent to going back in time and setting
114 # COMP_WORDBREAKS to exclude those characters. The intent is to
115 # make option types like --date=<type> and <rev>:<path> easy to
116 # recognize by treating each shell word as a single token.
118 # It is best not to set COMP_WORDBREAKS directly because the value is
119 # shared with other completion scripts. By the time the completion
120 # function gets called, COMP_WORDS has already been populated so local
121 # changes to COMP_WORDBREAKS have no effect.
123 # Output: words_, cword_, cur_.
125 __git_reassemble_comp_words_by_ref
()
127 local exclude i j first
128 # Which word separators to exclude?
129 exclude
="${1//[^$COMP_WORDBREAKS]}"
131 if [ -z "$exclude" ]; then
132 words_
=("${COMP_WORDS[@]}")
135 # List of word completion separators has shrunk;
136 # re-assemble words to complete.
137 for ((i
=0, j
=0; i
< ${#COMP_WORDS[@]}; i
++, j
++)); do
138 # Append each nonempty word consisting of just
139 # word separator characters to the current word.
143 [ -n "${COMP_WORDS[$i]}" ] &&
144 # word consists of excluded word separators
145 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
147 # Attach to the previous token,
148 # unless the previous token is the command name.
149 if [ $j -ge 2 ] && [ -n "$first" ]; then
153 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
154 if [ $i = $COMP_CWORD ]; then
157 if (($i < ${#COMP_WORDS[@]} - 1)); then
164 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
165 if [ $i = $COMP_CWORD ]; then
171 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
172 if [[ -z ${ZSH_VERSION:+set} ]]; then
173 _get_comp_words_by_ref
()
175 local exclude cur_ words_ cword_
176 if [ "$1" = "-n" ]; then
180 __git_reassemble_comp_words_by_ref
"$exclude"
181 cur_
=${words_[cword_]}
182 while [ $# -gt 0 ]; do
188 prev
=${words_[$cword_-1]}
191 words
=("${words_[@]}")
201 _get_comp_words_by_ref
()
203 while [ $# -gt 0 ]; do
206 cur
=${COMP_WORDS[COMP_CWORD]}
209 prev
=${COMP_WORDS[COMP_CWORD-1]}
212 words
=("${COMP_WORDS[@]}")
218 # assume COMP_WORDBREAKS is already set sanely
228 # Generates completion reply with compgen, appending a space to possible
229 # completion words, if necessary.
230 # It accepts 1 to 4 arguments:
231 # 1: List of possible completion words.
232 # 2: A prefix to be added to each possible completion word (optional).
233 # 3: Generate possible completion matches for this word (optional).
234 # 4: A suffix to be appended to each possible completion word (optional).
237 local cur_
="${3-$cur}"
245 COMPREPLY
=($
(compgen
-P "${2-}" \
246 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
252 # Generates completion reply with compgen from newline-separated possible
253 # completion words by appending a space to all of them.
254 # It accepts 1 to 4 arguments:
255 # 1: List of possible completion words, separated by a single newline.
256 # 2: A prefix to be added to each possible completion word (optional).
257 # 3: Generate possible completion matches for this word (optional).
258 # 4: A suffix to be appended to each possible completion word instead of
259 # the default space (optional). If specified but empty, nothing is
264 COMPREPLY
=($
(compgen
-P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
269 local dir
="$(__gitdir)"
270 if [ -d "$dir" ]; then
271 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
279 local dir
="$(__gitdir)"
280 if [ -d "$dir" ]; then
281 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
287 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
288 # presence of 2nd argument means use the guess heuristic employed
289 # by checkout for tracking branches
292 local i
hash dir
="$(__gitdir "${1-}")" track
="${2-}"
294 if [ -d "$dir" ]; then
302 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
303 if [ -e "$dir/$i" ]; then echo $i; fi
305 format
="refname:short"
306 refs
="refs/tags refs/heads refs/remotes"
309 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
311 if [ -n "$track" ]; then
312 # employ the heuristic used by git checkout
313 # Try to find a remote branch that matches the completion word
314 # but only output if the branch name is unique
316 git
--git-dir="$dir" for-each-ref
--shell --format="ref=%(refname:short)" \
318 while read -r entry
; do
321 if [[ "$ref" == "$cur"* ]]; then
330 git ls-remote
"$dir" "$cur*" 2>/dev
/null | \
331 while read -r hash i
; do
339 git ls-remote
"$dir" HEAD ORIG_HEAD
'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev
/null | \
340 while read -r hash i
; do
343 refs
/*) echo "${i#refs/*/}" ;;
351 # __git_refs2 requires 1 argument (to pass to __git_refs)
355 for i
in $
(__git_refs
"$1"); do
360 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
361 __git_refs_remotes
()
364 git ls-remote
"$1" 'refs/heads/*' 2>/dev
/null | \
365 while read -r hash i
; do
366 echo "$i:refs/remotes/$1/${i#refs/heads/}"
372 local i IFS
=$
'\n' d
="$(__gitdir)"
373 test -d "$d/remotes" && ls -1 "$d/remotes"
374 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
380 __git_list_merge_strategies
()
382 git merge
-s help 2>&1 |
383 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
392 __git_merge_strategies
=
393 # 'git merge -s help' (and thus detection of the merge strategy
394 # list) fails, unfortunately, if run outside of any git working
395 # tree. __git_merge_strategies is set to the empty string in
396 # that case, and the detection will be repeated the next time it
398 __git_compute_merge_strategies
()
400 test -n "$__git_merge_strategies" ||
401 __git_merge_strategies
=$
(__git_list_merge_strategies
)
404 __git_complete_revlist_file
()
406 local pfx
ls ref cur_
="$cur"
426 case "$COMP_WORDBREAKS" in
428 *) pfx
="$ref:$pfx" ;;
431 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" \
432 | sed '/^100... blob /{
448 pfx
="${cur_%...*}..."
450 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
455 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
458 __gitcomp_nl
"$(__git_refs)"
464 __git_complete_file
()
466 __git_complete_revlist_file
469 __git_complete_revlist
()
471 __git_complete_revlist_file
474 __git_complete_remote_or_refspec
()
476 local cur_
="$cur" cmd
="${words[1]}"
477 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
478 if [ "$cmd" = "remote" ]; then
481 while [ $c -lt $cword ]; do
484 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
487 push
) no_complete_refspec
=1 ;;
496 *) remote
="$i"; break ;;
500 if [ -z "$remote" ]; then
501 __gitcomp_nl
"$(__git_remotes)"
504 if [ $no_complete_refspec = 1 ]; then
508 [ "$remote" = "." ] && remote
=
511 case "$COMP_WORDBREAKS" in
513 *) pfx
="${cur_%%:*}:" ;;
525 if [ $lhs = 1 ]; then
526 __gitcomp_nl
"$(__git_refs2 "$remote")" "$pfx" "$cur_"
528 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
532 if [ $lhs = 1 ]; then
533 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
535 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
539 if [ $lhs = 1 ]; then
540 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
542 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
548 __git_complete_strategy
()
550 __git_compute_merge_strategies
553 __gitcomp
"$__git_merge_strategies"
558 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
565 __git_list_all_commands
()
568 for i
in $
(git
help -a|
egrep '^ [a-zA-Z0-9]')
571 *--*) : helper pattern
;;
578 __git_compute_all_commands
()
580 test -n "$__git_all_commands" ||
581 __git_all_commands
=$
(__git_list_all_commands
)
584 __git_list_porcelain_commands
()
587 __git_compute_all_commands
588 for i
in "help" $__git_all_commands
591 *--*) : helper pattern
;;
592 applymbox
) : ask gittus
;;
593 applypatch
) : ask gittus
;;
594 archimport
) : import
;;
595 cat-file
) : plumbing
;;
596 check-attr
) : plumbing
;;
597 check-ref-format
) : plumbing
;;
598 checkout-index
) : plumbing
;;
599 commit-tree
) : plumbing
;;
600 count-objects
) : infrequent
;;
601 credential-cache
) : credentials helper
;;
602 credential-store
) : credentials helper
;;
603 cvsexportcommit
) : export;;
604 cvsimport
) : import
;;
605 cvsserver
) : daemon
;;
607 diff-files
) : plumbing
;;
608 diff-index
) : plumbing
;;
609 diff-tree
) : plumbing
;;
610 fast-import
) : import
;;
611 fast-export
) : export;;
612 fsck-objects
) : plumbing
;;
613 fetch-pack
) : plumbing
;;
614 fmt-merge-msg
) : plumbing
;;
615 for-each-ref
) : plumbing
;;
616 hash-object
) : plumbing
;;
617 http-
*) : transport
;;
618 index-pack
) : plumbing
;;
619 init-db
) : deprecated
;;
620 local-fetch
) : plumbing
;;
621 lost-found
) : infrequent
;;
622 ls-files
) : plumbing
;;
623 ls-remote
) : plumbing
;;
624 ls-tree
) : plumbing
;;
625 mailinfo
) : plumbing
;;
626 mailsplit
) : plumbing
;;
627 merge-
*) : plumbing
;;
630 pack-objects
) : plumbing
;;
631 pack-redundant
) : plumbing
;;
632 pack-refs
) : plumbing
;;
633 parse-remote
) : plumbing
;;
634 patch-id
) : plumbing
;;
635 peek-remote
) : plumbing
;;
637 prune-packed
) : plumbing
;;
638 quiltimport
) : import
;;
639 read-tree
) : plumbing
;;
640 receive-pack
) : plumbing
;;
641 remote-
*) : transport
;;
642 repo-config
) : deprecated
;;
644 rev-list
) : plumbing
;;
645 rev-parse
) : plumbing
;;
646 runstatus
) : plumbing
;;
647 sh-setup
) : internal
;;
649 show-ref
) : plumbing
;;
650 send-pack
) : plumbing
;;
651 show-index
) : plumbing
;;
653 stripspace
) : plumbing
;;
654 symbolic-ref
) : plumbing
;;
655 tar-tree
) : deprecated
;;
656 unpack-file
) : plumbing
;;
657 unpack-objects
) : plumbing
;;
658 update-index
) : plumbing
;;
659 update-ref
) : plumbing
;;
660 update-server-info
) : daemon
;;
661 upload-archive
) : plumbing
;;
662 upload-pack
) : plumbing
;;
663 write-tree
) : plumbing
;;
665 verify-pack
) : infrequent
;;
666 verify-tag
) : plumbing
;;
672 __git_porcelain_commands
=
673 __git_compute_porcelain_commands
()
675 __git_compute_all_commands
676 test -n "$__git_porcelain_commands" ||
677 __git_porcelain_commands
=$
(__git_list_porcelain_commands
)
680 __git_pretty_aliases
()
683 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "pretty\..*" 2>/dev
/null
); do
696 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
706 # __git_aliased_command requires 1 argument
707 __git_aliased_command
()
709 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
710 config
--get "alias.$1")
711 for word
in $cmdline; do
717 \
!*) : shell
command alias ;;
719 *=*) : setting env
;;
728 # __git_find_on_cmdline requires 1 argument
729 __git_find_on_cmdline
()
731 local word subcommand c
=1
732 while [ $c -lt $cword ]; do
734 for subcommand
in $1; do
735 if [ "$subcommand" = "$word" ]; then
744 __git_has_doubledash
()
747 while [ $c -lt $cword ]; do
748 if [ "--" = "${words[c]}" ]; then
756 __git_whitespacelist
="nowarn warn error error-all fix"
760 local dir
="$(__gitdir)"
761 if [ -d "$dir"/rebase-apply
]; then
762 __gitcomp
"--skip --continue --resolved --abort"
767 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
772 --3way --committer-date-is-author-date --ignore-date
773 --ignore-whitespace --ignore-space-change
774 --interactive --keep --no-utf8 --signoff --utf8
775 --whitespace= --scissors
786 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
791 --stat --numstat --summary --check --index
792 --cached --index-info --reverse --reject --unidiff-zero
793 --apply --no-add --exclude=
794 --ignore-whitespace --ignore-space-change
795 --whitespace= --inaccurate-eof --verbose
804 __git_has_doubledash
&& return
809 --interactive --refresh --patch --update --dry-run
810 --ignore-errors --intent-to-add
821 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
825 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--remote=}"
830 --format= --list --verbose
831 --prefix= --remote= --exec=
841 __git_has_doubledash
&& return
843 local subcommands
="start bad good skip reset visualize replay log run"
844 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
845 if [ -z "$subcommand" ]; then
846 if [ -f "$(__gitdir)"/BISECT_START
]; then
847 __gitcomp
"$subcommands"
849 __gitcomp
"replay start"
854 case "$subcommand" in
855 bad|good|
reset|skip|start
)
856 __gitcomp_nl
"$(__git_refs)"
866 local i c
=1 only_local_ref
="n" has_r
="n"
868 while [ $c -lt $cword ]; do
871 -d|
-m) only_local_ref
="y" ;;
879 __gitcomp
"$(__git_refs)" "" "${cur##--set-upstream-to=}"
883 --color --no-color --verbose --abbrev= --no-abbrev
884 --track --no-track --contains --merged --no-merged
885 --set-upstream-to= --edit-description --list
890 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
891 __gitcomp_nl
"$(__git_heads)"
893 __gitcomp_nl
"$(__git_refs)"
901 local cmd
="${words[2]}"
904 __gitcomp
"create list-heads verify unbundle"
912 __git_complete_revlist
921 __git_has_doubledash
&& return
925 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
929 --quiet --ours --theirs --track --no-track --merge
930 --conflict= --orphan --patch
934 # check if --track, --no-track, or --no-guess was specified
935 # if so, disable DWIM mode
936 local flags
="--track --no-track --no-guess" track
=1
937 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
940 __gitcomp_nl
"$(__git_refs '' $track)"
947 __gitcomp
"$(__git_refs)"
954 __gitcomp
"--edit --no-commit"
957 __gitcomp_nl
"$(__git_refs)"
964 __git_has_doubledash
&& return
968 __gitcomp
"--dry-run --quiet"
1001 __git_has_doubledash
&& return
1005 __gitcomp
"default strip verbatim whitespace
1006 " "" "${cur##--cleanup=}"
1009 --reuse-message=*|
--reedit-message=*|\
1010 --fixup=*|
--squash=*)
1011 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1014 --untracked-files=*)
1015 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1020 --all --author= --signoff --verify --no-verify
1022 --amend --include --only --interactive
1023 --dry-run --reuse-message= --reedit-message=
1024 --reset-author --file= --message= --template=
1025 --cleanup= --untracked-files --untracked-files=
1026 --verbose --quiet --fixup= --squash=
1038 --all --tags --contains --abbrev= --candidates=
1039 --exact-match --debug --long --match --always
1043 __gitcomp_nl
"$(__git_refs)"
1046 __git_diff_common_options
="--stat --numstat --shortstat --summary
1047 --patch-with-stat --name-only --name-status --color
1048 --no-color --color-words --no-renames --check
1049 --full-index --binary --abbrev --diff-filter=
1050 --find-copies-harder
1051 --text --ignore-space-at-eol --ignore-space-change
1052 --ignore-all-space --exit-code --quiet --ext-diff
1054 --no-prefix --src-prefix= --dst-prefix=
1055 --inter-hunk-context=
1058 --dirstat --dirstat= --dirstat-by-file
1059 --dirstat-by-file= --cumulative
1064 __git_has_doubledash
&& return
1068 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1069 --base --ours --theirs --no-index
1070 $__git_diff_common_options
1075 __git_complete_revlist_file
1078 __git_mergetools_common
="diffuse ecmerge emerge kdiff3 meld opendiff
1079 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1084 __git_has_doubledash
&& return
1088 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1092 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1093 --base --ours --theirs
1094 --no-renames --diff-filter= --find-copies-harder
1095 --relative --ignore-submodules
1103 __git_fetch_options
="
1104 --quiet --verbose --append --upload-pack --force --keep --depth=
1105 --tags --no-tags --all --prune --dry-run
1112 __gitcomp
"$__git_fetch_options"
1116 __git_complete_remote_or_refspec
1119 __git_format_patch_options
="
1120 --stdout --attach --no-attach --thread --thread= --output-directory
1121 --numbered --start-number --numbered-files --keep-subject --signoff
1122 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1123 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1124 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1127 _git_format_patch
()
1133 " "" "${cur##--thread=}"
1137 __gitcomp
"$__git_format_patch_options"
1141 __git_complete_revlist
1149 --tags --root --unreachable --cache --no-reflogs --full
1150 --strict --verbose --lost-found
1162 __gitcomp
"--prune --aggressive"
1174 __git_match_ctag
() {
1175 awk "/^${1////\\/}/ { print \$1 }" "$2"
1180 __git_has_doubledash
&& return
1186 --text --ignore-case --word-regexp --invert-match
1187 --full-name --line-number
1188 --extended-regexp --basic-regexp --fixed-strings
1190 --files-with-matches --name-only
1191 --files-without-match
1194 --and --or --not --all-match
1200 case "$cword,$prev" in
1202 if test -r tags
; then
1203 __gitcomp_nl
"$(__git_match_ctag "$cur" tags)"
1209 __gitcomp_nl
"$(__git_refs)"
1216 __gitcomp
"--all --info --man --web"
1220 __git_compute_all_commands
1221 __gitcomp
"$__git_all_commands $(__git_aliases)
1222 attributes cli core-tutorial cvs-migration
1223 diffcore gitk glossary hooks ignore modules
1224 namespaces repository-layout tutorial tutorial-2
1234 false true umask group all world everybody
1235 " "" "${cur##--shared=}"
1239 __gitcomp
"--quiet --bare --template= --shared --shared="
1248 __git_has_doubledash
&& return
1252 __gitcomp
"--cached --deleted --modified --others --ignored
1253 --stage --directory --no-empty-directory --unmerged
1254 --killed --exclude= --exclude-from=
1255 --exclude-per-directory= --exclude-standard
1256 --error-unmatch --with-tree= --full-name
1257 --abbrev --ignored --exclude-per-directory
1267 __gitcomp_nl
"$(__git_remotes)"
1275 # Options that go well for log, shortlog and gitk
1276 __git_log_common_options
="
1278 --branches --tags --remotes
1279 --first-parent --merges --no-merges
1281 --max-age= --since= --after=
1282 --min-age= --until= --before=
1283 --min-parents= --max-parents=
1284 --no-min-parents --no-max-parents
1286 # Options that go well for log and gitk (not shortlog)
1287 __git_log_gitk_options
="
1288 --dense --sparse --full-history
1289 --simplify-merges --simplify-by-decoration
1290 --left-right --notes --no-notes
1292 # Options that go well for log and shortlog (not gitk)
1293 __git_log_shortlog_options
="
1294 --author= --committer= --grep=
1298 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1299 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1303 __git_has_doubledash
&& return
1305 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1307 if [ -f "$g/MERGE_HEAD" ]; then
1311 --pretty=*|
--format=*)
1312 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1317 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1321 __gitcomp
"long short" "" "${cur##--decorate=}"
1326 $__git_log_common_options
1327 $__git_log_shortlog_options
1328 $__git_log_gitk_options
1329 --root --topo-order --date-order --reverse
1330 --follow --full-diff
1331 --abbrev-commit --abbrev=
1332 --relative-date --date=
1333 --pretty= --format= --oneline
1336 --decorate --decorate=
1338 --parents --children
1340 $__git_diff_common_options
1341 --pickaxe-all --pickaxe-regex
1346 __git_complete_revlist
1349 __git_merge_options
="
1350 --no-commit --no-stat --log --no-log --squash --strategy
1351 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1356 __git_complete_strategy
&& return
1360 __gitcomp
"$__git_merge_options"
1363 __gitcomp_nl
"$(__git_refs)"
1370 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1383 __gitcomp_nl
"$(__git_refs)"
1390 __gitcomp
"--dry-run"
1399 __gitcomp
"--tags --all --stdin"
1404 local subcommands
='add append copy edit list prune remove show'
1405 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1407 case "$subcommand,$cur" in
1414 __gitcomp_nl
"$(__git_refs)"
1417 __gitcomp
"$subcommands --ref"
1421 add
,--reuse-message=*|append
,--reuse-message=*|\
1422 add
,--reedit-message=*|append
,--reedit-message=*)
1423 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1426 __gitcomp
'--file= --message= --reedit-message=
1433 __gitcomp
'--dry-run --verbose'
1442 __gitcomp_nl
"$(__git_refs)"
1451 __git_complete_strategy
&& return
1456 --rebase --no-rebase
1457 $__git_merge_options
1458 $__git_fetch_options
1463 __git_complete_remote_or_refspec
1470 __gitcomp_nl
"$(__git_remotes)"
1475 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--repo=}"
1480 --all --mirror --tags --dry-run --force --verbose
1481 --receive-pack= --repo= --set-upstream
1486 __git_complete_remote_or_refspec
1491 local dir
="$(__gitdir)"
1492 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1493 __gitcomp
"--continue --skip --abort"
1496 __git_complete_strategy
&& return
1499 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1504 --onto --merge --strategy --interactive
1505 --preserve-merges --stat --no-stat
1506 --committer-date-is-author-date --ignore-date
1507 --ignore-whitespace --whitespace=
1513 __gitcomp_nl
"$(__git_refs)"
1518 local subcommands
="show delete expire"
1519 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1521 if [ -z "$subcommand" ]; then
1522 __gitcomp
"$subcommands"
1524 __gitcomp_nl
"$(__git_refs)"
1528 __git_send_email_confirm_options
="always never auto cc compose"
1529 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1536 $__git_send_email_confirm_options
1537 " "" "${cur##--confirm=}"
1542 $__git_send_email_suppresscc_options
1543 " "" "${cur##--suppress-cc=}"
1547 --smtp-encryption=*)
1548 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1554 " "" "${cur##--thread=}"
1558 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1559 --compose --confirm= --dry-run --envelope-sender
1561 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1562 --no-suppress-from --no-thread --quiet
1563 --signed-off-by-cc --smtp-pass --smtp-server
1564 --smtp-server-port --smtp-encryption= --smtp-user
1565 --subject --suppress-cc= --suppress-from --thread --to
1566 --validate --no-validate
1567 $__git_format_patch_options"
1571 __git_complete_revlist
1579 __git_config_get_set_variables
()
1581 local prevword word config_file
= c
=$cword
1582 while [ $c -gt 1 ]; do
1585 --global|
--system|
--file=*)
1590 config_file
="$word $prevword"
1598 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1613 __gitcomp_nl
"$(__git_remotes)"
1617 __gitcomp_nl
"$(__git_refs)"
1621 local remote
="${prev#remote.}"
1622 remote
="${remote%.fetch}"
1623 if [ -z "$cur" ]; then
1624 COMPREPLY
=("refs/heads/")
1627 __gitcomp_nl
"$(__git_refs_remotes "$remote")"
1631 local remote
="${prev#remote.}"
1632 remote
="${remote%.push}"
1633 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" \
1634 for-each-ref --format='%(refname):%(refname)' \
1638 pull.twohead|pull.octopus
)
1639 __git_compute_merge_strategies
1640 __gitcomp
"$__git_merge_strategies"
1643 color.branch|color.
diff|color.interactive|\
1644 color.showbranch|color.status|color.ui
)
1645 __gitcomp
"always never auto"
1649 __gitcomp
"false true"
1654 normal black red green yellow blue magenta cyan white
1655 bold dim ul blink reverse
1660 __gitcomp
"man info web html"
1664 __gitcomp
"$__git_log_date_formats"
1667 sendemail.aliasesfiletype
)
1668 __gitcomp
"mutt mailrc pine elm gnus"
1672 __gitcomp
"$__git_send_email_confirm_options"
1675 sendemail.suppresscc
)
1676 __gitcomp
"$__git_send_email_suppresscc_options"
1679 --get|
--get-all|
--unset|
--unset-all)
1680 __gitcomp_nl
"$(__git_config_get_set_variables)"
1691 --global --system --file=
1692 --list --replace-all
1693 --get --get-all --get-regexp
1694 --add --unset --unset-all
1695 --remove-section --rename-section
1700 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1701 __gitcomp
"remote merge mergeoptions rebase" "$pfx" "$cur_"
1705 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1706 __gitcomp_nl
"$(__git_heads)" "$pfx" "$cur_" "."
1710 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1712 argprompt cmd confirm needsfile noconsole norescan
1713 prompt revprompt revunmerged title
1718 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1719 __gitcomp
"cmd path" "$pfx" "$cur_"
1723 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1724 __gitcomp
"cmd path" "$pfx" "$cur_"
1728 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1729 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur_"
1733 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1734 __git_compute_all_commands
1735 __gitcomp_nl
"$__git_all_commands" "$pfx" "$cur_"
1739 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1741 url proxy fetch push mirror skipDefaultUpdate
1742 receivepack uploadpack tagopt pushurl
1747 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1748 __gitcomp_nl
"$(__git_remotes)" "$pfx" "$cur_" "."
1752 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1753 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur_"
1759 advice.commitBeforeMerge
1761 advice.implicitIdentity
1762 advice.pushNonFastForward
1763 advice.resolveConflict
1767 apply.ignorewhitespace
1769 branch.autosetupmerge
1770 branch.autosetuprebase
1774 color.branch.current
1779 color.decorate.branch
1780 color.decorate.remoteBranch
1781 color.decorate.stash
1791 color.diff.whitespace
1796 color.grep.linenumber
1799 color.grep.separator
1801 color.interactive.error
1802 color.interactive.header
1803 color.interactive.help
1804 color.interactive.prompt
1809 color.status.changed
1811 color.status.nobranch
1812 color.status.untracked
1813 color.status.updated
1822 core.bigFileThreshold
1825 core.deltaBaseCacheLimit
1830 core.fsyncobjectfiles
1832 core.ignoreCygwinFSTricks
1835 core.logAllRefUpdates
1836 core.loosecompression
1839 core.packedGitWindowSize
1841 core.preferSymlinkRefs
1844 core.repositoryFormatVersion
1846 core.sharedRepository
1850 core.warnAmbiguousRefs
1853 diff.autorefreshindex
1856 diff.ignoreSubmodules
1861 diff.suppressBlankEmpty
1866 fetch.recurseSubmodules
1875 format.subjectprefix
1886 gc.reflogexpireunreachable
1890 gitcvs.commitmsgannotation
1891 gitcvs.dbTableNamePrefix
1902 gui.copyblamethreshold
1906 gui.matchtrackingbranch
1907 gui.newbranchtemplate
1908 gui.pruneduringfetch
1909 gui.spellingdictionary
1924 http.sslCertPasswordProtected
1929 i18n.logOutputEncoding
1935 imap.preformattedHTML
1945 interactive.singlekey
1961 mergetool.keepBackup
1962 mergetool.keepTemporaries
1967 notes.rewrite.rebase
1971 pack.deltaCacheLimit
1987 receive.denyCurrentBranch
1988 receive.denyDeleteCurrent
1990 receive.denyNonFastForwards
1993 receive.updateserverinfo
1995 repack.usedeltabaseoffset
1999 sendemail.aliasesfile
2000 sendemail.aliasfiletype
2004 sendemail.chainreplyto
2006 sendemail.envelopesender
2010 sendemail.signedoffbycc
2011 sendemail.smtpdomain
2012 sendemail.smtpencryption
2014 sendemail.smtpserver
2015 sendemail.smtpserveroption
2016 sendemail.smtpserverport
2018 sendemail.suppresscc
2019 sendemail.suppressfrom
2024 status.relativePaths
2025 status.showUntrackedFiles
2026 status.submodulesummary
2029 transfer.unpackLimit
2041 local subcommands
="add rename remove set-head set-branches set-url show prune update"
2042 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2043 if [ -z "$subcommand" ]; then
2044 __gitcomp
"$subcommands"
2048 case "$subcommand" in
2049 rename|remove|set-url|show|prune
)
2050 __gitcomp_nl
"$(__git_remotes)"
2052 set-head|set-branches
)
2053 __git_complete_remote_or_refspec
2056 local i c
='' IFS
=$
'\n'
2057 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2071 __gitcomp_nl
"$(__git_refs)"
2076 __git_has_doubledash
&& return
2080 __gitcomp
"--merge --mixed --hard --soft --patch"
2084 __gitcomp_nl
"$(__git_refs)"
2091 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2095 __gitcomp_nl
"$(__git_refs)"
2100 __git_has_doubledash
&& return
2104 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2113 __git_has_doubledash
&& return
2118 $__git_log_common_options
2119 $__git_log_shortlog_options
2120 --numbered --summary
2125 __git_complete_revlist
2130 __git_has_doubledash
&& return
2133 --pretty=*|
--format=*)
2134 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2139 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2140 $__git_diff_common_options
2153 --all --remotes --topo-order --current --more=
2154 --list --independent --merge-base --no-name
2156 --sha1-name --sparse --topics --reflog
2161 __git_complete_revlist
2166 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2167 local subcommands
='save list show apply clear drop pop create branch'
2168 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2169 if [ -z "$subcommand" ]; then
2172 __gitcomp
"$save_opts"
2175 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2176 __gitcomp
"$subcommands"
2183 case "$subcommand,$cur" in
2185 __gitcomp
"$save_opts"
2188 __gitcomp
"--index --quiet"
2190 show
,--*|drop
,--*|branch
,--*)
2193 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2194 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" stash list \
2195 | sed -n -e 's/:.*//p')"
2206 __git_has_doubledash
&& return
2208 local subcommands
="add status init update summary foreach sync"
2209 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2212 __gitcomp
"--quiet --cached"
2215 __gitcomp
"$subcommands"
2225 init fetch clone rebase dcommit log find-rev
2226 set-tree commit-diff info create-ignore propget
2227 proplist show-ignore show-externals branch tag blame
2228 migrate mkdirs reset gc
2230 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2231 if [ -z "$subcommand" ]; then
2232 __gitcomp
"$subcommands"
2234 local remote_opts
="--username= --config-dir= --no-auth-cache"
2236 --follow-parent --authors-file= --repack=
2237 --no-metadata --use-svm-props --use-svnsync-props
2238 --log-window-size= --no-checkout --quiet
2239 --repack-flags --use-log-author --localtime
2240 --ignore-paths= $remote_opts
2243 --template= --shared= --trunk= --tags=
2244 --branches= --stdlayout --minimize-url
2245 --no-metadata --use-svm-props --use-svnsync-props
2246 --rewrite-root= --prefix= --use-log-author
2247 --add-author-from $remote_opts
2250 --edit --rmdir --find-copies-harder --copy-similarity=
2253 case "$subcommand,$cur" in
2255 __gitcomp
"--revision= --fetch-all $fc_opts"
2258 __gitcomp
"--revision= $fc_opts $init_opts"
2261 __gitcomp
"$init_opts"
2265 --merge --strategy= --verbose --dry-run
2266 --fetch-all --no-rebase --commit-url
2267 --revision --interactive $cmt_opts $fc_opts
2271 __gitcomp
"--stdin $cmt_opts $fc_opts"
2273 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2274 show-externals
,--*|mkdirs
,--*)
2275 __gitcomp
"--revision="
2279 --limit= --revision= --verbose --incremental
2280 --oneline --show-commit --non-recursive
2281 --authors-file= --color
2286 --merge --verbose --strategy= --local
2287 --fetch-all --dry-run $fc_opts
2291 __gitcomp
"--message= --file= --revision= $cmt_opts"
2297 __gitcomp
"--dry-run --message --tag"
2300 __gitcomp
"--dry-run --message"
2303 __gitcomp
"--git-format"
2307 --config-dir= --ignore-paths= --minimize
2308 --no-auth-cache --username=
2312 __gitcomp
"--revision= --parent"
2324 while [ $c -lt $cword ]; do
2328 __gitcomp_nl
"$(__git_tags)"
2344 __gitcomp_nl
"$(__git_tags)"
2350 __gitcomp_nl
"$(__git_refs)"
2362 local i c
=1 command __git_dir
2364 while [ $c -lt $cword ]; do
2367 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2368 --bare) __git_dir
="." ;;
2369 --help) command="help"; break ;;
2372 *) command="$i"; break ;;
2377 if [ -z "$command" ]; then
2391 --no-replace-objects
2395 *) __git_compute_porcelain_commands
2396 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2401 local completion_func
="_git_${command//-/_}"
2402 declare -f $completion_func >/dev
/null
&& $completion_func && return
2404 local expansion
=$
(__git_aliased_command
"$command")
2405 if [ -n "$expansion" ]; then
2406 completion_func
="_git_${expansion//-/_}"
2407 declare -f $completion_func >/dev
/null
&& $completion_func
2413 __git_has_doubledash
&& return
2415 local g
="$(__gitdir)"
2417 if [ -f "$g/MERGE_HEAD" ]; then
2423 $__git_log_common_options
2424 $__git_log_gitk_options
2430 __git_complete_revlist
2435 if [[ -n ${ZSH_VERSION-} ]]; then
2439 # workaround zsh's bug that leaves 'words' as a special
2440 # variable in versions < 4.3.12
2443 # workaround zsh's bug that quotes spaces in the COMPREPLY
2444 # array if IFS doesn't contain spaces.
2447 local cur words cword prev
2448 _get_comp_words_by_ref
-n =: cur words cword prev
2452 # Setup completion for certain functions defined above by setting common
2453 # variables and workarounds.
2454 # This is NOT a public function; use at your own risk.
2457 local wrapper
="__git_wrap${2}"
2458 eval "$wrapper () { __git_func_wrap $2 ; }"
2459 complete
-o bashdefault
-o default
-o nospace
-F $wrapper $1 2>/dev
/null \
2460 || complete
-o default
-o nospace
-F $wrapper $1
2463 # wrapper for backwards compatibility
2466 __git_wrap__git_main
2469 # wrapper for backwards compatibility
2472 __git_wrap__gitk_main
2475 __git_complete git __git_main
2476 __git_complete gitk __gitk_main
2478 # The following are necessary only for Cygwin, and only are needed
2479 # when the user has tab-completed the executable name and consequently
2480 # included the '.exe' suffix.
2482 if [ Cygwin
= "$(uname -o 2>/dev/null)" ]; then
2483 __git_complete git.exe __git_main