summaryrefslogtreecommitdiff
path: root/.bash_completion.d
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2016-06-25 11:55:57 -0700
committerMike Crute <mike@crute.us>2016-06-25 11:55:57 -0700
commit6497b99182f8064538e24522158bdb6649b9ba28 (patch)
tree8dee3d1751072fbd91aa79514583532cd8ebc6dc /.bash_completion.d
parentee7c906db6e8b927870280e5af1d39db22f26cfa (diff)
downloaddotfiles-6497b99182f8064538e24522158bdb6649b9ba28.tar.bz2
dotfiles-6497b99182f8064538e24522158bdb6649b9ba28.tar.xz
dotfiles-6497b99182f8064538e24522158bdb6649b9ba28.zip
Update git completion from upstream
Diffstat (limited to '.bash_completion.d')
-rw-r--r--.bash_completion.d/git-completion.bash1148
1 files changed, 584 insertions, 564 deletions
diff --git a/.bash_completion.d/git-completion.bash b/.bash_completion.d/git-completion.bash
index b0062ba..3402475 100644
--- a/.bash_completion.d/git-completion.bash
+++ b/.bash_completion.d/git-completion.bash
@@ -1,5 +1,3 @@
1#!bash
2#
3# bash/zsh completion support for core Git. 1# bash/zsh completion support for core Git.
4# 2#
5# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org> 3# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
@@ -12,70 +10,24 @@
12# *) local and remote tag names 10# *) local and remote tag names
13# *) .git/remotes file names 11# *) .git/remotes file names
14# *) git 'subcommands' 12# *) git 'subcommands'
13# *) git email aliases for git-send-email
15# *) tree paths within 'ref:path/to/file' expressions 14# *) tree paths within 'ref:path/to/file' expressions
15# *) file paths within current working directory and index
16# *) common --long-options 16# *) common --long-options
17# 17#
18# To use these routines: 18# To use these routines:
19# 19#
20# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh). 20# 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21# 2) Add the following line to your .bashrc/.zshrc: 21# 2) Add the following line to your .bashrc/.zshrc:
22# source ~/.git-completion.sh 22# source ~/.git-completion.bash
23# 23# 3) Consider changing your PS1 to also show the current branch,
24# 3) Consider changing your PS1 to also show the current branch: 24# see git-prompt.sh for details.
25# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
26# ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
27#
28# The argument to __git_ps1 will be displayed only if you
29# are currently in a git repository. The %s token will be
30# the name of the current branch.
31#
32# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
33# value, unstaged (*) and staged (+) changes will be shown next
34# to the branch name. You can configure this per-repository
35# with the bash.showDirtyState variable, which defaults to true
36# once GIT_PS1_SHOWDIRTYSTATE is enabled.
37#
38# You can also see if currently something is stashed, by setting
39# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
40# then a '$' will be shown next to the branch name.
41#
42# If you would like to see if there're untracked files, then you can
43# set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
44# untracked files, then a '%' will be shown next to the branch name.
45#
46# If you would like to see the difference between HEAD and its
47# upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates
48# you are behind, ">" indicates you are ahead, and "<>"
49# indicates you have diverged. You can further control
50# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
51# list of values:
52# verbose show number of commits ahead/behind (+/-) upstream
53# legacy don't use the '--count' option available in recent
54# versions of git-rev-list
55# git always compare HEAD to @{upstream}
56# svn always compare HEAD to your SVN upstream
57# By default, __git_ps1 will compare HEAD to your SVN upstream
58# if it can find one, or @{upstream} otherwise. Once you have
59# set GIT_PS1_SHOWUPSTREAM, you can override it on a
60# per-repository basis by setting the bash.showUpstream config
61# variable.
62#
63#
64# To submit patches:
65#
66# *) Read Documentation/SubmittingPatches
67# *) Send all patches to the current maintainer:
68#
69# "Shawn O. Pearce" <spearce@spearce.org>
70#
71# *) Always CC the Git mailing list:
72# 25#
73# git@vger.kernel.org 26# If you use complex aliases of form '!f() { ... }; f', you can use the null
74# 27# command ':' as the first command in the function body to declare the desired
75 28# completion style. For example '!f() { : git commit ; ... }; f' will
76if [[ -n ${ZSH_VERSION-} ]]; then 29# tell the completion to use commit completion. This also works with aliases
77 autoload -U +X bashcompinit && bashcompinit 30# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
78fi
79 31
80case "$COMP_WORDBREAKS" in 32case "$COMP_WORDBREAKS" in
81*:*) : great ;; 33*:*) : great ;;
@@ -89,6 +41,9 @@ __gitdir ()
89 if [ -z "${1-}" ]; then 41 if [ -z "${1-}" ]; then
90 if [ -n "${__git_dir-}" ]; then 42 if [ -n "${__git_dir-}" ]; then
91 echo "$__git_dir" 43 echo "$__git_dir"
44 elif [ -n "${GIT_DIR-}" ]; then
45 test -d "${GIT_DIR-}" || return 1
46 echo "$GIT_DIR"
92 elif [ -d .git ]; then 47 elif [ -d .git ]; then
93 echo .git 48 echo .git
94 else 49 else
@@ -101,235 +56,6 @@ __gitdir ()
101 fi 56 fi
102} 57}
103 58
104# stores the divergence from upstream in $p
105# used by GIT_PS1_SHOWUPSTREAM
106__git_ps1_show_upstream ()
107{
108 local key value
109 local svn_remote=() svn_url_pattern count n
110 local upstream=git legacy="" verbose=""
111
112 # get some config options from git-config
113 local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
114 while read -r key value; do
115 case "$key" in
116 bash.showupstream)
117 GIT_PS1_SHOWUPSTREAM="$value"
118 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
119 p=""
120 return
121 fi
122 ;;
123 svn-remote.*.url)
124 svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
125 svn_url_pattern+="\\|$value"
126 upstream=svn+git # default upstream is SVN if available, else git
127 ;;
128 esac
129 done <<< "$output"
130
131 # parse configuration values
132 for option in ${GIT_PS1_SHOWUPSTREAM}; do
133 case "$option" in
134 git|svn) upstream="$option" ;;
135 verbose) verbose=1 ;;
136 legacy) legacy=1 ;;
137 esac
138 done
139
140 # Find our upstream
141 case "$upstream" in
142 git) upstream="@{upstream}" ;;
143 svn*)
144 # get the upstream from the "git-svn-id: ..." in a commit message
145 # (git-svn uses essentially the same procedure internally)
146 local svn_upstream=($(git log --first-parent -1 \
147 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
148 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
149 svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
150 svn_upstream=${svn_upstream%@*}
151 local n_stop="${#svn_remote[@]}"
152 for ((n=1; n <= n_stop; ++n)); do
153 svn_upstream=${svn_upstream#${svn_remote[$n]}}
154 done
155
156 if [[ -z "$svn_upstream" ]]; then
157 # default branch name for checkouts with no layout:
158 upstream=${GIT_SVN_ID:-git-svn}
159 else
160 upstream=${svn_upstream#/}
161 fi
162 elif [[ "svn+git" = "$upstream" ]]; then
163 upstream="@{upstream}"
164 fi
165 ;;
166 esac
167
168 # Find how many commits we are ahead/behind our upstream
169 if [[ -z "$legacy" ]]; then
170 count="$(git rev-list --count --left-right \
171 "$upstream"...HEAD 2>/dev/null)"
172 else
173 # produce equivalent output to --count for older versions of git
174 local commits
175 if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
176 then
177 local commit behind=0 ahead=0
178 for commit in $commits
179 do
180 case "$commit" in
181 "<"*) let ++behind
182 ;;
183 *) let ++ahead
184 ;;
185 esac
186 done
187 count="$behind $ahead"
188 else
189 count=""
190 fi
191 fi
192
193 # calculate the result
194 if [[ -z "$verbose" ]]; then
195 case "$count" in
196 "") # no upstream
197 p="" ;;
198 "0 0") # equal to upstream
199 p="=" ;;
200 "0 "*) # ahead of upstream
201 p=">" ;;
202 *" 0") # behind upstream
203 p="<" ;;
204 *) # diverged from upstream
205 p="<>" ;;
206 esac
207 else
208 case "$count" in
209 "") # no upstream
210 p="" ;;
211 "0 0") # equal to upstream
212 p=" u=" ;;
213 "0 "*) # ahead of upstream
214 p=" u+${count#0 }" ;;
215 *" 0") # behind upstream
216 p=" u-${count% 0}" ;;
217 *) # diverged from upstream
218 p=" u+${count#* }-${count% *}" ;;
219 esac
220 fi
221
222}
223
224
225# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
226# returns text to add to bash PS1 prompt (includes branch name)
227__git_ps1 ()
228{
229 local g="$(__gitdir)"
230 if [ -n "$g" ]; then
231 local r=""
232 local b=""
233 if [ -f "$g/rebase-merge/interactive" ]; then
234 r="|REBASE-i"
235 b="$(cat "$g/rebase-merge/head-name")"
236 elif [ -d "$g/rebase-merge" ]; then
237 r="|REBASE-m"
238 b="$(cat "$g/rebase-merge/head-name")"
239 else
240 if [ -d "$g/rebase-apply" ]; then
241 if [ -f "$g/rebase-apply/rebasing" ]; then
242 r="|REBASE"
243 elif [ -f "$g/rebase-apply/applying" ]; then
244 r="|AM"
245 else
246 r="|AM/REBASE"
247 fi
248 elif [ -f "$g/MERGE_HEAD" ]; then
249 r="|MERGING"
250 elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
251 r="|CHERRY-PICKING"
252 elif [ -f "$g/BISECT_LOG" ]; then
253 r="|BISECTING"
254 fi
255
256 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
257
258 b="$(
259 case "${GIT_PS1_DESCRIBE_STYLE-}" in
260 (contains)
261 git describe --contains HEAD ;;
262 (branch)
263 git describe --contains --all HEAD ;;
264 (describe)
265 git describe HEAD ;;
266 (* | default)
267 git describe --tags --exact-match HEAD ;;
268 esac 2>/dev/null)" ||
269
270 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
271 b="unknown"
272 b="($b)"
273 }
274 fi
275
276 local w=""
277 local i=""
278 local s=""
279 local u=""
280 local c=""
281 local p=""
282
283 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
284 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
285 c="BARE:"
286 else
287 b="GIT_DIR!"
288 fi
289 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
290 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
291 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
292 git diff --no-ext-diff --quiet --exit-code || w="*"
293 if git rev-parse --quiet --verify HEAD >/dev/null; then
294 git diff-index --cached --quiet HEAD -- || i="+"
295 else
296 i="#"
297 fi
298 fi
299 fi
300 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
301 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
302 fi
303
304 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
305 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
306 u="%"
307 fi
308 fi
309
310 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
311 __git_ps1_show_upstream
312 fi
313 fi
314
315 local f="$w$i$s$u"
316 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
317 fi
318}
319
320# __gitcomp_1 requires 2 arguments
321__gitcomp_1 ()
322{
323 local c IFS=' '$'\t'$'\n'
324 for c in $1; do
325 case "$c$2" in
326 --*=*) printf %s$'\n' "$c$2" ;;
327 *.) printf %s$'\n' "$c$2" ;;
328 *) printf %s$'\n' "$c$2 " ;;
329 esac
330 done
331}
332
333# The following function is based on code from: 59# The following function is based on code from:
334# 60#
335# bash_completion - programmable completion functions for bash 3.2+ 61# bash_completion - programmable completion functions for bash 3.2+
@@ -430,7 +156,6 @@ __git_reassemble_comp_words_by_ref()
430} 156}
431 157
432if ! type _get_comp_words_by_ref >/dev/null 2>&1; then 158if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
433if [[ -z ${ZSH_VERSION:+set} ]]; then
434_get_comp_words_by_ref () 159_get_comp_words_by_ref ()
435{ 160{
436 local exclude cur_ words_ cword_ 161 local exclude cur_ words_ cword_
@@ -458,36 +183,26 @@ _get_comp_words_by_ref ()
458 shift 183 shift
459 done 184 done
460} 185}
461else 186fi
462_get_comp_words_by_ref () 187
188__gitcompappend ()
463{ 189{
464 while [ $# -gt 0 ]; do 190 local x i=${#COMPREPLY[@]}
465 case "$1" in 191 for x in $1; do
466 cur) 192 if [[ "$x" == "$3"* ]]; then
467 cur=${COMP_WORDS[COMP_CWORD]} 193 COMPREPLY[i++]="$2$x$4"
468 ;; 194 fi
469 prev)
470 prev=${COMP_WORDS[COMP_CWORD-1]}
471 ;;
472 words)
473 words=("${COMP_WORDS[@]}")
474 ;;
475 cword)
476 cword=$COMP_CWORD
477 ;;
478 -n)
479 # assume COMP_WORDBREAKS is already set sanely
480 shift
481 ;;
482 esac
483 shift
484 done 195 done
485} 196}
486fi
487fi
488 197
489# Generates completion reply with compgen, appending a space to possible 198__gitcompadd ()
490# completion words, if necessary. 199{
200 COMPREPLY=()
201 __gitcompappend "$@"
202}
203
204# Generates completion reply, appending a space to possible completion words,
205# if necessary.
491# It accepts 1 to 4 arguments: 206# It accepts 1 to 4 arguments:
492# 1: List of possible completion words. 207# 1: List of possible completion words.
493# 2: A prefix to be added to each possible completion word (optional). 208# 2: A prefix to be added to each possible completion word (optional).
@@ -495,26 +210,37 @@ fi
495# 4: A suffix to be appended to each possible completion word (optional). 210# 4: A suffix to be appended to each possible completion word (optional).
496__gitcomp () 211__gitcomp ()
497{ 212{
498 local cur_="$cur" 213 local cur_="${3-$cur}"
499 214
500 if [ $# -gt 2 ]; then
501 cur_="$3"
502 fi
503 case "$cur_" in 215 case "$cur_" in
504 --*=) 216 --*=)
505 COMPREPLY=()
506 ;; 217 ;;
507 *) 218 *)
508 local IFS=$'\n' 219 local c i=0 IFS=$' \t\n'
509 COMPREPLY=($(compgen -P "${2-}" \ 220 for c in $1; do
510 -W "$(__gitcomp_1 "${1-}" "${4-}")" \ 221 c="$c${4-}"
511 -- "$cur_")) 222 if [[ $c == "$cur_"* ]]; then
223 case $c in
224 --*=*|*.) ;;
225 *) c="$c " ;;
226 esac
227 COMPREPLY[i++]="${2-}$c"
228 fi
229 done
512 ;; 230 ;;
513 esac 231 esac
514} 232}
515 233
516# Generates completion reply with compgen from newline-separated possible 234# Variation of __gitcomp_nl () that appends to the existing list of
517# completion words by appending a space to all of them. 235# completion candidates, COMPREPLY.
236__gitcomp_nl_append ()
237{
238 local IFS=$'\n'
239 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
240}
241
242# Generates completion reply from newline-separated possible completion words
243# by appending a space to all of them.
518# It accepts 1 to 4 arguments: 244# It accepts 1 to 4 arguments:
519# 1: List of possible completion words, separated by a single newline. 245# 1: List of possible completion words, separated by a single newline.
520# 2: A prefix to be added to each possible completion word (optional). 246# 2: A prefix to be added to each possible completion word (optional).
@@ -524,18 +250,66 @@ __gitcomp ()
524# appended. 250# appended.
525__gitcomp_nl () 251__gitcomp_nl ()
526{ 252{
527 local s=$'\n' IFS=' '$'\t'$'\n' 253 COMPREPLY=()
528 local cur_="$cur" suffix=" " 254 __gitcomp_nl_append "$@"
255}
529 256
530 if [ $# -gt 2 ]; then 257# Generates completion reply with compgen from newline-separated possible
531 cur_="$3" 258# completion filenames.
532 if [ $# -gt 3 ]; then 259# It accepts 1 to 3 arguments:
533 suffix="$4" 260# 1: List of possible completion filenames, separated by a single newline.
534 fi 261# 2: A directory prefix to be added to each possible completion filename
535 fi 262# (optional).
263# 3: Generate possible completion matches for this word (optional).
264__gitcomp_file ()
265{
266 local IFS=$'\n'
267
268 # XXX does not work when the directory prefix contains a tilde,
269 # since tilde expansion is not applied.
270 # This means that COMPREPLY will be empty and Bash default
271 # completion will be used.
272 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
273
274 # use a hack to enable file mode in bash < 4
275 compopt -o filenames +o nospace 2>/dev/null ||
276 compgen -f /non-existing-dir/ > /dev/null
277}
536 278
537 IFS=$s 279# Execute 'git ls-files', unless the --committable option is specified, in
538 COMPREPLY=($(compgen -P "${2-}" -S "$suffix" -W "$1" -- "$cur_")) 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.
283__git_ls_files_helper ()
284{
285 if [ "$2" == "--committable" ]; then
286 git -C "$1" diff-index --name-only --relative HEAD
287 else
288 # NOTE: $2 is not quoted in order to support multiple options
289 git -C "$1" ls-files --exclude-standard $2
290 fi 2>/dev/null
291}
292
293
294# __git_index_files accepts 1 or 2 arguments:
295# 1: Options to pass to ls-files (required).
296# 2: A directory path (optional).
297# If provided, only files within the specified directory are listed.
298# Sub directories are never recursed. Path must have a trailing
299# slash.
300__git_index_files ()
301{
302 local dir="$(__gitdir)" root="${2-.}" file
303
304 if [ -d "$dir" ]; then
305 __git_ls_files_helper "$root" "$1" |
306 while read -r file; do
307 case "$file" in
308 ?*/*) echo "${file%%/*}" ;;
309 *) echo "$file" ;;
310 esac
311 done | sort | uniq
312 fi
539} 313}
540 314
541__git_heads () 315__git_heads ()
@@ -595,7 +369,7 @@ __git_refs ()
595 if [[ "$ref" == "$cur"* ]]; then 369 if [[ "$ref" == "$cur"* ]]; then
596 echo "$ref" 370 echo "$ref"
597 fi 371 fi
598 done | uniq -u 372 done | sort | uniq -u
599 fi 373 fi
600 return 374 return
601 fi 375 fi
@@ -610,14 +384,9 @@ __git_refs ()
610 done 384 done
611 ;; 385 ;;
612 *) 386 *)
613 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \ 387 echo "HEAD"
614 while read -r hash i; do 388 git for-each-ref --format="%(refname:short)" -- \
615 case "$i" in 389 "refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##"
616 *^{}) ;;
617 refs/*) echo "${i#refs/*/}" ;;
618 *) echo "$i" ;;
619 esac
620 done
621 ;; 390 ;;
622 esac 391 esac
623} 392}
@@ -643,17 +412,9 @@ __git_refs_remotes ()
643 412
644__git_remotes () 413__git_remotes ()
645{ 414{
646 local i ngoff IFS=$'\n' d="$(__gitdir)" 415 local d="$(__gitdir)"
647 __git_shopt -q nullglob || ngoff=1 416 test -d "$d/remotes" && ls -1 "$d/remotes"
648 __git_shopt -s nullglob 417 git --git-dir="$d" remote
649 for i in "$d/remotes"/*; do
650 echo ${i#$d/remotes/}
651 done
652 [ "$ngoff" ] && __git_shopt -u nullglob
653 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
654 i="${i#remote.}"
655 echo "${i/.url*/}"
656 done
657} 418}
658 419
659__git_list_merge_strategies () 420__git_list_merge_strategies ()
@@ -676,7 +437,8 @@ __git_merge_strategies=
676# is needed. 437# is needed.
677__git_compute_merge_strategies () 438__git_compute_merge_strategies ()
678{ 439{
679 : ${__git_merge_strategies:=$(__git_list_merge_strategies)} 440 test -n "$__git_merge_strategies" ||
441 __git_merge_strategies=$(__git_list_merge_strategies)
680} 442}
681 443
682__git_complete_revlist_file () 444__git_complete_revlist_file ()
@@ -706,9 +468,7 @@ __git_complete_revlist_file ()
706 *) pfx="$ref:$pfx" ;; 468 *) pfx="$ref:$pfx" ;;
707 esac 469 esac
708 470
709 local IFS=$'\n' 471 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
710 COMPREPLY=($(compgen -P "$pfx" \
711 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
712 | sed '/^100... blob /{ 472 | sed '/^100... blob /{
713 s,^.* ,, 473 s,^.* ,,
714 s,$, , 474 s,$, ,
@@ -722,7 +482,7 @@ __git_complete_revlist_file ()
722 s,$,/, 482 s,$,/,
723 } 483 }
724 s/^.* //')" \ 484 s/^.* //')" \
725 -- "$cur_")) 485 "$pfx" "$cur_" ""
726 ;; 486 ;;
727 *...*) 487 *...*)
728 pfx="${cur_%...*}..." 488 pfx="${cur_%...*}..."
@@ -741,6 +501,25 @@ __git_complete_revlist_file ()
741} 501}
742 502
743 503
504# __git_complete_index_file requires 1 argument:
505# 1: the options to pass to ls-file
506#
507# The exception is --committable, which finds the files appropriate commit.
508__git_complete_index_file ()
509{
510 local pfx="" cur_="$cur"
511
512 case "$cur_" in
513 ?*/*)
514 pfx="${cur_%/*}"
515 cur_="${cur_##*/}"
516 pfx="${pfx}/"
517 ;;
518 esac
519
520 __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
521}
522
744__git_complete_file () 523__git_complete_file ()
745{ 524{
746 __git_complete_revlist_file 525 __git_complete_revlist_file
@@ -755,6 +534,9 @@ __git_complete_remote_or_refspec ()
755{ 534{
756 local cur_="$cur" cmd="${words[1]}" 535 local cur_="$cur" cmd="${words[1]}"
757 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0 536 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
537 if [ "$cmd" = "remote" ]; then
538 ((c++))
539 fi
758 while [ $c -lt $cword ]; do 540 while [ $c -lt $cword ]; do
759 i="${words[c]}" 541 i="${words[c]}"
760 case "$i" in 542 case "$i" in
@@ -763,7 +545,6 @@ __git_complete_remote_or_refspec ()
763 case "$cmd" in 545 case "$cmd" in
764 push) no_complete_refspec=1 ;; 546 push) no_complete_refspec=1 ;;
765 fetch) 547 fetch)
766 COMPREPLY=()
767 return 548 return
768 ;; 549 ;;
769 *) ;; 550 *) ;;
@@ -772,14 +553,13 @@ __git_complete_remote_or_refspec ()
772 -*) ;; 553 -*) ;;
773 *) remote="$i"; break ;; 554 *) remote="$i"; break ;;
774 esac 555 esac
775 c=$((++c)) 556 ((c++))
776 done 557 done
777 if [ -z "$remote" ]; then 558 if [ -z "$remote" ]; then
778 __gitcomp_nl "$(__git_remotes)" 559 __gitcomp_nl "$(__git_remotes)"
779 return 560 return
780 fi 561 fi
781 if [ $no_complete_refspec = 1 ]; then 562 if [ $no_complete_refspec = 1 ]; then
782 COMPREPLY=()
783 return 563 return
784 fi 564 fi
785 [ "$remote" = "." ] && remote= 565 [ "$remote" = "." ] && remote=
@@ -805,7 +585,7 @@ __git_complete_remote_or_refspec ()
805 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" 585 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
806 fi 586 fi
807 ;; 587 ;;
808 pull) 588 pull|remote)
809 if [ $lhs = 1 ]; then 589 if [ $lhs = 1 ]; then
810 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_" 590 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
811 else 591 else
@@ -839,10 +619,19 @@ __git_complete_strategy ()
839 return 1 619 return 1
840} 620}
841 621
622__git_commands () {
623 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
624 then
625 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
626 else
627 git help -a|egrep '^ [a-zA-Z0-9]'
628 fi
629}
630
842__git_list_all_commands () 631__git_list_all_commands ()
843{ 632{
844 local i IFS=" "$'\n' 633 local i IFS=" "$'\n'
845 for i in $(git help -a|egrep '^ [a-zA-Z0-9]') 634 for i in $(__git_commands)
846 do 635 do
847 case $i in 636 case $i in
848 *--*) : helper pattern;; 637 *--*) : helper pattern;;
@@ -854,14 +643,15 @@ __git_list_all_commands ()
854__git_all_commands= 643__git_all_commands=
855__git_compute_all_commands () 644__git_compute_all_commands ()
856{ 645{
857 : ${__git_all_commands:=$(__git_list_all_commands)} 646 test -n "$__git_all_commands" ||
647 __git_all_commands=$(__git_list_all_commands)
858} 648}
859 649
860__git_list_porcelain_commands () 650__git_list_porcelain_commands ()
861{ 651{
862 local i IFS=" "$'\n' 652 local i IFS=" "$'\n'
863 __git_compute_all_commands 653 __git_compute_all_commands
864 for i in "help" $__git_all_commands 654 for i in $__git_all_commands
865 do 655 do
866 case $i in 656 case $i in
867 *--*) : helper pattern;; 657 *--*) : helper pattern;;
@@ -870,10 +660,15 @@ __git_list_porcelain_commands ()
870 archimport) : import;; 660 archimport) : import;;
871 cat-file) : plumbing;; 661 cat-file) : plumbing;;
872 check-attr) : plumbing;; 662 check-attr) : plumbing;;
663 check-ignore) : plumbing;;
664 check-mailmap) : plumbing;;
873 check-ref-format) : plumbing;; 665 check-ref-format) : plumbing;;
874 checkout-index) : plumbing;; 666 checkout-index) : plumbing;;
667 column) : internal helper;;
875 commit-tree) : plumbing;; 668 commit-tree) : plumbing;;
876 count-objects) : infrequent;; 669 count-objects) : infrequent;;
670 credential) : credentials;;
671 credential-*) : credentials helper;;
877 cvsexportcommit) : export;; 672 cvsexportcommit) : export;;
878 cvsimport) : import;; 673 cvsimport) : import;;
879 cvsserver) : daemon;; 674 cvsserver) : daemon;;
@@ -892,7 +687,6 @@ __git_list_porcelain_commands ()
892 index-pack) : plumbing;; 687 index-pack) : plumbing;;
893 init-db) : deprecated;; 688 init-db) : deprecated;;
894 local-fetch) : plumbing;; 689 local-fetch) : plumbing;;
895 lost-found) : infrequent;;
896 ls-files) : plumbing;; 690 ls-files) : plumbing;;
897 ls-remote) : plumbing;; 691 ls-remote) : plumbing;;
898 ls-tree) : plumbing;; 692 ls-tree) : plumbing;;
@@ -906,14 +700,12 @@ __git_list_porcelain_commands ()
906 pack-refs) : plumbing;; 700 pack-refs) : plumbing;;
907 parse-remote) : plumbing;; 701 parse-remote) : plumbing;;
908 patch-id) : plumbing;; 702 patch-id) : plumbing;;
909 peek-remote) : plumbing;;
910 prune) : plumbing;; 703 prune) : plumbing;;
911 prune-packed) : plumbing;; 704 prune-packed) : plumbing;;
912 quiltimport) : import;; 705 quiltimport) : import;;
913 read-tree) : plumbing;; 706 read-tree) : plumbing;;
914 receive-pack) : plumbing;; 707 receive-pack) : plumbing;;
915 remote-*) : transport;; 708 remote-*) : transport;;
916 repo-config) : deprecated;;
917 rerere) : plumbing;; 709 rerere) : plumbing;;
918 rev-list) : plumbing;; 710 rev-list) : plumbing;;
919 rev-parse) : plumbing;; 711 rev-parse) : plumbing;;
@@ -926,7 +718,6 @@ __git_list_porcelain_commands ()
926 ssh-*) : transport;; 718 ssh-*) : transport;;
927 stripspace) : plumbing;; 719 stripspace) : plumbing;;
928 symbolic-ref) : plumbing;; 720 symbolic-ref) : plumbing;;
929 tar-tree) : deprecated;;
930 unpack-file) : plumbing;; 721 unpack-file) : plumbing;;
931 unpack-objects) : plumbing;; 722 unpack-objects) : plumbing;;
932 update-index) : plumbing;; 723 update-index) : plumbing;;
@@ -946,34 +737,28 @@ __git_list_porcelain_commands ()
946__git_porcelain_commands= 737__git_porcelain_commands=
947__git_compute_porcelain_commands () 738__git_compute_porcelain_commands ()
948{ 739{
949 __git_compute_all_commands 740 test -n "$__git_porcelain_commands" ||
950 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)} 741 __git_porcelain_commands=$(__git_list_porcelain_commands)
951} 742}
952 743
953__git_pretty_aliases () 744# Lists all set config variables starting with the given section prefix,
745# with the prefix removed.
746__git_get_config_variables ()
954{ 747{
955 local i IFS=$'\n' 748 local section="$1" i IFS=$'\n'
956 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do 749 for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do
957 case "$i" in 750 echo "${i#$section.}"
958 pretty.*)
959 i="${i#pretty.}"
960 echo "${i/ */}"
961 ;;
962 esac
963 done 751 done
964} 752}
965 753
754__git_pretty_aliases ()
755{
756 __git_get_config_variables "pretty"
757}
758
966__git_aliases () 759__git_aliases ()
967{ 760{
968 local i IFS=$'\n' 761 __git_get_config_variables "alias"
969 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
970 case "$i" in
971 alias.*)
972 i="${i#alias.}"
973 echo "${i/ */}"
974 ;;
975 esac
976 done
977} 762}
978 763
979# __git_aliased_command requires 1 argument 764# __git_aliased_command requires 1 argument
@@ -991,6 +776,10 @@ __git_aliased_command ()
991 -*) : option ;; 776 -*) : option ;;
992 *=*) : setting env ;; 777 *=*) : setting env ;;
993 git) : git itself ;; 778 git) : git itself ;;
779 \(\)) : skip parens of shell function definition ;;
780 {) : skip start of shell helper function ;;
781 :) : skip null command ;;
782 \'*) : skip opening quote after sh -c ;;
994 *) 783 *)
995 echo "$word" 784 echo "$word"
996 return 785 return
@@ -1010,7 +799,7 @@ __git_find_on_cmdline ()
1010 return 799 return
1011 fi 800 fi
1012 done 801 done
1013 c=$((++c)) 802 ((c++))
1014 done 803 done
1015} 804}
1016 805
@@ -1021,11 +810,48 @@ __git_has_doubledash ()
1021 if [ "--" = "${words[c]}" ]; then 810 if [ "--" = "${words[c]}" ]; then
1022 return 0 811 return 0
1023 fi 812 fi
1024 c=$((++c)) 813 ((c++))
1025 done 814 done
1026 return 1 815 return 1
1027} 816}
1028 817
818# Try to count non option arguments passed on the command line for the
819# specified git command.
820# When options are used, it is necessary to use the special -- option to
821# tell the implementation were non option arguments begin.
822# XXX this can not be improved, since options can appear everywhere, as
823# an example:
824# git mv x -n y
825#
826# __git_count_arguments requires 1 argument: the git command executed.
827__git_count_arguments ()
828{
829 local word i c=0
830
831 # Skip "git" (first argument)
832 for ((i=1; i < ${#words[@]}; i++)); do
833 word="${words[i]}"
834
835 case "$word" in
836 --)
837 # Good; we can assume that the following are only non
838 # option arguments.
839 ((c = 0))
840 ;;
841 "$1")
842 # Skip the specified git command and discard git
843 # main options
844 ((c = 0))
845 ;;
846 ?*)
847 ((c++))
848 ;;
849 esac
850 done
851
852 printf "%d" $c
853}
854
1029__git_whitespacelist="nowarn warn error error-all fix" 855__git_whitespacelist="nowarn warn error error-all fix"
1030 856
1031_git_am () 857_git_am ()
@@ -1049,7 +875,6 @@ _git_am ()
1049 " 875 "
1050 return 876 return
1051 esac 877 esac
1052 COMPREPLY=()
1053} 878}
1054 879
1055_git_apply () 880_git_apply ()
@@ -1069,13 +894,10 @@ _git_apply ()
1069 " 894 "
1070 return 895 return
1071 esac 896 esac
1072 COMPREPLY=()
1073} 897}
1074 898
1075_git_add () 899_git_add ()
1076{ 900{
1077 __git_has_doubledash && return
1078
1079 case "$cur" in 901 case "$cur" in
1080 --*) 902 --*)
1081 __gitcomp " 903 __gitcomp "
@@ -1084,7 +906,9 @@ _git_add ()
1084 " 906 "
1085 return 907 return
1086 esac 908 esac
1087 COMPREPLY=() 909
910 # XXX should we check for --update and --all options ?
911 __git_complete_index_file "--others --modified --directory --no-empty-directory"
1088} 912}
1089 913
1090_git_archive () 914_git_archive ()
@@ -1129,7 +953,6 @@ _git_bisect ()
1129 __gitcomp_nl "$(__git_refs)" 953 __gitcomp_nl "$(__git_refs)"
1130 ;; 954 ;;
1131 *) 955 *)
1132 COMPREPLY=()
1133 ;; 956 ;;
1134 esac 957 esac
1135} 958}
@@ -1144,15 +967,19 @@ _git_branch ()
1144 -d|-m) only_local_ref="y" ;; 967 -d|-m) only_local_ref="y" ;;
1145 -r) has_r="y" ;; 968 -r) has_r="y" ;;
1146 esac 969 esac
1147 c=$((++c)) 970 ((c++))
1148 done 971 done
1149 972
1150 case "$cur" in 973 case "$cur" in
974 --set-upstream-to=*)
975 __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}"
976 ;;
1151 --*) 977 --*)
1152 __gitcomp " 978 __gitcomp "
1153 --color --no-color --verbose --abbrev= --no-abbrev 979 --color --no-color --verbose --abbrev= --no-abbrev
1154 --track --no-track --contains --merged --no-merged 980 --track --no-track --contains --merged --no-merged
1155 --set-upstream 981 --set-upstream-to= --edit-description --list
982 --unset-upstream
1156 " 983 "
1157 ;; 984 ;;
1158 *) 985 *)
@@ -1213,14 +1040,19 @@ _git_checkout ()
1213 1040
1214_git_cherry () 1041_git_cherry ()
1215{ 1042{
1216 __gitcomp "$(__git_refs)" 1043 __gitcomp_nl "$(__git_refs)"
1217} 1044}
1218 1045
1219_git_cherry_pick () 1046_git_cherry_pick ()
1220{ 1047{
1048 local dir="$(__gitdir)"
1049 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1050 __gitcomp "--continue --quit --abort"
1051 return
1052 fi
1221 case "$cur" in 1053 case "$cur" in
1222 --*) 1054 --*)
1223 __gitcomp "--edit --no-commit" 1055 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1224 ;; 1056 ;;
1225 *) 1057 *)
1226 __gitcomp_nl "$(__git_refs)" 1058 __gitcomp_nl "$(__git_refs)"
@@ -1230,15 +1062,15 @@ _git_cherry_pick ()
1230 1062
1231_git_clean () 1063_git_clean ()
1232{ 1064{
1233 __git_has_doubledash && return
1234
1235 case "$cur" in 1065 case "$cur" in
1236 --*) 1066 --*)
1237 __gitcomp "--dry-run --quiet" 1067 __gitcomp "--dry-run --quiet"
1238 return 1068 return
1239 ;; 1069 ;;
1240 esac 1070 esac
1241 COMPREPLY=() 1071
1072 # XXX should we check for -x option ?
1073 __git_complete_index_file "--others --directory"
1242} 1074}
1243 1075
1244_git_clone () 1076_git_clone ()
@@ -1258,20 +1090,26 @@ _git_clone ()
1258 --upload-pack 1090 --upload-pack
1259 --template= 1091 --template=
1260 --depth 1092 --depth
1093 --single-branch
1094 --branch
1261 " 1095 "
1262 return 1096 return
1263 ;; 1097 ;;
1264 esac 1098 esac
1265 COMPREPLY=()
1266} 1099}
1267 1100
1268_git_commit () 1101_git_commit ()
1269{ 1102{
1270 __git_has_doubledash && return 1103 case "$prev" in
1104 -c|-C)
1105 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1106 return
1107 ;;
1108 esac
1271 1109
1272 case "$cur" in 1110 case "$cur" in
1273 --cleanup=*) 1111 --cleanup=*)
1274 __gitcomp "default strip verbatim whitespace 1112 __gitcomp "default scissors strip verbatim whitespace
1275 " "" "${cur##--cleanup=}" 1113 " "" "${cur##--cleanup=}"
1276 return 1114 return
1277 ;; 1115 ;;
@@ -1287,7 +1125,8 @@ _git_commit ()
1287 --*) 1125 --*)
1288 __gitcomp " 1126 __gitcomp "
1289 --all --author= --signoff --verify --no-verify 1127 --all --author= --signoff --verify --no-verify
1290 --edit --amend --include --only --interactive 1128 --edit --no-edit
1129 --amend --include --only --interactive
1291 --dry-run --reuse-message= --reedit-message= 1130 --dry-run --reuse-message= --reedit-message=
1292 --reset-author --file= --message= --template= 1131 --reset-author --file= --message= --template=
1293 --cleanup= --untracked-files --untracked-files= 1132 --cleanup= --untracked-files --untracked-files=
@@ -1295,7 +1134,13 @@ _git_commit ()
1295 " 1134 "
1296 return 1135 return
1297 esac 1136 esac
1298 COMPREPLY=() 1137
1138 if git rev-parse --verify --quiet HEAD >/dev/null; then
1139 __git_complete_index_file "--committable"
1140 else
1141 # This is the first commit
1142 __git_complete_index_file "--cached"
1143 fi
1299} 1144}
1300 1145
1301_git_describe () 1146_git_describe ()
@@ -1311,20 +1156,23 @@ _git_describe ()
1311 __gitcomp_nl "$(__git_refs)" 1156 __gitcomp_nl "$(__git_refs)"
1312} 1157}
1313 1158
1159__git_diff_algorithms="myers minimal patience histogram"
1160
1314__git_diff_common_options="--stat --numstat --shortstat --summary 1161__git_diff_common_options="--stat --numstat --shortstat --summary
1315 --patch-with-stat --name-only --name-status --color 1162 --patch-with-stat --name-only --name-status --color
1316 --no-color --color-words --no-renames --check 1163 --no-color --color-words --no-renames --check
1317 --full-index --binary --abbrev --diff-filter= 1164 --full-index --binary --abbrev --diff-filter=
1318 --find-copies-harder 1165 --find-copies-harder
1319 --text --ignore-space-at-eol --ignore-space-change 1166 --text --ignore-space-at-eol --ignore-space-change
1320 --ignore-all-space --exit-code --quiet --ext-diff 1167 --ignore-all-space --ignore-blank-lines --exit-code
1321 --no-ext-diff 1168 --quiet --ext-diff --no-ext-diff
1322 --no-prefix --src-prefix= --dst-prefix= 1169 --no-prefix --src-prefix= --dst-prefix=
1323 --inter-hunk-context= 1170 --inter-hunk-context=
1324 --patience 1171 --patience --histogram --minimal
1325 --raw 1172 --raw --word-diff --word-diff-regex=
1326 --dirstat --dirstat= --dirstat-by-file 1173 --dirstat --dirstat= --dirstat-by-file
1327 --dirstat-by-file= --cumulative 1174 --dirstat-by-file= --cumulative
1175 --diff-algorithm=
1328" 1176"
1329 1177
1330_git_diff () 1178_git_diff ()
@@ -1332,6 +1180,10 @@ _git_diff ()
1332 __git_has_doubledash && return 1180 __git_has_doubledash && return
1333 1181
1334 case "$cur" in 1182 case "$cur" in
1183 --diff-algorithm=*)
1184 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1185 return
1186 ;;
1335 --*) 1187 --*)
1336 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex 1188 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1337 --base --ours --theirs --no-index 1189 --base --ours --theirs --no-index
@@ -1343,8 +1195,8 @@ _git_diff ()
1343 __git_complete_revlist_file 1195 __git_complete_revlist_file
1344} 1196}
1345 1197
1346__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff 1198__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1347 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 1199 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare
1348" 1200"
1349 1201
1350_git_difftool () 1202_git_difftool ()
@@ -1365,17 +1217,23 @@ _git_difftool ()
1365 return 1217 return
1366 ;; 1218 ;;
1367 esac 1219 esac
1368 __git_complete_file 1220 __git_complete_revlist_file
1369} 1221}
1370 1222
1223__git_fetch_recurse_submodules="yes on-demand no"
1224
1371__git_fetch_options=" 1225__git_fetch_options="
1372 --quiet --verbose --append --upload-pack --force --keep --depth= 1226 --quiet --verbose --append --upload-pack --force --keep --depth=
1373 --tags --no-tags --all --prune --dry-run 1227 --tags --no-tags --all --prune --dry-run --recurse-submodules=
1374" 1228"
1375 1229
1376_git_fetch () 1230_git_fetch ()
1377{ 1231{
1378 case "$cur" in 1232 case "$cur" in
1233 --recurse-submodules=*)
1234 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1235 return
1236 ;;
1379 --*) 1237 --*)
1380 __gitcomp "$__git_fetch_options" 1238 __gitcomp "$__git_fetch_options"
1381 return 1239 return
@@ -1384,6 +1242,15 @@ _git_fetch ()
1384 __git_complete_remote_or_refspec 1242 __git_complete_remote_or_refspec
1385} 1243}
1386 1244
1245__git_format_patch_options="
1246 --stdout --attach --no-attach --thread --thread= --no-thread
1247 --numbered --start-number --numbered-files --keep-subject --signoff
1248 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1249 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1250 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1251 --output-directory --reroll-count --to= --quiet --notes
1252"
1253
1387_git_format_patch () 1254_git_format_patch ()
1388{ 1255{
1389 case "$cur" in 1256 case "$cur" in
@@ -1394,21 +1261,7 @@ _git_format_patch ()
1394 return 1261 return
1395 ;; 1262 ;;
1396 --*) 1263 --*)
1397 __gitcomp " 1264 __gitcomp "$__git_format_patch_options"
1398 --stdout --attach --no-attach --thread --thread=
1399 --output-directory
1400 --numbered --start-number
1401 --numbered-files
1402 --keep-subject
1403 --signoff --signature --no-signature
1404 --in-reply-to= --cc=
1405 --full-index --binary
1406 --not --all
1407 --cover-letter
1408 --no-prefix --src-prefix= --dst-prefix=
1409 --inline --suffix= --ignore-if-in-upstream
1410 --subject-prefix=
1411 "
1412 return 1265 return
1413 ;; 1266 ;;
1414 esac 1267 esac
@@ -1426,7 +1279,6 @@ _git_fsck ()
1426 return 1279 return
1427 ;; 1280 ;;
1428 esac 1281 esac
1429 COMPREPLY=()
1430} 1282}
1431 1283
1432_git_gc () 1284_git_gc ()
@@ -1437,7 +1289,6 @@ _git_gc ()
1437 return 1289 return
1438 ;; 1290 ;;
1439 esac 1291 esac
1440 COMPREPLY=()
1441} 1292}
1442 1293
1443_git_gitk () 1294_git_gitk ()
@@ -1446,7 +1297,7 @@ _git_gitk ()
1446} 1297}
1447 1298
1448__git_match_ctag() { 1299__git_match_ctag() {
1449 awk "/^${1////\\/}/ { print \$1 }" "$2" 1300 awk "/^${1//\//\\/}/ { print \$1 }" "$2"
1450} 1301}
1451 1302
1452_git_grep () 1303_git_grep ()
@@ -1461,6 +1312,7 @@ _git_grep ()
1461 --full-name --line-number 1312 --full-name --line-number
1462 --extended-regexp --basic-regexp --fixed-strings 1313 --extended-regexp --basic-regexp --fixed-strings
1463 --perl-regexp 1314 --perl-regexp
1315 --threads
1464 --files-with-matches --name-only 1316 --files-with-matches --name-only
1465 --files-without-match 1317 --files-without-match
1466 --max-depth 1318 --max-depth
@@ -1487,15 +1339,15 @@ _git_help ()
1487{ 1339{
1488 case "$cur" in 1340 case "$cur" in
1489 --*) 1341 --*)
1490 __gitcomp "--all --info --man --web" 1342 __gitcomp "--all --guides --info --man --web"
1491 return 1343 return
1492 ;; 1344 ;;
1493 esac 1345 esac
1494 __git_compute_all_commands 1346 __git_compute_all_commands
1495 __gitcomp "$__git_all_commands $(__git_aliases) 1347 __gitcomp "$__git_all_commands $(__git_aliases)
1496 attributes cli core-tutorial cvs-migration 1348 attributes cli core-tutorial cvs-migration
1497 diffcore gitk glossary hooks ignore modules 1349 diffcore everyday gitk glossary hooks ignore modules
1498 namespaces repository-layout tutorial tutorial-2 1350 namespaces repository-layout revisions tutorial tutorial-2
1499 workflows 1351 workflows
1500 " 1352 "
1501} 1353}
@@ -1514,13 +1366,10 @@ _git_init ()
1514 return 1366 return
1515 ;; 1367 ;;
1516 esac 1368 esac
1517 COMPREPLY=()
1518} 1369}
1519 1370
1520_git_ls_files () 1371_git_ls_files ()
1521{ 1372{
1522 __git_has_doubledash && return
1523
1524 case "$cur" in 1373 case "$cur" in
1525 --*) 1374 --*)
1526 __gitcomp "--cached --deleted --modified --others --ignored 1375 __gitcomp "--cached --deleted --modified --others --ignored
@@ -1533,7 +1382,10 @@ _git_ls_files ()
1533 return 1382 return
1534 ;; 1383 ;;
1535 esac 1384 esac
1536 COMPREPLY=() 1385
1386 # XXX ignore options like --modified and always suggest all cached
1387 # files.
1388 __git_complete_index_file "--cached"
1537} 1389}
1538 1390
1539_git_ls_remote () 1391_git_ls_remote ()
@@ -1566,7 +1418,7 @@ __git_log_gitk_options="
1566# Options that go well for log and shortlog (not gitk) 1418# Options that go well for log and shortlog (not gitk)
1567__git_log_shortlog_options=" 1419__git_log_shortlog_options="
1568 --author= --committer= --grep= 1420 --author= --committer= --grep=
1569 --all-match 1421 --all-match --invert-grep
1570" 1422"
1571 1423
1572__git_log_pretty_formats="oneline short medium full fuller email raw format:" 1424__git_log_pretty_formats="oneline short medium full fuller email raw format:"
@@ -1592,7 +1444,7 @@ _git_log ()
1592 return 1444 return
1593 ;; 1445 ;;
1594 --decorate=*) 1446 --decorate=*)
1595 __gitcomp "long short" "" "${cur##--decorate=}" 1447 __gitcomp "full short no" "" "${cur##--decorate=}"
1596 return 1448 return
1597 ;; 1449 ;;
1598 --*) 1450 --*)
@@ -1605,6 +1457,8 @@ _git_log ()
1605 --abbrev-commit --abbrev= 1457 --abbrev-commit --abbrev=
1606 --relative-date --date= 1458 --relative-date --date=
1607 --pretty= --format= --oneline 1459 --pretty= --format= --oneline
1460 --show-signature
1461 --cherry-mark
1608 --cherry-pick 1462 --cherry-pick
1609 --graph 1463 --graph
1610 --decorate --decorate= 1464 --decorate --decorate=
@@ -1620,9 +1474,12 @@ _git_log ()
1620 __git_complete_revlist 1474 __git_complete_revlist
1621} 1475}
1622 1476
1477# Common merge options shared by git-merge(1) and git-pull(1).
1623__git_merge_options=" 1478__git_merge_options="
1624 --no-commit --no-stat --log --no-log --squash --strategy 1479 --no-commit --no-stat --log --no-log --squash --strategy
1625 --commit --stat --no-squash --ff --no-ff --ff-only 1480 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1481 --verify-signatures --no-verify-signatures --gpg-sign
1482 --quiet --verbose --progress --no-progress
1626" 1483"
1627 1484
1628_git_merge () 1485_git_merge ()
@@ -1631,7 +1488,8 @@ _git_merge ()
1631 1488
1632 case "$cur" in 1489 case "$cur" in
1633 --*) 1490 --*)
1634 __gitcomp "$__git_merge_options" 1491 __gitcomp "$__git_merge_options
1492 --rerere-autoupdate --no-rerere-autoupdate --abort"
1635 return 1493 return
1636 esac 1494 esac
1637 __gitcomp_nl "$(__git_refs)" 1495 __gitcomp_nl "$(__git_refs)"
@@ -1649,11 +1507,16 @@ _git_mergetool ()
1649 return 1507 return
1650 ;; 1508 ;;
1651 esac 1509 esac
1652 COMPREPLY=()
1653} 1510}
1654 1511
1655_git_merge_base () 1512_git_merge_base ()
1656{ 1513{
1514 case "$cur" in
1515 --*)
1516 __gitcomp "--octopus --independent --is-ancestor --fork-point"
1517 return
1518 ;;
1519 esac
1657 __gitcomp_nl "$(__git_refs)" 1520 __gitcomp_nl "$(__git_refs)"
1658} 1521}
1659 1522
@@ -1665,7 +1528,14 @@ _git_mv ()
1665 return 1528 return
1666 ;; 1529 ;;
1667 esac 1530 esac
1668 COMPREPLY=() 1531
1532 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1533 # We need to show both cached and untracked files (including
1534 # empty directories) since this may not be the last argument.
1535 __git_complete_index_file "--cached --others --directory"
1536 else
1537 __git_complete_index_file "--cached"
1538 fi
1669} 1539}
1670 1540
1671_git_name_rev () 1541_git_name_rev ()
@@ -1683,7 +1553,7 @@ _git_notes ()
1683 __gitcomp '--ref' 1553 __gitcomp '--ref'
1684 ;; 1554 ;;
1685 ,*) 1555 ,*)
1686 case "${words[cword-1]}" in 1556 case "$prev" in
1687 --ref) 1557 --ref)
1688 __gitcomp_nl "$(__git_refs)" 1558 __gitcomp_nl "$(__git_refs)"
1689 ;; 1559 ;;
@@ -1709,7 +1579,7 @@ _git_notes ()
1709 prune,*) 1579 prune,*)
1710 ;; 1580 ;;
1711 *) 1581 *)
1712 case "${words[cword-1]}" in 1582 case "$prev" in
1713 -m|-F) 1583 -m|-F)
1714 ;; 1584 ;;
1715 *) 1585 *)
@@ -1725,6 +1595,10 @@ _git_pull ()
1725 __git_complete_strategy && return 1595 __git_complete_strategy && return
1726 1596
1727 case "$cur" in 1597 case "$cur" in
1598 --recurse-submodules=*)
1599 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1600 return
1601 ;;
1728 --*) 1602 --*)
1729 __gitcomp " 1603 __gitcomp "
1730 --rebase --no-rebase 1604 --rebase --no-rebase
@@ -1737,22 +1611,55 @@ _git_pull ()
1737 __git_complete_remote_or_refspec 1611 __git_complete_remote_or_refspec
1738} 1612}
1739 1613
1614__git_push_recurse_submodules="check on-demand"
1615
1616__git_complete_force_with_lease ()
1617{
1618 local cur_=$1
1619
1620 case "$cur_" in
1621 --*=)
1622 ;;
1623 *:*)
1624 __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}"
1625 ;;
1626 *)
1627 __gitcomp_nl "$(__git_refs)" "" "$cur_"
1628 ;;
1629 esac
1630}
1631
1740_git_push () 1632_git_push ()
1741{ 1633{
1742 case "$prev" in 1634 case "$prev" in
1743 --repo) 1635 --repo)
1744 __gitcomp_nl "$(__git_remotes)" 1636 __gitcomp_nl "$(__git_remotes)"
1745 return 1637 return
1638 ;;
1639 --recurse-submodules)
1640 __gitcomp "$__git_push_recurse_submodules"
1641 return
1642 ;;
1746 esac 1643 esac
1747 case "$cur" in 1644 case "$cur" in
1748 --repo=*) 1645 --repo=*)
1749 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}" 1646 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1750 return 1647 return
1751 ;; 1648 ;;
1649 --recurse-submodules=*)
1650 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
1651 return
1652 ;;
1653 --force-with-lease=*)
1654 __git_complete_force_with_lease "${cur##--force-with-lease=}"
1655 return
1656 ;;
1752 --*) 1657 --*)
1753 __gitcomp " 1658 __gitcomp "
1754 --all --mirror --tags --dry-run --force --verbose 1659 --all --mirror --tags --dry-run --force --verbose
1660 --quiet --prune --delete --follow-tags
1755 --receive-pack= --repo= --set-upstream 1661 --receive-pack= --repo= --set-upstream
1662 --force-with-lease --force-with-lease= --recurse-submodules=
1756 " 1663 "
1757 return 1664 return
1758 ;; 1665 ;;
@@ -1763,7 +1670,10 @@ _git_push ()
1763_git_rebase () 1670_git_rebase ()
1764{ 1671{
1765 local dir="$(__gitdir)" 1672 local dir="$(__gitdir)"
1766 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then 1673 if [ -f "$dir"/rebase-merge/interactive ]; then
1674 __gitcomp "--continue --skip --abort --edit-todo"
1675 return
1676 elif [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1767 __gitcomp "--continue --skip --abort" 1677 __gitcomp "--continue --skip --abort"
1768 return 1678 return
1769 fi 1679 fi
@@ -1779,7 +1689,12 @@ _git_rebase ()
1779 --preserve-merges --stat --no-stat 1689 --preserve-merges --stat --no-stat
1780 --committer-date-is-author-date --ignore-date 1690 --committer-date-is-author-date --ignore-date
1781 --ignore-whitespace --whitespace= 1691 --ignore-whitespace --whitespace=
1782 --autosquash 1692 --autosquash --no-autosquash
1693 --fork-point --no-fork-point
1694 --autostash --no-autostash
1695 --verify --no-verify
1696 --keep-empty --root --force-rebase --no-ff
1697 --exec
1783 " 1698 "
1784 1699
1785 return 1700 return
@@ -1804,6 +1719,15 @@ __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1804 1719
1805_git_send_email () 1720_git_send_email ()
1806{ 1721{
1722 case "$prev" in
1723 --to|--cc|--bcc|--from)
1724 __gitcomp "
1725 $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
1726 "
1727 return
1728 ;;
1729 esac
1730
1807 case "$cur" in 1731 case "$cur" in
1808 --confirm=*) 1732 --confirm=*)
1809 __gitcomp " 1733 __gitcomp "
@@ -1822,6 +1746,18 @@ _git_send_email ()
1822 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}" 1746 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1823 return 1747 return
1824 ;; 1748 ;;
1749 --thread=*)
1750 __gitcomp "
1751 deep shallow
1752 " "" "${cur##--thread=}"
1753 return
1754 ;;
1755 --to=*|--cc=*|--bcc=*|--from=*)
1756 __gitcomp "
1757 $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null)
1758 " "" "${cur#--*=}"
1759 return
1760 ;;
1825 --*) 1761 --*)
1826 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to 1762 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1827 --compose --confirm= --dry-run --envelope-sender 1763 --compose --confirm= --dry-run --envelope-sender
@@ -1831,11 +1767,12 @@ _git_send_email ()
1831 --signed-off-by-cc --smtp-pass --smtp-server 1767 --signed-off-by-cc --smtp-pass --smtp-server
1832 --smtp-server-port --smtp-encryption= --smtp-user 1768 --smtp-server-port --smtp-encryption= --smtp-user
1833 --subject --suppress-cc= --suppress-from --thread --to 1769 --subject --suppress-cc= --suppress-from --thread --to
1834 --validate --no-validate" 1770 --validate --no-validate
1771 $__git_format_patch_options"
1835 return 1772 return
1836 ;; 1773 ;;
1837 esac 1774 esac
1838 COMPREPLY=() 1775 __git_complete_revlist
1839} 1776}
1840 1777
1841_git_stage () 1778_git_stage ()
@@ -1849,7 +1786,7 @@ __git_config_get_set_variables ()
1849 while [ $c -gt 1 ]; do 1786 while [ $c -gt 1 ]; do
1850 word="${words[c]}" 1787 word="${words[c]}"
1851 case "$word" in 1788 case "$word" in
1852 --global|--system|--file=*) 1789 --system|--global|--local|--file=*)
1853 config_file="$word" 1790 config_file="$word"
1854 break 1791 break
1855 ;; 1792 ;;
@@ -1862,21 +1799,13 @@ __git_config_get_set_variables ()
1862 c=$((--c)) 1799 c=$((--c))
1863 done 1800 done
1864 1801
1865 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null | 1802 git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null
1866 while read -r line
1867 do
1868 case "$line" in
1869 *.*=*)
1870 echo "${line/=*/}"
1871 ;;
1872 esac
1873 done
1874} 1803}
1875 1804
1876_git_config () 1805_git_config ()
1877{ 1806{
1878 case "$prev" in 1807 case "$prev" in
1879 branch.*.remote) 1808 branch.*.remote|branch.*.pushremote)
1880 __gitcomp_nl "$(__git_remotes)" 1809 __gitcomp_nl "$(__git_remotes)"
1881 return 1810 return
1882 ;; 1811 ;;
@@ -1884,11 +1813,19 @@ _git_config ()
1884 __gitcomp_nl "$(__git_refs)" 1813 __gitcomp_nl "$(__git_refs)"
1885 return 1814 return
1886 ;; 1815 ;;
1816 branch.*.rebase)
1817 __gitcomp "false true preserve interactive"
1818 return
1819 ;;
1820 remote.pushdefault)
1821 __gitcomp_nl "$(__git_remotes)"
1822 return
1823 ;;
1887 remote.*.fetch) 1824 remote.*.fetch)
1888 local remote="${prev#remote.}" 1825 local remote="${prev#remote.}"
1889 remote="${remote%.fetch}" 1826 remote="${remote%.fetch}"
1890 if [ -z "$cur" ]; then 1827 if [ -z "$cur" ]; then
1891 COMPREPLY=("refs/heads/") 1828 __gitcomp_nl "refs/heads/" "" "" ""
1892 return 1829 return
1893 fi 1830 fi
1894 __gitcomp_nl "$(__git_refs_remotes "$remote")" 1831 __gitcomp_nl "$(__git_refs_remotes "$remote")"
@@ -1923,6 +1860,10 @@ _git_config ()
1923 " 1860 "
1924 return 1861 return
1925 ;; 1862 ;;
1863 diff.submodule)
1864 __gitcomp "log short"
1865 return
1866 ;;
1926 help.format) 1867 help.format)
1927 __gitcomp "man info web html" 1868 __gitcomp "man info web html"
1928 return 1869 return
@@ -1943,34 +1884,39 @@ _git_config ()
1943 __gitcomp "$__git_send_email_suppresscc_options" 1884 __gitcomp "$__git_send_email_suppresscc_options"
1944 return 1885 return
1945 ;; 1886 ;;
1887 sendemail.transferencoding)
1888 __gitcomp "7bit 8bit quoted-printable base64"
1889 return
1890 ;;
1946 --get|--get-all|--unset|--unset-all) 1891 --get|--get-all|--unset|--unset-all)
1947 __gitcomp_nl "$(__git_config_get_set_variables)" 1892 __gitcomp_nl "$(__git_config_get_set_variables)"
1948 return 1893 return
1949 ;; 1894 ;;
1950 *.*) 1895 *.*)
1951 COMPREPLY=()
1952 return 1896 return
1953 ;; 1897 ;;
1954 esac 1898 esac
1955 case "$cur" in 1899 case "$cur" in
1956 --*) 1900 --*)
1957 __gitcomp " 1901 __gitcomp "
1958 --global --system --file= 1902 --system --global --local --file=
1959 --list --replace-all 1903 --list --replace-all
1960 --get --get-all --get-regexp 1904 --get --get-all --get-regexp
1961 --add --unset --unset-all 1905 --add --unset --unset-all
1962 --remove-section --rename-section 1906 --remove-section --rename-section
1907 --name-only
1963 " 1908 "
1964 return 1909 return
1965 ;; 1910 ;;
1966 branch.*.*) 1911 branch.*.*)
1967 local pfx="${cur%.*}." cur_="${cur##*.}" 1912 local pfx="${cur%.*}." cur_="${cur##*.}"
1968 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_" 1913 __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
1969 return 1914 return
1970 ;; 1915 ;;
1971 branch.*) 1916 branch.*)
1972 local pfx="${cur%.*}." cur_="${cur#*.}" 1917 local pfx="${cur%.*}." cur_="${cur#*.}"
1973 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "." 1918 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1919 __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
1974 return 1920 return
1975 ;; 1921 ;;
1976 guitool.*.*) 1922 guitool.*.*)
@@ -2013,6 +1959,7 @@ _git_config ()
2013 remote.*) 1959 remote.*)
2014 local pfx="${cur%.*}." cur_="${cur#*.}" 1960 local pfx="${cur%.*}." cur_="${cur#*.}"
2015 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." 1961 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1962 __gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
2016 return 1963 return
2017 ;; 1964 ;;
2018 url.*.*) 1965 url.*.*)
@@ -2076,6 +2023,7 @@ _git_config ()
2076 color.status.changed 2023 color.status.changed
2077 color.status.header 2024 color.status.header
2078 color.status.nobranch 2025 color.status.nobranch
2026 color.status.unmerged
2079 color.status.untracked 2027 color.status.untracked
2080 color.status.updated 2028 color.status.updated
2081 color.ui 2029 color.ui
@@ -2096,7 +2044,6 @@ _git_config ()
2096 core.fileMode 2044 core.fileMode
2097 core.fsyncobjectfiles 2045 core.fsyncobjectfiles
2098 core.gitProxy 2046 core.gitProxy
2099 core.ignoreCygwinFSTricks
2100 core.ignoreStat 2047 core.ignoreStat
2101 core.ignorecase 2048 core.ignorecase
2102 core.logAllRefUpdates 2049 core.logAllRefUpdates
@@ -2114,6 +2061,7 @@ _git_config ()
2114 core.sparseCheckout 2061 core.sparseCheckout
2115 core.symlinks 2062 core.symlinks
2116 core.trustctime 2063 core.trustctime
2064 core.untrackedCache
2117 core.warnAmbiguousRefs 2065 core.warnAmbiguousRefs
2118 core.whitespace 2066 core.whitespace
2119 core.worktree 2067 core.worktree
@@ -2124,15 +2072,19 @@ _git_config ()
2124 diff.noprefix 2072 diff.noprefix
2125 diff.renameLimit 2073 diff.renameLimit
2126 diff.renames 2074 diff.renames
2075 diff.statGraphWidth
2076 diff.submodule
2127 diff.suppressBlankEmpty 2077 diff.suppressBlankEmpty
2128 diff.tool 2078 diff.tool
2129 diff.wordRegex 2079 diff.wordRegex
2080 diff.algorithm
2130 difftool. 2081 difftool.
2131 difftool.prompt 2082 difftool.prompt
2132 fetch.recurseSubmodules 2083 fetch.recurseSubmodules
2133 fetch.unpackLimit 2084 fetch.unpackLimit
2134 format.attach 2085 format.attach
2135 format.cc 2086 format.cc
2087 format.coverLetter
2136 format.headers 2088 format.headers
2137 format.numbered 2089 format.numbered
2138 format.pretty 2090 format.pretty
@@ -2184,6 +2136,8 @@ _git_config ()
2184 http.noEPSV 2136 http.noEPSV
2185 http.postBuffer 2137 http.postBuffer
2186 http.proxy 2138 http.proxy
2139 http.sslCipherList
2140 http.sslVersion
2187 http.sslCAInfo 2141 http.sslCAInfo
2188 http.sslCAPath 2142 http.sslCAPath
2189 http.sslCert 2143 http.sslCert
@@ -2247,6 +2201,7 @@ _git_config ()
2247 pull.octopus 2201 pull.octopus
2248 pull.twohead 2202 pull.twohead
2249 push.default 2203 push.default
2204 push.followTags
2250 rebase.autosquash 2205 rebase.autosquash
2251 rebase.stat 2206 rebase.stat
2252 receive.autogc 2207 receive.autogc
@@ -2257,6 +2212,7 @@ _git_config ()
2257 receive.fsckObjects 2212 receive.fsckObjects
2258 receive.unpackLimit 2213 receive.unpackLimit
2259 receive.updateserverinfo 2214 receive.updateserverinfo
2215 remote.pushdefault
2260 remotes. 2216 remotes.
2261 repack.usedeltabaseoffset 2217 repack.usedeltabaseoffset
2262 rerere.autoupdate 2218 rerere.autoupdate
@@ -2304,7 +2260,7 @@ _git_config ()
2304 2260
2305_git_remote () 2261_git_remote ()
2306{ 2262{
2307 local subcommands="add rename rm show prune update set-head" 2263 local subcommands="add rename remove set-head set-branches set-url show prune update"
2308 local subcommand="$(__git_find_on_cmdline "$subcommands")" 2264 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2309 if [ -z "$subcommand" ]; then 2265 if [ -z "$subcommand" ]; then
2310 __gitcomp "$subcommands" 2266 __gitcomp "$subcommands"
@@ -2312,19 +2268,16 @@ _git_remote ()
2312 fi 2268 fi
2313 2269
2314 case "$subcommand" in 2270 case "$subcommand" in
2315 rename|rm|show|prune) 2271 rename|remove|set-url|show|prune)
2316 __gitcomp_nl "$(__git_remotes)" 2272 __gitcomp_nl "$(__git_remotes)"
2317 ;; 2273 ;;
2274 set-head|set-branches)
2275 __git_complete_remote_or_refspec
2276 ;;
2318 update) 2277 update)
2319 local i c='' IFS=$'\n' 2278 __gitcomp "$(__git_get_config_variables "remotes")"
2320 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2321 i="${i#remotes.}"
2322 c="$c ${i/ */}"
2323 done
2324 __gitcomp "$c"
2325 ;; 2279 ;;
2326 *) 2280 *)
2327 COMPREPLY=()
2328 ;; 2281 ;;
2329 esac 2282 esac
2330} 2283}
@@ -2349,6 +2302,11 @@ _git_reset ()
2349 2302
2350_git_revert () 2303_git_revert ()
2351{ 2304{
2305 local dir="$(__gitdir)"
2306 if [ -f "$dir"/REVERT_HEAD ]; then
2307 __gitcomp "--continue --quit --abort"
2308 return
2309 fi
2352 case "$cur" in 2310 case "$cur" in
2353 --*) 2311 --*)
2354 __gitcomp "--edit --mainline --no-edit --no-commit --signoff" 2312 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
@@ -2360,15 +2318,14 @@ _git_revert ()
2360 2318
2361_git_rm () 2319_git_rm ()
2362{ 2320{
2363 __git_has_doubledash && return
2364
2365 case "$cur" in 2321 case "$cur" in
2366 --*) 2322 --*)
2367 __gitcomp "--cached --dry-run --ignore-unmatch --quiet" 2323 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2368 return 2324 return
2369 ;; 2325 ;;
2370 esac 2326 esac
2371 COMPREPLY=() 2327
2328 __git_complete_index_file "--cached"
2372} 2329}
2373 2330
2374_git_shortlog () 2331_git_shortlog ()
@@ -2398,14 +2355,19 @@ _git_show ()
2398 " "" "${cur#*=}" 2355 " "" "${cur#*=}"
2399 return 2356 return
2400 ;; 2357 ;;
2358 --diff-algorithm=*)
2359 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2360 return
2361 ;;
2401 --*) 2362 --*)
2402 __gitcomp "--pretty= --format= --abbrev-commit --oneline 2363 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2364 --show-signature
2403 $__git_diff_common_options 2365 $__git_diff_common_options
2404 " 2366 "
2405 return 2367 return
2406 ;; 2368 ;;
2407 esac 2369 esac
2408 __git_complete_file 2370 __git_complete_revlist_file
2409} 2371}
2410 2372
2411_git_show_branch () 2373_git_show_branch ()
@@ -2413,7 +2375,7 @@ _git_show_branch ()
2413 case "$cur" in 2375 case "$cur" in
2414 --*) 2376 --*)
2415 __gitcomp " 2377 __gitcomp "
2416 --all --remotes --topo-order --current --more= 2378 --all --remotes --topo-order --date-order --current --more=
2417 --list --independent --merge-base --no-name 2379 --list --independent --merge-base --no-name
2418 --color --no-color 2380 --color --no-color
2419 --sha1-name --sparse --topics --reflog 2381 --sha1-name --sparse --topics --reflog
@@ -2426,7 +2388,7 @@ _git_show_branch ()
2426 2388
2427_git_stash () 2389_git_stash ()
2428{ 2390{
2429 local save_opts='--keep-index --no-keep-index --quiet --patch' 2391 local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
2430 local subcommands='save list show apply clear drop pop create branch' 2392 local subcommands='save list show apply clear drop pop create branch'
2431 local subcommand="$(__git_find_on_cmdline "$subcommands")" 2393 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2432 if [ -z "$subcommand" ]; then 2394 if [ -z "$subcommand" ]; then
@@ -2437,8 +2399,6 @@ _git_stash ()
2437 *) 2399 *)
2438 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then 2400 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2439 __gitcomp "$subcommands" 2401 __gitcomp "$subcommands"
2440 else
2441 COMPREPLY=()
2442 fi 2402 fi
2443 ;; 2403 ;;
2444 esac 2404 esac
@@ -2450,15 +2410,24 @@ _git_stash ()
2450 apply,--*|pop,--*) 2410 apply,--*|pop,--*)
2451 __gitcomp "--index --quiet" 2411 __gitcomp "--index --quiet"
2452 ;; 2412 ;;
2453 show,--*|drop,--*|branch,--*) 2413 drop,--*)
2454 COMPREPLY=() 2414 __gitcomp "--quiet"
2415 ;;
2416 show,--*|branch,--*)
2417 ;;
2418 branch,*)
2419 if [ $cword -eq 3 ]; then
2420 __gitcomp_nl "$(__git_refs)";
2421 else
2422 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2423 | sed -n -e 's/:.*//p')"
2424 fi
2455 ;; 2425 ;;
2456 show,*|apply,*|drop,*|pop,*|branch,*) 2426 show,*|apply,*|drop,*|pop,*)
2457 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ 2427 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2458 | sed -n -e 's/:.*//p')" 2428 | sed -n -e 's/:.*//p')"
2459 ;; 2429 ;;
2460 *) 2430 *)
2461 COMPREPLY=()
2462 ;; 2431 ;;
2463 esac 2432 esac
2464 fi 2433 fi
@@ -2468,7 +2437,7 @@ _git_submodule ()
2468{ 2437{
2469 __git_has_doubledash && return 2438 __git_has_doubledash && return
2470 2439
2471 local subcommands="add status init update summary foreach sync" 2440 local subcommands="add status init deinit update summary foreach sync"
2472 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then 2441 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2473 case "$cur" in 2442 case "$cur" in
2474 --*) 2443 --*)
@@ -2500,7 +2469,7 @@ _git_svn ()
2500 --no-metadata --use-svm-props --use-svnsync-props 2469 --no-metadata --use-svm-props --use-svnsync-props
2501 --log-window-size= --no-checkout --quiet 2470 --log-window-size= --no-checkout --quiet
2502 --repack-flags --use-log-author --localtime 2471 --repack-flags --use-log-author --localtime
2503 --ignore-paths= $remote_opts 2472 --ignore-paths= --include-paths= $remote_opts
2504 " 2473 "
2505 local init_opts=" 2474 local init_opts="
2506 --template= --shared= --trunk= --tags= 2475 --template= --shared= --trunk= --tags=
@@ -2527,7 +2496,7 @@ _git_svn ()
2527 __gitcomp " 2496 __gitcomp "
2528 --merge --strategy= --verbose --dry-run 2497 --merge --strategy= --verbose --dry-run
2529 --fetch-all --no-rebase --commit-url 2498 --fetch-all --no-rebase --commit-url
2530 --revision $cmt_opts $fc_opts 2499 --revision --interactive $cmt_opts $fc_opts
2531 " 2500 "
2532 ;; 2501 ;;
2533 set-tree,--*) 2502 set-tree,--*)
@@ -2575,7 +2544,6 @@ _git_svn ()
2575 __gitcomp "--revision= --parent" 2544 __gitcomp "--revision= --parent"
2576 ;; 2545 ;;
2577 *) 2546 *)
2578 COMPREPLY=()
2579 ;; 2547 ;;
2580 esac 2548 esac
2581 fi 2549 fi
@@ -2595,24 +2563,31 @@ _git_tag ()
2595 f=1 2563 f=1
2596 ;; 2564 ;;
2597 esac 2565 esac
2598 c=$((++c)) 2566 ((c++))
2599 done 2567 done
2600 2568
2601 case "$prev" in 2569 case "$prev" in
2602 -m|-F) 2570 -m|-F)
2603 COMPREPLY=()
2604 ;; 2571 ;;
2605 -*|tag) 2572 -*|tag)
2606 if [ $f = 1 ]; then 2573 if [ $f = 1 ]; then
2607 __gitcomp_nl "$(__git_tags)" 2574 __gitcomp_nl "$(__git_tags)"
2608 else
2609 COMPREPLY=()
2610 fi 2575 fi
2611 ;; 2576 ;;
2612 *) 2577 *)
2613 __gitcomp_nl "$(__git_refs)" 2578 __gitcomp_nl "$(__git_refs)"
2614 ;; 2579 ;;
2615 esac 2580 esac
2581
2582 case "$cur" in
2583 --*)
2584 __gitcomp "
2585 --list --delete --verify --annotate --message --file
2586 --sign --cleanup --local-user --force --column --sort
2587 --contains --points-at
2588 "
2589 ;;
2590 esac
2616} 2591}
2617 2592
2618_git_whatchanged () 2593_git_whatchanged ()
@@ -2620,31 +2595,22 @@ _git_whatchanged ()
2620 _git_log 2595 _git_log
2621} 2596}
2622 2597
2623_git () 2598__git_main ()
2624{ 2599{
2625 local i c=1 command __git_dir 2600 local i c=1 command __git_dir
2626 2601
2627 if [[ -n ${ZSH_VERSION-} ]]; then
2628 emulate -L bash
2629 setopt KSH_TYPESET
2630
2631 # workaround zsh's bug that leaves 'words' as a special
2632 # variable in versions < 4.3.12
2633 typeset -h words
2634 fi
2635
2636 local cur words cword prev
2637 _get_comp_words_by_ref -n =: cur words cword prev
2638 while [ $c -lt $cword ]; do 2602 while [ $c -lt $cword ]; do
2639 i="${words[c]}" 2603 i="${words[c]}"
2640 case "$i" in 2604 case "$i" in
2641 --git-dir=*) __git_dir="${i#--git-dir=}" ;; 2605 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2606 --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
2642 --bare) __git_dir="." ;; 2607 --bare) __git_dir="." ;;
2643 --version|-p|--paginate) ;;
2644 --help) command="help"; break ;; 2608 --help) command="help"; break ;;
2609 -c|--work-tree|--namespace) ((c++)) ;;
2610 -*) ;;
2645 *) command="$i"; break ;; 2611 *) command="$i"; break ;;
2646 esac 2612 esac
2647 c=$((++c)) 2613 ((c++))
2648 done 2614 done
2649 2615
2650 if [ -z "$command" ]; then 2616 if [ -z "$command" ]; then
@@ -2656,9 +2622,13 @@ _git ()
2656 --bare 2622 --bare
2657 --version 2623 --version
2658 --exec-path 2624 --exec-path
2625 --exec-path=
2659 --html-path 2626 --html-path
2627 --man-path
2628 --info-path
2660 --work-tree= 2629 --work-tree=
2661 --namespace= 2630 --namespace=
2631 --no-replace-objects
2662 --help 2632 --help
2663 " 2633 "
2664 ;; 2634 ;;
@@ -2673,25 +2643,14 @@ _git ()
2673 2643
2674 local expansion=$(__git_aliased_command "$command") 2644 local expansion=$(__git_aliased_command "$command")
2675 if [ -n "$expansion" ]; then 2645 if [ -n "$expansion" ]; then
2646 words[1]=$expansion
2676 completion_func="_git_${expansion//-/_}" 2647 completion_func="_git_${expansion//-/_}"
2677 declare -f $completion_func >/dev/null && $completion_func 2648 declare -f $completion_func >/dev/null && $completion_func
2678 fi 2649 fi
2679} 2650}
2680 2651
2681_gitk () 2652__gitk_main ()
2682{ 2653{
2683 if [[ -n ${ZSH_VERSION-} ]]; then
2684 emulate -L bash
2685 setopt KSH_TYPESET
2686
2687 # workaround zsh's bug that leaves 'words' as a special
2688 # variable in versions < 4.3.12
2689 typeset -h words
2690 fi
2691
2692 local cur words cword prev
2693 _get_comp_words_by_ref -n =: cur words cword prev
2694
2695 __git_has_doubledash && return 2654 __git_has_doubledash && return
2696 2655
2697 local g="$(__gitdir)" 2656 local g="$(__gitdir)"
@@ -2712,46 +2671,107 @@ _gitk ()
2712 __git_complete_revlist 2671 __git_complete_revlist
2713} 2672}
2714 2673
2715complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \ 2674if [[ -n ${ZSH_VERSION-} ]]; then
2716 || complete -o default -o nospace -F _git git 2675 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2717complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2718 || complete -o default -o nospace -F _gitk gitk
2719 2676
2720# The following are necessary only for Cygwin, and only are needed 2677 autoload -U +X compinit && compinit
2721# when the user has tab-completed the executable name and consequently
2722# included the '.exe' suffix.
2723#
2724if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2725complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2726 || complete -o default -o nospace -F _git git.exe
2727fi
2728 2678
2729if [[ -n ${ZSH_VERSION-} ]]; then 2679 __gitcomp ()
2730 __git_shopt () { 2680 {
2731 local option 2681 emulate -L zsh
2732 if [ $# -ne 2 ]; then 2682
2733 echo "USAGE: $0 (-q|-s|-u) <option>" >&2 2683 local cur_="${3-$cur}"
2734 return 1 2684
2735 fi 2685 case "$cur_" in
2736 case "$2" in 2686 --*=)
2737 nullglob)
2738 option="$2"
2739 ;; 2687 ;;
2740 *) 2688 *)
2741 echo "$0: invalid option: $2" >&2 2689 local c IFS=$' \t\n'
2742 return 1 2690 local -a array
2743 esac 2691 for c in ${=1}; do
2744 case "$1" in 2692 c="$c${4-}"
2745 -q) setopt | grep -q "$option" ;; 2693 case $c in
2746 -u) unsetopt "$option" ;; 2694 --*=*|*.) ;;
2747 -s) setopt "$option" ;; 2695 *) c="$c " ;;
2748 *) 2696 esac
2749 echo "$0: invalid flag: $1" >&2 2697 array[${#array[@]}+1]="$c"
2750 return 1 2698 done
2699 compset -P '*[=:]'
2700 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2701 ;;
2751 esac 2702 esac
2752 } 2703 }
2753else 2704
2754 __git_shopt () { 2705 __gitcomp_nl ()
2755 shopt "$@" 2706 {
2707 emulate -L zsh
2708
2709 local IFS=$'\n'
2710 compset -P '*[=:]'
2711 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2712 }
2713
2714 __gitcomp_file ()
2715 {
2716 emulate -L zsh
2717
2718 local IFS=$'\n'
2719 compset -P '*[=:]'
2720 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2721 }
2722
2723 _git ()
2724 {
2725 local _ret=1 cur cword prev
2726 cur=${words[CURRENT]}
2727 prev=${words[CURRENT-1]}
2728 let cword=CURRENT-1
2729 emulate ksh -c __${service}_main
2730 let _ret && _default && _ret=0
2731 return _ret
2756 } 2732 }
2733
2734 compdef _git git gitk
2735 return
2736fi
2737
2738__git_func_wrap ()
2739{
2740 local cur words cword prev
2741 _get_comp_words_by_ref -n =: cur words cword prev
2742 $1
2743}
2744
2745# Setup completion for certain functions defined above by setting common
2746# variables and workarounds.
2747# This is NOT a public function; use at your own risk.
2748__git_complete ()
2749{
2750 local wrapper="__git_wrap${2}"
2751 eval "$wrapper () { __git_func_wrap $2 ; }"
2752 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2753 || complete -o default -o nospace -F $wrapper $1
2754}
2755
2756# wrapper for backwards compatibility
2757_git ()
2758{
2759 __git_wrap__git_main
2760}
2761
2762# wrapper for backwards compatibility
2763_gitk ()
2764{
2765 __git_wrap__gitk_main
2766}
2767
2768__git_complete git __git_main
2769__git_complete gitk __gitk_main
2770
2771# The following are necessary only for Cygwin, and only are needed
2772# when the user has tab-completed the executable name and consequently
2773# included the '.exe' suffix.
2774#
2775if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2776__git_complete git.exe __git_main
2757fi 2777fi