From 319aa859cb349e145ec43a27272efbc3324225a9 Mon Sep 17 00:00:00 2001 From: Dominik Rumian Date: May 13 2022 08:40:01 +0000 Subject: Refuse to "commit -c" when using %autochangelog Jira: RHELCMP-6876 Fixes: https://pagure.io/fedpkg/issue/454 Signed-off-by: Dominik Rumian --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index e7b6e26..df8b3af 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -2128,6 +2128,10 @@ class cliClient(object): if self.args.with_changelog and not self.args.message: raise rpkgError('--with-changelog must be used with -m together.') + if self.args.clog and self.cmd.uses_autochangelog: + raise rpkgError('You cannot generate the commit message from changelog while using ' + 'autochangelog!') + if self.args.clog or (self.args.message and self.args.with_changelog): self.cmd.clog(raw=self.args.raw, subject=self.args.message) # This assignment is a magic because commit message is in the file @@ -2866,6 +2870,10 @@ class cliClient(object): ('\n'.join(locals), '\n '.join(remotes))) def tag(self): + if self.args.clog and self.cmd.uses_autochangelog: + raise rpkgError('You cannot generate the commit message from changelog while using ' + 'autochangelog!') + if self.args.list: self.cmd.list_tag(self.args.tag) elif self.args.delete: diff --git a/tests/test_cli.py b/tests/test_cli.py index 054e950..4e69656 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -523,6 +523,48 @@ Initial version''' commit_msg = self.get_last_commit_message() self.assertTrue('Signed-off-by:' in commit_msg) + @patch('pyrpkg.Commands.commit') + @patch('pyrpkg.specfile_uses_rpmautospec', return_value=True) + def test_commit_with_clog_and_rpmautospec(self, specfile_uses_rpmautospec, commit): + """ + specfile_uses_rpmautospec is patched always (it doesn't recognize its input arguments) + """ + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, 'commit', '--clog'] + + with patch('sys.argv', new=cli_cmd): + six.assertRaisesRegex(self, rpkgError, + r'.+cannot generate the commit message from changelog while ' + r'using autochangelog.+', + self.cli_commit) + self.assertEqual(commit.call_args_list, []) + + @patch('pyrpkg.Commands.commit') + @patch('pyrpkg.Commands.uses_autochangelog', return_value=True) + def test_commit_with_clog_and_autochangelog(self, uses_autochangelog, commit): + """ + uses_autochangelog should prevent command "commit" to finish + """ + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, 'commit', '--clog'] + + with patch('sys.argv', new=cli_cmd): + six.assertRaisesRegex(self, rpkgError, + r'.+cannot generate the commit message from changelog while ' + r'using autochangelog.+', + self.cli_commit) + self.assertEqual(commit.call_args_list, []) + + @patch('pyrpkg.Commands.commit') + @patch('pyrpkg.Commands.uses_autorelease', return_value=True) + def test_commit_with_clog_and_autorelease(self, uses_autorelease, commit): + """ + uses_autorelease should allow command "commit" to finish (unlike uses_autochangelog) + """ + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, 'commit', '--clog'] + + with patch('sys.argv', new=cli_cmd): + self.cli_commit() + commit.assert_called_once() + class TestPull(CliTestCase): diff --git a/tests/test_commands.py b/tests/test_commands.py index c6fdc5b..758dd9a 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -134,6 +134,7 @@ class LoadNameVerRelTest(CommandTestCase): self.assertEqual('1.2', cmd._ver) self.assertEqual('2.el6', cmd._rel) self.assertIs(False, cmd._uses_autorelease) + self.assertIs(False, cmd._uses_autochangelog) self.assertIs(False, cmd._uses_rpmautospec) @patch('pyrpkg.Commands.load_rpmdefines', new=mock_load_rpmdefines) @@ -168,6 +169,7 @@ class LoadNameVerRelTest(CommandTestCase): def test_load_with_rpmautospec_pkg_missing(self): self.cmd.load_nameverrel() self.assertIs(0, self.cmd._uses_autorelease) + self.assertIs(0, self.cmd._uses_autochangelog) self.assertIs(0, self.cmd._uses_rpmautospec) @patch("subprocess.Popen", wraps=subprocess.Popen) @@ -181,6 +183,7 @@ class LoadNameVerRelTest(CommandTestCase): self.cmd.load_nameverrel() self.assertIs(True, self.cmd._uses_autorelease) + self.assertIs(True, self.cmd._uses_autochangelog) self.assertIs(True, self.cmd._uses_rpmautospec) self.assertEqual(1, wrapped_popen.call_count) args, kwargs = wrapped_popen.call_args