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