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