diff --git a/lib/spack/spack/cmd/config.py b/lib/spack/spack/cmd/config.py index f36dffd40a..06f6477dfd 100644 --- a/lib/spack/spack/cmd/config.py +++ b/lib/spack/spack/cmd/config.py @@ -120,7 +120,7 @@ def _get_scope_and_section(args): path = getattr(args, "path", None) # w/no args and an active environment, point to env manifest - if not section: + if not section and not scope: env = ev.active_environment() if env: scope = env.env_file_config_scope_name() diff --git a/lib/spack/spack/test/cmd/config.py b/lib/spack/spack/test/cmd/config.py index f9c3fae2f9..cdf9bc00a0 100644 --- a/lib/spack/spack/test/cmd/config.py +++ b/lib/spack/spack/test/cmd/config.py @@ -118,6 +118,14 @@ def test_config_edit_edits_spack_yaml(mutable_mock_env_path): assert config("edit", "--print-file").strip() == env.manifest_path +def test_config_add_with_scope_adds_to_scope(mutable_config, mutable_mock_env_path): + """Test adding to non-env config scope with an active environment""" + env = ev.create("test") + with env: + config("--scope=user", "add", "config:install_tree:root:/usr") + assert spack.config.get("config:install_tree:root", scope="user") == "/usr" + + def test_config_edit_fails_correctly_with_no_env(mutable_mock_env_path): output = config("edit", "--print-file", fail_on_error=False) assert "requires a section argument or an active environment" in output