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

Contents of /eclass/git-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (hide annotations) (download)
Fri Sep 23 13:59:11 2011 UTC (2 years, 10 months ago) by mgorny
Branch: MAIN
Changes since 1.24: +27 -11 lines
Remove git.eclass old clones if git-2 clone succeeds.

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

  ViewVC Help
Powered by ViewVC 1.1.20