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