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