Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add validation to restrict default remote repo in list of remote repos.
  • Loading branch information
karajan1001 committed Apr 29, 2020
1 parent a2de48b commit 55e1201
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 3 additions & 4 deletions dvc/command/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ class CmdRemoteRemove(CmdRemote):
def run(self):
with self.config.edit(self.args.level) as conf:
self._check_exists(conf)
del conf["remote"][self.args.name]

# Remove core.remote refs to this remote in any shadowing configs
for level in reversed(self.config.LEVELS):
with self.config.edit(level) as conf:
if conf["core"].get("remote") == self.args.name:
del conf["core"]["remote"]

if level == self.args.level:
break
if level == self.args.level:
del conf["remote"][self.args.name]
break

return 0

Expand Down
8 changes: 8 additions & 0 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,14 @@ def edit(self, level="repo"):
@staticmethod
def validate(data):
try:
if (
"remote" in data["core"]
and data["core"]["remote"] not in data["remote"]
):
print(data)
print(data["core"]["remote"])
print(data["remote"])
raise ConfigError("")
return COMPILED_SCHEMA(data)
except Invalid as exc:
raise ConfigError(str(exc)) from None
Expand Down
10 changes: 10 additions & 0 deletions tests/func/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test(self):


def test_show_default(dvc, capsys):
assert main(["remote", "add", "foo", "s3://bucket/name"]) == 0
assert main(["remote", "default", "foo"]) == 0
assert main(["remote", "default"]) == 0
out, _ = capsys.readouterr()
Expand Down Expand Up @@ -270,3 +271,12 @@ def test_remote_modify_validation(dvc):
)
config = configobj.ConfigObj(dvc.config.files["repo"])
assert unsupported_config not in config['remote "{}"'.format(remote_name)]


def test_remote_default_modify(dvc):
remote_name = "my_remote"
wrong_remote_name = "anything"
assert main(["remote", "add", remote_name, "s3://bucket/name"]) == 0

assert main(["remote", "default", remote_name]) == 0
assert main(["remote", "default", wrong_remote_name]) == 251

0 comments on commit 55e1201

Please sign in to comment.