Hi Daniel, On Wed, May 30, 2012 at 09:12:41PM +0200, Daniel Dehennin wrote: > * gbp/deb/git.py: Update imports. > (guess_version_from_upstream): New method adapted from > gbp.scripts.dch. Remove the logging. Caller is responsible of handling > possible GitRepositoryError exception. > > * tests/03_test_DebianGitRepository_guess_version_from_upstream.py: > Adapt 03_test_dch_guess_version.py. > (MockGitRepository): Inherit from DebianGitRepository. > (TestGuessVersionFromUpstream.test_guess_no_epoch): Test calls of > guess_version_from_upstream(). > (TestGuessVersionFromUpstream.test_guess_epoch): Ditoo with epoch in > version.
I implemented this slightly different since I don't want to pull in cp into DebianGitRepository. Could you rebase so I can pull the rest of #672954 And please squash 06e7b7e76aa30072c96eae8955ecc185b155458f and 5313e5d7985451ff98c76e0a8f9a18abc54192ce since it makes it more obvius that this is in large parts a shifting code around. Cheers and thanks for your work and patience, -- Guido > --- > gbp/deb/git.py | 17 +++++++ > ...ianGitRepository_guess_version_from_upstream.py | 47 > ++++++++++++++++++++ > 2 files changed, 64 insertions(+) > create mode 100644 > tests/03_test_DebianGitRepository_guess_version_from_upstream.py > > diff --git a/gbp/deb/git.py b/gbp/deb/git.py > index c9004ef..c4ca288 100644 > --- a/gbp/deb/git.py > +++ b/gbp/deb/git.py > @@ -19,6 +19,7 @@ > import re > from gbp.git import GitRepository, GitRepositoryError > from gbp.deb.pristinetar import DebianPristineTar > +from gbp.deb import compare_versions > > class DebianGitRepository(GitRepository): > """A git repository that holds the source of a Debian package""" > @@ -117,6 +118,22 @@ class DebianGitRepository(GitRepository): > return version > return None > > + def guess_version_from_upstream(self, upstream_tag_format, cp): > + """ > + Guess the version based on the latest version on the upstream branch > + """ > + pattern = upstream_tag_format % dict(version='*') > + tag = self.find_tag('HEAD', pattern=pattern) > + version = self.tag_to_version(tag, upstream_tag_format) > + if version: > + if cp == None: > + return "%s-1" % version > + if cp.has_epoch(): > + version = "%s:%s" % (cp.epoch, version) > + if compare_versions(version, cp.version) > 0: > + return "%s-1" % version > + return None > + > @property > def pristine_tar_branch(self): > """ > diff --git a/tests/03_test_DebianGitRepository_guess_version_from_upstream.py > b/tests/03_test_DebianGitRepository_guess_version_from_upstream.py > new file mode 100644 > index 0000000..1cfb439 > --- /dev/null > +++ b/tests/03_test_DebianGitRepository_guess_version_from_upstream.py > @@ -0,0 +1,47 @@ > +# vim: set fileencoding=utf-8 : > + > +"""Test L{Changelog}'s guess_version_from_upstream""" > + > +import unittest > + > +from gbp.errors import GbpError > +from gbp.deb.changelog import ChangeLog > +from gbp.deb.git import DebianGitRepository > + > +class MockGitRepository(DebianGitRepository): > + def __init__(self, upstream_tag): > + self.upstream_tag = upstream_tag > + > + def find_tag(self, branch, pattern): > + return self.upstream_tag > + > + def tag_to_version(self, tag, format): > + return DebianGitRepository.tag_to_version(tag, format) > + > + > +class MockedChangeLog(ChangeLog): > + contents = """foo (%s) experimental; urgency=low > + > + * a important change > + > + -- Debian Maintainer <ma...@debian.org> Sat, 01 Jan 2012 00:00:00 +0100""" > + > + def __init__(self, version): > + ChangeLog.__init__(self, contents=self.contents % version) > + > + > +class TestGuessVersionFromUpstream(unittest.TestCase): > + """Test guess_version_from_upstream""" > + def test_guess_no_epoch(self): > + """Guess the new version from the upstream tag""" > + repo = MockGitRepository(upstream_tag='upstream/1.1') > + cp = MockedChangeLog('1.0-1') > + guessed = repo.guess_version_from_upstream('upstream/%(version)s', > cp) > + self.assertEqual('1.1-1', guessed) > + > + def test_guess_epoch(self): > + """Check if we picked up the epoch correctly (#652366)""" > + repo = MockGitRepository(upstream_tag='upstream/1.1') > + cp = MockedChangeLog('1:1.0-1') > + guessed = repo.guess_version_from_upstream('upstream/%(version)s', > cp) > + self.assertEqual('1:1.1-1', guessed) > -- > 1.7.10.4 -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org