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