Skip to content

Commit 263cb12

Browse files
committed
Be more permissive when loading parent project_store in GitStore
1 parent 8492d42 commit 263cb12

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

osc/git_scm/store.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,23 @@ def __init__(self, path: str, *, check: bool = True):
156156
self.project_store = None
157157
if self.type == "package":
158158
# load either .osc or .git project store from the directory above topdir
159-
for cls in (Store, self.__class__):
159+
if not self.project_store:
160160
try:
161-
store = cls(os.path.join(self.topdir, ".."))
161+
store = Store(os.path.join(self.topdir, ".."))
162162
store.assert_is_project()
163163
self.project_store = store
164-
break
165164
except oscerr.NoWorkingCopy:
166165
pass
166+
167+
if not self.project_store:
168+
try:
169+
# turn off 'check' because we want at least partial metadata to be inherited to the package
170+
store = GitStore(os.path.join(self.topdir, ".."), check=False)
171+
if store.type == "project":
172+
self.project_store = store
173+
except oscerr.NoWorkingCopy:
174+
pass
175+
167176
elif self.type == "project":
168177
# load .osc project store that is next to .git and may provide medatata we don't have
169178
try:

tests/test_git_scm_store.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def _git_init(self, path, *, separate_git_dir=None):
103103
if separate_git_dir:
104104
git_init_cmd += ["--separate-git-dir", separate_git_dir]
105105
subprocess.check_output(git_init_cmd, cwd=path)
106+
subprocess.check_output(["git", "commit", "-m", "empty", "--allow-empty"], cwd=path)
106107
subprocess.check_output(["git", "checkout", "-b", "factory", "-q"], cwd=path)
107108
subprocess.check_output(["git", "remote", "add", "origin", "https://example.com/packages/my-package.git"], cwd=path)
108109

@@ -326,6 +327,27 @@ def test_pkg_git_with_no_project(self):
326327
with self.assertRaises(oscerr.NoWorkingCopy):
327328
GitStore(pkg_path)
328329

330+
def test_pkg_git_in_submodule(self):
331+
import subprocess
332+
333+
pkg_upstream_path = os.path.join(self.tmpdir, "pkg-upstream")
334+
self._git_init(pkg_upstream_path)
335+
336+
prj_path = os.path.join(self.tmpdir, "project")
337+
self._git_init(prj_path)
338+
manifest_data = {
339+
"obs_apiurl": "https://api.example.com",
340+
"obs_project": "PROJ",
341+
}
342+
self._write(os.path.join(prj_path, "_manifest"), osc_yaml.yaml_dumps(manifest_data))
343+
344+
subprocess.check_output(["git", "-c", "protocol.file.allow=always", "submodule", "add", pkg_upstream_path, "pkg"], cwd=prj_path, stderr=subprocess.DEVNULL)
345+
pkg_path = os.path.join(prj_path, "pkg")
346+
347+
store = GitStore(pkg_path)
348+
self.assertEqual(store.project, "PROJ")
349+
self.assertEqual(store.package, "pkg-upstream")
350+
329351

330352
if __name__ == "__main__":
331353
unittest.main()

0 commit comments

Comments
 (0)