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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.20