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