Commit d1567ad7 authored by Jelmer Vernooij's avatar Jelmer Vernooij

Don't update the changelog if the change we're describing is to the last changelog entry.

parent 0dbeee1f
...@@ -290,6 +290,38 @@ def get_committer(tree): ...@@ -290,6 +290,38 @@ def get_committer(tree):
return config.get('email') return config.get('email')
def only_changes_last_changelog_block(tree):
"""Check whether the only change in a tree is to the last changelog entry.
Args:
tree: Tree to analyze
Returns:
boolean
"""
basis_tree = tree.basis_tree()
with tree.lock_read(), basis_tree.lock_read():
changes = tree.iter_changes(basis_tree)
try:
first_change = next(changes)
except StopIteration:
return False
try:
next(changes)
except StopIteration:
pass
else:
return False
if first_change[1] != ('debian/changelog', 'debian/changelog'):
return False
new_cl = Changelog(tree.get_file_text('debian/changelog'))
old_cl = Changelog(basis_tree.get_file_text('debian/changelog'))
if old_cl.distributions != "UNRELEASED":
return False
del new_cl._blocks[0]
del old_cl._blocks[0]
return str(new_cl) == str(old_cl)
def run_lintian_fixer(local_tree, fixer, committer=None, def run_lintian_fixer(local_tree, fixer, committer=None,
update_changelog=True): update_changelog=True):
"""Run a lintian fixer on a tree. """Run a lintian fixer on a tree.
...@@ -331,9 +363,14 @@ def run_lintian_fixer(local_tree, fixer, committer=None, ...@@ -331,9 +363,14 @@ def run_lintian_fixer(local_tree, fixer, committer=None,
summary = result.description.splitlines()[0] summary = result.description.splitlines()[0]
if not list(local_tree.iter_changes(local_tree.basis_tree())): if not local_tree.has_changes():
raise NoChanges("Script didn't make any changes") raise NoChanges("Script didn't make any changes")
if update_changelog and only_changes_last_changelog_block(local_tree):
# If the script only changed the last entry in the changelog,
# don't update the changelog
update_changelog = False
if update_changelog: if update_changelog:
subprocess.check_call( subprocess.check_call(
["dch", "--no-auto-nmu", summary], cwd=local_tree.basedir) ["dch", "--no-auto-nmu", summary], cwd=local_tree.basedir)
......
...@@ -35,6 +35,7 @@ from lintian_brush import ( ...@@ -35,6 +35,7 @@ from lintian_brush import (
PendingChanges, PendingChanges,
available_lintian_fixers, available_lintian_fixers,
increment_version, increment_version,
only_changes_last_changelog_block,
run_lintian_fixer, run_lintian_fixer,
run_lintian_fixers, run_lintian_fixers,
) )
...@@ -390,3 +391,148 @@ class IncrementVersionTests(TestCase): ...@@ -390,3 +391,148 @@ class IncrementVersionTests(TestCase):
def test_native(self): def test_native(self):
self.assertVersion('1.1', '1.0') self.assertVersion('1.1', '1.0')
class OnlyChangesLastChangelogBlockTests(TestCaseWithTransport):
def make_package_tree(self):
tree = self.make_branch_and_tree('.')
self.build_tree_contents([
('debian/', ),
('debian/control', """\
Source: blah
Vcs-Git: https://example.com/blah
Testsuite: autopkgtest
Binary: blah
Arch: all
"""),
('debian/changelog', """\
blah (0.2) UNRELEASED; urgency=medium
* And a change.
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
blah (0.1) unstable; urgency=medium
* Initial release. (Closes: #911016)
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
""")])
tree.add(['debian', 'debian/changelog', 'debian/control'])
tree.commit('Initial thingy.')
return tree
def test_no_changes(self):
tree = self.make_package_tree()
self.assertFalse(only_changes_last_changelog_block(tree))
def test_other_change(self):
tree = self.make_package_tree()
self.build_tree_contents([
('debian/control', """\
Source: blah
Vcs-Bzr: https://example.com/blah
Testsuite: autopkgtest
Binary: blah
Arch: all
""")])
self.assertFalse(only_changes_last_changelog_block(tree))
def test_other_changes(self):
tree = self.make_package_tree()
self.build_tree_contents([
('debian/control', """\
Source: blah
Vcs-Bzr: https://example.com/blah
Testsuite: autopkgtest
Binary: blah
Arch: all
"""),
('debian/changelog', """\
blah (0.1) UNRELEASED; urgency=medium
* Initial release. (Closes: #911016)
* Some other change.
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
""")])
self.assertFalse(only_changes_last_changelog_block(tree))
def test_changes_to_other_changelog_entries(self):
tree = self.make_package_tree()
self.build_tree_contents([
('debian/changelog', """\
blah (0.2) UNRELEASED; urgency=medium
* debian/changelog: And a change.
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
blah (0.1) unstable; urgency=medium
* debian/changelog: Initial release. (Closes: #911016)
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
""")])
self.assertFalse(only_changes_last_changelog_block(tree))
def test_changes_to_last_only(self):
tree = self.make_package_tree()
self.build_tree_contents([
('debian/changelog', """\
blah (0.2) UNRELEASED; urgency=medium
* And a change.
* Not a team upload.
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
blah (0.1) unstable; urgency=medium
* Initial release. (Closes: #911016)
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
""")])
self.assertTrue(only_changes_last_changelog_block(tree))
def test_changes_to_last_only_but_released(self):
tree = self.make_package_tree()
self.build_tree_contents([
('debian/changelog', """\
blah (0.2) unstable; urgency=medium
* And a change.
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
blah (0.1) unstable; urgency=medium
* Initial release. (Closes: #911016)
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
""")])
tree.commit('release')
self.build_tree_contents([
('debian/changelog', """\
blah (0.2) unstable; urgency=medium
* And a change.
* Team Upload.
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
blah (0.1) unstable; urgency=medium
* Initial release. (Closes: #911016)
-- Blah <example@debian.org> Sat, 13 Oct 2018 11:21:39 +0100
""")])
self.assertFalse(only_changes_last_changelog_block(tree))
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