Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--style should work with unrecognised files #909

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/reuse/_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
25 changes: 25 additions & 0 deletions tests/test_main_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down