1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-21 01:32:10 +01:00

Fix 'linkpac' command for projects with a project link

This commit is contained in:
Daniel Mach 2025-01-10 10:56:09 +01:00
parent c5b4835c92
commit bb51a825f8
2 changed files with 19 additions and 1 deletions

View File

@ -35,9 +35,18 @@ Scenario: Run `osc linkpac --disable-publish`
@destructive
Scenario: Run `osc linkpac on a locked package`
Scenario: Run `osc linkpac` on a locked package
Given I execute osc with args "lock test:factory/test-pkgA"
When I execute osc with args "linkpac test:factory/test-pkgA home:Admin/test-pkgA"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin/test-pkgA/_meta"
And stdout doesn't contain "<lock>\s*<enable/>\s*</lock>"
@destructive
Scenario: Run `osc linkpac` with target project that has a project link
Given I execute osc with args "api -X PUT /source/home:Admin/_meta --data='<project name="home:Admin"><title/><description/><link project="test:factory"/></project>'"
When I execute osc with args "linkpac test:factory/test-pkgA home:Admin"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin/test-pkgA/_link"
And stdout contains "<link project=\"test:factory\" package=\"test-pkgA\">"

View File

@ -3287,12 +3287,21 @@ def link_pac(
apiurl = conf.config["apiurl"]
create_dst_package = False
src_package_obj = obs_api.Package.from_api(apiurl, src_project, src_package)
try:
dst_package_obj = obs_api.Package.from_api(apiurl, dst_project, dst_package)
if dst_package_obj.project != dst_project:
# If the target package doesn't exist and the target project contains a project link,
# the package meta from the linked project is returned instead!
# We need to detect it and create the target package based on source package meta.
create_dst_package = True
except HTTPError as e:
if e.code != 404:
raise
create_dst_package = True
if create_dst_package:
if missing_target:
# we start with empty values because we want has_changed() to return True
dst_package_obj = obs_api.Package(project="", name="")