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