summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-11-27 19:59:32 +0100
committerGuido Günther <agx@sigxcpu.org>2017-11-27 22:49:52 +0100
commit45a0652fa344e63b00970202003ff63ecfa9a2d9 (patch)
tree7ecf3ee349bb100f896d6c6610a64e92db3886b2
parentf777a46d612f4d1727f1947f191b46bcacb5f378 (diff)
dch: Create changelog if missing
Closes: #669171 Thanks: Daniel Dehennin for the groundwork on this
-rw-r--r--docs/manpages/gbp-dch.xml4
-rw-r--r--gbp/scripts/dch.py22
-rw-r--r--tests/11_test_dch_main.py9
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).
</para>
+ <para>
+ If not changelog exists yet it is created and the version number
+ is derived from the last upstream tag if found.
+ </para>
</refsect1>
<refsect1>
<title>OPTIONS</title>
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])