]>
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 | ls-files) : plumbing;; |
675 | ls-remote) : plumbing;; | |
676 | ls-tree) : plumbing;; | |
f2bb9f88 SP |
677 | mailinfo) : plumbing;; |
678 | mailsplit) : plumbing;; | |
679 | merge-*) : plumbing;; | |
680 | mktree) : plumbing;; | |
681 | mktag) : plumbing;; | |
682 | pack-objects) : plumbing;; | |
683 | pack-redundant) : plumbing;; | |
684 | pack-refs) : plumbing;; | |
685 | parse-remote) : plumbing;; | |
686 | patch-id) : plumbing;; | |
a925c6f1 SP |
687 | prune) : plumbing;; |
688 | prune-packed) : plumbing;; | |
689 | quiltimport) : import;; | |
f2bb9f88 SP |
690 | read-tree) : plumbing;; |
691 | receive-pack) : plumbing;; | |
63d04a78 | 692 | remote-*) : transport;; |
f2bb9f88 SP |
693 | rerere) : plumbing;; |
694 | rev-list) : plumbing;; | |
695 | rev-parse) : plumbing;; | |
696 | runstatus) : plumbing;; | |
697 | sh-setup) : internal;; | |
698 | shell) : daemon;; | |
ff2549dc | 699 | show-ref) : plumbing;; |
f2bb9f88 SP |
700 | send-pack) : plumbing;; |
701 | show-index) : plumbing;; | |
702 | ssh-*) : transport;; | |
703 | stripspace) : plumbing;; | |
704 | symbolic-ref) : plumbing;; | |
705 | unpack-file) : plumbing;; | |
706 | unpack-objects) : plumbing;; | |
a925c6f1 | 707 | update-index) : plumbing;; |
f2bb9f88 SP |
708 | update-ref) : plumbing;; |
709 | update-server-info) : daemon;; | |
710 | upload-archive) : plumbing;; | |
711 | upload-pack) : plumbing;; | |
712 | write-tree) : plumbing;; | |
ff2549dc PB |
713 | var) : infrequent;; |
714 | verify-pack) : infrequent;; | |
a925c6f1 | 715 | verify-tag) : plumbing;; |
f2bb9f88 SP |
716 | *) echo $i;; |
717 | esac | |
718 | done | |
719 | } | |
eaa4e6ee JN |
720 | |
721 | __git_porcelain_commands= | |
722 | __git_compute_porcelain_commands () | |
723 | { | |
724 | __git_compute_all_commands | |
cf0ff02a FC |
725 | test -n "$__git_porcelain_commands" || |
726 | __git_porcelain_commands=$(__git_list_porcelain_commands) | |
eaa4e6ee | 727 | } |
f2bb9f88 | 728 | |
c3898111 SG |
729 | __git_pretty_aliases () |
730 | { | |
731 | local i IFS=$'\n' | |
732 | for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do | |
733 | case "$i" in | |
734 | pretty.*) | |
735 | i="${i#pretty.}" | |
736 | echo "${i/ */}" | |
737 | ;; | |
738 | esac | |
739 | done | |
740 | } | |
741 | ||
367dce2a DS |
742 | __git_aliases () |
743 | { | |
56fc25f2 | 744 | local i IFS=$'\n' |
518ef8f0 | 745 | for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do |
e0d78059 SB |
746 | case "$i" in |
747 | alias.*) | |
748 | i="${i#alias.}" | |
749 | echo "${i/ */}" | |
750 | ;; | |
751 | esac | |
56fc25f2 | 752 | done |
367dce2a DS |
753 | } |
754 | ||
a42577d4 | 755 | # __git_aliased_command requires 1 argument |
367dce2a DS |
756 | __git_aliased_command () |
757 | { | |
873537fa | 758 | local word cmdline=$(git --git-dir="$(__gitdir)" \ |
e0d10e1c | 759 | config --get "alias.$1") |
367dce2a | 760 | for word in $cmdline; do |
c63437cb | 761 | case "$word" in |
66729509 SG |
762 | \!gitk|gitk) |
763 | echo "gitk" | |
367dce2a | 764 | return |
66729509 | 765 | ;; |
c63437cb SG |
766 | \!*) : shell command alias ;; |
767 | -*) : option ;; | |
768 | *=*) : setting env ;; | |
769 | git) : git itself ;; | |
770 | *) | |
771 | echo "$word" | |
367dce2a | 772 | return |
c63437cb | 773 | esac |
367dce2a DS |
774 | done |
775 | } | |
776 | ||
918c03c2 SG |
777 | # __git_find_on_cmdline requires 1 argument |
778 | __git_find_on_cmdline () | |
3ff1320d | 779 | { |
da4902a7 | 780 | local word subcommand c=1 |
da48616f PD |
781 | while [ $c -lt $cword ]; do |
782 | word="${words[c]}" | |
3ff1320d SG |
783 | for subcommand in $1; do |
784 | if [ "$subcommand" = "$word" ]; then | |
785 | echo "$subcommand" | |
786 | return | |
787 | fi | |
788 | done | |
6e8c755f | 789 | ((c++)) |
3ff1320d SG |
790 | done |
791 | } | |
792 | ||
d773c631 SG |
793 | __git_has_doubledash () |
794 | { | |
da4902a7 | 795 | local c=1 |
da48616f PD |
796 | while [ $c -lt $cword ]; do |
797 | if [ "--" = "${words[c]}" ]; then | |
d773c631 SG |
798 | return 0 |
799 | fi | |
6e8c755f | 800 | ((c++)) |
d773c631 SG |
801 | done |
802 | return 1 | |
803 | } | |
804 | ||
fea16b47 MP |
805 | # Try to count non option arguments passed on the command line for the |
806 | # specified git command. | |
807 | # When options are used, it is necessary to use the special -- option to | |
808 | # tell the implementation were non option arguments begin. | |
809 | # XXX this can not be improved, since options can appear everywhere, as | |
810 | # an example: | |
811 | # git mv x -n y | |
812 | # | |
813 | # __git_count_arguments requires 1 argument: the git command executed. | |
814 | __git_count_arguments () | |
815 | { | |
816 | local word i c=0 | |
817 | ||
818 | # Skip "git" (first argument) | |
819 | for ((i=1; i < ${#words[@]}; i++)); do | |
820 | word="${words[i]}" | |
821 | ||
822 | case "$word" in | |
823 | --) | |
824 | # Good; we can assume that the following are only non | |
825 | # option arguments. | |
826 | ((c = 0)) | |
827 | ;; | |
828 | "$1") | |
829 | # Skip the specified git command and discard git | |
830 | # main options | |
831 | ((c = 0)) | |
832 | ;; | |
833 | ?*) | |
834 | ((c++)) | |
835 | ;; | |
836 | esac | |
837 | done | |
838 | ||
839 | printf "%d" $c | |
840 | } | |
841 | ||
7950659d | 842 | __git_whitespacelist="nowarn warn error error-all fix" |
88329195 SP |
843 | |
844 | _git_am () | |
845 | { | |
da4902a7 | 846 | local dir="$(__gitdir)" |
51ef1daa | 847 | if [ -d "$dir"/rebase-apply ]; then |
85f6b439 | 848 | __gitcomp "--skip --continue --resolved --abort" |
88329195 SP |
849 | return |
850 | fi | |
851 | case "$cur" in | |
852 | --whitespace=*) | |
b3391775 | 853 | __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" |
88329195 SP |
854 | return |
855 | ;; | |
856 | --*) | |
b3391775 | 857 | __gitcomp " |
43acdf24 | 858 | --3way --committer-date-is-author-date --ignore-date |
86c91f91 | 859 | --ignore-whitespace --ignore-space-change |
43acdf24 | 860 | --interactive --keep --no-utf8 --signoff --utf8 |
af4e9e8c | 861 | --whitespace= --scissors |
b3391775 | 862 | " |
88329195 SP |
863 | return |
864 | esac | |
88329195 SP |
865 | } |
866 | ||
867 | _git_apply () | |
868 | { | |
88329195 SP |
869 | case "$cur" in |
870 | --whitespace=*) | |
b3391775 | 871 | __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" |
88329195 SP |
872 | return |
873 | ;; | |
874 | --*) | |
b3391775 | 875 | __gitcomp " |
88329195 SP |
876 | --stat --numstat --summary --check --index |
877 | --cached --index-info --reverse --reject --unidiff-zero | |
878 | --apply --no-add --exclude= | |
86c91f91 | 879 | --ignore-whitespace --ignore-space-change |
88329195 | 880 | --whitespace= --inaccurate-eof --verbose |
b3391775 | 881 | " |
88329195 SP |
882 | return |
883 | esac | |
88329195 SP |
884 | } |
885 | ||
8435b548 SP |
886 | _git_add () |
887 | { | |
8435b548 SP |
888 | case "$cur" in |
889 | --*) | |
1d284cba SG |
890 | __gitcomp " |
891 | --interactive --refresh --patch --update --dry-run | |
c9a114b5 | 892 | --ignore-errors --intent-to-add |
1d284cba | 893 | " |
8435b548 SP |
894 | return |
895 | esac | |
fea16b47 MP |
896 | |
897 | # XXX should we check for --update and --all options ? | |
ea95c7b8 | 898 | __git_complete_index_file "--others --modified --directory --no-empty-directory" |
8435b548 SP |
899 | } |
900 | ||
b3191ce2 LM |
901 | _git_archive () |
902 | { | |
b3191ce2 LM |
903 | case "$cur" in |
904 | --format=*) | |
905 | __gitcomp "$(git archive --list)" "" "${cur##--format=}" | |
906 | return | |
907 | ;; | |
908 | --remote=*) | |
a31e6262 | 909 | __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}" |
b3191ce2 LM |
910 | return |
911 | ;; | |
912 | --*) | |
913 | __gitcomp " | |
914 | --format= --list --verbose | |
915 | --prefix= --remote= --exec= | |
916 | " | |
917 | return | |
918 | ;; | |
919 | esac | |
920 | __git_complete_file | |
921 | } | |
922 | ||
b2e69f62 SP |
923 | _git_bisect () |
924 | { | |
d773c631 SG |
925 | __git_has_doubledash && return |
926 | ||
bf11d461 | 927 | local subcommands="start bad good skip reset visualize replay log run" |
918c03c2 | 928 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
3ff1320d | 929 | if [ -z "$subcommand" ]; then |
128191f5 SG |
930 | if [ -f "$(__gitdir)"/BISECT_START ]; then |
931 | __gitcomp "$subcommands" | |
932 | else | |
933 | __gitcomp "replay start" | |
934 | fi | |
b2e69f62 SP |
935 | return |
936 | fi | |
937 | ||
3ff1320d | 938 | case "$subcommand" in |
8205ff8e | 939 | bad|good|reset|skip|start) |
a31e6262 | 940 | __gitcomp_nl "$(__git_refs)" |
b2e69f62 SP |
941 | ;; |
942 | *) | |
b2e69f62 SP |
943 | ;; |
944 | esac | |
945 | } | |
946 | ||
690d8824 JH |
947 | _git_branch () |
948 | { | |
da4902a7 | 949 | local i c=1 only_local_ref="n" has_r="n" |
b9217642 | 950 | |
da48616f PD |
951 | while [ $c -lt $cword ]; do |
952 | i="${words[c]}" | |
b9217642 SG |
953 | case "$i" in |
954 | -d|-m) only_local_ref="y" ;; | |
955 | -r) has_r="y" ;; | |
956 | esac | |
6e8c755f | 957 | ((c++)) |
b9217642 SG |
958 | done |
959 | ||
da48616f | 960 | case "$cur" in |
ca45d0fa MG |
961 | --set-upstream-to=*) |
962 | __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}" | |
963 | ;; | |
3b376b0c SG |
964 | --*) |
965 | __gitcomp " | |
966 | --color --no-color --verbose --abbrev= --no-abbrev | |
50e61025 | 967 | --track --no-track --contains --merged --no-merged |
04308e9d CMN |
968 | --set-upstream-to= --edit-description --list |
969 | --unset-upstream | |
3b376b0c SG |
970 | " |
971 | ;; | |
b9217642 SG |
972 | *) |
973 | if [ $only_local_ref = "y" -a $has_r = "n" ]; then | |
a31e6262 | 974 | __gitcomp_nl "$(__git_heads)" |
b9217642 | 975 | else |
a31e6262 | 976 | __gitcomp_nl "$(__git_refs)" |
b9217642 SG |
977 | fi |
978 | ;; | |
3b376b0c | 979 | esac |
690d8824 JH |
980 | } |
981 | ||
374a58c9 ML |
982 | _git_bundle () |
983 | { | |
da48616f PD |
984 | local cmd="${words[2]}" |
985 | case "$cword" in | |
8d8163f3 | 986 | 2) |
374a58c9 ML |
987 | __gitcomp "create list-heads verify unbundle" |
988 | ;; | |
8d8163f3 | 989 | 3) |
374a58c9 ML |
990 | # looking for a file |
991 | ;; | |
992 | *) | |
993 | case "$cmd" in | |
994 | create) | |
995 | __git_complete_revlist | |
996 | ;; | |
997 | esac | |
998 | ;; | |
999 | esac | |
1000 | } | |
1001 | ||
690d8824 JH |
1002 | _git_checkout () |
1003 | { | |
c84bb14c SG |
1004 | __git_has_doubledash && return |
1005 | ||
e648f8b6 SG |
1006 | case "$cur" in |
1007 | --conflict=*) | |
1008 | __gitcomp "diff3 merge" "" "${cur##--conflict=}" | |
1009 | ;; | |
1010 | --*) | |
1011 | __gitcomp " | |
1012 | --quiet --ours --theirs --track --no-track --merge | |
86e8e7a5 | 1013 | --conflict= --orphan --patch |
e648f8b6 SG |
1014 | " |
1015 | ;; | |
1016 | *) | |
34a6bbb5 KB |
1017 | # check if --track, --no-track, or --no-guess was specified |
1018 | # if so, disable DWIM mode | |
1019 | local flags="--track --no-track --no-guess" track=1 | |
1020 | if [ -n "$(__git_find_on_cmdline "$flags")" ]; then | |
1021 | track='' | |
1022 | fi | |
a31e6262 | 1023 | __gitcomp_nl "$(__git_refs '' $track)" |
e648f8b6 SG |
1024 | ;; |
1025 | esac | |
690d8824 JH |
1026 | } |
1027 | ||
d8a9fea5 SP |
1028 | _git_cherry () |
1029 | { | |
1030 | __gitcomp "$(__git_refs)" | |
1031 | } | |
1032 | ||
1273231e SP |
1033 | _git_cherry_pick () |
1034 | { | |
7655fa7f FC |
1035 | local dir="$(__gitdir)" |
1036 | if [ -f "$dir"/CHERRY_PICK_HEAD ]; then | |
1037 | __gitcomp "--continue --quit --abort" | |
1038 | return | |
1039 | fi | |
1273231e SP |
1040 | case "$cur" in |
1041 | --*) | |
7655fa7f | 1042 | __gitcomp "--edit --no-commit --signoff --strategy= --mainline" |
1273231e SP |
1043 | ;; |
1044 | *) | |
a31e6262 | 1045 | __gitcomp_nl "$(__git_refs)" |
1273231e SP |
1046 | ;; |
1047 | esac | |
1048 | } | |
1049 | ||
4181c7e8 LM |
1050 | _git_clean () |
1051 | { | |
4181c7e8 LM |
1052 | case "$cur" in |
1053 | --*) | |
1054 | __gitcomp "--dry-run --quiet" | |
1055 | return | |
1056 | ;; | |
1057 | esac | |
fea16b47 MP |
1058 | |
1059 | # XXX should we check for -x option ? | |
ea95c7b8 | 1060 | __git_complete_index_file "--others --directory" |
4181c7e8 LM |
1061 | } |
1062 | ||
3eb11012 LM |
1063 | _git_clone () |
1064 | { | |
3eb11012 LM |
1065 | case "$cur" in |
1066 | --*) | |
1067 | __gitcomp " | |
1068 | --local | |
1069 | --no-hardlinks | |
1070 | --shared | |
1071 | --reference | |
1072 | --quiet | |
1073 | --no-checkout | |
1074 | --bare | |
1075 | --mirror | |
1076 | --origin | |
1077 | --upload-pack | |
1078 | --template= | |
1079 | --depth | |
4047fecf RT |
1080 | --single-branch |
1081 | --branch | |
3eb11012 LM |
1082 | " |
1083 | return | |
1084 | ;; | |
1085 | esac | |
3eb11012 LM |
1086 | } |
1087 | ||
4548e855 SP |
1088 | _git_commit () |
1089 | { | |
fea16b47 MP |
1090 | case "$prev" in |
1091 | -c|-C) | |
1092 | __gitcomp_nl "$(__git_refs)" "" "${cur}" | |
1093 | return | |
1094 | ;; | |
1095 | esac | |
d773c631 | 1096 | |
4548e855 | 1097 | case "$cur" in |
9a424b27 SG |
1098 | --cleanup=*) |
1099 | __gitcomp "default strip verbatim whitespace | |
1100 | " "" "${cur##--cleanup=}" | |
1101 | return | |
1102 | ;; | |
77653abd TM |
1103 | --reuse-message=*|--reedit-message=*|\ |
1104 | --fixup=*|--squash=*) | |
a31e6262 | 1105 | __gitcomp_nl "$(__git_refs)" "" "${cur#*=}" |
9a424b27 SG |
1106 | return |
1107 | ;; | |
1108 | --untracked-files=*) | |
1109 | __gitcomp "all no normal" "" "${cur##--untracked-files=}" | |
1110 | return | |
1111 | ;; | |
4548e855 | 1112 | --*) |
b3391775 | 1113 | __gitcomp " |
4548e855 | 1114 | --all --author= --signoff --verify --no-verify |
7dd9ab0c YB |
1115 | --edit --no-edit |
1116 | --amend --include --only --interactive | |
9a424b27 SG |
1117 | --dry-run --reuse-message= --reedit-message= |
1118 | --reset-author --file= --message= --template= | |
1119 | --cleanup= --untracked-files --untracked-files= | |
77653abd | 1120 | --verbose --quiet --fixup= --squash= |
b3391775 | 1121 | " |
4548e855 SP |
1122 | return |
1123 | esac | |
fea16b47 MP |
1124 | |
1125 | if git rev-parse --verify --quiet HEAD >/dev/null; then | |
f825972c | 1126 | __git_complete_index_file "--committable" |
fea16b47 MP |
1127 | else |
1128 | # This is the first commit | |
1129 | __git_complete_index_file "--cached" | |
1130 | fi | |
4548e855 SP |
1131 | } |
1132 | ||
217926c0 SP |
1133 | _git_describe () |
1134 | { | |
cbb504c9 TR |
1135 | case "$cur" in |
1136 | --*) | |
1137 | __gitcomp " | |
1138 | --all --tags --contains --abbrev= --candidates= | |
1139 | --exact-match --debug --long --match --always | |
1140 | " | |
1141 | return | |
1142 | esac | |
a31e6262 | 1143 | __gitcomp_nl "$(__git_refs)" |
217926c0 SP |
1144 | } |
1145 | ||
07924d4d MP |
1146 | __git_diff_algorithms="myers minimal patience histogram" |
1147 | ||
20bf7292 | 1148 | __git_diff_common_options="--stat --numstat --shortstat --summary |
b3a4f858 JS |
1149 | --patch-with-stat --name-only --name-status --color |
1150 | --no-color --color-words --no-renames --check | |
f135aacb | 1151 | --full-index --binary --abbrev --diff-filter= |
47d5a8fa | 1152 | --find-copies-harder |
b3a4f858 JS |
1153 | --text --ignore-space-at-eol --ignore-space-change |
1154 | --ignore-all-space --exit-code --quiet --ext-diff | |
aba201c6 PO |
1155 | --no-ext-diff |
1156 | --no-prefix --src-prefix= --dst-prefix= | |
6d0e674a | 1157 | --inter-hunk-context= |
216120ab | 1158 | --patience --histogram --minimal |
c0add307 | 1159 | --raw --word-diff |
8fd2cfa7 SB |
1160 | --dirstat --dirstat= --dirstat-by-file |
1161 | --dirstat-by-file= --cumulative | |
07924d4d | 1162 | --diff-algorithm= |
20bf7292 TR |
1163 | " |
1164 | ||
1165 | _git_diff () | |
1166 | { | |
1167 | __git_has_doubledash && return | |
1168 | ||
20bf7292 | 1169 | case "$cur" in |
07924d4d MP |
1170 | --diff-algorithm=*) |
1171 | __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" | |
1172 | return | |
1173 | ;; | |
20bf7292 | 1174 | --*) |
ebd15bf0 | 1175 | __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex |
861514d3 | 1176 | --base --ours --theirs --no-index |
20bf7292 | 1177 | $__git_diff_common_options |
aba201c6 | 1178 | " |
b3a4f858 JS |
1179 | return |
1180 | ;; | |
1181 | esac | |
1d66ec58 | 1182 | __git_complete_revlist_file |
690d8824 JH |
1183 | } |
1184 | ||
c5f424fd | 1185 | __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff |
755e8b3f | 1186 | tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare |
e2dc2de9 DA |
1187 | " |
1188 | ||
1189 | _git_difftool () | |
1190 | { | |
f7ad96cf MH |
1191 | __git_has_doubledash && return |
1192 | ||
e2dc2de9 DA |
1193 | case "$cur" in |
1194 | --tool=*) | |
1195 | __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}" | |
1196 | return | |
1197 | ;; | |
1198 | --*) | |
f7ad96cf MH |
1199 | __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex |
1200 | --base --ours --theirs | |
1201 | --no-renames --diff-filter= --find-copies-harder | |
1202 | --relative --ignore-submodules | |
1203 | --tool=" | |
e2dc2de9 DA |
1204 | return |
1205 | ;; | |
1206 | esac | |
d8517cc6 | 1207 | __git_complete_revlist_file |
e2dc2de9 DA |
1208 | } |
1209 | ||
0a4e1472 JS |
1210 | __git_fetch_options=" |
1211 | --quiet --verbose --append --upload-pack --force --keep --depth= | |
e25e2b42 | 1212 | --tags --no-tags --all --prune --dry-run |
0a4e1472 JS |
1213 | " |
1214 | ||
690d8824 JH |
1215 | _git_fetch () |
1216 | { | |
0a4e1472 JS |
1217 | case "$cur" in |
1218 | --*) | |
1219 | __gitcomp "$__git_fetch_options" | |
1220 | return | |
1221 | ;; | |
1222 | esac | |
52d5c3b5 | 1223 | __git_complete_remote_or_refspec |
690d8824 JH |
1224 | } |
1225 | ||
2f65494d | 1226 | __git_format_patch_options=" |
ea573521 | 1227 | --stdout --attach --no-attach --thread --thread= --no-thread |
2f65494d FC |
1228 | --numbered --start-number --numbered-files --keep-subject --signoff |
1229 | --signature --no-signature --in-reply-to= --cc= --full-index --binary | |
1230 | --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix= | |
1231 | --inline --suffix= --ignore-if-in-upstream --subject-prefix= | |
ea573521 | 1232 | --output-directory --reroll-count --to= --quiet --notes |
2f65494d FC |
1233 | " |
1234 | ||
f53352fb SP |
1235 | _git_format_patch () |
1236 | { | |
f53352fb | 1237 | case "$cur" in |
e1d37937 SB |
1238 | --thread=*) |
1239 | __gitcomp " | |
1240 | deep shallow | |
1241 | " "" "${cur##--thread=}" | |
1242 | return | |
1243 | ;; | |
f53352fb | 1244 | --*) |
2f65494d | 1245 | __gitcomp "$__git_format_patch_options" |
f53352fb SP |
1246 | return |
1247 | ;; | |
1248 | esac | |
1249 | __git_complete_revlist | |
1250 | } | |
1251 | ||
4bca8636 AJ |
1252 | _git_fsck () |
1253 | { | |
4bca8636 AJ |
1254 | case "$cur" in |
1255 | --*) | |
1256 | __gitcomp " | |
1257 | --tags --root --unreachable --cache --no-reflogs --full | |
1258 | --strict --verbose --lost-found | |
1259 | " | |
1260 | return | |
1261 | ;; | |
1262 | esac | |
4bca8636 AJ |
1263 | } |
1264 | ||
b26c8748 SP |
1265 | _git_gc () |
1266 | { | |
b26c8748 SP |
1267 | case "$cur" in |
1268 | --*) | |
47e98eec | 1269 | __gitcomp "--prune --aggressive" |
b26c8748 SP |
1270 | return |
1271 | ;; | |
1272 | esac | |
b26c8748 SP |
1273 | } |
1274 | ||
66729509 SG |
1275 | _git_gitk () |
1276 | { | |
1277 | _gitk | |
1278 | } | |
1279 | ||
29eec71f JK |
1280 | __git_match_ctag() { |
1281 | awk "/^${1////\\/}/ { print \$1 }" "$2" | |
1282 | } | |
1283 | ||
c72e0db1 LM |
1284 | _git_grep () |
1285 | { | |
1286 | __git_has_doubledash && return | |
1287 | ||
c72e0db1 LM |
1288 | case "$cur" in |
1289 | --*) | |
1290 | __gitcomp " | |
1291 | --cached | |
1292 | --text --ignore-case --word-regexp --invert-match | |
5a69eaf5 | 1293 | --full-name --line-number |
c72e0db1 | 1294 | --extended-regexp --basic-regexp --fixed-strings |
63e7e9d8 | 1295 | --perl-regexp |
c72e0db1 LM |
1296 | --files-with-matches --name-only |
1297 | --files-without-match | |
a91f453f | 1298 | --max-depth |
c72e0db1 LM |
1299 | --count |
1300 | --and --or --not --all-match | |
1301 | " | |
1302 | return | |
1303 | ;; | |
1304 | esac | |
17225c49 | 1305 | |
29eec71f JK |
1306 | case "$cword,$prev" in |
1307 | 2,*|*,-*) | |
1308 | if test -r tags; then | |
d2c78075 | 1309 | __gitcomp_nl "$(__git_match_ctag "$cur" tags)" |
29eec71f JK |
1310 | return |
1311 | fi | |
1312 | ;; | |
1313 | esac | |
1314 | ||
a31e6262 | 1315 | __gitcomp_nl "$(__git_refs)" |
c72e0db1 LM |
1316 | } |
1317 | ||
1eb7e2f8 LM |
1318 | _git_help () |
1319 | { | |
1eb7e2f8 LM |
1320 | case "$cur" in |
1321 | --*) | |
1322 | __gitcomp "--all --info --man --web" | |
1323 | return | |
1324 | ;; | |
1325 | esac | |
eaa4e6ee | 1326 | __git_compute_all_commands |
f85a6f0b | 1327 | __gitcomp "$__git_all_commands $(__git_aliases) |
2946cccf MG |
1328 | attributes cli core-tutorial cvs-migration |
1329 | diffcore gitk glossary hooks ignore modules | |
d49483f0 | 1330 | namespaces repository-layout tutorial tutorial-2 |
99f0b599 | 1331 | workflows |
2946cccf | 1332 | " |
1eb7e2f8 LM |
1333 | } |
1334 | ||
5dad868b LM |
1335 | _git_init () |
1336 | { | |
5dad868b LM |
1337 | case "$cur" in |
1338 | --shared=*) | |
1339 | __gitcomp " | |
1340 | false true umask group all world everybody | |
1341 | " "" "${cur##--shared=}" | |
1342 | return | |
1343 | ;; | |
1344 | --*) | |
1345 | __gitcomp "--quiet --bare --template= --shared --shared=" | |
1346 | return | |
1347 | ;; | |
1348 | esac | |
5dad868b LM |
1349 | } |
1350 | ||
b1bc1494 LM |
1351 | _git_ls_files () |
1352 | { | |
b1bc1494 LM |
1353 | case "$cur" in |
1354 | --*) | |
1355 | __gitcomp "--cached --deleted --modified --others --ignored | |
1356 | --stage --directory --no-empty-directory --unmerged | |
1357 | --killed --exclude= --exclude-from= | |
1358 | --exclude-per-directory= --exclude-standard | |
1359 | --error-unmatch --with-tree= --full-name | |
1360 | --abbrev --ignored --exclude-per-directory | |
1361 | " | |
1362 | return | |
1363 | ;; | |
1364 | esac | |
fea16b47 MP |
1365 | |
1366 | # XXX ignore options like --modified and always suggest all cached | |
1367 | # files. | |
1368 | __git_complete_index_file "--cached" | |
b1bc1494 LM |
1369 | } |
1370 | ||
690d8824 JH |
1371 | _git_ls_remote () |
1372 | { | |
a31e6262 | 1373 | __gitcomp_nl "$(__git_remotes)" |
690d8824 JH |
1374 | } |
1375 | ||
1376 | _git_ls_tree () | |
1377 | { | |
1378 | __git_complete_file | |
1379 | } | |
1380 | ||
a393777e TR |
1381 | # Options that go well for log, shortlog and gitk |
1382 | __git_log_common_options=" | |
1383 | --not --all | |
1384 | --branches --tags --remotes | |
4fe1a619 | 1385 | --first-parent --merges --no-merges |
a393777e TR |
1386 | --max-count= |
1387 | --max-age= --since= --after= | |
1388 | --min-age= --until= --before= | |
6a6ebded MG |
1389 | --min-parents= --max-parents= |
1390 | --no-min-parents --no-max-parents | |
a393777e TR |
1391 | " |
1392 | # Options that go well for log and gitk (not shortlog) | |
1393 | __git_log_gitk_options=" | |
1394 | --dense --sparse --full-history | |
1395 | --simplify-merges --simplify-by-decoration | |
3925b575 | 1396 | --left-right --notes --no-notes |
a393777e TR |
1397 | " |
1398 | # Options that go well for log and shortlog (not gitk) | |
1399 | __git_log_shortlog_options=" | |
1400 | --author= --committer= --grep= | |
1401 | --all-match | |
1402 | " | |
1403 | ||
3d279863 | 1404 | __git_log_pretty_formats="oneline short medium full fuller email raw format:" |
672c68cb | 1405 | __git_log_date_formats="relative iso8601 rfc2822 short local default raw" |
3d279863 | 1406 | |
690d8824 JH |
1407 | _git_log () |
1408 | { | |
d773c631 SG |
1409 | __git_has_doubledash && return |
1410 | ||
bf3c20f6 TR |
1411 | local g="$(git rev-parse --git-dir 2>/dev/null)" |
1412 | local merge="" | |
ba7906f2 | 1413 | if [ -f "$g/MERGE_HEAD" ]; then |
bf3c20f6 TR |
1414 | merge="--merge" |
1415 | fi | |
6e31b866 | 1416 | case "$cur" in |
e67d71e5 | 1417 | --pretty=*|--format=*) |
c3898111 | 1418 | __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases) |
e67d71e5 | 1419 | " "" "${cur#*=}" |
72de29c2 TL |
1420 | return |
1421 | ;; | |
47e98eec | 1422 | --date=*) |
672c68cb | 1423 | __gitcomp "$__git_log_date_formats" "" "${cur##--date=}" |
47e98eec SP |
1424 | return |
1425 | ;; | |
af4e9e8c SB |
1426 | --decorate=*) |
1427 | __gitcomp "long short" "" "${cur##--decorate=}" | |
1428 | return | |
1429 | ;; | |
6e31b866 | 1430 | --*) |
b3391775 | 1431 | __gitcomp " |
a393777e TR |
1432 | $__git_log_common_options |
1433 | $__git_log_shortlog_options | |
1434 | $__git_log_gitk_options | |
8f87fae6 | 1435 | --root --topo-order --date-order --reverse |
5d0e6343 | 1436 | --follow --full-diff |
6e31b866 | 1437 | --abbrev-commit --abbrev= |
47e98eec | 1438 | --relative-date --date= |
72de29c2 | 1439 | --pretty= --format= --oneline |
a393777e | 1440 | --cherry-pick |
20827d99 | 1441 | --graph |
af4e9e8c | 1442 | --decorate --decorate= |
20bf7292 | 1443 | --walk-reflogs |
a393777e | 1444 | --parents --children |
bf3c20f6 | 1445 | $merge |
20bf7292 | 1446 | $__git_diff_common_options |
47d5a8fa | 1447 | --pickaxe-all --pickaxe-regex |
b3391775 | 1448 | " |
6e31b866 SP |
1449 | return |
1450 | ;; | |
1451 | esac | |
f53352fb | 1452 | __git_complete_revlist |
690d8824 JH |
1453 | } |
1454 | ||
0a4e1472 JS |
1455 | __git_merge_options=" |
1456 | --no-commit --no-stat --log --no-log --squash --strategy | |
2ff14e31 | 1457 | --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit |
0a4e1472 JS |
1458 | " |
1459 | ||
4ad91321 SP |
1460 | _git_merge () |
1461 | { | |
3c7b480a JS |
1462 | __git_complete_strategy && return |
1463 | ||
4ad91321 SP |
1464 | case "$cur" in |
1465 | --*) | |
0a4e1472 | 1466 | __gitcomp "$__git_merge_options" |
4ad91321 SP |
1467 | return |
1468 | esac | |
a31e6262 | 1469 | __gitcomp_nl "$(__git_refs)" |
4ad91321 SP |
1470 | } |
1471 | ||
b4c72162 LM |
1472 | _git_mergetool () |
1473 | { | |
b4c72162 LM |
1474 | case "$cur" in |
1475 | --tool=*) | |
e2dc2de9 | 1476 | __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}" |
b4c72162 LM |
1477 | return |
1478 | ;; | |
1479 | --*) | |
1480 | __gitcomp "--tool=" | |
1481 | return | |
1482 | ;; | |
1483 | esac | |
b4c72162 LM |
1484 | } |
1485 | ||
690d8824 JH |
1486 | _git_merge_base () |
1487 | { | |
a31e6262 | 1488 | __gitcomp_nl "$(__git_refs)" |
690d8824 JH |
1489 | } |
1490 | ||
1127c51c LM |
1491 | _git_mv () |
1492 | { | |
1127c51c LM |
1493 | case "$cur" in |
1494 | --*) | |
1495 | __gitcomp "--dry-run" | |
1496 | return | |
1497 | ;; | |
1498 | esac | |
fea16b47 MP |
1499 | |
1500 | if [ $(__git_count_arguments "mv") -gt 0 ]; then | |
1501 | # We need to show both cached and untracked files (including | |
1502 | # empty directories) since this may not be the last argument. | |
1503 | __git_complete_index_file "--cached --others --directory" | |
1504 | else | |
1505 | __git_complete_index_file "--cached" | |
1506 | fi | |
1127c51c LM |
1507 | } |
1508 | ||
d33909bf SP |
1509 | _git_name_rev () |
1510 | { | |
b3391775 | 1511 | __gitcomp "--tags --all --stdin" |
d33909bf SP |
1512 | } |
1513 | ||
00f09d0e SG |
1514 | _git_notes () |
1515 | { | |
2a5da755 SG |
1516 | local subcommands='add append copy edit list prune remove show' |
1517 | local subcommand="$(__git_find_on_cmdline "$subcommands")" | |
00f09d0e | 1518 | |
2a5da755 SG |
1519 | case "$subcommand,$cur" in |
1520 | ,--*) | |
1521 | __gitcomp '--ref' | |
1522 | ;; | |
1523 | ,*) | |
39540681 | 1524 | case "$prev" in |
2a5da755 | 1525 | --ref) |
a31e6262 | 1526 | __gitcomp_nl "$(__git_refs)" |
2a5da755 SG |
1527 | ;; |
1528 | *) | |
1529 | __gitcomp "$subcommands --ref" | |
1530 | ;; | |
1531 | esac | |
1532 | ;; | |
a8f89bfa | 1533 | add,--reuse-message=*|append,--reuse-message=*|\ |
2a5da755 | 1534 | add,--reedit-message=*|append,--reedit-message=*) |
a31e6262 | 1535 | __gitcomp_nl "$(__git_refs)" "" "${cur#*=}" |
2a5da755 SG |
1536 | ;; |
1537 | add,--*|append,--*) | |
1538 | __gitcomp '--file= --message= --reedit-message= | |
1539 | --reuse-message=' | |
1540 | ;; | |
1541 | copy,--*) | |
1542 | __gitcomp '--stdin' | |
1543 | ;; | |
1544 | prune,--*) | |
1545 | __gitcomp '--dry-run --verbose' | |
1546 | ;; | |
1547 | prune,*) | |
00f09d0e SG |
1548 | ;; |
1549 | *) | |
39540681 | 1550 | case "$prev" in |
2a5da755 SG |
1551 | -m|-F) |
1552 | ;; | |
1553 | *) | |
a31e6262 | 1554 | __gitcomp_nl "$(__git_refs)" |
2a5da755 SG |
1555 | ;; |
1556 | esac | |
00f09d0e SG |
1557 | ;; |
1558 | esac | |
1559 | } | |
1560 | ||
690d8824 JH |
1561 | _git_pull () |
1562 | { | |
0a4e1472 JS |
1563 | __git_complete_strategy && return |
1564 | ||
0a4e1472 JS |
1565 | case "$cur" in |
1566 | --*) | |
1567 | __gitcomp " | |
1568 | --rebase --no-rebase | |
1569 | $__git_merge_options | |
1570 | $__git_fetch_options | |
1571 | " | |
1572 | return | |
1573 | ;; | |
1574 | esac | |
52d5c3b5 | 1575 | __git_complete_remote_or_refspec |
690d8824 JH |
1576 | } |
1577 | ||
1578 | _git_push () | |
1579 | { | |
da48616f | 1580 | case "$prev" in |
0a4e1472 | 1581 | --repo) |
a31e6262 | 1582 | __gitcomp_nl "$(__git_remotes)" |
0a4e1472 JS |
1583 | return |
1584 | esac | |
1585 | case "$cur" in | |
1586 | --repo=*) | |
a31e6262 | 1587 | __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}" |
0a4e1472 JS |
1588 | return |
1589 | ;; | |
1590 | --*) | |
1591 | __gitcomp " | |
1592 | --all --mirror --tags --dry-run --force --verbose | |
3623dc03 | 1593 | --receive-pack= --repo= --set-upstream |
0a4e1472 JS |
1594 | " |
1595 | return | |
1596 | ;; | |
1597 | esac | |
52d5c3b5 | 1598 | __git_complete_remote_or_refspec |
690d8824 JH |
1599 | } |
1600 | ||
61d926a3 SP |
1601 | _git_rebase () |
1602 | { | |
da48616f | 1603 | local dir="$(__gitdir)" |
51ef1daa | 1604 | if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then |
b3391775 | 1605 | __gitcomp "--continue --skip --abort" |
61d926a3 SP |
1606 | return |
1607 | fi | |
3c7b480a | 1608 | __git_complete_strategy && return |
61d926a3 | 1609 | case "$cur" in |
93cf50a4 BG |
1610 | --whitespace=*) |
1611 | __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" | |
1612 | return | |
1613 | ;; | |
61d926a3 | 1614 | --*) |
93cf50a4 BG |
1615 | __gitcomp " |
1616 | --onto --merge --strategy --interactive | |
1617 | --preserve-merges --stat --no-stat | |
1618 | --committer-date-is-author-date --ignore-date | |
1619 | --ignore-whitespace --whitespace= | |
6d0d465e | 1620 | --autosquash |
93cf50a4 BG |
1621 | " |
1622 | ||
61d926a3 SP |
1623 | return |
1624 | esac | |
a31e6262 | 1625 | __gitcomp_nl "$(__git_refs)" |
61d926a3 SP |
1626 | } |
1627 | ||
057f3279 TRC |
1628 | _git_reflog () |
1629 | { | |
1630 | local subcommands="show delete expire" | |
1631 | local subcommand="$(__git_find_on_cmdline "$subcommands")" | |
1632 | ||
1633 | if [ -z "$subcommand" ]; then | |
1634 | __gitcomp "$subcommands" | |
1635 | else | |
a31e6262 | 1636 | __gitcomp_nl "$(__git_refs)" |
057f3279 TRC |
1637 | fi |
1638 | } | |
1639 | ||
ae616de6 | 1640 | __git_send_email_confirm_options="always never auto cc compose" |
cb8a9bd5 | 1641 | __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all" |
ae616de6 | 1642 | |
25a1f374 TL |
1643 | _git_send_email () |
1644 | { | |
25a1f374 | 1645 | case "$cur" in |
ae616de6 SB |
1646 | --confirm=*) |
1647 | __gitcomp " | |
1648 | $__git_send_email_confirm_options | |
1649 | " "" "${cur##--confirm=}" | |
1650 | return | |
1651 | ;; | |
1652 | --suppress-cc=*) | |
1653 | __gitcomp " | |
1654 | $__git_send_email_suppresscc_options | |
1655 | " "" "${cur##--suppress-cc=}" | |
1656 | ||
1657 | return | |
1658 | ;; | |
1659 | --smtp-encryption=*) | |
1660 | __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}" | |
1661 | return | |
1662 | ;; | |
2f65494d FC |
1663 | --thread=*) |
1664 | __gitcomp " | |
1665 | deep shallow | |
1666 | " "" "${cur##--thread=}" | |
1667 | return | |
1668 | ;; | |
25a1f374 | 1669 | --*) |
77813151 | 1670 | __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to |
ae616de6 SB |
1671 | --compose --confirm= --dry-run --envelope-sender |
1672 | --from --identity | |
25a1f374 TL |
1673 | --in-reply-to --no-chain-reply-to --no-signed-off-by-cc |
1674 | --no-suppress-from --no-thread --quiet | |
1675 | --signed-off-by-cc --smtp-pass --smtp-server | |
ae616de6 SB |
1676 | --smtp-server-port --smtp-encryption= --smtp-user |
1677 | --subject --suppress-cc= --suppress-from --thread --to | |
2f65494d FC |
1678 | --validate --no-validate |
1679 | $__git_format_patch_options" | |
25a1f374 TL |
1680 | return |
1681 | ;; | |
1682 | esac | |
2f65494d | 1683 | __git_complete_revlist |
25a1f374 TL |
1684 | } |
1685 | ||
424cce83 SG |
1686 | _git_stage () |
1687 | { | |
1688 | _git_add | |
1689 | } | |
1690 | ||
00652369 SB |
1691 | __git_config_get_set_variables () |
1692 | { | |
da48616f | 1693 | local prevword word config_file= c=$cword |
00652369 | 1694 | while [ $c -gt 1 ]; do |
da48616f | 1695 | word="${words[c]}" |
00652369 | 1696 | case "$word" in |
66c0786c | 1697 | --system|--global|--local|--file=*) |
00652369 SB |
1698 | config_file="$word" |
1699 | break | |
1700 | ;; | |
1701 | -f|--file) | |
1702 | config_file="$word $prevword" | |
1703 | break | |
1704 | ;; | |
1705 | esac | |
1706 | prevword=$word | |
1707 | c=$((--c)) | |
1708 | done | |
1709 | ||
f581de1b | 1710 | git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null | |
6f2dd720 | 1711 | while read -r line |
f581de1b SB |
1712 | do |
1713 | case "$line" in | |
1714 | *.*=*) | |
1715 | echo "${line/=*/}" | |
00652369 SB |
1716 | ;; |
1717 | esac | |
1718 | done | |
1719 | } | |
1720 | ||
e0d10e1c | 1721 | _git_config () |
5de40f59 | 1722 | { |
da48616f | 1723 | case "$prev" in |
72f75077 | 1724 | branch.*.remote|branch.*.pushremote) |
a31e6262 | 1725 | __gitcomp_nl "$(__git_remotes)" |
5de40f59 SP |
1726 | return |
1727 | ;; | |
1728 | branch.*.merge) | |
a31e6262 | 1729 | __gitcomp_nl "$(__git_refs)" |
5de40f59 SP |
1730 | return |
1731 | ;; | |
a05490ed RR |
1732 | branch.*.rebase) |
1733 | __gitcomp "false true" | |
1734 | return | |
1735 | ;; | |
7e6a0cc4 RR |
1736 | remote.pushdefault) |
1737 | __gitcomp_nl "$(__git_remotes)" | |
1738 | return | |
1739 | ;; | |
5de40f59 | 1740 | remote.*.fetch) |
da48616f | 1741 | local remote="${prev#remote.}" |
5de40f59 | 1742 | remote="${remote%.fetch}" |
d51a8ecd | 1743 | if [ -z "$cur" ]; then |
73704451 | 1744 | __gitcomp_nl "refs/heads/" "" "" "" |
d51a8ecd SG |
1745 | return |
1746 | fi | |
a31e6262 | 1747 | __gitcomp_nl "$(__git_refs_remotes "$remote")" |
5de40f59 SP |
1748 | return |
1749 | ;; | |
1750 | remote.*.push) | |
da48616f | 1751 | local remote="${prev#remote.}" |
5de40f59 | 1752 | remote="${remote%.push}" |
a31e6262 | 1753 | __gitcomp_nl "$(git --git-dir="$(__gitdir)" \ |
5de40f59 | 1754 | for-each-ref --format='%(refname):%(refname)' \ |
78d4d6a2 SP |
1755 | refs/heads)" |
1756 | return | |
1757 | ;; | |
1758 | pull.twohead|pull.octopus) | |
eaa4e6ee JN |
1759 | __git_compute_merge_strategies |
1760 | __gitcomp "$__git_merge_strategies" | |
78d4d6a2 SP |
1761 | return |
1762 | ;; | |
6123d719 MH |
1763 | color.branch|color.diff|color.interactive|\ |
1764 | color.showbranch|color.status|color.ui) | |
78d4d6a2 SP |
1765 | __gitcomp "always never auto" |
1766 | return | |
1767 | ;; | |
901d615c MK |
1768 | color.pager) |
1769 | __gitcomp "false true" | |
1770 | return | |
1771 | ;; | |
78d4d6a2 SP |
1772 | color.*.*) |
1773 | __gitcomp " | |
98171a07 | 1774 | normal black red green yellow blue magenta cyan white |
78d4d6a2 SP |
1775 | bold dim ul blink reverse |
1776 | " | |
5de40f59 SP |
1777 | return |
1778 | ;; | |
2651baae RR |
1779 | diff.submodule) |
1780 | __gitcomp "log short" | |
1781 | return | |
1782 | ;; | |
9b82d63b SB |
1783 | help.format) |
1784 | __gitcomp "man info web html" | |
1785 | return | |
1786 | ;; | |
672c68cb SB |
1787 | log.date) |
1788 | __gitcomp "$__git_log_date_formats" | |
1789 | return | |
1790 | ;; | |
ae616de6 SB |
1791 | sendemail.aliasesfiletype) |
1792 | __gitcomp "mutt mailrc pine elm gnus" | |
1793 | return | |
1794 | ;; | |
1795 | sendemail.confirm) | |
1796 | __gitcomp "$__git_send_email_confirm_options" | |
1797 | return | |
1798 | ;; | |
1799 | sendemail.suppresscc) | |
1800 | __gitcomp "$__git_send_email_suppresscc_options" | |
1801 | return | |
1802 | ;; | |
00652369 | 1803 | --get|--get-all|--unset|--unset-all) |
a31e6262 | 1804 | __gitcomp_nl "$(__git_config_get_set_variables)" |
00652369 SB |
1805 | return |
1806 | ;; | |
5de40f59 | 1807 | *.*) |
5de40f59 SP |
1808 | return |
1809 | ;; | |
1810 | esac | |
1811 | case "$cur" in | |
1812 | --*) | |
78d4d6a2 | 1813 | __gitcomp " |
66c0786c | 1814 | --system --global --local --file= |
12977705 | 1815 | --list --replace-all |
5de40f59 | 1816 | --get --get-all --get-regexp |
1b71eb35 | 1817 | --add --unset --unset-all |
12977705 | 1818 | --remove-section --rename-section |
78d4d6a2 | 1819 | " |
5de40f59 SP |
1820 | return |
1821 | ;; | |
1822 | branch.*.*) | |
9244d69b | 1823 | local pfx="${cur%.*}." cur_="${cur##*.}" |
72f75077 | 1824 | __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_" |
5de40f59 SP |
1825 | return |
1826 | ;; | |
1827 | branch.*) | |
9244d69b | 1828 | local pfx="${cur%.*}." cur_="${cur#*.}" |
a31e6262 | 1829 | __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "." |
5de40f59 SP |
1830 | return |
1831 | ;; | |
0aa62fd0 | 1832 | guitool.*.*) |
9244d69b | 1833 | local pfx="${cur%.*}." cur_="${cur##*.}" |
0aa62fd0 SB |
1834 | __gitcomp " |
1835 | argprompt cmd confirm needsfile noconsole norescan | |
1836 | prompt revprompt revunmerged title | |
9244d69b | 1837 | " "$pfx" "$cur_" |
0aa62fd0 SB |
1838 | return |
1839 | ;; | |
1840 | difftool.*.*) | |
9244d69b SG |
1841 | local pfx="${cur%.*}." cur_="${cur##*.}" |
1842 | __gitcomp "cmd path" "$pfx" "$cur_" | |
0aa62fd0 SB |
1843 | return |
1844 | ;; | |
1845 | man.*.*) | |
9244d69b SG |
1846 | local pfx="${cur%.*}." cur_="${cur##*.}" |
1847 | __gitcomp "cmd path" "$pfx" "$cur_" | |
0aa62fd0 SB |
1848 | return |
1849 | ;; | |
1850 | mergetool.*.*) | |
9244d69b SG |
1851 | local pfx="${cur%.*}." cur_="${cur##*.}" |
1852 | __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" | |
0aa62fd0 SB |
1853 | return |
1854 | ;; | |
1855 | pager.*) | |
9244d69b | 1856 | local pfx="${cur%.*}." cur_="${cur#*.}" |
eaa4e6ee | 1857 | __git_compute_all_commands |
a31e6262 | 1858 | __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" |
0aa62fd0 SB |
1859 | return |
1860 | ;; | |
5de40f59 | 1861 | remote.*.*) |
9244d69b | 1862 | local pfx="${cur%.*}." cur_="${cur##*.}" |
12977705 | 1863 | __gitcomp " |
98171a07 | 1864 | url proxy fetch push mirror skipDefaultUpdate |
6fac1b83 | 1865 | receivepack uploadpack tagopt pushurl |
9244d69b | 1866 | " "$pfx" "$cur_" |
5de40f59 SP |
1867 | return |
1868 | ;; | |
1869 | remote.*) | |
9244d69b | 1870 | local pfx="${cur%.*}." cur_="${cur#*.}" |
a31e6262 | 1871 | __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." |
5de40f59 SP |
1872 | return |
1873 | ;; | |
0aa62fd0 | 1874 | url.*.*) |
9244d69b SG |
1875 | local pfx="${cur%.*}." cur_="${cur##*.}" |
1876 | __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" | |
0aa62fd0 SB |
1877 | return |
1878 | ;; | |
5de40f59 | 1879 | esac |
78d4d6a2 | 1880 | __gitcomp " |
6068ac88 MZ |
1881 | add.ignoreErrors |
1882 | advice.commitBeforeMerge | |
1883 | advice.detachedHead | |
1884 | advice.implicitIdentity | |
1885 | advice.pushNonFastForward | |
1886 | advice.resolveConflict | |
1887 | advice.statusHints | |
226b343c | 1888 | alias. |
6068ac88 | 1889 | am.keepcr |
86c91f91 | 1890 | apply.ignorewhitespace |
5de40f59 | 1891 | apply.whitespace |
98171a07 LM |
1892 | branch.autosetupmerge |
1893 | branch.autosetuprebase | |
6068ac88 | 1894 | browser. |
2122591b | 1895 | clean.requireForce |
78d4d6a2 SP |
1896 | color.branch |
1897 | color.branch.current | |
1898 | color.branch.local | |
78d4d6a2 | 1899 | color.branch.plain |
025a1929 | 1900 | color.branch.remote |
6068ac88 MZ |
1901 | color.decorate.HEAD |
1902 | color.decorate.branch | |
1903 | color.decorate.remoteBranch | |
1904 | color.decorate.stash | |
1905 | color.decorate.tag | |
a159ca0c | 1906 | color.diff |
025a1929 | 1907 | color.diff.commit |
78d4d6a2 | 1908 | color.diff.frag |
6068ac88 | 1909 | color.diff.func |
025a1929 | 1910 | color.diff.meta |
78d4d6a2 | 1911 | color.diff.new |
025a1929 LM |
1912 | color.diff.old |
1913 | color.diff.plain | |
78d4d6a2 | 1914 | color.diff.whitespace |
226b343c | 1915 | color.grep |
6068ac88 MZ |
1916 | color.grep.context |
1917 | color.grep.filename | |
1918 | color.grep.function | |
1919 | color.grep.linenumber | |
226b343c | 1920 | color.grep.match |
6068ac88 MZ |
1921 | color.grep.selected |
1922 | color.grep.separator | |
98171a07 | 1923 | color.interactive |
6068ac88 | 1924 | color.interactive.error |
98171a07 LM |
1925 | color.interactive.header |
1926 | color.interactive.help | |
1927 | color.interactive.prompt | |
a159ca0c | 1928 | color.pager |
6123d719 | 1929 | color.showbranch |
a159ca0c | 1930 | color.status |
78d4d6a2 SP |
1931 | color.status.added |
1932 | color.status.changed | |
025a1929 | 1933 | color.status.header |
98171a07 | 1934 | color.status.nobranch |
78d4d6a2 | 1935 | color.status.untracked |
98171a07 LM |
1936 | color.status.updated |
1937 | color.ui | |
6068ac88 | 1938 | commit.status |
98171a07 | 1939 | commit.template |
cdb791f6 | 1940 | core.abbrev |
6068ac88 MZ |
1941 | core.askpass |
1942 | core.attributesfile | |
98171a07 LM |
1943 | core.autocrlf |
1944 | core.bare | |
6068ac88 | 1945 | core.bigFileThreshold |
025a1929 | 1946 | core.compression |
226b343c | 1947 | core.createObject |
98171a07 LM |
1948 | core.deltaBaseCacheLimit |
1949 | core.editor | |
6068ac88 | 1950 | core.eol |
98171a07 | 1951 | core.excludesfile |
025a1929 | 1952 | core.fileMode |
98171a07 | 1953 | core.fsyncobjectfiles |
025a1929 LM |
1954 | core.gitProxy |
1955 | core.ignoreStat | |
6068ac88 | 1956 | core.ignorecase |
025a1929 LM |
1957 | core.logAllRefUpdates |
1958 | core.loosecompression | |
6068ac88 | 1959 | core.notesRef |
025a1929 LM |
1960 | core.packedGitLimit |
1961 | core.packedGitWindowSize | |
98171a07 | 1962 | core.pager |
025a1929 | 1963 | core.preferSymlinkRefs |
98171a07 LM |
1964 | core.preloadindex |
1965 | core.quotepath | |
025a1929 | 1966 | core.repositoryFormatVersion |
98171a07 | 1967 | core.safecrlf |
025a1929 | 1968 | core.sharedRepository |
6068ac88 | 1969 | core.sparseCheckout |
98171a07 LM |
1970 | core.symlinks |
1971 | core.trustctime | |
025a1929 | 1972 | core.warnAmbiguousRefs |
98171a07 LM |
1973 | core.whitespace |
1974 | core.worktree | |
1975 | diff.autorefreshindex | |
1976 | diff.external | |
6068ac88 | 1977 | diff.ignoreSubmodules |
98171a07 | 1978 | diff.mnemonicprefix |
6068ac88 | 1979 | diff.noprefix |
78d4d6a2 SP |
1980 | diff.renameLimit |
1981 | diff.renames | |
de7c201a | 1982 | diff.statGraphWidth |
2651baae | 1983 | diff.submodule |
226b343c SB |
1984 | diff.suppressBlankEmpty |
1985 | diff.tool | |
1986 | diff.wordRegex | |
07ab4dec | 1987 | diff.algorithm |
0aa62fd0 | 1988 | difftool. |
226b343c | 1989 | difftool.prompt |
6068ac88 | 1990 | fetch.recurseSubmodules |
78d4d6a2 | 1991 | fetch.unpackLimit |
226b343c SB |
1992 | format.attach |
1993 | format.cc | |
78d4d6a2 | 1994 | format.headers |
98171a07 LM |
1995 | format.numbered |
1996 | format.pretty | |
d8e1e5df | 1997 | format.signature |
226b343c SB |
1998 | format.signoff |
1999 | format.subjectprefix | |
98171a07 | 2000 | format.suffix |
226b343c | 2001 | format.thread |
6068ac88 MZ |
2002 | format.to |
2003 | gc. | |
98171a07 LM |
2004 | gc.aggressiveWindow |
2005 | gc.auto | |
2006 | gc.autopacklimit | |
12977705 | 2007 | gc.packrefs |
98171a07 | 2008 | gc.pruneexpire |
78d4d6a2 SP |
2009 | gc.reflogexpire |
2010 | gc.reflogexpireunreachable | |
2011 | gc.rerereresolved | |
2012 | gc.rerereunresolved | |
025a1929 | 2013 | gitcvs.allbinary |
226b343c | 2014 | gitcvs.commitmsgannotation |
98171a07 | 2015 | gitcvs.dbTableNamePrefix |
025a1929 LM |
2016 | gitcvs.dbdriver |
2017 | gitcvs.dbname | |
2018 | gitcvs.dbpass | |
025a1929 LM |
2019 | gitcvs.dbuser |
2020 | gitcvs.enabled | |
2021 | gitcvs.logfile | |
98171a07 | 2022 | gitcvs.usecrlfattr |
0aa62fd0 | 2023 | guitool. |
98171a07 LM |
2024 | gui.blamehistoryctx |
2025 | gui.commitmsgwidth | |
2026 | gui.copyblamethreshold | |
2027 | gui.diffcontext | |
2028 | gui.encoding | |
2029 | gui.fastcopyblame | |
2030 | gui.matchtrackingbranch | |
2031 | gui.newbranchtemplate | |
2032 | gui.pruneduringfetch | |
2033 | gui.spellingdictionary | |
2034 | gui.trustmtime | |
2035 | help.autocorrect | |
2036 | help.browser | |
2037 | help.format | |
78d4d6a2 SP |
2038 | http.lowSpeedLimit |
2039 | http.lowSpeedTime | |
025a1929 | 2040 | http.maxRequests |
6068ac88 | 2041 | http.minSessions |
5de40f59 | 2042 | http.noEPSV |
6068ac88 | 2043 | http.postBuffer |
98171a07 | 2044 | http.proxy |
025a1929 LM |
2045 | http.sslCAInfo |
2046 | http.sslCAPath | |
2047 | http.sslCert | |
6068ac88 | 2048 | http.sslCertPasswordProtected |
025a1929 LM |
2049 | http.sslKey |
2050 | http.sslVerify | |
6068ac88 | 2051 | http.useragent |
78d4d6a2 SP |
2052 | i18n.commitEncoding |
2053 | i18n.logOutputEncoding | |
6068ac88 | 2054 | imap.authMethod |
226b343c SB |
2055 | imap.folder |
2056 | imap.host | |
2057 | imap.pass | |
2058 | imap.port | |
2059 | imap.preformattedHTML | |
2060 | imap.sslverify | |
2061 | imap.tunnel | |
2062 | imap.user | |
6068ac88 | 2063 | init.templatedir |
98171a07 LM |
2064 | instaweb.browser |
2065 | instaweb.httpd | |
2066 | instaweb.local | |
2067 | instaweb.modulepath | |
2068 | instaweb.port | |
226b343c | 2069 | interactive.singlekey |
98171a07 | 2070 | log.date |
6068ac88 | 2071 | log.decorate |
78d4d6a2 | 2072 | log.showroot |
226b343c | 2073 | mailmap.file |
0aa62fd0 | 2074 | man. |
98171a07 | 2075 | man.viewer |
6068ac88 | 2076 | merge. |
98171a07 LM |
2077 | merge.conflictstyle |
2078 | merge.log | |
2079 | merge.renameLimit | |
6068ac88 | 2080 | merge.renormalize |
98171a07 | 2081 | merge.stat |
025a1929 | 2082 | merge.tool |
78d4d6a2 | 2083 | merge.verbosity |
0aa62fd0 | 2084 | mergetool. |
98171a07 | 2085 | mergetool.keepBackup |
6068ac88 | 2086 | mergetool.keepTemporaries |
226b343c | 2087 | mergetool.prompt |
6068ac88 MZ |
2088 | notes.displayRef |
2089 | notes.rewrite. | |
2090 | notes.rewrite.amend | |
2091 | notes.rewrite.rebase | |
2092 | notes.rewriteMode | |
2093 | notes.rewriteRef | |
47e98eec | 2094 | pack.compression |
47e98eec | 2095 | pack.deltaCacheLimit |
025a1929 LM |
2096 | pack.deltaCacheSize |
2097 | pack.depth | |
98171a07 LM |
2098 | pack.indexVersion |
2099 | pack.packSizeLimit | |
2100 | pack.threads | |
025a1929 LM |
2101 | pack.window |
2102 | pack.windowMemory | |
0aa62fd0 | 2103 | pager. |
6068ac88 | 2104 | pretty. |
78d4d6a2 SP |
2105 | pull.octopus |
2106 | pull.twohead | |
226b343c | 2107 | push.default |
6068ac88 | 2108 | rebase.autosquash |
226b343c | 2109 | rebase.stat |
6068ac88 | 2110 | receive.autogc |
98171a07 | 2111 | receive.denyCurrentBranch |
6068ac88 | 2112 | receive.denyDeleteCurrent |
98171a07 | 2113 | receive.denyDeletes |
025a1929 | 2114 | receive.denyNonFastForwards |
98171a07 | 2115 | receive.fsckObjects |
025a1929 | 2116 | receive.unpackLimit |
6068ac88 | 2117 | receive.updateserverinfo |
7e6a0cc4 | 2118 | remote.pushdefault |
6068ac88 | 2119 | remotes. |
98171a07 LM |
2120 | repack.usedeltabaseoffset |
2121 | rerere.autoupdate | |
2122 | rerere.enabled | |
6068ac88 | 2123 | sendemail. |
226b343c | 2124 | sendemail.aliasesfile |
6068ac88 | 2125 | sendemail.aliasfiletype |
226b343c SB |
2126 | sendemail.bcc |
2127 | sendemail.cc | |
2128 | sendemail.cccmd | |
2129 | sendemail.chainreplyto | |
2130 | sendemail.confirm | |
2131 | sendemail.envelopesender | |
6068ac88 MZ |
2132 | sendemail.from |
2133 | sendemail.identity | |
226b343c SB |
2134 | sendemail.multiedit |
2135 | sendemail.signedoffbycc | |
6068ac88 | 2136 | sendemail.smtpdomain |
226b343c SB |
2137 | sendemail.smtpencryption |
2138 | sendemail.smtppass | |
2139 | sendemail.smtpserver | |
6068ac88 | 2140 | sendemail.smtpserveroption |
226b343c SB |
2141 | sendemail.smtpserverport |
2142 | sendemail.smtpuser | |
2143 | sendemail.suppresscc | |
2144 | sendemail.suppressfrom | |
2145 | sendemail.thread | |
2146 | sendemail.to | |
2147 | sendemail.validate | |
78d4d6a2 | 2148 | showbranch.default |
98171a07 LM |
2149 | status.relativePaths |
2150 | status.showUntrackedFiles | |
6068ac88 MZ |
2151 | status.submodulesummary |
2152 | submodule. | |
78d4d6a2 SP |
2153 | tar.umask |
2154 | transfer.unpackLimit | |
0aa62fd0 | 2155 | url. |
78d4d6a2 | 2156 | user.email |
025a1929 | 2157 | user.name |
78d4d6a2 | 2158 | user.signingkey |
98171a07 | 2159 | web.browser |
5de40f59 | 2160 | branch. remote. |
78d4d6a2 | 2161 | " |
5de40f59 SP |
2162 | } |
2163 | ||
88293c67 SP |
2164 | _git_remote () |
2165 | { | |
e17dba8f | 2166 | local subcommands="add rename remove set-head set-branches set-url show prune update" |
918c03c2 | 2167 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
3ff1320d | 2168 | if [ -z "$subcommand" ]; then |
3903c618 | 2169 | __gitcomp "$subcommands" |
88293c67 SP |
2170 | return |
2171 | fi | |
2172 | ||
3ff1320d | 2173 | case "$subcommand" in |
e17dba8f | 2174 | rename|remove|set-url|show|prune) |
a31e6262 | 2175 | __gitcomp_nl "$(__git_remotes)" |
88293c67 | 2176 | ;; |
f1c6ffe6 PJ |
2177 | set-head|set-branches) |
2178 | __git_complete_remote_or_refspec | |
2179 | ;; | |
fb72759b SP |
2180 | update) |
2181 | local i c='' IFS=$'\n' | |
518ef8f0 TZ |
2182 | for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do |
2183 | i="${i#remotes.}" | |
2184 | c="$c ${i/ */}" | |
fb72759b SP |
2185 | done |
2186 | __gitcomp "$c" | |
2187 | ;; | |
88293c67 | 2188 | *) |
88293c67 SP |
2189 | ;; |
2190 | esac | |
2191 | } | |
2192 | ||
e1c1a067 BG |
2193 | _git_replace () |
2194 | { | |
a31e6262 | 2195 | __gitcomp_nl "$(__git_refs)" |
e1c1a067 BG |
2196 | } |
2197 | ||
67e78c3b SP |
2198 | _git_reset () |
2199 | { | |
d773c631 SG |
2200 | __git_has_doubledash && return |
2201 | ||
b3391775 SP |
2202 | case "$cur" in |
2203 | --*) | |
9f040e95 | 2204 | __gitcomp "--merge --mixed --hard --soft --patch" |
b3391775 SP |
2205 | return |
2206 | ;; | |
2207 | esac | |
a31e6262 | 2208 | __gitcomp_nl "$(__git_refs)" |
67e78c3b SP |
2209 | } |
2210 | ||
a6c2be24 LM |
2211 | _git_revert () |
2212 | { | |
a6c2be24 LM |
2213 | case "$cur" in |
2214 | --*) | |
2215 | __gitcomp "--edit --mainline --no-edit --no-commit --signoff" | |
2216 | return | |
2217 | ;; | |
2218 | esac | |
a31e6262 | 2219 | __gitcomp_nl "$(__git_refs)" |
a6c2be24 LM |
2220 | } |
2221 | ||
08c701d4 LM |
2222 | _git_rm () |
2223 | { | |
08c701d4 LM |
2224 | case "$cur" in |
2225 | --*) | |
2226 | __gitcomp "--cached --dry-run --ignore-unmatch --quiet" | |
2227 | return | |
2228 | ;; | |
2229 | esac | |
fea16b47 MP |
2230 | |
2231 | __git_complete_index_file "--cached" | |
08c701d4 LM |
2232 | } |
2233 | ||
1fd6bec9 SP |
2234 | _git_shortlog () |
2235 | { | |
d773c631 SG |
2236 | __git_has_doubledash && return |
2237 | ||
1fd6bec9 SP |
2238 | case "$cur" in |
2239 | --*) | |
2240 | __gitcomp " | |
a393777e TR |
2241 | $__git_log_common_options |
2242 | $__git_log_shortlog_options | |
1fd6bec9 SP |
2243 | --numbered --summary |
2244 | " | |
2245 | return | |
2246 | ;; | |
2247 | esac | |
2248 | __git_complete_revlist | |
2249 | } | |
2250 | ||
90131924 SP |
2251 | _git_show () |
2252 | { | |
41d8cf7d MH |
2253 | __git_has_doubledash && return |
2254 | ||
90131924 | 2255 | case "$cur" in |
e67d71e5 | 2256 | --pretty=*|--format=*) |
c3898111 | 2257 | __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases) |
e67d71e5 | 2258 | " "" "${cur#*=}" |
72de29c2 TL |
2259 | return |
2260 | ;; | |
07924d4d MP |
2261 | --diff-algorithm=*) |
2262 | __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" | |
2263 | return | |
2264 | ;; | |
90131924 | 2265 | --*) |
076c3237 | 2266 | __gitcomp "--pretty= --format= --abbrev-commit --oneline |
20bf7292 TR |
2267 | $__git_diff_common_options |
2268 | " | |
90131924 SP |
2269 | return |
2270 | ;; | |
2271 | esac | |
5269f7f8 | 2272 | __git_complete_revlist_file |
90131924 SP |
2273 | } |
2274 | ||
2ca880fe TR |
2275 | _git_show_branch () |
2276 | { | |
2ca880fe TR |
2277 | case "$cur" in |
2278 | --*) | |
2279 | __gitcomp " | |
2280 | --all --remotes --topo-order --current --more= | |
2281 | --list --independent --merge-base --no-name | |
6123d719 | 2282 | --color --no-color |
076c3237 | 2283 | --sha1-name --sparse --topics --reflog |
2ca880fe TR |
2284 | " |
2285 | return | |
2286 | ;; | |
2287 | esac | |
2288 | __git_complete_revlist | |
2289 | } | |
2290 | ||
7fd53fce JH |
2291 | _git_stash () |
2292 | { | |
59d5eeee | 2293 | local save_opts='--keep-index --no-keep-index --quiet --patch' |
95d43780 | 2294 | local subcommands='save list show apply clear drop pop create branch' |
918c03c2 | 2295 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
7bedebca | 2296 | if [ -z "$subcommand" ]; then |
59d5eeee SG |
2297 | case "$cur" in |
2298 | --*) | |
2299 | __gitcomp "$save_opts" | |
2300 | ;; | |
2301 | *) | |
2302 | if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then | |
2303 | __gitcomp "$subcommands" | |
59d5eeee SG |
2304 | fi |
2305 | ;; | |
2306 | esac | |
7bedebca | 2307 | else |
7bedebca SG |
2308 | case "$subcommand,$cur" in |
2309 | save,--*) | |
59d5eeee | 2310 | __gitcomp "$save_opts" |
7bedebca | 2311 | ;; |
8513c54b | 2312 | apply,--*|pop,--*) |
59d5eeee | 2313 | __gitcomp "--index --quiet" |
95d43780 | 2314 | ;; |
8513c54b | 2315 | show,--*|drop,--*|branch,--*) |
95d43780 LM |
2316 | ;; |
2317 | show,*|apply,*|drop,*|pop,*|branch,*) | |
a31e6262 | 2318 | __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ |
95d43780 LM |
2319 | | sed -n -e 's/:.*//p')" |
2320 | ;; | |
7bedebca | 2321 | *) |
7bedebca SG |
2322 | ;; |
2323 | esac | |
3ff1320d | 2324 | fi |
7fd53fce JH |
2325 | } |
2326 | ||
be86f7a0 SP |
2327 | _git_submodule () |
2328 | { | |
d773c631 SG |
2329 | __git_has_doubledash && return |
2330 | ||
cf419828 | 2331 | local subcommands="add status init deinit update summary foreach sync" |
918c03c2 | 2332 | if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then |
be86f7a0 SP |
2333 | case "$cur" in |
2334 | --*) | |
2335 | __gitcomp "--quiet --cached" | |
2336 | ;; | |
2337 | *) | |
3ff1320d | 2338 | __gitcomp "$subcommands" |
be86f7a0 SP |
2339 | ;; |
2340 | esac | |
2341 | return | |
2342 | fi | |
2343 | } | |
2344 | ||
47f6ee28 SG |
2345 | _git_svn () |
2346 | { | |
2347 | local subcommands=" | |
2348 | init fetch clone rebase dcommit log find-rev | |
2349 | set-tree commit-diff info create-ignore propget | |
4a5856cb | 2350 | proplist show-ignore show-externals branch tag blame |
c18d5d82 | 2351 | migrate mkdirs reset gc |
47f6ee28 | 2352 | " |
918c03c2 | 2353 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
47f6ee28 SG |
2354 | if [ -z "$subcommand" ]; then |
2355 | __gitcomp "$subcommands" | |
2356 | else | |
2357 | local remote_opts="--username= --config-dir= --no-auth-cache" | |
2358 | local fc_opts=" | |
2359 | --follow-parent --authors-file= --repack= | |
2360 | --no-metadata --use-svm-props --use-svnsync-props | |
2361 | --log-window-size= --no-checkout --quiet | |
4a5856cb | 2362 | --repack-flags --use-log-author --localtime |
a7b10230 | 2363 | --ignore-paths= --include-paths= $remote_opts |
47f6ee28 SG |
2364 | " |
2365 | local init_opts=" | |
2366 | --template= --shared= --trunk= --tags= | |
2367 | --branches= --stdlayout --minimize-url | |
2368 | --no-metadata --use-svm-props --use-svnsync-props | |
4a5856cb SG |
2369 | --rewrite-root= --prefix= --use-log-author |
2370 | --add-author-from $remote_opts | |
47f6ee28 SG |
2371 | " |
2372 | local cmt_opts=" | |
2373 | --edit --rmdir --find-copies-harder --copy-similarity= | |
2374 | " | |
2375 | ||
47f6ee28 SG |
2376 | case "$subcommand,$cur" in |
2377 | fetch,--*) | |
2378 | __gitcomp "--revision= --fetch-all $fc_opts" | |
2379 | ;; | |
2380 | clone,--*) | |
2381 | __gitcomp "--revision= $fc_opts $init_opts" | |
2382 | ;; | |
2383 | init,--*) | |
2384 | __gitcomp "$init_opts" | |
2385 | ;; | |
2386 | dcommit,--*) | |
2387 | __gitcomp " | |
2388 | --merge --strategy= --verbose --dry-run | |
4a5856cb | 2389 | --fetch-all --no-rebase --commit-url |
7b151f49 | 2390 | --revision --interactive $cmt_opts $fc_opts |
47f6ee28 SG |
2391 | " |
2392 | ;; | |
2393 | set-tree,--*) | |
2394 | __gitcomp "--stdin $cmt_opts $fc_opts" | |
2395 | ;; | |
2396 | create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\ | |
c18d5d82 | 2397 | show-externals,--*|mkdirs,--*) |
47f6ee28 SG |
2398 | __gitcomp "--revision=" |
2399 | ;; | |
2400 | log,--*) | |
2401 | __gitcomp " | |
2402 | --limit= --revision= --verbose --incremental | |
2403 | --oneline --show-commit --non-recursive | |
4a5856cb | 2404 | --authors-file= --color |
47f6ee28 SG |
2405 | " |
2406 | ;; | |
2407 | rebase,--*) | |
2408 | __gitcomp " | |
2409 | --merge --verbose --strategy= --local | |
4a5856cb | 2410 | --fetch-all --dry-run $fc_opts |
47f6ee28 SG |
2411 | " |
2412 | ;; | |
2413 | commit-diff,--*) | |
2414 | __gitcomp "--message= --file= --revision= $cmt_opts" | |
2415 | ;; | |
2416 | info,--*) | |
2417 | __gitcomp "--url" | |
2418 | ;; | |
4a5856cb SG |
2419 | branch,--*) |
2420 | __gitcomp "--dry-run --message --tag" | |
2421 | ;; | |
2422 | tag,--*) | |
2423 | __gitcomp "--dry-run --message" | |
2424 | ;; | |
2425 | blame,--*) | |
2426 | __gitcomp "--git-format" | |
2427 | ;; | |
2428 | migrate,--*) | |
2429 | __gitcomp " | |
2430 | --config-dir= --ignore-paths= --minimize | |
2431 | --no-auth-cache --username= | |
2432 | " | |
2433 | ;; | |
c18d5d82 RZ |
2434 | reset,--*) |
2435 | __gitcomp "--revision= --parent" | |
2436 | ;; | |
47f6ee28 | 2437 | *) |
47f6ee28 SG |
2438 | ;; |
2439 | esac | |
2440 | fi | |
2441 | } | |
2442 | ||
88e21dc7 SP |
2443 | _git_tag () |
2444 | { | |
2445 | local i c=1 f=0 | |
da48616f PD |
2446 | while [ $c -lt $cword ]; do |
2447 | i="${words[c]}" | |
88e21dc7 SP |
2448 | case "$i" in |
2449 | -d|-v) | |
a31e6262 | 2450 | __gitcomp_nl "$(__git_tags)" |
88e21dc7 SP |
2451 | return |
2452 | ;; | |
2453 | -f) | |
2454 | f=1 | |
2455 | ;; | |
2456 | esac | |
6e8c755f | 2457 | ((c++)) |
88e21dc7 SP |
2458 | done |
2459 | ||
da48616f | 2460 | case "$prev" in |
88e21dc7 | 2461 | -m|-F) |
88e21dc7 | 2462 | ;; |
8d8163f3 | 2463 | -*|tag) |
88e21dc7 | 2464 | if [ $f = 1 ]; then |
a31e6262 | 2465 | __gitcomp_nl "$(__git_tags)" |
88e21dc7 SP |
2466 | fi |
2467 | ;; | |
2468 | *) | |
a31e6262 | 2469 | __gitcomp_nl "$(__git_refs)" |
88e21dc7 SP |
2470 | ;; |
2471 | esac | |
2472 | } | |
2473 | ||
424cce83 SG |
2474 | _git_whatchanged () |
2475 | { | |
2476 | _git_log | |
2477 | } | |
2478 | ||
93b291e0 | 2479 | __git_main () |
690d8824 | 2480 | { |
873537fa SP |
2481 | local i c=1 command __git_dir |
2482 | ||
da48616f PD |
2483 | while [ $c -lt $cword ]; do |
2484 | i="${words[c]}" | |
873537fa SP |
2485 | case "$i" in |
2486 | --git-dir=*) __git_dir="${i#--git-dir=}" ;; | |
776009d1 | 2487 | --git-dir) ((c++)) ; __git_dir="${words[c]}" ;; |
873537fa | 2488 | --bare) __git_dir="." ;; |
1eb7e2f8 | 2489 | --help) command="help"; break ;; |
776009d1 | 2490 | -c|--work-tree|--namespace) ((c++)) ;; |
911d5da6 | 2491 | -*) ;; |
873537fa SP |
2492 | *) command="$i"; break ;; |
2493 | esac | |
6e8c755f | 2494 | ((c++)) |
873537fa SP |
2495 | done |
2496 | ||
1d17b22e | 2497 | if [ -z "$command" ]; then |
da48616f | 2498 | case "$cur" in |
47e98eec | 2499 | --*) __gitcomp " |
ce5a2c95 | 2500 | --paginate |
47e98eec SP |
2501 | --no-pager |
2502 | --git-dir= | |
2503 | --bare | |
2504 | --version | |
2505 | --exec-path | |
3ffcd086 | 2506 | --exec-path= |
89a56bfb | 2507 | --html-path |
66fb37d0 | 2508 | --man-path |
69ef3c02 | 2509 | --info-path |
ce5a2c95 | 2510 | --work-tree= |
a1bea2c1 | 2511 | --namespace= |
69ef3c02 | 2512 | --no-replace-objects |
ce5a2c95 | 2513 | --help |
47e98eec SP |
2514 | " |
2515 | ;; | |
eaa4e6ee JN |
2516 | *) __git_compute_porcelain_commands |
2517 | __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;; | |
72e5e989 SP |
2518 | esac |
2519 | return | |
873537fa | 2520 | fi |
367dce2a | 2521 | |
424cce83 | 2522 | local completion_func="_git_${command//-/_}" |
06f44c3c | 2523 | declare -f $completion_func >/dev/null && $completion_func && return |
8024ea60 | 2524 | |
873537fa | 2525 | local expansion=$(__git_aliased_command "$command") |
8024ea60 SG |
2526 | if [ -n "$expansion" ]; then |
2527 | completion_func="_git_${expansion//-/_}" | |
06f44c3c | 2528 | declare -f $completion_func >/dev/null && $completion_func |
8024ea60 | 2529 | fi |
690d8824 JH |
2530 | } |
2531 | ||
93b291e0 | 2532 | __gitk_main () |
690d8824 | 2533 | { |
d773c631 SG |
2534 | __git_has_doubledash && return |
2535 | ||
fa26a401 | 2536 | local g="$(__gitdir)" |
07ba53f7 | 2537 | local merge="" |
ba7906f2 | 2538 | if [ -f "$g/MERGE_HEAD" ]; then |
07ba53f7 RQ |
2539 | merge="--merge" |
2540 | fi | |
b3391775 SP |
2541 | case "$cur" in |
2542 | --*) | |
a393777e TR |
2543 | __gitcomp " |
2544 | $__git_log_common_options | |
2545 | $__git_log_gitk_options | |
2546 | $merge | |
2547 | " | |
b3391775 SP |
2548 | return |
2549 | ;; | |
2550 | esac | |
ec804891 | 2551 | __git_complete_revlist |
690d8824 JH |
2552 | } |
2553 | ||
d8b45314 FC |
2554 | if [[ -n ${ZSH_VERSION-} ]]; then |
2555 | echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2 | |
6b179adf | 2556 | |
9cd67bd2 FC |
2557 | autoload -U +X compinit && compinit |
2558 | ||
d8b45314 FC |
2559 | __gitcomp () |
2560 | { | |
2561 | emulate -L zsh | |
6b179adf | 2562 | |
d8b45314 FC |
2563 | local cur_="${3-$cur}" |
2564 | ||
2565 | case "$cur_" in | |
2566 | --*=) | |
2567 | ;; | |
2568 | *) | |
2569 | local c IFS=$' \t\n' | |
2570 | local -a array | |
2571 | for c in ${=1}; do | |
2572 | c="$c${4-}" | |
2573 | case $c in | |
2574 | --*=*|*.) ;; | |
2575 | *) c="$c " ;; | |
2576 | esac | |
5d5812f4 | 2577 | array[${#array[@]}+1]="$c" |
d8b45314 FC |
2578 | done |
2579 | compset -P '*[=:]' | |
2580 | compadd -Q -S '' -p "${2-}" -a -- array && _ret=0 | |
2581 | ;; | |
2582 | esac | |
2583 | } | |
2584 | ||
2585 | __gitcomp_nl () | |
2586 | { | |
2587 | emulate -L zsh | |
2588 | ||
2589 | local IFS=$'\n' | |
2590 | compset -P '*[=:]' | |
2591 | compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 | |
2592 | } | |
2593 | ||
fea16b47 MP |
2594 | __gitcomp_file () |
2595 | { | |
2596 | emulate -L zsh | |
2597 | ||
2598 | local IFS=$'\n' | |
2599 | compset -P '*[=:]' | |
2600 | compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 | |
2601 | } | |
2602 | ||
d8b45314 FC |
2603 | _git () |
2604 | { | |
2bcf694b FC |
2605 | local _ret=1 cur cword prev |
2606 | cur=${words[CURRENT]} | |
2607 | prev=${words[CURRENT-1]} | |
2608 | let cword=CURRENT-1 | |
2609 | emulate ksh -c __${service}_main | |
734b2f05 | 2610 | let _ret && _default && _ret=0 |
d8b45314 FC |
2611 | return _ret |
2612 | } | |
2613 | ||
2614 | compdef _git git gitk | |
2615 | return | |
2616 | fi | |
2617 | ||
2618 | __git_func_wrap () | |
2619 | { | |
6b179adf FC |
2620 | local cur words cword prev |
2621 | _get_comp_words_by_ref -n =: cur words cword prev | |
2622 | $1 | |
2623 | } | |
2624 | ||
2625 | # Setup completion for certain functions defined above by setting common | |
2626 | # variables and workarounds. | |
2627 | # This is NOT a public function; use at your own risk. | |
2628 | __git_complete () | |
2629 | { | |
2630 | local wrapper="__git_wrap${2}" | |
2631 | eval "$wrapper () { __git_func_wrap $2 ; }" | |
2632 | complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \ | |
2633 | || complete -o default -o nospace -F $wrapper $1 | |
2634 | } | |
2635 | ||
b0a4b2d2 FC |
2636 | # wrapper for backwards compatibility |
2637 | _git () | |
2638 | { | |
93b291e0 | 2639 | __git_wrap__git_main |
b0a4b2d2 FC |
2640 | } |
2641 | ||
2642 | # wrapper for backwards compatibility | |
2643 | _gitk () | |
2644 | { | |
93b291e0 | 2645 | __git_wrap__gitk_main |
b0a4b2d2 FC |
2646 | } |
2647 | ||
93b291e0 SG |
2648 | __git_complete git __git_main |
2649 | __git_complete gitk __gitk_main | |
690d8824 JH |
2650 | |
2651 | # The following are necessary only for Cygwin, and only are needed | |
2652 | # when the user has tab-completed the executable name and consequently | |
2653 | # included the '.exe' suffix. | |
2654 | # | |
76c3eb51 | 2655 | if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then |
93b291e0 | 2656 | __git_complete git.exe __git_main |
76c3eb51 | 2657 | fi |