Commit 18e4e945 authored by Jelmer Vernooij's avatar Jelmer Vernooij

Rather than stripping comments, refuse to edit control files with

comments.
parent 47606bcf
......@@ -7,6 +7,8 @@ lintian-brush (0.2) UNRELEASED; urgency=medium
* Fix running of specific fixers.
* Add missing dependency on python3-dulwich. Closes: #912219
* Obey git global and per-tree committer settings.
* Rather than stripping comments, refuse to edit control files with
comments.
-- Jelmer Vernooij <jelmer@debian.org> Sun, 28 Oct 2018 15:44:06 +0000
......
......@@ -30,6 +30,10 @@ class GeneratedFile(Exception):
"""File is generated and should not be edited."""
class FormattingUnpreservable(Exception):
"""Formatting unpreservable."""
def update_control(path='debian/control', **kwargs):
"""Update a control file.
......@@ -46,6 +50,8 @@ def update_control(path='debian/control', **kwargs):
original_contents = f.read()
if b"DO NOT EDIT" in original_contents:
raise GeneratedFile()
if any([l.startswith(b'#') for l in original_contents.splitlines()]):
raise FormattingUnpreservable()
update_control_file(BytesIO(original_contents), outf, **kwargs)
updated_contents = outf.getvalue()
if updated_contents.strip() != original_contents.strip():
......
......@@ -26,6 +26,7 @@ from lintian_brush.control import (
ensure_minimum_version,
update_control,
GeneratedFile,
FormattingUnpreservable,
PkgRelation,
format_relations,
parse_relations,
......@@ -45,6 +46,15 @@ Testsuite: autopkgtest
""")])
self.assertRaises(GeneratedFile, update_control)
def test_unpreservable(self):
self.build_tree_contents([('debian/', ), ('debian/control', """\
Source: blah
# A comment
Testsuite: autopkgtest
""")])
self.assertRaises(FormattingUnpreservable, update_control)
def test_modify_source(self):
self.build_tree_contents([('debian/', ), ('debian/control', """\
Source: blah
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment