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