mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-21 17:52:14 +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:
parent
6d91083413
commit
a6db8ad25c
@ -7269,6 +7269,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
@cmdln.alias('repos')
|
@cmdln.alias('repos')
|
||||||
@cmdln.alias('platforms')
|
@cmdln.alias('platforms')
|
||||||
def do_repositories(self, subcmd, opts, *args):
|
def do_repositories(self, subcmd, opts, *args):
|
||||||
|
from . import store as osc_store
|
||||||
from .core import build_table
|
from .core import build_table
|
||||||
from .core import get_repos_of_project
|
from .core import get_repos_of_project
|
||||||
from .core import get_repositories_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])
|
project = self._process_project_name(args[0])
|
||||||
package = args[1]
|
package = args[1]
|
||||||
elif len(args) == 0:
|
elif len(args) == 0:
|
||||||
if is_package_dir('.'):
|
store = osc_store.get_store(".")
|
||||||
package = store_read_package('.')
|
if store.is_package:
|
||||||
project = store_read_project('.')
|
package = store.package
|
||||||
elif is_project_dir('.'):
|
project = store.project
|
||||||
project = store_read_project('.')
|
elif store.is_project:
|
||||||
|
project = store.project
|
||||||
else:
|
else:
|
||||||
raise oscerr.WrongArgs('Wrong number of arguments')
|
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:
|
if not opts.local_package:
|
||||||
store = osc_store.get_store(Path.cwd(), print_warnings=True)
|
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:
|
try:
|
||||||
if opts.alternative_project and opts.alternative_project == store.project:
|
if opts.alternative_project and opts.alternative_project == store.project:
|
||||||
|
@ -29,10 +29,26 @@ class GitStore:
|
|||||||
def __init__(self, path, check=True):
|
def __init__(self, path, check=True):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.abspath = os.path.abspath(self.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?
|
# TODO: how to determine if the current git repo contains a project or a package?
|
||||||
self.is_project = False
|
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._package = None
|
||||||
self._project = None
|
self._project = None
|
||||||
@ -68,11 +84,21 @@ class GitStore:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def project(self):
|
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:
|
if self._project is None:
|
||||||
# get project from the branch name
|
# get project from the branch name
|
||||||
branch = self._run_git(["branch", "--show-current"])
|
branch = self._run_git(["branch", "--show-current"])
|
||||||
|
|
||||||
# HACK: replace hard-coded mapping with metadata from git or the build service
|
# 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":
|
if branch == "factory":
|
||||||
self._project = "openSUSE:Factory"
|
self._project = "openSUSE:Factory"
|
||||||
else:
|
else:
|
||||||
|
20
osc/store.py
20
osc/store.py
@ -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 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)
|
store = Store(path, check)
|
||||||
elif os.path.exists(os.path.join(path, ".git")):
|
except oscerr.NoWorkingCopy:
|
||||||
store = git_scm.GitStore(path, check)
|
pass
|
||||||
if print_warnings:
|
|
||||||
git_scm.warn_experimental()
|
if not store:
|
||||||
else:
|
try:
|
||||||
store = None
|
store = git_scm.GitStore(path, check)
|
||||||
|
if print_warnings:
|
||||||
|
git_scm.warn_experimental()
|
||||||
|
except oscerr.NoWorkingCopy:
|
||||||
|
pass
|
||||||
|
|
||||||
if not store:
|
if not store:
|
||||||
msg = f"Directory '{path}' is not a working copy"
|
msg = f"Directory '{path}' is not a working copy"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user