Hi Daniel, On Mon, Nov 21, 2011 at 03:44:41PM +0100, Daniel Dehennin wrote: > The snapshot mode fails to merge two "debian/changelog" entries if the > distribution is not "UNRELEASED". > > * tests/11_test_dch_main.py: test the new --distribution option to > dch.main(). Add only meaningful tests, i.e. options alone and combined > with --release and --snapshot. > > * git-dch (fixup_section): Rename as it's used to fix header in addition > to trailer, this require a new named parameter "options". > (main): Add version_group option "-D" and "--distribution" to > specify the distribution name. > Add version_group option "--force-distribution" to force the provided > distribution to be used, used by "dch". > Rename fixup_trailer() to fixup_section() and add options as parameters. > > * docs/manpages/git-dch.sgml: Update documentation for new options. > --- > docs/manpages/git-dch.sgml | 19 ++++ > gbp/scripts/dch.py | 29 ++++- > tests/11_test_dch_main.py | 252 > +++++++++++++++++++++++++++----------------- > 3 files changed, 198 insertions(+), 102 deletions(-) > > diff --git a/docs/manpages/git-dch.sgml b/docs/manpages/git-dch.sgml > index a009a58..0cccf09 100644 > --- a/docs/manpages/git-dch.sgml > +++ b/docs/manpages/git-dch.sgml > @@ -41,6 +41,8 @@ > <arg><option>--qa</option></arg> > <arg><option>--team</option></arg> > </group> > + > <arg><option>--distribution=</option><replaceable>name</replaceable></arg> > + <arg><option>--force-distribution</option></arg> > <arg><option>--[no-]full</option></arg> > <arg><option>--[no-]meta</option></arg> > <arg><option>--meta-closes=bug-close-tags</option></arg> > @@ -221,6 +223,23 @@ > </listitem> > </varlistentry> > <varlistentry> > + <term><option>--distribution=</option><replaceable>name</replaceable> > + </term> > + <listitem> > + <para>Set the distribution field > + to <replaceable>name</replaceable>.</para> > + </listitem> > + </varlistentry> > + <varlistentry> > + <term><option>--force-distribution</option> > + </term> > + <listitem> > + <para>Force the distribution specified > + with <option>--distribution</option> to be used, even if it > + doesn't match the list of known distributions.</para> > + </listitem> > + </varlistentry> > + <varlistentry> > > <term><option>--git-log=</option><replaceable>git-log-options</replaceable> > </term> > <listitem> > diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py > index b31a67b..5364775 100644 > --- a/gbp/scripts/dch.py > +++ b/gbp/scripts/dch.py > @@ -63,15 +63,30 @@ def get_author_email(repo, use_git_config): > return author, email > > > -def fixup_trailer(repo, git_author, dch_options): > +def fixup_section(repo, git_author, options, dch_options): > """ > - Fixup the changelog trailer's comitter and email address. > + Fixup the changelog header and trailer's comitter and email address > > It might otherwise point to the last git committer instead of the person > creating the changelog > + This apply --distribution and --urgency options passed to git-dch > """ > author, email = get_author_email(repo, git_author) > - ChangeLog.spawn_dch(msg='', author=author, email=email, > dch_options=dch_options) > + used_options = ['distribution'] > + header_opts = [] > + > + # This must not be done for snapshots or snapshots changelog entries > + # will not be concatenated > + if not options.snapshot: > + for opt in used_options: > + val = getattr(options, opt) > + if value: > + gbp.log.debug("Set header option '%s' to '%s'" % (opt, val)) > + header_opts.append("--%s=%s" % (opt, val))
I spotted this during reviewn and the tests fail too: this is supposed to be val instead of value? I'd fixed this up myself but wanted to check back in case you accidentaly pushed the wrong version. Cheers, -- Guido > + else: > + gbp.log.debug("Snapshot enabled: do not fixup options in header") > + > + ChangeLog.spawn_dch(msg='', author=author, email=email, > dch_options=dch_options+header_opts) > > > def snapshot_version(version): > @@ -223,6 +238,9 @@ def process_options(options, parser): > else: > dch_options.append("--nomultimaint") > > + if options.force_distribution: > + dch_options.append("--force-distribution") > + > get_customizations(options.customization_file) > return dch_options > > @@ -295,6 +313,9 @@ def main(argv): > help="mark as release") > version_group.add_option("-S", "--snapshot", action="store_true", > dest="snapshot", default=False, > help="mark as snapshot build") > + version_group.add_option("-D", "--distribution", dest="distribution", > help="Set distribution") > + version_group.add_option("--force-distribution", action="store_true", > dest="force_distribution", default=False, > + help="Force the provided distribution to be used, even > if it doesn't match the list of known distributions") > version_group.add_option("-N", "--new-version", dest="new_version", > help="use this as base for the new version number") > version_group.add_option("--bpo", dest="bpo", action="store_true", > default=False, > @@ -446,7 +467,7 @@ def main(argv): > version=version_change, > dch_options=dch_options) > > - fixup_trailer(repo, git_author=options.git_author, > + fixup_section(repo, git_author=options.git_author, options=options, > dch_options=dch_options) > > if options.release: > diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py > index f45857e..36431ef 100644 > --- a/tests/11_test_dch_main.py > +++ b/tests/11_test_dch_main.py > @@ -20,6 +20,9 @@ snap_header_1_2 = > r'^test-package\s\(1.0-1~2\.gbp([0-9a-f]{6})\)\sUNRELEASED;\su > > snap_mark = r'\s{2}\*{2}\sSNAPSHOT\sbuild\s@' > > +deb_tag = "debian/0.9-1" > +deb_tag_msg = "Pre stable release version 0.9-1" > + > cl_debian = """test-package (0.9-1) unstable; urgency=low > > [ Debian Maintainer ] > @@ -28,10 +31,12 @@ cl_debian = """test-package (0.9-1) unstable; urgency=low > -- Debian Maintainer <ma...@debian.org> Mon, 17 Oct 2011 10:15:22 +0200 > """ > > + > @unittest.skipIf(not os.path.exists('/usr/bin/dch'), "Dch not found") > class TestScriptDch(DebianGitTestRepo): > """Test git-dch""" > > + > def setUp(self): > DebianGitTestRepo.setUp(self) > self.add_file("foo", "bar") > @@ -48,76 +53,71 @@ class TestScriptDch(DebianGitTestRepo): > self.add_file("debian/control", """Source: test-package\nSection: > test\n""") > self.options = ["--upstream-tag=%s" % self.upstream_tag, > "--debian-branch=debian", > "--id-length=0", "--spawn-editor=/bin/true"] > + self.repo.create_tag(deb_tag, msg=deb_tag_msg, commit="HEAD~1") > + > > def tearDown(self): > os.chdir(self.top) > DebianGitTestRepo.tearDown(self) > > - def test_dch_main_new_upstream_version(self): > - """Test dch.py like git-dch script does: new upstream version""" > + > + def run_dch(self, dch_options=None): > + # Take care to copy the list > options = self.options[:] > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > + if dch_options is not None: > + options.extend(dch_options) > ret = dch.main(options) > self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + return file("debian/changelog").readlines() > + > + > + def test_dch_main_new_upstream_version(self): > + """Test dch.py like git-dch script does: new upstream version""" > + lines = self.run_dch() > self.assertEqual("test-package (1.0-1) UNRELEASED; urgency=low\n", > lines[0]) > self.assertIn(""" * added debian/control\n""", lines) > > + > def test_dch_main_new_upstream_version_with_release(self): > """Test dch.py like git-dch script does: new upstream version - > release""" > - options = self.options[:] > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > - options.append("--release") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + options = ["--release"] > + lines = self.run_dch(options) > self.assertEqual("test-package (1.0-1) unstable; urgency=low\n", > lines[0]) > self.assertIn(""" * added debian/control\n""", lines) > > + > def test_dch_main_new_upstream_version_with_auto(self): > """Test dch.py like git-dch script does: new upstream version - > guess last commit""" > - options = self.options[:] > - options.append("--auto") > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + options = ["--auto"] > + lines = self.run_dch(options) > self.assertEqual("test-package (1.0-1) UNRELEASED; urgency=low\n", > lines[0]) > self.assertIn(""" * added debian/control\n""", lines) > > + > def test_dch_main_new_upstream_version_with_snapshot(self): > - """Test dch.py like git-dch script does: new upstream version - > snashot mode""" > - options = self.options[:] > - options.append("--snapshot") > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + """Test dch.py like git-dch script does: new upstream version - > snapshot mode""" > + options = ["--snapshot"] > + 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_new_upstream_version_with_2_snapshots_auto(self): > """Test dch.py like git-dch script does: new upstream version - two > snapshots - auto""" > - options = self.options[:] > - options.append("--snapshot") > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + options = ["--snapshot"] > + lines = self.run_dch(options) > header1 = re.search(snap_header_1, lines[0]) > self.assertIsNotNone(header1) > self.assertEqual(header1.lastindex, 1) > self.assertIsNotNone(re.search(snap_mark + header1.group(1), > lines[2])) > self.assertIn(""" * added debian/control\n""", lines) > # New snapshot, use auto to guess last one > - options.append("--auto") > self.add_file("debian/compat", "9") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + options.append("--auto") > + lines = self.run_dch(options) > header2 = re.search(snap_header_1_2, lines[0]) > self.assertIsNotNone(header2) > self.assertEqual(header2.lastindex, 1) > @@ -127,27 +127,22 @@ class TestScriptDch(DebianGitTestRepo): > self.assertIn(""" * added debian/control\n""", lines) > self.assertIn(""" * added debian/compat\n""", lines) > > + > def > test_dch_main_new_upstream_version_with_2_snapshots_commit_auto(self): > """Test dch.py like git-dch script does: new upstream version - two > committed snapshots - auto""" > - options = self.options[:] > - options.append("--commit") > + options = ["--commit"] > options.append("--commit-msg=TEST-COMMITTED-SNAPSHOT") > options.append("--snapshot") > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + lines = self.run_dch(options) > header1 = re.search(snap_header_1, lines[0]) > self.assertIsNotNone(header1) > self.assertEqual(header1.lastindex, 1) > self.assertIsNotNone(re.search(snap_mark + header1.group(1), > lines[2])) > self.assertIn(""" * added debian/control\n""", lines) > # New snapshot, use auto to guess last one > - options.append("--auto") > self.add_file("debian/compat", "9") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + options.append("--auto") > + lines = self.run_dch(options) > header2 = re.search(snap_header_1_2, lines[0]) > self.assertIsNotNone(header2) > self.assertEqual(header2.lastindex, 1) > @@ -159,114 +154,175 @@ class TestScriptDch(DebianGitTestRepo): > # But its changelog must be included in the new one > self.assertIn(""" * TEST-COMMITTED-SNAPSHOT\n""", lines) > > + > def test_dch_main_new_upstream_version_with_auto_release(self): > """Test dch.py like git-dch script does: new upstream version - auto > - release""" > - options = self.options[:] > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > - options.append("--auto") > + options = ["--auto"] > options.append("--release") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + lines = self.run_dch(options) > self.assertEqual("test-package (1.0-1) unstable; urgency=low\n", > lines[0]) > self.assertIn(""" * added debian/control\n""", lines) > > + > def test_dch_main_new_upstream_version_with_auto_snapshot(self): > - """Test dch.py like git-dch script does: new upstream version - auto > - snashot mode""" > - options = self.options[:] > - options.append("--auto") > + """Test dch.py like git-dch script does: new upstream version - auto > - snapshot mode""" > + options = ["--auto"] > options.append("--snapshot") > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + 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_new_upstream_version_with_snapshot_release(self): > - """Test dch.py like git-dch script does: new upstream version - > snashot - release""" > - options = self.options[:] > - options.append("--snapshot") > + """Test dch.py like git-dch script does: new upstream version - > snapshot - release""" > + options = ["--snapshot"] > options.append("--release") > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > - self.assertRaises(SystemExit, dch.main, options) > + self.assertRaises(SystemExit, self.run_dch, options) > + > + > + def test_dch_main_new_upstream_version_with_distribution(self): > + """Test dch.py like git-dch script does: new upstream version - set > distribution""" > + options = ["--distribution=testing"] > + lines = self.run_dch(options) > + self.assertEqual("test-package (1.0-1) testing; urgency=low\n", > lines[0]) > + self.assertIn(""" * added debian/control\n""", lines) > + > + > + def test_dch_main_new_upstream_version_with_release_distribution(self): > + """Test dch.py like git-dch script does: new upstream version - > release - set distribution""" > + options = ["--release"] > + options.append("--distribution=testing") > + lines = self.run_dch(options) > + self.assertEqual("test-package (1.0-1) testing; urgency=low\n", > lines[0]) > + self.assertIn(""" * added debian/control\n""", lines) > + > + > + def test_dch_main_new_upstream_version_with_snapshot_distribution(self): > + """Test dch.py like git-dch script does: new upstream version - > snapshot mode - do not set distribution""" > + options = ["--snapshot"] > + options.append("--distribution=testing") > + 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_new_upstream_version_with_2_snapshots_auto_distribution(self): > + """Test dch.py like git-dch script does: new upstream version - two > snapshots - do not set distribution""" > + options = ["--snapshot"] > + options.append("--distribution=testing") > + lines = self.run_dch(options) > + header1 = re.search(snap_header_1, lines[0]) > + self.assertIsNotNone(header1) > + self.assertEqual(header1.lastindex, 1) > + self.assertIsNotNone(re.search(snap_mark + header1.group(1), > lines[2])) > + self.assertIn(""" * added debian/control\n""", lines) > + # New snapshot, use auto to guess last one > + self.add_file("debian/compat", "9") > + options.append("--auto") > + lines = self.run_dch(options) > + header2 = re.search(snap_header_1_2, lines[0]) > + self.assertIsNotNone(header2) > + self.assertEqual(header2.lastindex, 1) > + self.assertIsNotNone(re.search(snap_mark + header2.group(1), > lines[2])) > + # First snapshot entry must be concatenated with the last one > + self.assertNotIn(header1.group(0) + "\n", lines) > + self.assertIn(""" * added debian/control\n""", lines) > + self.assertIn(""" * added debian/compat\n""", lines) > + # But its changelog must not be included in the new one since > + # we do not commit > + self.assertNotIn(""" * TEST-COMMITTED-SNAPSHOT\n""", lines) > + > + > + def > test_dch_main_new_upstream_version_with_2_snapshots_commit_auto_distribution(self): > + """Test dch.py like git-dch script does: new upstream version - two > committed snapshots - do not set distribution""" > + options = ["--commit"] > + options.append("--commit-msg=TEST-COMMITTED-SNAPSHOT") > + options.append("--snapshot") > + options.append("--distribution=testing") > + lines = self.run_dch(options) > + header1 = re.search(snap_header_1, lines[0]) > + self.assertIsNotNone(header1) > + self.assertEqual(header1.lastindex, 1) > + self.assertIsNotNone(re.search(snap_mark + header1.group(1), > lines[2])) > + self.assertIn(""" * added debian/control\n""", lines) > + # New snapshot, use auto to guess last one > + self.add_file("debian/compat", "9") > + options.append("--auto") > + lines = self.run_dch(options) > + header2 = re.search(snap_header_1_2, lines[0]) > + self.assertIsNotNone(header2) > + self.assertEqual(header2.lastindex, 1) > + self.assertIsNotNone(re.search(snap_mark + header2.group(1), > lines[2])) > + self.assertIn(""" * added debian/control\n""", lines) > + self.assertIn(""" * added debian/compat\n""", lines) > + # First snapshot entry must have disapear > + self.assertNotIn(header1.group(0) + "\n", lines) > + # But its changelog must be included in the new one > + self.assertIn(""" * TEST-COMMITTED-SNAPSHOT\n""", lines) > + > > def test_dch_main_increment_debian_version(self): > """Test dch.py like git-dch script does: increment debian version""" > - options = self.options[:] > + self.repo.delete_tag("debian/0.9-1") > self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~2") > self.repo.delete_tag("upstream/1.0") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + lines = self.run_dch() > self.assertEqual("test-package (0.9-2) UNRELEASED; urgency=low\n", > lines[0]) > self.assertIn(""" * added debian/control\n""", lines) > > + > def test_dch_main_increment_debian_version_with_release(self): > """Test dch.py like git-dch script does: increment debian version - > release""" > - options = self.options[:] > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > self.repo.delete_tag("upstream/1.0") > - options.append("--release") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + options = ["--release"] > + lines = self.run_dch(options) > self.assertEqual("test-package (0.9-2) unstable; urgency=low\n", > lines[0]) > self.assertIn(""" * added debian/control\n""", lines) > > + > def test_dch_main_increment_debian_version_with_auto(self): > """Test dch.py like git-dch script does: increment debian version - > guess last commit""" > - options = self.options[:] > - options.append("--auto") > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > self.repo.delete_tag("upstream/1.0") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + options = ["--auto"] > + lines = self.run_dch(options) > self.assertEqual("test-package (0.9-2) UNRELEASED; urgency=low\n", > lines[0]) > self.assertIn(""" * added debian/control\n""", lines) > > + > def test_dch_main_increment_debian_version_with_snapshot(self): > - """Test dch.py like git-dch script does: increment debian version - > snashot mode""" > - options = self.options[:] > - options.append("--snapshot") > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > + """Test dch.py like git-dch script does: increment debian version - > snapshot mode""" > self.repo.delete_tag("upstream/1.0") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + options = ["--snapshot"] > + lines = self.run_dch(options) > header = re.search(snap_header_0_9, 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_increment_debian_version_with_auto_release(self): > """Test dch.py like git-dch script does: increment debian version - > auto - release""" > - options = self.options[:] > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > self.repo.delete_tag("upstream/1.0") > - options.append("--auto") > + options = ["--auto"] > options.append("--release") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + lines = self.run_dch(options) > self.assertEqual("test-package (0.9-2) unstable; urgency=low\n", > lines[0]) > self.assertIn(""" * added debian/control\n""", lines) > > + > def test_dch_main_increment_debian_version_with_auto_snapshot(self): > - """Test dch.py like git-dch script does: increment debian version - > auto - snashot mode""" > - options = self.options[:] > - options.append("--auto") > - options.append("--snapshot") > - self.repo.create_tag("debian/0.9-1", msg="Pre stable release version > 0.9-1", commit="HEAD~1") > + """Test dch.py like git-dch script does: increment debian version - > auto - snapshot mode""" > self.repo.delete_tag("upstream/1.0") > - ret = dch.main(options) > - self.assertEqual(ret, 0) > - lines = file("debian/changelog").readlines() > + options = ["--auto"] > + options.append("--snapshot") > + lines = self.run_dch(options) > header = re.search(snap_header_0_9, lines[0]) > self.assertIsNotNone(header) > self.assertEqual(header.lastindex, 1) > -- > 1.7.10.4 -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org