Blob Blame History Raw
From 6a381fd9cabcf9bc86efe8761f818ae00ae39bdc Mon Sep 17 00:00:00 2001
From: Otto Liljalaakso <otto.liljalaakso@iki.fi>
Date: Fri, 21 Apr 2023 12:33:56 +0300
Subject: [PATCH] Improve invalid branch name error message

Currently, if the resolved release name does not match any supported
pattern ('rawhide', 'f38' or so), the following error is printed:

    (foo) $ fedpkg prep
    Could not execute prep: Could not find the release/dist from branch name foo
    Please specify with --release

This is fine when the current Git branch name was used when resolving
the release. However, the exact same error is printed even if the
'--release' option was used, like this:

    $ fedpkg --release foo prep
    Could not execute prep: Could not find the release/dist from branch name foo
    Please specify with --release

The error message is split into two cases depending on if --release was
used (detected by checking if 'self.dist' is truthy):

    (foo) $ fedpkg prep
    Could not execute prep: Could not find release from branch name 'foo'. Please specify with --release.
    $ fedpkg --release foo prep
    Could not execute prep: Invalid release 'foo'.

JIRA: RHELCMP-11465
Fixes: https://pagure.io/rpkg/issue/671
Merges: https://pagure.io/fedpkg/pull-request/518

Signed-off-by: Otto Liljalaakso <otto.liljalaakso@iki.fi>
---
 fedpkg/__init__.py | 10 +++++++---
 test/test_cli.py   |  5 +++--
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py
index 9973286..b01ca73 100644
--- a/fedpkg/__init__.py
+++ b/fedpkg/__init__.py
@@ -138,9 +138,13 @@ class Commands(pyrpkg.Commands):
             self._distunset = 'rhel'
         # If we don't match one of the above, punt
         else:
-            raise pyrpkg.rpkgError('Could not find the release/dist from branch name '
-                                   '%s\nPlease specify with --release' %
-                                   self.branch_merge)
+            if self.dist:
+                msg = 'Invalid release \'%s\'.' % self.branch_merge
+            else:
+                msg = ('Could not find release from branch name \'%s\'. '
+                       'Please specify with --release.' % self.branch_merge)
+            raise pyrpkg.rpkgError(msg)
+
         self._rpmdefines = ["--define", "_sourcedir %s" % self.layout.sourcedir,
                             "--define", "_specdir %s" % self.layout.specdir,
                             "--define", "_builddir %s" % self.layout.builddir,
diff --git a/test/test_cli.py b/test/test_cli.py
index ecc279d..e0a1918 100644
--- a/test/test_cli.py
+++ b/test/test_cli.py
@@ -2310,10 +2310,11 @@ class TestReadReleasesFromLocalConfig(CliTestCase):
     @patch('pyrpkg.utils.validate_path')
     def test_no_config_file_is_create(self, validate_path):
         error_msg = 'given path \'{0}\' doesn\'t exist'.format(self.cloned_repo_path)
-        validate_path.side_effect=argparse.ArgumentTypeError(error_msg)
+        validate_path.side_effect = argparse.ArgumentTypeError(error_msg)
         with patch('sys.argv', new=self.fake_cmd):
             with patch('sys.stderr', new=six.StringIO()):
-                with self.assertRaises(SystemExit):  # argparse.ArgumentTypeError turns to SystemExit
+                # argparse.ArgumentTypeError turns to SystemExit
+                with self.assertRaises(SystemExit):
                     self.new_cli()
                 validate_path.assert_called_once_with(self.cloned_repo_path)
                 output = sys.stderr.getvalue().strip()
-- 
2.40.0