/[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.7 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.7 2011/05/20 14:35:01 scarabeus 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# Tomas Chvatal <scarabeus@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.
9# @DESCRIPTION: 9# @DESCRIPTION:
10# Eclass for easing maitenance of live ebuilds using git as remote repository. 10# Eclass for easing maitenance of live ebuilds using git as remote repository.
11# Eclass support working with git submodules and branching. 11# Eclass support working with git submodules and branching.
12 12
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} "$@"
236 addwrite / 249 addwrite /
237 mkdir -p "${EGIT_STORE_DIR}" \ 250 mkdir -p "${EGIT_STORE_DIR}" \
238 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\"" 251 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\""
239 fi 252 fi
240 253
241 cd -P "${EGIT_STORE_DIR}" \
242 || die "${FUNCNAME}: can't chdir to \"${EGIT_STORE_DIR}\""
243 # allow writing into EGIT_STORE_DIR 254 # allow writing into EGIT_STORE_DIR
244 addwrite "${EGIT_STORE_DIR}" 255 addwrite "${EGIT_STORE_DIR}"
245 # calculate the proper store dir for data 256 # calculate the proper store dir for data
246 # 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
247 # 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.
248 [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" 259 EGIT_REPO_URI=${EGIT_REPO_URI%/}
249 if [[ -z ${EGIT_DIR} ]]; then 260 if [[ ! ${EGIT_DIR} ]]; then
250 if [[ -n ${EGIT_PROJECT} ]]; then 261 if [[ ${EGIT_PROJECT} ]]; then
251 clone_dir=${EGIT_PROJECT} 262 clone_dir=${EGIT_PROJECT}
252 else 263 else
253 clone_dir=${EGIT_REPO_URI##*/} 264 clone_dir=${EGIT_REPO_URI##*/}
254 fi 265 fi
255 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
256 fi 279 fi
257 export EGIT_DIR=${EGIT_DIR} 280 export EGIT_DIR=${EGIT_DIR}
258 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"." 281 debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"."
259} 282}
260 283
261# @FUNCTION: git-2_move_source 284# @FUNCTION: git-2_move_source
285# @INTERNAL
262# @DESCRIPTION: 286# @DESCRIPTION:
263# 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.
264git-2_move_source() { 288git-2_move_source() {
265 debug-print-function ${FUNCNAME} "$@" 289 debug-print-function ${FUNCNAME} "$@"
266 290
272 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed" 296 || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed"
273 popd > /dev/null 297 popd > /dev/null
274} 298}
275 299
276# @FUNCTION: git-2_initial_clone 300# @FUNCTION: git-2_initial_clone
301# @INTERNAL
277# @DESCRIPTION: 302# @DESCRIPTION:
278# Internal function running initial clone on specified repo_uri. 303# Internal function running initial clone on specified repo_uri.
279git-2_initial_clone() { 304git-2_initial_clone() {
280 debug-print-function ${FUNCNAME} "$@" 305 debug-print-function ${FUNCNAME} "$@"
281 306
282 local repo_uri 307 local repo_uri
283 308
284 EGIT_REPO_URI_SELECTED="" 309 EGIT_REPO_URI_SELECTED=""
285 for repo_uri in ${EGIT_REPO_URI}; do 310 for repo_uri in ${EGIT_REPO_URI}; do
286 debug-print "${FUNCNAME}: git clone ${EGIT_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" 311 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\""
287 git clone ${EGIT_OPTIONS} "${repo_uri}" "${EGIT_DIR}" 312 if git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"; then
288 if [[ $? -eq 0 ]]; then
289 # global variable containing the repo_name we will be using 313 # global variable containing the repo_name we will be using
290 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 314 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
291 EGIT_REPO_URI_SELECTED="${repo_uri}" 315 EGIT_REPO_URI_SELECTED="${repo_uri}"
292 break 316 break
293 fi 317 fi
294 done 318 done
295 319
296 if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then 320 [[ ${EGIT_REPO_URI_SELECTED} ]] \
297 die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" 321 || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}"
298 fi
299} 322}
300 323
301# @FUNCTION: git-2_update_repo 324# @FUNCTION: git-2_update_repo
325# @INTERNAL
302# @DESCRIPTION: 326# @DESCRIPTION:
303# Internal function running update command on specified repo_uri. 327# Internal function running update command on specified repo_uri.
304git-2_update_repo() { 328git-2_update_repo() {
305 debug-print-function ${FUNCNAME} "$@" 329 debug-print-function ${FUNCNAME} "$@"
306 330
307 local repo_uri 331 local repo_uri
308 332
309 if [[ -n ${EGIT_NONBARE} ]]; then 333 if [[ ${EGIT_LOCAL_NONBARE} ]]; then
310 # checkout master branch and drop all other local branches 334 # checkout master branch and drop all other local branches
311 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}"
312 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
313 debug-print "${FUNCNAME}: git branch -D ${x}" 337 debug-print "${FUNCNAME}: git branch -D ${x}"
314 git branch -D ${x} > /dev/null 338 git branch -D ${x} > /dev/null
319 for repo_uri in ${EGIT_REPO_URI}; do 343 for repo_uri in ${EGIT_REPO_URI}; do
320 # git urls might change, so reset it 344 # git urls might change, so reset it
321 git config remote.origin.url "${repo_uri}" 345 git config remote.origin.url "${repo_uri}"
322 346
323 debug-print "${EGIT_UPDATE_CMD}" 347 debug-print "${EGIT_UPDATE_CMD}"
324 ${EGIT_UPDATE_CMD} > /dev/null 348 if ${EGIT_UPDATE_CMD} > /dev/null; then
325 if [[ $? -eq 0 ]]; then
326 # global variable containing the repo_name we will be using 349 # global variable containing the repo_name we will be using
327 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" 350 debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
328 EGIT_REPO_URI_SELECTED="${repo_uri}" 351 EGIT_REPO_URI_SELECTED="${repo_uri}"
329 break 352 break
330 fi 353 fi
331 done 354 done
332 355
333 if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then 356 [[ ${EGIT_REPO_URI_SELECTED} ]] \
334 die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" 357 || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}"
335 fi
336} 358}
337 359
338# @FUNCTION: git-2_fetch 360# @FUNCTION: git-2_fetch
361# @INTERNAL
339# @DESCRIPTION: 362# @DESCRIPTION:
340# 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
341# specified EGIT_STORE_DIR. 364# specified EGIT_STORE_DIR.
342git-2_fetch() { 365git-2_fetch() {
343 debug-print-function ${FUNCNAME} "$@" 366 debug-print-function ${FUNCNAME} "$@"
344 367
345 local oldsha cursha repo_type 368 local oldsha cursha repo_type
346 369
347 [[ -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"
348 371
349 if [[ ! -d ${EGIT_DIR} ]]; then 372 if [[ ! -d ${EGIT_DIR} ]]; then
350 git-2_initial_clone 373 git-2_initial_clone
351 pushd "${EGIT_DIR}" > /dev/null 374 pushd "${EGIT_DIR}" > /dev/null
352 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 375 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
353 echo "GIT NEW clone -->" 376 echo "GIT NEW clone -->"
354 echo " repository: ${EGIT_REPO_URI_SELECTED}" 377 echo " repository: ${EGIT_REPO_URI_SELECTED}"
355 echo " at the commit: ${cursha}" 378 echo " at the commit: ${cursha}"
356 379
357 popd > /dev/null 380 popd > /dev/null
358 elif [[ -n ${EVCS_OFFLINE} ]]; then 381 elif [[ ${EVCS_OFFLINE} ]]; then
359 pushd "${EGIT_DIR}" > /dev/null 382 pushd "${EGIT_DIR}" > /dev/null
360 cursha=$(git rev-parse ${UPSTREAM_BRANCH}) 383 cursha=$(git rev-parse ${UPSTREAM_BRANCH})
361 echo "GIT offline update -->" 384 echo "GIT offline update -->"
362 echo " repository: $(git config remote.origin.url)" 385 echo " repository: $(git config remote.origin.url)"
363 echo " at the commit: ${cursha}" 386 echo " at the commit: ${cursha}"
392 echo " storage directory: \"${EGIT_DIR}\"" 415 echo " storage directory: \"${EGIT_DIR}\""
393 echo " checkout type: ${repo_type}" 416 echo " checkout type: ${repo_type}"
394} 417}
395 418
396# @FUNCTION: git_bootstrap 419# @FUNCTION: git_bootstrap
420# @INTERNAL
397# @DESCRIPTION: 421# @DESCRIPTION:
398# Internal function that runs bootstrap command on unpacked source. 422# Internal function that runs bootstrap command on unpacked source.
399git-2_bootstrap() { 423git-2_bootstrap() {
400 debug-print-function ${FUNCNAME} "$@" 424 debug-print-function ${FUNCNAME} "$@"
401 425
402 # @ECLASS_VARIABLE: EGIT_BOOTSTRAP 426 # @ECLASS-VARIABLE: EGIT_BOOTSTRAP
403 # @DESCRIPTION: 427 # @DESCRIPTION:
404 # Command to be executed after checkout and clone of the specified 428 # Command to be executed after checkout and clone of the specified
405 # repository. 429 # repository.
406 # 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
407 # combination with --keep-going it would lead in not-updating 431 # combination with --keep-going it would lead in not-updating
408 # pakcages that are up-to-date. 432 # pakcages that are up-to-date.
409 if [[ -n ${EGIT_BOOTSTRAP} ]]; then 433 if [[ ${EGIT_BOOTSTRAP} ]]; then
410 pushd "${EGIT_SOURCEDIR}" > /dev/null 434 pushd "${EGIT_SOURCEDIR}" > /dev/null
411 einfo "Starting bootstrap" 435 einfo "Starting bootstrap"
412 436
413 if [[ -f ${EGIT_BOOTSTRAP} ]]; then 437 if [[ -f ${EGIT_BOOTSTRAP} ]]; then
414 # we have file in the repo which we should execute 438 # we have file in the repo which we should execute
434 popd > /dev/null 458 popd > /dev/null
435 fi 459 fi
436} 460}
437 461
438# @FUNCTION: git-2_migrate_repository 462# @FUNCTION: git-2_migrate_repository
463# @INTERNAL
439# @DESCRIPTION: 464# @DESCRIPTION:
440# Internal function migrating between bare and normal checkout repository. 465# Internal function migrating between bare and normal checkout repository.
441# 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
442# 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.
443git-2_migrate_repository() { 470git-2_migrate_repository() {
444 debug-print-function ${FUNCNAME} "$@" 471 debug-print-function ${FUNCNAME} "$@"
445 472
446 local target returnstate 473 local bare returnstate
447 474
448 # 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
449 if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then 477 if ! [[ ${EGIT_HAS_SUBMODULES} || ${EGIT_NONBARE} ]]; then
450 target="bare" 478 bare=1
451 else
452 target="full"
453 fi 479 fi
454 [[ -n ${EGIT_NONBARE} ]] && target="full"
455 480
456 # 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
457 # to migrate the data 482 # to migrate the data
458 if [[ -d ${EGIT_DIR} ]]; then 483 if [[ -d ${EGIT_DIR} ]]; then
459 if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then 484 if [[ ${bare} && -d ${EGIT_DIR}/.git ]]; then
460 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" 485 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy"
461 486
462 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" 487 ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy"
463 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" 488 mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare"
464 export GIT_DIR="${EGIT_DIR}.bare" 489 export GIT_DIR="${EGIT_DIR}.bare"
466 returnstate=$? 491 returnstate=$?
467 unset GIT_DIR 492 unset GIT_DIR
468 rm -rf "${EGIT_DIR}" 493 rm -rf "${EGIT_DIR}"
469 mv "${EGIT_DIR}.bare" "${EGIT_DIR}" 494 mv "${EGIT_DIR}.bare" "${EGIT_DIR}"
470 eend ${returnstate} 495 eend ${returnstate}
471 fi
472 if [[ ${target} == full && ! -d ${EGIT_DIR}/.git ]]; then 496 elif [[ ! ${bare} && ! -d ${EGIT_DIR}/.git ]]; then
473 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" 497 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy"
474 498
475 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" 499 ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy"
476 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null 500 git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null
477 returnstate=$? 501 returnstate=$?
487 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." 511 einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch."
488 rm -rf "${EGIT_DIR}" 512 rm -rf "${EGIT_DIR}"
489 fi 513 fi
490 514
491 # set various options to work with both targets 515 # set various options to work with both targets
492 if [[ ${target} == bare ]]; then 516 if [[ ${bare} ]]; then
493 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" 517 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
494 EGIT_OPTIONS+=" --bare" 518 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
495 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" 519 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
496 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}"
497 UPSTREAM_BRANCH="${EGIT_BRANCH}" 521 UPSTREAM_BRANCH="${EGIT_BRANCH}"
522 EGIT_LOCAL_NONBARE=
498 else 523 else
499 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}\""
500 MOVE_COMMAND="cp -pPR ." 525 MOVE_COMMAND="cp -pPR ."
526 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
501 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" 527 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
502 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}" 528 UPSTREAM_BRANCH="origin/${EGIT_BRANCH}"
503 EGIT_NONBARE="true" 529 EGIT_LOCAL_NONBARE="true"
504 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
505} 552}
506 553
507# @FUNCTION: git-2_src_unpack 554# @FUNCTION: git-2_src_unpack
508# @DESCRIPTION: 555# @DESCRIPTION:
509# Default git src_unpack function. 556# Default git src_unpack function.
517 git-2_gc 564 git-2_gc
518 git-2_submodules 565 git-2_submodules
519 git-2_move_source 566 git-2_move_source
520 git-2_branch 567 git-2_branch
521 git-2_bootstrap 568 git-2_bootstrap
569 git-2_cleanup
522 echo ">>> Unpacked to ${EGIT_SOURCEDIR}" 570 echo ">>> Unpacked to ${EGIT_SOURCEDIR}"
571
572 # Users can specify some SRC_URI and we should
573 # unpack the files too.
574 if [[ ! ${EGIT_NOUNPACK} ]]; then
575 if has ${EAPI:-0} 0 1; then
576 [[ ${A} ]] && unpack ${A}
577 else
578 default_src_unpack
579 fi
580 fi
523} 581}

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

  ViewVC Help
Powered by ViewVC 1.1.20