From 45a0652fa344e63b00970202003ff63ecfa9a2d9 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 27 Nov 2017 19:59:32 +0100 Subject: dch: Create changelog if missing Closes: #669171 Thanks: Daniel Dehennin for the groundwork on this --- docs/manpages/gbp-dch.xml | 4 ++++ gbp/scripts/dch.py | 22 +++++++++++++++++++++- tests/11_test_dch_main.py | 9 ++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/manpages/gbp-dch.xml b/docs/manpages/gbp-dch.xml index 24773b15..e85cb777 100644 --- a/docs/manpages/gbp-dch.xml +++ b/docs/manpages/gbp-dch.xml @@ -137,6 +137,10 @@ or upstream's tagging pattern (when using upstream's git directly). + + If not changelog exists yet it is created and the version number + is derived from the last upstream tag if found. + OPTIONS diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index 0d66a801..a086464c 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -304,6 +304,26 @@ def changelog_commit_msg(options, version): return options.commit_msg % dict(version=version) +def create_changelog(repo, source, options): + try: + name = source.control.name + except DebianSourceError: + raise GbpError("Did not find debian/changelog or debian/source. Is this a Debian package?") + version = guess_version_from_upstream(repo, options.upstream_tag, + options.upstream_branch, None) + return ChangeLog.create(name, version) + + +def maybe_create_changelog(repo, source, options): + """ + Get the changelog or create a new one if it does not exist yet + """ + try: + return source.changelog + except DebianSourceError: + return create_changelog(repo, source, options) + + def build_parser(name): try: parser = GbpOptionParserDebian(command=os.path.basename(name), @@ -452,7 +472,7 @@ def main(argv): raise GbpError("Use --ignore-branch to ignore or --debian-branch to set the branch name.") source = DebianSource('.') - cp = source.changelog + cp = maybe_create_changelog(repo, source, options) if options.since: since = options.since diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py index bebb1e4c..d9023c3c 100644 --- a/tests/11_test_dch_main.py +++ b/tests/11_test_dch_main.py @@ -404,4 +404,11 @@ class TestScriptDch(DebianGitTestRepo): def test_dch_subdir(self): os.chdir('debian/') - self.run_dch() + lines = self.run_dch() + self.assertEqual("test-package (1.0-1) UNRELEASED; urgency=%s\n" % default_urgency, lines[0]) + self.assertIn(""" * added debian/control\n""", lines) + + def test_dch_create_changelog(self): + os.unlink('debian/changelog') + lines = self.run_dch() + self.assertEqual("test-package (1.0-1) UNRELEASED; urgency=%s\n" % default_urgency, lines[0]) -- cgit v1.2.3