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