git-2.eclass 18 KB

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