]>
Commit | Line | Data |
---|---|---|
b5a49471 | 1 | # bash/zsh completion support for core Git. |
690d8824 | 2 | # |
c70680ce | 3 | # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org> |
690d8824 | 4 | # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). |
c70680ce | 5 | # Distributed under the GNU General Public License, version 2.0. |
690d8824 JH |
6 | # |
7 | # The contained completion routines provide support for completing: | |
8 | # | |
9 | # *) local and remote branch names | |
10 | # *) local and remote tag names | |
11 | # *) .git/remotes file names | |
12 | # *) git 'subcommands' | |
dfbe5eeb | 13 | # *) git email aliases for git-send-email |
690d8824 | 14 | # *) tree paths within 'ref:path/to/file' expressions |
fea16b47 | 15 | # *) file paths within current working directory and index |
c70680ce | 16 | # *) common --long-options |
690d8824 JH |
17 | # |
18 | # To use these routines: | |
19 | # | |
0e5ed7cc | 20 | # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash). |
b5a49471 | 21 | # 2) Add the following line to your .bashrc/.zshrc: |
0e5ed7cc | 22 | # source ~/.git-completion.bash |
af31a456 FC |
23 | # 3) Consider changing your PS1 to also show the current branch, |
24 | # see git-prompt.sh for details. | |
56f24e80 SP |
25 | # |
26 | # If you use complex aliases of form '!f() { ... }; f', you can use the null | |
27 | # command ':' as the first command in the function body to declare the desired | |
28 | # completion style. For example '!f() { : git commit ; ... }; f' will | |
29 | # tell the completion to use commit completion. This also works with aliases | |
30 | # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '". | |
690d8824 | 31 | |
db8a9ff0 SP |
32 | case "$COMP_WORDBREAKS" in |
33 | *:*) : great ;; | |
34 | *) COMP_WORDBREAKS="$COMP_WORDBREAKS:" | |
35 | esac | |
36 | ||
beb6ee71 SG |
37 | # Discovers the path to the git repository taking any '--git-dir=<path>' and |
38 | # '-C <path>' options into account and stores it in the $__git_repo_path | |
39 | # variable. | |
40 | __git_find_repo_path () | |
41 | { | |
fad9484f SG |
42 | if [ -n "$__git_repo_path" ]; then |
43 | # we already know where it is | |
44 | return | |
45 | fi | |
46 | ||
beb6ee71 SG |
47 | if [ -n "${__git_C_args-}" ]; then |
48 | __git_repo_path="$(git "${__git_C_args[@]}" \ | |
49 | ${__git_dir:+--git-dir="$__git_dir"} \ | |
50 | rev-parse --absolute-git-dir 2>/dev/null)" | |
51 | elif [ -n "${__git_dir-}" ]; then | |
52 | test -d "$__git_dir" && | |
53 | __git_repo_path="$__git_dir" | |
54 | elif [ -n "${GIT_DIR-}" ]; then | |
55 | test -d "${GIT_DIR-}" && | |
56 | __git_repo_path="$GIT_DIR" | |
57 | elif [ -d .git ]; then | |
58 | __git_repo_path=.git | |
59 | else | |
60 | __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)" | |
61 | fi | |
62 | } | |
63 | ||
fad9484f | 64 | # Deprecated: use __git_find_repo_path() and $__git_repo_path instead |
a42577d4 TP |
65 | # __gitdir accepts 0 or 1 arguments (i.e., location) |
66 | # returns location of .git repo | |
873537fa SP |
67 | __gitdir () |
68 | { | |
25a31f81 | 69 | if [ -z "${1-}" ]; then |
beb6ee71 SG |
70 | __git_find_repo_path || return 1 |
71 | echo "$__git_repo_path" | |
67ffa114 SP |
72 | elif [ -d "$1/.git" ]; then |
73 | echo "$1/.git" | |
74 | else | |
75 | echo "$1" | |
76 | fi | |
873537fa SP |
77 | } |
78 | ||
1cd23e9e SG |
79 | # Runs git with all the options given as argument, respecting any |
80 | # '--git-dir=<path>' and '-C <path>' options present on the command line | |
81 | __git () | |
82 | { | |
83 | git ${__git_C_args:+"${__git_C_args[@]}"} \ | |
e15098a3 | 84 | ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null |
1cd23e9e SG |
85 | } |
86 | ||
dbda3b10 JN |
87 | # The following function is based on code from: |
88 | # | |
89 | # bash_completion - programmable completion functions for bash 3.2+ | |
90 | # | |
91 | # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org> | |
92 | # © 2009-2010, Bash Completion Maintainers | |
93 | # <bash-completion-devel@lists.alioth.debian.org> | |
94 | # | |
95 | # This program is free software; you can redistribute it and/or modify | |
96 | # it under the terms of the GNU General Public License as published by | |
97 | # the Free Software Foundation; either version 2, or (at your option) | |
98 | # any later version. | |
99 | # | |
100 | # This program is distributed in the hope that it will be useful, | |
101 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
102 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
103 | # GNU General Public License for more details. | |
104 | # | |
105 | # You should have received a copy of the GNU General Public License | |
106 | # along with this program; if not, write to the Free Software Foundation, | |
107 | # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
108 | # | |
109 | # The latest version of this software can be obtained here: | |
110 | # | |
111 | # http://bash-completion.alioth.debian.org/ | |
112 | # | |
113 | # RELEASE: 2.x | |
114 | ||
115 | # This function can be used to access a tokenized list of words | |
116 | # on the command line: | |
117 | # | |
118 | # __git_reassemble_comp_words_by_ref '=:' | |
119 | # if test "${words_[cword_-1]}" = -w | |
120 | # then | |
121 | # ... | |
122 | # fi | |
123 | # | |
124 | # The argument should be a collection of characters from the list of | |
125 | # word completion separators (COMP_WORDBREAKS) to treat as ordinary | |
126 | # characters. | |
127 | # | |
128 | # This is roughly equivalent to going back in time and setting | |
129 | # COMP_WORDBREAKS to exclude those characters. The intent is to | |
130 | # make option types like --date=<type> and <rev>:<path> easy to | |
131 | # recognize by treating each shell word as a single token. | |
132 | # | |
133 | # It is best not to set COMP_WORDBREAKS directly because the value is | |
134 | # shared with other completion scripts. By the time the completion | |
135 | # function gets called, COMP_WORDS has already been populated so local | |
136 | # changes to COMP_WORDBREAKS have no effect. | |
137 | # | |
138 | # Output: words_, cword_, cur_. | |
139 | ||
140 | __git_reassemble_comp_words_by_ref() | |
141 | { | |
142 | local exclude i j first | |
143 | # Which word separators to exclude? | |
144 | exclude="${1//[^$COMP_WORDBREAKS]}" | |
145 | cword_=$COMP_CWORD | |
146 | if [ -z "$exclude" ]; then | |
147 | words_=("${COMP_WORDS[@]}") | |
148 | return | |
149 | fi | |
150 | # List of word completion separators has shrunk; | |
151 | # re-assemble words to complete. | |
152 | for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do | |
153 | # Append each nonempty word consisting of just | |
154 | # word separator characters to the current word. | |
155 | first=t | |
156 | while | |
157 | [ $i -gt 0 ] && | |
158 | [ -n "${COMP_WORDS[$i]}" ] && | |
159 | # word consists of excluded word separators | |
160 | [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] | |
161 | do | |
162 | # Attach to the previous token, | |
163 | # unless the previous token is the command name. | |
164 | if [ $j -ge 2 ] && [ -n "$first" ]; then | |
165 | ((j--)) | |
166 | fi | |
167 | first= | |
168 | words_[$j]=${words_[j]}${COMP_WORDS[i]} | |
169 | if [ $i = $COMP_CWORD ]; then | |
170 | cword_=$j | |
171 | fi | |
172 | if (($i < ${#COMP_WORDS[@]} - 1)); then | |
173 | ((i++)) | |
174 | else | |
175 | # Done. | |
176 | return | |
177 | fi | |
178 | done | |
179 | words_[$j]=${words_[j]}${COMP_WORDS[i]} | |
180 | if [ $i = $COMP_CWORD ]; then | |
181 | cword_=$j | |
182 | fi | |
183 | done | |
184 | } | |
185 | ||
da48616f PD |
186 | if ! type _get_comp_words_by_ref >/dev/null 2>&1; then |
187 | _get_comp_words_by_ref () | |
188 | { | |
dbda3b10 JN |
189 | local exclude cur_ words_ cword_ |
190 | if [ "$1" = "-n" ]; then | |
191 | exclude=$2 | |
192 | shift 2 | |
193 | fi | |
194 | __git_reassemble_comp_words_by_ref "$exclude" | |
195 | cur_=${words_[cword_]} | |
da48616f PD |
196 | while [ $# -gt 0 ]; do |
197 | case "$1" in | |
198 | cur) | |
dbda3b10 | 199 | cur=$cur_ |
da48616f PD |
200 | ;; |
201 | prev) | |
dbda3b10 | 202 | prev=${words_[$cword_-1]} |
da48616f PD |
203 | ;; |
204 | words) | |
dbda3b10 | 205 | words=("${words_[@]}") |
da48616f PD |
206 | ;; |
207 | cword) | |
dbda3b10 | 208 | cword=$cword_ |
da48616f PD |
209 | ;; |
210 | esac | |
211 | shift | |
212 | done | |
213 | } | |
214 | fi | |
215 | ||
f33c2c0f | 216 | __gitcompappend () |
1ce23aad | 217 | { |
852ff1c3 | 218 | local x i=${#COMPREPLY[@]} |
7d13e0a3 FC |
219 | for x in $1; do |
220 | if [[ "$x" == "$3"* ]]; then | |
221 | COMPREPLY[i++]="$2$x$4" | |
222 | fi | |
223 | done | |
1ce23aad FC |
224 | } |
225 | ||
f33c2c0f RR |
226 | __gitcompadd () |
227 | { | |
228 | COMPREPLY=() | |
229 | __gitcompappend "$@" | |
230 | } | |
231 | ||
7d13e0a3 FC |
232 | # Generates completion reply, appending a space to possible completion words, |
233 | # if necessary. | |
f674bb80 SG |
234 | # It accepts 1 to 4 arguments: |
235 | # 1: List of possible completion words. | |
236 | # 2: A prefix to be added to each possible completion word (optional). | |
237 | # 3: Generate possible completion matches for this word (optional). | |
238 | # 4: A suffix to be appended to each possible completion word (optional). | |
72e5e989 SP |
239 | __gitcomp () |
240 | { | |
583e4d57 | 241 | local cur_="${3-$cur}" |
9244d69b | 242 | |
9244d69b | 243 | case "$cur_" in |
5447aac7 | 244 | --*=) |
5447aac7 SG |
245 | ;; |
246 | *) | |
b4cfbc96 FC |
247 | local c i=0 IFS=$' \t\n' |
248 | for c in $1; do | |
249 | c="$c${4-}" | |
b4cfbc96 | 250 | if [[ $c == "$cur_"* ]]; then |
ddc996d7 FC |
251 | case $c in |
252 | --*=*|*.) ;; | |
253 | *) c="$c " ;; | |
254 | esac | |
b4cfbc96 FC |
255 | COMPREPLY[i++]="${2-}$c" |
256 | fi | |
257 | done | |
5447aac7 SG |
258 | ;; |
259 | esac | |
72e5e989 SP |
260 | } |
261 | ||
f33c2c0f RR |
262 | # Variation of __gitcomp_nl () that appends to the existing list of |
263 | # completion candidates, COMPREPLY. | |
264 | __gitcomp_nl_append () | |
265 | { | |
266 | local IFS=$'\n' | |
267 | __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }" | |
268 | } | |
269 | ||
7d13e0a3 FC |
270 | # Generates completion reply from newline-separated possible completion words |
271 | # by appending a space to all of them. | |
a31e6262 SG |
272 | # It accepts 1 to 4 arguments: |
273 | # 1: List of possible completion words, separated by a single newline. | |
274 | # 2: A prefix to be added to each possible completion word (optional). | |
275 | # 3: Generate possible completion matches for this word (optional). | |
276 | # 4: A suffix to be appended to each possible completion word instead of | |
277 | # the default space (optional). If specified but empty, nothing is | |
278 | # appended. | |
279 | __gitcomp_nl () | |
280 | { | |
f33c2c0f RR |
281 | COMPREPLY=() |
282 | __gitcomp_nl_append "$@" | |
a31e6262 SG |
283 | } |
284 | ||
fea16b47 MP |
285 | # Generates completion reply with compgen from newline-separated possible |
286 | # completion filenames. | |
287 | # It accepts 1 to 3 arguments: | |
288 | # 1: List of possible completion filenames, separated by a single newline. | |
289 | # 2: A directory prefix to be added to each possible completion filename | |
290 | # (optional). | |
291 | # 3: Generate possible completion matches for this word (optional). | |
292 | __gitcomp_file () | |
293 | { | |
294 | local IFS=$'\n' | |
295 | ||
296 | # XXX does not work when the directory prefix contains a tilde, | |
297 | # since tilde expansion is not applied. | |
298 | # This means that COMPREPLY will be empty and Bash default | |
299 | # completion will be used. | |
0afe8e9e | 300 | __gitcompadd "$1" "${2-}" "${3-$cur}" "" |
fea16b47 | 301 | |
3ffa4df4 | 302 | # use a hack to enable file mode in bash < 4 |
fbe45118 | 303 | compopt -o filenames +o nospace 2>/dev/null || |
3ffa4df4 | 304 | compgen -f /non-existing-dir/ > /dev/null |
fea16b47 MP |
305 | } |
306 | ||
f825972c FC |
307 | # Execute 'git ls-files', unless the --committable option is specified, in |
308 | # which case it runs 'git diff-index' to find out the files that can be | |
309 | # committed. It return paths relative to the directory specified in the first | |
310 | # argument, and using the options specified in the second argument. | |
fea16b47 MP |
311 | __git_ls_files_helper () |
312 | { | |
fca416a4 | 313 | if [ "$2" == "--committable" ]; then |
1cd23e9e | 314 | __git -C "$1" diff-index --name-only --relative HEAD |
fca416a4 JH |
315 | else |
316 | # NOTE: $2 is not quoted in order to support multiple options | |
1cd23e9e | 317 | __git -C "$1" ls-files --exclude-standard $2 |
e15098a3 | 318 | fi |
35ba83cc | 319 | } |
fea16b47 MP |
320 | |
321 | ||
fea16b47 MP |
322 | # __git_index_files accepts 1 or 2 arguments: |
323 | # 1: Options to pass to ls-files (required). | |
fea16b47 MP |
324 | # 2: A directory path (optional). |
325 | # If provided, only files within the specified directory are listed. | |
326 | # Sub directories are never recursed. Path must have a trailing | |
327 | # slash. | |
328 | __git_index_files () | |
329 | { | |
a958d40f | 330 | local root="${2-.}" file |
fea16b47 | 331 | |
a958d40f SG |
332 | __git_ls_files_helper "$root" "$1" | |
333 | while read -r file; do | |
334 | case "$file" in | |
335 | ?*/*) echo "${file%%/*}" ;; | |
336 | *) echo "$file" ;; | |
337 | esac | |
338 | done | sort | uniq | |
fea16b47 MP |
339 | } |
340 | ||
5de40f59 SP |
341 | __git_heads () |
342 | { | |
3ad8ea7c | 343 | __git for-each-ref --format='%(refname:strip=2)' refs/heads |
5de40f59 SP |
344 | } |
345 | ||
88e21dc7 SP |
346 | __git_tags () |
347 | { | |
3ad8ea7c | 348 | __git for-each-ref --format='%(refname:strip=2)' refs/tags |
88e21dc7 SP |
349 | } |
350 | ||
be6fbdb5 SG |
351 | # Lists refs from the local (by default) or from a remote repository. |
352 | # It accepts 0, 1 or 2 arguments: | |
353 | # 1: The remote to list refs from (optional; ignored, if set but empty). | |
91b7ea81 | 354 | # Can be the name of a configured remote, a path, or a URL. |
be6fbdb5 SG |
355 | # 2: In addition to local refs, list unique branches from refs/remotes/ for |
356 | # 'git checkout's tracking DWIMery (optional; ignored, if set but empty). | |
2ea328a1 | 357 | # 3: Currently ignored. |
e896369b SG |
358 | # 4: List only refs matching this word (optional; list all refs if unset or |
359 | # empty). | |
15b4a163 SG |
360 | # |
361 | # Use __git_complete_refs() instead. | |
690d8824 JH |
362 | __git_refs () |
363 | { | |
fad9484f | 364 | local i hash dir track="${2-}" |
5c12f642 | 365 | local list_refs_from=path remote="${1-}" |
49416ad2 | 366 | local format refs pfx |
2ea328a1 | 367 | local cur_="${4-$cur}" |
e896369b | 368 | local match="${4-}" |
5c12f642 | 369 | |
fad9484f SG |
370 | __git_find_repo_path |
371 | dir="$__git_repo_path" | |
372 | ||
62a1b732 SG |
373 | if [ -z "$remote" ]; then |
374 | if [ -z "$dir" ]; then | |
375 | return | |
376 | fi | |
377 | else | |
69a77596 SG |
378 | if __git_is_configured_remote "$remote"; then |
379 | # configured remote takes precedence over a | |
380 | # local directory with the same name | |
381 | list_refs_from=remote | |
382 | elif [ -d "$remote/.git" ]; then | |
5c12f642 SG |
383 | dir="$remote/.git" |
384 | elif [ -d "$remote" ]; then | |
385 | dir="$remote" | |
386 | else | |
69a77596 | 387 | list_refs_from=url |
5c12f642 SG |
388 | fi |
389 | fi | |
390 | ||
62a1b732 | 391 | if [ "$list_refs_from" = path ]; then |
aed38813 SG |
392 | if [[ "$cur_" == ^* ]]; then |
393 | pfx="^" | |
394 | cur_=${cur_#^} | |
e896369b | 395 | match=${match#^} |
aed38813 | 396 | fi |
2ea328a1 | 397 | case "$cur_" in |
608efb87 SG |
398 | refs|refs/*) |
399 | format="refname" | |
e896369b | 400 | refs=("$match*" "$match*/**") |
34a6bbb5 | 401 | track="" |
608efb87 SG |
402 | ;; |
403 | *) | |
d23e7570 | 404 | for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do |
e896369b SG |
405 | case "$i" in |
406 | $match*) | |
407 | if [ -e "$dir/$i" ]; then | |
408 | echo $pfx$i | |
409 | fi | |
410 | ;; | |
411 | esac | |
d23e7570 | 412 | done |
b2b68114 | 413 | format="refname:strip=2" |
e896369b SG |
414 | refs=("refs/tags/$match*" "refs/tags/$match*/**" |
415 | "refs/heads/$match*" "refs/heads/$match*/**" | |
416 | "refs/remotes/$match*" "refs/remotes/$match*/**") | |
608efb87 SG |
417 | ;; |
418 | esac | |
1cd23e9e | 419 | __git_dir="$dir" __git for-each-ref --format="$pfx%($format)" \ |
e896369b | 420 | "${refs[@]}" |
34a6bbb5 KB |
421 | if [ -n "$track" ]; then |
422 | # employ the heuristic used by git checkout | |
423 | # Try to find a remote branch that matches the completion word | |
424 | # but only output if the branch name is unique | |
425 | local ref entry | |
b2b68114 | 426 | __git for-each-ref --shell --format="ref=%(refname:strip=2)" \ |
34a6bbb5 | 427 | "refs/remotes/" | \ |
6f2dd720 | 428 | while read -r entry; do |
34a6bbb5 KB |
429 | eval "$entry" |
430 | ref="${ref#*/}" | |
e896369b | 431 | if [[ "$ref" == "$match"* ]]; then |
34a6bbb5 KB |
432 | echo "$ref" |
433 | fi | |
4db42b38 | 434 | done | sort | uniq -u |
34a6bbb5 | 435 | fi |
35e65ecc | 436 | return |
690d8824 | 437 | fi |
2ea328a1 | 438 | case "$cur_" in |
fb772cca | 439 | refs|refs/*) |
e896369b | 440 | __git ls-remote "$remote" "$match*" | \ |
6f2dd720 | 441 | while read -r hash i; do |
fb772cca SG |
442 | case "$i" in |
443 | *^{}) ;; | |
444 | *) echo "$i" ;; | |
445 | esac | |
446 | done | |
447 | ;; | |
448 | *) | |
91b7ea81 | 449 | if [ "$list_refs_from" = remote ]; then |
e896369b SG |
450 | case "HEAD" in |
451 | $match*) echo "HEAD" ;; | |
452 | esac | |
b2b68114 | 453 | __git for-each-ref --format="%(refname:strip=2)" \ |
e896369b SG |
454 | "refs/remotes/$remote/$match*" \ |
455 | "refs/remotes/$remote/$match*/**" | sed -e "s#^$remote/##" | |
91b7ea81 | 456 | else |
e896369b SG |
457 | local query_symref |
458 | case "HEAD" in | |
459 | $match*) query_symref="HEAD" ;; | |
460 | esac | |
461 | __git ls-remote "$remote" $query_symref \ | |
462 | "refs/tags/$match*" "refs/heads/$match*" \ | |
463 | "refs/remotes/$match*" | | |
91b7ea81 SG |
464 | while read -r hash i; do |
465 | case "$i" in | |
466 | *^{}) ;; | |
467 | refs/*) echo "${i#refs/*/}" ;; | |
468 | *) echo "$i" ;; # symbolic refs | |
469 | esac | |
470 | done | |
471 | fi | |
fb772cca SG |
472 | ;; |
473 | esac | |
690d8824 JH |
474 | } |
475 | ||
15b4a163 SG |
476 | # Completes refs, short and long, local and remote, symbolic and pseudo. |
477 | # | |
478 | # Usage: __git_complete_refs [<option>]... | |
479 | # --remote=<remote>: The remote to list refs from, can be the name of a | |
480 | # configured remote, a path, or a URL. | |
481 | # --track: List unique remote branches for 'git checkout's tracking DWIMery. | |
482 | # --pfx=<prefix>: A prefix to be added to each ref. | |
483 | # --cur=<word>: The current ref to be completed. Defaults to the current | |
484 | # word to be completed. | |
485 | # --sfx=<suffix>: A suffix to be appended to each ref instead of the default | |
486 | # space. | |
487 | __git_complete_refs () | |
488 | { | |
489 | local remote track pfx cur_="$cur" sfx=" " | |
490 | ||
491 | while test $# != 0; do | |
492 | case "$1" in | |
493 | --remote=*) remote="${1##--remote=}" ;; | |
494 | --track) track="yes" ;; | |
495 | --pfx=*) pfx="${1##--pfx=}" ;; | |
496 | --cur=*) cur_="${1##--cur=}" ;; | |
497 | --sfx=*) sfx="${1##--sfx=}" ;; | |
498 | *) return 1 ;; | |
499 | esac | |
500 | shift | |
501 | done | |
502 | ||
2ea328a1 SG |
503 | __gitcomp_nl "$(__git_refs "$remote" "$track" "" "$cur_")" \ |
504 | "$pfx" "$cur_" "$sfx" | |
15b4a163 SG |
505 | } |
506 | ||
a42577d4 | 507 | # __git_refs2 requires 1 argument (to pass to __git_refs) |
aa0644f7 | 508 | # Deprecated: use __git_complete_fetch_refspecs() instead. |
690d8824 JH |
509 | __git_refs2 () |
510 | { | |
67ffa114 SP |
511 | local i |
512 | for i in $(__git_refs "$1"); do | |
513 | echo "$i:$i" | |
690d8824 JH |
514 | done |
515 | } | |
516 | ||
aa0644f7 SG |
517 | # Completes refspecs for fetching from a remote repository. |
518 | # 1: The remote repository. | |
519 | # 2: A prefix to be added to each listed refspec (optional). | |
520 | # 3: The ref to be completed as a refspec instead of the current word to be | |
521 | # completed (optional) | |
522 | # 4: A suffix to be appended to each listed refspec instead of the default | |
523 | # space (optional). | |
524 | __git_complete_fetch_refspecs () | |
525 | { | |
526 | local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }" | |
527 | ||
528 | __gitcomp_nl "$( | |
529 | for i in $(__git_refs "$remote" "" "" "$cur_") ; do | |
530 | echo "$i:$i" | |
531 | done | |
532 | )" "$pfx" "$cur_" "$sfx" | |
533 | } | |
534 | ||
a42577d4 | 535 | # __git_refs_remotes requires 1 argument (to pass to ls-remote) |
5de40f59 SP |
536 | __git_refs_remotes () |
537 | { | |
48058f5d | 538 | local i hash |
e15098a3 | 539 | __git ls-remote "$1" 'refs/heads/*' | \ |
6f2dd720 | 540 | while read -r hash i; do |
48058f5d | 541 | echo "$i:refs/remotes/$1/${i#refs/heads/}" |
5de40f59 SP |
542 | done |
543 | } | |
544 | ||
690d8824 JH |
545 | __git_remotes () |
546 | { | |
fad9484f SG |
547 | __git_find_repo_path |
548 | test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes" | |
1cd23e9e | 549 | __git remote |
690d8824 JH |
550 | } |
551 | ||
69a77596 SG |
552 | # Returns true if $1 matches the name of a configured remote, false otherwise. |
553 | __git_is_configured_remote () | |
554 | { | |
555 | local remote | |
556 | for remote in $(__git_remotes); do | |
557 | if [ "$remote" = "$1" ]; then | |
558 | return 0 | |
559 | fi | |
560 | done | |
561 | return 1 | |
562 | } | |
563 | ||
eaa4e6ee | 564 | __git_list_merge_strategies () |
4ad91321 | 565 | { |
25b3d4d6 JH |
566 | git merge -s help 2>&1 | |
567 | sed -n -e '/[Aa]vailable strategies are: /,/^$/{ | |
568 | s/\.$// | |
569 | s/.*:// | |
570 | s/^[ ]*// | |
571 | s/[ ]*$// | |
4ad91321 | 572 | p |
25b3d4d6 | 573 | }' |
4ad91321 | 574 | } |
eaa4e6ee JN |
575 | |
576 | __git_merge_strategies= | |
577 | # 'git merge -s help' (and thus detection of the merge strategy | |
578 | # list) fails, unfortunately, if run outside of any git working | |
579 | # tree. __git_merge_strategies is set to the empty string in | |
580 | # that case, and the detection will be repeated the next time it | |
581 | # is needed. | |
582 | __git_compute_merge_strategies () | |
583 | { | |
cf0ff02a FC |
584 | test -n "$__git_merge_strategies" || |
585 | __git_merge_strategies=$(__git_list_merge_strategies) | |
eaa4e6ee | 586 | } |
4ad91321 | 587 | |
1d66ec58 | 588 | __git_complete_revlist_file () |
690d8824 | 589 | { |
da4902a7 | 590 | local pfx ls ref cur_="$cur" |
9244d69b | 591 | case "$cur_" in |
1d66ec58 SG |
592 | *..?*:*) |
593 | return | |
594 | ;; | |
690d8824 | 595 | ?*:*) |
9244d69b SG |
596 | ref="${cur_%%:*}" |
597 | cur_="${cur_#*:}" | |
598 | case "$cur_" in | |
690d8824 | 599 | ?*/*) |
9244d69b SG |
600 | pfx="${cur_%/*}" |
601 | cur_="${cur_##*/}" | |
690d8824 JH |
602 | ls="$ref:$pfx" |
603 | pfx="$pfx/" | |
604 | ;; | |
605 | *) | |
606 | ls="$ref" | |
607 | ;; | |
80152b09 | 608 | esac |
db8a9ff0 SP |
609 | |
610 | case "$COMP_WORDBREAKS" in | |
611 | *:*) : great ;; | |
612 | *) pfx="$ref:$pfx" ;; | |
613 | esac | |
614 | ||
e15098a3 | 615 | __gitcomp_nl "$(__git ls-tree "$ls" \ |
778306e4 SP |
616 | | sed '/^100... blob /{ |
617 | s,^.* ,, | |
618 | s,$, , | |
619 | } | |
620 | /^120000 blob /{ | |
621 | s,^.* ,, | |
622 | s,$, , | |
623 | } | |
690d8824 JH |
624 | /^040000 tree /{ |
625 | s,^.* ,, | |
626 | s,$,/, | |
627 | } | |
628 | s/^.* //')" \ | |
41e6229d | 629 | "$pfx" "$cur_" "" |
690d8824 | 630 | ;; |
f53352fb | 631 | *...*) |
9244d69b SG |
632 | pfx="${cur_%...*}..." |
633 | cur_="${cur_#*...}" | |
15b4a163 | 634 | __git_complete_refs --pfx="$pfx" --cur="$cur_" |
f53352fb SP |
635 | ;; |
636 | *..*) | |
9244d69b SG |
637 | pfx="${cur_%..*}.." |
638 | cur_="${cur_#*..}" | |
15b4a163 | 639 | __git_complete_refs --pfx="$pfx" --cur="$cur_" |
b3391775 | 640 | ;; |
f53352fb | 641 | *) |
15b4a163 | 642 | __git_complete_refs |
f53352fb SP |
643 | ;; |
644 | esac | |
645 | } | |
646 | ||
1d66ec58 | 647 | |
f825972c FC |
648 | # __git_complete_index_file requires 1 argument: |
649 | # 1: the options to pass to ls-file | |
650 | # | |
651 | # The exception is --committable, which finds the files appropriate commit. | |
fea16b47 MP |
652 | __git_complete_index_file () |
653 | { | |
fda54ef1 | 654 | local pfx="" cur_="$cur" |
fea16b47 MP |
655 | |
656 | case "$cur_" in | |
657 | ?*/*) | |
658 | pfx="${cur_%/*}" | |
659 | cur_="${cur_##*/}" | |
660 | pfx="${pfx}/" | |
fea16b47 MP |
661 | ;; |
662 | esac | |
fea16b47 | 663 | |
fca416a4 | 664 | __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_" |
fea16b47 MP |
665 | } |
666 | ||
1d66ec58 SG |
667 | __git_complete_file () |
668 | { | |
669 | __git_complete_revlist_file | |
670 | } | |
671 | ||
672 | __git_complete_revlist () | |
673 | { | |
674 | __git_complete_revlist_file | |
675 | } | |
676 | ||
52d5c3b5 JS |
677 | __git_complete_remote_or_refspec () |
678 | { | |
9244d69b | 679 | local cur_="$cur" cmd="${words[1]}" |
0a4e1472 | 680 | local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0 |
f1c6ffe6 | 681 | if [ "$cmd" = "remote" ]; then |
6e8c755f | 682 | ((c++)) |
f1c6ffe6 | 683 | fi |
da48616f PD |
684 | while [ $c -lt $cword ]; do |
685 | i="${words[c]}" | |
52d5c3b5 | 686 | case "$i" in |
e25e2b42 BG |
687 | --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;; |
688 | --all) | |
689 | case "$cmd" in | |
690 | push) no_complete_refspec=1 ;; | |
691 | fetch) | |
e25e2b42 BG |
692 | return |
693 | ;; | |
694 | *) ;; | |
695 | esac | |
696 | ;; | |
52d5c3b5 JS |
697 | -*) ;; |
698 | *) remote="$i"; break ;; | |
699 | esac | |
6e8c755f | 700 | ((c++)) |
52d5c3b5 JS |
701 | done |
702 | if [ -z "$remote" ]; then | |
a31e6262 | 703 | __gitcomp_nl "$(__git_remotes)" |
52d5c3b5 JS |
704 | return |
705 | fi | |
0a4e1472 | 706 | if [ $no_complete_refspec = 1 ]; then |
0a4e1472 JS |
707 | return |
708 | fi | |
52d5c3b5 | 709 | [ "$remote" = "." ] && remote= |
9244d69b | 710 | case "$cur_" in |
52d5c3b5 JS |
711 | *:*) |
712 | case "$COMP_WORDBREAKS" in | |
713 | *:*) : great ;; | |
9244d69b | 714 | *) pfx="${cur_%%:*}:" ;; |
52d5c3b5 | 715 | esac |
9244d69b | 716 | cur_="${cur_#*:}" |
52d5c3b5 JS |
717 | lhs=0 |
718 | ;; | |
719 | +*) | |
720 | pfx="+" | |
9244d69b | 721 | cur_="${cur_#+}" |
52d5c3b5 JS |
722 | ;; |
723 | esac | |
724 | case "$cmd" in | |
725 | fetch) | |
726 | if [ $lhs = 1 ]; then | |
aa0644f7 | 727 | __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_" |
52d5c3b5 | 728 | else |
15b4a163 | 729 | __git_complete_refs --pfx="$pfx" --cur="$cur_" |
52d5c3b5 JS |
730 | fi |
731 | ;; | |
f1c6ffe6 | 732 | pull|remote) |
52d5c3b5 | 733 | if [ $lhs = 1 ]; then |
15b4a163 | 734 | __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_" |
52d5c3b5 | 735 | else |
15b4a163 | 736 | __git_complete_refs --pfx="$pfx" --cur="$cur_" |
52d5c3b5 JS |
737 | fi |
738 | ;; | |
739 | push) | |
740 | if [ $lhs = 1 ]; then | |
15b4a163 | 741 | __git_complete_refs --pfx="$pfx" --cur="$cur_" |
52d5c3b5 | 742 | else |
15b4a163 | 743 | __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_" |
52d5c3b5 JS |
744 | fi |
745 | ;; | |
746 | esac | |
747 | } | |
748 | ||
3c7b480a JS |
749 | __git_complete_strategy () |
750 | { | |
eaa4e6ee | 751 | __git_compute_merge_strategies |
da48616f | 752 | case "$prev" in |
3c7b480a | 753 | -s|--strategy) |
eaa4e6ee | 754 | __gitcomp "$__git_merge_strategies" |
3c7b480a JS |
755 | return 0 |
756 | esac | |
3c7b480a JS |
757 | case "$cur" in |
758 | --strategy=*) | |
eaa4e6ee | 759 | __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}" |
3c7b480a JS |
760 | return 0 |
761 | ;; | |
762 | esac | |
763 | return 1 | |
764 | } | |
765 | ||
50478223 JH |
766 | __git_commands () { |
767 | if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}" | |
768 | then | |
769 | printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}" | |
770 | else | |
771 | git help -a|egrep '^ [a-zA-Z0-9]' | |
772 | fi | |
773 | } | |
774 | ||
eaa4e6ee | 775 | __git_list_all_commands () |
f2bb9f88 SP |
776 | { |
777 | local i IFS=" "$'\n' | |
50478223 | 778 | for i in $(__git_commands) |
1eb7e2f8 LM |
779 | do |
780 | case $i in | |
781 | *--*) : helper pattern;; | |
782 | *) echo $i;; | |
783 | esac | |
784 | done | |
785 | } | |
1eb7e2f8 | 786 | |
eaa4e6ee JN |
787 | __git_all_commands= |
788 | __git_compute_all_commands () | |
789 | { | |
cf0ff02a FC |
790 | test -n "$__git_all_commands" || |
791 | __git_all_commands=$(__git_list_all_commands) | |
eaa4e6ee JN |
792 | } |
793 | ||
794 | __git_list_porcelain_commands () | |
1eb7e2f8 | 795 | { |
1eb7e2f8 | 796 | local i IFS=" "$'\n' |
eaa4e6ee | 797 | __git_compute_all_commands |
585b96bd | 798 | for i in $__git_all_commands |
f2bb9f88 SP |
799 | do |
800 | case $i in | |
718a087a | 801 | *--*) : helper pattern;; |
a925c6f1 SP |
802 | applymbox) : ask gittus;; |
803 | applypatch) : ask gittus;; | |
804 | archimport) : import;; | |
2e3a430a | 805 | cat-file) : plumbing;; |
56d99c67 | 806 | check-attr) : plumbing;; |
368aa529 | 807 | check-ignore) : plumbing;; |
226ad348 | 808 | check-mailmap) : plumbing;; |
f2bb9f88 | 809 | check-ref-format) : plumbing;; |
ff2549dc | 810 | checkout-index) : plumbing;; |
160fcdb0 | 811 | column) : internal helper;; |
f2bb9f88 | 812 | commit-tree) : plumbing;; |
ff2549dc | 813 | count-objects) : infrequent;; |
a074aa90 SG |
814 | credential) : credentials;; |
815 | credential-*) : credentials helper;; | |
a925c6f1 SP |
816 | cvsexportcommit) : export;; |
817 | cvsimport) : import;; | |
f2bb9f88 SP |
818 | cvsserver) : daemon;; |
819 | daemon) : daemon;; | |
5cfb4fe5 SP |
820 | diff-files) : plumbing;; |
821 | diff-index) : plumbing;; | |
822 | diff-tree) : plumbing;; | |
c6ec3b13 | 823 | fast-import) : import;; |
ff2549dc | 824 | fast-export) : export;; |
a925c6f1 | 825 | fsck-objects) : plumbing;; |
f2bb9f88 | 826 | fetch-pack) : plumbing;; |
a925c6f1 | 827 | fmt-merge-msg) : plumbing;; |
56d99c67 | 828 | for-each-ref) : plumbing;; |
f2bb9f88 SP |
829 | hash-object) : plumbing;; |
830 | http-*) : transport;; | |
831 | index-pack) : plumbing;; | |
a925c6f1 | 832 | init-db) : deprecated;; |
f2bb9f88 | 833 | local-fetch) : plumbing;; |
ff2549dc PB |
834 | ls-files) : plumbing;; |
835 | ls-remote) : plumbing;; | |
836 | ls-tree) : plumbing;; | |
f2bb9f88 SP |
837 | mailinfo) : plumbing;; |
838 | mailsplit) : plumbing;; | |
839 | merge-*) : plumbing;; | |
840 | mktree) : plumbing;; | |
841 | mktag) : plumbing;; | |
842 | pack-objects) : plumbing;; | |
843 | pack-redundant) : plumbing;; | |
844 | pack-refs) : plumbing;; | |
845 | parse-remote) : plumbing;; | |
846 | patch-id) : plumbing;; | |
a925c6f1 SP |
847 | prune) : plumbing;; |
848 | prune-packed) : plumbing;; | |
849 | quiltimport) : import;; | |
f2bb9f88 SP |
850 | read-tree) : plumbing;; |
851 | receive-pack) : plumbing;; | |
63d04a78 | 852 | remote-*) : transport;; |
f2bb9f88 SP |
853 | rerere) : plumbing;; |
854 | rev-list) : plumbing;; | |
855 | rev-parse) : plumbing;; | |
856 | runstatus) : plumbing;; | |
857 | sh-setup) : internal;; | |
858 | shell) : daemon;; | |
ff2549dc | 859 | show-ref) : plumbing;; |
f2bb9f88 SP |
860 | send-pack) : plumbing;; |
861 | show-index) : plumbing;; | |
862 | ssh-*) : transport;; | |
863 | stripspace) : plumbing;; | |
864 | symbolic-ref) : plumbing;; | |
865 | unpack-file) : plumbing;; | |
866 | unpack-objects) : plumbing;; | |
a925c6f1 | 867 | update-index) : plumbing;; |
f2bb9f88 SP |
868 | update-ref) : plumbing;; |
869 | update-server-info) : daemon;; | |
870 | upload-archive) : plumbing;; | |
871 | upload-pack) : plumbing;; | |
872 | write-tree) : plumbing;; | |
ff2549dc PB |
873 | var) : infrequent;; |
874 | verify-pack) : infrequent;; | |
a925c6f1 | 875 | verify-tag) : plumbing;; |
f2bb9f88 SP |
876 | *) echo $i;; |
877 | esac | |
878 | done | |
879 | } | |
eaa4e6ee JN |
880 | |
881 | __git_porcelain_commands= | |
882 | __git_compute_porcelain_commands () | |
883 | { | |
cf0ff02a FC |
884 | test -n "$__git_porcelain_commands" || |
885 | __git_porcelain_commands=$(__git_list_porcelain_commands) | |
eaa4e6ee | 886 | } |
f2bb9f88 | 887 | |
e8f9e428 SG |
888 | # Lists all set config variables starting with the given section prefix, |
889 | # with the prefix removed. | |
890 | __git_get_config_variables () | |
c3898111 | 891 | { |
e8f9e428 | 892 | local section="$1" i IFS=$'\n' |
e15098a3 | 893 | for i in $(__git config --name-only --get-regexp "^$section\..*"); do |
905f2036 | 894 | echo "${i#$section.}" |
c3898111 SG |
895 | done |
896 | } | |
897 | ||
c3898111 SG |
898 | __git_pretty_aliases () |
899 | { | |
e8f9e428 | 900 | __git_get_config_variables "pretty" |
c3898111 SG |
901 | } |
902 | ||
367dce2a DS |
903 | __git_aliases () |
904 | { | |
e8f9e428 | 905 | __git_get_config_variables "alias" |
367dce2a DS |
906 | } |
907 | ||
a42577d4 | 908 | # __git_aliased_command requires 1 argument |
367dce2a DS |
909 | __git_aliased_command () |
910 | { | |
e15098a3 | 911 | local word cmdline=$(__git config --get "alias.$1") |
367dce2a | 912 | for word in $cmdline; do |
c63437cb | 913 | case "$word" in |
66729509 SG |
914 | \!gitk|gitk) |
915 | echo "gitk" | |
367dce2a | 916 | return |
66729509 | 917 | ;; |
c63437cb SG |
918 | \!*) : shell command alias ;; |
919 | -*) : option ;; | |
920 | *=*) : setting env ;; | |
921 | git) : git itself ;; | |
56f24e80 SP |
922 | \(\)) : skip parens of shell function definition ;; |
923 | {) : skip start of shell helper function ;; | |
924 | :) : skip null command ;; | |
925 | \'*) : skip opening quote after sh -c ;; | |
c63437cb SG |
926 | *) |
927 | echo "$word" | |
367dce2a | 928 | return |
c63437cb | 929 | esac |
367dce2a DS |
930 | done |
931 | } | |
932 | ||
918c03c2 SG |
933 | # __git_find_on_cmdline requires 1 argument |
934 | __git_find_on_cmdline () | |
3ff1320d | 935 | { |
da4902a7 | 936 | local word subcommand c=1 |
da48616f PD |
937 | while [ $c -lt $cword ]; do |
938 | word="${words[c]}" | |
3ff1320d SG |
939 | for subcommand in $1; do |
940 | if [ "$subcommand" = "$word" ]; then | |
941 | echo "$subcommand" | |
942 | return | |
943 | fi | |
944 | done | |
6e8c755f | 945 | ((c++)) |
3ff1320d SG |
946 | done |
947 | } | |
948 | ||
7c599e92 TB |
949 | # Echo the value of an option set on the command line or config |
950 | # | |
951 | # $1: short option name | |
952 | # $2: long option name including = | |
953 | # $3: list of possible values | |
954 | # $4: config string (optional) | |
955 | # | |
956 | # example: | |
957 | # result="$(__git_get_option_value "-d" "--do-something=" \ | |
958 | # "yes no" "core.doSomething")" | |
959 | # | |
960 | # result is then either empty (no option set) or "yes" or "no" | |
961 | # | |
962 | # __git_get_option_value requires 3 arguments | |
963 | __git_get_option_value () | |
964 | { | |
965 | local c short_opt long_opt val | |
966 | local result= values config_key word | |
967 | ||
968 | short_opt="$1" | |
969 | long_opt="$2" | |
970 | values="$3" | |
971 | config_key="$4" | |
972 | ||
973 | ((c = $cword - 1)) | |
974 | while [ $c -ge 0 ]; do | |
975 | word="${words[c]}" | |
976 | for val in $values; do | |
977 | if [ "$short_opt$val" = "$word" ] || | |
978 | [ "$long_opt$val" = "$word" ]; then | |
979 | result="$val" | |
980 | break 2 | |
981 | fi | |
982 | done | |
983 | ((c--)) | |
984 | done | |
985 | ||
986 | if [ -n "$config_key" ] && [ -z "$result" ]; then | |
1cd23e9e | 987 | result="$(__git config "$config_key")" |
7c599e92 TB |
988 | fi |
989 | ||
990 | echo "$result" | |
991 | } | |
992 | ||
d773c631 SG |
993 | __git_has_doubledash () |
994 | { | |
da4902a7 | 995 | local c=1 |
da48616f PD |
996 | while [ $c -lt $cword ]; do |
997 | if [ "--" = "${words[c]}" ]; then | |
d773c631 SG |
998 | return 0 |
999 | fi | |
6e8c755f | 1000 | ((c++)) |
d773c631 SG |
1001 | done |
1002 | return 1 | |
1003 | } | |
1004 | ||
fea16b47 MP |
1005 | # Try to count non option arguments passed on the command line for the |
1006 | # specified git command. | |
1007 | # When options are used, it is necessary to use the special -- option to | |
1008 | # tell the implementation were non option arguments begin. | |
1009 | # XXX this can not be improved, since options can appear everywhere, as | |
1010 | # an example: | |
1011 | # git mv x -n y | |
1012 | # | |
1013 | # __git_count_arguments requires 1 argument: the git command executed. | |
1014 | __git_count_arguments () | |
1015 | { | |
1016 | local word i c=0 | |
1017 | ||
1018 | # Skip "git" (first argument) | |
1019 | for ((i=1; i < ${#words[@]}; i++)); do | |
1020 | word="${words[i]}" | |
1021 | ||
1022 | case "$word" in | |
1023 | --) | |
1024 | # Good; we can assume that the following are only non | |
1025 | # option arguments. | |
1026 | ((c = 0)) | |
1027 | ;; | |
1028 | "$1") | |
1029 | # Skip the specified git command and discard git | |
1030 | # main options | |
1031 | ((c = 0)) | |
1032 | ;; | |
1033 | ?*) | |
1034 | ((c++)) | |
1035 | ;; | |
1036 | esac | |
1037 | done | |
1038 | ||
1039 | printf "%d" $c | |
1040 | } | |
1041 | ||
7950659d | 1042 | __git_whitespacelist="nowarn warn error error-all fix" |
88329195 SP |
1043 | |
1044 | _git_am () | |
1045 | { | |
fad9484f SG |
1046 | __git_find_repo_path |
1047 | if [ -d "$__git_repo_path"/rebase-apply ]; then | |
85f6b439 | 1048 | __gitcomp "--skip --continue --resolved --abort" |
88329195 SP |
1049 | return |
1050 | fi | |
1051 | case "$cur" in | |
1052 | --whitespace=*) | |
b3391775 | 1053 | __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" |
88329195 SP |
1054 | return |
1055 | ;; | |
1056 | --*) | |
b3391775 | 1057 | __gitcomp " |
43acdf24 | 1058 | --3way --committer-date-is-author-date --ignore-date |
86c91f91 | 1059 | --ignore-whitespace --ignore-space-change |
43acdf24 | 1060 | --interactive --keep --no-utf8 --signoff --utf8 |
af4e9e8c | 1061 | --whitespace= --scissors |
b3391775 | 1062 | " |
88329195 SP |
1063 | return |
1064 | esac | |
88329195 SP |
1065 | } |
1066 | ||
1067 | _git_apply () | |
1068 | { | |
88329195 SP |
1069 | case "$cur" in |
1070 | --whitespace=*) | |
b3391775 | 1071 | __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" |
88329195 SP |
1072 | return |
1073 | ;; | |
1074 | --*) | |
b3391775 | 1075 | __gitcomp " |
88329195 SP |
1076 | --stat --numstat --summary --check --index |
1077 | --cached --index-info --reverse --reject --unidiff-zero | |
1078 | --apply --no-add --exclude= | |
86c91f91 | 1079 | --ignore-whitespace --ignore-space-change |
88329195 | 1080 | --whitespace= --inaccurate-eof --verbose |
b3391775 | 1081 | " |
88329195 SP |
1082 | return |
1083 | esac | |
88329195 SP |
1084 | } |
1085 | ||
8435b548 SP |
1086 | _git_add () |
1087 | { | |
8435b548 SP |
1088 | case "$cur" in |
1089 | --*) | |
1d284cba SG |
1090 | __gitcomp " |
1091 | --interactive --refresh --patch --update --dry-run | |
c9a114b5 | 1092 | --ignore-errors --intent-to-add |
1d284cba | 1093 | " |
8435b548 SP |
1094 | return |
1095 | esac | |
fea16b47 MP |
1096 | |
1097 | # XXX should we check for --update and --all options ? | |
ea95c7b8 | 1098 | __git_complete_index_file "--others --modified --directory --no-empty-directory" |
8435b548 SP |
1099 | } |
1100 | ||
b3191ce2 LM |
1101 | _git_archive () |
1102 | { | |
b3191ce2 LM |
1103 | case "$cur" in |
1104 | --format=*) | |
1105 | __gitcomp "$(git archive --list)" "" "${cur##--format=}" | |
1106 | return | |
1107 | ;; | |
1108 | --remote=*) | |
a31e6262 | 1109 | __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}" |
b3191ce2 LM |
1110 | return |
1111 | ;; | |
1112 | --*) | |
1113 | __gitcomp " | |
1114 | --format= --list --verbose | |
1115 | --prefix= --remote= --exec= | |
1116 | " | |
1117 | return | |
1118 | ;; | |
1119 | esac | |
1120 | __git_complete_file | |
1121 | } | |
1122 | ||
b2e69f62 SP |
1123 | _git_bisect () |
1124 | { | |
d773c631 SG |
1125 | __git_has_doubledash && return |
1126 | ||
bf11d461 | 1127 | local subcommands="start bad good skip reset visualize replay log run" |
918c03c2 | 1128 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
3ff1320d | 1129 | if [ -z "$subcommand" ]; then |
fad9484f SG |
1130 | __git_find_repo_path |
1131 | if [ -f "$__git_repo_path"/BISECT_START ]; then | |
128191f5 SG |
1132 | __gitcomp "$subcommands" |
1133 | else | |
1134 | __gitcomp "replay start" | |
1135 | fi | |
b2e69f62 SP |
1136 | return |
1137 | fi | |
1138 | ||
3ff1320d | 1139 | case "$subcommand" in |
8205ff8e | 1140 | bad|good|reset|skip|start) |
15b4a163 | 1141 | __git_complete_refs |
b2e69f62 SP |
1142 | ;; |
1143 | *) | |
b2e69f62 SP |
1144 | ;; |
1145 | esac | |
1146 | } | |
1147 | ||
690d8824 JH |
1148 | _git_branch () |
1149 | { | |
da4902a7 | 1150 | local i c=1 only_local_ref="n" has_r="n" |
b9217642 | 1151 | |
da48616f PD |
1152 | while [ $c -lt $cword ]; do |
1153 | i="${words[c]}" | |
b9217642 | 1154 | case "$i" in |
2703c22f VS |
1155 | -d|--delete|-m|--move) only_local_ref="y" ;; |
1156 | -r|--remotes) has_r="y" ;; | |
b9217642 | 1157 | esac |
6e8c755f | 1158 | ((c++)) |
b9217642 SG |
1159 | done |
1160 | ||
da48616f | 1161 | case "$cur" in |
ca45d0fa | 1162 | --set-upstream-to=*) |
15b4a163 | 1163 | __git_complete_refs --cur="${cur##--set-upstream-to=}" |
ca45d0fa | 1164 | ;; |
3b376b0c SG |
1165 | --*) |
1166 | __gitcomp " | |
1167 | --color --no-color --verbose --abbrev= --no-abbrev | |
50e61025 | 1168 | --track --no-track --contains --merged --no-merged |
04308e9d | 1169 | --set-upstream-to= --edit-description --list |
2703c22f | 1170 | --unset-upstream --delete --move --remotes |
3b376b0c SG |
1171 | " |
1172 | ;; | |
b9217642 SG |
1173 | *) |
1174 | if [ $only_local_ref = "y" -a $has_r = "n" ]; then | |
a31e6262 | 1175 | __gitcomp_nl "$(__git_heads)" |
b9217642 | 1176 | else |
15b4a163 | 1177 | __git_complete_refs |
b9217642 SG |
1178 | fi |
1179 | ;; | |
3b376b0c | 1180 | esac |
690d8824 JH |
1181 | } |
1182 | ||
374a58c9 ML |
1183 | _git_bundle () |
1184 | { | |
da48616f PD |
1185 | local cmd="${words[2]}" |
1186 | case "$cword" in | |
8d8163f3 | 1187 | 2) |
374a58c9 ML |
1188 | __gitcomp "create list-heads verify unbundle" |
1189 | ;; | |
8d8163f3 | 1190 | 3) |
374a58c9 ML |
1191 | # looking for a file |
1192 | ;; | |
1193 | *) | |
1194 | case "$cmd" in | |
1195 | create) | |
1196 | __git_complete_revlist | |
1197 | ;; | |
1198 | esac | |
1199 | ;; | |
1200 | esac | |
1201 | } | |
1202 | ||
690d8824 JH |
1203 | _git_checkout () |
1204 | { | |
c84bb14c SG |
1205 | __git_has_doubledash && return |
1206 | ||
e648f8b6 SG |
1207 | case "$cur" in |
1208 | --conflict=*) | |
1209 | __gitcomp "diff3 merge" "" "${cur##--conflict=}" | |
1210 | ;; | |
1211 | --*) | |
1212 | __gitcomp " | |
1213 | --quiet --ours --theirs --track --no-track --merge | |
86e8e7a5 | 1214 | --conflict= --orphan --patch |
e648f8b6 SG |
1215 | " |
1216 | ;; | |
1217 | *) | |
34a6bbb5 KB |
1218 | # check if --track, --no-track, or --no-guess was specified |
1219 | # if so, disable DWIM mode | |
15b4a163 | 1220 | local flags="--track --no-track --no-guess" track_opt="--track" |
34a6bbb5 | 1221 | if [ -n "$(__git_find_on_cmdline "$flags")" ]; then |
15b4a163 | 1222 | track_opt='' |
34a6bbb5 | 1223 | fi |
15b4a163 | 1224 | __git_complete_refs $track_opt |
e648f8b6 SG |
1225 | ;; |
1226 | esac | |
690d8824 JH |
1227 | } |
1228 | ||
d8a9fea5 SP |
1229 | _git_cherry () |
1230 | { | |
15b4a163 | 1231 | __git_complete_refs |
d8a9fea5 SP |
1232 | } |
1233 | ||
1273231e SP |
1234 | _git_cherry_pick () |
1235 | { | |
fad9484f SG |
1236 | __git_find_repo_path |
1237 | if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then | |
7655fa7f FC |
1238 | __gitcomp "--continue --quit --abort" |
1239 | return | |
1240 | fi | |
1273231e SP |
1241 | case "$cur" in |
1242 | --*) | |
7655fa7f | 1243 | __gitcomp "--edit --no-commit --signoff --strategy= --mainline" |
1273231e SP |
1244 | ;; |
1245 | *) | |
15b4a163 | 1246 | __git_complete_refs |
1273231e SP |
1247 | ;; |
1248 | esac | |
1249 | } | |
1250 | ||
4181c7e8 LM |
1251 | _git_clean () |
1252 | { | |
4181c7e8 LM |
1253 | case "$cur" in |
1254 | --*) | |
1255 | __gitcomp "--dry-run --quiet" | |
1256 | return | |
1257 | ;; | |
1258 | esac | |
fea16b47 MP |
1259 | |
1260 | # XXX should we check for -x option ? | |
ea95c7b8 | 1261 | __git_complete_index_file "--others --directory" |
4181c7e8 LM |
1262 | } |
1263 | ||
3eb11012 LM |
1264 | _git_clone () |
1265 | { | |
3eb11012 LM |
1266 | case "$cur" in |
1267 | --*) | |
1268 | __gitcomp " | |
1269 | --local | |
1270 | --no-hardlinks | |
1271 | --shared | |
1272 | --reference | |
1273 | --quiet | |
1274 | --no-checkout | |
1275 | --bare | |
1276 | --mirror | |
1277 | --origin | |
1278 | --upload-pack | |
1279 | --template= | |
1280 | --depth | |
4047fecf RT |
1281 | --single-branch |
1282 | --branch | |
5f072e00 | 1283 | --recurse-submodules |
3eb11012 LM |
1284 | " |
1285 | return | |
1286 | ;; | |
1287 | esac | |
3eb11012 LM |
1288 | } |
1289 | ||
21d2a9e3 TB |
1290 | __git_untracked_file_modes="all no normal" |
1291 | ||
4548e855 SP |
1292 | _git_commit () |
1293 | { | |
fea16b47 MP |
1294 | case "$prev" in |
1295 | -c|-C) | |
15b4a163 | 1296 | __git_complete_refs |
fea16b47 MP |
1297 | return |
1298 | ;; | |
1299 | esac | |
d773c631 | 1300 | |
4548e855 | 1301 | case "$cur" in |
9a424b27 | 1302 | --cleanup=*) |
72dbb365 | 1303 | __gitcomp "default scissors strip verbatim whitespace |
9a424b27 SG |
1304 | " "" "${cur##--cleanup=}" |
1305 | return | |
1306 | ;; | |
77653abd TM |
1307 | --reuse-message=*|--reedit-message=*|\ |
1308 | --fixup=*|--squash=*) | |
15b4a163 | 1309 | __git_complete_refs --cur="${cur#*=}" |
9a424b27 SG |
1310 | return |
1311 | ;; | |
1312 | --untracked-files=*) | |
21d2a9e3 | 1313 | __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" |
9a424b27 SG |
1314 | return |
1315 | ;; | |
4548e855 | 1316 | --*) |
b3391775 | 1317 | __gitcomp " |
4548e855 | 1318 | --all --author= --signoff --verify --no-verify |
7dd9ab0c YB |
1319 | --edit --no-edit |
1320 | --amend --include --only --interactive | |
9a424b27 SG |
1321 | --dry-run --reuse-message= --reedit-message= |
1322 | --reset-author --file= --message= --template= | |
1323 | --cleanup= --untracked-files --untracked-files= | |
77653abd | 1324 | --verbose --quiet --fixup= --squash= |
b3391775 | 1325 | " |
4548e855 SP |
1326 | return |
1327 | esac | |
fea16b47 | 1328 | |
1cd23e9e | 1329 | if __git rev-parse --verify --quiet HEAD >/dev/null; then |
f825972c | 1330 | __git_complete_index_file "--committable" |
fea16b47 MP |
1331 | else |
1332 | # This is the first commit | |
1333 | __git_complete_index_file "--cached" | |
1334 | fi | |
4548e855 SP |
1335 | } |
1336 | ||
217926c0 SP |
1337 | _git_describe () |
1338 | { | |
cbb504c9 TR |
1339 | case "$cur" in |
1340 | --*) | |
1341 | __gitcomp " | |
1342 | --all --tags --contains --abbrev= --candidates= | |
1343 | --exact-match --debug --long --match --always | |
1344 | " | |
1345 | return | |
1346 | esac | |
15b4a163 | 1347 | __git_complete_refs |
217926c0 SP |
1348 | } |
1349 | ||
07924d4d MP |
1350 | __git_diff_algorithms="myers minimal patience histogram" |
1351 | ||
462f2134 | 1352 | __git_diff_submodule_formats="diff log short" |
ac76fd54 | 1353 | |
20bf7292 | 1354 | __git_diff_common_options="--stat --numstat --shortstat --summary |
b3a4f858 JS |
1355 | --patch-with-stat --name-only --name-status --color |
1356 | --no-color --color-words --no-renames --check | |
f135aacb | 1357 | --full-index --binary --abbrev --diff-filter= |
47d5a8fa | 1358 | --find-copies-harder |
b3a4f858 | 1359 | --text --ignore-space-at-eol --ignore-space-change |
c2545167 TB |
1360 | --ignore-all-space --ignore-blank-lines --exit-code |
1361 | --quiet --ext-diff --no-ext-diff | |
aba201c6 | 1362 | --no-prefix --src-prefix= --dst-prefix= |
6d0e674a | 1363 | --inter-hunk-context= |
216120ab | 1364 | --patience --histogram --minimal |
e6414b46 | 1365 | --raw --word-diff --word-diff-regex= |
8fd2cfa7 SB |
1366 | --dirstat --dirstat= --dirstat-by-file |
1367 | --dirstat-by-file= --cumulative | |
07924d4d | 1368 | --diff-algorithm= |
ac76fd54 | 1369 | --submodule --submodule= |
20bf7292 TR |
1370 | " |
1371 | ||
1372 | _git_diff () | |
1373 | { | |
1374 | __git_has_doubledash && return | |
1375 | ||
20bf7292 | 1376 | case "$cur" in |
07924d4d MP |
1377 | --diff-algorithm=*) |
1378 | __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" | |
1379 | return | |
1380 | ;; | |
ac76fd54 JK |
1381 | --submodule=*) |
1382 | __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" | |
1383 | return | |
1384 | ;; | |
20bf7292 | 1385 | --*) |
ebd15bf0 | 1386 | __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex |
861514d3 | 1387 | --base --ours --theirs --no-index |
20bf7292 | 1388 | $__git_diff_common_options |
aba201c6 | 1389 | " |
b3a4f858 JS |
1390 | return |
1391 | ;; | |
1392 | esac | |
1d66ec58 | 1393 | __git_complete_revlist_file |
690d8824 JH |
1394 | } |
1395 | ||
c5f424fd | 1396 | __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff |
f13f9b0e | 1397 | tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare |
e2dc2de9 DA |
1398 | " |
1399 | ||
1400 | _git_difftool () | |
1401 | { | |
f7ad96cf MH |
1402 | __git_has_doubledash && return |
1403 | ||
e2dc2de9 DA |
1404 | case "$cur" in |
1405 | --tool=*) | |
1406 | __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}" | |
1407 | return | |
1408 | ;; | |
1409 | --*) | |
f7ad96cf MH |
1410 | __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex |
1411 | --base --ours --theirs | |
1412 | --no-renames --diff-filter= --find-copies-harder | |
1413 | --relative --ignore-submodules | |
1414 | --tool=" | |
e2dc2de9 DA |
1415 | return |
1416 | ;; | |
1417 | esac | |
d8517cc6 | 1418 | __git_complete_revlist_file |
e2dc2de9 DA |
1419 | } |
1420 | ||
4dd5c470 SYS |
1421 | __git_fetch_recurse_submodules="yes on-demand no" |
1422 | ||
0a4e1472 JS |
1423 | __git_fetch_options=" |
1424 | --quiet --verbose --append --upload-pack --force --keep --depth= | |
4dd5c470 | 1425 | --tags --no-tags --all --prune --dry-run --recurse-submodules= |
0a4e1472 JS |
1426 | " |
1427 | ||
690d8824 JH |
1428 | _git_fetch () |
1429 | { | |
0a4e1472 | 1430 | case "$cur" in |
4dd5c470 SYS |
1431 | --recurse-submodules=*) |
1432 | __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}" | |
1433 | return | |
1434 | ;; | |
0a4e1472 JS |
1435 | --*) |
1436 | __gitcomp "$__git_fetch_options" | |
1437 | return | |
1438 | ;; | |
1439 | esac | |
52d5c3b5 | 1440 | __git_complete_remote_or_refspec |
690d8824 JH |
1441 | } |
1442 | ||
2f65494d | 1443 | __git_format_patch_options=" |
ea573521 | 1444 | --stdout --attach --no-attach --thread --thread= --no-thread |
2f65494d FC |
1445 | --numbered --start-number --numbered-files --keep-subject --signoff |
1446 | --signature --no-signature --in-reply-to= --cc= --full-index --binary | |
1447 | --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix= | |
1448 | --inline --suffix= --ignore-if-in-upstream --subject-prefix= | |
ea573521 | 1449 | --output-directory --reroll-count --to= --quiet --notes |
2f65494d FC |
1450 | " |
1451 | ||
f53352fb SP |
1452 | _git_format_patch () |
1453 | { | |
f53352fb | 1454 | case "$cur" in |
e1d37937 SB |
1455 | --thread=*) |
1456 | __gitcomp " | |
1457 | deep shallow | |
1458 | " "" "${cur##--thread=}" | |
1459 | return | |
1460 | ;; | |
f53352fb | 1461 | --*) |
2f65494d | 1462 | __gitcomp "$__git_format_patch_options" |
f53352fb SP |
1463 | return |
1464 | ;; | |
1465 | esac | |
1466 | __git_complete_revlist | |
1467 | } | |
1468 | ||
4bca8636 AJ |
1469 | _git_fsck () |
1470 | { | |
4bca8636 AJ |
1471 | case "$cur" in |
1472 | --*) | |
1473 | __gitcomp " | |
1474 | --tags --root --unreachable --cache --no-reflogs --full | |
1475 | --strict --verbose --lost-found | |
1476 | " | |
1477 | return | |
1478 | ;; | |
1479 | esac | |
4bca8636 AJ |
1480 | } |
1481 | ||
b26c8748 SP |
1482 | _git_gc () |
1483 | { | |
b26c8748 SP |
1484 | case "$cur" in |
1485 | --*) | |
47e98eec | 1486 | __gitcomp "--prune --aggressive" |
b26c8748 SP |
1487 | return |
1488 | ;; | |
1489 | esac | |
b26c8748 SP |
1490 | } |
1491 | ||
66729509 SG |
1492 | _git_gitk () |
1493 | { | |
1494 | _gitk | |
1495 | } | |
1496 | ||
29eec71f | 1497 | __git_match_ctag() { |
db8d7508 | 1498 | awk "/^${1//\//\\/}/ { print \$1 }" "$2" |
29eec71f JK |
1499 | } |
1500 | ||
c72e0db1 LM |
1501 | _git_grep () |
1502 | { | |
1503 | __git_has_doubledash && return | |
1504 | ||
c72e0db1 LM |
1505 | case "$cur" in |
1506 | --*) | |
1507 | __gitcomp " | |
1508 | --cached | |
1509 | --text --ignore-case --word-regexp --invert-match | |
5a69eaf5 | 1510 | --full-name --line-number |
c72e0db1 | 1511 | --extended-regexp --basic-regexp --fixed-strings |
63e7e9d8 | 1512 | --perl-regexp |
89f09dd3 | 1513 | --threads |
c72e0db1 LM |
1514 | --files-with-matches --name-only |
1515 | --files-without-match | |
a91f453f | 1516 | --max-depth |
c72e0db1 LM |
1517 | --count |
1518 | --and --or --not --all-match | |
1519 | " | |
1520 | return | |
1521 | ;; | |
1522 | esac | |
17225c49 | 1523 | |
29eec71f JK |
1524 | case "$cword,$prev" in |
1525 | 2,*|*,-*) | |
1526 | if test -r tags; then | |
d2c78075 | 1527 | __gitcomp_nl "$(__git_match_ctag "$cur" tags)" |
29eec71f JK |
1528 | return |
1529 | fi | |
1530 | ;; | |
1531 | esac | |
1532 | ||
15b4a163 | 1533 | __git_complete_refs |
c72e0db1 LM |
1534 | } |
1535 | ||
1eb7e2f8 LM |
1536 | _git_help () |
1537 | { | |
1eb7e2f8 LM |
1538 | case "$cur" in |
1539 | --*) | |
716b29db | 1540 | __gitcomp "--all --guides --info --man --web" |
1eb7e2f8 LM |
1541 | return |
1542 | ;; | |
1543 | esac | |
eaa4e6ee | 1544 | __git_compute_all_commands |
f85a6f0b | 1545 | __gitcomp "$__git_all_commands $(__git_aliases) |
2946cccf | 1546 | attributes cli core-tutorial cvs-migration |
4d10b7e1 RT |
1547 | diffcore everyday gitk glossary hooks ignore modules |
1548 | namespaces repository-layout revisions tutorial tutorial-2 | |
99f0b599 | 1549 | workflows |
2946cccf | 1550 | " |
1eb7e2f8 LM |
1551 | } |
1552 | ||
5dad868b LM |
1553 | _git_init () |
1554 | { | |
5dad868b LM |
1555 | case "$cur" in |
1556 | --shared=*) | |
1557 | __gitcomp " | |
1558 | false true umask group all world everybody | |
1559 | " "" "${cur##--shared=}" | |
1560 | return | |
1561 | ;; | |
1562 | --*) | |
1563 | __gitcomp "--quiet --bare --template= --shared --shared=" | |
1564 | return | |
1565 | ;; | |
1566 | esac | |
5dad868b LM |
1567 | } |
1568 | ||
b1bc1494 LM |
1569 | _git_ls_files () |
1570 | { | |
b1bc1494 LM |
1571 | case "$cur" in |
1572 | --*) | |
1573 | __gitcomp "--cached --deleted --modified --others --ignored | |
1574 | --stage --directory --no-empty-directory --unmerged | |
1575 | --killed --exclude= --exclude-from= | |
1576 | --exclude-per-directory= --exclude-standard | |
1577 | --error-unmatch --with-tree= --full-name | |
1578 | --abbrev --ignored --exclude-per-directory | |
1579 | " | |
1580 | return | |
1581 | ;; | |
1582 | esac | |
fea16b47 MP |
1583 | |
1584 | # XXX ignore options like --modified and always suggest all cached | |
1585 | # files. | |
1586 | __git_complete_index_file "--cached" | |
b1bc1494 LM |
1587 | } |
1588 | ||
690d8824 JH |
1589 | _git_ls_remote () |
1590 | { | |
a31e6262 | 1591 | __gitcomp_nl "$(__git_remotes)" |
690d8824 JH |
1592 | } |
1593 | ||
1594 | _git_ls_tree () | |
1595 | { | |
1596 | __git_complete_file | |
1597 | } | |
1598 | ||
a393777e TR |
1599 | # Options that go well for log, shortlog and gitk |
1600 | __git_log_common_options=" | |
1601 | --not --all | |
1602 | --branches --tags --remotes | |
4fe1a619 | 1603 | --first-parent --merges --no-merges |
a393777e TR |
1604 | --max-count= |
1605 | --max-age= --since= --after= | |
1606 | --min-age= --until= --before= | |
6a6ebded MG |
1607 | --min-parents= --max-parents= |
1608 | --no-min-parents --no-max-parents | |
a393777e TR |
1609 | " |
1610 | # Options that go well for log and gitk (not shortlog) | |
1611 | __git_log_gitk_options=" | |
1612 | --dense --sparse --full-history | |
1613 | --simplify-merges --simplify-by-decoration | |
3925b575 | 1614 | --left-right --notes --no-notes |
a393777e TR |
1615 | " |
1616 | # Options that go well for log and shortlog (not gitk) | |
1617 | __git_log_shortlog_options=" | |
1618 | --author= --committer= --grep= | |
22dfa8a2 | 1619 | --all-match --invert-grep |
a393777e TR |
1620 | " |
1621 | ||
3d279863 | 1622 | __git_log_pretty_formats="oneline short medium full fuller email raw format:" |
672c68cb | 1623 | __git_log_date_formats="relative iso8601 rfc2822 short local default raw" |
3d279863 | 1624 | |
690d8824 JH |
1625 | _git_log () |
1626 | { | |
d773c631 | 1627 | __git_has_doubledash && return |
fad9484f | 1628 | __git_find_repo_path |
d773c631 | 1629 | |
bf3c20f6 | 1630 | local merge="" |
fad9484f | 1631 | if [ -f "$__git_repo_path/MERGE_HEAD" ]; then |
bf3c20f6 TR |
1632 | merge="--merge" |
1633 | fi | |
6e31b866 | 1634 | case "$cur" in |
e67d71e5 | 1635 | --pretty=*|--format=*) |
c3898111 | 1636 | __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases) |
e67d71e5 | 1637 | " "" "${cur#*=}" |
72de29c2 TL |
1638 | return |
1639 | ;; | |
47e98eec | 1640 | --date=*) |
672c68cb | 1641 | __gitcomp "$__git_log_date_formats" "" "${cur##--date=}" |
47e98eec SP |
1642 | return |
1643 | ;; | |
af4e9e8c | 1644 | --decorate=*) |
af16bdaa | 1645 | __gitcomp "full short no" "" "${cur##--decorate=}" |
af4e9e8c SB |
1646 | return |
1647 | ;; | |
ac76fd54 JK |
1648 | --diff-algorithm=*) |
1649 | __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" | |
1650 | return | |
1651 | ;; | |
1652 | --submodule=*) | |
1653 | __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" | |
1654 | return | |
1655 | ;; | |
6e31b866 | 1656 | --*) |
b3391775 | 1657 | __gitcomp " |
a393777e TR |
1658 | $__git_log_common_options |
1659 | $__git_log_shortlog_options | |
1660 | $__git_log_gitk_options | |
8f87fae6 | 1661 | --root --topo-order --date-order --reverse |
5d0e6343 | 1662 | --follow --full-diff |
6e31b866 | 1663 | --abbrev-commit --abbrev= |
47e98eec | 1664 | --relative-date --date= |
72de29c2 | 1665 | --pretty= --format= --oneline |
2ca0b197 | 1666 | --show-signature |
d3bfbf91 | 1667 | --cherry-mark |
a393777e | 1668 | --cherry-pick |
20827d99 | 1669 | --graph |
af4e9e8c | 1670 | --decorate --decorate= |
20bf7292 | 1671 | --walk-reflogs |
a393777e | 1672 | --parents --children |
bf3c20f6 | 1673 | $merge |
20bf7292 | 1674 | $__git_diff_common_options |
47d5a8fa | 1675 | --pickaxe-all --pickaxe-regex |
b3391775 | 1676 | " |
6e31b866 SP |
1677 | return |
1678 | ;; | |
1679 | esac | |
f53352fb | 1680 | __git_complete_revlist |
690d8824 JH |
1681 | } |
1682 | ||
6d2b06f0 | 1683 | # Common merge options shared by git-merge(1) and git-pull(1). |
0a4e1472 JS |
1684 | __git_merge_options=" |
1685 | --no-commit --no-stat --log --no-log --squash --strategy | |
2ff14e31 | 1686 | --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit |
8fee8726 JK |
1687 | --verify-signatures --no-verify-signatures --gpg-sign |
1688 | --quiet --verbose --progress --no-progress | |
0a4e1472 JS |
1689 | " |
1690 | ||
4ad91321 SP |
1691 | _git_merge () |
1692 | { | |
3c7b480a JS |
1693 | __git_complete_strategy && return |
1694 | ||
4ad91321 SP |
1695 | case "$cur" in |
1696 | --*) | |
8fee8726 | 1697 | __gitcomp "$__git_merge_options |
c261a87e | 1698 | --rerere-autoupdate --no-rerere-autoupdate --abort --continue" |
4ad91321 SP |
1699 | return |
1700 | esac | |
15b4a163 | 1701 | __git_complete_refs |
4ad91321 SP |
1702 | } |
1703 | ||
b4c72162 LM |
1704 | _git_mergetool () |
1705 | { | |
b4c72162 LM |
1706 | case "$cur" in |
1707 | --tool=*) | |
e2dc2de9 | 1708 | __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}" |
b4c72162 LM |
1709 | return |
1710 | ;; | |
1711 | --*) | |
1712 | __gitcomp "--tool=" | |
1713 | return | |
1714 | ;; | |
1715 | esac | |
b4c72162 LM |
1716 | } |
1717 | ||
690d8824 JH |
1718 | _git_merge_base () |
1719 | { | |
85453fd1 JK |
1720 | case "$cur" in |
1721 | --*) | |
1722 | __gitcomp "--octopus --independent --is-ancestor --fork-point" | |
1723 | return | |
1724 | ;; | |
1725 | esac | |
15b4a163 | 1726 | __git_complete_refs |
690d8824 JH |
1727 | } |
1728 | ||
1127c51c LM |
1729 | _git_mv () |
1730 | { | |
1127c51c LM |
1731 | case "$cur" in |
1732 | --*) | |
1733 | __gitcomp "--dry-run" | |
1734 | return | |
1735 | ;; | |
1736 | esac | |
fea16b47 MP |
1737 | |
1738 | if [ $(__git_count_arguments "mv") -gt 0 ]; then | |
1739 | # We need to show both cached and untracked files (including | |
1740 | # empty directories) since this may not be the last argument. | |
1741 | __git_complete_index_file "--cached --others --directory" | |
1742 | else | |
1743 | __git_complete_index_file "--cached" | |
1744 | fi | |
1127c51c LM |
1745 | } |
1746 | ||
d33909bf SP |
1747 | _git_name_rev () |
1748 | { | |
b3391775 | 1749 | __gitcomp "--tags --all --stdin" |
d33909bf SP |
1750 | } |
1751 | ||
00f09d0e SG |
1752 | _git_notes () |
1753 | { | |
2a5da755 SG |
1754 | local subcommands='add append copy edit list prune remove show' |
1755 | local subcommand="$(__git_find_on_cmdline "$subcommands")" | |
00f09d0e | 1756 | |
2a5da755 SG |
1757 | case "$subcommand,$cur" in |
1758 | ,--*) | |
1759 | __gitcomp '--ref' | |
1760 | ;; | |
1761 | ,*) | |
39540681 | 1762 | case "$prev" in |
2a5da755 | 1763 | --ref) |
15b4a163 | 1764 | __git_complete_refs |
2a5da755 SG |
1765 | ;; |
1766 | *) | |
1767 | __gitcomp "$subcommands --ref" | |
1768 | ;; | |
1769 | esac | |
1770 | ;; | |
a8f89bfa | 1771 | add,--reuse-message=*|append,--reuse-message=*|\ |
2a5da755 | 1772 | add,--reedit-message=*|append,--reedit-message=*) |
15b4a163 | 1773 | __git_complete_refs --cur="${cur#*=}" |
2a5da755 SG |
1774 | ;; |
1775 | add,--*|append,--*) | |
1776 | __gitcomp '--file= --message= --reedit-message= | |
1777 | --reuse-message=' | |
1778 | ;; | |
1779 | copy,--*) | |
1780 | __gitcomp '--stdin' | |
1781 | ;; | |
1782 | prune,--*) | |
1783 | __gitcomp '--dry-run --verbose' | |
1784 | ;; | |
1785 | prune,*) | |
00f09d0e SG |
1786 | ;; |
1787 | *) | |
39540681 | 1788 | case "$prev" in |
2a5da755 SG |
1789 | -m|-F) |
1790 | ;; | |
1791 | *) | |
15b4a163 | 1792 | __git_complete_refs |
2a5da755 SG |
1793 | ;; |
1794 | esac | |
00f09d0e SG |
1795 | ;; |
1796 | esac | |
1797 | } | |
1798 | ||
690d8824 JH |
1799 | _git_pull () |
1800 | { | |
0a4e1472 JS |
1801 | __git_complete_strategy && return |
1802 | ||
0a4e1472 | 1803 | case "$cur" in |
4dd5c470 SYS |
1804 | --recurse-submodules=*) |
1805 | __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}" | |
1806 | return | |
1807 | ;; | |
0a4e1472 JS |
1808 | --*) |
1809 | __gitcomp " | |
1810 | --rebase --no-rebase | |
1811 | $__git_merge_options | |
1812 | $__git_fetch_options | |
1813 | " | |
1814 | return | |
1815 | ;; | |
1816 | esac | |
52d5c3b5 | 1817 | __git_complete_remote_or_refspec |
690d8824 JH |
1818 | } |
1819 | ||
4dd5c470 SYS |
1820 | __git_push_recurse_submodules="check on-demand" |
1821 | ||
aaf7253f JK |
1822 | __git_complete_force_with_lease () |
1823 | { | |
1824 | local cur_=$1 | |
1825 | ||
1826 | case "$cur_" in | |
1827 | --*=) | |
1828 | ;; | |
1829 | *:*) | |
15b4a163 | 1830 | __git_complete_refs --cur="${cur_#*:}" |
aaf7253f JK |
1831 | ;; |
1832 | *) | |
15b4a163 | 1833 | __git_complete_refs --cur="$cur_" |
aaf7253f JK |
1834 | ;; |
1835 | esac | |
1836 | } | |
1837 | ||
690d8824 JH |
1838 | _git_push () |
1839 | { | |
da48616f | 1840 | case "$prev" in |
0a4e1472 | 1841 | --repo) |
a31e6262 | 1842 | __gitcomp_nl "$(__git_remotes)" |
0a4e1472 | 1843 | return |
3a224ff2 JK |
1844 | ;; |
1845 | --recurse-submodules) | |
1846 | __gitcomp "$__git_push_recurse_submodules" | |
1847 | return | |
1848 | ;; | |
0a4e1472 JS |
1849 | esac |
1850 | case "$cur" in | |
1851 | --repo=*) | |
a31e6262 | 1852 | __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}" |
0a4e1472 JS |
1853 | return |
1854 | ;; | |
4dd5c470 SYS |
1855 | --recurse-submodules=*) |
1856 | __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}" | |
1857 | return | |
1858 | ;; | |
aaf7253f JK |
1859 | --force-with-lease=*) |
1860 | __git_complete_force_with_lease "${cur##--force-with-lease=}" | |
1861 | return | |
1862 | ;; | |
0a4e1472 JS |
1863 | --*) |
1864 | __gitcomp " | |
1865 | --all --mirror --tags --dry-run --force --verbose | |
9e8a6a94 | 1866 | --quiet --prune --delete --follow-tags |
3623dc03 | 1867 | --receive-pack= --repo= --set-upstream |
aaf7253f | 1868 | --force-with-lease --force-with-lease= --recurse-submodules= |
0a4e1472 JS |
1869 | " |
1870 | return | |
1871 | ;; | |
1872 | esac | |
52d5c3b5 | 1873 | __git_complete_remote_or_refspec |
690d8824 JH |
1874 | } |
1875 | ||
61d926a3 SP |
1876 | _git_rebase () |
1877 | { | |
fad9484f SG |
1878 | __git_find_repo_path |
1879 | if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then | |
9512177b | 1880 | __gitcomp "--continue --skip --abort --quit --edit-todo" |
09bb6520 | 1881 | return |
fad9484f SG |
1882 | elif [ -d "$__git_repo_path"/rebase-apply ] || \ |
1883 | [ -d "$__git_repo_path"/rebase-merge ]; then | |
9512177b | 1884 | __gitcomp "--continue --skip --abort --quit" |
61d926a3 SP |
1885 | return |
1886 | fi | |
3c7b480a | 1887 | __git_complete_strategy && return |
61d926a3 | 1888 | case "$cur" in |
93cf50a4 BG |
1889 | --whitespace=*) |
1890 | __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" | |
1891 | return | |
1892 | ;; | |
61d926a3 | 1893 | --*) |
93cf50a4 BG |
1894 | __gitcomp " |
1895 | --onto --merge --strategy --interactive | |
1896 | --preserve-merges --stat --no-stat | |
1897 | --committer-date-is-author-date --ignore-date | |
1898 | --ignore-whitespace --whitespace= | |
fa4b5e3a JK |
1899 | --autosquash --no-autosquash |
1900 | --fork-point --no-fork-point | |
1901 | --autostash --no-autostash | |
1902 | --verify --no-verify | |
1903 | --keep-empty --root --force-rebase --no-ff | |
1904 | --exec | |
93cf50a4 BG |
1905 | " |
1906 | ||
61d926a3 SP |
1907 | return |
1908 | esac | |
15b4a163 | 1909 | __git_complete_refs |
61d926a3 SP |
1910 | } |
1911 | ||
057f3279 TRC |
1912 | _git_reflog () |
1913 | { | |
1914 | local subcommands="show delete expire" | |
1915 | local subcommand="$(__git_find_on_cmdline "$subcommands")" | |
1916 | ||
1917 | if [ -z "$subcommand" ]; then | |
1918 | __gitcomp "$subcommands" | |
1919 | else | |
15b4a163 | 1920 | __git_complete_refs |
057f3279 TRC |
1921 | fi |
1922 | } | |
1923 | ||
ae616de6 | 1924 | __git_send_email_confirm_options="always never auto cc compose" |
cb8a9bd5 | 1925 | __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all" |
ae616de6 | 1926 | |
25a1f374 TL |
1927 | _git_send_email () |
1928 | { | |
dfbe5eeb JK |
1929 | case "$prev" in |
1930 | --to|--cc|--bcc|--from) | |
e15098a3 | 1931 | __gitcomp "$(__git send-email --dump-aliases)" |
dfbe5eeb JK |
1932 | return |
1933 | ;; | |
1934 | esac | |
1935 | ||
25a1f374 | 1936 | case "$cur" in |
ae616de6 SB |
1937 | --confirm=*) |
1938 | __gitcomp " | |
1939 | $__git_send_email_confirm_options | |
1940 | " "" "${cur##--confirm=}" | |
1941 | return | |
1942 | ;; | |
1943 | --suppress-cc=*) | |
1944 | __gitcomp " | |
1945 | $__git_send_email_suppresscc_options | |
1946 | " "" "${cur##--suppress-cc=}" | |
1947 | ||
1948 | return | |
1949 | ;; | |
1950 | --smtp-encryption=*) | |
1951 | __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}" | |
1952 | return | |
1953 | ;; | |
2f65494d FC |
1954 | --thread=*) |
1955 | __gitcomp " | |
1956 | deep shallow | |
1957 | " "" "${cur##--thread=}" | |
1958 | return | |
1959 | ;; | |
dfbe5eeb | 1960 | --to=*|--cc=*|--bcc=*|--from=*) |
e15098a3 | 1961 | __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}" |
dfbe5eeb JK |
1962 | return |
1963 | ;; | |
25a1f374 | 1964 | --*) |
77813151 | 1965 | __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to |
ae616de6 SB |
1966 | --compose --confirm= --dry-run --envelope-sender |
1967 | --from --identity | |
25a1f374 TL |
1968 | --in-reply-to --no-chain-reply-to --no-signed-off-by-cc |
1969 | --no-suppress-from --no-thread --quiet | |
1970 | --signed-off-by-cc --smtp-pass --smtp-server | |
ae616de6 SB |
1971 | --smtp-server-port --smtp-encryption= --smtp-user |
1972 | --subject --suppress-cc= --suppress-from --thread --to | |
2f65494d FC |
1973 | --validate --no-validate |
1974 | $__git_format_patch_options" | |
25a1f374 TL |
1975 | return |
1976 | ;; | |
1977 | esac | |
2f65494d | 1978 | __git_complete_revlist |
25a1f374 TL |
1979 | } |
1980 | ||
424cce83 SG |
1981 | _git_stage () |
1982 | { | |
1983 | _git_add | |
1984 | } | |
1985 | ||
634d2344 TB |
1986 | _git_status () |
1987 | { | |
1988 | local complete_opt | |
1989 | local untracked_state | |
1990 | ||
1991 | case "$cur" in | |
1992 | --ignore-submodules=*) | |
1993 | __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}" | |
1994 | return | |
1995 | ;; | |
1996 | --untracked-files=*) | |
1997 | __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" | |
1998 | return | |
1999 | ;; | |
2000 | --column=*) | |
2001 | __gitcomp " | |
2002 | always never auto column row plain dense nodense | |
2003 | " "" "${cur##--column=}" | |
2004 | return | |
2005 | ;; | |
2006 | --*) | |
2007 | __gitcomp " | |
2008 | --short --branch --porcelain --long --verbose | |
2009 | --untracked-files= --ignore-submodules= --ignored | |
2010 | --column= --no-column | |
2011 | " | |
2012 | return | |
2013 | ;; | |
2014 | esac | |
2015 | ||
2016 | untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \ | |
2017 | "$__git_untracked_file_modes" "status.showUntrackedFiles")" | |
2018 | ||
2019 | case "$untracked_state" in | |
2020 | no) | |
2021 | # --ignored option does not matter | |
2022 | complete_opt= | |
2023 | ;; | |
2024 | all|normal|*) | |
2025 | complete_opt="--cached --directory --no-empty-directory --others" | |
2026 | ||
2027 | if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then | |
2028 | complete_opt="$complete_opt --ignored --exclude=*" | |
2029 | fi | |
2030 | ;; | |
2031 | esac | |
2032 | ||
2033 | __git_complete_index_file "$complete_opt" | |
2034 | } | |
2035 | ||
00652369 SB |
2036 | __git_config_get_set_variables () |
2037 | { | |
da48616f | 2038 | local prevword word config_file= c=$cword |
00652369 | 2039 | while [ $c -gt 1 ]; do |
da48616f | 2040 | word="${words[c]}" |
00652369 | 2041 | case "$word" in |
66c0786c | 2042 | --system|--global|--local|--file=*) |
00652369 SB |
2043 | config_file="$word" |
2044 | break | |
2045 | ;; | |
2046 | -f|--file) | |
2047 | config_file="$word $prevword" | |
2048 | break | |
2049 | ;; | |
2050 | esac | |
2051 | prevword=$word | |
2052 | c=$((--c)) | |
2053 | done | |
2054 | ||
e15098a3 | 2055 | __git config $config_file --name-only --list |
00652369 SB |
2056 | } |
2057 | ||
e0d10e1c | 2058 | _git_config () |
5de40f59 | 2059 | { |
da48616f | 2060 | case "$prev" in |
72f75077 | 2061 | branch.*.remote|branch.*.pushremote) |
a31e6262 | 2062 | __gitcomp_nl "$(__git_remotes)" |
5de40f59 SP |
2063 | return |
2064 | ;; | |
2065 | branch.*.merge) | |
15b4a163 | 2066 | __git_complete_refs |
5de40f59 SP |
2067 | return |
2068 | ;; | |
a05490ed | 2069 | branch.*.rebase) |
17c4ddbb | 2070 | __gitcomp "false true preserve interactive" |
a05490ed RR |
2071 | return |
2072 | ;; | |
7e6a0cc4 RR |
2073 | remote.pushdefault) |
2074 | __gitcomp_nl "$(__git_remotes)" | |
2075 | return | |
2076 | ;; | |
5de40f59 | 2077 | remote.*.fetch) |
da48616f | 2078 | local remote="${prev#remote.}" |
5de40f59 | 2079 | remote="${remote%.fetch}" |
d51a8ecd | 2080 | if [ -z "$cur" ]; then |
73704451 | 2081 | __gitcomp_nl "refs/heads/" "" "" "" |
d51a8ecd SG |
2082 | return |
2083 | fi | |
a31e6262 | 2084 | __gitcomp_nl "$(__git_refs_remotes "$remote")" |
5de40f59 SP |
2085 | return |
2086 | ;; | |
2087 | remote.*.push) | |
da48616f | 2088 | local remote="${prev#remote.}" |
5de40f59 | 2089 | remote="${remote%.push}" |
3ba04201 | 2090 | __gitcomp_nl "$(__git for-each-ref \ |
1cd23e9e | 2091 | --format='%(refname):%(refname)' refs/heads)" |
78d4d6a2 SP |
2092 | return |
2093 | ;; | |
2094 | pull.twohead|pull.octopus) | |
eaa4e6ee JN |
2095 | __git_compute_merge_strategies |
2096 | __gitcomp "$__git_merge_strategies" | |
78d4d6a2 SP |
2097 | return |
2098 | ;; | |
6123d719 MH |
2099 | color.branch|color.diff|color.interactive|\ |
2100 | color.showbranch|color.status|color.ui) | |
78d4d6a2 SP |
2101 | __gitcomp "always never auto" |
2102 | return | |
2103 | ;; | |
901d615c MK |
2104 | color.pager) |
2105 | __gitcomp "false true" | |
2106 | return | |
2107 | ;; | |
78d4d6a2 SP |
2108 | color.*.*) |
2109 | __gitcomp " | |
98171a07 | 2110 | normal black red green yellow blue magenta cyan white |
78d4d6a2 SP |
2111 | bold dim ul blink reverse |
2112 | " | |
5de40f59 SP |
2113 | return |
2114 | ;; | |
2651baae RR |
2115 | diff.submodule) |
2116 | __gitcomp "log short" | |
2117 | return | |
2118 | ;; | |
9b82d63b SB |
2119 | help.format) |
2120 | __gitcomp "man info web html" | |
2121 | return | |
2122 | ;; | |
672c68cb SB |
2123 | log.date) |
2124 | __gitcomp "$__git_log_date_formats" | |
2125 | return | |
2126 | ;; | |
ae616de6 SB |
2127 | sendemail.aliasesfiletype) |
2128 | __gitcomp "mutt mailrc pine elm gnus" | |
2129 | return | |
2130 | ;; | |
2131 | sendemail.confirm) | |
2132 | __gitcomp "$__git_send_email_confirm_options" | |
2133 | return | |
2134 | ;; | |
2135 | sendemail.suppresscc) | |
2136 | __gitcomp "$__git_send_email_suppresscc_options" | |
2137 | return | |
2138 | ;; | |
8d814084 PB |
2139 | sendemail.transferencoding) |
2140 | __gitcomp "7bit 8bit quoted-printable base64" | |
2141 | return | |
2142 | ;; | |
00652369 | 2143 | --get|--get-all|--unset|--unset-all) |
a31e6262 | 2144 | __gitcomp_nl "$(__git_config_get_set_variables)" |
00652369 SB |
2145 | return |
2146 | ;; | |
5de40f59 | 2147 | *.*) |
5de40f59 SP |
2148 | return |
2149 | ;; | |
2150 | esac | |
2151 | case "$cur" in | |
2152 | --*) | |
78d4d6a2 | 2153 | __gitcomp " |
66c0786c | 2154 | --system --global --local --file= |
12977705 | 2155 | --list --replace-all |
5de40f59 | 2156 | --get --get-all --get-regexp |
1b71eb35 | 2157 | --add --unset --unset-all |
12977705 | 2158 | --remove-section --rename-section |
578625fa | 2159 | --name-only |
78d4d6a2 | 2160 | " |
5de40f59 SP |
2161 | return |
2162 | ;; | |
2163 | branch.*.*) | |
9244d69b | 2164 | local pfx="${cur%.*}." cur_="${cur##*.}" |
72f75077 | 2165 | __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_" |
5de40f59 SP |
2166 | return |
2167 | ;; | |
2168 | branch.*) | |
9244d69b | 2169 | local pfx="${cur%.*}." cur_="${cur#*.}" |
a31e6262 | 2170 | __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "." |
422553df | 2171 | __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_" |
5de40f59 SP |
2172 | return |
2173 | ;; | |
0aa62fd0 | 2174 | guitool.*.*) |
9244d69b | 2175 | local pfx="${cur%.*}." cur_="${cur##*.}" |
0aa62fd0 SB |
2176 | __gitcomp " |
2177 | argprompt cmd confirm needsfile noconsole norescan | |
2178 | prompt revprompt revunmerged title | |
9244d69b | 2179 | " "$pfx" "$cur_" |
0aa62fd0 SB |
2180 | return |
2181 | ;; | |
2182 | difftool.*.*) | |
9244d69b SG |
2183 | local pfx="${cur%.*}." cur_="${cur##*.}" |
2184 | __gitcomp "cmd path" "$pfx" "$cur_" | |
0aa62fd0 SB |
2185 | return |
2186 | ;; | |
2187 | man.*.*) | |
9244d69b SG |
2188 | local pfx="${cur%.*}." cur_="${cur##*.}" |
2189 | __gitcomp "cmd path" "$pfx" "$cur_" | |
0aa62fd0 SB |
2190 | return |
2191 | ;; | |
2192 | mergetool.*.*) | |
9244d69b SG |
2193 | local pfx="${cur%.*}." cur_="${cur##*.}" |
2194 | __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" | |
0aa62fd0 SB |
2195 | return |
2196 | ;; | |
2197 | pager.*) | |
9244d69b | 2198 | local pfx="${cur%.*}." cur_="${cur#*.}" |
eaa4e6ee | 2199 | __git_compute_all_commands |
a31e6262 | 2200 | __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" |
0aa62fd0 SB |
2201 | return |
2202 | ;; | |
5de40f59 | 2203 | remote.*.*) |
9244d69b | 2204 | local pfx="${cur%.*}." cur_="${cur##*.}" |
12977705 | 2205 | __gitcomp " |
98171a07 | 2206 | url proxy fetch push mirror skipDefaultUpdate |
6fac1b83 | 2207 | receivepack uploadpack tagopt pushurl |
9244d69b | 2208 | " "$pfx" "$cur_" |
5de40f59 SP |
2209 | return |
2210 | ;; | |
2211 | remote.*) | |
9244d69b | 2212 | local pfx="${cur%.*}." cur_="${cur#*.}" |
a31e6262 | 2213 | __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." |
c39a2f11 | 2214 | __gitcomp_nl_append "pushdefault" "$pfx" "$cur_" |
5de40f59 SP |
2215 | return |
2216 | ;; | |
0aa62fd0 | 2217 | url.*.*) |
9244d69b SG |
2218 | local pfx="${cur%.*}." cur_="${cur##*.}" |
2219 | __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" | |
0aa62fd0 SB |
2220 | return |
2221 | ;; | |
5de40f59 | 2222 | esac |
78d4d6a2 | 2223 | __gitcomp " |
6068ac88 MZ |
2224 | add.ignoreErrors |
2225 | advice.commitBeforeMerge | |
2226 | advice.detachedHead | |
2227 | advice.implicitIdentity | |
2228 | advice.pushNonFastForward | |
2229 | advice.resolveConflict | |
2230 | advice.statusHints | |
226b343c | 2231 | alias. |
6068ac88 | 2232 | am.keepcr |
86c91f91 | 2233 | apply.ignorewhitespace |
5de40f59 | 2234 | apply.whitespace |
98171a07 LM |
2235 | branch.autosetupmerge |
2236 | branch.autosetuprebase | |
6068ac88 | 2237 | browser. |
2122591b | 2238 | clean.requireForce |
78d4d6a2 SP |
2239 | color.branch |
2240 | color.branch.current | |
2241 | color.branch.local | |
78d4d6a2 | 2242 | color.branch.plain |
025a1929 | 2243 | color.branch.remote |
6068ac88 MZ |
2244 | color.decorate.HEAD |
2245 | color.decorate.branch | |
2246 | color.decorate.remoteBranch | |
2247 | color.decorate.stash | |
2248 | color.decorate.tag | |
a159ca0c | 2249 | color.diff |
025a1929 | 2250 | color.diff.commit |
78d4d6a2 | 2251 | color.diff.frag |
6068ac88 | 2252 | color.diff.func |
025a1929 | 2253 | color.diff.meta |
78d4d6a2 | 2254 | color.diff.new |
025a1929 LM |
2255 | color.diff.old |
2256 | color.diff.plain | |
78d4d6a2 | 2257 | color.diff.whitespace |
226b343c | 2258 | color.grep |
6068ac88 MZ |
2259 | color.grep.context |
2260 | color.grep.filename | |
2261 | color.grep.function | |
2262 | color.grep.linenumber | |
226b343c | 2263 | color.grep.match |
6068ac88 MZ |
2264 | color.grep.selected |
2265 | color.grep.separator | |
98171a07 | 2266 | color.interactive |
6068ac88 | 2267 | color.interactive.error |
98171a07 LM |
2268 | color.interactive.header |
2269 | color.interactive.help | |
2270 | color.interactive.prompt | |
a159ca0c | 2271 | color.pager |
6123d719 | 2272 | color.showbranch |
a159ca0c | 2273 | color.status |
78d4d6a2 SP |
2274 | color.status.added |
2275 | color.status.changed | |
025a1929 | 2276 | color.status.header |
98171a07 | 2277 | color.status.nobranch |
0d6accc0 | 2278 | color.status.unmerged |
78d4d6a2 | 2279 | color.status.untracked |
98171a07 LM |
2280 | color.status.updated |
2281 | color.ui | |
6068ac88 | 2282 | commit.status |
98171a07 | 2283 | commit.template |
cdb791f6 | 2284 | core.abbrev |
6068ac88 MZ |
2285 | core.askpass |
2286 | core.attributesfile | |
98171a07 LM |
2287 | core.autocrlf |
2288 | core.bare | |
6068ac88 | 2289 | core.bigFileThreshold |
025a1929 | 2290 | core.compression |
226b343c | 2291 | core.createObject |
98171a07 LM |
2292 | core.deltaBaseCacheLimit |
2293 | core.editor | |
6068ac88 | 2294 | core.eol |
98171a07 | 2295 | core.excludesfile |
025a1929 | 2296 | core.fileMode |
98171a07 | 2297 | core.fsyncobjectfiles |
025a1929 LM |
2298 | core.gitProxy |
2299 | core.ignoreStat | |
6068ac88 | 2300 | core.ignorecase |
025a1929 LM |
2301 | core.logAllRefUpdates |
2302 | core.loosecompression | |
6068ac88 | 2303 | core.notesRef |
025a1929 LM |
2304 | core.packedGitLimit |
2305 | core.packedGitWindowSize | |
98171a07 | 2306 | core.pager |
025a1929 | 2307 | core.preferSymlinkRefs |
98171a07 LM |
2308 | core.preloadindex |
2309 | core.quotepath | |
025a1929 | 2310 | core.repositoryFormatVersion |
98171a07 | 2311 | core.safecrlf |
025a1929 | 2312 | core.sharedRepository |
6068ac88 | 2313 | core.sparseCheckout |
98171a07 LM |
2314 | core.symlinks |
2315 | core.trustctime | |
435ec090 | 2316 | core.untrackedCache |
025a1929 | 2317 | core.warnAmbiguousRefs |
98171a07 LM |
2318 | core.whitespace |
2319 | core.worktree | |
2320 | diff.autorefreshindex | |
2321 | diff.external | |
6068ac88 | 2322 | diff.ignoreSubmodules |
98171a07 | 2323 | diff.mnemonicprefix |
6068ac88 | 2324 | diff.noprefix |
78d4d6a2 SP |
2325 | diff.renameLimit |
2326 | diff.renames | |
de7c201a | 2327 | diff.statGraphWidth |
2651baae | 2328 | diff.submodule |
226b343c SB |
2329 | diff.suppressBlankEmpty |
2330 | diff.tool | |
2331 | diff.wordRegex | |
07ab4dec | 2332 | diff.algorithm |
0aa62fd0 | 2333 | difftool. |
226b343c | 2334 | difftool.prompt |
6068ac88 | 2335 | fetch.recurseSubmodules |
78d4d6a2 | 2336 | fetch.unpackLimit |
226b343c SB |
2337 | format.attach |
2338 | format.cc | |
de06c13a | 2339 | format.coverLetter |
6bc6b6c0 | 2340 | format.from |
78d4d6a2 | 2341 | format.headers |
98171a07 LM |
2342 | format.numbered |
2343 | format.pretty | |
d8e1e5df | 2344 | format.signature |
226b343c SB |
2345 | format.signoff |
2346 | format.subjectprefix | |
98171a07 | 2347 | format.suffix |
226b343c | 2348 | format.thread |
6068ac88 MZ |
2349 | format.to |
2350 | gc. | |
98171a07 LM |
2351 | gc.aggressiveWindow |
2352 | gc.auto | |
2353 | gc.autopacklimit | |
12977705 | 2354 | gc.packrefs |
98171a07 | 2355 | gc.pruneexpire |
78d4d6a2 SP |
2356 | gc.reflogexpire |
2357 | gc.reflogexpireunreachable | |
2358 | gc.rerereresolved | |
2359 | gc.rerereunresolved | |
025a1929 | 2360 | gitcvs.allbinary |
226b343c | 2361 | gitcvs.commitmsgannotation |
98171a07 | 2362 | gitcvs.dbTableNamePrefix |
025a1929 LM |
2363 | gitcvs.dbdriver |
2364 | gitcvs.dbname | |
2365 | gitcvs.dbpass | |
025a1929 LM |
2366 | gitcvs.dbuser |
2367 | gitcvs.enabled | |
2368 | gitcvs.logfile | |
98171a07 | 2369 | gitcvs.usecrlfattr |
0aa62fd0 | 2370 | guitool. |
98171a07 LM |
2371 | gui.blamehistoryctx |
2372 | gui.commitmsgwidth | |
2373 | gui.copyblamethreshold | |
2374 | gui.diffcontext | |
2375 | gui.encoding | |
2376 | gui.fastcopyblame | |
2377 | gui.matchtrackingbranch | |
2378 | gui.newbranchtemplate | |
2379 | gui.pruneduringfetch | |
2380 | gui.spellingdictionary | |
2381 | gui.trustmtime | |
2382 | help.autocorrect | |
2383 | help.browser | |
2384 | help.format | |
78d4d6a2 SP |
2385 | http.lowSpeedLimit |
2386 | http.lowSpeedTime | |
025a1929 | 2387 | http.maxRequests |
6068ac88 | 2388 | http.minSessions |
5de40f59 | 2389 | http.noEPSV |
6068ac88 | 2390 | http.postBuffer |
98171a07 | 2391 | http.proxy |
f6f2a9e4 | 2392 | http.sslCipherList |
01861cb7 | 2393 | http.sslVersion |
025a1929 LM |
2394 | http.sslCAInfo |
2395 | http.sslCAPath | |
2396 | http.sslCert | |
6068ac88 | 2397 | http.sslCertPasswordProtected |
025a1929 LM |
2398 | http.sslKey |
2399 | http.sslVerify | |
6068ac88 | 2400 | http.useragent |
78d4d6a2 SP |
2401 | i18n.commitEncoding |
2402 | i18n.logOutputEncoding | |
6068ac88 | 2403 | imap.authMethod |
226b343c SB |
2404 | imap.folder |
2405 | imap.host | |
2406 | imap.pass | |
2407 | imap.port | |
2408 | imap.preformattedHTML | |
2409 | imap.sslverify | |
2410 | imap.tunnel | |
2411 | imap.user | |
6068ac88 | 2412 | init.templatedir |
98171a07 LM |
2413 | instaweb.browser |
2414 | instaweb.httpd | |
2415 | instaweb.local | |
2416 | instaweb.modulepath | |
2417 | instaweb.port | |
226b343c | 2418 | interactive.singlekey |
98171a07 | 2419 | log.date |
6068ac88 | 2420 | log.decorate |
78d4d6a2 | 2421 | log.showroot |
226b343c | 2422 | mailmap.file |
0aa62fd0 | 2423 | man. |
98171a07 | 2424 | man.viewer |
6068ac88 | 2425 | merge. |
98171a07 LM |
2426 | merge.conflictstyle |
2427 | merge.log | |
2428 | merge.renameLimit | |
6068ac88 | 2429 | merge.renormalize |
98171a07 | 2430 | merge.stat |
025a1929 | 2431 | merge.tool |
78d4d6a2 | 2432 | merge.verbosity |
0aa62fd0 | 2433 | mergetool. |
98171a07 | 2434 | mergetool.keepBackup |
6068ac88 | 2435 | mergetool.keepTemporaries |
226b343c | 2436 | mergetool.prompt |
6068ac88 MZ |
2437 | notes.displayRef |
2438 | notes.rewrite. | |
2439 | notes.rewrite.amend | |
2440 | notes.rewrite.rebase | |
2441 | notes.rewriteMode | |
2442 | notes.rewriteRef | |
47e98eec | 2443 | pack.compression |
47e98eec | 2444 | pack.deltaCacheLimit |
025a1929 LM |
2445 | pack.deltaCacheSize |
2446 | pack.depth | |
98171a07 LM |
2447 | pack.indexVersion |
2448 | pack.packSizeLimit | |
2449 | pack.threads | |
025a1929 LM |
2450 | pack.window |
2451 | pack.windowMemory | |
0aa62fd0 | 2452 | pager. |
6068ac88 | 2453 | pretty. |
78d4d6a2 SP |
2454 | pull.octopus |
2455 | pull.twohead | |
226b343c | 2456 | push.default |
a8bc269f | 2457 | push.followTags |
6068ac88 | 2458 | rebase.autosquash |
226b343c | 2459 | rebase.stat |
6068ac88 | 2460 | receive.autogc |
98171a07 | 2461 | receive.denyCurrentBranch |
6068ac88 | 2462 | receive.denyDeleteCurrent |
98171a07 | 2463 | receive.denyDeletes |
025a1929 | 2464 | receive.denyNonFastForwards |
98171a07 | 2465 | receive.fsckObjects |
025a1929 | 2466 | receive.unpackLimit |
6068ac88 | 2467 | receive.updateserverinfo |
7e6a0cc4 | 2468 | remote.pushdefault |
6068ac88 | 2469 | remotes. |
98171a07 LM |
2470 | repack.usedeltabaseoffset |
2471 | rerere.autoupdate | |
2472 | rerere.enabled | |
6068ac88 | 2473 | sendemail. |
226b343c | 2474 | sendemail.aliasesfile |
6068ac88 | 2475 | sendemail.aliasfiletype |
226b343c SB |
2476 | sendemail.bcc |
2477 | sendemail.cc | |
2478 | sendemail.cccmd | |
2479 | sendemail.chainreplyto | |
2480 | sendemail.confirm | |
2481 | sendemail.envelopesender | |
6068ac88 MZ |
2482 | sendemail.from |
2483 | sendemail.identity | |
226b343c SB |
2484 | sendemail.multiedit |
2485 | sendemail.signedoffbycc | |
6068ac88 | 2486 | sendemail.smtpdomain |
226b343c SB |
2487 | sendemail.smtpencryption |
2488 | sendemail.smtppass | |
2489 | sendemail.smtpserver | |
6068ac88 | 2490 | sendemail.smtpserveroption |
226b343c SB |
2491 | sendemail.smtpserverport |
2492 | sendemail.smtpuser | |
2493 | sendemail.suppresscc | |
2494 | sendemail.suppressfrom | |
2495 | sendemail.thread | |
2496 | sendemail.to | |
2497 | sendemail.validate | |
78d4d6a2 | 2498 | showbranch.default |
98171a07 LM |
2499 | status.relativePaths |
2500 | status.showUntrackedFiles | |
6068ac88 MZ |
2501 | status.submodulesummary |
2502 | submodule. | |
78d4d6a2 SP |
2503 | tar.umask |
2504 | transfer.unpackLimit | |
0aa62fd0 | 2505 | url. |
78d4d6a2 | 2506 | user.email |
025a1929 | 2507 | user.name |
78d4d6a2 | 2508 | user.signingkey |
98171a07 | 2509 | web.browser |
5de40f59 | 2510 | branch. remote. |
78d4d6a2 | 2511 | " |
5de40f59 SP |
2512 | } |
2513 | ||
88293c67 SP |
2514 | _git_remote () |
2515 | { | |
e17dba8f | 2516 | local subcommands="add rename remove set-head set-branches set-url show prune update" |
918c03c2 | 2517 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
3ff1320d | 2518 | if [ -z "$subcommand" ]; then |
3903c618 | 2519 | __gitcomp "$subcommands" |
88293c67 SP |
2520 | return |
2521 | fi | |
2522 | ||
3ff1320d | 2523 | case "$subcommand" in |
e17dba8f | 2524 | rename|remove|set-url|show|prune) |
a31e6262 | 2525 | __gitcomp_nl "$(__git_remotes)" |
88293c67 | 2526 | ;; |
f1c6ffe6 PJ |
2527 | set-head|set-branches) |
2528 | __git_complete_remote_or_refspec | |
2529 | ;; | |
fb72759b | 2530 | update) |
e8f9e428 | 2531 | __gitcomp "$(__git_get_config_variables "remotes")" |
fb72759b | 2532 | ;; |
88293c67 | 2533 | *) |
88293c67 SP |
2534 | ;; |
2535 | esac | |
2536 | } | |
2537 | ||
e1c1a067 BG |
2538 | _git_replace () |
2539 | { | |
15b4a163 | 2540 | __git_complete_refs |
e1c1a067 BG |
2541 | } |
2542 | ||
67e78c3b SP |
2543 | _git_reset () |
2544 | { | |
d773c631 SG |
2545 | __git_has_doubledash && return |
2546 | ||
b3391775 SP |
2547 | case "$cur" in |
2548 | --*) | |
9f040e95 | 2549 | __gitcomp "--merge --mixed --hard --soft --patch" |
b3391775 SP |
2550 | return |
2551 | ;; | |
2552 | esac | |
15b4a163 | 2553 | __git_complete_refs |
67e78c3b SP |
2554 | } |
2555 | ||
a6c2be24 LM |
2556 | _git_revert () |
2557 | { | |
fad9484f SG |
2558 | __git_find_repo_path |
2559 | if [ -f "$__git_repo_path"/REVERT_HEAD ]; then | |
956352b6 TB |
2560 | __gitcomp "--continue --quit --abort" |
2561 | return | |
2562 | fi | |
a6c2be24 LM |
2563 | case "$cur" in |
2564 | --*) | |
2565 | __gitcomp "--edit --mainline --no-edit --no-commit --signoff" | |
2566 | return | |
2567 | ;; | |
2568 | esac | |
15b4a163 | 2569 | __git_complete_refs |
a6c2be24 LM |
2570 | } |
2571 | ||
08c701d4 LM |
2572 | _git_rm () |
2573 | { | |
08c701d4 LM |
2574 | case "$cur" in |
2575 | --*) | |
2576 | __gitcomp "--cached --dry-run --ignore-unmatch --quiet" | |
2577 | return | |
2578 | ;; | |
2579 | esac | |
fea16b47 MP |
2580 | |
2581 | __git_complete_index_file "--cached" | |
08c701d4 LM |
2582 | } |
2583 | ||
1fd6bec9 SP |
2584 | _git_shortlog () |
2585 | { | |
d773c631 SG |
2586 | __git_has_doubledash && return |
2587 | ||
1fd6bec9 SP |
2588 | case "$cur" in |
2589 | --*) | |
2590 | __gitcomp " | |
a393777e TR |
2591 | $__git_log_common_options |
2592 | $__git_log_shortlog_options | |
1fd6bec9 SP |
2593 | --numbered --summary |
2594 | " | |
2595 | return | |
2596 | ;; | |
2597 | esac | |
2598 | __git_complete_revlist | |
2599 | } | |
2600 | ||
90131924 SP |
2601 | _git_show () |
2602 | { | |
41d8cf7d MH |
2603 | __git_has_doubledash && return |
2604 | ||
90131924 | 2605 | case "$cur" in |
e67d71e5 | 2606 | --pretty=*|--format=*) |
c3898111 | 2607 | __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases) |
e67d71e5 | 2608 | " "" "${cur#*=}" |
72de29c2 TL |
2609 | return |
2610 | ;; | |
07924d4d MP |
2611 | --diff-algorithm=*) |
2612 | __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" | |
2613 | return | |
2614 | ;; | |
ac76fd54 JK |
2615 | --submodule=*) |
2616 | __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" | |
2617 | return | |
2618 | ;; | |
90131924 | 2619 | --*) |
076c3237 | 2620 | __gitcomp "--pretty= --format= --abbrev-commit --oneline |
2ca0b197 | 2621 | --show-signature |
20bf7292 TR |
2622 | $__git_diff_common_options |
2623 | " | |
90131924 SP |
2624 | return |
2625 | ;; | |
2626 | esac | |
5269f7f8 | 2627 | __git_complete_revlist_file |
90131924 SP |
2628 | } |
2629 | ||
2ca880fe TR |
2630 | _git_show_branch () |
2631 | { | |
2ca880fe TR |
2632 | case "$cur" in |
2633 | --*) | |
2634 | __gitcomp " | |
f7c2e1a0 | 2635 | --all --remotes --topo-order --date-order --current --more= |
2ca880fe | 2636 | --list --independent --merge-base --no-name |
6123d719 | 2637 | --color --no-color |
076c3237 | 2638 | --sha1-name --sparse --topics --reflog |
2ca880fe TR |
2639 | " |
2640 | return | |
2641 | ;; | |
2642 | esac | |
2643 | __git_complete_revlist | |
2644 | } | |
2645 | ||
7fd53fce JH |
2646 | _git_stash () |
2647 | { | |
d7d4ca87 | 2648 | local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked' |
95d43780 | 2649 | local subcommands='save list show apply clear drop pop create branch' |
918c03c2 | 2650 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
7bedebca | 2651 | if [ -z "$subcommand" ]; then |
59d5eeee SG |
2652 | case "$cur" in |
2653 | --*) | |
2654 | __gitcomp "$save_opts" | |
2655 | ;; | |
2656 | *) | |
2657 | if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then | |
2658 | __gitcomp "$subcommands" | |
59d5eeee SG |
2659 | fi |
2660 | ;; | |
2661 | esac | |
7bedebca | 2662 | else |
7bedebca SG |
2663 | case "$subcommand,$cur" in |
2664 | save,--*) | |
59d5eeee | 2665 | __gitcomp "$save_opts" |
7bedebca | 2666 | ;; |
8513c54b | 2667 | apply,--*|pop,--*) |
59d5eeee | 2668 | __gitcomp "--index --quiet" |
95d43780 | 2669 | ;; |
d7d4ca87 PW |
2670 | drop,--*) |
2671 | __gitcomp "--quiet" | |
95d43780 | 2672 | ;; |
d7d4ca87 PW |
2673 | show,--*|branch,--*) |
2674 | ;; | |
2675 | branch,*) | |
59305aee | 2676 | if [ $cword -eq 3 ]; then |
15b4a163 | 2677 | __git_complete_refs |
d7d4ca87 | 2678 | else |
1cd23e9e | 2679 | __gitcomp_nl "$(__git stash list \ |
d7d4ca87 PW |
2680 | | sed -n -e 's/:.*//p')" |
2681 | fi | |
2682 | ;; | |
2683 | show,*|apply,*|drop,*|pop,*) | |
1cd23e9e | 2684 | __gitcomp_nl "$(__git stash list \ |
95d43780 LM |
2685 | | sed -n -e 's/:.*//p')" |
2686 | ;; | |
7bedebca | 2687 | *) |
7bedebca SG |
2688 | ;; |
2689 | esac | |
3ff1320d | 2690 | fi |
7fd53fce JH |
2691 | } |
2692 | ||
be86f7a0 SP |
2693 | _git_submodule () |
2694 | { | |
d773c631 SG |
2695 | __git_has_doubledash && return |
2696 | ||
cf419828 | 2697 | local subcommands="add status init deinit update summary foreach sync" |
918c03c2 | 2698 | if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then |
be86f7a0 SP |
2699 | case "$cur" in |
2700 | --*) | |
2701 | __gitcomp "--quiet --cached" | |
2702 | ;; | |
2703 | *) | |
3ff1320d | 2704 | __gitcomp "$subcommands" |
be86f7a0 SP |
2705 | ;; |
2706 | esac | |
2707 | return | |
2708 | fi | |
2709 | } | |
2710 | ||
47f6ee28 SG |
2711 | _git_svn () |
2712 | { | |
2713 | local subcommands=" | |
2714 | init fetch clone rebase dcommit log find-rev | |
2715 | set-tree commit-diff info create-ignore propget | |
4a5856cb | 2716 | proplist show-ignore show-externals branch tag blame |
c18d5d82 | 2717 | migrate mkdirs reset gc |
47f6ee28 | 2718 | " |
918c03c2 | 2719 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
47f6ee28 SG |
2720 | if [ -z "$subcommand" ]; then |
2721 | __gitcomp "$subcommands" | |
2722 | else | |
2723 | local remote_opts="--username= --config-dir= --no-auth-cache" | |
2724 | local fc_opts=" | |
2725 | --follow-parent --authors-file= --repack= | |
2726 | --no-metadata --use-svm-props --use-svnsync-props | |
2727 | --log-window-size= --no-checkout --quiet | |
4a5856cb | 2728 | --repack-flags --use-log-author --localtime |
a7b10230 | 2729 | --ignore-paths= --include-paths= $remote_opts |
47f6ee28 SG |
2730 | " |
2731 | local init_opts=" | |
2732 | --template= --shared= --trunk= --tags= | |
2733 | --branches= --stdlayout --minimize-url | |
2734 | --no-metadata --use-svm-props --use-svnsync-props | |
4a5856cb SG |
2735 | --rewrite-root= --prefix= --use-log-author |
2736 | --add-author-from $remote_opts | |
47f6ee28 SG |
2737 | " |
2738 | local cmt_opts=" | |
2739 | --edit --rmdir --find-copies-harder --copy-similarity= | |
2740 | " | |
2741 | ||
47f6ee28 SG |
2742 | case "$subcommand,$cur" in |
2743 | fetch,--*) | |
2744 | __gitcomp "--revision= --fetch-all $fc_opts" | |
2745 | ;; | |
2746 | clone,--*) | |
2747 | __gitcomp "--revision= $fc_opts $init_opts" | |
2748 | ;; | |
2749 | init,--*) | |
2750 | __gitcomp "$init_opts" | |
2751 | ;; | |
2752 | dcommit,--*) | |
2753 | __gitcomp " | |
2754 | --merge --strategy= --verbose --dry-run | |
4a5856cb | 2755 | --fetch-all --no-rebase --commit-url |
7b151f49 | 2756 | --revision --interactive $cmt_opts $fc_opts |
47f6ee28 SG |
2757 | " |
2758 | ;; | |
2759 | set-tree,--*) | |
2760 | __gitcomp "--stdin $cmt_opts $fc_opts" | |
2761 | ;; | |
2762 | create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\ | |
c18d5d82 | 2763 | show-externals,--*|mkdirs,--*) |
47f6ee28 SG |
2764 | __gitcomp "--revision=" |
2765 | ;; | |
2766 | log,--*) | |
2767 | __gitcomp " | |
2768 | --limit= --revision= --verbose --incremental | |
2769 | --oneline --show-commit --non-recursive | |
4a5856cb | 2770 | --authors-file= --color |
47f6ee28 SG |
2771 | " |
2772 | ;; | |
2773 | rebase,--*) | |
2774 | __gitcomp " | |
2775 | --merge --verbose --strategy= --local | |
4a5856cb | 2776 | --fetch-all --dry-run $fc_opts |
47f6ee28 SG |
2777 | " |
2778 | ;; | |
2779 | commit-diff,--*) | |
2780 | __gitcomp "--message= --file= --revision= $cmt_opts" | |
2781 | ;; | |
2782 | info,--*) | |
2783 | __gitcomp "--url" | |
2784 | ;; | |
4a5856cb SG |
2785 | branch,--*) |
2786 | __gitcomp "--dry-run --message --tag" | |
2787 | ;; | |
2788 | tag,--*) | |
2789 | __gitcomp "--dry-run --message" | |
2790 | ;; | |
2791 | blame,--*) | |
2792 | __gitcomp "--git-format" | |
2793 | ;; | |
2794 | migrate,--*) | |
2795 | __gitcomp " | |
2796 | --config-dir= --ignore-paths= --minimize | |
2797 | --no-auth-cache --username= | |
2798 | " | |
2799 | ;; | |
c18d5d82 RZ |
2800 | reset,--*) |
2801 | __gitcomp "--revision= --parent" | |
2802 | ;; | |
47f6ee28 | 2803 | *) |
47f6ee28 SG |
2804 | ;; |
2805 | esac | |
2806 | fi | |
2807 | } | |
2808 | ||
88e21dc7 SP |
2809 | _git_tag () |
2810 | { | |
2811 | local i c=1 f=0 | |
da48616f PD |
2812 | while [ $c -lt $cword ]; do |
2813 | i="${words[c]}" | |
88e21dc7 SP |
2814 | case "$i" in |
2815 | -d|-v) | |
a31e6262 | 2816 | __gitcomp_nl "$(__git_tags)" |
88e21dc7 SP |
2817 | return |
2818 | ;; | |
2819 | -f) | |
2820 | f=1 | |
2821 | ;; | |
2822 | esac | |
6e8c755f | 2823 | ((c++)) |
88e21dc7 SP |
2824 | done |
2825 | ||
da48616f | 2826 | case "$prev" in |
88e21dc7 | 2827 | -m|-F) |
88e21dc7 | 2828 | ;; |
8d8163f3 | 2829 | -*|tag) |
88e21dc7 | 2830 | if [ $f = 1 ]; then |
a31e6262 | 2831 | __gitcomp_nl "$(__git_tags)" |
88e21dc7 SP |
2832 | fi |
2833 | ;; | |
2834 | *) | |
15b4a163 | 2835 | __git_complete_refs |
88e21dc7 SP |
2836 | ;; |
2837 | esac | |
85ed2f32 RT |
2838 | |
2839 | case "$cur" in | |
2840 | --*) | |
2841 | __gitcomp " | |
2842 | --list --delete --verify --annotate --message --file | |
2843 | --sign --cleanup --local-user --force --column --sort | |
2844 | --contains --points-at | |
2845 | " | |
2846 | ;; | |
2847 | esac | |
88e21dc7 SP |
2848 | } |
2849 | ||
424cce83 SG |
2850 | _git_whatchanged () |
2851 | { | |
2852 | _git_log | |
2853 | } | |
2854 | ||
b462c024 NTND |
2855 | _git_worktree () |
2856 | { | |
6d308627 | 2857 | local subcommands="add list lock prune unlock" |
b462c024 NTND |
2858 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
2859 | if [ -z "$subcommand" ]; then | |
2860 | __gitcomp "$subcommands" | |
2861 | else | |
2862 | case "$subcommand,$cur" in | |
2863 | add,--*) | |
2864 | __gitcomp "--detach" | |
2865 | ;; | |
2866 | list,--*) | |
2867 | __gitcomp "--porcelain" | |
2868 | ;; | |
58142c09 NTND |
2869 | lock,--*) |
2870 | __gitcomp "--reason" | |
2871 | ;; | |
b462c024 NTND |
2872 | prune,--*) |
2873 | __gitcomp "--dry-run --expire --verbose" | |
2874 | ;; | |
2875 | *) | |
2876 | ;; | |
2877 | esac | |
2878 | fi | |
2879 | } | |
2880 | ||
93b291e0 | 2881 | __git_main () |
690d8824 | 2882 | { |
beb6ee71 | 2883 | local i c=1 command __git_dir __git_repo_path |
80ac0744 | 2884 | local __git_C_args C_args_count=0 |
873537fa | 2885 | |
da48616f PD |
2886 | while [ $c -lt $cword ]; do |
2887 | i="${words[c]}" | |
873537fa SP |
2888 | case "$i" in |
2889 | --git-dir=*) __git_dir="${i#--git-dir=}" ;; | |
776009d1 | 2890 | --git-dir) ((c++)) ; __git_dir="${words[c]}" ;; |
873537fa | 2891 | --bare) __git_dir="." ;; |
1eb7e2f8 | 2892 | --help) command="help"; break ;; |
80ac0744 SG |
2893 | -c|--work-tree|--namespace) ((c++)) ;; |
2894 | -C) __git_C_args[C_args_count++]=-C | |
2895 | ((c++)) | |
2896 | __git_C_args[C_args_count++]="${words[c]}" | |
2897 | ;; | |
911d5da6 | 2898 | -*) ;; |
873537fa SP |
2899 | *) command="$i"; break ;; |
2900 | esac | |
6e8c755f | 2901 | ((c++)) |
873537fa SP |
2902 | done |
2903 | ||
1d17b22e | 2904 | if [ -z "$command" ]; then |
7b329b9d SG |
2905 | case "$prev" in |
2906 | --git-dir|-C|--work-tree) | |
2907 | # these need a path argument, let's fall back to | |
2908 | # Bash filename completion | |
2909 | return | |
2910 | ;; | |
2911 | -c|--namespace) | |
2912 | # we don't support completing these options' arguments | |
2913 | return | |
2914 | ;; | |
2915 | esac | |
da48616f | 2916 | case "$cur" in |
47e98eec | 2917 | --*) __gitcomp " |
ce5a2c95 | 2918 | --paginate |
47e98eec SP |
2919 | --no-pager |
2920 | --git-dir= | |
2921 | --bare | |
2922 | --version | |
2923 | --exec-path | |
3ffcd086 | 2924 | --exec-path= |
89a56bfb | 2925 | --html-path |
66fb37d0 | 2926 | --man-path |
69ef3c02 | 2927 | --info-path |
ce5a2c95 | 2928 | --work-tree= |
a1bea2c1 | 2929 | --namespace= |
69ef3c02 | 2930 | --no-replace-objects |
ce5a2c95 | 2931 | --help |
47e98eec SP |
2932 | " |
2933 | ;; | |
eaa4e6ee JN |
2934 | *) __git_compute_porcelain_commands |
2935 | __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;; | |
72e5e989 SP |
2936 | esac |
2937 | return | |
873537fa | 2938 | fi |
367dce2a | 2939 | |
424cce83 | 2940 | local completion_func="_git_${command//-/_}" |
336d694c | 2941 | declare -f $completion_func >/dev/null 2>/dev/null && $completion_func && return |
8024ea60 | 2942 | |
873537fa | 2943 | local expansion=$(__git_aliased_command "$command") |
8024ea60 | 2944 | if [ -n "$expansion" ]; then |
880111c1 | 2945 | words[1]=$expansion |
8024ea60 | 2946 | completion_func="_git_${expansion//-/_}" |
336d694c | 2947 | declare -f $completion_func >/dev/null 2>/dev/null && $completion_func |
8024ea60 | 2948 | fi |
690d8824 JH |
2949 | } |
2950 | ||
93b291e0 | 2951 | __gitk_main () |
690d8824 | 2952 | { |
d773c631 SG |
2953 | __git_has_doubledash && return |
2954 | ||
beb6ee71 | 2955 | local __git_repo_path |
fad9484f SG |
2956 | __git_find_repo_path |
2957 | ||
07ba53f7 | 2958 | local merge="" |
fad9484f | 2959 | if [ -f "$__git_repo_path/MERGE_HEAD" ]; then |
07ba53f7 RQ |
2960 | merge="--merge" |
2961 | fi | |
b3391775 SP |
2962 | case "$cur" in |
2963 | --*) | |
a393777e TR |
2964 | __gitcomp " |
2965 | $__git_log_common_options | |
2966 | $__git_log_gitk_options | |
2967 | $merge | |
2968 | " | |
b3391775 SP |
2969 | return |
2970 | ;; | |
2971 | esac | |
ec804891 | 2972 | __git_complete_revlist |
690d8824 JH |
2973 | } |
2974 | ||
d8b45314 FC |
2975 | if [[ -n ${ZSH_VERSION-} ]]; then |
2976 | echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2 | |
6b179adf | 2977 | |
9cd67bd2 FC |
2978 | autoload -U +X compinit && compinit |
2979 | ||
d8b45314 FC |
2980 | __gitcomp () |
2981 | { | |
2982 | emulate -L zsh | |
6b179adf | 2983 | |
d8b45314 FC |
2984 | local cur_="${3-$cur}" |
2985 | ||
2986 | case "$cur_" in | |
2987 | --*=) | |
2988 | ;; | |
2989 | *) | |
2990 | local c IFS=$' \t\n' | |
2991 | local -a array | |
2992 | for c in ${=1}; do | |
2993 | c="$c${4-}" | |
2994 | case $c in | |
2995 | --*=*|*.) ;; | |
2996 | *) c="$c " ;; | |
2997 | esac | |
5d5812f4 | 2998 | array[${#array[@]}+1]="$c" |
d8b45314 FC |
2999 | done |
3000 | compset -P '*[=:]' | |
3001 | compadd -Q -S '' -p "${2-}" -a -- array && _ret=0 | |
3002 | ;; | |
3003 | esac | |
3004 | } | |
3005 | ||
3006 | __gitcomp_nl () | |
3007 | { | |
3008 | emulate -L zsh | |
3009 | ||
3010 | local IFS=$'\n' | |
3011 | compset -P '*[=:]' | |
3012 | compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 | |
3013 | } | |
3014 | ||
fea16b47 MP |
3015 | __gitcomp_file () |
3016 | { | |
3017 | emulate -L zsh | |
3018 | ||
3019 | local IFS=$'\n' | |
3020 | compset -P '*[=:]' | |
3021 | compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 | |
3022 | } | |
3023 | ||
d8b45314 FC |
3024 | _git () |
3025 | { | |
2bcf694b FC |
3026 | local _ret=1 cur cword prev |
3027 | cur=${words[CURRENT]} | |
3028 | prev=${words[CURRENT-1]} | |
3029 | let cword=CURRENT-1 | |
3030 | emulate ksh -c __${service}_main | |
734b2f05 | 3031 | let _ret && _default && _ret=0 |
d8b45314 FC |
3032 | return _ret |
3033 | } | |
3034 | ||
3035 | compdef _git git gitk | |
3036 | return | |
3037 | fi | |
3038 | ||
3039 | __git_func_wrap () | |
3040 | { | |
6b179adf FC |
3041 | local cur words cword prev |
3042 | _get_comp_words_by_ref -n =: cur words cword prev | |
3043 | $1 | |
3044 | } | |
3045 | ||
3046 | # Setup completion for certain functions defined above by setting common | |
3047 | # variables and workarounds. | |
3048 | # This is NOT a public function; use at your own risk. | |
3049 | __git_complete () | |
3050 | { | |
3051 | local wrapper="__git_wrap${2}" | |
3052 | eval "$wrapper () { __git_func_wrap $2 ; }" | |
3053 | complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \ | |
3054 | || complete -o default -o nospace -F $wrapper $1 | |
3055 | } | |
3056 | ||
b0a4b2d2 FC |
3057 | # wrapper for backwards compatibility |
3058 | _git () | |
3059 | { | |
93b291e0 | 3060 | __git_wrap__git_main |
b0a4b2d2 FC |
3061 | } |
3062 | ||
3063 | # wrapper for backwards compatibility | |
3064 | _gitk () | |
3065 | { | |
93b291e0 | 3066 | __git_wrap__gitk_main |
b0a4b2d2 FC |
3067 | } |
3068 | ||
93b291e0 SG |
3069 | __git_complete git __git_main |
3070 | __git_complete gitk __gitk_main | |
690d8824 JH |
3071 | |
3072 | # The following are necessary only for Cygwin, and only are needed | |
3073 | # when the user has tab-completed the executable name and consequently | |
3074 | # included the '.exe' suffix. | |
3075 | # | |
76c3eb51 | 3076 | if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then |
93b291e0 | 3077 | __git_complete git.exe __git_main |
76c3eb51 | 3078 | fi |