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