From 25f33e42ee3ef4202be4b3986ad0eff5da7ba562 Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Fri, 14 Feb 2020 21:58:40 +0545 Subject: [PATCH] dvc: do not set cache dir if not a dvc repo --- dvc/config.py | 2 +- tests/func/test_config.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index 6a0372f5b4..d893855f71 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -278,7 +278,7 @@ def load(self, validate=True): self.update(conf) # Add resolved default cache.dir - if not self["cache"].get("dir"): + if not self["cache"].get("dir") and self.dvc_dir: self["cache"]["dir"] = os.path.join(self.dvc_dir, "cache") def load_one(self, level): diff --git a/tests/func/test_config.py b/tests/func/test_config.py index dc0facc2bd..1ae0118b77 100644 --- a/tests/func/test_config.py +++ b/tests/func/test_config.py @@ -2,7 +2,7 @@ import configobj from dvc.main import main -from dvc.config import ConfigError +from dvc.config import Config, ConfigError from tests.basic_env import TestDvc @@ -101,3 +101,8 @@ def test_merging_two_levels(dvc): "url": "ssh://example.com", "password": "1", } + + +def test_config_loads_without_error_for_non_dvc_repo(tmp_dir): + # regression testing for https://github.com/iterative/dvc/issues/3328 + Config(validate=True)