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

Improve detecting git packages, use .osc metadata from project in parent directory

This commit is contained in:
Daniel Mach 2025-02-13 13:14:51 +01:00
parent 96c5a1491c
commit 29508519be

View File

@ -79,20 +79,42 @@ class GitStore:
@property @property
def apiurl(self): def apiurl(self):
from ..obs_scm.store import Store
# read apiurl from the current directory with .osc metadata
# NOTE: this never triggers if a store is retrieved from osc.store.get_store(),
# because obs_scm store takes precedence as .osc is present
store = Store(self.toplevel, check=False)
if store.apiurl:
return store.apiurl
# read project from parent directory that contains a project with .osc metadata
store = Store(os.path.join(self.toplevel, ".."), check=False)
if store.is_project and store.apiurl:
return store.apiurl
# HACK: we're using the currently configured apiurl # HACK: we're using the currently configured apiurl
return osc_conf.config["apiurl"] return osc_conf.config["apiurl"]
@property @property
def project(self): def project(self):
if self._project is None: from ..obs_scm.store import Store
try:
# read project from the current directory with .osc metadata
# NOTE: this never triggers if a store is retrieved from osc.store.get_store(), # NOTE: this never triggers if a store is retrieved from osc.store.get_store(),
# because obs_scm store takes precedence as .osc is present # because obs_scm store takes precedence as .osc is present
with open(os.path.join(self.toplevel, ".osc/_project")) as f: if self._project is None:
self._project = f.readline().strip() store = Store(self.toplevel, check=False)
except FileNotFoundError: if store.project:
pass self._project = store.project
# read project from parent directory that contains a project with .osc metadata
if self._project is None:
store = Store(os.path.join(self.toplevel, ".."), check=False)
if store.is_project and store.project:
self._project = store.project
# guess project from git branch
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"])