export-orig: Check 'origin/pristine-tar' as well for compression type
authorGuido Günther <agx@sigxcpu.org>
Mon, 7 Oct 2019 09:23:13 +0000 (11:23 +0200)
committerGuido Günther <agx@sigxcpu.org>
Mon, 7 Oct 2019 11:49:11 +0000 (13:49 +0200)
Closes: #941894
gbp/scripts/export_orig.py
tests/05_test_detection.py
tests/component/deb/test_export_orig.py

index 6a48502de1f1453bc5b4ab63ec5284a2b395e675..c288501458c058b55f1b70bb1511d67006e51574 100755 (executable)
@@ -235,14 +235,20 @@ def guess_comp_type(comp_type, source, repo, tarball_dir):
             comp_type = 'auto'
 
     if comp_type == 'auto':
-        if repo and repo.has_pristine_tar_branch():
+        branch = None
+        if repo.has_branch('pristine-tar'):
+            branch = 'pristine-tar'
+        elif repo.has_branch('origin/pristine-tar', remote=True):
+            branch = 'origin/pristine-tar'
+
+        if branch:
             regex = r'pristine-tar .* %s_%s\.orig.tar\.' % (source.name, source.upstream_version)
-            commits = repo.grep_log(regex, repo.pristine_tar_branch, merges=False)
+            commits = repo.grep_log(regex, branch, merges=False)
             if commits:
                 commit = commits[-1]
                 gbp.log.debug("Found pristine-tar commit at '%s'" % commit)
             else:
-                commit = repo.pristine_tar_branch
+                commit = branch
             tarball = repo.get_commit_info(commit)['subject']
             (base_name, archive_fmt, comp_type) = Archive.parse_filename(tarball)
             gbp.log.debug("Determined compression type '%s'" % comp_type)
@@ -250,8 +256,7 @@ def guess_comp_type(comp_type, source, repo, tarball_dir):
                 comp_type = 'gzip'
                 gbp.log.warn("Unknown compression type of %s, assuming %s" % (tarball, comp_type))
         else:
-            if not tarball_dir:
-                tarball_dir = '..'
+            tarball_dir = tarball_dir or '..'
             detected = None
             for comp in Compressor.Opts.keys():
                 if du.DebianPkgPolicy.has_orig(source.upstream_tarball_name(comp), tarball_dir):
index 5e903db3afcef3368d1997bb10b524282fcfe2db..d632233504a415f0130426c1cdd097614af5118b 100644 (file)
@@ -21,6 +21,9 @@ class MockGitRepository:
     def has_pristine_tar_branch(self):
         return self.with_branch
 
+    def has_branch(self, branch, remote=False):
+        return branch == 'pristine-tar' and self.with_branch
+
     def pristine_tar_branch(self):
         'pristine-tar'
 
index b2a8e8bb7e156bb183550f200530b41a46c15840..c01562def1c59652af822b9c50e08853b51436cf 100644 (file)
@@ -21,9 +21,11 @@ import os
 from tests.component import (ComponentTestBase,
                              ComponentTestGitRepository)
 from tests.component.deb import DEB_TEST_DATA_DIR
+from tests.component.deb.fixtures import RepoFixtures
 
 from nose.tools import ok_, assert_false, assert_true
 
+from gbp.scripts.clone import main as clone
 from gbp.scripts.import_dsc import main as import_dsc
 from gbp.scripts.export_orig import main as export_orig
 
@@ -136,3 +138,19 @@ class TestExportOrig(ComponentTestBase):
         for t in tarballs:
             self.assertFalse(os.path.exists(os.path.join('..', t)), "Tarball %s found" % t)
             self.assertTrue(os.path.exists(os.path.join(DEB_TEST_DATA_DIR, 'foo-2.8', t)), "Tarball %s not found" % t)
+
+    @RepoFixtures.quilt30(opts=['--pristine-tar'])
+    def test_pristine_tar_commit_on_origin(self, repo):
+        """Test that we can create tarball from 'origin/pristine-tar'"""
+
+        assert_true(repo.has_branch('pristine-tar'),
+                    "Pristine-tar branch must exist in origin")
+        dest = os.path.join(self._tmpdir, 'cloned_repo')
+        clone(['arg0', repo.path, dest])
+        cloned = ComponentTestGitRepository(dest)
+
+        os.chdir(cloned.path)
+        assert_false(cloned.has_branch('pristine-tar'),
+                     "Pristine-tar branch must not exist in clone")
+        ret = export_orig(['arg0', '--pristine-tar'])
+        ok_(ret == 0, "Exporting tarballs must not fail")