Skip to content

Commit

Permalink
push: improve 'no remote specified' hint
Browse files Browse the repository at this point in the history
Fixes #3121
  • Loading branch information
fabiosantoscode committed Jan 22, 2020
1 parent 74bbc3b commit abbe29e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 15 additions & 7 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ def __init__(self, msg):


class NoRemoteError(ConfigError):
def __init__(self, command):
msg = (
"no remote specified. Setup default remote with\n"
" dvc remote default <name>\n"
"or use:\n"
" dvc {} -r <name>\n".format(command)
)
def __init__(self, command, *, has_any_remote=True):
if has_any_remote:
msg = (
"no remote specified. Setup default remote with\n"
" dvc remote default <remote name>\n"
"or use:\n"
" dvc {} -r <remote name>".format(command)
)
else:
msg = (
"no remote specified. Create a remote with\n"
" dvc remote add <remote name> <remote url>\n"
"To create a default remote use the -d flag:\n"
" dvc remote add -d <remote name> <remote url>\n"
)

super().__init__(msg)

Expand Down
4 changes: 3 additions & 1 deletion dvc/data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def get_remote(self, remote=None, command="<command>"):
if remote:
return self._init_remote(remote)

raise NoRemoteError(command)
has_any_remote = any(key.startswith("remote ") for key in self._config)

raise NoRemoteError(command, has_any_remote=has_any_remote)

def _init_remote(self, remote):
return Remote(self.repo, name=remote)
Expand Down

0 comments on commit abbe29e

Please sign in to comment.