Skip to content

Commit 2ab459a

Browse files
committed
Improve GitStore's error messages by adding instructions on how to fix missing metadata
1 parent 263cb12 commit 2ab459a

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

osc/git_scm/store.py

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,28 @@ def assert_is_project(self):
255255
for name in ["apiurl", "project"]:
256256
if not getattr(self, name):
257257
missing.append(name)
258+
258259
if missing:
259-
msg = (
260-
f"Git SCM project working copy doesn't have the following metadata set: {', '.join(missing)}\n"
261-
"Use 'git-obs meta pull' or 'git-obs meta set' to fix that"
262-
)
260+
msg = f"Git SCM project working copy doesn't have the following metadata set: {', '.join(missing)}\n"
261+
262+
if "apiurl" in missing:
263+
msg += (
264+
"\n"
265+
"To fix apiurl:\n"
266+
" - Run 'git-obs meta pull' to retrieve the 'obs_apiurl' value from 'obs/configuration' repo, 'main' branch, 'configuration.yaml' file\n"
267+
" - Run 'git-obs meta set --apiurl=...\n"
268+
)
269+
270+
if "project" in missing:
271+
msg += (
272+
"\n"
273+
"To fix project:\n"
274+
" - Set 'obs_project' in '_manifest' file\n"
275+
" - Run 'git-obs meta set --project=...\n"
276+
)
277+
278+
msg += "\nCheck git-obs-metadata man page for more details"
279+
263280
raise oscerr.NoWorkingCopy(msg)
264281

265282
def assert_is_package(self):
@@ -271,11 +288,46 @@ def assert_is_package(self):
271288
for name in ["apiurl", "project", "package"]:
272289
if not getattr(self, name):
273290
missing.append(name)
291+
274292
if missing:
275-
msg = (
276-
f"Git SCM package working copy doesn't have the following metadata set: {', '.join(missing)}\n"
277-
"Use 'git-obs meta pull' or 'git-obs meta set' to fix that"
278-
)
293+
msg = f"Git SCM package working copy doesn't have the following metadata set: {', '.join(missing)}\n"
294+
295+
if self.project_store:
296+
msg += f" - The package has a parent project checkout: {self.project_store.abspath}\n"
297+
else:
298+
msg += " - The package has no parent project checkout\n"
299+
300+
if "apiurl" in missing:
301+
msg += "\n"
302+
msg += "To fix apiurl:\n"
303+
if self.project_store:
304+
msg += (
305+
" - Run 'git-obs meta pull' IN THE PROJECT in the parent directory to retrieve the 'obs_apiurl' value from 'obs/configuration' repo, 'main' branch, 'configuration.yaml' file\n"
306+
" - run 'git-obs meta set --apiurl=...' IN THE PROJECT\n"
307+
)
308+
else:
309+
msg += (
310+
" - Run 'git-obs meta set --apiurl=...'\n"
311+
)
312+
313+
if "project" in missing:
314+
msg += "\n"
315+
msg += "To fix project:\n"
316+
317+
if self.project_store:
318+
msg += (
319+
" - Set 'obs_project' in '_manifest' file IN THE PROJECT\n"
320+
" - Run 'git-obs meta set --project=...' IN THE PROJECT\n"
321+
)
322+
else:
323+
msg += (
324+
f" - Set 'obs_project' in the matching _ObsPrj git repo, '{self._git.current_branch}' branch, '_manifest' file\n"
325+
" Run 'git-obs meta pull'\n"
326+
" - Run 'git-obs meta set --project=...'\n"
327+
)
328+
329+
msg += "\nCheck git-obs-metadata man page for more details"
330+
279331
raise oscerr.NoWorkingCopy(msg)
280332

281333
# APIURL

0 commit comments

Comments
 (0)