#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG					#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2010 Christopher Bratusek		#
#							#
#########################################################

git_export() {

	if [[ "$1" != "" ]]; then
		git checkout-index --prefix="$1"/ -a
	fi

}

git_bzip() {

	git archive master | bzip2 -9 >"$PWD".tar.bz2

}

git_xz() {

	git archive master | xz -9 > "$PWD".tar.xz

}

get_gnome () {

	if [[ $GIT_USER_GNOME ]]; then
		if [[ $1 == "-m" ]]; then
			git clone git+ssh://$GIT_USER_GNOME@git.gnome.org/git/$2
		elif [[ $1 == "-mb" ]]; then
			git clone -b $3 git+ssh://$GIT_USER_GNOME@git.gnome.org/git/$2
		fi
	fi


	if [[ $1 == "-b" ]]; then
		git clone -b $3 git://git.gnome.org/$2
	else 	git clone git://git.gnome.org/$1
	fi

}

get_xfce () {

	if [[ $GIT_USER_XFCE ]]; then
		if [[ $1 == "-m" ]]; then
			git clone ssh://$GIT_USER_XFCE@git.xfce.org/git/$2
		elif [[ $1 == "-mb" ]]; then
			git clone -b $3 ssh://$GIT_USER_XFCE@git.xfce.org/git/$2
		fi
	fi

	if [[ $1 == "-b" ]]; then
		git clone -b $3 git://git.xfce.org/$2
	else	git clone git://git.xfce.org/$1
	fi

}

git_branch () {

	if [[ -d .git ]]; then
		BRANCH=$(git symbolic-ref HEAD 2>/dev/null)
		echo ${BRANCH#refs/heads/}
	else	echo --
	fi

}

git_revision () {

	if [[ -d .git ]]; then
		REVISION=$(git rev-parse HEAD 2>/dev/null)
		REVISION=${REVISION/HEAD/}
		echo ${REVISION:0:6}
	else	echo --
	fi

}

git_action () {

	if [[ -d .git ]]; then

		if [[ -f .git/dotest/rebasing ]]; then
			ACTION="rebase"
		elif [[ -f .git/dotest/applying ]]; then
			ACTION="apply"
		elif [[ -f .git/dotest-merge/interactive ]]; then
			ACTION="rebase -i"
		elif [[ -d .git/dotest-merge ]]; then
			ACTION="rebase -m"
		elif [[ -f .git/MERGE_HEAD ]]; then
			ACTION="merge"
		elif [[ -f .git/index.lock ]]; then
			ACTION="locked"
		elif [[ -f .git/BISECT_LOG ]]; then
			ACTION="bisect"
		else	ACTION="nothing"
		fi
		echo $ACTION
	else	echo --
	fi

}

get_kde () {

	if [[ "$SVN_USER_KDE" ]]; then
		if [[ $1 == "-m" ]]; then
			svn co --user-name="$SVN_USER_KDE" svn+ssh://svn.kde.org/home/kde/trunk/KDE/$2
		elif [[ $1 == "-mb" ]]; then
			svn co --user-name="$SVN_USER_KDE" svn+ssh://svn.kde.org/home/kde/branches/KDE/$2
		fi
	fi

	if [[ $1 == "-b" ]]; then
		svn co svn://svn.kde.org/home/kde/branches/KDE/$2
	else	svn co svn://svn.kde.org/home/kde/trunk/KDE/$2
	fi

}

get_e () {

	if [[ "$SVN_USER_ENLIGTENMENT" && $1 == "-m" ]]; then
		svn co svn+ssh://"$SVN_USER_ENLIGTENMENT"@svn.enlightenment.org/var/svn/$2
	else
		svn co http://svn.enlightenment.org/svn/$2
	fi

}
