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