Skip to content

Commit abbe29e

Browse files
push: improve 'no remote specified' hint
Fixes #3121
1 parent 74bbc3b commit abbe29e

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

dvc/config.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ def __init__(self, msg):
2424

2525

2626
class NoRemoteError(ConfigError):
27-
def __init__(self, command):
28-
msg = (
29-
"no remote specified. Setup default remote with\n"
30-
" dvc remote default <name>\n"
31-
"or use:\n"
32-
" dvc {} -r <name>\n".format(command)
33-
)
27+
def __init__(self, command, *, has_any_remote=True):
28+
if has_any_remote:
29+
msg = (
30+
"no remote specified. Setup default remote with\n"
31+
" dvc remote default <remote name>\n"
32+
"or use:\n"
33+
" dvc {} -r <remote name>".format(command)
34+
)
35+
else:
36+
msg = (
37+
"no remote specified. Create a remote with\n"
38+
" dvc remote add <remote name> <remote url>\n"
39+
"To create a default remote use the -d flag:\n"
40+
" dvc remote add -d <remote name> <remote url>\n"
41+
)
3442

3543
super().__init__(msg)
3644

dvc/data_cloud.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def get_remote(self, remote=None, command="<command>"):
3939
if remote:
4040
return self._init_remote(remote)
4141

42-
raise NoRemoteError(command)
42+
has_any_remote = any(key.startswith("remote ") for key in self._config)
43+
44+
raise NoRemoteError(command, has_any_remote=has_any_remote)
4345

4446
def _init_remote(self, remote):
4547
return Remote(self.repo, name=remote)

0 commit comments

Comments
 (0)