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