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