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