/[gentoo-x86]/eclass/git-2.eclass
Gentoo

Diff of /eclass/git-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.12 Revision 1.28
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2012 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.12 2011/07/16 13:11:54 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.28 2012/01/19 16:53:39 mgorny Exp $
4 4
5# @ECLASS: git-2.eclass 5# @ECLASS: git-2.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Donnie Berkholz <dberkholz@gentoo.org> 7# Donnie Berkholz <dberkholz@gentoo.org>
8# Michał Górny <mgorny@gentoo.org>
8# @BLURB: Eclass for fetching and unpacking git repositories. 9# @BLURB: Eclass for fetching and unpacking git repositories.
9# @DESCRIPTION: 10# @DESCRIPTION:
10# Eclass for easing maitenance of live ebuilds using git as remote repository. 11# Eclass for easing maitenance of live ebuilds using git as remote repository.
11# Eclass support working with git submodules and branching. 12# Eclass support working with git submodules and branching.
12 13
55# EGIT_PROJECT="${EGIT_REPO_URI##*/}" 56# EGIT_PROJECT="${EGIT_REPO_URI##*/}"
56 57
57# @ECLASS-VARIABLE: EGIT_DIR 58# @ECLASS-VARIABLE: EGIT_DIR
58# @DESCRIPTION: 59# @DESCRIPTION:
59# Directory where we want to store the git data. 60# Directory where we want to store the git data.
60# This should not be overriden unless really required. 61# This variable should not be overriden.
61# 62#
62# EGIT_DIR="${EGIT_STORE_DIR}/${EGIT_PROJECT}" 63# EGIT_DIR="${EGIT_STORE_DIR}/${EGIT_PROJECT}"
63 64
64# @ECLASS-VARIABLE: EGIT_REPO_URI 65# @ECLASS-VARIABLE: EGIT_REPO_URI
65# @REQUIRED 66# @REQUIRED
111# @DESCRIPTION: 112# @DESCRIPTION:
112# If non-empty this variable specifies that all checkouts will be done using 113# If non-empty this variable specifies that all checkouts will be done using
113# non bare repositories. This is useful if you can't operate with bare 114# non bare repositories. This is useful if you can't operate with bare
114# checkouts for some reason. 115# checkouts for some reason.
115 116
117# @ECLASS-VARIABLE: EGIT_NOUNPACK
118# @DEFAULT_UNSET
119# @DESCRIPTION:
120# If non-empty this variable bans unpacking of ${A} content into the srcdir.
121# Default behaviour is to unpack ${A} content.
122
116# @FUNCTION: git-2_init_variables 123# @FUNCTION: git-2_init_variables
124# @INTERNAL
117# @DESCRIPTION: 125# @DESCRIPTION:
118# Internal function initializing all git variables. 126# Internal function initializing all git variables.
119# We define it in function scope so user can define 127# We define it in function scope so user can define
120# all the variables before and after inherit. 128# all the variables before and after inherit.
121git-2_init_variables() { 129git-2_init_variables() {
122 debug-print-function ${FUNCNAME} "$@" 130 debug-print-function ${FUNCNAME} "$@"
123 131
124 local x 132 local esc_pn liverepo livebranch livecommit
133 esc_pn=${PN//[-+]/_}
125 134
126 : ${EGIT_SOURCEDIR="${S}"} 135 : ${EGIT_SOURCEDIR="${S}"}
127 136
128 : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"} 137 : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"}
129 138
131 140
132 : ${EGIT_OPTIONS:=} 141 : ${EGIT_OPTIONS:=}
133 142
134 : ${EGIT_MASTER:=master} 143 : ${EGIT_MASTER:=master}
135 144
136 eval x="\$${PN//[-+]/_}_LIVE_REPO" 145 liverepo=${esc_pn}_LIVE_REPO
137 EGIT_REPO_URI=${x:-${EGIT_REPO_URI}} 146 EGIT_REPO_URI=${!liverepo:-${EGIT_REPO_URI}}
138 [[ -z ${EGIT_REPO_URI} ]] && die "EGIT_REPO_URI must have some value" 147 [[ ${EGIT_REPO_URI} ]] || die "EGIT_REPO_URI must have some value"
139 148
140 : ${EVCS_OFFLINE:=} 149 : ${EVCS_OFFLINE:=}
141 150
142 eval x="\$${PN//[-+]/_}_LIVE_BRANCH" 151 livebranch=${esc_pn}_LIVE_BRANCH
143 [[ -n ${x} ]] && ewarn "QA: using \"${PN//[-+]/_}_LIVE_BRANCH\" variable, you won't get any support" 152 [[ ${!livebranch} ]] && ewarn "QA: using \"${esc_pn}_LIVE_BRANCH\" variable, you won't get any support"
144 EGIT_BRANCH=${x:-${EGIT_BRANCH:-${EGIT_MASTER}}} 153 EGIT_BRANCH=${!livebranch:-${EGIT_BRANCH:-${EGIT_MASTER}}}
145 154
146 eval x="\$${PN//[-+]/_}_LIVE_COMMIT" 155 livecommit=${esc_pn}_LIVE_COMMIT
147 [[ -n ${x} ]] && ewarn "QA: using \"${PN//[-+]/_}_LIVE_COMMIT\" variable, you won't get any support" 156 [[ ${!livecommit} ]] && ewarn "QA: using \"${esc_pn}_LIVE_COMMIT\" variable, you won't get any support"
148 EGIT_COMMIT=${x:-${EGIT_COMMIT:-${EGIT_BRANCH}}} 157 EGIT_COMMIT=${!livecommit:-${EGIT_COMMIT:-${EGIT_BRANCH}}}
149 158
150 : ${EGIT_REPACK:=} 159 : ${EGIT_REPACK:=}
151 160
152 : ${EGIT_PRUNE:=} 161 : ${EGIT_PRUNE:=}
153} 162}
154 163
155# @FUNCTION: git-2_submodules 164# @FUNCTION: git-2_submodules
165# @INTERNAL
156# @DESCRIPTION: 166# @DESCRIPTION:
157# Internal function wrapping the submodule initialisation and update. 167# Internal function wrapping the submodule initialisation and update.
158git-2_submodules() { 168git-2_submodules() {
159 debug-print-function ${FUNCNAME} "$@" 169 debug-print-function ${FUNCNAME} "$@"
160 if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then 170 if [[ ${EGIT_HAS_SUBMODULES} ]]; then
161 if [[ -n ${EVCS_OFFLINE} ]]; then 171 if [[ ${EVCS_OFFLINE} ]]; then
162 # for submodules operations we need to be online 172 # for submodules operations we need to be online
163 debug-print "${FUNCNAME}: not updating submodules in offline mode" 173 debug-print "${FUNCNAME}: not updating submodules in offline mode"
164 return 1 174 return 1
165 fi 175 fi
166 176
177 popd > /dev/null 187 popd > /dev/null
178 fi 188 fi
179} 189}
180 190
181# @FUNCTION: git-2_branch 191# @FUNCTION: git-2_branch
192# @INTERNAL
182# @DESCRIPTION: 193# @DESCRIPTION:
183# Internal function that changes branch for the repo based on EGIT_COMMIT and 194# Internal function that changes branch for the repo based on EGIT_COMMIT and
184# EGIT_BRANCH variables. 195# EGIT_BRANCH variables.
185git-2_branch() { 196git-2_branch() {
186 debug-print-function ${FUNCNAME} "$@" 197 debug-print-function ${FUNCNAME} "$@"
198
199 local branchname src
187 200
188 debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\"" 201 debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\""
189 pushd "${EGIT_SOURCEDIR}" > /dev/null 202 pushd "${EGIT_SOURCEDIR}" > /dev/null
190 203
191 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH} 204 local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH}
196 debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}" 209 debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}"
197 git checkout -b ${branchname} ${src} \ 210 git checkout -b ${branchname} ${src} \
198 || die "${FUNCNAME}: changing the branch failed" 211 || die "${FUNCNAME}: changing the branch failed"
199 212
200 popd > /dev/null 213 popd > /dev/null
201
202 unset branchname src
203} 214}
204 215
205# @FUNCTION: git-2_gc 216# @FUNCTION: git-2_gc
217# @INTERNAL
206# @DESCRIPTION: 218# @DESCRIPTION:
207# Internal function running garbage collector on checked out tree. 219# Internal function running garbage collector on checked out tree.
208git-2_gc() { 220git-2_gc() {
209 debug-print-function ${FUNCNAME} "$@" 221 debug-print-function ${FUNCNAME} "$@"
210 222
223 local args
224
225 if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then
211 pushd "${EGIT_DIR}" > /dev/null 226 pushd "${EGIT_DIR}" > /dev/null
212 if [[ -n ${EGIT_REPACK} || -n ${EGIT_PRUNE} ]]; then
213 ebegin "Garbage collecting the repository" 227 ebegin "Garbage collecting the repository"
214 local args
215 [[ -n ${EGIT_PRUNE} ]] && args='--prune' 228 [[ ${EGIT_PRUNE} ]] && args='--prune'
216 debug-print "${FUNCNAME}: git gc ${args}" 229 debug-print "${FUNCNAME}: git gc ${args}"
217 git gc ${args} 230 git gc ${args}
218 eend $? 231 eend $?
219 fi
220 popd > /dev/null 232 popd > /dev/null
233 fi
221} 234}
222 235
223# @FUNCTION: git-2_prepare_storedir 236# @FUNCTION: git-2_prepare_storedir
237# @INTERNAL
224# @DESCRIPTION: 238# @DESCRIPTION:
225# Internal function preparing directory where we are going to store SCM 239# Internal function preparing directory where we are going to store SCM
226# repository. 240# repository.
227git-2_prepare_storedir() { 241git-2_prepare_storedir() {
228 debug-print-function ${FUNCNAME} "$@" 242 debug-print-function ${FUNCNAME} "$@"
232 # initial clone, we have to create master git storage directory and play 246 # initial clone, we have to create master git storage directory and play
233 # nicely with sandbox 247 # nicely with sandbox
234 if [[ ! -d ${EGIT_STORE_DIR} ]]; then 248 if [[ ! -d ${EGIT_STORE_DIR} ]]; then
235 debug-print "${FUNCNAME}: Creating git main storage directory" 249 debug-print "${FUNCNAME}: Creating git main storage directory"
236 addwrite / 250 addwrite /
237 mkdir -p "${EGIT_STORE_DIR}" \ 251 mkdir -m 775 -p "${EGIT_STORE_DIR}" \
238 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\"" 252 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\""
239 fi 253 fi
240 254
241 # allow writing into EGIT_STORE_DIR 255 # allow writing into EGIT_STORE_DIR
242 addwrite "${EGIT_STORE_DIR}" 256 addwrite "${EGIT_STORE_DIR}"
257
258 # calculate git.eclass store dir for data
259 # We will try to clone the old repository,
260 # and we will remove it if we don't need it anymore.
261 EGIT_OLD_CLONE=
262 if [[ ${EGIT_STORE_DIR} == */egit-src ]]; then
263 local old_store_dir=${EGIT_STORE_DIR/%egit-src/git-src}
264 local old_location=${old_store_dir}/${EGIT_PROJECT:-${PN}}
265
266 if [[ -d ${old_location} ]]; then
267 EGIT_OLD_CLONE=${old_location}
268 # required to remove the old clone
269 addwrite "${old_store_dir}"
270 fi
271 fi
272
243 # calculate the proper store dir for data 273 # calculate the proper store dir for data
244 # If user didn't specify the EGIT_DIR, we check if he did specify 274 # If user didn't specify the EGIT_DIR, we check if he did specify
245 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI. 275 # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI.
246 [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" 276 EGIT_REPO_URI=${EGIT_REPO_URI%/}
247 if [[ -z ${EGIT_DIR} ]]; then 277 if [[ ! ${EGIT_DIR} ]]; then
248 if [[ -n ${EGIT_PROJECT} ]]; then 278 if [[ ${EGIT_PROJECT} ]]; then
249 clone_dir=${EGIT_PROJECT} 279 clone_dir=${EGIT_PROJECT}
250 else 280 else
251 clone_dir=${EGIT_REPO_URI##*/} 281 local strippeduri=${EGIT_REPO_URI%/.git}
282 clone_dir=${strippeduri##*/}
252 fi 283 fi
253 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir} 284 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir}
285
286 if [[ ${EGIT_OLD_CLONE} && ! -d ${EGIT_DIR} ]]; then
287 elog "${FUNCNAME}: ${CATEGORY}/${PF} will be cloned from old location."
288 elog "It will be necessary to rebuild the package to fetch updates."
289 EGIT_REPO_URI="${EGIT_OLD_CLONE} ${EGIT_REPO_URI}"
290 fi
254 fi 291 fi
255 export EGIT_DIR=${EGIT_DIR} 292 export EGIT_DIR=${EGIT_DIR}
256 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"." 293 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"."
257} 294}
258 295
259# @FUNCTION: git-2_move_source 296# @FUNCTION: git-2_move_source
297# @INTERNAL
260# @DESCRIPTION: 298# @DESCRIPTION:
261# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir. 299# Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir.
262git-2_move_source() { 300git-2_move_source() {
263 debug-print-function ${FUNCNAME} "$@" 301 debug-print-function ${FUNCNAME} "$@"
264 302
270 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed" 308 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed"
271 popd > /dev/null 309 popd > /dev/null
272} 310}
273 311
274# @FUNCTION: git-2_initial_clone 312# @FUNCTION: git-2_initial_clone
313# @INTERNAL
275# @DESCRIPTION: 314# @DESCRIPTION:
276# Internal function running initial clone on specified repo_uri. 315# Internal function running initial clone on specified repo_uri.
277git-2_initial_clone() { 316git-2_initial_clone() {
278 debug-print-function ${FUNCNAME} "$@" 317 debug-print-function ${FUNCNAME} "$@"
279 318
280 local repo_uri 319 local repo_uri
281 320
282 EGIT_REPO_URI_SELECTED="" 321 EGIT_REPO_URI_SELECTED=""
283 for repo_uri in ${EGIT_REPO_URI}; do 322 for repo_uri in ${EGIT_REPO_URI}; do
284 debug-print "${FUNCNAME}: git clone ${EGIT_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" 323 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\""
285 git clone ${EGIT_OPTIONS} "${repo_uri}" "${EGIT_DIR}" 324 if git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"; then
286 if [[ $? -eq 0 ]]; then
287 # global variable containing the repo_name we will be using 325 # global variable containing the repo_name we will be using
288 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 326 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
289 EGIT_REPO_URI_SELECTED="${repo_uri}" 327 EGIT_REPO_URI_SELECTED="${repo_uri}"
290 break 328 break
291 fi 329 fi
292 done 330 done
293 331
294 if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then 332 [[ ${EGIT_REPO_URI_SELECTED} ]] \
295 die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" 333 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}"
296 fi
297} 334}
298 335
299# @FUNCTION: git-2_update_repo 336# @FUNCTION: git-2_update_repo
337# @INTERNAL
300# @DESCRIPTION: 338# @DESCRIPTION:
301# Internal function running update command on specified repo_uri. 339# Internal function running update command on specified repo_uri.
302git-2_update_repo() { 340git-2_update_repo() {
303 debug-print-function ${FUNCNAME} "$@" 341 debug-print-function ${FUNCNAME} "$@"
304 342
305 local repo_uri 343 local repo_uri
306 344
307 if [[ -n ${EGIT_NONBARE} ]]; then 345 if [[ ${EGIT_LOCAL_NONBARE} ]]; then
308 # checkout master branch and drop all other local branches 346 # checkout master branch and drop all other local branches
309 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}" 347 git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}"
310 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do 348 for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do
311 debug-print "${FUNCNAME}: git branch -D ${x}" 349 debug-print "${FUNCNAME}: git branch -D ${x}"
312 git branch -D ${x} > /dev/null 350 git branch -D ${x} > /dev/null
317 for repo_uri in ${EGIT_REPO_URI}; do 355 for repo_uri in ${EGIT_REPO_URI}; do
318 # git urls might change, so reset it 356 # git urls might change, so reset it
319 git config remote.origin.url "${repo_uri}" 357 git config remote.origin.url "${repo_uri}"
320 358
321 debug-print "${EGIT_UPDATE_CMD}" 359 debug-print "${EGIT_UPDATE_CMD}"
322 ${EGIT_UPDATE_CMD} > /dev/null 360 if ${EGIT_UPDATE_CMD} > /dev/null; then
323 if [[ $? -eq 0 ]]; then
324 # global variable containing the repo_name we will be using 361 # global variable containing the repo_name we will be using
325 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 362 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
326 EGIT_REPO_URI_SELECTED="${repo_uri}" 363 EGIT_REPO_URI_SELECTED="${repo_uri}"
327 break 364 break
328 fi 365 fi
329 done 366 done
330 367
331 if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then 368 [[ ${EGIT_REPO_URI_SELECTED} ]] \
332 die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" 369 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}"
333 fi
334} 370}
335 371
336# @FUNCTION: git-2_fetch 372# @FUNCTION: git-2_fetch
373# @INTERNAL
337# @DESCRIPTION: 374# @DESCRIPTION:
338# Internal function fetching repository from EGIT_REPO_URI and storing it in 375# Internal function fetching repository from EGIT_REPO_URI and storing it in
339# specified EGIT_STORE_DIR. 376# specified EGIT_STORE_DIR.
340git-2_fetch() { 377git-2_fetch() {
341 debug-print-function ${FUNCNAME} "$@" 378 debug-print-function ${FUNCNAME} "$@"
342 379
343 local oldsha cursha repo_type 380 local oldsha cursha repo_type
344 381
345 [[ -n ${EGIT_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository" 382 [[ ${EGIT_LOCAL_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository"
346 383
347 if [[ ! -d ${EGIT_DIR} ]]; then 384 if [[ ! -d ${EGIT_DIR} ]]; then
348 git-2_initial_clone 385 git-2_initial_clone
349 pushd "${EGIT_DIR}" > /dev/null 386 pushd "${EGIT_DIR}" > /dev/null
350 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 387 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
351 echo "GIT NEW clone -->" 388 echo "GIT NEW clone -->"
352 echo " repository: ${EGIT_REPO_URI_SELECTED}" 389 echo " repository: ${EGIT_REPO_URI_SELECTED}"
353 echo " at the commit: ${cursha}" 390 echo " at the commit: ${cursha}"
354 391
355 popd > /dev/null 392 popd > /dev/null
356 elif [[ -n ${EVCS_OFFLINE} ]]; then 393 elif [[ ${EVCS_OFFLINE} ]]; then
357 pushd "${EGIT_DIR}" > /dev/null 394 pushd "${EGIT_DIR}" > /dev/null
358 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 395 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
359 echo "GIT offline update -->" 396 echo "GIT offline update -->"
360 echo " repository: $(git config remote.origin.url)" 397 echo " repository: $(git config remote.origin.url)"
361 echo " at the commit: ${cursha}" 398 echo " at the commit: ${cursha}"
387 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \ 424 [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \
388 && echo " commit: ${EGIT_COMMIT}" 425 && echo " commit: ${EGIT_COMMIT}"
389 echo " branch: ${EGIT_BRANCH}" 426 echo " branch: ${EGIT_BRANCH}"
390 echo " storage directory: \"${EGIT_DIR}\"" 427 echo " storage directory: \"${EGIT_DIR}\""
391 echo " checkout type: ${repo_type}" 428 echo " checkout type: ${repo_type}"
429
430 # Cleanup after git.eclass
431 if [[ ${EGIT_OLD_CLONE} ]]; then
432 einfo "${FUNCNAME}: removing old clone in ${EGIT_OLD_CLONE}."
433 rm -rf "${EGIT_OLD_CLONE}"
434 fi
392} 435}
393 436
394# @FUNCTION: git_bootstrap 437# @FUNCTION: git_bootstrap
438# @INTERNAL
395# @DESCRIPTION: 439# @DESCRIPTION:
396# Internal function that runs bootstrap command on unpacked source. 440# Internal function that runs bootstrap command on unpacked source.
397git-2_bootstrap() { 441git-2_bootstrap() {
398 debug-print-function ${FUNCNAME} "$@" 442 debug-print-function ${FUNCNAME} "$@"
399 443
400 # @ECLASS_VARIABLE: EGIT_BOOTSTRAP 444 # @ECLASS-VARIABLE: EGIT_BOOTSTRAP
401 # @DESCRIPTION: 445 # @DESCRIPTION:
402 # Command to be executed after checkout and clone of the specified 446 # Command to be executed after checkout and clone of the specified
403 # repository. 447 # repository.
404 # enviroment the package will fail if there is no update, thus in 448 # enviroment the package will fail if there is no update, thus in
405 # combination with --keep-going it would lead in not-updating 449 # combination with --keep-going it would lead in not-updating
406 # pakcages that are up-to-date. 450 # pakcages that are up-to-date.
407 if [[ -n ${EGIT_BOOTSTRAP} ]]; then 451 if [[ ${EGIT_BOOTSTRAP} ]]; then
408 pushd "${EGIT_SOURCEDIR}" > /dev/null 452 pushd "${EGIT_SOURCEDIR}" > /dev/null
409 einfo "Starting bootstrap" 453 einfo "Starting bootstrap"
410 454
411 if [[ -f ${EGIT_BOOTSTRAP} ]]; then 455 if [[ -f ${EGIT_BOOTSTRAP} ]]; then
412 # we have file in the repo which we should execute 456 # we have file in the repo which we should execute
432 popd > /dev/null 476 popd > /dev/null
433 fi 477 fi
434} 478}
435 479
436# @FUNCTION: git-2_migrate_repository 480# @FUNCTION: git-2_migrate_repository
481# @INTERNAL
437# @DESCRIPTION: 482# @DESCRIPTION:
438# Internal function migrating between bare and normal checkout repository. 483# Internal function migrating between bare and normal checkout repository.
439# This is based on usage of EGIT_SUBMODULES, at least until they 484# This is based on usage of EGIT_SUBMODULES, at least until they
440# start to work with bare checkouts sanely. 485# start to work with bare checkouts sanely.
486# This function also set some global variables that differ between
487# bare and non-bare checkout.
441git-2_migrate_repository() { 488git-2_migrate_repository() {
442 debug-print-function ${FUNCNAME} "$@" 489 debug-print-function ${FUNCNAME} "$@"
443 490
444 local target returnstate 491 local bare returnstate
445 492
446 # first find out if we have submodules 493 # first find out if we have submodules
494 # or user explicitly wants us to use non-bare clones
447 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then 495 if ! [[ ${EGIT_HAS_SUBMODULES} || ${EGIT_NONBARE} ]]; then
448 target="bare" 496 bare=1
449 else
450 target="full"
451 fi 497 fi
452 [[ -n ${EGIT_NONBARE} ]] && target="full"
453 498
454 # test if we already have some repo and if so find out if we have 499 # test if we already have some repo and if so find out if we have
455 # to migrate the data 500 # to migrate the data
456 if [[ -d ${EGIT_DIR} ]]; then 501 if [[ -d ${EGIT_DIR} ]]; then
457 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then 502 if [[ ${bare} && -d ${EGIT_DIR}/.git ]]; then
458 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" 503 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy"
459 504
460 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" 505 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy"
461 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" 506 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare"
462 export GIT_DIR="${EGIT_DIR}.bare" 507 export GIT_DIR="${EGIT_DIR}.bare"
464 returnstate=$? 509 returnstate=$?
465 unset GIT_DIR 510 unset GIT_DIR
466 rm -rf "${EGIT_DIR}" 511 rm -rf "${EGIT_DIR}"
467 mv "${EGIT_DIR}.bare" "${EGIT_DIR}" 512 mv "${EGIT_DIR}.bare" "${EGIT_DIR}"
468 eend ${returnstate} 513 eend ${returnstate}
469 fi
470 if [[ ${target} == full && ! -d ${EGIT_DIR}/.git ]]; then 514 elif [[ ! ${bare} && ! -d ${EGIT_DIR}/.git ]]; then
471 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" 515 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy"
472 516
473 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" 517 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy"
474 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null 518 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null
475 returnstate=$? 519 returnstate=$?
485 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." 529 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch."
486 rm -rf "${EGIT_DIR}" 530 rm -rf "${EGIT_DIR}"
487 fi 531 fi
488 532
489 # set various options to work with both targets 533 # set various options to work with both targets
490 if [[ ${target} == bare ]]; then 534 if [[ ${bare} ]]; then
491 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 535 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
492 EGIT_OPTIONS+=" --bare" 536 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
493 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 537 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
494 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" 538 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
495 UPSTREAM_BRANCH="${EGIT_BRANCH}" 539 UPSTREAM_BRANCH="${EGIT_BRANCH}"
540 EGIT_LOCAL_NONBARE=
496 else 541 else
497 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\"" 542 debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\""
498 MOVE_COMMAND="cp -pPR ." 543 MOVE_COMMAND="cp -pPR ."
544 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
499 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 545 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
500 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}" 546 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}"
501 EGIT_NONBARE="true" 547 EGIT_LOCAL_NONBARE="true"
502 fi 548 fi
549}
550
551# @FUNCTION: git-2_cleanup
552# @INTERNAL
553# @DESCRIPTION:
554# Internal function cleaning up all the global variables
555# that are not required after the unpack has been done.
556git-2_cleanup() {
557 debug-print-function ${FUNCNAME} "$@"
558
559 # Here we can unset only variables that are GLOBAL
560 # defined by the eclass, BUT NOT subject to change
561 # by user (like EGIT_PROJECT).
562 # If ebuild writer polutes his environment it is
563 # his problem only.
564 unset EGIT_DIR
565 unset MOVE_COMMAND
566 unset EGIT_LOCAL_OPTIONS
567 unset EGIT_UPDATE_CMD
568 unset UPSTREAM_BRANCH
569 unset EGIT_LOCAL_NONBARE
503} 570}
504 571
505# @FUNCTION: git-2_src_unpack 572# @FUNCTION: git-2_src_unpack
506# @DESCRIPTION: 573# @DESCRIPTION:
507# Default git src_unpack function. 574# Default git src_unpack function.
515 git-2_gc 582 git-2_gc
516 git-2_submodules 583 git-2_submodules
517 git-2_move_source 584 git-2_move_source
518 git-2_branch 585 git-2_branch
519 git-2_bootstrap 586 git-2_bootstrap
587 git-2_cleanup
520 echo ">>> Unpacked to ${EGIT_SOURCEDIR}" 588 echo ">>> Unpacked to ${EGIT_SOURCEDIR}"
521 589
522 # Users can specify some SRC_URI and we should 590 # Users can specify some SRC_URI and we should
523 # unpack the files too. 591 # unpack the files too.
592 if [[ ! ${EGIT_NOUNPACK} ]]; then
524 if has ${EAPI:-0} 0 1; then 593 if has ${EAPI:-0} 0 1; then
525 [[ -n ${A} ]] && unpack ${A} 594 [[ ${A} ]] && unpack ${A}
526 else 595 else
527 default_src_unpack 596 default_src_unpack
528 fi 597 fi
598 fi
529} 599}

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.28

  ViewVC Help
Powered by ViewVC 1.1.20