diff --git a/behave/features/linkpac.feature b/behave/features/linkpac.feature
index 93339998..a4eec3f8 100644
--- a/behave/features/linkpac.feature
+++ b/behave/features/linkpac.feature
@@ -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 "\s*\s*"
+
+
+@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=''"
+ 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 ""
diff --git a/osc/core.py b/osc/core.py
index 37709b57..feb7592d 100644
--- a/osc/core.py
+++ b/osc/core.py
@@ -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="")