1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 06:46:15 +01:00

Change 'repairwc' command to fix missing .osc/_osclib_version

This commit is contained in:
Daniel Mach 2024-07-02 10:53:38 +02:00
parent 30a33b91f1
commit 5c185f26f7
5 changed files with 74 additions and 8 deletions

View File

@ -0,0 +1,47 @@
Feature: `osc repairwc` command
Scenario: Run `osc repairwc` on a project
Given I set working directory to "{context.osc.temp}"
And I execute osc with args "checkout test:factory"
And I set working directory to "{context.osc.temp}/test:factory"
When I execute osc with args "repairwc"
Then the exit code is 0
When I execute osc with args "status"
Then the exit code is 0
Scenario: Run `osc repairwc` on a project without .osc/_osclib_version
Given I set working directory to "{context.osc.temp}"
And I execute osc with args "checkout test:factory"
And I set working directory to "{context.osc.temp}/test:factory"
And I remove file "{context.osc.temp}/test:factory/.osc/_osclib_version"
When I execute osc with args "status"
Then the exit code is 1
When I execute osc with args "repairwc"
Then the exit code is 0
When I execute osc with args "status"
Then the exit code is 0
Scenario: Run `osc repairwc` on a package
Given I set working directory to "{context.osc.temp}"
And I execute osc with args "checkout test:factory/test-pkgA"
And I set working directory to "{context.osc.temp}/test:factory/test-pkgA"
When I execute osc with args "repairwc"
Then the exit code is 0
When I execute osc with args "status"
Then the exit code is 0
Scenario: Run `osc repairwc` on a package without .osc/_osclib_version
Given I set working directory to "{context.osc.temp}"
And I execute osc with args "checkout test:factory/test-pkgA"
And I set working directory to "{context.osc.temp}/test:factory/test-pkgA"
And I remove file "{context.osc.temp}/test:factory/test-pkgA/.osc/_osclib_version"
When I execute osc with args "status"
Then the exit code is 1
When I execute osc with args "repairwc"
Then the exit code is 0
When I execute osc with args "status"
Then the exit code is 0

View File

@ -194,6 +194,13 @@ def step_impl(context, source, destination):
shutil.copyfile(source, destination)
@behave.step('I remove file "{path}"')
def step_impl(context, path):
# substitutions
path = path.format(context=context)
os.remove(path)
@behave.step('file "{path}" exists')
def step_impl(context, path):
path = path.format(context=context)

View File

@ -10102,8 +10102,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if is_project_dir(i):
try:
prj = Project(i, getPackageList=False)
except oscerr.WorkingCopyInconsistent as e:
if '_apiurl' in e.dirty_files and (not apiurl or not opts.force_apiurl):
except (oscerr.WorkingCopyInconsistent, oscerr.NoWorkingCopy) as e:
dirty_files = getattr(e, "dirty_files", [])
if '_apiurl' in dirty_files and (not apiurl or not opts.force_apiurl):
apiurl = get_apiurl(apiurls)
prj = Project(i, getPackageList=False, wc_check=False)
prj.wc_repair(apiurl)
@ -10122,8 +10123,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
for pdir in pacs:
try:
p = Package(pdir)
except oscerr.WorkingCopyInconsistent as e:
if '_apiurl' in e.dirty_files and (not apiurl or not opts.force_apiurl):
except (oscerr.WorkingCopyInconsistent, oscerr.NoWorkingCopy) as e:
dirty_files = getattr(e, "dirty_files", [])
if '_apiurl' in dirty_files and (not apiurl or not opts.force_apiurl):
apiurl = get_apiurl(apiurls)
p = Package(pdir, wc_check=False)
p.wc_repair(apiurl)

View File

@ -51,7 +51,7 @@ class Package:
self.dir = workingdir or "."
self.absdir = os.path.abspath(self.dir)
self.store = osc_store.get_store(self.dir)
self.store = osc_store.get_store(self.dir, check=wc_check)
self.store.assert_is_package()
self.storedir = os.path.join(self.absdir, store)
self.progress_obj = progress_obj
@ -178,8 +178,13 @@ class Package:
def wc_repair(self, apiurl: Optional[str] = None):
from ..core import get_source_file
store = Store(self.dir)
store = Store(self.dir, check=False)
store.assert_is_package()
# there was a time when osc did not write _osclib_version file; let's assume these checkouts have version 1.0
if not store.exists("_osclib_version"):
store.write_string("_osclib_version", "1.0")
if not store.exists("_apiurl") or apiurl:
if apiurl is None:
msg = 'cannot repair wc: the \'_apiurl\' file is missing but ' \

View File

@ -87,7 +87,7 @@ class Project:
self.dir = Path(dir)
self.absdir = os.path.abspath(dir)
self.store = Store(dir)
self.store = Store(dir, check=wc_check)
self.progress_obj = progress_obj
self.name = store_read_project(self.dir)
@ -140,8 +140,13 @@ class Project:
return dirty_files
def wc_repair(self, apiurl: Optional[str] = None):
store = Store(self.dir)
store = Store(self.dir, check=False)
store.assert_is_project()
# there was a time when osc did not write _osclib_version file; let's assume these checkouts have version 1.0
if not store.exists("_osclib_version"):
store.write_string("_osclib_version", "1.0")
if not store.exists("_apiurl") or apiurl:
if apiurl is None:
msg = 'cannot repair wc: the \'_apiurl\' file is missing but ' \