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