dch: Honor epoch when guessing new upstream version
authorGuido Günther <agx@sigxcpu.org>
Wed, 28 Dec 2011 09:30:07 +0000 (10:30 +0100)
committerGuido Günther <agx@sigxcpu.org>
Wed, 28 Dec 2011 09:44:36 +0000 (10:44 +0100)
Closes: #652366
Thanks: a lot to Daniel Dehennin for the testcase

gbp/scripts/dch.py
tests/03_test_dch_guess_version.py [new file with mode: 0644]

index 2d4a8ed..2ee988d 100644 (file)
@@ -106,15 +106,16 @@ def guess_version_from_upstream(repo, upstream_tag_format, cp):
     """
     Guess the version based on the latest version on the upstream branch
     """
-    pattern = upstream_tag_format.replace('%(version)s', '*')
+    pattern = upstream_tag_format % dict(version='*')
     try:
         tag = repo.find_tag('HEAD', pattern=pattern)
-        upstream = repo.tag_to_version(tag, upstream_tag_format)
-        if upstream:
-            gbp.log.debug("Found upstream version %s." % upstream)
-            new_version = "%s-1" % upstream
-            if compare_versions(upstream, cp.version) > 0:
-                return new_version
+        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
     except GitRepositoryError:
         gbp.log.debug("No tag found matching pattern %s." % pattern)
     return None
diff --git a/tests/03_test_dch_guess_version.py b/tests/03_test_dch_guess_version.py
new file mode 100644 (file)
index 0000000..1034307
--- /dev/null
@@ -0,0 +1,50 @@
+import unittest
+
+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):
+    contents = """foo (%s) experimental; urgency=low
+
+  * a important change
+
+ -- Debian Maintainer <maint@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):
+    """Dest 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',
+                                                  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',
+                                                  cp)
+        self.assertEqual('1:1.1-1', guessed)
+
+