Commit | Line | Data |
---|---|---|
690d8824 JH |
1 | # |
2 | # bash completion support for core Git. | |
3 | # | |
c70680ce | 4 | # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org> |
690d8824 | 5 | # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). |
c70680ce | 6 | # Distributed under the GNU General Public License, version 2.0. |
690d8824 JH |
7 | # |
8 | # The contained completion routines provide support for completing: | |
9 | # | |
10 | # *) local and remote branch names | |
11 | # *) local and remote tag names | |
12 | # *) .git/remotes file names | |
13 | # *) git 'subcommands' | |
14 | # *) tree paths within 'ref:path/to/file' expressions | |
c70680ce | 15 | # *) common --long-options |
690d8824 JH |
16 | # |
17 | # To use these routines: | |
18 | # | |
19 | # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh). | |
20 | # 2) Added the following line to your .bashrc: | |
21 | # source ~/.git-completion.sh | |
22 | # | |
b51ec6bd SP |
23 | # 3) You may want to make sure the git executable is available |
24 | # in your PATH before this script is sourced, as some caching | |
25 | # is performed while the script loads. If git isn't found | |
26 | # at source time then all lookups will be done on demand, | |
27 | # which may be slightly slower. | |
28 | # | |
29 | # 4) Consider changing your PS1 to also show the current branch: | |
d3d717a4 SP |
30 | # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' |
31 | # | |
32 | # The argument to __git_ps1 will be displayed only if you | |
33 | # are currently in a git repository. The %s token will be | |
34 | # the name of the current branch. | |
35 | # | |
c70680ce SP |
36 | # To submit patches: |
37 | # | |
38 | # *) Read Documentation/SubmittingPatches | |
39 | # *) Send all patches to the current maintainer: | |
40 | # | |
41 | # "Shawn O. Pearce" <spearce@spearce.org> | |
42 | # | |
43 | # *) Always CC the Git mailing list: | |
44 | # | |
45 | # git@vger.kernel.org | |
46 | # | |
690d8824 | 47 | |
db8a9ff0 SP |
48 | case "$COMP_WORDBREAKS" in |
49 | *:*) : great ;; | |
50 | *) COMP_WORDBREAKS="$COMP_WORDBREAKS:" | |
51 | esac | |
52 | ||
873537fa SP |
53 | __gitdir () |
54 | { | |
67ffa114 SP |
55 | if [ -z "$1" ]; then |
56 | if [ -n "$__git_dir" ]; then | |
57 | echo "$__git_dir" | |
58 | elif [ -d .git ]; then | |
59 | echo .git | |
60 | else | |
61 | git rev-parse --git-dir 2>/dev/null | |
62 | fi | |
63 | elif [ -d "$1/.git" ]; then | |
64 | echo "$1/.git" | |
65 | else | |
66 | echo "$1" | |
67 | fi | |
873537fa SP |
68 | } |
69 | ||
d3d717a4 SP |
70 | __git_ps1 () |
71 | { | |
e7520196 RR |
72 | local g="$(git rev-parse --git-dir 2>/dev/null)" |
73 | if [ -n "$g" ]; then | |
74 | local r | |
75 | local b | |
51ef1daa | 76 | if [ -d "$g/rebase-apply" ] |
e7520196 | 77 | then |
51ef1daa | 78 | if test -f "$g/rebase-apply/rebasing" |
3041c324 JH |
79 | then |
80 | r="|REBASE" | |
51ef1daa | 81 | elif test -f "$g/rebase-apply/applying" |
3041c324 JH |
82 | then |
83 | r="|AM" | |
84 | else | |
85 | r="|AM/REBASE" | |
86 | fi | |
e7520196 | 87 | b="$(git symbolic-ref HEAD 2>/dev/null)" |
28ed6e7b | 88 | elif [ -f "$g/rebase-merge/interactive" ] |
e7520196 RR |
89 | then |
90 | r="|REBASE-i" | |
28ed6e7b JS |
91 | b="$(cat "$g/rebase-merge/head-name")" |
92 | elif [ -d "$g/rebase-merge" ] | |
e7520196 RR |
93 | then |
94 | r="|REBASE-m" | |
28ed6e7b | 95 | b="$(cat "$g/rebase-merge/head-name")" |
e7520196 RR |
96 | elif [ -f "$g/MERGE_HEAD" ] |
97 | then | |
98 | r="|MERGING" | |
99 | b="$(git symbolic-ref HEAD 2>/dev/null)" | |
100 | else | |
a5c4f85b | 101 | if [ -f "$g/BISECT_LOG" ] |
e7520196 RR |
102 | then |
103 | r="|BISECTING" | |
104 | fi | |
105 | if ! b="$(git symbolic-ref HEAD 2>/dev/null)" | |
106 | then | |
27c57888 SP |
107 | if ! b="$(git describe --exact-match HEAD 2>/dev/null)" |
108 | then | |
a5c4f85b | 109 | b="$(cut -c1-7 "$g/HEAD")..." |
27c57888 | 110 | fi |
e7520196 RR |
111 | fi |
112 | fi | |
113 | ||
d3d717a4 | 114 | if [ -n "$1" ]; then |
e7520196 | 115 | printf "$1" "${b##refs/heads/}$r" |
d3d717a4 | 116 | else |
e7520196 | 117 | printf " (%s)" "${b##refs/heads/}$r" |
d3d717a4 SP |
118 | fi |
119 | fi | |
120 | } | |
121 | ||
ab02dfe5 SP |
122 | __gitcomp_1 () |
123 | { | |
124 | local c IFS=' '$'\t'$'\n' | |
125 | for c in $1; do | |
126 | case "$c$2" in | |
127 | --*=*) printf %s$'\n' "$c$2" ;; | |
128 | *.) printf %s$'\n' "$c$2" ;; | |
129 | *) printf %s$'\n' "$c$2 " ;; | |
130 | esac | |
131 | done | |
132 | } | |
133 | ||
72e5e989 SP |
134 | __gitcomp () |
135 | { | |
78d4d6a2 | 136 | local cur="${COMP_WORDS[COMP_CWORD]}" |
b3391775 | 137 | if [ $# -gt 2 ]; then |
78d4d6a2 SP |
138 | cur="$3" |
139 | fi | |
5447aac7 SG |
140 | case "$cur" in |
141 | --*=) | |
142 | COMPREPLY=() | |
5447aac7 SG |
143 | ;; |
144 | *) | |
ab02dfe5 SP |
145 | local IFS=$'\n' |
146 | COMPREPLY=($(compgen -P "$2" \ | |
147 | -W "$(__gitcomp_1 "$1" "$4")" \ | |
148 | -- "$cur")) | |
5447aac7 SG |
149 | ;; |
150 | esac | |
72e5e989 SP |
151 | } |
152 | ||
5de40f59 SP |
153 | __git_heads () |
154 | { | |
67ffa114 | 155 | local cmd i is_hash=y dir="$(__gitdir "$1")" |
5de40f59 | 156 | if [ -d "$dir" ]; then |
05e8b3d6 SG |
157 | git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ |
158 | refs/heads | |
5de40f59 SP |
159 | return |
160 | fi | |
799596a5 | 161 | for i in $(git ls-remote "$1" 2>/dev/null); do |
5de40f59 SP |
162 | case "$is_hash,$i" in |
163 | y,*) is_hash=n ;; | |
164 | n,*^{}) is_hash=y ;; | |
165 | n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;; | |
166 | n,*) is_hash=y; echo "$i" ;; | |
167 | esac | |
168 | done | |
169 | } | |
170 | ||
88e21dc7 SP |
171 | __git_tags () |
172 | { | |
173 | local cmd i is_hash=y dir="$(__gitdir "$1")" | |
174 | if [ -d "$dir" ]; then | |
05e8b3d6 SG |
175 | git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ |
176 | refs/tags | |
88e21dc7 SP |
177 | return |
178 | fi | |
799596a5 | 179 | for i in $(git ls-remote "$1" 2>/dev/null); do |
88e21dc7 SP |
180 | case "$is_hash,$i" in |
181 | y,*) is_hash=n ;; | |
182 | n,*^{}) is_hash=y ;; | |
183 | n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;; | |
184 | n,*) is_hash=y; echo "$i" ;; | |
185 | esac | |
186 | done | |
187 | } | |
188 | ||
690d8824 JH |
189 | __git_refs () |
190 | { | |
67ffa114 | 191 | local cmd i is_hash=y dir="$(__gitdir "$1")" |
873537fa | 192 | if [ -d "$dir" ]; then |
35e65ecc | 193 | if [ -e "$dir/HEAD" ]; then echo HEAD; fi |
05e8b3d6 SG |
194 | git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ |
195 | refs/tags refs/heads refs/remotes | |
35e65ecc | 196 | return |
690d8824 | 197 | fi |
799596a5 | 198 | for i in $(git ls-remote "$dir" 2>/dev/null); do |
690d8824 JH |
199 | case "$is_hash,$i" in |
200 | y,*) is_hash=n ;; | |
201 | n,*^{}) is_hash=y ;; | |
202 | n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;; | |
203 | n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;; | |
35e65ecc | 204 | n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;; |
690d8824 JH |
205 | n,*) is_hash=y; echo "$i" ;; |
206 | esac | |
207 | done | |
208 | } | |
209 | ||
210 | __git_refs2 () | |
211 | { | |
67ffa114 SP |
212 | local i |
213 | for i in $(__git_refs "$1"); do | |
214 | echo "$i:$i" | |
690d8824 JH |
215 | done |
216 | } | |
217 | ||
5de40f59 SP |
218 | __git_refs_remotes () |
219 | { | |
220 | local cmd i is_hash=y | |
799596a5 | 221 | for i in $(git ls-remote "$1" 2>/dev/null); do |
5de40f59 SP |
222 | case "$is_hash,$i" in |
223 | n,refs/heads/*) | |
224 | is_hash=y | |
225 | echo "$i:refs/remotes/$1/${i#refs/heads/}" | |
226 | ;; | |
227 | y,*) is_hash=n ;; | |
228 | n,*^{}) is_hash=y ;; | |
229 | n,refs/tags/*) is_hash=y;; | |
230 | n,*) is_hash=y; ;; | |
231 | esac | |
232 | done | |
233 | } | |
234 | ||
690d8824 JH |
235 | __git_remotes () |
236 | { | |
873537fa | 237 | local i ngoff IFS=$'\n' d="$(__gitdir)" |
56fc25f2 | 238 | shopt -q nullglob || ngoff=1 |
690d8824 | 239 | shopt -s nullglob |
873537fa SP |
240 | for i in "$d/remotes"/*; do |
241 | echo ${i#$d/remotes/} | |
690d8824 | 242 | done |
56fc25f2 | 243 | [ "$ngoff" ] && shopt -u nullglob |
e0d10e1c | 244 | for i in $(git --git-dir="$d" config --list); do |
56fc25f2 SP |
245 | case "$i" in |
246 | remote.*.url=*) | |
247 | i="${i#remote.}" | |
248 | echo "${i/.url=*/}" | |
249 | ;; | |
250 | esac | |
251 | done | |
690d8824 JH |
252 | } |
253 | ||
4ad91321 SP |
254 | __git_merge_strategies () |
255 | { | |
b51ec6bd SP |
256 | if [ -n "$__git_merge_strategylist" ]; then |
257 | echo "$__git_merge_strategylist" | |
258 | return | |
259 | fi | |
25b3d4d6 JH |
260 | git merge -s help 2>&1 | |
261 | sed -n -e '/[Aa]vailable strategies are: /,/^$/{ | |
262 | s/\.$// | |
263 | s/.*:// | |
264 | s/^[ ]*// | |
265 | s/[ ]*$// | |
4ad91321 | 266 | p |
25b3d4d6 | 267 | }' |
4ad91321 | 268 | } |
b51ec6bd | 269 | __git_merge_strategylist= |
25b3d4d6 | 270 | __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null) |
4ad91321 | 271 | |
690d8824 JH |
272 | __git_complete_file () |
273 | { | |
a79c6551 | 274 | local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}" |
690d8824 JH |
275 | case "$cur" in |
276 | ?*:*) | |
a79c6551 SP |
277 | ref="${cur%%:*}" |
278 | cur="${cur#*:}" | |
690d8824 JH |
279 | case "$cur" in |
280 | ?*/*) | |
a79c6551 SP |
281 | pfx="${cur%/*}" |
282 | cur="${cur##*/}" | |
690d8824 JH |
283 | ls="$ref:$pfx" |
284 | pfx="$pfx/" | |
285 | ;; | |
286 | *) | |
287 | ls="$ref" | |
288 | ;; | |
289 | esac | |
db8a9ff0 SP |
290 | |
291 | case "$COMP_WORDBREAKS" in | |
292 | *:*) : great ;; | |
293 | *) pfx="$ref:$pfx" ;; | |
294 | esac | |
295 | ||
778306e4 | 296 | local IFS=$'\n' |
690d8824 | 297 | COMPREPLY=($(compgen -P "$pfx" \ |
873537fa | 298 | -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \ |
778306e4 SP |
299 | | sed '/^100... blob /{ |
300 | s,^.* ,, | |
301 | s,$, , | |
302 | } | |
303 | /^120000 blob /{ | |
304 | s,^.* ,, | |
305 | s,$, , | |
306 | } | |
690d8824 JH |
307 | /^040000 tree /{ |
308 | s,^.* ,, | |
309 | s,$,/, | |
310 | } | |
311 | s/^.* //')" \ | |
312 | -- "$cur")) | |
313 | ;; | |
314 | *) | |
b3391775 | 315 | __gitcomp "$(__git_refs)" |
690d8824 JH |
316 | ;; |
317 | esac | |
318 | } | |
319 | ||
f53352fb SP |
320 | __git_complete_revlist () |
321 | { | |
322 | local pfx cur="${COMP_WORDS[COMP_CWORD]}" | |
323 | case "$cur" in | |
324 | *...*) | |
325 | pfx="${cur%...*}..." | |
326 | cur="${cur#*...}" | |
b3391775 | 327 | __gitcomp "$(__git_refs)" "$pfx" "$cur" |
f53352fb SP |
328 | ;; |
329 | *..*) | |
330 | pfx="${cur%..*}.." | |
331 | cur="${cur#*..}" | |
b3391775 SP |
332 | __gitcomp "$(__git_refs)" "$pfx" "$cur" |
333 | ;; | |
f53352fb | 334 | *) |
b3391775 | 335 | __gitcomp "$(__git_refs)" |
f53352fb SP |
336 | ;; |
337 | esac | |
338 | } | |
339 | ||
1eb7e2f8 | 340 | __git_all_commands () |
f2bb9f88 | 341 | { |
1eb7e2f8 LM |
342 | if [ -n "$__git_all_commandlist" ]; then |
343 | echo "$__git_all_commandlist" | |
b51ec6bd SP |
344 | return |
345 | fi | |
f2bb9f88 SP |
346 | local i IFS=" "$'\n' |
347 | for i in $(git help -a|egrep '^ ') | |
1eb7e2f8 LM |
348 | do |
349 | case $i in | |
350 | *--*) : helper pattern;; | |
351 | *) echo $i;; | |
352 | esac | |
353 | done | |
354 | } | |
355 | __git_all_commandlist= | |
356 | __git_all_commandlist="$(__git_all_commands 2>/dev/null)" | |
357 | ||
358 | __git_porcelain_commands () | |
359 | { | |
360 | if [ -n "$__git_porcelain_commandlist" ]; then | |
361 | echo "$__git_porcelain_commandlist" | |
362 | return | |
363 | fi | |
364 | local i IFS=" "$'\n' | |
365 | for i in "help" $(__git_all_commands) | |
f2bb9f88 SP |
366 | do |
367 | case $i in | |
718a087a | 368 | *--*) : helper pattern;; |
a925c6f1 SP |
369 | applymbox) : ask gittus;; |
370 | applypatch) : ask gittus;; | |
371 | archimport) : import;; | |
2e3a430a | 372 | cat-file) : plumbing;; |
56d99c67 | 373 | check-attr) : plumbing;; |
f2bb9f88 | 374 | check-ref-format) : plumbing;; |
ff2549dc | 375 | checkout-index) : plumbing;; |
f2bb9f88 | 376 | commit-tree) : plumbing;; |
ff2549dc | 377 | count-objects) : infrequent;; |
a925c6f1 SP |
378 | cvsexportcommit) : export;; |
379 | cvsimport) : import;; | |
f2bb9f88 SP |
380 | cvsserver) : daemon;; |
381 | daemon) : daemon;; | |
5cfb4fe5 SP |
382 | diff-files) : plumbing;; |
383 | diff-index) : plumbing;; | |
384 | diff-tree) : plumbing;; | |
c6ec3b13 | 385 | fast-import) : import;; |
ff2549dc | 386 | fast-export) : export;; |
a925c6f1 | 387 | fsck-objects) : plumbing;; |
f2bb9f88 | 388 | fetch-pack) : plumbing;; |
a925c6f1 | 389 | fmt-merge-msg) : plumbing;; |
56d99c67 | 390 | for-each-ref) : plumbing;; |
f2bb9f88 SP |
391 | hash-object) : plumbing;; |
392 | http-*) : transport;; | |
393 | index-pack) : plumbing;; | |
a925c6f1 | 394 | init-db) : deprecated;; |
f2bb9f88 | 395 | local-fetch) : plumbing;; |
ff2549dc PB |
396 | lost-found) : infrequent;; |
397 | ls-files) : plumbing;; | |
398 | ls-remote) : plumbing;; | |
399 | ls-tree) : plumbing;; | |
f2bb9f88 SP |
400 | mailinfo) : plumbing;; |
401 | mailsplit) : plumbing;; | |
402 | merge-*) : plumbing;; | |
403 | mktree) : plumbing;; | |
404 | mktag) : plumbing;; | |
405 | pack-objects) : plumbing;; | |
406 | pack-redundant) : plumbing;; | |
407 | pack-refs) : plumbing;; | |
408 | parse-remote) : plumbing;; | |
409 | patch-id) : plumbing;; | |
410 | peek-remote) : plumbing;; | |
a925c6f1 SP |
411 | prune) : plumbing;; |
412 | prune-packed) : plumbing;; | |
413 | quiltimport) : import;; | |
f2bb9f88 SP |
414 | read-tree) : plumbing;; |
415 | receive-pack) : plumbing;; | |
2e3a430a | 416 | reflog) : plumbing;; |
5c66d0d4 | 417 | repo-config) : deprecated;; |
f2bb9f88 SP |
418 | rerere) : plumbing;; |
419 | rev-list) : plumbing;; | |
420 | rev-parse) : plumbing;; | |
421 | runstatus) : plumbing;; | |
422 | sh-setup) : internal;; | |
423 | shell) : daemon;; | |
ff2549dc | 424 | show-ref) : plumbing;; |
f2bb9f88 SP |
425 | send-pack) : plumbing;; |
426 | show-index) : plumbing;; | |
427 | ssh-*) : transport;; | |
428 | stripspace) : plumbing;; | |
429 | symbolic-ref) : plumbing;; | |
a925c6f1 | 430 | tar-tree) : deprecated;; |
f2bb9f88 SP |
431 | unpack-file) : plumbing;; |
432 | unpack-objects) : plumbing;; | |
a925c6f1 | 433 | update-index) : plumbing;; |
f2bb9f88 SP |
434 | update-ref) : plumbing;; |
435 | update-server-info) : daemon;; | |
436 | upload-archive) : plumbing;; | |
437 | upload-pack) : plumbing;; | |
438 | write-tree) : plumbing;; | |
ff2549dc PB |
439 | var) : infrequent;; |
440 | verify-pack) : infrequent;; | |
a925c6f1 | 441 | verify-tag) : plumbing;; |
f2bb9f88 SP |
442 | *) echo $i;; |
443 | esac | |
444 | done | |
445 | } | |
1eb7e2f8 LM |
446 | __git_porcelain_commandlist= |
447 | __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)" | |
f2bb9f88 | 448 | |
367dce2a DS |
449 | __git_aliases () |
450 | { | |
56fc25f2 | 451 | local i IFS=$'\n' |
e0d10e1c | 452 | for i in $(git --git-dir="$(__gitdir)" config --list); do |
56fc25f2 SP |
453 | case "$i" in |
454 | alias.*) | |
455 | i="${i#alias.}" | |
456 | echo "${i/=*/}" | |
457 | ;; | |
458 | esac | |
459 | done | |
367dce2a DS |
460 | } |
461 | ||
462 | __git_aliased_command () | |
463 | { | |
873537fa | 464 | local word cmdline=$(git --git-dir="$(__gitdir)" \ |
e0d10e1c | 465 | config --get "alias.$1") |
367dce2a DS |
466 | for word in $cmdline; do |
467 | if [ "${word##-*}" ]; then | |
468 | echo $word | |
469 | return | |
470 | fi | |
471 | done | |
472 | } | |
473 | ||
3ff1320d SG |
474 | __git_find_subcommand () |
475 | { | |
476 | local word subcommand c=1 | |
477 | ||
478 | while [ $c -lt $COMP_CWORD ]; do | |
479 | word="${COMP_WORDS[c]}" | |
480 | for subcommand in $1; do | |
481 | if [ "$subcommand" = "$word" ]; then | |
482 | echo "$subcommand" | |
483 | return | |
484 | fi | |
485 | done | |
486 | c=$((++c)) | |
487 | done | |
488 | } | |
489 | ||
d773c631 SG |
490 | __git_has_doubledash () |
491 | { | |
492 | local c=1 | |
493 | while [ $c -lt $COMP_CWORD ]; do | |
494 | if [ "--" = "${COMP_WORDS[c]}" ]; then | |
495 | return 0 | |
496 | fi | |
497 | c=$((++c)) | |
498 | done | |
499 | return 1 | |
500 | } | |
501 | ||
7950659d | 502 | __git_whitespacelist="nowarn warn error error-all fix" |
88329195 SP |
503 | |
504 | _git_am () | |
505 | { | |
28ed6e7b | 506 | local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)" |
51ef1daa | 507 | if [ -d "$dir"/rebase-apply ]; then |
a31c00b0 | 508 | __gitcomp "--skip --resolved --abort" |
88329195 SP |
509 | return |
510 | fi | |
511 | case "$cur" in | |
512 | --whitespace=*) | |
b3391775 | 513 | __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" |
88329195 SP |
514 | return |
515 | ;; | |
516 | --*) | |
b3391775 | 517 | __gitcomp " |
88329195 SP |
518 | --signoff --utf8 --binary --3way --interactive |
519 | --whitespace= | |
b3391775 | 520 | " |
88329195 SP |
521 | return |
522 | esac | |
523 | COMPREPLY=() | |
524 | } | |
525 | ||
526 | _git_apply () | |
527 | { | |
528 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
529 | case "$cur" in | |
530 | --whitespace=*) | |
b3391775 | 531 | __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" |
88329195 SP |
532 | return |
533 | ;; | |
534 | --*) | |
b3391775 | 535 | __gitcomp " |
88329195 SP |
536 | --stat --numstat --summary --check --index |
537 | --cached --index-info --reverse --reject --unidiff-zero | |
538 | --apply --no-add --exclude= | |
539 | --whitespace= --inaccurate-eof --verbose | |
b3391775 | 540 | " |
88329195 SP |
541 | return |
542 | esac | |
543 | COMPREPLY=() | |
544 | } | |
545 | ||
8435b548 SP |
546 | _git_add () |
547 | { | |
d773c631 SG |
548 | __git_has_doubledash && return |
549 | ||
8435b548 SP |
550 | local cur="${COMP_WORDS[COMP_CWORD]}" |
551 | case "$cur" in | |
552 | --*) | |
1d284cba SG |
553 | __gitcomp " |
554 | --interactive --refresh --patch --update --dry-run | |
555 | --ignore-errors | |
556 | " | |
8435b548 SP |
557 | return |
558 | esac | |
559 | COMPREPLY=() | |
560 | } | |
561 | ||
b3191ce2 LM |
562 | _git_archive () |
563 | { | |
564 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
565 | case "$cur" in | |
566 | --format=*) | |
567 | __gitcomp "$(git archive --list)" "" "${cur##--format=}" | |
568 | return | |
569 | ;; | |
570 | --remote=*) | |
571 | __gitcomp "$(__git_remotes)" "" "${cur##--remote=}" | |
572 | return | |
573 | ;; | |
574 | --*) | |
575 | __gitcomp " | |
576 | --format= --list --verbose | |
577 | --prefix= --remote= --exec= | |
578 | " | |
579 | return | |
580 | ;; | |
581 | esac | |
582 | __git_complete_file | |
583 | } | |
584 | ||
b2e69f62 SP |
585 | _git_bisect () |
586 | { | |
d773c631 SG |
587 | __git_has_doubledash && return |
588 | ||
bf11d461 | 589 | local subcommands="start bad good skip reset visualize replay log run" |
3ff1320d SG |
590 | local subcommand="$(__git_find_subcommand "$subcommands")" |
591 | if [ -z "$subcommand" ]; then | |
592 | __gitcomp "$subcommands" | |
b2e69f62 SP |
593 | return |
594 | fi | |
595 | ||
3ff1320d | 596 | case "$subcommand" in |
bf11d461 | 597 | bad|good|reset|skip) |
b2e69f62 SP |
598 | __gitcomp "$(__git_refs)" |
599 | ;; | |
600 | *) | |
601 | COMPREPLY=() | |
602 | ;; | |
603 | esac | |
604 | } | |
605 | ||
690d8824 JH |
606 | _git_branch () |
607 | { | |
b9217642 SG |
608 | local i c=1 only_local_ref="n" has_r="n" |
609 | ||
610 | while [ $c -lt $COMP_CWORD ]; do | |
611 | i="${COMP_WORDS[c]}" | |
612 | case "$i" in | |
613 | -d|-m) only_local_ref="y" ;; | |
614 | -r) has_r="y" ;; | |
615 | esac | |
616 | c=$((++c)) | |
617 | done | |
618 | ||
3b376b0c SG |
619 | case "${COMP_WORDS[COMP_CWORD]}" in |
620 | --*=*) COMPREPLY=() ;; | |
621 | --*) | |
622 | __gitcomp " | |
623 | --color --no-color --verbose --abbrev= --no-abbrev | |
50e61025 | 624 | --track --no-track --contains --merged --no-merged |
3b376b0c SG |
625 | " |
626 | ;; | |
b9217642 SG |
627 | *) |
628 | if [ $only_local_ref = "y" -a $has_r = "n" ]; then | |
629 | __gitcomp "$(__git_heads)" | |
630 | else | |
631 | __gitcomp "$(__git_refs)" | |
632 | fi | |
633 | ;; | |
3b376b0c | 634 | esac |
690d8824 JH |
635 | } |
636 | ||
374a58c9 ML |
637 | _git_bundle () |
638 | { | |
639 | local mycword="$COMP_CWORD" | |
640 | case "${COMP_WORDS[0]}" in | |
641 | git) | |
642 | local cmd="${COMP_WORDS[2]}" | |
643 | mycword="$((mycword-1))" | |
644 | ;; | |
645 | git-bundle*) | |
646 | local cmd="${COMP_WORDS[1]}" | |
647 | ;; | |
648 | esac | |
649 | case "$mycword" in | |
650 | 1) | |
651 | __gitcomp "create list-heads verify unbundle" | |
652 | ;; | |
653 | 2) | |
654 | # looking for a file | |
655 | ;; | |
656 | *) | |
657 | case "$cmd" in | |
658 | create) | |
659 | __git_complete_revlist | |
660 | ;; | |
661 | esac | |
662 | ;; | |
663 | esac | |
664 | } | |
665 | ||
690d8824 JH |
666 | _git_checkout () |
667 | { | |
c84bb14c SG |
668 | __git_has_doubledash && return |
669 | ||
b3391775 | 670 | __gitcomp "$(__git_refs)" |
690d8824 JH |
671 | } |
672 | ||
d8a9fea5 SP |
673 | _git_cherry () |
674 | { | |
675 | __gitcomp "$(__git_refs)" | |
676 | } | |
677 | ||
1273231e SP |
678 | _git_cherry_pick () |
679 | { | |
680 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
681 | case "$cur" in | |
682 | --*) | |
b3391775 | 683 | __gitcomp "--edit --no-commit" |
1273231e SP |
684 | ;; |
685 | *) | |
b3391775 | 686 | __gitcomp "$(__git_refs)" |
1273231e SP |
687 | ;; |
688 | esac | |
689 | } | |
690 | ||
4181c7e8 LM |
691 | _git_clean () |
692 | { | |
693 | __git_has_doubledash && return | |
694 | ||
695 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
696 | case "$cur" in | |
697 | --*) | |
698 | __gitcomp "--dry-run --quiet" | |
699 | return | |
700 | ;; | |
701 | esac | |
702 | COMPREPLY=() | |
703 | } | |
704 | ||
3eb11012 LM |
705 | _git_clone () |
706 | { | |
707 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
708 | case "$cur" in | |
709 | --*) | |
710 | __gitcomp " | |
711 | --local | |
712 | --no-hardlinks | |
713 | --shared | |
714 | --reference | |
715 | --quiet | |
716 | --no-checkout | |
717 | --bare | |
718 | --mirror | |
719 | --origin | |
720 | --upload-pack | |
721 | --template= | |
722 | --depth | |
723 | " | |
724 | return | |
725 | ;; | |
726 | esac | |
727 | COMPREPLY=() | |
728 | } | |
729 | ||
4548e855 SP |
730 | _git_commit () |
731 | { | |
d773c631 SG |
732 | __git_has_doubledash && return |
733 | ||
4548e855 SP |
734 | local cur="${COMP_WORDS[COMP_CWORD]}" |
735 | case "$cur" in | |
736 | --*) | |
b3391775 | 737 | __gitcomp " |
4548e855 | 738 | --all --author= --signoff --verify --no-verify |
aa5735be | 739 | --edit --amend --include --only --interactive |
b3391775 | 740 | " |
4548e855 SP |
741 | return |
742 | esac | |
743 | COMPREPLY=() | |
744 | } | |
745 | ||
217926c0 SP |
746 | _git_describe () |
747 | { | |
cbb504c9 TR |
748 | local cur="${COMP_WORDS[COMP_CWORD]}" |
749 | case "$cur" in | |
750 | --*) | |
751 | __gitcomp " | |
752 | --all --tags --contains --abbrev= --candidates= | |
753 | --exact-match --debug --long --match --always | |
754 | " | |
755 | return | |
756 | esac | |
217926c0 SP |
757 | __gitcomp "$(__git_refs)" |
758 | } | |
759 | ||
690d8824 JH |
760 | _git_diff () |
761 | { | |
d773c631 SG |
762 | __git_has_doubledash && return |
763 | ||
b3a4f858 JS |
764 | local cur="${COMP_WORDS[COMP_CWORD]}" |
765 | case "$cur" in | |
766 | --*) | |
767 | __gitcomp "--cached --stat --numstat --shortstat --summary | |
768 | --patch-with-stat --name-only --name-status --color | |
769 | --no-color --color-words --no-renames --check | |
f135aacb | 770 | --full-index --binary --abbrev --diff-filter= |
b3a4f858 JS |
771 | --find-copies-harder --pickaxe-all --pickaxe-regex |
772 | --text --ignore-space-at-eol --ignore-space-change | |
773 | --ignore-all-space --exit-code --quiet --ext-diff | |
aba201c6 PO |
774 | --no-ext-diff |
775 | --no-prefix --src-prefix= --dst-prefix= | |
f4574139 | 776 | --base --ours --theirs |
aba201c6 | 777 | " |
b3a4f858 JS |
778 | return |
779 | ;; | |
780 | esac | |
690d8824 JH |
781 | __git_complete_file |
782 | } | |
783 | ||
690d8824 JH |
784 | _git_fetch () |
785 | { | |
786 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
787 | ||
5a625b07 | 788 | if [ "$COMP_CWORD" = 2 ]; then |
b3391775 | 789 | __gitcomp "$(__git_remotes)" |
5a625b07 | 790 | else |
690d8824 JH |
791 | case "$cur" in |
792 | *:*) | |
db8a9ff0 SP |
793 | local pfx="" |
794 | case "$COMP_WORDBREAKS" in | |
795 | *:*) : great ;; | |
796 | *) pfx="${cur%%:*}:" ;; | |
797 | esac | |
798 | __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}" | |
690d8824 JH |
799 | ;; |
800 | *) | |
801 | local remote | |
802 | case "${COMP_WORDS[0]}" in | |
803 | git-fetch) remote="${COMP_WORDS[1]}" ;; | |
804 | git) remote="${COMP_WORDS[2]}" ;; | |
805 | esac | |
b3391775 | 806 | __gitcomp "$(__git_refs2 "$remote")" |
690d8824 JH |
807 | ;; |
808 | esac | |
5a625b07 | 809 | fi |
690d8824 JH |
810 | } |
811 | ||
f53352fb SP |
812 | _git_format_patch () |
813 | { | |
814 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
815 | case "$cur" in | |
816 | --*) | |
b3391775 | 817 | __gitcomp " |
f53352fb SP |
818 | --stdout --attach --thread |
819 | --output-directory | |
820 | --numbered --start-number | |
47e98eec | 821 | --numbered-files |
f53352fb SP |
822 | --keep-subject |
823 | --signoff | |
824 | --in-reply-to= | |
825 | --full-index --binary | |
ec804891 | 826 | --not --all |
be5f5bf0 | 827 | --cover-letter |
aba201c6 | 828 | --no-prefix --src-prefix= --dst-prefix= |
b3391775 | 829 | " |
f53352fb SP |
830 | return |
831 | ;; | |
832 | esac | |
833 | __git_complete_revlist | |
834 | } | |
835 | ||
b26c8748 SP |
836 | _git_gc () |
837 | { | |
838 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
839 | case "$cur" in | |
840 | --*) | |
47e98eec | 841 | __gitcomp "--prune --aggressive" |
b26c8748 SP |
842 | return |
843 | ;; | |
844 | esac | |
845 | COMPREPLY=() | |
846 | } | |
847 | ||
c72e0db1 LM |
848 | _git_grep () |
849 | { | |
850 | __git_has_doubledash && return | |
851 | ||
852 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
853 | case "$cur" in | |
854 | --*) | |
855 | __gitcomp " | |
856 | --cached | |
857 | --text --ignore-case --word-regexp --invert-match | |
858 | --full-name | |
859 | --extended-regexp --basic-regexp --fixed-strings | |
860 | --files-with-matches --name-only | |
861 | --files-without-match | |
862 | --count | |
863 | --and --or --not --all-match | |
864 | " | |
865 | return | |
866 | ;; | |
867 | esac | |
868 | COMPREPLY=() | |
869 | } | |
870 | ||
1eb7e2f8 LM |
871 | _git_help () |
872 | { | |
873 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
874 | case "$cur" in | |
875 | --*) | |
876 | __gitcomp "--all --info --man --web" | |
877 | return | |
878 | ;; | |
879 | esac | |
2946cccf MG |
880 | __gitcomp "$(__git_all_commands) |
881 | attributes cli core-tutorial cvs-migration | |
882 | diffcore gitk glossary hooks ignore modules | |
883 | repository-layout tutorial tutorial-2 | |
99f0b599 | 884 | workflows |
2946cccf | 885 | " |
1eb7e2f8 LM |
886 | } |
887 | ||
5dad868b LM |
888 | _git_init () |
889 | { | |
890 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
891 | case "$cur" in | |
892 | --shared=*) | |
893 | __gitcomp " | |
894 | false true umask group all world everybody | |
895 | " "" "${cur##--shared=}" | |
896 | return | |
897 | ;; | |
898 | --*) | |
899 | __gitcomp "--quiet --bare --template= --shared --shared=" | |
900 | return | |
901 | ;; | |
902 | esac | |
903 | COMPREPLY=() | |
904 | } | |
905 | ||
b1bc1494 LM |
906 | _git_ls_files () |
907 | { | |
908 | __git_has_doubledash && return | |
909 | ||
910 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
911 | case "$cur" in | |
912 | --*) | |
913 | __gitcomp "--cached --deleted --modified --others --ignored | |
914 | --stage --directory --no-empty-directory --unmerged | |
915 | --killed --exclude= --exclude-from= | |
916 | --exclude-per-directory= --exclude-standard | |
917 | --error-unmatch --with-tree= --full-name | |
918 | --abbrev --ignored --exclude-per-directory | |
919 | " | |
920 | return | |
921 | ;; | |
922 | esac | |
923 | COMPREPLY=() | |
924 | } | |
925 | ||
690d8824 JH |
926 | _git_ls_remote () |
927 | { | |
b3391775 | 928 | __gitcomp "$(__git_remotes)" |
690d8824 JH |
929 | } |
930 | ||
931 | _git_ls_tree () | |
932 | { | |
933 | __git_complete_file | |
934 | } | |
935 | ||
936 | _git_log () | |
937 | { | |
d773c631 SG |
938 | __git_has_doubledash && return |
939 | ||
6e31b866 SP |
940 | local cur="${COMP_WORDS[COMP_CWORD]}" |
941 | case "$cur" in | |
942 | --pretty=*) | |
b3391775 | 943 | __gitcomp " |
6e31b866 | 944 | oneline short medium full fuller email raw |
b3391775 | 945 | " "" "${cur##--pretty=}" |
6e31b866 SP |
946 | return |
947 | ;; | |
47e98eec SP |
948 | --date=*) |
949 | __gitcomp " | |
950 | relative iso8601 rfc2822 short local default | |
951 | " "" "${cur##--date=}" | |
952 | return | |
953 | ;; | |
6e31b866 | 954 | --*) |
b3391775 | 955 | __gitcomp " |
6e31b866 SP |
956 | --max-count= --max-age= --since= --after= |
957 | --min-age= --before= --until= | |
8f87fae6 | 958 | --root --topo-order --date-order --reverse |
47e98eec | 959 | --no-merges --follow |
6e31b866 | 960 | --abbrev-commit --abbrev= |
47e98eec | 961 | --relative-date --date= |
6e31b866 SP |
962 | --author= --committer= --grep= |
963 | --all-match | |
8f87fae6 | 964 | --pretty= --name-status --name-only --raw |
ec804891 | 965 | --not --all |
7d37b5bf | 966 | --left-right --cherry-pick |
20827d99 | 967 | --graph |
66aafad5 TL |
968 | --stat --numstat --shortstat |
969 | --decorate --diff-filter= | |
970 | --color-words --walk-reflogs | |
e49b99a6 | 971 | --parents --children --full-history |
5a13c8f6 | 972 | --merge |
b3391775 | 973 | " |
6e31b866 SP |
974 | return |
975 | ;; | |
976 | esac | |
f53352fb | 977 | __git_complete_revlist |
690d8824 JH |
978 | } |
979 | ||
4ad91321 SP |
980 | _git_merge () |
981 | { | |
982 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
ce1e39d2 SP |
983 | case "${COMP_WORDS[COMP_CWORD-1]}" in |
984 | -s|--strategy) | |
b3391775 | 985 | __gitcomp "$(__git_merge_strategies)" |
ce1e39d2 SP |
986 | return |
987 | esac | |
4ad91321 | 988 | case "$cur" in |
ce1e39d2 | 989 | --strategy=*) |
b3391775 | 990 | __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}" |
ce1e39d2 SP |
991 | return |
992 | ;; | |
4ad91321 | 993 | --*) |
b3391775 | 994 | __gitcomp " |
efb779f8 | 995 | --no-commit --no-stat --log --no-log --squash --strategy |
b3391775 | 996 | " |
4ad91321 SP |
997 | return |
998 | esac | |
b3391775 | 999 | __gitcomp "$(__git_refs)" |
4ad91321 SP |
1000 | } |
1001 | ||
b4c72162 LM |
1002 | _git_mergetool () |
1003 | { | |
1004 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1005 | case "$cur" in | |
1006 | --tool=*) | |
1007 | __gitcomp " | |
1008 | kdiff3 tkdiff meld xxdiff emerge | |
1009 | vimdiff gvimdiff ecmerge opendiff | |
1010 | " "" "${cur##--tool=}" | |
1011 | return | |
1012 | ;; | |
1013 | --*) | |
1014 | __gitcomp "--tool=" | |
1015 | return | |
1016 | ;; | |
1017 | esac | |
1018 | COMPREPLY=() | |
1019 | } | |
1020 | ||
690d8824 JH |
1021 | _git_merge_base () |
1022 | { | |
b3391775 | 1023 | __gitcomp "$(__git_refs)" |
690d8824 JH |
1024 | } |
1025 | ||
1127c51c LM |
1026 | _git_mv () |
1027 | { | |
1028 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1029 | case "$cur" in | |
1030 | --*) | |
1031 | __gitcomp "--dry-run" | |
1032 | return | |
1033 | ;; | |
1034 | esac | |
1035 | COMPREPLY=() | |
1036 | } | |
1037 | ||
d33909bf SP |
1038 | _git_name_rev () |
1039 | { | |
b3391775 | 1040 | __gitcomp "--tags --all --stdin" |
d33909bf SP |
1041 | } |
1042 | ||
690d8824 JH |
1043 | _git_pull () |
1044 | { | |
1045 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1046 | ||
5a625b07 | 1047 | if [ "$COMP_CWORD" = 2 ]; then |
b3391775 | 1048 | __gitcomp "$(__git_remotes)" |
5a625b07 | 1049 | else |
690d8824 JH |
1050 | local remote |
1051 | case "${COMP_WORDS[0]}" in | |
1052 | git-pull) remote="${COMP_WORDS[1]}" ;; | |
1053 | git) remote="${COMP_WORDS[2]}" ;; | |
1054 | esac | |
b3391775 | 1055 | __gitcomp "$(__git_refs "$remote")" |
5a625b07 | 1056 | fi |
690d8824 JH |
1057 | } |
1058 | ||
1059 | _git_push () | |
1060 | { | |
1061 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1062 | ||
5a625b07 | 1063 | if [ "$COMP_CWORD" = 2 ]; then |
b3391775 | 1064 | __gitcomp "$(__git_remotes)" |
5a625b07 | 1065 | else |
690d8824 JH |
1066 | case "$cur" in |
1067 | *:*) | |
1068 | local remote | |
1069 | case "${COMP_WORDS[0]}" in | |
1070 | git-push) remote="${COMP_WORDS[1]}" ;; | |
1071 | git) remote="${COMP_WORDS[2]}" ;; | |
1072 | esac | |
db8a9ff0 SP |
1073 | |
1074 | local pfx="" | |
1075 | case "$COMP_WORDBREAKS" in | |
1076 | *:*) : great ;; | |
1077 | *) pfx="${cur%%:*}:" ;; | |
1078 | esac | |
1079 | ||
1080 | __gitcomp "$(__git_refs "$remote")" "$pfx" "${cur#*:}" | |
690d8824 | 1081 | ;; |
161fea83 SP |
1082 | +*) |
1083 | __gitcomp "$(__git_refs)" + "${cur#+}" | |
1084 | ;; | |
690d8824 | 1085 | *) |
92d7c8e3 | 1086 | __gitcomp "$(__git_refs)" |
690d8824 JH |
1087 | ;; |
1088 | esac | |
5a625b07 | 1089 | fi |
690d8824 JH |
1090 | } |
1091 | ||
61d926a3 SP |
1092 | _git_rebase () |
1093 | { | |
51fe1209 | 1094 | local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)" |
51ef1daa | 1095 | if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then |
b3391775 | 1096 | __gitcomp "--continue --skip --abort" |
61d926a3 SP |
1097 | return |
1098 | fi | |
ce1e39d2 SP |
1099 | case "${COMP_WORDS[COMP_CWORD-1]}" in |
1100 | -s|--strategy) | |
b3391775 | 1101 | __gitcomp "$(__git_merge_strategies)" |
ce1e39d2 SP |
1102 | return |
1103 | esac | |
61d926a3 | 1104 | case "$cur" in |
ce1e39d2 | 1105 | --strategy=*) |
b3391775 | 1106 | __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}" |
ce1e39d2 SP |
1107 | return |
1108 | ;; | |
61d926a3 | 1109 | --*) |
d9e3b702 | 1110 | __gitcomp "--onto --merge --strategy --interactive" |
61d926a3 SP |
1111 | return |
1112 | esac | |
b3391775 | 1113 | __gitcomp "$(__git_refs)" |
61d926a3 SP |
1114 | } |
1115 | ||
25a1f374 TL |
1116 | _git_send_email () |
1117 | { | |
1118 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1119 | case "$cur" in | |
1120 | --*) | |
1121 | __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose | |
1122 | --dry-run --envelope-sender --from --identity | |
1123 | --in-reply-to --no-chain-reply-to --no-signed-off-by-cc | |
1124 | --no-suppress-from --no-thread --quiet | |
1125 | --signed-off-by-cc --smtp-pass --smtp-server | |
1126 | --smtp-server-port --smtp-ssl --smtp-user --subject | |
fd3a8dcb TL |
1127 | --suppress-cc --suppress-from --thread --to |
1128 | --validate --no-validate" | |
25a1f374 TL |
1129 | return |
1130 | ;; | |
1131 | esac | |
1132 | COMPREPLY=() | |
1133 | } | |
1134 | ||
e0d10e1c | 1135 | _git_config () |
5de40f59 SP |
1136 | { |
1137 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1138 | local prv="${COMP_WORDS[COMP_CWORD-1]}" | |
1139 | case "$prv" in | |
1140 | branch.*.remote) | |
78d4d6a2 | 1141 | __gitcomp "$(__git_remotes)" |
5de40f59 SP |
1142 | return |
1143 | ;; | |
1144 | branch.*.merge) | |
78d4d6a2 | 1145 | __gitcomp "$(__git_refs)" |
5de40f59 SP |
1146 | return |
1147 | ;; | |
1148 | remote.*.fetch) | |
1149 | local remote="${prv#remote.}" | |
1150 | remote="${remote%.fetch}" | |
78d4d6a2 | 1151 | __gitcomp "$(__git_refs_remotes "$remote")" |
5de40f59 SP |
1152 | return |
1153 | ;; | |
1154 | remote.*.push) | |
1155 | local remote="${prv#remote.}" | |
1156 | remote="${remote%.push}" | |
78d4d6a2 | 1157 | __gitcomp "$(git --git-dir="$(__gitdir)" \ |
5de40f59 | 1158 | for-each-ref --format='%(refname):%(refname)' \ |
78d4d6a2 SP |
1159 | refs/heads)" |
1160 | return | |
1161 | ;; | |
1162 | pull.twohead|pull.octopus) | |
1163 | __gitcomp "$(__git_merge_strategies)" | |
1164 | return | |
1165 | ;; | |
1166 | color.branch|color.diff|color.status) | |
1167 | __gitcomp "always never auto" | |
1168 | return | |
1169 | ;; | |
1170 | color.*.*) | |
1171 | __gitcomp " | |
1172 | black red green yellow blue magenta cyan white | |
1173 | bold dim ul blink reverse | |
1174 | " | |
5de40f59 SP |
1175 | return |
1176 | ;; | |
1177 | *.*) | |
1178 | COMPREPLY=() | |
1179 | return | |
1180 | ;; | |
1181 | esac | |
1182 | case "$cur" in | |
1183 | --*) | |
78d4d6a2 | 1184 | __gitcomp " |
47e98eec | 1185 | --global --system --file= |
12977705 | 1186 | --list --replace-all |
5de40f59 | 1187 | --get --get-all --get-regexp |
1b71eb35 | 1188 | --add --unset --unset-all |
12977705 | 1189 | --remove-section --rename-section |
78d4d6a2 | 1190 | " |
5de40f59 SP |
1191 | return |
1192 | ;; | |
1193 | branch.*.*) | |
1194 | local pfx="${cur%.*}." | |
1195 | cur="${cur##*.}" | |
78d4d6a2 | 1196 | __gitcomp "remote merge" "$pfx" "$cur" |
5de40f59 SP |
1197 | return |
1198 | ;; | |
1199 | branch.*) | |
1200 | local pfx="${cur%.*}." | |
1201 | cur="${cur#*.}" | |
78d4d6a2 | 1202 | __gitcomp "$(__git_heads)" "$pfx" "$cur" "." |
5de40f59 SP |
1203 | return |
1204 | ;; | |
1205 | remote.*.*) | |
1206 | local pfx="${cur%.*}." | |
1207 | cur="${cur##*.}" | |
12977705 SP |
1208 | __gitcomp " |
1209 | url fetch push skipDefaultUpdate | |
1210 | receivepack uploadpack tagopt | |
1211 | " "$pfx" "$cur" | |
5de40f59 SP |
1212 | return |
1213 | ;; | |
1214 | remote.*) | |
1215 | local pfx="${cur%.*}." | |
1216 | cur="${cur#*.}" | |
78d4d6a2 | 1217 | __gitcomp "$(__git_remotes)" "$pfx" "$cur" "." |
5de40f59 SP |
1218 | return |
1219 | ;; | |
1220 | esac | |
78d4d6a2 | 1221 | __gitcomp " |
5de40f59 SP |
1222 | apply.whitespace |
1223 | core.fileMode | |
1224 | core.gitProxy | |
1225 | core.ignoreStat | |
1226 | core.preferSymlinkRefs | |
1227 | core.logAllRefUpdates | |
47e98eec | 1228 | core.loosecompression |
5de40f59 SP |
1229 | core.repositoryFormatVersion |
1230 | core.sharedRepository | |
1231 | core.warnAmbiguousRefs | |
1232 | core.compression | |
78d4d6a2 SP |
1233 | core.packedGitWindowSize |
1234 | core.packedGitLimit | |
2122591b | 1235 | clean.requireForce |
78d4d6a2 SP |
1236 | color.branch |
1237 | color.branch.current | |
1238 | color.branch.local | |
1239 | color.branch.remote | |
1240 | color.branch.plain | |
a159ca0c | 1241 | color.diff |
78d4d6a2 SP |
1242 | color.diff.plain |
1243 | color.diff.meta | |
1244 | color.diff.frag | |
1245 | color.diff.old | |
1246 | color.diff.new | |
1247 | color.diff.commit | |
1248 | color.diff.whitespace | |
a159ca0c | 1249 | color.pager |
a159ca0c | 1250 | color.status |
78d4d6a2 SP |
1251 | color.status.header |
1252 | color.status.added | |
1253 | color.status.changed | |
1254 | color.status.untracked | |
1255 | diff.renameLimit | |
1256 | diff.renames | |
1257 | fetch.unpackLimit | |
1258 | format.headers | |
47e98eec | 1259 | format.subjectprefix |
78d4d6a2 SP |
1260 | gitcvs.enabled |
1261 | gitcvs.logfile | |
12977705 | 1262 | gitcvs.allbinary |
6aeeffd1 JE |
1263 | gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass |
1264 | gitcvs.dbtablenameprefix | |
12977705 | 1265 | gc.packrefs |
78d4d6a2 SP |
1266 | gc.reflogexpire |
1267 | gc.reflogexpireunreachable | |
1268 | gc.rerereresolved | |
1269 | gc.rerereunresolved | |
5de40f59 SP |
1270 | http.sslVerify |
1271 | http.sslCert | |
1272 | http.sslKey | |
1273 | http.sslCAInfo | |
1274 | http.sslCAPath | |
1275 | http.maxRequests | |
78d4d6a2 SP |
1276 | http.lowSpeedLimit |
1277 | http.lowSpeedTime | |
5de40f59 | 1278 | http.noEPSV |
78d4d6a2 SP |
1279 | i18n.commitEncoding |
1280 | i18n.logOutputEncoding | |
1281 | log.showroot | |
12977705 | 1282 | merge.tool |
78d4d6a2 SP |
1283 | merge.summary |
1284 | merge.verbosity | |
5de40f59 | 1285 | pack.window |
12977705 | 1286 | pack.depth |
47e98eec SP |
1287 | pack.windowMemory |
1288 | pack.compression | |
1289 | pack.deltaCacheSize | |
1290 | pack.deltaCacheLimit | |
78d4d6a2 SP |
1291 | pull.octopus |
1292 | pull.twohead | |
5de40f59 | 1293 | repack.useDeltaBaseOffset |
78d4d6a2 SP |
1294 | showbranch.default |
1295 | tar.umask | |
1296 | transfer.unpackLimit | |
5de40f59 SP |
1297 | receive.unpackLimit |
1298 | receive.denyNonFastForwards | |
78d4d6a2 SP |
1299 | user.name |
1300 | user.email | |
1301 | user.signingkey | |
5de40f59 | 1302 | branch. remote. |
78d4d6a2 | 1303 | " |
5de40f59 SP |
1304 | } |
1305 | ||
88293c67 SP |
1306 | _git_remote () |
1307 | { | |
3ff1320d SG |
1308 | local subcommands="add rm show prune update" |
1309 | local subcommand="$(__git_find_subcommand "$subcommands")" | |
1310 | if [ -z "$subcommand" ]; then | |
3903c618 | 1311 | __gitcomp "$subcommands" |
88293c67 SP |
1312 | return |
1313 | fi | |
1314 | ||
3ff1320d | 1315 | case "$subcommand" in |
a3b811a4 | 1316 | rm|show|prune) |
88293c67 SP |
1317 | __gitcomp "$(__git_remotes)" |
1318 | ;; | |
fb72759b SP |
1319 | update) |
1320 | local i c='' IFS=$'\n' | |
1321 | for i in $(git --git-dir="$(__gitdir)" config --list); do | |
1322 | case "$i" in | |
1323 | remotes.*) | |
1324 | i="${i#remotes.}" | |
1325 | c="$c ${i/=*/}" | |
1326 | ;; | |
1327 | esac | |
1328 | done | |
1329 | __gitcomp "$c" | |
1330 | ;; | |
88293c67 SP |
1331 | *) |
1332 | COMPREPLY=() | |
1333 | ;; | |
1334 | esac | |
1335 | } | |
1336 | ||
67e78c3b SP |
1337 | _git_reset () |
1338 | { | |
d773c631 SG |
1339 | __git_has_doubledash && return |
1340 | ||
67e78c3b | 1341 | local cur="${COMP_WORDS[COMP_CWORD]}" |
b3391775 SP |
1342 | case "$cur" in |
1343 | --*) | |
1344 | __gitcomp "--mixed --hard --soft" | |
1345 | return | |
1346 | ;; | |
1347 | esac | |
1348 | __gitcomp "$(__git_refs)" | |
67e78c3b SP |
1349 | } |
1350 | ||
a6c2be24 LM |
1351 | _git_revert () |
1352 | { | |
1353 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1354 | case "$cur" in | |
1355 | --*) | |
1356 | __gitcomp "--edit --mainline --no-edit --no-commit --signoff" | |
1357 | return | |
1358 | ;; | |
1359 | esac | |
1360 | COMPREPLY=() | |
1361 | } | |
1362 | ||
08c701d4 LM |
1363 | _git_rm () |
1364 | { | |
1365 | __git_has_doubledash && return | |
1366 | ||
1367 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1368 | case "$cur" in | |
1369 | --*) | |
1370 | __gitcomp "--cached --dry-run --ignore-unmatch --quiet" | |
1371 | return | |
1372 | ;; | |
1373 | esac | |
1374 | COMPREPLY=() | |
1375 | } | |
1376 | ||
1fd6bec9 SP |
1377 | _git_shortlog () |
1378 | { | |
d773c631 SG |
1379 | __git_has_doubledash && return |
1380 | ||
1fd6bec9 SP |
1381 | local cur="${COMP_WORDS[COMP_CWORD]}" |
1382 | case "$cur" in | |
1383 | --*) | |
1384 | __gitcomp " | |
1385 | --max-count= --max-age= --since= --after= | |
1386 | --min-age= --before= --until= | |
1387 | --no-merges | |
1388 | --author= --committer= --grep= | |
1389 | --all-match | |
1390 | --not --all | |
1391 | --numbered --summary | |
1392 | " | |
1393 | return | |
1394 | ;; | |
1395 | esac | |
1396 | __git_complete_revlist | |
1397 | } | |
1398 | ||
90131924 SP |
1399 | _git_show () |
1400 | { | |
41d8cf7d MH |
1401 | __git_has_doubledash && return |
1402 | ||
90131924 SP |
1403 | local cur="${COMP_WORDS[COMP_CWORD]}" |
1404 | case "$cur" in | |
1405 | --pretty=*) | |
b3391775 | 1406 | __gitcomp " |
90131924 | 1407 | oneline short medium full fuller email raw |
b3391775 | 1408 | " "" "${cur##--pretty=}" |
90131924 SP |
1409 | return |
1410 | ;; | |
1411 | --*) | |
b3391775 | 1412 | __gitcomp "--pretty=" |
90131924 SP |
1413 | return |
1414 | ;; | |
1415 | esac | |
1416 | __git_complete_file | |
1417 | } | |
1418 | ||
2ca880fe TR |
1419 | _git_show_branch () |
1420 | { | |
1421 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1422 | case "$cur" in | |
1423 | --*) | |
1424 | __gitcomp " | |
1425 | --all --remotes --topo-order --current --more= | |
1426 | --list --independent --merge-base --no-name | |
1427 | --sha1-name --topics --reflog | |
1428 | " | |
1429 | return | |
1430 | ;; | |
1431 | esac | |
1432 | __git_complete_revlist | |
1433 | } | |
1434 | ||
7fd53fce JH |
1435 | _git_stash () |
1436 | { | |
95d43780 | 1437 | local subcommands='save list show apply clear drop pop create branch' |
7bedebca SG |
1438 | local subcommand="$(__git_find_subcommand "$subcommands")" |
1439 | if [ -z "$subcommand" ]; then | |
3ff1320d | 1440 | __gitcomp "$subcommands" |
7bedebca SG |
1441 | else |
1442 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1443 | case "$subcommand,$cur" in | |
1444 | save,--*) | |
1445 | __gitcomp "--keep-index" | |
1446 | ;; | |
95d43780 LM |
1447 | apply,--*) |
1448 | __gitcomp "--index" | |
1449 | ;; | |
5a7ebd4f | 1450 | show,--*|drop,--*|pop,--*|branch,--*) |
95d43780 LM |
1451 | COMPREPLY=() |
1452 | ;; | |
1453 | show,*|apply,*|drop,*|pop,*|branch,*) | |
1454 | __gitcomp "$(git --git-dir="$(__gitdir)" stash list \ | |
1455 | | sed -n -e 's/:.*//p')" | |
1456 | ;; | |
7bedebca SG |
1457 | *) |
1458 | COMPREPLY=() | |
1459 | ;; | |
1460 | esac | |
3ff1320d | 1461 | fi |
7fd53fce JH |
1462 | } |
1463 | ||
be86f7a0 SP |
1464 | _git_submodule () |
1465 | { | |
d773c631 SG |
1466 | __git_has_doubledash && return |
1467 | ||
1b0f7978 | 1468 | local subcommands="add status init update summary foreach sync" |
3ff1320d | 1469 | if [ -z "$(__git_find_subcommand "$subcommands")" ]; then |
be86f7a0 SP |
1470 | local cur="${COMP_WORDS[COMP_CWORD]}" |
1471 | case "$cur" in | |
1472 | --*) | |
1473 | __gitcomp "--quiet --cached" | |
1474 | ;; | |
1475 | *) | |
3ff1320d | 1476 | __gitcomp "$subcommands" |
be86f7a0 SP |
1477 | ;; |
1478 | esac | |
1479 | return | |
1480 | fi | |
1481 | } | |
1482 | ||
47f6ee28 SG |
1483 | _git_svn () |
1484 | { | |
1485 | local subcommands=" | |
1486 | init fetch clone rebase dcommit log find-rev | |
1487 | set-tree commit-diff info create-ignore propget | |
1488 | proplist show-ignore show-externals | |
1489 | " | |
1490 | local subcommand="$(__git_find_subcommand "$subcommands")" | |
1491 | if [ -z "$subcommand" ]; then | |
1492 | __gitcomp "$subcommands" | |
1493 | else | |
1494 | local remote_opts="--username= --config-dir= --no-auth-cache" | |
1495 | local fc_opts=" | |
1496 | --follow-parent --authors-file= --repack= | |
1497 | --no-metadata --use-svm-props --use-svnsync-props | |
1498 | --log-window-size= --no-checkout --quiet | |
1499 | --repack-flags --user-log-author $remote_opts | |
1500 | " | |
1501 | local init_opts=" | |
1502 | --template= --shared= --trunk= --tags= | |
1503 | --branches= --stdlayout --minimize-url | |
1504 | --no-metadata --use-svm-props --use-svnsync-props | |
1505 | --rewrite-root= $remote_opts | |
1506 | " | |
1507 | local cmt_opts=" | |
1508 | --edit --rmdir --find-copies-harder --copy-similarity= | |
1509 | " | |
1510 | ||
1511 | local cur="${COMP_WORDS[COMP_CWORD]}" | |
1512 | case "$subcommand,$cur" in | |
1513 | fetch,--*) | |
1514 | __gitcomp "--revision= --fetch-all $fc_opts" | |
1515 | ;; | |
1516 | clone,--*) | |
1517 | __gitcomp "--revision= $fc_opts $init_opts" | |
1518 | ;; | |
1519 | init,--*) | |
1520 | __gitcomp "$init_opts" | |
1521 | ;; | |
1522 | dcommit,--*) | |
1523 | __gitcomp " | |
1524 | --merge --strategy= --verbose --dry-run | |
1525 | --fetch-all --no-rebase $cmt_opts $fc_opts | |
1526 | " | |
1527 | ;; | |
1528 | set-tree,--*) | |
1529 | __gitcomp "--stdin $cmt_opts $fc_opts" | |
1530 | ;; | |
1531 | create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\ | |
1532 | show-externals,--*) | |
1533 | __gitcomp "--revision=" | |
1534 | ;; | |
1535 | log,--*) | |
1536 | __gitcomp " | |
1537 | --limit= --revision= --verbose --incremental | |
1538 | --oneline --show-commit --non-recursive | |
1539 | --authors-file= | |
1540 | " | |
1541 | ;; | |
1542 | rebase,--*) | |
1543 | __gitcomp " | |
1544 | --merge --verbose --strategy= --local | |
1545 | --fetch-all $fc_opts | |
1546 | " | |
1547 | ;; | |
1548 | commit-diff,--*) | |
1549 | __gitcomp "--message= --file= --revision= $cmt_opts" | |
1550 | ;; | |
1551 | info,--*) | |
1552 | __gitcomp "--url" | |
1553 | ;; | |
1554 | *) | |
1555 | COMPREPLY=() | |
1556 | ;; | |
1557 | esac | |
1558 | fi | |
1559 | } | |
1560 | ||
88e21dc7 SP |
1561 | _git_tag () |
1562 | { | |
1563 | local i c=1 f=0 | |
1564 | while [ $c -lt $COMP_CWORD ]; do | |
1565 | i="${COMP_WORDS[c]}" | |
1566 | case "$i" in | |
1567 | -d|-v) | |
1568 | __gitcomp "$(__git_tags)" | |
1569 | return | |
1570 | ;; | |
1571 | -f) | |
1572 | f=1 | |
1573 | ;; | |
1574 | esac | |
1575 | c=$((++c)) | |
1576 | done | |
1577 | ||
1578 | case "${COMP_WORDS[COMP_CWORD-1]}" in | |
1579 | -m|-F) | |
1580 | COMPREPLY=() | |
1581 | ;; | |
1582 | -*|tag|git-tag) | |
1583 | if [ $f = 1 ]; then | |
1584 | __gitcomp "$(__git_tags)" | |
1585 | else | |
1586 | COMPREPLY=() | |
1587 | fi | |
1588 | ;; | |
1589 | *) | |
1590 | __gitcomp "$(__git_refs)" | |
1591 | ;; | |
1592 | esac | |
1593 | } | |
1594 | ||
690d8824 JH |
1595 | _git () |
1596 | { | |
873537fa SP |
1597 | local i c=1 command __git_dir |
1598 | ||
1599 | while [ $c -lt $COMP_CWORD ]; do | |
1600 | i="${COMP_WORDS[c]}" | |
1601 | case "$i" in | |
1602 | --git-dir=*) __git_dir="${i#--git-dir=}" ;; | |
1603 | --bare) __git_dir="." ;; | |
1eb7e2f8 LM |
1604 | --version|-p|--paginate) ;; |
1605 | --help) command="help"; break ;; | |
873537fa SP |
1606 | *) command="$i"; break ;; |
1607 | esac | |
1608 | c=$((++c)) | |
1609 | done | |
1610 | ||
1d17b22e | 1611 | if [ -z "$command" ]; then |
72e5e989 SP |
1612 | case "${COMP_WORDS[COMP_CWORD]}" in |
1613 | --*=*) COMPREPLY=() ;; | |
47e98eec | 1614 | --*) __gitcomp " |
ce5a2c95 | 1615 | --paginate |
47e98eec SP |
1616 | --no-pager |
1617 | --git-dir= | |
1618 | --bare | |
1619 | --version | |
1620 | --exec-path | |
ce5a2c95 TL |
1621 | --work-tree= |
1622 | --help | |
47e98eec SP |
1623 | " |
1624 | ;; | |
1eb7e2f8 | 1625 | *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;; |
72e5e989 SP |
1626 | esac |
1627 | return | |
873537fa | 1628 | fi |
367dce2a | 1629 | |
873537fa SP |
1630 | local expansion=$(__git_aliased_command "$command") |
1631 | [ "$expansion" ] && command="$expansion" | |
367dce2a | 1632 | |
873537fa | 1633 | case "$command" in |
88329195 | 1634 | am) _git_am ;; |
8435b548 | 1635 | add) _git_add ;; |
88329195 | 1636 | apply) _git_apply ;; |
b3191ce2 | 1637 | archive) _git_archive ;; |
b2e69f62 | 1638 | bisect) _git_bisect ;; |
374a58c9 | 1639 | bundle) _git_bundle ;; |
873537fa | 1640 | branch) _git_branch ;; |
873537fa | 1641 | checkout) _git_checkout ;; |
d8a9fea5 | 1642 | cherry) _git_cherry ;; |
1273231e | 1643 | cherry-pick) _git_cherry_pick ;; |
4181c7e8 | 1644 | clean) _git_clean ;; |
3eb11012 | 1645 | clone) _git_clone ;; |
4548e855 | 1646 | commit) _git_commit ;; |
e0d10e1c | 1647 | config) _git_config ;; |
217926c0 | 1648 | describe) _git_describe ;; |
873537fa | 1649 | diff) _git_diff ;; |
873537fa | 1650 | fetch) _git_fetch ;; |
f53352fb | 1651 | format-patch) _git_format_patch ;; |
b26c8748 | 1652 | gc) _git_gc ;; |
c72e0db1 | 1653 | grep) _git_grep ;; |
1eb7e2f8 | 1654 | help) _git_help ;; |
5dad868b | 1655 | init) _git_init ;; |
873537fa | 1656 | log) _git_log ;; |
b1bc1494 | 1657 | ls-files) _git_ls_files ;; |
873537fa SP |
1658 | ls-remote) _git_ls_remote ;; |
1659 | ls-tree) _git_ls_tree ;; | |
4ad91321 | 1660 | merge) _git_merge;; |
b4c72162 | 1661 | mergetool) _git_mergetool;; |
873537fa | 1662 | merge-base) _git_merge_base ;; |
1127c51c | 1663 | mv) _git_mv ;; |
d33909bf | 1664 | name-rev) _git_name_rev ;; |
873537fa SP |
1665 | pull) _git_pull ;; |
1666 | push) _git_push ;; | |
61d926a3 | 1667 | rebase) _git_rebase ;; |
88293c67 | 1668 | remote) _git_remote ;; |
873537fa | 1669 | reset) _git_reset ;; |
a6c2be24 | 1670 | revert) _git_revert ;; |
08c701d4 | 1671 | rm) _git_rm ;; |
25a1f374 | 1672 | send-email) _git_send_email ;; |
1fd6bec9 | 1673 | shortlog) _git_shortlog ;; |
90131924 | 1674 | show) _git_show ;; |
2ca880fe | 1675 | show-branch) _git_show_branch ;; |
7fd53fce | 1676 | stash) _git_stash ;; |
be86f7a0 | 1677 | submodule) _git_submodule ;; |
47f6ee28 | 1678 | svn) _git_svn ;; |
88e21dc7 | 1679 | tag) _git_tag ;; |
873537fa SP |
1680 | whatchanged) _git_log ;; |
1681 | *) COMPREPLY=() ;; | |
1682 | esac | |
690d8824 JH |
1683 | } |
1684 | ||
1685 | _gitk () | |
1686 | { | |
d773c631 SG |
1687 | __git_has_doubledash && return |
1688 | ||
690d8824 | 1689 | local cur="${COMP_WORDS[COMP_CWORD]}" |
07ba53f7 RQ |
1690 | local g="$(git rev-parse --git-dir 2>/dev/null)" |
1691 | local merge="" | |
1692 | if [ -f $g/MERGE_HEAD ]; then | |
1693 | merge="--merge" | |
1694 | fi | |
b3391775 SP |
1695 | case "$cur" in |
1696 | --*) | |
07ba53f7 | 1697 | __gitcomp "--not --all $merge" |
b3391775 SP |
1698 | return |
1699 | ;; | |
1700 | esac | |
ec804891 | 1701 | __git_complete_revlist |
690d8824 JH |
1702 | } |
1703 | ||
1704 | complete -o default -o nospace -F _git git | |
b3391775 | 1705 | complete -o default -o nospace -F _gitk gitk |
690d8824 JH |
1706 | |
1707 | # The following are necessary only for Cygwin, and only are needed | |
1708 | # when the user has tab-completed the executable name and consequently | |
1709 | # included the '.exe' suffix. | |
1710 | # | |
76c3eb51 | 1711 | if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then |
144d33de | 1712 | complete -o default -o nospace -F _git git.exe |
76c3eb51 | 1713 | fi |