Commit edf3e029 authored by Tristan Van Berkom's avatar Tristan Van Berkom

Add soft reset functionality for workspaces

Add `--soft` option to `bst workspace reset` which would allow uses to
reset workspace-related state without affecting its contents. This will
be useful in case when an user wants to re-run configure-commands for a
workspaced element.

Patch originally by Chandan Singh, rebased against recent refactor.

Fixes #375.
parent 8985da07
Pipeline #21824620 passed with stages
in 16 minutes and 9 seconds
......@@ -651,6 +651,8 @@ def workspace_close(app, remove_dir, all_, elements):
# Workspace Reset Command #
##################################################################
@workspace.command(name='reset', short_help="Reset a workspace to its original state")
@click.option('--soft', default=False, is_flag=True,
help="Reset workspace state without affecting its contents")
@click.option('--track', 'track_', default=False, is_flag=True,
help="Track and fetch the latest source before resetting")
@click.option('--all', '-a', 'all_', default=False, is_flag=True,
......@@ -658,7 +660,7 @@ def workspace_close(app, remove_dir, all_, elements):
@click.argument('elements', nargs=-1,
type=click.Path(dir_okay=False, readable=True))
@click.pass_obj
def workspace_reset(app, track_, all_, elements):
def workspace_reset(app, soft, track_, all_, elements):
"""Reset a workspace to its original state"""
# Check that the workspaces in question exist
......@@ -677,7 +679,7 @@ def workspace_reset(app, track_, all_, elements):
if nonexisting:
raise AppError("Workspace does not exist", detail="\n".join(nonexisting))
if app.interactive:
if app.interactive and not soft:
if not click.confirm('This will remove all your changes, are you sure?'):
click.echo('Aborting', err=True)
sys.exit(-1)
......@@ -685,7 +687,7 @@ def workspace_reset(app, track_, all_, elements):
if all_:
elements = tuple(element_name for element_name, _ in app.project.workspaces.list())
app.stream.workspace_reset(elements, track_first=track_)
app.stream.workspace_reset(elements, soft=soft, track_first=track_)
##################################################################
......
......@@ -504,9 +504,10 @@ class Stream():
#
# Args:
# targets (list of str): The target elements to reset the workspace for
# soft (bool): Only reset workspace state
# track_first (bool): Whether to also track the sources first
#
def workspace_reset(self, targets, *, track_first):
def workspace_reset(self, targets, *, soft, track_first):
if track_first:
track_targets = targets
......@@ -522,6 +523,12 @@ class Stream():
for element in elements:
workspace = self._project.workspaces.get_workspace(element.name)
if soft:
workspace.prepared = False
self._message(MessageType.INFO, "Reset workspace state for {} at: {}"
.format(element.name, workspace.path))
continue
with element.timed_activity("Removing workspace directory {}"
.format(workspace.path)):
try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment