From 7943b55a6ed144ff75c60fd0b88c20decea0a61e Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Thu, 27 Jul 2023 13:29:38 +0200 Subject: [PATCH] Add limited support of Git SCM to the 'build' command --- osc/commandline.py | 8 +++++++- osc/core.py | 10 +++++----- osc/store.py | 21 ++++++++++++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 78756a5c..2cf69148 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -30,6 +30,7 @@ from . import build as osc_build from . import cmdln from . import commands as osc_commands from . import conf +from . import git_scm from . import oscerr from . import store as osc_store from .core import * @@ -7197,12 +7198,17 @@ Please submit there instead, or use --nodevelproject to force direct submission. if len(args) > 3: raise oscerr.WrongArgs('Too many arguments') - store = osc_store.Store(Path.cwd()) + store = osc_store.get_store(Path.cwd(), print_warnings=True) store.assert_is_package() if opts.alternative_project == store.project: opts.alternative_project = None + # HACK: avoid calling some underlying store_*() functions from parse_repoarchdescr() method + # We'll fix parse_repoarchdescr() later because it requires a larger change + if not opts.alternative_project and isinstance(store, git_scm.GitStore): + opts.alternative_project = store.project + if len(args) == 0 and store.is_package and store.last_buildroot: # build env not specified, just read from last build attempt args = [store.last_buildroot[0], store.last_buildroot[1]] diff --git a/osc/core.py b/osc/core.py index 8b5fda50..3e07fa8f 100644 --- a/osc/core.py +++ b/osc/core.py @@ -49,6 +49,7 @@ from . import _private from . import conf from . import meter from . import oscerr +from . import store as osc_store from .connection import http_request, http_GET, http_POST, http_PUT, http_DELETE from .store import Store from .util.helper import decode_list, decode_it, raw_input, _html_escape @@ -1238,7 +1239,8 @@ class Package: self.dir = workingdir or "." self.absdir = os.path.abspath(self.dir) - self.store = Store(self.dir) + self.store = osc_store.get_store(self.dir) + self.store.assert_is_package() self.storedir = os.path.join(self.absdir, store) self.progress_obj = progress_obj self.size_limit = size_limit @@ -1246,10 +1248,8 @@ class Package: if size_limit and size_limit == 0: self.size_limit = None - check_store_version(self.dir) - - self.prjname = store_read_project(self.dir) - self.name = store_read_package(self.dir) + self.prjname = self.store.project + self.name = self.store.package self.apiurl = self.store.apiurl self.update_datastructs() diff --git a/osc/store.py b/osc/store.py index a4f8f4fa..e81cae63 100644 --- a/osc/store.py +++ b/osc/store.py @@ -10,7 +10,7 @@ from xml.etree import ElementTree as ET from . import oscerr from ._private import api - +from . import git_scm class Store: STORE_DIR = ".osc" @@ -309,3 +309,22 @@ class Store: else: root = self.read_xml_node("_meta", "project").getroot() return root + + +def get_store(path, check=True, print_warnings=False): + """ + Return a store object that wraps SCM in given `path`: + - Store for OBS SCM + - GitStore for Git SCM + """ + try: + store = Store(path, check) + except oscerr.NoWorkingCopy as ex: + try: + store = git_scm.GitStore(path, check) + if print_warnings: + git_scm.warn_experimental() + except oscerr.NoWorkingCopy as ex_git: + # raise the original exception, do not inform that we've tried git working copy + raise ex from None + return store