From a6415b3de588a71d5104b601f9d5107e087d70b8 Mon Sep 17 00:00:00 2001 From: Milind Shakya Date: Fri, 15 May 2026 12:44:29 -0400 Subject: [PATCH] Update early check and tests --- giticket/giticket.py | 4 ++-- tests/test_giticket.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/giticket/giticket.py b/giticket/giticket.py index a765c77..3709a51 100644 --- a/giticket/giticket.py +++ b/giticket/giticket.py @@ -105,8 +105,8 @@ def main(argv=None): default=underscore_split_mode, choices=[underscore_split_mode, regex_match_mode]) args = parser.parse_args(argv) - if not args.conventionalcommits and not args.format: - parser.error('You must provide --format if not using --conventionalcommits') + if not args.conventionalcommits and not args.format and not args.to_trailer: + parser.error('You must provide --format if not using --conventionalcommits and not --to_trailer') return 1 regex = args.regex or r'[A-Z]+-\d+' # noqa format_string = args.format or '{ticket} {commit_msg}' # noqa diff --git a/tests/test_giticket.py b/tests/test_giticket.py index e3ca259..5298b15 100644 --- a/tests/test_giticket.py +++ b/tests/test_giticket.py @@ -288,3 +288,19 @@ def test_main(mock_update_commit_message, mock_argparse): True, 0, False) + + +@mock.patch(TESTING_MODULE + '.update_commit_message') +def test_main_to_trailer_only_is_allowed(mock_update_commit_message): + main(['foo.txt', '--to_trailer']) + mock_update_commit_message.assert_called_once_with('foo.txt', r'[A-Z]+-\d+', + 'underscore_split', + '{ticket} {commit_msg}', + False, + 0, + True) + + +def test_main_errors_without_format_or_conventionalcommits_or_to_trailer(): + with pytest.raises(SystemExit): + main(['foo.txt'])