[Notes] [Git][BuildStream/buildstream][bst-1.2] 2 commits: _stream.py: Added functionality for workspace open -f



Title: GitLab

Valentin David pushed to branch bst-1.2 at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/_stream.py
    ... ... @@ -478,7 +478,7 @@ class Stream():
    478 478
     
    
    479 479
             # Check for workspace config
    
    480 480
             workspace = workspaces.get_workspace(target._get_full_name())
    
    481
    -        if workspace:
    
    481
    +        if workspace and not force:
    
    482 482
                 raise StreamError("Workspace '{}' is already defined at: {}"
    
    483 483
                                   .format(target.name, workspace.path))
    
    484 484
     
    
    ... ... @@ -497,6 +497,10 @@ class Stream():
    497 497
                                   "fetch the latest version of the " +
    
    498 498
                                   "source.")
    
    499 499
     
    
    500
    +        if workspace:
    
    501
    +            workspaces.delete_workspace(target._get_full_name())
    
    502
    +            workspaces.save_config()
    
    503
    +            shutil.rmtree(directory)
    
    500 504
             try:
    
    501 505
                 os.makedirs(directory, exist_ok=True)
    
    502 506
             except OSError as e:
    

  • tests/frontend/workspace.py
    ... ... @@ -123,6 +123,58 @@ def test_open_force(cli, tmpdir, datafiles, kind):
    123 123
         result.assert_success()
    
    124 124
     
    
    125 125
     
    
    126
    +@pytest.mark.datafiles(DATA_DIR)
    
    127
    +@pytest.mark.parametrize("kind", repo_kinds)
    
    128
    +def test_open_force_open(cli, tmpdir, datafiles, kind):
    
    129
    +    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
    
    130
    +
    
    131
    +    # Assert the workspace dir exists
    
    132
    +    assert os.path.exists(workspace)
    
    133
    +
    
    134
    +    # Now open the workspace again with --force, this should happily succeed
    
    135
    +    result = cli.run(project=project, args=[
    
    136
    +        'workspace', 'open', '--force', element_name, workspace
    
    137
    +    ])
    
    138
    +    result.assert_success()
    
    139
    +
    
    140
    +
    
    141
    +@pytest.mark.datafiles(DATA_DIR)
    
    142
    +@pytest.mark.parametrize("kind", repo_kinds)
    
    143
    +def test_open_force_different_workspace(cli, tmpdir, datafiles, kind):
    
    144
    +    element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False, "-alpha")
    
    145
    +
    
    146
    +    # Assert the workspace dir exists
    
    147
    +    assert os.path.exists(workspace)
    
    148
    +
    
    149
    +    hello_path = os.path.join(workspace, 'usr', 'bin', 'hello')
    
    150
    +    hello1_path = os.path.join(workspace, 'usr', 'bin', 'hello1')
    
    151
    +
    
    152
    +    tmpdir = os.path.join(str(tmpdir), "-beta")
    
    153
    +    shutil.move(hello_path, hello1_path)
    
    154
    +    element_name2, project2, workspace2 = open_workspace(cli, tmpdir, datafiles, kind, False, "-beta")
    
    155
    +
    
    156
    +    # Assert the workspace dir exists
    
    157
    +    assert os.path.exists(workspace2)
    
    158
    +
    
    159
    +    # Assert that workspace 1 contains the modified file
    
    160
    +    assert os.path.exists(hello1_path)
    
    161
    +
    
    162
    +    # Assert that workspace 2 contains the unmodified file
    
    163
    +    assert os.path.exists(os.path.join(workspace2, 'usr', 'bin', 'hello'))
    
    164
    +
    
    165
    +    # Now open the workspace again with --force, this should happily succeed
    
    166
    +    result = cli.run(project=project, args=[
    
    167
    +        'workspace', 'open', '--force', element_name2, workspace
    
    168
    +    ])
    
    169
    +
    
    170
    +    # Assert that the file in workspace 1 has been replaced
    
    171
    +    # With the file from workspace 2
    
    172
    +    assert os.path.exists(hello_path)
    
    173
    +    assert not os.path.exists(hello1_path)
    
    174
    +
    
    175
    +    result.assert_success()
    
    176
    +
    
    177
    +
    
    126 178
     @pytest.mark.datafiles(DATA_DIR)
    
    127 179
     @pytest.mark.parametrize("kind", repo_kinds)
    
    128 180
     def test_close(cli, tmpdir, datafiles, kind):
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]