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

Contents of /eclass/git-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.30 - (hide annotations) (download)
Wed Jan 9 17:26:55 2013 UTC (2 years, 3 months ago) by axs
Branch: MAIN
Changes since 1.29: +5 -2 lines
added documentation for an undocumented override variable

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

  ViewVC Help
Powered by ViewVC 1.1.20