mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-12 00:46:14 +01:00
Change 'repairwc' command to fix missing .osc/_osclib_version
This commit is contained in:
parent
30a33b91f1
commit
5c185f26f7
47
behave/features/repairwc.feature
Normal file
47
behave/features/repairwc.feature
Normal 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
|
@ -194,6 +194,13 @@ def step_impl(context, source, destination):
|
|||||||
shutil.copyfile(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')
|
@behave.step('file "{path}" exists')
|
||||||
def step_impl(context, path):
|
def step_impl(context, path):
|
||||||
path = path.format(context=context)
|
path = path.format(context=context)
|
||||||
|
@ -10102,8 +10102,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
if is_project_dir(i):
|
if is_project_dir(i):
|
||||||
try:
|
try:
|
||||||
prj = Project(i, getPackageList=False)
|
prj = Project(i, getPackageList=False)
|
||||||
except oscerr.WorkingCopyInconsistent as e:
|
except (oscerr.WorkingCopyInconsistent, oscerr.NoWorkingCopy) as e:
|
||||||
if '_apiurl' in e.dirty_files and (not apiurl or not opts.force_apiurl):
|
dirty_files = getattr(e, "dirty_files", [])
|
||||||
|
if '_apiurl' in dirty_files and (not apiurl or not opts.force_apiurl):
|
||||||
apiurl = get_apiurl(apiurls)
|
apiurl = get_apiurl(apiurls)
|
||||||
prj = Project(i, getPackageList=False, wc_check=False)
|
prj = Project(i, getPackageList=False, wc_check=False)
|
||||||
prj.wc_repair(apiurl)
|
prj.wc_repair(apiurl)
|
||||||
@ -10122,8 +10123,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
for pdir in pacs:
|
for pdir in pacs:
|
||||||
try:
|
try:
|
||||||
p = Package(pdir)
|
p = Package(pdir)
|
||||||
except oscerr.WorkingCopyInconsistent as e:
|
except (oscerr.WorkingCopyInconsistent, oscerr.NoWorkingCopy) as e:
|
||||||
if '_apiurl' in e.dirty_files and (not apiurl or not opts.force_apiurl):
|
dirty_files = getattr(e, "dirty_files", [])
|
||||||
|
if '_apiurl' in dirty_files and (not apiurl or not opts.force_apiurl):
|
||||||
apiurl = get_apiurl(apiurls)
|
apiurl = get_apiurl(apiurls)
|
||||||
p = Package(pdir, wc_check=False)
|
p = Package(pdir, wc_check=False)
|
||||||
p.wc_repair(apiurl)
|
p.wc_repair(apiurl)
|
||||||
|
@ -51,7 +51,7 @@ class Package:
|
|||||||
|
|
||||||
self.dir = workingdir or "."
|
self.dir = workingdir or "."
|
||||||
self.absdir = os.path.abspath(self.dir)
|
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.store.assert_is_package()
|
||||||
self.storedir = os.path.join(self.absdir, store)
|
self.storedir = os.path.join(self.absdir, store)
|
||||||
self.progress_obj = progress_obj
|
self.progress_obj = progress_obj
|
||||||
@ -178,8 +178,13 @@ class Package:
|
|||||||
def wc_repair(self, apiurl: Optional[str] = None):
|
def wc_repair(self, apiurl: Optional[str] = None):
|
||||||
from ..core import get_source_file
|
from ..core import get_source_file
|
||||||
|
|
||||||
store = Store(self.dir)
|
store = Store(self.dir, check=False)
|
||||||
store.assert_is_package()
|
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 not store.exists("_apiurl") or apiurl:
|
||||||
if apiurl is None:
|
if apiurl is None:
|
||||||
msg = 'cannot repair wc: the \'_apiurl\' file is missing but ' \
|
msg = 'cannot repair wc: the \'_apiurl\' file is missing but ' \
|
||||||
|
@ -87,7 +87,7 @@ class Project:
|
|||||||
|
|
||||||
self.dir = Path(dir)
|
self.dir = Path(dir)
|
||||||
self.absdir = os.path.abspath(dir)
|
self.absdir = os.path.abspath(dir)
|
||||||
self.store = Store(dir)
|
self.store = Store(dir, check=wc_check)
|
||||||
self.progress_obj = progress_obj
|
self.progress_obj = progress_obj
|
||||||
|
|
||||||
self.name = store_read_project(self.dir)
|
self.name = store_read_project(self.dir)
|
||||||
@ -140,8 +140,13 @@ class Project:
|
|||||||
return dirty_files
|
return dirty_files
|
||||||
|
|
||||||
def wc_repair(self, apiurl: Optional[str] = None):
|
def wc_repair(self, apiurl: Optional[str] = None):
|
||||||
store = Store(self.dir)
|
store = Store(self.dir, check=False)
|
||||||
store.assert_is_project()
|
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 not store.exists("_apiurl") or apiurl:
|
||||||
if apiurl is None:
|
if apiurl is None:
|
||||||
msg = 'cannot repair wc: the \'_apiurl\' file is missing but ' \
|
msg = 'cannot repair wc: the \'_apiurl\' file is missing but ' \
|
||||||
|
Loading…
Reference in New Issue
Block a user