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