| 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.9 2011/05/20 15:53:43 scarabeus Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/git-2.eclass,v 1.21 2011/09/23 13:58:09 mgorny Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: git-2.eclass |
5 | # @ECLASS: git-2.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Tomas Chvatal <scarabeus@gentoo.org> |
7 | # Donnie Berkholz <dberkholz@gentoo.org> |
| 8 | # @BLURB: Eclass for fetching and unpacking git repositories. |
8 | # @BLURB: Eclass for fetching and unpacking git repositories. |
| 9 | # @DESCRIPTION: |
9 | # @DESCRIPTION: |
| 10 | # Eclass for easing maitenance of live ebuilds using git as remote repository. |
10 | # Eclass for easing maitenance of live ebuilds using git as remote repository. |
| 11 | # Eclass support working with git submodules and branching. |
11 | # Eclass support working with git submodules and branching. |
| 12 | |
12 | |
| … | |
… | |
| 55 | # EGIT_PROJECT="${EGIT_REPO_URI##*/}" |
55 | # EGIT_PROJECT="${EGIT_REPO_URI##*/}" |
| 56 | |
56 | |
| 57 | # @ECLASS-VARIABLE: EGIT_DIR |
57 | # @ECLASS-VARIABLE: EGIT_DIR |
| 58 | # @DESCRIPTION: |
58 | # @DESCRIPTION: |
| 59 | # Directory where we want to store the git data. |
59 | # Directory where we want to store the git data. |
| 60 | # This should not be overriden unless really required. |
60 | # This variable should not be overriden. |
| 61 | # |
61 | # |
| 62 | # EGIT_DIR="${EGIT_STORE_DIR}/${EGIT_PROJECT}" |
62 | # EGIT_DIR="${EGIT_STORE_DIR}/${EGIT_PROJECT}" |
| 63 | |
63 | |
| 64 | # @ECLASS-VARIABLE: EGIT_REPO_URI |
64 | # @ECLASS-VARIABLE: EGIT_REPO_URI |
| 65 | # @REQUIRED |
65 | # @REQUIRED |
| … | |
… | |
| 110 | # @DEFAULT_UNSET |
110 | # @DEFAULT_UNSET |
| 111 | # @DESCRIPTION: |
111 | # @DESCRIPTION: |
| 112 | # If non-empty this variable specifies that all checkouts will be done using |
112 | # If non-empty this variable specifies that all checkouts will be done using |
| 113 | # non bare repositories. This is useful if you can't operate with bare |
113 | # non bare repositories. This is useful if you can't operate with bare |
| 114 | # checkouts for some reason. |
114 | # checkouts for some reason. |
|
|
115 | |
|
|
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. |
| 115 | |
121 | |
| 116 | # @FUNCTION: git-2_init_variables |
122 | # @FUNCTION: git-2_init_variables |
| 117 | # @DESCRIPTION: |
123 | # @DESCRIPTION: |
| 118 | # Internal function initializing all git variables. |
124 | # Internal function initializing all git variables. |
| 119 | # We define it in function scope so user can define |
125 | # We define it in function scope so user can define |
| 120 | # all the variables before and after inherit. |
126 | # all the variables before and after inherit. |
| 121 | git-2_init_variables() { |
127 | git-2_init_variables() { |
| 122 | debug-print-function ${FUNCNAME} "$@" |
128 | debug-print-function ${FUNCNAME} "$@" |
| 123 | |
129 | |
| 124 | local x |
130 | local esc_pn liverepo livebranch livecommit |
|
|
131 | esc_pn=${PN//[-+]/_} |
| 125 | |
132 | |
| 126 | : ${EGIT_SOURCEDIR="${S}"} |
133 | : ${EGIT_SOURCEDIR="${S}"} |
| 127 | |
134 | |
| 128 | : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"} |
135 | : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"} |
| 129 | |
136 | |
| … | |
… | |
| 131 | |
138 | |
| 132 | : ${EGIT_OPTIONS:=} |
139 | : ${EGIT_OPTIONS:=} |
| 133 | |
140 | |
| 134 | : ${EGIT_MASTER:=master} |
141 | : ${EGIT_MASTER:=master} |
| 135 | |
142 | |
| 136 | eval x="\$${PN//[-+]/_}_LIVE_REPO" |
143 | liverepo=${esc_pn}_LIVE_REPO |
| 137 | EGIT_REPO_URI=${x:-${EGIT_REPO_URI}} |
144 | EGIT_REPO_URI=${!liverepo:-${EGIT_REPO_URI}} |
| 138 | [[ -z ${EGIT_REPO_URI} ]] && die "EGIT_REPO_URI must have some value" |
145 | [[ ${EGIT_REPO_URI} ]] || die "EGIT_REPO_URI must have some value" |
| 139 | |
146 | |
| 140 | : ${EVCS_OFFLINE:=} |
147 | : ${EVCS_OFFLINE:=} |
| 141 | |
148 | |
| 142 | eval x="\$${PN//[-+]/_}_LIVE_BRANCH" |
149 | livebranch=${esc_pn}_LIVE_BRANCH |
| 143 | [[ -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" |
| 144 | EGIT_BRANCH=${x:-${EGIT_BRANCH:-${EGIT_MASTER}}} |
151 | EGIT_BRANCH=${!livebranch:-${EGIT_BRANCH:-${EGIT_MASTER}}} |
| 145 | |
152 | |
| 146 | eval x="\$${PN//[-+]/_}_LIVE_COMMIT" |
153 | livecommit=${esc_pn}_LIVE_COMMIT |
| 147 | [[ -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" |
| 148 | EGIT_COMMIT=${x:-${EGIT_COMMIT:-${EGIT_BRANCH}}} |
155 | EGIT_COMMIT=${!livecommit:-${EGIT_COMMIT:-${EGIT_BRANCH}}} |
| 149 | |
156 | |
| 150 | : ${EGIT_REPACK:=} |
157 | : ${EGIT_REPACK:=} |
| 151 | |
158 | |
| 152 | : ${EGIT_PRUNE:=} |
159 | : ${EGIT_PRUNE:=} |
| 153 | } |
160 | } |
| … | |
… | |
| 155 | # @FUNCTION: git-2_submodules |
162 | # @FUNCTION: git-2_submodules |
| 156 | # @DESCRIPTION: |
163 | # @DESCRIPTION: |
| 157 | # Internal function wrapping the submodule initialisation and update. |
164 | # Internal function wrapping the submodule initialisation and update. |
| 158 | git-2_submodules() { |
165 | git-2_submodules() { |
| 159 | debug-print-function ${FUNCNAME} "$@" |
166 | debug-print-function ${FUNCNAME} "$@" |
| 160 | if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then |
167 | if [[ ${EGIT_HAS_SUBMODULES} ]]; then |
| 161 | if [[ -n ${EVCS_OFFLINE} ]]; then |
168 | if [[ ${EVCS_OFFLINE} ]]; then |
| 162 | # for submodules operations we need to be online |
169 | # for submodules operations we need to be online |
| 163 | debug-print "${FUNCNAME}: not updating submodules in offline mode" |
170 | debug-print "${FUNCNAME}: not updating submodules in offline mode" |
| 164 | return 1 |
171 | return 1 |
| 165 | fi |
172 | fi |
| 166 | |
173 | |
| … | |
… | |
| 183 | # 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 |
| 184 | # EGIT_BRANCH variables. |
191 | # EGIT_BRANCH variables. |
| 185 | git-2_branch() { |
192 | git-2_branch() { |
| 186 | debug-print-function ${FUNCNAME} "$@" |
193 | debug-print-function ${FUNCNAME} "$@" |
| 187 | |
194 | |
|
|
195 | local branchname src |
|
|
196 | |
| 188 | debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\"" |
197 | debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\"" |
| 189 | pushd "${EGIT_SOURCEDIR}" > /dev/null |
198 | pushd "${EGIT_SOURCEDIR}" > /dev/null |
| 190 | |
199 | |
| 191 | local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH} |
200 | local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH} |
| 192 | if [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]]; then |
201 | if [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]]; then |
| … | |
… | |
| 196 | debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}" |
205 | debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}" |
| 197 | git checkout -b ${branchname} ${src} \ |
206 | git checkout -b ${branchname} ${src} \ |
| 198 | || die "${FUNCNAME}: changing the branch failed" |
207 | || die "${FUNCNAME}: changing the branch failed" |
| 199 | |
208 | |
| 200 | popd > /dev/null |
209 | popd > /dev/null |
| 201 | |
|
|
| 202 | unset branchname src |
|
|
| 203 | } |
210 | } |
| 204 | |
211 | |
| 205 | # @FUNCTION: git-2_gc |
212 | # @FUNCTION: git-2_gc |
| 206 | # @DESCRIPTION: |
213 | # @DESCRIPTION: |
| 207 | # Internal function running garbage collector on checked out tree. |
214 | # Internal function running garbage collector on checked out tree. |
| 208 | git-2_gc() { |
215 | git-2_gc() { |
| 209 | debug-print-function ${FUNCNAME} "$@" |
216 | debug-print-function ${FUNCNAME} "$@" |
| 210 | |
217 | |
|
|
218 | local args |
|
|
219 | |
|
|
220 | if [[ ${EGIT_REPACK} || ${EGIT_PRUNE} ]]; then |
| 211 | pushd "${EGIT_DIR}" > /dev/null |
221 | pushd "${EGIT_DIR}" > /dev/null |
| 212 | if [[ -n ${EGIT_REPACK} || -n ${EGIT_PRUNE} ]]; then |
|
|
| 213 | ebegin "Garbage collecting the repository" |
222 | ebegin "Garbage collecting the repository" |
| 214 | local args |
|
|
| 215 | [[ -n ${EGIT_PRUNE} ]] && args='--prune' |
223 | [[ ${EGIT_PRUNE} ]] && args='--prune' |
| 216 | debug-print "${FUNCNAME}: git gc ${args}" |
224 | debug-print "${FUNCNAME}: git gc ${args}" |
| 217 | git gc ${args} |
225 | git gc ${args} |
| 218 | eend $? |
226 | eend $? |
| 219 | fi |
|
|
| 220 | popd > /dev/null |
227 | popd > /dev/null |
|
|
228 | fi |
| 221 | } |
229 | } |
| 222 | |
230 | |
| 223 | # @FUNCTION: git-2_prepare_storedir |
231 | # @FUNCTION: git-2_prepare_storedir |
| 224 | # @DESCRIPTION: |
232 | # @DESCRIPTION: |
| 225 | # Internal function preparing directory where we are going to store SCM |
233 | # Internal function preparing directory where we are going to store SCM |
| … | |
… | |
| 241 | # allow writing into EGIT_STORE_DIR |
249 | # allow writing into EGIT_STORE_DIR |
| 242 | addwrite "${EGIT_STORE_DIR}" |
250 | addwrite "${EGIT_STORE_DIR}" |
| 243 | # calculate the proper store dir for data |
251 | # calculate the proper store dir for data |
| 244 | # If user didn't specify the EGIT_DIR, we check if he did specify |
252 | # If user didn't specify the EGIT_DIR, we check if he did specify |
| 245 | # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI. |
253 | # the EGIT_PROJECT or get the folder name from EGIT_REPO_URI. |
| 246 | [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" |
254 | EGIT_REPO_URI=${EGIT_REPO_URI%/} |
| 247 | if [[ -z ${EGIT_DIR} ]]; then |
255 | if [[ ! ${EGIT_DIR} ]]; then |
| 248 | if [[ -n ${EGIT_PROJECT} ]]; then |
256 | if [[ ${EGIT_PROJECT} ]]; then |
| 249 | clone_dir=${EGIT_PROJECT} |
257 | clone_dir=${EGIT_PROJECT} |
| 250 | else |
258 | else |
| 251 | clone_dir=${EGIT_REPO_URI##*/} |
259 | clone_dir=${EGIT_REPO_URI##*/} |
| 252 | fi |
260 | fi |
| 253 | EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir} |
261 | EGIT_DIR=${EGIT_STORE_DIR}/${clone_dir} |
| … | |
… | |
| 279 | |
287 | |
| 280 | local repo_uri |
288 | local repo_uri |
| 281 | |
289 | |
| 282 | EGIT_REPO_URI_SELECTED="" |
290 | EGIT_REPO_URI_SELECTED="" |
| 283 | for repo_uri in ${EGIT_REPO_URI}; do |
291 | for repo_uri in ${EGIT_REPO_URI}; do |
| 284 | debug-print "${FUNCNAME}: git clone ${EGIT_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" |
292 | debug-print "${FUNCNAME}: git clone ${EGIT_LOCAL_OPTIONS} \"${repo_uri}\" \"${EGIT_DIR}\"" |
| 285 | git clone ${EGIT_OPTIONS} "${repo_uri}" "${EGIT_DIR}" |
293 | if git clone ${EGIT_LOCAL_OPTIONS} "${repo_uri}" "${EGIT_DIR}"; then |
| 286 | if [[ $? -eq 0 ]]; then |
|
|
| 287 | # global variable containing the repo_name we will be using |
294 | # global variable containing the repo_name we will be using |
| 288 | debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" |
295 | debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" |
| 289 | EGIT_REPO_URI_SELECTED="${repo_uri}" |
296 | EGIT_REPO_URI_SELECTED="${repo_uri}" |
| 290 | break |
297 | break |
| 291 | fi |
298 | fi |
| 292 | done |
299 | done |
| 293 | |
300 | |
| 294 | if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then |
301 | [[ ${EGIT_REPO_URI_SELECTED} ]] \ |
| 295 | die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" |
302 | || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}" |
| 296 | fi |
|
|
| 297 | } |
303 | } |
| 298 | |
304 | |
| 299 | # @FUNCTION: git-2_update_repo |
305 | # @FUNCTION: git-2_update_repo |
| 300 | # @DESCRIPTION: |
306 | # @DESCRIPTION: |
| 301 | # Internal function running update command on specified repo_uri. |
307 | # Internal function running update command on specified repo_uri. |
| 302 | git-2_update_repo() { |
308 | git-2_update_repo() { |
| 303 | debug-print-function ${FUNCNAME} "$@" |
309 | debug-print-function ${FUNCNAME} "$@" |
| 304 | |
310 | |
| 305 | local repo_uri |
311 | local repo_uri |
| 306 | |
312 | |
| 307 | if [[ -n ${EGIT_NONBARE} ]]; then |
313 | if [[ ${EGIT_LOCAL_NONBARE} ]]; then |
| 308 | # checkout master branch and drop all other local branches |
314 | # checkout master branch and drop all other local branches |
| 309 | 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}" |
| 310 | 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 |
| 311 | debug-print "${FUNCNAME}: git branch -D ${x}" |
317 | debug-print "${FUNCNAME}: git branch -D ${x}" |
| 312 | git branch -D ${x} > /dev/null |
318 | git branch -D ${x} > /dev/null |
| … | |
… | |
| 317 | for repo_uri in ${EGIT_REPO_URI}; do |
323 | for repo_uri in ${EGIT_REPO_URI}; do |
| 318 | # git urls might change, so reset it |
324 | # git urls might change, so reset it |
| 319 | git config remote.origin.url "${repo_uri}" |
325 | git config remote.origin.url "${repo_uri}" |
| 320 | |
326 | |
| 321 | debug-print "${EGIT_UPDATE_CMD}" |
327 | debug-print "${EGIT_UPDATE_CMD}" |
| 322 | ${EGIT_UPDATE_CMD} > /dev/null |
328 | if ${EGIT_UPDATE_CMD} > /dev/null; then |
| 323 | if [[ $? -eq 0 ]]; then |
|
|
| 324 | # global variable containing the repo_name we will be using |
329 | # global variable containing the repo_name we will be using |
| 325 | debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" |
330 | debug-print "${FUNCNAME}: EGIT_REPO_URI_SELECTED=\"${repo_uri}\"" |
| 326 | EGIT_REPO_URI_SELECTED="${repo_uri}" |
331 | EGIT_REPO_URI_SELECTED="${repo_uri}" |
| 327 | break |
332 | break |
| 328 | fi |
333 | fi |
| 329 | done |
334 | done |
| 330 | |
335 | |
| 331 | if [[ -z ${EGIT_REPO_URI_SELECTED} ]]; then |
336 | [[ ${EGIT_REPO_URI_SELECTED} ]] \ |
| 332 | die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" |
337 | || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}" |
| 333 | fi |
|
|
| 334 | } |
338 | } |
| 335 | |
339 | |
| 336 | # @FUNCTION: git-2_fetch |
340 | # @FUNCTION: git-2_fetch |
| 337 | # @DESCRIPTION: |
341 | # @DESCRIPTION: |
| 338 | # 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 |
| … | |
… | |
| 340 | git-2_fetch() { |
344 | git-2_fetch() { |
| 341 | debug-print-function ${FUNCNAME} "$@" |
345 | debug-print-function ${FUNCNAME} "$@" |
| 342 | |
346 | |
| 343 | local oldsha cursha repo_type |
347 | local oldsha cursha repo_type |
| 344 | |
348 | |
| 345 | [[ -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" |
| 346 | |
350 | |
| 347 | if [[ ! -d ${EGIT_DIR} ]]; then |
351 | if [[ ! -d ${EGIT_DIR} ]]; then |
| 348 | git-2_initial_clone |
352 | git-2_initial_clone |
| 349 | pushd "${EGIT_DIR}" > /dev/null |
353 | pushd "${EGIT_DIR}" > /dev/null |
| 350 | cursha=$(git rev-parse ${UPSTREAM_BRANCH}) |
354 | cursha=$(git rev-parse ${UPSTREAM_BRANCH}) |
| 351 | echo "GIT NEW clone -->" |
355 | echo "GIT NEW clone -->" |
| 352 | echo " repository: ${EGIT_REPO_URI_SELECTED}" |
356 | echo " repository: ${EGIT_REPO_URI_SELECTED}" |
| 353 | echo " at the commit: ${cursha}" |
357 | echo " at the commit: ${cursha}" |
| 354 | |
358 | |
| 355 | popd > /dev/null |
359 | popd > /dev/null |
| 356 | elif [[ -n ${EVCS_OFFLINE} ]]; then |
360 | elif [[ ${EVCS_OFFLINE} ]]; then |
| 357 | pushd "${EGIT_DIR}" > /dev/null |
361 | pushd "${EGIT_DIR}" > /dev/null |
| 358 | cursha=$(git rev-parse ${UPSTREAM_BRANCH}) |
362 | cursha=$(git rev-parse ${UPSTREAM_BRANCH}) |
| 359 | echo "GIT offline update -->" |
363 | echo "GIT offline update -->" |
| 360 | echo " repository: $(git config remote.origin.url)" |
364 | echo " repository: $(git config remote.origin.url)" |
| 361 | echo " at the commit: ${cursha}" |
365 | echo " at the commit: ${cursha}" |
| … | |
… | |
| 395 | # @DESCRIPTION: |
399 | # @DESCRIPTION: |
| 396 | # Internal function that runs bootstrap command on unpacked source. |
400 | # Internal function that runs bootstrap command on unpacked source. |
| 397 | git-2_bootstrap() { |
401 | git-2_bootstrap() { |
| 398 | debug-print-function ${FUNCNAME} "$@" |
402 | debug-print-function ${FUNCNAME} "$@" |
| 399 | |
403 | |
| 400 | # @ECLASS_VARIABLE: EGIT_BOOTSTRAP |
404 | # @ECLASS-VARIABLE: EGIT_BOOTSTRAP |
| 401 | # @DESCRIPTION: |
405 | # @DESCRIPTION: |
| 402 | # Command to be executed after checkout and clone of the specified |
406 | # Command to be executed after checkout and clone of the specified |
| 403 | # repository. |
407 | # repository. |
| 404 | # 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 |
| 405 | # combination with --keep-going it would lead in not-updating |
409 | # combination with --keep-going it would lead in not-updating |
| 406 | # pakcages that are up-to-date. |
410 | # pakcages that are up-to-date. |
| 407 | if [[ -n ${EGIT_BOOTSTRAP} ]]; then |
411 | if [[ ${EGIT_BOOTSTRAP} ]]; then |
| 408 | pushd "${EGIT_SOURCEDIR}" > /dev/null |
412 | pushd "${EGIT_SOURCEDIR}" > /dev/null |
| 409 | einfo "Starting bootstrap" |
413 | einfo "Starting bootstrap" |
| 410 | |
414 | |
| 411 | if [[ -f ${EGIT_BOOTSTRAP} ]]; then |
415 | if [[ -f ${EGIT_BOOTSTRAP} ]]; then |
| 412 | # we have file in the repo which we should execute |
416 | # we have file in the repo which we should execute |
| … | |
… | |
| 436 | # @FUNCTION: git-2_migrate_repository |
440 | # @FUNCTION: git-2_migrate_repository |
| 437 | # @DESCRIPTION: |
441 | # @DESCRIPTION: |
| 438 | # Internal function migrating between bare and normal checkout repository. |
442 | # Internal function migrating between bare and normal checkout repository. |
| 439 | # 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 |
| 440 | # 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. |
| 441 | git-2_migrate_repository() { |
447 | git-2_migrate_repository() { |
| 442 | debug-print-function ${FUNCNAME} "$@" |
448 | debug-print-function ${FUNCNAME} "$@" |
| 443 | |
449 | |
| 444 | local target returnstate |
450 | local bare returnstate |
| 445 | |
451 | |
| 446 | # 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 |
| 447 | if [[ -z ${EGIT_HAS_SUBMODULES} ]]; then |
454 | if ! [[ ${EGIT_HAS_SUBMODULES} || ${EGIT_NONBARE} ]]; then |
| 448 | target="bare" |
455 | bare=1 |
| 449 | else |
|
|
| 450 | target="full" |
|
|
| 451 | fi |
456 | fi |
| 452 | [[ -n ${EGIT_NONBARE} ]] && target="full" |
|
|
| 453 | |
457 | |
| 454 | # 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 |
| 455 | # to migrate the data |
459 | # to migrate the data |
| 456 | if [[ -d ${EGIT_DIR} ]]; then |
460 | if [[ -d ${EGIT_DIR} ]]; then |
| 457 | if [[ ${target} == bare && -d ${EGIT_DIR}/.git ]]; then |
461 | if [[ ${bare} && -d ${EGIT_DIR}/.git ]]; then |
| 458 | debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" |
462 | debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to bare copy" |
| 459 | |
463 | |
| 460 | ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" |
464 | ebegin "Converting \"${EGIT_DIR}\" from non-bare to bare copy" |
| 461 | mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" |
465 | mv "${EGIT_DIR}/.git" "${EGIT_DIR}.bare" |
| 462 | export GIT_DIR="${EGIT_DIR}.bare" |
466 | export GIT_DIR="${EGIT_DIR}.bare" |
| … | |
… | |
| 464 | returnstate=$? |
468 | returnstate=$? |
| 465 | unset GIT_DIR |
469 | unset GIT_DIR |
| 466 | rm -rf "${EGIT_DIR}" |
470 | rm -rf "${EGIT_DIR}" |
| 467 | mv "${EGIT_DIR}.bare" "${EGIT_DIR}" |
471 | mv "${EGIT_DIR}.bare" "${EGIT_DIR}" |
| 468 | eend ${returnstate} |
472 | eend ${returnstate} |
| 469 | fi |
|
|
| 470 | if [[ ${target} == full && ! -d ${EGIT_DIR}/.git ]]; then |
473 | elif [[ ! ${bare} && ! -d ${EGIT_DIR}/.git ]]; then |
| 471 | debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" |
474 | debug-print "${FUNCNAME}: converting \"${EGIT_DIR}\" to non-bare copy" |
| 472 | |
475 | |
| 473 | ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" |
476 | ebegin "Converting \"${EGIT_DIR}\" from bare to non-bare copy" |
| 474 | git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null |
477 | git clone -l "${EGIT_DIR}" "${EGIT_DIR}.nonbare" > /dev/null |
| 475 | returnstate=$? |
478 | returnstate=$? |
| … | |
… | |
| 485 | einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." |
488 | einfo "Migration failed, removing \"${EGIT_DIR}\" to start from scratch." |
| 486 | rm -rf "${EGIT_DIR}" |
489 | rm -rf "${EGIT_DIR}" |
| 487 | fi |
490 | fi |
| 488 | |
491 | |
| 489 | # set various options to work with both targets |
492 | # set various options to work with both targets |
| 490 | if [[ ${target} == bare ]]; then |
493 | if [[ ${bare} ]]; then |
| 491 | debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" |
494 | debug-print "${FUNCNAME}: working in bare repository for \"${EGIT_DIR}\"" |
| 492 | EGIT_OPTIONS+=" --bare" |
495 | EGIT_LOCAL_OPTIONS+="${EGIT_OPTIONS} --bare" |
| 493 | MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" |
496 | MOVE_COMMAND="git clone -l -s -n ${EGIT_DIR// /\\ }" |
| 494 | EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" |
497 | EGIT_UPDATE_CMD="git fetch -t -f -u origin ${EGIT_BRANCH}:${EGIT_BRANCH}" |
| 495 | UPSTREAM_BRANCH="${EGIT_BRANCH}" |
498 | UPSTREAM_BRANCH="${EGIT_BRANCH}" |
| 496 | else |
499 | else |
| 497 | 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}\"" |
| 498 | MOVE_COMMAND="cp -pPR ." |
501 | MOVE_COMMAND="cp -pPR ." |
|
|
502 | EGIT_LOCAL_OPTIONS="${EGIT_OPTIONS}" |
| 499 | EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" |
503 | EGIT_UPDATE_CMD="git pull -f -u ${EGIT_OPTIONS}" |
| 500 | UPSTREAM_BRANCH="origin/${EGIT_BRANCH}" |
504 | UPSTREAM_BRANCH="origin/${EGIT_BRANCH}" |
| 501 | EGIT_NONBARE="true" |
505 | EGIT_LOCAL_NONBARE="true" |
| 502 | 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. |
|
|
513 | git-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 |
| 503 | } |
527 | } |
| 504 | |
528 | |
| 505 | # @FUNCTION: git-2_src_unpack |
529 | # @FUNCTION: git-2_src_unpack |
| 506 | # @DESCRIPTION: |
530 | # @DESCRIPTION: |
| 507 | # Default git src_unpack function. |
531 | # Default git src_unpack function. |
| … | |
… | |
| 515 | git-2_gc |
539 | git-2_gc |
| 516 | git-2_submodules |
540 | git-2_submodules |
| 517 | git-2_move_source |
541 | git-2_move_source |
| 518 | git-2_branch |
542 | git-2_branch |
| 519 | git-2_bootstrap |
543 | git-2_bootstrap |
|
|
544 | git-2_cleanup |
| 520 | echo ">>> Unpacked to ${EGIT_SOURCEDIR}" |
545 | echo ">>> Unpacked to ${EGIT_SOURCEDIR}" |
| 521 | |
546 | |
| 522 | # Users can specify some SRC_URI and we should |
547 | # Users can specify some SRC_URI and we should |
| 523 | # unpack the files too. |
548 | # unpack the files too. |
|
|
549 | if [[ ! ${EGIT_NOUNPACK} ]]; then |
|
|
550 | if has ${EAPI:-0} 0 1; then |
|
|
551 | [[ ${A} ]] && unpack ${A} |
|
|
552 | else |
| 524 | default_src_unpack |
553 | default_src_unpack |
|
|
554 | fi |
|
|
555 | fi |
| 525 | } |
556 | } |