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