]> git.ipfire.org Git - thirdparty/git.git/blob - contrib/completion/git-completion.bash
completion: Support the DWIM mode for git checkout
[thirdparty/git.git] / contrib / completion / git-completion.bash
1 #!bash
2 #
3 # bash completion support for core Git.
4 #
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
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
16 # *) common --long-options
17 #
18 # To use these routines:
19 #
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 # 2) Added the following line to your .bashrc:
22 # source ~/.git-completion.sh
23 #
24 # 3) Consider changing your PS1 to also show the current branch:
25 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
26 #
27 # The argument to __git_ps1 will be displayed only if you
28 # are currently in a git repository. The %s token will be
29 # the name of the current branch.
30 #
31 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
32 # value, unstaged (*) and staged (+) changes will be shown next
33 # to the branch name. You can configure this per-repository
34 # with the bash.showDirtyState variable, which defaults to true
35 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
36 #
37 # You can also see if currently something is stashed, by setting
38 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
39 # then a '$' will be shown next to the branch name.
40 #
41 # If you would like to see if there're untracked files, then you can
42 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
43 # untracked files, then a '%' will be shown next to the branch name.
44 #
45 # If you would like to see the difference between HEAD and its
46 # upstream, set GIT_PS1_SHOWUPSTREAM="auto". A "<" indicates
47 # you are behind, ">" indicates you are ahead, and "<>"
48 # indicates you have diverged. You can further control
49 # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated
50 # list of values:
51 # verbose show number of commits ahead/behind (+/-) upstream
52 # legacy don't use the '--count' option available in recent
53 # versions of git-rev-list
54 # git always compare HEAD to @{upstream}
55 # svn always compare HEAD to your SVN upstream
56 # By default, __git_ps1 will compare HEAD to your SVN upstream
57 # if it can find one, or @{upstream} otherwise. Once you have
58 # set GIT_PS1_SHOWUPSTREAM, you can override it on a
59 # per-repository basis by setting the bash.showUpstream config
60 # variable.
61 #
62 #
63 # To submit patches:
64 #
65 # *) Read Documentation/SubmittingPatches
66 # *) Send all patches to the current maintainer:
67 #
68 # "Shawn O. Pearce" <spearce@spearce.org>
69 #
70 # *) Always CC the Git mailing list:
71 #
72 # git@vger.kernel.org
73 #
74
75 case "$COMP_WORDBREAKS" in
76 *:*) : great ;;
77 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
78 esac
79
80 # __gitdir accepts 0 or 1 arguments (i.e., location)
81 # returns location of .git repo
82 __gitdir ()
83 {
84 if [ -z "${1-}" ]; then
85 if [ -n "${__git_dir-}" ]; then
86 echo "$__git_dir"
87 elif [ -d .git ]; then
88 echo .git
89 else
90 git rev-parse --git-dir 2>/dev/null
91 fi
92 elif [ -d "$1/.git" ]; then
93 echo "$1/.git"
94 else
95 echo "$1"
96 fi
97 }
98
99 # stores the divergence from upstream in $p
100 # used by GIT_PS1_SHOWUPSTREAM
101 __git_ps1_show_upstream ()
102 {
103 local key value
104 local svn_remote=() svn_url_pattern count n
105 local upstream=git legacy="" verbose=""
106
107 # get some config options from git-config
108 while read key value; do
109 case "$key" in
110 bash.showupstream)
111 GIT_PS1_SHOWUPSTREAM="$value"
112 if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
113 p=""
114 return
115 fi
116 ;;
117 svn-remote.*.url)
118 svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
119 svn_url_pattern+="\\|$value"
120 upstream=svn+git # default upstream is SVN if available, else git
121 ;;
122 esac
123 done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
124
125 # parse configuration values
126 for option in ${GIT_PS1_SHOWUPSTREAM}; do
127 case "$option" in
128 git|svn) upstream="$option" ;;
129 verbose) verbose=1 ;;
130 legacy) legacy=1 ;;
131 esac
132 done
133
134 # Find our upstream
135 case "$upstream" in
136 git) upstream="@{upstream}" ;;
137 svn*)
138 # get the upstream from the "git-svn-id: ..." in a commit message
139 # (git-svn uses essentially the same procedure internally)
140 local svn_upstream=($(git log --first-parent -1 \
141 --grep="^git-svn-id: \(${svn_url_pattern:2}\)" 2>/dev/null))
142 if [[ 0 -ne ${#svn_upstream[@]} ]]; then
143 svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}
144 svn_upstream=${svn_upstream%@*}
145 for ((n=1; "$n" <= "${#svn_remote[@]}"; ++n)); do
146 svn_upstream=${svn_upstream#${svn_remote[$n]}}
147 done
148
149 if [[ -z "$svn_upstream" ]]; then
150 # default branch name for checkouts with no layout:
151 upstream=${GIT_SVN_ID:-git-svn}
152 else
153 upstream=${svn_upstream#/}
154 fi
155 elif [[ "svn+git" = "$upstream" ]]; then
156 upstream="@{upstream}"
157 fi
158 ;;
159 esac
160
161 # Find how many commits we are ahead/behind our upstream
162 if [[ -z "$legacy" ]]; then
163 count="$(git rev-list --count --left-right \
164 "$upstream"...HEAD 2>/dev/null)"
165 else
166 # produce equivalent output to --count for older versions of git
167 local commits
168 if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
169 then
170 local commit behind=0 ahead=0
171 for commit in $commits
172 do
173 case "$commit" in
174 "<"*) let ++behind
175 ;;
176 *) let ++ahead
177 ;;
178 esac
179 done
180 count="$behind $ahead"
181 else
182 count=""
183 fi
184 fi
185
186 # calculate the result
187 if [[ -z "$verbose" ]]; then
188 case "$count" in
189 "") # no upstream
190 p="" ;;
191 "0 0") # equal to upstream
192 p="=" ;;
193 "0 "*) # ahead of upstream
194 p=">" ;;
195 *" 0") # behind upstream
196 p="<" ;;
197 *) # diverged from upstream
198 p="<>" ;;
199 esac
200 else
201 case "$count" in
202 "") # no upstream
203 p="" ;;
204 "0 0") # equal to upstream
205 p=" u=" ;;
206 "0 "*) # ahead of upstream
207 p=" u+${count#0 }" ;;
208 *" 0") # behind upstream
209 p=" u-${count% 0}" ;;
210 *) # diverged from upstream
211 p=" u+${count#* }-${count% *}" ;;
212 esac
213 fi
214
215 }
216
217
218 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
219 # returns text to add to bash PS1 prompt (includes branch name)
220 __git_ps1 ()
221 {
222 local g="$(__gitdir)"
223 if [ -n "$g" ]; then
224 local r=""
225 local b=""
226 if [ -f "$g/rebase-merge/interactive" ]; then
227 r="|REBASE-i"
228 b="$(cat "$g/rebase-merge/head-name")"
229 elif [ -d "$g/rebase-merge" ]; then
230 r="|REBASE-m"
231 b="$(cat "$g/rebase-merge/head-name")"
232 else
233 if [ -d "$g/rebase-apply" ]; then
234 if [ -f "$g/rebase-apply/rebasing" ]; then
235 r="|REBASE"
236 elif [ -f "$g/rebase-apply/applying" ]; then
237 r="|AM"
238 else
239 r="|AM/REBASE"
240 fi
241 elif [ -f "$g/MERGE_HEAD" ]; then
242 r="|MERGING"
243 elif [ -f "$g/BISECT_LOG" ]; then
244 r="|BISECTING"
245 fi
246
247 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
248
249 b="$(
250 case "${GIT_PS1_DESCRIBE_STYLE-}" in
251 (contains)
252 git describe --contains HEAD ;;
253 (branch)
254 git describe --contains --all HEAD ;;
255 (describe)
256 git describe HEAD ;;
257 (* | default)
258 git describe --exact-match HEAD ;;
259 esac 2>/dev/null)" ||
260
261 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
262 b="unknown"
263 b="($b)"
264 }
265 fi
266
267 local w=""
268 local i=""
269 local s=""
270 local u=""
271 local c=""
272 local p=""
273
274 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
275 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
276 c="BARE:"
277 else
278 b="GIT_DIR!"
279 fi
280 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
281 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
282 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
283 git diff --no-ext-diff --quiet --exit-code || w="*"
284 if git rev-parse --quiet --verify HEAD >/dev/null; then
285 git diff-index --cached --quiet HEAD -- || i="+"
286 else
287 i="#"
288 fi
289 fi
290 fi
291 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
292 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
293 fi
294
295 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
296 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
297 u="%"
298 fi
299 fi
300
301 if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
302 __git_ps1_show_upstream
303 fi
304 fi
305
306 local f="$w$i$s$u"
307 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p"
308 fi
309 }
310
311 # __gitcomp_1 requires 2 arguments
312 __gitcomp_1 ()
313 {
314 local c IFS=' '$'\t'$'\n'
315 for c in $1; do
316 case "$c$2" in
317 --*=*) printf %s$'\n' "$c$2" ;;
318 *.) printf %s$'\n' "$c$2" ;;
319 *) printf %s$'\n' "$c$2 " ;;
320 esac
321 done
322 }
323
324 # __gitcomp accepts 1, 2, 3, or 4 arguments
325 # generates completion reply with compgen
326 __gitcomp ()
327 {
328 local cur="${COMP_WORDS[COMP_CWORD]}"
329 if [ $# -gt 2 ]; then
330 cur="$3"
331 fi
332 case "$cur" in
333 --*=)
334 COMPREPLY=()
335 ;;
336 *)
337 local IFS=$'\n'
338 COMPREPLY=($(compgen -P "${2-}" \
339 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
340 -- "$cur"))
341 ;;
342 esac
343 }
344
345 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
346 __git_heads ()
347 {
348 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
349 if [ -d "$dir" ]; then
350 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
351 refs/heads
352 return
353 fi
354 for i in $(git ls-remote "${1-}" 2>/dev/null); do
355 case "$is_hash,$i" in
356 y,*) is_hash=n ;;
357 n,*^{}) is_hash=y ;;
358 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
359 n,*) is_hash=y; echo "$i" ;;
360 esac
361 done
362 }
363
364 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
365 __git_tags ()
366 {
367 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
368 if [ -d "$dir" ]; then
369 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
370 refs/tags
371 return
372 fi
373 for i in $(git ls-remote "${1-}" 2>/dev/null); do
374 case "$is_hash,$i" in
375 y,*) is_hash=n ;;
376 n,*^{}) is_hash=y ;;
377 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
378 n,*) is_hash=y; echo "$i" ;;
379 esac
380 done
381 }
382
383 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
384 # presence of 2nd argument means use the guess heuristic employed
385 # by checkout for tracking branches
386 __git_refs ()
387 {
388 local i is_hash=y dir="$(__gitdir "${1-}")" track="${2-}"
389 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
390 if [ -d "$dir" ]; then
391 case "$cur" in
392 refs|refs/*)
393 format="refname"
394 refs="${cur%/*}"
395 track=""
396 ;;
397 *)
398 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
399 if [ -e "$dir/$i" ]; then echo $i; fi
400 done
401 format="refname:short"
402 refs="refs/tags refs/heads refs/remotes"
403 ;;
404 esac
405 git --git-dir="$dir" for-each-ref --format="%($format)" \
406 $refs
407 if [ -n "$track" ]; then
408 # employ the heuristic used by git checkout
409 # Try to find a remote branch that matches the completion word
410 # but only output if the branch name is unique
411 local ref entry
412 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
413 "refs/remotes/" | \
414 while read entry; do
415 eval "$entry"
416 ref="${ref#*/}"
417 if [[ "$ref" == "$cur"* ]]; then
418 echo "$ref"
419 fi
420 done | uniq -u
421 fi
422 return
423 fi
424 for i in $(git ls-remote "$dir" 2>/dev/null); do
425 case "$is_hash,$i" in
426 y,*) is_hash=n ;;
427 n,*^{}) is_hash=y ;;
428 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
429 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
430 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
431 n,*) is_hash=y; echo "$i" ;;
432 esac
433 done
434 }
435
436 # __git_refs2 requires 1 argument (to pass to __git_refs)
437 __git_refs2 ()
438 {
439 local i
440 for i in $(__git_refs "$1"); do
441 echo "$i:$i"
442 done
443 }
444
445 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
446 __git_refs_remotes ()
447 {
448 local cmd i is_hash=y
449 for i in $(git ls-remote "$1" 2>/dev/null); do
450 case "$is_hash,$i" in
451 n,refs/heads/*)
452 is_hash=y
453 echo "$i:refs/remotes/$1/${i#refs/heads/}"
454 ;;
455 y,*) is_hash=n ;;
456 n,*^{}) is_hash=y ;;
457 n,refs/tags/*) is_hash=y;;
458 n,*) is_hash=y; ;;
459 esac
460 done
461 }
462
463 __git_remotes ()
464 {
465 local i ngoff IFS=$'\n' d="$(__gitdir)"
466 shopt -q nullglob || ngoff=1
467 shopt -s nullglob
468 for i in "$d/remotes"/*; do
469 echo ${i#$d/remotes/}
470 done
471 [ "$ngoff" ] && shopt -u nullglob
472 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
473 i="${i#remote.}"
474 echo "${i/.url*/}"
475 done
476 }
477
478 __git_list_merge_strategies ()
479 {
480 git merge -s help 2>&1 |
481 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
482 s/\.$//
483 s/.*://
484 s/^[ ]*//
485 s/[ ]*$//
486 p
487 }'
488 }
489
490 __git_merge_strategies=
491 # 'git merge -s help' (and thus detection of the merge strategy
492 # list) fails, unfortunately, if run outside of any git working
493 # tree. __git_merge_strategies is set to the empty string in
494 # that case, and the detection will be repeated the next time it
495 # is needed.
496 __git_compute_merge_strategies ()
497 {
498 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
499 }
500
501 __git_complete_file ()
502 {
503 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
504 case "$cur" in
505 ?*:*)
506 ref="${cur%%:*}"
507 cur="${cur#*:}"
508 case "$cur" in
509 ?*/*)
510 pfx="${cur%/*}"
511 cur="${cur##*/}"
512 ls="$ref:$pfx"
513 pfx="$pfx/"
514 ;;
515 *)
516 ls="$ref"
517 ;;
518 esac
519
520 case "$COMP_WORDBREAKS" in
521 *:*) : great ;;
522 *) pfx="$ref:$pfx" ;;
523 esac
524
525 local IFS=$'\n'
526 COMPREPLY=($(compgen -P "$pfx" \
527 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
528 | sed '/^100... blob /{
529 s,^.* ,,
530 s,$, ,
531 }
532 /^120000 blob /{
533 s,^.* ,,
534 s,$, ,
535 }
536 /^040000 tree /{
537 s,^.* ,,
538 s,$,/,
539 }
540 s/^.* //')" \
541 -- "$cur"))
542 ;;
543 *)
544 __gitcomp "$(__git_refs)"
545 ;;
546 esac
547 }
548
549 __git_complete_revlist ()
550 {
551 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
552 case "$cur" in
553 *...*)
554 pfx="${cur%...*}..."
555 cur="${cur#*...}"
556 __gitcomp "$(__git_refs)" "$pfx" "$cur"
557 ;;
558 *..*)
559 pfx="${cur%..*}.."
560 cur="${cur#*..}"
561 __gitcomp "$(__git_refs)" "$pfx" "$cur"
562 ;;
563 *)
564 __gitcomp "$(__git_refs)"
565 ;;
566 esac
567 }
568
569 __git_complete_remote_or_refspec ()
570 {
571 local cmd="${COMP_WORDS[1]}"
572 local cur="${COMP_WORDS[COMP_CWORD]}"
573 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
574 while [ $c -lt $COMP_CWORD ]; do
575 i="${COMP_WORDS[c]}"
576 case "$i" in
577 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
578 --all)
579 case "$cmd" in
580 push) no_complete_refspec=1 ;;
581 fetch)
582 COMPREPLY=()
583 return
584 ;;
585 *) ;;
586 esac
587 ;;
588 -*) ;;
589 *) remote="$i"; break ;;
590 esac
591 c=$((++c))
592 done
593 if [ -z "$remote" ]; then
594 __gitcomp "$(__git_remotes)"
595 return
596 fi
597 if [ $no_complete_refspec = 1 ]; then
598 COMPREPLY=()
599 return
600 fi
601 [ "$remote" = "." ] && remote=
602 case "$cur" in
603 *:*)
604 case "$COMP_WORDBREAKS" in
605 *:*) : great ;;
606 *) pfx="${cur%%:*}:" ;;
607 esac
608 cur="${cur#*:}"
609 lhs=0
610 ;;
611 +*)
612 pfx="+"
613 cur="${cur#+}"
614 ;;
615 esac
616 case "$cmd" in
617 fetch)
618 if [ $lhs = 1 ]; then
619 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
620 else
621 __gitcomp "$(__git_refs)" "$pfx" "$cur"
622 fi
623 ;;
624 pull)
625 if [ $lhs = 1 ]; then
626 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
627 else
628 __gitcomp "$(__git_refs)" "$pfx" "$cur"
629 fi
630 ;;
631 push)
632 if [ $lhs = 1 ]; then
633 __gitcomp "$(__git_refs)" "$pfx" "$cur"
634 else
635 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
636 fi
637 ;;
638 esac
639 }
640
641 __git_complete_strategy ()
642 {
643 __git_compute_merge_strategies
644 case "${COMP_WORDS[COMP_CWORD-1]}" in
645 -s|--strategy)
646 __gitcomp "$__git_merge_strategies"
647 return 0
648 esac
649 local cur="${COMP_WORDS[COMP_CWORD]}"
650 case "$cur" in
651 --strategy=*)
652 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
653 return 0
654 ;;
655 esac
656 return 1
657 }
658
659 __git_list_all_commands ()
660 {
661 local i IFS=" "$'\n'
662 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
663 do
664 case $i in
665 *--*) : helper pattern;;
666 *) echo $i;;
667 esac
668 done
669 }
670
671 __git_all_commands=
672 __git_compute_all_commands ()
673 {
674 : ${__git_all_commands:=$(__git_list_all_commands)}
675 }
676
677 __git_list_porcelain_commands ()
678 {
679 local i IFS=" "$'\n'
680 __git_compute_all_commands
681 for i in "help" $__git_all_commands
682 do
683 case $i in
684 *--*) : helper pattern;;
685 applymbox) : ask gittus;;
686 applypatch) : ask gittus;;
687 archimport) : import;;
688 cat-file) : plumbing;;
689 check-attr) : plumbing;;
690 check-ref-format) : plumbing;;
691 checkout-index) : plumbing;;
692 commit-tree) : plumbing;;
693 count-objects) : infrequent;;
694 cvsexportcommit) : export;;
695 cvsimport) : import;;
696 cvsserver) : daemon;;
697 daemon) : daemon;;
698 diff-files) : plumbing;;
699 diff-index) : plumbing;;
700 diff-tree) : plumbing;;
701 fast-import) : import;;
702 fast-export) : export;;
703 fsck-objects) : plumbing;;
704 fetch-pack) : plumbing;;
705 fmt-merge-msg) : plumbing;;
706 for-each-ref) : plumbing;;
707 hash-object) : plumbing;;
708 http-*) : transport;;
709 index-pack) : plumbing;;
710 init-db) : deprecated;;
711 local-fetch) : plumbing;;
712 lost-found) : infrequent;;
713 ls-files) : plumbing;;
714 ls-remote) : plumbing;;
715 ls-tree) : plumbing;;
716 mailinfo) : plumbing;;
717 mailsplit) : plumbing;;
718 merge-*) : plumbing;;
719 mktree) : plumbing;;
720 mktag) : plumbing;;
721 pack-objects) : plumbing;;
722 pack-redundant) : plumbing;;
723 pack-refs) : plumbing;;
724 parse-remote) : plumbing;;
725 patch-id) : plumbing;;
726 peek-remote) : plumbing;;
727 prune) : plumbing;;
728 prune-packed) : plumbing;;
729 quiltimport) : import;;
730 read-tree) : plumbing;;
731 receive-pack) : plumbing;;
732 reflog) : plumbing;;
733 remote-*) : transport;;
734 repo-config) : deprecated;;
735 rerere) : plumbing;;
736 rev-list) : plumbing;;
737 rev-parse) : plumbing;;
738 runstatus) : plumbing;;
739 sh-setup) : internal;;
740 shell) : daemon;;
741 show-ref) : plumbing;;
742 send-pack) : plumbing;;
743 show-index) : plumbing;;
744 ssh-*) : transport;;
745 stripspace) : plumbing;;
746 symbolic-ref) : plumbing;;
747 tar-tree) : deprecated;;
748 unpack-file) : plumbing;;
749 unpack-objects) : plumbing;;
750 update-index) : plumbing;;
751 update-ref) : plumbing;;
752 update-server-info) : daemon;;
753 upload-archive) : plumbing;;
754 upload-pack) : plumbing;;
755 write-tree) : plumbing;;
756 var) : infrequent;;
757 verify-pack) : infrequent;;
758 verify-tag) : plumbing;;
759 *) echo $i;;
760 esac
761 done
762 }
763
764 __git_porcelain_commands=
765 __git_compute_porcelain_commands ()
766 {
767 __git_compute_all_commands
768 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
769 }
770
771 __git_aliases ()
772 {
773 local i IFS=$'\n'
774 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
775 case "$i" in
776 alias.*)
777 i="${i#alias.}"
778 echo "${i/ */}"
779 ;;
780 esac
781 done
782 }
783
784 # __git_aliased_command requires 1 argument
785 __git_aliased_command ()
786 {
787 local word cmdline=$(git --git-dir="$(__gitdir)" \
788 config --get "alias.$1")
789 for word in $cmdline; do
790 case "$word" in
791 \!gitk|gitk)
792 echo "gitk"
793 return
794 ;;
795 \!*) : shell command alias ;;
796 -*) : option ;;
797 *=*) : setting env ;;
798 git) : git itself ;;
799 *)
800 echo "$word"
801 return
802 esac
803 done
804 }
805
806 # __git_find_on_cmdline requires 1 argument
807 __git_find_on_cmdline ()
808 {
809 local word subcommand c=1
810
811 while [ $c -lt $COMP_CWORD ]; do
812 word="${COMP_WORDS[c]}"
813 for subcommand in $1; do
814 if [ "$subcommand" = "$word" ]; then
815 echo "$subcommand"
816 return
817 fi
818 done
819 c=$((++c))
820 done
821 }
822
823 __git_has_doubledash ()
824 {
825 local c=1
826 while [ $c -lt $COMP_CWORD ]; do
827 if [ "--" = "${COMP_WORDS[c]}" ]; then
828 return 0
829 fi
830 c=$((++c))
831 done
832 return 1
833 }
834
835 __git_whitespacelist="nowarn warn error error-all fix"
836
837 _git_am ()
838 {
839 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
840 if [ -d "$dir"/rebase-apply ]; then
841 __gitcomp "--skip --continue --resolved --abort"
842 return
843 fi
844 case "$cur" in
845 --whitespace=*)
846 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
847 return
848 ;;
849 --*)
850 __gitcomp "
851 --3way --committer-date-is-author-date --ignore-date
852 --ignore-whitespace --ignore-space-change
853 --interactive --keep --no-utf8 --signoff --utf8
854 --whitespace= --scissors
855 "
856 return
857 esac
858 COMPREPLY=()
859 }
860
861 _git_apply ()
862 {
863 local cur="${COMP_WORDS[COMP_CWORD]}"
864 case "$cur" in
865 --whitespace=*)
866 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
867 return
868 ;;
869 --*)
870 __gitcomp "
871 --stat --numstat --summary --check --index
872 --cached --index-info --reverse --reject --unidiff-zero
873 --apply --no-add --exclude=
874 --ignore-whitespace --ignore-space-change
875 --whitespace= --inaccurate-eof --verbose
876 "
877 return
878 esac
879 COMPREPLY=()
880 }
881
882 _git_add ()
883 {
884 __git_has_doubledash && return
885
886 local cur="${COMP_WORDS[COMP_CWORD]}"
887 case "$cur" in
888 --*)
889 __gitcomp "
890 --interactive --refresh --patch --update --dry-run
891 --ignore-errors --intent-to-add
892 "
893 return
894 esac
895 COMPREPLY=()
896 }
897
898 _git_archive ()
899 {
900 local cur="${COMP_WORDS[COMP_CWORD]}"
901 case "$cur" in
902 --format=*)
903 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
904 return
905 ;;
906 --remote=*)
907 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
908 return
909 ;;
910 --*)
911 __gitcomp "
912 --format= --list --verbose
913 --prefix= --remote= --exec=
914 "
915 return
916 ;;
917 esac
918 __git_complete_file
919 }
920
921 _git_bisect ()
922 {
923 __git_has_doubledash && return
924
925 local subcommands="start bad good skip reset visualize replay log run"
926 local subcommand="$(__git_find_on_cmdline "$subcommands")"
927 if [ -z "$subcommand" ]; then
928 __gitcomp "$subcommands"
929 return
930 fi
931
932 case "$subcommand" in
933 bad|good|reset|skip)
934 __gitcomp "$(__git_refs)"
935 ;;
936 *)
937 COMPREPLY=()
938 ;;
939 esac
940 }
941
942 _git_branch ()
943 {
944 local i c=1 only_local_ref="n" has_r="n"
945
946 while [ $c -lt $COMP_CWORD ]; do
947 i="${COMP_WORDS[c]}"
948 case "$i" in
949 -d|-m) only_local_ref="y" ;;
950 -r) has_r="y" ;;
951 esac
952 c=$((++c))
953 done
954
955 case "${COMP_WORDS[COMP_CWORD]}" in
956 --*)
957 __gitcomp "
958 --color --no-color --verbose --abbrev= --no-abbrev
959 --track --no-track --contains --merged --no-merged
960 --set-upstream
961 "
962 ;;
963 *)
964 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
965 __gitcomp "$(__git_heads)"
966 else
967 __gitcomp "$(__git_refs)"
968 fi
969 ;;
970 esac
971 }
972
973 _git_bundle ()
974 {
975 local cmd="${COMP_WORDS[2]}"
976 case "$COMP_CWORD" in
977 2)
978 __gitcomp "create list-heads verify unbundle"
979 ;;
980 3)
981 # looking for a file
982 ;;
983 *)
984 case "$cmd" in
985 create)
986 __git_complete_revlist
987 ;;
988 esac
989 ;;
990 esac
991 }
992
993 _git_checkout ()
994 {
995 __git_has_doubledash && return
996
997 local cur="${COMP_WORDS[COMP_CWORD]}"
998 case "$cur" in
999 --conflict=*)
1000 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1001 ;;
1002 --*)
1003 __gitcomp "
1004 --quiet --ours --theirs --track --no-track --merge
1005 --conflict= --orphan --patch
1006 "
1007 ;;
1008 *)
1009 # check if --track, --no-track, or --no-guess was specified
1010 # if so, disable DWIM mode
1011 local flags="--track --no-track --no-guess" track=1
1012 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1013 track=''
1014 fi
1015 __gitcomp "$(__git_refs '' $track)"
1016 ;;
1017 esac
1018 }
1019
1020 _git_cherry ()
1021 {
1022 __gitcomp "$(__git_refs)"
1023 }
1024
1025 _git_cherry_pick ()
1026 {
1027 local cur="${COMP_WORDS[COMP_CWORD]}"
1028 case "$cur" in
1029 --*)
1030 __gitcomp "--edit --no-commit"
1031 ;;
1032 *)
1033 __gitcomp "$(__git_refs)"
1034 ;;
1035 esac
1036 }
1037
1038 _git_clean ()
1039 {
1040 __git_has_doubledash && return
1041
1042 local cur="${COMP_WORDS[COMP_CWORD]}"
1043 case "$cur" in
1044 --*)
1045 __gitcomp "--dry-run --quiet"
1046 return
1047 ;;
1048 esac
1049 COMPREPLY=()
1050 }
1051
1052 _git_clone ()
1053 {
1054 local cur="${COMP_WORDS[COMP_CWORD]}"
1055 case "$cur" in
1056 --*)
1057 __gitcomp "
1058 --local
1059 --no-hardlinks
1060 --shared
1061 --reference
1062 --quiet
1063 --no-checkout
1064 --bare
1065 --mirror
1066 --origin
1067 --upload-pack
1068 --template=
1069 --depth
1070 "
1071 return
1072 ;;
1073 esac
1074 COMPREPLY=()
1075 }
1076
1077 _git_commit ()
1078 {
1079 __git_has_doubledash && return
1080
1081 local cur="${COMP_WORDS[COMP_CWORD]}"
1082 case "$cur" in
1083 --cleanup=*)
1084 __gitcomp "default strip verbatim whitespace
1085 " "" "${cur##--cleanup=}"
1086 return
1087 ;;
1088 --reuse-message=*)
1089 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
1090 return
1091 ;;
1092 --reedit-message=*)
1093 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
1094 return
1095 ;;
1096 --untracked-files=*)
1097 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1098 return
1099 ;;
1100 --*)
1101 __gitcomp "
1102 --all --author= --signoff --verify --no-verify
1103 --edit --amend --include --only --interactive
1104 --dry-run --reuse-message= --reedit-message=
1105 --reset-author --file= --message= --template=
1106 --cleanup= --untracked-files --untracked-files=
1107 --verbose --quiet
1108 "
1109 return
1110 esac
1111 COMPREPLY=()
1112 }
1113
1114 _git_describe ()
1115 {
1116 local cur="${COMP_WORDS[COMP_CWORD]}"
1117 case "$cur" in
1118 --*)
1119 __gitcomp "
1120 --all --tags --contains --abbrev= --candidates=
1121 --exact-match --debug --long --match --always
1122 "
1123 return
1124 esac
1125 __gitcomp "$(__git_refs)"
1126 }
1127
1128 __git_diff_common_options="--stat --numstat --shortstat --summary
1129 --patch-with-stat --name-only --name-status --color
1130 --no-color --color-words --no-renames --check
1131 --full-index --binary --abbrev --diff-filter=
1132 --find-copies-harder
1133 --text --ignore-space-at-eol --ignore-space-change
1134 --ignore-all-space --exit-code --quiet --ext-diff
1135 --no-ext-diff
1136 --no-prefix --src-prefix= --dst-prefix=
1137 --inter-hunk-context=
1138 --patience
1139 --raw
1140 --dirstat --dirstat= --dirstat-by-file
1141 --dirstat-by-file= --cumulative
1142 "
1143
1144 _git_diff ()
1145 {
1146 __git_has_doubledash && return
1147
1148 local cur="${COMP_WORDS[COMP_CWORD]}"
1149 case "$cur" in
1150 --*)
1151 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1152 --base --ours --theirs --no-index
1153 $__git_diff_common_options
1154 "
1155 return
1156 ;;
1157 esac
1158 __git_complete_file
1159 }
1160
1161 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1162 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
1163 "
1164
1165 _git_difftool ()
1166 {
1167 __git_has_doubledash && return
1168
1169 local cur="${COMP_WORDS[COMP_CWORD]}"
1170 case "$cur" in
1171 --tool=*)
1172 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1173 return
1174 ;;
1175 --*)
1176 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1177 --base --ours --theirs
1178 --no-renames --diff-filter= --find-copies-harder
1179 --relative --ignore-submodules
1180 --tool="
1181 return
1182 ;;
1183 esac
1184 __git_complete_file
1185 }
1186
1187 __git_fetch_options="
1188 --quiet --verbose --append --upload-pack --force --keep --depth=
1189 --tags --no-tags --all --prune --dry-run
1190 "
1191
1192 _git_fetch ()
1193 {
1194 local cur="${COMP_WORDS[COMP_CWORD]}"
1195 case "$cur" in
1196 --*)
1197 __gitcomp "$__git_fetch_options"
1198 return
1199 ;;
1200 esac
1201 __git_complete_remote_or_refspec
1202 }
1203
1204 _git_format_patch ()
1205 {
1206 local cur="${COMP_WORDS[COMP_CWORD]}"
1207 case "$cur" in
1208 --thread=*)
1209 __gitcomp "
1210 deep shallow
1211 " "" "${cur##--thread=}"
1212 return
1213 ;;
1214 --*)
1215 __gitcomp "
1216 --stdout --attach --no-attach --thread --thread=
1217 --output-directory
1218 --numbered --start-number
1219 --numbered-files
1220 --keep-subject
1221 --signoff --signature --no-signature
1222 --in-reply-to= --cc=
1223 --full-index --binary
1224 --not --all
1225 --cover-letter
1226 --no-prefix --src-prefix= --dst-prefix=
1227 --inline --suffix= --ignore-if-in-upstream
1228 --subject-prefix=
1229 "
1230 return
1231 ;;
1232 esac
1233 __git_complete_revlist
1234 }
1235
1236 _git_fsck ()
1237 {
1238 local cur="${COMP_WORDS[COMP_CWORD]}"
1239 case "$cur" in
1240 --*)
1241 __gitcomp "
1242 --tags --root --unreachable --cache --no-reflogs --full
1243 --strict --verbose --lost-found
1244 "
1245 return
1246 ;;
1247 esac
1248 COMPREPLY=()
1249 }
1250
1251 _git_gc ()
1252 {
1253 local cur="${COMP_WORDS[COMP_CWORD]}"
1254 case "$cur" in
1255 --*)
1256 __gitcomp "--prune --aggressive"
1257 return
1258 ;;
1259 esac
1260 COMPREPLY=()
1261 }
1262
1263 _git_gitk ()
1264 {
1265 _gitk
1266 }
1267
1268 _git_grep ()
1269 {
1270 __git_has_doubledash && return
1271
1272 local cur="${COMP_WORDS[COMP_CWORD]}"
1273 case "$cur" in
1274 --*)
1275 __gitcomp "
1276 --cached
1277 --text --ignore-case --word-regexp --invert-match
1278 --full-name
1279 --extended-regexp --basic-regexp --fixed-strings
1280 --files-with-matches --name-only
1281 --files-without-match
1282 --max-depth
1283 --count
1284 --and --or --not --all-match
1285 "
1286 return
1287 ;;
1288 esac
1289
1290 __gitcomp "$(__git_refs)"
1291 }
1292
1293 _git_help ()
1294 {
1295 local cur="${COMP_WORDS[COMP_CWORD]}"
1296 case "$cur" in
1297 --*)
1298 __gitcomp "--all --info --man --web"
1299 return
1300 ;;
1301 esac
1302 __git_compute_all_commands
1303 __gitcomp "$__git_all_commands
1304 attributes cli core-tutorial cvs-migration
1305 diffcore gitk glossary hooks ignore modules
1306 repository-layout tutorial tutorial-2
1307 workflows
1308 "
1309 }
1310
1311 _git_init ()
1312 {
1313 local cur="${COMP_WORDS[COMP_CWORD]}"
1314 case "$cur" in
1315 --shared=*)
1316 __gitcomp "
1317 false true umask group all world everybody
1318 " "" "${cur##--shared=}"
1319 return
1320 ;;
1321 --*)
1322 __gitcomp "--quiet --bare --template= --shared --shared="
1323 return
1324 ;;
1325 esac
1326 COMPREPLY=()
1327 }
1328
1329 _git_ls_files ()
1330 {
1331 __git_has_doubledash && return
1332
1333 local cur="${COMP_WORDS[COMP_CWORD]}"
1334 case "$cur" in
1335 --*)
1336 __gitcomp "--cached --deleted --modified --others --ignored
1337 --stage --directory --no-empty-directory --unmerged
1338 --killed --exclude= --exclude-from=
1339 --exclude-per-directory= --exclude-standard
1340 --error-unmatch --with-tree= --full-name
1341 --abbrev --ignored --exclude-per-directory
1342 "
1343 return
1344 ;;
1345 esac
1346 COMPREPLY=()
1347 }
1348
1349 _git_ls_remote ()
1350 {
1351 __gitcomp "$(__git_remotes)"
1352 }
1353
1354 _git_ls_tree ()
1355 {
1356 __git_complete_file
1357 }
1358
1359 # Options that go well for log, shortlog and gitk
1360 __git_log_common_options="
1361 --not --all
1362 --branches --tags --remotes
1363 --first-parent --merges --no-merges
1364 --max-count=
1365 --max-age= --since= --after=
1366 --min-age= --until= --before=
1367 "
1368 # Options that go well for log and gitk (not shortlog)
1369 __git_log_gitk_options="
1370 --dense --sparse --full-history
1371 --simplify-merges --simplify-by-decoration
1372 --left-right
1373 "
1374 # Options that go well for log and shortlog (not gitk)
1375 __git_log_shortlog_options="
1376 --author= --committer= --grep=
1377 --all-match
1378 "
1379
1380 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1381 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1382
1383 _git_log ()
1384 {
1385 __git_has_doubledash && return
1386
1387 local cur="${COMP_WORDS[COMP_CWORD]}"
1388 local g="$(git rev-parse --git-dir 2>/dev/null)"
1389 local merge=""
1390 if [ -f "$g/MERGE_HEAD" ]; then
1391 merge="--merge"
1392 fi
1393 case "$cur" in
1394 --pretty=*)
1395 __gitcomp "$__git_log_pretty_formats
1396 " "" "${cur##--pretty=}"
1397 return
1398 ;;
1399 --format=*)
1400 __gitcomp "$__git_log_pretty_formats
1401 " "" "${cur##--format=}"
1402 return
1403 ;;
1404 --date=*)
1405 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1406 return
1407 ;;
1408 --decorate=*)
1409 __gitcomp "long short" "" "${cur##--decorate=}"
1410 return
1411 ;;
1412 --*)
1413 __gitcomp "
1414 $__git_log_common_options
1415 $__git_log_shortlog_options
1416 $__git_log_gitk_options
1417 --root --topo-order --date-order --reverse
1418 --follow --full-diff
1419 --abbrev-commit --abbrev=
1420 --relative-date --date=
1421 --pretty= --format= --oneline
1422 --cherry-pick
1423 --graph
1424 --decorate --decorate=
1425 --walk-reflogs
1426 --parents --children
1427 $merge
1428 $__git_diff_common_options
1429 --pickaxe-all --pickaxe-regex
1430 "
1431 return
1432 ;;
1433 esac
1434 __git_complete_revlist
1435 }
1436
1437 __git_merge_options="
1438 --no-commit --no-stat --log --no-log --squash --strategy
1439 --commit --stat --no-squash --ff --no-ff --ff-only
1440 "
1441
1442 _git_merge ()
1443 {
1444 __git_complete_strategy && return
1445
1446 local cur="${COMP_WORDS[COMP_CWORD]}"
1447 case "$cur" in
1448 --*)
1449 __gitcomp "$__git_merge_options"
1450 return
1451 esac
1452 __gitcomp "$(__git_refs)"
1453 }
1454
1455 _git_mergetool ()
1456 {
1457 local cur="${COMP_WORDS[COMP_CWORD]}"
1458 case "$cur" in
1459 --tool=*)
1460 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1461 return
1462 ;;
1463 --*)
1464 __gitcomp "--tool="
1465 return
1466 ;;
1467 esac
1468 COMPREPLY=()
1469 }
1470
1471 _git_merge_base ()
1472 {
1473 __gitcomp "$(__git_refs)"
1474 }
1475
1476 _git_mv ()
1477 {
1478 local cur="${COMP_WORDS[COMP_CWORD]}"
1479 case "$cur" in
1480 --*)
1481 __gitcomp "--dry-run"
1482 return
1483 ;;
1484 esac
1485 COMPREPLY=()
1486 }
1487
1488 _git_name_rev ()
1489 {
1490 __gitcomp "--tags --all --stdin"
1491 }
1492
1493 _git_notes ()
1494 {
1495 local subcommands="edit show"
1496 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1497 __gitcomp "$subcommands"
1498 return
1499 fi
1500
1501 case "${COMP_WORDS[COMP_CWORD-1]}" in
1502 -m|-F)
1503 COMPREPLY=()
1504 ;;
1505 *)
1506 __gitcomp "$(__git_refs)"
1507 ;;
1508 esac
1509 }
1510
1511 _git_pull ()
1512 {
1513 __git_complete_strategy && return
1514
1515 local cur="${COMP_WORDS[COMP_CWORD]}"
1516 case "$cur" in
1517 --*)
1518 __gitcomp "
1519 --rebase --no-rebase
1520 $__git_merge_options
1521 $__git_fetch_options
1522 "
1523 return
1524 ;;
1525 esac
1526 __git_complete_remote_or_refspec
1527 }
1528
1529 _git_push ()
1530 {
1531 local cur="${COMP_WORDS[COMP_CWORD]}"
1532 case "${COMP_WORDS[COMP_CWORD-1]}" in
1533 --repo)
1534 __gitcomp "$(__git_remotes)"
1535 return
1536 esac
1537 case "$cur" in
1538 --repo=*)
1539 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1540 return
1541 ;;
1542 --*)
1543 __gitcomp "
1544 --all --mirror --tags --dry-run --force --verbose
1545 --receive-pack= --repo=
1546 "
1547 return
1548 ;;
1549 esac
1550 __git_complete_remote_or_refspec
1551 }
1552
1553 _git_rebase ()
1554 {
1555 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1556 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1557 __gitcomp "--continue --skip --abort"
1558 return
1559 fi
1560 __git_complete_strategy && return
1561 case "$cur" in
1562 --whitespace=*)
1563 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1564 return
1565 ;;
1566 --*)
1567 __gitcomp "
1568 --onto --merge --strategy --interactive
1569 --preserve-merges --stat --no-stat
1570 --committer-date-is-author-date --ignore-date
1571 --ignore-whitespace --whitespace=
1572 --autosquash
1573 "
1574
1575 return
1576 esac
1577 __gitcomp "$(__git_refs)"
1578 }
1579
1580 __git_send_email_confirm_options="always never auto cc compose"
1581 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1582
1583 _git_send_email ()
1584 {
1585 local cur="${COMP_WORDS[COMP_CWORD]}"
1586 case "$cur" in
1587 --confirm=*)
1588 __gitcomp "
1589 $__git_send_email_confirm_options
1590 " "" "${cur##--confirm=}"
1591 return
1592 ;;
1593 --suppress-cc=*)
1594 __gitcomp "
1595 $__git_send_email_suppresscc_options
1596 " "" "${cur##--suppress-cc=}"
1597
1598 return
1599 ;;
1600 --smtp-encryption=*)
1601 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1602 return
1603 ;;
1604 --*)
1605 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1606 --compose --confirm= --dry-run --envelope-sender
1607 --from --identity
1608 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1609 --no-suppress-from --no-thread --quiet
1610 --signed-off-by-cc --smtp-pass --smtp-server
1611 --smtp-server-port --smtp-encryption= --smtp-user
1612 --subject --suppress-cc= --suppress-from --thread --to
1613 --validate --no-validate"
1614 return
1615 ;;
1616 esac
1617 COMPREPLY=()
1618 }
1619
1620 _git_stage ()
1621 {
1622 _git_add
1623 }
1624
1625 __git_config_get_set_variables ()
1626 {
1627 local prevword word config_file= c=$COMP_CWORD
1628 while [ $c -gt 1 ]; do
1629 word="${COMP_WORDS[c]}"
1630 case "$word" in
1631 --global|--system|--file=*)
1632 config_file="$word"
1633 break
1634 ;;
1635 -f|--file)
1636 config_file="$word $prevword"
1637 break
1638 ;;
1639 esac
1640 prevword=$word
1641 c=$((--c))
1642 done
1643
1644 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1645 while read line
1646 do
1647 case "$line" in
1648 *.*=*)
1649 echo "${line/=*/}"
1650 ;;
1651 esac
1652 done
1653 }
1654
1655 _git_config ()
1656 {
1657 local cur="${COMP_WORDS[COMP_CWORD]}"
1658 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1659 case "$prv" in
1660 branch.*.remote)
1661 __gitcomp "$(__git_remotes)"
1662 return
1663 ;;
1664 branch.*.merge)
1665 __gitcomp "$(__git_refs)"
1666 return
1667 ;;
1668 remote.*.fetch)
1669 local remote="${prv#remote.}"
1670 remote="${remote%.fetch}"
1671 __gitcomp "$(__git_refs_remotes "$remote")"
1672 return
1673 ;;
1674 remote.*.push)
1675 local remote="${prv#remote.}"
1676 remote="${remote%.push}"
1677 __gitcomp "$(git --git-dir="$(__gitdir)" \
1678 for-each-ref --format='%(refname):%(refname)' \
1679 refs/heads)"
1680 return
1681 ;;
1682 pull.twohead|pull.octopus)
1683 __git_compute_merge_strategies
1684 __gitcomp "$__git_merge_strategies"
1685 return
1686 ;;
1687 color.branch|color.diff|color.interactive|\
1688 color.showbranch|color.status|color.ui)
1689 __gitcomp "always never auto"
1690 return
1691 ;;
1692 color.pager)
1693 __gitcomp "false true"
1694 return
1695 ;;
1696 color.*.*)
1697 __gitcomp "
1698 normal black red green yellow blue magenta cyan white
1699 bold dim ul blink reverse
1700 "
1701 return
1702 ;;
1703 help.format)
1704 __gitcomp "man info web html"
1705 return
1706 ;;
1707 log.date)
1708 __gitcomp "$__git_log_date_formats"
1709 return
1710 ;;
1711 sendemail.aliasesfiletype)
1712 __gitcomp "mutt mailrc pine elm gnus"
1713 return
1714 ;;
1715 sendemail.confirm)
1716 __gitcomp "$__git_send_email_confirm_options"
1717 return
1718 ;;
1719 sendemail.suppresscc)
1720 __gitcomp "$__git_send_email_suppresscc_options"
1721 return
1722 ;;
1723 --get|--get-all|--unset|--unset-all)
1724 __gitcomp "$(__git_config_get_set_variables)"
1725 return
1726 ;;
1727 *.*)
1728 COMPREPLY=()
1729 return
1730 ;;
1731 esac
1732 case "$cur" in
1733 --*)
1734 __gitcomp "
1735 --global --system --file=
1736 --list --replace-all
1737 --get --get-all --get-regexp
1738 --add --unset --unset-all
1739 --remove-section --rename-section
1740 "
1741 return
1742 ;;
1743 branch.*.*)
1744 local pfx="${cur%.*}."
1745 cur="${cur##*.}"
1746 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1747 return
1748 ;;
1749 branch.*)
1750 local pfx="${cur%.*}."
1751 cur="${cur#*.}"
1752 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1753 return
1754 ;;
1755 guitool.*.*)
1756 local pfx="${cur%.*}."
1757 cur="${cur##*.}"
1758 __gitcomp "
1759 argprompt cmd confirm needsfile noconsole norescan
1760 prompt revprompt revunmerged title
1761 " "$pfx" "$cur"
1762 return
1763 ;;
1764 difftool.*.*)
1765 local pfx="${cur%.*}."
1766 cur="${cur##*.}"
1767 __gitcomp "cmd path" "$pfx" "$cur"
1768 return
1769 ;;
1770 man.*.*)
1771 local pfx="${cur%.*}."
1772 cur="${cur##*.}"
1773 __gitcomp "cmd path" "$pfx" "$cur"
1774 return
1775 ;;
1776 mergetool.*.*)
1777 local pfx="${cur%.*}."
1778 cur="${cur##*.}"
1779 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1780 return
1781 ;;
1782 pager.*)
1783 local pfx="${cur%.*}."
1784 cur="${cur#*.}"
1785 __git_compute_all_commands
1786 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1787 return
1788 ;;
1789 remote.*.*)
1790 local pfx="${cur%.*}."
1791 cur="${cur##*.}"
1792 __gitcomp "
1793 url proxy fetch push mirror skipDefaultUpdate
1794 receivepack uploadpack tagopt pushurl
1795 " "$pfx" "$cur"
1796 return
1797 ;;
1798 remote.*)
1799 local pfx="${cur%.*}."
1800 cur="${cur#*.}"
1801 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1802 return
1803 ;;
1804 url.*.*)
1805 local pfx="${cur%.*}."
1806 cur="${cur##*.}"
1807 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1808 return
1809 ;;
1810 esac
1811 __gitcomp "
1812 add.ignore-errors
1813 alias.
1814 apply.ignorewhitespace
1815 apply.whitespace
1816 branch.autosetupmerge
1817 branch.autosetuprebase
1818 clean.requireForce
1819 color.branch
1820 color.branch.current
1821 color.branch.local
1822 color.branch.plain
1823 color.branch.remote
1824 color.diff
1825 color.diff.commit
1826 color.diff.frag
1827 color.diff.meta
1828 color.diff.new
1829 color.diff.old
1830 color.diff.plain
1831 color.diff.whitespace
1832 color.grep
1833 color.grep.external
1834 color.grep.match
1835 color.interactive
1836 color.interactive.header
1837 color.interactive.help
1838 color.interactive.prompt
1839 color.pager
1840 color.showbranch
1841 color.status
1842 color.status.added
1843 color.status.changed
1844 color.status.header
1845 color.status.nobranch
1846 color.status.untracked
1847 color.status.updated
1848 color.ui
1849 commit.template
1850 core.autocrlf
1851 core.bare
1852 core.compression
1853 core.createObject
1854 core.deltaBaseCacheLimit
1855 core.editor
1856 core.excludesfile
1857 core.fileMode
1858 core.fsyncobjectfiles
1859 core.gitProxy
1860 core.ignoreCygwinFSTricks
1861 core.ignoreStat
1862 core.logAllRefUpdates
1863 core.loosecompression
1864 core.packedGitLimit
1865 core.packedGitWindowSize
1866 core.pager
1867 core.preferSymlinkRefs
1868 core.preloadindex
1869 core.quotepath
1870 core.repositoryFormatVersion
1871 core.safecrlf
1872 core.sharedRepository
1873 core.symlinks
1874 core.trustctime
1875 core.warnAmbiguousRefs
1876 core.whitespace
1877 core.worktree
1878 diff.autorefreshindex
1879 diff.external
1880 diff.mnemonicprefix
1881 diff.renameLimit
1882 diff.renameLimit.
1883 diff.renames
1884 diff.suppressBlankEmpty
1885 diff.tool
1886 diff.wordRegex
1887 difftool.
1888 difftool.prompt
1889 fetch.unpackLimit
1890 format.attach
1891 format.cc
1892 format.headers
1893 format.numbered
1894 format.pretty
1895 format.signature
1896 format.signoff
1897 format.subjectprefix
1898 format.suffix
1899 format.thread
1900 gc.aggressiveWindow
1901 gc.auto
1902 gc.autopacklimit
1903 gc.packrefs
1904 gc.pruneexpire
1905 gc.reflogexpire
1906 gc.reflogexpireunreachable
1907 gc.rerereresolved
1908 gc.rerereunresolved
1909 gitcvs.allbinary
1910 gitcvs.commitmsgannotation
1911 gitcvs.dbTableNamePrefix
1912 gitcvs.dbdriver
1913 gitcvs.dbname
1914 gitcvs.dbpass
1915 gitcvs.dbuser
1916 gitcvs.enabled
1917 gitcvs.logfile
1918 gitcvs.usecrlfattr
1919 guitool.
1920 gui.blamehistoryctx
1921 gui.commitmsgwidth
1922 gui.copyblamethreshold
1923 gui.diffcontext
1924 gui.encoding
1925 gui.fastcopyblame
1926 gui.matchtrackingbranch
1927 gui.newbranchtemplate
1928 gui.pruneduringfetch
1929 gui.spellingdictionary
1930 gui.trustmtime
1931 help.autocorrect
1932 help.browser
1933 help.format
1934 http.lowSpeedLimit
1935 http.lowSpeedTime
1936 http.maxRequests
1937 http.noEPSV
1938 http.proxy
1939 http.sslCAInfo
1940 http.sslCAPath
1941 http.sslCert
1942 http.sslKey
1943 http.sslVerify
1944 i18n.commitEncoding
1945 i18n.logOutputEncoding
1946 imap.folder
1947 imap.host
1948 imap.pass
1949 imap.port
1950 imap.preformattedHTML
1951 imap.sslverify
1952 imap.tunnel
1953 imap.user
1954 instaweb.browser
1955 instaweb.httpd
1956 instaweb.local
1957 instaweb.modulepath
1958 instaweb.port
1959 interactive.singlekey
1960 log.date
1961 log.showroot
1962 mailmap.file
1963 man.
1964 man.viewer
1965 merge.conflictstyle
1966 merge.log
1967 merge.renameLimit
1968 merge.stat
1969 merge.tool
1970 merge.verbosity
1971 mergetool.
1972 mergetool.keepBackup
1973 mergetool.prompt
1974 pack.compression
1975 pack.deltaCacheLimit
1976 pack.deltaCacheSize
1977 pack.depth
1978 pack.indexVersion
1979 pack.packSizeLimit
1980 pack.threads
1981 pack.window
1982 pack.windowMemory
1983 pager.
1984 pull.octopus
1985 pull.twohead
1986 push.default
1987 rebase.stat
1988 receive.denyCurrentBranch
1989 receive.denyDeletes
1990 receive.denyNonFastForwards
1991 receive.fsckObjects
1992 receive.unpackLimit
1993 repack.usedeltabaseoffset
1994 rerere.autoupdate
1995 rerere.enabled
1996 sendemail.aliasesfile
1997 sendemail.aliasesfiletype
1998 sendemail.bcc
1999 sendemail.cc
2000 sendemail.cccmd
2001 sendemail.chainreplyto
2002 sendemail.confirm
2003 sendemail.envelopesender
2004 sendemail.multiedit
2005 sendemail.signedoffbycc
2006 sendemail.smtpencryption
2007 sendemail.smtppass
2008 sendemail.smtpserver
2009 sendemail.smtpserverport
2010 sendemail.smtpuser
2011 sendemail.suppresscc
2012 sendemail.suppressfrom
2013 sendemail.thread
2014 sendemail.to
2015 sendemail.validate
2016 showbranch.default
2017 status.relativePaths
2018 status.showUntrackedFiles
2019 tar.umask
2020 transfer.unpackLimit
2021 url.
2022 user.email
2023 user.name
2024 user.signingkey
2025 web.browser
2026 branch. remote.
2027 "
2028 }
2029
2030 _git_remote ()
2031 {
2032 local subcommands="add rename rm show prune update set-head"
2033 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2034 if [ -z "$subcommand" ]; then
2035 __gitcomp "$subcommands"
2036 return
2037 fi
2038
2039 case "$subcommand" in
2040 rename|rm|show|prune)
2041 __gitcomp "$(__git_remotes)"
2042 ;;
2043 update)
2044 local i c='' IFS=$'\n'
2045 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2046 i="${i#remotes.}"
2047 c="$c ${i/ */}"
2048 done
2049 __gitcomp "$c"
2050 ;;
2051 *)
2052 COMPREPLY=()
2053 ;;
2054 esac
2055 }
2056
2057 _git_replace ()
2058 {
2059 __gitcomp "$(__git_refs)"
2060 }
2061
2062 _git_reset ()
2063 {
2064 __git_has_doubledash && return
2065
2066 local cur="${COMP_WORDS[COMP_CWORD]}"
2067 case "$cur" in
2068 --*)
2069 __gitcomp "--merge --mixed --hard --soft --patch"
2070 return
2071 ;;
2072 esac
2073 __gitcomp "$(__git_refs)"
2074 }
2075
2076 _git_revert ()
2077 {
2078 local cur="${COMP_WORDS[COMP_CWORD]}"
2079 case "$cur" in
2080 --*)
2081 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2082 return
2083 ;;
2084 esac
2085 __gitcomp "$(__git_refs)"
2086 }
2087
2088 _git_rm ()
2089 {
2090 __git_has_doubledash && return
2091
2092 local cur="${COMP_WORDS[COMP_CWORD]}"
2093 case "$cur" in
2094 --*)
2095 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2096 return
2097 ;;
2098 esac
2099 COMPREPLY=()
2100 }
2101
2102 _git_shortlog ()
2103 {
2104 __git_has_doubledash && return
2105
2106 local cur="${COMP_WORDS[COMP_CWORD]}"
2107 case "$cur" in
2108 --*)
2109 __gitcomp "
2110 $__git_log_common_options
2111 $__git_log_shortlog_options
2112 --numbered --summary
2113 "
2114 return
2115 ;;
2116 esac
2117 __git_complete_revlist
2118 }
2119
2120 _git_show ()
2121 {
2122 __git_has_doubledash && return
2123
2124 local cur="${COMP_WORDS[COMP_CWORD]}"
2125 case "$cur" in
2126 --pretty=*)
2127 __gitcomp "$__git_log_pretty_formats
2128 " "" "${cur##--pretty=}"
2129 return
2130 ;;
2131 --format=*)
2132 __gitcomp "$__git_log_pretty_formats
2133 " "" "${cur##--format=}"
2134 return
2135 ;;
2136 --*)
2137 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2138 $__git_diff_common_options
2139 "
2140 return
2141 ;;
2142 esac
2143 __git_complete_file
2144 }
2145
2146 _git_show_branch ()
2147 {
2148 local cur="${COMP_WORDS[COMP_CWORD]}"
2149 case "$cur" in
2150 --*)
2151 __gitcomp "
2152 --all --remotes --topo-order --current --more=
2153 --list --independent --merge-base --no-name
2154 --color --no-color
2155 --sha1-name --sparse --topics --reflog
2156 "
2157 return
2158 ;;
2159 esac
2160 __git_complete_revlist
2161 }
2162
2163 _git_stash ()
2164 {
2165 local cur="${COMP_WORDS[COMP_CWORD]}"
2166 local save_opts='--keep-index --no-keep-index --quiet --patch'
2167 local subcommands='save list show apply clear drop pop create branch'
2168 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2169 if [ -z "$subcommand" ]; then
2170 case "$cur" in
2171 --*)
2172 __gitcomp "$save_opts"
2173 ;;
2174 *)
2175 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2176 __gitcomp "$subcommands"
2177 else
2178 COMPREPLY=()
2179 fi
2180 ;;
2181 esac
2182 else
2183 case "$subcommand,$cur" in
2184 save,--*)
2185 __gitcomp "$save_opts"
2186 ;;
2187 apply,--*|pop,--*)
2188 __gitcomp "--index --quiet"
2189 ;;
2190 show,--*|drop,--*|branch,--*)
2191 COMPREPLY=()
2192 ;;
2193 show,*|apply,*|drop,*|pop,*|branch,*)
2194 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2195 | sed -n -e 's/:.*//p')"
2196 ;;
2197 *)
2198 COMPREPLY=()
2199 ;;
2200 esac
2201 fi
2202 }
2203
2204 _git_submodule ()
2205 {
2206 __git_has_doubledash && return
2207
2208 local subcommands="add status init update summary foreach sync"
2209 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2210 local cur="${COMP_WORDS[COMP_CWORD]}"
2211 case "$cur" in
2212 --*)
2213 __gitcomp "--quiet --cached"
2214 ;;
2215 *)
2216 __gitcomp "$subcommands"
2217 ;;
2218 esac
2219 return
2220 fi
2221 }
2222
2223 _git_svn ()
2224 {
2225 local subcommands="
2226 init fetch clone rebase dcommit log find-rev
2227 set-tree commit-diff info create-ignore propget
2228 proplist show-ignore show-externals branch tag blame
2229 migrate mkdirs reset gc
2230 "
2231 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2232 if [ -z "$subcommand" ]; then
2233 __gitcomp "$subcommands"
2234 else
2235 local remote_opts="--username= --config-dir= --no-auth-cache"
2236 local fc_opts="
2237 --follow-parent --authors-file= --repack=
2238 --no-metadata --use-svm-props --use-svnsync-props
2239 --log-window-size= --no-checkout --quiet
2240 --repack-flags --use-log-author --localtime
2241 --ignore-paths= $remote_opts
2242 "
2243 local init_opts="
2244 --template= --shared= --trunk= --tags=
2245 --branches= --stdlayout --minimize-url
2246 --no-metadata --use-svm-props --use-svnsync-props
2247 --rewrite-root= --prefix= --use-log-author
2248 --add-author-from $remote_opts
2249 "
2250 local cmt_opts="
2251 --edit --rmdir --find-copies-harder --copy-similarity=
2252 "
2253
2254 local cur="${COMP_WORDS[COMP_CWORD]}"
2255 case "$subcommand,$cur" in
2256 fetch,--*)
2257 __gitcomp "--revision= --fetch-all $fc_opts"
2258 ;;
2259 clone,--*)
2260 __gitcomp "--revision= $fc_opts $init_opts"
2261 ;;
2262 init,--*)
2263 __gitcomp "$init_opts"
2264 ;;
2265 dcommit,--*)
2266 __gitcomp "
2267 --merge --strategy= --verbose --dry-run
2268 --fetch-all --no-rebase --commit-url
2269 --revision $cmt_opts $fc_opts
2270 "
2271 ;;
2272 set-tree,--*)
2273 __gitcomp "--stdin $cmt_opts $fc_opts"
2274 ;;
2275 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2276 show-externals,--*|mkdirs,--*)
2277 __gitcomp "--revision="
2278 ;;
2279 log,--*)
2280 __gitcomp "
2281 --limit= --revision= --verbose --incremental
2282 --oneline --show-commit --non-recursive
2283 --authors-file= --color
2284 "
2285 ;;
2286 rebase,--*)
2287 __gitcomp "
2288 --merge --verbose --strategy= --local
2289 --fetch-all --dry-run $fc_opts
2290 "
2291 ;;
2292 commit-diff,--*)
2293 __gitcomp "--message= --file= --revision= $cmt_opts"
2294 ;;
2295 info,--*)
2296 __gitcomp "--url"
2297 ;;
2298 branch,--*)
2299 __gitcomp "--dry-run --message --tag"
2300 ;;
2301 tag,--*)
2302 __gitcomp "--dry-run --message"
2303 ;;
2304 blame,--*)
2305 __gitcomp "--git-format"
2306 ;;
2307 migrate,--*)
2308 __gitcomp "
2309 --config-dir= --ignore-paths= --minimize
2310 --no-auth-cache --username=
2311 "
2312 ;;
2313 reset,--*)
2314 __gitcomp "--revision= --parent"
2315 ;;
2316 *)
2317 COMPREPLY=()
2318 ;;
2319 esac
2320 fi
2321 }
2322
2323 _git_tag ()
2324 {
2325 local i c=1 f=0
2326 while [ $c -lt $COMP_CWORD ]; do
2327 i="${COMP_WORDS[c]}"
2328 case "$i" in
2329 -d|-v)
2330 __gitcomp "$(__git_tags)"
2331 return
2332 ;;
2333 -f)
2334 f=1
2335 ;;
2336 esac
2337 c=$((++c))
2338 done
2339
2340 case "${COMP_WORDS[COMP_CWORD-1]}" in
2341 -m|-F)
2342 COMPREPLY=()
2343 ;;
2344 -*|tag)
2345 if [ $f = 1 ]; then
2346 __gitcomp "$(__git_tags)"
2347 else
2348 COMPREPLY=()
2349 fi
2350 ;;
2351 *)
2352 __gitcomp "$(__git_refs)"
2353 ;;
2354 esac
2355 }
2356
2357 _git_whatchanged ()
2358 {
2359 _git_log
2360 }
2361
2362 _git ()
2363 {
2364 local i c=1 command __git_dir
2365
2366 while [ $c -lt $COMP_CWORD ]; do
2367 i="${COMP_WORDS[c]}"
2368 case "$i" in
2369 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2370 --bare) __git_dir="." ;;
2371 --version|-p|--paginate) ;;
2372 --help) command="help"; break ;;
2373 *) command="$i"; break ;;
2374 esac
2375 c=$((++c))
2376 done
2377
2378 if [ -z "$command" ]; then
2379 case "${COMP_WORDS[COMP_CWORD]}" in
2380 --*) __gitcomp "
2381 --paginate
2382 --no-pager
2383 --git-dir=
2384 --bare
2385 --version
2386 --exec-path
2387 --html-path
2388 --work-tree=
2389 --help
2390 "
2391 ;;
2392 *) __git_compute_porcelain_commands
2393 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2394 esac
2395 return
2396 fi
2397
2398 local completion_func="_git_${command//-/_}"
2399 declare -F $completion_func >/dev/null && $completion_func && return
2400
2401 local expansion=$(__git_aliased_command "$command")
2402 if [ -n "$expansion" ]; then
2403 completion_func="_git_${expansion//-/_}"
2404 declare -F $completion_func >/dev/null && $completion_func
2405 fi
2406 }
2407
2408 _gitk ()
2409 {
2410 __git_has_doubledash && return
2411
2412 local cur="${COMP_WORDS[COMP_CWORD]}"
2413 local g="$(__gitdir)"
2414 local merge=""
2415 if [ -f "$g/MERGE_HEAD" ]; then
2416 merge="--merge"
2417 fi
2418 case "$cur" in
2419 --*)
2420 __gitcomp "
2421 $__git_log_common_options
2422 $__git_log_gitk_options
2423 $merge
2424 "
2425 return
2426 ;;
2427 esac
2428 __git_complete_revlist
2429 }
2430
2431 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2432 || complete -o default -o nospace -F _git git
2433 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2434 || complete -o default -o nospace -F _gitk gitk
2435
2436 # The following are necessary only for Cygwin, and only are needed
2437 # when the user has tab-completed the executable name and consequently
2438 # included the '.exe' suffix.
2439 #
2440 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2441 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2442 || complete -o default -o nospace -F _git git.exe
2443 fi