bash: add new 'git stash' 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
3ff1320d
SG
431__git_find_subcommand ()
432{
433 local word subcommand c=1
434
435 while [ $c -lt $COMP_CWORD ]; do
436 word="${COMP_WORDS[c]}"
437 for subcommand in $1; do
438 if [ "$subcommand" = "$word" ]; then
439 echo "$subcommand"
440 return
441 fi
442 done
443 c=$((++c))
444 done
445}
446
88329195
SP
447__git_whitespacelist="nowarn warn error error-all strip"
448
449_git_am ()
450{
451 local cur="${COMP_WORDS[COMP_CWORD]}"
452 if [ -d .dotest ]; then
b3391775 453 __gitcomp "--skip --resolved"
88329195
SP
454 return
455 fi
456 case "$cur" in
457 --whitespace=*)
b3391775 458 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
459 return
460 ;;
461 --*)
b3391775 462 __gitcomp "
88329195
SP
463 --signoff --utf8 --binary --3way --interactive
464 --whitespace=
b3391775 465 "
88329195
SP
466 return
467 esac
468 COMPREPLY=()
469}
470
471_git_apply ()
472{
473 local cur="${COMP_WORDS[COMP_CWORD]}"
474 case "$cur" in
475 --whitespace=*)
b3391775 476 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
477 return
478 ;;
479 --*)
b3391775 480 __gitcomp "
88329195
SP
481 --stat --numstat --summary --check --index
482 --cached --index-info --reverse --reject --unidiff-zero
483 --apply --no-add --exclude=
484 --whitespace= --inaccurate-eof --verbose
b3391775 485 "
88329195
SP
486 return
487 esac
488 COMPREPLY=()
489}
490
8435b548
SP
491_git_add ()
492{
493 local cur="${COMP_WORDS[COMP_CWORD]}"
494 case "$cur" in
495 --*)
47e98eec 496 __gitcomp "--interactive --refresh"
8435b548
SP
497 return
498 esac
499 COMPREPLY=()
500}
501
b2e69f62
SP
502_git_bisect ()
503{
3ff1320d
SG
504 local subcommands="start bad good reset visualize replay log"
505 local subcommand="$(__git_find_subcommand "$subcommands")"
506 if [ -z "$subcommand" ]; then
507 __gitcomp "$subcommands"
b2e69f62
SP
508 return
509 fi
510
3ff1320d 511 case "$subcommand" in
b2e69f62
SP
512 bad|good|reset)
513 __gitcomp "$(__git_refs)"
514 ;;
515 *)
516 COMPREPLY=()
517 ;;
518 esac
519}
520
690d8824
JH
521_git_branch ()
522{
b9217642
SG
523 local i c=1 only_local_ref="n" has_r="n"
524
525 while [ $c -lt $COMP_CWORD ]; do
526 i="${COMP_WORDS[c]}"
527 case "$i" in
528 -d|-m) only_local_ref="y" ;;
529 -r) has_r="y" ;;
530 esac
531 c=$((++c))
532 done
533
3b376b0c
SG
534 case "${COMP_WORDS[COMP_CWORD]}" in
535 --*=*) COMPREPLY=() ;;
536 --*)
537 __gitcomp "
538 --color --no-color --verbose --abbrev= --no-abbrev
539 --track --no-track
540 "
541 ;;
b9217642
SG
542 *)
543 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
544 __gitcomp "$(__git_heads)"
545 else
546 __gitcomp "$(__git_refs)"
547 fi
548 ;;
3b376b0c 549 esac
690d8824
JH
550}
551
374a58c9
ML
552_git_bundle ()
553{
554 local mycword="$COMP_CWORD"
555 case "${COMP_WORDS[0]}" in
556 git)
557 local cmd="${COMP_WORDS[2]}"
558 mycword="$((mycword-1))"
559 ;;
560 git-bundle*)
561 local cmd="${COMP_WORDS[1]}"
562 ;;
563 esac
564 case "$mycword" in
565 1)
566 __gitcomp "create list-heads verify unbundle"
567 ;;
568 2)
569 # looking for a file
570 ;;
571 *)
572 case "$cmd" in
573 create)
574 __git_complete_revlist
575 ;;
576 esac
577 ;;
578 esac
579}
580
690d8824
JH
581_git_checkout ()
582{
b3391775 583 __gitcomp "$(__git_refs)"
690d8824
JH
584}
585
d8a9fea5
SP
586_git_cherry ()
587{
588 __gitcomp "$(__git_refs)"
589}
590
1273231e
SP
591_git_cherry_pick ()
592{
593 local cur="${COMP_WORDS[COMP_CWORD]}"
594 case "$cur" in
595 --*)
b3391775 596 __gitcomp "--edit --no-commit"
1273231e
SP
597 ;;
598 *)
b3391775 599 __gitcomp "$(__git_refs)"
1273231e
SP
600 ;;
601 esac
602}
603
4548e855
SP
604_git_commit ()
605{
606 local cur="${COMP_WORDS[COMP_CWORD]}"
607 case "$cur" in
608 --*)
b3391775 609 __gitcomp "
4548e855
SP
610 --all --author= --signoff --verify --no-verify
611 --edit --amend --include --only
b3391775 612 "
4548e855
SP
613 return
614 esac
615 COMPREPLY=()
616}
617
217926c0
SP
618_git_describe ()
619{
620 __gitcomp "$(__git_refs)"
621}
622
690d8824
JH
623_git_diff ()
624{
b3a4f858
JS
625 local cur="${COMP_WORDS[COMP_CWORD]}"
626 case "$cur" in
627 --*)
628 __gitcomp "--cached --stat --numstat --shortstat --summary
629 --patch-with-stat --name-only --name-status --color
630 --no-color --color-words --no-renames --check
631 --full-index --binary --abbrev --diff-filter
632 --find-copies-harder --pickaxe-all --pickaxe-regex
633 --text --ignore-space-at-eol --ignore-space-change
634 --ignore-all-space --exit-code --quiet --ext-diff
635 --no-ext-diff"
636 return
637 ;;
638 esac
690d8824
JH
639 __git_complete_file
640}
641
642_git_diff_tree ()
643{
b3391775 644 __gitcomp "$(__git_refs)"
690d8824
JH
645}
646
647_git_fetch ()
648{
649 local cur="${COMP_WORDS[COMP_CWORD]}"
650
651 case "${COMP_WORDS[0]},$COMP_CWORD" in
652 git-fetch*,1)
b3391775 653 __gitcomp "$(__git_remotes)"
690d8824
JH
654 ;;
655 git,2)
b3391775 656 __gitcomp "$(__git_remotes)"
690d8824
JH
657 ;;
658 *)
659 case "$cur" in
660 *:*)
b3391775 661 __gitcomp "$(__git_refs)" "" "${cur#*:}"
690d8824
JH
662 ;;
663 *)
664 local remote
665 case "${COMP_WORDS[0]}" in
666 git-fetch) remote="${COMP_WORDS[1]}" ;;
667 git) remote="${COMP_WORDS[2]}" ;;
668 esac
b3391775 669 __gitcomp "$(__git_refs2 "$remote")"
690d8824
JH
670 ;;
671 esac
672 ;;
673 esac
674}
675
f53352fb
SP
676_git_format_patch ()
677{
678 local cur="${COMP_WORDS[COMP_CWORD]}"
679 case "$cur" in
680 --*)
b3391775 681 __gitcomp "
f53352fb
SP
682 --stdout --attach --thread
683 --output-directory
684 --numbered --start-number
47e98eec 685 --numbered-files
f53352fb
SP
686 --keep-subject
687 --signoff
688 --in-reply-to=
689 --full-index --binary
ec804891 690 --not --all
be5f5bf0 691 --cover-letter
b3391775 692 "
f53352fb
SP
693 return
694 ;;
695 esac
696 __git_complete_revlist
697}
698
b26c8748
SP
699_git_gc ()
700{
701 local cur="${COMP_WORDS[COMP_CWORD]}"
702 case "$cur" in
703 --*)
47e98eec 704 __gitcomp "--prune --aggressive"
b26c8748
SP
705 return
706 ;;
707 esac
708 COMPREPLY=()
709}
710
690d8824
JH
711_git_ls_remote ()
712{
b3391775 713 __gitcomp "$(__git_remotes)"
690d8824
JH
714}
715
716_git_ls_tree ()
717{
718 __git_complete_file
719}
720
721_git_log ()
722{
6e31b866
SP
723 local cur="${COMP_WORDS[COMP_CWORD]}"
724 case "$cur" in
725 --pretty=*)
b3391775 726 __gitcomp "
6e31b866 727 oneline short medium full fuller email raw
b3391775 728 " "" "${cur##--pretty=}"
6e31b866
SP
729 return
730 ;;
47e98eec
SP
731 --date=*)
732 __gitcomp "
733 relative iso8601 rfc2822 short local default
734 " "" "${cur##--date=}"
735 return
736 ;;
6e31b866 737 --*)
b3391775 738 __gitcomp "
6e31b866
SP
739 --max-count= --max-age= --since= --after=
740 --min-age= --before= --until=
8f87fae6 741 --root --topo-order --date-order --reverse
47e98eec 742 --no-merges --follow
6e31b866 743 --abbrev-commit --abbrev=
47e98eec 744 --relative-date --date=
6e31b866
SP
745 --author= --committer= --grep=
746 --all-match
8f87fae6 747 --pretty= --name-status --name-only --raw
ec804891 748 --not --all
7d37b5bf 749 --left-right --cherry-pick
b3391775 750 "
6e31b866
SP
751 return
752 ;;
753 esac
f53352fb 754 __git_complete_revlist
690d8824
JH
755}
756
4ad91321
SP
757_git_merge ()
758{
759 local cur="${COMP_WORDS[COMP_CWORD]}"
ce1e39d2
SP
760 case "${COMP_WORDS[COMP_CWORD-1]}" in
761 -s|--strategy)
b3391775 762 __gitcomp "$(__git_merge_strategies)"
ce1e39d2
SP
763 return
764 esac
4ad91321 765 case "$cur" in
ce1e39d2 766 --strategy=*)
b3391775 767 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
768 return
769 ;;
4ad91321 770 --*)
b3391775 771 __gitcomp "
61d926a3 772 --no-commit --no-summary --squash --strategy
b3391775 773 "
4ad91321
SP
774 return
775 esac
b3391775 776 __gitcomp "$(__git_refs)"
4ad91321
SP
777}
778
690d8824
JH
779_git_merge_base ()
780{
b3391775 781 __gitcomp "$(__git_refs)"
690d8824
JH
782}
783
d33909bf
SP
784_git_name_rev ()
785{
b3391775 786 __gitcomp "--tags --all --stdin"
d33909bf
SP
787}
788
690d8824
JH
789_git_pull ()
790{
791 local cur="${COMP_WORDS[COMP_CWORD]}"
792
793 case "${COMP_WORDS[0]},$COMP_CWORD" in
794 git-pull*,1)
b3391775 795 __gitcomp "$(__git_remotes)"
690d8824
JH
796 ;;
797 git,2)
b3391775 798 __gitcomp "$(__git_remotes)"
690d8824
JH
799 ;;
800 *)
801 local remote
802 case "${COMP_WORDS[0]}" in
803 git-pull) remote="${COMP_WORDS[1]}" ;;
804 git) remote="${COMP_WORDS[2]}" ;;
805 esac
b3391775 806 __gitcomp "$(__git_refs "$remote")"
690d8824
JH
807 ;;
808 esac
809}
810
811_git_push ()
812{
813 local cur="${COMP_WORDS[COMP_CWORD]}"
814
815 case "${COMP_WORDS[0]},$COMP_CWORD" in
816 git-push*,1)
b3391775 817 __gitcomp "$(__git_remotes)"
690d8824
JH
818 ;;
819 git,2)
b3391775 820 __gitcomp "$(__git_remotes)"
690d8824
JH
821 ;;
822 *)
823 case "$cur" in
824 *:*)
825 local remote
826 case "${COMP_WORDS[0]}" in
827 git-push) remote="${COMP_WORDS[1]}" ;;
828 git) remote="${COMP_WORDS[2]}" ;;
829 esac
b3391775 830 __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
690d8824 831 ;;
161fea83
SP
832 +*)
833 __gitcomp "$(__git_refs)" + "${cur#+}"
834 ;;
690d8824 835 *)
92d7c8e3 836 __gitcomp "$(__git_refs)"
690d8824
JH
837 ;;
838 esac
839 ;;
840 esac
841}
842
61d926a3
SP
843_git_rebase ()
844{
845 local cur="${COMP_WORDS[COMP_CWORD]}"
c5650b08 846 if [ -d .dotest ] || [ -d .git/.dotest-merge ]; then
b3391775 847 __gitcomp "--continue --skip --abort"
61d926a3
SP
848 return
849 fi
ce1e39d2
SP
850 case "${COMP_WORDS[COMP_CWORD-1]}" in
851 -s|--strategy)
b3391775 852 __gitcomp "$(__git_merge_strategies)"
ce1e39d2
SP
853 return
854 esac
61d926a3 855 case "$cur" in
ce1e39d2 856 --strategy=*)
b3391775 857 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
ce1e39d2
SP
858 return
859 ;;
61d926a3 860 --*)
b3391775 861 __gitcomp "--onto --merge --strategy"
61d926a3
SP
862 return
863 esac
b3391775 864 __gitcomp "$(__git_refs)"
61d926a3
SP
865}
866
e0d10e1c 867_git_config ()
5de40f59
SP
868{
869 local cur="${COMP_WORDS[COMP_CWORD]}"
870 local prv="${COMP_WORDS[COMP_CWORD-1]}"
871 case "$prv" in
872 branch.*.remote)
78d4d6a2 873 __gitcomp "$(__git_remotes)"
5de40f59
SP
874 return
875 ;;
876 branch.*.merge)
78d4d6a2 877 __gitcomp "$(__git_refs)"
5de40f59
SP
878 return
879 ;;
880 remote.*.fetch)
881 local remote="${prv#remote.}"
882 remote="${remote%.fetch}"
78d4d6a2 883 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
884 return
885 ;;
886 remote.*.push)
887 local remote="${prv#remote.}"
888 remote="${remote%.push}"
78d4d6a2 889 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 890 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
891 refs/heads)"
892 return
893 ;;
894 pull.twohead|pull.octopus)
895 __gitcomp "$(__git_merge_strategies)"
896 return
897 ;;
898 color.branch|color.diff|color.status)
899 __gitcomp "always never auto"
900 return
901 ;;
902 color.*.*)
903 __gitcomp "
904 black red green yellow blue magenta cyan white
905 bold dim ul blink reverse
906 "
5de40f59
SP
907 return
908 ;;
909 *.*)
910 COMPREPLY=()
911 return
912 ;;
913 esac
914 case "$cur" in
915 --*)
78d4d6a2 916 __gitcomp "
47e98eec 917 --global --system --file=
12977705 918 --list --replace-all
5de40f59 919 --get --get-all --get-regexp
1b71eb35 920 --add --unset --unset-all
12977705 921 --remove-section --rename-section
78d4d6a2 922 "
5de40f59
SP
923 return
924 ;;
925 branch.*.*)
926 local pfx="${cur%.*}."
927 cur="${cur##*.}"
78d4d6a2 928 __gitcomp "remote merge" "$pfx" "$cur"
5de40f59
SP
929 return
930 ;;
931 branch.*)
932 local pfx="${cur%.*}."
933 cur="${cur#*.}"
78d4d6a2 934 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
5de40f59
SP
935 return
936 ;;
937 remote.*.*)
938 local pfx="${cur%.*}."
939 cur="${cur##*.}"
12977705
SP
940 __gitcomp "
941 url fetch push skipDefaultUpdate
942 receivepack uploadpack tagopt
943 " "$pfx" "$cur"
5de40f59
SP
944 return
945 ;;
946 remote.*)
947 local pfx="${cur%.*}."
948 cur="${cur#*.}"
78d4d6a2 949 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
5de40f59
SP
950 return
951 ;;
952 esac
78d4d6a2 953 __gitcomp "
5de40f59
SP
954 apply.whitespace
955 core.fileMode
956 core.gitProxy
957 core.ignoreStat
958 core.preferSymlinkRefs
959 core.logAllRefUpdates
47e98eec 960 core.loosecompression
5de40f59
SP
961 core.repositoryFormatVersion
962 core.sharedRepository
963 core.warnAmbiguousRefs
964 core.compression
965 core.legacyHeaders
78d4d6a2
SP
966 core.packedGitWindowSize
967 core.packedGitLimit
2122591b 968 clean.requireForce
78d4d6a2
SP
969 color.branch
970 color.branch.current
971 color.branch.local
972 color.branch.remote
973 color.branch.plain
a159ca0c 974 color.diff
78d4d6a2
SP
975 color.diff.plain
976 color.diff.meta
977 color.diff.frag
978 color.diff.old
979 color.diff.new
980 color.diff.commit
981 color.diff.whitespace
a159ca0c 982 color.pager
a159ca0c 983 color.status
78d4d6a2
SP
984 color.status.header
985 color.status.added
986 color.status.changed
987 color.status.untracked
988 diff.renameLimit
989 diff.renames
990 fetch.unpackLimit
991 format.headers
47e98eec 992 format.subjectprefix
78d4d6a2
SP
993 gitcvs.enabled
994 gitcvs.logfile
12977705
SP
995 gitcvs.allbinary
996 gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dvpass
997 gc.packrefs
78d4d6a2
SP
998 gc.reflogexpire
999 gc.reflogexpireunreachable
1000 gc.rerereresolved
1001 gc.rerereunresolved
5de40f59
SP
1002 http.sslVerify
1003 http.sslCert
1004 http.sslKey
1005 http.sslCAInfo
1006 http.sslCAPath
1007 http.maxRequests
78d4d6a2
SP
1008 http.lowSpeedLimit
1009 http.lowSpeedTime
5de40f59 1010 http.noEPSV
78d4d6a2
SP
1011 i18n.commitEncoding
1012 i18n.logOutputEncoding
1013 log.showroot
12977705 1014 merge.tool
78d4d6a2
SP
1015 merge.summary
1016 merge.verbosity
5de40f59 1017 pack.window
12977705 1018 pack.depth
47e98eec
SP
1019 pack.windowMemory
1020 pack.compression
1021 pack.deltaCacheSize
1022 pack.deltaCacheLimit
78d4d6a2
SP
1023 pull.octopus
1024 pull.twohead
5de40f59 1025 repack.useDeltaBaseOffset
78d4d6a2
SP
1026 show.difftree
1027 showbranch.default
1028 tar.umask
1029 transfer.unpackLimit
5de40f59
SP
1030 receive.unpackLimit
1031 receive.denyNonFastForwards
78d4d6a2
SP
1032 user.name
1033 user.email
1034 user.signingkey
1035 whatchanged.difftree
5de40f59 1036 branch. remote.
78d4d6a2 1037 "
5de40f59
SP
1038}
1039
88293c67
SP
1040_git_remote ()
1041{
3ff1320d
SG
1042 local subcommands="add rm show prune update"
1043 local subcommand="$(__git_find_subcommand "$subcommands")"
1044 if [ -z "$subcommand" ]; then
88293c67
SP
1045 return
1046 fi
1047
3ff1320d 1048 case "$subcommand" in
a3b811a4 1049 rm|show|prune)
88293c67
SP
1050 __gitcomp "$(__git_remotes)"
1051 ;;
fb72759b
SP
1052 update)
1053 local i c='' IFS=$'\n'
1054 for i in $(git --git-dir="$(__gitdir)" config --list); do
1055 case "$i" in
1056 remotes.*)
1057 i="${i#remotes.}"
1058 c="$c ${i/=*/}"
1059 ;;
1060 esac
1061 done
1062 __gitcomp "$c"
1063 ;;
88293c67
SP
1064 *)
1065 COMPREPLY=()
1066 ;;
1067 esac
1068}
1069
67e78c3b
SP
1070_git_reset ()
1071{
1072 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
1073 case "$cur" in
1074 --*)
1075 __gitcomp "--mixed --hard --soft"
1076 return
1077 ;;
1078 esac
1079 __gitcomp "$(__git_refs)"
67e78c3b
SP
1080}
1081
1fd6bec9
SP
1082_git_shortlog ()
1083{
1084 local cur="${COMP_WORDS[COMP_CWORD]}"
1085 case "$cur" in
1086 --*)
1087 __gitcomp "
1088 --max-count= --max-age= --since= --after=
1089 --min-age= --before= --until=
1090 --no-merges
1091 --author= --committer= --grep=
1092 --all-match
1093 --not --all
1094 --numbered --summary
1095 "
1096 return
1097 ;;
1098 esac
1099 __git_complete_revlist
1100}
1101
90131924
SP
1102_git_show ()
1103{
1104 local cur="${COMP_WORDS[COMP_CWORD]}"
1105 case "$cur" in
1106 --pretty=*)
b3391775 1107 __gitcomp "
90131924 1108 oneline short medium full fuller email raw
b3391775 1109 " "" "${cur##--pretty=}"
90131924
SP
1110 return
1111 ;;
1112 --*)
b3391775 1113 __gitcomp "--pretty="
90131924
SP
1114 return
1115 ;;
1116 esac
1117 __git_complete_file
1118}
1119
7fd53fce
JH
1120_git_stash ()
1121{
88b302f5 1122 local subcommands='save list show apply clear drop pop create'
3ff1320d
SG
1123 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1124 __gitcomp "$subcommands"
1125 fi
7fd53fce
JH
1126}
1127
be86f7a0
SP
1128_git_submodule ()
1129{
3ff1320d
SG
1130 local subcommands="add status init update"
1131 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
be86f7a0
SP
1132 local cur="${COMP_WORDS[COMP_CWORD]}"
1133 case "$cur" in
1134 --*)
1135 __gitcomp "--quiet --cached"
1136 ;;
1137 *)
3ff1320d 1138 __gitcomp "$subcommands"
be86f7a0
SP
1139 ;;
1140 esac
1141 return
1142 fi
1143}
1144
88e21dc7
SP
1145_git_tag ()
1146{
1147 local i c=1 f=0
1148 while [ $c -lt $COMP_CWORD ]; do
1149 i="${COMP_WORDS[c]}"
1150 case "$i" in
1151 -d|-v)
1152 __gitcomp "$(__git_tags)"
1153 return
1154 ;;
1155 -f)
1156 f=1
1157 ;;
1158 esac
1159 c=$((++c))
1160 done
1161
1162 case "${COMP_WORDS[COMP_CWORD-1]}" in
1163 -m|-F)
1164 COMPREPLY=()
1165 ;;
1166 -*|tag|git-tag)
1167 if [ $f = 1 ]; then
1168 __gitcomp "$(__git_tags)"
1169 else
1170 COMPREPLY=()
1171 fi
1172 ;;
1173 *)
1174 __gitcomp "$(__git_refs)"
1175 ;;
1176 esac
1177}
1178
690d8824
JH
1179_git ()
1180{
873537fa
SP
1181 local i c=1 command __git_dir
1182
1183 while [ $c -lt $COMP_CWORD ]; do
1184 i="${COMP_WORDS[c]}"
1185 case "$i" in
1186 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1187 --bare) __git_dir="." ;;
1188 --version|--help|-p|--paginate) ;;
1189 *) command="$i"; break ;;
1190 esac
1191 c=$((++c))
1192 done
1193
1d17b22e 1194 if [ -z "$command" ]; then
72e5e989
SP
1195 case "${COMP_WORDS[COMP_CWORD]}" in
1196 --*=*) COMPREPLY=() ;;
47e98eec
SP
1197 --*) __gitcomp "
1198 --no-pager
1199 --git-dir=
1200 --bare
1201 --version
1202 --exec-path
1203 "
1204 ;;
72e5e989
SP
1205 *) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1206 esac
1207 return
873537fa 1208 fi
367dce2a 1209
873537fa
SP
1210 local expansion=$(__git_aliased_command "$command")
1211 [ "$expansion" ] && command="$expansion"
367dce2a 1212
873537fa 1213 case "$command" in
88329195 1214 am) _git_am ;;
8435b548 1215 add) _git_add ;;
88329195 1216 apply) _git_apply ;;
b2e69f62 1217 bisect) _git_bisect ;;
374a58c9 1218 bundle) _git_bundle ;;
873537fa 1219 branch) _git_branch ;;
873537fa 1220 checkout) _git_checkout ;;
d8a9fea5 1221 cherry) _git_cherry ;;
1273231e 1222 cherry-pick) _git_cherry_pick ;;
4548e855 1223 commit) _git_commit ;;
e0d10e1c 1224 config) _git_config ;;
217926c0 1225 describe) _git_describe ;;
873537fa 1226 diff) _git_diff ;;
873537fa 1227 fetch) _git_fetch ;;
f53352fb 1228 format-patch) _git_format_patch ;;
b26c8748 1229 gc) _git_gc ;;
873537fa
SP
1230 log) _git_log ;;
1231 ls-remote) _git_ls_remote ;;
1232 ls-tree) _git_ls_tree ;;
4ad91321 1233 merge) _git_merge;;
873537fa 1234 merge-base) _git_merge_base ;;
d33909bf 1235 name-rev) _git_name_rev ;;
873537fa
SP
1236 pull) _git_pull ;;
1237 push) _git_push ;;
61d926a3 1238 rebase) _git_rebase ;;
88293c67 1239 remote) _git_remote ;;
873537fa 1240 reset) _git_reset ;;
1fd6bec9 1241 shortlog) _git_shortlog ;;
90131924 1242 show) _git_show ;;
873537fa 1243 show-branch) _git_log ;;
7fd53fce 1244 stash) _git_stash ;;
be86f7a0 1245 submodule) _git_submodule ;;
88e21dc7 1246 tag) _git_tag ;;
873537fa
SP
1247 whatchanged) _git_log ;;
1248 *) COMPREPLY=() ;;
1249 esac
690d8824
JH
1250}
1251
1252_gitk ()
1253{
1254 local cur="${COMP_WORDS[COMP_CWORD]}"
b3391775
SP
1255 case "$cur" in
1256 --*)
1257 __gitcomp "--not --all"
1258 return
1259 ;;
1260 esac
ec804891 1261 __git_complete_revlist
690d8824
JH
1262}
1263
1264complete -o default -o nospace -F _git git
b3391775
SP
1265complete -o default -o nospace -F _gitk gitk
1266complete -o default -o nospace -F _git_am git-am
1267complete -o default -o nospace -F _git_apply git-apply
b2e69f62 1268complete -o default -o nospace -F _git_bisect git-bisect
b3391775 1269complete -o default -o nospace -F _git_branch git-branch
374a58c9 1270complete -o default -o nospace -F _git_bundle git-bundle
b3391775 1271complete -o default -o nospace -F _git_checkout git-checkout
d8a9fea5 1272complete -o default -o nospace -F _git_cherry git-cherry
b3391775
SP
1273complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1274complete -o default -o nospace -F _git_commit git-commit
217926c0 1275complete -o default -o nospace -F _git_describe git-describe
690d8824 1276complete -o default -o nospace -F _git_diff git-diff
690d8824 1277complete -o default -o nospace -F _git_fetch git-fetch
f53352fb 1278complete -o default -o nospace -F _git_format_patch git-format-patch
b26c8748 1279complete -o default -o nospace -F _git_gc git-gc
690d8824 1280complete -o default -o nospace -F _git_log git-log
b3391775 1281complete -o default -o nospace -F _git_ls_remote git-ls-remote
690d8824 1282complete -o default -o nospace -F _git_ls_tree git-ls-tree
b3391775
SP
1283complete -o default -o nospace -F _git_merge git-merge
1284complete -o default -o nospace -F _git_merge_base git-merge-base
1285complete -o default -o nospace -F _git_name_rev git-name-rev
690d8824
JH
1286complete -o default -o nospace -F _git_pull git-pull
1287complete -o default -o nospace -F _git_push git-push
b3391775
SP
1288complete -o default -o nospace -F _git_rebase git-rebase
1289complete -o default -o nospace -F _git_config git-config
88293c67 1290complete -o default -o nospace -F _git_remote git-remote
b3391775 1291complete -o default -o nospace -F _git_reset git-reset
1fd6bec9 1292complete -o default -o nospace -F _git_shortlog git-shortlog
90131924 1293complete -o default -o nospace -F _git_show git-show
7fd53fce 1294complete -o default -o nospace -F _git_stash git-stash
be86f7a0 1295complete -o default -o nospace -F _git_submodule git-submodule
144d33de 1296complete -o default -o nospace -F _git_log git-show-branch
88e21dc7 1297complete -o default -o nospace -F _git_tag git-tag
690d8824
JH
1298complete -o default -o nospace -F _git_log git-whatchanged
1299
1300# The following are necessary only for Cygwin, and only are needed
1301# when the user has tab-completed the executable name and consequently
1302# included the '.exe' suffix.
1303#
76c3eb51 1304if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
b3391775
SP
1305complete -o default -o nospace -F _git_add git-add.exe
1306complete -o default -o nospace -F _git_apply git-apply.exe
144d33de 1307complete -o default -o nospace -F _git git.exe
b3391775 1308complete -o default -o nospace -F _git_branch git-branch.exe
374a58c9 1309complete -o default -o nospace -F _git_bundle git-bundle.exe
d8a9fea5 1310complete -o default -o nospace -F _git_cherry git-cherry.exe
217926c0 1311complete -o default -o nospace -F _git_describe git-describe.exe
690d8824 1312complete -o default -o nospace -F _git_diff git-diff.exe
f53352fb 1313complete -o default -o nospace -F _git_format_patch git-format-patch.exe
690d8824
JH
1314complete -o default -o nospace -F _git_log git-log.exe
1315complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
b3391775
SP
1316complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1317complete -o default -o nospace -F _git_name_rev git-name-rev.exe
690d8824 1318complete -o default -o nospace -F _git_push git-push.exe
b3391775 1319complete -o default -o nospace -F _git_config git-config
1fd6bec9 1320complete -o default -o nospace -F _git_shortlog git-shortlog.exe
90131924 1321complete -o default -o nospace -F _git_show git-show.exe
144d33de 1322complete -o default -o nospace -F _git_log git-show-branch.exe
88e21dc7 1323complete -o default -o nospace -F _git_tag git-tag.exe
690d8824 1324complete -o default -o nospace -F _git_log git-whatchanged.exe
76c3eb51 1325fi