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

Contents of /eclass/git-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.27 - (hide annotations) (download)
Wed Dec 14 23:40:18 2011 UTC (2 years, 8 months ago) by vapier
Branch: MAIN
Changes since 1.26: +2 -2 lines
create backing store dirs with group write perms so that people can more easily switch between user based testing (ebuild/etc...) and root/userpriv based emerging

1 scarabeus 1.1 # Copyright 1999-2011 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 vapier 1.27 # $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.26 2011/09/23 14:10:47 mgorny Exp $
4 scarabeus 1.1
5     # @ECLASS: git-2.eclass
6     # @MAINTAINER:
7 dberkholz 1.11 # Donnie Berkholz <dberkholz@gentoo.org>
8 mgorny 1.26 # Michał Górny <mgorny@gentoo.org>
9 scarabeus 1.1 # @BLURB: Eclass for fetching and unpacking git repositories.
10     # @DESCRIPTION:
11     # Eclass for easing maitenance of live ebuilds using git as remote repository.
12     # Eclass support working with git submodules and branching.
13    
14     # This eclass support all EAPIs
15     EXPORT_FUNCTIONS src_unpack
16    
17     DEPEND="dev-vcs/git"
18    
19     # @ECLASS-VARIABLE: EGIT_SOURCEDIR
20     # @DESCRIPTION:
21     # This variable specifies destination where the cloned
22     # data are copied to.
23     #
24     # EGIT_SOURCEDIR="${S}"
25    
26     # @ECLASS-VARIABLE: EGIT_STORE_DIR
27     # @DESCRIPTION:
28     # Storage directory for git sources.
29     #
30     # EGIT_STORE_DIR="${DISTDIR}/egit-src"
31    
32     # @ECLASS-VARIABLE: EGIT_HAS_SUBMODULES
33     # @DEFAULT_UNSET
34     # @DESCRIPTION:
35     # If non-empty this variable enables support for git submodules in our
36     # checkout. Also this makes the checkout to be non-bare for now.
37    
38     # @ECLASS-VARIABLE: EGIT_OPTIONS
39     # @DEFAULT_UNSET
40     # @DESCRIPTION:
41     # Variable specifying additional options for fetch command.
42    
43     # @ECLASS-VARIABLE: EGIT_MASTER
44     # @DESCRIPTION:
45     # Variable for specifying master branch.
46     # Usefull when upstream don't have master branch or name it differently.
47     #
48     # EGIT_MASTER="master"
49    
50 scarabeus 1.6 # @ECLASS-VARIABLE: EGIT_PROJECT
51     # @DESCRIPTION:
52     # Variable specifying name for the folder where we check out the git
53     # repository. Value of this variable should be unique in the
54     # EGIT_STORE_DIR as otherwise you would override another repository.
55     #
56     # EGIT_PROJECT="${EGIT_REPO_URI##*/}"
57    
58 scarabeus 1.1 # @ECLASS-VARIABLE: EGIT_DIR
59     # @DESCRIPTION:
60     # Directory where we want to store the git data.
61 scarabeus 1.13 # This variable should not be overriden.
62 scarabeus 1.1 #
63 scarabeus 1.6 # EGIT_DIR="${EGIT_STORE_DIR}/${EGIT_PROJECT}"
64 scarabeus 1.1
65     # @ECLASS-VARIABLE: EGIT_REPO_URI
66     # @REQUIRED
67     # @DEFAULT_UNSET
68     # @DESCRIPTION:
69     # URI for the repository
70     # e.g. http://foo, git://bar
71     #
72     # Support multiple values:
73     # EGIT_REPO_URI="git://a/b.git http://c/d.git"
74    
75     # @ECLASS-VARIABLE: EVCS_OFFLINE
76     # @DEFAULT_UNSET
77     # @DESCRIPTION:
78     # If non-empty this variable prevents performance of any online
79     # operations.
80    
81     # @ECLASS-VARIABLE: EGIT_BRANCH
82     # @DESCRIPTION:
83     # Variable containing branch name we want to check out.
84     # It can be overriden via env using packagename_LIVE_BRANCH
85     # variable.
86     #
87     # EGIT_BRANCH="${EGIT_MASTER}"
88    
89     # @ECLASS-VARIABLE: EGIT_COMMIT
90     # @DESCRIPTION:
91     # Variable containing commit hash/tag we want to check out.
92     # It can be overriden via env using packagename_LIVE_COMMIT
93     # variable.
94     #
95 scarabeus 1.4 # EGIT_COMMIT="${EGIT_BRANCH}"
96 scarabeus 1.1
97     # @ECLASS-VARIABLE: EGIT_REPACK
98     # @DEFAULT_UNSET
99     # @DESCRIPTION:
100     # If non-empty this variable specifies that repository will be repacked to
101     # save space. However this can take a REALLY LONG time with VERY big
102     # repositories.
103    
104     # @ECLASS-VARIABLE: EGIT_PRUNE
105     # @DEFAULT_UNSET
106     # @DESCRIPTION:
107     # If non-empty this variable enables pruning all loose objects on each fetch.
108     # This is useful if upstream rewinds and rebases branches often.
109    
110     # @ECLASS-VARIABLE: EGIT_NONBARE
111     # @DEFAULT_UNSET
112     # @DESCRIPTION:
113     # If non-empty this variable specifies that all checkouts will be done using
114     # non bare repositories. This is useful if you can't operate with bare
115     # checkouts for some reason.
116    
117 scarabeus 1.13 # @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    
123 scarabeus 1.1 # @FUNCTION: git-2_init_variables
124 mgorny 1.22 # @INTERNAL
125 scarabeus 1.1 # @DESCRIPTION:
126     # Internal function initializing all git variables.
127     # We define it in function scope so user can define
128     # all the variables before and after inherit.
129     git-2_init_variables() {
130     debug-print-function ${FUNCNAME} "$@"
131    
132 mgorny 1.15 local esc_pn liverepo livebranch livecommit
133     esc_pn=${PN//[-+]/_}
134 scarabeus 1.1
135     : ${EGIT_SOURCEDIR="${S}"}
136    
137     : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"}
138    
139     : ${EGIT_HAS_SUBMODULES:=}
140    
141     : ${EGIT_OPTIONS:=}
142    
143     : ${EGIT_MASTER:=master}
144    
145 mgorny 1.15 liverepo=${esc_pn}_LIVE_REPO
146     EGIT_REPO_URI=${!liverepo:-${EGIT_REPO_URI}}
147 mgorny 1.17 [[ ${EGIT_REPO_URI} ]] || die "EGIT_REPO_URI must have some value"
148 scarabeus 1.1
149     : ${EVCS_OFFLINE:=}
150    
151 mgorny 1.15 livebranch=${esc_pn}_LIVE_BRANCH
152 mgorny 1.17 [[ ${!livebranch} ]] && ewarn "QA: using \"${esc_pn}_LIVE_BRANCH\" variable, you won't get any support"
153 mgorny 1.15 EGIT_BRANCH=${!livebranch:-${EGIT_BRANCH:-${EGIT_MASTER}}}
154    
155     livecommit=${esc_pn}_LIVE_COMMIT
156 mgorny 1.17 [[ ${!livecommit} ]] && ewarn "QA: using \"${esc_pn}_LIVE_COMMIT\" variable, you won't get any support"
157 mgorny 1.15 EGIT_COMMIT=${!livecommit:-${EGIT_COMMIT:-${EGIT_BRANCH}}}
158 scarabeus 1.1
159     : ${EGIT_REPACK:=}
160    
161     : ${EGIT_PRUNE:=}
162     }
163    
164     # @FUNCTION: git-2_submodules
165 mgorny 1.22 # @INTERNAL
166 scarabeus 1.1 # @DESCRIPTION:
167     # Internal function wrapping the submodule initialisation and update.
168     git-2_submodules() {
169     debug-print-function ${FUNCNAME} "$@"
170 mgorny 1.17 if [[ ${EGIT_HAS_SUBMODULES} ]]; then
171     if [[ ${EVCS_OFFLINE} ]]; then
172 scarabeus 1.1 # for submodules operations we need to be online
173     debug-print "${FUNCNAME}: not updating submodules in offline mode"
174     return 1
175     fi
176    
177     debug-print "${FUNCNAME}: working in \"${1}\""
178     pushd "${EGIT_DIR}" > /dev/null
179    
180     debug-print "${FUNCNAME}: git submodule init"
181     git submodule init || die
182     debug-print "${FUNCNAME}: git submodule sync"
183     git submodule sync || die
184     debug-print "${FUNCNAME}: git submodule update"
185     git submodule update || die
186    
187     popd > /dev/null
188     fi
189     }
190    
191     # @FUNCTION: git-2_branch
192 mgorny 1.22 # @INTERNAL
193 scarabeus 1.1 # @DESCRIPTION:
194     # Internal function that changes branch for the repo based on EGIT_COMMIT and
195     # EGIT_BRANCH variables.
196     git-2_branch() {
197     debug-print-function ${FUNCNAME} "$@"
198    
199 scarabeus 1.13 local branchname src
200    
201 scarabeus 1.1 debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\""
202     pushd "${EGIT_SOURCEDIR}" > /dev/null
203    
204     local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH}
205     if [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]]; then
206     branchname=tree-${EGIT_COMMIT}
207     src=${EGIT_COMMIT}
208     fi
209     debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}"
210     git checkout -b ${branchname} ${src} \
211     || die "${FUNCNAME}: changing the branch failed"
212    
213     popd > /dev/null
214     }
215    
216     # @FUNCTION: git-2_gc
217 mgorny 1.22 # @INTERNAL
218 scarabeus 1.1 # @DESCRIPTION:
219     # Internal function running garbage collector on checked out tree.
220     git-2_gc() {
221     debug-print-function ${FUNCNAME} "$@"
222    
223 scarabeus 1.13 local args
224    
225 mgorny 1.17 if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then
226 mgorny 1.21 pushd "${EGIT_DIR}" > /dev/null
227 scarabeus 1.1 ebegin "Garbage collecting the repository"
228 mgorny 1.17 [[ ${EGIT_PRUNE} ]] && args='--prune'
229 scarabeus 1.1 debug-print "${FUNCNAME}: git gc ${args}"
230     git gc ${args}
231     eend $?
232 mgorny 1.21 popd > /dev/null
233 scarabeus 1.1 fi
234     }
235    
236     # @FUNCTION: git-2_prepare_storedir
237 mgorny 1.22 # @INTERNAL
238 scarabeus 1.1 # @DESCRIPTION:
239     # Internal function preparing directory where we are going to store SCM
240     # repository.
241     git-2_prepare_storedir() {
242     debug-print-function ${FUNCNAME} "$@"
243    
244     local clone_dir
245    
246     # initial clone, we have to create master git storage directory and play
247     # nicely with sandbox
248     if [[ ! -d ${EGIT_STORE_DIR} ]]; then
249     debug-print "${FUNCNAME}: Creating git main storage directory"
250     addwrite /
251 vapier 1.27 mkdir -m 775 -p "${EGIT_STORE_DIR}" \
252 scarabeus 1.1 || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\""
253     fi
254    
255     # allow writing into EGIT_STORE_DIR
256     addwrite "${EGIT_STORE_DIR}"
257 mgorny 1.25
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    
273 scarabeus 1.1 # calculate the proper store dir for data
274 scarabeus 1.6 # If user didn't specify the EGIT_DIR, we check if he did specify
275     # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI.
276 mgorny 1.16 EGIT_REPO_URI=${EGIT_REPO_URI%/}
277 mgorny 1.17 if [[ ! ${EGIT_DIR} ]]; then
278     if [[ ${EGIT_PROJECT} ]]; then
279 scarabeus 1.6 clone_dir=${EGIT_PROJECT}
280     else
281     clone_dir=${EGIT_REPO_URI##*/}
282     fi
283 scarabeus 1.1 EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir}
284 mgorny 1.24
285 mgorny 1.25 if [[ ${EGIT_OLD_CLONE} && ! -d ${EGIT_DIR} ]]; then
286     elog "${FUNCNAME}: ${CATEGORY}/${PF} will be cloned from old location."
287     elog "It will be necessary to rebuild the package to fetch updates."
288     EGIT_REPO_URI="${EGIT_OLD_CLONE} ${EGIT_REPO_URI}"
289 mgorny 1.24 fi
290 scarabeus 1.1 fi
291     export EGIT_DIR=${EGIT_DIR}
292     debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"."
293     }
294    
295     # @FUNCTION: git-2_move_source
296 mgorny 1.22 # @INTERNAL
297 scarabeus 1.1 # @DESCRIPTION:
298     # Internal function moving sources from the EGIT_DIR to EGIT_SOURCEDIR dir.
299     git-2_move_source() {
300     debug-print-function ${FUNCNAME} "$@"
301    
302     debug-print "${FUNCNAME}: ${MOVE_COMMAND} \"${EGIT_DIR}\" \"${EGIT_SOURCEDIR}\""
303     pushd "${EGIT_DIR}" > /dev/null
304     mkdir -p "${EGIT_SOURCEDIR}" \
305     || die "${FUNCNAME}: failed to create ${EGIT_SOURCEDIR}"
306     ${MOVE_COMMAND} "${EGIT_SOURCEDIR}" \
307     || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed"
308     popd > /dev/null
309     }
310    
311     # @FUNCTION: git-2_initial_clone
312 mgorny 1.22 # @INTERNAL
313 scarabeus 1.1 # @DESCRIPTION:
314     # Internal function running initial clone on specified repo_uri.
315     git-2_initial_clone() {
316     debug-print-function ${FUNCNAME} "$@"
317    
318     local repo_uri
319    
320     EGIT_REPO_URI_SELECTED=""
321     for repo_uri in ${EGIT_REPO_URI}; do
322 scarabeus 1.13 debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\""
323 mgorny 1.18 if git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"; then
324 scarabeus 1.1 # global variable containing the repo_name we will be using
325     debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
326     EGIT_REPO_URI_SELECTED="${repo_uri}"
327     break
328     fi
329     done
330    
331 mgorny 1.17 [[ ${EGIT_REPO_URI_SELECTED} ]] \
332     || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}"
333 scarabeus 1.1 }
334    
335     # @FUNCTION: git-2_update_repo
336 mgorny 1.22 # @INTERNAL
337 scarabeus 1.1 # @DESCRIPTION:
338     # Internal function running update command on specified repo_uri.
339     git-2_update_repo() {
340     debug-print-function ${FUNCNAME} "$@"
341    
342     local repo_uri
343    
344 mgorny 1.17 if [[ ${EGIT_LOCAL_NONBARE} ]]; then
345 scarabeus 1.1 # checkout master branch and drop all other local branches
346     git checkout ${EGIT_MASTER} || die "${FUNCNAME}: can't checkout master branch ${EGIT_MASTER}"
347     for x in $(git branch | grep -v "* ${EGIT_MASTER}" | tr '\n' ' '); do
348     debug-print "${FUNCNAME}: git branch -D ${x}"
349     git branch -D ${x} > /dev/null
350     done
351     fi
352    
353     EGIT_REPO_URI_SELECTED=""
354     for repo_uri in ${EGIT_REPO_URI}; do
355     # git urls might change, so reset it
356     git config remote.origin.url "${repo_uri}"
357    
358 scarabeus 1.3 debug-print "${EGIT_UPDATE_CMD}"
359 mgorny 1.18 if ${EGIT_UPDATE_CMD} > /dev/null; then
360 scarabeus 1.1 # global variable containing the repo_name we will be using
361     debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\""
362     EGIT_REPO_URI_SELECTED="${repo_uri}"
363     break
364     fi
365     done
366    
367 mgorny 1.17 [[ ${EGIT_REPO_URI_SELECTED} ]] \
368     || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}"
369 scarabeus 1.1 }
370    
371     # @FUNCTION: git-2_fetch
372 mgorny 1.22 # @INTERNAL
373 scarabeus 1.1 # @DESCRIPTION:
374     # Internal function fetching repository from EGIT_REPO_URI and storing it in
375     # specified EGIT_STORE_DIR.
376     git-2_fetch() {
377     debug-print-function ${FUNCNAME} "$@"
378    
379     local oldsha cursha repo_type
380    
381 mgorny 1.17 [[ ${EGIT_LOCAL_NONBARE} ]] && repo_type="non-bare repository" || repo_type="bare repository"
382 scarabeus 1.1
383     if [[ ! -d ${EGIT_DIR} ]]; then
384     git-2_initial_clone
385     pushd "${EGIT_DIR}" > /dev/null
386     cursha=$(git rev-parse ${UPSTREAM_BRANCH})
387     echo "GIT NEW clone -->"
388     echo " repository: ${EGIT_REPO_URI_SELECTED}"
389     echo " at the commit: ${cursha}"
390    
391     popd > /dev/null
392 mgorny 1.17 elif [[ ${EVCS_OFFLINE} ]]; then
393 scarabeus 1.1 pushd "${EGIT_DIR}" > /dev/null
394     cursha=$(git rev-parse ${UPSTREAM_BRANCH})
395     echo "GIT offline update -->"
396     echo " repository: $(git config remote.origin.url)"
397     echo " at the commit: ${cursha}"
398     popd > /dev/null
399     else
400     pushd "${EGIT_DIR}" > /dev/null
401     oldsha=$(git rev-parse ${UPSTREAM_BRANCH})
402     git-2_update_repo
403     cursha=$(git rev-parse ${UPSTREAM_BRANCH})
404    
405     # fetch updates
406     echo "GIT update -->"
407     echo " repository: ${EGIT_REPO_URI_SELECTED}"
408     # write out message based on the revisions
409 mgorny 1.5 if [[ "${oldsha}" != "${cursha}" ]]; then
410 scarabeus 1.1 echo " updating from commit: ${oldsha}"
411     echo " to commit: ${cursha}"
412     else
413     echo " at the commit: ${cursha}"
414     fi
415    
416     # print nice statistic of what was changed
417     git --no-pager diff --stat ${oldsha}..${UPSTREAM_BRANCH}
418     popd > /dev/null
419     fi
420     # export the version the repository is at
421 mgorny 1.5 export EGIT_VERSION="${cursha}"
422 scarabeus 1.1 # log the repo state
423     [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] \
424     && echo " commit: ${EGIT_COMMIT}"
425     echo " branch: ${EGIT_BRANCH}"
426     echo " storage directory: \"${EGIT_DIR}\""
427     echo " checkout type: ${repo_type}"
428 mgorny 1.25
429     # Cleanup after git.eclass
430     if [[ ${EGIT_OLD_CLONE} ]]; then
431     einfo "${FUNCNAME}: removing old clone in ${EGIT_OLD_CLONE}."
432     rm -rf "${EGIT_OLD_CLONE}"
433     fi
434 scarabeus 1.1 }
435    
436     # @FUNCTION: git_bootstrap
437 mgorny 1.22 # @INTERNAL
438 scarabeus 1.1 # @DESCRIPTION:
439     # Internal function that runs bootstrap command on unpacked source.
440     git-2_bootstrap() {
441     debug-print-function ${FUNCNAME} "$@"
442    
443 vapier 1.14 # @ECLASS-VARIABLE: EGIT_BOOTSTRAP
444 scarabeus 1.1 # @DESCRIPTION:
445     # Command to be executed after checkout and clone of the specified
446     # repository.
447     # enviroment the package will fail if there is no update, thus in
448     # combination with --keep-going it would lead in not-updating
449     # pakcages that are up-to-date.
450 mgorny 1.17 if [[ ${EGIT_BOOTSTRAP} ]]; then
451 scarabeus 1.1 pushd "${EGIT_SOURCEDIR}" > /dev/null
452     einfo "Starting bootstrap"
453    
454     if [[ -f ${EGIT_BOOTSTRAP} ]]; then
455     # we have file in the repo which we should execute
456     debug-print "${FUNCNAME}: bootstraping with file \"${EGIT_BOOTSTRAP}\""
457    
458     if [[ -x ${EGIT_BOOTSTRAP} ]]; then
459     eval "./${EGIT_BOOTSTRAP}" \
460     || die "${FUNCNAME}: bootstrap script failed"
461     else
462     eerror "\"${EGIT_BOOTSTRAP}\" is not executable."
463     eerror "Report upstream, or bug ebuild maintainer to remove bootstrap command."
464     die "\"${EGIT_BOOTSTRAP}\" is not executable"
465     fi
466     else
467     # we execute some system command
468     debug-print "${FUNCNAME}: bootstraping with commands \"${EGIT_BOOTSTRAP}\""
469    
470     eval "${EGIT_BOOTSTRAP}" \
471     || die "${FUNCNAME}: bootstrap commands failed"
472     fi
473    
474     einfo "Bootstrap finished"
475     popd > /dev/null
476     fi
477     }
478    
479     # @FUNCTION: git-2_migrate_repository
480 mgorny 1.22 # @INTERNAL
481 scarabeus 1.1 # @DESCRIPTION:
482     # Internal function migrating between bare and normal checkout repository.
483     # This is based on usage of EGIT_SUBMODULES, at least until they
484     # start to work with bare checkouts sanely.
485 scarabeus 1.13 # This function also set some global variables that differ between
486     # bare and non-bare checkout.
487 scarabeus 1.1 git-2_migrate_repository() {
488     debug-print-function ${FUNCNAME} "$@"
489    
490 mgorny 1.20 local bare returnstate
491 scarabeus 1.1
492     # first find out if we have submodules
493 mgorny 1.20 # or user explicitly wants us to use non-bare clones
494     if ! [[ ${EGIT_HAS_SUBMODULES} || ${EGIT_NONBARE} ]]; then
495     bare=1
496 scarabeus 1.13 fi
497 scarabeus 1.1
498     # test if we already have some repo and if so find out if we have
499     # to migrate the data
500     if [[ -d ${EGIT_DIR} ]]; then
501 mgorny 1.20 if [[ ${bare} && -d ${EGIT_DIR}/.git ]]; then
502 scarabeus 1.1 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy"
503    
504     ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy"
505     mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare"
506     export GIT_DIR="${EGIT_DIR}.bare"
507     git config core.bare true > /dev/null
508     returnstate=$?
509     unset GIT_DIR
510     rm -rf "${EGIT_DIR}"
511     mv "${EGIT_DIR}.bare" "${EGIT_DIR}"
512     eend ${returnstate}
513 mgorny 1.20 elif [[ ! ${bare} && ! -d ${EGIT_DIR}/.git ]]; then
514 scarabeus 1.1 debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy"
515    
516     ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy"
517     git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null
518     returnstate=$?
519     rm -rf "${EGIT_DIR}"
520     mv "${EGIT_DIR}.nonbare" "${EGIT_DIR}"
521     eend ${returnstate}
522     fi
523     fi
524     if [[ ${returnstate} -ne 0 ]]; then
525     debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" failed, removing to start from scratch"
526    
527     # migration failed, remove the EGIT_DIR to play it safe
528     einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch."
529     rm -rf "${EGIT_DIR}"
530     fi
531    
532     # set various options to work with both targets
533 mgorny 1.20 if [[ ${bare} ]]; then
534 scarabeus 1.1 debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\""
535 scarabeus 1.13 EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare"
536 scarabeus 1.1 MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }"
537 scarabeus 1.2 EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}"
538 scarabeus 1.1 UPSTREAM_BRANCH="${EGIT_BRANCH}"
539 mgorny 1.23 EGIT_LOCAL_NONBARE=
540 scarabeus 1.1 else
541     debug-print "${FUNCNAME}: working in bare repository for non-bare \"${EGIT_DIR}\""
542     MOVE_COMMAND="cp -pPR ."
543 scarabeus 1.13 EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}"
544 scarabeus 1.1 EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}"
545     UPSTREAM_BRANCH="origin/${EGIT_BRANCH}"
546 scarabeus 1.13 EGIT_LOCAL_NONBARE="true"
547 scarabeus 1.1 fi
548     }
549    
550 scarabeus 1.13 # @FUNCTION: git-2_cleanup
551 mgorny 1.22 # @INTERNAL
552 scarabeus 1.13 # @DESCRIPTION:
553     # Internal function cleaning up all the global variables
554     # that are not required after the unpack has been done.
555     git-2_cleanup() {
556     debug-print-function ${FUNCNAME} "$@"
557    
558     # Here we can unset only variables that are GLOBAL
559     # defined by the eclass, BUT NOT subject to change
560     # by user (like EGIT_PROJECT).
561     # If ebuild writer polutes his environment it is
562     # his problem only.
563     unset EGIT_DIR
564     unset MOVE_COMMAND
565     unset EGIT_LOCAL_OPTIONS
566     unset EGIT_UPDATE_CMD
567     unset UPSTREAM_BRANCH
568     unset EGIT_LOCAL_NONBARE
569     }
570    
571 scarabeus 1.1 # @FUNCTION: git-2_src_unpack
572     # @DESCRIPTION:
573 scarabeus 1.7 # Default git src_unpack function.
574 scarabeus 1.1 git-2_src_unpack() {
575     debug-print-function ${FUNCNAME} "$@"
576    
577     git-2_init_variables
578     git-2_prepare_storedir
579     git-2_migrate_repository
580     git-2_fetch "$@"
581     git-2_gc
582     git-2_submodules
583     git-2_move_source
584     git-2_branch
585     git-2_bootstrap
586 scarabeus 1.13 git-2_cleanup
587 scarabeus 1.1 echo ">>> Unpacked to ${EGIT_SOURCEDIR}"
588 scarabeus 1.9
589     # Users can specify some SRC_URI and we should
590     # unpack the files too.
591 mgorny 1.17 if [[ ! ${EGIT_NOUNPACK} ]]; then
592 scarabeus 1.13 if has ${EAPI:-0} 0 1; then
593 mgorny 1.17 [[ ${A} ]] && unpack ${A}
594 scarabeus 1.13 else
595     default_src_unpack
596     fi
597 mgorny 1.12 fi
598 scarabeus 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20