From b0b8588e7c520d4ff111605db41fd051aa26c9a9 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Fri, 11 Oct 2024 14:25:08 +0200 Subject: [PATCH] Fix crash in 'build' command when building with --local-package --alternative-project from a locally initialized .osc package --- osc/build.py | 2 +- osc/commandline.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/osc/build.py b/osc/build.py index 6fbf8ea12..a6558c4dd 100644 --- a/osc/build.py +++ b/osc/build.py @@ -917,7 +917,7 @@ def main(apiurl, store, opts, argv): bc_file = None bi_filename = '_buildinfo-%s-%s.xml' % (repo, arch) bc_filename = '_buildconfig-%s-%s' % (repo, arch) - if store.is_package and os.access(core.store, os.W_OK): + if store is not None and store.is_package and os.access(core.store, os.W_OK): bi_filename = os.path.join(os.getcwd(), core.store, bi_filename) bc_filename = os.path.join(os.getcwd(), core.store, bc_filename) elif not os.access('.', os.W_OK): diff --git a/osc/commandline.py b/osc/commandline.py index 86a29f172..fa6b2e6f6 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -7408,10 +7408,19 @@ def do_build(self, subcmd, opts, *args): pass else: try: - store = osc_store.get_store(os.path.dirname(Path.cwd()), print_warnings=True) + store = osc_store.get_store(Path.cwd(), print_warnings=True) except oscerr.NoWorkingCopy: store = None + if store is None: + try: + # if opts.local_package is set, build.main() reads project from the store and sets package to "_project" + # that's why we're ok with store from the parent directory that holds information about the project + # FIXME: the parent directory may contain a git repo that doesn't contain a project; we have no way of recognizing that! + store = osc_store.get_store(os.path.dirname(Path.cwd()), print_warnings=True) + except oscerr.NoWorkingCopy: + store = 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):