2017-05-26 20:08:45 +00:00
|
|
|
"""
|
2020-01-06 01:40:27 +00:00
|
|
|
Copyright 2020 Oliver Smith
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
This file is part of pmbootstrap.
|
|
|
|
|
|
|
|
pmbootstrap is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
pmbootstrap is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
import pmb.build
|
|
|
|
import pmb.chroot.apk
|
|
|
|
import pmb.config
|
2017-09-25 22:05:29 +00:00
|
|
|
import pmb.helpers.run
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
2019-12-22 11:11:21 +00:00
|
|
|
def clone(args, name_repo, shallow=True):
|
|
|
|
""" Clone a git repository to $WORK/cache_git/$name_repo.
|
|
|
|
|
|
|
|
:param name_repo: short alias used for the repository name, from
|
|
|
|
pmb.config.git_repos (e.g. "aports_upstream",
|
|
|
|
"pmaports")
|
|
|
|
:param shallow: only clone the last revision of the repository, instead
|
|
|
|
of the entire repository (faster, saves bandwith) """
|
2018-09-05 05:57:38 +00:00
|
|
|
# Check for repo name in the config
|
|
|
|
if name_repo not in pmb.config.git_repos:
|
|
|
|
raise ValueError("No git repository configured for " + name_repo)
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2018-09-05 05:57:38 +00:00
|
|
|
# Skip if already checked out
|
2019-12-22 11:11:21 +00:00
|
|
|
path = args.work + "/cache_git/" + name_repo
|
|
|
|
if os.path.exists(path):
|
2018-09-05 05:57:38 +00:00
|
|
|
return
|
|
|
|
|
2019-12-22 11:11:21 +00:00
|
|
|
# Build git command
|
|
|
|
url = pmb.config.git_repos[name_repo]
|
|
|
|
command = ["git", "clone"]
|
|
|
|
if shallow:
|
|
|
|
command += ["--depth=1"]
|
|
|
|
command += [url, path]
|
2017-08-23 16:40:16 +00:00
|
|
|
|
2019-12-22 11:11:21 +00:00
|
|
|
# Create parent dir and clone
|
|
|
|
logging.info("Clone git repository: " + url)
|
|
|
|
os.makedirs(args.work + "/cache_git", exist_ok=True)
|
|
|
|
pmb.helpers.run.user(args, command, output="stdout")
|
2018-09-05 05:57:38 +00:00
|
|
|
|
2017-08-23 16:40:16 +00:00
|
|
|
|
|
|
|
def rev_parse(args, revision="HEAD"):
|
2019-12-24 12:03:25 +00:00
|
|
|
""" Run "git rev-parse" in the pmaports.git dir.
|
|
|
|
|
|
|
|
:returns: commit string like "90cd0ad84d390897efdcf881c0315747a4f3a966"
|
|
|
|
"""
|
|
|
|
|
2017-08-23 16:40:16 +00:00
|
|
|
rev = pmb.helpers.run.user(args, ["git", "rev-parse", revision],
|
2019-12-24 12:03:25 +00:00
|
|
|
args.aports, output_return=True)
|
2017-08-23 16:40:16 +00:00
|
|
|
return rev.rstrip()
|