From 0dc9e1eb8b4ff3f63f7cb507a052322b78035615 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Sun, 26 Mar 2023 09:57:06 -0700 Subject: [PATCH] Provide clearer error message when repository entry is empty Signed-off-by: Christophe Bedard --- test/bad.repos | 4 ++++ test/test_commands.py | 6 ++++++ test/validate_bad.txt | 2 ++ vcstool/commands/import_.py | 6 ++++++ 4 files changed, 18 insertions(+) create mode 100644 test/bad.repos create mode 100644 test/validate_bad.txt diff --git a/test/bad.repos b/test/bad.repos new file mode 100644 index 00000000..e5d48ca2 --- /dev/null +++ b/test/bad.repos @@ -0,0 +1,4 @@ +repositories: + empty_entry: + missing_url: + type: git diff --git a/test/test_commands.py b/test/test_commands.py index 8751427b..e062e1d7 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -16,6 +16,7 @@ REPOS2_FILE = os.path.join(os.path.dirname(__file__), 'list2.repos') TEST_WORKSPACE = os.path.join( os.path.dirname(os.path.dirname(__file__)), 'test_workspace') +BAD_REPOS_FILE = os.path.join(os.path.dirname(__file__), 'bad.repos') CI = os.environ.get('CI') == 'true' # Travis CI / Github actions set: CI=true svn = which('svn') @@ -326,6 +327,11 @@ def test_validate(self): expected = get_expected_output('validate_hide') self.assertEqual(output, expected) + output = run_command( + 'validate', ['--input', BAD_REPOS_FILE]) + expected = get_expected_output('validate_bad') + self.assertEqual(output, expected) + @unittest.skipIf(not svn and not CI, '`svn` was not found') @unittest.skipIf(not hg and not CI, '`hg` was not found') def test_validate_svn_and_hg(self): diff --git a/test/validate_bad.txt b/test/validate_bad.txt new file mode 100644 index 00000000..be1010c2 --- /dev/null +++ b/test/validate_bad.txt @@ -0,0 +1,2 @@ +Repository 'empty_entry' is empty +Repository 'missing_url' does not provide the necessary information: 'url' diff --git a/vcstool/commands/import_.py b/vcstool/commands/import_.py index 55b3e184..af342b65 100644 --- a/vcstool/commands/import_.py +++ b/vcstool/commands/import_.py @@ -102,6 +102,12 @@ def get_repos_in_vcstool_format(repositories): for path in repositories: repo = {} attributes = repositories[path] + if not attributes: + print( + ansi('yellowf') + ( + "Repository '%s' is empty" % path) + ansi('reset'), + file=sys.stderr) + continue try: repo['type'] = attributes['type'] repo['url'] = attributes['url']