bash: get --pretty=m<tab> completion to work with bash v4
[git/git.git] / contrib / completion / git-completion.bash
CommitLineData
a42577d4 1#!bash
690d8824
JH
2#
3# bash completion support for core Git.
4#
c70680ce 5# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
690d8824 6# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
c70680ce 7# Distributed under the GNU General Public License, version 2.0.
690d8824
JH
8#
9# The contained completion routines provide support for completing:
10#
11# *) local and remote branch names
12# *) local and remote tag names
13# *) .git/remotes file names
14# *) git 'subcommands'
15# *) tree paths within 'ref:path/to/file' expressions
c70680ce 16# *) common --long-options
690d8824
JH
17#
18# To use these routines:
19#
20# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21# 2) Added the following line to your .bashrc:
22# source ~/.git-completion.sh
23#
eaa4e6ee 24# 3) Consider changing your PS1 to also show the current branch:
d3d717a4
SP
25# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
26#
27# The argument to __git_ps1 will be displayed only if you
28# are currently in a git repository. The %s token will be
29# the name of the current branch.
30#
a9ee90d7
TP
31# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
32# value, unstaged (*) and staged (+) changes will be shown next
33# to the branch name. You can configure this per-repository
34# with the bash.showDirtyState variable, which defaults to true
35# once GIT_PS1_SHOWDIRTYSTATE is enabled.
738a94a9 36#
2414b45c
DT
37# You can also see if currently something is stashed, by setting
38# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
39# then a '$' will be shown next to the branch name.
40#
397f7c63
DT
41# If you would like to see if there're untracked files, then you can
42# set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
43# untracked files, then a '%' will be shown next to the branch name.
44#
6d158cba
AS
45# If you would like to see the difference between HEAD and its
46# upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates
47# you are behind, ">" indicates you are ahead, and "<>"
48# indicates you have diverged. You can further control
49# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
50# list of values:
51# verbose show number of commits ahead/behind (+/-) upstream
52# legacy don't use the '--count' option available in recent
53# versions of git-rev-list
54# git always compare HEAD to @{upstream}
55# svn always compare HEAD to your SVN upstream
56# By default, __git_ps1 will compare HEAD to your SVN upstream
57# if it can find one, or @{upstream} otherwise. Once you have
58# set GIT_PS1_SHOWUPSTREAM, you can override it on a
59# per-repository basis by setting the bash.showUpstream config
60# variable.
61#
62#
c70680ce
SP
63# To submit patches:
64#
65# *) Read Documentation/SubmittingPatches
66# *) Send all patches to the current maintainer:
67#
68# "Shawn O. Pearce" <spearce@spearce.org>
69#
70# *) Always CC the Git mailing list:
71#
72# git@vger.kernel.org
73#
690d8824 74
db8a9ff0
SP
75case "$COMP_WORDBREAKS" in
76*:*) : great ;;
77*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
78esac
79
a42577d4
TP
80# __gitdir accepts 0 or 1 arguments (i.e., location)
81# returns location of .git repo
873537fa
SP
82__gitdir ()
83{
25a31f81 84 if [ -z "${1-}" ]; then
5c9cc64a 85 if [ -n "${__git_dir-}" ]; then
67ffa114
SP
86 echo "$__git_dir"
87 elif [ -d .git ]; then
88 echo .git
89 else
90 git rev-parse --git-dir 2>/dev/null
91 fi
92 elif [ -d "$1/.git" ]; then
93 echo "$1/.git"
94 else
95 echo "$1"
96 fi
873537fa
SP
97}
98
6d158cba
AS
99# stores the divergence from upstream in $p
100# used by GIT_PS1_SHOWUPSTREAM
101__git_ps1_show_upstream ()
102{
103 local key value
104 local svn_remote=() svn_url_pattern count n
105 local upstream=git legacy="" verbose=""
106
107 # get some config options from git-config
108 while read key value; do
109 case "$key" in
110 bash.showupstream)
111 GIT_PS1_SHOWUPSTREAM="$value"
112 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
113 p=""
114 return
115 fi
116 ;;
117 svn-remote.*.url)
118 svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
119 svn_url_pattern+="\\|$value"
120 upstream=svn+git # default upstream is SVN if available, else git
121 ;;
122 esac
123 done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
124
125 # parse configuration values
126 for option in ${GIT_PS1_SHOWUPSTREAM}; do
127 case "$option" in
128 git|svn) upstream="$option" ;;
129 verbose) verbose=1 ;;
130 legacy) legacy=1 ;;
131 esac
132 done
133
134 # Find our upstream
135 case "$upstream" in
136 git) upstream="@{upstream}" ;;
137 svn*)
138 # get the upstream from the "git-svn-id: ..." in a commit message
139 # (git-svn uses essentially the same procedure internally)
140 local svn_upstream=($(git log --first-parent -1 \
141 --grep="^git-svn-id: \(${svn_url_pattern:2}\)" 2>/dev/null))
142 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
143 svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
144 svn_upstream=${svn_upstream%@*}
145 for ((n=1; "$n" <= "${#svn_remote[@]}"; ++n)); do
146 svn_upstream=${svn_upstream#${svn_remote[$n]}}
147 done
148
149 if [[ -z "$svn_upstream" ]]; then
150 # default branch name for checkouts with no layout:
151 upstream=${GIT_SVN_ID:-git-svn}
152 else
153 upstream=${svn_upstream#/}
154 fi
155 elif [[ "svn+git" = "$upstream" ]]; then
156 upstream="@{upstream}"
157 fi
158 ;;
159 esac
160
161 # Find how many commits we are ahead/behind our upstream
162 if [[ -z "$legacy" ]]; then
163 count="$(git rev-list --count --left-right \
164 "$upstream"...HEAD 2>/dev/null)"
165 else
166 # produce equivalent output to --count for older versions of git
167 local commits
168 if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
169 then
170 local commit behind=0 ahead=0
171 for commit in $commits
172 do
173 case "$commit" in
174 "<"*) let ++behind
175 ;;
176 *) let ++ahead
177 ;;
178 esac
179 done
180 count="$behind $ahead"
181 else
182 count=""
183 fi
184 fi
185
186 # calculate the result
187 if [[ -z "$verbose" ]]; then
188 case "$count" in
189 "") # no upstream
190 p="" ;;
191 "0 0") # equal to upstream
192 p="=" ;;
193 "0 "*) # ahead of upstream
194 p=">" ;;
195 *" 0") # behind upstream
196 p="<" ;;
197 *) # diverged from upstream
198 p="<>" ;;
199 esac
200 else
201 case "$count" in
202 "") # no upstream
203 p="" ;;
204 "0 0") # equal to upstream
205 p=" u=" ;;
206 "0 "*) # ahead of upstream
207 p=" u+${count#0 }" ;;
208 *" 0") # behind upstream
209 p=" u-${count% 0}" ;;
210 *) # diverged from upstream
211 p=" u+${count#* }-${count% *}" ;;
212 esac
213 fi
214
215}
216
217
a42577d4
TP
218# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
219# returns text to add to bash PS1 prompt (includes branch name)
d3d717a4
SP
220__git_ps1 ()
221{
fa26a401 222 local g="$(__gitdir)"
e7520196 223 if [ -n "$g" ]; then
6c44b640
AS
224 local r=""
225 local b=""
d7107ca6 226 if [ -f "$g/rebase-merge/interactive" ]; then
e7520196 227 r="|REBASE-i"
28ed6e7b 228 b="$(cat "$g/rebase-merge/head-name")"
ad244d25 229 elif [ -d "$g/rebase-merge" ]; then
e7520196 230 r="|REBASE-m"
28ed6e7b 231 b="$(cat "$g/rebase-merge/head-name")"
e7520196 232 else
d7107ca6
JH
233 if [ -d "$g/rebase-apply" ]; then
234 if [ -f "$g/rebase-apply/rebasing" ]; then
235 r="|REBASE"
236 elif [ -f "$g/rebase-apply/applying" ]; then
237 r="|AM"
238 else
239 r="|AM/REBASE"
240 fi
241 elif [ -f "$g/MERGE_HEAD" ]; then
8763dbb1 242 r="|MERGING"
d7107ca6 243 elif [ -f "$g/BISECT_LOG" ]; then
e7520196
RR
244 r="|BISECTING"
245 fi
ff790b6a
JH
246
247 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
dd42c2f0
JH
248
249 b="$(
250 case "${GIT_PS1_DESCRIBE_STYLE-}" in
251 (contains)
252 git describe --contains HEAD ;;
253 (branch)
254 git describe --contains --all HEAD ;;
255 (describe)
256 git describe HEAD ;;
257 (* | default)
bd40d252 258 git describe --tags --exact-match HEAD ;;
dd42c2f0
JH
259 esac 2>/dev/null)" ||
260
ff790b6a
JH
261 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
262 b="unknown"
ff790b6a
JH
263 b="($b)"
264 }
e7520196
RR
265 fi
266
6c44b640
AS
267 local w=""
268 local i=""
269 local s=""
270 local u=""
271 local c=""
6d158cba 272 local p=""
738a94a9 273
e5dd864a 274 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
8dfb17e1 275 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
ddb6d010
MSO
276 c="BARE:"
277 else
278 b="GIT_DIR!"
279 fi
e5dd864a
TP
280 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
281 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
282 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
cf6e7ba1 283 git diff --no-ext-diff --quiet --exit-code || w="*"
e5dd864a 284 if git rev-parse --quiet --verify HEAD >/dev/null; then
cf6e7ba1 285 git diff-index --cached --quiet HEAD -- || i="+"
e5dd864a
TP
286 else
287 i="#"
288 fi
738a94a9
TR
289 fi
290 fi
2414b45c
DT
291 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
292 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
293 fi
397f7c63
DT
294
295 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
296 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
297 u="%"
298 fi
299 fi
6d158cba
AS
300
301 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
302 __git_ps1_show_upstream
303 fi
738a94a9
TR
304 fi
305
4cc47382 306 local f="$w$i$s$u"
6d158cba 307 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
d3d717a4
SP
308 fi
309}
310
a42577d4 311# __gitcomp_1 requires 2 arguments
ab02dfe5
SP
312__gitcomp_1 ()
313{
314 local c IFS=' '$'\t'$'\n'
315 for c in $1; do
316 case "$c$2" in
317 --*=*) printf %s$'\n' "$c$2" ;;
318 *.) printf %s$'\n' "$c$2" ;;
319 *) printf %s$'\n' "$c$2 " ;;
320 esac
321 done
322}
323
da48616f
PD
324if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
325_get_comp_words_by_ref ()
326{
327 while [ $# -gt 0 ]; do
328 case "$1" in
329 cur)
330 cur=${COMP_WORDS[COMP_CWORD]}
331 ;;
332 prev)
333 prev=${COMP_WORDS[COMP_CWORD-1]}
334 ;;
335 words)
336 words=("${COMP_WORDS[@]}")
337 ;;
338 cword)
339 cword=$COMP_CWORD
340 ;;
341 -n)
342 # assume COMP_WORDBREAKS is already set sanely
343 shift
344 ;;
345 esac
346 shift
347 done
348}
349fi
350
a42577d4
TP
351# __gitcomp accepts 1, 2, 3, or 4 arguments
352# generates completion reply with compgen
72e5e989
SP
353__gitcomp ()
354{
da48616f
PD
355 local cur
356 _get_comp_words_by_ref -n =: cur
b3391775 357 if [ $# -gt 2 ]; then
78d4d6a2
SP
358 cur="$3"
359 fi
5447aac7
SG
360 case "$cur" in
361 --*=)
362 COMPREPLY=()
5447aac7
SG
363 ;;
364 *)
ab02dfe5 365 local IFS=$'\n'
25a31f81
TP
366 COMPREPLY=($(compgen -P "${2-}" \
367 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
ab02dfe5 368 -- "$cur"))
5447aac7
SG
369 ;;
370 esac
72e5e989
SP
371}
372
a42577d4 373# __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
5de40f59
SP
374__git_heads ()
375{
25a31f81 376 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
5de40f59 377 if [ -d "$dir" ]; then
05e8b3d6
SG
378 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
379 refs/heads
5de40f59
SP
380 return
381 fi
25a31f81 382 for i in $(git ls-remote "${1-}" 2>/dev/null); do
5de40f59
SP
383 case "$is_hash,$i" in
384 y,*) is_hash=n ;;
385 n,*^{}) is_hash=y ;;
386 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
387 n,*) is_hash=y; echo "$i" ;;
388 esac
389 done
390}
391
a42577d4 392# __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
88e21dc7
SP
393__git_tags ()
394{
25a31f81 395 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
88e21dc7 396 if [ -d "$dir" ]; then
05e8b3d6
SG
397 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
398 refs/tags
88e21dc7
SP
399 return
400 fi
25a31f81 401 for i in $(git ls-remote "${1-}" 2>/dev/null); do
88e21dc7
SP
402 case "$is_hash,$i" in
403 y,*) is_hash=n ;;
404 n,*^{}) is_hash=y ;;
405 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
406 n,*) is_hash=y; echo "$i" ;;
407 esac
408 done
409}
410
a42577d4 411# __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
690d8824
JH
412__git_refs ()
413{
25a31f81 414 local i is_hash=y dir="$(__gitdir "${1-}")"
da48616f
PD
415 local cur format refs
416 _get_comp_words_by_ref -n =: cur
873537fa 417 if [ -d "$dir" ]; then
608efb87
SG
418 case "$cur" in
419 refs|refs/*)
420 format="refname"
421 refs="${cur%/*}"
422 ;;
423 *)
d23e7570
IWC
424 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
425 if [ -e "$dir/$i" ]; then echo $i; fi
426 done
608efb87
SG
427 format="refname:short"
428 refs="refs/tags refs/heads refs/remotes"
429 ;;
430 esac
431 git --git-dir="$dir" for-each-ref --format="%($format)" \
432 $refs
35e65ecc 433 return
690d8824 434 fi
799596a5 435 for i in $(git ls-remote "$dir" 2>/dev/null); do
690d8824
JH
436 case "$is_hash,$i" in
437 y,*) is_hash=n ;;
438 n,*^{}) is_hash=y ;;
439 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
440 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
35e65ecc 441 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
690d8824
JH
442 n,*) is_hash=y; echo "$i" ;;
443 esac
444 done
445}
446
a42577d4 447# __git_refs2 requires 1 argument (to pass to __git_refs)
690d8824
JH
448__git_refs2 ()
449{
67ffa114
SP
450 local i
451 for i in $(__git_refs "$1"); do
452 echo "$i:$i"
690d8824
JH
453 done
454}
455
a42577d4 456# __git_refs_remotes requires 1 argument (to pass to ls-remote)
5de40f59
SP
457__git_refs_remotes ()
458{
459 local cmd i is_hash=y
799596a5 460 for i in $(git ls-remote "$1" 2>/dev/null); do
5de40f59
SP
461 case "$is_hash,$i" in
462 n,refs/heads/*)
463 is_hash=y
464 echo "$i:refs/remotes/$1/${i#refs/heads/}"
465 ;;
466 y,*) is_hash=n ;;
467 n,*^{}) is_hash=y ;;
468 n,refs/tags/*) is_hash=y;;
469 n,*) is_hash=y; ;;
470 esac
471 done
472}
473
690d8824
JH
474__git_remotes ()
475{
873537fa 476 local i ngoff IFS=$'\n' d="$(__gitdir)"
56fc25f2 477 shopt -q nullglob || ngoff=1
690d8824 478 shopt -s nullglob
873537fa
SP
479 for i in "$d/remotes"/*; do
480 echo ${i#$d/remotes/}
690d8824 481 done
56fc25f2 482 [ "$ngoff" ] && shopt -u nullglob
518ef8f0
TZ
483 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
484 i="${i#remote.}"
485 echo "${i/.url*/}"
56fc25f2 486 done
690d8824
JH
487}
488
eaa4e6ee 489__git_list_merge_strategies ()
4ad91321 490{
25b3d4d6
JH
491 git merge -s help 2>&1 |
492 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
493 s/\.$//
494 s/.*://
495 s/^[ ]*//
496 s/[ ]*$//
4ad91321 497 p
25b3d4d6 498 }'
4ad91321 499}
eaa4e6ee
JN
500
501__git_merge_strategies=
502# 'git merge -s help' (and thus detection of the merge strategy
503# list) fails, unfortunately, if run outside of any git working
504# tree. __git_merge_strategies is set to the empty string in
505# that case, and the detection will be repeated the next time it
506# is needed.
507__git_compute_merge_strategies ()
508{
509 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
510}
4ad91321 511
690d8824
JH
512__git_complete_file ()
513{
da48616f
PD
514 local pfx ls ref cur
515 _get_comp_words_by_ref -n =: cur
690d8824
JH
516 case "$cur" in
517 ?*:*)
a79c6551
SP
518 ref="${cur%%:*}"
519 cur="${cur#*:}"
690d8824
JH
520 case "$cur" in
521 ?*/*)
a79c6551
SP
522 pfx="${cur%/*}"
523 cur="${cur##*/}"
690d8824
JH
524 ls="$ref:$pfx"
525 pfx="$pfx/"
526 ;;
527 *)
528 ls="$ref"
529 ;;
530 esac
db8a9ff0
SP
531
532 case "$COMP_WORDBREAKS" in
533 *:*) : great ;;
534 *) pfx="$ref:$pfx" ;;
535 esac
536
778306e4 537 local IFS=$'\n'
690d8824 538 COMPREPLY=($(compgen -P "$pfx" \
873537fa 539 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
778306e4
SP
540 | sed '/^100... blob /{
541 s,^.* ,,
542 s,$, ,
543 }
544 /^120000 blob /{
545 s,^.* ,,
546 s,$, ,
547 }
690d8824
JH
548 /^040000 tree /{
549 s,^.* ,,
550 s,$,/,
551 }
552 s/^.* //')" \
553 -- "$cur"))
554 ;;
555 *)
b3391775 556 __gitcomp "$(__git_refs)"
690d8824
JH
557 ;;
558 esac
559}
560
f53352fb
SP
561__git_complete_revlist ()
562{
da48616f
PD
563 local pfx cur
564 _get_comp_words_by_ref -n =: cur
f53352fb
SP
565 case "$cur" in
566 *...*)
567 pfx="${cur%...*}..."
568 cur="${cur#*...}"
b3391775 569 __gitcomp "$(__git_refs)" "$pfx" "$cur"
f53352fb
SP
570 ;;
571 *..*)
572 pfx="${cur%..*}.."
573 cur="${cur#*..}"
b3391775
SP
574 __gitcomp "$(__git_refs)" "$pfx" "$cur"
575 ;;
f53352fb 576 *)
b3391775 577 __gitcomp "$(__git_refs)"
f53352fb
SP
578 ;;
579 esac
580}
581
52d5c3b5
JS
582__git_complete_remote_or_refspec ()
583{
da48616f
PD
584 local cur words cword
585 _get_comp_words_by_ref -n =: cur words cword
586 local cmd="${words[1]}"
0a4e1472 587 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
da48616f
PD
588 while [ $c -lt $cword ]; do
589 i="${words[c]}"
52d5c3b5 590 case "$i" in
e25e2b42
BG
591 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
592 --all)
593 case "$cmd" in
594 push) no_complete_refspec=1 ;;
595 fetch)
596 COMPREPLY=()
597 return
598 ;;
599 *) ;;
600 esac
601 ;;
52d5c3b5
JS
602 -*) ;;
603 *) remote="$i"; break ;;
604 esac
605 c=$((++c))
606 done
607 if [ -z "$remote" ]; then
608 __gitcomp "$(__git_remotes)"
609 return
610 fi
0a4e1472
JS
611 if [ $no_complete_refspec = 1 ]; then
612 COMPREPLY=()
613 return
614 fi
52d5c3b5
JS
615 [ "$remote" = "." ] && remote=
616 case "$cur" in
617 *:*)
618 case "$COMP_WORDBREAKS" in
619 *:*) : great ;;
620 *) pfx="${cur%%:*}:" ;;
621 esac
622 cur="${cur#*:}"
623 lhs=0
624 ;;
625 +*)
626 pfx="+"
627 cur="${cur#+}"
628 ;;
629 esac
630 case "$cmd" in
631 fetch)
632 if [ $lhs = 1 ]; then
633 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
634 else
635 __gitcomp "$(__git_refs)" "$pfx" "$cur"
636 fi
637 ;;
638 pull)
639 if [ $lhs = 1 ]; then
640 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
641 else
642 __gitcomp "$(__git_refs)" "$pfx" "$cur"
643 fi
644 ;;
645 push)
646 if [ $lhs = 1 ]; then
647 __gitcomp "$(__git_refs)" "$pfx" "$cur"
648 else
649 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
650 fi
651 ;;
652 esac
653}
654
3c7b480a
JS
655__git_complete_strategy ()
656{
da48616f
PD
657 local cur prev
658 _get_comp_words_by_ref -n =: cur prev
eaa4e6ee 659 __git_compute_merge_strategies
da48616f 660 case "$prev" in
3c7b480a 661 -s|--strategy)
eaa4e6ee 662 __gitcomp "$__git_merge_strategies"
3c7b480a
JS
663 return 0
664 esac
3c7b480a
JS
665 case "$cur" in
666 --strategy=*)
eaa4e6ee 667 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
3c7b480a
JS
668 return 0
669 ;;
670 esac
671 return 1
672}
673
eaa4e6ee 674__git_list_all_commands ()
f2bb9f88
SP
675{
676 local i IFS=" "$'\n'
427e586b 677 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
1eb7e2f8
LM
678 do
679 case $i in
680 *--*) : helper pattern;;
681 *) echo $i;;
682 esac
683 done
684}
1eb7e2f8 685
eaa4e6ee
JN
686__git_all_commands=
687__git_compute_all_commands ()
688{
689 : ${__git_all_commands:=$(__git_list_all_commands)}
690}
691
692__git_list_porcelain_commands ()
1eb7e2f8 693{
1eb7e2f8 694 local i IFS=" "$'\n'
eaa4e6ee
JN
695 __git_compute_all_commands
696 for i in "help" $__git_all_commands
f2bb9f88
SP
697 do
698 case $i in
718a087a 699 *--*) : helper pattern;;
a925c6f1
SP
700 applymbox) : ask gittus;;
701 applypatch) : ask gittus;;
702 archimport) : import;;
2e3a430a 703 cat-file) : plumbing;;
56d99c67 704 check-attr) : plumbing;;
f2bb9f88 705 check-ref-format) : plumbing;;
ff2549dc 706 checkout-index) : plumbing;;
f2bb9f88 707 commit-tree) : plumbing;;
ff2549dc 708 count-objects) : infrequent;;
a925c6f1
SP
709 cvsexportcommit) : export;;
710 cvsimport) : import;;
f2bb9f88
SP
711 cvsserver) : daemon;;
712 daemon) : daemon;;
5cfb4fe5
SP
713 diff-files) : plumbing;;
714 diff-index) : plumbing;;
715 diff-tree) : plumbing;;
c6ec3b13 716 fast-import) : import;;
ff2549dc 717 fast-export) : export;;
a925c6f1 718 fsck-objects) : plumbing;;
f2bb9f88 719 fetch-pack) : plumbing;;
a925c6f1 720 fmt-merge-msg) : plumbing;;
56d99c67 721 for-each-ref) : plumbing;;
f2bb9f88
SP
722 hash-object) : plumbing;;
723 http-*) : transport;;
724 index-pack) : plumbing;;
a925c6f1 725 init-db) : deprecated;;
f2bb9f88 726 local-fetch) : plumbing;;
ff2549dc
PB
727 lost-found) : infrequent;;
728 ls-files) : plumbing;;
729 ls-remote) : plumbing;;
730 ls-tree) : plumbing;;
f2bb9f88
SP
731 mailinfo) : plumbing;;
732 mailsplit) : plumbing;;
733 merge-*) : plumbing;;
734 mktree) : plumbing;;
735 mktag) : plumbing;;
736 pack-objects) : plumbing;;
737 pack-redundant) : plumbing;;
738 pack-refs) : plumbing;;
739 parse-remote) : plumbing;;
740 patch-id) : plumbing;;
741 peek-remote) : plumbing;;
a925c6f1
SP
742 prune) : plumbing;;
743 prune-packed) : plumbing;;
744 quiltimport) : import;;
f2bb9f88
SP
745 read-tree) : plumbing;;
746 receive-pack) : plumbing;;
2e3a430a 747 reflog) : plumbing;;
63d04a78 748 remote-*) : transport;;
5c66d0d4 749 repo-config) : deprecated;;
f2bb9f88
SP
750 rerere) : plumbing;;
751 rev-list) : plumbing;;
752 rev-parse) : plumbing;;
753 runstatus) : plumbing;;
754 sh-setup) : internal;;
755 shell) : daemon;;
ff2549dc 756 show-ref) : plumbing;;
f2bb9f88
SP
757 send-pack) : plumbing;;
758 show-index) : plumbing;;
759 ssh-*) : transport;;
760 stripspace) : plumbing;;
761 symbolic-ref) : plumbing;;
a925c6f1 762 tar-tree) : deprecated;;
f2bb9f88
SP
763 unpack-file) : plumbing;;
764 unpack-objects) : plumbing;;
a925c6f1 765 update-index) : plumbing;;
f2bb9f88
SP
766 update-ref) : plumbing;;
767 update-server-info) : daemon;;
768 upload-archive) : plumbing;;
769 upload-pack) : plumbing;;
770 write-tree) : plumbing;;
ff2549dc
PB
771 var) : infrequent;;
772 verify-pack) : infrequent;;
a925c6f1 773 verify-tag) : plumbing;;
f2bb9f88
SP
774 *) echo $i;;
775 esac
776 done
777}
eaa4e6ee
JN
778
779__git_porcelain_commands=
780__git_compute_porcelain_commands ()
781{
782 __git_compute_all_commands
783 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
784}
f2bb9f88 785
367dce2a
DS
786__git_aliases ()
787{
56fc25f2 788 local i IFS=$'\n'
518ef8f0 789 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
e0d78059
SB
790 case "$i" in
791 alias.*)
792 i="${i#alias.}"
793 echo "${i/ */}"
794 ;;
795 esac
56fc25f2 796 done
367dce2a
DS
797}
798
a42577d4 799# __git_aliased_command requires 1 argument
367dce2a
DS
800__git_aliased_command ()
801{
873537fa 802 local word cmdline=$(git --git-dir="$(__gitdir)" \
e0d10e1c 803 config --get "alias.$1")
367dce2a 804 for word in $cmdline; do
c63437cb 805 case "$word" in
66729509
SG
806 \!gitk|gitk)
807 echo "gitk"
367dce2a 808 return
66729509 809 ;;
c63437cb
SG
810 \!*) : shell command alias ;;
811 -*) : option ;;
812 *=*) : setting env ;;
813 git) : git itself ;;
814 *)
815 echo "$word"
367dce2a 816 return
c63437cb 817 esac
367dce2a
DS
818 done
819}
820
918c03c2
SG
821# __git_find_on_cmdline requires 1 argument
822__git_find_on_cmdline ()
3ff1320d 823{
da48616f
PD
824 local word subcommand c=1 words cword
825 _get_comp_words_by_ref -n =: words cword
826 while [ $c -lt $cword ]; do
827 word="${words[c]}"
3ff1320d
SG
828 for subcommand in $1; do
829 if [ "$subcommand" = "$word" ]; then
830 echo "$subcommand"
831 return
832 fi
833 done
834 c=$((++c))
835 done
836}
837
d773c631
SG
838__git_has_doubledash ()
839{
da48616f
PD
840 local c=1 words cword
841 _get_comp_words_by_ref -n =: words cword
842 while [ $c -lt $cword ]; do
843 if [ "--" = "${words[c]}" ]; then
d773c631
SG
844 return 0
845 fi
846 c=$((++c))
847 done
848 return 1
849}
850
7950659d 851__git_whitespacelist="nowarn warn error error-all fix"
88329195
SP
852
853_git_am ()
854{
da48616f
PD
855 local cur dir="$(__gitdir)"
856 _get_comp_words_by_ref -n =: cur
51ef1daa 857 if [ -d "$dir"/rebase-apply ]; then
85f6b439 858 __gitcomp "--skip --continue --resolved --abort"
88329195
SP
859 return
860 fi
861 case "$cur" in
862 --whitespace=*)
b3391775 863 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
864 return
865 ;;
866 --*)
b3391775 867 __gitcomp "
43acdf24 868 --3way --committer-date-is-author-date --ignore-date
86c91f91 869 --ignore-whitespace --ignore-space-change
43acdf24 870 --interactive --keep --no-utf8 --signoff --utf8
af4e9e8c 871 --whitespace= --scissors
b3391775 872 "
88329195
SP
873 return
874 esac
875 COMPREPLY=()
876}
877
878_git_apply ()
879{
da48616f
PD
880 local cur
881 _get_comp_words_by_ref -n =: cur
88329195
SP
882 case "$cur" in
883 --whitespace=*)
b3391775 884 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
88329195
SP
885 return
886 ;;
887 --*)
b3391775 888 __gitcomp "
88329195
SP
889 --stat --numstat --summary --check --index
890 --cached --index-info --reverse --reject --unidiff-zero
891 --apply --no-add --exclude=
86c91f91 892 --ignore-whitespace --ignore-space-change
88329195 893 --whitespace= --inaccurate-eof --verbose
b3391775 894 "
88329195
SP
895 return
896 esac
897 COMPREPLY=()
898}
899
8435b548
SP
900_git_add ()
901{
d773c631
SG
902 __git_has_doubledash && return
903
da48616f
PD
904 local cur
905 _get_comp_words_by_ref -n =: cur
8435b548
SP
906 case "$cur" in
907 --*)
1d284cba
SG
908 __gitcomp "
909 --interactive --refresh --patch --update --dry-run
c9a114b5 910 --ignore-errors --intent-to-add
1d284cba 911 "
8435b548
SP
912 return
913 esac
914 COMPREPLY=()
915}
916
b3191ce2
LM
917_git_archive ()
918{
da48616f
PD
919 local cur
920 _get_comp_words_by_ref -n =: cur
b3191ce2
LM
921 case "$cur" in
922 --format=*)
923 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
924 return
925 ;;
926 --remote=*)
927 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
928 return
929 ;;
930 --*)
931 __gitcomp "
932 --format= --list --verbose
933 --prefix= --remote= --exec=
934 "
935 return
936 ;;
937 esac
938 __git_complete_file
939}
940
b2e69f62
SP
941_git_bisect ()
942{
d773c631
SG
943 __git_has_doubledash && return
944
bf11d461 945 local subcommands="start bad good skip reset visualize replay log run"
918c03c2 946 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3ff1320d
SG
947 if [ -z "$subcommand" ]; then
948 __gitcomp "$subcommands"
b2e69f62
SP
949 return
950 fi
951
3ff1320d 952 case "$subcommand" in
bf11d461 953 bad|good|reset|skip)
b2e69f62
SP
954 __gitcomp "$(__git_refs)"
955 ;;
956 *)
957 COMPREPLY=()
958 ;;
959 esac
960}
961
690d8824
JH
962_git_branch ()
963{
da48616f 964 local i c=1 only_local_ref="n" has_r="n" cur words cword
b9217642 965
da48616f
PD
966 _get_comp_words_by_ref -n =: cur words cword
967 while [ $c -lt $cword ]; do
968 i="${words[c]}"
b9217642
SG
969 case "$i" in
970 -d|-m) only_local_ref="y" ;;
971 -r) has_r="y" ;;
972 esac
973 c=$((++c))
974 done
975
da48616f 976 case "$cur" in
3b376b0c
SG
977 --*)
978 __gitcomp "
979 --color --no-color --verbose --abbrev= --no-abbrev
50e61025 980 --track --no-track --contains --merged --no-merged
ff9c0825 981 --set-upstream
3b376b0c
SG
982 "
983 ;;
b9217642
SG
984 *)
985 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
986 __gitcomp "$(__git_heads)"
987 else
988 __gitcomp "$(__git_refs)"
989 fi
990 ;;
3b376b0c 991 esac
690d8824
JH
992}
993
374a58c9
ML
994_git_bundle ()
995{
da48616f
PD
996 local words cword
997 _get_comp_words_by_ref -n =: words cword
998 local cmd="${words[2]}"
999 case "$cword" in
8d8163f3 1000 2)
374a58c9
ML
1001 __gitcomp "create list-heads verify unbundle"
1002 ;;
8d8163f3 1003 3)
374a58c9
ML
1004 # looking for a file
1005 ;;
1006 *)
1007 case "$cmd" in
1008 create)
1009 __git_complete_revlist
1010 ;;
1011 esac
1012 ;;
1013 esac
1014}
1015
690d8824
JH
1016_git_checkout ()
1017{
c84bb14c
SG
1018 __git_has_doubledash && return
1019
da48616f
PD
1020 local cur
1021 _get_comp_words_by_ref -n =: cur
e648f8b6
SG
1022 case "$cur" in
1023 --conflict=*)
1024 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1025 ;;
1026 --*)
1027 __gitcomp "
1028 --quiet --ours --theirs --track --no-track --merge
86e8e7a5 1029 --conflict= --orphan --patch
e648f8b6
SG
1030 "
1031 ;;
1032 *)
1033 __gitcomp "$(__git_refs)"
1034 ;;
1035 esac
690d8824
JH
1036}
1037
d8a9fea5
SP
1038_git_cherry ()
1039{
1040 __gitcomp "$(__git_refs)"
1041}
1042
1273231e
SP
1043_git_cherry_pick ()
1044{
da48616f
PD
1045 local cur
1046 _get_comp_words_by_ref -n =: cur
1273231e
SP
1047 case "$cur" in
1048 --*)
b3391775 1049 __gitcomp "--edit --no-commit"
1273231e
SP
1050 ;;
1051 *)
b3391775 1052 __gitcomp "$(__git_refs)"
1273231e
SP
1053 ;;
1054 esac
1055}
1056
4181c7e8
LM
1057_git_clean ()
1058{
1059 __git_has_doubledash && return
1060
da48616f
PD
1061 local cur
1062 _get_comp_words_by_ref -n =: cur
4181c7e8
LM
1063 case "$cur" in
1064 --*)
1065 __gitcomp "--dry-run --quiet"
1066 return
1067 ;;
1068 esac
1069 COMPREPLY=()
1070}
1071
3eb11012
LM
1072_git_clone ()
1073{
da48616f
PD
1074 local cur
1075 _get_comp_words_by_ref -n =: cur
3eb11012
LM
1076 case "$cur" in
1077 --*)
1078 __gitcomp "
1079 --local
1080 --no-hardlinks
1081 --shared
1082 --reference
1083 --quiet
1084 --no-checkout
1085 --bare
1086 --mirror
1087 --origin
1088 --upload-pack
1089 --template=
1090 --depth
1091 "
1092 return
1093 ;;
1094 esac
1095 COMPREPLY=()
1096}
1097
4548e855
SP
1098_git_commit ()
1099{
d773c631
SG
1100 __git_has_doubledash && return
1101
da48616f
PD
1102 local cur
1103 _get_comp_words_by_ref -n =: cur
4548e855 1104 case "$cur" in
9a424b27
SG
1105 --cleanup=*)
1106 __gitcomp "default strip verbatim whitespace
1107 " "" "${cur##--cleanup=}"
1108 return
1109 ;;
1110 --reuse-message=*)
1111 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1112 return
1113 ;;
1114 --reedit-message=*)
1115 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1116 return
1117 ;;
1118 --untracked-files=*)
1119 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1120 return
1121 ;;
4548e855 1122 --*)
b3391775 1123 __gitcomp "
4548e855 1124 --all --author= --signoff --verify --no-verify
aa5735be 1125 --edit --amend --include --only --interactive
9a424b27
SG
1126 --dry-run --reuse-message= --reedit-message=
1127 --reset-author --file= --message= --template=
1128 --cleanup= --untracked-files --untracked-files=
1129 --verbose --quiet
b3391775 1130 "
4548e855
SP
1131 return
1132 esac
1133 COMPREPLY=()
1134}
1135
217926c0
SP
1136_git_describe ()
1137{
da48616f
PD
1138 local cur
1139 _get_comp_words_by_ref -n =: cur
cbb504c9
TR
1140 case "$cur" in
1141 --*)
1142 __gitcomp "
1143 --all --tags --contains --abbrev= --candidates=
1144 --exact-match --debug --long --match --always
1145 "
1146 return
1147 esac
217926c0
SP
1148 __gitcomp "$(__git_refs)"
1149}
1150
20bf7292 1151__git_diff_common_options="--stat --numstat --shortstat --summary
b3a4f858
JS
1152 --patch-with-stat --name-only --name-status --color
1153 --no-color --color-words --no-renames --check
f135aacb 1154 --full-index --binary --abbrev --diff-filter=
47d5a8fa 1155 --find-copies-harder
b3a4f858
JS
1156 --text --ignore-space-at-eol --ignore-space-change
1157 --ignore-all-space --exit-code --quiet --ext-diff
aba201c6
PO
1158 --no-ext-diff
1159 --no-prefix --src-prefix= --dst-prefix=
6d0e674a 1160 --inter-hunk-context=
cc545709 1161 --patience
20bf7292 1162 --raw
8fd2cfa7
SB
1163 --dirstat --dirstat= --dirstat-by-file
1164 --dirstat-by-file= --cumulative
20bf7292
TR
1165"
1166
1167_git_diff ()
1168{
1169 __git_has_doubledash && return
1170
da48616f
PD
1171 local cur
1172 _get_comp_words_by_ref -n =: cur
20bf7292
TR
1173 case "$cur" in
1174 --*)
ebd15bf0 1175 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
20bf7292
TR
1176 --base --ours --theirs
1177 $__git_diff_common_options
aba201c6 1178 "
b3a4f858
JS
1179 return
1180 ;;
1181 esac
690d8824
JH
1182 __git_complete_file
1183}
1184
e2dc2de9 1185__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
c8998b48 1186 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
e2dc2de9
DA
1187"
1188
1189_git_difftool ()
1190{
f7ad96cf
MH
1191 __git_has_doubledash && return
1192
da48616f
PD
1193 local cur
1194 _get_comp_words_by_ref -n =: cur
e2dc2de9
DA
1195 case "$cur" in
1196 --tool=*)
1197 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1198 return
1199 ;;
1200 --*)
f7ad96cf
MH
1201 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1202 --base --ours --theirs
1203 --no-renames --diff-filter= --find-copies-harder
1204 --relative --ignore-submodules
1205 --tool="
e2dc2de9
DA
1206 return
1207 ;;
1208 esac
f7ad96cf 1209 __git_complete_file
e2dc2de9
DA
1210}
1211
0a4e1472
JS
1212__git_fetch_options="
1213 --quiet --verbose --append --upload-pack --force --keep --depth=
e25e2b42 1214 --tags --no-tags --all --prune --dry-run
0a4e1472
JS
1215"
1216
690d8824
JH
1217_git_fetch ()
1218{
da48616f
PD
1219 local cur
1220 _get_comp_words_by_ref -n =: cur
0a4e1472
JS
1221 case "$cur" in
1222 --*)
1223 __gitcomp "$__git_fetch_options"
1224 return
1225 ;;
1226 esac
52d5c3b5 1227 __git_complete_remote_or_refspec
690d8824
JH
1228}
1229
f53352fb
SP
1230_git_format_patch ()
1231{
da48616f
PD
1232 local cur
1233 _get_comp_words_by_ref -n =: cur
f53352fb 1234 case "$cur" in
e1d37937
SB
1235 --thread=*)
1236 __gitcomp "
1237 deep shallow
1238 " "" "${cur##--thread=}"
1239 return
1240 ;;
f53352fb 1241 --*)
b3391775 1242 __gitcomp "
e1d37937 1243 --stdout --attach --no-attach --thread --thread=
f53352fb
SP
1244 --output-directory
1245 --numbered --start-number
47e98eec 1246 --numbered-files
f53352fb 1247 --keep-subject
d8e1e5df 1248 --signoff --signature --no-signature
3f7df3a7 1249 --in-reply-to= --cc=
f53352fb 1250 --full-index --binary
ec804891 1251 --not --all
be5f5bf0 1252 --cover-letter
aba201c6 1253 --no-prefix --src-prefix= --dst-prefix=
81085134
SG
1254 --inline --suffix= --ignore-if-in-upstream
1255 --subject-prefix=
b3391775 1256 "
f53352fb
SP
1257 return
1258 ;;
1259 esac
1260 __git_complete_revlist
1261}
1262
4bca8636
AJ
1263_git_fsck ()
1264{
da48616f
PD
1265 local cur
1266 _get_comp_words_by_ref -n =: cur
4bca8636
AJ
1267 case "$cur" in
1268 --*)
1269 __gitcomp "
1270 --tags --root --unreachable --cache --no-reflogs --full
1271 --strict --verbose --lost-found
1272 "
1273 return
1274 ;;
1275 esac
1276 COMPREPLY=()
1277}
1278
b26c8748
SP
1279_git_gc ()
1280{
da48616f
PD
1281 local cur
1282 _get_comp_words_by_ref -n =: cur
b26c8748
SP
1283 case "$cur" in
1284 --*)
47e98eec 1285 __gitcomp "--prune --aggressive"
b26c8748
SP
1286 return
1287 ;;
1288 esac
1289 COMPREPLY=()
1290}
1291
66729509
SG
1292_git_gitk ()
1293{
1294 _gitk
1295}
1296
c72e0db1
LM
1297_git_grep ()
1298{
1299 __git_has_doubledash && return
1300
da48616f
PD
1301 local cur
1302 _get_comp_words_by_ref -n =: cur
c72e0db1
LM
1303 case "$cur" in
1304 --*)
1305 __gitcomp "
1306 --cached
1307 --text --ignore-case --word-regexp --invert-match
1308 --full-name
1309 --extended-regexp --basic-regexp --fixed-strings
1310 --files-with-matches --name-only
1311 --files-without-match
a91f453f 1312 --max-depth
c72e0db1
LM
1313 --count
1314 --and --or --not --all-match
1315 "
1316 return
1317 ;;
1318 esac
17225c49
TR
1319
1320 __gitcomp "$(__git_refs)"
c72e0db1
LM
1321}
1322
1eb7e2f8
LM
1323_git_help ()
1324{
da48616f
PD
1325 local cur
1326 _get_comp_words_by_ref -n =: cur
1eb7e2f8
LM
1327 case "$cur" in
1328 --*)
1329 __gitcomp "--all --info --man --web"
1330 return
1331 ;;
1332 esac
eaa4e6ee
JN
1333 __git_compute_all_commands
1334 __gitcomp "$__git_all_commands
2946cccf
MG
1335 attributes cli core-tutorial cvs-migration
1336 diffcore gitk glossary hooks ignore modules
1337 repository-layout tutorial tutorial-2
99f0b599 1338 workflows
2946cccf 1339 "
1eb7e2f8
LM
1340}
1341
5dad868b
LM
1342_git_init ()
1343{
da48616f
PD
1344 local cur
1345 _get_comp_words_by_ref -n =: cur
5dad868b
LM
1346 case "$cur" in
1347 --shared=*)
1348 __gitcomp "
1349 false true umask group all world everybody
1350 " "" "${cur##--shared=}"
1351 return
1352 ;;
1353 --*)
1354 __gitcomp "--quiet --bare --template= --shared --shared="
1355 return
1356 ;;
1357 esac
1358 COMPREPLY=()
1359}
1360
b1bc1494
LM
1361_git_ls_files ()
1362{
1363 __git_has_doubledash && return
1364
da48616f
PD
1365 local cur
1366 _get_comp_words_by_ref -n =: cur
b1bc1494
LM
1367 case "$cur" in
1368 --*)
1369 __gitcomp "--cached --deleted --modified --others --ignored
1370 --stage --directory --no-empty-directory --unmerged
1371 --killed --exclude= --exclude-from=
1372 --exclude-per-directory= --exclude-standard
1373 --error-unmatch --with-tree= --full-name
1374 --abbrev --ignored --exclude-per-directory
1375 "
1376 return
1377 ;;
1378 esac
1379 COMPREPLY=()
1380}
1381
690d8824
JH
1382_git_ls_remote ()
1383{
b3391775 1384 __gitcomp "$(__git_remotes)"
690d8824
JH
1385}
1386
1387_git_ls_tree ()
1388{
1389 __git_complete_file
1390}
1391
a393777e
TR
1392# Options that go well for log, shortlog and gitk
1393__git_log_common_options="
1394 --not --all
1395 --branches --tags --remotes
4fe1a619 1396 --first-parent --merges --no-merges
a393777e
TR
1397 --max-count=
1398 --max-age= --since= --after=
1399 --min-age= --until= --before=
1400"
1401# Options that go well for log and gitk (not shortlog)
1402__git_log_gitk_options="
1403 --dense --sparse --full-history
1404 --simplify-merges --simplify-by-decoration
1405 --left-right
1406"
1407# Options that go well for log and shortlog (not gitk)
1408__git_log_shortlog_options="
1409 --author= --committer= --grep=
1410 --all-match
1411"
1412
3d279863 1413__git_log_pretty_formats="oneline short medium full fuller email raw format:"
672c68cb 1414__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
3d279863 1415
690d8824
JH
1416_git_log ()
1417{
d773c631
SG
1418 __git_has_doubledash && return
1419
bf3c20f6
TR
1420 local g="$(git rev-parse --git-dir 2>/dev/null)"
1421 local merge=""
ba7906f2 1422 if [ -f "$g/MERGE_HEAD" ]; then
bf3c20f6
TR
1423 merge="--merge"
1424 fi
da48616f
PD
1425 local cur
1426 _get_comp_words_by_ref -n =: cur
6e31b866
SP
1427 case "$cur" in
1428 --pretty=*)
3d279863 1429 __gitcomp "$__git_log_pretty_formats
b3391775 1430 " "" "${cur##--pretty=}"
6e31b866
SP
1431 return
1432 ;;
72de29c2
TL
1433 --format=*)
1434 __gitcomp "$__git_log_pretty_formats
1435 " "" "${cur##--format=}"
1436 return
1437 ;;
47e98eec 1438 --date=*)
672c68cb 1439 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
47e98eec
SP
1440 return
1441 ;;
af4e9e8c
SB
1442 --decorate=*)
1443 __gitcomp "long short" "" "${cur##--decorate=}"
1444 return
1445 ;;
6e31b866 1446 --*)
b3391775 1447 __gitcomp "
a393777e
TR
1448 $__git_log_common_options
1449 $__git_log_shortlog_options
1450 $__git_log_gitk_options
8f87fae6 1451 --root --topo-order --date-order --reverse
5d0e6343 1452 --follow --full-diff
6e31b866 1453 --abbrev-commit --abbrev=
47e98eec 1454 --relative-date --date=
72de29c2 1455 --pretty= --format= --oneline
a393777e 1456 --cherry-pick
20827d99 1457 --graph
af4e9e8c 1458 --decorate --decorate=
20bf7292 1459 --walk-reflogs
a393777e 1460 --parents --children
bf3c20f6 1461 $merge
20bf7292 1462 $__git_diff_common_options
47d5a8fa 1463 --pickaxe-all --pickaxe-regex
b3391775 1464 "
6e31b866
SP
1465 return
1466 ;;
1467 esac
f53352fb 1468 __git_complete_revlist
690d8824
JH
1469}
1470
0a4e1472
JS
1471__git_merge_options="
1472 --no-commit --no-stat --log --no-log --squash --strategy
9858b87f 1473 --commit --stat --no-squash --ff --no-ff --ff-only
0a4e1472
JS
1474"
1475
4ad91321
SP
1476_git_merge ()
1477{
3c7b480a
JS
1478 __git_complete_strategy && return
1479
da48616f
PD
1480 local cur
1481 _get_comp_words_by_ref -n =: cur
4ad91321
SP
1482 case "$cur" in
1483 --*)
0a4e1472 1484 __gitcomp "$__git_merge_options"
4ad91321
SP
1485 return
1486 esac
b3391775 1487 __gitcomp "$(__git_refs)"
4ad91321
SP
1488}
1489
b4c72162
LM
1490_git_mergetool ()
1491{
da48616f
PD
1492 local cur
1493 _get_comp_words_by_ref -n =: cur
b4c72162
LM
1494 case "$cur" in
1495 --tool=*)
e2dc2de9 1496 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
b4c72162
LM
1497 return
1498 ;;
1499 --*)
1500 __gitcomp "--tool="
1501 return
1502 ;;
1503 esac
1504 COMPREPLY=()
1505}
1506
690d8824
JH
1507_git_merge_base ()
1508{
b3391775 1509 __gitcomp "$(__git_refs)"
690d8824
JH
1510}
1511
1127c51c
LM
1512_git_mv ()
1513{
da48616f
PD
1514 local cur
1515 _get_comp_words_by_ref -n =: cur
1127c51c
LM
1516 case "$cur" in
1517 --*)
1518 __gitcomp "--dry-run"
1519 return
1520 ;;
1521 esac
1522 COMPREPLY=()
1523}
1524
d33909bf
SP
1525_git_name_rev ()
1526{
b3391775 1527 __gitcomp "--tags --all --stdin"
d33909bf
SP
1528}
1529
00f09d0e
SG
1530_git_notes ()
1531{
1532 local subcommands="edit show"
da48616f
PD
1533 local words cword
1534 _get_comp_words_by_ref -n =: words cword
00f09d0e
SG
1535 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1536 __gitcomp "$subcommands"
1537 return
1538 fi
1539
da48616f 1540 case "${words[cword-1]}" in
00f09d0e
SG
1541 -m|-F)
1542 COMPREPLY=()
1543 ;;
1544 *)
1545 __gitcomp "$(__git_refs)"
1546 ;;
1547 esac
1548}
1549
690d8824
JH
1550_git_pull ()
1551{
0a4e1472
JS
1552 __git_complete_strategy && return
1553
da48616f
PD
1554 local cur
1555 _get_comp_words_by_ref -n =: cur
0a4e1472
JS
1556 case "$cur" in
1557 --*)
1558 __gitcomp "
1559 --rebase --no-rebase
1560 $__git_merge_options
1561 $__git_fetch_options
1562 "
1563 return
1564 ;;
1565 esac
52d5c3b5 1566 __git_complete_remote_or_refspec
690d8824
JH
1567}
1568
1569_git_push ()
1570{
da48616f
PD
1571 local cur prev
1572 _get_comp_words_by_ref -n =: cur prev
1573 case "$prev" in
0a4e1472
JS
1574 --repo)
1575 __gitcomp "$(__git_remotes)"
1576 return
1577 esac
1578 case "$cur" in
1579 --repo=*)
1580 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1581 return
1582 ;;
1583 --*)
1584 __gitcomp "
1585 --all --mirror --tags --dry-run --force --verbose
1586 --receive-pack= --repo=
1587 "
1588 return
1589 ;;
1590 esac
52d5c3b5 1591 __git_complete_remote_or_refspec
690d8824
JH
1592}
1593
61d926a3
SP
1594_git_rebase ()
1595{
da48616f
PD
1596 local dir="$(__gitdir)"
1597 local cur
1598 _get_comp_words_by_ref -n =: cur
51ef1daa 1599 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
b3391775 1600 __gitcomp "--continue --skip --abort"
61d926a3
SP
1601 return
1602 fi
3c7b480a 1603 __git_complete_strategy && return
61d926a3 1604 case "$cur" in
93cf50a4
BG
1605 --whitespace=*)
1606 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1607 return
1608 ;;
61d926a3 1609 --*)
93cf50a4
BG
1610 __gitcomp "
1611 --onto --merge --strategy --interactive
1612 --preserve-merges --stat --no-stat
1613 --committer-date-is-author-date --ignore-date
1614 --ignore-whitespace --whitespace=
6d0d465e 1615 --autosquash
93cf50a4
BG
1616 "
1617
61d926a3
SP
1618 return
1619 esac
b3391775 1620 __gitcomp "$(__git_refs)"
61d926a3
SP
1621}
1622
ae616de6 1623__git_send_email_confirm_options="always never auto cc compose"
cb8a9bd5 1624__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
ae616de6 1625
25a1f374
TL
1626_git_send_email ()
1627{
da48616f
PD
1628 local cur
1629 _get_comp_words_by_ref -n =: cur
25a1f374 1630 case "$cur" in
ae616de6
SB
1631 --confirm=*)
1632 __gitcomp "
1633 $__git_send_email_confirm_options
1634 " "" "${cur##--confirm=}"
1635 return
1636 ;;
1637 --suppress-cc=*)
1638 __gitcomp "
1639 $__git_send_email_suppresscc_options
1640 " "" "${cur##--suppress-cc=}"
1641
1642 return
1643 ;;
1644 --smtp-encryption=*)
1645 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1646 return
1647 ;;
25a1f374 1648 --*)
77813151 1649 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
ae616de6
SB
1650 --compose --confirm= --dry-run --envelope-sender
1651 --from --identity
25a1f374
TL
1652 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1653 --no-suppress-from --no-thread --quiet
1654 --signed-off-by-cc --smtp-pass --smtp-server
ae616de6
SB
1655 --smtp-server-port --smtp-encryption= --smtp-user
1656 --subject --suppress-cc= --suppress-from --thread --to
fd3a8dcb 1657 --validate --no-validate"
25a1f374
TL
1658 return
1659 ;;
1660 esac
1661 COMPREPLY=()
1662}
1663
424cce83
SG
1664_git_stage ()
1665{
1666 _git_add
1667}
1668
00652369
SB
1669__git_config_get_set_variables ()
1670{
da48616f
PD
1671 local words cword
1672 _get_comp_words_by_ref -n =: words cword
1673 local prevword word config_file= c=$cword
00652369 1674 while [ $c -gt 1 ]; do
da48616f 1675 word="${words[c]}"
00652369
SB
1676 case "$word" in
1677 --global|--system|--file=*)
1678 config_file="$word"
1679 break
1680 ;;
1681 -f|--file)
1682 config_file="$word $prevword"
1683 break
1684 ;;
1685 esac
1686 prevword=$word
1687 c=$((--c))
1688 done
1689
f581de1b
SB
1690 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1691 while read line
1692 do
1693 case "$line" in
1694 *.*=*)
1695 echo "${line/=*/}"
00652369
SB
1696 ;;
1697 esac
1698 done
1699}
1700
e0d10e1c 1701_git_config ()
5de40f59 1702{
da48616f
PD
1703 local cur prev
1704 _get_comp_words_by_ref -n =: cur prev
1705 case "$prev" in
5de40f59 1706 branch.*.remote)
78d4d6a2 1707 __gitcomp "$(__git_remotes)"
5de40f59
SP
1708 return
1709 ;;
1710 branch.*.merge)
78d4d6a2 1711 __gitcomp "$(__git_refs)"
5de40f59
SP
1712 return
1713 ;;
1714 remote.*.fetch)
da48616f 1715 local remote="${prev#remote.}"
5de40f59 1716 remote="${remote%.fetch}"
78d4d6a2 1717 __gitcomp "$(__git_refs_remotes "$remote")"
5de40f59
SP
1718 return
1719 ;;
1720 remote.*.push)
da48616f 1721 local remote="${prev#remote.}"
5de40f59 1722 remote="${remote%.push}"
78d4d6a2 1723 __gitcomp "$(git --git-dir="$(__gitdir)" \
5de40f59 1724 for-each-ref --format='%(refname):%(refname)' \
78d4d6a2
SP
1725 refs/heads)"
1726 return
1727 ;;
1728 pull.twohead|pull.octopus)
eaa4e6ee
JN
1729 __git_compute_merge_strategies
1730 __gitcomp "$__git_merge_strategies"
78d4d6a2
SP
1731 return
1732 ;;
6123d719
MH
1733 color.branch|color.diff|color.interactive|\
1734 color.showbranch|color.status|color.ui)
78d4d6a2
SP
1735 __gitcomp "always never auto"
1736 return
1737 ;;
901d615c
MK
1738 color.pager)
1739 __gitcomp "false true"
1740 return
1741 ;;
78d4d6a2
SP
1742 color.*.*)
1743 __gitcomp "
98171a07 1744 normal black red green yellow blue magenta cyan white
78d4d6a2
SP
1745 bold dim ul blink reverse
1746 "
5de40f59
SP
1747 return
1748 ;;
9b82d63b
SB
1749 help.format)
1750 __gitcomp "man info web html"
1751 return
1752 ;;
672c68cb
SB
1753 log.date)
1754 __gitcomp "$__git_log_date_formats"
1755 return
1756 ;;
ae616de6
SB
1757 sendemail.aliasesfiletype)
1758 __gitcomp "mutt mailrc pine elm gnus"
1759 return
1760 ;;
1761 sendemail.confirm)
1762 __gitcomp "$__git_send_email_confirm_options"
1763 return
1764 ;;
1765 sendemail.suppresscc)
1766 __gitcomp "$__git_send_email_suppresscc_options"
1767 return
1768 ;;
00652369
SB
1769 --get|--get-all|--unset|--unset-all)
1770 __gitcomp "$(__git_config_get_set_variables)"
1771 return
1772 ;;
5de40f59
SP
1773 *.*)
1774 COMPREPLY=()
1775 return
1776 ;;
1777 esac
1778 case "$cur" in
1779 --*)
78d4d6a2 1780 __gitcomp "
47e98eec 1781 --global --system --file=
12977705 1782 --list --replace-all
5de40f59 1783 --get --get-all --get-regexp
1b71eb35 1784 --add --unset --unset-all
12977705 1785 --remove-section --rename-section
78d4d6a2 1786 "
5de40f59
SP
1787 return
1788 ;;
1789 branch.*.*)
1790 local pfx="${cur%.*}."
1791 cur="${cur##*.}"
6fac1b83 1792 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
5de40f59
SP
1793 return
1794 ;;
1795 branch.*)
1796 local pfx="${cur%.*}."
1797 cur="${cur#*.}"
78d4d6a2 1798 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
5de40f59
SP
1799 return
1800 ;;
0aa62fd0
SB
1801 guitool.*.*)
1802 local pfx="${cur%.*}."
1803 cur="${cur##*.}"
1804 __gitcomp "
1805 argprompt cmd confirm needsfile noconsole norescan
1806 prompt revprompt revunmerged title
1807 " "$pfx" "$cur"
1808 return
1809 ;;
1810 difftool.*.*)
1811 local pfx="${cur%.*}."
1812 cur="${cur##*.}"
1813 __gitcomp "cmd path" "$pfx" "$cur"
1814 return
1815 ;;
1816 man.*.*)
1817 local pfx="${cur%.*}."
1818 cur="${cur##*.}"
1819 __gitcomp "cmd path" "$pfx" "$cur"
1820 return
1821 ;;
1822 mergetool.*.*)
1823 local pfx="${cur%.*}."
1824 cur="${cur##*.}"
1825 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1826 return
1827 ;;
1828 pager.*)
1829 local pfx="${cur%.*}."
1830 cur="${cur#*.}"
eaa4e6ee
JN
1831 __git_compute_all_commands
1832 __gitcomp "$__git_all_commands" "$pfx" "$cur"
0aa62fd0
SB
1833 return
1834 ;;
5de40f59
SP
1835 remote.*.*)
1836 local pfx="${cur%.*}."
1837 cur="${cur##*.}"
12977705 1838 __gitcomp "
98171a07 1839 url proxy fetch push mirror skipDefaultUpdate
6fac1b83 1840 receivepack uploadpack tagopt pushurl
12977705 1841 " "$pfx" "$cur"
5de40f59
SP
1842 return
1843 ;;
1844 remote.*)
1845 local pfx="${cur%.*}."
1846 cur="${cur#*.}"
78d4d6a2 1847 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
5de40f59
SP
1848 return
1849 ;;
0aa62fd0
SB
1850 url.*.*)
1851 local pfx="${cur%.*}."
1852 cur="${cur##*.}"
1c2eafb8 1853 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
0aa62fd0
SB
1854 return
1855 ;;
5de40f59 1856 esac
78d4d6a2 1857 __gitcomp "
6fac1b83 1858 add.ignore-errors
226b343c 1859 alias.
86c91f91 1860 apply.ignorewhitespace
5de40f59 1861 apply.whitespace
98171a07
LM
1862 branch.autosetupmerge
1863 branch.autosetuprebase
2122591b 1864 clean.requireForce
78d4d6a2
SP
1865 color.branch
1866 color.branch.current
1867 color.branch.local
78d4d6a2 1868 color.branch.plain
025a1929 1869 color.branch.remote
a159ca0c 1870 color.diff
025a1929 1871 color.diff.commit
78d4d6a2 1872 color.diff.frag
025a1929 1873 color.diff.meta
78d4d6a2 1874 color.diff.new
025a1929
LM
1875 color.diff.old
1876 color.diff.plain
78d4d6a2 1877 color.diff.whitespace
226b343c
SB
1878 color.grep
1879 color.grep.external
1880 color.grep.match
98171a07
LM
1881 color.interactive
1882 color.interactive.header
1883 color.interactive.help
1884 color.interactive.prompt
a159ca0c 1885 color.pager
6123d719 1886 color.showbranch
a159ca0c 1887 color.status
78d4d6a2
SP
1888 color.status.added
1889 color.status.changed
025a1929 1890 color.status.header
98171a07 1891 color.status.nobranch
78d4d6a2 1892 color.status.untracked
98171a07
LM
1893 color.status.updated
1894 color.ui
1895 commit.template
1896 core.autocrlf
1897 core.bare
025a1929 1898 core.compression
226b343c 1899 core.createObject
98171a07
LM
1900 core.deltaBaseCacheLimit
1901 core.editor
1902 core.excludesfile
025a1929 1903 core.fileMode
98171a07 1904 core.fsyncobjectfiles
025a1929 1905 core.gitProxy
98171a07 1906 core.ignoreCygwinFSTricks
025a1929
LM
1907 core.ignoreStat
1908 core.logAllRefUpdates
1909 core.loosecompression
1910 core.packedGitLimit
1911 core.packedGitWindowSize
98171a07 1912 core.pager
025a1929 1913 core.preferSymlinkRefs
98171a07
LM
1914 core.preloadindex
1915 core.quotepath
025a1929 1916 core.repositoryFormatVersion
98171a07 1917 core.safecrlf
025a1929 1918 core.sharedRepository
98171a07
LM
1919 core.symlinks
1920 core.trustctime
025a1929 1921 core.warnAmbiguousRefs
98171a07
LM
1922 core.whitespace
1923 core.worktree
1924 diff.autorefreshindex
1925 diff.external
1926 diff.mnemonicprefix
78d4d6a2 1927 diff.renameLimit
98171a07 1928 diff.renameLimit.
78d4d6a2 1929 diff.renames
226b343c
SB
1930 diff.suppressBlankEmpty
1931 diff.tool
1932 diff.wordRegex
0aa62fd0 1933 difftool.
226b343c 1934 difftool.prompt
78d4d6a2 1935 fetch.unpackLimit
226b343c
SB
1936 format.attach
1937 format.cc
78d4d6a2 1938 format.headers
98171a07
LM
1939 format.numbered
1940 format.pretty
d8e1e5df 1941 format.signature
226b343c
SB
1942 format.signoff
1943 format.subjectprefix
98171a07 1944 format.suffix
226b343c 1945 format.thread
98171a07
LM
1946 gc.aggressiveWindow
1947 gc.auto
1948 gc.autopacklimit
12977705 1949 gc.packrefs
98171a07 1950 gc.pruneexpire
78d4d6a2
SP
1951 gc.reflogexpire
1952 gc.reflogexpireunreachable
1953 gc.rerereresolved
1954 gc.rerereunresolved
025a1929 1955 gitcvs.allbinary
226b343c 1956 gitcvs.commitmsgannotation
98171a07 1957 gitcvs.dbTableNamePrefix
025a1929
LM
1958 gitcvs.dbdriver
1959 gitcvs.dbname
1960 gitcvs.dbpass
025a1929
LM
1961 gitcvs.dbuser
1962 gitcvs.enabled
1963 gitcvs.logfile
98171a07 1964 gitcvs.usecrlfattr
0aa62fd0 1965 guitool.
98171a07
LM
1966 gui.blamehistoryctx
1967 gui.commitmsgwidth
1968 gui.copyblamethreshold
1969 gui.diffcontext
1970 gui.encoding
1971 gui.fastcopyblame
1972 gui.matchtrackingbranch
1973 gui.newbranchtemplate
1974 gui.pruneduringfetch
1975 gui.spellingdictionary
1976 gui.trustmtime
1977 help.autocorrect
1978 help.browser
1979 help.format
78d4d6a2
SP
1980 http.lowSpeedLimit
1981 http.lowSpeedTime
025a1929 1982 http.maxRequests
5de40f59 1983 http.noEPSV
98171a07 1984 http.proxy
025a1929
LM
1985 http.sslCAInfo
1986 http.sslCAPath
1987 http.sslCert
1988 http.sslKey
1989 http.sslVerify
78d4d6a2
SP
1990 i18n.commitEncoding
1991 i18n.logOutputEncoding
226b343c
SB
1992 imap.folder
1993 imap.host
1994 imap.pass
1995 imap.port
1996 imap.preformattedHTML
1997 imap.sslverify
1998 imap.tunnel
1999 imap.user
98171a07
LM
2000 instaweb.browser
2001 instaweb.httpd
2002 instaweb.local
2003 instaweb.modulepath
2004 instaweb.port
226b343c 2005 interactive.singlekey
98171a07 2006 log.date
78d4d6a2 2007 log.showroot
226b343c 2008 mailmap.file
0aa62fd0 2009 man.
98171a07
LM
2010 man.viewer
2011 merge.conflictstyle
2012 merge.log
2013 merge.renameLimit
2014 merge.stat
025a1929 2015 merge.tool
78d4d6a2 2016 merge.verbosity
0aa62fd0 2017 mergetool.
98171a07 2018 mergetool.keepBackup
226b343c 2019 mergetool.prompt
47e98eec 2020 pack.compression
47e98eec 2021 pack.deltaCacheLimit
025a1929
LM
2022 pack.deltaCacheSize
2023 pack.depth
98171a07
LM
2024 pack.indexVersion
2025 pack.packSizeLimit
2026 pack.threads
025a1929
LM
2027 pack.window
2028 pack.windowMemory
0aa62fd0 2029 pager.
78d4d6a2
SP
2030 pull.octopus
2031 pull.twohead
226b343c
SB
2032 push.default
2033 rebase.stat
98171a07
LM
2034 receive.denyCurrentBranch
2035 receive.denyDeletes
025a1929 2036 receive.denyNonFastForwards
98171a07 2037 receive.fsckObjects
025a1929 2038 receive.unpackLimit
98171a07
LM
2039 repack.usedeltabaseoffset
2040 rerere.autoupdate
2041 rerere.enabled
226b343c
SB
2042 sendemail.aliasesfile
2043 sendemail.aliasesfiletype
2044 sendemail.bcc
2045 sendemail.cc
2046 sendemail.cccmd
2047 sendemail.chainreplyto
2048 sendemail.confirm
2049 sendemail.envelopesender
2050 sendemail.multiedit
2051 sendemail.signedoffbycc
2052 sendemail.smtpencryption
2053 sendemail.smtppass
2054 sendemail.smtpserver
2055 sendemail.smtpserverport
2056 sendemail.smtpuser
2057 sendemail.suppresscc
2058 sendemail.suppressfrom
2059 sendemail.thread
2060 sendemail.to
2061 sendemail.validate
78d4d6a2 2062 showbranch.default
98171a07
LM
2063 status.relativePaths
2064 status.showUntrackedFiles
78d4d6a2
SP
2065 tar.umask
2066 transfer.unpackLimit
0aa62fd0 2067 url.
78d4d6a2 2068 user.email
025a1929 2069 user.name
78d4d6a2 2070 user.signingkey
98171a07 2071 web.browser
5de40f59 2072 branch. remote.
78d4d6a2 2073 "
5de40f59
SP
2074}
2075
88293c67
SP
2076_git_remote ()
2077{
bc14fac8 2078 local subcommands="add rename rm show prune update set-head"
918c03c2 2079 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3ff1320d 2080 if [ -z "$subcommand" ]; then
3903c618 2081 __gitcomp "$subcommands"
88293c67
SP
2082 return
2083 fi
2084
3ff1320d 2085 case "$subcommand" in
f135e72d 2086 rename|rm|show|prune)
88293c67
SP
2087 __gitcomp "$(__git_remotes)"
2088 ;;
fb72759b
SP
2089 update)
2090 local i c='' IFS=$'\n'
518ef8f0
TZ
2091 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2092 i="${i#remotes.}"
2093 c="$c ${i/ */}"
fb72759b
SP
2094 done
2095 __gitcomp "$c"
2096 ;;
88293c67
SP
2097 *)
2098 COMPREPLY=()
2099 ;;
2100 esac
2101}
2102
e1c1a067
BG
2103_git_replace ()
2104{
2105 __gitcomp "$(__git_refs)"
2106}
2107
67e78c3b
SP
2108_git_reset ()
2109{
d773c631
SG
2110 __git_has_doubledash && return
2111
da48616f
PD
2112 local cur
2113 _get_comp_words_by_ref -n =: cur
b3391775
SP
2114 case "$cur" in
2115 --*)
9f040e95 2116 __gitcomp "--merge --mixed --hard --soft --patch"
b3391775
SP
2117 return
2118 ;;
2119 esac
2120 __gitcomp "$(__git_refs)"
67e78c3b
SP
2121}
2122
a6c2be24
LM
2123_git_revert ()
2124{
da48616f
PD
2125 local cur
2126 _get_comp_words_by_ref -n =: cur
a6c2be24
LM
2127 case "$cur" in
2128 --*)
2129 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2130 return
2131 ;;
2132 esac
c0783837 2133 __gitcomp "$(__git_refs)"
a6c2be24
LM
2134}
2135
08c701d4
LM
2136_git_rm ()
2137{
2138 __git_has_doubledash && return
2139
da48616f
PD
2140 local cur
2141 _get_comp_words_by_ref -n =: cur
08c701d4
LM
2142 case "$cur" in
2143 --*)
2144 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2145 return
2146 ;;
2147 esac
2148 COMPREPLY=()
2149}
2150
1fd6bec9
SP
2151_git_shortlog ()
2152{
d773c631
SG
2153 __git_has_doubledash && return
2154
da48616f
PD
2155 local cur
2156 _get_comp_words_by_ref -n =: cur
1fd6bec9
SP
2157 case "$cur" in
2158 --*)
2159 __gitcomp "
a393777e
TR
2160 $__git_log_common_options
2161 $__git_log_shortlog_options
1fd6bec9
SP
2162 --numbered --summary
2163 "
2164 return
2165 ;;
2166 esac
2167 __git_complete_revlist
2168}
2169
90131924
SP
2170_git_show ()
2171{
41d8cf7d
MH
2172 __git_has_doubledash && return
2173
da48616f
PD
2174 local cur
2175 _get_comp_words_by_ref -n =: cur
90131924
SP
2176 case "$cur" in
2177 --pretty=*)
3d279863 2178 __gitcomp "$__git_log_pretty_formats
b3391775 2179 " "" "${cur##--pretty=}"
90131924
SP
2180 return
2181 ;;
72de29c2
TL
2182 --format=*)
2183 __gitcomp "$__git_log_pretty_formats
2184 " "" "${cur##--format=}"
2185 return
2186 ;;
90131924 2187 --*)
076c3237 2188 __gitcomp "--pretty= --format= --abbrev-commit --oneline
20bf7292
TR
2189 $__git_diff_common_options
2190 "
90131924
SP
2191 return
2192 ;;
2193 esac
2194 __git_complete_file
2195}
2196
2ca880fe
TR
2197_git_show_branch ()
2198{
da48616f
PD
2199 local cur
2200 _get_comp_words_by_ref -n =: cur
2ca880fe
TR
2201 case "$cur" in
2202 --*)
2203 __gitcomp "
2204 --all --remotes --topo-order --current --more=
2205 --list --independent --merge-base --no-name
6123d719 2206 --color --no-color
076c3237 2207 --sha1-name --sparse --topics --reflog
2ca880fe
TR
2208 "
2209 return
2210 ;;
2211 esac
2212 __git_complete_revlist
2213}
2214
7fd53fce
JH
2215_git_stash ()
2216{
da48616f
PD
2217 local cur
2218 _get_comp_words_by_ref -n =: cur
59d5eeee 2219 local save_opts='--keep-index --no-keep-index --quiet --patch'
95d43780 2220 local subcommands='save list show apply clear drop pop create branch'
918c03c2 2221 local subcommand="$(__git_find_on_cmdline "$subcommands")"
7bedebca 2222 if [ -z "$subcommand" ]; then
59d5eeee
SG
2223 case "$cur" in
2224 --*)
2225 __gitcomp "$save_opts"
2226 ;;
2227 *)
2228 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2229 __gitcomp "$subcommands"
2230 else
2231 COMPREPLY=()
2232 fi
2233 ;;
2234 esac
7bedebca 2235 else
7bedebca
SG
2236 case "$subcommand,$cur" in
2237 save,--*)
59d5eeee 2238 __gitcomp "$save_opts"
7bedebca 2239 ;;
8513c54b 2240 apply,--*|pop,--*)
59d5eeee 2241 __gitcomp "--index --quiet"
95d43780 2242 ;;
8513c54b 2243 show,--*|drop,--*|branch,--*)
95d43780
LM
2244 COMPREPLY=()
2245 ;;
2246 show,*|apply,*|drop,*|pop,*|branch,*)
2247 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2248 | sed -n -e 's/:.*//p')"
2249 ;;
7bedebca
SG
2250 *)
2251 COMPREPLY=()
2252 ;;
2253 esac
3ff1320d 2254 fi
7fd53fce
JH
2255}
2256
be86f7a0
SP
2257_git_submodule ()
2258{
d773c631
SG
2259 __git_has_doubledash && return
2260
1b0f7978 2261 local subcommands="add status init update summary foreach sync"
918c03c2 2262 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
da48616f
PD
2263 local cur
2264 _get_comp_words_by_ref -n =: cur
be86f7a0
SP
2265 case "$cur" in
2266 --*)
2267 __gitcomp "--quiet --cached"
2268 ;;
2269 *)
3ff1320d 2270 __gitcomp "$subcommands"
be86f7a0
SP
2271 ;;
2272 esac
2273 return
2274 fi
2275}
2276
47f6ee28
SG
2277_git_svn ()
2278{
2279 local subcommands="
2280 init fetch clone rebase dcommit log find-rev
2281 set-tree commit-diff info create-ignore propget
4a5856cb 2282 proplist show-ignore show-externals branch tag blame
c18d5d82 2283 migrate mkdirs reset gc
47f6ee28 2284 "
918c03c2 2285 local subcommand="$(__git_find_on_cmdline "$subcommands")"
47f6ee28
SG
2286 if [ -z "$subcommand" ]; then
2287 __gitcomp "$subcommands"
2288 else
2289 local remote_opts="--username= --config-dir= --no-auth-cache"
2290 local fc_opts="
2291 --follow-parent --authors-file= --repack=
2292 --no-metadata --use-svm-props --use-svnsync-props
2293 --log-window-size= --no-checkout --quiet
4a5856cb
SG
2294 --repack-flags --use-log-author --localtime
2295 --ignore-paths= $remote_opts
47f6ee28
SG
2296 "
2297 local init_opts="
2298 --template= --shared= --trunk= --tags=
2299 --branches= --stdlayout --minimize-url
2300 --no-metadata --use-svm-props --use-svnsync-props
4a5856cb
SG
2301 --rewrite-root= --prefix= --use-log-author
2302 --add-author-from $remote_opts
47f6ee28
SG
2303 "
2304 local cmt_opts="
2305 --edit --rmdir --find-copies-harder --copy-similarity=
2306 "
2307
da48616f
PD
2308 local cur
2309 _get_comp_words_by_ref -n =: cur
47f6ee28
SG
2310 case "$subcommand,$cur" in
2311 fetch,--*)
2312 __gitcomp "--revision= --fetch-all $fc_opts"
2313 ;;
2314 clone,--*)
2315 __gitcomp "--revision= $fc_opts $init_opts"
2316 ;;
2317 init,--*)
2318 __gitcomp "$init_opts"
2319 ;;
2320 dcommit,--*)
2321 __gitcomp "
2322 --merge --strategy= --verbose --dry-run
4a5856cb
SG
2323 --fetch-all --no-rebase --commit-url
2324 --revision $cmt_opts $fc_opts
47f6ee28
SG
2325 "
2326 ;;
2327 set-tree,--*)
2328 __gitcomp "--stdin $cmt_opts $fc_opts"
2329 ;;
2330 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
c18d5d82 2331 show-externals,--*|mkdirs,--*)
47f6ee28
SG
2332 __gitcomp "--revision="
2333 ;;
2334 log,--*)
2335 __gitcomp "
2336 --limit= --revision= --verbose --incremental
2337 --oneline --show-commit --non-recursive
4a5856cb 2338 --authors-file= --color
47f6ee28
SG
2339 "
2340 ;;
2341 rebase,--*)
2342 __gitcomp "
2343 --merge --verbose --strategy= --local
4a5856cb 2344 --fetch-all --dry-run $fc_opts
47f6ee28
SG
2345 "
2346 ;;
2347 commit-diff,--*)
2348 __gitcomp "--message= --file= --revision= $cmt_opts"
2349 ;;
2350 info,--*)
2351 __gitcomp "--url"
2352 ;;
4a5856cb
SG
2353 branch,--*)
2354 __gitcomp "--dry-run --message --tag"
2355 ;;
2356 tag,--*)
2357 __gitcomp "--dry-run --message"
2358 ;;
2359 blame,--*)
2360 __gitcomp "--git-format"
2361 ;;
2362 migrate,--*)
2363 __gitcomp "
2364 --config-dir= --ignore-paths= --minimize
2365 --no-auth-cache --username=
2366 "
2367 ;;
c18d5d82
RZ
2368 reset,--*)
2369 __gitcomp "--revision= --parent"
2370 ;;
47f6ee28
SG
2371 *)
2372 COMPREPLY=()
2373 ;;
2374 esac
2375 fi
2376}
2377
88e21dc7
SP
2378_git_tag ()
2379{
2380 local i c=1 f=0
da48616f
PD
2381 local words cword prev
2382 _get_comp_words_by_ref -n =: words cword prev
2383 while [ $c -lt $cword ]; do
2384 i="${words[c]}"
88e21dc7
SP
2385 case "$i" in
2386 -d|-v)
2387 __gitcomp "$(__git_tags)"
2388 return
2389 ;;
2390 -f)
2391 f=1
2392 ;;
2393 esac
2394 c=$((++c))
2395 done
2396
da48616f 2397 case "$prev" in
88e21dc7
SP
2398 -m|-F)
2399 COMPREPLY=()
2400 ;;
8d8163f3 2401 -*|tag)
88e21dc7
SP
2402 if [ $f = 1 ]; then
2403 __gitcomp "$(__git_tags)"
2404 else
2405 COMPREPLY=()
2406 fi
2407 ;;
2408 *)
2409 __gitcomp "$(__git_refs)"
2410 ;;
2411 esac
2412}
2413
424cce83
SG
2414_git_whatchanged ()
2415{
2416 _git_log
2417}
2418
690d8824
JH
2419_git ()
2420{
873537fa
SP
2421 local i c=1 command __git_dir
2422
da48616f
PD
2423 local cur words cword
2424 _get_comp_words_by_ref -n =: cur words cword
2425 while [ $c -lt $cword ]; do
2426 i="${words[c]}"
873537fa
SP
2427 case "$i" in
2428 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2429 --bare) __git_dir="." ;;
1eb7e2f8
LM
2430 --version|-p|--paginate) ;;
2431 --help) command="help"; break ;;
873537fa
SP
2432 *) command="$i"; break ;;
2433 esac
2434 c=$((++c))
2435 done
2436
1d17b22e 2437 if [ -z "$command" ]; then
da48616f 2438 case "$cur" in
47e98eec 2439 --*) __gitcomp "
ce5a2c95 2440 --paginate
47e98eec
SP
2441 --no-pager
2442 --git-dir=
2443 --bare
2444 --version
2445 --exec-path
89a56bfb 2446 --html-path
ce5a2c95
TL
2447 --work-tree=
2448 --help
47e98eec
SP
2449 "
2450 ;;
eaa4e6ee
JN
2451 *) __git_compute_porcelain_commands
2452 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
72e5e989
SP
2453 esac
2454 return
873537fa 2455 fi
367dce2a 2456
424cce83 2457 local completion_func="_git_${command//-/_}"
8024ea60
SG
2458 declare -F $completion_func >/dev/null && $completion_func && return
2459
873537fa 2460 local expansion=$(__git_aliased_command "$command")
8024ea60
SG
2461 if [ -n "$expansion" ]; then
2462 completion_func="_git_${expansion//-/_}"
2463 declare -F $completion_func >/dev/null && $completion_func
2464 fi
690d8824
JH
2465}
2466
2467_gitk ()
2468{
d773c631
SG
2469 __git_has_doubledash && return
2470
da48616f 2471 local cur
fa26a401 2472 local g="$(__gitdir)"
07ba53f7 2473 local merge=""
ba7906f2 2474 if [ -f "$g/MERGE_HEAD" ]; then
07ba53f7
RQ
2475 merge="--merge"
2476 fi
da48616f 2477 _get_comp_words_by_ref -n =: cur
b3391775
SP
2478 case "$cur" in
2479 --*)
a393777e
TR
2480 __gitcomp "
2481 $__git_log_common_options
2482 $__git_log_gitk_options
2483 $merge
2484 "
b3391775
SP
2485 return
2486 ;;
2487 esac
ec804891 2488 __git_complete_revlist
690d8824
JH
2489}
2490
50e126e1
TP
2491complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2492 || complete -o default -o nospace -F _git git
2493complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2494 || complete -o default -o nospace -F _gitk gitk
690d8824
JH
2495
2496# The following are necessary only for Cygwin, and only are needed
2497# when the user has tab-completed the executable name and consequently
2498# included the '.exe' suffix.
2499#
76c3eb51 2500if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
50e126e1
TP
2501complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2502 || complete -o default -o nospace -F _git git.exe
76c3eb51 2503fi