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