Skip to content

Commit

Permalink
Improve error message when a folder is not an SCM repo (#8956)
Browse files Browse the repository at this point in the history
Before you would get this:
ConanException: Not a valid 'svn' repository

Which doesn't help much, especially if you're using
"conan create" which may be off in a folder you didn't
create.

Add the path of the folder to the error message to instead
get:
ConanException: '/a/b/not_an_svn_repo' is not a valid 'svn' repository
  • Loading branch information
DavidSpickett committed May 24, 2021
1 parent 377bcd8 commit 36ef440
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion conans/client/tools/scm.py
Expand Up @@ -16,7 +16,7 @@


def _check_repo(cmd, folder):
msg = "Not a valid '{0}' repository or '{0}' not found.".format(cmd[0])
msg = "'{0}' is not a valid '{1}' repository or '{1}' not found.".format(folder, cmd[0])
try:
ret = muted_runner(cmd, folder=folder)
except Exception:
Expand Down
5 changes: 3 additions & 2 deletions conans/test/functional/scm/test_command_export.py
Expand Up @@ -34,8 +34,9 @@ def test_no_repo(self, repo_type, autos):
rev_value=rev_value)
})
self.client.run("export . lib/version@user/channel", assert_error=True)
self.assertIn("ERROR: Not a valid '{}' repository".format(repo_type.lower()),
self.client.out)
self.assertIn("ERROR: '{}' is not a valid '{}' repository".format(
self.client.current_folder, repo_type.lower()), self.client.out)


@pytest.mark.tool_git
class ExportCommandTestCase(unittest.TestCase):
Expand Down
9 changes: 6 additions & 3 deletions conans/test/functional/scm/tools/test_git.py
@@ -1,5 +1,6 @@
# coding=utf-8
import os
import re
import subprocess
import unittest

Expand Down Expand Up @@ -397,9 +398,11 @@ def test_in_branch_with_tag(self):

def test_get_tag_no_git_repo(self):
# Try to get tag out of a git repo
git = Git(folder=temp_folder())
with six.assertRaisesRegex(self, ConanException,
"Not a valid 'git' repository or 'git' not found"):
tmp_folder = temp_folder()
git = Git(folder=tmp_folder)
pattern = "'{0}' is not a valid 'git' repository or 'git' not found".format(
re.escape(tmp_folder))
with six.assertRaisesRegex(self, ConanException, pattern):
git.get_tag()

def test_excluded_files(self):
Expand Down
4 changes: 3 additions & 1 deletion conans/test/functional/scm/tools/test_svn.py
@@ -1,6 +1,7 @@
# coding=utf-8

import os
import re
import shutil
import subprocess
import unittest
Expand Down Expand Up @@ -56,7 +57,8 @@ def test_check_svn_repo(self):
project_url, _ = self.create_project(files={'myfile': "contents"})
tmp_folder = self.gimme_tmp()
svn = SVN(folder=tmp_folder)
with six.assertRaisesRegex(self, ConanException, "Not a valid 'svn' repository"):
pattern = "'{0}' is not a valid 'svn' repository".format(re.escape(tmp_folder))
with six.assertRaisesRegex(self, ConanException, pattern):
svn.check_repo()
svn.checkout(url=project_url)
try:
Expand Down

0 comments on commit 36ef440

Please sign in to comment.