diff --git a/CHANGELOG.md b/CHANGELOG.md index a1119c1ae..b05b7c367 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,9 @@ CLI command and its behaviour. There are no guarantees of stability for the ### Fixed +- `annotate`'s '`--style` now works again when used for a file with an + unrecognised extension. (#909) + ### Security ## 3.0.1 - 2024-01-19 diff --git a/src/reuse/_annotate.py b/src/reuse/_annotate.py index b867d62a2..4d282ce7b 100644 --- a/src/reuse/_annotate.py +++ b/src/reuse/_annotate.py @@ -342,11 +342,13 @@ def verify_write_access( def verify_paths_comment_style(args: Namespace, paths: Iterable[Path]) -> None: - """Exit if --fallback-dot-license or --skip-unrecognised is not enabled and - one of the paths has an unrecognised style. + """Exit if --style, --force-dot-license, --fallback-dot-license, + or --skip-unrecognised is not enabled and one of the paths has an + unrecognised style. """ if ( - not args.fallback_dot_license + not args.style + and not args.fallback_dot_license and not args.skip_unrecognised and not args.force_dot_license ): diff --git a/tests/test_main_annotate.py b/tests/test_main_annotate.py index 781ecc8fc..367c18ba6 100644 --- a/tests/test_main_annotate.py +++ b/tests/test_main_annotate.py @@ -452,6 +452,31 @@ def test_annotate_specify_style(fake_repository, stringio, mock_date_today): assert simple_file.read_text() == expected +def test_annotate_specify_style_unrecognised( + fake_repository, stringio, mock_date_today +): + """Add a header to a file that is unrecognised.""" + + simple_file = fake_repository / "hello.foo" + simple_file.touch() + expected = "# SPDX-FileCopyrightText: 2018 Jane Doe" + + result = main( + [ + "annotate", + "--copyright", + "Jane Doe", + "--style", + "python", + "hello.foo", + ], + out=stringio, + ) + + assert result == 0 + assert simple_file.read_text().strip() == expected + + def test_annotate_implicit_style(fake_repository, stringio, mock_date_today): """Add a header to a file that has a recognised extension.""" simple_file = fake_repository / "foo.js"