Skip to content

Commit

Permalink
Fix local building in git projects
Browse files Browse the repository at this point in the history
osc did not find it's store and was unable to run a local build
in a project git
  • Loading branch information
adrianschroeter committed Sep 17, 2024
1 parent 1647395 commit 9ca0799
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
6 changes: 5 additions & 1 deletion osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7390,7 +7390,10 @@ def do_build(self, subcmd, opts, *args):

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:
Expand All @@ -7404,6 +7407,7 @@ def do_build(self, subcmd, opts, *args):
except oscerr.NoWorkingCopy:
store = None


# HACK: avoid calling some underlying store_*() functions from parse_repoarchdescr() method
# We'll fix parse_repoarchdescr() later because it requires a larger change
if not opts.alternative_project and isinstance(store, git_scm.GitStore):
Expand Down
17 changes: 15 additions & 2 deletions osc/git_scm/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ def __init__(self, path, check=True):
self.abspath = os.path.abspath(self.path)

# 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"))

# NOTE: we have only one store in project-git for all packages
self._toplevel = self._run_git(["rev-parse", "--show-toplevel"])
if self._toplevel == self.abspath:
self.is_project = True
self.is_package = False
else:
self.is_project = False
self.is_package = True

self._package = None
self._project = None
Expand Down Expand Up @@ -68,11 +75,17 @@ def apiurl(self):

@property
def project(self):
if self._project is None:
if self._toplevel:
with open(os.path.join(self._toplevel, '.osc/_project')) as f:
self._project = f.readline().strip()

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:
Expand Down
12 changes: 12 additions & 0 deletions osc/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


import os
import subprocess
from xml.etree import ElementTree as ET

from . import oscerr
Expand All @@ -29,6 +30,17 @@ def get_store(path, check=True, print_warnings=False):
git_scm.warn_experimental()
else:
store = None
try:
toplevel = subprocess.check_output(["git", "rev-parse", "--show-toplevel"],
encoding="utf-8",
stderr=subprocess.DEVNULL).strip()
if toplevel:
store = git_scm.GitStore(toplevel, check)
if print_warnings:
git_scm.warn_experimental()
except:

Check notice

Code scanning / CodeQL

Except block handles 'BaseException' Note

Except block directly handles BaseException.
# we nay should distinguish between git cli fails or git is not installed
pass

if not store:
msg = f"Directory '{path}' is not a working copy"
Expand Down

0 comments on commit 9ca0799

Please sign in to comment.