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