Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'branch' command to allow using '--new-package' option on packages that do not exist #1535

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions behave/container-setup-initial-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down
65 changes: 65 additions & 0 deletions behave/features/branch.feature
Original file line number Diff line number Diff line change
@@ -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\""
3 changes: 3 additions & 0 deletions behave/features/list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand Down
4 changes: 2 additions & 2 deletions behave/features/repo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
"""
1 change: 1 addition & 0 deletions behave/features/token.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions behave/features/undelete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions behave/fixtures/prj/test_factory_update.xml
Original file line number Diff line number Diff line change
@@ -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>

24 changes: 24 additions & 0 deletions behave/fixtures/prj/test_leap_15.6.xml
Original file line number Diff line number Diff line change
@@ -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>

25 changes: 25 additions & 0 deletions behave/fixtures/prj/test_leap_15.6_update.xml
Original file line number Diff line number Diff line change
@@ -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>

14 changes: 10 additions & 4 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
Loading