Skip to content

Commit

Permalink
Merge pull request #1693 from dmach/fix-linkpac-project-link
Browse files Browse the repository at this point in the history
Fix 'linkpac' command for projects with a project link
  • Loading branch information
dmach authored Jan 10, 2025
2 parents 4fd94a0 + bb51a82 commit f2b83ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 10 additions & 1 deletion behave/features/linkpac.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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\">"
13 changes: 11 additions & 2 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
Expand All @@ -3317,11 +3326,11 @@ def link_pac(
if disable_publish:
dst_package_obj.publish_list = [{"flag": "disable"}]

dst_package_obj.scmsync = None

if dst_package_obj.has_changed():
dst_package_obj.to_api(apiurl)

dst_package_obj.scmsync = None

# create the _link file
# but first, make sure not to overwrite an existing one
if '_link' in meta_get_filelist(apiurl, dst_project, dst_package):
Expand Down

0 comments on commit f2b83ec

Please sign in to comment.