summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDaniel Gollub <dgollub@brocade.com>2015-03-17 08:12:53 +0100
committerGuido Günther <agx@sigxcpu.org>2015-04-25 09:19:56 +0200
commitaa8548d526397a3c4353b7212f3f848ab1f1e283 (patch)
tree1a5d0ee3741167bbf471b1fb04ba1797aa01a935
parent4a53c0f5c5819fb26cd02d746f08d6d4f4ba18f0 (diff)
Guess upstream-tag based on merge-base
In some unfortunate cases you might have something like this: $ git tag v1.0 vyatta/1.0-0something1 ... where later tag is closer to describe current HEAD. With upstream-tag set to v%(version)s find_tag() is going to propose something based on vyatta/1.0-0something1 which is not expected. The problem is that find_tag() returns tags, which match the upstream-tag format, but which are not on the upstream-branch at all. To fix this find_tag()/git-describe should not be used to determine the closest upstream-tag. Closes: gh#7
-rw-r--r--gbp/deb/git.py7
-rw-r--r--gbp/git/repository.py15
-rw-r--r--gbp/scripts/dch.py11
-rw-r--r--tests/03_test_dch_guess_version.py35
-rw-r--r--tests/11_test_dch_main.py3
-rw-r--r--tests/test_GitRepository.py17
6 files changed, 80 insertions, 8 deletions
diff --git a/gbp/deb/git.py b/gbp/deb/git.py
index 87df84eb..28177eb3 100644
--- a/gbp/deb/git.py
+++ b/gbp/deb/git.py
@@ -63,7 +63,8 @@ class DebianGitRepository(GitRepository):
return None
return None
- def debian_version_from_upstream(self, upstream_tag_format, commit='HEAD',
+ def debian_version_from_upstream(self, upstream_tag_format,
+ upstream_branch, commit='HEAD',
epoch=None):
"""
Build the Debian version that a package based on upstream commit
@@ -71,13 +72,15 @@ class DebianGitRepository(GitRepository):
@param upstream_tag_format: the tag format on the upstream branch
@type upstream_tag_format: C{str}
+ @param upstream_branch: the upstream branch
+ @type upstream_branch: 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 GitRepositoryError: if no upstream tag was found
"""
pattern = upstream_tag_format % dict(version='*')
- tag = self.find_tag(commit, pattern=pattern)
+ tag = self.find_branch_tag(commit, upstream_branch, pattern=pattern)
version = self.tag_to_version(tag, upstream_tag_format)
version += "-1"
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 689430f0..3b208bf4 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -713,6 +713,21 @@ class GitRepository(object):
"""
return self.describe(commit, pattern, abbrev=0)
+ def find_branch_tag(self, commit, branch, pattern=None):
+ """
+ Find the closest tag on a certain branch to a given commit
+
+ @param commit: the commit to describe
+ @type commit: C{str}
+ @type branch: C{str}
+ @param pattern: only look for tags matching I{pattern}
+ @type pattern: C{str}
+ @return: the found tag
+ @rtype: C{str}
+ """
+ base_commit = self.get_merge_base(commit, branch)
+ return self.describe(base_commit, pattern, abbrev=0)
+
def get_tags(self, pattern=None):
"""
List tags
diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py
index d0e9794d..bc223f93 100644
--- a/gbp/scripts/dch.py
+++ b/gbp/scripts/dch.py
@@ -38,18 +38,19 @@ user_customizations = {}
snapshot_re = re.compile("\s*\*\* SNAPSHOT build @(?P<commit>[a-z0-9]+)\s+\*\*")
-def guess_version_from_upstream(repo, upstream_tag_format, cp):
+def guess_version_from_upstream(repo, upstream_tag_format, upstream_branch, cp):
"""
Guess the version based on the latest version on the upstream branch
"""
try:
version = repo.debian_version_from_upstream(upstream_tag_format,
+ upstream_branch,
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 upstream tag found")
+ except GitRepositoryError as e:
+ gbp.log.debug("No upstream tag found: %s" % e)
return None
@@ -318,6 +319,7 @@ def build_parser(name):
parser.add_option_group(custom_group)
parser.add_boolean_config_file_option(option_name = "ignore-branch", dest="ignore_branch")
+ naming_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
naming_group.add_config_file_option(option_name="debian-branch", dest="debian_branch")
naming_group.add_config_file_option(option_name="upstream-tag", dest="upstream_tag")
naming_group.add_config_file_option(option_name="debian-tag", dest="debian_tag")
@@ -474,7 +476,8 @@ def main(argv):
if add_section and not version_change and not source.is_native():
# Get version from upstream if none provided
- v = guess_version_from_upstream(repo, options.upstream_tag, cp)
+ v = guess_version_from_upstream(repo, options.upstream_tag,
+ options.upstream_branch, cp)
if v:
version_change['version'] = v
diff --git a/tests/03_test_dch_guess_version.py b/tests/03_test_dch_guess_version.py
index 38d097c2..d7035018 100644
--- a/tests/03_test_dch_guess_version.py
+++ b/tests/03_test_dch_guess_version.py
@@ -15,14 +15,18 @@ class TestGuessVersionFromUpstream(testutils.DebianGitTestRepo):
cp = testutils.MockedChangeLog('1.0-1')
tagformat = 'upstream/%(version)s'
uversion = '1.1'
+ upstream_branch = 'upstream'
+
self.add_file('doesnot', 'matter')
+ self.repo.create_branch('upstream')
tag = self.repo.version_to_tag(tagformat, uversion)
self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
sign=False)
-
+ self.repo.set_branch("master")
guessed = dch.guess_version_from_upstream(self.repo,
tagformat,
+ upstream_branch,
cp)
self.assertEqual('1.1-1', guessed)
@@ -32,14 +36,43 @@ class TestGuessVersionFromUpstream(testutils.DebianGitTestRepo):
tagformat = 'upstream/%(version)s'
uversion = '1.1'
+ upstream_branch = 'upstream'
self.add_file('doesnot', 'matter')
+ self.repo.create_branch('upstream')
tag = self.repo.version_to_tag(tagformat, uversion)
self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
sign=False)
+ self.repo.set_branch("master")
guessed = dch.guess_version_from_upstream(self.repo,
tagformat,
+ upstream_branch,
cp)
self.assertEqual('1:1.1-1', guessed)
+
+ def test_guess_upstream_tag_clash_with_non_upstream_tag(self):
+ """Guess with clashing upstream- and non-upstream-tag"""
+ cp = testutils.MockedChangeLog('0.9-1')
+
+ tagformat = 'v%(version)s'
+ uversion = '1.0'
+ upstream_branch = 'upstream'
+
+ self.add_file('doesnot', 'matter')
+ self.repo.create_branch('upstream')
+ tag = self.repo.version_to_tag(tagformat, uversion)
+ self.repo.create_tag(name=tag, msg="Upstream release %s" % uversion,
+ sign=False)
+ self.repo.set_branch("master")
+ self.add_file("clash", "bar")
+ self.repo.create_tag("vyatta/something", msg="some non-upstream tag but not package release tag either")
+ self.add_file("clash2", "bar")
+
+ guessed = dch.guess_version_from_upstream(self.repo,
+ tagformat,
+ upstream_branch,
+ cp)
+
+ self.assertEqual('1.0-1', guessed)
diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py
index 538d2e84..acea6920 100644
--- a/tests/11_test_dch_main.py
+++ b/tests/11_test_dch_main.py
@@ -57,6 +57,7 @@ class TestScriptDch(DebianGitTestRepo):
self.repo.create_tag("upstream/0.9", msg="upstream version 0.9")
self.add_file("bar", "foo")
self.repo.create_tag("upstream/1.0", msg="upstream version 1.0")
+ self.repo.create_branch("upstream")
self.repo.create_branch("debian")
self.repo.set_branch("debian")
self.upstream_tag = "upstream/%(version)s"
@@ -66,7 +67,7 @@ class TestScriptDch(DebianGitTestRepo):
self.add_file("debian/changelog", cl_debian)
self.add_file("debian/control", """Source: test-package\nSection: test\n""")
self.options = ["--upstream-tag=%s" % self.upstream_tag, "--debian-branch=debian",
- "--id-length=0", "--spawn-editor=/bin/true"]
+ "--upstream-branch=upstream", "--id-length=0", "--spawn-editor=/bin/true"]
self.repo.create_tag(deb_tag, msg=deb_tag_msg, commit="HEAD~1")
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index 8803e857..83ae8edb 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -309,6 +309,23 @@ def test_find_tag():
GitRepositoryError: Can't describe HEAD. Git error: fatal: No names found, cannot describe anything.
"""
+def test_find_branch_tag():
+ """
+ Find the closest tags on a certain branch to a given commit
+
+ Methods tested:
+ - L{gbp.git.GitRepository.find_branch_tag}
+
+ >>> import gbp.git
+ >>> repo = gbp.git.GitRepository(repo_dir)
+ >>> repo.find_branch_tag('HEAD', 'master', 'tag*')
+ 'tag2'
+ >>> repo.find_branch_tag('HEAD', 'master', 'v*') # doctest:+ELLIPSIS
+ Traceback (most recent call last):
+ ...
+ GitRepositoryError: Can't describe .... Git error: fatal: No names found, cannot describe anything.
+ """
+
def test_move_tag():
"""
Move a tag