Detect compression from orig tarball
authorLoïc Minier <lool@debian.org>
Fri, 8 Apr 2011 01:54:07 +0000 (03:54 +0200)
committerGuido Günther <agx@sigxcpu.org>
Sat, 9 Apr 2011 20:42:36 +0000 (22:42 +0200)
git-buildpackage
tests/05_test_detection.py

index 11773ab..c52cd01 100755 (executable)
@@ -278,7 +278,18 @@ def guess_comp_type(repo, comp_type, cp, tarball_dir):
 
     if comp_type == 'auto':
         if not repo.has_branch(PristineTar.branch):
-            comp_type = 'gzip'
+            if not tarball_dir:
+                tarball_dir = '..'
+            detected = None
+            for comp in du.compressor_opts.keys():
+                if du.has_orig(cp, comp, tarball_dir):
+                    if detected is not None:
+                        raise GbpError, "Multiple orig tarballs found."
+                    detected = comp
+            if detected is not None:
+                comp_type = detected
+            else:
+                comp_type = 'gzip'
         else:
             regex = 'pristine-tar .* %s_%s\.orig.tar\.' % (srcpkg, upstream_version)
             commits = repo.grep_log(regex, PristineTar.branch)
index 4c028ff..72c9316 100644 (file)
@@ -5,6 +5,7 @@ import unittest
 
 import git_buildpackage
 from gbp.deb import has_orig
+from gbp.errors import GbpError
 
 class MockGitRepository:
     def __init__(self, with_branch=False, subject=None):
@@ -28,12 +29,31 @@ class TestDetection(unittest.TestCase):
     def tearDown(self):
         shutil.rmtree(self.tmpdir)
 
-    def test_guess_comp_type_no_pristine_tar(self):
+    def test_guess_comp_type_no_pristine_tar_no_orig(self):
         repo = MockGitRepository(with_branch=False)
         guessed = git_buildpackage.guess_comp_type(
             repo, 'auto', self.cp, self.tmpdir)
         self.assertEqual('gzip', guessed)
 
+    def test_guess_comp_type_no_pristine_tar_with_orig(self):
+        open(os.path.join(self.tmpdir, 'source_1.2.orig.tar.bz2'), "w").close()
+        repo = MockGitRepository(with_branch=False)
+        guessed = git_buildpackage.guess_comp_type(
+            repo, 'auto', self.cp, self.tmpdir)
+        self.assertEqual('bzip2', guessed)
+
+    def test_guess_comp_type_no_pristine_tar_with_multiple_origs(self):
+        open(os.path.join(self.tmpdir, 'source_1.2.orig.tar.gz'), "w").close()
+        open(os.path.join(self.tmpdir, 'source_1.2.orig.tar.xz'), "w").close()
+        repo = MockGitRepository(with_branch=False)
+        self.assertRaises(
+            GbpError,
+            git_buildpackage.guess_comp_type,
+            repo,
+            'auto',
+            self.cp,
+            self.tmpdir)
+
     def test_guess_comp_type_bzip2(self):
         subject = 'pristine-tar data for source_1.2-3.orig.tar.bz2'
         repo = MockGitRepository(with_branch=True, subject=subject)