]> git.ipfire.org Git - thirdparty/git.git/blame - contrib/completion/git-completion.bash
git checkout's reflog: even when detaching the HEAD, say from where
[thirdparty/git.git] / contrib / completion / git-completion.bash
CommitLineData
690d8824
JH
1#
2# bash completion support for core Git.
3#
c70680ce 4# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
690d8824 5# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
c70680ce 6# Distributed under the GNU General Public License, version 2.0.
690d8824
JH
7#
8# The contained completion routines provide support for completing:
9#
10# *) local and remote branch names
11# *) local and remote tag names
12# *) .git/remotes file names
13# *) git 'subcommands'
14# *) tree paths within 'ref:path/to/file' expressions
c70680ce 15# *) common --long-options
690d8824
JH
16#
17# To use these routines:
18#
19# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
20# 2) Added the following line to your .bashrc:
21# source ~/.git-completion.sh
22#
b51ec6bd
SP
23# 3) You may want to make sure the git executable is available
24# in your PATH before this script is sourced, as some caching
25# is performed while the script loads. If git isn't found
26# at source time then all lookups will be done on demand,
27# which may be slightly slower.
28#
29# 4) Consider changing your PS1 to also show the current branch:
d3d717a4
SP
30# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
31#
32# The argument to __git_ps1 will be displayed only if you
33# are currently in a git repository. The %s token will be
34# the name of the current branch.
35#
c70680ce
SP
36# To submit patches:
37#
38# *) Read Documentation/SubmittingPatches
39# *) Send all patches to the current maintainer:
40#
41# "Shawn O. Pearce" <spearce@spearce.org>
42#
43# *) Always CC the Git mailing list:
44#
45# git@vger.kernel.org
46#
690d8824 47
873537fa
SP
48__gitdir ()
49{
67ffa114
SP
50 if [ -z "$1" ]; then
51 if [ -n "$__git_dir" ]; then
52 echo "$__git_dir"
53 elif [ -d .git ]; then
54 echo .git
55 else
56 git rev-parse --git-dir 2>/dev/null
57 fi
58 elif [ -d "$1/.git" ]; then
59 echo "$1/.git"
60 else
61 echo "$1"
62 fi
873537fa
SP
63}
64
d3d717a4
SP
65__git_ps1 ()
66{
67 local b="$(git symbolic-ref HEAD 2>/dev/null)"
68 if [ -n "$b" ]; then
69 if [ -n "$1" ]; then
70 printf "$1" "${b##refs/heads/}"
71 else
72 printf " (%s)" "${b##refs/heads/}"
73 fi
74 fi
75}
76
72e5e989
SP
77__gitcomp ()
78{
79 local all c s=$'\n' IFS=' '$'\t'$'\n'
78d4d6a2 80 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775 81 if [ $# -gt 2 ]; then
78d4d6a2
SP
82 cur="$3"
83 fi
72e5e989 84 for c in $1; do
78d4d6a2
SP
85 case "$c$4" in
86 --*=*) all="$all$c$4$s" ;;
87 *.) all="$all$c$4$s" ;;
88 *) all="$all$c$4 $s" ;;
72e5e989
SP
89 esac
90 done
91 IFS=$s
78d4d6a2 92 COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
72e5e989
SP
93 return
94}
95
5de40f59
SP
96__git_heads ()
97{
67ffa114 98 local cmd i is_hash=y dir="$(__gitdir "$1")"
5de40f59
SP
99 if [ -d "$dir" ]; then
100 for i in $(git --git-dir="$dir" \
101 for-each-ref --format='%(refname)' \
102 refs/heads ); do
103 echo "${i#refs/heads/}"
104 done
105 return
106 fi
67ffa114 107 for i in $(git-ls-remote "$1" 2>/dev/null); do
5de40f59
SP
108 case "$is_hash,$i" in
109 y,*) is_hash=n ;;
110 n,*^{}) is_hash=y ;;
111 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
112 n,*) is_hash=y; echo "$i" ;;
113 esac
114 done
115}
116
88e21dc7
SP
117__git_tags ()
118{
119 local cmd i is_hash=y dir="$(__gitdir "$1")"
120 if [ -d "$dir" ]; then
121 for i in $(git --git-dir="$dir" \
122 for-each-ref --format='%(refname)' \
123 refs/tags ); do
124 echo "${i#refs/tags/}"
125 done
126 return
127 fi
128 for i in $(git-ls-remote "$1" 2>/dev/null); do
129 case "$is_hash,$i" in
130 y,*) is_hash=n ;;
131 n,*^{}) is_hash=y ;;
132 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
133 n,*) is_hash=y; echo "$i" ;;
134 esac
135 done
136}
137
690d8824
JH
138__git_refs ()
139{
67ffa114 140 local cmd i is_hash=y dir="$(__gitdir "$1")"
873537fa 141 if [ -d "$dir" ]; then
35e65ecc
SP
142 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
143 for i in $(git --git-dir="$dir" \
144 for-each-ref --format='%(refname)' \
145 refs/tags refs/heads refs/remotes); do
146 case "$i" in
147 refs/tags/*) echo "${i#refs/tags/}" ;;
148 refs/heads/*) echo "${i#refs/heads/}" ;;
149 refs/remotes/*) echo "${i#refs/remotes/}" ;;
150 *) echo "$i" ;;
151 esac
152 done
153 return
690d8824 154 fi
35e65ecc 155 for i in $(git-ls-remote "$dir" 2>/dev/null); do
690d8824
JH
156 case "$is_hash,$i" in
157 y,*) is_hash=n ;;
158 n,*^{}) is_hash=y ;;
159 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
160 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
35e65ecc 161 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
162 n,*) is_hash=y; echo "$i" ;;
163 esac
164 done
165}
166
167__git_refs2 ()
168{
67ffa114
SP
169 local i
170 for i in $(__git_refs "$1"); do
171 echo "$i:$i"
690d8824
JH
172 done
173}
174
5de40f59
SP
175__git_refs_remotes ()
176{
177 local cmd i is_hash=y
178 for i in $(git-ls-remote "$1" 2>/dev/null); do
179 case "$is_hash,$i" in
180 n,refs/heads/*)
181 is_hash=y
182 echo "$i:refs/remotes/$1/${i#refs/heads/}"
183 ;;
184 y,*) is_hash=n ;;
185 n,*^{}) is_hash=y ;;
186 n,refs/tags/*) is_hash=y;;
187 n,*) is_hash=y; ;;
188 esac
189 done
190}
191
690d8824
JH
192__git_remotes ()
193{
873537fa 194 local i ngoff IFS=$'\n' d="$(__gitdir)"
56fc25f2 195 shopt -q nullglob || ngoff=1
690d8824 196 shopt -s nullglob
873537fa
SP
197 for i in "$d/remotes"/*; do
198 echo ${i#$d/remotes/}
690d8824 199 done
56fc25f2 200 [ "$ngoff" ] && shopt -u nullglob
e0d10e1c 201 for i in $(git --git-dir="$d" config --list); do
56fc25f2
SP
202 case "$i" in
203 remote.*.url=*)
204 i="${i#remote.}"
205 echo "${i/.url=*/}"
206 ;;
207 esac
208 done
690d8824
JH
209}
210
4ad91321
SP
211__git_merge_strategies ()
212{
b51ec6bd
SP
213 if [ -n "$__git_merge_strategylist" ]; then
214 echo "$__git_merge_strategylist"
215 return
216 fi
4ad91321
SP
217 sed -n "/^all_strategies='/{
218 s/^all_strategies='//
219 s/'//
220 p
221 q
222 }" "$(git --exec-path)/git-merge"
223}
b51ec6bd
SP
224__git_merge_strategylist=
225__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
4ad91321 226
690d8824
JH
227__git_complete_file ()
228{
a79c6551 229 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
690d8824
JH
230 case "$cur" in
231 ?*:*)
a79c6551
SP
232 ref="${cur%%:*}"
233 cur="${cur#*:}"
690d8824
JH
234 case "$cur" in
235 ?*/*)
a79c6551
SP
236 pfx="${cur%/*}"
237 cur="${cur##*/}"
690d8824
JH
238 ls="$ref:$pfx"
239 pfx="$pfx/"
240 ;;
241 *)
242 ls="$ref"
243 ;;
244 esac
245 COMPREPLY=($(compgen -P "$pfx" \
873537fa 246 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
690d8824
JH
247 | sed '/^100... blob /s,^.* ,,
248 /^040000 tree /{
249 s,^.* ,,
250 s,$,/,
251 }
252 s/^.* //')" \
253 -- "$cur"))
254 ;;
255 *)
b3391775 256 __gitcomp "$(__git_refs)"
690d8824
JH
257 ;;
258 esac
259}
260
f53352fb
SP
261__git_complete_revlist ()
262{
263 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
264 case "$cur" in
265 *...*)
266 pfx="${cur%...*}..."
267 cur="${cur#*...}"
b3391775 268 __gitcomp "$(__git_refs)" "$pfx" "$cur"
f53352fb
SP
269 ;;
270 *..*)
271 pfx="${cur%..*}.."
272 cur="${cur#*..}"
b3391775
SP
273 __gitcomp "$(__git_refs)" "$pfx" "$cur"
274 ;;
275 *.)
276 __gitcomp "$cur."
f53352fb
SP
277 ;;
278 *)
b3391775 279 __gitcomp "$(__git_refs)"
f53352fb
SP
280 ;;
281 esac
282}
283
f2bb9f88
SP
284__git_commands ()
285{
b51ec6bd
SP
286 if [ -n "$__git_commandlist" ]; then
287 echo "$__git_commandlist"
288 return
289 fi
f2bb9f88
SP
290 local i IFS=" "$'\n'
291 for i in $(git help -a|egrep '^ ')
292 do
293 case $i in
8435b548 294 add--interactive) : plumbing;;
a925c6f1
SP
295 applymbox) : ask gittus;;
296 applypatch) : ask gittus;;
297 archimport) : import;;
2e3a430a 298 cat-file) : plumbing;;
56d99c67 299 check-attr) : plumbing;;
f2bb9f88
SP
300 check-ref-format) : plumbing;;
301 commit-tree) : plumbing;;
a925c6f1
SP
302 cvsexportcommit) : export;;
303 cvsimport) : import;;
f2bb9f88
SP
304 cvsserver) : daemon;;
305 daemon) : daemon;;
5cfb4fe5
SP
306 diff-files) : plumbing;;
307 diff-index) : plumbing;;
308 diff-tree) : plumbing;;
c6ec3b13 309 fast-import) : import;;
a925c6f1 310 fsck-objects) : plumbing;;
56d99c67 311 fetch--tool) : plumbing;;
f2bb9f88 312 fetch-pack) : plumbing;;
a925c6f1 313 fmt-merge-msg) : plumbing;;
56d99c67 314 for-each-ref) : plumbing;;
f2bb9f88
SP
315 hash-object) : plumbing;;
316 http-*) : transport;;
317 index-pack) : plumbing;;
a925c6f1 318 init-db) : deprecated;;
f2bb9f88
SP
319 local-fetch) : plumbing;;
320 mailinfo) : plumbing;;
321 mailsplit) : plumbing;;
322 merge-*) : plumbing;;
323 mktree) : plumbing;;
324 mktag) : plumbing;;
325 pack-objects) : plumbing;;
326 pack-redundant) : plumbing;;
327 pack-refs) : plumbing;;
328 parse-remote) : plumbing;;
329 patch-id) : plumbing;;
330 peek-remote) : plumbing;;
a925c6f1
SP
331 prune) : plumbing;;
332 prune-packed) : plumbing;;
333 quiltimport) : import;;
f2bb9f88
SP
334 read-tree) : plumbing;;
335 receive-pack) : plumbing;;
2e3a430a 336 reflog) : plumbing;;
a925c6f1 337 repo-config) : plumbing;;
f2bb9f88
SP
338 rerere) : plumbing;;
339 rev-list) : plumbing;;
340 rev-parse) : plumbing;;
341 runstatus) : plumbing;;
342 sh-setup) : internal;;
343 shell) : daemon;;
344 send-pack) : plumbing;;
345 show-index) : plumbing;;
346 ssh-*) : transport;;
347 stripspace) : plumbing;;
a925c6f1 348 svn) : import export;;
f2bb9f88 349 symbolic-ref) : plumbing;;
a925c6f1 350 tar-tree) : deprecated;;
f2bb9f88
SP
351 unpack-file) : plumbing;;
352 unpack-objects) : plumbing;;
a925c6f1 353 update-index) : plumbing;;
f2bb9f88
SP
354 update-ref) : plumbing;;
355 update-server-info) : daemon;;
356 upload-archive) : plumbing;;
357 upload-pack) : plumbing;;
358 write-tree) : plumbing;;
a925c6f1 359 verify-tag) : plumbing;;
f2bb9f88
SP
360 *) echo $i;;
361 esac
362 done
363}
b51ec6bd
SP
364__git_commandlist=
365__git_commandlist="$(__git_commands 2>/dev/null)"
f2bb9f88 366
367dce2a
DS
367__git_aliases ()
368{
56fc25f2 369 local i IFS=$'\n'
e0d10e1c 370 for i in $(git --git-dir="$(__gitdir)" config --list); do
56fc25f2
SP
371 case "$i" in
372 alias.*)
373 i="${i#alias.}"
374 echo "${i/=*/}"
375 ;;
376 esac
377 done
367dce2a
DS
378}
379
380__git_aliased_command ()
381{
873537fa 382 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 383 config --get "alias.$1")
367dce2a
DS
384 for word in $cmdline; do
385 if [ "${word##-*}" ]; then
386 echo $word
387 return
388 fi
389 done
390}
391
88329195
SP
392__git_whitespacelist="nowarn warn error error-all strip"
393
394_git_am ()
395{
396 local cur="${COMP_WORDS[COMP_CWORD]}"
397 if [ -d .dotest ]; then
b3391775 398 __gitcomp "--skip --resolved"
88329195
SP
399 return
400 fi
401 case "$cur" in
402 --whitespace=*)
b3391775 403 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
404 return
405 ;;
406 --*)
b3391775 407 __gitcomp "
88329195
SP
408 --signoff --utf8 --binary --3way --interactive
409 --whitespace=
b3391775 410 "
88329195
SP
411 return
412 esac
413 COMPREPLY=()
414}
415
416_git_apply ()
417{
418 local cur="${COMP_WORDS[COMP_CWORD]}"
419 case "$cur" in
420 --whitespace=*)
b3391775 421 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
422 return
423 ;;
424 --*)
b3391775 425 __gitcomp "
88329195
SP
426 --stat --numstat --summary --check --index
427 --cached --index-info --reverse --reject --unidiff-zero
428 --apply --no-add --exclude=
429 --whitespace= --inaccurate-eof --verbose
b3391775 430 "
88329195
SP
431 return
432 esac
433 COMPREPLY=()
434}
435
8435b548
SP
436_git_add ()
437{
438 local cur="${COMP_WORDS[COMP_CWORD]}"
439 case "$cur" in
440 --*)
47e98eec 441 __gitcomp "--interactive --refresh"
8435b548
SP
442 return
443 esac
444 COMPREPLY=()
445}
446
b2e69f62
SP
447_git_bisect ()
448{
449 local i c=1 command
450 while [ $c -lt $COMP_CWORD ]; do
451 i="${COMP_WORDS[c]}"
452 case "$i" in
453 start|bad|good|reset|visualize|replay|log)
454 command="$i"
455 break
456 ;;
457 esac
458 c=$((++c))
459 done
460
461 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
462 __gitcomp "start bad good reset visualize replay log"
463 return
464 fi
465
466 case "$command" in
467 bad|good|reset)
468 __gitcomp "$(__git_refs)"
469 ;;
470 *)
471 COMPREPLY=()
472 ;;
473 esac
474}
475
690d8824
JH
476_git_branch ()
477{
b3391775 478 __gitcomp "$(__git_refs)"
690d8824
JH
479}
480
374a58c9
ML
481_git_bundle ()
482{
483 local mycword="$COMP_CWORD"
484 case "${COMP_WORDS[0]}" in
485 git)
486 local cmd="${COMP_WORDS[2]}"
487 mycword="$((mycword-1))"
488 ;;
489 git-bundle*)
490 local cmd="${COMP_WORDS[1]}"
491 ;;
492 esac
493 case "$mycword" in
494 1)
495 __gitcomp "create list-heads verify unbundle"
496 ;;
497 2)
498 # looking for a file
499 ;;
500 *)
501 case "$cmd" in
502 create)
503 __git_complete_revlist
504 ;;
505 esac
506 ;;
507 esac
508}
509
690d8824
JH
510_git_checkout ()
511{
b3391775 512 __gitcomp "$(__git_refs)"
690d8824
JH
513}
514
d8a9fea5
SP
515_git_cherry ()
516{
517 __gitcomp "$(__git_refs)"
518}
519
1273231e
SP
520_git_cherry_pick ()
521{
522 local cur="${COMP_WORDS[COMP_CWORD]}"
523 case "$cur" in
524 --*)
b3391775 525 __gitcomp "--edit --no-commit"
1273231e
SP
526 ;;
527 *)
b3391775 528 __gitcomp "$(__git_refs)"
1273231e
SP
529 ;;
530 esac
531}
532
4548e855
SP
533_git_commit ()
534{
535 local cur="${COMP_WORDS[COMP_CWORD]}"
536 case "$cur" in
537 --*)
b3391775 538 __gitcomp "
4548e855
SP
539 --all --author= --signoff --verify --no-verify
540 --edit --amend --include --only
b3391775 541 "
4548e855
SP
542 return
543 esac
544 COMPREPLY=()
545}
546
217926c0
SP
547_git_describe ()
548{
549 __gitcomp "$(__git_refs)"
550}
551
690d8824
JH
552_git_diff ()
553{
554 __git_complete_file
555}
556
557_git_diff_tree ()
558{
b3391775 559 __gitcomp "$(__git_refs)"
690d8824
JH
560}
561
562_git_fetch ()
563{
564 local cur="${COMP_WORDS[COMP_CWORD]}"
565
566 case "${COMP_WORDS[0]},$COMP_CWORD" in
567 git-fetch*,1)
b3391775 568 __gitcomp "$(__git_remotes)"
690d8824
JH
569 ;;
570 git,2)
b3391775 571 __gitcomp "$(__git_remotes)"
690d8824
JH
572 ;;
573 *)
574 case "$cur" in
575 *:*)
b3391775 576 __gitcomp "$(__git_refs)" "" "${cur#*:}"
690d8824
JH
577 ;;
578 *)
579 local remote
580 case "${COMP_WORDS[0]}" in
581 git-fetch) remote="${COMP_WORDS[1]}" ;;
582 git) remote="${COMP_WORDS[2]}" ;;
583 esac
b3391775 584 __gitcomp "$(__git_refs2 "$remote")"
690d8824
JH
585 ;;
586 esac
587 ;;
588 esac
589}
590
f53352fb
SP
591_git_format_patch ()
592{
593 local cur="${COMP_WORDS[COMP_CWORD]}"
594 case "$cur" in
595 --*)
b3391775 596 __gitcomp "
f53352fb
SP
597 --stdout --attach --thread
598 --output-directory
599 --numbered --start-number
47e98eec 600 --numbered-files
f53352fb
SP
601 --keep-subject
602 --signoff
603 --in-reply-to=
604 --full-index --binary
ec804891 605 --not --all
b3391775 606 "
f53352fb
SP
607 return
608 ;;
609 esac
610 __git_complete_revlist
611}
612
b26c8748
SP
613_git_gc ()
614{
615 local cur="${COMP_WORDS[COMP_CWORD]}"
616 case "$cur" in
617 --*)
47e98eec 618 __gitcomp "--prune --aggressive"
b26c8748
SP
619 return
620 ;;
621 esac
622 COMPREPLY=()
623}
624
690d8824
JH
625_git_ls_remote ()
626{
b3391775 627 __gitcomp "$(__git_remotes)"
690d8824
JH
628}
629
630_git_ls_tree ()
631{
632 __git_complete_file
633}
634
635_git_log ()
636{
6e31b866
SP
637 local cur="${COMP_WORDS[COMP_CWORD]}"
638 case "$cur" in
639 --pretty=*)
b3391775 640 __gitcomp "
6e31b866 641 oneline short medium full fuller email raw
b3391775 642 " "" "${cur##--pretty=}"
6e31b866
SP
643 return
644 ;;
47e98eec
SP
645 --date=*)
646 __gitcomp "
647 relative iso8601 rfc2822 short local default
648 " "" "${cur##--date=}"
649 return
650 ;;
6e31b866 651 --*)
b3391775 652 __gitcomp "
6e31b866
SP
653 --max-count= --max-age= --since= --after=
654 --min-age= --before= --until=
8f87fae6 655 --root --topo-order --date-order --reverse
47e98eec 656 --no-merges --follow
6e31b866 657 --abbrev-commit --abbrev=
47e98eec 658 --relative-date --date=
6e31b866
SP
659 --author= --committer= --grep=
660 --all-match
8f87fae6 661 --pretty= --name-status --name-only --raw
ec804891 662 --not --all
7d37b5bf 663 --left-right --cherry-pick
b3391775 664 "
6e31b866
SP
665 return
666 ;;
667 esac
f53352fb 668 __git_complete_revlist
690d8824
JH
669}
670
4ad91321
SP
671_git_merge ()
672{
673 local cur="${COMP_WORDS[COMP_CWORD]}"
ce1e39d2
SP
674 case "${COMP_WORDS[COMP_CWORD-1]}" in
675 -s|--strategy)
b3391775 676 __gitcomp "$(__git_merge_strategies)"
ce1e39d2
SP
677 return
678 esac
4ad91321 679 case "$cur" in
ce1e39d2 680 --strategy=*)
b3391775 681 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
682 return
683 ;;
4ad91321 684 --*)
b3391775 685 __gitcomp "
61d926a3 686 --no-commit --no-summary --squash --strategy
b3391775 687 "
4ad91321
SP
688 return
689 esac
b3391775 690 __gitcomp "$(__git_refs)"
4ad91321
SP
691}
692
690d8824
JH
693_git_merge_base ()
694{
b3391775 695 __gitcomp "$(__git_refs)"
690d8824
JH
696}
697
d33909bf
SP
698_git_name_rev ()
699{
b3391775 700 __gitcomp "--tags --all --stdin"
d33909bf
SP
701}
702
690d8824
JH
703_git_pull ()
704{
705 local cur="${COMP_WORDS[COMP_CWORD]}"
706
707 case "${COMP_WORDS[0]},$COMP_CWORD" in
708 git-pull*,1)
b3391775 709 __gitcomp "$(__git_remotes)"
690d8824
JH
710 ;;
711 git,2)
b3391775 712 __gitcomp "$(__git_remotes)"
690d8824
JH
713 ;;
714 *)
715 local remote
716 case "${COMP_WORDS[0]}" in
717 git-pull) remote="${COMP_WORDS[1]}" ;;
718 git) remote="${COMP_WORDS[2]}" ;;
719 esac
b3391775 720 __gitcomp "$(__git_refs "$remote")"
690d8824
JH
721 ;;
722 esac
723}
724
725_git_push ()
726{
727 local cur="${COMP_WORDS[COMP_CWORD]}"
728
729 case "${COMP_WORDS[0]},$COMP_CWORD" in
730 git-push*,1)
b3391775 731 __gitcomp "$(__git_remotes)"
690d8824
JH
732 ;;
733 git,2)
b3391775 734 __gitcomp "$(__git_remotes)"
690d8824
JH
735 ;;
736 *)
737 case "$cur" in
738 *:*)
739 local remote
740 case "${COMP_WORDS[0]}" in
741 git-push) remote="${COMP_WORDS[1]}" ;;
742 git) remote="${COMP_WORDS[2]}" ;;
743 esac
b3391775 744 __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
690d8824 745 ;;
161fea83
SP
746 +*)
747 __gitcomp "$(__git_refs)" + "${cur#+}"
748 ;;
690d8824 749 *)
92d7c8e3 750 __gitcomp "$(__git_refs)"
690d8824
JH
751 ;;
752 esac
753 ;;
754 esac
755}
756
61d926a3
SP
757_git_rebase ()
758{
759 local cur="${COMP_WORDS[COMP_CWORD]}"
c5650b08 760 if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
b3391775 761 __gitcomp "--continue --skip --abort"
61d926a3
SP
762 return
763 fi
ce1e39d2
SP
764 case "${COMP_WORDS[COMP_CWORD-1]}" in
765 -s|--strategy)
b3391775 766 __gitcomp "$(__git_merge_strategies)"
ce1e39d2
SP
767 return
768 esac
61d926a3 769 case "$cur" in
ce1e39d2 770 --strategy=*)
b3391775 771 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
772 return
773 ;;
61d926a3 774 --*)
b3391775 775 __gitcomp "--onto --merge --strategy"
61d926a3
SP
776 return
777 esac
b3391775 778 __gitcomp "$(__git_refs)"
61d926a3
SP
779}
780
e0d10e1c 781_git_config ()
5de40f59
SP
782{
783 local cur="${COMP_WORDS[COMP_CWORD]}"
784 local prv="${COMP_WORDS[COMP_CWORD-1]}"
785 case "$prv" in
786 branch.*.remote)
78d4d6a2 787 __gitcomp "$(__git_remotes)"
5de40f59
SP
788 return
789 ;;
790 branch.*.merge)
78d4d6a2 791 __gitcomp "$(__git_refs)"
5de40f59
SP
792 return
793 ;;
794 remote.*.fetch)
795 local remote="${prv#remote.}"
796 remote="${remote%.fetch}"
78d4d6a2 797 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
798 return
799 ;;
800 remote.*.push)
801 local remote="${prv#remote.}"
802 remote="${remote%.push}"
78d4d6a2 803 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 804 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
805 refs/heads)"
806 return
807 ;;
808 pull.twohead|pull.octopus)
809 __gitcomp "$(__git_merge_strategies)"
810 return
811 ;;
812 color.branch|color.diff|color.status)
813 __gitcomp "always never auto"
814 return
815 ;;
816 color.*.*)
817 __gitcomp "
818 black red green yellow blue magenta cyan white
819 bold dim ul blink reverse
820 "
5de40f59
SP
821 return
822 ;;
823 *.*)
824 COMPREPLY=()
825 return
826 ;;
827 esac
828 case "$cur" in
829 --*)
78d4d6a2 830 __gitcomp "
47e98eec 831 --global --system --file=
12977705 832 --list --replace-all
5de40f59 833 --get --get-all --get-regexp
1b71eb35 834 --add --unset --unset-all
12977705 835 --remove-section --rename-section
78d4d6a2 836 "
5de40f59
SP
837 return
838 ;;
839 branch.*.*)
840 local pfx="${cur%.*}."
841 cur="${cur##*.}"
78d4d6a2 842 __gitcomp "remote merge" "$pfx" "$cur"
5de40f59
SP
843 return
844 ;;
845 branch.*)
846 local pfx="${cur%.*}."
847 cur="${cur#*.}"
78d4d6a2 848 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
5de40f59
SP
849 return
850 ;;
851 remote.*.*)
852 local pfx="${cur%.*}."
853 cur="${cur##*.}"
12977705
SP
854 __gitcomp "
855 url fetch push skipDefaultUpdate
856 receivepack uploadpack tagopt
857 " "$pfx" "$cur"
5de40f59
SP
858 return
859 ;;
860 remote.*)
861 local pfx="${cur%.*}."
862 cur="${cur#*.}"
78d4d6a2 863 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
5de40f59
SP
864 return
865 ;;
866 esac
78d4d6a2 867 __gitcomp "
5de40f59
SP
868 apply.whitespace
869 core.fileMode
870 core.gitProxy
871 core.ignoreStat
872 core.preferSymlinkRefs
873 core.logAllRefUpdates
47e98eec 874 core.loosecompression
5de40f59
SP
875 core.repositoryFormatVersion
876 core.sharedRepository
877 core.warnAmbiguousRefs
878 core.compression
879 core.legacyHeaders
78d4d6a2
SP
880 core.packedGitWindowSize
881 core.packedGitLimit
2122591b 882 clean.requireForce
78d4d6a2
SP
883 color.branch
884 color.branch.current
885 color.branch.local
886 color.branch.remote
887 color.branch.plain
a159ca0c 888 color.diff
78d4d6a2
SP
889 color.diff.plain
890 color.diff.meta
891 color.diff.frag
892 color.diff.old
893 color.diff.new
894 color.diff.commit
895 color.diff.whitespace
a159ca0c 896 color.pager
a159ca0c 897 color.status
78d4d6a2
SP
898 color.status.header
899 color.status.added
900 color.status.changed
901 color.status.untracked
902 diff.renameLimit
903 diff.renames
904 fetch.unpackLimit
905 format.headers
47e98eec 906 format.subjectprefix
78d4d6a2
SP
907 gitcvs.enabled
908 gitcvs.logfile
12977705
SP
909 gitcvs.allbinary
910 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dvpass
911 gc.packrefs
78d4d6a2
SP
912 gc.reflogexpire
913 gc.reflogexpireunreachable
914 gc.rerereresolved
915 gc.rerereunresolved
5de40f59
SP
916 http.sslVerify
917 http.sslCert
918 http.sslKey
919 http.sslCAInfo
920 http.sslCAPath
921 http.maxRequests
78d4d6a2
SP
922 http.lowSpeedLimit
923 http.lowSpeedTime
5de40f59 924 http.noEPSV
78d4d6a2
SP
925 i18n.commitEncoding
926 i18n.logOutputEncoding
927 log.showroot
12977705 928 merge.tool
78d4d6a2
SP
929 merge.summary
930 merge.verbosity
5de40f59 931 pack.window
12977705 932 pack.depth
47e98eec
SP
933 pack.windowMemory
934 pack.compression
935 pack.deltaCacheSize
936 pack.deltaCacheLimit
78d4d6a2
SP
937 pull.octopus
938 pull.twohead
5de40f59 939 repack.useDeltaBaseOffset
78d4d6a2
SP
940 show.difftree
941 showbranch.default
942 tar.umask
943 transfer.unpackLimit
5de40f59
SP
944 receive.unpackLimit
945 receive.denyNonFastForwards
78d4d6a2
SP
946 user.name
947 user.email
948 user.signingkey
949 whatchanged.difftree
5de40f59 950 branch. remote.
78d4d6a2 951 "
5de40f59
SP
952}
953
88293c67
SP
954_git_remote ()
955{
956 local i c=1 command
957 while [ $c -lt $COMP_CWORD ]; do
958 i="${COMP_WORDS[c]}"
959 case "$i" in
fb72759b 960 add|show|prune|update) command="$i"; break ;;
88293c67
SP
961 esac
962 c=$((++c))
963 done
964
965 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
fb72759b 966 __gitcomp "add show prune update"
88293c67
SP
967 return
968 fi
969
970 case "$command" in
971 show|prune)
972 __gitcomp "$(__git_remotes)"
973 ;;
fb72759b
SP
974 update)
975 local i c='' IFS=$'\n'
976 for i in $(git --git-dir="$(__gitdir)" config --list); do
977 case "$i" in
978 remotes.*)
979 i="${i#remotes.}"
980 c="$c ${i/=*/}"
981 ;;
982 esac
983 done
984 __gitcomp "$c"
985 ;;
88293c67
SP
986 *)
987 COMPREPLY=()
988 ;;
989 esac
990}
991
67e78c3b
SP
992_git_reset ()
993{
994 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
995 case "$cur" in
996 --*)
997 __gitcomp "--mixed --hard --soft"
998 return
999 ;;
1000 esac
1001 __gitcomp "$(__git_refs)"
67e78c3b
SP
1002}
1003
1fd6bec9
SP
1004_git_shortlog ()
1005{
1006 local cur="${COMP_WORDS[COMP_CWORD]}"
1007 case "$cur" in
1008 --*)
1009 __gitcomp "
1010 --max-count= --max-age= --since= --after=
1011 --min-age= --before= --until=
1012 --no-merges
1013 --author= --committer= --grep=
1014 --all-match
1015 --not --all
1016 --numbered --summary
1017 "
1018 return
1019 ;;
1020 esac
1021 __git_complete_revlist
1022}
1023
90131924
SP
1024_git_show ()
1025{
1026 local cur="${COMP_WORDS[COMP_CWORD]}"
1027 case "$cur" in
1028 --pretty=*)
b3391775 1029 __gitcomp "
90131924 1030 oneline short medium full fuller email raw
b3391775 1031 " "" "${cur##--pretty=}"
90131924
SP
1032 return
1033 ;;
1034 --*)
b3391775 1035 __gitcomp "--pretty="
90131924
SP
1036 return
1037 ;;
1038 esac
1039 __git_complete_file
1040}
1041
7fd53fce
JH
1042_git_stash ()
1043{
1044 __gitcomp 'list show apply clear'
1045}
1046
be86f7a0
SP
1047_git_submodule ()
1048{
1049 local i c=1 command
1050 while [ $c -lt $COMP_CWORD ]; do
1051 i="${COMP_WORDS[c]}"
1052 case "$i" in
1053 add|status|init|update) command="$i"; break ;;
1054 esac
1055 c=$((++c))
1056 done
1057
1058 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
1059 local cur="${COMP_WORDS[COMP_CWORD]}"
1060 case "$cur" in
1061 --*)
1062 __gitcomp "--quiet --cached"
1063 ;;
1064 *)
1065 __gitcomp "add status init update"
1066 ;;
1067 esac
1068 return
1069 fi
1070}
1071
88e21dc7
SP
1072_git_tag ()
1073{
1074 local i c=1 f=0
1075 while [ $c -lt $COMP_CWORD ]; do
1076 i="${COMP_WORDS[c]}"
1077 case "$i" in
1078 -d|-v)
1079 __gitcomp "$(__git_tags)"
1080 return
1081 ;;
1082 -f)
1083 f=1
1084 ;;
1085 esac
1086 c=$((++c))
1087 done
1088
1089 case "${COMP_WORDS[COMP_CWORD-1]}" in
1090 -m|-F)
1091 COMPREPLY=()
1092 ;;
1093 -*|tag|git-tag)
1094 if [ $f = 1 ]; then
1095 __gitcomp "$(__git_tags)"
1096 else
1097 COMPREPLY=()
1098 fi
1099 ;;
1100 *)
1101 __gitcomp "$(__git_refs)"
1102 ;;
1103 esac
1104}
1105
690d8824
JH
1106_git ()
1107{
873537fa
SP
1108 local i c=1 command __git_dir
1109
1110 while [ $c -lt $COMP_CWORD ]; do
1111 i="${COMP_WORDS[c]}"
1112 case "$i" in
1113 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1114 --bare) __git_dir="." ;;
1115 --version|--help|-p|--paginate) ;;
1116 *) command="$i"; break ;;
1117 esac
1118 c=$((++c))
1119 done
1120
1121 if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
72e5e989
SP
1122 case "${COMP_WORDS[COMP_CWORD]}" in
1123 --*=*) COMPREPLY=() ;;
47e98eec
SP
1124 --*) __gitcomp "
1125 --no-pager
1126 --git-dir=
1127 --bare
1128 --version
1129 --exec-path
1130 "
1131 ;;
72e5e989
SP
1132 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1133 esac
1134 return
873537fa 1135 fi
367dce2a 1136
873537fa
SP
1137 local expansion=$(__git_aliased_command "$command")
1138 [ "$expansion" ] && command="$expansion"
367dce2a 1139
873537fa 1140 case "$command" in
88329195 1141 am) _git_am ;;
8435b548 1142 add) _git_add ;;
88329195 1143 apply) _git_apply ;;
b2e69f62 1144 bisect) _git_bisect ;;
374a58c9 1145 bundle) _git_bundle ;;
873537fa 1146 branch) _git_branch ;;
873537fa 1147 checkout) _git_checkout ;;
d8a9fea5 1148 cherry) _git_cherry ;;
1273231e 1149 cherry-pick) _git_cherry_pick ;;
4548e855 1150 commit) _git_commit ;;
e0d10e1c 1151 config) _git_config ;;
217926c0 1152 describe) _git_describe ;;
873537fa 1153 diff) _git_diff ;;
873537fa 1154 fetch) _git_fetch ;;
f53352fb 1155 format-patch) _git_format_patch ;;
b26c8748 1156 gc) _git_gc ;;
873537fa
SP
1157 log) _git_log ;;
1158 ls-remote) _git_ls_remote ;;
1159 ls-tree) _git_ls_tree ;;
4ad91321 1160 merge) _git_merge;;
873537fa 1161 merge-base) _git_merge_base ;;
d33909bf 1162 name-rev) _git_name_rev ;;
873537fa
SP
1163 pull) _git_pull ;;
1164 push) _git_push ;;
61d926a3 1165 rebase) _git_rebase ;;
88293c67 1166 remote) _git_remote ;;
873537fa 1167 reset) _git_reset ;;
1fd6bec9 1168 shortlog) _git_shortlog ;;
90131924 1169 show) _git_show ;;
873537fa 1170 show-branch) _git_log ;;
7fd53fce 1171 stash) _git_stash ;;
be86f7a0 1172 submodule) _git_submodule ;;
88e21dc7 1173 tag) _git_tag ;;
873537fa
SP
1174 whatchanged) _git_log ;;
1175 *) COMPREPLY=() ;;
1176 esac
690d8824
JH
1177}
1178
1179_gitk ()
1180{
1181 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
1182 case "$cur" in
1183 --*)
1184 __gitcomp "--not --all"
1185 return
1186 ;;
1187 esac
ec804891 1188 __git_complete_revlist
690d8824
JH
1189}
1190
1191complete -o default -o nospace -F _git git
b3391775
SP
1192complete -o default -o nospace -F _gitk gitk
1193complete -o default -o nospace -F _git_am git-am
1194complete -o default -o nospace -F _git_apply git-apply
b2e69f62 1195complete -o default -o nospace -F _git_bisect git-bisect
b3391775 1196complete -o default -o nospace -F _git_branch git-branch
374a58c9 1197complete -o default -o nospace -F _git_bundle git-bundle
b3391775 1198complete -o default -o nospace -F _git_checkout git-checkout
d8a9fea5 1199complete -o default -o nospace -F _git_cherry git-cherry
b3391775
SP
1200complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1201complete -o default -o nospace -F _git_commit git-commit
217926c0 1202complete -o default -o nospace -F _git_describe git-describe
690d8824 1203complete -o default -o nospace -F _git_diff git-diff
690d8824 1204complete -o default -o nospace -F _git_fetch git-fetch
f53352fb 1205complete -o default -o nospace -F _git_format_patch git-format-patch
b26c8748 1206complete -o default -o nospace -F _git_gc git-gc
690d8824 1207complete -o default -o nospace -F _git_log git-log
b3391775 1208complete -o default -o nospace -F _git_ls_remote git-ls-remote
690d8824 1209complete -o default -o nospace -F _git_ls_tree git-ls-tree
b3391775
SP
1210complete -o default -o nospace -F _git_merge git-merge
1211complete -o default -o nospace -F _git_merge_base git-merge-base
1212complete -o default -o nospace -F _git_name_rev git-name-rev
690d8824
JH
1213complete -o default -o nospace -F _git_pull git-pull
1214complete -o default -o nospace -F _git_push git-push
b3391775
SP
1215complete -o default -o nospace -F _git_rebase git-rebase
1216complete -o default -o nospace -F _git_config git-config
88293c67 1217complete -o default -o nospace -F _git_remote git-remote
b3391775 1218complete -o default -o nospace -F _git_reset git-reset
1fd6bec9 1219complete -o default -o nospace -F _git_shortlog git-shortlog
90131924 1220complete -o default -o nospace -F _git_show git-show
7fd53fce 1221complete -o default -o nospace -F _git_stash git-stash
be86f7a0 1222complete -o default -o nospace -F _git_submodule git-submodule
144d33de 1223complete -o default -o nospace -F _git_log git-show-branch
88e21dc7 1224complete -o default -o nospace -F _git_tag git-tag
690d8824
JH
1225complete -o default -o nospace -F _git_log git-whatchanged
1226
1227# The following are necessary only for Cygwin, and only are needed
1228# when the user has tab-completed the executable name and consequently
1229# included the '.exe' suffix.
1230#
76c3eb51 1231if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
b3391775
SP
1232complete -o default -o nospace -F _git_add git-add.exe
1233complete -o default -o nospace -F _git_apply git-apply.exe
144d33de 1234complete -o default -o nospace -F _git git.exe
b3391775 1235complete -o default -o nospace -F _git_branch git-branch.exe
374a58c9 1236complete -o default -o nospace -F _git_bundle git-bundle.exe
d8a9fea5 1237complete -o default -o nospace -F _git_cherry git-cherry.exe
217926c0 1238complete -o default -o nospace -F _git_describe git-describe.exe
690d8824 1239complete -o default -o nospace -F _git_diff git-diff.exe
f53352fb 1240complete -o default -o nospace -F _git_format_patch git-format-patch.exe
690d8824
JH
1241complete -o default -o nospace -F _git_log git-log.exe
1242complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
b3391775
SP
1243complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1244complete -o default -o nospace -F _git_name_rev git-name-rev.exe
690d8824 1245complete -o default -o nospace -F _git_push git-push.exe
b3391775 1246complete -o default -o nospace -F _git_config git-config
1fd6bec9 1247complete -o default -o nospace -F _git_shortlog git-shortlog.exe
90131924 1248complete -o default -o nospace -F _git_show git-show.exe
144d33de 1249complete -o default -o nospace -F _git_log git-show-branch.exe
88e21dc7 1250complete -o default -o nospace -F _git_tag git-tag.exe
690d8824 1251complete -o default -o nospace -F _git_log git-whatchanged.exe
76c3eb51 1252fi