summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-07-25 15:01:33 +0000
committerJonathan Maw <jonathan.maw@codethink.co.uk>2018-07-25 15:01:33 +0000
commitf62b6cb7420c91c2f87b3ebba4dcfcf16b4d6f0a (patch)
tree4a6aadb683a543b0080eaf5efce5c26347a3705e
parent889bf23825d2627fec04443cc936f79d836c7486 (diff)
parent54fee6c8589e79728b5933598f1e4652540ca205 (diff)
downloadbuildstream-f62b6cb7420c91c2f87b3ebba4dcfcf16b4d6f0a.tar.gz
Merge branch 'bst_workspace_open_force_does_nothing' into 'master'
_stream.py: Added functionality for workspace open -f See merge request BuildStream/buildstream!549
-rw-r--r--buildstream/_stream.py6
-rw-r--r--tests/frontend/workspace.py52
2 files changed, 57 insertions, 1 deletions
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index 365709c46..dcefc64f1 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:
+ 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..566fbb1cd 100644
--- a/tests/frontend/workspace.py
+++ b/tests/frontend/workspace.py
@@ -125,6 +125,58 @@ 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)
+
+ hello_path = os.path.join(workspace, 'usr', 'bin', 'hello')
+ hello1_path = os.path.join(workspace, 'usr', 'bin', 'hello1')
+
+ tmpdir = os.path.join(str(tmpdir), "-beta")
+ shutil.move(hello_path, hello1_path)
+ 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(hello1_path)
+
+ # Assert that workspace 2 contains the unmodified file
+ assert os.path.exists(os.path.join(workspace2, 'usr', 'bin', 'hello'))
+
+ # 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 in workspace 1 has been replaced
+ # With the file from workspace 2
+ assert os.path.exists(hello_path)
+ assert not os.path.exists(hello1_path)
+
+ 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)