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