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