Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote: verify repository exists when level requires it #3194

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dvc/command/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class CmdConfig(CmdBaseNoRepo):
def __init__(self, args):
super().__init__(args)

self.config = Config(validate=False)
# Verify repository existance when level requires to modify its config
repository_levels = [Config.LEVEL_REPO, Config.LEVEL_LOCAL]
verify_repo = self.args.level in repository_levels

self.config = Config(validate=False, verify_repo=verify_repo)

def run(self):
section, opt = self.args.name.lower().strip().split(".", 1)
Expand Down
4 changes: 3 additions & 1 deletion dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class Config(object): # pylint: disable=too-many-instance-attributes
}
COMPILED_SCHEMA = Schema(SCHEMA)

def __init__(self, dvc_dir=None, validate=True):
def __init__(self, dvc_dir=None, validate=True, verify_repo=False):
Copy link
Author

@ghost ghost Jan 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new parameter because I didn't want to mess up with any previous logic dealing with having an empty dvc_dir.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrOutis This looks like a hack rather than a proper solution 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efiop, could you explain? Not sure how to proceed with such observation 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are hacking your way through the bug instead of solving the bug. This verify_repo shouldn't be an option at all. Config should always raise if you try to modify in-repo config when there isn't one.

self.dvc_dir = dvc_dir
self.validate = validate

Expand All @@ -260,6 +260,8 @@ def __init__(self, dvc_dir=None, validate=True):

self.dvc_dir = os.path.join(Repo.find_dvc_dir())
except NotDvcRepoError:
if verify_repo:
raise
self.dvc_dir = None
else:
self.dvc_dir = os.path.abspath(os.path.realpath(dvc_dir))
Expand Down
13 changes: 13 additions & 0 deletions tests/func/test_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import configobj

import pytest

from dvc.main import main
from tests.basic_env import TestDvc

Expand Down Expand Up @@ -83,3 +85,14 @@ def test_non_existing(self):

ret = main(["config", "core.non_existing_field", "-u"])
self.assertEqual(ret, 251)


@pytest.mark.parametrize(
"cmd",
[
["config", "core.analytics", "false"],
["config", "--local", "core.analytics", "false"],
],
)
def test_commands_outside_dvc_repository(tmp_dir, cmd):
assert 253 == main(cmd)