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