1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) tree paths within 'ref:path/to/file' expressions
14 # *) file paths within current working directory and index
15 # *) common --long-options
17 # To use these routines:
19 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
20 # 2) Add the following line to your .bashrc/.zshrc:
21 # source ~/.git-completion.sh
22 # 3) Consider changing your PS1 to also show the current branch,
23 # see git-prompt.sh for details.
25 case "$COMP_WORDBREAKS" in
27 *) COMP_WORDBREAKS
="$COMP_WORDBREAKS:"
30 # __gitdir accepts 0 or 1 arguments (i.e., location)
31 # returns location of .git repo
34 if [ -z "${1-}" ]; then
35 if [ -n "${__git_dir-}" ]; then
37 elif [ -n "${GIT_DIR-}" ]; then
38 test -d "${GIT_DIR-}" ||
return 1
40 elif [ -d .git
]; then
43 git rev-parse
--git-dir 2>/dev
/null
45 elif [ -d "$1/.git" ]; then
52 # The following function is based on code from:
54 # bash_completion - programmable completion functions for bash 3.2+
56 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
57 # © 2009-2010, Bash Completion Maintainers
58 # <bash-completion-devel@lists.alioth.debian.org>
60 # This program is free software; you can redistribute it and/or modify
61 # it under the terms of the GNU General Public License as published by
62 # the Free Software Foundation; either version 2, or (at your option)
65 # This program is distributed in the hope that it will be useful,
66 # but WITHOUT ANY WARRANTY; without even the implied warranty of
67 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68 # GNU General Public License for more details.
70 # You should have received a copy of the GNU General Public License
71 # along with this program; if not, write to the Free Software Foundation,
72 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
74 # The latest version of this software can be obtained here:
76 # http://bash-completion.alioth.debian.org/
80 # This function can be used to access a tokenized list of words
81 # on the command line:
83 # __git_reassemble_comp_words_by_ref '=:'
84 # if test "${words_[cword_-1]}" = -w
89 # The argument should be a collection of characters from the list of
90 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
93 # This is roughly equivalent to going back in time and setting
94 # COMP_WORDBREAKS to exclude those characters. The intent is to
95 # make option types like --date=<type> and <rev>:<path> easy to
96 # recognize by treating each shell word as a single token.
98 # It is best not to set COMP_WORDBREAKS directly because the value is
99 # shared with other completion scripts. By the time the completion
100 # function gets called, COMP_WORDS has already been populated so local
101 # changes to COMP_WORDBREAKS have no effect.
103 # Output: words_, cword_, cur_.
105 __git_reassemble_comp_words_by_ref
()
107 local exclude i j first
108 # Which word separators to exclude?
109 exclude
="${1//[^$COMP_WORDBREAKS]}"
111 if [ -z "$exclude" ]; then
112 words_
=("${COMP_WORDS[@]}")
115 # List of word completion separators has shrunk;
116 # re-assemble words to complete.
117 for ((i
=0, j
=0; i
< ${#COMP_WORDS[@]}; i
++, j
++)); do
118 # Append each nonempty word consisting of just
119 # word separator characters to the current word.
123 [ -n "${COMP_WORDS[$i]}" ] &&
124 # word consists of excluded word separators
125 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
127 # Attach to the previous token,
128 # unless the previous token is the command name.
129 if [ $j -ge 2 ] && [ -n "$first" ]; then
133 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
134 if [ $i = $COMP_CWORD ]; then
137 if (($i < ${#COMP_WORDS[@]} - 1)); then
144 words_
[$j]=${words_[j]}${COMP_WORDS[i]}
145 if [ $i = $COMP_CWORD ]; then
151 if ! type _get_comp_words_by_ref
>/dev
/null
2>&1; then
152 _get_comp_words_by_ref
()
154 local exclude cur_ words_ cword_
155 if [ "$1" = "-n" ]; then
159 __git_reassemble_comp_words_by_ref
"$exclude"
160 cur_
=${words_[cword_]}
161 while [ $# -gt 0 ]; do
167 prev
=${words_[$cword_-1]}
170 words
=("${words_[@]}")
185 if [[ "$x" == "$3"* ]]; then
186 COMPREPLY
[i
++]="$2$x$4"
191 # Generates completion reply, appending a space to possible completion words,
193 # It accepts 1 to 4 arguments:
194 # 1: List of possible completion words.
195 # 2: A prefix to be added to each possible completion word (optional).
196 # 3: Generate possible completion matches for this word (optional).
197 # 4: A suffix to be appended to each possible completion word (optional).
200 local cur_
="${3-$cur}"
206 local c i
=0 IFS
=$
' \t\n'
209 if [[ $c == "$cur_"* ]]; then
214 COMPREPLY
[i
++]="${2-}$c"
221 # Generates completion reply from newline-separated possible completion words
222 # by appending a space to all of them.
223 # It accepts 1 to 4 arguments:
224 # 1: List of possible completion words, separated by a single newline.
225 # 2: A prefix to be added to each possible completion word (optional).
226 # 3: Generate possible completion matches for this word (optional).
227 # 4: A suffix to be appended to each possible completion word instead of
228 # the default space (optional). If specified but empty, nothing is
233 __gitcompadd
"$1" "${2-}" "${3-$cur}" "${4- }"
236 # Generates completion reply with compgen from newline-separated possible
237 # completion filenames.
238 # It accepts 1 to 3 arguments:
239 # 1: List of possible completion filenames, separated by a single newline.
240 # 2: A directory prefix to be added to each possible completion filename
242 # 3: Generate possible completion matches for this word (optional).
247 # XXX does not work when the directory prefix contains a tilde,
248 # since tilde expansion is not applied.
249 # This means that COMPREPLY will be empty and Bash default
250 # completion will be used.
251 __gitcompadd
"$1" "${2-}" "${3-$cur}" ""
253 # use a hack to enable file mode in bash < 4
254 compopt
-o filenames
+o nospace
2>/dev
/null ||
255 compgen
-f /non-existing-dir
/ > /dev
/null
258 # Execute 'git ls-files', unless the --committable option is specified, in
259 # which case it runs 'git diff-index' to find out the files that can be
260 # committed. It return paths relative to the directory specified in the first
261 # argument, and using the options specified in the second argument.
262 __git_ls_files_helper
()
265 test -n "${CDPATH+set}" && unset CDPATH
267 if [ "$2" == "--committable" ]; then
268 git diff-index
--name-only --relative HEAD
270 # NOTE: $2 is not quoted in order to support multiple options
271 git ls-files
--exclude-standard $2
277 # __git_index_files accepts 1 or 2 arguments:
278 # 1: Options to pass to ls-files (required).
279 # 2: A directory path (optional).
280 # If provided, only files within the specified directory are listed.
281 # Sub directories are never recursed. Path must have a trailing
285 local dir
="$(__gitdir)" root
="${2-.}" file
287 if [ -d "$dir" ]; then
288 __git_ls_files_helper
"$root" "$1" |
289 while read -r file; do
291 ?
*/*) echo "${file%%/*}" ;;
300 local dir
="$(__gitdir)"
301 if [ -d "$dir" ]; then
302 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
310 local dir
="$(__gitdir)"
311 if [ -d "$dir" ]; then
312 git
--git-dir="$dir" for-each-ref
--format='%(refname:short)' \
318 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
319 # presence of 2nd argument means use the guess heuristic employed
320 # by checkout for tracking branches
323 local i
hash dir
="$(__gitdir "${1-}")" track
="${2-}"
325 if [ -d "$dir" ]; then
333 for i
in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD
; do
334 if [ -e "$dir/$i" ]; then echo $i; fi
336 format
="refname:short"
337 refs
="refs/tags refs/heads refs/remotes"
340 git
--git-dir="$dir" for-each-ref
--format="%($format)" \
342 if [ -n "$track" ]; then
343 # employ the heuristic used by git checkout
344 # Try to find a remote branch that matches the completion word
345 # but only output if the branch name is unique
347 git
--git-dir="$dir" for-each-ref
--shell --format="ref=%(refname:short)" \
349 while read -r entry
; do
352 if [[ "$ref" == "$cur"* ]]; then
355 done |
sort |
uniq -u
361 git ls-remote
"$dir" "$cur*" 2>/dev
/null | \
362 while read -r hash i
; do
371 git for-each-ref
--format="%(refname:short)" -- "refs/remotes/$dir/" |
sed -e "s#^$dir/##"
376 # __git_refs2 requires 1 argument (to pass to __git_refs)
380 for i
in $
(__git_refs
"$1"); do
385 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
386 __git_refs_remotes
()
389 git ls-remote
"$1" 'refs/heads/*' 2>/dev
/null | \
390 while read -r hash i
; do
391 echo "$i:refs/remotes/$1/${i#refs/heads/}"
397 local i IFS
=$
'\n' d
="$(__gitdir)"
398 test -d "$d/remotes" && ls -1 "$d/remotes"
399 for i
in $
(git
--git-dir="$d" config
--get-regexp 'remote\..*\.url' 2>/dev
/null
); do
405 __git_list_merge_strategies
()
407 git merge
-s help 2>&1 |
408 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
417 __git_merge_strategies
=
418 # 'git merge -s help' (and thus detection of the merge strategy
419 # list) fails, unfortunately, if run outside of any git working
420 # tree. __git_merge_strategies is set to the empty string in
421 # that case, and the detection will be repeated the next time it
423 __git_compute_merge_strategies
()
425 test -n "$__git_merge_strategies" ||
426 __git_merge_strategies
=$
(__git_list_merge_strategies
)
429 __git_complete_revlist_file
()
431 local pfx
ls ref cur_
="$cur"
451 case "$COMP_WORDBREAKS" in
453 *) pfx
="$ref:$pfx" ;;
456 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" ls-tree "$ls" 2>/dev/null \
457 | sed '/^100... blob /{
473 pfx
="${cur_%...*}..."
475 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
480 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
483 __gitcomp_nl
"$(__git_refs)"
489 # __git_complete_index_file requires 1 argument:
490 # 1: the options to pass to ls-file
492 # The exception is --committable, which finds the files appropriate commit.
493 __git_complete_index_file
()
495 local pfx
="" cur_
="$cur"
505 __gitcomp_file
"$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
508 __git_complete_file
()
510 __git_complete_revlist_file
513 __git_complete_revlist
()
515 __git_complete_revlist_file
518 __git_complete_remote_or_refspec
()
520 local cur_
="$cur" cmd
="${words[1]}"
521 local i c
=2 remote
="" pfx
="" lhs
=1 no_complete_refspec
=0
522 if [ "$cmd" = "remote" ]; then
525 while [ $c -lt $cword ]; do
528 --mirror) [ "$cmd" = "push" ] && no_complete_refspec
=1 ;;
531 push
) no_complete_refspec
=1 ;;
539 *) remote
="$i"; break ;;
543 if [ -z "$remote" ]; then
544 __gitcomp_nl
"$(__git_remotes)"
547 if [ $no_complete_refspec = 1 ]; then
550 [ "$remote" = "." ] && remote
=
553 case "$COMP_WORDBREAKS" in
555 *) pfx
="${cur_%%:*}:" ;;
567 if [ $lhs = 1 ]; then
568 __gitcomp_nl
"$(__git_refs2 "$remote")" "$pfx" "$cur_"
570 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
574 if [ $lhs = 1 ]; then
575 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
577 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
581 if [ $lhs = 1 ]; then
582 __gitcomp_nl
"$(__git_refs)" "$pfx" "$cur_"
584 __gitcomp_nl
"$(__git_refs "$remote")" "$pfx" "$cur_"
590 __git_complete_strategy
()
592 __git_compute_merge_strategies
595 __gitcomp
"$__git_merge_strategies"
600 __gitcomp
"$__git_merge_strategies" "" "${cur##--strategy=}"
608 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
610 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
612 git
help -a|
egrep '^ [a-zA-Z0-9]'
616 __git_list_all_commands
()
619 for i
in $
(__git_commands
)
622 *--*) : helper pattern
;;
629 __git_compute_all_commands
()
631 test -n "$__git_all_commands" ||
632 __git_all_commands
=$
(__git_list_all_commands
)
635 __git_list_porcelain_commands
()
638 __git_compute_all_commands
639 for i
in $__git_all_commands
642 *--*) : helper pattern
;;
643 applymbox
) : ask gittus
;;
644 applypatch
) : ask gittus
;;
645 archimport
) : import
;;
646 cat-file
) : plumbing
;;
647 check-attr
) : plumbing
;;
648 check-ignore
) : plumbing
;;
649 check-mailmap
) : plumbing
;;
650 check-ref-format
) : plumbing
;;
651 checkout-index
) : plumbing
;;
652 commit-tree
) : plumbing
;;
653 count-objects
) : infrequent
;;
654 credential-cache
) : credentials helper
;;
655 credential-store
) : credentials helper
;;
656 cvsexportcommit
) : export;;
657 cvsimport
) : import
;;
658 cvsserver
) : daemon
;;
660 diff-files
) : plumbing
;;
661 diff-index
) : plumbing
;;
662 diff-tree
) : plumbing
;;
663 fast-import
) : import
;;
664 fast-export
) : export;;
665 fsck-objects
) : plumbing
;;
666 fetch-pack
) : plumbing
;;
667 fmt-merge-msg
) : plumbing
;;
668 for-each-ref
) : plumbing
;;
669 hash-object
) : plumbing
;;
670 http-
*) : transport
;;
671 index-pack
) : plumbing
;;
672 init-db
) : deprecated
;;
673 local-fetch
) : plumbing
;;
674 lost-found
) : infrequent
;;
675 ls-files
) : plumbing
;;
676 ls-remote
) : plumbing
;;
677 ls-tree
) : plumbing
;;
678 mailinfo
) : plumbing
;;
679 mailsplit
) : plumbing
;;
680 merge-
*) : plumbing
;;
683 pack-objects
) : plumbing
;;
684 pack-redundant
) : plumbing
;;
685 pack-refs
) : plumbing
;;
686 parse-remote
) : plumbing
;;
687 patch-id
) : plumbing
;;
688 peek-remote
) : plumbing
;;
690 prune-packed
) : plumbing
;;
691 quiltimport
) : import
;;
692 read-tree
) : plumbing
;;
693 receive-pack
) : plumbing
;;
694 remote-
*) : transport
;;
695 repo-config
) : deprecated
;;
697 rev-list
) : plumbing
;;
698 rev-parse
) : plumbing
;;
699 runstatus
) : plumbing
;;
700 sh-setup
) : internal
;;
702 show-ref
) : plumbing
;;
703 send-pack
) : plumbing
;;
704 show-index
) : plumbing
;;
706 stripspace
) : plumbing
;;
707 symbolic-ref
) : plumbing
;;
708 tar-tree
) : deprecated
;;
709 unpack-file
) : plumbing
;;
710 unpack-objects
) : plumbing
;;
711 update-index
) : plumbing
;;
712 update-ref
) : plumbing
;;
713 update-server-info
) : daemon
;;
714 upload-archive
) : plumbing
;;
715 upload-pack
) : plumbing
;;
716 write-tree
) : plumbing
;;
718 verify-pack
) : infrequent
;;
719 verify-tag
) : plumbing
;;
725 __git_porcelain_commands
=
726 __git_compute_porcelain_commands
()
728 __git_compute_all_commands
729 test -n "$__git_porcelain_commands" ||
730 __git_porcelain_commands
=$
(__git_list_porcelain_commands
)
733 __git_pretty_aliases
()
736 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "pretty\..*" 2>/dev
/null
); do
749 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "alias\..*" 2>/dev
/null
); do
759 # __git_aliased_command requires 1 argument
760 __git_aliased_command
()
762 local word cmdline
=$
(git
--git-dir="$(__gitdir)" \
763 config
--get "alias.$1")
764 for word
in $cmdline; do
770 \
!*) : shell
command alias ;;
772 *=*) : setting env
;;
781 # __git_find_on_cmdline requires 1 argument
782 __git_find_on_cmdline
()
784 local word subcommand c
=1
785 while [ $c -lt $cword ]; do
787 for subcommand
in $1; do
788 if [ "$subcommand" = "$word" ]; then
797 __git_has_doubledash
()
800 while [ $c -lt $cword ]; do
801 if [ "--" = "${words[c]}" ]; then
809 # Try to count non option arguments passed on the command line for the
810 # specified git command.
811 # When options are used, it is necessary to use the special -- option to
812 # tell the implementation were non option arguments begin.
813 # XXX this can not be improved, since options can appear everywhere, as
817 # __git_count_arguments requires 1 argument: the git command executed.
818 __git_count_arguments
()
822 # Skip "git" (first argument)
823 for ((i
=1; i
< ${#words[@]}; i
++)); do
828 # Good; we can assume that the following are only non
833 # Skip the specified git command and discard git
846 __git_whitespacelist
="nowarn warn error error-all fix"
850 local dir
="$(__gitdir)"
851 if [ -d "$dir"/rebase-apply
]; then
852 __gitcomp
"--skip --continue --resolved --abort"
857 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
862 --3way --committer-date-is-author-date --ignore-date
863 --ignore-whitespace --ignore-space-change
864 --interactive --keep --no-utf8 --signoff --utf8
865 --whitespace= --scissors
875 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
880 --stat --numstat --summary --check --index
881 --cached --index-info --reverse --reject --unidiff-zero
882 --apply --no-add --exclude=
883 --ignore-whitespace --ignore-space-change
884 --whitespace= --inaccurate-eof --verbose
895 --interactive --refresh --patch --update --dry-run
896 --ignore-errors --intent-to-add
901 # XXX should we check for --update and --all options ?
902 __git_complete_index_file
"--others --modified --directory --no-empty-directory"
909 __gitcomp
"$(git archive --list)" "" "${cur##--format=}"
913 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--remote=}"
918 --format= --list --verbose
919 --prefix= --remote= --exec=
929 __git_has_doubledash
&& return
931 local subcommands
="start bad good skip reset visualize replay log run"
932 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
933 if [ -z "$subcommand" ]; then
934 if [ -f "$(__gitdir)"/BISECT_START
]; then
935 __gitcomp
"$subcommands"
937 __gitcomp
"replay start"
942 case "$subcommand" in
943 bad|good|
reset|skip|start
)
944 __gitcomp_nl
"$(__git_refs)"
953 local i c
=1 only_local_ref
="n" has_r
="n"
955 while [ $c -lt $cword ]; do
958 -d|
-m) only_local_ref
="y" ;;
966 __gitcomp
"$(__git_refs)" "" "${cur##--set-upstream-to=}"
970 --color --no-color --verbose --abbrev= --no-abbrev
971 --track --no-track --contains --merged --no-merged
972 --set-upstream-to= --edit-description --list
977 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
978 __gitcomp_nl
"$(__git_heads)"
980 __gitcomp_nl
"$(__git_refs)"
988 local cmd
="${words[2]}"
991 __gitcomp
"create list-heads verify unbundle"
999 __git_complete_revlist
1008 __git_has_doubledash
&& return
1012 __gitcomp
"diff3 merge" "" "${cur##--conflict=}"
1016 --quiet --ours --theirs --track --no-track --merge
1017 --conflict= --orphan --patch
1021 # check if --track, --no-track, or --no-guess was specified
1022 # if so, disable DWIM mode
1023 local flags
="--track --no-track --no-guess" track
=1
1024 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1027 __gitcomp_nl
"$(__git_refs '' $track)"
1034 __gitcomp
"$(__git_refs)"
1039 local dir
="$(__gitdir)"
1040 if [ -f "$dir"/CHERRY_PICK_HEAD
]; then
1041 __gitcomp
"--continue --quit --abort"
1046 __gitcomp
"--edit --no-commit --signoff --strategy= --mainline"
1049 __gitcomp_nl
"$(__git_refs)"
1058 __gitcomp
"--dry-run --quiet"
1063 # XXX should we check for -x option ?
1064 __git_complete_index_file
"--others --directory"
1096 __gitcomp_nl
"$(__git_refs)" "" "${cur}"
1103 __gitcomp
"default strip verbatim whitespace
1104 " "" "${cur##--cleanup=}"
1107 --reuse-message=*|
--reedit-message=*|\
1108 --fixup=*|
--squash=*)
1109 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1112 --untracked-files=*)
1113 __gitcomp
"all no normal" "" "${cur##--untracked-files=}"
1118 --all --author= --signoff --verify --no-verify
1120 --amend --include --only --interactive
1121 --dry-run --reuse-message= --reedit-message=
1122 --reset-author --file= --message= --template=
1123 --cleanup= --untracked-files --untracked-files=
1124 --verbose --quiet --fixup= --squash=
1129 if git rev-parse
--verify --quiet HEAD
>/dev
/null
; then
1130 __git_complete_index_file
"--committable"
1132 # This is the first commit
1133 __git_complete_index_file
"--cached"
1142 --all --tags --contains --abbrev= --candidates=
1143 --exact-match --debug --long --match --always
1147 __gitcomp_nl
"$(__git_refs)"
1150 __git_diff_algorithms
="myers minimal patience histogram"
1152 __git_diff_common_options
="--stat --numstat --shortstat --summary
1153 --patch-with-stat --name-only --name-status --color
1154 --no-color --color-words --no-renames --check
1155 --full-index --binary --abbrev --diff-filter=
1156 --find-copies-harder
1157 --text --ignore-space-at-eol --ignore-space-change
1158 --ignore-all-space --exit-code --quiet --ext-diff
1160 --no-prefix --src-prefix= --dst-prefix=
1161 --inter-hunk-context=
1162 --patience --histogram --minimal
1164 --dirstat --dirstat= --dirstat-by-file
1165 --dirstat-by-file= --cumulative
1171 __git_has_doubledash
&& return
1175 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1179 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1180 --base --ours --theirs --no-index
1181 $__git_diff_common_options
1186 __git_complete_revlist_file
1189 __git_mergetools_common
="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1190 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1195 __git_has_doubledash
&& return
1199 __gitcomp
"$__git_mergetools_common kompare" "" "${cur##--tool=}"
1203 __gitcomp
"--cached --staged --pickaxe-all --pickaxe-regex
1204 --base --ours --theirs
1205 --no-renames --diff-filter= --find-copies-harder
1206 --relative --ignore-submodules
1211 __git_complete_revlist_file
1214 __git_fetch_options
="
1215 --quiet --verbose --append --upload-pack --force --keep --depth=
1216 --tags --no-tags --all --prune --dry-run
1223 __gitcomp
"$__git_fetch_options"
1227 __git_complete_remote_or_refspec
1230 __git_format_patch_options
="
1231 --stdout --attach --no-attach --thread --thread= --no-thread
1232 --numbered --start-number --numbered-files --keep-subject --signoff
1233 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1234 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1235 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1236 --output-directory --reroll-count --to= --quiet --notes
1239 _git_format_patch
()
1245 " "" "${cur##--thread=}"
1249 __gitcomp
"$__git_format_patch_options"
1253 __git_complete_revlist
1261 --tags --root --unreachable --cache --no-reflogs --full
1262 --strict --verbose --lost-found
1273 __gitcomp
"--prune --aggressive"
1284 __git_match_ctag
() {
1285 awk "/^${1////\\/}/ { print \$1 }" "$2"
1290 __git_has_doubledash
&& return
1296 --text --ignore-case --word-regexp --invert-match
1297 --full-name --line-number
1298 --extended-regexp --basic-regexp --fixed-strings
1300 --files-with-matches --name-only
1301 --files-without-match
1304 --and --or --not --all-match
1310 case "$cword,$prev" in
1312 if test -r tags
; then
1313 __gitcomp_nl
"$(__git_match_ctag "$cur" tags)"
1319 __gitcomp_nl
"$(__git_refs)"
1326 __gitcomp
"--all --info --man --web"
1330 __git_compute_all_commands
1331 __gitcomp
"$__git_all_commands $(__git_aliases)
1332 attributes cli core-tutorial cvs-migration
1333 diffcore gitk glossary hooks ignore modules
1334 namespaces repository-layout tutorial tutorial-2
1344 false true umask group all world everybody
1345 " "" "${cur##--shared=}"
1349 __gitcomp
"--quiet --bare --template= --shared --shared="
1359 __gitcomp
"--cached --deleted --modified --others --ignored
1360 --stage --directory --no-empty-directory --unmerged
1361 --killed --exclude= --exclude-from=
1362 --exclude-per-directory= --exclude-standard
1363 --error-unmatch --with-tree= --full-name
1364 --abbrev --ignored --exclude-per-directory
1370 # XXX ignore options like --modified and always suggest all cached
1372 __git_complete_index_file
"--cached"
1377 __gitcomp_nl
"$(__git_remotes)"
1385 # Options that go well for log, shortlog and gitk
1386 __git_log_common_options
="
1388 --branches --tags --remotes
1389 --first-parent --merges --no-merges
1391 --max-age= --since= --after=
1392 --min-age= --until= --before=
1393 --min-parents= --max-parents=
1394 --no-min-parents --no-max-parents
1396 # Options that go well for log and gitk (not shortlog)
1397 __git_log_gitk_options
="
1398 --dense --sparse --full-history
1399 --simplify-merges --simplify-by-decoration
1400 --left-right --notes --no-notes
1402 # Options that go well for log and shortlog (not gitk)
1403 __git_log_shortlog_options
="
1404 --author= --committer= --grep=
1408 __git_log_pretty_formats
="oneline short medium full fuller email raw format:"
1409 __git_log_date_formats
="relative iso8601 rfc2822 short local default raw"
1413 __git_has_doubledash
&& return
1415 local g
="$(git rev-parse --git-dir 2>/dev/null)"
1417 if [ -f "$g/MERGE_HEAD" ]; then
1421 --pretty=*|
--format=*)
1422 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
1427 __gitcomp
"$__git_log_date_formats" "" "${cur##--date=}"
1431 __gitcomp
"long short" "" "${cur##--decorate=}"
1436 $__git_log_common_options
1437 $__git_log_shortlog_options
1438 $__git_log_gitk_options
1439 --root --topo-order --date-order --reverse
1440 --follow --full-diff
1441 --abbrev-commit --abbrev=
1442 --relative-date --date=
1443 --pretty= --format= --oneline
1446 --decorate --decorate=
1448 --parents --children
1450 $__git_diff_common_options
1451 --pickaxe-all --pickaxe-regex
1456 __git_complete_revlist
1459 __git_merge_options
="
1460 --no-commit --no-stat --log --no-log --squash --strategy
1461 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1466 __git_complete_strategy
&& return
1470 __gitcomp
"$__git_merge_options"
1473 __gitcomp_nl
"$(__git_refs)"
1480 __gitcomp
"$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1492 __gitcomp_nl
"$(__git_refs)"
1499 __gitcomp
"--dry-run"
1504 if [ $
(__git_count_arguments
"mv") -gt 0 ]; then
1505 # We need to show both cached and untracked files (including
1506 # empty directories) since this may not be the last argument.
1507 __git_complete_index_file
"--cached --others --directory"
1509 __git_complete_index_file
"--cached"
1515 __gitcomp
"--tags --all --stdin"
1520 local subcommands
='add append copy edit list prune remove show'
1521 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1523 case "$subcommand,$cur" in
1530 __gitcomp_nl
"$(__git_refs)"
1533 __gitcomp
"$subcommands --ref"
1537 add
,--reuse-message=*|append
,--reuse-message=*|\
1538 add
,--reedit-message=*|append
,--reedit-message=*)
1539 __gitcomp_nl
"$(__git_refs)" "" "${cur#*=}"
1542 __gitcomp
'--file= --message= --reedit-message=
1549 __gitcomp
'--dry-run --verbose'
1558 __gitcomp_nl
"$(__git_refs)"
1567 __git_complete_strategy
&& return
1572 --rebase --no-rebase
1573 $__git_merge_options
1574 $__git_fetch_options
1579 __git_complete_remote_or_refspec
1586 __gitcomp_nl
"$(__git_remotes)"
1591 __gitcomp_nl
"$(__git_remotes)" "" "${cur##--repo=}"
1596 --all --mirror --tags --dry-run --force --verbose
1597 --receive-pack= --repo= --set-upstream
1602 __git_complete_remote_or_refspec
1607 local dir
="$(__gitdir)"
1608 if [ -d "$dir"/rebase-apply
] ||
[ -d "$dir"/rebase-merge
]; then
1609 __gitcomp
"--continue --skip --abort"
1612 __git_complete_strategy
&& return
1615 __gitcomp
"$__git_whitespacelist" "" "${cur##--whitespace=}"
1620 --onto --merge --strategy --interactive
1621 --preserve-merges --stat --no-stat
1622 --committer-date-is-author-date --ignore-date
1623 --ignore-whitespace --whitespace=
1629 __gitcomp_nl
"$(__git_refs)"
1634 local subcommands
="show delete expire"
1635 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
1637 if [ -z "$subcommand" ]; then
1638 __gitcomp
"$subcommands"
1640 __gitcomp_nl
"$(__git_refs)"
1644 __git_send_email_confirm_options
="always never auto cc compose"
1645 __git_send_email_suppresscc_options
="author self cc bodycc sob cccmd body all"
1652 $__git_send_email_confirm_options
1653 " "" "${cur##--confirm=}"
1658 $__git_send_email_suppresscc_options
1659 " "" "${cur##--suppress-cc=}"
1663 --smtp-encryption=*)
1664 __gitcomp
"ssl tls" "" "${cur##--smtp-encryption=}"
1670 " "" "${cur##--thread=}"
1674 __gitcomp
"--annotate --bcc --cc --cc-cmd --chain-reply-to
1675 --compose --confirm= --dry-run --envelope-sender
1677 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1678 --no-suppress-from --no-thread --quiet
1679 --signed-off-by-cc --smtp-pass --smtp-server
1680 --smtp-server-port --smtp-encryption= --smtp-user
1681 --subject --suppress-cc= --suppress-from --thread --to
1682 --validate --no-validate
1683 $__git_format_patch_options"
1687 __git_complete_revlist
1695 __git_config_get_set_variables
()
1697 local prevword word config_file
= c
=$cword
1698 while [ $c -gt 1 ]; do
1701 --system|
--global|
--local|
--file=*)
1706 config_file
="$word $prevword"
1714 git
--git-dir="$(__gitdir)" config
$config_file --list 2>/dev
/null |
1728 branch.
*.remote|branch.
*.pushremote
)
1729 __gitcomp_nl
"$(__git_remotes)"
1733 __gitcomp_nl
"$(__git_refs)"
1737 __gitcomp
"false true"
1741 __gitcomp_nl
"$(__git_remotes)"
1745 local remote
="${prev#remote.}"
1746 remote
="${remote%.fetch}"
1747 if [ -z "$cur" ]; then
1748 __gitcomp_nl
"refs/heads/" "" "" ""
1751 __gitcomp_nl
"$(__git_refs_remotes "$remote")"
1755 local remote
="${prev#remote.}"
1756 remote
="${remote%.push}"
1757 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" \
1758 for-each-ref --format='%(refname):%(refname)' \
1762 pull.twohead|pull.octopus
)
1763 __git_compute_merge_strategies
1764 __gitcomp
"$__git_merge_strategies"
1767 color.branch|color.
diff|color.interactive|\
1768 color.showbranch|color.status|color.ui
)
1769 __gitcomp
"always never auto"
1773 __gitcomp
"false true"
1778 normal black red green yellow blue magenta cyan white
1779 bold dim ul blink reverse
1784 __gitcomp
"log short"
1788 __gitcomp
"man info web html"
1792 __gitcomp
"$__git_log_date_formats"
1795 sendemail.aliasesfiletype
)
1796 __gitcomp
"mutt mailrc pine elm gnus"
1800 __gitcomp
"$__git_send_email_confirm_options"
1803 sendemail.suppresscc
)
1804 __gitcomp
"$__git_send_email_suppresscc_options"
1807 --get|
--get-all|
--unset|
--unset-all)
1808 __gitcomp_nl
"$(__git_config_get_set_variables)"
1818 --system --global --local --file=
1819 --list --replace-all
1820 --get --get-all --get-regexp
1821 --add --unset --unset-all
1822 --remove-section --rename-section
1827 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1828 __gitcomp
"remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
1832 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1833 __gitcomp_nl
"$(__git_heads)" "$pfx" "$cur_" "."
1837 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1839 argprompt cmd confirm needsfile noconsole norescan
1840 prompt revprompt revunmerged title
1845 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1846 __gitcomp
"cmd path" "$pfx" "$cur_"
1850 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1851 __gitcomp
"cmd path" "$pfx" "$cur_"
1855 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1856 __gitcomp
"cmd path trustExitCode" "$pfx" "$cur_"
1860 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1861 __git_compute_all_commands
1862 __gitcomp_nl
"$__git_all_commands" "$pfx" "$cur_"
1866 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1868 url proxy fetch push mirror skipDefaultUpdate
1869 receivepack uploadpack tagopt pushurl
1874 local pfx
="${cur%.*}." cur_
="${cur#*.}"
1875 __gitcomp_nl
"$(__git_remotes)" "$pfx" "$cur_" "."
1879 local pfx
="${cur%.*}." cur_
="${cur##*.}"
1880 __gitcomp
"insteadOf pushInsteadOf" "$pfx" "$cur_"
1886 advice.commitBeforeMerge
1888 advice.implicitIdentity
1889 advice.pushNonFastForward
1890 advice.resolveConflict
1894 apply.ignorewhitespace
1896 branch.autosetupmerge
1897 branch.autosetuprebase
1901 color.branch.current
1906 color.decorate.branch
1907 color.decorate.remoteBranch
1908 color.decorate.stash
1918 color.diff.whitespace
1923 color.grep.linenumber
1926 color.grep.separator
1928 color.interactive.error
1929 color.interactive.header
1930 color.interactive.help
1931 color.interactive.prompt
1936 color.status.changed
1938 color.status.nobranch
1939 color.status.untracked
1940 color.status.updated
1949 core.bigFileThreshold
1952 core.deltaBaseCacheLimit
1957 core.fsyncobjectfiles
1961 core.logAllRefUpdates
1962 core.loosecompression
1965 core.packedGitWindowSize
1967 core.preferSymlinkRefs
1970 core.repositoryFormatVersion
1972 core.sharedRepository
1976 core.warnAmbiguousRefs
1979 diff.autorefreshindex
1981 diff.ignoreSubmodules
1988 diff.suppressBlankEmpty
1994 fetch.recurseSubmodules
2003 format.subjectprefix
2014 gc.reflogexpireunreachable
2018 gitcvs.commitmsgannotation
2019 gitcvs.dbTableNamePrefix
2030 gui.copyblamethreshold
2034 gui.matchtrackingbranch
2035 gui.newbranchtemplate
2036 gui.pruneduringfetch
2037 gui.spellingdictionary
2052 http.sslCertPasswordProtected
2057 i18n.logOutputEncoding
2063 imap.preformattedHTML
2073 interactive.singlekey
2089 mergetool.keepBackup
2090 mergetool.keepTemporaries
2095 notes.rewrite.rebase
2099 pack.deltaCacheLimit
2115 receive.denyCurrentBranch
2116 receive.denyDeleteCurrent
2118 receive.denyNonFastForwards
2121 receive.updateserverinfo
2124 repack.usedeltabaseoffset
2128 sendemail.aliasesfile
2129 sendemail.aliasfiletype
2133 sendemail.chainreplyto
2135 sendemail.envelopesender
2139 sendemail.signedoffbycc
2140 sendemail.smtpdomain
2141 sendemail.smtpencryption
2143 sendemail.smtpserver
2144 sendemail.smtpserveroption
2145 sendemail.smtpserverport
2147 sendemail.suppresscc
2148 sendemail.suppressfrom
2153 status.relativePaths
2154 status.showUntrackedFiles
2155 status.submodulesummary
2158 transfer.unpackLimit
2170 local subcommands
="add rename remove set-head set-branches set-url show prune update"
2171 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2172 if [ -z "$subcommand" ]; then
2173 __gitcomp
"$subcommands"
2177 case "$subcommand" in
2178 rename|remove|set-url|show|prune
)
2179 __gitcomp_nl
"$(__git_remotes)"
2181 set-head|set-branches
)
2182 __git_complete_remote_or_refspec
2185 local i c
='' IFS
=$
'\n'
2186 for i
in $
(git
--git-dir="$(__gitdir)" config
--get-regexp "remotes\..*" 2>/dev
/null
); do
2199 __gitcomp_nl
"$(__git_refs)"
2204 __git_has_doubledash
&& return
2208 __gitcomp
"--merge --mixed --hard --soft --patch"
2212 __gitcomp_nl
"$(__git_refs)"
2219 __gitcomp
"--edit --mainline --no-edit --no-commit --signoff"
2223 __gitcomp_nl
"$(__git_refs)"
2230 __gitcomp
"--cached --dry-run --ignore-unmatch --quiet"
2235 __git_complete_index_file
"--cached"
2240 __git_has_doubledash
&& return
2245 $__git_log_common_options
2246 $__git_log_shortlog_options
2247 --numbered --summary
2252 __git_complete_revlist
2257 __git_has_doubledash
&& return
2260 --pretty=*|
--format=*)
2261 __gitcomp
"$__git_log_pretty_formats $(__git_pretty_aliases)
2266 __gitcomp
"$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2270 __gitcomp
"--pretty= --format= --abbrev-commit --oneline
2271 $__git_diff_common_options
2276 __git_complete_revlist_file
2284 --all --remotes --topo-order --current --more=
2285 --list --independent --merge-base --no-name
2287 --sha1-name --sparse --topics --reflog
2292 __git_complete_revlist
2297 local save_opts
='--keep-index --no-keep-index --quiet --patch'
2298 local subcommands
='save list show apply clear drop pop create branch'
2299 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2300 if [ -z "$subcommand" ]; then
2303 __gitcomp
"$save_opts"
2306 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2307 __gitcomp
"$subcommands"
2312 case "$subcommand,$cur" in
2314 __gitcomp
"$save_opts"
2317 __gitcomp
"--index --quiet"
2319 show
,--*|drop
,--*|branch
,--*)
2321 show
,*|apply
,*|drop
,*|pop
,*|branch
,*)
2322 __gitcomp_nl
"$(git --git-dir="$
(__gitdir
)" stash list \
2323 | sed -n -e 's/:.*//p')"
2333 __git_has_doubledash
&& return
2335 local subcommands
="add status init deinit update summary foreach sync"
2336 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2339 __gitcomp
"--quiet --cached"
2342 __gitcomp
"$subcommands"
2352 init fetch clone rebase dcommit log find-rev
2353 set-tree commit-diff info create-ignore propget
2354 proplist show-ignore show-externals branch tag blame
2355 migrate mkdirs reset gc
2357 local subcommand
="$(__git_find_on_cmdline "$subcommands")"
2358 if [ -z "$subcommand" ]; then
2359 __gitcomp
"$subcommands"
2361 local remote_opts
="--username= --config-dir= --no-auth-cache"
2363 --follow-parent --authors-file= --repack=
2364 --no-metadata --use-svm-props --use-svnsync-props
2365 --log-window-size= --no-checkout --quiet
2366 --repack-flags --use-log-author --localtime
2367 --ignore-paths= --include-paths= $remote_opts
2370 --template= --shared= --trunk= --tags=
2371 --branches= --stdlayout --minimize-url
2372 --no-metadata --use-svm-props --use-svnsync-props
2373 --rewrite-root= --prefix= --use-log-author
2374 --add-author-from $remote_opts
2377 --edit --rmdir --find-copies-harder --copy-similarity=
2380 case "$subcommand,$cur" in
2382 __gitcomp
"--revision= --fetch-all $fc_opts"
2385 __gitcomp
"--revision= $fc_opts $init_opts"
2388 __gitcomp
"$init_opts"
2392 --merge --strategy= --verbose --dry-run
2393 --fetch-all --no-rebase --commit-url
2394 --revision --interactive $cmt_opts $fc_opts
2398 __gitcomp
"--stdin $cmt_opts $fc_opts"
2400 create-ignore
,--*|propget
,--*|proplist
,--*|show-ignore
,--*|\
2401 show-externals
,--*|mkdirs
,--*)
2402 __gitcomp
"--revision="
2406 --limit= --revision= --verbose --incremental
2407 --oneline --show-commit --non-recursive
2408 --authors-file= --color
2413 --merge --verbose --strategy= --local
2414 --fetch-all --dry-run $fc_opts
2418 __gitcomp
"--message= --file= --revision= $cmt_opts"
2424 __gitcomp
"--dry-run --message --tag"
2427 __gitcomp
"--dry-run --message"
2430 __gitcomp
"--git-format"
2434 --config-dir= --ignore-paths= --minimize
2435 --no-auth-cache --username=
2439 __gitcomp
"--revision= --parent"
2450 while [ $c -lt $cword ]; do
2454 __gitcomp_nl
"$(__git_tags)"
2469 __gitcomp_nl
"$(__git_tags)"
2473 __gitcomp_nl
"$(__git_refs)"
2485 local i c
=1 command __git_dir
2487 while [ $c -lt $cword ]; do
2490 --git-dir=*) __git_dir
="${i#--git-dir=}" ;;
2491 --git-dir) ((c
++)) ; __git_dir
="${words[c]}" ;;
2492 --bare) __git_dir
="." ;;
2493 --help) command="help"; break ;;
2494 -c|
--work-tree|
--namespace) ((c
++)) ;;
2496 *) command="$i"; break ;;
2501 if [ -z "$command" ]; then
2516 --no-replace-objects
2520 *) __git_compute_porcelain_commands
2521 __gitcomp
"$__git_porcelain_commands $(__git_aliases)" ;;
2526 local completion_func
="_git_${command//-/_}"
2527 declare -f $completion_func >/dev
/null
&& $completion_func && return
2529 local expansion
=$
(__git_aliased_command
"$command")
2530 if [ -n "$expansion" ]; then
2531 completion_func
="_git_${expansion//-/_}"
2532 declare -f $completion_func >/dev
/null
&& $completion_func
2538 __git_has_doubledash
&& return
2540 local g
="$(__gitdir)"
2542 if [ -f "$g/MERGE_HEAD" ]; then
2548 $__git_log_common_options
2549 $__git_log_gitk_options
2555 __git_complete_revlist
2558 if [[ -n ${ZSH_VERSION-} ]]; then
2559 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2561 autoload
-U +X compinit
&& compinit
2567 local cur_
="${3-$cur}"
2573 local c IFS
=$
' \t\n'
2581 array
[${#array[@]}+1]="$c"
2584 compadd
-Q -S '' -p "${2-}" -a -- array
&& _ret
=0
2595 compadd
-Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2604 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2609 local _ret=1 cur cword prev
2610 cur=${words[CURRENT]}
2611 prev=${words[CURRENT-1]}
2613 emulate ksh -c __${service}_main
2614 let _ret && _default && _ret=0
2618 compdef _git git gitk
2624 local cur words cword prev
2625 _get_comp_words_by_ref -n =: cur words cword prev
2629 # Setup completion for certain functions defined above by setting common
2630 # variables and workarounds.
2631 # This is NOT a public function; use at your own risk.
2634 local wrapper="__git_wrap
${2}"
2635 eval "$wrapper () { __git_func_wrap
$2 ; }"
2636 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2637 || complete -o default -o nospace -F $wrapper $1
2640 # wrapper for backwards compatibility
2643 __git_wrap__git_main
2646 # wrapper for backwards compatibility
2649 __git_wrap__gitk_main
2652 __git_complete git __git_main
2653 __git_complete gitk __gitk_main
2655 # The following are necessary only for Cygwin, and only are needed
2656 # when the user has tab-completed the executable name and consequently
2657 # included the '.exe' suffix.
2659 if [ Cygwin = "$
(uname
-o 2>/dev
/null
)" ]; then
2660 __git_complete git.exe __git_main