Skip to content

Commit

Permalink
linktobranch: Migrate to pop_project_package_from_args()
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Jan 12, 2023
1 parent cbcfd91 commit f7d2d15
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
27 changes: 27 additions & 0 deletions behave/features/linktobranch.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature: `osc linktobranch` command


# common steps for all scenarios
Background:
Given I set working directory to "{context.osc.temp}"
And I execute osc with args "linkpac test:factory/test-pkgA home:Admin"


@destructive
Scenario: Run `osc linktobranch <project> <package>`
When I execute osc with args "linktobranch home:Admin test-pkgA"
Then the exit code is 0


@destructive
Scenario: Run `osc linktobranch <project>`
When I execute osc with args "linktobranch home:Admin"
Then the exit code is 1


@destructive
Scenario: Run `osc linktobranch` from a package working copy
Given I execute osc with args "co home:Admin/test-pkgA"
And I set working directory to "{context.osc.temp}/home:Admin/test-pkgA"
When I execute osc with args "linktobranch"
Then the exit code is 0
30 changes: 12 additions & 18 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2944,30 +2944,24 @@ def do_linktobranch(self, subcmd, opts, *args):
to a branch. This is a full copy with a _link file pointing to the branched place.
usage:
osc linktobranch # can be used in checked out package
osc linktobranch # from a package working copy
osc linktobranch PROJECT PACKAGE
"""
args = slash_split(args)
apiurl = self.get_api_url()

if len(args) == 0:
wd = Path.cwd()
project = store_read_project(wd)
package = store_read_package(wd)
update_local_dir = True
elif len(args) < 2:
raise oscerr.WrongArgs('Too few arguments (required none or two)')
elif len(args) > 2:
raise oscerr.WrongArgs('Too many arguments (required none or two)')
else:
project = self._process_project_name(args[0])
package = args[1]
update_local_dir = False
# assume we're in a working copy if no args were specfied
update_working_copy = not args

args = list(args)
project, package = pop_project_package_from_args(
args, default_project=".", default_package=".", package_is_optional=False
)
ensure_no_remaining_args(args)

# execute
link_to_branch(apiurl, project, package)
if update_local_dir:
pac = Package(wd)

if update_working_copy:
pac = Package(Path.cwd())
pac.update(rev=pac.latest_rev())

@cmdln.option('-m', '--message', metavar='TEXT',
Expand Down

0 comments on commit f7d2d15

Please sign in to comment.