diff --git a/dvc/config.py b/dvc/config.py index 13965264b..cb0fd8e70 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -424,10 +424,13 @@ class Config(object): # pylint: disable=too-many-instance-attributes config.write() def validate(self, config=None): - d = (config or self.config).dict() + ret = copy.deepcopy(self.config) + + if config: + ret.merge(config) try: - return self.COMPILED_SCHEMA(d) + return self.COMPILED_SCHEMA(ret.dict()) except Invalid as exc: raise ConfigError(str(exc)) from exc diff --git a/tests/func/test_remote.py b/tests/func/test_remote.py index 2bbe5088f..78730d6da 100644 --- a/tests/func/test_remote.py +++ b/tests/func/test_remote.py @@ -265,3 +265,10 @@ def test_modify_invalid_key(dvc): with pytest.raises(ConfigError, match=r"extra keys not allowed"): remote_config.modify("example", "random_key", "value") + + +def test_merging_two_levels(tmp_dir, dvc): + assert 0 == main(["remote", "add", "test", "https://example.com"]) + assert 0 == main(["remote", "modify", "--local", "test", "password", "1"]) + assert "example.com" in (tmp_dir / ".dvc" / "config").read_text() + assert "password" in (tmp_dir / ".dvc" / "config.local").read_text()