From 77f24af727c7ed6225296b20e80fd9e7b56b7460 Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Fri, 14 Feb 2020 22:52:23 +0545 Subject: [PATCH] dvc: do not set cache dir if not a dvc repo (#3329) --- 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 6a0372f5b..d893855f7 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -278,7 +278,7 @@ class Config(dict): 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 dc0facc2b..1ae0118b7 100644 --- a/tests/func/test_config.py +++ b/tests/func/test_config.py @@ -2,7 +2,7 @@ import pytest 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)