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