Commit e441d2d9 authored by Jelmer Vernooij's avatar Jelmer Vernooij

Print proper error when tree does not contain a debian package.

parent 2bd46d87
......@@ -50,6 +50,13 @@ class DescriptionMissing(Exception):
"""The fixer script did not provide a description on stdout."""
class NotDebianPackage(Exception):
"""The specified directory does not contain a Debian package."""
def __init__(self, tree):
super(NotDebianPackage, self).__init__(tree.basedir)
class FixerResult(object):
"""Result of a fixer run."""
......@@ -163,6 +170,14 @@ def available_lintian_fixers(fixers_dir=None):
def increment_version(v):
"""Increment a version number.
For native packages, increment the main version number.
For other packages, increment the debian revision.
Args:
v: Version to increment (modified in place)
"""
if v.debian_revision is not None:
v.debian_revision = re.sub(
'\\d+$', lambda x: str(int(x.group())+1), v.debian_revision)
......@@ -184,6 +199,8 @@ def run_lintian_fixer(local_tree, fixer, update_changelog=True):
# Just check there are no changes to begin with
if list(local_tree.iter_changes(local_tree.basis_tree())):
raise AssertionError("Local tree %s has changes" % local_tree.basedir)
if not local_tree.has_filename('debian/changelog'):
raise NotDebianPackage(local_tree)
with local_tree.get_file('debian/changelog') as f:
cl = Changelog(f, max_blocks=1)
if cl.distributions == 'UNRELEASED':
......
......@@ -31,6 +31,7 @@ import breezy.git # noqa: E402
import breezy.bzr # noqa: E402
from . import ( # noqa: E402
NotDebianPackage,
available_lintian_fixers,
find_fixers_dir,
run_lintian_fixers,
......@@ -75,5 +76,8 @@ else:
if args.fixers:
fixers = [f for f in fixers if f.tag in args.fixers]
with wt.lock_write():
run_lintian_fixers(
wt, fixers, update_changelog=(not args.no_update_changelog))
try:
run_lintian_fixers(
wt, fixers, update_changelog=(not args.no_update_changelog))
except NotDebianPackage:
print("%s: Not a debian package" % wt.basedir, file=sys.stderr)
......@@ -30,6 +30,7 @@ from lintian_brush import (
Fixer,
FixerResult,
NoChanges,
NotDebianPackage,
available_lintian_fixers,
increment_version,
run_lintian_fixer,
......@@ -98,6 +99,15 @@ Arch: all
self.tree.add(['debian', 'debian/changelog', 'debian/control'])
self.tree.commit('Initial thingy.')
def test_not_debian_tree(self):
self.tree.remove('debian/changelog')
os.remove('debian/changelog')
self.tree.commit("not a debian dir")
with self.tree.lock_write():
self.assertRaises(
NotDebianPackage, run_lintian_fixer,
self.tree, DummyFixer('some-tag'), update_changelog=False)
def test_simple_modify(self):
with self.tree.lock_write():
fixed_tags, summary = run_lintian_fixer(
......
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