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