mirror of
https://github.com/openSUSE/osc.git
synced 2025-09-07 21:58:41 +02:00
Improve detection of git package when project git contains both .git and .osc
This commit is contained in:
@@ -98,9 +98,6 @@ class GitStore:
|
||||
return None
|
||||
|
||||
def get_project_git_scm_store(self):
|
||||
if not self.is_package:
|
||||
return None
|
||||
|
||||
path = self.abspath
|
||||
while path:
|
||||
if path == "/":
|
||||
@@ -210,13 +207,26 @@ class GitStore:
|
||||
|
||||
@property
|
||||
def apiurl(self):
|
||||
from ..obs_scm import Store
|
||||
|
||||
if not self._apiurl:
|
||||
if self.is_package and self.project_store:
|
||||
if not self._apiurl and self.project_store:
|
||||
# get apiurl from .osc that is at the same level as project .git
|
||||
try:
|
||||
store = Store(self.project_store.abspath)
|
||||
store.assert_is_project()
|
||||
self._apiurl = store.apiurl
|
||||
except oscerr.NoWorkingCopy:
|
||||
pass
|
||||
|
||||
if not self._apiurl and self.is_package and self.project_store:
|
||||
# read apiurl from parent directory that contains a project with .osc metadata
|
||||
self._apiurl = self.project_store.apiurl
|
||||
|
||||
if not self._apiurl:
|
||||
# HACK: use the currently configured apiurl
|
||||
self._apiurl = osc_conf.config["apiurl"]
|
||||
|
||||
return self._apiurl
|
||||
|
||||
@apiurl.setter
|
||||
@@ -225,11 +235,22 @@ class GitStore:
|
||||
|
||||
@property
|
||||
def project(self):
|
||||
from ..obs_scm import Store
|
||||
|
||||
if not self._project:
|
||||
if self.is_package:
|
||||
# handle _project in a package
|
||||
|
||||
if self.project_store:
|
||||
if not self._project and self.project_store:
|
||||
# get project from .osc that is at the same level as project .git
|
||||
try:
|
||||
store = Store(self.project_store.abspath)
|
||||
store.assert_is_project()
|
||||
self._project = store.project
|
||||
except oscerr.NoWorkingCopy:
|
||||
pass
|
||||
|
||||
if not self._project and self.project_store:
|
||||
# read project from detected project store
|
||||
self._project = self.project_store.project
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import unittest
|
||||
|
||||
import osc.conf
|
||||
from osc.git_scm.store import GitStore
|
||||
from osc.util import yaml as osc_yaml
|
||||
|
||||
from .common import patch
|
||||
|
||||
@@ -133,6 +134,25 @@ class TestGitStoreProject(unittest.TestCase):
|
||||
self.assertEqual(store.project, "PROJ")
|
||||
self.assertEqual(store.package, "my-package")
|
||||
|
||||
def test_nested_pkg_osc_project_from_git(self):
|
||||
# project .git and .osc are next to each other
|
||||
prj_path = os.path.join(self.tmpdir, "project")
|
||||
self._git_init(prj_path)
|
||||
self._write(os.path.join(prj_path, "_config"))
|
||||
self._osc_init(prj_path, project="PROJ")
|
||||
|
||||
# the nested package must be under a subdirectory tracked in _subdirs file
|
||||
# otherwise it's not recognized as a package
|
||||
subdirs = {"subdirs": ["group"]}
|
||||
self._write(os.path.join(prj_path, "_subdirs"), osc_yaml.yaml_dumps(subdirs))
|
||||
|
||||
pkg_path = os.path.join(prj_path, "group/package")
|
||||
os.makedirs(pkg_path, exist_ok=True)
|
||||
|
||||
store = GitStore(pkg_path)
|
||||
self.assertEqual(store.project, "PROJ")
|
||||
self.assertEqual(store.package, "my-package")
|
||||
|
||||
def test_pkg_git_project(self):
|
||||
prj_path = os.path.join(self.tmpdir, "project")
|
||||
self._git_init(prj_path)
|
||||
|
Reference in New Issue
Block a user