On Mon, Sep 26, 2016 at 08:19:27AM +0200, Guido Günther wrote:
[...]
> This makes sense. Can you add a test to 11_test_dch_main.py to make sure
> we don't break this again in the future?
> Cheers,

I added a test, and have attached the v2 patch. The following are the test
results with and without the patch applied:

$ git checkout master
$ git checkout snapshot-fix -- tests/11_test_dch_main.py
$ dpkg-buildpackage -us -uc
[...]
python setup.py nosetests --with-xcoverage
running nosetests
running egg_info
writing gbp.egg-info/PKG-INFO
writing top-level names to gbp.egg-info/top_level.txt
writing dependency_links to gbp.egg-info/dependency_links.txt
writing entry points to gbp.egg-info/entry_points.txt
reading manifest file 'gbp.egg-info/SOURCES.txt'
writing manifest file 'gbp.egg-info/SOURCES.txt'
.............................................................SS.................................................................................F............Switched
 to a new branch 'bar'
.Switched to a new branch 'bar'
.......................................................................................................................................................................
======================================================================
FAIL: Test dch.py like gbp dch script does: snapshot mode with unreleased 
debian version
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/crosetto/dev/git-buildpackage/tests/11_test_dch_main.py", line 
353, in test_dch_main_unreleased_debian_version_with_snapshot
    self.assertIsNotNone(header)
AssertionError: unexpectedly None
-------------------- >> begin captured logging << --------------------
gbp: info: Changelog last touched at 'f6cf282ecee80f64016056ede581ecf4eb38df65'
gbp: info: Continuing from commit 'f6cf282ecee80f64016056ede581ecf4eb38df65'
gbp: info: Changelog 1.0-2~1.gbp3a1060 (snapshot #1) prepared up to 3a10607
--------------------- >> end captured logging << ---------------------
[...]
$ git reset HEAD --hard
$ git am v2-0001-dch-avoid-adding-section-in-snapshot-mode-if-dist.patch
Applying: dch: avoid adding section in snapshot mode if distribution is 
UNRELEASED
.git/rebase-apply/patch:18: indent with spaces.
        add_section = False
.git/rebase-apply/patch:34: indent with spaces.
        elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner:
.git/rebase-apply/patch:35: indent with spaces.
            if commits:
.git/rebase-apply/patch:36: indent with spaces.
                # the last version was a release and we have pending commits
.git/rebase-apply/patch:37: indent with spaces.
                add_section = True
warning: squelched 17 whitespace errors
warning: 22 lines add whitespace errors.
$ dpkg-buildpackage -us -uc
[...]
python setup.py nosetests --with-xcoverage
running nosetests
running egg_info
writing gbp.egg-info/PKG-INFO
writing top-level names to gbp.egg-info/top_level.txt 
writing dependency_links to gbp.egg-info/dependency_links.txt
writing entry points to gbp.egg-info/entry_points.txt 
reading manifest file 'gbp.egg-info/SOURCES.txt'
writing manifest file 'gbp.egg-info/SOURCES.txt'
.............................................................SS..............................................................................................Switched
 to a new branch 'bar'
.Switched to a new branch 'bar'
.......................................................................................................................................................................
[...]

-- Linn
From d5870bc950fc88cd120f832c93477ed560577be6 Mon Sep 17 00:00:00 2001
From: Linn Crosetto <l...@hpe.com>
Date: Wed, 21 Sep 2016 15:59:00 -0600
Subject: [PATCH v2] dch: avoid adding section in snapshot mode if distribution
 is UNRELEASED

When using git-dch in snapshot mode, a section is added without checking
whether the distribution is set to UNRELEASED. If the distribution is
UNRELEASED, the version will be incremented but a new section will not be
added, resulting in a skipped version in the changelog.

Change this behavior to add a new section in snapshot mode only if the
distribution is not set to UNRELEASED.

Signed-off-by: Linn Crosetto <l...@hpe.com>
---
v2
 - dhc.py: set default value for add_section
 - add test_dch_main_unreleased_debian_version_with_snapshot (Guido Günther)

 gbp/scripts/dch.py        | 16 ++++++++--------
 tests/11_test_dch_main.py | 16 ++++++++++++++++
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py
index 2ccbacb..d716fba 100644
--- a/gbp/scripts/dch.py
+++ b/gbp/scripts/dch.py
@@ -466,6 +466,7 @@ def main(argv):
                                    options=options.git_log.split(" "))
         commits.reverse()
 
+        add_section = False
         # add a new changelog section if:
         if (options.new_version or options.bpo or options.nmu or options.qa or
                 options.team or options.security):
@@ -483,14 +484,13 @@ def main(argv):
                 version_change['version'] = options.new_version
             # the user wants to force a new version
             add_section = True
-        elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner and commits:
-            # the last version was a release and we have pending commits
-            add_section = True
-        elif options.snapshot and not found_snapshot_banner:
-            # the user want to switch to snapshot mode
-            add_section = True
-        else:
-            add_section = False
+        elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner:
+            if commits:
+                # the last version was a release and we have pending commits
+                add_section = True
+            if options.snapshot:
+                # the user want to switch to snapshot mode
+                add_section = True
 
         if add_section and not version_change and not source.is_native():
             # Get version from upstream if none provided
diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py
index a6c7876..e9b6400 100644
--- a/tests/11_test_dch_main.py
+++ b/tests/11_test_dch_main.py
@@ -339,6 +339,22 @@ class TestScriptDch(DebianGitTestRepo):
         self.assertIsNotNone(re.search(snap_mark + header.group(1), lines[2]))
         self.assertIn("""  * added debian/control\n""", lines)
 
+    def test_dch_main_unreleased_debian_version_with_snapshot(self):
+        """Test dch.py like gbp dch script does: snapshot mode with unreleased debian version"""
+        new_version_1_0 = '1.0-1'
+        options = ["--commit"]
+        options.append("--commit-msg=UNRELEASED-version")
+        lines = self.run_dch()
+        header = re.search(r"\(%s\) UNRELEASED" % new_version_1_0, lines[0])
+        self.assertIsNotNone(header)
+        options = ["--snapshot", "--auto"]
+        lines = self.run_dch(options)
+        header = re.search(snap_header_1, lines[0])
+        self.assertIsNotNone(header)
+        self.assertEqual(header.lastindex, 1)
+        self.assertIsNotNone(re.search(snap_mark + header.group(1), lines[2]))
+        self.assertIn("""  * added debian/control\n""", lines)
+
     def test_dch_main_closes_default(self):
         options = ["--meta"]
         self.add_file("closes", "test file",
-- 
2.9.3

Attachment: signature.asc
Description: Digital signature

Reply via email to