return None
return None
+ def debian_version_from_upstream(self, upstream_tag_format, commit='HEAD',
+ epoch=None):
+ """
+ Build the Debian version that a package based on upstream commit
+ I{commit} would carry taking into account a possible epoch.
+
+ @param upstream_tag_format; the tag format on the upstream branch
+ @type upstream_tag_format; C{str}
+ @param commit: the commit to search for the latest upstream version
+ @param epoch: an epoch to use
+ @returns: a new debian version
+ @raises: L{GitRepositoryError} if no upstream tag was found
+ """
+ pattern = upstream_tag_format % dict(version='*')
+ tag = self.find_tag(commit, pattern=pattern)
+ version = self.tag_to_version(tag, upstream_tag_format)
+
+ version += "-1"
+ if epoch:
+ version = "%s:%s" % (epoch, version)
+ return version
+
@staticmethod
def _build_legacy_tag(format, version):
"""
"""
Guess the version based on the latest version on the upstream branch
"""
- pattern = upstream_tag_format % dict(version='*')
try:
- tag = repo.find_tag('HEAD', pattern=pattern)
- version = repo.tag_to_version(tag, upstream_tag_format)
- if version:
- gbp.log.debug("Found upstream version %s." % version)
- if cp.has_epoch():
- version = "%s:%s" % (cp.epoch, version)
- if compare_versions(version, cp.version) > 0:
- return "%s-1" % version
+ version = repo.debian_version_from_upstream(upstream_tag_format,
+ epoch=cp.epoch)
+ gbp.log.debug("Found upstream version %s." % version)
+ if compare_versions(version, cp.version) > 0:
+ return version
except GitRepositoryError:
- gbp.log.debug("No tag found matching pattern %s." % pattern)
+ gbp.log.debug("No upstream tag found")
return None
"""Test L{Changelog}'s guess_version_from_upstream"""
-import unittest
+import testutils
from gbp.scripts import dch
-from gbp.errors import GbpError
from gbp.deb.changelog import ChangeLog
-from gbp.deb.git import DebianGitRepository
-
-class MockGitRepository(object):
- 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):
ChangeLog.__init__(self, contents=self.contents % version)
-class TestGuessVersionFromUpstream(unittest.TestCase):
+class TestGuessVersionFromUpstream(testutils.DebianGitTestRepo):
"""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 = dch.guess_version_from_upstream(repo,
- 'upstream/%(version)s',
+ tagformat = 'upstream/%(version)s'
+ uversion = '1.1'
+
+ self.add_file('doesnot', 'matter')
+ tag = self.repo.version_to_tag(tagformat, uversion)
+ self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
+ sign=False)
+
+ guessed = dch.guess_version_from_upstream(self.repo,
+ tagformat,
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 = dch.guess_version_from_upstream(repo,
- 'upstream/%(version)s',
+
+ tagformat = 'upstream/%(version)s'
+ uversion = '1.1'
+
+ self.add_file('doesnot', 'matter')
+ tag = self.repo.version_to_tag(tagformat, uversion)
+ self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
+ sign=False)
+
+ guessed = dch.guess_version_from_upstream(self.repo,
+ tagformat,
cp)
+
self.assertEqual('1:1.1-1', guessed)