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

Merge pull request #1705 from dmach/fix-git-project-local-build

Improve detecting git packages, use .osc metadata from project in parent directory
This commit is contained in:
Daniel Mach 2025-02-13 14:50:56 +01:00 committed by GitHub
commit 7b15faf53d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 11 deletions

View File

@ -873,9 +873,10 @@ class Osc(cmdln.Cmdln):
print("Path.cwd() failed: ", e, file=sys.stderr)
sys.exit(1)
if (is_package_dir(localdir) or is_project_dir(localdir)) and not self.options.apiurl:
return osc_store.Store(Path.cwd()).apiurl
else:
try:
store = osc_store.get_store(Path.cwd())
return store.apiurl
except oscerr.NoWorkingCopy:
return conf.config['apiurl']
def do_version(self, subcmd, opts):

View File

@ -79,20 +79,42 @@ class GitStore:
@property
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
return osc_conf.config["apiurl"]
@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
from ..obs_scm.store import Store
# read project 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
if self._project is None:
store = Store(self.toplevel, check=False)
if store.project:
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:
# get project from the branch name
branch = self._run_git(["branch", "--show-current"])