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

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.24

  ViewVC Help
Powered by ViewVC 1.1.20