1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-12-26 10:44:17 +01:00

Fix running 'osc build --alternative-project=...' when there's no .osc in the current directory

This commit is contained in:
2025-12-15 15:08:34 +01:00
parent a03093df37
commit 403eea94ce
3 changed files with 33 additions and 2 deletions

View File

@@ -11,3 +11,21 @@ Background:
Scenario: Run `osc build --just-print-buildroot`
When I execute osc with args "build --just-print-buildroot"
Then the exit code is 0
Scenario: Run `osc build --alternative-project in an empty directory`
Given I set working directory to "{context.osc.temp}"
# we point to a spec that doesn't exist, so the command parses the arguments but fails to run the build
When I execute osc with args "build --alternative-project=test:factory does-not-exist.spec"
Then stdout contains "Building does-not-exist.spec for standard/x86_64"
And the exit code is 2
Scenario: Run `osc build --alternative-project in an empty directory that has .git in the parent tree`
Given I set working directory to "{context.osc.temp}"
And I execute "git init -b main"
And I create directory "{context.osc.temp}/package"
# we point to a spec that doesn't exist, so the command parses the arguments but fails to run the build
When I execute osc with args "build --alternative-project=test:factory does-not-exist.spec"
Then stdout contains "Building does-not-exist.spec for standard/x86_64"
And the exit code is 2

View File

@@ -205,6 +205,12 @@ def step_impl(context):
raise AssertionError(f"Stderr doesn't match:\n{expected}\n\nActual stderr:\n{found}")
@behave.step('I create directory "{path}"')
def step_impl(context, path):
path = path.format(context=context)
os.makedirs(path, exist_ok=True)
@behave.step('I set working directory to "{path}"')
def step_impl(context, path):
path = path.format(context=context)

View File

@@ -7554,7 +7554,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
self._debug("arg_repository: ", arg_repository)
self._debug("arg_descr: ", arg_descr)
store_obj = osc_store.get_store(".")
# we shouldn't make any assumptions if the working copy is valid or not, we simply *try* to read the store and get the metadata from it
# the code that calls parse_repoarchdescr() is responsible for checking the store if necessary
store_obj = osc_store.get_store(".", check=False)
repositories = []
# store list of repos for potential offline use
@@ -7907,7 +7909,12 @@ Please submit there instead, or use --nodevelproject to force direct submission.
except oscerr.NoWorkingCopy:
if opts.apiurl and opts.alternative_project:
# HACK: ignore invalid working copy and run the build anyway if --alternative-project is specified
store = git_scm.GitStore(Path.cwd(), check=False)
try:
store = git_scm.GitStore(Path.cwd(), check=False)
except oscerr.NoWorkingCopy:
# HACK: if running from an empty directory that has no .git in the parent tree, initialize an empty Store() object
# this allows running the build with --alternative-project even if .osc doesn't exist at all
store = osc_store.Store(Path.cwd(), check=False)
else:
raise