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