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