summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Smyth <phillipsmyth@codethink.co.uk>2018-07-18 16:06:52 +0100
committerknownexus <phillip.smyth@codethink.co.uk>2018-07-24 11:59:51 +0100
commitdf6b43f664d95e653b42ace748600875e0672b67 (patch)
tree3f4eb4a84c3c5182c11c70a957cfb38f8cec00b2
parent335afb5b973a31595b6059c8c4e9add4b7cbbe9a (diff)
downloadbuildstream-bst_workspace_open_force_does_nothing.tar.gz
_stream.py: Added functionality for workspace open -fbst_workspace_open_force_does_nothing
tests/frontend/workspace.py: Added tests
-rw-r--r--buildstream/_stream.py6
-rw-r--r--tests/frontend/workspace.py44
2 files changed, 49 insertions, 1 deletions
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index 365709c46..cc5deb765 100644
--- a/buildstream/_stream.py
+++ b/buildstream/_stream.py
@@ -476,7 +476,7 @@ class Stream():
# Check for workspace config
workspace = workspaces.get_workspace(target._get_full_name())
- if workspace:
+ if workspace and not force:
raise StreamError("Workspace '{}' is already defined at: {}"
.format(target.name, workspace.path))
@@ -495,6 +495,10 @@ class Stream():
"fetch the latest version of the " +
"source.")
+ if workspace and workspace.get_absolute_path() == workdir:
+ workspaces.delete_workspace(target._get_full_name())
+ workspaces.save_config()
+ shutil.rmtree(directory)
try:
os.makedirs(directory, exist_ok=True)
except OSError as e:
diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py
index 90b50613f..817cd9f17 100644
--- a/tests/frontend/workspace.py
+++ b/tests/frontend/workspace.py
@@ -125,6 +125,50 @@ def test_open_force(cli, tmpdir, datafiles, kind):
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("kind", repo_kinds)
+def test_open_force_open(cli, tmpdir, datafiles, kind):
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
+
+ # Assert the workspace dir exists
+ assert os.path.exists(workspace)
+
+ # Now open the workspace again with --force, this should happily succeed
+ result = cli.run(project=project, args=[
+ 'workspace', 'open', '--force', element_name, workspace
+ ])
+ result.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("kind", repo_kinds)
+def test_open_force_different_workspace(cli, tmpdir, datafiles, kind):
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False, "-alpha")
+
+ # Assert the workspace dir exists
+ assert os.path.exists(workspace)
+
+ tmpdir = os.path.join(str(tmpdir), "-beta")
+ shutil.move(os.path.join(workspace, 'usr', 'bin', 'hello'), os.path.join(workspace, 'usr', 'bin', 'hello1'))
+ element_name2, project2, workspace2 = open_workspace(cli, tmpdir, datafiles, kind, False, "-beta")
+
+ # Assert the workspace dir exists
+ assert os.path.exists(workspace2)
+
+ # Assert that workspace 1 contains the modified file
+ assert os.path.exists(os.path.join(workspace, 'usr', 'bin', 'hello1'))
+
+ # Now open the workspace again with --force, this should happily succeed
+ result = cli.run(project=project, args=[
+ 'workspace', 'open', '--force', element_name2, workspace
+ ])
+
+ # Assert that the file has been replaced
+ assert os.path.exists(os.path.join(workspace2, 'usr', 'bin', 'hello'))
+
+ result.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("kind", repo_kinds)
def test_close(cli, tmpdir, datafiles, kind):
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)