aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-01-10 15:23:37 +0100
committerGuido Günther <agx@sigxcpu.org>2017-01-10 15:26:37 +0100
commit4086fc9b7e019b70eda53391489d3644494abba5 (patch)
treeddb27a9efa9a2a5e15fc8fc0e842bed0756e1345
parent92f8799fe1e293b6f206721757c7c66f4ededfa6 (diff)
import_dsc: Store debian/changelog in commit message
when importing packages. Closes: #577810
-rw-r--r--gbp/scripts/import_dsc.py34
-rw-r--r--tests/component/deb/test_import_dsc.py22
2 files changed, 51 insertions, 5 deletions
diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py
index cfeecace..280be433 100644
--- a/gbp/scripts/import_dsc.py
+++ b/gbp/scripts/import_dsc.py
@@ -31,6 +31,7 @@ from gbp.deb.git import (DebianGitRepository, GitRepositoryError)
from gbp.deb.changelog import ChangeLog
from gbp.git import rfc822_date_to_git
from gbp.git.modifier import GitModifier
+from gbp.git.vfs import GitVfs
from gbp.config import (GbpOptionParserDebian, GbpOptionGroup,
no_upstream_branch_msg)
from gbp.errors import GbpError
@@ -142,7 +143,7 @@ def check_parents(repo, branch, tag):
return parents
-def apply_debian_patch(repo, unpack_dir, src, options, tag):
+def apply_debian_patch(repo, unpack_dir, src, options, tag, is_empty):
"""apply the debian patch and tag appropriately"""
try:
os.chdir(unpack_dir)
@@ -163,8 +164,14 @@ def apply_debian_patch(repo, unpack_dir, src, options, tag):
author = get_author_from_changelog(unpack_dir)
committer = get_committer_from_author(author, options)
+
+ changes = get_changes(unpack_dir,
+ repo,
+ is_empty,
+ options.debian_branch)
+ commit_msg = "Import Debian changes %s\n%s" % (src.version, changes)
commit = repo.commit_dir(unpack_dir,
- "Import Debian patch %s" % src.version,
+ commit_msg,
branch=options.debian_branch,
other_parents=parents,
author=author,
@@ -336,6 +343,20 @@ def parse_all(argv):
return options, pkg, target
+def get_changes(dir, repo, is_empty, debian_branch):
+ if is_empty:
+ version = "0~"
+ else:
+ vfs = GitVfs(repo, debian_branch)
+ try:
+ with vfs.open('debian/changelog') as f:
+ version = ChangeLog(contents=f.read()).version
+ except IOError:
+ version = "0~" # Use full history if debian branch has no changelog
+ cl = ChangeLog(filename=os.path.join(dir, 'debian/changelog'))
+ return cl.get_changes(version)
+
+
def main(argv):
dirs = dict(top=os.path.abspath(os.curdir))
needs_repo = False
@@ -425,11 +446,16 @@ def main(argv):
if src.native:
author = get_author_from_changelog(upstream.unpacked)
committer = get_committer_from_author(author, options)
+ commit_msg = "Import %s\n%s" % (msg, get_changes(upstream.unpacked,
+ repo,
+ is_empty,
+ options.debian_branch))
else:
author = committer = {}
+ commit_msg = "Import %s" % msg
commit = repo.commit_dir(upstream.unpacked,
- "Import %s" % msg,
+ commit_msg,
branch,
author=author,
committer=committer)
@@ -453,7 +479,7 @@ def main(argv):
if not src.native:
if src.diff or src.deb_tgz:
apply_debian_patch(repo, upstream.unpacked, src, options,
- tag)
+ tag, is_empty)
else:
gbp.log.warn("Didn't find a diff to apply.")
if repo.get_branch() == options.debian_branch or is_empty:
diff --git a/tests/component/deb/test_import_dsc.py b/tests/component/deb/test_import_dsc.py
index ed586799..da4849ee 100644
--- a/tests/component/deb/test_import_dsc.py
+++ b/tests/component/deb/test_import_dsc.py
@@ -45,17 +45,27 @@ class TestImportDsc(ComponentTestBase):
repo = ComponentTestGitRepository('git-buildpackage')
self._check_repo_state(repo, 'master', ['master'])
assert len(repo.get_commits()) == 1
+ commitmsg = repo.get_commit_info('HEAD')['body']
+ ok_("git-buildpackage (0.01) unstable; urgency=low" in commitmsg)
+ ok_("git-buildpackage (0.4.14) unstable; urgency=low" in commitmsg)
os.chdir('git-buildpackage')
dsc = _dsc('0.4.15')
assert import_dsc(['arg0', dsc]) == 0
self._check_repo_state(repo, 'master', ['master'])
assert len(repo.get_commits()) == 2
+ commitmsg = repo.get_commit_info('HEAD')['body']
+ ok_("git-buildpackage (0.4.14) unstable; urgency=low" not in commitmsg)
+ ok_("git-buildpackage (0.4.15) unstable; urgency=low" in commitmsg)
dsc = _dsc('0.4.16')
assert import_dsc(['arg0', dsc]) == 0
self._check_repo_state(repo, 'master', ['master'])
assert len(repo.get_commits()) == 3
+ commitmsg = repo.get_commit_info('HEAD')['body']
+ ok_("git-buildpackage (0.4.14) unstable; urgency=low" not in commitmsg)
+ ok_("git-buildpackage (0.4.15) unstable; urgency=low" not in commitmsg)
+ ok_("git-buildpackage (0.4.16) unstable; urgency=low" in commitmsg)
@skipUnless(os.getenv("GBP_NETWORK_TESTS"), "network tests disabled")
def test_download(self):
@@ -102,7 +112,7 @@ class TestImportDsc(ComponentTestBase):
os.chdir('hello-debhelper')
assert len(repo.get_commits()) == 2
reflog, ret = repo._git_getoutput('reflog')
- ok_("gbp: Import Debian patch" in reflog[1])
+ ok_("gbp: Import Debian changes" in reflog[1])
ok_("gbp: Import Upstream version 2.6" in reflog[2])
self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream'])
dsc = _dsc('2.8-1')
@@ -134,6 +144,9 @@ class TestImportDsc(ComponentTestBase):
repo = ComponentTestGitRepository('hello-debhelper')
self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream'])
commits, expected = len(repo.get_commits()), 2
+ commitmsg = repo.get_commit_info('HEAD')['body']
+ ok_("hello-debhelper (2.8-1) unstable; urgency=low" in commitmsg)
+ ok_("hello (1.3-7) experimental; urgency=LOW" in commitmsg)
for file in ['foo/test1', 'foo/test2']:
ok_(file in repo.ls_tree('HEAD'),
@@ -229,6 +242,9 @@ class TestImportDsc(ComponentTestBase):
ok_("gbp: Import Debian changes" in reflog[1])
ok_("gbp: Import Upstream version 2.6" in reflog[2])
self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream'])
+ commitmsg = repo.get_commit_info('HEAD')['body']
+ ok_("hello-debhelper (2.6-2) unstable; urgency=medium" in commitmsg)
+ ok_("hello (1.3-7) experimental; urgency=LOW" in commitmsg)
dsc = _dsc('2.8-1')
assert import_dsc(['arg0',
@@ -239,3 +255,7 @@ class TestImportDsc(ComponentTestBase):
dsc]) == 0
commits, expected = len(repo.get_commits()), 4
ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))
+ commitmsg = repo.get_commit_info('HEAD')['body']
+ ok_("hello-debhelper (2.8-1) unstable; urgency=low" in commitmsg)
+ ok_("ello-debhelper (2.7-1) unstable; urgency=low" in commitmsg)
+ ok_("hello-debhelper (2.6-2) unstable; urgency=medium" not in commitmsg)