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