1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-12 23:56:13 +01:00

Merge pull request #1535 from dmach/fix-branch-new-package

Fix 'branch' command to allow using '--new-package' option on packages that do not exist
This commit is contained in:
Daniel Mach 2024-04-12 17:18:01 +02:00 committed by GitHub
commit 1909c141d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 184 additions and 8 deletions

View File

@ -19,7 +19,15 @@ OSC="osc -A https://localhost"
# create projects
$OSC api -X PUT '/source/openSUSE.org/_meta' --file "$FIXTURES_DIR/prj/openSUSE.org.xml"
$OSC api -X PUT '/source/test:devel/_meta' --file "$FIXTURES_DIR/prj/test_devel.xml"
# test:factory:update inherits from test:factory; test:factory has test:devel devel project
$OSC api -X PUT '/source/test:factory/_meta' --file "$FIXTURES_DIR/prj/test_factory.xml"
$OSC api -X PUT '/source/test:factory:update/_meta' --file "$FIXTURES_DIR/prj/test_factory_update.xml"
# test:leap:15.6:update inherits from test:leap:15.6; test:leap:15.6 has no devel project
$OSC api -X PUT '/source/test:leap:15.6/_meta' --file "$FIXTURES_DIR/prj/test_leap_15.6.xml"
$OSC api -X PUT '/source/test:leap:15.6:update/_meta' --file "$FIXTURES_DIR/prj/test_leap_15.6_update.xml"
$OSC api -X PUT '/source/test:release/_meta' --file "$FIXTURES_DIR/prj/test_release.xml"
$OSC api -X PUT '/source/home:Admin/_meta' --file "$FIXTURES_DIR/prj/home_Admin.xml"
@ -92,6 +100,24 @@ $OSC commit -m 'Initial commit'
rm -rf "$TMP_DIR"
# create package 'test:leap:15.6/test-pkgA'
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"
$OSC checkout test:leap:15.6
cd "$_"
$OSC mkpac test-pkgA
cd "$_"
cp "$FIXTURES_DIR/pac/test-pkgA-1.spec" test-pkgA.spec
cp "$FIXTURES_DIR/pac/test-pkgA-1.changes" test-pkgA.changes
$OSC add test-pkgA.spec test-pkgA.changes
$OSC commit -m 'Initial commit'
rm -rf "$TMP_DIR"
# create package 'test:devel/test-pkgA'
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR"

View File

@ -0,0 +1,65 @@
Feature: `osc branch` command
@destructive
Scenario: Run `osc branch` on an inherited package that has no devel project set
When I execute osc with args "branch test:leap:15.6:update/test-pkgA"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin:branches:test:leap:15.6/test-pkgA/_link"
And stdout contains "<link project=\"test:leap:15.6\""
@destructive
Scenario: Run `osc branch --nodevelproject` on an inherited package that has no devel project set
When I execute osc with args "branch test:leap:15.6:update/test-pkgA"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin:branches:test:leap:15.6/test-pkgA/_link"
And stdout contains "<link project=\"test:leap:15.6\""
@destructive
Scenario: Run `osc branch --new-package` on an inherited package that has no devel project set
When I execute osc with args "branch --new-package test:leap:15.6:update/test-pkgA"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin:branches:test:leap:15.6:update/test-pkgA/_link"
And stdout contains "<link project=\"test:leap:15.6:update\""
@destructive
Scenario: Run `osc branch` on a package that has a devel project set
When I execute osc with args "branch test:factory/test-pkgA"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin:branches:test:devel/test-pkgA/_link"
And stdout contains "<link project=\"test:devel\""
@destructive
Scenario: Run `osc branch --nodevelproject` on a package that has a devel project set
When I execute osc with args "branch --nodevelproject test:factory/test-pkgA"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin:branches:test:factory/test-pkgA/_link"
And stdout contains "<link project=\"test:factory\""
@destructive
Scenario: Run `osc branch` on an inherited package that has a devel project set
When I execute osc with args "branch test:factory:update/test-pkgA"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin:branches:test:devel/test-pkgA/_link"
And stdout contains "<link project=\"test:devel\""
@destructive
Scenario: Run `osc branch --nodevelproject` on an inherited package that has a devel project set
When I execute osc with args "branch --nodevelproject test:factory:update/test-pkgA"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin:branches:test:factory/test-pkgA/_link"
And stdout contains "<link project=\"test:factory\""
@destructive
Scenario: Run `osc branch --new-package` on a package that doesn't exist
When I execute osc with args "branch --new-package test:factory/test-pkgNEW"
Then the exit code is 0
And I execute osc with args "api /source/home:Admin:branches:test:factory/test-pkgNEW/_link"
And stdout contains "<link project=\"test:factory\""

