summaryrefslogtreecommitdiff
path: root/eclass/git.eclass
blob: 55146d3030ddfc8f799ca49b973a82f31a2140e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
# Nonofficial eclass by Ycarus. For new version look here : http://gentoo.zugaina.org/
# This is a modified version of the git eclass

# Author: Ycarus <ycarus@zugaina.org>
# Hacked by: Beber <beber@gna.org>
# 
# The git eclass is written to fetch the software sources from
# git repositories.
#
#
# Description:
#   If you use this eclass, the ${S} is ${WORKDIR}/${P}.
#   It is necessary to define the EGIT_REPO_URI variables at least.
#

inherit eutils

ECLASS="git"
INHERITED="${INHERITED} ${ECLASS}"
EGIT="git.eclass"

EXPORT_FUNCTIONS src_unpack

HOMEPAGE="http://kernel.org/pub/software/scm/git/"
DESCRIPTION="GIT eclass"

DEPEND="dev-util/cogito"

# EGIT_TOP_DIR -- The directory under which GIT branches are checked out.
[ -z "$EGIT_TOP_DIR" ] && EGIT_TOP_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/git-src"

# EGIT_FETCH_CMD -- git fetch command
[ -z "${EGIT_FETCH_CMD}" ] && EGIT_FETCH_CMD="cg-clone"
[ -z "${EGIT_UPDATE_CMD}" ] && EGIT_UPDATE_CMD="cg-update"

# EGIT_REPO_URI -- repository uri
[ -z "${EGIT_REPO_URI}" ] && EGIT_REPO_URI=""

## -- EGIT_PROJECT: project name of your ebuild
#
# git eclass will check out the git repository like:
#
#   ${EGIT_TOP_DIR}/${EGIT_PROJECT}/${EGIT_REPO_URI##*/}
#
# default: ${PN/-git}.
#
[ -z "${EGIT_PROJECT}" ] && EGIT_PROJECT="${PN/-git}"

## -- git_fetch() ------------------------------------------------- #

function git_fetch() {
	# EGIT_REPO_URI is empty.
	[ -z "${EGIT_REPO_URI}" ] && die "${EGIT}: EGIT_REPO_URI is empty."
	EGIT_REPO_URI="${EGIT_REPO_URI} ${EGIT_PROJECT}"
	# check for the protocol.
	case ${EGIT_REPO_URI%%:*} in
		rsync)	   ;;
		http)	   ;;
		ssh)	   ;;
		git+ssh)   ;;
		git)	   ;;
		*)
			die "${EGITN}: fetch from "${EGIT_REPO_URI%:*}" is not yet implemented."
			;;
	esac

	if [ ! -d "${EGIT_TOP_DIR}" ]; then
		debug-print "${FUNCNAME}: initial checkout. creating git directory"

		addwrite /
		mkdir -p "${EGIT_TOP_DIR}"      || die "${EGIT}: can't mkdir ${EGIT_TOP_DIR}."
		chmod -f o+rw "${EGIT_TOP_DIR}" || die "${EGIT}: can't chmod ${EGIT_TOP_DIR}."
		export SANDBOX_WRITE="${SANDBOX_WRITE%%:/}"
	fi

	cd -P "${EGIT_TOP_DIR}" || die "${EGIT}: can't chdir to ${EGIT_TOP_DIR}"

	# every time
	addwrite "${EGIT_TOP_DIR}"

	[ -z "${EGIT_REPO_URI##*/}" ] && EGIT_REPO_URI="${EGIT_REPO_URI%/}"
	EGIT_CO_DIR="${EGIT_PROJECT}/${EGIT_PROJECT}"
	if [ ! -d "${EGIT_CO_DIR}/.git" ]; then
		# first check out
		einfo "git check out start -->"
		einfo "   checkout from: ${EGIT_REPO_URI}"

		mkdir -p "${EGIT_PROJECT}"      || die "${EGIT}: can't mkdir ${EGIT_PROJECT}."
		chmod -f o+rw "${EGIT_PROJECT}" || die "${EGIT}: can't chmod ${EGIT_PROJECT}."
		cd "${EGIT_PROJECT}"
		${EGIT_FETCH_CMD} ${EGIT_REPO_URI} || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}."

		einfo "   checkouted in: ${EGIT_TOP_DIR}/${EGIT_CO_DIR}"
	else
		# update working copy
		einfo "git update start -->"
		einfo "   update from: ${EGIT_REPO_URI}"
		cd "${EGIT_CO_DIR}"
		${EGIT_UPDATE_CMD} || die "${EGIT}: can't update from ${EGIT_REPO_URI}."
		einfo "    updated in: ${EGIT_TOP_DIR}/${EGIT_CO_DIR}"
	fi

	# copy to the ${WORKDIR}
	cp -Rf "${EGIT_TOP_DIR}/${EGIT_CO_DIR}" "${S}" || die "${EGIT}: can't copy to ${S}."
	einfo "     copied to: ${S}"
	echo
}

function git_src_unpack()
{
	[ "${A}" != "" ] && unpack ${A}
	git_fetch || die "${EGIT}: unknown problem in git_fetch()."
}