diff options
-rw-r--r-- | gbp/scripts/import_dsc.py | 17 | ||||
-rw-r--r-- | tests/component/deb/test_import_dsc.py | 36 |
2 files changed, 45 insertions, 8 deletions
diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py index eb42925c..1765d973 100644 --- a/gbp/scripts/import_dsc.py +++ b/gbp/scripts/import_dsc.py @@ -41,6 +41,19 @@ class SkipImport(Exception): pass +def generate_pristine_tarballs(repo, src, upstream_tree): + subdirs = src.additional_tarballs.keys() + main_tree = repo.tree_drop_dirs(upstream_tree, subdirs) + + for dir, tarball in src.additional_tarballs.items(): + subtree = repo.tree_get_dir(upstream_tree, dir) + if not subtree: + raise GbpError("No tree for '%s' found in '%s' to create pristine tar commit from" % (dir, upstream_tree)) + gbp.log.debug("Creating pristine tar commit '%s' from '%s'" % (dir, subtree)) + repo.pristine_tar.commit(tarball, subtree) + repo.pristine_tar.commit(src.tgz, main_tree) + + def download_source(pkg, dirs, unauth): opts = [ '--download-only' ] if unauth: @@ -328,8 +341,6 @@ def main(argv): if repo.bare: disable_pristine_tar(options, "Bare repository") - elif src.additional_tarballs: - disable_pristine_tar(options, "Component tarballs found") dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..')) upstream = DebianUpstreamSource(src.tgz) @@ -389,7 +400,7 @@ def main(argv): if is_empty: repo.create_branch(options.upstream_branch, commit) if options.pristine_tar: - repo.pristine_tar.commit(src.tgz, options.upstream_branch) + generate_pristine_tarballs(repo, src, options.upstream_branch) if (not repo.has_branch(options.debian_branch) and (is_empty or options.create_missing_branches)): repo.create_branch(options.debian_branch, commit) diff --git a/tests/component/deb/test_import_dsc.py b/tests/component/deb/test_import_dsc.py index 7a82ce0c..615ef979 100644 --- a/tests/component/deb/test_import_dsc.py +++ b/tests/component/deb/test_import_dsc.py @@ -17,19 +17,30 @@ # <http://www.gnu.org/licenses/> import os +import hashlib from tests.component import (ComponentTestBase, ComponentTestGitRepository) from tests.component.deb import DEB_TEST_DATA_DIR -from nose.tools import ok_ +from nose.tools import ok_, eq_ from gbp.scripts.import_dsc import main as import_dsc +from gbp.deb.pristinetar import DebianPristineTar +from gbp.deb.dscfile import DscFile class TestImportDsc(ComponentTestBase): """Test importing of debian source packages""" + @staticmethod + def _hash_file(filename): + h = hashlib.md5() + with open(filename, 'rb') as f: + buf = f.read() + h.update(buf) + return h.hexdigest() + def test_debian_import(self): """Test that importing of debian native packages works""" def _dsc(version): @@ -84,22 +95,22 @@ class TestImportDsc(ComponentTestBase): commits, expected = len(repo.get_commits()), 2 ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected)) - def test_import_multiple(self): + def test_import_multiple_pristine_tar(self): """Test if importing a multiple tarball package works""" def _dsc(version): return os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0-additional-tarballs', 'hello-debhelper_%s.dsc' % version) - dsc = _dsc('2.8-1') + dscfile = _dsc('2.8-1') assert import_dsc(['arg0', '--verbose', '--pristine-tar', '--debian-branch=master', '--upstream-branch=upstream', - dsc]) == 0 + dscfile]) == 0 repo = ComponentTestGitRepository('hello-debhelper') - self._check_repo_state(repo, 'master', ['master', 'upstream']) + self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream']) commits, expected = len(repo.get_commits()), 2 for file in ['foo/test1', 'foo/test2']: @@ -108,6 +119,21 @@ class TestImportDsc(ComponentTestBase): ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected)) + dsc = DscFile.parse(dscfile) + # Check if we can rebuild the tarball and subtarball + ptars = [('hello-debhelper_2.8.orig.tar.gz', 'pristine-tar', '', dsc.tgz), + ('hello-debhelper_2.8.orig-foo.tar.gz', 'pristine-tar^', 'foo', dsc.additional_tarballs['foo'])] + + p = DebianPristineTar(repo) + outdir = os.path.abspath('.') + for f, w, s, o in ptars: + eq_(repo.get_subject(w), 'pristine-tar data for %s' % f) + old = self._hash_file(o) + p.checkout('hello-debhelper', '2.8', 'gzip', outdir, subtarball=s) + new = self._hash_file(os.path.join(outdir, f)) + eq_(old, new, "Checksum %s of regenerated tarball %s does not match original %s" % + (f, old, new)) + def test_existing_dir(self): """ Importing outside of git repository with existing target |