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 4, 2024
1 parent 1647395 commit 5c8ea7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion osc/git_scm/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, path, check=True):

# 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"))
self.is_package = os.path.exists(os.path.join(self.abspath, ".git")) or os.path.exists(os.path.join(self.abspath, "../.git"))

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

@property
def project(self):
if self._project is None:
with open(os.path.join(os.path.join(self.abspath, '.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
2 changes: 2 additions & 0 deletions osc/obs_scm/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ def status(self, pac: str):
if st is None and exists:
return '?'
elif st is None:
if os.path.exists(os.path.join(self.absdir, '.git')):
return '?'
raise oscerr.OscIOError(None, f'osc: \'{pac}\' is not under version control')
elif st in ('A', ' ') and not exists:
return '!'
Expand Down
4 changes: 4 additions & 0 deletions osc/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def get_store(path, check=True, print_warnings=False):
store = git_scm.GitStore(path, check)
if print_warnings:
git_scm.warn_experimental()
elif os.path.exists(os.path.join(path, "../.git")):
store = git_scm.GitStore(os.path.join(path, "../"), check)
if print_warnings:
git_scm.warn_experimental()
else:
store = None

Expand Down

0 comments on commit 5c8ea7f

Please sign in to comment.