diff options
author | Guido Günther <agx@sigxcpu.org> | 2017-03-14 08:33:34 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2017-03-14 08:35:17 +0100 |
commit | 1dd290a792d5a9e3b712ff88482540fd283f0171 (patch) | |
tree | 499dd8df509101e1fb08ef3d2b40087e183decae | |
parent | fe821e2bec0df8611c2d0639a52baa8ddc84cc28 (diff) |
pq: unbreak --commit when patch series becomes empty
We skipped the commit when the patch series became completely empty
but we want to commit that change too.
-rwxr-xr-x | gbp/scripts/pq.py | 21 | ||||
-rw-r--r-- | tests/13_test_gbp_pq.py | 26 |
2 files changed, 37 insertions, 10 deletions
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 2693d30d..1a0dcfa8 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -223,18 +223,19 @@ def export_patches(repo, branch, options): with open(series_file, 'w') as seriesfd: for patch in patches: seriesfd.write(os.path.relpath(patch, patch_dir) + '\n') - if options.commit: - added, removed = commit_patches(repo, branch, patches, options, patch_dir) - if added: - what = 'patches' if len(added) > 1 else 'patch' - gbp.log.info("Added %s %s to patch series" % (what, ', '.join(added))) - if removed: - what = 'patches' if len(removed) > 1 else 'patch' - gbp.log.info("Removed %s %s from patch series" % (what, ', '.join(removed))) + else: + gbp.log.info("No patches on '%s' - nothing to export." % pq_branch) + + if options.commit: + added, removed = commit_patches(repo, branch, patches, options, patch_dir) + if added: + what = 'patches' if len(added) > 1 else 'patch' + gbp.log.info("Added %s %s to patch series" % (what, ', '.join(added))) + if removed: + what = 'patches' if len(removed) > 1 else 'patch' + gbp.log.info("Removed %s %s from patch series" % (what, ', '.join(removed))) else: GitCommand('status', cwd=repo.path)(['--', PATCH_DIR]) - else: - gbp.log.info("No patches on '%s' - nothing to do." % pq_branch) if options.drop: drop_pq(repo, branch) diff --git a/tests/13_test_gbp_pq.py b/tests/13_test_gbp_pq.py index c63ee12d..bb2206c6 100644 --- a/tests/13_test_gbp_pq.py +++ b/tests/13_test_gbp_pq.py @@ -217,6 +217,7 @@ class TestExport(testutils.DebianGitTestRepo): meta_closes = False meta_closes_bugnum = '' pq_from = 'DEBIAN' + commit = False def setUp(self): testutils.DebianGitTestRepo.setUp(self) @@ -257,6 +258,31 @@ class TestExport(testutils.DebianGitTestRepo): self.assertEqual(len(repo.get_commits()), 2, "Export must not create another commit") + def test_commit_dropped_patches(self): + """Test if we commit the patch-queue branch with all patches dropped""" + repo = self.repo + start = repo.get_branch() + pq_branch = os.path.join('patch-queue', start) + opts = TestExport.Options() + opts.commit = True + patch_dir = os.path.join(repo.path, 'debian/patches') + os.makedirs(patch_dir) + with open(os.path.join(patch_dir, 'series'), 'w') as f: + f.write("patch1.diff\n") + f.write("patch2.diff\n") + repo.add_files('debian/patches') + repo.commit_all('Add series file') + pq.switch_pq(repo, start) + self.assertEqual(len(repo.get_commits()), 2) + self.assertEqual(repo.get_branch(), pq_branch) + export_patches(repo, pq_branch, opts) + self.assertEqual(repo.get_branch(), start) + self.assertTrue(repo.has_branch(pq_branch)) + self.assertEqual(len(repo.get_commits()), 3, + "Export did not create commit") + self.assertIn("Dropped patch1.diff:", repo.show('HEAD')) + self.assertIn("Dropped patch2.diff:", repo.show('HEAD')) + class TestParseGbpCommand(unittest.TestCase): def test_empty_body(self): |