Skip to content

Commit

Permalink
Add limited support of Git SCM to the 'build' command
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Jul 28, 2023
1 parent 4138a40 commit 7943b55
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
8 changes: 7 additions & 1 deletion osc/commandline.py
Expand Up @@ -30,6 +30,7 @@
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 *
Expand Down Expand Up @@ -7197,12 +7198,17 @@ def do_build(self, subcmd, opts, *args):
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]]
Expand Down
10 changes: 5 additions & 5 deletions osc/core.py
Expand Up @@ -49,6 +49,7 @@
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
Expand Down Expand Up @@ -1238,18 +1239,17 @@ def __init__(self, workingdir, progress_obj=None, size_limit=None, wc_check=True

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
self.scm_url = self.store.scmurl
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()
Expand Down
21 changes: 20 additions & 1 deletion osc/store.py
Expand Up @@ -10,7 +10,7 @@

from . import oscerr
from ._private import api

from . import git_scm

class Store:
STORE_DIR = ".osc"
Expand Down Expand Up @@ -309,3 +309,22 @@ def _meta_node(self):
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

0 comments on commit 7943b55

Please sign in to comment.