Commit fe0e573c authored by Jelmer Vernooij's avatar Jelmer Vernooij

Check for reproducibility of formatting, rather than for comments specifically.

parent 18d94546
......@@ -8,7 +8,7 @@ lintian-brush (0.2) UNRELEASED; urgency=medium
* d/control: Add missing dependency on python3-dulwich. Closes: #912219
* lintian-brush: Obey git global and per-tree committer settings.
* lintian-brush: Rather than stripping comments, refuse to edit control
files with comments (until support for preserving them is added).
files where formatting can not be preserved.
-- Jelmer Vernooij <> Sun, 28 Oct 2018 15:44:06 +0000
......@@ -33,6 +33,22 @@ class FormattingUnpreservable(Exception):
"""Formatting unpreservable."""
def can_preserve_deb822(contents):
"""Check whether it's possible to preserve a control file.
contents: Original contents
New contents
outf = BytesIO()
for paragraph in Deb822.iter_paragraphs(BytesIO(contents),
paragraph.dump(fd=outf, encoding='utf-8')
return outf.getvalue().strip() == contents.strip()
def update_control(path='debian/control', **kwargs):
"""Update a control file.
......@@ -44,13 +60,13 @@ def update_control(path='debian/control', **kwargs):
source_package_cb: Called on source package paragraph
binary_package_cb: Called on each binary package paragraph
outf = BytesIO()
with open(path, 'rb') as f:
original_contents =
if b"DO NOT EDIT" in original_contents:
raise GeneratedFile()
if any([l.startswith(b'#') for l in original_contents.splitlines()]):
raise FormattingUnpreservable()
if not can_preserve_deb822(original_contents):
raise FormattingUnpreservable("Unable to preserve formatting", path)
outf = BytesIO()
update_control_file(BytesIO(original_contents), outf, **kwargs)
updated_contents = outf.getvalue()
if updated_contents.strip() != original_contents.strip():
......@@ -23,6 +23,7 @@ from breezy.tests import (
from lintian_brush.control import (
......@@ -33,6 +34,24 @@ from lintian_brush.control import (
class CanPreserveDeb822Tests(TestCase):
def test_comment(self):
Source: blah
# A comment
Testsuite: autopkgtest
def test_fine(self):
Source: blah
Testsuite: autopkgtest
class UpdateControlTests(TestCaseWithTransport):
def test_do_not_edit(self):
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