Update Release Notes for 1.6.6 to remove old bugfixes
[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
9a424b27
SG
899 --cleanup=*)
900 __gitcomp "default strip verbatim whitespace
901 " "" "${cur##--cleanup=}"
902 return
903 ;;
904 --reuse-message=*)
905 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
906 return
907 ;;
908 --reedit-message=*)
909 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
910 return
911 ;;
912 --untracked-files=*)
913 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
914 return
915 ;;
4548e855 916 --*)
b3391775 917 __gitcomp "
4548e855 918 --all --author= --signoff --verify --no-verify
aa5735be 919 --edit --amend --include --only --interactive
9a424b27
SG
920 --dry-run --reuse-message= --reedit-message=
921 --reset-author --file= --message= --template=
922 --cleanup= --untracked-files --untracked-files=
923 --verbose --quiet
b3391775 924 "
4548e855
SP
925 return
926 esac
927 COMPREPLY=()
928}
929
217926c0
SP
930_git_describe ()
931{
cbb504c9
TR
932 local cur="${COMP_WORDS[COMP_CWORD]}"
933 case "$cur" in
934 --*)
935 __gitcomp "
936 --all --tags --contains --abbrev= --candidates=
937 --exact-match --debug --long --match --always
938 "
939 return
940 esac
217926c0
SP
941 __gitcomp "$(__git_refs)"
942}
943
20bf7292 944__git_diff_common_options="--stat --numstat --shortstat --summary
b3a4f858
JS
945 --patch-with-stat --name-only --name-status --color
946 --no-color --color-words --no-renames --check
f135aacb 947 --full-index --binary --abbrev --diff-filter=
47d5a8fa 948 --find-copies-harder
b3a4f858
JS
949 --text --ignore-space-at-eol --ignore-space-change
950 --ignore-all-space --exit-code --quiet --ext-diff
aba201c6
PO
951 --no-ext-diff
952 --no-prefix --src-prefix= --dst-prefix=
6d0e674a 953 --inter-hunk-context=
cc545709 954 --patience
20bf7292 955 --raw
8fd2cfa7
SB
956 --dirstat --dirstat= --dirstat-by-file
957 --dirstat-by-file= --cumulative
20bf7292
TR
958"
959
960_git_diff ()
961{
962 __git_has_doubledash && return
963
964 local cur="${COMP_WORDS[COMP_CWORD]}"
965 case "$cur" in
966 --*)
ebd15bf0 967 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
20bf7292
TR
968 --base --ours --theirs
969 $__git_diff_common_options
aba201c6 970 "
b3a4f858
JS
971 return
972 ;;
973 esac
690d8824
JH
974 __git_complete_file
975}
976
e2dc2de9 977__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
c8998b48 978 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
e2dc2de9
DA
979"
980
981_git_difftool ()
982{
f7ad96cf
MH
983 __git_has_doubledash && return
984
e2dc2de9
DA
985 local cur="${COMP_WORDS[COMP_CWORD]}"
986 case "$cur" in
987 --tool=*)
988 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
989 return
990 ;;
991 --*)
f7ad96cf
MH
992 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
993 --base --ours --theirs
994 --no-renames --diff-filter= --find-copies-harder
995 --relative --ignore-submodules
996 --tool="
e2dc2de9
DA
997 return
998 ;;
999 esac
f7ad96cf 1000 __git_complete_file
e2dc2de9
DA
1001}
1002
0a4e1472
JS
1003__git_fetch_options="
1004 --quiet --verbose --append --upload-pack --force --keep --depth=
1005 --tags --no-tags
1006"
1007
690d8824
JH
1008_git_fetch ()
1009{
0a4e1472
JS
1010 local cur="${COMP_WORDS[COMP_CWORD]}"
1011 case "$cur" in
1012 --*)
1013 __gitcomp "$__git_fetch_options"
1014 return
1015 ;;
1016 esac
52d5c3b5 1017 __git_complete_remote_or_refspec
690d8824
JH
1018}
1019
f53352fb
SP
1020_git_format_patch ()
1021{
1022 local cur="${COMP_WORDS[COMP_CWORD]}"
1023 case "$cur" in
e1d37937
SB
1024 --thread=*)
1025 __gitcomp "
1026 deep shallow
1027 " "" "${cur##--thread=}"
1028 return
1029 ;;
f53352fb 1030 --*)
b3391775 1031 __gitcomp "
e1d37937 1032 --stdout --attach --no-attach --thread --thread=
f53352fb
SP
1033 --output-directory
1034 --numbered --start-number
47e98eec 1035 --numbered-files
f53352fb
SP
1036 --keep-subject
1037 --signoff
3f7df3a7 1038 --in-reply-to= --cc=
f53352fb 1039 --full-index --binary
ec804891 1040 --not --all
be5f5bf0 1041 --cover-letter
aba201c6 1042 --no-prefix --src-prefix= --dst-prefix=
81085134
SG
1043 --inline --suffix= --ignore-if-in-upstream
1044 --subject-prefix=
b3391775 1045 "
f53352fb
SP
1046 return
1047 ;;
1048 esac
1049 __git_complete_revlist
1050}
1051
4bca8636
AJ
1052_git_fsck ()
1053{
1054 local cur="${COMP_WORDS[COMP_CWORD]}"
1055 case "$cur" in
1056 --*)
1057 __gitcomp "
1058 --tags --root --unreachable --cache --no-reflogs --full
1059 --strict --verbose --lost-found
1060 "
1061 return
1062 ;;
1063 esac
1064 COMPREPLY=()
1065}
1066
b26c8748
SP
1067_git_gc ()
1068{
1069 local cur="${COMP_WORDS[COMP_CWORD]}"
1070 case "$cur" in
1071 --*)
47e98eec 1072 __gitcomp "--prune --aggressive"
b26c8748
SP
1073 return
1074 ;;
1075 esac
1076 COMPREPLY=()
1077}
1078
c72e0db1
LM
1079_git_grep ()
1080{
1081 __git_has_doubledash && return
1082
1083 local cur="${COMP_WORDS[COMP_CWORD]}"
1084 case "$cur" in
1085 --*)
1086 __gitcomp "
1087 --cached
1088 --text --ignore-case --word-regexp --invert-match
1089 --full-name
1090 --extended-regexp --basic-regexp --fixed-strings
1091 --files-with-matches --name-only
1092 --files-without-match
a91f453f 1093 --max-depth
c72e0db1
LM
1094 --count
1095 --and --or --not --all-match
1096 "
1097 return
1098 ;;
1099 esac
17225c49
TR
1100
1101 __gitcomp "$(__git_refs)"
c72e0db1
LM
1102}
1103
1eb7e2f8
LM
1104_git_help ()
1105{
1106 local cur="${COMP_WORDS[COMP_CWORD]}"
1107 case "$cur" in
1108 --*)
1109 __gitcomp "--all --info --man --web"
1110 return
1111 ;;
1112 esac
eaa4e6ee
JN
1113 __git_compute_all_commands
1114 __gitcomp "$__git_all_commands
2946cccf
MG
1115 attributes cli core-tutorial cvs-migration
1116 diffcore gitk glossary hooks ignore modules
1117 repository-layout tutorial tutorial-2
99f0b599 1118 workflows
2946cccf 1119 "
1eb7e2f8
LM
1120}
1121
5dad868b
LM
1122_git_init ()
1123{
1124 local cur="${COMP_WORDS[COMP_CWORD]}"
1125 case "$cur" in
1126 --shared=*)
1127 __gitcomp "
1128 false true umask group all world everybody
1129 " "" "${cur##--shared=}"
1130 return
1131 ;;
1132 --*)
1133 __gitcomp "--quiet --bare --template= --shared --shared="
1134 return
1135 ;;
1136 esac
1137 COMPREPLY=()
1138}
1139
b1bc1494
LM
1140_git_ls_files ()
1141{
1142 __git_has_doubledash && return
1143
1144 local cur="${COMP_WORDS[COMP_CWORD]}"
1145 case "$cur" in
1146 --*)
1147 __gitcomp "--cached --deleted --modified --others --ignored
1148 --stage --directory --no-empty-directory --unmerged
1149 --killed --exclude= --exclude-from=
1150 --exclude-per-directory= --exclude-standard
1151 --error-unmatch --with-tree= --full-name
1152 --abbrev --ignored --exclude-per-directory
1153 "
1154 return
1155 ;;
1156 esac
1157 COMPREPLY=()
1158}
1159
690d8824
JH
1160_git_ls_remote ()
1161{
b3391775 1162 __gitcomp "$(__git_remotes)"
690d8824
JH
1163}
1164
1165_git_ls_tree ()
1166{
1167 __git_complete_file
1168}
1169
a393777e
TR
1170# Options that go well for log, shortlog and gitk
1171__git_log_common_options="
1172 --not --all
1173 --branches --tags --remotes
4fe1a619 1174 --first-parent --merges --no-merges
a393777e
TR
1175 --max-count=
1176 --max-age= --since= --after=
1177 --min-age= --until= --before=
1178"
1179# Options that go well for log and gitk (not shortlog)
1180__git_log_gitk_options="
1181 --dense --sparse --full-history
1182 --simplify-merges --simplify-by-decoration
1183 --left-right
1184"
1185# Options that go well for log and shortlog (not gitk)
1186__git_log_shortlog_options="
1187 --author= --committer= --grep=
1188 --all-match
1189"
1190
3d279863 1191__git_log_pretty_formats="oneline short medium full fuller email raw format:"
672c68cb 1192__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
3d279863 1193
690d8824
JH
1194_git_log ()
1195{
d773c631
SG
1196 __git_has_doubledash && return
1197
6e31b866 1198 local cur="${COMP_WORDS[COMP_CWORD]}"
bf3c20f6
TR
1199 local g="$(git rev-parse --git-dir 2>/dev/null)"
1200 local merge=""
ba7906f2 1201 if [ -f "$g/MERGE_HEAD" ]; then
bf3c20f6
TR
1202 merge="--merge"
1203 fi
6e31b866
SP
1204 case "$cur" in
1205 --pretty=*)
3d279863 1206 __gitcomp "$__git_log_pretty_formats
b3391775 1207 " "" "${cur##--pretty=}"
6e31b866
SP
1208 return
1209 ;;
72de29c2
TL
1210 --format=*)
1211 __gitcomp "$__git_log_pretty_formats
1212 " "" "${cur##--format=}"
1213 return
1214 ;;
47e98eec 1215 --date=*)
672c68cb 1216 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
47e98eec
SP
1217 return
1218 ;;
af4e9e8c
SB
1219 --decorate=*)
1220 __gitcomp "long short" "" "${cur##--decorate=}"
1221 return
1222 ;;
6e31b866 1223 --*)
b3391775 1224 __gitcomp "
a393777e
TR
1225 $__git_log_common_options
1226 $__git_log_shortlog_options
1227 $__git_log_gitk_options
8f87fae6 1228 --root --topo-order --date-order --reverse
5d0e6343 1229 --follow --full-diff
6e31b866 1230 --abbrev-commit --abbrev=
47e98eec 1231 --relative-date --date=
72de29c2 1232 --pretty= --format= --oneline
a393777e 1233 --cherry-pick
20827d99 1234 --graph
af4e9e8c 1235 --decorate --decorate=
20bf7292 1236 --walk-reflogs
a393777e 1237 --parents --children
bf3c20f6 1238 $merge
20bf7292 1239 $__git_diff_common_options
47d5a8fa 1240 --pickaxe-all --pickaxe-regex
b3391775 1241 "
6e31b866
SP
1242 return
1243 ;;
1244 esac
f53352fb 1245 __git_complete_revlist
690d8824
JH
1246}
1247
0a4e1472
JS
1248__git_merge_options="
1249 --no-commit --no-stat --log --no-log --squash --strategy
9858b87f 1250 --commit --stat --no-squash --ff --no-ff --ff-only
0a4e1472
JS
1251"
1252
4ad91321
SP
1253_git_merge ()
1254{
3c7b480a
JS
1255 __git_complete_strategy && return
1256
4ad91321
SP
1257 local cur="${COMP_WORDS[COMP_CWORD]}"
1258 case "$cur" in
1259 --*)
0a4e1472 1260 __gitcomp "$__git_merge_options"
4ad91321
SP
1261 return
1262 esac
b3391775 1263 __gitcomp "$(__git_refs)"
4ad91321
SP
1264}
1265
b4c72162
LM
1266_git_mergetool ()
1267{
1268 local cur="${COMP_WORDS[COMP_CWORD]}"
1269 case "$cur" in
1270 --tool=*)
e2dc2de9 1271 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
b4c72162
LM
1272 return
1273 ;;
1274 --*)
1275 __gitcomp "--tool="
1276 return
1277 ;;
1278 esac
1279 COMPREPLY=()
1280}
1281
690d8824
JH
1282_git_merge_base ()
1283{
b3391775 1284 __gitcomp "$(__git_refs)"
690d8824
JH
1285}
1286
1127c51c
LM
1287_git_mv ()
1288{
1289 local cur="${COMP_WORDS[COMP_CWORD]}"
1290 case "$cur" in
1291 --*)
1292 __gitcomp "--dry-run"
1293 return
1294 ;;
1295 esac
1296 COMPREPLY=()
1297}
1298
d33909bf
SP
1299_git_name_rev ()
1300{
b3391775 1301 __gitcomp "--tags --all --stdin"
d33909bf
SP
1302}
1303
690d8824
JH
1304_git_pull ()
1305{
0a4e1472
JS
1306 __git_complete_strategy && return
1307
1308 local cur="${COMP_WORDS[COMP_CWORD]}"
1309 case "$cur" in
1310 --*)
1311 __gitcomp "
1312 --rebase --no-rebase
1313 $__git_merge_options
1314 $__git_fetch_options
1315 "
1316 return
1317 ;;
1318 esac
52d5c3b5 1319 __git_complete_remote_or_refspec
690d8824
JH
1320}
1321
1322_git_push ()
1323{
0a4e1472
JS
1324 local cur="${COMP_WORDS[COMP_CWORD]}"
1325 case "${COMP_WORDS[COMP_CWORD-1]}" in
1326 --repo)
1327 __gitcomp "$(__git_remotes)"
1328 return
1329 esac
1330 case "$cur" in
1331 --repo=*)
1332 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1333 return
1334 ;;
1335 --*)
1336 __gitcomp "
1337 --all --mirror --tags --dry-run --force --verbose
1338 --receive-pack= --repo=
1339 "
1340 return
1341 ;;
1342 esac
52d5c3b5 1343 __git_complete_remote_or_refspec
690d8824
JH
1344}
1345
61d926a3
SP
1346_git_rebase ()
1347{
51fe1209 1348 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
51ef1daa 1349 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
b3391775 1350 __gitcomp "--continue --skip --abort"
61d926a3
SP
1351 return
1352 fi
3c7b480a 1353 __git_complete_strategy && return
61d926a3 1354 case "$cur" in
93cf50a4
BG
1355 --whitespace=*)
1356 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1357 return
1358 ;;
61d926a3 1359 --*)
93cf50a4
BG
1360 __gitcomp "
1361 --onto --merge --strategy --interactive
1362 --preserve-merges --stat --no-stat
1363 --committer-date-is-author-date --ignore-date
1364 --ignore-whitespace --whitespace=
1365 "
1366
61d926a3
SP
1367 return
1368 esac
b3391775 1369 __gitcomp "$(__git_refs)"
61d926a3
SP
1370}
1371
ae616de6 1372__git_send_email_confirm_options="always never auto cc compose"
cb8a9bd5 1373__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
ae616de6 1374
25a1f374
TL
1375_git_send_email ()
1376{
1377 local cur="${COMP_WORDS[COMP_CWORD]}"
1378 case "$cur" in
ae616de6
SB
1379 --confirm=*)
1380 __gitcomp "
1381 $__git_send_email_confirm_options
1382 " "" "${cur##--confirm=}"
1383 return
1384 ;;
1385 --suppress-cc=*)
1386 __gitcomp "
1387 $__git_send_email_suppresscc_options
1388 " "" "${cur##--suppress-cc=}"
1389
1390 return
1391 ;;
1392 --smtp-encryption=*)
1393 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1394 return
1395 ;;
25a1f374 1396 --*)
77813151 1397 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
ae616de6
SB
1398 --compose --confirm= --dry-run --envelope-sender
1399 --from --identity
25a1f374
TL
1400 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1401 --no-suppress-from --no-thread --quiet
1402 --signed-off-by-cc --smtp-pass --smtp-server
ae616de6
SB
1403 --smtp-server-port --smtp-encryption= --smtp-user
1404 --subject --suppress-cc= --suppress-from --thread --to
fd3a8dcb 1405 --validate --no-validate"
25a1f374
TL
1406 return
1407 ;;
1408 esac
1409 COMPREPLY=()
1410}
1411
00652369
SB
1412__git_config_get_set_variables ()
1413{
1414 local prevword word config_file= c=$COMP_CWORD
1415 while [ $c -gt 1 ]; do
1416 word="${COMP_WORDS[c]}"
1417 case "$word" in
1418 --global|--system|--file=*)
1419 config_file="$word"
1420 break
1421 ;;
1422 -f|--file)
1423 config_file="$word $prevword"
1424 break
1425 ;;
1426 esac
1427 prevword=$word
1428 c=$((--c))
1429 done
1430
f581de1b
SB
1431 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1432 while read line
1433 do
1434 case "$line" in
1435 *.*=*)
1436 echo "${line/=*/}"
00652369
SB
1437 ;;
1438 esac
1439 done
1440}
1441
e0d10e1c 1442_git_config ()
5de40f59
SP
1443{
1444 local cur="${COMP_WORDS[COMP_CWORD]}"
1445 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1446 case "$prv" in
1447 branch.*.remote)
78d4d6a2 1448 __gitcomp "$(__git_remotes)"
5de40f59
SP
1449 return
1450 ;;
1451 branch.*.merge)
78d4d6a2 1452 __gitcomp "$(__git_refs)"
5de40f59
SP
1453 return
1454 ;;
1455 remote.*.fetch)
1456 local remote="${prv#remote.}"
1457 remote="${remote%.fetch}"
78d4d6a2 1458 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
1459 return
1460 ;;
1461 remote.*.push)
1462 local remote="${prv#remote.}"
1463 remote="${remote%.push}"
78d4d6a2 1464 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 1465 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
1466 refs/heads)"
1467 return
1468 ;;
1469 pull.twohead|pull.octopus)
eaa4e6ee
JN
1470 __git_compute_merge_strategies
1471 __gitcomp "$__git_merge_strategies"
78d4d6a2
SP
1472 return
1473 ;;
6123d719
MH
1474 color.branch|color.diff|color.interactive|\
1475 color.showbranch|color.status|color.ui)
78d4d6a2
SP
1476 __gitcomp "always never auto"
1477 return
1478 ;;
901d615c
MK
1479 color.pager)
1480 __gitcomp "false true"
1481 return
1482 ;;
78d4d6a2
SP
1483 color.*.*)
1484 __gitcomp "
98171a07 1485 normal black red green yellow blue magenta cyan white
78d4d6a2
SP
1486 bold dim ul blink reverse
1487 "
5de40f59
SP
1488 return
1489 ;;
9b82d63b
SB
1490 help.format)
1491 __gitcomp "man info web html"
1492 return
1493 ;;
672c68cb
SB
1494 log.date)
1495 __gitcomp "$__git_log_date_formats"
1496 return
1497 ;;
ae616de6
SB
1498 sendemail.aliasesfiletype)
1499 __gitcomp "mutt mailrc pine elm gnus"
1500 return
1501 ;;
1502 sendemail.confirm)
1503 __gitcomp "$__git_send_email_confirm_options"
1504 return
1505 ;;
1506 sendemail.suppresscc)
1507 __gitcomp "$__git_send_email_suppresscc_options"
1508 return
1509 ;;
00652369
SB
1510 --get|--get-all|--unset|--unset-all)
1511 __gitcomp "$(__git_config_get_set_variables)"
1512 return
1513 ;;
5de40f59
SP
1514 *.*)
1515 COMPREPLY=()
1516 return
1517 ;;
1518 esac
1519 case "$cur" in
1520 --*)
78d4d6a2 1521 __gitcomp "
47e98eec 1522 --global --system --file=
12977705 1523 --list --replace-all
5de40f59 1524 --get --get-all --get-regexp
1b71eb35 1525 --add --unset --unset-all
12977705 1526 --remove-section --rename-section
78d4d6a2 1527 "
5de40f59
SP
1528 return
1529 ;;
1530 branch.*.*)
1531 local pfx="${cur%.*}."
1532 cur="${cur##*.}"
6fac1b83 1533 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
5de40f59
SP
1534 return
1535 ;;
1536 branch.*)
1537 local pfx="${cur%.*}."
1538 cur="${cur#*.}"
78d4d6a2 1539 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
5de40f59
SP
1540 return
1541 ;;
0aa62fd0
SB
1542 guitool.*.*)
1543 local pfx="${cur%.*}."
1544 cur="${cur##*.}"
1545 __gitcomp "
1546 argprompt cmd confirm needsfile noconsole norescan
1547 prompt revprompt revunmerged title
1548 " "$pfx" "$cur"
1549 return
1550 ;;
1551 difftool.*.*)
1552 local pfx="${cur%.*}."
1553 cur="${cur##*.}"
1554 __gitcomp "cmd path" "$pfx" "$cur"
1555 return
1556 ;;
1557 man.*.*)
1558 local pfx="${cur%.*}."
1559 cur="${cur##*.}"
1560 __gitcomp "cmd path" "$pfx" "$cur"
1561 return
1562 ;;
1563 mergetool.*.*)
1564 local pfx="${cur%.*}."
1565 cur="${cur##*.}"
1566 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1567 return
1568 ;;
1569 pager.*)
1570 local pfx="${cur%.*}."
1571 cur="${cur#*.}"
eaa4e6ee
JN
1572 __git_compute_all_commands
1573 __gitcomp "$__git_all_commands" "$pfx" "$cur"
0aa62fd0
SB
1574 return
1575 ;;
5de40f59
SP
1576 remote.*.*)
1577 local pfx="${cur%.*}."
1578 cur="${cur##*.}"
12977705 1579 __gitcomp "
98171a07 1580 url proxy fetch push mirror skipDefaultUpdate
6fac1b83 1581 receivepack uploadpack tagopt pushurl
12977705 1582 " "$pfx" "$cur"
5de40f59
SP
1583 return
1584 ;;
1585 remote.*)
1586 local pfx="${cur%.*}."
1587 cur="${cur#*.}"
78d4d6a2 1588 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
5de40f59
SP
1589 return
1590 ;;
0aa62fd0
SB
1591 url.*.*)
1592 local pfx="${cur%.*}."
1593 cur="${cur##*.}"
1c2eafb8 1594 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
0aa62fd0
SB
1595 return
1596 ;;
5de40f59 1597 esac
78d4d6a2 1598 __gitcomp "
6fac1b83 1599 add.ignore-errors
226b343c 1600 alias.
86c91f91 1601 apply.ignorewhitespace
5de40f59 1602 apply.whitespace
98171a07
LM
1603 branch.autosetupmerge
1604 branch.autosetuprebase
2122591b 1605 clean.requireForce
78d4d6a2
SP
1606 color.branch
1607 color.branch.current
1608 color.branch.local
78d4d6a2 1609 color.branch.plain
025a1929 1610 color.branch.remote
a159ca0c 1611 color.diff
025a1929 1612 color.diff.commit
78d4d6a2 1613 color.diff.frag
025a1929 1614 color.diff.meta
78d4d6a2 1615 color.diff.new
025a1929
LM
1616 color.diff.old
1617 color.diff.plain
78d4d6a2 1618 color.diff.whitespace
226b343c
SB
1619 color.grep
1620 color.grep.external
1621 color.grep.match
98171a07
LM
1622 color.interactive
1623 color.interactive.header
1624 color.interactive.help
1625 color.interactive.prompt
a159ca0c 1626 color.pager
6123d719 1627 color.showbranch
a159ca0c 1628 color.status
78d4d6a2
SP
1629 color.status.added
1630 color.status.changed
025a1929 1631 color.status.header
98171a07 1632 color.status.nobranch
78d4d6a2 1633 color.status.untracked
98171a07
LM
1634 color.status.updated
1635 color.ui
1636 commit.template
1637 core.autocrlf
1638 core.bare
025a1929 1639 core.compression
226b343c 1640 core.createObject
98171a07
LM
1641 core.deltaBaseCacheLimit
1642 core.editor
1643 core.excludesfile
025a1929 1644 core.fileMode
98171a07 1645 core.fsyncobjectfiles
025a1929 1646 core.gitProxy
98171a07 1647 core.ignoreCygwinFSTricks
025a1929
LM
1648 core.ignoreStat
1649 core.logAllRefUpdates
1650 core.loosecompression
1651 core.packedGitLimit
1652 core.packedGitWindowSize
98171a07 1653 core.pager
025a1929 1654 core.preferSymlinkRefs
98171a07
LM
1655 core.preloadindex
1656 core.quotepath
025a1929 1657 core.repositoryFormatVersion
98171a07 1658 core.safecrlf
025a1929 1659 core.sharedRepository
98171a07
LM
1660 core.symlinks
1661 core.trustctime
025a1929 1662 core.warnAmbiguousRefs
98171a07
LM
1663 core.whitespace
1664 core.worktree
1665 diff.autorefreshindex
1666 diff.external
1667 diff.mnemonicprefix
78d4d6a2 1668 diff.renameLimit
98171a07 1669 diff.renameLimit.
78d4d6a2 1670 diff.renames
226b343c
SB
1671 diff.suppressBlankEmpty
1672 diff.tool
1673 diff.wordRegex
0aa62fd0 1674 difftool.
226b343c 1675 difftool.prompt
78d4d6a2 1676 fetch.unpackLimit
226b343c
SB
1677 format.attach
1678 format.cc
78d4d6a2 1679 format.headers
98171a07
LM
1680 format.numbered
1681 format.pretty
226b343c
SB
1682 format.signoff
1683 format.subjectprefix
98171a07 1684 format.suffix
226b343c 1685 format.thread
98171a07
LM
1686 gc.aggressiveWindow
1687 gc.auto
1688 gc.autopacklimit
12977705 1689 gc.packrefs
98171a07 1690 gc.pruneexpire
78d4d6a2
SP
1691 gc.reflogexpire
1692 gc.reflogexpireunreachable
1693 gc.rerereresolved
1694 gc.rerereunresolved
025a1929 1695 gitcvs.allbinary
226b343c 1696 gitcvs.commitmsgannotation
98171a07 1697 gitcvs.dbTableNamePrefix
025a1929
LM
1698 gitcvs.dbdriver
1699 gitcvs.dbname
1700 gitcvs.dbpass
025a1929
LM
1701 gitcvs.dbuser
1702 gitcvs.enabled
1703 gitcvs.logfile
98171a07 1704 gitcvs.usecrlfattr
0aa62fd0 1705 guitool.
98171a07
LM
1706 gui.blamehistoryctx
1707 gui.commitmsgwidth
1708 gui.copyblamethreshold
1709 gui.diffcontext
1710 gui.encoding
1711 gui.fastcopyblame
1712 gui.matchtrackingbranch
1713 gui.newbranchtemplate
1714 gui.pruneduringfetch
1715 gui.spellingdictionary
1716 gui.trustmtime
1717 help.autocorrect
1718 help.browser
1719 help.format
78d4d6a2
SP
1720 http.lowSpeedLimit
1721 http.lowSpeedTime
025a1929 1722 http.maxRequests
5de40f59 1723 http.noEPSV
98171a07 1724 http.proxy
025a1929
LM
1725 http.sslCAInfo
1726 http.sslCAPath
1727 http.sslCert
1728 http.sslKey
1729 http.sslVerify
78d4d6a2
SP
1730 i18n.commitEncoding
1731 i18n.logOutputEncoding
226b343c
SB
1732 imap.folder
1733 imap.host
1734 imap.pass
1735 imap.port
1736 imap.preformattedHTML
1737 imap.sslverify
1738 imap.tunnel
1739 imap.user
98171a07
LM
1740 instaweb.browser
1741 instaweb.httpd
1742 instaweb.local
1743 instaweb.modulepath
1744 instaweb.port
226b343c 1745 interactive.singlekey
98171a07 1746 log.date
78d4d6a2 1747 log.showroot
226b343c 1748 mailmap.file
0aa62fd0 1749 man.
98171a07
LM
1750 man.viewer
1751 merge.conflictstyle
1752 merge.log
1753 merge.renameLimit
1754 merge.stat
025a1929 1755 merge.tool
78d4d6a2 1756 merge.verbosity
0aa62fd0 1757 mergetool.
98171a07 1758 mergetool.keepBackup
226b343c 1759 mergetool.prompt
47e98eec 1760 pack.compression
47e98eec 1761 pack.deltaCacheLimit
025a1929
LM
1762 pack.deltaCacheSize
1763 pack.depth
98171a07
LM
1764 pack.indexVersion
1765 pack.packSizeLimit
1766 pack.threads
025a1929
LM
1767 pack.window
1768 pack.windowMemory
0aa62fd0 1769 pager.
78d4d6a2
SP
1770 pull.octopus
1771 pull.twohead
226b343c
SB
1772 push.default
1773 rebase.stat
98171a07
LM
1774 receive.denyCurrentBranch
1775 receive.denyDeletes
025a1929 1776 receive.denyNonFastForwards
98171a07 1777 receive.fsckObjects
025a1929 1778 receive.unpackLimit
98171a07
LM
1779 repack.usedeltabaseoffset
1780 rerere.autoupdate
1781 rerere.enabled
226b343c
SB
1782 sendemail.aliasesfile
1783 sendemail.aliasesfiletype
1784 sendemail.bcc
1785 sendemail.cc
1786 sendemail.cccmd
1787 sendemail.chainreplyto
1788 sendemail.confirm
1789 sendemail.envelopesender
1790 sendemail.multiedit
1791 sendemail.signedoffbycc
1792 sendemail.smtpencryption
1793 sendemail.smtppass
1794 sendemail.smtpserver
1795 sendemail.smtpserverport
1796 sendemail.smtpuser
1797 sendemail.suppresscc
1798 sendemail.suppressfrom
1799 sendemail.thread
1800 sendemail.to
1801 sendemail.validate
78d4d6a2 1802 showbranch.default
98171a07
LM
1803 status.relativePaths
1804 status.showUntrackedFiles
78d4d6a2
SP
1805 tar.umask
1806 transfer.unpackLimit
0aa62fd0 1807 url.
78d4d6a2 1808 user.email
025a1929 1809 user.name
78d4d6a2 1810 user.signingkey
98171a07 1811 web.browser
5de40f59 1812 branch. remote.
78d4d6a2 1813 "
5de40f59
SP
1814}
1815
88293c67
SP
1816_git_remote ()
1817{
bc14fac8 1818 local subcommands="add rename rm show prune update set-head"
918c03c2 1819 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3ff1320d 1820 if [ -z "$subcommand" ]; then
3903c618 1821 __gitcomp "$subcommands"
88293c67
SP
1822 return
1823 fi
1824
3ff1320d 1825 case "$subcommand" in
f135e72d 1826 rename|rm|show|prune)
88293c67
SP
1827 __gitcomp "$(__git_remotes)"
1828 ;;
fb72759b
SP
1829 update)
1830 local i c='' IFS=$'\n'
518ef8f0
TZ
1831 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1832 i="${i#remotes.}"
1833 c="$c ${i/ */}"
fb72759b
SP
1834 done
1835 __gitcomp "$c"
1836 ;;
88293c67
SP
1837 *)
1838 COMPREPLY=()
1839 ;;
1840 esac
1841}
1842
e1c1a067
BG
1843_git_replace ()
1844{
1845 __gitcomp "$(__git_refs)"
1846}
1847
67e78c3b
SP
1848_git_reset ()
1849{
d773c631
SG
1850 __git_has_doubledash && return
1851
67e78c3b 1852 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
1853 case "$cur" in
1854 --*)
9f040e95 1855 __gitcomp "--merge --mixed --hard --soft --patch"
b3391775
SP
1856 return
1857 ;;
1858 esac
1859 __gitcomp "$(__git_refs)"
67e78c3b
SP
1860}
1861
a6c2be24
LM
1862_git_revert ()
1863{
1864 local cur="${COMP_WORDS[COMP_CWORD]}"
1865 case "$cur" in
1866 --*)
1867 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1868 return
1869 ;;
1870 esac
c0783837 1871 __gitcomp "$(__git_refs)"
a6c2be24
LM
1872}
1873
08c701d4
LM
1874_git_rm ()
1875{
1876 __git_has_doubledash && return
1877
1878 local cur="${COMP_WORDS[COMP_CWORD]}"
1879 case "$cur" in
1880 --*)
1881 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1882 return
1883 ;;
1884 esac
1885 COMPREPLY=()
1886}
1887
1fd6bec9
SP
1888_git_shortlog ()
1889{
d773c631
SG
1890 __git_has_doubledash && return
1891
1fd6bec9
SP
1892 local cur="${COMP_WORDS[COMP_CWORD]}"
1893 case "$cur" in
1894 --*)
1895 __gitcomp "
a393777e
TR
1896 $__git_log_common_options
1897 $__git_log_shortlog_options
1fd6bec9
SP
1898 --numbered --summary
1899 "
1900 return
1901 ;;
1902 esac
1903 __git_complete_revlist
1904}
1905
90131924
SP
1906_git_show ()
1907{
41d8cf7d
MH
1908 __git_has_doubledash && return
1909
90131924
SP
1910 local cur="${COMP_WORDS[COMP_CWORD]}"
1911 case "$cur" in
1912 --pretty=*)
3d279863 1913 __gitcomp "$__git_log_pretty_formats
b3391775 1914 " "" "${cur##--pretty=}"
90131924
SP
1915 return
1916 ;;
72de29c2
TL
1917 --format=*)
1918 __gitcomp "$__git_log_pretty_formats
1919 " "" "${cur##--format=}"
1920 return
1921 ;;
90131924 1922 --*)
076c3237 1923 __gitcomp "--pretty= --format= --abbrev-commit --oneline
20bf7292
TR
1924 $__git_diff_common_options
1925 "
90131924
SP
1926 return
1927 ;;
1928 esac
1929 __git_complete_file
1930}
1931
2ca880fe
TR
1932_git_show_branch ()
1933{
1934 local cur="${COMP_WORDS[COMP_CWORD]}"
1935 case "$cur" in
1936 --*)
1937 __gitcomp "
1938 --all --remotes --topo-order --current --more=
1939 --list --independent --merge-base --no-name
6123d719 1940 --color --no-color
076c3237 1941 --sha1-name --sparse --topics --reflog
2ca880fe
TR
1942 "
1943 return
1944 ;;
1945 esac
1946 __git_complete_revlist
1947}
1948
7fd53fce
JH
1949_git_stash ()
1950{
59d5eeee
SG
1951 local cur="${COMP_WORDS[COMP_CWORD]}"
1952 local save_opts='--keep-index --no-keep-index --quiet --patch'
95d43780 1953 local subcommands='save list show apply clear drop pop create branch'
918c03c2 1954 local subcommand="$(__git_find_on_cmdline "$subcommands")"
7bedebca 1955 if [ -z "$subcommand" ]; then
59d5eeee
SG
1956 case "$cur" in
1957 --*)
1958 __gitcomp "$save_opts"
1959 ;;
1960 *)
1961 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1962 __gitcomp "$subcommands"
1963 else
1964 COMPREPLY=()
1965 fi
1966 ;;
1967 esac
7bedebca 1968 else
7bedebca
SG
1969 case "$subcommand,$cur" in
1970 save,--*)
59d5eeee 1971 __gitcomp "$save_opts"
7bedebca 1972 ;;
8513c54b 1973 apply,--*|pop,--*)
59d5eeee 1974 __gitcomp "--index --quiet"
95d43780 1975 ;;
8513c54b 1976 show,--*|drop,--*|branch,--*)
95d43780
LM
1977 COMPREPLY=()
1978 ;;
1979 show,*|apply,*|drop,*|pop,*|branch,*)
1980 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1981 | sed -n -e 's/:.*//p')"
1982 ;;
7bedebca
SG
1983 *)
1984 COMPREPLY=()
1985 ;;
1986 esac
3ff1320d 1987 fi
7fd53fce
JH
1988}
1989
be86f7a0
SP
1990_git_submodule ()
1991{
d773c631
SG
1992 __git_has_doubledash && return
1993
1b0f7978 1994 local subcommands="add status init update summary foreach sync"
918c03c2 1995 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
be86f7a0
SP
1996 local cur="${COMP_WORDS[COMP_CWORD]}"
1997 case "$cur" in
1998 --*)
1999 __gitcomp "--quiet --cached"
2000 ;;
2001 *)
3ff1320d 2002 __gitcomp "$subcommands"
be86f7a0
SP
2003 ;;
2004 esac
2005 return
2006 fi
2007}
2008
47f6ee28
SG
2009_git_svn ()
2010{
2011 local subcommands="
2012 init fetch clone rebase dcommit log find-rev
2013 set-tree commit-diff info create-ignore propget
4a5856cb
SG
2014 proplist show-ignore show-externals branch tag blame
2015 migrate
47f6ee28 2016 "
918c03c2 2017 local subcommand="$(__git_find_on_cmdline "$subcommands")"
47f6ee28
SG
2018 if [ -z "$subcommand" ]; then
2019 __gitcomp "$subcommands"
2020 else
2021 local remote_opts="--username= --config-dir= --no-auth-cache"
2022 local fc_opts="
2023 --follow-parent --authors-file= --repack=
2024 --no-metadata --use-svm-props --use-svnsync-props
2025 --log-window-size= --no-checkout --quiet
4a5856cb
SG
2026 --repack-flags --use-log-author --localtime
2027 --ignore-paths= $remote_opts
47f6ee28
SG
2028 "
2029 local init_opts="
2030 --template= --shared= --trunk= --tags=
2031 --branches= --stdlayout --minimize-url
2032 --no-metadata --use-svm-props --use-svnsync-props
4a5856cb
SG
2033 --rewrite-root= --prefix= --use-log-author
2034 --add-author-from $remote_opts
47f6ee28
SG
2035 "
2036 local cmt_opts="
2037 --edit --rmdir --find-copies-harder --copy-similarity=
2038 "
2039
2040 local cur="${COMP_WORDS[COMP_CWORD]}"
2041 case "$subcommand,$cur" in
2042 fetch,--*)
2043 __gitcomp "--revision= --fetch-all $fc_opts"
2044 ;;
2045 clone,--*)
2046 __gitcomp "--revision= $fc_opts $init_opts"
2047 ;;
2048 init,--*)
2049 __gitcomp "$init_opts"
2050 ;;
2051 dcommit,--*)
2052 __gitcomp "
2053 --merge --strategy= --verbose --dry-run
4a5856cb
SG
2054 --fetch-all --no-rebase --commit-url
2055 --revision $cmt_opts $fc_opts
47f6ee28
SG
2056 "
2057 ;;
2058 set-tree,--*)
2059 __gitcomp "--stdin $cmt_opts $fc_opts"
2060 ;;
2061 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2062 show-externals,--*)
2063 __gitcomp "--revision="
2064 ;;
2065 log,--*)
2066 __gitcomp "
2067 --limit= --revision= --verbose --incremental
2068 --oneline --show-commit --non-recursive
4a5856cb 2069 --authors-file= --color
47f6ee28
SG
2070 "
2071 ;;
2072 rebase,--*)
2073 __gitcomp "
2074 --merge --verbose --strategy= --local
4a5856cb 2075 --fetch-all --dry-run $fc_opts
47f6ee28
SG
2076 "
2077 ;;
2078 commit-diff,--*)
2079 __gitcomp "--message= --file= --revision= $cmt_opts"
2080 ;;
2081 info,--*)
2082 __gitcomp "--url"
2083 ;;
4a5856cb
SG
2084 branch,--*)
2085 __gitcomp "--dry-run --message --tag"
2086 ;;
2087 tag,--*)
2088 __gitcomp "--dry-run --message"
2089 ;;
2090 blame,--*)
2091 __gitcomp "--git-format"
2092 ;;
2093 migrate,--*)
2094 __gitcomp "
2095 --config-dir= --ignore-paths= --minimize
2096 --no-auth-cache --username=
2097 "
2098 ;;
47f6ee28
SG
2099 *)
2100 COMPREPLY=()
2101 ;;
2102 esac
2103 fi
2104}
2105
88e21dc7
SP
2106_git_tag ()
2107{
2108 local i c=1 f=0
2109 while [ $c -lt $COMP_CWORD ]; do
2110 i="${COMP_WORDS[c]}"
2111 case "$i" in
2112 -d|-v)
2113 __gitcomp "$(__git_tags)"
2114 return
2115 ;;
2116 -f)
2117 f=1
2118 ;;
2119 esac
2120 c=$((++c))
2121 done
2122
2123 case "${COMP_WORDS[COMP_CWORD-1]}" in
2124 -m|-F)
2125 COMPREPLY=()
2126 ;;
8d8163f3 2127 -*|tag)
88e21dc7
SP
2128 if [ $f = 1 ]; then
2129 __gitcomp "$(__git_tags)"
2130 else
2131 COMPREPLY=()
2132 fi
2133 ;;
2134 *)
2135 __gitcomp "$(__git_refs)"
2136 ;;
2137 esac
2138}
2139
690d8824
JH
2140_git ()
2141{
873537fa
SP
2142 local i c=1 command __git_dir
2143
2144 while [ $c -lt $COMP_CWORD ]; do
2145 i="${COMP_WORDS[c]}"
2146 case "$i" in
2147 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2148 --bare) __git_dir="." ;;
1eb7e2f8
LM
2149 --version|-p|--paginate) ;;
2150 --help) command="help"; break ;;
873537fa
SP
2151 *) command="$i"; break ;;
2152 esac
2153 c=$((++c))
2154 done
2155
1d17b22e 2156 if [ -z "$command" ]; then
72e5e989 2157 case "${COMP_WORDS[COMP_CWORD]}" in
47e98eec 2158 --*) __gitcomp "
ce5a2c95 2159 --paginate
47e98eec
SP
2160 --no-pager
2161 --git-dir=
2162 --bare
2163 --version
2164 --exec-path
89a56bfb 2165 --html-path
ce5a2c95
TL
2166 --work-tree=
2167 --help
47e98eec
SP
2168 "
2169 ;;
eaa4e6ee
JN
2170 *) __git_compute_porcelain_commands
2171 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
72e5e989
SP
2172 esac
2173 return
873537fa 2174 fi
367dce2a 2175
873537fa
SP
2176 local expansion=$(__git_aliased_command "$command")
2177 [ "$expansion" ] && command="$expansion"
367dce2a 2178
873537fa 2179 case "$command" in
88329195 2180 am) _git_am ;;
8435b548 2181 add) _git_add ;;
88329195 2182 apply) _git_apply ;;
b3191ce2 2183 archive) _git_archive ;;
b2e69f62 2184 bisect) _git_bisect ;;
374a58c9 2185 bundle) _git_bundle ;;
873537fa 2186 branch) _git_branch ;;
873537fa 2187 checkout) _git_checkout ;;
d8a9fea5 2188 cherry) _git_cherry ;;
1273231e 2189 cherry-pick) _git_cherry_pick ;;
4181c7e8 2190 clean) _git_clean ;;
3eb11012 2191 clone) _git_clone ;;
4548e855 2192 commit) _git_commit ;;
e0d10e1c 2193 config) _git_config ;;
217926c0 2194 describe) _git_describe ;;
873537fa 2195 diff) _git_diff ;;
e2dc2de9 2196 difftool) _git_difftool ;;
873537fa 2197 fetch) _git_fetch ;;
f53352fb 2198 format-patch) _git_format_patch ;;
4bca8636 2199 fsck) _git_fsck ;;
b26c8748 2200 gc) _git_gc ;;
c72e0db1 2201 grep) _git_grep ;;
1eb7e2f8 2202 help) _git_help ;;
5dad868b 2203 init) _git_init ;;
873537fa 2204 log) _git_log ;;
b1bc1494 2205 ls-files) _git_ls_files ;;
873537fa
SP
2206 ls-remote) _git_ls_remote ;;
2207 ls-tree) _git_ls_tree ;;
4ad91321 2208 merge) _git_merge;;
b4c72162 2209 mergetool) _git_mergetool;;
873537fa 2210 merge-base) _git_merge_base ;;
1127c51c 2211 mv) _git_mv ;;
d33909bf 2212 name-rev) _git_name_rev ;;
873537fa
SP
2213 pull) _git_pull ;;
2214 push) _git_push ;;
61d926a3 2215 rebase) _git_rebase ;;
88293c67 2216 remote) _git_remote ;;
e1c1a067 2217 replace) _git_replace ;;
873537fa 2218 reset) _git_reset ;;
a6c2be24 2219 revert) _git_revert ;;
08c701d4 2220 rm) _git_rm ;;
25a1f374 2221 send-email) _git_send_email ;;
1fd6bec9 2222 shortlog) _git_shortlog ;;
90131924 2223 show) _git_show ;;
2ca880fe 2224 show-branch) _git_show_branch ;;
7fd53fce 2225 stash) _git_stash ;;
df398771 2226 stage) _git_add ;;
be86f7a0 2227 submodule) _git_submodule ;;
47f6ee28 2228 svn) _git_svn ;;
88e21dc7 2229 tag) _git_tag ;;
873537fa
SP
2230 whatchanged) _git_log ;;
2231 *) COMPREPLY=() ;;
2232 esac
690d8824
JH
2233}
2234
2235_gitk ()
2236{
d773c631
SG
2237 __git_has_doubledash && return
2238
690d8824 2239 local cur="${COMP_WORDS[COMP_CWORD]}"
fa26a401 2240 local g="$(__gitdir)"
07ba53f7 2241 local merge=""
ba7906f2 2242 if [ -f "$g/MERGE_HEAD" ]; then
07ba53f7
RQ
2243 merge="--merge"
2244 fi
b3391775
SP
2245 case "$cur" in
2246 --*)
a393777e
TR
2247 __gitcomp "
2248 $__git_log_common_options
2249 $__git_log_gitk_options
2250 $merge
2251 "
b3391775
SP
2252 return
2253 ;;
2254 esac
ec804891 2255 __git_complete_revlist
690d8824
JH
2256}
2257
50e126e1
TP
2258complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2259 || complete -o default -o nospace -F _git git
2260complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2261 || complete -o default -o nospace -F _gitk gitk
690d8824
JH
2262
2263# The following are necessary only for Cygwin, and only are needed
2264# when the user has tab-completed the executable name and consequently
2265# included the '.exe' suffix.
2266#
76c3eb51 2267if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
50e126e1
TP
2268complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2269 || complete -o default -o nospace -F _git git.exe
76c3eb51 2270fi