## bash completion support for core Git.## Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org># Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).# Distributed under the GNU General Public License, version 2.0.## The contained completion routines provide support for completing:## *) local and remote branch names# *) local and remote tag names# *) .git/remotes file names# *) git 'subcommands'# *) tree paths within 'ref:path/to/file' expressions# *) common --long-options## To use these routines:## 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).# 2) Added the following line to your .bashrc:# source ~/.git-completion.sh## 3) You may want to make sure the git executable is available# in your PATH before this script is sourced, as some caching# is performed while the script loads. If git isn't found# at source time then all lookups will be done on demand,# which may be slightly slower.## 4) Consider changing your PS1 to also show the current branch:# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '## The argument to __git_ps1 will be displayed only if you# are currently in a git repository. The %s token will be# the name of the current branch.## To submit patches:## *) Read Documentation/SubmittingPatches# *) Send all patches to the current maintainer:## "Shawn O. Pearce" <spearce@spearce.org>## *) Always CC the Git mailing list:## git@vger.kernel.org#__gitdir ()
{
if [ -z "$1" ]; thenif [ -n "$__git_dir" ]; thenecho"$__git_dir"elif [ -d .git ]; thenecho .git
else git rev-parse --git-dir 2>/dev/null
fielif [ -d "$1/.git" ]; thenecho"$1/.git"elseecho"$1"fi}
__git_ps1 ()
{
localg="$(git rev-parse --git-dir 2>/dev/null)"if [ -n "$g" ]; thenlocal r
local b
if [ -d "$g/../.dotest" ]
thenr="|AM/REBASE"b="$(git symbolic-ref HEAD 2>/dev/null)"elif [ -f "$g/.dotest-merge/interactive" ]
thenr="|REBASE-i"b="$(cat $g/.dotest-merge/head-name)"elif [ -d "$g/.dotest-merge" ]
thenr="|REBASE-m"b="$(cat $g/.dotest-merge/head-name)"elif [ -f "$g/MERGE_HEAD" ]
thenr="|MERGING"b="$(git symbolic-ref HEAD 2>/dev/null)"elseif [ -f $g/BISECT_LOG ]
thenr="|BISECTING"fiif ! b="$(git symbolic-ref HEAD 2>/dev/null)"thenb="$(cut -c1-7 $g/HEAD)..."fifiif [ -n "$1" ]; thenprintf"$1""${b##refs/heads/}$r"elseprintf" (%s)""${b##refs/heads/}$r"fifi}
__gitcomp ()
{
local all c s=$'\n'IFS=' '$'\t'$'\n'localcur="${COMP_WORDS[COMP_CWORD]}"if [ $# -gt 2 ]; then