Skip to content

Commit

Permalink
Change 'repairwc' command to fix missing .osc/_osclib_version
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Jul 2, 2024
1 parent 30a33b9 commit 5c185f2
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
47 changes: 47 additions & 0 deletions behave/features/repairwc.feature
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions behave/features/steps/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -10102,8 +10102,9 @@ def get_apiurl(apiurls):
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)
Expand All @@ -10122,8 +10123,9 @@ def get_apiurl(apiurls):
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)
Expand Down
9 changes: 7 additions & 2 deletions osc/obs_scm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, workingdir, progress_obj=None, size_limit=None, wc_check=True

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
Expand Down Expand Up @@ -178,8 +178,13 @@ def wc_check(self):
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 ' \
Expand Down
9 changes: 7 additions & 2 deletions osc/obs_scm/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, dir, getPackageList=True, progress_obj=None, wc_check=True):

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)
Expand Down Expand Up @@ -140,8 +140,13 @@ def wc_check(self):
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 ' \
Expand Down

0 comments on commit 5c185f2

Please sign in to comment.