aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMaximiliano Curia <maxy@debian.org>2016-09-11 16:23:11 +0200
committerGuido Günther <agx@sigxcpu.org>2017-12-24 19:47:46 +0100
commit17a471d1fc07935dd85c31d3a7c4ae3ea5c39208 (patch)
tree4ef3b83af5078774ffb0c315f9ededaf3e707938 /tests
parent4312e54b6ed154f4149ddcfd1b88a40cc1b4caad (diff)
pq: Parse DEP3 headers
Currently the patch headers in DEP3 format are partially supported, as git's mailinfo only reads the From and Subject fields from the first paragraph. But the default in dep3 patches is Description and Author, that are ignored by git. Even worse, when this fields are in the first paragraph (again the default) git mailinfo drops all the contained information. This patch parses the dep3 headers if git's mailinfo couldn't obtain any useful information, any header other than Subject|Description and Author|From is appended to the patch message. The description field is splitted in first line for the short description and the rest is prepended to the patch message. Closes: #785274
Diffstat (limited to 'tests')
-rw-r--r--tests/component/__init__.py19
-rw-r--r--tests/component/deb/test_pq.py105
2 files changed, 124 insertions, 0 deletions
diff --git a/tests/component/__init__.py b/tests/component/__init__.py
index 84acf6a6..c670851f 100644
--- a/tests/component/__init__.py
+++ b/tests/component/__init__.py
@@ -86,6 +86,25 @@ class ComponentTestGitRepository(GitRepository):
blobs = [obj[3] for obj in objs if obj[1] == 'blob']
return set(blobs)
+ def get_head_author_subject(self):
+ out, err, ret = self._git_inout('format-patch', ['-1', '--stdout', '--subject-prefix='],
+ capture_stderr=True)
+ if ret:
+ raise GitRepositoryError("Cannot get head author/subject: %s" %
+ err.strip())
+
+ output = out.decode('utf-8')
+ for line in output.split('\n'):
+ line = line.strip()
+ if not line:
+ # end of headers
+ break
+ if line.startswith('From:'):
+ author = line.replace('From:', '').strip()
+ elif line.startswith('Subject:'):
+ subject = line.replace('Subject:', '').strip()
+ return author, subject
+
class ComponentTestBase(unittest.TestCase, GbpLogTester):
"""Base class for testing cmdline tools of git-buildpackage"""
diff --git a/tests/component/deb/test_pq.py b/tests/component/deb/test_pq.py
index 976e4154..9dd985a4 100644
--- a/tests/component/deb/test_pq.py
+++ b/tests/component/deb/test_pq.py
@@ -19,11 +19,14 @@
import os
from tests.component import (ComponentTestBase)
+
+from tests.component.deb import DEB_TEST_DATA_DIR
from tests.component.deb.fixtures import RepoFixtures
from nose.tools import ok_, eq_
from gbp.scripts.pq import main as pq
+from gbp.scripts.import_dsc import main as import_dsc
class TestPq(ComponentTestBase):
@@ -81,3 +84,105 @@ class TestPq(ComponentTestBase):
with open(patch) as f:
self.assertTrue('rename from' not in f.read())
self.assertTrue('rename to' not in f.read())
+
+ @staticmethod
+ def _dsc_name(pkg, version, dir):
+ return os.path.join(DEB_TEST_DATA_DIR,
+ dir,
+ '%s_%s.dsc' % (pkg, version))
+
+ @staticmethod
+ def _append_patch(repo, name, contents):
+ with open(os.path.join(repo.path, 'debian/patches/series'), 'a') as series_file:
+ series_file.write('{}.patch\n'.format(name))
+
+ with open(os.path.join(repo.path, 'debian/patches/{}.patch'.format(name)), 'w') as patch:
+ patch.write(contents)
+
+ repo.add_files('debian/patches/{}.patch'.format(name))
+ repo.commit_files(msg='Add patch: {}.patch'.format(name),
+ files=['debian/patches/series',
+ 'debian/patches/{}.patch'.format(name)])
+
+ @RepoFixtures.quilt30()
+ def test_import(self, repo):
+ pkg = 'hello-debhelper'
+ dsc = self._dsc_name(pkg, '2.6-2', 'dsc-3.0')
+ eq_(import_dsc(['arg0', dsc]), 0)
+ self._test_pq(repo, 'import')
+
+ author, subject = repo.get_head_author_subject()
+ eq_(author, 'Santiago Vila <sanvila@debian.org>')
+ eq_(subject, 'Modified doc/Makefile.in to avoid '
+ '/usr/share/info/dir.gz')
+
+ self._test_pq(repo, 'switch')
+
+ self._append_patch(repo, 'foo', '''\
+Author: Mr. T. St <t@example.com>
+Description: Short DEP3 description
+ Long DEP3 description
+ .
+ Continued
+--- /dev/null
++++ b/foo
+@@ -0,0 +1 @@
++foo
+''')
+ self._test_pq(repo, 'import', ['--force'])
+
+ author, subject = repo.get_head_author_subject()
+ eq_(subject, 'Short DEP3 description')
+ eq_(author, '"Mr. T. St" <t@example.com>')
+
+ @RepoFixtures.quilt30()
+ def test_import_poor_dep3_behaviour(self, repo):
+ """Demonstrate the issues with the current DEP3 support"""
+
+ pkg = 'hello-debhelper'
+ dsc = self._dsc_name(pkg, '2.6-2', 'dsc-3.0')
+ eq_(import_dsc(['arg0', dsc]), 0)
+
+ self._append_patch(repo, 'foo', '''\
+Author: Mr. T. St <t@example.com>
+Description: A very long description with wrapp-
+ ing to increase readability in the file, which
+ is currently split into a short and long description.
+Origin: https://twitter.com/MrT/status/941789967361097728
+Forwarded: not-needed
+--- /dev/null
++++ b/foo
+@@ -0,0 +1 @@
++foo
+''')
+ self._test_pq(repo, 'import', ['--force'])
+
+ _, subject = repo.get_head_author_subject()
+ eq_(subject, 'A very long description with wrapp-')
+
+ self._test_pq(repo, 'export')
+
+ relevant_parts_of_patch = ''
+ with open('debian/patches/foo.patch') as patch_file:
+ for line in patch_file:
+ # skip the date as it's currently set to now(),
+ # not a deterministic value
+ if line.startswith('Date: '):
+ continue
+
+ # stop reading after the main part of the description;
+ # i.e. ignore the bit that git(1) fully controls.
+ if line.startswith('---'):
+ break
+
+ relevant_parts_of_patch += line
+
+ eq_(relevant_parts_of_patch, '''\
+From: "Mr. T. St" <t@example.com>
+Subject: A very long description with wrapp-
+
+ ing to increase readability in the file, which
+ is currently split into a short and long description.
+Origin: https://twitter.com/MrT/status/941789967361097728
+Forwarded: not-needed
+''')