1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-19 08:42:11 +01:00

Fix local building in git projects

osc did not find it's store and was unable to run a local build
in a project git
This commit is contained in:
Adrian Schröter 2024-08-29 13:58:46 +02:00 committed by Daniel Mach
parent 6d91083413
commit a6db8ad25c
3 changed files with 51 additions and 14 deletions

View File

@ -7269,6 +7269,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
@cmdln.alias('repos')
@cmdln.alias('platforms')
def do_repositories(self, subcmd, opts, *args):
from . import store as osc_store
from .core import build_table
from .core import get_repos_of_project
from .core import get_repositories_of_project
@ -7299,11 +7300,12 @@ Please submit there instead, or use --nodevelproject to force direct submission.
project = self._process_project_name(args[0])
package = args[1]
elif len(args) == 0:
if is_package_dir('.'):
package = store_read_package('.')
project = store_read_project('.')
elif is_project_dir('.'):
project = store_read_project('.')
store = osc_store.get_store(".")
if store.is_package:
package = store.package
project = store.project
elif store.is_project:
project = store.project
else:
raise oscerr.WrongArgs('Wrong number of arguments')
@ -7731,7 +7733,10 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if not opts.local_package:
store = osc_store.get_store(Path.cwd(), print_warnings=True)
store.assert_is_package()
if isinstance(store, git_scm.store.GitStore):
opts.local_package = True
else:
store.assert_is_package()
try:
if opts.alternative_project and opts.alternative_project == store.project:

View File

@ -29,10 +29,26 @@ class GitStore:
def __init__(self, path, check=True):
self.path = path
self.abspath = os.path.abspath(self.path)
try:
self.toplevel = self._run_git(["rev-parse", "--show-toplevel"])
self.toplevel = os.path.abspath(self.toplevel)
except subprocess.CalledProcessError:
self.toplevel = None
# TODO: how to determine if the current git repo contains a project or a package?
self.is_project = False
self.is_package = os.path.exists(os.path.join(self.abspath, ".git"))
self.is_package = False
if self.toplevel:
# NOTE: we have only one store in project-git for all packages
config_path = os.path.join(self.toplevel, "_config")
pbuild_path = os.path.join(self.toplevel, "_pbuild")
if self.toplevel == self.abspath and (os.path.isfile(config_path) or os.path.isfile(pbuild_path)):
self.is_project = True
self.is_package = False
else:
self.is_project = False
self.is_package = True
self._package = None
self._project = None
@ -68,11 +84,21 @@ class GitStore:
@property
def project(self):
if self._project is None:
try:
# NOTE: this never triggers if a store is retrieved from osc.store.get_store(),
# because obs_scm store takes precedence as .osc is present
with open(os.path.join(self.toplevel, ".osc/_project")) as f:
self._project = f.readline().strip()
except FileNotFoundError:
pass
if self._project is None:
# get project from the branch name
branch = self._run_git(["branch", "--show-current"])
# HACK: replace hard-coded mapping with metadata from git or the build service
# NOTE: you never know which git repo is supposed to be used in which project
if branch == "factory":
self._project = "openSUSE:Factory"
else:

View File

@ -21,14 +21,20 @@ def get_store(path, check=True, print_warnings=False):
"""
# if there are '.osc' and '.git' directories next to each other, '.osc' takes preference
if os.path.exists(os.path.join(path, ".osc")):
store = None
try:
store = Store(path, check)
elif os.path.exists(os.path.join(path, ".git")):
store = git_scm.GitStore(path, check)
if print_warnings:
git_scm.warn_experimental()
else:
store = None
except oscerr.NoWorkingCopy:
pass
if not store:
try:
store = git_scm.GitStore(path, check)
if print_warnings:
git_scm.warn_experimental()
except oscerr.NoWorkingCopy:
pass
if not store:
msg = f"Directory '{path}' is not a working copy"