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