From 8b2282e87e2a47b84874e397380f3b649b94d3b0 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Wed, 14 Feb 2024 08:50:12 +0100 Subject: [PATCH 1/2] --style should work with unrecognised files Signed-off-by: Carmen Bianca BAKKER --- src/reuse/_annotate.py | 8 +++++--- tests/test_main_annotate.py | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/reuse/_annotate.py b/src/reuse/_annotate.py index b867d62a..4d282ce7 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 781ecc8f..367c18ba 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" From 96de54ad1c3aa1fe6380eab1852cb170e597ec78 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Wed, 14 Feb 2024 08:52:38 +0100 Subject: [PATCH 2/2] Add change log entry Signed-off-by: Carmen Bianca BAKKER --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1119c1a..b05b7c36 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