summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-01-08 19:48:24 +0100
committerGuido Günther <agx@sigxcpu.org>2012-01-10 13:15:12 +0100
commit8328c326f1fd40ecf9d6404faaee8658ec37f201 (patch)
treeee1bbecbd455373740b901dfb50228546c504249
parentd316e22a64bee277efdc21b353294b262eb22c23 (diff)
Allow to specify the upstream tree via --upstream-tree
without the indirection to --upstream-branch.
-rw-r--r--docs/manpages/git-buildpackage.sgml15
-rw-r--r--gbp/config.py2
-rw-r--r--gbp/scripts/buildpackage.py35
-rw-r--r--tests/10_test_get_upstream_tree.py81
-rw-r--r--tests/testutils.py41
5 files changed, 154 insertions, 20 deletions
diff --git a/docs/manpages/git-buildpackage.sgml b/docs/manpages/git-buildpackage.sgml
index 5e5ae73..b6f02e1 100644
--- a/docs/manpages/git-buildpackage.sgml
+++ b/docs/manpages/git-buildpackage.sgml
@@ -43,7 +43,7 @@
<arg><option>--git-debian-tag=</option><replaceable>tag-format</replaceable></arg>
<arg><option>--git-force-create</option></arg>
<arg><option>--git-no-create-orig</option></arg>
- <arg><option>--git-upstream-tree=</option><replaceable>[tag|branch]</replaceable></arg>
+ <arg><option>--git-upstream-tree=</option><replaceable>[TAG|BRANCH|treeish]</replaceable></arg>
<arg><option>--git-tarball-dir=</option><replaceable>directory</replaceable></arg>
<arg><option>--git-compression=</option><replaceable>type</replaceable></arg>
<arg><option>--git-compression-level=</option><replaceable>level</replaceable></arg>
@@ -196,9 +196,8 @@
</term>
<listitem>
<para>Branch to build the orig tarball from if <option>--git-upstream-tree</option>
- is set to <replaceable>branch</replaceable>. Default is
- <replaceable>upstream</replaceable>. You can give any treeish object
- here.</para>
+ is set to <replaceable>BRANCH</replaceable>. Default is
+ <replaceable>upstream</replaceable>.</para>
</listitem>
</varlistentry>
<varlistentry>
@@ -334,10 +333,12 @@
</term>
<listitem>
<para>How to find the upstream sources used to generate the tarball.
- <replaceable>tag</replaceable> looks at a tag corresponding to the
- version in the changelog. <replaceable>branch</replaceable> looks at
+ <replaceable>TAG</replaceable> looks at a tag corresponding to the
+ version in the changelog. <replaceable>BRANCH</replaceable> looks at
the upstream branch given via the <option>--git-upstream-branch</option>
- option. This doesn't have any effect if <option>--git-pristine-tar</option>
+ option. Other values are interpreted as treeishs.
+ </para><para>
+ This doesn't have any effect if <option>--git-pristine-tar</option>
is being used.
</para>
</listitem>
diff --git a/gbp/config.py b/gbp/config.py
index 78c88ca..030f116 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -72,7 +72,7 @@ class GbpOptionParser(OptionParser):
'cleaner' : 'debuild -d clean',
'debian-branch' : 'master',
'upstream-branch' : 'upstream',
- 'upstream-tree' : 'tag',
+ 'upstream-tree' : 'TAG',
'pristine-tar' : 'False',
'filter-pristine-tar' : 'False',
'sign-tags' : 'False',
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py
index 911552d..8510ed1 100644
--- a/gbp/scripts/buildpackage.py
+++ b/gbp/scripts/buildpackage.py
@@ -330,24 +330,35 @@ def pristine_tar_build_orig(repo, cp, output_dir, options):
return False
-def git_archive_build_orig(repo, cp, output_dir, options):
- """build orig using git-archive"""
- if options.upstream_tree == 'tag':
- upstream_tree = repo.version_to_tag(options.upstream_tag, cp['Upstream-Version'])
- elif options.upstream_tree == 'branch':
+def get_upstream_tree(repo, cp, options):
+ """Determine the upstream tree from the given options"""
+ if options.upstream_tree.upper() == 'TAG':
+ upstream_tree = repo.version_to_tag(options.upstream_tag,
+ cp['Upstream-Version'])
+ elif options.upstream_tree.upper() == 'BRANCH':
+ if not repo.has_branch(options.upstream_branch):
+ raise GbpError("%s is not a valid branch" % options.upstream_branch)
upstream_tree = options.upstream_branch
else:
- raise GbpError, "Unknown value %s" % options.upstream_tree
+ upstream_tree = options.upstream_tree
+ if not repo.has_treeish(upstream_tree):
+ raise GbpError # git-ls-tree printed an error message already
+ return upstream_tree
+
+
+def git_archive_build_orig(repo, cp, output_dir, options):
+ """build orig using git-archive"""
+ upstream_tree = get_upstream_tree(repo, cp, options)
gbp.log.info("%s does not exist, creating from '%s'" % (du.orig_file(cp,
options.comp_type),
upstream_tree))
- if not repo.has_treeish(upstream_tree):
- raise GbpError # git-ls-tree printed an error message already
- gbp.log.debug("Building upstream tarball with compression '%s -%s'" % (options.comp_type,
- options.comp_level))
+ gbp.log.debug("Building upstream tarball with compression '%s -%s'" %
+ (options.comp_type, options.comp_level))
if not git_archive(repo, cp, output_dir, upstream_tree,
- options.comp_type, options.comp_level, options.with_submodules):
- raise GbpError, "Cannot create upstream tarball at '%s'" % output_dir
+ options.comp_type,
+ options.comp_level,
+ options.with_submodules):
+ raise GbpError("Cannot create upstream tarball at '%s'" % output_dir)
def guess_comp_type(repo, comp_type, cp, tarball_dir):
diff --git a/tests/10_test_get_upstream_tree.py b/tests/10_test_get_upstream_tree.py
new file mode 100644
index 0000000..3cd7eb8
--- /dev/null
+++ b/tests/10_test_get_upstream_tree.py
@@ -0,0 +1,81 @@
+# vim: set fileencoding=utf-8 :
+
+"""Test L{buildpackage}'s get_upstream_tree method"""
+
+import testutils
+
+import gbp.errors
+import gbp.scripts.buildpackage as buildpackage
+
+class MockOptions(object):
+ def __init__(self,
+ upstream_branch=None,
+ upstream_tree=None,
+ upstream_tag=None):
+ self.upstream_branch = upstream_branch
+ self.upstream_tree = upstream_tree
+ self.upstream_tag = upstream_tag
+
+class TestGetUpstreamTree(testutils.DebianGitTestRepo):
+ def test_valid_upstream_branch(self):
+ """Write out index file to nonexistant dir"""
+ self.add_file('foo')
+ self.repo.create_branch('upstream')
+ options = MockOptions(upstream_tree='BRANCH',
+ upstream_branch='upstream')
+ t = buildpackage.get_upstream_tree(self.repo, None, options)
+ self.assertEqual(t, 'upstream')
+
+ def test_invalid_upstream_branch(self):
+ """Write out index file to nonexistant dir"""
+ self.add_file('foo')
+ options = MockOptions(upstream_tree='BRANCH',
+ upstream_branch='upstream')
+ self.assertRaises(gbp.errors.GbpError,
+ buildpackage.get_upstream_tree,
+ self.repo,
+ None,
+ options)
+
+ def test_valid_tree(self):
+ """Write out index file to nonexistant dir"""
+ self.add_file('foo')
+ tree = self.repo.rev_parse('master')
+ options = MockOptions(upstream_tree=tree)
+ t = buildpackage.get_upstream_tree(self.repo, None, options)
+ self.assertEqual(t, tree)
+
+ def test_invalid_tree(self):
+ """Write out index file to nonexistant dir"""
+ self.add_file('foo')
+ options = MockOptions(upstream_tree='doesnotexist')
+ self.assertRaises(gbp.errors.GbpError,
+ buildpackage.get_upstream_tree,
+ self.repo,
+ None,
+ options)
+
+ def test_valid_tag(self):
+ """Write out index file to nonexistant dir"""
+ self.add_file('foo')
+ tree = self.repo.rev_parse('master')
+ cp = { 'Upstream-Version': '1.0~rc3' }
+ self.repo.create_tag('upstream/1.0_rc3')
+ options = MockOptions(upstream_tree="TAG",
+ upstream_tag="upstream/%(version)s")
+ tag = buildpackage.get_upstream_tree(self.repo, cp, options)
+ self.assertEqual(tag, "upstream/1.0_rc3")
+
+ def test_invalid_tag(self):
+ """Write out index file to nonexistant dir"""
+ self.add_file('foo')
+ cp = { 'Upstream-Version': '1.0~rc3' }
+ options = MockOptions(upstream_tree="TAG",
+ upstream_tag="upstream/%(version)s")
+ self.assertRaises(gbp.errors.GbpError,
+ buildpackage.get_upstream_tree,
+ self.repo,
+ cp,
+ options)
+
+# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
diff --git a/tests/testutils.py b/tests/testutils.py
new file mode 100644
index 0000000..74b1067
--- /dev/null
+++ b/tests/testutils.py
@@ -0,0 +1,41 @@
+# vim: set fileencoding=utf-8 :
+
+import os
+import shutil
+import unittest
+
+import gbp.log
+import gbp.deb.git
+import gbp.errors
+import gbp.scripts.buildpackage as buildpackage
+
+class DebianGitTestRepo(unittest.TestCase):
+ """Scratch repo for a single test"""
+
+ def setUp(self):
+ gbp.log.setup(False, False)
+ top = os.path.abspath(os.path.curdir)
+ self.tmpdir = os.path.join(top, 'gbp_%s_repo' % __name__)
+ os.mkdir(self.tmpdir)
+
+ repodir = os.path.join(self.tmpdir, 'test_repo')
+ self.repo = gbp.deb.git.DebianGitRepository.create(repodir)
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def add_file(self, name, content=None):
+ """
+ Add a single file with name I{name} and content I{content}. If
+ I{content} is C{none} the content of the file is undefined.
+
+ @param name: the file's path relativ to the git repo
+ @type name: C{str}
+ @param content: the file's content
+ @type content: C{str}
+ """
+ path = os.path.join(self.repo.path, name)
+ with file(path, 'w+') as f:
+ content == None or f.write(content)
+ self.repo.add_files(name, force=True)
+ self.repo.commit_files(path, "added %s" % name)