View File

@ -9,6 +9,9 @@ Scenario: Run `osc list` with no arguments to display all projects
openSUSE.org
test:devel
test:factory
test:factory:update
test:leap:15.6
test:leap:15.6:update
test:release
"""

View File

@ -43,8 +43,8 @@ Scenario: Run `osc repo add` on a project
@destructive
Scenario: Run `osc repo remove` on a project
When I execute osc with args "repo remove --yes test:factory --repo=standard --repo=does-not-exist"
And I execute osc with args "repo list test:factory"
When I execute osc with args "repo remove --yes test:factory:update --repo=standard --repo=does-not-exist"
And I execute osc with args "repo list test:factory:update"
Then stdout is
"""
"""

View File

@ -9,6 +9,7 @@ Scenario: Run `osc token` with no arguments
"""
@destructive
Scenario: Run `osc token --operation rebuild`
When I execute osc with args "token --create --operation rebuild test:factory test-pkgA"
Then stdout matches

View File

@ -15,6 +15,7 @@ Scenario: Run `osc undelete <project>/<package>`
@destructive
Scenario: Run `osc undelete <project>`
Given I execute osc with args "rdelete test:factory --recursive -m 'why:delete'"
When I execute osc with args "undelete test:factory -m 'why:undelete'"
Given I execute osc with args "rdelete test:factory:update --recursive -m 'why:delete'"
And the exit code is 0
When I execute osc with args "undelete test:factory:update -m 'why:undelete'"
Then the exit code is 0

View File

@ -0,0 +1,25 @@
<project name="test:factory:update">
<title/>
<description/>
<link project="test:factory"/>
<person userid="Admin" role="maintainer"/>
<lock>
<disable/>
</lock>
<build>
<disable/>
</build>
<repository name="standard">
<path project="test:factory" repository="standard"/>
<arch>x86_64</arch>
<arch>i586</arch>
</repository>
</project>

View File

@ -0,0 +1,24 @@
<project name="test:leap:15.6">
<title/>
<description/>
<person userid="Admin" role="maintainer"/>
<lock>
<disable/>
</lock>
<build>
<disable/>
</build>
<repository name="standard">
<!-- it's only for test purposes, let's use the same repo as test:factory -->
<path project="openSUSE.org:openSUSE:Tumbleweed" repository="standard"/>
<arch>x86_64</arch>
<arch>i586</arch>
</repository>
</project>

View File

@ -0,0 +1,25 @@
<project name="test:leap:15.6:update">
<title/>
<description/>
<link project="test:leap:15.6"/>
<person userid="Admin" role="maintainer"/>
<lock>
<disable/>
</lock>
<build>
<disable/>
</build>
<repository name="standard">
<path project="test:leap:15.6" repository="standard"/>
<arch>x86_64</arch>
<arch>i586</arch>
</repository>
</project>

View File

@ -6107,12 +6107,18 @@ def branch_pkg(
# BEGIN: Error out on branching scmsync packages; this should be properly handled in the API
# read src_package meta
m = b"".join(show_package_meta(apiurl, src_project, src_package))
root = ET.fromstring(m)
try:
m = b"".join(show_package_meta(apiurl, src_project, src_package))
root = ET.fromstring(m)
except HTTPError as e:
if e.code == 404 and missingok:
root = None
else:
raise
devel_project = None
devel_package = None
if not nodevelproject:
if root is not None and not nodevelproject:
devel_node = root.find("devel")
if devel_node is not None:
devel_project = devel_node.get("project")
@ -6123,7 +6129,7 @@ def branch_pkg(
root = ET.fromstring(m)
# error out if we're branching a scmsync package (we'd end up with garbage anyway)
if root.find("scmsync") is not None:
if root is not None and root.find("scmsync") is not None:
msg = "Cannot branch a package with <scmsync> set."
if devel_project:
raise oscerr.PackageError(devel_project, devel_package, msg)