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