diff --git a/debian/changelog b/debian/changelog index c648044dea98f979850c75d11e302f6842b1b70f..736fef99bf149aeddb55155e1a5a6ab9806df545 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ lintian-brush (0.2) UNRELEASED; urgency=medium * Add --verbose option. * Fix running of specific fixers. * Add missing dependency on python3-dulwich. Closes: #912219 + * Obey git global and per-tree committer settings. -- Jelmer Vernooij Sun, 28 Oct 2018 15:44:06 +0000 diff --git a/lintian_brush/__init__.py b/lintian_brush/__init__.py index d30f67435c1333bb716b2788aee7567f30bba3d8..77e880601f8984367e8d4f16f1f689d31ce6a100 100644 --- a/lintian_brush/__init__.py +++ b/lintian_brush/__init__.py @@ -28,6 +28,8 @@ import warnings from breezy import ui +import breezy.bzr # noqa: F401 +import breezy.git # noqa: F401 from breezy.clean_tree import ( iter_deletables, ) @@ -225,6 +227,22 @@ def delete_items(deletables, dry_run=False): 'unable to remove "{0}": {1}.'.format(path, e.strerror)) +def get_committer(tree): + """Get the committer string for a tree. + + Args: + tree: A Tree object + Returns: + A committer string + """ + # TODO(jelmer): Perhaps this logic should be in Breezy? + if getattr(tree.branch.repository, '_git', None): + return tree.branch.repository._git._get_user_identity() + else: + config = tree.branch.get_config_stack() + return config.get('email') + + def run_lintian_fixer(local_tree, fixer, update_changelog=True): """Run a lintian fixer on a tree. @@ -284,7 +302,8 @@ def run_lintian_fixer(local_tree, fixer, update_changelog=True): "for more details.\n") % tag local_tree.commit(description, allow_pointless=False, - reporter=NullCommitReporter()) + reporter=NullCommitReporter(), + committer=get_committer(local_tree)) # TODO(jelmer): Run sbuild & verify lintian warning is gone? return result.fixed_lintian_tags, summary diff --git a/lintian_brush/tests/test_run.py b/lintian_brush/tests/test_run.py index f46accc1b717fb1f48cac376ca1690dff8647a1b..2dacd63874f9a2c98a880b7d3aa3a63997816cd7 100644 --- a/lintian_brush/tests/test_run.py +++ b/lintian_brush/tests/test_run.py @@ -220,6 +220,53 @@ Arch: all [], list(self.tree.iter_changes(self.tree.basis_tree()))) +class HonorsVcsCommitter(TestCaseWithTransport): + + def make_package_tree(self, format): + tree = self.make_branch_and_tree('.', format=format) + self.build_tree_contents([ + ('debian/', ), + ('debian/control', """\ +Source: blah +Vcs-Git: https://example.com/blah +Testsuite: autopkgtest + +Binary: blah +Arch: all + +"""), + CHANGELOG_FILE]) + tree.add(['debian', 'debian/changelog', 'debian/control']) + tree.commit('Initial thingy.') + return tree + + def make_change(self, tree): + with tree.lock_write(): + fixed_tags, summary = run_lintian_fixer( + tree, DummyFixer('dummy', 'some-tag'), + update_changelog=False) + self.assertEqual(summary, "Fixed some tag.") + self.assertEqual(['some-tag'], fixed_tags) + self.assertEqual(2, tree.branch.revno()) + self.assertEqual( + tree.get_file_lines('debian/control')[-1], + b"a new line\n") + + def test_honors_tree_committer_config(self): + tree = self.make_package_tree('git') + with open(os.path.join(tree.basedir, '.git/config'), 'w') as f: + f.write("""\ +[user] + email = jane@example.com + name = Jane Example + +""") + + self.make_change(tree) + rev = tree.branch.repository.get_revision(tree.branch.last_revision()) + self.assertEqual(rev.committer, 'Jane Example ') + + # TODO(jelmer): run_lintian_fixers