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